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

Side by Side Diff: core/src/fxcodec/codec/fx_codec_png.cpp

Issue 1720043003: Remove foo != NULL outside of xfa/ (Closed) Base URL: https://pdfium.googlesource.com/pdfium@master
Patch Set: rebase 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
« no previous file with comments | « core/src/fxcodec/codec/fx_codec_gif.cpp ('k') | core/src/fxcodec/codec/fx_codec_progress.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 <algorithm> 7 #include <algorithm>
8 8
9 #include "core/include/fxcodec/fx_codec.h" 9 #include "core/include/fxcodec/fx_codec.h"
10 #include "core/include/fxge/fx_dib.h" 10 #include "core/include/fxge/fx_dib.h"
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 void* child_ptr; 98 void* child_ptr;
99 99
100 void* (*m_AllocFunc)(unsigned int); 100 void* (*m_AllocFunc)(unsigned int);
101 void (*m_FreeFunc)(void*); 101 void (*m_FreeFunc)(void*);
102 }; 102 };
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 if (p != NULL) { 108 FX_Free(p);
109 FX_Free(p);
110 }
111 } 109 }
112 }; 110 };
113 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) {
114 FXPNG_Context* p = (FXPNG_Context*)png_get_progressive_ptr(png_ptr); 112 FXPNG_Context* p = (FXPNG_Context*)png_get_progressive_ptr(png_ptr);
115 if (p == NULL) { 113 if (p == NULL) {
116 return; 114 return;
117 } 115 }
118 CCodec_PngModule* pModule = (CCodec_PngModule*)p->parent_ptr; 116 CCodec_PngModule* pModule = (CCodec_PngModule*)p->parent_ptr;
119 if (pModule == NULL) { 117 if (pModule == NULL) {
120 return; 118 return;
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 int pass) { 183 int pass) {
186 FXPNG_Context* p = (FXPNG_Context*)png_get_progressive_ptr(png_ptr); 184 FXPNG_Context* p = (FXPNG_Context*)png_get_progressive_ptr(png_ptr);
187 if (p == NULL) { 185 if (p == NULL) {
188 return; 186 return;
189 } 187 }
190 CCodec_PngModule* pModule = (CCodec_PngModule*)p->parent_ptr; 188 CCodec_PngModule* pModule = (CCodec_PngModule*)p->parent_ptr;
191 uint8_t* src_buf = NULL; 189 uint8_t* src_buf = NULL;
192 if (!pModule->AskScanlineBufCallback(p->child_ptr, row_num, src_buf)) { 190 if (!pModule->AskScanlineBufCallback(p->child_ptr, row_num, src_buf)) {
193 png_error(png_ptr, "Ask Scanline buffer Callback Error"); 191 png_error(png_ptr, "Ask Scanline buffer Callback Error");
194 } 192 }
195 if (src_buf != NULL) { 193 if (src_buf) {
196 png_progressive_combine_row(png_ptr, src_buf, new_row); 194 png_progressive_combine_row(png_ptr, src_buf, new_row);
197 } 195 }
198 pModule->FillScanlineBufCompletedCallback(p->child_ptr, pass, row_num); 196 pModule->FillScanlineBufCompletedCallback(p->child_ptr, pass, row_num);
199 } 197 }
200 void* CCodec_PngModule::Start(void* pModule) { 198 void* CCodec_PngModule::Start(void* pModule) {
201 FXPNG_Context* p = (FXPNG_Context*)FX_Alloc(uint8_t, sizeof(FXPNG_Context)); 199 FXPNG_Context* p = (FXPNG_Context*)FX_Alloc(uint8_t, sizeof(FXPNG_Context));
202 if (p == NULL) { 200 if (p == NULL) {
203 return NULL; 201 return NULL;
204 } 202 }
205 p->m_AllocFunc = _png_alloc_func; 203 p->m_AllocFunc = _png_alloc_func;
206 p->m_FreeFunc = _png_free_func; 204 p->m_FreeFunc = _png_free_func;
207 p->png_ptr = NULL; 205 p->png_ptr = NULL;
208 p->info_ptr = NULL; 206 p->info_ptr = NULL;
209 p->parent_ptr = (void*)this; 207 p->parent_ptr = (void*)this;
210 p->child_ptr = pModule; 208 p->child_ptr = pModule;
211 p->png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); 209 p->png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
212 if (p->png_ptr == NULL) { 210 if (p->png_ptr == NULL) {
213 FX_Free(p); 211 FX_Free(p);
214 return NULL; 212 return NULL;
215 } 213 }
216 p->info_ptr = png_create_info_struct(p->png_ptr); 214 p->info_ptr = png_create_info_struct(p->png_ptr);
217 if (p->info_ptr == NULL) { 215 if (p->info_ptr == NULL) {
218 png_destroy_read_struct(&(p->png_ptr), (png_infopp)NULL, (png_infopp)NULL); 216 png_destroy_read_struct(&(p->png_ptr), (png_infopp)NULL, (png_infopp)NULL);
219 FX_Free(p); 217 FX_Free(p);
220 return NULL; 218 return NULL;
221 } 219 }
222 if (setjmp(png_jmpbuf(p->png_ptr))) { 220 if (setjmp(png_jmpbuf(p->png_ptr))) {
223 if (p != NULL) { 221 if (p) {
224 png_destroy_read_struct(&(p->png_ptr), &(p->info_ptr), (png_infopp)NULL); 222 png_destroy_read_struct(&(p->png_ptr), &(p->info_ptr), (png_infopp)NULL);
225 FX_Free(p); 223 FX_Free(p);
226 } 224 }
227 return NULL; 225 return NULL;
228 } 226 }
229 png_set_progressive_read_fn(p->png_ptr, p, _png_get_header_func, 227 png_set_progressive_read_fn(p->png_ptr, p, _png_get_header_func,
230 _png_get_row_func, _png_get_end_func); 228 _png_get_row_func, _png_get_end_func);
231 png_set_error_fn(p->png_ptr, m_szLastError, (png_error_ptr)_png_error_data, 229 png_set_error_fn(p->png_ptr, m_szLastError, (png_error_ptr)_png_error_data,
232 (png_error_ptr)_png_warning_data); 230 (png_error_ptr)_png_warning_data);
233 return p; 231 return p;
234 } 232 }
235 void CCodec_PngModule::Finish(void* pContext) { 233 void CCodec_PngModule::Finish(void* pContext) {
236 FXPNG_Context* p = (FXPNG_Context*)pContext; 234 FXPNG_Context* p = (FXPNG_Context*)pContext;
237 if (p != NULL) { 235 if (p) {
238 png_destroy_read_struct(&(p->png_ptr), &(p->info_ptr), (png_infopp)NULL); 236 png_destroy_read_struct(&(p->png_ptr), &(p->info_ptr), (png_infopp)NULL);
239 p->m_FreeFunc(p); 237 p->m_FreeFunc(p);
240 } 238 }
241 } 239 }
242 FX_BOOL CCodec_PngModule::Input(void* pContext, 240 FX_BOOL CCodec_PngModule::Input(void* pContext,
243 const uint8_t* src_buf, 241 const uint8_t* src_buf,
244 FX_DWORD src_size, 242 FX_DWORD src_size,
245 CFX_DIBAttribute* pAttribute) { 243 CFX_DIBAttribute* pAttribute) {
246 FXPNG_Context* p = (FXPNG_Context*)pContext; 244 FXPNG_Context* p = (FXPNG_Context*)pContext;
247 if (setjmp(png_jmpbuf(p->png_ptr))) { 245 if (setjmp(png_jmpbuf(p->png_ptr))) {
248 if (pAttribute && 246 if (pAttribute &&
249 0 == FXSYS_strcmp(m_szLastError, "Read Header Callback Error")) { 247 0 == FXSYS_strcmp(m_szLastError, "Read Header Callback Error")) {
250 _png_load_bmp_attribute(p->png_ptr, p->info_ptr, pAttribute); 248 _png_load_bmp_attribute(p->png_ptr, p->info_ptr, pAttribute);
251 } 249 }
252 return FALSE; 250 return FALSE;
253 } 251 }
254 png_process_data(p->png_ptr, p->info_ptr, (uint8_t*)src_buf, src_size); 252 png_process_data(p->png_ptr, p->info_ptr, (uint8_t*)src_buf, src_size);
255 return TRUE; 253 return TRUE;
256 } 254 }
OLDNEW
« no previous file with comments | « core/src/fxcodec/codec/fx_codec_gif.cpp ('k') | core/src/fxcodec/codec/fx_codec_progress.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698