| 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 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 static void _error_do_nothing2(j_common_ptr cinfo, char*) {} | 75 static void _error_do_nothing2(j_common_ptr cinfo, char*) {} |
| 76 }; | 76 }; |
| 77 #define JPEG_MARKER_EXIF (JPEG_APP0 + 1) | 77 #define JPEG_MARKER_EXIF (JPEG_APP0 + 1) |
| 78 #define JPEG_MARKER_ICC (JPEG_APP0 + 2) | 78 #define JPEG_MARKER_ICC (JPEG_APP0 + 2) |
| 79 #define JPEG_MARKER_AUTHORTIME (JPEG_APP0 + 3) | 79 #define JPEG_MARKER_AUTHORTIME (JPEG_APP0 + 3) |
| 80 #define JPEG_MARKER_MAXSIZE 0xFFFF | 80 #define JPEG_MARKER_MAXSIZE 0xFFFF |
| 81 #define JPEG_OVERHEAD_LEN 14 | 81 #define JPEG_OVERHEAD_LEN 14 |
| 82 static FX_BOOL _JpegEmbedIccProfile(j_compress_ptr cinfo, | 82 static FX_BOOL _JpegEmbedIccProfile(j_compress_ptr cinfo, |
| 83 const uint8_t* icc_buf_ptr, | 83 const uint8_t* icc_buf_ptr, |
| 84 FX_DWORD icc_length) { | 84 FX_DWORD icc_length) { |
| 85 if (icc_buf_ptr == NULL || icc_length == 0) { | 85 if (!icc_buf_ptr || icc_length == 0) { |
| 86 return FALSE; | 86 return FALSE; |
| 87 } | 87 } |
| 88 FX_DWORD icc_segment_size = (JPEG_MARKER_MAXSIZE - 2 - JPEG_OVERHEAD_LEN); | 88 FX_DWORD icc_segment_size = (JPEG_MARKER_MAXSIZE - 2 - JPEG_OVERHEAD_LEN); |
| 89 FX_DWORD icc_segment_num = (icc_length / icc_segment_size) + 1; | 89 FX_DWORD icc_segment_num = (icc_length / icc_segment_size) + 1; |
| 90 if (icc_segment_num > 255) { | 90 if (icc_segment_num > 255) { |
| 91 return FALSE; | 91 return FALSE; |
| 92 } | 92 } |
| 93 FX_DWORD icc_data_length = | 93 FX_DWORD icc_data_length = |
| 94 JPEG_OVERHEAD_LEN + (icc_segment_num > 1 ? icc_segment_size : icc_length); | 94 JPEG_OVERHEAD_LEN + (icc_segment_num > 1 ? icc_segment_size : icc_length); |
| 95 uint8_t* icc_data = FX_Alloc(uint8_t, icc_data_length); | 95 uint8_t* icc_data = FX_Alloc(uint8_t, icc_data_length); |
| (...skipping 398 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 494 FX_DWORD CCodec_JpegDecoder::GetSrcOffset() { | 494 FX_DWORD CCodec_JpegDecoder::GetSrcOffset() { |
| 495 return (FX_DWORD)(m_SrcSize - src.bytes_in_buffer); | 495 return (FX_DWORD)(m_SrcSize - src.bytes_in_buffer); |
| 496 } | 496 } |
| 497 ICodec_ScanlineDecoder* CCodec_JpegModule::CreateDecoder( | 497 ICodec_ScanlineDecoder* CCodec_JpegModule::CreateDecoder( |
| 498 const uint8_t* src_buf, | 498 const uint8_t* src_buf, |
| 499 FX_DWORD src_size, | 499 FX_DWORD src_size, |
| 500 int width, | 500 int width, |
| 501 int height, | 501 int height, |
| 502 int nComps, | 502 int nComps, |
| 503 FX_BOOL ColorTransform) { | 503 FX_BOOL ColorTransform) { |
| 504 if (src_buf == NULL || src_size == 0) { | 504 if (!src_buf || src_size == 0) { |
| 505 return NULL; | 505 return NULL; |
| 506 } | 506 } |
| 507 CCodec_JpegDecoder* pDecoder = new CCodec_JpegDecoder; | 507 CCodec_JpegDecoder* pDecoder = new CCodec_JpegDecoder; |
| 508 if (!pDecoder->Create(src_buf, src_size, width, height, nComps, | 508 if (!pDecoder->Create(src_buf, src_size, width, height, nComps, |
| 509 ColorTransform)) { | 509 ColorTransform)) { |
| 510 delete pDecoder; | 510 delete pDecoder; |
| 511 return NULL; | 511 return NULL; |
| 512 } | 512 } |
| 513 return pDecoder; | 513 return pDecoder; |
| 514 } | 514 } |
| 515 FX_BOOL CCodec_JpegModule::LoadInfo(const uint8_t* src_buf, | 515 FX_BOOL CCodec_JpegModule::LoadInfo(const uint8_t* src_buf, |
| 516 FX_DWORD src_size, | 516 FX_DWORD src_size, |
| 517 int& width, | 517 int& width, |
| 518 int& height, | 518 int& height, |
| 519 int& num_components, | 519 int& num_components, |
| 520 int& bits_per_components, | 520 int& bits_per_components, |
| 521 FX_BOOL& color_transform, | 521 FX_BOOL& color_transform, |
| 522 uint8_t** icc_buf_ptr, | 522 uint8_t** icc_buf_ptr, |
| 523 FX_DWORD* icc_length) { | 523 FX_DWORD* icc_length) { |
| 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()) { | 534 if (pSource->GetBPP() < 8 || pSource->GetPalette()) |
| 535 ASSERT(pSource->GetBPP() >= 8 && pSource->GetPalette() == NULL); | |
| 536 return FALSE; | 535 return FALSE; |
| 537 } | 536 |
| 538 _JpegEncode(pSource, dest_buf, dest_size, quality, icc_buf, icc_length); | 537 _JpegEncode(pSource, dest_buf, dest_size, quality, icc_buf, icc_length); |
| 539 return TRUE; | 538 return TRUE; |
| 540 } | 539 } |
| 541 struct FXJPEG_Context { | 540 struct FXJPEG_Context { |
| 542 jmp_buf m_JumpMark; | 541 jmp_buf m_JumpMark; |
| 543 jpeg_decompress_struct m_Info; | 542 jpeg_decompress_struct m_Info; |
| 544 jpeg_error_mgr m_ErrMgr; | 543 jpeg_error_mgr m_ErrMgr; |
| 545 jpeg_source_mgr m_SrcMgr; | 544 jpeg_source_mgr m_SrcMgr; |
| 546 unsigned int m_SkipSize; | 545 unsigned int m_SkipSize; |
| 547 void* (*m_AllocFunc)(unsigned int); | 546 void* (*m_AllocFunc)(unsigned int); |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 657 uint8_t** avail_buf_ptr) { | 656 uint8_t** avail_buf_ptr) { |
| 658 if (avail_buf_ptr) { | 657 if (avail_buf_ptr) { |
| 659 *avail_buf_ptr = NULL; | 658 *avail_buf_ptr = NULL; |
| 660 if (((FXJPEG_Context*)pContext)->m_SrcMgr.bytes_in_buffer > 0) { | 659 if (((FXJPEG_Context*)pContext)->m_SrcMgr.bytes_in_buffer > 0) { |
| 661 *avail_buf_ptr = | 660 *avail_buf_ptr = |
| 662 (uint8_t*)((FXJPEG_Context*)pContext)->m_SrcMgr.next_input_byte; | 661 (uint8_t*)((FXJPEG_Context*)pContext)->m_SrcMgr.next_input_byte; |
| 663 } | 662 } |
| 664 } | 663 } |
| 665 return (FX_DWORD)((FXJPEG_Context*)pContext)->m_SrcMgr.bytes_in_buffer; | 664 return (FX_DWORD)((FXJPEG_Context*)pContext)->m_SrcMgr.bytes_in_buffer; |
| 666 } | 665 } |
| OLD | NEW |