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

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: Git rid of comparisons against NULL 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 175 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)); \
(...skipping 165 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

Powered by Google App Engine
This is Rietveld 408576698