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

Side by Side Diff: core/fxcodec/codec/fx_codec_tiff.cpp

Issue 2032613003: Get rid of NULLs in core/ (Closed) Base URL: https://pdfium.googlesource.com/pdfium@master
Patch Set: Fix a bad merge Created 4 years, 6 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/fxcodec/codec/codec_int.h" 7 #include "core/fxcodec/codec/codec_int.h"
8 #include "core/fxcodec/include/fx_codec.h" 8 #include "core/fxcodec/include/fx_codec.h"
9 #include "core/fxge/include/fx_dib.h" 9 #include "core/fxge/include/fx_dib.h"
10 10
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 FX_BOOL Decode24bppRGB(CFX_DIBitmap* pDIBitmap, 66 FX_BOOL Decode24bppRGB(CFX_DIBitmap* pDIBitmap,
67 int32_t height, 67 int32_t height,
68 int32_t width, 68 int32_t width,
69 uint16_t bps, 69 uint16_t bps,
70 uint16_t spp); 70 uint16_t spp);
71 }; 71 };
72 CCodec_TiffContext::CCodec_TiffContext() { 72 CCodec_TiffContext::CCodec_TiffContext() {
73 offset = 0; 73 offset = 0;
74 frame_num = 0; 74 frame_num = 0;
75 frame_cur = 0; 75 frame_cur = 0;
76 io.in = NULL; 76 io.in = nullptr;
77 tif_ctx = NULL; 77 tif_ctx = nullptr;
78 icc_ctx = NULL; 78 icc_ctx = nullptr;
79 isDecoder = TRUE; 79 isDecoder = TRUE;
80 } 80 }
81 CCodec_TiffContext::~CCodec_TiffContext() { 81 CCodec_TiffContext::~CCodec_TiffContext() {
82 if (icc_ctx) { 82 if (icc_ctx) {
83 IccLib_DestroyTransform(icc_ctx); 83 IccLib_DestroyTransform(icc_ctx);
84 icc_ctx = NULL; 84 icc_ctx = nullptr;
85 } 85 }
86 if (tif_ctx) { 86 if (tif_ctx) {
87 TIFFClose(tif_ctx); 87 TIFFClose(tif_ctx);
88 } 88 }
89 } 89 }
90 static tsize_t _tiff_read(thandle_t context, tdata_t buf, tsize_t length) { 90 static tsize_t _tiff_read(thandle_t context, tdata_t buf, tsize_t length) {
91 CCodec_TiffContext* pTiffContext = (CCodec_TiffContext*)context; 91 CCodec_TiffContext* pTiffContext = (CCodec_TiffContext*)context;
92 FX_BOOL ret = FALSE; 92 FX_BOOL ret = FALSE;
93 if (pTiffContext->isDecoder) { 93 if (pTiffContext->isDecoder) {
94 ret = pTiffContext->io.in->ReadBlock(buf, pTiffContext->offset, length); 94 ret = pTiffContext->io.in->ReadBlock(buf, pTiffContext->offset, length);
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 TIFFErrorHandler _TIFFerrorHandler = nullptr; 186 TIFFErrorHandler _TIFFerrorHandler = nullptr;
187 187
188 int TIFFCmyk2Rgb(thandle_t context, 188 int TIFFCmyk2Rgb(thandle_t context,
189 uint8 c, 189 uint8 c,
190 uint8 m, 190 uint8 m,
191 uint8 y, 191 uint8 y,
192 uint8 k, 192 uint8 k,
193 uint8* r, 193 uint8* r,
194 uint8* g, 194 uint8* g,
195 uint8* b) { 195 uint8* b) {
196 if (context == NULL) { 196 if (!context)
197 return 0; 197 return 0;
198 } 198
199 CCodec_TiffContext* p = (CCodec_TiffContext*)context; 199 CCodec_TiffContext* p = (CCodec_TiffContext*)context;
200 if (p->icc_ctx) { 200 if (p->icc_ctx) {
201 unsigned char cmyk[4], bgr[3]; 201 unsigned char cmyk[4], bgr[3];
202 cmyk[0] = c, cmyk[1] = m, cmyk[2] = y, cmyk[3] = k; 202 cmyk[0] = c, cmyk[1] = m, cmyk[2] = y, cmyk[3] = k;
203 IccLib_TranslateImage(p->icc_ctx, bgr, cmyk, 1); 203 IccLib_TranslateImage(p->icc_ctx, bgr, cmyk, 1);
204 *r = bgr[2], *g = bgr[1], *b = bgr[0]; 204 *r = bgr[2], *g = bgr[1], *b = bgr[0];
205 } else { 205 } else {
206 AdobeCMYK_to_sRGB1(c, m, y, k, *r, *g, *b); 206 AdobeCMYK_to_sRGB1(c, m, y, k, *r, *g, *b);
207 } 207 }
208 return 1; 208 return 1;
209 } 209 }
210 FX_BOOL CCodec_TiffContext::InitDecoder(IFX_FileRead* file_ptr) { 210 FX_BOOL CCodec_TiffContext::InitDecoder(IFX_FileRead* file_ptr) {
211 io.in = file_ptr; 211 io.in = file_ptr;
212 tif_ctx = _tiff_open(this, "r"); 212 return !!_tiff_open(this, "r");
213 if (tif_ctx == NULL) {
214 return FALSE;
215 }
216 return TRUE;
217 } 213 }
218 void CCodec_TiffContext::GetFrames(int32_t& frames) { 214 void CCodec_TiffContext::GetFrames(int32_t& frames) {
219 frames = frame_num = TIFFNumberOfDirectories(tif_ctx); 215 frames = frame_num = TIFFNumberOfDirectories(tif_ctx);
220 } 216 }
221 #define TIFF_EXIF_GETINFO(key, T, tag) \ 217 #define TIFF_EXIF_GETINFO(key, T, tag) \
222 { \ 218 { \
223 T val = (T)0; \ 219 T val = (T)0; \
224 TIFFGetField(tif_ctx, tag, &val); \ 220 TIFFGetField(tif_ctx, tag, &val); \
225 if (val) { \ 221 if (val) { \
226 (key) = FX_Alloc(uint8_t, sizeof(T)); \ 222 (key) = FX_Alloc(uint8_t, sizeof(T)); \
227 if ((key)) { \ 223 if ((key)) { \
228 T* ptr = (T*)(key); \ 224 T* ptr = (T*)(key); \
229 *ptr = val; \ 225 *ptr = val; \
230 pExif->m_TagVal.SetAt(tag, (key)); \ 226 pExif->m_TagVal.SetAt(tag, (key)); \
231 } \ 227 } \
232 } \ 228 } \
233 } \ 229 } \
234 (key) = NULL; 230 (key) = nullptr;
235 #define TIFF_EXIF_GETSTRINGINFO(key, tag) \ 231 #define TIFF_EXIF_GETSTRINGINFO(key, tag) \
236 { \ 232 { \
237 uint32_t size = 0; \ 233 uint32_t size = 0; \
238 uint8_t* buf = NULL; \ 234 uint8_t* buf = nullptr; \
239 TIFFGetField(tif_ctx, tag, &size, &buf); \ 235 TIFFGetField(tif_ctx, tag, &size, &buf); \
240 if (size && buf) { \ 236 if (size && buf) { \
241 (key) = FX_Alloc(uint8_t, size); \ 237 (key) = FX_Alloc(uint8_t, size); \
242 if ((key)) { \ 238 if ((key)) { \
243 FXSYS_memcpy((key), buf, size); \ 239 FXSYS_memcpy((key), buf, size); \
244 pExif->m_TagVal.SetAt(tag, (key)); \ 240 pExif->m_TagVal.SetAt(tag, (key)); \
245 } \ 241 } \
246 } \ 242 } \
247 } \ 243 } \
248 (key) = NULL; 244 (key) = nullptr;
249 245
250 namespace { 246 namespace {
251 247
252 template <class T> 248 template <class T>
253 FX_BOOL Tiff_Exif_GetInfo(TIFF* tif_ctx, ttag_t tag, CFX_DIBAttribute* pAttr) { 249 FX_BOOL Tiff_Exif_GetInfo(TIFF* tif_ctx, ttag_t tag, CFX_DIBAttribute* pAttr) {
254 T val = 0; 250 T val = 0;
255 TIFFGetField(tif_ctx, tag, &val); 251 TIFFGetField(tif_ctx, tag, &val);
256 if (!val) 252 if (!val)
257 return FALSE; 253 return FALSE;
258 T* ptr = FX_Alloc(T, 1); 254 T* ptr = FX_Alloc(T, 1);
(...skipping 21 matching lines...) Expand all
280 uint32_t& width, 276 uint32_t& width,
281 uint32_t& height, 277 uint32_t& height,
282 uint32_t& comps, 278 uint32_t& comps,
283 uint32_t& bpc, 279 uint32_t& bpc,
284 CFX_DIBAttribute* pAttribute) { 280 CFX_DIBAttribute* pAttribute) {
285 if (!TIFFSetDirectory(tif_ctx, (uint16)frame)) { 281 if (!TIFFSetDirectory(tif_ctx, (uint16)frame)) {
286 return FALSE; 282 return FALSE;
287 } 283 }
288 uint16_t tif_cs; 284 uint16_t tif_cs;
289 uint32_t tif_icc_size = 0; 285 uint32_t tif_icc_size = 0;
290 uint8_t* tif_icc_buf = NULL; 286 uint8_t* tif_icc_buf = nullptr;
291 uint16_t tif_bpc = 0; 287 uint16_t tif_bpc = 0;
292 uint16_t tif_cps; 288 uint16_t tif_cps;
293 uint32_t tif_rps; 289 uint32_t tif_rps;
294 width = height = comps = 0; 290 width = height = comps = 0;
295 TIFFGetField(tif_ctx, TIFFTAG_IMAGEWIDTH, &width); 291 TIFFGetField(tif_ctx, TIFFTAG_IMAGEWIDTH, &width);
296 TIFFGetField(tif_ctx, TIFFTAG_IMAGELENGTH, &height); 292 TIFFGetField(tif_ctx, TIFFTAG_IMAGELENGTH, &height);
297 TIFFGetField(tif_ctx, TIFFTAG_SAMPLESPERPIXEL, &comps); 293 TIFFGetField(tif_ctx, TIFFTAG_SAMPLESPERPIXEL, &comps);
298 TIFFGetField(tif_ctx, TIFFTAG_BITSPERSAMPLE, &tif_bpc); 294 TIFFGetField(tif_ctx, TIFFTAG_BITSPERSAMPLE, &tif_bpc);
299 TIFFGetField(tif_ctx, TIFFTAG_PHOTOMETRIC, &tif_cs); 295 TIFFGetField(tif_ctx, TIFFTAG_PHOTOMETRIC, &tif_cs);
300 TIFFGetField(tif_ctx, TIFFTAG_COMPRESSION, &tif_cps); 296 TIFFGetField(tif_ctx, TIFFTAG_COMPRESSION, &tif_cps);
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
392 int32_t width, 388 int32_t width,
393 uint16_t bps, 389 uint16_t bps,
394 uint16_t spp) { 390 uint16_t spp) {
395 if (pDIBitmap->GetBPP() != 1 || spp != 1 || bps != 1 || 391 if (pDIBitmap->GetBPP() != 1 || spp != 1 || bps != 1 ||
396 !isSupport(pDIBitmap)) { 392 !isSupport(pDIBitmap)) {
397 return FALSE; 393 return FALSE;
398 } 394 }
399 SetPalette(pDIBitmap, bps); 395 SetPalette(pDIBitmap, bps);
400 int32_t size = (int32_t)TIFFScanlineSize(tif_ctx); 396 int32_t size = (int32_t)TIFFScanlineSize(tif_ctx);
401 uint8_t* buf = (uint8_t*)_TIFFmalloc(size); 397 uint8_t* buf = (uint8_t*)_TIFFmalloc(size);
402 if (buf == NULL) { 398 if (!buf) {
403 TIFFError(TIFFFileName(tif_ctx), "No space for scanline buffer"); 399 TIFFError(TIFFFileName(tif_ctx), "No space for scanline buffer");
404 return FALSE; 400 return FALSE;
405 } 401 }
406 uint8_t* bitMapbuffer = (uint8_t*)pDIBitmap->GetBuffer(); 402 uint8_t* bitMapbuffer = (uint8_t*)pDIBitmap->GetBuffer();
407 uint32_t pitch = pDIBitmap->GetPitch(); 403 uint32_t pitch = pDIBitmap->GetPitch();
408 for (int32_t row = 0; row < height; row++) { 404 for (int32_t row = 0; row < height; row++) {
409 TIFFReadScanline(tif_ctx, buf, row, 0); 405 TIFFReadScanline(tif_ctx, buf, row, 0);
410 for (int32_t j = 0; j < size; j++) { 406 for (int32_t j = 0; j < size; j++) {
411 bitMapbuffer[row * pitch + j] = buf[j]; 407 bitMapbuffer[row * pitch + j] = buf[j];
412 } 408 }
413 } 409 }
414 _TIFFfree(buf); 410 _TIFFfree(buf);
415 return TRUE; 411 return TRUE;
416 } 412 }
417 FX_BOOL CCodec_TiffContext::Decode8bppRGB(CFX_DIBitmap* pDIBitmap, 413 FX_BOOL CCodec_TiffContext::Decode8bppRGB(CFX_DIBitmap* pDIBitmap,
418 int32_t height, 414 int32_t height,
419 int32_t width, 415 int32_t width,
420 uint16_t bps, 416 uint16_t bps,
421 uint16_t spp) { 417 uint16_t spp) {
422 if (pDIBitmap->GetBPP() != 8 || spp != 1 || (bps != 4 && bps != 8) || 418 if (pDIBitmap->GetBPP() != 8 || spp != 1 || (bps != 4 && bps != 8) ||
423 !isSupport(pDIBitmap)) { 419 !isSupport(pDIBitmap)) {
424 return FALSE; 420 return FALSE;
425 } 421 }
426 SetPalette(pDIBitmap, bps); 422 SetPalette(pDIBitmap, bps);
427 int32_t size = (int32_t)TIFFScanlineSize(tif_ctx); 423 int32_t size = (int32_t)TIFFScanlineSize(tif_ctx);
428 uint8_t* buf = (uint8_t*)_TIFFmalloc(size); 424 uint8_t* buf = (uint8_t*)_TIFFmalloc(size);
429 if (buf == NULL) { 425 if (!buf) {
430 TIFFError(TIFFFileName(tif_ctx), "No space for scanline buffer"); 426 TIFFError(TIFFFileName(tif_ctx), "No space for scanline buffer");
431 return FALSE; 427 return FALSE;
432 } 428 }
433 uint8_t* bitMapbuffer = (uint8_t*)pDIBitmap->GetBuffer(); 429 uint8_t* bitMapbuffer = (uint8_t*)pDIBitmap->GetBuffer();
434 uint32_t pitch = pDIBitmap->GetPitch(); 430 uint32_t pitch = pDIBitmap->GetPitch();
435 for (int32_t row = 0; row < height; row++) { 431 for (int32_t row = 0; row < height; row++) {
436 TIFFReadScanline(tif_ctx, buf, row, 0); 432 TIFFReadScanline(tif_ctx, buf, row, 0);
437 for (int32_t j = 0; j < size; j++) { 433 for (int32_t j = 0; j < size; j++) {
438 switch (bps) { 434 switch (bps) {
439 case 4: 435 case 4:
(...skipping 12 matching lines...) Expand all
452 FX_BOOL CCodec_TiffContext::Decode24bppRGB(CFX_DIBitmap* pDIBitmap, 448 FX_BOOL CCodec_TiffContext::Decode24bppRGB(CFX_DIBitmap* pDIBitmap,
453 int32_t height, 449 int32_t height,
454 int32_t width, 450 int32_t width,
455 uint16_t bps, 451 uint16_t bps,
456 uint16_t spp) { 452 uint16_t spp) {
457 if (pDIBitmap->GetBPP() != 24 || !isSupport(pDIBitmap)) { 453 if (pDIBitmap->GetBPP() != 24 || !isSupport(pDIBitmap)) {
458 return FALSE; 454 return FALSE;
459 } 455 }
460 int32_t size = (int32_t)TIFFScanlineSize(tif_ctx); 456 int32_t size = (int32_t)TIFFScanlineSize(tif_ctx);
461 uint8_t* buf = (uint8_t*)_TIFFmalloc(size); 457 uint8_t* buf = (uint8_t*)_TIFFmalloc(size);
462 if (buf == NULL) { 458 if (!buf) {
463 TIFFError(TIFFFileName(tif_ctx), "No space for scanline buffer"); 459 TIFFError(TIFFFileName(tif_ctx), "No space for scanline buffer");
464 return FALSE; 460 return FALSE;
465 } 461 }
466 uint8_t* bitMapbuffer = (uint8_t*)pDIBitmap->GetBuffer(); 462 uint8_t* bitMapbuffer = (uint8_t*)pDIBitmap->GetBuffer();
467 uint32_t pitch = pDIBitmap->GetPitch(); 463 uint32_t pitch = pDIBitmap->GetPitch();
468 for (int32_t row = 0; row < height; row++) { 464 for (int32_t row = 0; row < height; row++) {
469 TIFFReadScanline(tif_ctx, buf, row, 0); 465 TIFFReadScanline(tif_ctx, buf, row, 0);
470 for (int32_t j = 0; j < size - 2; j += 3) { 466 for (int32_t j = 0; j < size - 2; j += 3) {
471 bitMapbuffer[row * pitch + j + 0] = buf[j + 2]; 467 bitMapbuffer[row * pitch + j + 0] = buf[j + 2];
472 bitMapbuffer[row * pitch + j + 1] = buf[j + 1]; 468 bitMapbuffer[row * pitch + j + 1] = buf[j + 1];
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
537 } 533 }
538 534
539 FX_BOOL CCodec_TiffModule::Decode(CCodec_TiffContext* ctx, 535 FX_BOOL CCodec_TiffModule::Decode(CCodec_TiffContext* ctx,
540 class CFX_DIBitmap* pDIBitmap) { 536 class CFX_DIBitmap* pDIBitmap) {
541 return ctx->Decode(pDIBitmap); 537 return ctx->Decode(pDIBitmap);
542 } 538 }
543 539
544 void CCodec_TiffModule::DestroyDecoder(CCodec_TiffContext* ctx) { 540 void CCodec_TiffModule::DestroyDecoder(CCodec_TiffContext* ctx) {
545 delete ctx; 541 delete ctx;
546 } 542 }
OLDNEW
« no previous file with comments | « core/fxcodec/codec/fx_codec_progress.cpp ('k') | core/fxcodec/codec/include/ccodec_progressivedecoder.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698