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

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

Issue 1832173003: Remove FX_DWORD from core/ and delete definition (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Created 4 years, 9 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/fxcodec/codec/fx_codec_progress.cpp ('k') | core/fxcodec/jbig2/JBig2_ArithIntDecoder.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 "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
11 extern "C" { 11 extern "C" {
12 #include "third_party/libtiff/tiffiop.h" 12 #include "third_party/libtiff/tiffiop.h"
13 } 13 }
14 14
15 void* IccLib_CreateTransform_sRGB(const unsigned char* pProfileData, 15 void* IccLib_CreateTransform_sRGB(const unsigned char* pProfileData,
16 unsigned int dwProfileSize, 16 unsigned int dwProfileSize,
17 int nComponents, 17 int nComponents,
18 int intent, 18 int intent,
19 FX_DWORD dwSrcFormat = Icc_FORMAT_DEFAULT); 19 uint32_t dwSrcFormat = Icc_FORMAT_DEFAULT);
20 void IccLib_TranslateImage(void* pTransform, 20 void IccLib_TranslateImage(void* pTransform,
21 unsigned char* pDest, 21 unsigned char* pDest,
22 const unsigned char* pSrc, 22 const unsigned char* pSrc,
23 int pixels); 23 int pixels);
24 void IccLib_DestroyTransform(void* pTransform); 24 void IccLib_DestroyTransform(void* pTransform);
25 class CCodec_TiffContext { 25 class CCodec_TiffContext {
26 public: 26 public:
27 CCodec_TiffContext(); 27 CCodec_TiffContext();
28 ~CCodec_TiffContext(); 28 ~CCodec_TiffContext();
29 29
30 FX_BOOL InitDecoder(IFX_FileRead* file_ptr); 30 FX_BOOL InitDecoder(IFX_FileRead* file_ptr);
31 void GetFrames(int32_t& frames); 31 void GetFrames(int32_t& frames);
32 FX_BOOL LoadFrameInfo(int32_t frame, 32 FX_BOOL LoadFrameInfo(int32_t frame,
33 FX_DWORD& width, 33 uint32_t& width,
34 FX_DWORD& height, 34 uint32_t& height,
35 FX_DWORD& comps, 35 uint32_t& comps,
36 FX_DWORD& bpc, 36 uint32_t& bpc,
37 CFX_DIBAttribute* pAttribute); 37 CFX_DIBAttribute* pAttribute);
38 FX_BOOL Decode(CFX_DIBitmap* pDIBitmap); 38 FX_BOOL Decode(CFX_DIBitmap* pDIBitmap);
39 39
40 union { 40 union {
41 IFX_FileRead* in; 41 IFX_FileRead* in;
42 IFX_FileStream* out; 42 IFX_FileStream* out;
43 } io; 43 } io;
44 44
45 FX_DWORD offset; 45 uint32_t offset;
46 46
47 TIFF* tif_ctx; 47 TIFF* tif_ctx;
48 void* icc_ctx; 48 void* icc_ctx;
49 int32_t frame_num; 49 int32_t frame_num;
50 int32_t frame_cur; 50 int32_t frame_cur;
51 FX_BOOL isDecoder; 51 FX_BOOL isDecoder;
52 52
53 private: 53 private:
54 FX_BOOL isSupport(CFX_DIBitmap* pDIBitmap); 54 FX_BOOL isSupport(CFX_DIBitmap* pDIBitmap);
55 void SetPalette(CFX_DIBitmap* pDIBitmap, uint16_t bps); 55 void SetPalette(CFX_DIBitmap* pDIBitmap, uint16_t bps);
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
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);
95 } else { 95 } else {
96 ret = pTiffContext->io.out->ReadBlock(buf, pTiffContext->offset, length); 96 ret = pTiffContext->io.out->ReadBlock(buf, pTiffContext->offset, length);
97 } 97 }
98 if (!ret) { 98 if (!ret) {
99 return 0; 99 return 0;
100 } 100 }
101 pTiffContext->offset += (FX_DWORD)length; 101 pTiffContext->offset += (uint32_t)length;
102 return length; 102 return length;
103 } 103 }
104 static tsize_t _tiff_write(thandle_t context, tdata_t buf, tsize_t length) { 104 static tsize_t _tiff_write(thandle_t context, tdata_t buf, tsize_t length) {
105 CCodec_TiffContext* pTiffContext = (CCodec_TiffContext*)context; 105 CCodec_TiffContext* pTiffContext = (CCodec_TiffContext*)context;
106 ASSERT(!pTiffContext->isDecoder); 106 ASSERT(!pTiffContext->isDecoder);
107 if (!pTiffContext->io.out->WriteBlock(buf, pTiffContext->offset, length)) { 107 if (!pTiffContext->io.out->WriteBlock(buf, pTiffContext->offset, length)) {
108 return 0; 108 return 0;
109 } 109 }
110 pTiffContext->offset += (FX_DWORD)length; 110 pTiffContext->offset += (uint32_t)length;
111 return length; 111 return length;
112 } 112 }
113 static toff_t _tiff_seek(thandle_t context, toff_t offset, int whence) { 113 static toff_t _tiff_seek(thandle_t context, toff_t offset, int whence) {
114 CCodec_TiffContext* pTiffContext = (CCodec_TiffContext*)context; 114 CCodec_TiffContext* pTiffContext = (CCodec_TiffContext*)context;
115 switch (whence) { 115 switch (whence) {
116 case 0: 116 case 0:
117 pTiffContext->offset = (FX_DWORD)offset; 117 pTiffContext->offset = (uint32_t)offset;
118 break; 118 break;
119 case 1: 119 case 1:
120 pTiffContext->offset += (FX_DWORD)offset; 120 pTiffContext->offset += (uint32_t)offset;
121 break; 121 break;
122 case 2: 122 case 2:
123 if (pTiffContext->isDecoder) { 123 if (pTiffContext->isDecoder) {
124 if (pTiffContext->io.in->GetSize() < (FX_FILESIZE)offset) { 124 if (pTiffContext->io.in->GetSize() < (FX_FILESIZE)offset) {
125 return static_cast<toff_t>(-1); 125 return static_cast<toff_t>(-1);
126 } 126 }
127 pTiffContext->offset = 127 pTiffContext->offset =
128 (FX_DWORD)(pTiffContext->io.in->GetSize() - offset); 128 (uint32_t)(pTiffContext->io.in->GetSize() - offset);
129 } else { 129 } else {
130 if (pTiffContext->io.out->GetSize() < (FX_FILESIZE)offset) { 130 if (pTiffContext->io.out->GetSize() < (FX_FILESIZE)offset) {
131 return static_cast<toff_t>(-1); 131 return static_cast<toff_t>(-1);
132 } 132 }
133 pTiffContext->offset = 133 pTiffContext->offset =
134 (FX_DWORD)(pTiffContext->io.out->GetSize() - offset); 134 (uint32_t)(pTiffContext->io.out->GetSize() - offset);
135 } 135 }
136 break; 136 break;
137 default: 137 default:
138 return static_cast<toff_t>(-1); 138 return static_cast<toff_t>(-1);
139 } 139 }
140 ASSERT(pTiffContext->isDecoder ? (pTiffContext->offset <= 140 ASSERT(pTiffContext->isDecoder ? (pTiffContext->offset <=
141 (FX_DWORD)pTiffContext->io.in->GetSize()) 141 (uint32_t)pTiffContext->io.in->GetSize())
142 : TRUE); 142 : TRUE);
143 return pTiffContext->offset; 143 return pTiffContext->offset;
144 } 144 }
145 static int _tiff_close(thandle_t context) { 145 static int _tiff_close(thandle_t context) {
146 return 0; 146 return 0;
147 } 147 }
148 static toff_t _tiff_get_size(thandle_t context) { 148 static toff_t _tiff_get_size(thandle_t context) {
149 CCodec_TiffContext* pTiffContext = (CCodec_TiffContext*)context; 149 CCodec_TiffContext* pTiffContext = (CCodec_TiffContext*)context;
150 return pTiffContext->isDecoder ? (toff_t)pTiffContext->io.in->GetSize() 150 return pTiffContext->isDecoder ? (toff_t)pTiffContext->io.in->GetSize()
151 : (toff_t)pTiffContext->io.out->GetSize(); 151 : (toff_t)pTiffContext->io.out->GetSize();
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 if ((key)) { \ 227 if ((key)) { \
228 T* ptr = (T*)(key); \ 228 T* ptr = (T*)(key); \
229 *ptr = val; \ 229 *ptr = val; \
230 pExif->m_TagVal.SetAt(tag, (key)); \ 230 pExif->m_TagVal.SetAt(tag, (key)); \
231 } \ 231 } \
232 } \ 232 } \
233 } \ 233 } \
234 (key) = NULL; 234 (key) = NULL;
235 #define TIFF_EXIF_GETSTRINGINFO(key, tag) \ 235 #define TIFF_EXIF_GETSTRINGINFO(key, tag) \
236 { \ 236 { \
237 FX_DWORD size = 0; \ 237 uint32_t size = 0; \
238 uint8_t* buf = NULL; \ 238 uint8_t* buf = NULL; \
239 TIFFGetField(tif_ctx, tag, &size, &buf); \ 239 TIFFGetField(tif_ctx, tag, &size, &buf); \
240 if (size && buf) { \ 240 if (size && buf) { \
241 (key) = FX_Alloc(uint8_t, size); \ 241 (key) = FX_Alloc(uint8_t, size); \
242 if ((key)) { \ 242 if ((key)) { \
243 FXSYS_memcpy((key), buf, size); \ 243 FXSYS_memcpy((key), buf, size); \
244 pExif->m_TagVal.SetAt(tag, (key)); \ 244 pExif->m_TagVal.SetAt(tag, (key)); \
245 } \ 245 } \
246 } \ 246 } \
247 } \ 247 } \
(...skipping 22 matching lines...) Expand all
270 FX_STRSIZE size = FXSYS_strlen(buf); 270 FX_STRSIZE size = FXSYS_strlen(buf);
271 uint8_t* ptr = FX_Alloc(uint8_t, size + 1); 271 uint8_t* ptr = FX_Alloc(uint8_t, size + 1);
272 FXSYS_memcpy(ptr, buf, size); 272 FXSYS_memcpy(ptr, buf, size);
273 ptr[size] = 0; 273 ptr[size] = 0;
274 pAttr->m_Exif[tag] = ptr; 274 pAttr->m_Exif[tag] = ptr;
275 } 275 }
276 276
277 } // namespace 277 } // namespace
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 uint32_t& width,
281 FX_DWORD& height, 281 uint32_t& height,
282 FX_DWORD& comps, 282 uint32_t& comps,
283 FX_DWORD& bpc, 283 uint32_t& 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 uint16_t tif_cs; 288 uint16_t tif_cs;
289 FX_DWORD tif_icc_size = 0; 289 uint32_t tif_icc_size = 0;
290 uint8_t* tif_icc_buf = NULL; 290 uint8_t* tif_icc_buf = NULL;
291 uint16_t tif_bpc = 0; 291 uint16_t tif_bpc = 0;
292 uint16_t tif_cps; 292 uint16_t tif_cps;
293 FX_DWORD tif_rps; 293 uint32_t 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) {
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
372 TIFFGetField(tif_ctx, TIFFTAG_COLORMAP, &red_orig, &green_orig, &blue_orig); 372 TIFFGetField(tif_ctx, TIFFTAG_COLORMAP, &red_orig, &green_orig, &blue_orig);
373 for (int32_t i = (1L << bps) - 1; i >= 0; i--) { 373 for (int32_t i = (1L << bps) - 1; i >= 0; i--) {
374 #define CVT(x) ((uint16_t)((x) >> 8)) 374 #define CVT(x) ((uint16_t)((x) >> 8))
375 red_orig[i] = CVT(red_orig[i]); 375 red_orig[i] = CVT(red_orig[i]);
376 green_orig[i] = CVT(green_orig[i]); 376 green_orig[i] = CVT(green_orig[i]);
377 blue_orig[i] = CVT(blue_orig[i]); 377 blue_orig[i] = CVT(blue_orig[i]);
378 #undef CVT 378 #undef CVT
379 } 379 }
380 int32_t len = 1 << bps; 380 int32_t len = 1 << bps;
381 for (int32_t index = 0; index < len; index++) { 381 for (int32_t index = 0; index < len; index++) {
382 FX_DWORD r = red_orig[index] & 0xFF; 382 uint32_t r = red_orig[index] & 0xFF;
383 FX_DWORD g = green_orig[index] & 0xFF; 383 uint32_t g = green_orig[index] & 0xFF;
384 FX_DWORD b = blue_orig[index] & 0xFF; 384 uint32_t b = blue_orig[index] & 0xFF;
385 FX_DWORD color = (uint32_t)b | ((uint32_t)g << 8) | ((uint32_t)r << 16) | 385 uint32_t color = (uint32_t)b | ((uint32_t)g << 8) | ((uint32_t)r << 16) |
386 (((uint32)0xffL) << 24); 386 (((uint32)0xffL) << 24);
387 pDIBitmap->SetPaletteEntry(index, color); 387 pDIBitmap->SetPaletteEntry(index, color);
388 } 388 }
389 } 389 }
390 FX_BOOL CCodec_TiffContext::Decode1bppRGB(CFX_DIBitmap* pDIBitmap, 390 FX_BOOL CCodec_TiffContext::Decode1bppRGB(CFX_DIBitmap* pDIBitmap,
391 int32_t height, 391 int32_t height,
392 int32_t width, 392 int32_t width,
393 uint16_t bps, 393 uint16_t bps,
394 uint16_t spp) { 394 uint16_t spp) {
395 if (pDIBitmap->GetBPP() != 1 || spp != 1 || bps != 1 || 395 if (pDIBitmap->GetBPP() != 1 || spp != 1 || bps != 1 ||
396 !isSupport(pDIBitmap)) { 396 !isSupport(pDIBitmap)) {
397 return FALSE; 397 return FALSE;
398 } 398 }
399 SetPalette(pDIBitmap, bps); 399 SetPalette(pDIBitmap, bps);
400 int32_t size = (int32_t)TIFFScanlineSize(tif_ctx); 400 int32_t size = (int32_t)TIFFScanlineSize(tif_ctx);
401 uint8_t* buf = (uint8_t*)_TIFFmalloc(size); 401 uint8_t* buf = (uint8_t*)_TIFFmalloc(size);
402 if (buf == NULL) { 402 if (buf == NULL) {
403 TIFFError(TIFFFileName(tif_ctx), "No space for scanline buffer"); 403 TIFFError(TIFFFileName(tif_ctx), "No space for scanline buffer");
404 return FALSE; 404 return FALSE;
405 } 405 }
406 uint8_t* bitMapbuffer = (uint8_t*)pDIBitmap->GetBuffer(); 406 uint8_t* bitMapbuffer = (uint8_t*)pDIBitmap->GetBuffer();
407 FX_DWORD pitch = pDIBitmap->GetPitch(); 407 uint32_t pitch = pDIBitmap->GetPitch();
408 for (int32_t row = 0; row < height; row++) { 408 for (int32_t row = 0; row < height; row++) {
409 TIFFReadScanline(tif_ctx, buf, row, 0); 409 TIFFReadScanline(tif_ctx, buf, row, 0);
410 for (int32_t j = 0; j < size; j++) { 410 for (int32_t j = 0; j < size; j++) {
411 bitMapbuffer[row * pitch + j] = buf[j]; 411 bitMapbuffer[row * pitch + j] = buf[j];
412 } 412 }
413 } 413 }
414 _TIFFfree(buf); 414 _TIFFfree(buf);
415 return TRUE; 415 return TRUE;
416 } 416 }
417 FX_BOOL CCodec_TiffContext::Decode8bppRGB(CFX_DIBitmap* pDIBitmap, 417 FX_BOOL CCodec_TiffContext::Decode8bppRGB(CFX_DIBitmap* pDIBitmap,
418 int32_t height, 418 int32_t height,
419 int32_t width, 419 int32_t width,
420 uint16_t bps, 420 uint16_t bps,
421 uint16_t spp) { 421 uint16_t spp) {
422 if (pDIBitmap->GetBPP() != 8 || spp != 1 || (bps != 4 && bps != 8) || 422 if (pDIBitmap->GetBPP() != 8 || spp != 1 || (bps != 4 && bps != 8) ||
423 !isSupport(pDIBitmap)) { 423 !isSupport(pDIBitmap)) {
424 return FALSE; 424 return FALSE;
425 } 425 }
426 SetPalette(pDIBitmap, bps); 426 SetPalette(pDIBitmap, bps);
427 int32_t size = (int32_t)TIFFScanlineSize(tif_ctx); 427 int32_t size = (int32_t)TIFFScanlineSize(tif_ctx);
428 uint8_t* buf = (uint8_t*)_TIFFmalloc(size); 428 uint8_t* buf = (uint8_t*)_TIFFmalloc(size);
429 if (buf == NULL) { 429 if (buf == NULL) {
430 TIFFError(TIFFFileName(tif_ctx), "No space for scanline buffer"); 430 TIFFError(TIFFFileName(tif_ctx), "No space for scanline buffer");
431 return FALSE; 431 return FALSE;
432 } 432 }
433 uint8_t* bitMapbuffer = (uint8_t*)pDIBitmap->GetBuffer(); 433 uint8_t* bitMapbuffer = (uint8_t*)pDIBitmap->GetBuffer();
434 FX_DWORD pitch = pDIBitmap->GetPitch(); 434 uint32_t pitch = pDIBitmap->GetPitch();
435 for (int32_t row = 0; row < height; row++) { 435 for (int32_t row = 0; row < height; row++) {
436 TIFFReadScanline(tif_ctx, buf, row, 0); 436 TIFFReadScanline(tif_ctx, buf, row, 0);
437 for (int32_t j = 0; j < size; j++) { 437 for (int32_t j = 0; j < size; j++) {
438 switch (bps) { 438 switch (bps) {
439 case 4: 439 case 4:
440 bitMapbuffer[row * pitch + 2 * j + 0] = (buf[j] & 0xF0) >> 4; 440 bitMapbuffer[row * pitch + 2 * j + 0] = (buf[j] & 0xF0) >> 4;
441 bitMapbuffer[row * pitch + 2 * j + 1] = (buf[j] & 0x0F) >> 0; 441 bitMapbuffer[row * pitch + 2 * j + 1] = (buf[j] & 0x0F) >> 0;
442 break; 442 break;
443 case 8: 443 case 8:
444 bitMapbuffer[row * pitch + j] = buf[j]; 444 bitMapbuffer[row * pitch + j] = buf[j];
(...skipping 12 matching lines...) Expand all
457 if (pDIBitmap->GetBPP() != 24 || !isSupport(pDIBitmap)) { 457 if (pDIBitmap->GetBPP() != 24 || !isSupport(pDIBitmap)) {
458 return FALSE; 458 return FALSE;
459 } 459 }
460 int32_t size = (int32_t)TIFFScanlineSize(tif_ctx); 460 int32_t size = (int32_t)TIFFScanlineSize(tif_ctx);
461 uint8_t* buf = (uint8_t*)_TIFFmalloc(size); 461 uint8_t* buf = (uint8_t*)_TIFFmalloc(size);
462 if (buf == NULL) { 462 if (buf == NULL) {
463 TIFFError(TIFFFileName(tif_ctx), "No space for scanline buffer"); 463 TIFFError(TIFFFileName(tif_ctx), "No space for scanline buffer");
464 return FALSE; 464 return FALSE;
465 } 465 }
466 uint8_t* bitMapbuffer = (uint8_t*)pDIBitmap->GetBuffer(); 466 uint8_t* bitMapbuffer = (uint8_t*)pDIBitmap->GetBuffer();
467 FX_DWORD pitch = pDIBitmap->GetPitch(); 467 uint32_t pitch = pDIBitmap->GetPitch();
468 for (int32_t row = 0; row < height; row++) { 468 for (int32_t row = 0; row < height; row++) {
469 TIFFReadScanline(tif_ctx, buf, row, 0); 469 TIFFReadScanline(tif_ctx, buf, row, 0);
470 for (int32_t j = 0; j < size - 2; j += 3) { 470 for (int32_t j = 0; j < size - 2; j += 3) {
471 bitMapbuffer[row * pitch + j + 0] = buf[j + 2]; 471 bitMapbuffer[row * pitch + j + 0] = buf[j + 2];
472 bitMapbuffer[row * pitch + j + 1] = buf[j + 1]; 472 bitMapbuffer[row * pitch + j + 1] = buf[j + 1];
473 bitMapbuffer[row * pitch + j + 2] = buf[j + 0]; 473 bitMapbuffer[row * pitch + j + 2] = buf[j + 0];
474 } 474 }
475 } 475 }
476 _TIFFfree(buf); 476 _TIFFfree(buf);
477 return TRUE; 477 return TRUE;
478 } 478 }
479 FX_BOOL CCodec_TiffContext::Decode(CFX_DIBitmap* pDIBitmap) { 479 FX_BOOL CCodec_TiffContext::Decode(CFX_DIBitmap* pDIBitmap) {
480 FX_DWORD img_wid = pDIBitmap->GetWidth(); 480 uint32_t img_wid = pDIBitmap->GetWidth();
481 FX_DWORD img_hei = pDIBitmap->GetHeight(); 481 uint32_t img_hei = pDIBitmap->GetHeight();
482 FX_DWORD width = 0; 482 uint32_t width = 0;
483 FX_DWORD height = 0; 483 uint32_t 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 uint16_t 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 (uint32_t 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 }
501 } 501 }
502 uint16_t spp, bps; 502 uint16_t spp, bps;
503 TIFFGetField(tif_ctx, TIFFTAG_SAMPLESPERPIXEL, &spp); 503 TIFFGetField(tif_ctx, TIFFTAG_SAMPLESPERPIXEL, &spp);
504 TIFFGetField(tif_ctx, TIFFTAG_BITSPERSAMPLE, &bps); 504 TIFFGetField(tif_ctx, TIFFTAG_BITSPERSAMPLE, &bps);
505 FX_DWORD bpp = bps * spp; 505 uint32_t bpp = bps * spp;
506 if (bpp == 1) { 506 if (bpp == 1) {
507 return Decode1bppRGB(pDIBitmap, height, width, bps, spp); 507 return Decode1bppRGB(pDIBitmap, height, width, bps, spp);
508 } else if (bpp <= 8) { 508 } else if (bpp <= 8) {
509 return Decode8bppRGB(pDIBitmap, height, width, bps, spp); 509 return Decode8bppRGB(pDIBitmap, height, width, bps, spp);
510 } else if (bpp <= 24) { 510 } else if (bpp <= 24) {
511 return Decode24bppRGB(pDIBitmap, height, width, bps, spp); 511 return Decode24bppRGB(pDIBitmap, height, width, bps, spp);
512 } 512 }
513 return FALSE; 513 return FALSE;
514 } 514 }
515 void* CCodec_TiffModule::CreateDecoder(IFX_FileRead* file_ptr) { 515 void* CCodec_TiffModule::CreateDecoder(IFX_FileRead* file_ptr) {
516 CCodec_TiffContext* pDecoder = new CCodec_TiffContext; 516 CCodec_TiffContext* pDecoder = new CCodec_TiffContext;
517 if (!pDecoder->InitDecoder(file_ptr)) { 517 if (!pDecoder->InitDecoder(file_ptr)) {
518 delete pDecoder; 518 delete pDecoder;
519 return NULL; 519 return NULL;
520 } 520 }
521 return pDecoder; 521 return pDecoder;
522 } 522 }
523 void CCodec_TiffModule::GetFrames(void* ctx, int32_t& frames) { 523 void CCodec_TiffModule::GetFrames(void* ctx, int32_t& frames) {
524 CCodec_TiffContext* pDecoder = (CCodec_TiffContext*)ctx; 524 CCodec_TiffContext* pDecoder = (CCodec_TiffContext*)ctx;
525 pDecoder->GetFrames(frames); 525 pDecoder->GetFrames(frames);
526 } 526 }
527 FX_BOOL CCodec_TiffModule::LoadFrameInfo(void* ctx, 527 FX_BOOL CCodec_TiffModule::LoadFrameInfo(void* ctx,
528 int32_t frame, 528 int32_t frame,
529 FX_DWORD& width, 529 uint32_t& width,
530 FX_DWORD& height, 530 uint32_t& height,
531 FX_DWORD& comps, 531 uint32_t& comps,
532 FX_DWORD& bpc, 532 uint32_t& bpc,
533 CFX_DIBAttribute* pAttribute) { 533 CFX_DIBAttribute* pAttribute) {
534 CCodec_TiffContext* pDecoder = (CCodec_TiffContext*)ctx; 534 CCodec_TiffContext* pDecoder = (CCodec_TiffContext*)ctx;
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 }
OLDNEW
« no previous file with comments | « core/fxcodec/codec/fx_codec_progress.cpp ('k') | core/fxcodec/jbig2/JBig2_ArithIntDecoder.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698