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 413 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
509 FX_DWORD CCodec_JpegDecoder::GetSrcOffset() { | 509 FX_DWORD CCodec_JpegDecoder::GetSrcOffset() { |
510 return (FX_DWORD)(m_SrcSize - src.bytes_in_buffer); | 510 return (FX_DWORD)(m_SrcSize - src.bytes_in_buffer); |
511 } | 511 } |
512 ICodec_ScanlineDecoder* CCodec_JpegModule::CreateDecoder( | 512 ICodec_ScanlineDecoder* CCodec_JpegModule::CreateDecoder( |
513 const uint8_t* src_buf, | 513 const uint8_t* src_buf, |
514 FX_DWORD src_size, | 514 FX_DWORD src_size, |
515 int width, | 515 int width, |
516 int height, | 516 int height, |
517 int nComps, | 517 int nComps, |
518 FX_BOOL ColorTransform) { | 518 FX_BOOL ColorTransform) { |
519 if (src_buf == NULL || src_size == 0) { | 519 if (!src_buf || src_size == 0) { |
520 return NULL; | 520 return NULL; |
521 } | 521 } |
522 CCodec_JpegDecoder* pDecoder = new CCodec_JpegDecoder; | 522 CCodec_JpegDecoder* pDecoder = new CCodec_JpegDecoder; |
523 if (!pDecoder->Create(src_buf, src_size, width, height, nComps, | 523 if (!pDecoder->Create(src_buf, src_size, width, height, nComps, |
524 ColorTransform)) { | 524 ColorTransform)) { |
525 delete pDecoder; | 525 delete pDecoder; |
526 return NULL; | 526 return NULL; |
527 } | 527 } |
528 return pDecoder; | 528 return pDecoder; |
529 } | 529 } |
530 FX_BOOL CCodec_JpegModule::LoadInfo(const uint8_t* src_buf, | 530 FX_BOOL CCodec_JpegModule::LoadInfo(const uint8_t* src_buf, |
531 FX_DWORD src_size, | 531 FX_DWORD src_size, |
532 int& width, | 532 int& width, |
533 int& height, | 533 int& height, |
534 int& num_components, | 534 int& num_components, |
535 int& bits_per_components, | 535 int& bits_per_components, |
536 FX_BOOL& color_transform, | 536 FX_BOOL& color_transform, |
537 uint8_t** icc_buf_ptr, | 537 uint8_t** icc_buf_ptr, |
538 FX_DWORD* icc_length) { | 538 FX_DWORD* icc_length) { |
539 return _JpegLoadInfo(src_buf, src_size, width, height, num_components, | 539 return _JpegLoadInfo(src_buf, src_size, width, height, num_components, |
540 bits_per_components, color_transform, icc_buf_ptr, | 540 bits_per_components, color_transform, icc_buf_ptr, |
541 icc_length); | 541 icc_length); |
542 } | 542 } |
543 FX_BOOL CCodec_JpegModule::Encode(const CFX_DIBSource* pSource, | 543 FX_BOOL CCodec_JpegModule::Encode(const CFX_DIBSource* pSource, |
544 uint8_t*& dest_buf, | 544 uint8_t*& dest_buf, |
545 FX_STRSIZE& dest_size, | 545 FX_STRSIZE& dest_size, |
546 int quality, | 546 int quality, |
547 const uint8_t* icc_buf, | 547 const uint8_t* icc_buf, |
548 FX_DWORD icc_length) { | 548 FX_DWORD icc_length) { |
549 if (pSource->GetBPP() < 8 || pSource->GetPalette()) { | 549 if (pSource->GetBPP() < 8 || pSource->GetPalette()) |
550 ASSERT(pSource->GetBPP() >= 8 && pSource->GetPalette() == NULL); | |
551 return FALSE; | 550 return FALSE; |
552 } | 551 |
553 _JpegEncode(pSource, dest_buf, dest_size, quality, icc_buf, icc_length); | 552 _JpegEncode(pSource, dest_buf, dest_size, quality, icc_buf, icc_length); |
554 return TRUE; | 553 return TRUE; |
555 } | 554 } |
556 struct FXJPEG_Context { | 555 struct FXJPEG_Context { |
557 jmp_buf m_JumpMark; | 556 jmp_buf m_JumpMark; |
558 jpeg_decompress_struct m_Info; | 557 jpeg_decompress_struct m_Info; |
559 jpeg_error_mgr m_ErrMgr; | 558 jpeg_error_mgr m_ErrMgr; |
560 jpeg_source_mgr m_SrcMgr; | 559 jpeg_source_mgr m_SrcMgr; |
561 unsigned int m_SkipSize; | 560 unsigned int m_SkipSize; |
562 void* (*m_AllocFunc)(unsigned int); | 561 void* (*m_AllocFunc)(unsigned int); |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
684 uint8_t** avail_buf_ptr) { | 683 uint8_t** avail_buf_ptr) { |
685 if (avail_buf_ptr) { | 684 if (avail_buf_ptr) { |
686 *avail_buf_ptr = NULL; | 685 *avail_buf_ptr = NULL; |
687 if (((FXJPEG_Context*)pContext)->m_SrcMgr.bytes_in_buffer > 0) { | 686 if (((FXJPEG_Context*)pContext)->m_SrcMgr.bytes_in_buffer > 0) { |
688 *avail_buf_ptr = | 687 *avail_buf_ptr = |
689 (uint8_t*)((FXJPEG_Context*)pContext)->m_SrcMgr.next_input_byte; | 688 (uint8_t*)((FXJPEG_Context*)pContext)->m_SrcMgr.next_input_byte; |
690 } | 689 } |
691 } | 690 } |
692 return (FX_DWORD)((FXJPEG_Context*)pContext)->m_SrcMgr.bytes_in_buffer; | 691 return (FX_DWORD)((FXJPEG_Context*)pContext)->m_SrcMgr.bytes_in_buffer; |
693 } | 692 } |
OLD | NEW |