zenilib  0.5.3.0
 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
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
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
63  c->cur = lib3ds_io_tell(io);
64 }
65 
66 
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
92 }
93 
94 
95 void
97  ((Lib3dsIoImpl*)io->impl)->log_indent--;
99 }
100 
101 
110 void
112  assert(c);
113  lib3ds_io_write_word(io, c->chunk);
114  lib3ds_io_write_dword(io, c->size);
115 }
116 
117 
118 void
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
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;
136 }
137 
138 
139 void
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 
else Out of place iCCP chunk
Definition: pngrutil.c:1260
const char * lib3ds_chunk_name(uint16_t chunk)
unsigned short uint16_t
uint32_t cur
Definition: lib3ds_impl.h:299
void lib3ds_chunk_unknown(uint16_t chunk, Lib3dsIo *io)
Definition: lib3ds_chunk.c:140
void lib3ds_chunk_read(Lib3dsChunk *c, Lib3dsIo *io)
Definition: lib3ds_chunk.c:34
return Display return Display Bool Bool int d
Definition: SDL_x11sym.h:30
#define assert(x)
Definition: SDL_malloc.c:1234
uint32_t lib3ds_io_read_dword(Lib3dsIo *io)
Definition: lib3ds_io.c:172
uint32_t size
Definition: lib3ds_impl.h:297
uint16_t lib3ds_chunk_read_next(Lib3dsChunk *c, Lib3dsIo *io)
Definition: lib3ds_chunk.c:68
void lib3ds_chunk_write_start(Lib3dsChunk *c, Lib3dsIo *io)
Definition: lib3ds_chunk.c:119
long lib3ds_io_tell(Lib3dsIo *io)
Definition: lib3ds_io.c:62
void lib3ds_chunk_read_reset(Lib3dsChunk *c, Lib3dsIo *io)
Definition: lib3ds_chunk.c:90
uint32_t end
Definition: lib3ds_impl.h:298
const GLfloat * c
Definition: glew.h:14913
uint16_t lib3ds_io_read_word(Lib3dsIo *io)
Definition: lib3ds_io.c:156
void lib3ds_chunk_read_end(Lib3dsChunk *c, Lib3dsIo *io)
Definition: lib3ds_chunk.c:96
void lib3ds_chunk_read_tell(Lib3dsChunk *c, Lib3dsIo *io)
Definition: lib3ds_chunk.c:62
void(* log_func)(void *self, Lib3dsLogLevel level, int indent, const char *msg)
Definition: lib3ds.h:63
void lib3ds_io_log(Lib3dsIo *io, Lib3dsLogLevel level, const char *format,...)
Definition: lib3ds_io.c:100
void lib3ds_chunk_write(Lib3dsChunk *c, Lib3dsIo *io)
Definition: lib3ds_chunk.c:111
void lib3ds_chunk_read_start(Lib3dsChunk *c, uint16_t chunk, Lib3dsIo *io)
Definition: lib3ds_chunk.c:50
void * impl
Definition: lib3ds.h:57
long lib3ds_io_seek(Lib3dsIo *io, long offset, Lib3dsIoSeek origin)
Definition: lib3ds_io.c:52
uint16_t chunk
Definition: lib3ds_impl.h:296
void lib3ds_io_write_dword(Lib3dsIo *io, uint32_t d)
Definition: lib3ds_io.c:338
void lib3ds_chunk_write_end(Lib3dsChunk *c, Lib3dsIo *io)
Definition: lib3ds_chunk.c:129
void lib3ds_io_write_word(Lib3dsIo *io, uint16_t w)
Definition: lib3ds_io.c:322