| 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 <setjmp.h> | 7 #include <setjmp.h> |
| 8 | 8 |
| 9 #include "core/fxcodec/codec/codec_int.h" | 9 #include "core/fxcodec/codec/codec_int.h" |
| 10 #include "core/fxcodec/include/fx_codec.h" | 10 #include "core/fxcodec/include/fx_codec.h" |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 175 cinfo.image_width = width; | 175 cinfo.image_width = width; |
| 176 cinfo.image_height = height; | 176 cinfo.image_height = height; |
| 177 cinfo.input_components = nComponents; | 177 cinfo.input_components = nComponents; |
| 178 if (nComponents == 1) { | 178 if (nComponents == 1) { |
| 179 cinfo.in_color_space = JCS_GRAYSCALE; | 179 cinfo.in_color_space = JCS_GRAYSCALE; |
| 180 } else if (nComponents == 3) { | 180 } else if (nComponents == 3) { |
| 181 cinfo.in_color_space = JCS_RGB; | 181 cinfo.in_color_space = JCS_RGB; |
| 182 } else { | 182 } else { |
| 183 cinfo.in_color_space = JCS_CMYK; | 183 cinfo.in_color_space = JCS_CMYK; |
| 184 } | 184 } |
| 185 uint8_t* line_buf = NULL; | 185 uint8_t* line_buf = nullptr; |
| 186 if (nComponents > 1) { | 186 if (nComponents > 1) { |
| 187 line_buf = FX_Alloc2D(uint8_t, width, nComponents); | 187 line_buf = FX_Alloc2D(uint8_t, width, nComponents); |
| 188 } | 188 } |
| 189 jpeg_set_defaults(&cinfo); | 189 jpeg_set_defaults(&cinfo); |
| 190 if (quality != 75) { | 190 if (quality != 75) { |
| 191 jpeg_set_quality(&cinfo, quality, TRUE); | 191 jpeg_set_quality(&cinfo, quality, TRUE); |
| 192 } | 192 } |
| 193 jpeg_start_compress(&cinfo, TRUE); | 193 jpeg_start_compress(&cinfo, TRUE); |
| 194 _JpegEmbedIccProfile(&cinfo, icc_buf, icc_length); | 194 _JpegEmbedIccProfile(&cinfo, icc_buf, icc_length); |
| 195 JSAMPROW row_pointer[1]; | 195 JSAMPROW row_pointer[1]; |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 227 } | 227 } |
| 228 jpeg_finish_compress(&cinfo); | 228 jpeg_finish_compress(&cinfo); |
| 229 jpeg_destroy_compress(&cinfo); | 229 jpeg_destroy_compress(&cinfo); |
| 230 FX_Free(line_buf); | 230 FX_Free(line_buf); |
| 231 dest_size = dest_buf_length - (FX_STRSIZE)dest.free_in_buffer; | 231 dest_size = dest_buf_length - (FX_STRSIZE)dest.free_in_buffer; |
| 232 } | 232 } |
| 233 | 233 |
| 234 #ifdef PDF_ENABLE_XFA | 234 #ifdef PDF_ENABLE_XFA |
| 235 static void _JpegLoadAttribute(struct jpeg_decompress_struct* pInfo, | 235 static void _JpegLoadAttribute(struct jpeg_decompress_struct* pInfo, |
| 236 CFX_DIBAttribute* pAttribute) { | 236 CFX_DIBAttribute* pAttribute) { |
| 237 if (pInfo == NULL || pAttribute == NULL) { | |
| 238 return; | |
| 239 } | |
| 240 if (pAttribute) { | 237 if (pAttribute) { |
| 241 pAttribute->m_nXDPI = pInfo->X_density; | 238 pAttribute->m_nXDPI = pInfo->X_density; |
| 242 pAttribute->m_nYDPI = pInfo->Y_density; | 239 pAttribute->m_nYDPI = pInfo->Y_density; |
| 243 pAttribute->m_wDPIUnit = pInfo->density_unit; | 240 pAttribute->m_wDPIUnit = pInfo->density_unit; |
| 244 } | 241 } |
| 245 } | 242 } |
| 246 #endif // PDF_ENABLE_XFA | 243 #endif // PDF_ENABLE_XFA |
| 247 | 244 |
| 248 static FX_BOOL _JpegLoadInfo(const uint8_t* src_buf, | 245 static FX_BOOL _JpegLoadInfo(const uint8_t* src_buf, |
| 249 uint32_t src_size, | 246 uint32_t src_size, |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 291 jpeg_destroy_decompress(&cinfo); | 288 jpeg_destroy_decompress(&cinfo); |
| 292 return FALSE; | 289 return FALSE; |
| 293 } | 290 } |
| 294 width = cinfo.image_width; | 291 width = cinfo.image_width; |
| 295 height = cinfo.image_height; | 292 height = cinfo.image_height; |
| 296 num_components = cinfo.num_components; | 293 num_components = cinfo.num_components; |
| 297 color_transform = | 294 color_transform = |
| 298 cinfo.jpeg_color_space == JCS_YCbCr || cinfo.jpeg_color_space == JCS_YCCK; | 295 cinfo.jpeg_color_space == JCS_YCbCr || cinfo.jpeg_color_space == JCS_YCCK; |
| 299 bits_per_components = cinfo.data_precision; | 296 bits_per_components = cinfo.data_precision; |
| 300 if (icc_buf_ptr) { | 297 if (icc_buf_ptr) { |
| 301 *icc_buf_ptr = NULL; | 298 *icc_buf_ptr = nullptr; |
| 302 } | 299 } |
| 303 if (icc_length) { | 300 if (icc_length) { |
| 304 *icc_length = 0; | 301 *icc_length = 0; |
| 305 } | 302 } |
| 306 jpeg_destroy_decompress(&cinfo); | 303 jpeg_destroy_decompress(&cinfo); |
| 307 return TRUE; | 304 return TRUE; |
| 308 } | 305 } |
| 309 | 306 |
| 310 class CCodec_JpegDecoder : public CCodec_ScanlineDecoder { | 307 class CCodec_JpegDecoder : public CCodec_ScanlineDecoder { |
| 311 public: | 308 public: |
| (...skipping 24 matching lines...) Expand all Loading... |
| 336 | 333 |
| 337 FX_BOOL m_bInited; | 334 FX_BOOL m_bInited; |
| 338 FX_BOOL m_bStarted; | 335 FX_BOOL m_bStarted; |
| 339 FX_BOOL m_bJpegTransform; | 336 FX_BOOL m_bJpegTransform; |
| 340 | 337 |
| 341 protected: | 338 protected: |
| 342 uint32_t m_nDefaultScaleDenom; | 339 uint32_t m_nDefaultScaleDenom; |
| 343 }; | 340 }; |
| 344 | 341 |
| 345 CCodec_JpegDecoder::CCodec_JpegDecoder() { | 342 CCodec_JpegDecoder::CCodec_JpegDecoder() { |
| 346 m_pScanlineBuf = NULL; | 343 m_pScanlineBuf = nullptr; |
| 347 m_bStarted = FALSE; | 344 m_bStarted = FALSE; |
| 348 m_bInited = FALSE; | 345 m_bInited = FALSE; |
| 349 FXSYS_memset(&cinfo, 0, sizeof(cinfo)); | 346 FXSYS_memset(&cinfo, 0, sizeof(cinfo)); |
| 350 FXSYS_memset(&jerr, 0, sizeof(jerr)); | 347 FXSYS_memset(&jerr, 0, sizeof(jerr)); |
| 351 FXSYS_memset(&src, 0, sizeof(src)); | 348 FXSYS_memset(&src, 0, sizeof(src)); |
| 352 m_nDefaultScaleDenom = 1; | 349 m_nDefaultScaleDenom = 1; |
| 353 } | 350 } |
| 354 CCodec_JpegDecoder::~CCodec_JpegDecoder() { | 351 CCodec_JpegDecoder::~CCodec_JpegDecoder() { |
| 355 FX_Free(m_pScanlineBuf); | 352 FX_Free(m_pScanlineBuf); |
| 356 if (m_bInited) { | 353 if (m_bInited) { |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 476 return (uint32_t)(m_SrcSize - src.bytes_in_buffer); | 473 return (uint32_t)(m_SrcSize - src.bytes_in_buffer); |
| 477 } | 474 } |
| 478 CCodec_ScanlineDecoder* CCodec_JpegModule::CreateDecoder( | 475 CCodec_ScanlineDecoder* CCodec_JpegModule::CreateDecoder( |
| 479 const uint8_t* src_buf, | 476 const uint8_t* src_buf, |
| 480 uint32_t src_size, | 477 uint32_t src_size, |
| 481 int width, | 478 int width, |
| 482 int height, | 479 int height, |
| 483 int nComps, | 480 int nComps, |
| 484 FX_BOOL ColorTransform) { | 481 FX_BOOL ColorTransform) { |
| 485 if (!src_buf || src_size == 0) { | 482 if (!src_buf || src_size == 0) { |
| 486 return NULL; | 483 return nullptr; |
| 487 } | 484 } |
| 488 CCodec_JpegDecoder* pDecoder = new CCodec_JpegDecoder; | 485 CCodec_JpegDecoder* pDecoder = new CCodec_JpegDecoder; |
| 489 if (!pDecoder->Create(src_buf, src_size, width, height, nComps, | 486 if (!pDecoder->Create(src_buf, src_size, width, height, nComps, |
| 490 ColorTransform)) { | 487 ColorTransform)) { |
| 491 delete pDecoder; | 488 delete pDecoder; |
| 492 return NULL; | 489 return nullptr; |
| 493 } | 490 } |
| 494 return pDecoder; | 491 return pDecoder; |
| 495 } | 492 } |
| 496 FX_BOOL CCodec_JpegModule::LoadInfo(const uint8_t* src_buf, | 493 FX_BOOL CCodec_JpegModule::LoadInfo(const uint8_t* src_buf, |
| 497 uint32_t src_size, | 494 uint32_t src_size, |
| 498 int& width, | 495 int& width, |
| 499 int& height, | 496 int& height, |
| 500 int& num_components, | 497 int& num_components, |
| 501 int& bits_per_components, | 498 int& bits_per_components, |
| 502 FX_BOOL& color_transform, | 499 FX_BOOL& color_transform, |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 640 if (setjmp(ctx->m_JumpMark) == -1) | 637 if (setjmp(ctx->m_JumpMark) == -1) |
| 641 return FALSE; | 638 return FALSE; |
| 642 | 639 |
| 643 int nlines = jpeg_read_scanlines(&ctx->m_Info, &dest_buf, 1); | 640 int nlines = jpeg_read_scanlines(&ctx->m_Info, &dest_buf, 1); |
| 644 return nlines == 1; | 641 return nlines == 1; |
| 645 } | 642 } |
| 646 | 643 |
| 647 uint32_t CCodec_JpegModule::GetAvailInput(FXJPEG_Context* ctx, | 644 uint32_t CCodec_JpegModule::GetAvailInput(FXJPEG_Context* ctx, |
| 648 uint8_t** avail_buf_ptr) { | 645 uint8_t** avail_buf_ptr) { |
| 649 if (avail_buf_ptr) { | 646 if (avail_buf_ptr) { |
| 650 *avail_buf_ptr = NULL; | 647 *avail_buf_ptr = nullptr; |
| 651 if (ctx->m_SrcMgr.bytes_in_buffer > 0) { | 648 if (ctx->m_SrcMgr.bytes_in_buffer > 0) { |
| 652 *avail_buf_ptr = (uint8_t*)ctx->m_SrcMgr.next_input_byte; | 649 *avail_buf_ptr = (uint8_t*)ctx->m_SrcMgr.next_input_byte; |
| 653 } | 650 } |
| 654 } | 651 } |
| 655 return (uint32_t)ctx->m_SrcMgr.bytes_in_buffer; | 652 return (uint32_t)ctx->m_SrcMgr.bytes_in_buffer; |
| 656 } | 653 } |
| OLD | NEW |