| 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 406 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 980 } | 980 } |
| 981 if ((src_format & 0xff) >= 24) { | 981 if ((src_format & 0xff) >= 24) { |
| 982 return _ConvertBuffer_RgbOrCmyk2Gray(dest_buf, dest_pitch, width, | 982 return _ConvertBuffer_RgbOrCmyk2Gray(dest_buf, dest_pitch, width, |
| 983 height, pSrcBitmap, src_left, | 983 height, pSrcBitmap, src_left, |
| 984 src_top, pIccTransform); | 984 src_top, pIccTransform); |
| 985 } | 985 } |
| 986 return FALSE; | 986 return FALSE; |
| 987 } | 987 } |
| 988 case FXDIB_8bppRgb: | 988 case FXDIB_8bppRgb: |
| 989 case FXDIB_8bppRgba: { | 989 case FXDIB_8bppRgba: { |
| 990 if ((src_format & 0xff) == 8 && pSrcBitmap->GetPalette() == NULL) { | 990 if ((src_format & 0xff) == 8 && !pSrcBitmap->GetPalette()) { |
| 991 return ConvertBuffer(FXDIB_8bppMask, dest_buf, dest_pitch, width, | 991 return ConvertBuffer(FXDIB_8bppMask, dest_buf, dest_pitch, width, |
| 992 height, pSrcBitmap, src_left, src_top, d_pal, | 992 height, pSrcBitmap, src_left, src_top, d_pal, |
| 993 pIccTransform); | 993 pIccTransform); |
| 994 } | 994 } |
| 995 d_pal = FX_Alloc(FX_DWORD, 256); | 995 d_pal = FX_Alloc(FX_DWORD, 256); |
| 996 if (((src_format & 0xff) == 1 || (src_format & 0xff) == 8) && | 996 if (((src_format & 0xff) == 1 || (src_format & 0xff) == 8) && |
| 997 pSrcBitmap->GetPalette()) { | 997 pSrcBitmap->GetPalette()) { |
| 998 return _ConvertBuffer_Plt2PltRgb8(dest_buf, dest_pitch, width, height, | 998 return _ConvertBuffer_Plt2PltRgb8(dest_buf, dest_pitch, width, height, |
| 999 pSrcBitmap, src_left, src_top, d_pal, | 999 pSrcBitmap, src_left, src_top, d_pal, |
| 1000 pIccTransform); | 1000 pIccTransform); |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1075 return FALSE; | 1075 return FALSE; |
| 1076 } | 1076 } |
| 1077 default: | 1077 default: |
| 1078 return FALSE; | 1078 return FALSE; |
| 1079 } | 1079 } |
| 1080 return FALSE; | 1080 return FALSE; |
| 1081 } | 1081 } |
| 1082 CFX_DIBitmap* CFX_DIBSource::CloneConvert(FXDIB_Format dest_format, | 1082 CFX_DIBitmap* CFX_DIBSource::CloneConvert(FXDIB_Format dest_format, |
| 1083 const FX_RECT* pClip, | 1083 const FX_RECT* pClip, |
| 1084 void* pIccTransform) const { | 1084 void* pIccTransform) const { |
| 1085 if (dest_format == GetFormat() && pIccTransform == NULL) { | 1085 if (dest_format == GetFormat() && !pIccTransform) { |
| 1086 return Clone(pClip); | 1086 return Clone(pClip); |
| 1087 } | 1087 } |
| 1088 if (pClip) { | 1088 if (pClip) { |
| 1089 CFX_DIBitmap* pClone = Clone(pClip); | 1089 CFX_DIBitmap* pClone = Clone(pClip); |
| 1090 if (pClone == NULL) { | 1090 if (!pClone) { |
| 1091 return NULL; | 1091 return NULL; |
| 1092 } | 1092 } |
| 1093 if (!pClone->ConvertFormat(dest_format, pIccTransform)) { | 1093 if (!pClone->ConvertFormat(dest_format, pIccTransform)) { |
| 1094 delete pClone; | 1094 delete pClone; |
| 1095 return NULL; | 1095 return NULL; |
| 1096 } | 1096 } |
| 1097 return pClone; | 1097 return pClone; |
| 1098 } | 1098 } |
| 1099 CFX_DIBitmap* pClone = new CFX_DIBitmap; | 1099 CFX_DIBitmap* pClone = new CFX_DIBitmap; |
| 1100 if (!pClone->Create(m_Width, m_Height, dest_format)) { | 1100 if (!pClone->Create(m_Width, m_Height, dest_format)) { |
| 1101 delete pClone; | 1101 delete pClone; |
| 1102 return NULL; | 1102 return NULL; |
| 1103 } | 1103 } |
| 1104 FX_BOOL ret = TRUE; | 1104 FX_BOOL ret = TRUE; |
| 1105 CFX_DIBitmap* pSrcAlpha = NULL; | 1105 CFX_DIBitmap* pSrcAlpha = NULL; |
| 1106 if (HasAlpha()) { | 1106 if (HasAlpha()) { |
| 1107 pSrcAlpha = (GetFormat() == FXDIB_Argb) ? GetAlphaMask() : m_pAlphaMask; | 1107 pSrcAlpha = (GetFormat() == FXDIB_Argb) ? GetAlphaMask() : m_pAlphaMask; |
| 1108 if (pSrcAlpha == NULL) { | 1108 if (!pSrcAlpha) { |
| 1109 delete pClone; | 1109 delete pClone; |
| 1110 return NULL; | 1110 return NULL; |
| 1111 } | 1111 } |
| 1112 } | 1112 } |
| 1113 if (dest_format & 0x0200) { | 1113 if (dest_format & 0x0200) { |
| 1114 if (dest_format == FXDIB_Argb) | 1114 if (dest_format == FXDIB_Argb) |
| 1115 ret = pSrcAlpha ? pClone->LoadChannel(FXDIB_Alpha, pSrcAlpha, FXDIB_Alpha) | 1115 ret = pSrcAlpha ? pClone->LoadChannel(FXDIB_Alpha, pSrcAlpha, FXDIB_Alpha) |
| 1116 : pClone->LoadChannel(FXDIB_Alpha, 0xff); | 1116 : pClone->LoadChannel(FXDIB_Alpha, 0xff); |
| 1117 else { | 1117 else { |
| 1118 ret = pClone->CopyAlphaMask(pSrcAlpha); | 1118 ret = pClone->CopyAlphaMask(pSrcAlpha); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 1137 if (pal_8bpp) { | 1137 if (pal_8bpp) { |
| 1138 pClone->CopyPalette(pal_8bpp); | 1138 pClone->CopyPalette(pal_8bpp); |
| 1139 FX_Free(pal_8bpp); | 1139 FX_Free(pal_8bpp); |
| 1140 pal_8bpp = NULL; | 1140 pal_8bpp = NULL; |
| 1141 } | 1141 } |
| 1142 return pClone; | 1142 return pClone; |
| 1143 } | 1143 } |
| 1144 FX_BOOL CFX_DIBitmap::ConvertFormat(FXDIB_Format dest_format, | 1144 FX_BOOL CFX_DIBitmap::ConvertFormat(FXDIB_Format dest_format, |
| 1145 void* pIccTransform) { | 1145 void* pIccTransform) { |
| 1146 FXDIB_Format src_format = GetFormat(); | 1146 FXDIB_Format src_format = GetFormat(); |
| 1147 if (dest_format == src_format && pIccTransform == NULL) { | 1147 if (dest_format == src_format && !pIccTransform) { |
| 1148 return TRUE; | 1148 return TRUE; |
| 1149 } | 1149 } |
| 1150 if (dest_format == FXDIB_8bppMask && src_format == FXDIB_8bppRgb && | 1150 if (dest_format == FXDIB_8bppMask && src_format == FXDIB_8bppRgb && |
| 1151 m_pPalette == NULL) { | 1151 !m_pPalette) { |
| 1152 m_AlphaFlag = 1; | 1152 m_AlphaFlag = 1; |
| 1153 return TRUE; | 1153 return TRUE; |
| 1154 } | 1154 } |
| 1155 if (dest_format == FXDIB_Argb && src_format == FXDIB_Rgb32 && | 1155 if (dest_format == FXDIB_Argb && src_format == FXDIB_Rgb32 && |
| 1156 pIccTransform == NULL) { | 1156 !pIccTransform) { |
| 1157 m_AlphaFlag = 2; | 1157 m_AlphaFlag = 2; |
| 1158 for (int row = 0; row < m_Height; row++) { | 1158 for (int row = 0; row < m_Height; row++) { |
| 1159 uint8_t* scanline = m_pBuffer + row * m_Pitch + 3; | 1159 uint8_t* scanline = m_pBuffer + row * m_Pitch + 3; |
| 1160 for (int col = 0; col < m_Width; col++) { | 1160 for (int col = 0; col < m_Width; col++) { |
| 1161 *scanline = 0xff; | 1161 *scanline = 0xff; |
| 1162 scanline += 4; | 1162 scanline += 4; |
| 1163 } | 1163 } |
| 1164 } | 1164 } |
| 1165 return TRUE; | 1165 return TRUE; |
| 1166 } | 1166 } |
| 1167 int dest_bpp = dest_format & 0xff; | 1167 int dest_bpp = dest_format & 0xff; |
| 1168 int dest_pitch = (dest_bpp * m_Width + 31) / 32 * 4; | 1168 int dest_pitch = (dest_bpp * m_Width + 31) / 32 * 4; |
| 1169 uint8_t* dest_buf = FX_TryAlloc(uint8_t, dest_pitch * m_Height + 4); | 1169 uint8_t* dest_buf = FX_TryAlloc(uint8_t, dest_pitch * m_Height + 4); |
| 1170 if (dest_buf == NULL) { | 1170 if (!dest_buf) { |
| 1171 return FALSE; | 1171 return FALSE; |
| 1172 } | 1172 } |
| 1173 CFX_DIBitmap* pAlphaMask = NULL; | 1173 CFX_DIBitmap* pAlphaMask = NULL; |
| 1174 if (dest_format == FXDIB_Argb) { | 1174 if (dest_format == FXDIB_Argb) { |
| 1175 FXSYS_memset(dest_buf, 0xff, dest_pitch * m_Height + 4); | 1175 FXSYS_memset(dest_buf, 0xff, dest_pitch * m_Height + 4); |
| 1176 if (m_pAlphaMask) { | 1176 if (m_pAlphaMask) { |
| 1177 for (int row = 0; row < m_Height; row++) { | 1177 for (int row = 0; row < m_Height; row++) { |
| 1178 uint8_t* pDstScanline = dest_buf + row * dest_pitch + 3; | 1178 uint8_t* pDstScanline = dest_buf + row * dest_pitch + 3; |
| 1179 const uint8_t* pSrcScanline = m_pAlphaMask->GetScanline(row); | 1179 const uint8_t* pSrcScanline = m_pAlphaMask->GetScanline(row); |
| 1180 for (int col = 0; col < m_Width; col++) { | 1180 for (int col = 0; col < m_Width; col++) { |
| 1181 *pDstScanline = *pSrcScanline++; | 1181 *pDstScanline = *pSrcScanline++; |
| 1182 pDstScanline += 4; | 1182 pDstScanline += 4; |
| 1183 } | 1183 } |
| 1184 } | 1184 } |
| 1185 } | 1185 } |
| 1186 } else if (dest_format & 0x0200) { | 1186 } else if (dest_format & 0x0200) { |
| 1187 if (src_format == FXDIB_Argb) { | 1187 if (src_format == FXDIB_Argb) { |
| 1188 pAlphaMask = GetAlphaMask(); | 1188 pAlphaMask = GetAlphaMask(); |
| 1189 if (pAlphaMask == NULL) { | 1189 if (!pAlphaMask) { |
| 1190 FX_Free(dest_buf); | 1190 FX_Free(dest_buf); |
| 1191 return FALSE; | 1191 return FALSE; |
| 1192 } | 1192 } |
| 1193 } else { | 1193 } else { |
| 1194 if (m_pAlphaMask == NULL) { | 1194 if (!m_pAlphaMask) { |
| 1195 if (!BuildAlphaMask()) { | 1195 if (!BuildAlphaMask()) { |
| 1196 FX_Free(dest_buf); | 1196 FX_Free(dest_buf); |
| 1197 return FALSE; | 1197 return FALSE; |
| 1198 } | 1198 } |
| 1199 pAlphaMask = m_pAlphaMask; | 1199 pAlphaMask = m_pAlphaMask; |
| 1200 m_pAlphaMask = NULL; | 1200 m_pAlphaMask = NULL; |
| 1201 } else { | 1201 } else { |
| 1202 pAlphaMask = m_pAlphaMask; | 1202 pAlphaMask = m_pAlphaMask; |
| 1203 } | 1203 } |
| 1204 } | 1204 } |
| (...skipping 19 matching lines...) Expand all Loading... |
| 1224 if (!m_bExtBuf) { | 1224 if (!m_bExtBuf) { |
| 1225 FX_Free(m_pBuffer); | 1225 FX_Free(m_pBuffer); |
| 1226 } | 1226 } |
| 1227 m_bExtBuf = FALSE; | 1227 m_bExtBuf = FALSE; |
| 1228 m_pBuffer = dest_buf; | 1228 m_pBuffer = dest_buf; |
| 1229 m_bpp = (uint8_t)dest_format; | 1229 m_bpp = (uint8_t)dest_format; |
| 1230 m_AlphaFlag = (uint8_t)(dest_format >> 8); | 1230 m_AlphaFlag = (uint8_t)(dest_format >> 8); |
| 1231 m_Pitch = dest_pitch; | 1231 m_Pitch = dest_pitch; |
| 1232 return TRUE; | 1232 return TRUE; |
| 1233 } | 1233 } |
| OLD | NEW |