| 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 "../../../include/fxcodec/fx_codec.h" | 7 #include "../../../include/fxcodec/fx_codec.h" |
| 8 #include "../../../include/fxge/fx_dib.h" | 8 #include "../../../include/fxge/fx_dib.h" |
| 9 #include "codec_int.h" | 9 #include "codec_int.h" |
| 10 extern "C" { | 10 extern "C" { |
| 11 #include "../fx_tiff/include/fx_tiffiop.h" | 11 #include "../fx_tiff/include/fx_tiffiop.h" |
| 12 } | 12 } |
| 13 void* IccLib_CreateTransform_sRGB(const unsigned char* pProfileData, unsigned in
t dwProfileSize, int nComponents, int intent, FX_DWORD dwSrcFormat = Icc_FORMAT_
DEFAULT); | 13 void* IccLib_CreateTransform_sRGB(const unsigned char* pProfileData, unsigned in
t dwProfileSize, int nComponents, int intent, FX_DWORD dwSrcFormat = Icc_FORMAT_
DEFAULT); |
| 14 void IccLib_TranslateImage(void* pTransform, unsigned char* pDest, const unsigne
d char* pSrc, int pixels); | 14 void IccLib_TranslateImage(void* pTransform, unsigned char* pDest, const unsigne
d char* pSrc, int pixels); |
| 15 void IccLib_DestroyTransform(void* pTransform); | 15 void IccLib_DestroyTransform(void* pTransform); |
| 16 class CCodec_TiffContext | 16 class CCodec_TiffContext |
| 17 { | 17 { |
| 18 public: | 18 public: |
| 19 CCodec_TiffContext(); | 19 CCodec_TiffContext(); |
| 20 ~CCodec_TiffContext(); | 20 ~CCodec_TiffContext(); |
| 21 | 21 |
| 22 FX_BOOL InitDecoder(IFX_FileRead* file_ptr); | 22 FX_BOOL InitDecoder(IFX_FileRead* file_ptr); |
| 23 void» GetFrames(FX_INT32& frames); | 23 void» GetFrames(int32_t& frames); |
| 24 FX_BOOL» LoadFrameInfo(FX_INT32 frame, FX_DWORD& width, FX_DWORD& height,
FX_DWORD& comps, FX_DWORD& bpc, CFX_DIBAttribute* pAttribute); | 24 FX_BOOL» LoadFrameInfo(int32_t frame, FX_DWORD& width, FX_DWORD& height,
FX_DWORD& comps, FX_DWORD& bpc, CFX_DIBAttribute* pAttribute); |
| 25 FX_BOOL Decode(CFX_DIBitmap* pDIBitmap); | 25 FX_BOOL Decode(CFX_DIBitmap* pDIBitmap); |
| 26 | 26 |
| 27 union { | 27 union { |
| 28 IFX_FileRead* in; | 28 IFX_FileRead* in; |
| 29 IFX_FileStream* out; | 29 IFX_FileStream* out; |
| 30 } io; | 30 } io; |
| 31 | 31 |
| 32 FX_DWORD offset; | 32 FX_DWORD offset; |
| 33 | 33 |
| 34 TIFF* tif_ctx; | 34 TIFF* tif_ctx; |
| 35 void* icc_ctx; | 35 void* icc_ctx; |
| 36 FX_INT32» » frame_num; | 36 int32_t» » frame_num; |
| 37 FX_INT32» » frame_cur; | 37 int32_t» » frame_cur; |
| 38 FX_BOOL isDecoder; | 38 FX_BOOL isDecoder; |
| 39 private: | 39 private: |
| 40 FX_BOOL isSupport(CFX_DIBitmap* pDIBitmap); | 40 FX_BOOL isSupport(CFX_DIBitmap* pDIBitmap); |
| 41 void» SetPalette(CFX_DIBitmap* pDIBitmap, FX_UINT16 bps); | 41 void» SetPalette(CFX_DIBitmap* pDIBitmap, uint16_t bps); |
| 42 FX_BOOL» Decode1bppRGB(CFX_DIBitmap* pDIBitmap, FX_INT32 height, FX_INT32
width, FX_UINT16 bps, FX_UINT16 spp); | 42 FX_BOOL» Decode1bppRGB(CFX_DIBitmap* pDIBitmap, int32_t height, int32_t w
idth, uint16_t bps, uint16_t spp); |
| 43 FX_BOOL» Decode8bppRGB(CFX_DIBitmap* pDIBitmap, FX_INT32 height, FX_INT32
width, FX_UINT16 bps, FX_UINT16 spp); | 43 FX_BOOL» Decode8bppRGB(CFX_DIBitmap* pDIBitmap, int32_t height, int32_t w
idth, uint16_t bps, uint16_t spp); |
| 44 FX_BOOL» Decode24bppRGB(CFX_DIBitmap* pDIBitmap, FX_INT32 height, FX_INT3
2 width, FX_UINT16 bps, FX_UINT16 spp); | 44 FX_BOOL» Decode24bppRGB(CFX_DIBitmap* pDIBitmap, int32_t height, int32_t
width, uint16_t bps, uint16_t spp); |
| 45 }; | 45 }; |
| 46 CCodec_TiffContext::CCodec_TiffContext() | 46 CCodec_TiffContext::CCodec_TiffContext() |
| 47 { | 47 { |
| 48 offset = 0; | 48 offset = 0; |
| 49 frame_num = 0; | 49 frame_num = 0; |
| 50 frame_cur = 0; | 50 frame_cur = 0; |
| 51 io.in = NULL; | 51 io.in = NULL; |
| 52 tif_ctx = NULL; | 52 tif_ctx = NULL; |
| 53 icc_ctx = NULL; | 53 icc_ctx = NULL; |
| 54 isDecoder = TRUE; | 54 isDecoder = TRUE; |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 return 0; | 135 return 0; |
| 136 } | 136 } |
| 137 static void _tiff_unmap(thandle_t context, tdata_t, toff_t) {} | 137 static void _tiff_unmap(thandle_t context, tdata_t, toff_t) {} |
| 138 TIFF* _tiff_open(void* context, const char* mode) | 138 TIFF* _tiff_open(void* context, const char* mode) |
| 139 { | 139 { |
| 140 TIFF* tif = TIFFClientOpen("Tiff Image", mode, | 140 TIFF* tif = TIFFClientOpen("Tiff Image", mode, |
| 141 (thandle_t)context, | 141 (thandle_t)context, |
| 142 _tiff_read, _tiff_write, _tiff_seek, _tiff_close, | 142 _tiff_read, _tiff_write, _tiff_seek, _tiff_close, |
| 143 _tiff_get_size, _tiff_map, _tiff_unmap); | 143 _tiff_get_size, _tiff_map, _tiff_unmap); |
| 144 if(tif) { | 144 if(tif) { |
| 145 tif->tif_fd = (int)(FX_INTPTR)context; | 145 tif->tif_fd = (int)(intptr_t)context; |
| 146 } | 146 } |
| 147 return tif; | 147 return tif; |
| 148 } | 148 } |
| 149 void* _TIFFmalloc(tmsize_t size) | 149 void* _TIFFmalloc(tmsize_t size) |
| 150 { | 150 { |
| 151 return FXMEM_DefaultAlloc(size, 0); | 151 return FXMEM_DefaultAlloc(size, 0); |
| 152 } | 152 } |
| 153 void _TIFFfree(void* ptr) | 153 void _TIFFfree(void* ptr) |
| 154 { | 154 { |
| 155 FXMEM_DefaultFree(ptr, 0); | 155 FXMEM_DefaultFree(ptr, 0); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 200 } | 200 } |
| 201 FX_BOOL CCodec_TiffContext::InitDecoder(IFX_FileRead* file_ptr) | 201 FX_BOOL CCodec_TiffContext::InitDecoder(IFX_FileRead* file_ptr) |
| 202 { | 202 { |
| 203 io.in = file_ptr; | 203 io.in = file_ptr; |
| 204 tif_ctx = _tiff_open(this, "r"); | 204 tif_ctx = _tiff_open(this, "r"); |
| 205 if(tif_ctx == NULL) { | 205 if(tif_ctx == NULL) { |
| 206 return FALSE; | 206 return FALSE; |
| 207 } | 207 } |
| 208 return TRUE; | 208 return TRUE; |
| 209 } | 209 } |
| 210 void CCodec_TiffContext::GetFrames(FX_INT32& frames) | 210 void CCodec_TiffContext::GetFrames(int32_t& frames) |
| 211 { | 211 { |
| 212 frames = frame_num = TIFFNumberOfDirectories(tif_ctx); | 212 frames = frame_num = TIFFNumberOfDirectories(tif_ctx); |
| 213 } | 213 } |
| 214 #define TIFF_EXIF_GETINFO(key, T, tag) {\ | 214 #define TIFF_EXIF_GETINFO(key, T, tag) {\ |
| 215 T val = (T)0;\ | 215 T val = (T)0;\ |
| 216 TIFFGetField(tif_ctx,tag,&val);\ | 216 TIFFGetField(tif_ctx,tag,&val);\ |
| 217 if (val) {\ | 217 if (val) {\ |
| 218 (key) = FX_Alloc(FX_BYTE,sizeof(T));\ | 218 (key) = FX_Alloc(uint8_t,sizeof(T));\ |
| 219 if ((key)) {\ | 219 if ((key)) {\ |
| 220 T* ptr = (T*)(key);\ | 220 T* ptr = (T*)(key);\ |
| 221 *ptr = val;\ | 221 *ptr = val;\ |
| 222 pExif->m_TagVal.SetAt(tag,(key));}}}\ | 222 pExif->m_TagVal.SetAt(tag,(key));}}}\ |
| 223 (key) = NULL; | 223 (key) = NULL; |
| 224 #define TIFF_EXIF_GETSTRINGINFO(key, tag) {\ | 224 #define TIFF_EXIF_GETSTRINGINFO(key, tag) {\ |
| 225 FX_DWORD size = 0;\ | 225 FX_DWORD size = 0;\ |
| 226 FX_LPBYTE buf = NULL;\ | 226 FX_LPBYTE buf = NULL;\ |
| 227 TIFFGetField(tif_ctx,tag,&size, &buf);\ | 227 TIFFGetField(tif_ctx,tag,&size, &buf);\ |
| 228 if (size && buf) {\ | 228 if (size && buf) {\ |
| 229 (key) = FX_Alloc(FX_BYTE,size);\ | 229 (key) = FX_Alloc(uint8_t,size);\ |
| 230 if ((key)) {\ | 230 if ((key)) {\ |
| 231 FXSYS_memcpy32((key),buf,size);\ | 231 FXSYS_memcpy32((key),buf,size);\ |
| 232 pExif->m_TagVal.SetAt(tag,(key));}}}\ | 232 pExif->m_TagVal.SetAt(tag,(key));}}}\ |
| 233 (key) = NULL; | 233 (key) = NULL; |
| 234 template <class T> | 234 template <class T> |
| 235 static FX_BOOL Tiff_Exif_GetInfo(TIFF* tif_ctx, ttag_t tag, CFX_DIBAttributeExif
* pExif) | 235 static FX_BOOL Tiff_Exif_GetInfo(TIFF* tif_ctx, ttag_t tag, CFX_DIBAttributeExif
* pExif) |
| 236 { | 236 { |
| 237 FX_LPBYTE key = NULL; | 237 FX_LPBYTE key = NULL; |
| 238 T val = (T)0; | 238 T val = (T)0; |
| 239 TIFFGetField(tif_ctx, tag, &val); | 239 TIFFGetField(tif_ctx, tag, &val); |
| 240 if (val) { | 240 if (val) { |
| 241 (key) = FX_Alloc(FX_BYTE, sizeof(T)); | 241 (key) = FX_Alloc(uint8_t, sizeof(T)); |
| 242 if ((key) == NULL) { | 242 if ((key) == NULL) { |
| 243 return FALSE; | 243 return FALSE; |
| 244 } | 244 } |
| 245 T* ptr = (T*)(key); | 245 T* ptr = (T*)(key); |
| 246 *ptr = val; | 246 *ptr = val; |
| 247 pExif->m_TagVal.SetAt(tag, (key)); | 247 pExif->m_TagVal.SetAt(tag, (key)); |
| 248 return TRUE; | 248 return TRUE; |
| 249 } | 249 } |
| 250 return FALSE; | 250 return FALSE; |
| 251 } | 251 } |
| 252 static void Tiff_Exif_GetStringInfo(TIFF* tif_ctx, ttag_t tag, CFX_DIBAttributeE
xif* pExif) | 252 static void Tiff_Exif_GetStringInfo(TIFF* tif_ctx, ttag_t tag, CFX_DIBAttributeE
xif* pExif) |
| 253 { | 253 { |
| 254 FX_LPSTR buf = NULL; | 254 FX_LPSTR buf = NULL; |
| 255 FX_LPBYTE key = NULL; | 255 FX_LPBYTE key = NULL; |
| 256 TIFFGetField(tif_ctx, tag, &buf); | 256 TIFFGetField(tif_ctx, tag, &buf); |
| 257 if (buf) { | 257 if (buf) { |
| 258 FX_INT32 size = (FX_INT32)FXSYS_strlen(buf); | 258 int32_t size = (int32_t)FXSYS_strlen(buf); |
| 259 (key) = FX_Alloc(FX_BYTE, size + 1); | 259 (key) = FX_Alloc(uint8_t, size + 1); |
| 260 if ((key) == NULL) { | 260 if ((key) == NULL) { |
| 261 return; | 261 return; |
| 262 } | 262 } |
| 263 FXSYS_memcpy32((key), buf, size); | 263 FXSYS_memcpy32((key), buf, size); |
| 264 key[size] = 0; | 264 key[size] = 0; |
| 265 pExif->m_TagVal.SetAt(tag, (key)); | 265 pExif->m_TagVal.SetAt(tag, (key)); |
| 266 } | 266 } |
| 267 } | 267 } |
| 268 FX_BOOL CCodec_TiffContext::LoadFrameInfo(FX_INT32 frame, FX_DWORD& width, FX_DW
ORD& height, FX_DWORD& comps, FX_DWORD& bpc, CFX_DIBAttribute* pAttribute) | 268 FX_BOOL CCodec_TiffContext::LoadFrameInfo(int32_t frame, FX_DWORD& width, FX_DWO
RD& height, FX_DWORD& comps, FX_DWORD& bpc, CFX_DIBAttribute* pAttribute) |
| 269 { | 269 { |
| 270 if (!TIFFSetDirectory(tif_ctx, (uint16)frame)) { | 270 if (!TIFFSetDirectory(tif_ctx, (uint16)frame)) { |
| 271 return FALSE; | 271 return FALSE; |
| 272 } | 272 } |
| 273 FX_WORD tif_cs; | 273 FX_WORD tif_cs; |
| 274 FX_DWORD tif_icc_size = 0; | 274 FX_DWORD tif_icc_size = 0; |
| 275 FX_LPBYTE tif_icc_buf = NULL; | 275 FX_LPBYTE tif_icc_buf = NULL; |
| 276 FX_WORD tif_bpc = 0; | 276 FX_WORD tif_bpc = 0; |
| 277 FX_WORD tif_cps; | 277 FX_WORD tif_cps; |
| 278 FX_DWORD tif_rps; | 278 FX_DWORD tif_rps; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 289 pAttribute->m_wDPIUnit = FXCODEC_RESUNIT_INCH; | 289 pAttribute->m_wDPIUnit = FXCODEC_RESUNIT_INCH; |
| 290 if (TIFFGetField(tif_ctx, TIFFTAG_RESOLUTIONUNIT, &pAttribute->m_wDPIUni
t)) { | 290 if (TIFFGetField(tif_ctx, TIFFTAG_RESOLUTIONUNIT, &pAttribute->m_wDPIUni
t)) { |
| 291 pAttribute->m_wDPIUnit -= 1; | 291 pAttribute->m_wDPIUnit -= 1; |
| 292 } | 292 } |
| 293 CFX_DIBAttributeExif* pExif = (CFX_DIBAttributeExif*)pAttribute->m_pExif
; | 293 CFX_DIBAttributeExif* pExif = (CFX_DIBAttributeExif*)pAttribute->m_pExif
; |
| 294 pExif->clear(); | 294 pExif->clear(); |
| 295 Tiff_Exif_GetInfo<FX_WORD>(tif_ctx, TIFFTAG_ORIENTATION, pExif); | 295 Tiff_Exif_GetInfo<FX_WORD>(tif_ctx, TIFFTAG_ORIENTATION, pExif); |
| 296 if (Tiff_Exif_GetInfo<FX_FLOAT>(tif_ctx, TIFFTAG_XRESOLUTION, pExif)) { | 296 if (Tiff_Exif_GetInfo<FX_FLOAT>(tif_ctx, TIFFTAG_XRESOLUTION, pExif)) { |
| 297 FX_FLOAT fDpi = 0; | 297 FX_FLOAT fDpi = 0; |
| 298 pExif->GetInfo(TIFFTAG_XRESOLUTION, &fDpi); | 298 pExif->GetInfo(TIFFTAG_XRESOLUTION, &fDpi); |
| 299 pAttribute->m_nXDPI = (FX_INT32)(fDpi + 0.5f); | 299 pAttribute->m_nXDPI = (int32_t)(fDpi + 0.5f); |
| 300 } | 300 } |
| 301 if (Tiff_Exif_GetInfo<FX_FLOAT>(tif_ctx, TIFFTAG_YRESOLUTION, pExif)) { | 301 if (Tiff_Exif_GetInfo<FX_FLOAT>(tif_ctx, TIFFTAG_YRESOLUTION, pExif)) { |
| 302 FX_FLOAT fDpi = 0; | 302 FX_FLOAT fDpi = 0; |
| 303 pExif->GetInfo(TIFFTAG_YRESOLUTION, &fDpi); | 303 pExif->GetInfo(TIFFTAG_YRESOLUTION, &fDpi); |
| 304 pAttribute->m_nYDPI = (FX_INT32)(fDpi + 0.5f); | 304 pAttribute->m_nYDPI = (int32_t)(fDpi + 0.5f); |
| 305 } | 305 } |
| 306 Tiff_Exif_GetStringInfo(tif_ctx, TIFFTAG_IMAGEDESCRIPTION, pExif); | 306 Tiff_Exif_GetStringInfo(tif_ctx, TIFFTAG_IMAGEDESCRIPTION, pExif); |
| 307 Tiff_Exif_GetStringInfo(tif_ctx, TIFFTAG_MAKE, pExif); | 307 Tiff_Exif_GetStringInfo(tif_ctx, TIFFTAG_MAKE, pExif); |
| 308 Tiff_Exif_GetStringInfo(tif_ctx, TIFFTAG_MODEL, pExif); | 308 Tiff_Exif_GetStringInfo(tif_ctx, TIFFTAG_MODEL, pExif); |
| 309 } | 309 } |
| 310 bpc = tif_bpc; | 310 bpc = tif_bpc; |
| 311 if(tif_rps > height) { | 311 if(tif_rps > height) { |
| 312 TIFFSetField(tif_ctx, TIFFTAG_ROWSPERSTRIP, tif_rps = height); | 312 TIFFSetField(tif_ctx, TIFFTAG_ROWSPERSTRIP, tif_rps = height); |
| 313 } | 313 } |
| 314 return TRUE; | 314 return TRUE; |
| 315 } | 315 } |
| 316 void _TiffBGRA2RGBA(FX_LPBYTE pBuf, FX_INT32 pixel, FX_INT32 spp) | 316 void _TiffBGRA2RGBA(FX_LPBYTE pBuf, int32_t pixel, int32_t spp) |
| 317 { | 317 { |
| 318 register FX_BYTE tmp; | 318 register uint8_t tmp; |
| 319 for (FX_INT32 n = 0; n < pixel; n++) { | 319 for (int32_t n = 0; n < pixel; n++) { |
| 320 tmp = pBuf[0]; | 320 tmp = pBuf[0]; |
| 321 pBuf[0] = pBuf[2]; | 321 pBuf[0] = pBuf[2]; |
| 322 pBuf[2] = tmp; | 322 pBuf[2] = tmp; |
| 323 pBuf += spp; | 323 pBuf += spp; |
| 324 } | 324 } |
| 325 } | 325 } |
| 326 FX_BOOL CCodec_TiffContext::isSupport(CFX_DIBitmap* pDIBitmap) | 326 FX_BOOL CCodec_TiffContext::isSupport(CFX_DIBitmap* pDIBitmap) |
| 327 { | 327 { |
| 328 if (TIFFIsTiled(tif_ctx)) { | 328 if (TIFFIsTiled(tif_ctx)) { |
| 329 return FALSE; | 329 return FALSE; |
| 330 } | 330 } |
| 331 FX_UINT16 photometric; | 331 uint16_t photometric; |
| 332 if (!TIFFGetField(tif_ctx, TIFFTAG_PHOTOMETRIC, &photometric)) { | 332 if (!TIFFGetField(tif_ctx, TIFFTAG_PHOTOMETRIC, &photometric)) { |
| 333 return FALSE; | 333 return FALSE; |
| 334 } | 334 } |
| 335 switch (pDIBitmap->GetBPP()) { | 335 switch (pDIBitmap->GetBPP()) { |
| 336 case 1: | 336 case 1: |
| 337 case 8: | 337 case 8: |
| 338 if (photometric != PHOTOMETRIC_PALETTE) { | 338 if (photometric != PHOTOMETRIC_PALETTE) { |
| 339 return FALSE; | 339 return FALSE; |
| 340 } | 340 } |
| 341 break; | 341 break; |
| 342 case 24: | 342 case 24: |
| 343 if (photometric != PHOTOMETRIC_RGB) { | 343 if (photometric != PHOTOMETRIC_RGB) { |
| 344 return FALSE; | 344 return FALSE; |
| 345 } | 345 } |
| 346 break; | 346 break; |
| 347 default: | 347 default: |
| 348 return FALSE; | 348 return FALSE; |
| 349 } | 349 } |
| 350 FX_UINT16 planarconfig; | 350 uint16_t planarconfig; |
| 351 if (!TIFFGetFieldDefaulted(tif_ctx, TIFFTAG_PLANARCONFIG, &planarconfig)) { | 351 if (!TIFFGetFieldDefaulted(tif_ctx, TIFFTAG_PLANARCONFIG, &planarconfig)) { |
| 352 return FALSE; | 352 return FALSE; |
| 353 } | 353 } |
| 354 if (planarconfig == PLANARCONFIG_SEPARATE) { | 354 if (planarconfig == PLANARCONFIG_SEPARATE) { |
| 355 return FALSE; | 355 return FALSE; |
| 356 } | 356 } |
| 357 return TRUE; | 357 return TRUE; |
| 358 } | 358 } |
| 359 void CCodec_TiffContext::SetPalette(CFX_DIBitmap* pDIBitmap, FX_UINT16 bps) | 359 void CCodec_TiffContext::SetPalette(CFX_DIBitmap* pDIBitmap, uint16_t bps) |
| 360 { | 360 { |
| 361 FX_UINT16 *red_orig, *green_orig, *blue_orig; | 361 uint16_t *red_orig, *green_orig, *blue_orig; |
| 362 TIFFGetField(tif_ctx, TIFFTAG_COLORMAP, &red_orig, &green_orig, &blue_orig); | 362 TIFFGetField(tif_ctx, TIFFTAG_COLORMAP, &red_orig, &green_orig, &blue_orig); |
| 363 for (FX_INT32 i = (1L << bps) - 1; i >= 0; i--) { | 363 for (int32_t i = (1L << bps) - 1; i >= 0; i--) { |
| 364 #define»CVT(x)» » ((FX_UINT16)((x)>>8)) | 364 #define»CVT(x)» » ((uint16_t)((x)>>8)) |
| 365 red_orig[i] = CVT(red_orig[i]); | 365 red_orig[i] = CVT(red_orig[i]); |
| 366 green_orig[i] = CVT(green_orig[i]); | 366 green_orig[i] = CVT(green_orig[i]); |
| 367 blue_orig[i] = CVT(blue_orig[i]); | 367 blue_orig[i] = CVT(blue_orig[i]); |
| 368 #undef CVT | 368 #undef CVT |
| 369 } | 369 } |
| 370 FX_INT32 len = 1 << bps; | 370 int32_t len = 1 << bps; |
| 371 for(FX_INT32 index = 0; index < len; index++) { | 371 for(int32_t index = 0; index < len; index++) { |
| 372 FX_DWORD r = red_orig[index] & 0xFF; | 372 FX_DWORD r = red_orig[index] & 0xFF; |
| 373 FX_DWORD g = green_orig[index] & 0xFF; | 373 FX_DWORD g = green_orig[index] & 0xFF; |
| 374 FX_DWORD b = blue_orig[index] & 0xFF; | 374 FX_DWORD b = blue_orig[index] & 0xFF; |
| 375 FX_DWORD color = (FX_UINT32)b | ((FX_UINT32)g << 8) | ((FX_UINT32)r << 1
6) | (((uint32)0xffL) << 24); | 375 FX_DWORD color = (uint32_t)b | ((uint32_t)g << 8) | ((uint32_t)r << 16)
| (((uint32)0xffL) << 24); |
| 376 pDIBitmap->SetPaletteEntry(index, color); | 376 pDIBitmap->SetPaletteEntry(index, color); |
| 377 } | 377 } |
| 378 } | 378 } |
| 379 FX_BOOL CCodec_TiffContext::Decode1bppRGB(CFX_DIBitmap* pDIBitmap, FX_INT32 heig
ht, FX_INT32 width, FX_UINT16 bps, FX_UINT16 spp) | 379 FX_BOOL CCodec_TiffContext::Decode1bppRGB(CFX_DIBitmap* pDIBitmap, int32_t heigh
t, int32_t width, uint16_t bps, uint16_t spp) |
| 380 { | 380 { |
| 381 if (pDIBitmap->GetBPP() != 1 || spp != 1 || bps != 1 || !isSupport(pDIBitmap
)) { | 381 if (pDIBitmap->GetBPP() != 1 || spp != 1 || bps != 1 || !isSupport(pDIBitmap
)) { |
| 382 return FALSE; | 382 return FALSE; |
| 383 } | 383 } |
| 384 SetPalette(pDIBitmap, bps); | 384 SetPalette(pDIBitmap, bps); |
| 385 FX_INT32 size = (FX_INT32)TIFFScanlineSize(tif_ctx); | 385 int32_t size = (int32_t)TIFFScanlineSize(tif_ctx); |
| 386 FX_LPBYTE buf = (FX_LPBYTE)_TIFFmalloc(size); | 386 FX_LPBYTE buf = (FX_LPBYTE)_TIFFmalloc(size); |
| 387 if (buf == NULL) { | 387 if (buf == NULL) { |
| 388 TIFFError(TIFFFileName(tif_ctx), "No space for scanline buffer"); | 388 TIFFError(TIFFFileName(tif_ctx), "No space for scanline buffer"); |
| 389 return FALSE; | 389 return FALSE; |
| 390 } | 390 } |
| 391 FX_LPBYTE bitMapbuffer = (FX_LPBYTE)pDIBitmap->GetBuffer(); | 391 FX_LPBYTE bitMapbuffer = (FX_LPBYTE)pDIBitmap->GetBuffer(); |
| 392 FX_DWORD pitch = pDIBitmap->GetPitch(); | 392 FX_DWORD pitch = pDIBitmap->GetPitch(); |
| 393 for(FX_INT32 row = 0; row < height; row++) { | 393 for(int32_t row = 0; row < height; row++) { |
| 394 TIFFReadScanline(tif_ctx, buf, row, 0); | 394 TIFFReadScanline(tif_ctx, buf, row, 0); |
| 395 for(FX_INT32 j = 0; j < size; j++) { | 395 for(int32_t j = 0; j < size; j++) { |
| 396 bitMapbuffer[row * pitch + j] = buf[j]; | 396 bitMapbuffer[row * pitch + j] = buf[j]; |
| 397 } | 397 } |
| 398 } | 398 } |
| 399 _TIFFfree(buf); | 399 _TIFFfree(buf); |
| 400 return TRUE; | 400 return TRUE; |
| 401 } | 401 } |
| 402 FX_BOOL CCodec_TiffContext::Decode8bppRGB(CFX_DIBitmap* pDIBitmap, FX_INT32 heig
ht, FX_INT32 width, FX_UINT16 bps, FX_UINT16 spp) | 402 FX_BOOL CCodec_TiffContext::Decode8bppRGB(CFX_DIBitmap* pDIBitmap, int32_t heigh
t, int32_t width, uint16_t bps, uint16_t spp) |
| 403 { | 403 { |
| 404 if (pDIBitmap->GetBPP() != 8 || spp != 1 || (bps != 4 && bps != 8) || !isSup
port(pDIBitmap)) { | 404 if (pDIBitmap->GetBPP() != 8 || spp != 1 || (bps != 4 && bps != 8) || !isSup
port(pDIBitmap)) { |
| 405 return FALSE; | 405 return FALSE; |
| 406 } | 406 } |
| 407 SetPalette(pDIBitmap, bps); | 407 SetPalette(pDIBitmap, bps); |
| 408 FX_INT32 size = (FX_INT32)TIFFScanlineSize(tif_ctx); | 408 int32_t size = (int32_t)TIFFScanlineSize(tif_ctx); |
| 409 FX_LPBYTE buf = (FX_LPBYTE)_TIFFmalloc(size); | 409 FX_LPBYTE buf = (FX_LPBYTE)_TIFFmalloc(size); |
| 410 if (buf == NULL) { | 410 if (buf == NULL) { |
| 411 TIFFError(TIFFFileName(tif_ctx), "No space for scanline buffer"); | 411 TIFFError(TIFFFileName(tif_ctx), "No space for scanline buffer"); |
| 412 return FALSE; | 412 return FALSE; |
| 413 } | 413 } |
| 414 FX_LPBYTE bitMapbuffer = (FX_LPBYTE)pDIBitmap->GetBuffer(); | 414 FX_LPBYTE bitMapbuffer = (FX_LPBYTE)pDIBitmap->GetBuffer(); |
| 415 FX_DWORD pitch = pDIBitmap->GetPitch(); | 415 FX_DWORD pitch = pDIBitmap->GetPitch(); |
| 416 for(FX_INT32 row = 0; row < height; row++) { | 416 for(int32_t row = 0; row < height; row++) { |
| 417 TIFFReadScanline(tif_ctx, buf, row, 0); | 417 TIFFReadScanline(tif_ctx, buf, row, 0); |
| 418 for(FX_INT32 j = 0; j < size; j++) { | 418 for(int32_t j = 0; j < size; j++) { |
| 419 switch(bps) { | 419 switch(bps) { |
| 420 case 4: | 420 case 4: |
| 421 bitMapbuffer[row * pitch + 2 * j + 0] = (buf[j] & 0xF0) >> 4
; | 421 bitMapbuffer[row * pitch + 2 * j + 0] = (buf[j] & 0xF0) >> 4
; |
| 422 bitMapbuffer[row * pitch + 2 * j + 1] = (buf[j] & 0x0F) >> 0
; | 422 bitMapbuffer[row * pitch + 2 * j + 1] = (buf[j] & 0x0F) >> 0
; |
| 423 break; | 423 break; |
| 424 case 8: | 424 case 8: |
| 425 bitMapbuffer[row * pitch + j] = buf[j]; | 425 bitMapbuffer[row * pitch + j] = buf[j]; |
| 426 break; | 426 break; |
| 427 } | 427 } |
| 428 } | 428 } |
| 429 } | 429 } |
| 430 _TIFFfree(buf); | 430 _TIFFfree(buf); |
| 431 return TRUE; | 431 return TRUE; |
| 432 } | 432 } |
| 433 FX_BOOL CCodec_TiffContext::Decode24bppRGB(CFX_DIBitmap* pDIBitmap, FX_INT32 hei
ght, FX_INT32 width, FX_UINT16 bps, FX_UINT16 spp) | 433 FX_BOOL CCodec_TiffContext::Decode24bppRGB(CFX_DIBitmap* pDIBitmap, int32_t heig
ht, int32_t width, uint16_t bps, uint16_t spp) |
| 434 { | 434 { |
| 435 if (pDIBitmap->GetBPP() != 24 || !isSupport(pDIBitmap)) { | 435 if (pDIBitmap->GetBPP() != 24 || !isSupport(pDIBitmap)) { |
| 436 return FALSE; | 436 return FALSE; |
| 437 } | 437 } |
| 438 FX_INT32 size = (FX_INT32)TIFFScanlineSize(tif_ctx); | 438 int32_t size = (int32_t)TIFFScanlineSize(tif_ctx); |
| 439 FX_LPBYTE buf = (FX_LPBYTE)_TIFFmalloc(size); | 439 FX_LPBYTE buf = (FX_LPBYTE)_TIFFmalloc(size); |
| 440 if (buf == NULL) { | 440 if (buf == NULL) { |
| 441 TIFFError(TIFFFileName(tif_ctx), "No space for scanline buffer"); | 441 TIFFError(TIFFFileName(tif_ctx), "No space for scanline buffer"); |
| 442 return FALSE; | 442 return FALSE; |
| 443 } | 443 } |
| 444 FX_LPBYTE bitMapbuffer = (FX_LPBYTE)pDIBitmap->GetBuffer(); | 444 FX_LPBYTE bitMapbuffer = (FX_LPBYTE)pDIBitmap->GetBuffer(); |
| 445 FX_DWORD pitch = pDIBitmap->GetPitch(); | 445 FX_DWORD pitch = pDIBitmap->GetPitch(); |
| 446 for(FX_INT32 row = 0; row < height; row++) { | 446 for(int32_t row = 0; row < height; row++) { |
| 447 TIFFReadScanline(tif_ctx, buf, row, 0); | 447 TIFFReadScanline(tif_ctx, buf, row, 0); |
| 448 for(FX_INT32 j = 0; j < size - 2; j += 3) { | 448 for(int32_t j = 0; j < size - 2; j += 3) { |
| 449 bitMapbuffer[row * pitch + j + 0] = buf[j + 2]; | 449 bitMapbuffer[row * pitch + j + 0] = buf[j + 2]; |
| 450 bitMapbuffer[row * pitch + j + 1] = buf[j + 1]; | 450 bitMapbuffer[row * pitch + j + 1] = buf[j + 1]; |
| 451 bitMapbuffer[row * pitch + j + 2] = buf[j + 0]; | 451 bitMapbuffer[row * pitch + j + 2] = buf[j + 0]; |
| 452 } | 452 } |
| 453 } | 453 } |
| 454 _TIFFfree(buf); | 454 _TIFFfree(buf); |
| 455 return TRUE; | 455 return TRUE; |
| 456 } | 456 } |
| 457 FX_BOOL CCodec_TiffContext::Decode(CFX_DIBitmap* pDIBitmap) | 457 FX_BOOL CCodec_TiffContext::Decode(CFX_DIBitmap* pDIBitmap) |
| 458 { | 458 { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 470 TIFFGetField(tif_ctx, TIFFTAG_ORIENTATION, &rotation); | 470 TIFFGetField(tif_ctx, TIFFTAG_ORIENTATION, &rotation); |
| 471 if(TIFFReadRGBAImageOriented(tif_ctx, img_wid, img_hei, | 471 if(TIFFReadRGBAImageOriented(tif_ctx, img_wid, img_hei, |
| 472 (uint32*)pDIBitmap->GetBuffer(), rotation,
1)) { | 472 (uint32*)pDIBitmap->GetBuffer(), rotation,
1)) { |
| 473 for (FX_DWORD row = 0; row < img_hei; row++) { | 473 for (FX_DWORD row = 0; row < img_hei; row++) { |
| 474 FX_LPBYTE row_buf = (FX_LPBYTE)pDIBitmap->GetScanline(row); | 474 FX_LPBYTE row_buf = (FX_LPBYTE)pDIBitmap->GetScanline(row); |
| 475 _TiffBGRA2RGBA(row_buf, img_wid, 4); | 475 _TiffBGRA2RGBA(row_buf, img_wid, 4); |
| 476 } | 476 } |
| 477 return TRUE; | 477 return TRUE; |
| 478 } | 478 } |
| 479 } | 479 } |
| 480 FX_UINT16 spp, bps; | 480 uint16_t spp, bps; |
| 481 TIFFGetField(tif_ctx, TIFFTAG_SAMPLESPERPIXEL, &spp); | 481 TIFFGetField(tif_ctx, TIFFTAG_SAMPLESPERPIXEL, &spp); |
| 482 TIFFGetField(tif_ctx, TIFFTAG_BITSPERSAMPLE, &bps); | 482 TIFFGetField(tif_ctx, TIFFTAG_BITSPERSAMPLE, &bps); |
| 483 FX_DWORD bpp = bps * spp; | 483 FX_DWORD bpp = bps * spp; |
| 484 if (bpp == 1) { | 484 if (bpp == 1) { |
| 485 return Decode1bppRGB(pDIBitmap, height, width, bps, spp); | 485 return Decode1bppRGB(pDIBitmap, height, width, bps, spp); |
| 486 } else if (bpp <= 8) { | 486 } else if (bpp <= 8) { |
| 487 return Decode8bppRGB(pDIBitmap, height, width, bps, spp); | 487 return Decode8bppRGB(pDIBitmap, height, width, bps, spp); |
| 488 } else if (bpp <= 24) { | 488 } else if (bpp <= 24) { |
| 489 return Decode24bppRGB(pDIBitmap, height, width, bps, spp); | 489 return Decode24bppRGB(pDIBitmap, height, width, bps, spp); |
| 490 } | 490 } |
| 491 return FALSE; | 491 return FALSE; |
| 492 } | 492 } |
| 493 FX_LPVOID CCodec_TiffModule::CreateDecoder(IFX_FileRead* file_ptr) | 493 FX_LPVOID CCodec_TiffModule::CreateDecoder(IFX_FileRead* file_ptr) |
| 494 { | 494 { |
| 495 CCodec_TiffContext* pDecoder = new CCodec_TiffContext; | 495 CCodec_TiffContext* pDecoder = new CCodec_TiffContext; |
| 496 if (!pDecoder->InitDecoder(file_ptr)) { | 496 if (!pDecoder->InitDecoder(file_ptr)) { |
| 497 delete pDecoder; | 497 delete pDecoder; |
| 498 return NULL; | 498 return NULL; |
| 499 } | 499 } |
| 500 return pDecoder; | 500 return pDecoder; |
| 501 } | 501 } |
| 502 void CCodec_TiffModule::GetFrames(FX_LPVOID ctx, FX_INT32& frames) | 502 void CCodec_TiffModule::GetFrames(FX_LPVOID ctx, int32_t& frames) |
| 503 { | 503 { |
| 504 CCodec_TiffContext* pDecoder = (CCodec_TiffContext*)ctx; | 504 CCodec_TiffContext* pDecoder = (CCodec_TiffContext*)ctx; |
| 505 pDecoder->GetFrames(frames); | 505 pDecoder->GetFrames(frames); |
| 506 } | 506 } |
| 507 FX_BOOL CCodec_TiffModule::LoadFrameInfo(FX_LPVOID ctx, FX_INT32 frame, FX_DWORD
& width, FX_DWORD& height, FX_DWORD& comps, FX_DWORD& bpc, CFX_DIBAttribute* pAt
tribute) | 507 FX_BOOL CCodec_TiffModule::LoadFrameInfo(FX_LPVOID ctx, int32_t frame, FX_DWORD&
width, FX_DWORD& height, FX_DWORD& comps, FX_DWORD& bpc, CFX_DIBAttribute* pAtt
ribute) |
| 508 { | 508 { |
| 509 CCodec_TiffContext* pDecoder = (CCodec_TiffContext*)ctx; | 509 CCodec_TiffContext* pDecoder = (CCodec_TiffContext*)ctx; |
| 510 return pDecoder->LoadFrameInfo(frame, width, height, comps, bpc, pAttribute)
; | 510 return pDecoder->LoadFrameInfo(frame, width, height, comps, bpc, pAttribute)
; |
| 511 } | 511 } |
| 512 FX_BOOL CCodec_TiffModule::Decode(void* ctx, class CFX_DIBitmap* pDIBitmap) | 512 FX_BOOL CCodec_TiffModule::Decode(void* ctx, class CFX_DIBitmap* pDIBitmap) |
| 513 { | 513 { |
| 514 CCodec_TiffContext* pDecoder = (CCodec_TiffContext*)ctx; | 514 CCodec_TiffContext* pDecoder = (CCodec_TiffContext*)ctx; |
| 515 return pDecoder->Decode(pDIBitmap); | 515 return pDecoder->Decode(pDIBitmap); |
| 516 } | 516 } |
| 517 void CCodec_TiffModule::DestroyDecoder(void* ctx) | 517 void CCodec_TiffModule::DestroyDecoder(void* ctx) |
| 518 { | 518 { |
| 519 CCodec_TiffContext* pDecoder = (CCodec_TiffContext*)ctx; | 519 CCodec_TiffContext* pDecoder = (CCodec_TiffContext*)ctx; |
| 520 delete pDecoder; | 520 delete pDecoder; |
| 521 } | 521 } |
| OLD | NEW |