| 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 "../../../include/fxcodec/fx_codec.h" | 9 #include "../../../include/fxcodec/fx_codec.h" |
| 10 #include "../../../include/fxcrt/fx_safe_types.h" | 10 #include "../../../include/fxcrt/fx_safe_types.h" |
| (...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 217 dest.next_output_byte = dest_buf + dest_buf_length - dest.free_in_buffer; | 217 dest.next_output_byte = dest_buf + dest_buf_length - dest.free_in_buffer; |
| 218 dest_buf_length += JPEG_BLOCK_SIZE; | 218 dest_buf_length += JPEG_BLOCK_SIZE; |
| 219 dest.free_in_buffer += JPEG_BLOCK_SIZE; | 219 dest.free_in_buffer += JPEG_BLOCK_SIZE; |
| 220 } | 220 } |
| 221 } | 221 } |
| 222 jpeg_finish_compress(&cinfo); | 222 jpeg_finish_compress(&cinfo); |
| 223 jpeg_destroy_compress(&cinfo); | 223 jpeg_destroy_compress(&cinfo); |
| 224 FX_Free(line_buf); | 224 FX_Free(line_buf); |
| 225 dest_size = dest_buf_length - (FX_STRSIZE)dest.free_in_buffer; | 225 dest_size = dest_buf_length - (FX_STRSIZE)dest.free_in_buffer; |
| 226 } | 226 } |
| 227 #ifdef PDF_ENABLE_XFA |
| 228 static void _JpegLoadAttribute(struct jpeg_decompress_struct* pInfo, |
| 229 CFX_DIBAttribute* pAttribute) { |
| 230 if (pInfo == NULL || pAttribute == NULL) { |
| 231 return; |
| 232 } |
| 233 if (pAttribute) { |
| 234 pAttribute->m_nXDPI = pInfo->X_density; |
| 235 pAttribute->m_nYDPI = pInfo->Y_density; |
| 236 pAttribute->m_wDPIUnit = pInfo->density_unit; |
| 237 } |
| 238 } |
| 239 #endif |
| 227 static FX_BOOL _JpegLoadInfo(const uint8_t* src_buf, | 240 static FX_BOOL _JpegLoadInfo(const uint8_t* src_buf, |
| 228 FX_DWORD src_size, | 241 FX_DWORD src_size, |
| 229 int& width, | 242 int& width, |
| 230 int& height, | 243 int& height, |
| 231 int& num_components, | 244 int& num_components, |
| 232 int& bits_per_components, | 245 int& bits_per_components, |
| 233 FX_BOOL& color_transform, | 246 FX_BOOL& color_transform, |
| 234 uint8_t** icc_buf_ptr, | 247 uint8_t** icc_buf_ptr, |
| 235 FX_DWORD* icc_length) { | 248 FX_DWORD* icc_length) { |
| 236 _JpegScanSOI(src_buf, src_size); | 249 _JpegScanSOI(src_buf, src_size); |
| (...skipping 413 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 650 src_size -= p->m_SkipSize; | 663 src_size -= p->m_SkipSize; |
| 651 src_buf += p->m_SkipSize; | 664 src_buf += p->m_SkipSize; |
| 652 p->m_SkipSize = 0; | 665 p->m_SkipSize = 0; |
| 653 } | 666 } |
| 654 p->m_SrcMgr.next_input_byte = src_buf; | 667 p->m_SrcMgr.next_input_byte = src_buf; |
| 655 p->m_SrcMgr.bytes_in_buffer = src_size; | 668 p->m_SrcMgr.bytes_in_buffer = src_size; |
| 656 } | 669 } |
| 657 int CCodec_JpegModule::ReadHeader(void* pContext, | 670 int CCodec_JpegModule::ReadHeader(void* pContext, |
| 658 int* width, | 671 int* width, |
| 659 int* height, | 672 int* height, |
| 673 #ifndef PDF_ENABLE_XFA |
| 660 int* nComps) { | 674 int* nComps) { |
| 675 #else |
| 676 int* nComps, |
| 677 CFX_DIBAttribute* pAttribute) { |
| 678 #endif |
| 661 if (m_pExtProvider) { | 679 if (m_pExtProvider) { |
| 680 #ifndef PDF_ENABLE_XFA |
| 662 return m_pExtProvider->ReadHeader(pContext, width, height, nComps); | 681 return m_pExtProvider->ReadHeader(pContext, width, height, nComps); |
| 682 #else |
| 683 return m_pExtProvider->ReadHeader(pContext, width, height, nComps, |
| 684 pAttribute); |
| 685 #endif |
| 663 } | 686 } |
| 664 FXJPEG_Context* p = (FXJPEG_Context*)pContext; | 687 FXJPEG_Context* p = (FXJPEG_Context*)pContext; |
| 665 if (setjmp(p->m_JumpMark) == -1) { | 688 if (setjmp(p->m_JumpMark) == -1) { |
| 666 return 1; | 689 return 1; |
| 667 } | 690 } |
| 668 int ret = jpeg_read_header(&p->m_Info, true); | 691 int ret = jpeg_read_header(&p->m_Info, true); |
| 669 if (ret == JPEG_SUSPENDED) { | 692 if (ret == JPEG_SUSPENDED) { |
| 670 return 2; | 693 return 2; |
| 671 } | 694 } |
| 672 if (ret != JPEG_HEADER_OK) { | 695 if (ret != JPEG_HEADER_OK) { |
| 673 return 1; | 696 return 1; |
| 674 } | 697 } |
| 675 *width = p->m_Info.image_width; | 698 *width = p->m_Info.image_width; |
| 676 *height = p->m_Info.image_height; | 699 *height = p->m_Info.image_height; |
| 677 *nComps = p->m_Info.num_components; | 700 *nComps = p->m_Info.num_components; |
| 701 #ifdef PDF_ENABLE_XFA |
| 702 _JpegLoadAttribute(&p->m_Info, pAttribute); |
| 703 #endif |
| 678 return 0; | 704 return 0; |
| 679 } | 705 } |
| 680 int CCodec_JpegModule::StartScanline(void* pContext, int down_scale) { | 706 int CCodec_JpegModule::StartScanline(void* pContext, int down_scale) { |
| 681 if (m_pExtProvider) { | 707 if (m_pExtProvider) { |
| 682 return m_pExtProvider->StartScanline(pContext, down_scale); | 708 return m_pExtProvider->StartScanline(pContext, down_scale); |
| 683 } | 709 } |
| 684 FXJPEG_Context* p = (FXJPEG_Context*)pContext; | 710 FXJPEG_Context* p = (FXJPEG_Context*)pContext; |
| 685 if (setjmp(p->m_JumpMark) == -1) { | 711 if (setjmp(p->m_JumpMark) == -1) { |
| 686 return 0; | 712 return 0; |
| 687 } | 713 } |
| (...skipping 19 matching lines...) Expand all Loading... |
| 707 } | 733 } |
| 708 if (avail_buf_ptr != NULL) { | 734 if (avail_buf_ptr != NULL) { |
| 709 *avail_buf_ptr = NULL; | 735 *avail_buf_ptr = NULL; |
| 710 if (((FXJPEG_Context*)pContext)->m_SrcMgr.bytes_in_buffer > 0) { | 736 if (((FXJPEG_Context*)pContext)->m_SrcMgr.bytes_in_buffer > 0) { |
| 711 *avail_buf_ptr = | 737 *avail_buf_ptr = |
| 712 (uint8_t*)((FXJPEG_Context*)pContext)->m_SrcMgr.next_input_byte; | 738 (uint8_t*)((FXJPEG_Context*)pContext)->m_SrcMgr.next_input_byte; |
| 713 } | 739 } |
| 714 } | 740 } |
| 715 return (FX_DWORD)((FXJPEG_Context*)pContext)->m_SrcMgr.bytes_in_buffer; | 741 return (FX_DWORD)((FXJPEG_Context*)pContext)->m_SrcMgr.bytes_in_buffer; |
| 716 } | 742 } |
| OLD | NEW |