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 "core/include/fxcodec/fx_codec.h" | 7 #include "core/include/fxcodec/fx_codec.h" |
8 #include "core/include/fxge/fx_dib.h" | 8 #include "core/include/fxge/fx_dib.h" |
9 #include "core/include/fxge/fx_ge.h" | 9 #include "core/include/fxge/fx_ge.h" |
10 | 10 |
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
202 m_aLut = NULL; | 202 m_aLut = NULL; |
203 m_lut = 0; | 203 m_lut = 0; |
204 } | 204 } |
205 CFX_Palette::~CFX_Palette() { | 205 CFX_Palette::~CFX_Palette() { |
206 FX_Free(m_pPalette); | 206 FX_Free(m_pPalette); |
207 FX_Free(m_cLut); | 207 FX_Free(m_cLut); |
208 FX_Free(m_aLut); | 208 FX_Free(m_aLut); |
209 m_lut = 0; | 209 m_lut = 0; |
210 } | 210 } |
211 FX_BOOL CFX_Palette::BuildPalette(const CFX_DIBSource* pBitmap, int pal_type) { | 211 FX_BOOL CFX_Palette::BuildPalette(const CFX_DIBSource* pBitmap, int pal_type) { |
212 if (pBitmap == NULL) { | 212 if (!pBitmap) { |
213 return FALSE; | 213 return FALSE; |
214 } | 214 } |
215 FX_Free(m_pPalette); | 215 FX_Free(m_pPalette); |
216 m_pPalette = FX_Alloc(FX_DWORD, 256); | 216 m_pPalette = FX_Alloc(FX_DWORD, 256); |
217 int bpp = pBitmap->GetBPP() / 8; | 217 int bpp = pBitmap->GetBPP() / 8; |
218 int width = pBitmap->GetWidth(); | 218 int width = pBitmap->GetWidth(); |
219 int height = pBitmap->GetHeight(); | 219 int height = pBitmap->GetHeight(); |
220 FX_Free(m_cLut); | 220 FX_Free(m_cLut); |
221 m_cLut = NULL; | 221 m_cLut = NULL; |
222 FX_Free(m_aLut); | 222 FX_Free(m_aLut); |
(...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
553 const CFX_DIBSource* pSrcBitmap, | 553 const CFX_DIBSource* pSrcBitmap, |
554 int src_left, | 554 int src_left, |
555 int src_top, | 555 int src_top, |
556 FX_DWORD* dst_plt) { | 556 FX_DWORD* dst_plt) { |
557 int bpp = pSrcBitmap->GetBPP() / 8; | 557 int bpp = pSrcBitmap->GetBPP() / 8; |
558 int row, col; | 558 int row, col; |
559 CFX_Palette palette; | 559 CFX_Palette palette; |
560 palette.BuildPalette(pSrcBitmap, FXDIB_PALETTE_LOC); | 560 palette.BuildPalette(pSrcBitmap, FXDIB_PALETTE_LOC); |
561 FX_DWORD* cLut = palette.GetColorLut(); | 561 FX_DWORD* cLut = palette.GetColorLut(); |
562 FX_DWORD* aLut = palette.GetAmountLut(); | 562 FX_DWORD* aLut = palette.GetAmountLut(); |
563 if (cLut == NULL || aLut == NULL) { | 563 if (!cLut || !aLut) { |
564 return FALSE; | 564 return FALSE; |
565 } | 565 } |
566 int lut = palette.Getlut(); | 566 int lut = palette.Getlut(); |
567 FX_DWORD* pPalette = palette.GetPalette(); | 567 FX_DWORD* pPalette = palette.GetPalette(); |
568 if (lut > 256) { | 568 if (lut > 256) { |
569 int err, min_err; | 569 int err, min_err; |
570 int lut_256 = lut - 256; | 570 int lut_256 = lut - 256; |
571 for (row = 0; row < lut_256; row++) { | 571 for (row = 0; row < lut_256; row++) { |
572 min_err = 1000000; | 572 min_err = 1000000; |
573 uint8_t r, g, b; | 573 uint8_t r, g, b; |
(...skipping 400 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
974 } | 974 } |
975 if ((src_format & 0xff) >= 24) { | 975 if ((src_format & 0xff) >= 24) { |
976 return _ConvertBuffer_RgbOrCmyk2Gray(dest_buf, dest_pitch, width, | 976 return _ConvertBuffer_RgbOrCmyk2Gray(dest_buf, dest_pitch, width, |
977 height, pSrcBitmap, src_left, | 977 height, pSrcBitmap, src_left, |
978 src_top, pIccTransform); | 978 src_top, pIccTransform); |
979 } | 979 } |
980 return FALSE; | 980 return FALSE; |
981 } | 981 } |
982 case FXDIB_8bppRgb: | 982 case FXDIB_8bppRgb: |
983 case FXDIB_8bppRgba: { | 983 case FXDIB_8bppRgba: { |
984 if ((src_format & 0xff) == 8 && pSrcBitmap->GetPalette() == NULL) { | 984 if ((src_format & 0xff) == 8 && !pSrcBitmap->GetPalette()) { |
985 return ConvertBuffer(FXDIB_8bppMask, dest_buf, dest_pitch, width, | 985 return ConvertBuffer(FXDIB_8bppMask, dest_buf, dest_pitch, width, |
986 height, pSrcBitmap, src_left, src_top, d_pal, | 986 height, pSrcBitmap, src_left, src_top, d_pal, |
987 pIccTransform); | 987 pIccTransform); |
988 } | 988 } |
989 d_pal = FX_Alloc(FX_DWORD, 256); | 989 d_pal = FX_Alloc(FX_DWORD, 256); |
990 if (((src_format & 0xff) == 1 || (src_format & 0xff) == 8) && | 990 if (((src_format & 0xff) == 1 || (src_format & 0xff) == 8) && |
991 pSrcBitmap->GetPalette()) { | 991 pSrcBitmap->GetPalette()) { |
992 return _ConvertBuffer_Plt2PltRgb8(dest_buf, dest_pitch, width, height, | 992 return _ConvertBuffer_Plt2PltRgb8(dest_buf, dest_pitch, width, height, |
993 pSrcBitmap, src_left, src_top, d_pal, | 993 pSrcBitmap, src_left, src_top, d_pal, |
994 pIccTransform); | 994 pIccTransform); |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1069 return FALSE; | 1069 return FALSE; |
1070 } | 1070 } |
1071 default: | 1071 default: |
1072 return FALSE; | 1072 return FALSE; |
1073 } | 1073 } |
1074 return FALSE; | 1074 return FALSE; |
1075 } | 1075 } |
1076 CFX_DIBitmap* CFX_DIBSource::CloneConvert(FXDIB_Format dest_format, | 1076 CFX_DIBitmap* CFX_DIBSource::CloneConvert(FXDIB_Format dest_format, |
1077 const FX_RECT* pClip, | 1077 const FX_RECT* pClip, |
1078 void* pIccTransform) const { | 1078 void* pIccTransform) const { |
1079 if (dest_format == GetFormat() && pIccTransform == NULL) { | 1079 if (dest_format == GetFormat() && !pIccTransform) { |
1080 return Clone(pClip); | 1080 return Clone(pClip); |
1081 } | 1081 } |
1082 if (pClip) { | 1082 if (pClip) { |
1083 CFX_DIBitmap* pClone = Clone(pClip); | 1083 CFX_DIBitmap* pClone = Clone(pClip); |
1084 if (pClone == NULL) { | 1084 if (!pClone) { |
1085 return NULL; | 1085 return NULL; |
1086 } | 1086 } |
1087 if (!pClone->ConvertFormat(dest_format, pIccTransform)) { | 1087 if (!pClone->ConvertFormat(dest_format, pIccTransform)) { |
1088 delete pClone; | 1088 delete pClone; |
1089 return NULL; | 1089 return NULL; |
1090 } | 1090 } |
1091 return pClone; | 1091 return pClone; |
1092 } | 1092 } |
1093 CFX_DIBitmap* pClone = new CFX_DIBitmap; | 1093 CFX_DIBitmap* pClone = new CFX_DIBitmap; |
1094 if (!pClone->Create(m_Width, m_Height, dest_format)) { | 1094 if (!pClone->Create(m_Width, m_Height, dest_format)) { |
1095 delete pClone; | 1095 delete pClone; |
1096 return NULL; | 1096 return NULL; |
1097 } | 1097 } |
1098 FX_BOOL ret = TRUE; | 1098 FX_BOOL ret = TRUE; |
1099 CFX_DIBitmap* pSrcAlpha = NULL; | 1099 CFX_DIBitmap* pSrcAlpha = NULL; |
1100 if (HasAlpha()) { | 1100 if (HasAlpha()) { |
1101 pSrcAlpha = (GetFormat() == FXDIB_Argb) ? GetAlphaMask() : m_pAlphaMask; | 1101 pSrcAlpha = (GetFormat() == FXDIB_Argb) ? GetAlphaMask() : m_pAlphaMask; |
1102 if (pSrcAlpha == NULL) { | 1102 if (!pSrcAlpha) { |
1103 delete pClone; | 1103 delete pClone; |
1104 return NULL; | 1104 return NULL; |
1105 } | 1105 } |
1106 } | 1106 } |
1107 if (dest_format & 0x0200) { | 1107 if (dest_format & 0x0200) { |
1108 if (dest_format == FXDIB_Argb) | 1108 if (dest_format == FXDIB_Argb) |
1109 ret = pSrcAlpha ? pClone->LoadChannel(FXDIB_Alpha, pSrcAlpha, FXDIB_Alpha) | 1109 ret = pSrcAlpha ? pClone->LoadChannel(FXDIB_Alpha, pSrcAlpha, FXDIB_Alpha) |
1110 : pClone->LoadChannel(FXDIB_Alpha, 0xff); | 1110 : pClone->LoadChannel(FXDIB_Alpha, 0xff); |
1111 else { | 1111 else { |
1112 ret = pClone->CopyAlphaMask(pSrcAlpha); | 1112 ret = pClone->CopyAlphaMask(pSrcAlpha); |
(...skipping 18 matching lines...) Expand all Loading... |
1131 if (pal_8bpp) { | 1131 if (pal_8bpp) { |
1132 pClone->CopyPalette(pal_8bpp); | 1132 pClone->CopyPalette(pal_8bpp); |
1133 FX_Free(pal_8bpp); | 1133 FX_Free(pal_8bpp); |
1134 pal_8bpp = NULL; | 1134 pal_8bpp = NULL; |
1135 } | 1135 } |
1136 return pClone; | 1136 return pClone; |
1137 } | 1137 } |
1138 FX_BOOL CFX_DIBitmap::ConvertFormat(FXDIB_Format dest_format, | 1138 FX_BOOL CFX_DIBitmap::ConvertFormat(FXDIB_Format dest_format, |
1139 void* pIccTransform) { | 1139 void* pIccTransform) { |
1140 FXDIB_Format src_format = GetFormat(); | 1140 FXDIB_Format src_format = GetFormat(); |
1141 if (dest_format == src_format && pIccTransform == NULL) { | 1141 if (dest_format == src_format && !pIccTransform) { |
1142 return TRUE; | 1142 return TRUE; |
1143 } | 1143 } |
1144 if (dest_format == FXDIB_8bppMask && src_format == FXDIB_8bppRgb && | 1144 if (dest_format == FXDIB_8bppMask && src_format == FXDIB_8bppRgb && |
1145 m_pPalette == NULL) { | 1145 !m_pPalette) { |
1146 m_AlphaFlag = 1; | 1146 m_AlphaFlag = 1; |
1147 return TRUE; | 1147 return TRUE; |
1148 } | 1148 } |
1149 if (dest_format == FXDIB_Argb && src_format == FXDIB_Rgb32 && | 1149 if (dest_format == FXDIB_Argb && src_format == FXDIB_Rgb32 && |
1150 pIccTransform == NULL) { | 1150 !pIccTransform) { |
1151 m_AlphaFlag = 2; | 1151 m_AlphaFlag = 2; |
1152 for (int row = 0; row < m_Height; row++) { | 1152 for (int row = 0; row < m_Height; row++) { |
1153 uint8_t* scanline = m_pBuffer + row * m_Pitch + 3; | 1153 uint8_t* scanline = m_pBuffer + row * m_Pitch + 3; |
1154 for (int col = 0; col < m_Width; col++) { | 1154 for (int col = 0; col < m_Width; col++) { |
1155 *scanline = 0xff; | 1155 *scanline = 0xff; |
1156 scanline += 4; | 1156 scanline += 4; |
1157 } | 1157 } |
1158 } | 1158 } |
1159 return TRUE; | 1159 return TRUE; |
1160 } | 1160 } |
1161 int dest_bpp = dest_format & 0xff; | 1161 int dest_bpp = dest_format & 0xff; |
1162 int dest_pitch = (dest_bpp * m_Width + 31) / 32 * 4; | 1162 int dest_pitch = (dest_bpp * m_Width + 31) / 32 * 4; |
1163 uint8_t* dest_buf = FX_TryAlloc(uint8_t, dest_pitch * m_Height + 4); | 1163 uint8_t* dest_buf = FX_TryAlloc(uint8_t, dest_pitch * m_Height + 4); |
1164 if (dest_buf == NULL) { | 1164 if (!dest_buf) { |
1165 return FALSE; | 1165 return FALSE; |
1166 } | 1166 } |
1167 CFX_DIBitmap* pAlphaMask = NULL; | 1167 CFX_DIBitmap* pAlphaMask = NULL; |
1168 if (dest_format == FXDIB_Argb) { | 1168 if (dest_format == FXDIB_Argb) { |
1169 FXSYS_memset(dest_buf, 0xff, dest_pitch * m_Height + 4); | 1169 FXSYS_memset(dest_buf, 0xff, dest_pitch * m_Height + 4); |
1170 if (m_pAlphaMask) { | 1170 if (m_pAlphaMask) { |
1171 for (int row = 0; row < m_Height; row++) { | 1171 for (int row = 0; row < m_Height; row++) { |
1172 uint8_t* pDstScanline = dest_buf + row * dest_pitch + 3; | 1172 uint8_t* pDstScanline = dest_buf + row * dest_pitch + 3; |
1173 const uint8_t* pSrcScanline = m_pAlphaMask->GetScanline(row); | 1173 const uint8_t* pSrcScanline = m_pAlphaMask->GetScanline(row); |
1174 for (int col = 0; col < m_Width; col++) { | 1174 for (int col = 0; col < m_Width; col++) { |
1175 *pDstScanline = *pSrcScanline++; | 1175 *pDstScanline = *pSrcScanline++; |
1176 pDstScanline += 4; | 1176 pDstScanline += 4; |
1177 } | 1177 } |
1178 } | 1178 } |
1179 } | 1179 } |
1180 } else if (dest_format & 0x0200) { | 1180 } else if (dest_format & 0x0200) { |
1181 if (src_format == FXDIB_Argb) { | 1181 if (src_format == FXDIB_Argb) { |
1182 pAlphaMask = GetAlphaMask(); | 1182 pAlphaMask = GetAlphaMask(); |
1183 if (pAlphaMask == NULL) { | 1183 if (!pAlphaMask) { |
1184 FX_Free(dest_buf); | 1184 FX_Free(dest_buf); |
1185 return FALSE; | 1185 return FALSE; |
1186 } | 1186 } |
1187 } else { | 1187 } else { |
1188 if (m_pAlphaMask == NULL) { | 1188 if (!m_pAlphaMask) { |
1189 if (!BuildAlphaMask()) { | 1189 if (!BuildAlphaMask()) { |
1190 FX_Free(dest_buf); | 1190 FX_Free(dest_buf); |
1191 return FALSE; | 1191 return FALSE; |
1192 } | 1192 } |
1193 pAlphaMask = m_pAlphaMask; | 1193 pAlphaMask = m_pAlphaMask; |
1194 m_pAlphaMask = NULL; | 1194 m_pAlphaMask = NULL; |
1195 } else { | 1195 } else { |
1196 pAlphaMask = m_pAlphaMask; | 1196 pAlphaMask = m_pAlphaMask; |
1197 } | 1197 } |
1198 } | 1198 } |
(...skipping 19 matching lines...) Expand all Loading... |
1218 if (!m_bExtBuf) { | 1218 if (!m_bExtBuf) { |
1219 FX_Free(m_pBuffer); | 1219 FX_Free(m_pBuffer); |
1220 } | 1220 } |
1221 m_bExtBuf = FALSE; | 1221 m_bExtBuf = FALSE; |
1222 m_pBuffer = dest_buf; | 1222 m_pBuffer = dest_buf; |
1223 m_bpp = (uint8_t)dest_format; | 1223 m_bpp = (uint8_t)dest_format; |
1224 m_AlphaFlag = (uint8_t)(dest_format >> 8); | 1224 m_AlphaFlag = (uint8_t)(dest_format >> 8); |
1225 m_Pitch = dest_pitch; | 1225 m_Pitch = dest_pitch; |
1226 return TRUE; | 1226 return TRUE; |
1227 } | 1227 } |
OLD | NEW |