zenilib: zenilib/jni/external/lib3ds/src/lib3ds_chunk.c Source File

zenilib 0.5.3.0

- Main Page
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
lib3ds_chunk.c
Go to the documentation of this file.
1 /*
2 Copyright (C) 1996-2008 by Jan Eric Kyprianidis <www.kyprianidis.com>
3 All rights reserved.
4
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published
7 by the Free Software Foundation, either version 2.1 of the License, or
8 (at your option) any later version.
9
10 Thisprogram is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public License
16 along with this program; If not, see <http://www.gnu.org/licenses/>.
17 */
18 #include "lib3ds_impl.h"
19
20
21 /*#define LIB3DS_CHUNK_DEBUG*/
22 /*#define LIB3DS_CHUNK_WARNING*/
23
24
33 void
34 lib3ds_chunk_read(Lib3dsChunk *c, Lib3dsIo *io) {
35 assert(c);
36 assert(io);
37 c->cur = lib3ds_io_tell(io);
38 c->chunk = lib3ds_io_read_word(io);
39 c->size = lib3ds_io_read_dword(io);
40 c->end = c->cur + c->size;
41 c->cur += 6;
42 if (c->size < 6) {
43 lib3ds_io_log(io, LIB3DS_LOG_ERROR, "Invalid chunk header.");
44 }
45
46 }
47
48
49 void
50 lib3ds_chunk_read_start(Lib3dsChunk *c, uint16_t chunk, Lib3dsIo *io) {
51 assert(c);
52 assert(io);
53 lib3ds_chunk_read(c, io);
54 if ((chunk != 0) && (c->chunk != chunk)) {
55 lib3ds_io_log(io, LIB3DS_LOG_ERROR, "Unexpected chunk found.");
56 }
57 ((Lib3dsIoImpl*)io->impl)->log_indent++;
58 }
59
60
61 void
62 lib3ds_chunk_read_tell(Lib3dsChunk *c, Lib3dsIo *io) {
63 c->cur = lib3ds_io_tell(io);
64 }
65
66
67 uint16_t
68 lib3ds_chunk_read_next(Lib3dsChunk *c, Lib3dsIo *io) {
69 Lib3dsChunk d;
70
71 if (c->cur >= c->end) {
72 assert(c->cur == c->end);
73 return 0;
74 }
75
76 lib3ds_io_seek(io, (long)c->cur, LIB3DS_SEEK_SET);
77 d.chunk = lib3ds_io_read_word(io);
78 d.size = lib3ds_io_read_dword(io);
79 c->cur += d.size;
80
81 if (io->log_func) {
82 lib3ds_io_log(io, LIB3DS_LOG_INFO, "%s (0x%X) size=%lu", lib3ds_chunk_name(d.chunk), d.chunk, d.size);
83 }
84
85 return d.chunk;
86 }
87
88
89 void
90 lib3ds_chunk_read_reset(Lib3dsChunk *c, Lib3dsIo *io) {
91 lib3ds_io_seek(io, -6, LIB3DS_SEEK_CUR);
92 }
93
94
95 void
96 lib3ds_chunk_read_end(Lib3dsChunk *c, Lib3dsIo *io) {
97 ((Lib3dsIoImpl*)io->impl)->log_indent--;
98 lib3ds_io_seek(io, c->end, LIB3DS_SEEK_SET);
99 }
100
101
110 void
111 lib3ds_chunk_write(Lib3dsChunk *c, Lib3dsIo *io) {
112 assert(c);
113 lib3ds_io_write_word(io, c->chunk);
114 lib3ds_io_write_dword(io, c->size);
115 }
116
117
118 void
119 lib3ds_chunk_write_start(Lib3dsChunk *c, Lib3dsIo *io) {
120 assert(c);
121 c->size = 0;
122 c->cur = lib3ds_io_tell(io);
123 lib3ds_io_write_word(io, c->chunk);
124 lib3ds_io_write_dword(io, c->size);
125 }
126
127
128 void
129 lib3ds_chunk_write_end(Lib3dsChunk *c, Lib3dsIo *io) {
130 assert(c);
131 c->size = lib3ds_io_tell(io) - c->cur;
132 lib3ds_io_seek(io, c->cur + 2, LIB3DS_SEEK_SET);
133 lib3ds_io_write_dword(io, c->size);
134 c->cur += c->size;
135 lib3ds_io_seek(io, c->cur, LIB3DS_SEEK_SET);
136 }
137
138
139 void
140 lib3ds_chunk_unknown(uint16_t chunk, Lib3dsIo *io) {
141 if (io->log_func) {
142 lib3ds_io_log(io, LIB3DS_LOG_WARN, "Unknown Chunk: %s (0x%X)", lib3ds_chunk_name(chunk), chunk);
143 }
144 }
145
146
LIB3DS_SEEK_CUR
Definition: lib3ds.h:45
chunk
else Out of place iCCP chunk
Definition: pngrutil.c:1260
lib3ds_chunk_name
const char * lib3ds_chunk_name(uint16_t chunk)
Definition: lib3ds_chunktable.c:250
Lib3dsChunk
Definition: lib3ds_impl.h:295
uint16_t
unsigned short uint16_t
Definition: SDL_config_windows.h:60
Lib3dsChunk::cur
uint32_t cur
Definition: lib3ds_impl.h:299
lib3ds_chunk_unknown
void lib3ds_chunk_unknown(uint16_t chunk, Lib3dsIo *io)
Definition: lib3ds_chunk.c:140
lib3ds_chunk_read
void lib3ds_chunk_read(Lib3dsChunk *c, Lib3dsIo *io)
Definition: lib3ds_chunk.c:34
d
return Display return Display Bool Bool int d
Definition: SDL_x11sym.h:30
assert
#define assert(x)
Definition: SDL_malloc.c:1234
lib3ds_io_read_dword
uint32_t lib3ds_io_read_dword(Lib3dsIo *io)
Definition: lib3ds_io.c:172
Lib3dsChunk::size
uint32_t size
Definition: lib3ds_impl.h:297
lib3ds_chunk_read_next
uint16_t lib3ds_chunk_read_next(Lib3dsChunk *c, Lib3dsIo *io)
Definition: lib3ds_chunk.c:68
LIB3DS_LOG_INFO
Definition: lib3ds.h:52
lib3ds_chunk_write_start
void lib3ds_chunk_write_start(Lib3dsChunk *c, Lib3dsIo *io)
Definition: lib3ds_chunk.c:119
lib3ds_io_tell
long lib3ds_io_tell(Lib3dsIo *io)
Definition: lib3ds_io.c:62
lib3ds_chunk_read_reset
void lib3ds_chunk_read_reset(Lib3dsChunk *c, Lib3dsIo *io)
Definition: lib3ds_chunk.c:90
Lib3dsChunk::end
uint32_t end
Definition: lib3ds_impl.h:298
c
const GLfloat * c
Definition: glew.h:14913
lib3ds_io_read_word
uint16_t lib3ds_io_read_word(Lib3dsIo *io)
Definition: lib3ds_io.c:156
lib3ds_chunk_read_end
void lib3ds_chunk_read_end(Lib3dsChunk *c, Lib3dsIo *io)
Definition: lib3ds_chunk.c:96
lib3ds_chunk_read_tell
void lib3ds_chunk_read_tell(Lib3dsChunk *c, Lib3dsIo *io)
Definition: lib3ds_chunk.c:62
Lib3dsIo::log_func
void(* log_func)(void *self, Lib3dsLogLevel level, int indent, const char *msg)
Definition: lib3ds.h:63
Lib3dsIo
Definition: lib3ds.h:56
LIB3DS_SEEK_SET
Definition: lib3ds.h:44
lib3ds_io_log
void lib3ds_io_log(Lib3dsIo *io, Lib3dsLogLevel level, const char *format,...)
Definition: lib3ds_io.c:100
lib3ds_chunk_write
void lib3ds_chunk_write(Lib3dsChunk *c, Lib3dsIo *io)
Definition: lib3ds_chunk.c:111
lib3ds_chunk_read_start
void lib3ds_chunk_read_start(Lib3dsChunk *c, uint16_t chunk, Lib3dsIo *io)
Definition: lib3ds_chunk.c:50
Lib3dsIo::impl
void * impl
Definition: lib3ds.h:57
Lib3dsIoImpl
Definition: lib3ds_impl.h:314
lib3ds_io_seek
long lib3ds_io_seek(Lib3dsIo *io, long offset, Lib3dsIoSeek origin)
Definition: lib3ds_io.c:52
Lib3dsChunk::chunk
uint16_t chunk
Definition: lib3ds_impl.h:296
lib3ds_io_write_dword
void lib3ds_io_write_dword(Lib3dsIo *io, uint32_t d)
Definition: lib3ds_io.c:338
LIB3DS_LOG_WARN
Definition: lib3ds.h:51
lib3ds_impl.h
lib3ds_chunk_write_end
void lib3ds_chunk_write_end(Lib3dsChunk *c, Lib3dsIo *io)
Definition: lib3ds_chunk.c:129
LIB3DS_LOG_ERROR
Definition: lib3ds.h:50
lib3ds_io_write_word
void lib3ds_io_write_word(Lib3dsIo *io, uint16_t w)
Definition: lib3ds_io.c:322