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/fxge/fx_dib.h" | 7 #include "../../../include/fxge/fx_dib.h" |
8 #include "../../../include/fxge/fx_ge.h" | 8 #include "../../../include/fxge/fx_ge.h" |
9 #include "../../../include/fxcodec/fx_codec.h" | 9 #include "../../../include/fxcodec/fx_codec.h" |
10 const FX_DWORD g_dwWinPalette[256] = { | 10 const FX_DWORD g_dwWinPalette[256] = { |
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
229 } | 229 } |
230 FX_BOOL CFX_Palette::BuildPalette(const CFX_DIBSource* pBitmap, int pal_type) | 230 FX_BOOL CFX_Palette::BuildPalette(const CFX_DIBSource* pBitmap, int pal_type) |
231 { | 231 { |
232 if (pBitmap == NULL) { | 232 if (pBitmap == NULL) { |
233 return FALSE; | 233 return FALSE; |
234 } | 234 } |
235 if (m_pPalette != NULL) { | 235 if (m_pPalette != NULL) { |
236 FX_Free(m_pPalette); | 236 FX_Free(m_pPalette); |
237 } | 237 } |
238 m_pPalette = FX_Alloc(FX_DWORD, 256); | 238 m_pPalette = FX_Alloc(FX_DWORD, 256); |
239 if (!m_pPalette) { | |
240 return FALSE; | |
241 } | |
242 int bpp = pBitmap->GetBPP() / 8; | 239 int bpp = pBitmap->GetBPP() / 8; |
243 int width = pBitmap->GetWidth(); | 240 int width = pBitmap->GetWidth(); |
244 int height = pBitmap->GetHeight(); | 241 int height = pBitmap->GetHeight(); |
245 if (m_cLut) { | 242 if (m_cLut) { |
246 FX_Free(m_cLut); | 243 FX_Free(m_cLut); |
247 m_cLut = NULL; | 244 m_cLut = NULL; |
248 } | 245 } |
249 if (m_aLut) { | 246 if (m_aLut) { |
250 FX_Free(m_aLut); | 247 FX_Free(m_aLut); |
251 m_aLut = NULL; | 248 m_aLut = NULL; |
252 } | 249 } |
253 m_cLut = FX_Alloc(FX_DWORD, 4096); | 250 m_cLut = FX_Alloc(FX_DWORD, 4096); |
254 if (!m_cLut) { | |
255 return FALSE; | |
256 } | |
257 m_aLut = FX_Alloc(FX_DWORD, 4096); | 251 m_aLut = FX_Alloc(FX_DWORD, 4096); |
258 if (!m_aLut) { | |
259 return FALSE; | |
260 } | |
261 int row, col; | 252 int row, col; |
262 m_lut = 0; | 253 m_lut = 0; |
263 for (row = 0; row < height; row++) { | 254 for (row = 0; row < height; row++) { |
264 FX_BYTE* scan_line = (FX_BYTE*)pBitmap->GetScanline(row); | 255 FX_BYTE* scan_line = (FX_BYTE*)pBitmap->GetScanline(row); |
265 for (col = 0; col < width; col++) { | 256 for (col = 0; col < width; col++) { |
266 FX_BYTE* src_port = scan_line + col * bpp; | 257 FX_BYTE* src_port = scan_line + col * bpp; |
267 FX_DWORD b = src_port[0] & 0xf0; | 258 FX_DWORD b = src_port[0] & 0xf0; |
268 FX_DWORD g = src_port[1] & 0xf0; | 259 FX_DWORD g = src_port[1] & 0xf0; |
269 FX_DWORD r = src_port[2] & 0xf0; | 260 FX_DWORD r = src_port[2] & 0xf0; |
270 FX_DWORD index = (r << 4) + g + (b >> 4); | 261 FX_DWORD index = (r << 4) + g + (b >> 4); |
(...skipping 594 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
865 return _ConvertBuffer_RgbOrCmyk2Gray(dest_buf, dest_pitch, w
idth, height, pSrcBitmap, src_left, src_top, pIccTransform); | 856 return _ConvertBuffer_RgbOrCmyk2Gray(dest_buf, dest_pitch, w
idth, height, pSrcBitmap, src_left, src_top, pIccTransform); |
866 } | 857 } |
867 return FALSE; | 858 return FALSE; |
868 } | 859 } |
869 case FXDIB_8bppRgb: | 860 case FXDIB_8bppRgb: |
870 case FXDIB_8bppRgba: { | 861 case FXDIB_8bppRgba: { |
871 if ((src_format & 0xff) == 8 && pSrcBitmap->GetPalette() == NULL
) { | 862 if ((src_format & 0xff) == 8 && pSrcBitmap->GetPalette() == NULL
) { |
872 return ConvertBuffer(FXDIB_8bppMask, dest_buf, dest_pitch, w
idth, height, pSrcBitmap, src_left, src_top, d_pal, pIccTransform); | 863 return ConvertBuffer(FXDIB_8bppMask, dest_buf, dest_pitch, w
idth, height, pSrcBitmap, src_left, src_top, d_pal, pIccTransform); |
873 } | 864 } |
874 d_pal = FX_Alloc(FX_DWORD, 256); | 865 d_pal = FX_Alloc(FX_DWORD, 256); |
875 if (!d_pal) { | |
876 return FALSE; | |
877 } | |
878 if (((src_format & 0xff) == 1 || (src_format & 0xff) == 8) && pS
rcBitmap->GetPalette()) { | 866 if (((src_format & 0xff) == 1 || (src_format & 0xff) == 8) && pS
rcBitmap->GetPalette()) { |
879 return _ConvertBuffer_Plt2PltRgb8(dest_buf, dest_pitch, widt
h, height, pSrcBitmap, src_left, src_top, d_pal, pIccTransform); | 867 return _ConvertBuffer_Plt2PltRgb8(dest_buf, dest_pitch, widt
h, height, pSrcBitmap, src_left, src_top, d_pal, pIccTransform); |
880 } else if ((src_format & 0xff) >= 24) { | 868 } else if ((src_format & 0xff) >= 24) { |
881 return _ConvertBuffer_Rgb2PltRgb8(dest_buf, dest_pitch, widt
h, height, pSrcBitmap, src_left, src_top, d_pal, pIccTransform); | 869 return _ConvertBuffer_Rgb2PltRgb8(dest_buf, dest_pitch, widt
h, height, pSrcBitmap, src_left, src_top, d_pal, pIccTransform); |
882 } | 870 } |
883 return FALSE; | 871 return FALSE; |
884 } | 872 } |
885 case FXDIB_Rgb: | 873 case FXDIB_Rgb: |
886 case FXDIB_Rgba: { | 874 case FXDIB_Rgba: { |
887 if ((src_format & 0xff) == 1) { | 875 if ((src_format & 0xff) == 1) { |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1078 if (!m_bExtBuf) { | 1066 if (!m_bExtBuf) { |
1079 FX_Free(m_pBuffer); | 1067 FX_Free(m_pBuffer); |
1080 } | 1068 } |
1081 m_bExtBuf = FALSE; | 1069 m_bExtBuf = FALSE; |
1082 m_pBuffer = dest_buf; | 1070 m_pBuffer = dest_buf; |
1083 m_bpp = (FX_BYTE)dest_format; | 1071 m_bpp = (FX_BYTE)dest_format; |
1084 m_AlphaFlag = (FX_BYTE)(dest_format >> 8); | 1072 m_AlphaFlag = (FX_BYTE)(dest_format >> 8); |
1085 m_Pitch = dest_pitch; | 1073 m_Pitch = dest_pitch; |
1086 return TRUE; | 1074 return TRUE; |
1087 } | 1075 } |
OLD | NEW |