Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(50)

Side by Side Diff: core/src/fxcodec/lgif/fx_gif.cpp

Issue 1739623002: Rename some functions that start with underscore. (Closed) Base URL: https://pdfium.googlesource.com/pdfium@master
Patch Set: Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 PDFium Authors. All rights reserved. 1 // Copyright 2014 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6 6
7 #include "core/src/fxcodec/lgif/fx_gif.h" 7 #include "core/src/fxcodec/lgif/fx_gif.h"
8
9 #include "core/src/fxcodec/lbmp/fx_bmp.h"
10
8 void CGifLZWDecoder::Input(uint8_t* src_buf, FX_DWORD src_size) { 11 void CGifLZWDecoder::Input(uint8_t* src_buf, FX_DWORD src_size) {
9 next_in = src_buf; 12 next_in = src_buf;
10 avail_in = src_size; 13 avail_in = src_size;
11 } 14 }
12 FX_DWORD CGifLZWDecoder::GetAvailInput() { 15 FX_DWORD CGifLZWDecoder::GetAvailInput() {
13 return avail_in; 16 return avail_in;
14 } 17 }
15 void CGifLZWDecoder::InitTable(uint8_t code_len) { 18 void CGifLZWDecoder::InitTable(uint8_t code_len) {
16 code_size = code_len; 19 code_size = code_len;
17 code_clear = 1 << code_size; 20 code_clear = 1 << code_size;
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 stack_size = 0; 137 stack_size = 0;
135 } 138 }
136 } 139 }
137 } 140 }
138 if (avail_in == 0) { 141 if (avail_in == 0) {
139 des_size = i; 142 des_size = i;
140 return 2; 143 return 2;
141 } 144 }
142 return 0; 145 return 0;
143 } 146 }
144 static FX_BOOL _gif_grow_buf(uint8_t*& dst_buf, 147 static FX_BOOL gif_grow_buf(uint8_t*& dst_buf,
145 FX_DWORD& dst_len, 148 FX_DWORD& dst_len,
146 FX_DWORD size) { 149 FX_DWORD size) {
147 if (dst_len < size) { 150 if (dst_len < size) {
148 FX_DWORD len_org = dst_len; 151 FX_DWORD len_org = dst_len;
149 while (dst_buf && dst_len < size) { 152 while (dst_buf && dst_len < size) {
150 dst_len <<= 1; 153 dst_len <<= 1;
151 dst_buf = FX_Realloc(uint8_t, dst_buf, dst_len); 154 dst_buf = FX_Realloc(uint8_t, dst_buf, dst_len);
152 } 155 }
153 if (dst_buf == NULL) { 156 if (dst_buf == NULL) {
154 dst_len = size; 157 dst_len = size;
155 dst_buf = FX_Realloc(uint8_t, dst_buf, dst_len); 158 dst_buf = FX_Realloc(uint8_t, dst_buf, dst_len);
156 if (dst_buf == NULL) { 159 if (dst_buf == NULL) {
157 return FALSE; 160 return FALSE;
158 } 161 }
159 } 162 }
160 FXSYS_memset(dst_buf + len_org, 0, dst_len - len_org); 163 FXSYS_memset(dst_buf + len_org, 0, dst_len - len_org);
161 return dst_buf != NULL; 164 return dst_buf != NULL;
162 } 165 }
163 return TRUE; 166 return TRUE;
164 } 167 }
165 static inline void _gif_cut_index(uint8_t& val, 168 static inline void gif_cut_index(uint8_t& val,
166 FX_DWORD index, 169 FX_DWORD index,
167 uint8_t index_bit, 170 uint8_t index_bit,
168 uint8_t index_bit_use, 171 uint8_t index_bit_use,
169 uint8_t bit_use) { 172 uint8_t bit_use) {
170 FX_DWORD cut = ((1 << (index_bit - index_bit_use)) - 1) << index_bit_use; 173 FX_DWORD cut = ((1 << (index_bit - index_bit_use)) - 1) << index_bit_use;
171 val |= ((index & cut) >> index_bit_use) << bit_use; 174 val |= ((index & cut) >> index_bit_use) << bit_use;
172 } 175 }
173 static inline uint8_t _gif_cut_buf(const uint8_t* buf, 176 static inline uint8_t gif_cut_buf(const uint8_t* buf,
174 FX_DWORD& offset, 177 FX_DWORD& offset,
175 uint8_t bit_cut, 178 uint8_t bit_cut,
176 uint8_t& bit_offset, 179 uint8_t& bit_offset,
177 FX_DWORD& bit_num) { 180 FX_DWORD& bit_num) {
178 if (bit_cut != 8) { 181 if (bit_cut != 8) {
179 FX_WORD index = 0; 182 FX_WORD index = 0;
180 index |= ((1 << bit_cut) - 1) << (7 - bit_offset); 183 index |= ((1 << bit_cut) - 1) << (7 - bit_offset);
181 uint8_t ret = ((index & buf[offset]) >> (7 - bit_offset)); 184 uint8_t ret = ((index & buf[offset]) >> (7 - bit_offset));
182 bit_offset += bit_cut; 185 bit_offset += bit_cut;
183 if (bit_offset >= 8) { 186 if (bit_offset >= 8) {
184 if (bit_offset > 8) { 187 if (bit_offset > 8) {
185 ret |= ((index & (buf[offset + 1] << 8)) >> 8); 188 ret |= ((index & (buf[offset + 1] << 8)) >> 8);
186 } 189 }
187 bit_offset -= 8; 190 bit_offset -= 8;
(...skipping 29 matching lines...) Expand all
217 code_size = 2; 220 code_size = 2;
218 } 221 }
219 code_clear = 1 << code_size; 222 code_clear = 1 << code_size;
220 code_end = code_clear + 1; 223 code_end = code_clear + 1;
221 dst_buf[offset++] = code_size; 224 dst_buf[offset++] = code_size;
222 bit_offset = 0; 225 bit_offset = 0;
223 ClearTable(); 226 ClearTable();
224 src_offset = 0; 227 src_offset = 0;
225 src_bit_offset = 0; 228 src_bit_offset = 0;
226 src_bit_num = 0; 229 src_bit_num = 0;
227 code_table[index_num].prefix = _gif_cut_buf(src_buf, src_offset, src_bit_cut, 230 code_table[index_num].prefix = gif_cut_buf(src_buf, src_offset, src_bit_cut,
228 src_bit_offset, src_bit_num); 231 src_bit_offset, src_bit_num);
229 code_table[index_num].suffix = _gif_cut_buf(src_buf, src_offset, src_bit_cut, 232 code_table[index_num].suffix = gif_cut_buf(src_buf, src_offset, src_bit_cut,
230 src_bit_offset, src_bit_num); 233 src_bit_offset, src_bit_num);
231 } 234 }
232 void CGifLZWEncoder::WriteBlock(uint8_t*& dst_buf, 235 void CGifLZWEncoder::WriteBlock(uint8_t*& dst_buf,
233 FX_DWORD& dst_len, 236 FX_DWORD& dst_len,
234 FX_DWORD& offset) { 237 FX_DWORD& offset) {
235 if (!_gif_grow_buf(dst_buf, dst_len, offset + GIF_DATA_BLOCK + 1)) { 238 if (!gif_grow_buf(dst_buf, dst_len, offset + GIF_DATA_BLOCK + 1)) {
236 longjmp(jmp, 1); 239 longjmp(jmp, 1);
237 } 240 }
238 dst_buf[offset++] = index_buf_len; 241 dst_buf[offset++] = index_buf_len;
239 FXSYS_memcpy(&dst_buf[offset], index_buf, index_buf_len); 242 FXSYS_memcpy(&dst_buf[offset], index_buf, index_buf_len);
240 offset += index_buf_len; 243 offset += index_buf_len;
241 FXSYS_memset(index_buf, 0, GIF_DATA_BLOCK); 244 FXSYS_memset(index_buf, 0, GIF_DATA_BLOCK);
242 index_buf_len = 0; 245 index_buf_len = 0;
243 } 246 }
244 void CGifLZWEncoder::EncodeString(FX_DWORD index, 247 void CGifLZWEncoder::EncodeString(FX_DWORD index,
245 uint8_t*& dst_buf, 248 uint8_t*& dst_buf,
246 FX_DWORD& dst_len, 249 FX_DWORD& dst_len,
247 FX_DWORD& offset) { 250 FX_DWORD& offset) {
248 uint8_t index_bit_use; 251 uint8_t index_bit_use;
249 index_bit_use = 0; 252 index_bit_use = 0;
250 if (index_buf_len == GIF_DATA_BLOCK) { 253 if (index_buf_len == GIF_DATA_BLOCK) {
251 WriteBlock(dst_buf, dst_len, offset); 254 WriteBlock(dst_buf, dst_len, offset);
252 } 255 }
253 _gif_cut_index(index_buf[index_buf_len], index, index_bit_cur, index_bit_use, 256 gif_cut_index(index_buf[index_buf_len], index, index_bit_cur, index_bit_use,
254 bit_offset); 257 bit_offset);
255 if (index_bit_cur <= (8 - bit_offset)) { 258 if (index_bit_cur <= (8 - bit_offset)) {
256 bit_offset += index_bit_cur; 259 bit_offset += index_bit_cur;
257 } else if (index_bit_cur <= (16 - bit_offset)) { 260 } else if (index_bit_cur <= (16 - bit_offset)) {
258 index_bit_use += (8 - bit_offset); 261 index_bit_use += (8 - bit_offset);
259 bit_offset = 0; 262 bit_offset = 0;
260 index_buf_len++; 263 index_buf_len++;
261 if (index_buf_len == GIF_DATA_BLOCK) { 264 if (index_buf_len == GIF_DATA_BLOCK) {
262 WriteBlock(dst_buf, dst_len, offset); 265 WriteBlock(dst_buf, dst_len, offset);
263 } 266 }
264 _gif_cut_index(index_buf[index_buf_len], index, index_bit_cur, 267 gif_cut_index(index_buf[index_buf_len], index, index_bit_cur, index_bit_use,
265 index_bit_use, bit_offset); 268 bit_offset);
266 bit_offset = index_bit_cur - index_bit_use; 269 bit_offset = index_bit_cur - index_bit_use;
267 } else { 270 } else {
268 index_bit_use += (8 - bit_offset); 271 index_bit_use += (8 - bit_offset);
269 bit_offset = 0; 272 bit_offset = 0;
270 index_buf_len++; 273 index_buf_len++;
271 if (index_buf_len == GIF_DATA_BLOCK) { 274 if (index_buf_len == GIF_DATA_BLOCK) {
272 WriteBlock(dst_buf, dst_len, offset); 275 WriteBlock(dst_buf, dst_len, offset);
273 } 276 }
274 _gif_cut_index(index_buf[index_buf_len], index, index_bit_cur, 277 gif_cut_index(index_buf[index_buf_len], index, index_bit_cur, index_bit_use,
275 index_bit_use, bit_offset); 278 bit_offset);
276 index_bit_use += 8; 279 index_bit_use += 8;
277 bit_offset = 0; 280 bit_offset = 0;
278 index_buf_len++; 281 index_buf_len++;
279 if (index_buf_len == GIF_DATA_BLOCK) { 282 if (index_buf_len == GIF_DATA_BLOCK) {
280 WriteBlock(dst_buf, dst_len, offset); 283 WriteBlock(dst_buf, dst_len, offset);
281 } 284 }
282 _gif_cut_index(index_buf[index_buf_len], index, index_bit_cur, 285 gif_cut_index(index_buf[index_buf_len], index, index_bit_cur, index_bit_use,
283 index_bit_use, bit_offset); 286 bit_offset);
284 bit_offset = index_bit_cur - index_bit_use; 287 bit_offset = index_bit_cur - index_bit_use;
285 } 288 }
286 if (bit_offset == 8) { 289 if (bit_offset == 8) {
287 bit_offset = 0; 290 bit_offset = 0;
288 index_buf_len++; 291 index_buf_len++;
289 if (index_buf_len == GIF_DATA_BLOCK) { 292 if (index_buf_len == GIF_DATA_BLOCK) {
290 WriteBlock(dst_buf, dst_len, offset); 293 WriteBlock(dst_buf, dst_len, offset);
291 } 294 }
292 } 295 }
293 if (index == code_end) { 296 if (index == code_end) {
(...skipping 14 matching lines...) Expand all
308 return FALSE; 311 return FALSE;
309 } 312 }
310 while (src_bit_num < src_len) { 313 while (src_bit_num < src_len) {
311 if (!LookUpInTable(src_buf, src_offset, src_bit_offset)) { 314 if (!LookUpInTable(src_buf, src_offset, src_bit_offset)) {
312 EncodeString(code_table[index_num].prefix, dst_buf, dst_len, offset); 315 EncodeString(code_table[index_num].prefix, dst_buf, dst_len, offset);
313 if (index_num == GIF_MAX_LZW_CODE) { 316 if (index_num == GIF_MAX_LZW_CODE) {
314 suffix = code_table[index_num - 1].suffix; 317 suffix = code_table[index_num - 1].suffix;
315 EncodeString(code_clear, dst_buf, dst_len, offset); 318 EncodeString(code_clear, dst_buf, dst_len, offset);
316 ClearTable(); 319 ClearTable();
317 code_table[index_num].prefix = suffix; 320 code_table[index_num].prefix = suffix;
318 code_table[index_num].suffix = _gif_cut_buf( 321 code_table[index_num].suffix = gif_cut_buf(
319 src_buf, src_offset, src_bit_cut, src_bit_offset, src_bit_num); 322 src_buf, src_offset, src_bit_cut, src_bit_offset, src_bit_num);
320 } else { 323 } else {
321 code_table[index_num].prefix = code_table[index_num - 1].suffix; 324 code_table[index_num].prefix = code_table[index_num - 1].suffix;
322 code_table[index_num].suffix = _gif_cut_buf( 325 code_table[index_num].suffix = gif_cut_buf(
323 src_buf, src_offset, src_bit_cut, src_bit_offset, src_bit_num); 326 src_buf, src_offset, src_bit_cut, src_bit_offset, src_bit_num);
324 } 327 }
325 } 328 }
326 } 329 }
327 src_offset = 0; 330 src_offset = 0;
328 src_bit_offset = 0; 331 src_bit_offset = 0;
329 src_bit_num = 0; 332 src_bit_num = 0;
330 return TRUE; 333 return TRUE;
331 } 334 }
332 FX_BOOL CGifLZWEncoder::LookUpInTable(const uint8_t* buf, 335 FX_BOOL CGifLZWEncoder::LookUpInTable(const uint8_t* buf,
333 FX_DWORD& offset, 336 FX_DWORD& offset,
334 uint8_t& bit_offset) { 337 uint8_t& bit_offset) {
335 for (FX_WORD i = table_cur; i < index_num; i++) { 338 for (FX_WORD i = table_cur; i < index_num; i++) {
336 if (code_table[i].prefix == code_table[index_num].prefix && 339 if (code_table[i].prefix == code_table[index_num].prefix &&
337 code_table[i].suffix == code_table[index_num].suffix) { 340 code_table[i].suffix == code_table[index_num].suffix) {
338 code_table[index_num].prefix = i; 341 code_table[index_num].prefix = i;
339 code_table[index_num].suffix = 342 code_table[index_num].suffix =
340 _gif_cut_buf(buf, offset, src_bit_cut, bit_offset, src_bit_num); 343 gif_cut_buf(buf, offset, src_bit_cut, bit_offset, src_bit_num);
341 table_cur = i; 344 table_cur = i;
342 return TRUE; 345 return TRUE;
343 } 346 }
344 } 347 }
345 table_cur = code_end + 1; 348 table_cur = code_end + 1;
346 return FALSE; 349 return FALSE;
347 } 350 }
348 void CGifLZWEncoder::Finish(uint8_t*& dst_buf, 351 void CGifLZWEncoder::Finish(uint8_t*& dst_buf,
349 FX_DWORD& dst_len, 352 FX_DWORD& dst_len,
350 FX_DWORD& offset) { 353 FX_DWORD& offset) {
351 EncodeString(code_table[index_num].prefix, dst_buf, dst_len, offset); 354 EncodeString(code_table[index_num].prefix, dst_buf, dst_len, offset);
352 EncodeString(code_end, dst_buf, dst_len, offset); 355 EncodeString(code_end, dst_buf, dst_len, offset);
353 bit_offset = 0; 356 bit_offset = 0;
354 ClearTable(); 357 ClearTable();
355 } 358 }
356 gif_decompress_struct_p _gif_create_decompress() { 359 gif_decompress_struct_p gif_create_decompress() {
357 gif_decompress_struct_p gif_ptr = 360 gif_decompress_struct_p gif_ptr =
358 (gif_decompress_struct*)FX_Alloc(uint8_t, sizeof(gif_decompress_struct)); 361 (gif_decompress_struct*)FX_Alloc(uint8_t, sizeof(gif_decompress_struct));
359 if (gif_ptr == NULL) { 362 if (gif_ptr == NULL) {
360 return NULL; 363 return NULL;
361 } 364 }
362 FXSYS_memset(gif_ptr, 0, sizeof(gif_decompress_struct)); 365 FXSYS_memset(gif_ptr, 0, sizeof(gif_decompress_struct));
363 gif_ptr->decode_status = GIF_D_STATUS_SIG; 366 gif_ptr->decode_status = GIF_D_STATUS_SIG;
364 gif_ptr->img_ptr_arr_ptr = new CFX_ArrayTemplate<GifImage*>; 367 gif_ptr->img_ptr_arr_ptr = new CFX_ArrayTemplate<GifImage*>;
365 #ifdef GIF_SUPPORT_COMMENT_EXTENSION 368 #ifdef GIF_SUPPORT_COMMENT_EXTENSION
366 gif_ptr->cmt_data_ptr = new CFX_ByteString; 369 gif_ptr->cmt_data_ptr = new CFX_ByteString;
367 #endif 370 #endif
368 #ifdef GIF_SUPPORT_PLAIN_TEXT_EXTENSION 371 #ifdef GIF_SUPPORT_PLAIN_TEXT_EXTENSION
369 gif_ptr->pt_ptr_arr_ptr = new CFX_ArrayTemplate<GifPlainText*>; 372 gif_ptr->pt_ptr_arr_ptr = new CFX_ArrayTemplate<GifPlainText*>;
370 #endif 373 #endif
371 return gif_ptr; 374 return gif_ptr;
372 } 375 }
373 void _gif_destroy_decompress(gif_decompress_struct_pp gif_ptr_ptr) { 376 void gif_destroy_decompress(gif_decompress_struct_pp gif_ptr_ptr) {
374 if (gif_ptr_ptr == NULL || *gif_ptr_ptr == NULL) { 377 if (gif_ptr_ptr == NULL || *gif_ptr_ptr == NULL) {
375 return; 378 return;
376 } 379 }
377 gif_decompress_struct_p gif_ptr = *gif_ptr_ptr; 380 gif_decompress_struct_p gif_ptr = *gif_ptr_ptr;
378 *gif_ptr_ptr = NULL; 381 *gif_ptr_ptr = NULL;
379 FX_Free(gif_ptr->global_pal_ptr); 382 FX_Free(gif_ptr->global_pal_ptr);
380 delete gif_ptr->img_decoder_ptr; 383 delete gif_ptr->img_decoder_ptr;
381 if (gif_ptr->img_ptr_arr_ptr) { 384 if (gif_ptr->img_ptr_arr_ptr) {
382 int32_t size_img_arr = gif_ptr->img_ptr_arr_ptr->GetSize(); 385 int32_t size_img_arr = gif_ptr->img_ptr_arr_ptr->GetSize();
383 for (int32_t i = 0; i < size_img_arr; i++) { 386 for (int32_t i = 0; i < size_img_arr; i++) {
(...skipping 26 matching lines...) Expand all
410 FX_Free(p->gce_ptr); 413 FX_Free(p->gce_ptr);
411 FX_Free(p->pte_ptr); 414 FX_Free(p->pte_ptr);
412 delete p->string_ptr; 415 delete p->string_ptr;
413 } 416 }
414 gif_ptr->pt_ptr_arr_ptr->RemoveAll(); 417 gif_ptr->pt_ptr_arr_ptr->RemoveAll();
415 delete gif_ptr->pt_ptr_arr_ptr; 418 delete gif_ptr->pt_ptr_arr_ptr;
416 } 419 }
417 #endif 420 #endif
418 FX_Free(gif_ptr); 421 FX_Free(gif_ptr);
419 } 422 }
420 gif_compress_struct_p _gif_create_compress() { 423 gif_compress_struct_p gif_create_compress() {
421 gif_compress_struct_p gif_ptr = 424 gif_compress_struct_p gif_ptr =
422 (gif_compress_struct*)FX_Alloc(uint8_t, sizeof(gif_compress_struct)); 425 (gif_compress_struct*)FX_Alloc(uint8_t, sizeof(gif_compress_struct));
423 if (gif_ptr == NULL) { 426 if (gif_ptr == NULL) {
424 return NULL; 427 return NULL;
425 } 428 }
426 FXSYS_memset(gif_ptr, 0, sizeof(gif_compress_struct)); 429 FXSYS_memset(gif_ptr, 0, sizeof(gif_compress_struct));
427 gif_ptr->img_encoder_ptr = new CGifLZWEncoder; 430 gif_ptr->img_encoder_ptr = new CGifLZWEncoder;
428 gif_ptr->header_ptr = (GifHeader*)FX_Alloc(uint8_t, sizeof(GifHeader)); 431 gif_ptr->header_ptr = (GifHeader*)FX_Alloc(uint8_t, sizeof(GifHeader));
429 if (gif_ptr->header_ptr == NULL) { 432 if (gif_ptr->header_ptr == NULL) {
430 delete (gif_ptr->img_encoder_ptr); 433 delete (gif_ptr->img_encoder_ptr);
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
475 FX_Free(gif_ptr->header_ptr); 478 FX_Free(gif_ptr->header_ptr);
476 delete (gif_ptr->img_encoder_ptr); 479 delete (gif_ptr->img_encoder_ptr);
477 FX_Free(gif_ptr); 480 FX_Free(gif_ptr);
478 return NULL; 481 return NULL;
479 } 482 }
480 FXSYS_memset(gif_ptr->pte_ptr, 0, sizeof(GifPTE)); 483 FXSYS_memset(gif_ptr->pte_ptr, 0, sizeof(GifPTE));
481 gif_ptr->pte_ptr->block_size = 12; 484 gif_ptr->pte_ptr->block_size = 12;
482 #endif 485 #endif
483 return gif_ptr; 486 return gif_ptr;
484 } 487 }
485 void _gif_destroy_compress(gif_compress_struct_pp gif_ptr_ptr) { 488 void gif_destroy_compress(gif_compress_struct_pp gif_ptr_ptr) {
486 if (gif_ptr_ptr == NULL || *gif_ptr_ptr == NULL) { 489 if (gif_ptr_ptr == NULL || *gif_ptr_ptr == NULL) {
487 return; 490 return;
488 } 491 }
489 gif_compress_struct_p gif_ptr = *gif_ptr_ptr; 492 gif_compress_struct_p gif_ptr = *gif_ptr_ptr;
490 *gif_ptr_ptr = NULL; 493 *gif_ptr_ptr = NULL;
491 FX_Free(gif_ptr->header_ptr); 494 FX_Free(gif_ptr->header_ptr);
492 FX_Free(gif_ptr->lsd_ptr); 495 FX_Free(gif_ptr->lsd_ptr);
493 FX_Free(gif_ptr->global_pal); 496 FX_Free(gif_ptr->global_pal);
494 FX_Free(gif_ptr->image_info_ptr); 497 FX_Free(gif_ptr->image_info_ptr);
495 FX_Free(gif_ptr->local_pal); 498 FX_Free(gif_ptr->local_pal);
496 delete gif_ptr->img_encoder_ptr; 499 delete gif_ptr->img_encoder_ptr;
497 #ifdef GIF_SUPPORT_APPLICATION_EXTENSION 500 #ifdef GIF_SUPPORT_APPLICATION_EXTENSION
498 FX_Free(gif_ptr->app_data); 501 FX_Free(gif_ptr->app_data);
499 #endif 502 #endif
500 #ifdef GIF_SUPPORT_GRAPHIC_CONTROL_EXTENSION 503 #ifdef GIF_SUPPORT_GRAPHIC_CONTROL_EXTENSION
501 FX_Free(gif_ptr->gce_ptr); 504 FX_Free(gif_ptr->gce_ptr);
502 #endif 505 #endif
503 #ifdef GIF_SUPPORT_COMMENT_EXTENSION 506 #ifdef GIF_SUPPORT_COMMENT_EXTENSION
504 FX_Free(gif_ptr->cmt_data_ptr); 507 FX_Free(gif_ptr->cmt_data_ptr);
505 #endif 508 #endif
506 #ifdef GIF_SUPPORT_PLAIN_TEXT_EXTENSION 509 #ifdef GIF_SUPPORT_PLAIN_TEXT_EXTENSION
507 FX_Free(gif_ptr->pte_ptr); 510 FX_Free(gif_ptr->pte_ptr);
508 #endif 511 #endif
509 FX_Free(gif_ptr); 512 FX_Free(gif_ptr);
510 } 513 }
511 void _gif_error(gif_decompress_struct_p gif_ptr, const FX_CHAR* err_msg) { 514 void gif_error(gif_decompress_struct_p gif_ptr, const FX_CHAR* err_msg) {
512 if (gif_ptr && gif_ptr->_gif_error_fn) { 515 if (gif_ptr && gif_ptr->_gif_error_fn) {
513 gif_ptr->_gif_error_fn(gif_ptr, err_msg); 516 gif_ptr->_gif_error_fn(gif_ptr, err_msg);
514 } 517 }
515 } 518 }
516 void _gif_warn(gif_decompress_struct_p gif_ptr, const FX_CHAR* err_msg) {} 519 void gif_warn(gif_decompress_struct_p gif_ptr, const FX_CHAR* err_msg) {}
517 int32_t _gif_read_header(gif_decompress_struct_p gif_ptr) { 520 int32_t gif_read_header(gif_decompress_struct_p gif_ptr) {
518 if (gif_ptr == NULL) { 521 if (gif_ptr == NULL) {
519 return 0; 522 return 0;
520 } 523 }
521 FX_DWORD skip_size_org = gif_ptr->skip_size; 524 FX_DWORD skip_size_org = gif_ptr->skip_size;
522 ASSERT(sizeof(GifHeader) == 6); 525 ASSERT(sizeof(GifHeader) == 6);
523 GifHeader* gif_header_ptr = NULL; 526 GifHeader* gif_header_ptr = NULL;
524 if (_gif_read_data(gif_ptr, (uint8_t**)&gif_header_ptr, 6) == NULL) { 527 if (gif_read_data(gif_ptr, (uint8_t**)&gif_header_ptr, 6) == NULL) {
525 return 2; 528 return 2;
526 } 529 }
527 if (FXSYS_strncmp(gif_header_ptr->signature, GIF_SIGNATURE, 3) != 0 || 530 if (FXSYS_strncmp(gif_header_ptr->signature, GIF_SIGNATURE, 3) != 0 ||
528 gif_header_ptr->version[0] != '8' || gif_header_ptr->version[2] != 'a') { 531 gif_header_ptr->version[0] != '8' || gif_header_ptr->version[2] != 'a') {
529 _gif_error(gif_ptr, "Not A Gif Image"); 532 gif_error(gif_ptr, "Not A Gif Image");
530 return 0; 533 return 0;
531 } 534 }
532 ASSERT(sizeof(GifLSD) == 7); 535 ASSERT(sizeof(GifLSD) == 7);
533 GifLSD* gif_lsd_ptr = NULL; 536 GifLSD* gif_lsd_ptr = NULL;
534 if (_gif_read_data(gif_ptr, (uint8_t**)&gif_lsd_ptr, 7) == NULL) { 537 if (gif_read_data(gif_ptr, (uint8_t**)&gif_lsd_ptr, 7) == NULL) {
535 gif_ptr->skip_size = skip_size_org; 538 gif_ptr->skip_size = skip_size_org;
536 return 2; 539 return 2;
537 } 540 }
538 if (((GifGF*)&gif_lsd_ptr->global_flag)->global_pal) { 541 if (((GifGF*)&gif_lsd_ptr->global_flag)->global_pal) {
539 gif_ptr->global_pal_num = 2 542 gif_ptr->global_pal_num = 2
540 << ((GifGF*)&gif_lsd_ptr->global_flag)->pal_bits; 543 << ((GifGF*)&gif_lsd_ptr->global_flag)->pal_bits;
541 ASSERT(sizeof(GifPalette) == 3); 544 ASSERT(sizeof(GifPalette) == 3);
542 int32_t global_pal_size = gif_ptr->global_pal_num * 3; 545 int32_t global_pal_size = gif_ptr->global_pal_num * 3;
543 uint8_t* global_pal_ptr = NULL; 546 uint8_t* global_pal_ptr = NULL;
544 if (_gif_read_data(gif_ptr, &global_pal_ptr, global_pal_size) == NULL) { 547 if (gif_read_data(gif_ptr, &global_pal_ptr, global_pal_size) == NULL) {
545 gif_ptr->skip_size = skip_size_org; 548 gif_ptr->skip_size = skip_size_org;
546 return 2; 549 return 2;
547 } 550 }
548 gif_ptr->global_sort_flag = ((GifGF*)&gif_lsd_ptr->global_flag)->sort_flag; 551 gif_ptr->global_sort_flag = ((GifGF*)&gif_lsd_ptr->global_flag)->sort_flag;
549 gif_ptr->global_color_resolution = 552 gif_ptr->global_color_resolution =
550 ((GifGF*)&gif_lsd_ptr->global_flag)->color_resolution; 553 ((GifGF*)&gif_lsd_ptr->global_flag)->color_resolution;
551 FX_Free(gif_ptr->global_pal_ptr); 554 FX_Free(gif_ptr->global_pal_ptr);
552 gif_ptr->global_pal_ptr = (GifPalette*)FX_Alloc(uint8_t, global_pal_size); 555 gif_ptr->global_pal_ptr = (GifPalette*)FX_Alloc(uint8_t, global_pal_size);
553 FXSYS_memcpy(gif_ptr->global_pal_ptr, global_pal_ptr, global_pal_size); 556 FXSYS_memcpy(gif_ptr->global_pal_ptr, global_pal_ptr, global_pal_size);
554 } 557 }
555 gif_ptr->width = (int)_GetWord_LSBFirst((uint8_t*)&gif_lsd_ptr->width); 558 gif_ptr->width = (int)GetWord_LSBFirst((uint8_t*)&gif_lsd_ptr->width);
556 gif_ptr->height = (int)_GetWord_LSBFirst((uint8_t*)&gif_lsd_ptr->height); 559 gif_ptr->height = (int)GetWord_LSBFirst((uint8_t*)&gif_lsd_ptr->height);
557 gif_ptr->bc_index = gif_lsd_ptr->bc_index; 560 gif_ptr->bc_index = gif_lsd_ptr->bc_index;
558 gif_ptr->pixel_aspect = gif_lsd_ptr->pixel_aspect; 561 gif_ptr->pixel_aspect = gif_lsd_ptr->pixel_aspect;
559 return 1; 562 return 1;
560 } 563 }
561 int32_t _gif_get_frame(gif_decompress_struct_p gif_ptr) { 564 int32_t gif_get_frame(gif_decompress_struct_p gif_ptr) {
562 if (gif_ptr == NULL) { 565 if (gif_ptr == NULL) {
563 return 0; 566 return 0;
564 } 567 }
565 int32_t ret = 1; 568 int32_t ret = 1;
566 while (TRUE) { 569 while (TRUE) {
567 switch (gif_ptr->decode_status) { 570 switch (gif_ptr->decode_status) {
568 case GIF_D_STATUS_TAIL: 571 case GIF_D_STATUS_TAIL:
569 return 1; 572 return 1;
570 case GIF_D_STATUS_SIG: { 573 case GIF_D_STATUS_SIG: {
571 uint8_t* sig_ptr = NULL; 574 uint8_t* sig_ptr = NULL;
572 if (_gif_read_data(gif_ptr, &sig_ptr, 1) == NULL) { 575 if (gif_read_data(gif_ptr, &sig_ptr, 1) == NULL) {
573 return 2; 576 return 2;
574 } 577 }
575 switch (*sig_ptr) { 578 switch (*sig_ptr) {
576 case GIF_SIG_EXTENSION: 579 case GIF_SIG_EXTENSION:
577 _gif_save_decoding_status(gif_ptr, GIF_D_STATUS_EXT); 580 gif_save_decoding_status(gif_ptr, GIF_D_STATUS_EXT);
578 continue; 581 continue;
579 case GIF_SIG_IMAGE: 582 case GIF_SIG_IMAGE:
580 _gif_save_decoding_status(gif_ptr, GIF_D_STATUS_IMG_INFO); 583 gif_save_decoding_status(gif_ptr, GIF_D_STATUS_IMG_INFO);
581 continue; 584 continue;
582 case GIF_SIG_TRAILER: 585 case GIF_SIG_TRAILER:
583 _gif_save_decoding_status(gif_ptr, GIF_D_STATUS_TAIL); 586 gif_save_decoding_status(gif_ptr, GIF_D_STATUS_TAIL);
584 return 1; 587 return 1;
585 default: 588 default:
586 if (gif_ptr->avail_in) { 589 if (gif_ptr->avail_in) {
587 _gif_warn(gif_ptr, "The Gif File has non_standard Tag!"); 590 gif_warn(gif_ptr, "The Gif File has non_standard Tag!");
588 _gif_save_decoding_status(gif_ptr, GIF_D_STATUS_SIG); 591 gif_save_decoding_status(gif_ptr, GIF_D_STATUS_SIG);
589 continue; 592 continue;
590 } 593 }
591 _gif_warn(gif_ptr, "The Gif File Doesn't have Trailer Tag!"); 594 gif_warn(gif_ptr, "The Gif File Doesn't have Trailer Tag!");
592 return 1; 595 return 1;
593 } 596 }
594 } 597 }
595 case GIF_D_STATUS_EXT: { 598 case GIF_D_STATUS_EXT: {
596 uint8_t* ext_ptr = NULL; 599 uint8_t* ext_ptr = NULL;
597 if (_gif_read_data(gif_ptr, &ext_ptr, 1) == NULL) { 600 if (gif_read_data(gif_ptr, &ext_ptr, 1) == NULL) {
598 return 2; 601 return 2;
599 } 602 }
600 switch (*ext_ptr) { 603 switch (*ext_ptr) {
601 #ifdef GIF_SUPPORT_APPLICATION_EXTENSION 604 #ifdef GIF_SUPPORT_APPLICATION_EXTENSION
602 case GIF_BLOCK_AE: 605 case GIF_BLOCK_AE:
603 _gif_save_decoding_status(gif_ptr, GIF_D_STATUS_EXT_AE); 606 gif_save_decoding_status(gif_ptr, GIF_D_STATUS_EXT_AE);
604 continue; 607 continue;
605 #endif 608 #endif
606 #ifdef GIF_SUPPORT_COMMENT_EXTENSION 609 #ifdef GIF_SUPPORT_COMMENT_EXTENSION
607 case GIF_BLOCK_CE: 610 case GIF_BLOCK_CE:
608 _gif_save_decoding_status(gif_ptr, GIF_D_STATUS_EXT_CE); 611 gif_save_decoding_status(gif_ptr, GIF_D_STATUS_EXT_CE);
609 continue; 612 continue;
610 #endif 613 #endif
611 #ifdef GIF_SUPPORT_GRAPHIC_CONTROL_EXTENSION 614 #ifdef GIF_SUPPORT_GRAPHIC_CONTROL_EXTENSION
612 case GIF_BLOCK_GCE: 615 case GIF_BLOCK_GCE:
613 _gif_save_decoding_status(gif_ptr, GIF_D_STATUS_EXT_GCE); 616 gif_save_decoding_status(gif_ptr, GIF_D_STATUS_EXT_GCE);
614 continue; 617 continue;
615 #endif 618 #endif
616 #ifdef GIF_SUPPORT_PLAIN_TEXT_EXTENSION 619 #ifdef GIF_SUPPORT_PLAIN_TEXT_EXTENSION
617 case GIF_BLOCK_PTE: 620 case GIF_BLOCK_PTE:
618 _gif_save_decoding_status(gif_ptr, GIF_D_STATUS_EXT_PTE); 621 gif_save_decoding_status(gif_ptr, GIF_D_STATUS_EXT_PTE);
619 continue; 622 continue;
620 #endif 623 #endif
621 default: { 624 default: {
622 int32_t status = GIF_D_STATUS_EXT_UNE; 625 int32_t status = GIF_D_STATUS_EXT_UNE;
623 #ifndef GIF_SUPPORT_PLAIN_TEXT_EXTENSION 626 #ifndef GIF_SUPPORT_PLAIN_TEXT_EXTENSION
624 if (*ext_ptr == GIF_BLOCK_PTE) { 627 if (*ext_ptr == GIF_BLOCK_PTE) {
625 status = GIF_D_STATUS_EXT_PTE; 628 status = GIF_D_STATUS_EXT_PTE;
626 } 629 }
627 #endif 630 #endif
628 _gif_save_decoding_status(gif_ptr, status); 631 gif_save_decoding_status(gif_ptr, status);
629 continue; 632 continue;
630 } 633 }
631 } 634 }
632 } 635 }
633 case GIF_D_STATUS_IMG_INFO: { 636 case GIF_D_STATUS_IMG_INFO: {
634 ret = _gif_decode_image_info(gif_ptr); 637 ret = gif_decode_image_info(gif_ptr);
635 if (ret != 1) { 638 if (ret != 1) {
636 return ret; 639 return ret;
637 } 640 }
638 continue; 641 continue;
639 } 642 }
640 case GIF_D_STATUS_IMG_DATA: { 643 case GIF_D_STATUS_IMG_DATA: {
641 uint8_t* data_size_ptr = NULL; 644 uint8_t* data_size_ptr = NULL;
642 uint8_t* data_ptr = NULL; 645 uint8_t* data_ptr = NULL;
643 FX_DWORD skip_size_org = gif_ptr->skip_size; 646 FX_DWORD skip_size_org = gif_ptr->skip_size;
644 if (_gif_read_data(gif_ptr, &data_size_ptr, 1) == NULL) { 647 if (gif_read_data(gif_ptr, &data_size_ptr, 1) == NULL) {
645 return 2; 648 return 2;
646 } 649 }
647 while (*data_size_ptr != GIF_BLOCK_TERMINAL) { 650 while (*data_size_ptr != GIF_BLOCK_TERMINAL) {
648 if (_gif_read_data(gif_ptr, &data_ptr, *data_size_ptr) == NULL) { 651 if (gif_read_data(gif_ptr, &data_ptr, *data_size_ptr) == NULL) {
649 gif_ptr->skip_size = skip_size_org; 652 gif_ptr->skip_size = skip_size_org;
650 return 2; 653 return 2;
651 } 654 }
652 _gif_save_decoding_status(gif_ptr, GIF_D_STATUS_IMG_DATA); 655 gif_save_decoding_status(gif_ptr, GIF_D_STATUS_IMG_DATA);
653 skip_size_org = gif_ptr->skip_size; 656 skip_size_org = gif_ptr->skip_size;
654 if (_gif_read_data(gif_ptr, &data_size_ptr, 1) == NULL) { 657 if (gif_read_data(gif_ptr, &data_size_ptr, 1) == NULL) {
655 return 2; 658 return 2;
656 } 659 }
657 } 660 }
658 _gif_save_decoding_status(gif_ptr, GIF_D_STATUS_SIG); 661 gif_save_decoding_status(gif_ptr, GIF_D_STATUS_SIG);
659 continue; 662 continue;
660 } 663 }
661 default: { 664 default: {
662 ret = _gif_decode_extension(gif_ptr); 665 ret = gif_decode_extension(gif_ptr);
663 if (ret != 1) { 666 if (ret != 1) {
664 return ret; 667 return ret;
665 } 668 }
666 continue; 669 continue;
667 } 670 }
668 } 671 }
669 } 672 }
670 return 1; 673 return 1;
671 } 674 }
672 void _gif_takeover_gce_ptr(gif_decompress_struct_p gif_ptr, 675 void gif_takeover_gce_ptr(gif_decompress_struct_p gif_ptr,
673 GifGCE** gce_ptr_ptr) { 676 GifGCE** gce_ptr_ptr) {
674 *gce_ptr_ptr = NULL; 677 *gce_ptr_ptr = NULL;
675 #ifdef GIF_SUPPORT_GRAPHIC_CONTROL_EXTENSION 678 #ifdef GIF_SUPPORT_GRAPHIC_CONTROL_EXTENSION
676 if (gif_ptr->gce_ptr && gce_ptr_ptr) { 679 if (gif_ptr->gce_ptr && gce_ptr_ptr) {
677 *gce_ptr_ptr = gif_ptr->gce_ptr; 680 *gce_ptr_ptr = gif_ptr->gce_ptr;
678 gif_ptr->gce_ptr = NULL; 681 gif_ptr->gce_ptr = NULL;
679 } 682 }
680 #endif 683 #endif
681 } 684 }
682 int32_t _gif_decode_extension(gif_decompress_struct_p gif_ptr) { 685 int32_t gif_decode_extension(gif_decompress_struct_p gif_ptr) {
683 uint8_t* data_size_ptr = NULL; 686 uint8_t* data_size_ptr = NULL;
684 uint8_t* data_ptr = NULL; 687 uint8_t* data_ptr = NULL;
685 FX_DWORD skip_size_org = gif_ptr->skip_size; 688 FX_DWORD skip_size_org = gif_ptr->skip_size;
686 switch (gif_ptr->decode_status) { 689 switch (gif_ptr->decode_status) {
687 #ifdef GIF_SUPPORT_APPLICATION_EXTENSION 690 #ifdef GIF_SUPPORT_APPLICATION_EXTENSION
688 case GIF_D_STATUS_EXT_AE: { 691 case GIF_D_STATUS_EXT_AE: {
689 ASSERT(sizeof(GifAE) == 12); 692 ASSERT(sizeof(GifAE) == 12);
690 GifAE* gif_ae_ptr = NULL; 693 GifAE* gif_ae_ptr = NULL;
691 if (_gif_read_data(gif_ptr, (uint8_t**)&gif_ae_ptr, 12) == NULL) { 694 if (gif_read_data(gif_ptr, (uint8_t**)&gif_ae_ptr, 12) == NULL) {
692 return 2; 695 return 2;
693 } 696 }
694 CFX_ByteString gif_ae_data_str; 697 CFX_ByteString gif_ae_data_str;
695 if (_gif_read_data(gif_ptr, &data_size_ptr, 1) == NULL) { 698 if (gif_read_data(gif_ptr, &data_size_ptr, 1) == NULL) {
696 gif_ptr->skip_size = skip_size_org; 699 gif_ptr->skip_size = skip_size_org;
697 return 2; 700 return 2;
698 } 701 }
699 while (*data_size_ptr != GIF_BLOCK_TERMINAL) { 702 while (*data_size_ptr != GIF_BLOCK_TERMINAL) {
700 uint8_t data_size = *data_size_ptr; 703 uint8_t data_size = *data_size_ptr;
701 if (_gif_read_data(gif_ptr, &data_ptr, *data_size_ptr) == NULL || 704 if (gif_read_data(gif_ptr, &data_ptr, *data_size_ptr) == NULL ||
702 _gif_read_data(gif_ptr, &data_size_ptr, 1) == NULL) { 705 gif_read_data(gif_ptr, &data_size_ptr, 1) == NULL) {
703 gif_ptr->skip_size = skip_size_org; 706 gif_ptr->skip_size = skip_size_org;
704 return 2; 707 return 2;
705 } 708 }
706 gif_ae_data_str += CFX_ByteString((const uint8_t*)data_ptr, data_size); 709 gif_ae_data_str += CFX_ByteString((const uint8_t*)data_ptr, data_size);
707 } 710 }
708 FXSYS_memcpy(gif_ptr->app_identify, gif_ae_ptr->app_identify, 8); 711 FXSYS_memcpy(gif_ptr->app_identify, gif_ae_ptr->app_identify, 8);
709 FXSYS_memcpy(gif_ptr->app_authentication, gif_ae_ptr->app_authentication, 712 FXSYS_memcpy(gif_ptr->app_authentication, gif_ae_ptr->app_authentication,
710 3); 713 3);
711 gif_ptr->app_data_size = gif_ae_data_str.GetLength(); 714 gif_ptr->app_data_size = gif_ae_data_str.GetLength();
712 FX_Free(gif_ptr->app_data); 715 FX_Free(gif_ptr->app_data);
713 gif_ptr->app_data = FX_Alloc(uint8_t, gif_ptr->app_data_size); 716 gif_ptr->app_data = FX_Alloc(uint8_t, gif_ptr->app_data_size);
714 FXSYS_memcpy(gif_ptr->app_data, const uint8_t*(gif_ae_data_str), 717 FXSYS_memcpy(gif_ptr->app_data, const uint8_t*(gif_ae_data_str),
715 gif_ptr->app_data_size); 718 gif_ptr->app_data_size);
716 } break; 719 } break;
717 #endif 720 #endif
718 #ifdef GIF_SUPPORT_COMMENT_EXTENSION 721 #ifdef GIF_SUPPORT_COMMENT_EXTENSION
719 case GIF_D_STATUS_EXT_CE: { 722 case GIF_D_STATUS_EXT_CE: {
720 if (_gif_read_data(gif_ptr, &data_size_ptr, 1) == NULL) { 723 if (gif_read_data(gif_ptr, &data_size_ptr, 1) == NULL) {
721 gif_ptr->skip_size = skip_size_org; 724 gif_ptr->skip_size = skip_size_org;
722 return 2; 725 return 2;
723 } 726 }
724 gif_ptr->cmt_data_ptr->Empty(); 727 gif_ptr->cmt_data_ptr->Empty();
725 while (*data_size_ptr != GIF_BLOCK_TERMINAL) { 728 while (*data_size_ptr != GIF_BLOCK_TERMINAL) {
726 uint8_t data_size = *data_size_ptr; 729 uint8_t data_size = *data_size_ptr;
727 if (_gif_read_data(gif_ptr, &data_ptr, *data_size_ptr) == NULL || 730 if (gif_read_data(gif_ptr, &data_ptr, *data_size_ptr) == NULL ||
728 _gif_read_data(gif_ptr, &data_size_ptr, 1) == NULL) { 731 gif_read_data(gif_ptr, &data_size_ptr, 1) == NULL) {
729 gif_ptr->skip_size = skip_size_org; 732 gif_ptr->skip_size = skip_size_org;
730 return 2; 733 return 2;
731 } 734 }
732 *(gif_ptr->cmt_data_ptr) += 735 *(gif_ptr->cmt_data_ptr) +=
733 CFX_ByteString((const FX_CHAR*)data_ptr, data_size); 736 CFX_ByteString((const FX_CHAR*)data_ptr, data_size);
734 } 737 }
735 } break; 738 } break;
736 #endif 739 #endif
737 #ifdef GIF_SUPPORT_PLAIN_TEXT_EXTENSION 740 #ifdef GIF_SUPPORT_PLAIN_TEXT_EXTENSION
738 case GIF_D_STATUS_EXT_PTE: { 741 case GIF_D_STATUS_EXT_PTE: {
739 ASSERT(sizeof(GifPTE) == 13); 742 ASSERT(sizeof(GifPTE) == 13);
740 GifPTE* gif_pte_ptr = NULL; 743 GifPTE* gif_pte_ptr = NULL;
741 if (_gif_read_data(gif_ptr, (uint8_t**)&gif_pte_ptr, 13) == NULL) { 744 if (gif_read_data(gif_ptr, (uint8_t**)&gif_pte_ptr, 13) == NULL) {
742 return 2; 745 return 2;
743 } 746 }
744 GifPlainText* gif_pt_ptr = FX_Alloc(GifPlainText, 1); 747 GifPlainText* gif_pt_ptr = FX_Alloc(GifPlainText, 1);
745 FXSYS_memset(gif_pt_ptr, 0, sizeof(GifPlainText)); 748 FXSYS_memset(gif_pt_ptr, 0, sizeof(GifPlainText));
746 _gif_takeover_gce_ptr(gif_ptr, &gif_pt_ptr->gce_ptr); 749 gif_takeover_gce_ptr(gif_ptr, &gif_pt_ptr->gce_ptr);
747 gif_pt_ptr->pte_ptr = (GifPTE*)FX_Alloc(uint8_t, sizeof(GifPTE)); 750 gif_pt_ptr->pte_ptr = (GifPTE*)FX_Alloc(uint8_t, sizeof(GifPTE));
748 gif_pt_ptr->string_ptr = new CFX_ByteString; 751 gif_pt_ptr->string_ptr = new CFX_ByteString;
749 gif_pt_ptr->pte_ptr->block_size = gif_pte_ptr->block_size; 752 gif_pt_ptr->pte_ptr->block_size = gif_pte_ptr->block_size;
750 gif_pt_ptr->pte_ptr->grid_left = 753 gif_pt_ptr->pte_ptr->grid_left =
751 _GetWord_LSBFirst((uint8_t*)&gif_pte_ptr->grid_left); 754 GetWord_LSBFirst((uint8_t*)&gif_pte_ptr->grid_left);
752 gif_pt_ptr->pte_ptr->grid_top = 755 gif_pt_ptr->pte_ptr->grid_top =
753 _GetWord_LSBFirst((uint8_t*)&gif_pte_ptr->grid_top); 756 GetWord_LSBFirst((uint8_t*)&gif_pte_ptr->grid_top);
754 gif_pt_ptr->pte_ptr->grid_width = 757 gif_pt_ptr->pte_ptr->grid_width =
755 _GetWord_LSBFirst((uint8_t*)&gif_pte_ptr->grid_width); 758 GetWord_LSBFirst((uint8_t*)&gif_pte_ptr->grid_width);
756 gif_pt_ptr->pte_ptr->grid_height = 759 gif_pt_ptr->pte_ptr->grid_height =
757 _GetWord_LSBFirst((uint8_t*)&gif_pte_ptr->grid_height); 760 GetWord_LSBFirst((uint8_t*)&gif_pte_ptr->grid_height);
758 gif_pt_ptr->pte_ptr->char_width = gif_pte_ptr->char_width; 761 gif_pt_ptr->pte_ptr->char_width = gif_pte_ptr->char_width;
759 gif_pt_ptr->pte_ptr->char_height = gif_pte_ptr->char_height; 762 gif_pt_ptr->pte_ptr->char_height = gif_pte_ptr->char_height;
760 gif_pt_ptr->pte_ptr->fc_index = gif_pte_ptr->fc_index; 763 gif_pt_ptr->pte_ptr->fc_index = gif_pte_ptr->fc_index;
761 gif_pt_ptr->pte_ptr->bc_index = gif_pte_ptr->bc_index; 764 gif_pt_ptr->pte_ptr->bc_index = gif_pte_ptr->bc_index;
762 if (_gif_read_data(gif_ptr, &data_size_ptr, 1) == NULL) { 765 if (gif_read_data(gif_ptr, &data_size_ptr, 1) == NULL) {
763 gif_ptr->skip_size = skip_size_org; 766 gif_ptr->skip_size = skip_size_org;
764 if (gif_pt_ptr) { 767 if (gif_pt_ptr) {
765 FX_Free(gif_pt_ptr->gce_ptr); 768 FX_Free(gif_pt_ptr->gce_ptr);
766 FX_Free(gif_pt_ptr->pte_ptr); 769 FX_Free(gif_pt_ptr->pte_ptr);
767 delete gif_pt_ptr->string_ptr; 770 delete gif_pt_ptr->string_ptr;
768 FX_Free(gif_pt_ptr); 771 FX_Free(gif_pt_ptr);
769 } 772 }
770 return 2; 773 return 2;
771 } 774 }
772 while (*data_size_ptr != GIF_BLOCK_TERMINAL) { 775 while (*data_size_ptr != GIF_BLOCK_TERMINAL) {
773 uint8_t data_size = *data_size_ptr; 776 uint8_t data_size = *data_size_ptr;
774 if (_gif_read_data(gif_ptr, &data_ptr, *data_size_ptr) == NULL || 777 if (gif_read_data(gif_ptr, &data_ptr, *data_size_ptr) == NULL ||
775 _gif_read_data(gif_ptr, &data_size_ptr, 1) == NULL) { 778 gif_read_data(gif_ptr, &data_size_ptr, 1) == NULL) {
776 gif_ptr->skip_size = skip_size_org; 779 gif_ptr->skip_size = skip_size_org;
777 if (gif_pt_ptr) { 780 if (gif_pt_ptr) {
778 FX_Free(gif_pt_ptr->gce_ptr); 781 FX_Free(gif_pt_ptr->gce_ptr);
779 FX_Free(gif_pt_ptr->pte_ptr); 782 FX_Free(gif_pt_ptr->pte_ptr);
780 delete gif_pt_ptr->string_ptr; 783 delete gif_pt_ptr->string_ptr;
781 FX_Free(gif_pt_ptr); 784 FX_Free(gif_pt_ptr);
782 } 785 }
783 return 2; 786 return 2;
784 } 787 }
785 *(gif_pt_ptr->string_ptr) += 788 *(gif_pt_ptr->string_ptr) +=
786 CFX_ByteString((const FX_CHAR*)data_ptr, data_size); 789 CFX_ByteString((const FX_CHAR*)data_ptr, data_size);
787 } 790 }
788 gif_ptr->pt_ptr_arr_ptr->Add(gif_pt_ptr); 791 gif_ptr->pt_ptr_arr_ptr->Add(gif_pt_ptr);
789 } break; 792 } break;
790 #endif 793 #endif
791 #ifdef GIF_SUPPORT_GRAPHIC_CONTROL_EXTENSION 794 #ifdef GIF_SUPPORT_GRAPHIC_CONTROL_EXTENSION
792 case GIF_D_STATUS_EXT_GCE: { 795 case GIF_D_STATUS_EXT_GCE: {
793 ASSERT(sizeof(GifGCE) == 5); 796 ASSERT(sizeof(GifGCE) == 5);
794 GifGCE* gif_gce_ptr = NULL; 797 GifGCE* gif_gce_ptr = NULL;
795 if (_gif_read_data(gif_ptr, (uint8_t**)&gif_gce_ptr, 6) == NULL) { 798 if (gif_read_data(gif_ptr, (uint8_t**)&gif_gce_ptr, 6) == NULL) {
796 return 2; 799 return 2;
797 } 800 }
798 if (gif_ptr->gce_ptr == NULL) { 801 if (gif_ptr->gce_ptr == NULL) {
799 gif_ptr->gce_ptr = (GifGCE*)FX_Alloc(uint8_t, sizeof(GifGCE)); 802 gif_ptr->gce_ptr = (GifGCE*)FX_Alloc(uint8_t, sizeof(GifGCE));
800 } 803 }
801 gif_ptr->gce_ptr->block_size = gif_gce_ptr->block_size; 804 gif_ptr->gce_ptr->block_size = gif_gce_ptr->block_size;
802 gif_ptr->gce_ptr->gce_flag = gif_gce_ptr->gce_flag; 805 gif_ptr->gce_ptr->gce_flag = gif_gce_ptr->gce_flag;
803 gif_ptr->gce_ptr->delay_time = 806 gif_ptr->gce_ptr->delay_time =
804 _GetWord_LSBFirst((uint8_t*)&gif_gce_ptr->delay_time); 807 GetWord_LSBFirst((uint8_t*)&gif_gce_ptr->delay_time);
805 gif_ptr->gce_ptr->trans_index = gif_gce_ptr->trans_index; 808 gif_ptr->gce_ptr->trans_index = gif_gce_ptr->trans_index;
806 } break; 809 } break;
807 #endif 810 #endif
808 default: { 811 default: {
809 #ifndef GIF_SUPPORT_PLAIN_TEXT_EXTENSION 812 #ifndef GIF_SUPPORT_PLAIN_TEXT_EXTENSION
810 #ifdef GIF_SUPPORT_GRAPHIC_CONTROL_EXTENSION 813 #ifdef GIF_SUPPORT_GRAPHIC_CONTROL_EXTENSION
811 if (gif_ptr->decode_status == GIF_D_STATUS_EXT_PTE) { 814 if (gif_ptr->decode_status == GIF_D_STATUS_EXT_PTE) {
812 FX_Free(gif_ptr->gce_ptr); 815 FX_Free(gif_ptr->gce_ptr);
813 gif_ptr->gce_ptr = NULL; 816 gif_ptr->gce_ptr = NULL;
814 } 817 }
815 #endif 818 #endif
816 #endif 819 #endif
817 if (_gif_read_data(gif_ptr, &data_size_ptr, 1) == NULL) { 820 if (gif_read_data(gif_ptr, &data_size_ptr, 1) == NULL) {
818 return 2; 821 return 2;
819 } 822 }
820 while (*data_size_ptr != GIF_BLOCK_TERMINAL) { 823 while (*data_size_ptr != GIF_BLOCK_TERMINAL) {
821 if (_gif_read_data(gif_ptr, &data_ptr, *data_size_ptr) == NULL || 824 if (gif_read_data(gif_ptr, &data_ptr, *data_size_ptr) == NULL ||
822 _gif_read_data(gif_ptr, &data_size_ptr, 1) == NULL) { 825 gif_read_data(gif_ptr, &data_size_ptr, 1) == NULL) {
823 gif_ptr->skip_size = skip_size_org; 826 gif_ptr->skip_size = skip_size_org;
824 return 2; 827 return 2;
825 } 828 }
826 } 829 }
827 } 830 }
828 } 831 }
829 _gif_save_decoding_status(gif_ptr, GIF_D_STATUS_SIG); 832 gif_save_decoding_status(gif_ptr, GIF_D_STATUS_SIG);
830 return 1; 833 return 1;
831 } 834 }
832 int32_t _gif_decode_image_info(gif_decompress_struct_p gif_ptr) { 835 int32_t gif_decode_image_info(gif_decompress_struct_p gif_ptr) {
833 if (gif_ptr->width == 0 || gif_ptr->height == 0) { 836 if (gif_ptr->width == 0 || gif_ptr->height == 0) {
834 _gif_error(gif_ptr, "No Image Header Info"); 837 gif_error(gif_ptr, "No Image Header Info");
835 return 0; 838 return 0;
836 } 839 }
837 FX_DWORD skip_size_org = gif_ptr->skip_size; 840 FX_DWORD skip_size_org = gif_ptr->skip_size;
838 ASSERT(sizeof(GifImageInfo) == 9); 841 ASSERT(sizeof(GifImageInfo) == 9);
839 GifImageInfo* gif_img_info_ptr = NULL; 842 GifImageInfo* gif_img_info_ptr = NULL;
840 if (_gif_read_data(gif_ptr, (uint8_t**)&gif_img_info_ptr, 9) == NULL) { 843 if (gif_read_data(gif_ptr, (uint8_t**)&gif_img_info_ptr, 9) == NULL) {
841 return 2; 844 return 2;
842 } 845 }
843 GifImage* gif_image_ptr = (GifImage*)FX_Alloc(uint8_t, sizeof(GifImage)); 846 GifImage* gif_image_ptr = (GifImage*)FX_Alloc(uint8_t, sizeof(GifImage));
844 FXSYS_memset(gif_image_ptr, 0, sizeof(GifImage)); 847 FXSYS_memset(gif_image_ptr, 0, sizeof(GifImage));
845 gif_image_ptr->image_info_ptr = 848 gif_image_ptr->image_info_ptr =
846 (GifImageInfo*)FX_Alloc(uint8_t, sizeof(GifImageInfo)); 849 (GifImageInfo*)FX_Alloc(uint8_t, sizeof(GifImageInfo));
847 gif_image_ptr->image_info_ptr->left = 850 gif_image_ptr->image_info_ptr->left =
848 _GetWord_LSBFirst((uint8_t*)&gif_img_info_ptr->left); 851 GetWord_LSBFirst((uint8_t*)&gif_img_info_ptr->left);
849 gif_image_ptr->image_info_ptr->top = 852 gif_image_ptr->image_info_ptr->top =
850 _GetWord_LSBFirst((uint8_t*)&gif_img_info_ptr->top); 853 GetWord_LSBFirst((uint8_t*)&gif_img_info_ptr->top);
851 gif_image_ptr->image_info_ptr->width = 854 gif_image_ptr->image_info_ptr->width =
852 _GetWord_LSBFirst((uint8_t*)&gif_img_info_ptr->width); 855 GetWord_LSBFirst((uint8_t*)&gif_img_info_ptr->width);
853 gif_image_ptr->image_info_ptr->height = 856 gif_image_ptr->image_info_ptr->height =
854 _GetWord_LSBFirst((uint8_t*)&gif_img_info_ptr->height); 857 GetWord_LSBFirst((uint8_t*)&gif_img_info_ptr->height);
855 gif_image_ptr->image_info_ptr->local_flag = gif_img_info_ptr->local_flag; 858 gif_image_ptr->image_info_ptr->local_flag = gif_img_info_ptr->local_flag;
856 if (gif_image_ptr->image_info_ptr->left + 859 if (gif_image_ptr->image_info_ptr->left +
857 gif_image_ptr->image_info_ptr->width > 860 gif_image_ptr->image_info_ptr->width >
858 gif_ptr->width || 861 gif_ptr->width ||
859 gif_image_ptr->image_info_ptr->top + 862 gif_image_ptr->image_info_ptr->top +
860 gif_image_ptr->image_info_ptr->height > 863 gif_image_ptr->image_info_ptr->height >
861 gif_ptr->height) { 864 gif_ptr->height) {
862 FX_Free(gif_image_ptr->image_info_ptr); 865 FX_Free(gif_image_ptr->image_info_ptr);
863 FX_Free(gif_image_ptr->image_row_buf); 866 FX_Free(gif_image_ptr->image_row_buf);
864 FX_Free(gif_image_ptr); 867 FX_Free(gif_image_ptr);
865 _gif_error(gif_ptr, "Image Data Out Of LSD, The File May Be Corrupt"); 868 gif_error(gif_ptr, "Image Data Out Of LSD, The File May Be Corrupt");
866 return 0; 869 return 0;
867 } 870 }
868 GifLF* gif_img_info_lf_ptr = (GifLF*)&gif_img_info_ptr->local_flag; 871 GifLF* gif_img_info_lf_ptr = (GifLF*)&gif_img_info_ptr->local_flag;
869 if (gif_img_info_lf_ptr->local_pal) { 872 if (gif_img_info_lf_ptr->local_pal) {
870 ASSERT(sizeof(GifPalette) == 3); 873 ASSERT(sizeof(GifPalette) == 3);
871 int32_t loc_pal_size = (2 << gif_img_info_lf_ptr->pal_bits) * 3; 874 int32_t loc_pal_size = (2 << gif_img_info_lf_ptr->pal_bits) * 3;
872 uint8_t* loc_pal_ptr = NULL; 875 uint8_t* loc_pal_ptr = NULL;
873 if (_gif_read_data(gif_ptr, &loc_pal_ptr, loc_pal_size) == NULL) { 876 if (gif_read_data(gif_ptr, &loc_pal_ptr, loc_pal_size) == NULL) {
874 gif_ptr->skip_size = skip_size_org; 877 gif_ptr->skip_size = skip_size_org;
875 FX_Free(gif_image_ptr->image_info_ptr); 878 FX_Free(gif_image_ptr->image_info_ptr);
876 FX_Free(gif_image_ptr->image_row_buf); 879 FX_Free(gif_image_ptr->image_row_buf);
877 FX_Free(gif_image_ptr); 880 FX_Free(gif_image_ptr);
878 return 2; 881 return 2;
879 } 882 }
880 gif_image_ptr->local_pal_ptr = 883 gif_image_ptr->local_pal_ptr =
881 (GifPalette*)gif_ptr->_gif_ask_buf_for_pal_fn(gif_ptr, loc_pal_size); 884 (GifPalette*)gif_ptr->_gif_ask_buf_for_pal_fn(gif_ptr, loc_pal_size);
882 if (gif_image_ptr->local_pal_ptr) { 885 if (gif_image_ptr->local_pal_ptr) {
883 FXSYS_memcpy((uint8_t*)gif_image_ptr->local_pal_ptr, loc_pal_ptr, 886 FXSYS_memcpy((uint8_t*)gif_image_ptr->local_pal_ptr, loc_pal_ptr,
884 loc_pal_size); 887 loc_pal_size);
885 } 888 }
886 } 889 }
887 uint8_t* code_size_ptr = NULL; 890 uint8_t* code_size_ptr = NULL;
888 if (_gif_read_data(gif_ptr, &code_size_ptr, 1) == NULL) { 891 if (gif_read_data(gif_ptr, &code_size_ptr, 1) == NULL) {
889 gif_ptr->skip_size = skip_size_org; 892 gif_ptr->skip_size = skip_size_org;
890 FX_Free(gif_image_ptr->image_info_ptr); 893 FX_Free(gif_image_ptr->image_info_ptr);
891 FX_Free(gif_image_ptr->local_pal_ptr); 894 FX_Free(gif_image_ptr->local_pal_ptr);
892 FX_Free(gif_image_ptr->image_row_buf); 895 FX_Free(gif_image_ptr->image_row_buf);
893 FX_Free(gif_image_ptr); 896 FX_Free(gif_image_ptr);
894 return 2; 897 return 2;
895 } 898 }
896 gif_image_ptr->image_code_size = *code_size_ptr; 899 gif_image_ptr->image_code_size = *code_size_ptr;
897 gif_ptr->_gif_record_current_position_fn(gif_ptr, 900 gif_ptr->_gif_record_current_position_fn(gif_ptr,
898 &gif_image_ptr->image_data_pos); 901 &gif_image_ptr->image_data_pos);
899 gif_image_ptr->image_data_pos += gif_ptr->skip_size; 902 gif_image_ptr->image_data_pos += gif_ptr->skip_size;
900 _gif_takeover_gce_ptr(gif_ptr, &gif_image_ptr->image_gce_ptr); 903 gif_takeover_gce_ptr(gif_ptr, &gif_image_ptr->image_gce_ptr);
901 gif_ptr->img_ptr_arr_ptr->Add(gif_image_ptr); 904 gif_ptr->img_ptr_arr_ptr->Add(gif_image_ptr);
902 _gif_save_decoding_status(gif_ptr, GIF_D_STATUS_IMG_DATA); 905 gif_save_decoding_status(gif_ptr, GIF_D_STATUS_IMG_DATA);
903 return 1; 906 return 1;
904 } 907 }
905 int32_t _gif_load_frame(gif_decompress_struct_p gif_ptr, int32_t frame_num) { 908 int32_t gif_load_frame(gif_decompress_struct_p gif_ptr, int32_t frame_num) {
906 if (gif_ptr == NULL || frame_num < 0 || 909 if (gif_ptr == NULL || frame_num < 0 ||
907 frame_num >= gif_ptr->img_ptr_arr_ptr->GetSize()) { 910 frame_num >= gif_ptr->img_ptr_arr_ptr->GetSize()) {
908 return 0; 911 return 0;
909 } 912 }
910 uint8_t* data_size_ptr = NULL; 913 uint8_t* data_size_ptr = NULL;
911 uint8_t* data_ptr = NULL; 914 uint8_t* data_ptr = NULL;
912 FX_DWORD skip_size_org = gif_ptr->skip_size; 915 FX_DWORD skip_size_org = gif_ptr->skip_size;
913 GifImage* gif_image_ptr = gif_ptr->img_ptr_arr_ptr->GetAt(frame_num); 916 GifImage* gif_image_ptr = gif_ptr->img_ptr_arr_ptr->GetAt(frame_num);
914 FX_DWORD gif_img_row_bytes = gif_image_ptr->image_info_ptr->width; 917 FX_DWORD gif_img_row_bytes = gif_image_ptr->image_info_ptr->width;
915 if (gif_ptr->decode_status == GIF_D_STATUS_TAIL) { 918 if (gif_ptr->decode_status == GIF_D_STATUS_TAIL) {
(...skipping 15 matching lines...) Expand all
931 gif_image_ptr->image_info_ptr->left, 934 gif_image_ptr->image_info_ptr->left,
932 gif_image_ptr->image_info_ptr->top, 935 gif_image_ptr->image_info_ptr->top,
933 gif_image_ptr->image_info_ptr->width, 936 gif_image_ptr->image_info_ptr->width,
934 gif_image_ptr->image_info_ptr->height, loc_pal_num, 937 gif_image_ptr->image_info_ptr->height, loc_pal_num,
935 gif_image_ptr->local_pal_ptr, 0, 0, -1, 0, 938 gif_image_ptr->local_pal_ptr, 0, 0, -1, 0,
936 (FX_BOOL)((GifLF*)&gif_image_ptr->image_info_ptr->local_flag) 939 (FX_BOOL)((GifLF*)&gif_image_ptr->image_info_ptr->local_flag)
937 ->interlace); 940 ->interlace);
938 if (!bRes) { 941 if (!bRes) {
939 FX_Free(gif_image_ptr->image_row_buf); 942 FX_Free(gif_image_ptr->image_row_buf);
940 gif_image_ptr->image_row_buf = NULL; 943 gif_image_ptr->image_row_buf = NULL;
941 _gif_error(gif_ptr, "Error Read Record Position Data"); 944 gif_error(gif_ptr, "Error Read Record Position Data");
942 return 0; 945 return 0;
943 } 946 }
944 } else { 947 } else {
945 FX_BOOL bRes = gif_ptr->_gif_get_record_position_fn( 948 FX_BOOL bRes = gif_ptr->_gif_get_record_position_fn(
946 gif_ptr, gif_image_ptr->image_data_pos, 949 gif_ptr, gif_image_ptr->image_data_pos,
947 gif_image_ptr->image_info_ptr->left, 950 gif_image_ptr->image_info_ptr->left,
948 gif_image_ptr->image_info_ptr->top, 951 gif_image_ptr->image_info_ptr->top,
949 gif_image_ptr->image_info_ptr->width, 952 gif_image_ptr->image_info_ptr->width,
950 gif_image_ptr->image_info_ptr->height, loc_pal_num, 953 gif_image_ptr->image_info_ptr->height, loc_pal_num,
951 gif_image_ptr->local_pal_ptr, 954 gif_image_ptr->local_pal_ptr,
952 (int32_t)gif_image_ptr->image_gce_ptr->delay_time, 955 (int32_t)gif_image_ptr->image_gce_ptr->delay_time,
953 (FX_BOOL)((GifCEF*)&gif_image_ptr->image_gce_ptr->gce_flag) 956 (FX_BOOL)((GifCEF*)&gif_image_ptr->image_gce_ptr->gce_flag)
954 ->user_input, 957 ->user_input,
955 ((GifCEF*)&gif_image_ptr->image_gce_ptr->gce_flag)->transparency 958 ((GifCEF*)&gif_image_ptr->image_gce_ptr->gce_flag)->transparency
956 ? (int32_t)gif_image_ptr->image_gce_ptr->trans_index 959 ? (int32_t)gif_image_ptr->image_gce_ptr->trans_index
957 : -1, 960 : -1,
958 (int32_t)((GifCEF*)&gif_image_ptr->image_gce_ptr->gce_flag) 961 (int32_t)((GifCEF*)&gif_image_ptr->image_gce_ptr->gce_flag)
959 ->disposal_method, 962 ->disposal_method,
960 (FX_BOOL)((GifLF*)&gif_image_ptr->image_info_ptr->local_flag) 963 (FX_BOOL)((GifLF*)&gif_image_ptr->image_info_ptr->local_flag)
961 ->interlace); 964 ->interlace);
962 if (!bRes) { 965 if (!bRes) {
963 FX_Free(gif_image_ptr->image_row_buf); 966 FX_Free(gif_image_ptr->image_row_buf);
964 gif_image_ptr->image_row_buf = NULL; 967 gif_image_ptr->image_row_buf = NULL;
965 _gif_error(gif_ptr, "Error Read Record Position Data"); 968 gif_error(gif_ptr, "Error Read Record Position Data");
966 return 0; 969 return 0;
967 } 970 }
968 } 971 }
969 if (gif_ptr->img_decoder_ptr == NULL) { 972 if (gif_ptr->img_decoder_ptr == NULL) {
970 gif_ptr->img_decoder_ptr = new CGifLZWDecoder(gif_ptr->err_ptr); 973 gif_ptr->img_decoder_ptr = new CGifLZWDecoder(gif_ptr->err_ptr);
971 } 974 }
972 gif_ptr->img_decoder_ptr->InitTable(gif_image_ptr->image_code_size); 975 gif_ptr->img_decoder_ptr->InitTable(gif_image_ptr->image_code_size);
973 gif_ptr->img_row_offset = 0; 976 gif_ptr->img_row_offset = 0;
974 gif_ptr->img_row_avail_size = 0; 977 gif_ptr->img_row_avail_size = 0;
975 gif_ptr->img_pass_num = 0; 978 gif_ptr->img_pass_num = 0;
976 gif_image_ptr->image_row_num = 0; 979 gif_image_ptr->image_row_num = 0;
977 _gif_save_decoding_status(gif_ptr, GIF_D_STATUS_IMG_DATA); 980 gif_save_decoding_status(gif_ptr, GIF_D_STATUS_IMG_DATA);
978 } 981 }
979 CGifLZWDecoder* img_decoder_ptr = gif_ptr->img_decoder_ptr; 982 CGifLZWDecoder* img_decoder_ptr = gif_ptr->img_decoder_ptr;
980 if (gif_ptr->decode_status == GIF_D_STATUS_IMG_DATA) { 983 if (gif_ptr->decode_status == GIF_D_STATUS_IMG_DATA) {
981 if (_gif_read_data(gif_ptr, &data_size_ptr, 1) == NULL) { 984 if (gif_read_data(gif_ptr, &data_size_ptr, 1) == NULL) {
982 return 2; 985 return 2;
983 } 986 }
984 if (*data_size_ptr != GIF_BLOCK_TERMINAL) { 987 if (*data_size_ptr != GIF_BLOCK_TERMINAL) {
985 if (_gif_read_data(gif_ptr, &data_ptr, *data_size_ptr) == NULL) { 988 if (gif_read_data(gif_ptr, &data_ptr, *data_size_ptr) == NULL) {
986 gif_ptr->skip_size = skip_size_org; 989 gif_ptr->skip_size = skip_size_org;
987 return 2; 990 return 2;
988 } 991 }
989 img_decoder_ptr->Input(data_ptr, *data_size_ptr); 992 img_decoder_ptr->Input(data_ptr, *data_size_ptr);
990 _gif_save_decoding_status(gif_ptr, GIF_D_STATUS_IMG_DATA); 993 gif_save_decoding_status(gif_ptr, GIF_D_STATUS_IMG_DATA);
991 gif_ptr->img_row_offset += gif_ptr->img_row_avail_size; 994 gif_ptr->img_row_offset += gif_ptr->img_row_avail_size;
992 gif_ptr->img_row_avail_size = gif_img_row_bytes - gif_ptr->img_row_offset; 995 gif_ptr->img_row_avail_size = gif_img_row_bytes - gif_ptr->img_row_offset;
993 int32_t ret = img_decoder_ptr->Decode( 996 int32_t ret = img_decoder_ptr->Decode(
994 gif_image_ptr->image_row_buf + gif_ptr->img_row_offset, 997 gif_image_ptr->image_row_buf + gif_ptr->img_row_offset,
995 gif_ptr->img_row_avail_size); 998 gif_ptr->img_row_avail_size);
996 if (ret == 0) { 999 if (ret == 0) {
997 FX_Free(gif_image_ptr->image_row_buf); 1000 FX_Free(gif_image_ptr->image_row_buf);
998 gif_image_ptr->image_row_buf = NULL; 1001 gif_image_ptr->image_row_buf = NULL;
999 _gif_save_decoding_status(gif_ptr, GIF_D_STATUS_TAIL); 1002 gif_save_decoding_status(gif_ptr, GIF_D_STATUS_TAIL);
1000 _gif_error(gif_ptr, "Decode Image Data Error"); 1003 gif_error(gif_ptr, "Decode Image Data Error");
1001 return 0; 1004 return 0;
1002 } 1005 }
1003 while (ret != 0) { 1006 while (ret != 0) {
1004 if (ret == 1) { 1007 if (ret == 1) {
1005 gif_ptr->_gif_get_row_fn(gif_ptr, gif_image_ptr->image_row_num, 1008 gif_ptr->_gif_get_row_fn(gif_ptr, gif_image_ptr->image_row_num,
1006 gif_image_ptr->image_row_buf); 1009 gif_image_ptr->image_row_buf);
1007 FX_Free(gif_image_ptr->image_row_buf); 1010 FX_Free(gif_image_ptr->image_row_buf);
1008 gif_image_ptr->image_row_buf = NULL; 1011 gif_image_ptr->image_row_buf = NULL;
1009 _gif_save_decoding_status(gif_ptr, GIF_D_STATUS_TAIL); 1012 gif_save_decoding_status(gif_ptr, GIF_D_STATUS_TAIL);
1010 return 1; 1013 return 1;
1011 } 1014 }
1012 if (ret == 2) { 1015 if (ret == 2) {
1013 ASSERT(img_decoder_ptr->GetAvailInput() == 0); 1016 ASSERT(img_decoder_ptr->GetAvailInput() == 0);
1014 skip_size_org = gif_ptr->skip_size; 1017 skip_size_org = gif_ptr->skip_size;
1015 if (_gif_read_data(gif_ptr, &data_size_ptr, 1) == NULL) { 1018 if (gif_read_data(gif_ptr, &data_size_ptr, 1) == NULL) {
1016 return 2; 1019 return 2;
1017 } 1020 }
1018 if (*data_size_ptr != GIF_BLOCK_TERMINAL) { 1021 if (*data_size_ptr != GIF_BLOCK_TERMINAL) {
1019 if (_gif_read_data(gif_ptr, &data_ptr, *data_size_ptr) == NULL) { 1022 if (gif_read_data(gif_ptr, &data_ptr, *data_size_ptr) == NULL) {
1020 gif_ptr->skip_size = skip_size_org; 1023 gif_ptr->skip_size = skip_size_org;
1021 return 2; 1024 return 2;
1022 } 1025 }
1023 img_decoder_ptr->Input(data_ptr, *data_size_ptr); 1026 img_decoder_ptr->Input(data_ptr, *data_size_ptr);
1024 _gif_save_decoding_status(gif_ptr, GIF_D_STATUS_IMG_DATA); 1027 gif_save_decoding_status(gif_ptr, GIF_D_STATUS_IMG_DATA);
1025 gif_ptr->img_row_offset += gif_ptr->img_row_avail_size; 1028 gif_ptr->img_row_offset += gif_ptr->img_row_avail_size;
1026 gif_ptr->img_row_avail_size = 1029 gif_ptr->img_row_avail_size =
1027 gif_img_row_bytes - gif_ptr->img_row_offset; 1030 gif_img_row_bytes - gif_ptr->img_row_offset;
1028 ret = img_decoder_ptr->Decode( 1031 ret = img_decoder_ptr->Decode(
1029 gif_image_ptr->image_row_buf + gif_ptr->img_row_offset, 1032 gif_image_ptr->image_row_buf + gif_ptr->img_row_offset,
1030 gif_ptr->img_row_avail_size); 1033 gif_ptr->img_row_avail_size);
1031 } 1034 }
1032 } 1035 }
1033 if (ret == 3) { 1036 if (ret == 3) {
1034 if (((GifLF*)&gif_image_ptr->image_info_ptr->local_flag)->interlace) { 1037 if (((GifLF*)&gif_image_ptr->image_info_ptr->local_flag)->interlace) {
(...skipping 13 matching lines...) Expand all
1048 } 1051 }
1049 gif_ptr->img_row_offset = 0; 1052 gif_ptr->img_row_offset = 0;
1050 gif_ptr->img_row_avail_size = gif_img_row_bytes; 1053 gif_ptr->img_row_avail_size = gif_img_row_bytes;
1051 ret = img_decoder_ptr->Decode( 1054 ret = img_decoder_ptr->Decode(
1052 gif_image_ptr->image_row_buf + gif_ptr->img_row_offset, 1055 gif_image_ptr->image_row_buf + gif_ptr->img_row_offset,
1053 gif_ptr->img_row_avail_size); 1056 gif_ptr->img_row_avail_size);
1054 } 1057 }
1055 if (ret == 0) { 1058 if (ret == 0) {
1056 FX_Free(gif_image_ptr->image_row_buf); 1059 FX_Free(gif_image_ptr->image_row_buf);
1057 gif_image_ptr->image_row_buf = NULL; 1060 gif_image_ptr->image_row_buf = NULL;
1058 _gif_save_decoding_status(gif_ptr, GIF_D_STATUS_TAIL); 1061 gif_save_decoding_status(gif_ptr, GIF_D_STATUS_TAIL);
1059 _gif_error(gif_ptr, "Decode Image Data Error"); 1062 gif_error(gif_ptr, "Decode Image Data Error");
1060 return 0; 1063 return 0;
1061 } 1064 }
1062 } 1065 }
1063 } 1066 }
1064 _gif_save_decoding_status(gif_ptr, GIF_D_STATUS_TAIL); 1067 gif_save_decoding_status(gif_ptr, GIF_D_STATUS_TAIL);
1065 } 1068 }
1066 _gif_error(gif_ptr, "Decode Image Data Error"); 1069 gif_error(gif_ptr, "Decode Image Data Error");
1067 return 0; 1070 return 0;
1068 } 1071 }
1069 void _gif_save_decoding_status(gif_decompress_struct_p gif_ptr, 1072 void gif_save_decoding_status(gif_decompress_struct_p gif_ptr, int32_t status) {
1070 int32_t status) {
1071 gif_ptr->decode_status = status; 1073 gif_ptr->decode_status = status;
1072 gif_ptr->next_in += gif_ptr->skip_size; 1074 gif_ptr->next_in += gif_ptr->skip_size;
1073 gif_ptr->avail_in -= gif_ptr->skip_size; 1075 gif_ptr->avail_in -= gif_ptr->skip_size;
1074 gif_ptr->skip_size = 0; 1076 gif_ptr->skip_size = 0;
1075 } 1077 }
1076 uint8_t* _gif_read_data(gif_decompress_struct_p gif_ptr, 1078 uint8_t* gif_read_data(gif_decompress_struct_p gif_ptr,
1077 uint8_t** des_buf_pp, 1079 uint8_t** des_buf_pp,
1078 FX_DWORD data_size) { 1080 FX_DWORD data_size) {
1079 if (gif_ptr == NULL || gif_ptr->avail_in < gif_ptr->skip_size + data_size) { 1081 if (gif_ptr == NULL || gif_ptr->avail_in < gif_ptr->skip_size + data_size) {
1080 return NULL; 1082 return NULL;
1081 } 1083 }
1082 *des_buf_pp = gif_ptr->next_in + gif_ptr->skip_size; 1084 *des_buf_pp = gif_ptr->next_in + gif_ptr->skip_size;
1083 gif_ptr->skip_size += data_size; 1085 gif_ptr->skip_size += data_size;
1084 return *des_buf_pp; 1086 return *des_buf_pp;
1085 } 1087 }
1086 void _gif_input_buffer(gif_decompress_struct_p gif_ptr, 1088 void gif_input_buffer(gif_decompress_struct_p gif_ptr,
1087 uint8_t* src_buf, 1089 uint8_t* src_buf,
1088 FX_DWORD src_size) { 1090 FX_DWORD src_size) {
1089 gif_ptr->next_in = src_buf; 1091 gif_ptr->next_in = src_buf;
1090 gif_ptr->avail_in = src_size; 1092 gif_ptr->avail_in = src_size;
1091 gif_ptr->skip_size = 0; 1093 gif_ptr->skip_size = 0;
1092 } 1094 }
1093 FX_DWORD _gif_get_avail_input(gif_decompress_struct_p gif_ptr, 1095 FX_DWORD gif_get_avail_input(gif_decompress_struct_p gif_ptr,
1094 uint8_t** avial_buf_ptr) { 1096 uint8_t** avial_buf_ptr) {
1095 if (avial_buf_ptr) { 1097 if (avial_buf_ptr) {
1096 *avial_buf_ptr = NULL; 1098 *avial_buf_ptr = NULL;
1097 if (gif_ptr->avail_in > 0) { 1099 if (gif_ptr->avail_in > 0) {
1098 *avial_buf_ptr = gif_ptr->next_in; 1100 *avial_buf_ptr = gif_ptr->next_in;
1099 } 1101 }
1100 } 1102 }
1101 return gif_ptr->avail_in; 1103 return gif_ptr->avail_in;
1102 } 1104 }
1103 int32_t _gif_get_frame_num(gif_decompress_struct_p gif_ptr) { 1105 int32_t gif_get_frame_num(gif_decompress_struct_p gif_ptr) {
1104 return gif_ptr->img_ptr_arr_ptr->GetSize(); 1106 return gif_ptr->img_ptr_arr_ptr->GetSize();
1105 } 1107 }
1106 static FX_BOOL _gif_write_header(gif_compress_struct_p gif_ptr, 1108 static FX_BOOL gif_write_header(gif_compress_struct_p gif_ptr,
1107 uint8_t*& dst_buf, 1109 uint8_t*& dst_buf,
1108 FX_DWORD& dst_len) { 1110 FX_DWORD& dst_len) {
1109 if (gif_ptr->cur_offset) { 1111 if (gif_ptr->cur_offset) {
1110 return TRUE; 1112 return TRUE;
1111 } 1113 }
1112 dst_len = sizeof(GifHeader) + sizeof(GifLSD) + sizeof(GifGF); 1114 dst_len = sizeof(GifHeader) + sizeof(GifLSD) + sizeof(GifGF);
1113 dst_buf = FX_TryAlloc(uint8_t, dst_len); 1115 dst_buf = FX_TryAlloc(uint8_t, dst_len);
1114 if (dst_buf == NULL) { 1116 if (dst_buf == NULL) {
1115 return FALSE; 1117 return FALSE;
1116 } 1118 }
1117 FXSYS_memset(dst_buf, 0, dst_len); 1119 FXSYS_memset(dst_buf, 0, dst_len);
1118 FXSYS_memcpy(dst_buf, gif_ptr->header_ptr, sizeof(GifHeader)); 1120 FXSYS_memcpy(dst_buf, gif_ptr->header_ptr, sizeof(GifHeader));
1119 gif_ptr->cur_offset += sizeof(GifHeader); 1121 gif_ptr->cur_offset += sizeof(GifHeader);
1120 _SetWord_LSBFirst(dst_buf + gif_ptr->cur_offset, gif_ptr->lsd_ptr->width); 1122 SetWord_LSBFirst(dst_buf + gif_ptr->cur_offset, gif_ptr->lsd_ptr->width);
1121 gif_ptr->cur_offset += 2; 1123 gif_ptr->cur_offset += 2;
1122 _SetWord_LSBFirst(dst_buf + gif_ptr->cur_offset, gif_ptr->lsd_ptr->height); 1124 SetWord_LSBFirst(dst_buf + gif_ptr->cur_offset, gif_ptr->lsd_ptr->height);
1123 gif_ptr->cur_offset += 2; 1125 gif_ptr->cur_offset += 2;
1124 dst_buf[gif_ptr->cur_offset++] = gif_ptr->lsd_ptr->global_flag; 1126 dst_buf[gif_ptr->cur_offset++] = gif_ptr->lsd_ptr->global_flag;
1125 dst_buf[gif_ptr->cur_offset++] = gif_ptr->lsd_ptr->bc_index; 1127 dst_buf[gif_ptr->cur_offset++] = gif_ptr->lsd_ptr->bc_index;
1126 dst_buf[gif_ptr->cur_offset++] = gif_ptr->lsd_ptr->pixel_aspect; 1128 dst_buf[gif_ptr->cur_offset++] = gif_ptr->lsd_ptr->pixel_aspect;
1127 if (gif_ptr->global_pal) { 1129 if (gif_ptr->global_pal) {
1128 FX_WORD size = sizeof(GifPalette) * gif_ptr->gpal_num; 1130 FX_WORD size = sizeof(GifPalette) * gif_ptr->gpal_num;
1129 if (!_gif_grow_buf(dst_buf, dst_len, gif_ptr->cur_offset + size)) { 1131 if (!gif_grow_buf(dst_buf, dst_len, gif_ptr->cur_offset + size)) {
1130 return FALSE; 1132 return FALSE;
1131 } 1133 }
1132 FXSYS_memcpy(&dst_buf[gif_ptr->cur_offset], gif_ptr->global_pal, size); 1134 FXSYS_memcpy(&dst_buf[gif_ptr->cur_offset], gif_ptr->global_pal, size);
1133 gif_ptr->cur_offset += size; 1135 gif_ptr->cur_offset += size;
1134 } 1136 }
1135 return TRUE; 1137 return TRUE;
1136 } 1138 }
1137 void interlace_buf(const uint8_t* buf, FX_DWORD pitch, FX_DWORD height) { 1139 void interlace_buf(const uint8_t* buf, FX_DWORD pitch, FX_DWORD height) {
1138 CFX_ArrayTemplate<uint8_t*> pass[4]; 1140 CFX_ArrayTemplate<uint8_t*> pass[4];
1139 int i, j; 1141 int i, j;
(...skipping 18 matching lines...) Expand all
1158 pass[j].Add(temp); 1160 pass[j].Add(temp);
1159 row++; 1161 row++;
1160 } 1162 }
1161 for (i = 0, row = 0; i < 4; i++) { 1163 for (i = 0, row = 0; i < 4; i++) {
1162 for (j = 0; j < pass[i].GetSize(); j++, row++) { 1164 for (j = 0; j < pass[i].GetSize(); j++, row++) {
1163 FXSYS_memcpy((uint8_t*)&buf[pitch * row], pass[i].GetAt(j), pitch); 1165 FXSYS_memcpy((uint8_t*)&buf[pitch * row], pass[i].GetAt(j), pitch);
1164 FX_Free(pass[i].GetAt(j)); 1166 FX_Free(pass[i].GetAt(j));
1165 } 1167 }
1166 } 1168 }
1167 } 1169 }
1168 static void _gif_write_block_data(const uint8_t* src_buf, 1170 static void gif_write_block_data(const uint8_t* src_buf,
1169 FX_DWORD src_len, 1171 FX_DWORD src_len,
1170 uint8_t*& dst_buf, 1172 uint8_t*& dst_buf,
1171 FX_DWORD& dst_len, 1173 FX_DWORD& dst_len,
1172 FX_DWORD& dst_offset) { 1174 FX_DWORD& dst_offset) {
1173 FX_DWORD src_offset = 0; 1175 FX_DWORD src_offset = 0;
1174 while (src_len > GIF_DATA_BLOCK) { 1176 while (src_len > GIF_DATA_BLOCK) {
1175 dst_buf[dst_offset++] = GIF_DATA_BLOCK; 1177 dst_buf[dst_offset++] = GIF_DATA_BLOCK;
1176 FXSYS_memcpy(&dst_buf[dst_offset], &src_buf[src_offset], GIF_DATA_BLOCK); 1178 FXSYS_memcpy(&dst_buf[dst_offset], &src_buf[src_offset], GIF_DATA_BLOCK);
1177 dst_offset += GIF_DATA_BLOCK; 1179 dst_offset += GIF_DATA_BLOCK;
1178 src_offset += GIF_DATA_BLOCK; 1180 src_offset += GIF_DATA_BLOCK;
1179 src_len -= GIF_DATA_BLOCK; 1181 src_len -= GIF_DATA_BLOCK;
1180 } 1182 }
1181 dst_buf[dst_offset++] = (uint8_t)src_len; 1183 dst_buf[dst_offset++] = (uint8_t)src_len;
1182 FXSYS_memcpy(&dst_buf[dst_offset], &src_buf[src_offset], src_len); 1184 FXSYS_memcpy(&dst_buf[dst_offset], &src_buf[src_offset], src_len);
1183 dst_offset += src_len; 1185 dst_offset += src_len;
1184 } 1186 }
1185 static FX_BOOL _gif_write_data(gif_compress_struct_p gif_ptr, 1187 static FX_BOOL gif_write_data(gif_compress_struct_p gif_ptr,
1186 uint8_t*& dst_buf, 1188 uint8_t*& dst_buf,
1187 FX_DWORD& dst_len) { 1189 FX_DWORD& dst_len) {
1188 if (!_gif_grow_buf(dst_buf, dst_len, gif_ptr->cur_offset + GIF_DATA_BLOCK)) { 1190 if (!gif_grow_buf(dst_buf, dst_len, gif_ptr->cur_offset + GIF_DATA_BLOCK)) {
1189 return FALSE; 1191 return FALSE;
1190 } 1192 }
1191 #ifdef GIF_SUPPORT_GRAPHIC_CONTROL_EXTENSION 1193 #ifdef GIF_SUPPORT_GRAPHIC_CONTROL_EXTENSION
1192 if (FXSYS_memcmp(gif_ptr->header_ptr->version, "89a", 3) == 0) { 1194 if (FXSYS_memcmp(gif_ptr->header_ptr->version, "89a", 3) == 0) {
1193 dst_buf[gif_ptr->cur_offset++] = GIF_SIG_EXTENSION; 1195 dst_buf[gif_ptr->cur_offset++] = GIF_SIG_EXTENSION;
1194 dst_buf[gif_ptr->cur_offset++] = GIF_BLOCK_GCE; 1196 dst_buf[gif_ptr->cur_offset++] = GIF_BLOCK_GCE;
1195 gif_ptr->gce_ptr->block_size = 4; 1197 gif_ptr->gce_ptr->block_size = 4;
1196 dst_buf[gif_ptr->cur_offset++] = gif_ptr->gce_ptr->block_size; 1198 dst_buf[gif_ptr->cur_offset++] = gif_ptr->gce_ptr->block_size;
1197 gif_ptr->gce_ptr->gce_flag = 0; 1199 gif_ptr->gce_ptr->gce_flag = 0;
1198 dst_buf[gif_ptr->cur_offset++] = gif_ptr->gce_ptr->gce_flag; 1200 dst_buf[gif_ptr->cur_offset++] = gif_ptr->gce_ptr->gce_flag;
1199 gif_ptr->gce_ptr->delay_time = 10; 1201 gif_ptr->gce_ptr->delay_time = 10;
1200 _SetWord_LSBFirst(dst_buf + gif_ptr->cur_offset, 1202 SetWord_LSBFirst(dst_buf + gif_ptr->cur_offset,
1201 gif_ptr->gce_ptr->delay_time); 1203 gif_ptr->gce_ptr->delay_time);
1202 gif_ptr->cur_offset += 2; 1204 gif_ptr->cur_offset += 2;
1203 gif_ptr->gce_ptr->trans_index = 0; 1205 gif_ptr->gce_ptr->trans_index = 0;
1204 dst_buf[gif_ptr->cur_offset++] = gif_ptr->gce_ptr->trans_index; 1206 dst_buf[gif_ptr->cur_offset++] = gif_ptr->gce_ptr->trans_index;
1205 dst_buf[gif_ptr->cur_offset++] = 0; 1207 dst_buf[gif_ptr->cur_offset++] = 0;
1206 } 1208 }
1207 #endif 1209 #endif
1208 dst_buf[gif_ptr->cur_offset++] = GIF_SIG_IMAGE; 1210 dst_buf[gif_ptr->cur_offset++] = GIF_SIG_IMAGE;
1209 _SetWord_LSBFirst(dst_buf + gif_ptr->cur_offset, 1211 SetWord_LSBFirst(dst_buf + gif_ptr->cur_offset,
1210 gif_ptr->image_info_ptr->left); 1212 gif_ptr->image_info_ptr->left);
1211 gif_ptr->cur_offset += 2; 1213 gif_ptr->cur_offset += 2;
1212 _SetWord_LSBFirst(dst_buf + gif_ptr->cur_offset, 1214 SetWord_LSBFirst(dst_buf + gif_ptr->cur_offset, gif_ptr->image_info_ptr->top);
1213 gif_ptr->image_info_ptr->top);
1214 gif_ptr->cur_offset += 2; 1215 gif_ptr->cur_offset += 2;
1215 _SetWord_LSBFirst(dst_buf + gif_ptr->cur_offset, 1216 SetWord_LSBFirst(dst_buf + gif_ptr->cur_offset,
1216 gif_ptr->image_info_ptr->width); 1217 gif_ptr->image_info_ptr->width);
1217 gif_ptr->cur_offset += 2; 1218 gif_ptr->cur_offset += 2;
1218 _SetWord_LSBFirst(dst_buf + gif_ptr->cur_offset, 1219 SetWord_LSBFirst(dst_buf + gif_ptr->cur_offset,
1219 gif_ptr->image_info_ptr->height); 1220 gif_ptr->image_info_ptr->height);
1220 gif_ptr->cur_offset += 2; 1221 gif_ptr->cur_offset += 2;
1221 GifLF& lf = (GifLF&)gif_ptr->image_info_ptr->local_flag; 1222 GifLF& lf = (GifLF&)gif_ptr->image_info_ptr->local_flag;
1222 dst_buf[gif_ptr->cur_offset++] = gif_ptr->image_info_ptr->local_flag; 1223 dst_buf[gif_ptr->cur_offset++] = gif_ptr->image_info_ptr->local_flag;
1223 if (gif_ptr->local_pal) { 1224 if (gif_ptr->local_pal) {
1224 FX_DWORD pal_size = sizeof(GifPalette) * gif_ptr->lpal_num; 1225 FX_DWORD pal_size = sizeof(GifPalette) * gif_ptr->lpal_num;
1225 if (!_gif_grow_buf(dst_buf, dst_len, pal_size + gif_ptr->cur_offset)) { 1226 if (!gif_grow_buf(dst_buf, dst_len, pal_size + gif_ptr->cur_offset)) {
1226 return FALSE; 1227 return FALSE;
1227 } 1228 }
1228 FXSYS_memcpy(&dst_buf[gif_ptr->cur_offset], gif_ptr->local_pal, pal_size); 1229 FXSYS_memcpy(&dst_buf[gif_ptr->cur_offset], gif_ptr->local_pal, pal_size);
1229 gif_ptr->cur_offset += pal_size; 1230 gif_ptr->cur_offset += pal_size;
1230 } 1231 }
1231 if (lf.interlace) { 1232 if (lf.interlace) {
1232 interlace_buf(gif_ptr->src_buf, gif_ptr->src_pitch, 1233 interlace_buf(gif_ptr->src_buf, gif_ptr->src_pitch,
1233 gif_ptr->image_info_ptr->height); 1234 gif_ptr->image_info_ptr->height);
1234 } 1235 }
1235 uint8_t code_bit = lf.pal_bits; 1236 uint8_t code_bit = lf.pal_bits;
(...skipping 12 matching lines...) Expand all
1248 return FALSE; 1249 return FALSE;
1249 } 1250 }
1250 } 1251 }
1251 gif_ptr->img_encoder_ptr->Finish(dst_buf, dst_len, gif_ptr->cur_offset); 1252 gif_ptr->img_encoder_ptr->Finish(dst_buf, dst_len, gif_ptr->cur_offset);
1252 dst_buf[gif_ptr->cur_offset++] = 0; 1253 dst_buf[gif_ptr->cur_offset++] = 0;
1253 #ifdef GIF_SUPPORT_COMMENT_EXTENSION 1254 #ifdef GIF_SUPPORT_COMMENT_EXTENSION
1254 if (FXSYS_memcmp(gif_ptr->header_ptr->version, "89a", 3) == 0 && 1255 if (FXSYS_memcmp(gif_ptr->header_ptr->version, "89a", 3) == 0 &&
1255 gif_ptr->cmt_data_ptr) { 1256 gif_ptr->cmt_data_ptr) {
1256 dst_buf[gif_ptr->cur_offset++] = GIF_SIG_EXTENSION; 1257 dst_buf[gif_ptr->cur_offset++] = GIF_SIG_EXTENSION;
1257 dst_buf[gif_ptr->cur_offset++] = GIF_BLOCK_CE; 1258 dst_buf[gif_ptr->cur_offset++] = GIF_BLOCK_CE;
1258 _gif_write_block_data(gif_ptr->cmt_data_ptr, gif_ptr->cmt_data_len, dst_buf, 1259 gif_write_block_data(gif_ptr->cmt_data_ptr, gif_ptr->cmt_data_len, dst_buf,
1259 dst_len, gif_ptr->cur_offset); 1260 dst_len, gif_ptr->cur_offset);
1260 dst_buf[gif_ptr->cur_offset++] = 0; 1261 dst_buf[gif_ptr->cur_offset++] = 0;
1261 } 1262 }
1262 #endif 1263 #endif
1263 #ifdef GIF_SUPPORT_PLAIN_TEXT_EXTENSION 1264 #ifdef GIF_SUPPORT_PLAIN_TEXT_EXTENSION
1264 if (FXSYS_memcmp(gif_ptr->header_ptr->version, "89a", 3) == 0 && 1265 if (FXSYS_memcmp(gif_ptr->header_ptr->version, "89a", 3) == 0 &&
1265 gif_ptr->pte_data_ptr) { 1266 gif_ptr->pte_data_ptr) {
1266 dst_buf[gif_ptr->cur_offset++] = GIF_SIG_EXTENSION; 1267 dst_buf[gif_ptr->cur_offset++] = GIF_SIG_EXTENSION;
1267 dst_buf[gif_ptr->cur_offset++] = GIF_BLOCK_PTE; 1268 dst_buf[gif_ptr->cur_offset++] = GIF_BLOCK_PTE;
1268 dst_buf[gif_ptr->cur_offset++] = gif_ptr->pte_ptr->block_size; 1269 dst_buf[gif_ptr->cur_offset++] = gif_ptr->pte_ptr->block_size;
1269 _SetWord_LSBFirst(dst_buf + gif_ptr->cur_offset, 1270 SetWord_LSBFirst(dst_buf + gif_ptr->cur_offset,
1270 gif_ptr->pte_ptr->grid_left); 1271 gif_ptr->pte_ptr->grid_left);
1271 gif_ptr->cur_offset += 2; 1272 gif_ptr->cur_offset += 2;
1272 _SetWord_LSBFirst(dst_buf + gif_ptr->cur_offset, 1273 SetWord_LSBFirst(dst_buf + gif_ptr->cur_offset, gif_ptr->pte_ptr->grid_top);
1273 gif_ptr->pte_ptr->grid_top);
1274 gif_ptr->cur_offset += 2; 1274 gif_ptr->cur_offset += 2;
1275 _SetWord_LSBFirst(dst_buf + gif_ptr->cur_offset, 1275 SetWord_LSBFirst(dst_buf + gif_ptr->cur_offset,
1276 gif_ptr->pte_ptr->grid_width); 1276 gif_ptr->pte_ptr->grid_width);
1277 gif_ptr->cur_offset += 2; 1277 gif_ptr->cur_offset += 2;
1278 _SetWord_LSBFirst(dst_buf + gif_ptr->cur_offset, 1278 SetWord_LSBFirst(dst_buf + gif_ptr->cur_offset,
1279 gif_ptr->pte_ptr->grid_height); 1279 gif_ptr->pte_ptr->grid_height);
1280 gif_ptr->cur_offset += 2; 1280 gif_ptr->cur_offset += 2;
1281 _SetWord_LSBFirst(dst_buf + gif_ptr->cur_offset, 1281 SetWord_LSBFirst(dst_buf + gif_ptr->cur_offset,
1282 gif_ptr->pte_ptr->char_width); 1282 gif_ptr->pte_ptr->char_width);
1283 gif_ptr->cur_offset += 2; 1283 gif_ptr->cur_offset += 2;
1284 _SetWord_LSBFirst(dst_buf + gif_ptr->cur_offset, 1284 SetWord_LSBFirst(dst_buf + gif_ptr->cur_offset,
1285 gif_ptr->pte_ptr->char_height); 1285 gif_ptr->pte_ptr->char_height);
1286 gif_ptr->cur_offset += 2; 1286 gif_ptr->cur_offset += 2;
1287 _SetWord_LSBFirst(dst_buf + gif_ptr->cur_offset, 1287 SetWord_LSBFirst(dst_buf + gif_ptr->cur_offset, gif_ptr->pte_ptr->fc_index);
1288 gif_ptr->pte_ptr->fc_index);
1289 gif_ptr->cur_offset += 2; 1288 gif_ptr->cur_offset += 2;
1290 _SetWord_LSBFirst(dst_buf + gif_ptr->cur_offset, 1289 SetWord_LSBFirst(dst_buf + gif_ptr->cur_offset, gif_ptr->pte_ptr->bc_index);
1291 gif_ptr->pte_ptr->bc_index);
1292 gif_ptr->cur_offset += 2; 1290 gif_ptr->cur_offset += 2;
1293 _gif_write_block_data(gif_ptr->pte_data_ptr, gif_ptr->pte_data_len, dst_buf, 1291 gif_write_block_data(gif_ptr->pte_data_ptr, gif_ptr->pte_data_len, dst_buf,
1294 dst_len, gif_ptr->cur_offset); 1292 dst_len, gif_ptr->cur_offset);
1295 gif_ptr->cur_offset += gif_ptr->pte_data_len; 1293 gif_ptr->cur_offset += gif_ptr->pte_data_len;
1296 dst_buf[gif_ptr->cur_offset++] = 0; 1294 dst_buf[gif_ptr->cur_offset++] = 0;
1297 } 1295 }
1298 #endif 1296 #endif
1299 #ifdef GIF_SUPPORT_APPLICATION_EXTENSION 1297 #ifdef GIF_SUPPORT_APPLICATION_EXTENSION
1300 if (FXSYS_memcmp(gif_ptr->header_ptr->version, "89a", 3) == 0 && 1298 if (FXSYS_memcmp(gif_ptr->header_ptr->version, "89a", 3) == 0 &&
1301 gif_ptr->app_data) { 1299 gif_ptr->app_data) {
1302 dst_buf[gif_ptr->cur_offset++] = GIF_SIG_EXTENSION; 1300 dst_buf[gif_ptr->cur_offset++] = GIF_SIG_EXTENSION;
1303 dst_buf[gif_ptr->cur_offset++] = GIF_BLOCK_AE; 1301 dst_buf[gif_ptr->cur_offset++] = GIF_BLOCK_AE;
1304 dst_buf[gif_ptr->cur_offset++] = 11; 1302 dst_buf[gif_ptr->cur_offset++] = 11;
1305 FXSYS_memcpy(&dst_buf[gif_ptr->cur_offset], gif_ptr->app_identify, 8); 1303 FXSYS_memcpy(&dst_buf[gif_ptr->cur_offset], gif_ptr->app_identify, 8);
1306 gif_ptr->cur_offset += 8; 1304 gif_ptr->cur_offset += 8;
1307 FXSYS_memcpy(&dst_buf[gif_ptr->cur_offset], gif_ptr->app_authentication, 8); 1305 FXSYS_memcpy(&dst_buf[gif_ptr->cur_offset], gif_ptr->app_authentication, 8);
1308 gif_ptr->cur_offset += 3; 1306 gif_ptr->cur_offset += 3;
1309 FXSYS_memcpy(&dst_buf[gif_ptr->cur_offset], gif_ptr->app_data, 1307 FXSYS_memcpy(&dst_buf[gif_ptr->cur_offset], gif_ptr->app_data,
1310 gif_ptr->app_data_size); 1308 gif_ptr->app_data_size);
1311 gif_ptr->cur_offset += gif_ptr->app_data_size; 1309 gif_ptr->cur_offset += gif_ptr->app_data_size;
1312 dst_buf[gif_ptr->cur_offset++] = 0; 1310 dst_buf[gif_ptr->cur_offset++] = 0;
1313 } 1311 }
1314 #endif 1312 #endif
1315 dst_buf[gif_ptr->cur_offset++] = GIF_SIG_TRAILER; 1313 dst_buf[gif_ptr->cur_offset++] = GIF_SIG_TRAILER;
1316 return TRUE; 1314 return TRUE;
1317 } 1315 }
1318 FX_BOOL _gif_encode(gif_compress_struct_p gif_ptr, 1316 FX_BOOL gif_encode(gif_compress_struct_p gif_ptr,
1319 uint8_t*& dst_buf, 1317 uint8_t*& dst_buf,
1320 FX_DWORD& dst_len) { 1318 FX_DWORD& dst_len) {
1321 if (!_gif_write_header(gif_ptr, dst_buf, dst_len)) { 1319 if (!gif_write_header(gif_ptr, dst_buf, dst_len)) {
1322 return FALSE; 1320 return FALSE;
1323 } 1321 }
1324 FX_DWORD cur_offset = gif_ptr->cur_offset; 1322 FX_DWORD cur_offset = gif_ptr->cur_offset;
1325 FX_BOOL res = TRUE; 1323 FX_BOOL res = TRUE;
1326 if (gif_ptr->frames) { 1324 if (gif_ptr->frames) {
1327 gif_ptr->cur_offset--; 1325 gif_ptr->cur_offset--;
1328 } 1326 }
1329 if (!_gif_write_data(gif_ptr, dst_buf, dst_len)) { 1327 if (!gif_write_data(gif_ptr, dst_buf, dst_len)) {
1330 gif_ptr->cur_offset = cur_offset; 1328 gif_ptr->cur_offset = cur_offset;
1331 res = FALSE; 1329 res = FALSE;
1332 } 1330 }
1333 dst_len = gif_ptr->cur_offset; 1331 dst_len = gif_ptr->cur_offset;
1334 dst_buf[dst_len - 1] = GIF_SIG_TRAILER; 1332 dst_buf[dst_len - 1] = GIF_SIG_TRAILER;
1335 if (res) { 1333 if (res) {
1336 gif_ptr->frames++; 1334 gif_ptr->frames++;
1337 } 1335 }
1338 return res; 1336 return res;
1339 } 1337 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698