| 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 "codec_int.h" | 9 #include "codec_int.h" |
| 10 #include "core/include/fxcodec/fx_codec.h" | 10 #include "core/include/fxcodec/fx_codec.h" |
| (...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 275 if (ret != JPEG_HEADER_OK) { | 275 if (ret != JPEG_HEADER_OK) { |
| 276 jpeg_destroy_decompress(&cinfo); | 276 jpeg_destroy_decompress(&cinfo); |
| 277 return FALSE; | 277 return FALSE; |
| 278 } | 278 } |
| 279 width = cinfo.image_width; | 279 width = cinfo.image_width; |
| 280 height = cinfo.image_height; | 280 height = cinfo.image_height; |
| 281 num_components = cinfo.num_components; | 281 num_components = cinfo.num_components; |
| 282 color_transform = | 282 color_transform = |
| 283 cinfo.jpeg_color_space == JCS_YCbCr || cinfo.jpeg_color_space == JCS_YCCK; | 283 cinfo.jpeg_color_space == JCS_YCbCr || cinfo.jpeg_color_space == JCS_YCCK; |
| 284 bits_per_components = cinfo.data_precision; | 284 bits_per_components = cinfo.data_precision; |
| 285 if (icc_buf_ptr != NULL) { | 285 if (icc_buf_ptr) { |
| 286 *icc_buf_ptr = NULL; | 286 *icc_buf_ptr = NULL; |
| 287 } | 287 } |
| 288 if (icc_length != NULL) { | 288 if (icc_length) { |
| 289 *icc_length = 0; | 289 *icc_length = 0; |
| 290 } | 290 } |
| 291 jpeg_destroy_decompress(&cinfo); | 291 jpeg_destroy_decompress(&cinfo); |
| 292 return TRUE; | 292 return TRUE; |
| 293 } | 293 } |
| 294 | 294 |
| 295 class CCodec_JpegDecoder : public CCodec_ScanlineDecoder { | 295 class CCodec_JpegDecoder : public CCodec_ScanlineDecoder { |
| 296 public: | 296 public: |
| 297 CCodec_JpegDecoder(); | 297 CCodec_JpegDecoder(); |
| 298 ~CCodec_JpegDecoder() override; | 298 ~CCodec_JpegDecoder() override; |
| (...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 524 return _JpegLoadInfo(src_buf, src_size, width, height, num_components, | 524 return _JpegLoadInfo(src_buf, src_size, width, height, num_components, |
| 525 bits_per_components, color_transform, icc_buf_ptr, | 525 bits_per_components, color_transform, icc_buf_ptr, |
| 526 icc_length); | 526 icc_length); |
| 527 } | 527 } |
| 528 FX_BOOL CCodec_JpegModule::Encode(const CFX_DIBSource* pSource, | 528 FX_BOOL CCodec_JpegModule::Encode(const CFX_DIBSource* pSource, |
| 529 uint8_t*& dest_buf, | 529 uint8_t*& dest_buf, |
| 530 FX_STRSIZE& dest_size, | 530 FX_STRSIZE& dest_size, |
| 531 int quality, | 531 int quality, |
| 532 const uint8_t* icc_buf, | 532 const uint8_t* icc_buf, |
| 533 FX_DWORD icc_length) { | 533 FX_DWORD icc_length) { |
| 534 if (pSource->GetBPP() < 8 || pSource->GetPalette() != NULL) { | 534 if (pSource->GetBPP() < 8 || pSource->GetPalette()) { |
| 535 ASSERT(pSource->GetBPP() >= 8 && pSource->GetPalette() == NULL); | 535 ASSERT(pSource->GetBPP() >= 8 && pSource->GetPalette() == NULL); |
| 536 return FALSE; | 536 return FALSE; |
| 537 } | 537 } |
| 538 _JpegEncode(pSource, dest_buf, dest_size, quality, icc_buf, icc_length); | 538 _JpegEncode(pSource, dest_buf, dest_size, quality, icc_buf, icc_length); |
| 539 return TRUE; | 539 return TRUE; |
| 540 } | 540 } |
| 541 struct FXJPEG_Context { | 541 struct FXJPEG_Context { |
| 542 jmp_buf m_JumpMark; | 542 jmp_buf m_JumpMark; |
| 543 jpeg_decompress_struct m_Info; | 543 jpeg_decompress_struct m_Info; |
| 544 jpeg_error_mgr m_ErrMgr; | 544 jpeg_error_mgr m_ErrMgr; |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 648 unsigned char* dest_buf) { | 648 unsigned char* dest_buf) { |
| 649 FXJPEG_Context* p = (FXJPEG_Context*)pContext; | 649 FXJPEG_Context* p = (FXJPEG_Context*)pContext; |
| 650 if (setjmp(p->m_JumpMark) == -1) { | 650 if (setjmp(p->m_JumpMark) == -1) { |
| 651 return FALSE; | 651 return FALSE; |
| 652 } | 652 } |
| 653 int nlines = jpeg_read_scanlines(&p->m_Info, &dest_buf, 1); | 653 int nlines = jpeg_read_scanlines(&p->m_Info, &dest_buf, 1); |
| 654 return nlines == 1; | 654 return nlines == 1; |
| 655 } | 655 } |
| 656 FX_DWORD CCodec_JpegModule::GetAvailInput(void* pContext, | 656 FX_DWORD CCodec_JpegModule::GetAvailInput(void* pContext, |
| 657 uint8_t** avail_buf_ptr) { | 657 uint8_t** avail_buf_ptr) { |
| 658 if (avail_buf_ptr != NULL) { | 658 if (avail_buf_ptr) { |
| 659 *avail_buf_ptr = NULL; | 659 *avail_buf_ptr = NULL; |
| 660 if (((FXJPEG_Context*)pContext)->m_SrcMgr.bytes_in_buffer > 0) { | 660 if (((FXJPEG_Context*)pContext)->m_SrcMgr.bytes_in_buffer > 0) { |
| 661 *avail_buf_ptr = | 661 *avail_buf_ptr = |
| 662 (uint8_t*)((FXJPEG_Context*)pContext)->m_SrcMgr.next_input_byte; | 662 (uint8_t*)((FXJPEG_Context*)pContext)->m_SrcMgr.next_input_byte; |
| 663 } | 663 } |
| 664 } | 664 } |
| 665 return (FX_DWORD)((FXJPEG_Context*)pContext)->m_SrcMgr.bytes_in_buffer; | 665 return (FX_DWORD)((FXJPEG_Context*)pContext)->m_SrcMgr.bytes_in_buffer; |
| 666 } | 666 } |
| OLD | NEW |