Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(50)

Side by Side Diff: core/src/fpdfapi/fpdf_render/fpdf_render_loadimage.cpp

Issue 1304873002: Merge to XFA: Fix some -Wmaybe-uninitialized errors. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@xfa
Patch Set: Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "../../../../third_party/base/nonstd_unique_ptr.h" 7 #include "../../../../third_party/base/nonstd_unique_ptr.h"
8 #include "../../../include/fpdfapi/fpdf_module.h" 8 #include "../../../include/fpdfapi/fpdf_module.h"
9 #include "../../../include/fpdfapi/fpdf_pageobj.h" 9 #include "../../../include/fpdfapi/fpdf_pageobj.h"
10 #include "../../../include/fpdfapi/fpdf_render.h" 10 #include "../../../include/fpdfapi/fpdf_render.h"
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 private: 84 private:
85 ICodec_JpxModule* jpx_module_; // Weak pointer. 85 ICodec_JpxModule* jpx_module_; // Weak pointer.
86 void* ctx_; // Decoder context, owned. 86 void* ctx_; // Decoder context, owned.
87 unsigned char* output_offsets_; // Output offsets for decoding, owned. 87 unsigned char* output_offsets_; // Output offsets for decoding, owned.
88 88
89 // Disallow evil constructors 89 // Disallow evil constructors
90 JpxBitMapContext(const JpxBitMapContext&); 90 JpxBitMapContext(const JpxBitMapContext&);
91 void operator=(const JpxBitMapContext&); 91 void operator=(const JpxBitMapContext&);
92 }; 92 };
93 93
94 const int kMaxImageDimension = 0x01FFFF;
95
94 } // namespace 96 } // namespace
95 97
96 CFX_DIBSource* CPDF_Image::LoadDIBSource(CFX_DIBSource** ppMask, 98 CFX_DIBSource* CPDF_Image::LoadDIBSource(CFX_DIBSource** ppMask,
97 FX_DWORD* pMatteColor, 99 FX_DWORD* pMatteColor,
98 FX_BOOL bStdCS, 100 FX_BOOL bStdCS,
99 FX_DWORD GroupFamily, 101 FX_DWORD GroupFamily,
100 FX_BOOL bLoadMask) const { 102 FX_BOOL bLoadMask) const {
101 CPDF_DIBSource* pSource = new CPDF_DIBSource; 103 CPDF_DIBSource* pSource = new CPDF_DIBSource;
102 if (pSource->Load(m_pDocument, m_pStream, (CPDF_DIBSource**)ppMask, 104 if (pSource->Load(m_pDocument, m_pStream, (CPDF_DIBSource**)ppMask,
103 pMatteColor, NULL, NULL, bStdCS, GroupFamily, bLoadMask)) { 105 pMatteColor, NULL, NULL, bStdCS, GroupFamily, bLoadMask)) {
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
218 return FALSE; 220 return FALSE;
219 } 221 }
220 m_pDocument = pDoc; 222 m_pDocument = pDoc;
221 m_pDict = pStream->GetDict(); 223 m_pDict = pStream->GetDict();
222 if (m_pDict == NULL) { 224 if (m_pDict == NULL) {
223 return FALSE; 225 return FALSE;
224 } 226 }
225 m_pStream = pStream; 227 m_pStream = pStream;
226 m_Width = m_pDict->GetInteger(FX_BSTRC("Width")); 228 m_Width = m_pDict->GetInteger(FX_BSTRC("Width"));
227 m_Height = m_pDict->GetInteger(FX_BSTRC("Height")); 229 m_Height = m_pDict->GetInteger(FX_BSTRC("Height"));
228 if (m_Width <= 0 || m_Height <= 0 || m_Width > 0x01ffff || 230 if (m_Width <= 0 || m_Height <= 0 || m_Width > kMaxImageDimension ||
229 m_Height > 0x01ffff) { 231 m_Height > kMaxImageDimension) {
230 return FALSE; 232 return FALSE;
231 } 233 }
232 m_GroupFamily = GroupFamily; 234 m_GroupFamily = GroupFamily;
233 m_bLoadMask = bLoadMask; 235 m_bLoadMask = bLoadMask;
234 if (!LoadColorInfo(m_pStream->GetObjNum() != 0 ? NULL : pFormResources, 236 if (!LoadColorInfo(m_pStream->GetObjNum() != 0 ? NULL : pFormResources,
235 pPageResources)) { 237 pPageResources)) {
236 return FALSE; 238 return FALSE;
237 } 239 }
238 if (m_bDoBpcCheck && (m_bpc == 0 || m_nComponents == 0)) { 240 if (m_bDoBpcCheck && (m_bpc == 0 || m_nComponents == 0)) {
239 return FALSE; 241 return FALSE;
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
338 if (pStream == NULL) { 340 if (pStream == NULL) {
339 return 0; 341 return 0;
340 } 342 }
341 m_pDocument = pDoc; 343 m_pDocument = pDoc;
342 m_pDict = pStream->GetDict(); 344 m_pDict = pStream->GetDict();
343 m_pStream = pStream; 345 m_pStream = pStream;
344 m_bStdCS = bStdCS; 346 m_bStdCS = bStdCS;
345 m_bHasMask = bHasMask; 347 m_bHasMask = bHasMask;
346 m_Width = m_pDict->GetInteger(FX_BSTRC("Width")); 348 m_Width = m_pDict->GetInteger(FX_BSTRC("Width"));
347 m_Height = m_pDict->GetInteger(FX_BSTRC("Height")); 349 m_Height = m_pDict->GetInteger(FX_BSTRC("Height"));
348 if (m_Width <= 0 || m_Height <= 0 || m_Width > 0x01ffff || 350 if (m_Width <= 0 || m_Height <= 0 || m_Width > kMaxImageDimension ||
349 m_Height > 0x01ffff) { 351 m_Height > kMaxImageDimension) {
350 return 0; 352 return 0;
351 } 353 }
352 m_GroupFamily = GroupFamily; 354 m_GroupFamily = GroupFamily;
353 m_bLoadMask = bLoadMask; 355 m_bLoadMask = bLoadMask;
354 if (!LoadColorInfo(m_pStream->GetObjNum() != 0 ? NULL : pFormResources, 356 if (!LoadColorInfo(m_pStream->GetObjNum() != 0 ? NULL : pFormResources,
355 pPageResources)) { 357 pPageResources)) {
356 return 0; 358 return 0;
357 } 359 }
358 if (m_bDoBpcCheck && (m_bpc == 0 || m_nComponents == 0)) { 360 if (m_bDoBpcCheck && (m_bpc == 0 || m_nComponents == 0)) {
359 return 0; 361 return 0;
(...skipping 415 matching lines...) Expand 10 before | Expand all | Expand 10 after
775 uint8_t* scanline = (uint8_t*)m_pCachedBitmap->GetScanline(row); 777 uint8_t* scanline = (uint8_t*)m_pCachedBitmap->GetScanline(row);
776 for (FX_DWORD col = 0; col < width; ++col) { 778 for (FX_DWORD col = 0; col < width; ++col) {
777 *scanline = (*scanline) >> scale; 779 *scanline = (*scanline) >> scale;
778 ++scanline; 780 ++scanline;
779 } 781 }
780 } 782 }
781 } 783 }
782 m_bpc = 8; 784 m_bpc = 8;
783 } 785 }
784 CPDF_DIBSource* CPDF_DIBSource::LoadMask(FX_DWORD& MatteColor) { 786 CPDF_DIBSource* CPDF_DIBSource::LoadMask(FX_DWORD& MatteColor) {
785 MatteColor = 0xffffffff; 787 MatteColor = 0xFFFFFFFF;
786 CPDF_Stream* pSoftMask = m_pDict->GetStream(FX_BSTRC("SMask")); 788 CPDF_Stream* pSoftMask = m_pDict->GetStream(FX_BSTRC("SMask"));
787 if (pSoftMask) { 789 if (pSoftMask) {
788 CPDF_Array* pMatte = pSoftMask->GetDict()->GetArray(FX_BSTRC("Matte")); 790 CPDF_Array* pMatte = pSoftMask->GetDict()->GetArray(FX_BSTRC("Matte"));
789 if (pMatte != NULL && m_pColorSpace && 791 if (pMatte != NULL && m_pColorSpace &&
790 (FX_DWORD)m_pColorSpace->CountComponents() <= m_nComponents) { 792 (FX_DWORD)m_pColorSpace->CountComponents() <= m_nComponents) {
791 FX_FLOAT* pColor = FX_Alloc(FX_FLOAT, m_nComponents); 793 FX_FLOAT* pColor = FX_Alloc(FX_FLOAT, m_nComponents);
792 for (FX_DWORD i = 0; i < m_nComponents; i++) { 794 for (FX_DWORD i = 0; i < m_nComponents; i++) {
793 pColor[i] = pMatte->GetFloat(i); 795 pColor[i] = pMatte->GetFloat(i);
794 } 796 }
795 FX_FLOAT R, G, B; 797 FX_FLOAT R, G, B;
796 m_pColorSpace->GetRGB(pColor, R, G, B); 798 m_pColorSpace->GetRGB(pColor, R, G, B);
797 FX_Free(pColor); 799 FX_Free(pColor);
798 MatteColor = FXARGB_MAKE(0, FXSYS_round(R * 255), FXSYS_round(G * 255), 800 MatteColor = FXARGB_MAKE(0, FXSYS_round(R * 255), FXSYS_round(G * 255),
799 FXSYS_round(B * 255)); 801 FXSYS_round(B * 255));
800 } 802 }
801 return LoadMaskDIB(pSoftMask); 803 return LoadMaskDIB(pSoftMask);
802 } 804 }
803 CPDF_Object* pMask = m_pDict->GetElementValue(FX_BSTRC("Mask")); 805 CPDF_Object* pMask = m_pDict->GetElementValue(FX_BSTRC("Mask"));
804 if (pMask == NULL) { 806 if (pMask == NULL) {
805 return NULL; 807 return NULL;
806 } 808 }
807 if (pMask->GetType() == PDFOBJ_STREAM) { 809 if (pMask->GetType() == PDFOBJ_STREAM) {
808 return LoadMaskDIB((CPDF_Stream*)pMask); 810 return LoadMaskDIB((CPDF_Stream*)pMask);
809 } 811 }
810 return NULL; 812 return NULL;
811 } 813 }
812 int CPDF_DIBSource::StratLoadMask() { 814 int CPDF_DIBSource::StratLoadMask() {
813 m_MatteColor = 0xffffffff; 815 m_MatteColor = 0XFFFFFFFF;
814 m_pMaskStream = m_pDict->GetStream(FX_BSTRC("SMask")); 816 m_pMaskStream = m_pDict->GetStream(FX_BSTRC("SMask"));
815 if (m_pMaskStream) { 817 if (m_pMaskStream) {
816 CPDF_Array* pMatte = m_pMaskStream->GetDict()->GetArray(FX_BSTRC("Matte")); 818 CPDF_Array* pMatte = m_pMaskStream->GetDict()->GetArray(FX_BSTRC("Matte"));
817 if (pMatte != NULL && m_pColorSpace && 819 if (pMatte != NULL && m_pColorSpace &&
818 (FX_DWORD)m_pColorSpace->CountComponents() <= m_nComponents) { 820 (FX_DWORD)m_pColorSpace->CountComponents() <= m_nComponents) {
819 FX_FLOAT R, G, B; 821 FX_FLOAT R, G, B;
820 FX_FLOAT* pColor = FX_Alloc(FX_FLOAT, m_nComponents); 822 FX_FLOAT* pColor = FX_Alloc(FX_FLOAT, m_nComponents);
821 for (FX_DWORD i = 0; i < m_nComponents; i++) { 823 for (FX_DWORD i = 0; i < m_nComponents; i++) {
822 pColor[i] = pMatte->GetFloat(i); 824 pColor[i] = pMatte->GetFloat(i);
823 } 825 }
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
1036 dest_scan[dest_byte_pos + 1] = G * 255 / max_data; 1038 dest_scan[dest_byte_pos + 1] = G * 255 / max_data;
1037 dest_scan[dest_byte_pos + 2] = R * 255 / max_data; 1039 dest_scan[dest_byte_pos + 2] = R * 255 / max_data;
1038 dest_byte_pos += 3; 1040 dest_byte_pos += 3;
1039 } 1041 }
1040 break; 1042 break;
1041 } 1043 }
1042 return; 1044 return;
1043 } 1045 }
1044 if (m_bpc == 8) { 1046 if (m_bpc == 8) {
1045 if (m_nComponents == m_pColorSpace->CountComponents()) 1047 if (m_nComponents == m_pColorSpace->CountComponents())
1046 m_pColorSpace->TranslateImageLine( 1048 m_pColorSpace->TranslateImageLine(dest_scan, src_scan, m_Width, m_Width,
1047 dest_scan, src_scan, m_Width, m_Width, m_Height, 1049 m_Height, TransMask());
1048 m_bLoadMask && m_GroupFamily == PDFCS_DEVICECMYK &&
1049 m_Family == PDFCS_DEVICECMYK);
1050 return; 1050 return;
1051 } 1051 }
1052 } 1052 }
1053 CFX_FixedBufGrow<FX_FLOAT, 16> color_values1(m_nComponents); 1053 CFX_FixedBufGrow<FX_FLOAT, 16> color_values1(m_nComponents);
1054 FX_FLOAT* color_values = color_values1; 1054 FX_FLOAT* color_values = color_values1;
1055 FX_FLOAT R = 0.0f, G = 0.0f, B = 0.0f; 1055 FX_FLOAT R = 0.0f, G = 0.0f, B = 0.0f;
1056 if (m_bpc == 8) { 1056 if (m_bpc == 8) {
1057 int src_byte_pos = 0; 1057 int src_byte_pos = 0;
1058 int dest_byte_pos = 0; 1058 int dest_byte_pos = 0;
1059 for (int column = 0; column < m_Width; column++) { 1059 for (int column = 0; column < m_Width; column++) {
1060 for (FX_DWORD color = 0; color < m_nComponents; color++) { 1060 for (FX_DWORD color = 0; color < m_nComponents; color++) {
1061 int data = src_scan[src_byte_pos++]; 1061 int data = src_scan[src_byte_pos++];
1062 color_values[color] = m_pCompData[color].m_DecodeMin + 1062 color_values[color] = m_pCompData[color].m_DecodeMin +
1063 m_pCompData[color].m_DecodeStep * data; 1063 m_pCompData[color].m_DecodeStep * data;
1064 } 1064 }
1065 if (m_bLoadMask && m_GroupFamily == PDFCS_DEVICECMYK && 1065 if (TransMask()) {
1066 m_Family == PDFCS_DEVICECMYK) {
1067 FX_FLOAT k = 1.0f - color_values[3]; 1066 FX_FLOAT k = 1.0f - color_values[3];
1068 R = (1.0f - color_values[0]) * k; 1067 R = (1.0f - color_values[0]) * k;
1069 G = (1.0f - color_values[1]) * k; 1068 G = (1.0f - color_values[1]) * k;
1070 B = (1.0f - color_values[2]) * k; 1069 B = (1.0f - color_values[2]) * k;
1071 } else { 1070 } else {
1072 m_pColorSpace->GetRGB(color_values, R, G, B); 1071 m_pColorSpace->GetRGB(color_values, R, G, B);
1073 } 1072 }
1074 R = NORMALCOLOR_MAX(R, 1); 1073 R = NORMALCOLOR_MAX(R, 1);
1075 G = NORMALCOLOR_MAX(G, 1); 1074 G = NORMALCOLOR_MAX(G, 1);
1076 B = NORMALCOLOR_MAX(B, 1); 1075 B = NORMALCOLOR_MAX(B, 1);
1077 dest_scan[dest_byte_pos] = (int32_t)(B * 255); 1076 dest_scan[dest_byte_pos] = (int32_t)(B * 255);
1078 dest_scan[dest_byte_pos + 1] = (int32_t)(G * 255); 1077 dest_scan[dest_byte_pos + 1] = (int32_t)(G * 255);
1079 dest_scan[dest_byte_pos + 2] = (int32_t)(R * 255); 1078 dest_scan[dest_byte_pos + 2] = (int32_t)(R * 255);
1080 dest_byte_pos += 3; 1079 dest_byte_pos += 3;
1081 } 1080 }
1082 } else { 1081 } else {
1083 int src_bit_pos = 0; 1082 int src_bit_pos = 0;
1084 int dest_byte_pos = 0; 1083 int dest_byte_pos = 0;
1085 for (int column = 0; column < m_Width; column++) { 1084 for (int column = 0; column < m_Width; column++) {
1086 for (FX_DWORD color = 0; color < m_nComponents; color++) { 1085 for (FX_DWORD color = 0; color < m_nComponents; color++) {
1087 int data = _GetBits8(src_scan, src_bit_pos, m_bpc); 1086 int data = _GetBits8(src_scan, src_bit_pos, m_bpc);
1088 color_values[color] = m_pCompData[color].m_DecodeMin + 1087 color_values[color] = m_pCompData[color].m_DecodeMin +
1089 m_pCompData[color].m_DecodeStep * data; 1088 m_pCompData[color].m_DecodeStep * data;
1090 src_bit_pos += m_bpc; 1089 src_bit_pos += m_bpc;
1091 } 1090 }
1092 if (m_bLoadMask && m_GroupFamily == PDFCS_DEVICECMYK && 1091 if (TransMask()) {
1093 m_Family == PDFCS_DEVICECMYK) {
1094 FX_FLOAT k = 1.0f - color_values[3]; 1092 FX_FLOAT k = 1.0f - color_values[3];
1095 R = (1.0f - color_values[0]) * k; 1093 R = (1.0f - color_values[0]) * k;
1096 G = (1.0f - color_values[1]) * k; 1094 G = (1.0f - color_values[1]) * k;
1097 B = (1.0f - color_values[2]) * k; 1095 B = (1.0f - color_values[2]) * k;
1098 } else { 1096 } else {
1099 m_pColorSpace->GetRGB(color_values, R, G, B); 1097 m_pColorSpace->GetRGB(color_values, R, G, B);
1100 } 1098 }
1101 R = NORMALCOLOR_MAX(R, 1); 1099 R = NORMALCOLOR_MAX(R, 1);
1102 G = NORMALCOLOR_MAX(G, 1); 1100 G = NORMALCOLOR_MAX(G, 1);
1103 B = NORMALCOLOR_MAX(B, 1); 1101 B = NORMALCOLOR_MAX(B, 1);
(...skipping 26 matching lines...) Expand all
1130 pSrcLine = m_pCachedBitmap->GetScanline(line); 1128 pSrcLine = m_pCachedBitmap->GetScanline(line);
1131 } else if (m_pDecoder) { 1129 } else if (m_pDecoder) {
1132 pSrcLine = m_pDecoder->GetScanline(line); 1130 pSrcLine = m_pDecoder->GetScanline(line);
1133 } else { 1131 } else {
1134 if (m_pStreamAcc->GetSize() >= (line + 1) * src_pitch_value) { 1132 if (m_pStreamAcc->GetSize() >= (line + 1) * src_pitch_value) {
1135 pSrcLine = m_pStreamAcc->GetData() + line * src_pitch_value; 1133 pSrcLine = m_pStreamAcc->GetData() + line * src_pitch_value;
1136 } 1134 }
1137 } 1135 }
1138 if (pSrcLine == NULL) { 1136 if (pSrcLine == NULL) {
1139 uint8_t* pLineBuf = m_pMaskedLine ? m_pMaskedLine : m_pLineBuf; 1137 uint8_t* pLineBuf = m_pMaskedLine ? m_pMaskedLine : m_pLineBuf;
1140 FXSYS_memset(pLineBuf, 0xff, m_Pitch); 1138 FXSYS_memset(pLineBuf, 0xFF, m_Pitch);
1141 return pLineBuf; 1139 return pLineBuf;
1142 } 1140 }
1143 if (m_bpc * m_nComponents == 1) { 1141 if (m_bpc * m_nComponents == 1) {
1144 if (m_bImageMask && m_bDefaultDecode) { 1142 if (m_bImageMask && m_bDefaultDecode) {
1145 for (FX_DWORD i = 0; i < src_pitch_value; i++) { 1143 for (FX_DWORD i = 0; i < src_pitch_value; i++) {
1146 m_pLineBuf[i] = ~pSrcLine[i]; 1144 m_pLineBuf[i] = ~pSrcLine[i];
1147 } 1145 }
1148 } else if (m_bColorKey) { 1146 } else if (m_bColorKey) {
1149 FX_DWORD reset_argb, set_argb; 1147 FX_DWORD reset_argb, set_argb;
1150 reset_argb = m_pPalette ? m_pPalette[0] : 0xff000000; 1148 reset_argb = m_pPalette ? m_pPalette[0] : 0xFF000000;
1151 set_argb = m_pPalette ? m_pPalette[1] : 0xffffffff; 1149 set_argb = m_pPalette ? m_pPalette[1] : 0xFFFFFFFF;
1152 if (m_pCompData[0].m_ColorKeyMin == 0) { 1150 if (m_pCompData[0].m_ColorKeyMin == 0) {
1153 reset_argb = 0; 1151 reset_argb = 0;
1154 } 1152 }
1155 if (m_pCompData[0].m_ColorKeyMax == 1) { 1153 if (m_pCompData[0].m_ColorKeyMax == 1) {
1156 set_argb = 0; 1154 set_argb = 0;
1157 } 1155 }
1158 set_argb = FXARGB_TODIB(set_argb); 1156 set_argb = FXARGB_TODIB(set_argb);
1159 reset_argb = FXARGB_TODIB(reset_argb); 1157 reset_argb = FXARGB_TODIB(reset_argb);
1160 FX_DWORD* dest_scan = (FX_DWORD*)m_pMaskedLine; 1158 FX_DWORD* dest_scan = (FX_DWORD*)m_pMaskedLine;
1161 for (int col = 0; col < m_Width; col++) { 1159 for (int col = 0; col < m_Width; col++) {
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
1196 *pDestPixel++ = FXARGB_B(m_pPalette[index]); 1194 *pDestPixel++ = FXARGB_B(m_pPalette[index]);
1197 *pDestPixel++ = FXARGB_G(m_pPalette[index]); 1195 *pDestPixel++ = FXARGB_G(m_pPalette[index]);
1198 *pDestPixel++ = FXARGB_R(m_pPalette[index]); 1196 *pDestPixel++ = FXARGB_R(m_pPalette[index]);
1199 } else { 1197 } else {
1200 *pDestPixel++ = index; 1198 *pDestPixel++ = index;
1201 *pDestPixel++ = index; 1199 *pDestPixel++ = index;
1202 *pDestPixel++ = index; 1200 *pDestPixel++ = index;
1203 } 1201 }
1204 *pDestPixel = (index < m_pCompData[0].m_ColorKeyMin || 1202 *pDestPixel = (index < m_pCompData[0].m_ColorKeyMin ||
1205 index > m_pCompData[0].m_ColorKeyMax) 1203 index > m_pCompData[0].m_ColorKeyMax)
1206 ? 0xff 1204 ? 0xFF
1207 : 0; 1205 : 0;
1208 pDestPixel++; 1206 pDestPixel++;
1209 } 1207 }
1210 return m_pMaskedLine; 1208 return m_pMaskedLine;
1211 } 1209 }
1212 return m_pLineBuf; 1210 return m_pLineBuf;
1213 } 1211 }
1214 if (m_bColorKey) { 1212 if (m_bColorKey) {
1215 if (m_nComponents == 3 && m_bpc == 8) { 1213 if (m_nComponents == 3 && m_bpc == 8) {
1216 uint8_t* alpha_channel = m_pMaskedLine + 3; 1214 uint8_t* alpha_channel = m_pMaskedLine + 3;
1217 for (int col = 0; col < m_Width; col++) { 1215 for (int col = 0; col < m_Width; col++) {
1218 const uint8_t* pPixel = pSrcLine + col * 3; 1216 const uint8_t* pPixel = pSrcLine + col * 3;
1219 alpha_channel[col * 4] = (pPixel[0] < m_pCompData[0].m_ColorKeyMin || 1217 alpha_channel[col * 4] = (pPixel[0] < m_pCompData[0].m_ColorKeyMin ||
1220 pPixel[0] > m_pCompData[0].m_ColorKeyMax || 1218 pPixel[0] > m_pCompData[0].m_ColorKeyMax ||
1221 pPixel[1] < m_pCompData[1].m_ColorKeyMin || 1219 pPixel[1] < m_pCompData[1].m_ColorKeyMin ||
1222 pPixel[1] > m_pCompData[1].m_ColorKeyMax || 1220 pPixel[1] > m_pCompData[1].m_ColorKeyMax ||
1223 pPixel[2] < m_pCompData[2].m_ColorKeyMin || 1221 pPixel[2] < m_pCompData[2].m_ColorKeyMin ||
1224 pPixel[2] > m_pCompData[2].m_ColorKeyMax) 1222 pPixel[2] > m_pCompData[2].m_ColorKeyMax)
1225 ? 0xff 1223 ? 0xFF
1226 : 0; 1224 : 0;
1227 } 1225 }
1228 } else { 1226 } else {
1229 FXSYS_memset(m_pMaskedLine, 0xff, m_Pitch); 1227 FXSYS_memset(m_pMaskedLine, 0xFF, m_Pitch);
1230 } 1228 }
1231 } 1229 }
1232 if (m_pColorSpace) { 1230 if (m_pColorSpace) {
1233 TranslateScanline24bpp(m_pLineBuf, pSrcLine); 1231 TranslateScanline24bpp(m_pLineBuf, pSrcLine);
1234 pSrcLine = m_pLineBuf; 1232 pSrcLine = m_pLineBuf;
1235 } 1233 }
1236 if (m_bColorKey) { 1234 if (m_bColorKey) {
1237 const uint8_t* pSrcPixel = pSrcLine; 1235 const uint8_t* pSrcPixel = pSrcLine;
1238 uint8_t* pDestPixel = m_pMaskedLine; 1236 uint8_t* pDestPixel = m_pMaskedLine;
1239 for (int col = 0; col < m_Width; col++) { 1237 for (int col = 0; col < m_Width; col++) {
1240 *pDestPixel++ = *pSrcPixel++; 1238 *pDestPixel++ = *pSrcPixel++;
1241 *pDestPixel++ = *pSrcPixel++; 1239 *pDestPixel++ = *pSrcPixel++;
1242 *pDestPixel++ = *pSrcPixel++; 1240 *pDestPixel++ = *pSrcPixel++;
1243 pDestPixel++; 1241 pDestPixel++;
1244 } 1242 }
1245 return m_pMaskedLine; 1243 return m_pMaskedLine;
1246 } 1244 }
1247 return pSrcLine; 1245 return pSrcLine;
1248 } 1246 }
1247
1249 FX_BOOL CPDF_DIBSource::SkipToScanline(int line, IFX_Pause* pPause) const { 1248 FX_BOOL CPDF_DIBSource::SkipToScanline(int line, IFX_Pause* pPause) const {
1250 if (m_pDecoder) { 1249 return m_pDecoder && m_pDecoder->SkipToScanline(line, pPause);
1251 return m_pDecoder->SkipToScanline(line, pPause);
1252 }
1253 return FALSE;
1254 } 1250 }
1251
1255 void CPDF_DIBSource::DownSampleScanline(int line, 1252 void CPDF_DIBSource::DownSampleScanline(int line,
1256 uint8_t* dest_scan, 1253 uint8_t* dest_scan,
1257 int dest_bpp, 1254 int dest_bpp,
1258 int dest_width, 1255 int dest_width,
1259 FX_BOOL bFlipX, 1256 FX_BOOL bFlipX,
1260 int clip_left, 1257 int clip_left,
1261 int clip_width) const { 1258 int clip_width) const {
1262 if (line < 0 || dest_scan == NULL || dest_bpp <= 0 || dest_width <= 0 || 1259 if (line < 0 || !dest_scan || dest_bpp <= 0 || dest_width <= 0 ||
1263 clip_left < 0 || clip_width <= 0) { 1260 clip_left < 0 || clip_width <= 0) {
1264 return; 1261 return;
1265 } 1262 }
1266 1263
1267 FX_DWORD src_width = m_Width; 1264 FX_DWORD src_width = m_Width;
1268 FX_SAFE_DWORD pitch = CalculatePitch8(m_bpc, m_nComponents, m_Width, 1); 1265 FX_SAFE_DWORD pitch = CalculatePitch8(m_bpc, m_nComponents, m_Width, 1);
1269 if (!pitch.IsValid()) { 1266 if (!pitch.IsValid())
1270 return; 1267 return;
1271 }
1272 1268
1273 const uint8_t* pSrcLine = NULL; 1269 const uint8_t* pSrcLine = nullptr;
1274 if (m_pCachedBitmap) { 1270 if (m_pCachedBitmap) {
1275 pSrcLine = m_pCachedBitmap->GetScanline(line); 1271 pSrcLine = m_pCachedBitmap->GetScanline(line);
1276 } else if (m_pDecoder) { 1272 } else if (m_pDecoder) {
1277 pSrcLine = m_pDecoder->GetScanline(line); 1273 pSrcLine = m_pDecoder->GetScanline(line);
1278 } else { 1274 } else {
1279 FX_DWORD src_pitch = pitch.ValueOrDie(); 1275 FX_DWORD src_pitch = pitch.ValueOrDie();
1280 pitch *= (line + 1); 1276 pitch *= (line + 1);
1281 if (!pitch.IsValid()) { 1277 if (!pitch.IsValid()) {
1282 return; 1278 return;
1283 } 1279 }
1284 1280
1285 if (m_pStreamAcc->GetSize() >= pitch.ValueOrDie()) { 1281 if (m_pStreamAcc->GetSize() >= pitch.ValueOrDie()) {
1286 pSrcLine = m_pStreamAcc->GetData() + line * src_pitch; 1282 pSrcLine = m_pStreamAcc->GetData() + line * src_pitch;
1287 } 1283 }
1288 } 1284 }
1289 int orig_Bpp = m_bpc * m_nComponents / 8; 1285 int orig_Bpp = m_bpc * m_nComponents / 8;
1290 int dest_Bpp = dest_bpp / 8; 1286 int dest_Bpp = dest_bpp / 8;
1291 if (pSrcLine == NULL) { 1287 if (!pSrcLine) {
1292 FXSYS_memset(dest_scan, 0xff, dest_Bpp * clip_width); 1288 FXSYS_memset(dest_scan, 0xFF, dest_Bpp * clip_width);
1293 return; 1289 return;
1294 } 1290 }
1295 1291
1296 FX_SAFE_INT32 max_src_x = clip_left; 1292 FX_SAFE_INT32 max_src_x = clip_left;
1297 max_src_x += clip_width - 1; 1293 max_src_x += clip_width - 1;
1298 max_src_x *= src_width; 1294 max_src_x *= src_width;
1299 max_src_x /= dest_width; 1295 max_src_x /= dest_width;
1300 if (!max_src_x.IsValid()) { 1296 if (!max_src_x.IsValid())
1301 return; 1297 return;
1302 } 1298
1303
1304 CFX_FixedBufGrow<uint8_t, 128> temp(orig_Bpp);
1305 if (m_bpc * m_nComponents == 1) { 1299 if (m_bpc * m_nComponents == 1) {
1306 FX_DWORD set_argb = (FX_DWORD)-1, reset_argb = 0; 1300 DownSampleScanline1Bit(orig_Bpp, dest_Bpp, src_width, pSrcLine, dest_scan,
1307 if (m_bImageMask) { 1301 dest_width, bFlipX, clip_left, clip_width);
1308 if (m_bDefaultDecode) { 1302 } else if (m_bpc * m_nComponents <= 8) {
1309 set_argb = 0; 1303 DownSampleScanline8Bit(orig_Bpp, dest_Bpp, src_width, pSrcLine, dest_scan,
1310 reset_argb = (FX_DWORD)-1; 1304 dest_width, bFlipX, clip_left, clip_width);
1311 } 1305 } else {
1312 } else if (m_bColorKey) { 1306 DownSampleScanline32Bit(orig_Bpp, dest_Bpp, src_width, pSrcLine, dest_scan,
1313 reset_argb = m_pPalette ? m_pPalette[0] : 0xff000000; 1307 dest_width, bFlipX, clip_left, clip_width);
1314 set_argb = m_pPalette ? m_pPalette[1] : 0xffffffff; 1308 }
1315 if (m_pCompData[0].m_ColorKeyMin == 0) { 1309 }
1316 reset_argb = 0; 1310
1317 } 1311 void CPDF_DIBSource::DownSampleScanline1Bit(int orig_Bpp,
1318 if (m_pCompData[0].m_ColorKeyMax == 1) { 1312 int dest_Bpp,
1319 set_argb = 0; 1313 FX_DWORD src_width,
1320 } 1314 const uint8_t* pSrcLine,
1321 set_argb = FXARGB_TODIB(set_argb); 1315 uint8_t* dest_scan,
1322 reset_argb = FXARGB_TODIB(reset_argb); 1316 int dest_width,
1323 for (int i = 0; i < clip_width; i++) { 1317 FX_BOOL bFlipX,
1324 FX_DWORD src_x = (clip_left + i) * src_width / dest_width; 1318 int clip_left,
1325 if (bFlipX) { 1319 int clip_width) const {
1326 src_x = src_width - src_x - 1; 1320 FX_DWORD set_argb = (FX_DWORD)-1;
1327 } 1321 FX_DWORD reset_argb = 0;
1328 src_x %= src_width; 1322 if (m_bImageMask) {
1329 if (pSrcLine[src_x / 8] & (1 << (7 - src_x % 8))) { 1323 if (m_bDefaultDecode) {
1330 ((FX_DWORD*)dest_scan)[i] = set_argb; 1324 set_argb = 0;
1331 } else { 1325 reset_argb = (FX_DWORD)-1;
1332 ((FX_DWORD*)dest_scan)[i] = reset_argb; 1326 }
1333 } 1327 } else if (m_bColorKey) {
1334 } 1328 reset_argb = m_pPalette ? m_pPalette[0] : 0xFF000000;
1335 return; 1329 set_argb = m_pPalette ? m_pPalette[1] : 0xFFFFFFFF;
1336 } else { 1330 if (m_pCompData[0].m_ColorKeyMin == 0) {
1337 if (dest_Bpp == 1) { 1331 reset_argb = 0;
1338 } else if (m_pPalette) { 1332 }
1339 reset_argb = m_pPalette[0]; 1333 if (m_pCompData[0].m_ColorKeyMax == 1) {
1340 set_argb = m_pPalette[1]; 1334 set_argb = 0;
1341 } 1335 }
1342 } 1336 set_argb = FXARGB_TODIB(set_argb);
1337 reset_argb = FXARGB_TODIB(reset_argb);
1343 for (int i = 0; i < clip_width; i++) { 1338 for (int i = 0; i < clip_width; i++) {
1344 FX_DWORD src_x = (clip_left + i) * src_width / dest_width; 1339 FX_DWORD src_x = (clip_left + i) * src_width / dest_width;
1345 if (bFlipX) { 1340 if (bFlipX) {
1346 src_x = src_width - src_x - 1; 1341 src_x = src_width - src_x - 1;
1347 } 1342 }
1348 src_x %= src_width; 1343 src_x %= src_width;
1349 int dest_pos = i * dest_Bpp;
1350 if (pSrcLine[src_x / 8] & (1 << (7 - src_x % 8))) { 1344 if (pSrcLine[src_x / 8] & (1 << (7 - src_x % 8))) {
1351 if (dest_Bpp == 1) { 1345 ((FX_DWORD*)dest_scan)[i] = set_argb;
1352 dest_scan[dest_pos] = (uint8_t)set_argb; 1346 } else {
1353 } else if (dest_Bpp == 3) { 1347 ((FX_DWORD*)dest_scan)[i] = reset_argb;
1354 dest_scan[dest_pos] = FXARGB_B(set_argb);
1355 dest_scan[dest_pos + 1] = FXARGB_G(set_argb);
1356 dest_scan[dest_pos + 2] = FXARGB_R(set_argb);
1357 } else {
1358 *(FX_DWORD*)(dest_scan + dest_pos) = set_argb;
1359 }
1360 } else {
1361 if (dest_Bpp == 1) {
1362 dest_scan[dest_pos] = (uint8_t)reset_argb;
1363 } else if (dest_Bpp == 3) {
1364 dest_scan[dest_pos] = FXARGB_B(reset_argb);
1365 dest_scan[dest_pos + 1] = FXARGB_G(reset_argb);
1366 dest_scan[dest_pos + 2] = FXARGB_R(reset_argb);
1367 } else {
1368 *(FX_DWORD*)(dest_scan + dest_pos) = reset_argb;
1369 }
1370 } 1348 }
1371 } 1349 }
1372 return; 1350 return;
1373 } else if (m_bpc * m_nComponents <= 8) { 1351 } else {
1374 if (m_bpc < 8) { 1352 if (dest_Bpp == 1) {
1375 int src_bit_pos = 0; 1353 } else if (m_pPalette) {
1376 for (FX_DWORD col = 0; col < src_width; col++) { 1354 reset_argb = m_pPalette[0];
1377 int color_index = 0; 1355 set_argb = m_pPalette[1];
1378 for (FX_DWORD color = 0; color < m_nComponents; color++) { 1356 }
1379 int data = _GetBits8(pSrcLine, src_bit_pos, m_bpc); 1357 }
1380 color_index |= data << (color * m_bpc); 1358 for (int i = 0; i < clip_width; i++) {
1381 src_bit_pos += m_bpc; 1359 FX_DWORD src_x = (clip_left + i) * src_width / dest_width;
1382 } 1360 if (bFlipX) {
1383 m_pLineBuf[col] = color_index; 1361 src_x = src_width - src_x - 1;
1384 } 1362 }
1385 pSrcLine = m_pLineBuf; 1363 src_x %= src_width;
1386 } 1364 int dest_pos = i * dest_Bpp;
1387 if (m_bColorKey) { 1365 if (pSrcLine[src_x / 8] & (1 << (7 - src_x % 8))) {
1388 for (int i = 0; i < clip_width; i++) { 1366 if (dest_Bpp == 1) {
1389 FX_DWORD src_x = (clip_left + i) * src_width / dest_width; 1367 dest_scan[dest_pos] = (uint8_t)set_argb;
1390 if (bFlipX) { 1368 } else if (dest_Bpp == 3) {
1391 src_x = src_width - src_x - 1; 1369 dest_scan[dest_pos] = FXARGB_B(set_argb);
1392 } 1370 dest_scan[dest_pos + 1] = FXARGB_G(set_argb);
1393 src_x %= src_width; 1371 dest_scan[dest_pos + 2] = FXARGB_R(set_argb);
1394 uint8_t* pDestPixel = dest_scan + i * 4; 1372 } else {
1395 uint8_t index = pSrcLine[src_x]; 1373 *(FX_DWORD*)(dest_scan + dest_pos) = set_argb;
1396 if (m_pPalette) { 1374 }
1397 *pDestPixel++ = FXARGB_B(m_pPalette[index]); 1375 } else {
1398 *pDestPixel++ = FXARGB_G(m_pPalette[index]); 1376 if (dest_Bpp == 1) {
1399 *pDestPixel++ = FXARGB_R(m_pPalette[index]); 1377 dest_scan[dest_pos] = (uint8_t)reset_argb;
1400 } else { 1378 } else if (dest_Bpp == 3) {
1401 *pDestPixel++ = index; 1379 dest_scan[dest_pos] = FXARGB_B(reset_argb);
1402 *pDestPixel++ = index; 1380 dest_scan[dest_pos + 1] = FXARGB_G(reset_argb);
1403 *pDestPixel++ = index; 1381 dest_scan[dest_pos + 2] = FXARGB_R(reset_argb);
1404 } 1382 } else {
1405 *pDestPixel = (index < m_pCompData[0].m_ColorKeyMin || 1383 *(FX_DWORD*)(dest_scan + dest_pos) = reset_argb;
1406 index > m_pCompData[0].m_ColorKeyMax) 1384 }
1407 ? 0xff 1385 }
1408 : 0; 1386 }
1409 } 1387 }
1410 return; 1388
1411 } 1389 void CPDF_DIBSource::DownSampleScanline8Bit(int orig_Bpp,
1390 int dest_Bpp,
1391 FX_DWORD src_width,
1392 const uint8_t* pSrcLine,
1393 uint8_t* dest_scan,
1394 int dest_width,
1395 FX_BOOL bFlipX,
1396 int clip_left,
1397 int clip_width) const {
1398 if (m_bpc < 8) {
1399 int src_bit_pos = 0;
1400 for (FX_DWORD col = 0; col < src_width; col++) {
1401 int color_index = 0;
1402 for (FX_DWORD color = 0; color < m_nComponents; color++) {
1403 int data = _GetBits8(pSrcLine, src_bit_pos, m_bpc);
1404 color_index |= data << (color * m_bpc);
1405 src_bit_pos += m_bpc;
1406 }
1407 m_pLineBuf[col] = color_index;
1408 }
1409 pSrcLine = m_pLineBuf;
1410 }
1411 if (m_bColorKey) {
1412 for (int i = 0; i < clip_width; i++) { 1412 for (int i = 0; i < clip_width; i++) {
1413 FX_DWORD src_x = (clip_left + i) * src_width / dest_width; 1413 FX_DWORD src_x = (clip_left + i) * src_width / dest_width;
1414 if (bFlipX) { 1414 if (bFlipX) {
1415 src_x = src_width - src_x - 1; 1415 src_x = src_width - src_x - 1;
1416 } 1416 }
1417 src_x %= src_width; 1417 src_x %= src_width;
1418 uint8_t* pDestPixel = dest_scan + i * 4;
1418 uint8_t index = pSrcLine[src_x]; 1419 uint8_t index = pSrcLine[src_x];
1419 if (dest_Bpp == 1) { 1420 if (m_pPalette) {
1420 dest_scan[i] = index; 1421 *pDestPixel++ = FXARGB_B(m_pPalette[index]);
1421 } else { 1422 *pDestPixel++ = FXARGB_G(m_pPalette[index]);
1422 int dest_pos = i * dest_Bpp; 1423 *pDestPixel++ = FXARGB_R(m_pPalette[index]);
1423 FX_ARGB argb = m_pPalette[index]; 1424 } else {
1424 dest_scan[dest_pos] = FXARGB_B(argb); 1425 *pDestPixel++ = index;
1425 dest_scan[dest_pos + 1] = FXARGB_G(argb); 1426 *pDestPixel++ = index;
1426 dest_scan[dest_pos + 2] = FXARGB_R(argb); 1427 *pDestPixel++ = index;
1427 } 1428 }
1429 *pDestPixel = (index < m_pCompData[0].m_ColorKeyMin ||
1430 index > m_pCompData[0].m_ColorKeyMax)
1431 ? 0xFF
1432 : 0;
1428 } 1433 }
1429 return; 1434 return;
1430 } else { 1435 }
1431 int last_src_x = -1; 1436 for (int i = 0; i < clip_width; i++) {
1432 FX_ARGB last_argb; 1437 FX_DWORD src_x = (clip_left + i) * src_width / dest_width;
1433 FX_FLOAT orig_Not8Bpp = (FX_FLOAT)m_bpc * (FX_FLOAT)m_nComponents / 8.0f; 1438 if (bFlipX) {
1434 FX_FLOAT unit_To8Bpc = 255.0f / ((1 << m_bpc) - 1); 1439 src_x = src_width - src_x - 1;
1435 for (int i = 0; i < clip_width; i++) { 1440 }
1436 int dest_x = clip_left + i; 1441 src_x %= src_width;
1437 FX_DWORD src_x = (bFlipX ? (dest_width - dest_x - 1) : dest_x) * 1442 uint8_t index = pSrcLine[src_x];
1438 (int64_t)src_width / dest_width; 1443 if (dest_Bpp == 1) {
1439 src_x %= src_width; 1444 dest_scan[i] = index;
1440 const uint8_t* pSrcPixel = NULL; 1445 } else {
1441 if (m_bpc % 8 == 0) { 1446 int dest_pos = i * dest_Bpp;
1442 pSrcPixel = pSrcLine + src_x * orig_Bpp; 1447 FX_ARGB argb = m_pPalette[index];
1443 } else { 1448 dest_scan[dest_pos] = FXARGB_B(argb);
1444 pSrcPixel = pSrcLine + (int)(src_x * orig_Not8Bpp); 1449 dest_scan[dest_pos + 1] = FXARGB_G(argb);
1445 } 1450 dest_scan[dest_pos + 2] = FXARGB_R(argb);
1446 uint8_t* pDestPixel = dest_scan + i * dest_Bpp; 1451 }
1447 FX_ARGB argb; 1452 }
1448 if (src_x == last_src_x) { 1453 }
1449 argb = last_argb; 1454
1450 } else { 1455 void CPDF_DIBSource::DownSampleScanline32Bit(int orig_Bpp,
1451 if (m_pColorSpace) { 1456 int dest_Bpp,
1452 uint8_t color[4]; 1457 FX_DWORD src_width,
1453 if (!m_bDefaultDecode) { 1458 const uint8_t* pSrcLine,
1454 for (int i = 0; i < m_nComponents; i++) { 1459 uint8_t* dest_scan,
1455 int color_value = 1460 int dest_width,
1456 (int)((m_pCompData[i].m_DecodeMin + 1461 FX_BOOL bFlipX,
1457 m_pCompData[i].m_DecodeStep * (FX_FLOAT)pSrcPixel[i]) * 1462 int clip_left,
1458 255.0f + 1463 int clip_width) const {
1459 0.5f); 1464 int last_src_x = -1;
1460 temp[i] = 1465 FX_ARGB last_argb = FXARGB_MAKE(0xFF, 0xFF, 0xFF, 0xFF);
1461 color_value > 255 ? 255 : (color_value < 0 ? 0 : color_value); 1466 FX_FLOAT orig_Not8Bpp = (FX_FLOAT)m_bpc * (FX_FLOAT)m_nComponents / 8.0f;
1467 FX_FLOAT unit_To8Bpc = 255.0f / ((1 << m_bpc) - 1);
1468 for (int i = 0; i < clip_width; i++) {
1469 int dest_x = clip_left + i;
1470 FX_DWORD src_x = (bFlipX ? (dest_width - dest_x - 1) : dest_x) *
1471 (int64_t)src_width / dest_width;
1472 src_x %= src_width;
1473 const uint8_t* pSrcPixel = nullptr;
1474 if (m_bpc % 8 == 0) {
1475 pSrcPixel = pSrcLine + src_x * orig_Bpp;
1476 } else {
1477 pSrcPixel = pSrcLine + (int)(src_x * orig_Not8Bpp);
1478 }
1479 uint8_t* pDestPixel = dest_scan + i * dest_Bpp;
1480 FX_ARGB argb;
1481 if (src_x == last_src_x) {
1482 argb = last_argb;
1483 } else {
1484 if (m_pColorSpace) {
1485 CFX_FixedBufGrow<uint8_t, 128> temp(orig_Bpp);
1486 uint8_t color[4];
1487 const FX_BOOL bTransMask = TransMask();
1488 if (m_bDefaultDecode) {
1489 if (m_bpc < 8) {
1490 int src_bit_pos = 0;
1491 if (src_x % 2) {
1492 src_bit_pos = 4;
1462 } 1493 }
1463 m_pColorSpace->TranslateImageLine( 1494 for (FX_DWORD j = 0; j < m_nComponents; ++j) {
1464 color, temp, 1, 0, 0, m_bLoadMask && 1495 temp[j] = (uint8_t)(_GetBits8(pSrcPixel, src_bit_pos, m_bpc) *
1465 m_GroupFamily == PDFCS_DEVICECMYK && 1496 unit_To8Bpc);
1466 m_Family == PDFCS_DEVICECMYK); 1497 src_bit_pos += m_bpc;
1498 }
1499 m_pColorSpace->TranslateImageLine(color, temp, 1, 0, 0, bTransMask);
1467 } else { 1500 } else {
1468 if (m_bpc < 8) { 1501 m_pColorSpace->TranslateImageLine(color, pSrcPixel, 1, 0, 0,
1469 int src_bit_pos = 0; 1502 bTransMask);
1470 if (src_x % 2) {
1471 src_bit_pos = 4;
1472 }
1473 for (FX_DWORD i = 0; i < m_nComponents; i++) {
1474 temp[i] = (uint8_t)(_GetBits8(pSrcPixel, src_bit_pos, m_bpc) *
1475 unit_To8Bpc);
1476 src_bit_pos += m_bpc;
1477 }
1478 m_pColorSpace->TranslateImageLine(
1479 color, temp, 1, 0, 0, m_bLoadMask &&
1480 m_GroupFamily == PDFCS_DEVICECMYK &&
1481 m_Family == PDFCS_DEVICECMYK);
1482 } else {
1483 m_pColorSpace->TranslateImageLine(
1484 color, pSrcPixel, 1, 0, 0,
1485 m_bLoadMask && m_GroupFamily == PDFCS_DEVICECMYK &&
1486 m_Family == PDFCS_DEVICECMYK);
1487 }
1488 } 1503 }
1489 argb = FXARGB_MAKE(0xff, color[2], color[1], color[0]);
1490 } else { 1504 } else {
1491 argb = FXARGB_MAKE(0xff, pSrcPixel[2], pSrcPixel[1], pSrcPixel[0]); 1505 for (int j = 0; j < m_nComponents; ++j) {
1506 int color_value =
1507 (int)((m_pCompData[j].m_DecodeMin +
1508 m_pCompData[j].m_DecodeStep * (FX_FLOAT)pSrcPixel[j]) *
1509 255.0f +
1510 0.5f);
1511 temp[j] =
1512 color_value > 255 ? 255 : (color_value < 0 ? 0 : color_value);
1513 }
1514 m_pColorSpace->TranslateImageLine(color, temp, 1, 0, 0, bTransMask);
1492 } 1515 }
1493 if (m_bColorKey) { 1516 argb = FXARGB_MAKE(0xFF, color[2], color[1], color[0]);
1494 int alpha = 0xff; 1517 } else {
1495 if (m_nComponents == 3 && m_bpc == 8) { 1518 argb = FXARGB_MAKE(0xFf, pSrcPixel[2], pSrcPixel[1], pSrcPixel[0]);
1496 alpha = (pSrcPixel[0] < m_pCompData[0].m_ColorKeyMin || 1519 }
1497 pSrcPixel[0] > m_pCompData[0].m_ColorKeyMax || 1520 if (m_bColorKey) {
1498 pSrcPixel[1] < m_pCompData[1].m_ColorKeyMin || 1521 int alpha = 0xFF;
1499 pSrcPixel[1] > m_pCompData[1].m_ColorKeyMax || 1522 if (m_nComponents == 3 && m_bpc == 8) {
1500 pSrcPixel[2] < m_pCompData[2].m_ColorKeyMin || 1523 alpha = (pSrcPixel[0] < m_pCompData[0].m_ColorKeyMin ||
1501 pSrcPixel[2] > m_pCompData[2].m_ColorKeyMax) 1524 pSrcPixel[0] > m_pCompData[0].m_ColorKeyMax ||
1502 ? 0xff 1525 pSrcPixel[1] < m_pCompData[1].m_ColorKeyMin ||
1503 : 0; 1526 pSrcPixel[1] > m_pCompData[1].m_ColorKeyMax ||
1504 } 1527 pSrcPixel[2] < m_pCompData[2].m_ColorKeyMin ||
1505 argb &= 0xffffff; 1528 pSrcPixel[2] > m_pCompData[2].m_ColorKeyMax)
1506 argb |= alpha << 24; 1529 ? 0xFF
1530 : 0;
1507 } 1531 }
1508 last_src_x = src_x; 1532 argb &= 0xFFFFFF;
1509 last_argb = argb; 1533 argb |= alpha << 24;
1510 } 1534 }
1511 if (dest_Bpp == 4) { 1535 last_src_x = src_x;
1512 *(FX_DWORD*)pDestPixel = FXARGB_TODIB(argb); 1536 last_argb = argb;
1513 } else { 1537 }
1514 *pDestPixel++ = FXARGB_B(argb); 1538 if (dest_Bpp == 4) {
1515 *pDestPixel++ = FXARGB_G(argb); 1539 *(FX_DWORD*)pDestPixel = FXARGB_TODIB(argb);
1516 *pDestPixel = FXARGB_R(argb); 1540 } else {
1517 } 1541 *pDestPixel++ = FXARGB_B(argb);
1518 } 1542 *pDestPixel++ = FXARGB_G(argb);
1519 } 1543 *pDestPixel = FXARGB_R(argb);
1520 } 1544 }
1545 }
1546 }
1547
1548 FX_BOOL CPDF_DIBSource::TransMask() const {
1549 return m_bLoadMask && m_GroupFamily == PDFCS_DEVICECMYK &&
1550 m_Family == PDFCS_DEVICECMYK;
1551 }
1552
1521 void CPDF_DIBSource::SetDownSampleSize(int dest_width, int dest_height) const { 1553 void CPDF_DIBSource::SetDownSampleSize(int dest_width, int dest_height) const {
1522 if (m_pDecoder) { 1554 if (m_pDecoder) {
1523 m_pDecoder->DownScale(dest_width, dest_height); 1555 m_pDecoder->DownScale(dest_width, dest_height);
1524 ((CPDF_DIBSource*)this)->m_Width = m_pDecoder->GetWidth(); 1556 ((CPDF_DIBSource*)this)->m_Width = m_pDecoder->GetWidth();
1525 ((CPDF_DIBSource*)this)->m_Height = m_pDecoder->GetHeight(); 1557 ((CPDF_DIBSource*)this)->m_Height = m_pDecoder->GetHeight();
1526 } 1558 }
1527 } 1559 }
1560
1528 void CPDF_DIBSource::ClearImageData() { 1561 void CPDF_DIBSource::ClearImageData() {
1529 if (m_pDecoder) { 1562 if (m_pDecoder) {
1530 m_pDecoder->ClearImageData(); 1563 m_pDecoder->ClearImageData();
1531 } 1564 }
1532 } 1565 }
1566
1533 CPDF_ProgressiveImageLoaderHandle::CPDF_ProgressiveImageLoaderHandle() { 1567 CPDF_ProgressiveImageLoaderHandle::CPDF_ProgressiveImageLoaderHandle() {
1534 m_pImageLoader = NULL; 1568 m_pImageLoader = NULL;
1535 m_pCache = NULL; 1569 m_pCache = NULL;
1536 m_pImage = NULL; 1570 m_pImage = NULL;
1537 } 1571 }
1538 CPDF_ProgressiveImageLoaderHandle::~CPDF_ProgressiveImageLoaderHandle() {} 1572 CPDF_ProgressiveImageLoaderHandle::~CPDF_ProgressiveImageLoaderHandle() {}
1539 FX_BOOL CPDF_ProgressiveImageLoaderHandle::Start( 1573 FX_BOOL CPDF_ProgressiveImageLoaderHandle::Start(
1540 CPDF_ImageLoader* pImageLoader, 1574 CPDF_ImageLoader* pImageLoader,
1541 const CPDF_ImageObject* pImage, 1575 const CPDF_ImageObject* pImage,
1542 CPDF_PageRenderCache* pCache, 1576 CPDF_PageRenderCache* pCache,
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
1639 } 1673 }
1640 FX_BOOL CPDF_ImageLoader::Continue(void* LoadHandle, IFX_Pause* pPause) { 1674 FX_BOOL CPDF_ImageLoader::Continue(void* LoadHandle, IFX_Pause* pPause) {
1641 return ((CPDF_ProgressiveImageLoaderHandle*)LoadHandle)->Continue(pPause); 1675 return ((CPDF_ProgressiveImageLoaderHandle*)LoadHandle)->Continue(pPause);
1642 } 1676 }
1643 CPDF_ImageLoader::~CPDF_ImageLoader() { 1677 CPDF_ImageLoader::~CPDF_ImageLoader() {
1644 if (!m_bCached) { 1678 if (!m_bCached) {
1645 delete m_pBitmap; 1679 delete m_pBitmap;
1646 delete m_pMask; 1680 delete m_pMask;
1647 } 1681 }
1648 } 1682 }
OLDNEW
« no previous file with comments | « core/src/fpdfapi/fpdf_edit/fpdf_edit_image.cpp ('k') | core/src/fpdfapi/fpdf_render/render_int.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698