| 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 "core/fxcodec/codec/codec_int.h" | 7 #include "core/fxcodec/codec/codec_int.h" |
| 8 #include "core/include/fxcodec/fx_codec.h" | 8 #include "core/include/fxcodec/fx_codec.h" |
| 9 #include "core/include/fxge/fx_dib.h" | 9 #include "core/include/fxge/fx_dib.h" |
| 10 | 10 |
| (...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 278 | 278 |
| 279 FX_BOOL CCodec_TiffContext::LoadFrameInfo(int32_t frame, | 279 FX_BOOL CCodec_TiffContext::LoadFrameInfo(int32_t frame, |
| 280 FX_DWORD& width, | 280 FX_DWORD& width, |
| 281 FX_DWORD& height, | 281 FX_DWORD& height, |
| 282 FX_DWORD& comps, | 282 FX_DWORD& comps, |
| 283 FX_DWORD& bpc, | 283 FX_DWORD& bpc, |
| 284 CFX_DIBAttribute* pAttribute) { | 284 CFX_DIBAttribute* pAttribute) { |
| 285 if (!TIFFSetDirectory(tif_ctx, (uint16)frame)) { | 285 if (!TIFFSetDirectory(tif_ctx, (uint16)frame)) { |
| 286 return FALSE; | 286 return FALSE; |
| 287 } | 287 } |
| 288 FX_WORD tif_cs; | 288 uint16_t tif_cs; |
| 289 FX_DWORD tif_icc_size = 0; | 289 FX_DWORD tif_icc_size = 0; |
| 290 uint8_t* tif_icc_buf = NULL; | 290 uint8_t* tif_icc_buf = NULL; |
| 291 FX_WORD tif_bpc = 0; | 291 uint16_t tif_bpc = 0; |
| 292 FX_WORD tif_cps; | 292 uint16_t tif_cps; |
| 293 FX_DWORD tif_rps; | 293 FX_DWORD tif_rps; |
| 294 width = height = comps = 0; | 294 width = height = comps = 0; |
| 295 TIFFGetField(tif_ctx, TIFFTAG_IMAGEWIDTH, &width); | 295 TIFFGetField(tif_ctx, TIFFTAG_IMAGEWIDTH, &width); |
| 296 TIFFGetField(tif_ctx, TIFFTAG_IMAGELENGTH, &height); | 296 TIFFGetField(tif_ctx, TIFFTAG_IMAGELENGTH, &height); |
| 297 TIFFGetField(tif_ctx, TIFFTAG_SAMPLESPERPIXEL, &comps); | 297 TIFFGetField(tif_ctx, TIFFTAG_SAMPLESPERPIXEL, &comps); |
| 298 TIFFGetField(tif_ctx, TIFFTAG_BITSPERSAMPLE, &tif_bpc); | 298 TIFFGetField(tif_ctx, TIFFTAG_BITSPERSAMPLE, &tif_bpc); |
| 299 TIFFGetField(tif_ctx, TIFFTAG_PHOTOMETRIC, &tif_cs); | 299 TIFFGetField(tif_ctx, TIFFTAG_PHOTOMETRIC, &tif_cs); |
| 300 TIFFGetField(tif_ctx, TIFFTAG_COMPRESSION, &tif_cps); | 300 TIFFGetField(tif_ctx, TIFFTAG_COMPRESSION, &tif_cps); |
| 301 TIFFGetField(tif_ctx, TIFFTAG_ROWSPERSTRIP, &tif_rps); | 301 TIFFGetField(tif_ctx, TIFFTAG_ROWSPERSTRIP, &tif_rps); |
| 302 TIFFGetField(tif_ctx, TIFFTAG_ICCPROFILE, &tif_icc_size, &tif_icc_buf); | 302 TIFFGetField(tif_ctx, TIFFTAG_ICCPROFILE, &tif_icc_size, &tif_icc_buf); |
| 303 if (pAttribute) { | 303 if (pAttribute) { |
| 304 pAttribute->m_wDPIUnit = FXCODEC_RESUNIT_INCH; | 304 pAttribute->m_wDPIUnit = FXCODEC_RESUNIT_INCH; |
| 305 if (TIFFGetField(tif_ctx, TIFFTAG_RESOLUTIONUNIT, | 305 if (TIFFGetField(tif_ctx, TIFFTAG_RESOLUTIONUNIT, |
| 306 &pAttribute->m_wDPIUnit)) { | 306 &pAttribute->m_wDPIUnit)) { |
| 307 pAttribute->m_wDPIUnit -= 1; | 307 pAttribute->m_wDPIUnit -= 1; |
| 308 } | 308 } |
| 309 Tiff_Exif_GetInfo<FX_WORD>(tif_ctx, TIFFTAG_ORIENTATION, pAttribute); | 309 Tiff_Exif_GetInfo<uint16_t>(tif_ctx, TIFFTAG_ORIENTATION, pAttribute); |
| 310 if (Tiff_Exif_GetInfo<FX_FLOAT>(tif_ctx, TIFFTAG_XRESOLUTION, pAttribute)) { | 310 if (Tiff_Exif_GetInfo<FX_FLOAT>(tif_ctx, TIFFTAG_XRESOLUTION, pAttribute)) { |
| 311 void* val = pAttribute->m_Exif[TIFFTAG_XRESOLUTION]; | 311 void* val = pAttribute->m_Exif[TIFFTAG_XRESOLUTION]; |
| 312 FX_FLOAT fDpi = val ? *reinterpret_cast<FX_FLOAT*>(val) : 0; | 312 FX_FLOAT fDpi = val ? *reinterpret_cast<FX_FLOAT*>(val) : 0; |
| 313 pAttribute->m_nXDPI = (int32_t)(fDpi + 0.5f); | 313 pAttribute->m_nXDPI = (int32_t)(fDpi + 0.5f); |
| 314 } | 314 } |
| 315 if (Tiff_Exif_GetInfo<FX_FLOAT>(tif_ctx, TIFFTAG_YRESOLUTION, pAttribute)) { | 315 if (Tiff_Exif_GetInfo<FX_FLOAT>(tif_ctx, TIFFTAG_YRESOLUTION, pAttribute)) { |
| 316 void* val = pAttribute->m_Exif[TIFFTAG_YRESOLUTION]; | 316 void* val = pAttribute->m_Exif[TIFFTAG_YRESOLUTION]; |
| 317 FX_FLOAT fDpi = val ? *reinterpret_cast<FX_FLOAT*>(val) : 0; | 317 FX_FLOAT fDpi = val ? *reinterpret_cast<FX_FLOAT*>(val) : 0; |
| 318 pAttribute->m_nYDPI = (int32_t)(fDpi + 0.5f); | 318 pAttribute->m_nYDPI = (int32_t)(fDpi + 0.5f); |
| 319 } | 319 } |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 480 FX_DWORD img_wid = pDIBitmap->GetWidth(); | 480 FX_DWORD img_wid = pDIBitmap->GetWidth(); |
| 481 FX_DWORD img_hei = pDIBitmap->GetHeight(); | 481 FX_DWORD img_hei = pDIBitmap->GetHeight(); |
| 482 FX_DWORD width = 0; | 482 FX_DWORD width = 0; |
| 483 FX_DWORD height = 0; | 483 FX_DWORD height = 0; |
| 484 TIFFGetField(tif_ctx, TIFFTAG_IMAGEWIDTH, &width); | 484 TIFFGetField(tif_ctx, TIFFTAG_IMAGEWIDTH, &width); |
| 485 TIFFGetField(tif_ctx, TIFFTAG_IMAGELENGTH, &height); | 485 TIFFGetField(tif_ctx, TIFFTAG_IMAGELENGTH, &height); |
| 486 if (img_wid != width || img_hei != height) { | 486 if (img_wid != width || img_hei != height) { |
| 487 return FALSE; | 487 return FALSE; |
| 488 } | 488 } |
| 489 if (pDIBitmap->GetBPP() == 32) { | 489 if (pDIBitmap->GetBPP() == 32) { |
| 490 FX_WORD rotation = ORIENTATION_TOPLEFT; | 490 uint16_t rotation = ORIENTATION_TOPLEFT; |
| 491 TIFFGetField(tif_ctx, TIFFTAG_ORIENTATION, &rotation); | 491 TIFFGetField(tif_ctx, TIFFTAG_ORIENTATION, &rotation); |
| 492 if (TIFFReadRGBAImageOriented(tif_ctx, img_wid, img_hei, | 492 if (TIFFReadRGBAImageOriented(tif_ctx, img_wid, img_hei, |
| 493 (uint32*)pDIBitmap->GetBuffer(), rotation, | 493 (uint32*)pDIBitmap->GetBuffer(), rotation, |
| 494 1)) { | 494 1)) { |
| 495 for (FX_DWORD row = 0; row < img_hei; row++) { | 495 for (FX_DWORD row = 0; row < img_hei; row++) { |
| 496 uint8_t* row_buf = (uint8_t*)pDIBitmap->GetScanline(row); | 496 uint8_t* row_buf = (uint8_t*)pDIBitmap->GetScanline(row); |
| 497 _TiffBGRA2RGBA(row_buf, img_wid, 4); | 497 _TiffBGRA2RGBA(row_buf, img_wid, 4); |
| 498 } | 498 } |
| 499 return TRUE; | 499 return TRUE; |
| 500 } | 500 } |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 535 return pDecoder->LoadFrameInfo(frame, width, height, comps, bpc, pAttribute); | 535 return pDecoder->LoadFrameInfo(frame, width, height, comps, bpc, pAttribute); |
| 536 } | 536 } |
| 537 FX_BOOL CCodec_TiffModule::Decode(void* ctx, class CFX_DIBitmap* pDIBitmap) { | 537 FX_BOOL CCodec_TiffModule::Decode(void* ctx, class CFX_DIBitmap* pDIBitmap) { |
| 538 CCodec_TiffContext* pDecoder = (CCodec_TiffContext*)ctx; | 538 CCodec_TiffContext* pDecoder = (CCodec_TiffContext*)ctx; |
| 539 return pDecoder->Decode(pDIBitmap); | 539 return pDecoder->Decode(pDIBitmap); |
| 540 } | 540 } |
| 541 void CCodec_TiffModule::DestroyDecoder(void* ctx) { | 541 void CCodec_TiffModule::DestroyDecoder(void* ctx) { |
| 542 CCodec_TiffContext* pDecoder = (CCodec_TiffContext*)ctx; | 542 CCodec_TiffContext* pDecoder = (CCodec_TiffContext*)ctx; |
| 543 delete pDecoder; | 543 delete pDecoder; |
| 544 } | 544 } |
| OLD | NEW |