aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src/others/mimesh/libg3d-0.0.8/plugins/import/imp_skp/imp_skp_read.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/others/mimesh/libg3d-0.0.8/plugins/import/imp_skp/imp_skp_read.c')
-rw-r--r--src/others/mimesh/libg3d-0.0.8/plugins/import/imp_skp/imp_skp_read.c114
1 files changed, 114 insertions, 0 deletions
diff --git a/src/others/mimesh/libg3d-0.0.8/plugins/import/imp_skp/imp_skp_read.c b/src/others/mimesh/libg3d-0.0.8/plugins/import/imp_skp/imp_skp_read.c
new file mode 100644
index 0000000..7f95477
--- /dev/null
+++ b/src/others/mimesh/libg3d-0.0.8/plugins/import/imp_skp/imp_skp_read.c
@@ -0,0 +1,114 @@
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 "imp_skp.h"
23#include "imp_skp_read.h"
24
25guint32 skp_read_xint16(G3DStream *stream)
26{
27 guint32 val;
28
29 val = g3d_stream_read_int16_le(stream);
30 if(val & 0x8000L) {
31 val &= 0x7FFF;
32 val |= (g3d_stream_read_int16_le(stream) << 16);
33 }
34 return val;
35}
36
37gchar *skp_read_char(G3DStream *stream)
38{
39 guint32 magic, n;
40 gchar *text;
41
42 magic = g3d_stream_read_int32_be(stream);
43 if(magic != 0xffff0000) {
44 g_warning("SKP: wrong text magic: 0x%08x", magic);
45 return NULL;
46 }
47 n = g3d_stream_read_int16_le(stream);
48
49 text = g_new0(gchar, n + 1);
50 g3d_stream_read(stream, text, n);
51
52 return text;
53}
54
55gchar *skp_read_wchar(G3DStream *stream)
56{
57 gint32 i;
58 guint32 magic, n;
59 gunichar2 *u16text;
60 gchar *text;
61 GError *error = NULL;
62
63 magic = g3d_stream_read_int32_be(stream);
64 if((magic & 0xFFFFFF00) != 0xfffeff00) {
65#if DEBUG > 1
66 g_debug("SKP: wrong UTF-16 magic: 0x%08x", magic);
67#endif
68 g3d_stream_seek(stream, -4, G_SEEK_CUR);
69 return NULL;
70 }
71 n = magic & 0x000000FF;
72
73 u16text = g_new0(gunichar2, n + 1);
74 for(i = 0; i < n; i ++) {
75 u16text[i] = g3d_stream_read_int16_le(stream);
76 }
77
78 text = g_utf16_to_utf8(u16text, n, NULL, NULL, &error);
79 if(error != NULL) {
80 g_warning("UTF-16 to UTF-8 conversion failed: %s",
81 error->message);
82 g_error_free(error);
83 }
84 g_free(u16text);
85
86 return text;
87}
88
89gboolean skp_read_dbl3(G3DStream *stream,
90 gdouble *d1, gdouble *d2, gdouble *d3)
91{
92 *d1 = g3d_stream_read_double_le(stream);
93 *d2 = g3d_stream_read_double_le(stream);
94 *d3 = g3d_stream_read_double_le(stream);
95 return TRUE;
96}
97
98gboolean skp_read_10b(G3DStream *stream)
99{
100 guint32 x1, x2;
101 guint8 u1, u2;
102
103 x1 = g3d_stream_read_int32_be(stream);
104 u1 = g3d_stream_read_int8(stream);
105
106 if(((x1 & 0x00FFFFFF) != 0x0001) || (u1 != 0x01)) {
107 g_warning("skp_read_10b: %#08x, %#02x", x1, u1);
108 }
109 u2 = g3d_stream_read_int8(stream);
110 x2 = g3d_stream_read_int32_le(stream);
111 g_debug("\tread 10b: %08x %02x %02x %08x", x1, u1, u2, x2);
112 return TRUE;
113}
114