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

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

Issue 2477443002: Remove FX_BOOL from core (Closed)
Patch Set: Created 4 years, 1 month 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
« no previous file with comments | « core/fxcodec/lgif/fx_gif.h ('k') | core/fxcrt/extension.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/fxcodec/lgif/fx_gif.h" 7 #include "core/fxcodec/lgif/fx_gif.h"
8 8
9 #include "core/fxcodec/lbmp/fx_bmp.h" 9 #include "core/fxcodec/lbmp/fx_bmp.h"
10 10
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 code_next = code_end + 1; 51 code_next = code_end + 1;
52 code_old = (uint16_t)-1; 52 code_old = (uint16_t)-1;
53 FXSYS_memset(code_table, 0, sizeof(tag_Table) * GIF_MAX_LZW_CODE); 53 FXSYS_memset(code_table, 0, sizeof(tag_Table) * GIF_MAX_LZW_CODE);
54 FXSYS_memset(stack, 0, GIF_MAX_LZW_CODE); 54 FXSYS_memset(stack, 0, GIF_MAX_LZW_CODE);
55 for (uint16_t i = 0; i < code_clear; i++) { 55 for (uint16_t i = 0; i < code_clear; i++) {
56 code_table[i].suffix = (uint8_t)i; 56 code_table[i].suffix = (uint8_t)i;
57 } 57 }
58 } 58 }
59 void CGifLZWDecoder::DecodeString(uint16_t code) { 59 void CGifLZWDecoder::DecodeString(uint16_t code) {
60 stack_size = 0; 60 stack_size = 0;
61 while (TRUE) { 61 while (true) {
62 ASSERT(code <= code_next); 62 ASSERT(code <= code_next);
63 if (code < code_clear || code > code_next) { 63 if (code < code_clear || code > code_next) {
64 break; 64 break;
65 } 65 }
66 stack[GIF_MAX_LZW_CODE - 1 - stack_size++] = code_table[code].suffix; 66 stack[GIF_MAX_LZW_CODE - 1 - stack_size++] = code_table[code].suffix;
67 code = code_table[code].prefix; 67 code = code_table[code].prefix;
68 } 68 }
69 stack[GIF_MAX_LZW_CODE - 1 - stack_size++] = (uint8_t)code; 69 stack[GIF_MAX_LZW_CODE - 1 - stack_size++] = (uint8_t)code;
70 code_first = (uint8_t)code; 70 code_first = (uint8_t)code;
71 } 71 }
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 stack_size = 0; 156 stack_size = 0;
157 } 157 }
158 } 158 }
159 } 159 }
160 if (avail_in == 0) { 160 if (avail_in == 0) {
161 des_size = i; 161 des_size = i;
162 return 2; 162 return 2;
163 } 163 }
164 return 0; 164 return 0;
165 } 165 }
166 static FX_BOOL gif_grow_buf(uint8_t*& dst_buf, 166 static bool gif_grow_buf(uint8_t*& dst_buf, uint32_t& dst_len, uint32_t size) {
167 uint32_t& dst_len,
168 uint32_t size) {
169 if (dst_len < size) { 167 if (dst_len < size) {
170 uint32_t len_org = dst_len; 168 uint32_t len_org = dst_len;
171 while (dst_buf && dst_len < size) { 169 while (dst_buf && dst_len < size) {
172 dst_len <<= 1; 170 dst_len <<= 1;
173 // TODO(thestig): Probably should be a try-realloc here. 171 // TODO(thestig): Probably should be a try-realloc here.
174 dst_buf = FX_Realloc(uint8_t, dst_buf, dst_len); 172 dst_buf = FX_Realloc(uint8_t, dst_buf, dst_len);
175 } 173 }
176 if (!dst_buf) { 174 if (!dst_buf) {
177 dst_len = size; 175 dst_len = size;
178 dst_buf = FX_Realloc(uint8_t, dst_buf, dst_len); 176 dst_buf = FX_Realloc(uint8_t, dst_buf, dst_len);
179 } 177 }
180 FXSYS_memset(dst_buf + len_org, 0, dst_len - len_org); 178 FXSYS_memset(dst_buf + len_org, 0, dst_len - len_org);
181 return !!dst_buf; 179 return !!dst_buf;
182 } 180 }
183 return TRUE; 181 return true;
184 } 182 }
185 static inline void gif_cut_index(uint8_t& val, 183 static inline void gif_cut_index(uint8_t& val,
186 uint32_t index, 184 uint32_t index,
187 uint8_t index_bit, 185 uint8_t index_bit,
188 uint8_t index_bit_use, 186 uint8_t index_bit_use,
189 uint8_t bit_use) { 187 uint8_t bit_use) {
190 uint32_t cut = ((1 << (index_bit - index_bit_use)) - 1) << index_bit_use; 188 uint32_t cut = ((1 << (index_bit - index_bit_use)) - 1) << index_bit_use;
191 val |= ((index & cut) >> index_bit_use) << bit_use; 189 val |= ((index & cut) >> index_bit_use) << bit_use;
192 } 190 }
193 static inline uint8_t gif_cut_buf(const uint8_t* buf, 191 static inline uint8_t gif_cut_buf(const uint8_t* buf,
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
311 } 309 }
312 } 310 }
313 if (index == code_end) { 311 if (index == code_end) {
314 index_buf_len++; 312 index_buf_len++;
315 WriteBlock(dst_buf, dst_len, offset); 313 WriteBlock(dst_buf, dst_len, offset);
316 } 314 }
317 if (index_num++ >> index_bit_cur) { 315 if (index_num++ >> index_bit_cur) {
318 index_bit_cur++; 316 index_bit_cur++;
319 } 317 }
320 } 318 }
321 FX_BOOL CGifLZWEncoder::Encode(const uint8_t* src_buf, 319 bool CGifLZWEncoder::Encode(const uint8_t* src_buf,
322 uint32_t src_len, 320 uint32_t src_len,
323 uint8_t*& dst_buf, 321 uint8_t*& dst_buf,
324 uint32_t& dst_len, 322 uint32_t& dst_len,
325 uint32_t& offset) { 323 uint32_t& offset) {
326 uint8_t suffix; 324 uint8_t suffix;
327 if (setjmp(jmp)) { 325 if (setjmp(jmp)) {
328 return FALSE; 326 return false;
329 } 327 }
330 while (src_bit_num < src_len) { 328 while (src_bit_num < src_len) {
331 if (!LookUpInTable(src_buf, src_offset, src_bit_offset)) { 329 if (!LookUpInTable(src_buf, src_offset, src_bit_offset)) {
332 EncodeString(code_table[index_num].prefix, dst_buf, dst_len, offset); 330 EncodeString(code_table[index_num].prefix, dst_buf, dst_len, offset);
333 if (index_num == GIF_MAX_LZW_CODE) { 331 if (index_num == GIF_MAX_LZW_CODE) {
334 suffix = code_table[index_num - 1].suffix; 332 suffix = code_table[index_num - 1].suffix;
335 EncodeString(code_clear, dst_buf, dst_len, offset); 333 EncodeString(code_clear, dst_buf, dst_len, offset);
336 ClearTable(); 334 ClearTable();
337 code_table[index_num].prefix = suffix; 335 code_table[index_num].prefix = suffix;
338 code_table[index_num].suffix = gif_cut_buf( 336 code_table[index_num].suffix = gif_cut_buf(
339 src_buf, src_offset, src_bit_cut, src_bit_offset, src_bit_num); 337 src_buf, src_offset, src_bit_cut, src_bit_offset, src_bit_num);
340 } else { 338 } else {
341 code_table[index_num].prefix = code_table[index_num - 1].suffix; 339 code_table[index_num].prefix = code_table[index_num - 1].suffix;
342 code_table[index_num].suffix = gif_cut_buf( 340 code_table[index_num].suffix = gif_cut_buf(
343 src_buf, src_offset, src_bit_cut, src_bit_offset, src_bit_num); 341 src_buf, src_offset, src_bit_cut, src_bit_offset, src_bit_num);
344 } 342 }
345 } 343 }
346 } 344 }
347 src_offset = 0; 345 src_offset = 0;
348 src_bit_offset = 0; 346 src_bit_offset = 0;
349 src_bit_num = 0; 347 src_bit_num = 0;
350 return TRUE; 348 return true;
351 } 349 }
352 FX_BOOL CGifLZWEncoder::LookUpInTable(const uint8_t* buf, 350 bool CGifLZWEncoder::LookUpInTable(const uint8_t* buf,
353 uint32_t& offset, 351 uint32_t& offset,
354 uint8_t& out_bit_offset) { 352 uint8_t& out_bit_offset) {
355 for (uint16_t i = table_cur; i < index_num; i++) { 353 for (uint16_t i = table_cur; i < index_num; i++) {
356 if (code_table[i].prefix == code_table[index_num].prefix && 354 if (code_table[i].prefix == code_table[index_num].prefix &&
357 code_table[i].suffix == code_table[index_num].suffix) { 355 code_table[i].suffix == code_table[index_num].suffix) {
358 code_table[index_num].prefix = i; 356 code_table[index_num].prefix = i;
359 code_table[index_num].suffix = 357 code_table[index_num].suffix =
360 gif_cut_buf(buf, offset, src_bit_cut, out_bit_offset, src_bit_num); 358 gif_cut_buf(buf, offset, src_bit_cut, out_bit_offset, src_bit_num);
361 table_cur = i; 359 table_cur = i;
362 return TRUE; 360 return true;
363 } 361 }
364 } 362 }
365 table_cur = code_end + 1; 363 table_cur = code_end + 1;
366 return FALSE; 364 return false;
367 } 365 }
368 void CGifLZWEncoder::Finish(uint8_t*& dst_buf, 366 void CGifLZWEncoder::Finish(uint8_t*& dst_buf,
369 uint32_t& dst_len, 367 uint32_t& dst_len,
370 uint32_t& offset) { 368 uint32_t& offset) {
371 EncodeString(code_table[index_num].prefix, dst_buf, dst_len, offset); 369 EncodeString(code_table[index_num].prefix, dst_buf, dst_len, offset);
372 EncodeString(code_end, dst_buf, dst_len, offset); 370 EncodeString(code_end, dst_buf, dst_len, offset);
373 bit_offset = 0; 371 bit_offset = 0;
374 ClearTable(); 372 ClearTable();
375 } 373 }
376 gif_decompress_struct_p gif_create_decompress() { 374 gif_decompress_struct_p gif_create_decompress() {
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
547 gif_ptr->height = (int)GetWord_LSBFirst((uint8_t*)&gif_lsd_ptr->height); 545 gif_ptr->height = (int)GetWord_LSBFirst((uint8_t*)&gif_lsd_ptr->height);
548 gif_ptr->bc_index = gif_lsd_ptr->bc_index; 546 gif_ptr->bc_index = gif_lsd_ptr->bc_index;
549 gif_ptr->pixel_aspect = gif_lsd_ptr->pixel_aspect; 547 gif_ptr->pixel_aspect = gif_lsd_ptr->pixel_aspect;
550 return 1; 548 return 1;
551 } 549 }
552 int32_t gif_get_frame(gif_decompress_struct_p gif_ptr) { 550 int32_t gif_get_frame(gif_decompress_struct_p gif_ptr) {
553 if (!gif_ptr) 551 if (!gif_ptr)
554 return 0; 552 return 0;
555 553
556 int32_t ret = 1; 554 int32_t ret = 1;
557 while (TRUE) { 555 while (true) {
558 switch (gif_ptr->decode_status) { 556 switch (gif_ptr->decode_status) {
559 case GIF_D_STATUS_TAIL: 557 case GIF_D_STATUS_TAIL:
560 return 1; 558 return 1;
561 case GIF_D_STATUS_SIG: { 559 case GIF_D_STATUS_SIG: {
562 uint8_t* sig_ptr = nullptr; 560 uint8_t* sig_ptr = nullptr;
563 if (!gif_read_data(gif_ptr, &sig_ptr, 1)) 561 if (!gif_read_data(gif_ptr, &sig_ptr, 1))
564 return 2; 562 return 2;
565 563
566 switch (*sig_ptr) { 564 switch (*sig_ptr) {
567 case GIF_SIG_EXTENSION: 565 case GIF_SIG_EXTENSION:
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after
852 } 850 }
853 gif_image_ptr->image_row_buf = FX_Alloc(uint8_t, gif_img_row_bytes); 851 gif_image_ptr->image_row_buf = FX_Alloc(uint8_t, gif_img_row_bytes);
854 GifGCE* gif_img_gce_ptr = gif_image_ptr->image_gce_ptr; 852 GifGCE* gif_img_gce_ptr = gif_image_ptr->image_gce_ptr;
855 int32_t loc_pal_num = 853 int32_t loc_pal_num =
856 ((GifLF*)&gif_image_ptr->image_info_ptr->local_flag)->local_pal 854 ((GifLF*)&gif_image_ptr->image_info_ptr->local_flag)->local_pal
857 ? (2 << ((GifLF*)&gif_image_ptr->image_info_ptr->local_flag) 855 ? (2 << ((GifLF*)&gif_image_ptr->image_info_ptr->local_flag)
858 ->pal_bits) 856 ->pal_bits)
859 : 0; 857 : 0;
860 gif_ptr->avail_in = 0; 858 gif_ptr->avail_in = 0;
861 if (!gif_img_gce_ptr) { 859 if (!gif_img_gce_ptr) {
862 FX_BOOL bRes = gif_ptr->gif_get_record_position_fn( 860 bool bRes = gif_ptr->gif_get_record_position_fn(
863 gif_ptr, gif_image_ptr->image_data_pos, 861 gif_ptr, gif_image_ptr->image_data_pos,
864 gif_image_ptr->image_info_ptr->left, 862 gif_image_ptr->image_info_ptr->left,
865 gif_image_ptr->image_info_ptr->top, 863 gif_image_ptr->image_info_ptr->top,
866 gif_image_ptr->image_info_ptr->width, 864 gif_image_ptr->image_info_ptr->width,
867 gif_image_ptr->image_info_ptr->height, loc_pal_num, 865 gif_image_ptr->image_info_ptr->height, loc_pal_num,
868 gif_image_ptr->local_pal_ptr, 0, 0, -1, 0, 866 gif_image_ptr->local_pal_ptr, 0, 0, -1, 0,
869 (FX_BOOL)((GifLF*)&gif_image_ptr->image_info_ptr->local_flag) 867 (bool)((GifLF*)&gif_image_ptr->image_info_ptr->local_flag)
870 ->interlace); 868 ->interlace);
871 if (!bRes) { 869 if (!bRes) {
872 FX_Free(gif_image_ptr->image_row_buf); 870 FX_Free(gif_image_ptr->image_row_buf);
873 gif_image_ptr->image_row_buf = nullptr; 871 gif_image_ptr->image_row_buf = nullptr;
874 gif_error(gif_ptr, "Error Read Record Position Data"); 872 gif_error(gif_ptr, "Error Read Record Position Data");
875 return 0; 873 return 0;
876 } 874 }
877 } else { 875 } else {
878 FX_BOOL bRes = gif_ptr->gif_get_record_position_fn( 876 bool bRes = gif_ptr->gif_get_record_position_fn(
879 gif_ptr, gif_image_ptr->image_data_pos, 877 gif_ptr, gif_image_ptr->image_data_pos,
880 gif_image_ptr->image_info_ptr->left, 878 gif_image_ptr->image_info_ptr->left,
881 gif_image_ptr->image_info_ptr->top, 879 gif_image_ptr->image_info_ptr->top,
882 gif_image_ptr->image_info_ptr->width, 880 gif_image_ptr->image_info_ptr->width,
883 gif_image_ptr->image_info_ptr->height, loc_pal_num, 881 gif_image_ptr->image_info_ptr->height, loc_pal_num,
884 gif_image_ptr->local_pal_ptr, 882 gif_image_ptr->local_pal_ptr,
885 (int32_t)gif_image_ptr->image_gce_ptr->delay_time, 883 (int32_t)gif_image_ptr->image_gce_ptr->delay_time,
886 (FX_BOOL)((GifCEF*)&gif_image_ptr->image_gce_ptr->gce_flag) 884 (bool)((GifCEF*)&gif_image_ptr->image_gce_ptr->gce_flag)->user_input,
887 ->user_input,
888 ((GifCEF*)&gif_image_ptr->image_gce_ptr->gce_flag)->transparency 885 ((GifCEF*)&gif_image_ptr->image_gce_ptr->gce_flag)->transparency
889 ? (int32_t)gif_image_ptr->image_gce_ptr->trans_index 886 ? (int32_t)gif_image_ptr->image_gce_ptr->trans_index
890 : -1, 887 : -1,
891 (int32_t)((GifCEF*)&gif_image_ptr->image_gce_ptr->gce_flag) 888 (int32_t)((GifCEF*)&gif_image_ptr->image_gce_ptr->gce_flag)
892 ->disposal_method, 889 ->disposal_method,
893 (FX_BOOL)((GifLF*)&gif_image_ptr->image_info_ptr->local_flag) 890 (bool)((GifLF*)&gif_image_ptr->image_info_ptr->local_flag)
894 ->interlace); 891 ->interlace);
895 if (!bRes) { 892 if (!bRes) {
896 FX_Free(gif_image_ptr->image_row_buf); 893 FX_Free(gif_image_ptr->image_row_buf);
897 gif_image_ptr->image_row_buf = nullptr; 894 gif_image_ptr->image_row_buf = nullptr;
898 gif_error(gif_ptr, "Error Read Record Position Data"); 895 gif_error(gif_ptr, "Error Read Record Position Data");
899 return 0; 896 return 0;
900 } 897 }
901 } 898 }
902 if (!gif_ptr->img_decoder_ptr) 899 if (!gif_ptr->img_decoder_ptr)
903 gif_ptr->img_decoder_ptr = new CGifLZWDecoder(gif_ptr->err_ptr); 900 gif_ptr->img_decoder_ptr = new CGifLZWDecoder(gif_ptr->err_ptr);
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
1032 *avail_buf_ptr = nullptr; 1029 *avail_buf_ptr = nullptr;
1033 if (gif_ptr->avail_in > 0) { 1030 if (gif_ptr->avail_in > 0) {
1034 *avail_buf_ptr = gif_ptr->next_in; 1031 *avail_buf_ptr = gif_ptr->next_in;
1035 } 1032 }
1036 } 1033 }
1037 return gif_ptr->avail_in; 1034 return gif_ptr->avail_in;
1038 } 1035 }
1039 int32_t gif_get_frame_num(gif_decompress_struct_p gif_ptr) { 1036 int32_t gif_get_frame_num(gif_decompress_struct_p gif_ptr) {
1040 return gif_ptr->img_ptr_arr_ptr->GetSize(); 1037 return gif_ptr->img_ptr_arr_ptr->GetSize();
1041 } 1038 }
1042 static FX_BOOL gif_write_header(gif_compress_struct_p gif_ptr, 1039 static bool gif_write_header(gif_compress_struct_p gif_ptr,
1043 uint8_t*& dst_buf, 1040 uint8_t*& dst_buf,
1044 uint32_t& dst_len) { 1041 uint32_t& dst_len) {
1045 if (gif_ptr->cur_offset) { 1042 if (gif_ptr->cur_offset) {
1046 return TRUE; 1043 return true;
1047 } 1044 }
1048 dst_len = sizeof(GifHeader) + sizeof(GifLSD) + sizeof(GifGF); 1045 dst_len = sizeof(GifHeader) + sizeof(GifLSD) + sizeof(GifGF);
1049 dst_buf = FX_TryAlloc(uint8_t, dst_len); 1046 dst_buf = FX_TryAlloc(uint8_t, dst_len);
1050 if (!dst_buf) 1047 if (!dst_buf)
1051 return FALSE; 1048 return false;
1052 1049
1053 FXSYS_memset(dst_buf, 0, dst_len); 1050 FXSYS_memset(dst_buf, 0, dst_len);
1054 FXSYS_memcpy(dst_buf, gif_ptr->header_ptr, sizeof(GifHeader)); 1051 FXSYS_memcpy(dst_buf, gif_ptr->header_ptr, sizeof(GifHeader));
1055 gif_ptr->cur_offset += sizeof(GifHeader); 1052 gif_ptr->cur_offset += sizeof(GifHeader);
1056 SetWord_LSBFirst(dst_buf + gif_ptr->cur_offset, gif_ptr->lsd_ptr->width); 1053 SetWord_LSBFirst(dst_buf + gif_ptr->cur_offset, gif_ptr->lsd_ptr->width);
1057 gif_ptr->cur_offset += 2; 1054 gif_ptr->cur_offset += 2;
1058 SetWord_LSBFirst(dst_buf + gif_ptr->cur_offset, gif_ptr->lsd_ptr->height); 1055 SetWord_LSBFirst(dst_buf + gif_ptr->cur_offset, gif_ptr->lsd_ptr->height);
1059 gif_ptr->cur_offset += 2; 1056 gif_ptr->cur_offset += 2;
1060 dst_buf[gif_ptr->cur_offset++] = gif_ptr->lsd_ptr->global_flag; 1057 dst_buf[gif_ptr->cur_offset++] = gif_ptr->lsd_ptr->global_flag;
1061 dst_buf[gif_ptr->cur_offset++] = gif_ptr->lsd_ptr->bc_index; 1058 dst_buf[gif_ptr->cur_offset++] = gif_ptr->lsd_ptr->bc_index;
1062 dst_buf[gif_ptr->cur_offset++] = gif_ptr->lsd_ptr->pixel_aspect; 1059 dst_buf[gif_ptr->cur_offset++] = gif_ptr->lsd_ptr->pixel_aspect;
1063 if (gif_ptr->global_pal) { 1060 if (gif_ptr->global_pal) {
1064 uint16_t size = sizeof(GifPalette) * gif_ptr->gpal_num; 1061 uint16_t size = sizeof(GifPalette) * gif_ptr->gpal_num;
1065 if (!gif_grow_buf(dst_buf, dst_len, gif_ptr->cur_offset + size)) { 1062 if (!gif_grow_buf(dst_buf, dst_len, gif_ptr->cur_offset + size)) {
1066 return FALSE; 1063 return false;
1067 } 1064 }
1068 FXSYS_memcpy(&dst_buf[gif_ptr->cur_offset], gif_ptr->global_pal, size); 1065 FXSYS_memcpy(&dst_buf[gif_ptr->cur_offset], gif_ptr->global_pal, size);
1069 gif_ptr->cur_offset += size; 1066 gif_ptr->cur_offset += size;
1070 } 1067 }
1071 return TRUE; 1068 return true;
1072 } 1069 }
1073 void interlace_buf(const uint8_t* buf, uint32_t pitch, uint32_t height) { 1070 void interlace_buf(const uint8_t* buf, uint32_t pitch, uint32_t height) {
1074 CFX_ArrayTemplate<uint8_t*> pass[4]; 1071 CFX_ArrayTemplate<uint8_t*> pass[4];
1075 int i, j; 1072 int i, j;
1076 uint32_t row; 1073 uint32_t row;
1077 row = 0; 1074 row = 0;
1078 uint8_t* temp; 1075 uint8_t* temp;
1079 while (row < height) { 1076 while (row < height) {
1080 if (row % 8 == 0) { 1077 if (row % 8 == 0) {
1081 j = 0; 1078 j = 0;
(...skipping 26 matching lines...) Expand all
1108 dst_buf[dst_offset++] = GIF_DATA_BLOCK; 1105 dst_buf[dst_offset++] = GIF_DATA_BLOCK;
1109 FXSYS_memcpy(&dst_buf[dst_offset], &src_buf[src_offset], GIF_DATA_BLOCK); 1106 FXSYS_memcpy(&dst_buf[dst_offset], &src_buf[src_offset], GIF_DATA_BLOCK);
1110 dst_offset += GIF_DATA_BLOCK; 1107 dst_offset += GIF_DATA_BLOCK;
1111 src_offset += GIF_DATA_BLOCK; 1108 src_offset += GIF_DATA_BLOCK;
1112 src_len -= GIF_DATA_BLOCK; 1109 src_len -= GIF_DATA_BLOCK;
1113 } 1110 }
1114 dst_buf[dst_offset++] = (uint8_t)src_len; 1111 dst_buf[dst_offset++] = (uint8_t)src_len;
1115 FXSYS_memcpy(&dst_buf[dst_offset], &src_buf[src_offset], src_len); 1112 FXSYS_memcpy(&dst_buf[dst_offset], &src_buf[src_offset], src_len);
1116 dst_offset += src_len; 1113 dst_offset += src_len;
1117 } 1114 }
1118 static FX_BOOL gif_write_data(gif_compress_struct_p gif_ptr, 1115 static bool gif_write_data(gif_compress_struct_p gif_ptr,
1119 uint8_t*& dst_buf, 1116 uint8_t*& dst_buf,
1120 uint32_t& dst_len) { 1117 uint32_t& dst_len) {
1121 if (!gif_grow_buf(dst_buf, dst_len, gif_ptr->cur_offset + GIF_DATA_BLOCK)) { 1118 if (!gif_grow_buf(dst_buf, dst_len, gif_ptr->cur_offset + GIF_DATA_BLOCK)) {
1122 return FALSE; 1119 return false;
1123 } 1120 }
1124 if (FXSYS_memcmp(gif_ptr->header_ptr->version, "89a", 3) == 0) { 1121 if (FXSYS_memcmp(gif_ptr->header_ptr->version, "89a", 3) == 0) {
1125 dst_buf[gif_ptr->cur_offset++] = GIF_SIG_EXTENSION; 1122 dst_buf[gif_ptr->cur_offset++] = GIF_SIG_EXTENSION;
1126 dst_buf[gif_ptr->cur_offset++] = GIF_BLOCK_GCE; 1123 dst_buf[gif_ptr->cur_offset++] = GIF_BLOCK_GCE;
1127 gif_ptr->gce_ptr->block_size = 4; 1124 gif_ptr->gce_ptr->block_size = 4;
1128 dst_buf[gif_ptr->cur_offset++] = gif_ptr->gce_ptr->block_size; 1125 dst_buf[gif_ptr->cur_offset++] = gif_ptr->gce_ptr->block_size;
1129 gif_ptr->gce_ptr->gce_flag = 0; 1126 gif_ptr->gce_ptr->gce_flag = 0;
1130 dst_buf[gif_ptr->cur_offset++] = gif_ptr->gce_ptr->gce_flag; 1127 dst_buf[gif_ptr->cur_offset++] = gif_ptr->gce_ptr->gce_flag;
1131 gif_ptr->gce_ptr->delay_time = 10; 1128 gif_ptr->gce_ptr->delay_time = 10;
1132 SetWord_LSBFirst(dst_buf + gif_ptr->cur_offset, 1129 SetWord_LSBFirst(dst_buf + gif_ptr->cur_offset,
(...skipping 13 matching lines...) Expand all
1146 gif_ptr->image_info_ptr->width); 1143 gif_ptr->image_info_ptr->width);
1147 gif_ptr->cur_offset += 2; 1144 gif_ptr->cur_offset += 2;
1148 SetWord_LSBFirst(dst_buf + gif_ptr->cur_offset, 1145 SetWord_LSBFirst(dst_buf + gif_ptr->cur_offset,
1149 gif_ptr->image_info_ptr->height); 1146 gif_ptr->image_info_ptr->height);
1150 gif_ptr->cur_offset += 2; 1147 gif_ptr->cur_offset += 2;
1151 GifLF& lf = (GifLF&)gif_ptr->image_info_ptr->local_flag; 1148 GifLF& lf = (GifLF&)gif_ptr->image_info_ptr->local_flag;
1152 dst_buf[gif_ptr->cur_offset++] = gif_ptr->image_info_ptr->local_flag; 1149 dst_buf[gif_ptr->cur_offset++] = gif_ptr->image_info_ptr->local_flag;
1153 if (gif_ptr->local_pal) { 1150 if (gif_ptr->local_pal) {
1154 uint32_t pal_size = sizeof(GifPalette) * gif_ptr->lpal_num; 1151 uint32_t pal_size = sizeof(GifPalette) * gif_ptr->lpal_num;
1155 if (!gif_grow_buf(dst_buf, dst_len, pal_size + gif_ptr->cur_offset)) { 1152 if (!gif_grow_buf(dst_buf, dst_len, pal_size + gif_ptr->cur_offset)) {
1156 return FALSE; 1153 return false;
1157 } 1154 }
1158 FXSYS_memcpy(&dst_buf[gif_ptr->cur_offset], gif_ptr->local_pal, pal_size); 1155 FXSYS_memcpy(&dst_buf[gif_ptr->cur_offset], gif_ptr->local_pal, pal_size);
1159 gif_ptr->cur_offset += pal_size; 1156 gif_ptr->cur_offset += pal_size;
1160 } 1157 }
1161 if (lf.interlace) { 1158 if (lf.interlace) {
1162 interlace_buf(gif_ptr->src_buf, gif_ptr->src_pitch, 1159 interlace_buf(gif_ptr->src_buf, gif_ptr->src_pitch,
1163 gif_ptr->image_info_ptr->height); 1160 gif_ptr->image_info_ptr->height);
1164 } 1161 }
1165 uint8_t code_bit = lf.pal_bits; 1162 uint8_t code_bit = lf.pal_bits;
1166 if (lf.local_pal == 0) { 1163 if (lf.local_pal == 0) {
1167 GifGF& gf = (GifGF&)gif_ptr->lsd_ptr->global_flag; 1164 GifGF& gf = (GifGF&)gif_ptr->lsd_ptr->global_flag;
1168 code_bit = gf.pal_bits; 1165 code_bit = gf.pal_bits;
1169 } 1166 }
1170 gif_ptr->img_encoder_ptr->Start(code_bit, gif_ptr->src_buf, dst_buf, 1167 gif_ptr->img_encoder_ptr->Start(code_bit, gif_ptr->src_buf, dst_buf,
1171 gif_ptr->cur_offset); 1168 gif_ptr->cur_offset);
1172 uint32_t i; 1169 uint32_t i;
1173 for (i = 0; i < gif_ptr->src_row; i++) { 1170 for (i = 0; i < gif_ptr->src_row; i++) {
1174 if (!gif_ptr->img_encoder_ptr->Encode( 1171 if (!gif_ptr->img_encoder_ptr->Encode(
1175 &gif_ptr->src_buf[i * gif_ptr->src_pitch], 1172 &gif_ptr->src_buf[i * gif_ptr->src_pitch],
1176 gif_ptr->src_width * (code_bit + 1), dst_buf, dst_len, 1173 gif_ptr->src_width * (code_bit + 1), dst_buf, dst_len,
1177 gif_ptr->cur_offset)) { 1174 gif_ptr->cur_offset)) {
1178 return FALSE; 1175 return false;
1179 } 1176 }
1180 } 1177 }
1181 gif_ptr->img_encoder_ptr->Finish(dst_buf, dst_len, gif_ptr->cur_offset); 1178 gif_ptr->img_encoder_ptr->Finish(dst_buf, dst_len, gif_ptr->cur_offset);
1182 dst_buf[gif_ptr->cur_offset++] = 0; 1179 dst_buf[gif_ptr->cur_offset++] = 0;
1183 if (FXSYS_memcmp(gif_ptr->header_ptr->version, "89a", 3) == 0 && 1180 if (FXSYS_memcmp(gif_ptr->header_ptr->version, "89a", 3) == 0 &&
1184 gif_ptr->cmt_data_ptr) { 1181 gif_ptr->cmt_data_ptr) {
1185 dst_buf[gif_ptr->cur_offset++] = GIF_SIG_EXTENSION; 1182 dst_buf[gif_ptr->cur_offset++] = GIF_SIG_EXTENSION;
1186 dst_buf[gif_ptr->cur_offset++] = GIF_BLOCK_CE; 1183 dst_buf[gif_ptr->cur_offset++] = GIF_BLOCK_CE;
1187 gif_write_block_data(gif_ptr->cmt_data_ptr, gif_ptr->cmt_data_len, dst_buf, 1184 gif_write_block_data(gif_ptr->cmt_data_ptr, gif_ptr->cmt_data_len, dst_buf,
1188 dst_len, gif_ptr->cur_offset); 1185 dst_len, gif_ptr->cur_offset);
(...skipping 24 matching lines...) Expand all
1213 SetWord_LSBFirst(dst_buf + gif_ptr->cur_offset, gif_ptr->pte_ptr->fc_index); 1210 SetWord_LSBFirst(dst_buf + gif_ptr->cur_offset, gif_ptr->pte_ptr->fc_index);
1214 gif_ptr->cur_offset += 2; 1211 gif_ptr->cur_offset += 2;
1215 SetWord_LSBFirst(dst_buf + gif_ptr->cur_offset, gif_ptr->pte_ptr->bc_index); 1212 SetWord_LSBFirst(dst_buf + gif_ptr->cur_offset, gif_ptr->pte_ptr->bc_index);
1216 gif_ptr->cur_offset += 2; 1213 gif_ptr->cur_offset += 2;
1217 gif_write_block_data(gif_ptr->pte_data_ptr, gif_ptr->pte_data_len, dst_buf, 1214 gif_write_block_data(gif_ptr->pte_data_ptr, gif_ptr->pte_data_len, dst_buf,
1218 dst_len, gif_ptr->cur_offset); 1215 dst_len, gif_ptr->cur_offset);
1219 gif_ptr->cur_offset += gif_ptr->pte_data_len; 1216 gif_ptr->cur_offset += gif_ptr->pte_data_len;
1220 dst_buf[gif_ptr->cur_offset++] = 0; 1217 dst_buf[gif_ptr->cur_offset++] = 0;
1221 } 1218 }
1222 dst_buf[gif_ptr->cur_offset++] = GIF_SIG_TRAILER; 1219 dst_buf[gif_ptr->cur_offset++] = GIF_SIG_TRAILER;
1223 return TRUE; 1220 return true;
1224 } 1221 }
1225 FX_BOOL gif_encode(gif_compress_struct_p gif_ptr, 1222 bool gif_encode(gif_compress_struct_p gif_ptr,
1226 uint8_t*& dst_buf, 1223 uint8_t*& dst_buf,
1227 uint32_t& dst_len) { 1224 uint32_t& dst_len) {
1228 if (!gif_write_header(gif_ptr, dst_buf, dst_len)) { 1225 if (!gif_write_header(gif_ptr, dst_buf, dst_len)) {
1229 return FALSE; 1226 return false;
1230 } 1227 }
1231 uint32_t cur_offset = gif_ptr->cur_offset; 1228 uint32_t cur_offset = gif_ptr->cur_offset;
1232 FX_BOOL res = TRUE; 1229 bool res = true;
1233 if (gif_ptr->frames) { 1230 if (gif_ptr->frames) {
1234 gif_ptr->cur_offset--; 1231 gif_ptr->cur_offset--;
1235 } 1232 }
1236 if (!gif_write_data(gif_ptr, dst_buf, dst_len)) { 1233 if (!gif_write_data(gif_ptr, dst_buf, dst_len)) {
1237 gif_ptr->cur_offset = cur_offset; 1234 gif_ptr->cur_offset = cur_offset;
1238 res = FALSE; 1235 res = false;
1239 } 1236 }
1240 dst_len = gif_ptr->cur_offset; 1237 dst_len = gif_ptr->cur_offset;
1241 dst_buf[dst_len - 1] = GIF_SIG_TRAILER; 1238 dst_buf[dst_len - 1] = GIF_SIG_TRAILER;
1242 if (res) { 1239 if (res) {
1243 gif_ptr->frames++; 1240 gif_ptr->frames++;
1244 } 1241 }
1245 return res; 1242 return res;
1246 } 1243 }
OLDNEW
« no previous file with comments | « core/fxcodec/lgif/fx_gif.h ('k') | core/fxcrt/extension.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698