| 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 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 = NULL; |
| 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 void* CCodec_PngModule::Start(void* pModule) { | 198 |
| 199 FXPNG_Context* CCodec_PngModule::Start(void* pModule) { |
| 199 FXPNG_Context* p = (FXPNG_Context*)FX_Alloc(uint8_t, sizeof(FXPNG_Context)); | 200 FXPNG_Context* p = (FXPNG_Context*)FX_Alloc(uint8_t, sizeof(FXPNG_Context)); |
| 200 if (p == NULL) { | 201 if (!p) |
| 201 return NULL; | 202 return nullptr; |
| 202 } | 203 |
| 203 p->m_AllocFunc = _png_alloc_func; | 204 p->m_AllocFunc = _png_alloc_func; |
| 204 p->m_FreeFunc = _png_free_func; | 205 p->m_FreeFunc = _png_free_func; |
| 205 p->png_ptr = NULL; | 206 p->png_ptr = nullptr; |
| 206 p->info_ptr = NULL; | 207 p->info_ptr = nullptr; |
| 207 p->parent_ptr = (void*)this; | 208 p->parent_ptr = (void*)this; |
| 208 p->child_ptr = pModule; | 209 p->child_ptr = pModule; |
| 209 p->png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); | 210 p->png_ptr = |
| 210 if (p->png_ptr == NULL) { | 211 png_create_read_struct(PNG_LIBPNG_VER_STRING, nullptr, nullptr, nullptr); |
| 212 if (!p->png_ptr) { |
| 211 FX_Free(p); | 213 FX_Free(p); |
| 212 return NULL; | 214 return nullptr; |
| 213 } | 215 } |
| 214 p->info_ptr = png_create_info_struct(p->png_ptr); | 216 p->info_ptr = png_create_info_struct(p->png_ptr); |
| 215 if (p->info_ptr == NULL) { | 217 if (!p->info_ptr) { |
| 216 png_destroy_read_struct(&(p->png_ptr), (png_infopp)NULL, (png_infopp)NULL); | 218 png_destroy_read_struct(&(p->png_ptr), nullptr, nullptr); |
| 217 FX_Free(p); | 219 FX_Free(p); |
| 218 return NULL; | 220 return nullptr; |
| 219 } | 221 } |
| 220 if (setjmp(png_jmpbuf(p->png_ptr))) { | 222 if (setjmp(png_jmpbuf(p->png_ptr))) { |
| 221 if (p) { | 223 if (p) { |
| 222 png_destroy_read_struct(&(p->png_ptr), &(p->info_ptr), (png_infopp)NULL); | 224 png_destroy_read_struct(&(p->png_ptr), &(p->info_ptr), nullptr); |
| 223 FX_Free(p); | 225 FX_Free(p); |
| 224 } | 226 } |
| 225 return NULL; | 227 return nullptr; |
| 226 } | 228 } |
| 227 png_set_progressive_read_fn(p->png_ptr, p, _png_get_header_func, | 229 png_set_progressive_read_fn(p->png_ptr, p, _png_get_header_func, |
| 228 _png_get_row_func, _png_get_end_func); | 230 _png_get_row_func, _png_get_end_func); |
| 229 png_set_error_fn(p->png_ptr, m_szLastError, (png_error_ptr)_png_error_data, | 231 png_set_error_fn(p->png_ptr, m_szLastError, (png_error_ptr)_png_error_data, |
| 230 (png_error_ptr)_png_warning_data); | 232 (png_error_ptr)_png_warning_data); |
| 231 return p; | 233 return p; |
| 232 } | 234 } |
| 233 void CCodec_PngModule::Finish(void* pContext) { | 235 |
| 234 FXPNG_Context* p = (FXPNG_Context*)pContext; | 236 void CCodec_PngModule::Finish(FXPNG_Context* ctx) { |
| 235 if (p) { | 237 if (ctx) { |
| 236 png_destroy_read_struct(&(p->png_ptr), &(p->info_ptr), (png_infopp)NULL); | 238 png_destroy_read_struct(&(ctx->png_ptr), &(ctx->info_ptr), nullptr); |
| 237 p->m_FreeFunc(p); | 239 ctx->m_FreeFunc(ctx); |
| 238 } | 240 } |
| 239 } | 241 } |
| 240 FX_BOOL CCodec_PngModule::Input(void* pContext, | 242 |
| 243 FX_BOOL CCodec_PngModule::Input(FXPNG_Context* ctx, |
| 241 const uint8_t* src_buf, | 244 const uint8_t* src_buf, |
| 242 uint32_t src_size, | 245 uint32_t src_size, |
| 243 CFX_DIBAttribute* pAttribute) { | 246 CFX_DIBAttribute* pAttribute) { |
| 244 FXPNG_Context* p = (FXPNG_Context*)pContext; | 247 if (setjmp(png_jmpbuf(ctx->png_ptr))) { |
| 245 if (setjmp(png_jmpbuf(p->png_ptr))) { | |
| 246 if (pAttribute && | 248 if (pAttribute && |
| 247 0 == FXSYS_strcmp(m_szLastError, "Read Header Callback Error")) { | 249 0 == FXSYS_strcmp(m_szLastError, "Read Header Callback Error")) { |
| 248 _png_load_bmp_attribute(p->png_ptr, p->info_ptr, pAttribute); | 250 _png_load_bmp_attribute(ctx->png_ptr, ctx->info_ptr, pAttribute); |
| 249 } | 251 } |
| 250 return FALSE; | 252 return FALSE; |
| 251 } | 253 } |
| 252 png_process_data(p->png_ptr, p->info_ptr, (uint8_t*)src_buf, src_size); | 254 png_process_data(ctx->png_ptr, ctx->info_ptr, (uint8_t*)src_buf, src_size); |
| 253 return TRUE; | 255 return TRUE; |
| 254 } | 256 } |
| OLD | NEW |