OLD | NEW |
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 <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "core/fxcodec/codec/codec_int.h" | 9 #include "core/fxcodec/codec/codec_int.h" |
10 #include "core/fxcodec/include/fx_codec.h" | 10 #include "core/fxcodec/include/fx_codec.h" |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 #if defined(PNG_iCCP_SUPPORTED) | 44 #if defined(PNG_iCCP_SUPPORTED) |
45 png_charp icc_name; | 45 png_charp icc_name; |
46 png_bytep icc_profile; | 46 png_bytep icc_profile; |
47 png_uint_32 icc_proflen; | 47 png_uint_32 icc_proflen; |
48 int compress_type; | 48 int compress_type; |
49 png_get_iCCP(png_ptr, info_ptr, &icc_name, &compress_type, &icc_profile, | 49 png_get_iCCP(png_ptr, info_ptr, &icc_name, &compress_type, &icc_profile, |
50 &icc_proflen); | 50 &icc_proflen); |
51 #endif | 51 #endif |
52 int bTime = 0; | 52 int bTime = 0; |
53 #if defined(PNG_tIME_SUPPORTED) | 53 #if defined(PNG_tIME_SUPPORTED) |
54 png_timep t = NULL; | 54 png_timep t = nullptr; |
55 png_get_tIME(png_ptr, info_ptr, &t); | 55 png_get_tIME(png_ptr, info_ptr, &t); |
56 if (t) { | 56 if (t) { |
57 FXSYS_memset(pAttribute->m_strTime, 0, sizeof(pAttribute->m_strTime)); | 57 FXSYS_memset(pAttribute->m_strTime, 0, sizeof(pAttribute->m_strTime)); |
58 FXSYS_snprintf((FX_CHAR*)pAttribute->m_strTime, | 58 FXSYS_snprintf((FX_CHAR*)pAttribute->m_strTime, |
59 sizeof(pAttribute->m_strTime), "%4d:%2d:%2d %2d:%2d:%2d", | 59 sizeof(pAttribute->m_strTime), "%4d:%2d:%2d %2d:%2d:%2d", |
60 t->year, t->month, t->day, t->hour, t->minute, t->second); | 60 t->year, t->month, t->day, t->hour, t->minute, t->second); |
61 pAttribute->m_strTime[sizeof(pAttribute->m_strTime) - 1] = 0; | 61 pAttribute->m_strTime[sizeof(pAttribute->m_strTime) - 1] = 0; |
62 bTime = 1; | 62 bTime = 1; |
63 } | 63 } |
64 #endif | 64 #endif |
65 #if defined(PNG_TEXT_SUPPORTED) | 65 #if defined(PNG_TEXT_SUPPORTED) |
66 int i; | 66 int i; |
67 FX_STRSIZE len; | 67 FX_STRSIZE len; |
68 const FX_CHAR* buf; | 68 const FX_CHAR* buf; |
69 int num_text; | 69 int num_text; |
70 png_textp text = NULL; | 70 png_textp text = nullptr; |
71 png_get_text(png_ptr, info_ptr, &text, &num_text); | 71 png_get_text(png_ptr, info_ptr, &text, &num_text); |
72 for (i = 0; i < num_text; i++) { | 72 for (i = 0; i < num_text; i++) { |
73 len = FXSYS_strlen(text[i].key); | 73 len = FXSYS_strlen(text[i].key); |
74 buf = "Time"; | 74 buf = "Time"; |
75 if (!FXSYS_memcmp(buf, text[i].key, std::min(len, FXSYS_strlen(buf)))) { | 75 if (!FXSYS_memcmp(buf, text[i].key, std::min(len, FXSYS_strlen(buf)))) { |
76 if (!bTime) { | 76 if (!bTime) { |
77 FXSYS_memset(pAttribute->m_strTime, 0, sizeof(pAttribute->m_strTime)); | 77 FXSYS_memset(pAttribute->m_strTime, 0, sizeof(pAttribute->m_strTime)); |
78 FXSYS_memcpy( | 78 FXSYS_memcpy( |
79 pAttribute->m_strTime, text[i].text, | 79 pAttribute->m_strTime, text[i].text, |
80 std::min(sizeof(pAttribute->m_strTime) - 1, text[i].text_length)); | 80 std::min(sizeof(pAttribute->m_strTime) - 1, text[i].text_length)); |
(...skipping 22 matching lines...) Expand all Loading... |
103 extern "C" { | 103 extern "C" { |
104 static void* _png_alloc_func(unsigned int size) { | 104 static void* _png_alloc_func(unsigned int size) { |
105 return FX_Alloc(char, size); | 105 return FX_Alloc(char, size); |
106 } | 106 } |
107 static void _png_free_func(void* p) { | 107 static void _png_free_func(void* p) { |
108 FX_Free(p); | 108 FX_Free(p); |
109 } | 109 } |
110 }; | 110 }; |
111 static void _png_get_header_func(png_structp png_ptr, png_infop info_ptr) { | 111 static void _png_get_header_func(png_structp png_ptr, png_infop info_ptr) { |
112 FXPNG_Context* p = (FXPNG_Context*)png_get_progressive_ptr(png_ptr); | 112 FXPNG_Context* p = (FXPNG_Context*)png_get_progressive_ptr(png_ptr); |
113 if (p == NULL) { | 113 if (!p) |
114 return; | 114 return; |
115 } | 115 |
116 CCodec_PngModule* pModule = (CCodec_PngModule*)p->parent_ptr; | 116 CCodec_PngModule* pModule = (CCodec_PngModule*)p->parent_ptr; |
117 if (pModule == NULL) { | 117 if (!pModule) |
118 return; | 118 return; |
119 } | 119 |
120 png_uint_32 width = 0, height = 0; | 120 png_uint_32 width = 0, height = 0; |
121 int bpc = 0, color_type = 0, color_type1 = 0, pass = 0; | 121 int bpc = 0, color_type = 0, color_type1 = 0, pass = 0; |
122 double gamma = 1.0; | 122 double gamma = 1.0; |
123 png_get_IHDR(png_ptr, info_ptr, &width, &height, &bpc, &color_type, NULL, | 123 png_get_IHDR(png_ptr, info_ptr, &width, &height, &bpc, &color_type, nullptr, |
124 NULL, NULL); | 124 nullptr, nullptr); |
125 color_type1 = color_type; | 125 color_type1 = color_type; |
126 if (bpc > 8) { | 126 if (bpc > 8) { |
127 png_set_strip_16(png_ptr); | 127 png_set_strip_16(png_ptr); |
128 } else if (bpc < 8) { | 128 } else if (bpc < 8) { |
129 png_set_expand_gray_1_2_4_to_8(png_ptr); | 129 png_set_expand_gray_1_2_4_to_8(png_ptr); |
130 } | 130 } |
131 bpc = 8; | 131 bpc = 8; |
132 if (color_type == PNG_COLOR_TYPE_PALETTE) { | 132 if (color_type == PNG_COLOR_TYPE_PALETTE) { |
133 png_set_palette_to_rgb(png_ptr); | 133 png_set_palette_to_rgb(png_ptr); |
134 } | 134 } |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 png_set_filler(png_ptr, 0xff, PNG_FILLER_AFTER); | 175 png_set_filler(png_ptr, 0xff, PNG_FILLER_AFTER); |
176 } | 176 } |
177 png_read_update_info(png_ptr, info_ptr); | 177 png_read_update_info(png_ptr, info_ptr); |
178 } | 178 } |
179 static void _png_get_end_func(png_structp png_ptr, png_infop info_ptr) {} | 179 static void _png_get_end_func(png_structp png_ptr, png_infop info_ptr) {} |
180 static void _png_get_row_func(png_structp png_ptr, | 180 static void _png_get_row_func(png_structp png_ptr, |
181 png_bytep new_row, | 181 png_bytep new_row, |
182 png_uint_32 row_num, | 182 png_uint_32 row_num, |
183 int pass) { | 183 int pass) { |
184 FXPNG_Context* p = (FXPNG_Context*)png_get_progressive_ptr(png_ptr); | 184 FXPNG_Context* p = (FXPNG_Context*)png_get_progressive_ptr(png_ptr); |
185 if (p == NULL) { | 185 if (!p) |
186 return; | 186 return; |
187 } | 187 |
188 CCodec_PngModule* pModule = (CCodec_PngModule*)p->parent_ptr; | 188 CCodec_PngModule* pModule = (CCodec_PngModule*)p->parent_ptr; |
189 uint8_t* src_buf = NULL; | 189 uint8_t* src_buf = nullptr; |
190 if (!pModule->AskScanlineBufCallback(p->child_ptr, row_num, src_buf)) { | 190 if (!pModule->AskScanlineBufCallback(p->child_ptr, row_num, src_buf)) { |
191 png_error(png_ptr, "Ask Scanline buffer Callback Error"); | 191 png_error(png_ptr, "Ask Scanline buffer Callback Error"); |
192 } | 192 } |
193 if (src_buf) { | 193 if (src_buf) { |
194 png_progressive_combine_row(png_ptr, src_buf, new_row); | 194 png_progressive_combine_row(png_ptr, src_buf, new_row); |
195 } | 195 } |
196 pModule->FillScanlineBufCompletedCallback(p->child_ptr, pass, row_num); | 196 pModule->FillScanlineBufCompletedCallback(p->child_ptr, pass, row_num); |
197 } | 197 } |
198 | 198 |
199 FXPNG_Context* CCodec_PngModule::Start(void* pModule) { | 199 FXPNG_Context* CCodec_PngModule::Start(void* pModule) { |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
247 if (setjmp(png_jmpbuf(ctx->png_ptr))) { | 247 if (setjmp(png_jmpbuf(ctx->png_ptr))) { |
248 if (pAttribute && | 248 if (pAttribute && |
249 0 == FXSYS_strcmp(m_szLastError, "Read Header Callback Error")) { | 249 0 == FXSYS_strcmp(m_szLastError, "Read Header Callback Error")) { |
250 _png_load_bmp_attribute(ctx->png_ptr, ctx->info_ptr, pAttribute); | 250 _png_load_bmp_attribute(ctx->png_ptr, ctx->info_ptr, pAttribute); |
251 } | 251 } |
252 return FALSE; | 252 return FALSE; |
253 } | 253 } |
254 png_process_data(ctx->png_ptr, ctx->info_ptr, (uint8_t*)src_buf, src_size); | 254 png_process_data(ctx->png_ptr, ctx->info_ptr, (uint8_t*)src_buf, src_size); |
255 return TRUE; | 255 return TRUE; |
256 } | 256 } |
OLD | NEW |