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 590 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
861 return _ConvertBuffer_RgbOrCmyk2Gray(dest_buf, dest_pitch, w
idth, height, pSrcBitmap, src_left, src_top, pIccTransform); | 852 return _ConvertBuffer_RgbOrCmyk2Gray(dest_buf, dest_pitch, w
idth, height, pSrcBitmap, src_left, src_top, pIccTransform); |
862 } | 853 } |
863 return FALSE; | 854 return FALSE; |
864 } | 855 } |
865 case FXDIB_8bppRgb: | 856 case FXDIB_8bppRgb: |
866 case FXDIB_8bppRgba: { | 857 case FXDIB_8bppRgba: { |
867 if ((src_format & 0xff) == 8 && pSrcBitmap->GetPalette() == NULL
) { | 858 if ((src_format & 0xff) == 8 && pSrcBitmap->GetPalette() == NULL
) { |
868 return ConvertBuffer(FXDIB_8bppMask, dest_buf, dest_pitch, w
idth, height, pSrcBitmap, src_left, src_top, d_pal, pIccTransform); | 859 return ConvertBuffer(FXDIB_8bppMask, dest_buf, dest_pitch, w
idth, height, pSrcBitmap, src_left, src_top, d_pal, pIccTransform); |
869 } | 860 } |
870 d_pal = FX_Alloc(FX_DWORD, 256); | 861 d_pal = FX_Alloc(FX_DWORD, 256); |
871 if (!d_pal) { | |
872 return FALSE; | |
873 } | |
874 if (((src_format & 0xff) == 1 || (src_format & 0xff) == 8) && pS
rcBitmap->GetPalette()) { | 862 if (((src_format & 0xff) == 1 || (src_format & 0xff) == 8) && pS
rcBitmap->GetPalette()) { |
875 return _ConvertBuffer_Plt2PltRgb8(dest_buf, dest_pitch, widt
h, height, pSrcBitmap, src_left, src_top, d_pal, pIccTransform); | 863 return _ConvertBuffer_Plt2PltRgb8(dest_buf, dest_pitch, widt
h, height, pSrcBitmap, src_left, src_top, d_pal, pIccTransform); |
876 } else if ((src_format & 0xff) >= 24) { | 864 } else if ((src_format & 0xff) >= 24) { |
877 return _ConvertBuffer_Rgb2PltRgb8(dest_buf, dest_pitch, widt
h, height, pSrcBitmap, src_left, src_top, d_pal, pIccTransform); | 865 return _ConvertBuffer_Rgb2PltRgb8(dest_buf, dest_pitch, widt
h, height, pSrcBitmap, src_left, src_top, d_pal, pIccTransform); |
878 } | 866 } |
879 return FALSE; | 867 return FALSE; |
880 } | 868 } |
881 case FXDIB_Rgb: | 869 case FXDIB_Rgb: |
882 case FXDIB_Rgba: { | 870 case FXDIB_Rgba: { |
883 if ((src_format & 0xff) == 1) { | 871 if ((src_format & 0xff) == 1) { |
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1071 if (!m_bExtBuf) { | 1059 if (!m_bExtBuf) { |
1072 FX_Free(m_pBuffer); | 1060 FX_Free(m_pBuffer); |
1073 } | 1061 } |
1074 m_bExtBuf = FALSE; | 1062 m_bExtBuf = FALSE; |
1075 m_pBuffer = dest_buf; | 1063 m_pBuffer = dest_buf; |
1076 m_bpp = (FX_BYTE)dest_format; | 1064 m_bpp = (FX_BYTE)dest_format; |
1077 m_AlphaFlag = (FX_BYTE)(dest_format >> 8); | 1065 m_AlphaFlag = (FX_BYTE)(dest_format >> 8); |
1078 m_Pitch = dest_pitch; | 1066 m_Pitch = dest_pitch; |
1079 return TRUE; | 1067 return TRUE; |
1080 } | 1068 } |
OLD | NEW |