diff options
Diffstat (limited to 'src/others/mimesh/libg3d-0.0.8/src/stream_gsf_class.c')
-rw-r--r-- | src/others/mimesh/libg3d-0.0.8/src/stream_gsf_class.c | 135 |
1 files changed, 135 insertions, 0 deletions
diff --git a/src/others/mimesh/libg3d-0.0.8/src/stream_gsf_class.c b/src/others/mimesh/libg3d-0.0.8/src/stream_gsf_class.c new file mode 100644 index 0000000..ff127bf --- /dev/null +++ b/src/others/mimesh/libg3d-0.0.8/src/stream_gsf_class.c | |||
@@ -0,0 +1,135 @@ | |||
1 | /* $Id:$ */ | ||
2 | |||
3 | /* | ||
4 | libg3d - 3D object loading library | ||
5 | |||
6 | Copyright (C) 2005-2009 Markus Dahms <mad@automagically.de> | ||
7 | |||
8 | This library is free software; you can redistribute it and/or | ||
9 | modify it under the terms of the GNU Lesser General Public | ||
10 | License as published by the Free Software Foundation; either | ||
11 | version 2.1 of the License, or (at your option) any later version. | ||
12 | |||
13 | This library is distributed in the hope that it will be useful, | ||
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
16 | Lesser General Public License for more details. | ||
17 | |||
18 | You should have received a copy of the GNU Lesser General Public | ||
19 | License along with this library; if not, write to the Free Software | ||
20 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
21 | */ | ||
22 | #include <gsf/gsf-infile.h> | ||
23 | #include <gsf/gsf-infile-impl.h> | ||
24 | #include <gsf/gsf-impl-utils.h> | ||
25 | |||
26 | #include <g3d/types.h> | ||
27 | #include <g3d/stream.h> | ||
28 | |||
29 | #include "stream_gsf_class.h" | ||
30 | |||
31 | static GObjectClass *parent_class; | ||
32 | |||
33 | struct _G3DGsfInputStream { | ||
34 | GsfInput input; | ||
35 | G3DStream *stream; | ||
36 | guint8 *buf; | ||
37 | gsize buf_size; | ||
38 | }; | ||
39 | |||
40 | typedef struct { | ||
41 | GsfInputClass input_class; | ||
42 | } G3DGsfInputStreamClass; | ||
43 | |||
44 | EAPI | ||
45 | GsfInput *g3d_gsf_input_stream_new(G3DStream *stream) | ||
46 | { | ||
47 | G3DGsfInputStream *g3dsf; | ||
48 | |||
49 | g3dsf = g_object_new(G3D_GSF_INPUT_STREAM_TYPE, NULL); | ||
50 | g3dsf->stream = stream; | ||
51 | |||
52 | gsf_input_set_size(GSF_INPUT(g3dsf), g3d_stream_size(stream)); | ||
53 | gsf_input_set_name_from_filename(GSF_INPUT(g3dsf), stream->uri); | ||
54 | |||
55 | return GSF_INPUT(g3dsf); | ||
56 | } | ||
57 | |||
58 | EAPI G3DStream *g3d_gsf_input_stream_get_stream(GsfInput *input) | ||
59 | { | ||
60 | G3DGsfInputStream *g3dsf = G3D_GSF_INPUT_STREAM(input); | ||
61 | |||
62 | return g3dsf->stream; | ||
63 | } | ||
64 | |||
65 | static void g3d_gsf_input_stream_finalize(GObject *obj) | ||
66 | { | ||
67 | G3DGsfInputStream *g3dsf = G3D_GSF_INPUT_STREAM(obj); | ||
68 | |||
69 | if(g3dsf->buf) | ||
70 | g_free(g3dsf->buf); | ||
71 | |||
72 | parent_class->finalize(obj); | ||
73 | } | ||
74 | |||
75 | static GsfInput *g3d_gsf_input_stream_dup(GsfInput *src_input, GError **err) | ||
76 | { | ||
77 | G3DGsfInputStream *g3dsf = G3D_GSF_INPUT_STREAM(src_input); | ||
78 | |||
79 | return g3d_gsf_input_stream_new(g3dsf->stream); | ||
80 | } | ||
81 | |||
82 | static const guint8 *g3d_gsf_input_stream_read(GsfInput *input, | ||
83 | size_t num_bytes, guint8 *buffer) | ||
84 | { | ||
85 | G3DGsfInputStream *g3dsf = G3D_GSF_INPUT_STREAM(input); | ||
86 | |||
87 | if(buffer == NULL) { | ||
88 | if(g3dsf->buf_size < num_bytes) { | ||
89 | g3dsf->buf_size = num_bytes; | ||
90 | if(g3dsf->buf) | ||
91 | g_free(g3dsf->buf); | ||
92 | g3dsf->buf = g_new0(guint8, num_bytes); | ||
93 | } | ||
94 | buffer = g3dsf->buf; | ||
95 | } | ||
96 | |||
97 | g3d_stream_read(g3dsf->stream, buffer, num_bytes); | ||
98 | return buffer; | ||
99 | } | ||
100 | |||
101 | static gboolean g3d_gsf_input_stream_seek(GsfInput *input, gsf_off_t offset, | ||
102 | GSeekType whence) | ||
103 | { | ||
104 | G3DGsfInputStream *g3dsf = G3D_GSF_INPUT_STREAM(input); | ||
105 | |||
106 | return g3d_stream_seek(g3dsf->stream, offset, whence); | ||
107 | } | ||
108 | |||
109 | static void g3d_gsf_input_stream_init(GObject *obj) | ||
110 | { | ||
111 | G3DGsfInputStream *g3dsf = G3D_GSF_INPUT_STREAM(obj); | ||
112 | |||
113 | g3dsf->stream = NULL; | ||
114 | g3dsf->buf = NULL; | ||
115 | g3dsf->buf_size = 0; | ||
116 | } | ||
117 | |||
118 | static void g3d_gsf_input_stream_class_init(GObjectClass *gobject_class) | ||
119 | { | ||
120 | GsfInputClass *input_class = GSF_INPUT_CLASS(gobject_class); | ||
121 | |||
122 | gobject_class->finalize = g3d_gsf_input_stream_finalize; | ||
123 | input_class->Dup = g3d_gsf_input_stream_dup; | ||
124 | input_class->Read = g3d_gsf_input_stream_read; | ||
125 | input_class->Seek = g3d_gsf_input_stream_seek; | ||
126 | |||
127 | parent_class = g_type_class_peek_parent(gobject_class); | ||
128 | } | ||
129 | |||
130 | GSF_CLASS(G3DGsfInputStream, | ||
131 | g3d_gsf_input_stream, | ||
132 | g3d_gsf_input_stream_class_init, | ||
133 | g3d_gsf_input_stream_init, | ||
134 | GSF_INPUT_TYPE) | ||
135 | |||