| 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 "../../../include/fxcodec/fx_codec.h" | 7 #include "../../../include/fxcodec/fx_codec.h" |
| 8 #include "../../../include/fxge/fx_dib.h" | 8 #include "../../../include/fxge/fx_dib.h" |
| 9 #include "codec_int.h" | 9 #include "codec_int.h" |
| 10 extern "C" { | 10 extern "C" { |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 #define JPEG_OVERHEAD_LEN 14 | 75 #define JPEG_OVERHEAD_LEN 14 |
| 76 static FX_BOOL _JpegIsIccMarker(jpeg_saved_marker_ptr marker) | 76 static FX_BOOL _JpegIsIccMarker(jpeg_saved_marker_ptr marker) |
| 77 { | 77 { |
| 78 if (marker->marker == JPEG_MARKER_ICC && | 78 if (marker->marker == JPEG_MARKER_ICC && |
| 79 marker->data_length >= JPEG_OVERHEAD_LEN && | 79 marker->data_length >= JPEG_OVERHEAD_LEN && |
| 80 (FXSYS_memcmp32(marker->data, "\x49\x43\x43\x5f\x50\x52\x4f\x46\x49\
x4c\x45\x00", 12) == 0)) { | 80 (FXSYS_memcmp32(marker->data, "\x49\x43\x43\x5f\x50\x52\x4f\x46\x49\
x4c\x45\x00", 12) == 0)) { |
| 81 return TRUE; | 81 return TRUE; |
| 82 } | 82 } |
| 83 return FALSE; | 83 return FALSE; |
| 84 } | 84 } |
| 85 static FX_BOOL _JpegLoadIccProfile(j_decompress_ptr cinfo, FX_LPBYTE* icc_buf_p
tr, FX_DWORD* icc_length) | |
| 86 { | |
| 87 if(icc_buf_ptr == NULL || icc_length == NULL) { | |
| 88 return FALSE; | |
| 89 } | |
| 90 *icc_buf_ptr = NULL; | |
| 91 *icc_length = 0; | |
| 92 FX_LPBYTE icc_data_ptr = NULL; | |
| 93 FX_DWORD icc_data_len = 0; | |
| 94 FX_BYTE count_icc_marker = 0; | |
| 95 FX_BYTE num_icc_marker = 0; | |
| 96 jpeg_saved_marker_ptr marker_list[256] = {NULL}; | |
| 97 for (jpeg_saved_marker_ptr cur_marker = cinfo->marker_list; | |
| 98 cur_marker != NULL; | |
| 99 cur_marker = cur_marker->next) { | |
| 100 if(_JpegIsIccMarker(cur_marker)) { | |
| 101 if(count_icc_marker == 0) { | |
| 102 num_icc_marker = cur_marker->data[13]; | |
| 103 } else if(num_icc_marker != cur_marker->data[13]) { | |
| 104 return FALSE; | |
| 105 } | |
| 106 int sn = cur_marker->data[12] - 1; | |
| 107 if(sn < 0 || sn >= num_icc_marker) { | |
| 108 return FALSE; | |
| 109 } | |
| 110 if(marker_list[sn] == NULL) { | |
| 111 marker_list[sn] = cur_marker; | |
| 112 } else { | |
| 113 return FALSE; | |
| 114 } | |
| 115 count_icc_marker ++; | |
| 116 icc_data_len += (cur_marker->data_length - JPEG_OVERHEAD_LEN); | |
| 117 } | |
| 118 } | |
| 119 if(count_icc_marker != num_icc_marker) { | |
| 120 return FALSE; | |
| 121 } | |
| 122 if(num_icc_marker == 0) { | |
| 123 return TRUE; | |
| 124 } | |
| 125 icc_data_ptr = FX_Alloc(FX_BYTE, icc_data_len); | |
| 126 if(icc_buf_ptr == NULL) { | |
| 127 return FALSE; | |
| 128 } | |
| 129 *icc_buf_ptr = icc_data_ptr; | |
| 130 *icc_length = icc_data_len; | |
| 131 for (int idx = 0; idx < num_icc_marker; idx++) { | |
| 132 icc_data_len = marker_list[idx]->data_length - JPEG_OVERHEAD_LEN; | |
| 133 FXSYS_memcpy32(icc_data_ptr, marker_list[idx]->data + JPEG_OVERHEAD_LEN,
icc_data_len); | |
| 134 icc_data_ptr += icc_data_len; | |
| 135 } | |
| 136 return TRUE; | |
| 137 } | |
| 138 static FX_BOOL _JpegEmbedIccProfile(j_compress_ptr cinfo, FX_LPCBYTE icc_buf_pt
r, FX_DWORD icc_length) | 85 static FX_BOOL _JpegEmbedIccProfile(j_compress_ptr cinfo, FX_LPCBYTE icc_buf_pt
r, FX_DWORD icc_length) |
| 139 { | 86 { |
| 140 if(icc_buf_ptr == NULL || icc_length == 0) { | 87 if(icc_buf_ptr == NULL || icc_length == 0) { |
| 141 return FALSE; | 88 return FALSE; |
| 142 } | 89 } |
| 143 FX_DWORD icc_segment_size = (JPEG_MARKER_MAXSIZE - 2 - JPEG_OVERHEAD_LEN); | 90 FX_DWORD icc_segment_size = (JPEG_MARKER_MAXSIZE - 2 - JPEG_OVERHEAD_LEN); |
| 144 FX_DWORD icc_segment_num = (icc_length / icc_segment_size) + 1; | 91 FX_DWORD icc_segment_num = (icc_length / icc_segment_size) + 1; |
| 145 if (icc_segment_num > 255) { | 92 if (icc_segment_num > 255) { |
| 146 return FALSE; | 93 return FALSE; |
| 147 } | 94 } |
| (...skipping 578 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 726 return m_pExtProvider->GetAvailInput(pContext, avail_buf_ptr); | 673 return m_pExtProvider->GetAvailInput(pContext, avail_buf_ptr); |
| 727 } | 674 } |
| 728 if(avail_buf_ptr != NULL) { | 675 if(avail_buf_ptr != NULL) { |
| 729 *avail_buf_ptr = NULL; | 676 *avail_buf_ptr = NULL; |
| 730 if(((FXJPEG_Context*)pContext)->m_SrcMgr.bytes_in_buffer > 0) { | 677 if(((FXJPEG_Context*)pContext)->m_SrcMgr.bytes_in_buffer > 0) { |
| 731 *avail_buf_ptr = (FX_LPBYTE)((FXJPEG_Context*)pContext)->m_SrcMgr.ne
xt_input_byte; | 678 *avail_buf_ptr = (FX_LPBYTE)((FXJPEG_Context*)pContext)->m_SrcMgr.ne
xt_input_byte; |
| 732 } | 679 } |
| 733 } | 680 } |
| 734 return (FX_DWORD)((FXJPEG_Context*)pContext)->m_SrcMgr.bytes_in_buffer; | 681 return (FX_DWORD)((FXJPEG_Context*)pContext)->m_SrcMgr.bytes_in_buffer; |
| 735 } | 682 } |
| OLD | NEW |