| 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 #include "dib_int.h" | 10 #include "dib_int.h" |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 CFX_DIBitmap::CFX_DIBitmap() | 55 CFX_DIBitmap::CFX_DIBitmap() |
| 56 { | 56 { |
| 57 m_bExtBuf = FALSE; | 57 m_bExtBuf = FALSE; |
| 58 m_pBuffer = NULL; | 58 m_pBuffer = NULL; |
| 59 m_pPalette = NULL; | 59 m_pPalette = NULL; |
| 60 } | 60 } |
| 61 #define _MAX_OOM_LIMIT_ 12000000 | 61 #define _MAX_OOM_LIMIT_ 12000000 |
| 62 FX_BOOL CFX_DIBitmap::Create(int width, int height, FXDIB_Format format, FX_LPBY
TE pBuffer, int pitch) | 62 FX_BOOL CFX_DIBitmap::Create(int width, int height, FXDIB_Format format, FX_LPBY
TE pBuffer, int pitch) |
| 63 { | 63 { |
| 64 m_pBuffer = NULL; | 64 m_pBuffer = NULL; |
| 65 m_bpp = (FX_BYTE)format; | 65 m_bpp = (uint8_t)format; |
| 66 m_AlphaFlag = (FX_BYTE)(format >> 8); | 66 m_AlphaFlag = (uint8_t)(format >> 8); |
| 67 m_Width = m_Height = m_Pitch = 0; | 67 m_Width = m_Height = m_Pitch = 0; |
| 68 if (width <= 0 || height <= 0 || pitch < 0) { | 68 if (width <= 0 || height <= 0 || pitch < 0) { |
| 69 return FALSE; | 69 return FALSE; |
| 70 } | 70 } |
| 71 if ((INT_MAX - 31) / width < (format & 0xff)) { | 71 if ((INT_MAX - 31) / width < (format & 0xff)) { |
| 72 return FALSE; | 72 return FALSE; |
| 73 } | 73 } |
| 74 if (!pitch) { | 74 if (!pitch) { |
| 75 pitch = (width * (format & 0xff) + 31) / 32 * 4; | 75 pitch = (width * (format & 0xff) + 31) / 32 * 4; |
| 76 } | 76 } |
| 77 if ((1 << 30) / pitch < height) { | 77 if ((1 << 30) / pitch < height) { |
| 78 return FALSE; | 78 return FALSE; |
| 79 } | 79 } |
| 80 if (pBuffer) { | 80 if (pBuffer) { |
| 81 m_pBuffer = pBuffer; | 81 m_pBuffer = pBuffer; |
| 82 m_bExtBuf = TRUE; | 82 m_bExtBuf = TRUE; |
| 83 } else { | 83 } else { |
| 84 int size = pitch * height + 4; | 84 int size = pitch * height + 4; |
| 85 int oomlimit = _MAX_OOM_LIMIT_; | 85 int oomlimit = _MAX_OOM_LIMIT_; |
| 86 if (oomlimit >= 0 && size >= oomlimit) { | 86 if (oomlimit >= 0 && size >= oomlimit) { |
| 87 m_pBuffer = FX_TryAlloc(FX_BYTE, size); | 87 m_pBuffer = FX_TryAlloc(uint8_t, size); |
| 88 if (m_pBuffer == NULL) { | 88 if (m_pBuffer == NULL) { |
| 89 return FALSE; | 89 return FALSE; |
| 90 } | 90 } |
| 91 } else { | 91 } else { |
| 92 m_pBuffer = FX_Alloc(FX_BYTE, size); | 92 m_pBuffer = FX_Alloc(uint8_t, size); |
| 93 } | 93 } |
| 94 } | 94 } |
| 95 m_Width = width; | 95 m_Width = width; |
| 96 m_Height = height; | 96 m_Height = height; |
| 97 m_Pitch = pitch; | 97 m_Pitch = pitch; |
| 98 if (HasAlpha() && format != FXDIB_Argb) { | 98 if (HasAlpha() && format != FXDIB_Argb) { |
| 99 FX_BOOL ret = TRUE; | 99 FX_BOOL ret = TRUE; |
| 100 ret = BuildAlphaMask(); | 100 ret = BuildAlphaMask(); |
| 101 if (!ret) { | 101 if (!ret) { |
| 102 if (!m_bExtBuf && m_pBuffer) { | 102 if (!m_bExtBuf && m_pBuffer) { |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 260 BuildPalette(); | 260 BuildPalette(); |
| 261 } | 261 } |
| 262 m_pPalette[index] = color; | 262 m_pPalette[index] = color; |
| 263 } | 263 } |
| 264 int CFX_DIBSource::FindPalette(FX_DWORD color) const | 264 int CFX_DIBSource::FindPalette(FX_DWORD color) const |
| 265 { | 265 { |
| 266 ASSERT((GetBPP() == 1 || GetBPP() == 8) && !IsAlphaMask()); | 266 ASSERT((GetBPP() == 1 || GetBPP() == 8) && !IsAlphaMask()); |
| 267 if (m_pPalette == NULL) { | 267 if (m_pPalette == NULL) { |
| 268 if (IsCmykImage()) { | 268 if (IsCmykImage()) { |
| 269 if (GetBPP() == 1) { | 269 if (GetBPP() == 1) { |
| 270 return ((FX_BYTE)color == 0xff) ? 0 : 1; | 270 return ((uint8_t)color == 0xff) ? 0 : 1; |
| 271 } | 271 } |
| 272 return 0xff - (FX_BYTE)color; | 272 return 0xff - (uint8_t)color; |
| 273 } | 273 } |
| 274 if (GetBPP() == 1) { | 274 if (GetBPP() == 1) { |
| 275 return ((FX_BYTE)color == 0xff) ? 1 : 0; | 275 return ((uint8_t)color == 0xff) ? 1 : 0; |
| 276 } | 276 } |
| 277 return (FX_BYTE)color; | 277 return (uint8_t)color; |
| 278 } | 278 } |
| 279 int palsize = (1 << GetBPP()); | 279 int palsize = (1 << GetBPP()); |
| 280 for (int i = 0; i < palsize; i ++) | 280 for (int i = 0; i < palsize; i ++) |
| 281 if (m_pPalette[i] == color) { | 281 if (m_pPalette[i] == color) { |
| 282 return i; | 282 return i; |
| 283 } | 283 } |
| 284 return -1; | 284 return -1; |
| 285 } | 285 } |
| 286 void CFX_DIBitmap::Clear(FX_DWORD color) | 286 void CFX_DIBitmap::Clear(FX_DWORD color) |
| 287 { | 287 { |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 450 pIccModule->TranslateScanline(pIccTransform, color_p, color_p, 1); | 450 pIccModule->TranslateScanline(pIccTransform, color_p, color_p, 1); |
| 451 } else { | 451 } else { |
| 452 if (alpha_flag >> 8 && !IsCmykImage()) | 452 if (alpha_flag >> 8 && !IsCmykImage()) |
| 453 AdobeCMYK_to_sRGB1(FXSYS_GetCValue(color), FXSYS_GetMValue(color), F
XSYS_GetYValue(color), FXSYS_GetKValue(color), | 453 AdobeCMYK_to_sRGB1(FXSYS_GetCValue(color), FXSYS_GetMValue(color), F
XSYS_GetYValue(color), FXSYS_GetKValue(color), |
| 454 color_p[2], color_p[1], color_p[0]); | 454 color_p[2], color_p[1], color_p[0]); |
| 455 else if (!(alpha_flag >> 8) && IsCmykImage()) { | 455 else if (!(alpha_flag >> 8) && IsCmykImage()) { |
| 456 return FALSE; | 456 return FALSE; |
| 457 } | 457 } |
| 458 } | 458 } |
| 459 if(!IsCmykImage()) { | 459 if(!IsCmykImage()) { |
| 460 color_p[3] = (FX_BYTE)alpha; | 460 color_p[3] = (uint8_t)alpha; |
| 461 } | 461 } |
| 462 if (GetFormat() == FXDIB_Argb) { | 462 if (GetFormat() == FXDIB_Argb) { |
| 463 for (int row = 0; row < height; row ++) { | 463 for (int row = 0; row < height; row ++) { |
| 464 FX_DWORD* dest_pos = (FX_DWORD*)(m_pBuffer + (dest_top + row) * m_Pi
tch + dest_left * 4); | 464 FX_DWORD* dest_pos = (FX_DWORD*)(m_pBuffer + (dest_top + row) * m_Pi
tch + dest_left * 4); |
| 465 FX_LPCBYTE src_scan = pMask->GetScanline(src_top + row); | 465 FX_LPCBYTE src_scan = pMask->GetScanline(src_top + row); |
| 466 if (src_bpp == 1) { | 466 if (src_bpp == 1) { |
| 467 for (int col = 0; col < width; col ++) { | 467 for (int col = 0; col < width; col ++) { |
| 468 int src_bitpos = src_left + col; | 468 int src_bitpos = src_left + col; |
| 469 if (src_scan[src_bitpos / 8] & (1 << (7 - src_bitpos % 8)))
{ | 469 if (src_scan[src_bitpos / 8] & (1 << (7 - src_bitpos % 8)))
{ |
| 470 *dest_pos = dst_color; | 470 *dest_pos = dst_color; |
| (...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 870 FX_BOOL CFX_DIBitmap::GetGrayData(void* pIccTransform) | 870 FX_BOOL CFX_DIBitmap::GetGrayData(void* pIccTransform) |
| 871 { | 871 { |
| 872 if (m_pBuffer == NULL) { | 872 if (m_pBuffer == NULL) { |
| 873 return FALSE; | 873 return FALSE; |
| 874 } | 874 } |
| 875 switch (GetFormat()) { | 875 switch (GetFormat()) { |
| 876 case FXDIB_1bppRgb: { | 876 case FXDIB_1bppRgb: { |
| 877 if (m_pPalette == NULL) { | 877 if (m_pPalette == NULL) { |
| 878 return FALSE; | 878 return FALSE; |
| 879 } | 879 } |
| 880 FX_BYTE gray[2]; | 880 uint8_t gray[2]; |
| 881 for (int i = 0; i < 2; i ++) { | 881 for (int i = 0; i < 2; i ++) { |
| 882 int r = (FX_BYTE)(m_pPalette[i] >> 16); | 882 int r = (uint8_t)(m_pPalette[i] >> 16); |
| 883 int g = (FX_BYTE)(m_pPalette[i] >> 8); | 883 int g = (uint8_t)(m_pPalette[i] >> 8); |
| 884 int b = (FX_BYTE)m_pPalette[i]; | 884 int b = (uint8_t)m_pPalette[i]; |
| 885 gray[i] = (FX_BYTE)FXRGB2GRAY(r, g, b); | 885 gray[i] = (uint8_t)FXRGB2GRAY(r, g, b); |
| 886 } | 886 } |
| 887 CFX_DIBitmap* pMask = new CFX_DIBitmap; | 887 CFX_DIBitmap* pMask = new CFX_DIBitmap; |
| 888 if (!pMask->Create(m_Width, m_Height, FXDIB_8bppMask)) { | 888 if (!pMask->Create(m_Width, m_Height, FXDIB_8bppMask)) { |
| 889 delete pMask; | 889 delete pMask; |
| 890 return FALSE; | 890 return FALSE; |
| 891 } | 891 } |
| 892 FXSYS_memset8(pMask->GetBuffer(), gray[0], pMask->GetPitch() * m
_Height); | 892 FXSYS_memset8(pMask->GetBuffer(), gray[0], pMask->GetPitch() * m
_Height); |
| 893 for (int row = 0; row < m_Height; row ++) { | 893 for (int row = 0; row < m_Height; row ++) { |
| 894 FX_LPBYTE src_pos = m_pBuffer + row * m_Pitch; | 894 FX_LPBYTE src_pos = m_pBuffer + row * m_Pitch; |
| 895 FX_LPBYTE dest_pos = (FX_LPBYTE)pMask->GetScanline(row); | 895 FX_LPBYTE dest_pos = (FX_LPBYTE)pMask->GetScanline(row); |
| 896 for (int col = 0; col < m_Width; col ++) { | 896 for (int col = 0; col < m_Width; col ++) { |
| 897 if (src_pos[col / 8] & (1 << (7 - col % 8))) { | 897 if (src_pos[col / 8] & (1 << (7 - col % 8))) { |
| 898 *dest_pos = gray[1]; | 898 *dest_pos = gray[1]; |
| 899 } | 899 } |
| 900 dest_pos ++; | 900 dest_pos ++; |
| 901 } | 901 } |
| 902 } | 902 } |
| 903 TakeOver(pMask); | 903 TakeOver(pMask); |
| 904 delete pMask; | 904 delete pMask; |
| 905 break; | 905 break; |
| 906 } | 906 } |
| 907 case FXDIB_8bppRgb: { | 907 case FXDIB_8bppRgb: { |
| 908 if (m_pPalette == NULL) { | 908 if (m_pPalette == NULL) { |
| 909 return FALSE; | 909 return FALSE; |
| 910 } | 910 } |
| 911 FX_BYTE gray[256]; | 911 uint8_t gray[256]; |
| 912 for (int i = 0; i < 256; i ++) { | 912 for (int i = 0; i < 256; i ++) { |
| 913 int r = (FX_BYTE)(m_pPalette[i] >> 16); | 913 int r = (uint8_t)(m_pPalette[i] >> 16); |
| 914 int g = (FX_BYTE)(m_pPalette[i] >> 8); | 914 int g = (uint8_t)(m_pPalette[i] >> 8); |
| 915 int b = (FX_BYTE)m_pPalette[i]; | 915 int b = (uint8_t)m_pPalette[i]; |
| 916 gray[i] = (FX_BYTE)FXRGB2GRAY(r, g, b); | 916 gray[i] = (uint8_t)FXRGB2GRAY(r, g, b); |
| 917 } | 917 } |
| 918 CFX_DIBitmap* pMask = new CFX_DIBitmap; | 918 CFX_DIBitmap* pMask = new CFX_DIBitmap; |
| 919 if (!pMask->Create(m_Width, m_Height, FXDIB_8bppMask)) { | 919 if (!pMask->Create(m_Width, m_Height, FXDIB_8bppMask)) { |
| 920 delete pMask; | 920 delete pMask; |
| 921 return FALSE; | 921 return FALSE; |
| 922 } | 922 } |
| 923 for (int row = 0; row < m_Height; row ++) { | 923 for (int row = 0; row < m_Height; row ++) { |
| 924 FX_LPBYTE dest_pos = pMask->GetBuffer() + row * pMask->GetPi
tch(); | 924 FX_LPBYTE dest_pos = pMask->GetBuffer() + row * pMask->GetPi
tch(); |
| 925 FX_LPBYTE src_pos = m_pBuffer + row * m_Pitch; | 925 FX_LPBYTE src_pos = m_pBuffer + row * m_Pitch; |
| 926 for (int col = 0; col < m_Width; col ++) { | 926 for (int col = 0; col < m_Width; col ++) { |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1083 } | 1083 } |
| 1084 } else { | 1084 } else { |
| 1085 if (color == 0xffffffff) { | 1085 if (color == 0xffffffff) { |
| 1086 *pos |= 1 << (7 - x % 8); | 1086 *pos |= 1 << (7 - x % 8); |
| 1087 } else { | 1087 } else { |
| 1088 *pos &= ~(1 << (7 - x % 8)); | 1088 *pos &= ~(1 << (7 - x % 8)); |
| 1089 } | 1089 } |
| 1090 } | 1090 } |
| 1091 break; | 1091 break; |
| 1092 case FXDIB_8bppMask: | 1092 case FXDIB_8bppMask: |
| 1093 *pos = (FX_BYTE)(color >> 24); | 1093 *pos = (uint8_t)(color >> 24); |
| 1094 break; | 1094 break; |
| 1095 case FXDIB_8bppRgb: { | 1095 case FXDIB_8bppRgb: { |
| 1096 if (m_pPalette) { | 1096 if (m_pPalette) { |
| 1097 for (int i = 0; i < 256; i ++) { | 1097 for (int i = 0; i < 256; i ++) { |
| 1098 if (m_pPalette[i] == color) { | 1098 if (m_pPalette[i] == color) { |
| 1099 *pos = (FX_BYTE)i; | 1099 *pos = (uint8_t)i; |
| 1100 return; | 1100 return; |
| 1101 } | 1101 } |
| 1102 } | 1102 } |
| 1103 *pos = 0; | 1103 *pos = 0; |
| 1104 } else { | 1104 } else { |
| 1105 *pos = FXRGB2GRAY(FXARGB_R(color), FXARGB_G(color), FXARGB_B
(color)); | 1105 *pos = FXRGB2GRAY(FXARGB_R(color), FXARGB_G(color), FXARGB_B
(color)); |
| 1106 } | 1106 } |
| 1107 break; | 1107 break; |
| 1108 } | 1108 } |
| 1109 case FXDIB_Rgb: | 1109 case FXDIB_Rgb: |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1218 } | 1218 } |
| 1219 } else if (forecolor == 0 && backcolor == 0xffffff && m_pPalette == NULL
) { | 1219 } else if (forecolor == 0 && backcolor == 0xffffff && m_pPalette == NULL
) { |
| 1220 return TRUE; | 1220 return TRUE; |
| 1221 } | 1221 } |
| 1222 if (m_pPalette == NULL) { | 1222 if (m_pPalette == NULL) { |
| 1223 BuildPalette(); | 1223 BuildPalette(); |
| 1224 } | 1224 } |
| 1225 int size = 1 << m_bpp; | 1225 int size = 1 << m_bpp; |
| 1226 if (isCmykImage) { | 1226 if (isCmykImage) { |
| 1227 for (int i = 0; i < size; i ++) { | 1227 for (int i = 0; i < size; i ++) { |
| 1228 FX_BYTE b, g, r; | 1228 uint8_t b, g, r; |
| 1229 AdobeCMYK_to_sRGB1(FXSYS_GetCValue(m_pPalette[i]), FXSYS_GetMVal
ue(m_pPalette[i]), FXSYS_GetYValue(m_pPalette[i]), FXSYS_GetKValue(m_pPalette[i]
), | 1229 AdobeCMYK_to_sRGB1(FXSYS_GetCValue(m_pPalette[i]), FXSYS_GetMVal
ue(m_pPalette[i]), FXSYS_GetYValue(m_pPalette[i]), FXSYS_GetKValue(m_pPalette[i]
), |
| 1230 r, g, b); | 1230 r, g, b); |
| 1231 int gray = 255 - FXRGB2GRAY(r, g, b); | 1231 int gray = 255 - FXRGB2GRAY(r, g, b); |
| 1232 m_pPalette[i] = CmykEncode(bc + (fc - bc) * gray / 255, bm + (fm
- bm) * gray / 255, | 1232 m_pPalette[i] = CmykEncode(bc + (fc - bc) * gray / 255, bm + (fm
- bm) * gray / 255, |
| 1233 by + (fy - by) * gray / 255, bk + (fk
- bk) * gray / 255); | 1233 by + (fy - by) * gray / 255, bk + (fk
- bk) * gray / 255); |
| 1234 } | 1234 } |
| 1235 } else | 1235 } else |
| 1236 for (int i = 0; i < size; i ++) { | 1236 for (int i = 0; i < size; i ++) { |
| 1237 int gray = FXRGB2GRAY(FXARGB_R(m_pPalette[i]), FXARGB_G(m_pPalet
te[i]), FXARGB_B(m_pPalette[i])); | 1237 int gray = FXRGB2GRAY(FXARGB_R(m_pPalette[i]), FXARGB_G(m_pPalet
te[i]), FXARGB_B(m_pPalette[i])); |
| 1238 m_pPalette[i] = FXARGB_MAKE(0xff, br + (fr - br) * gray / 255, b
g + (fg - bg) * gray / 255, | 1238 m_pPalette[i] = FXARGB_MAKE(0xff, br + (fr - br) * gray / 255, b
g + (fg - bg) * gray / 255, |
| 1239 bb + (fb - bb) * gray / 255); | 1239 bb + (fb - bb) * gray / 255); |
| 1240 } | 1240 } |
| 1241 return TRUE; | 1241 return TRUE; |
| 1242 } | 1242 } |
| 1243 if (isCmykImage) { | 1243 if (isCmykImage) { |
| 1244 if (forecolor == 0xff && backcolor == 0x00) { | 1244 if (forecolor == 0xff && backcolor == 0x00) { |
| 1245 for (int row = 0; row < m_Height; row ++) { | 1245 for (int row = 0; row < m_Height; row ++) { |
| 1246 FX_LPBYTE scanline = m_pBuffer + row * m_Pitch; | 1246 FX_LPBYTE scanline = m_pBuffer + row * m_Pitch; |
| 1247 for (int col = 0; col < m_Width; col ++) { | 1247 for (int col = 0; col < m_Width; col ++) { |
| 1248 FX_BYTE b, g, r; | 1248 uint8_t b, g, r; |
| 1249 AdobeCMYK_to_sRGB1(scanline[0], scanline[1], scanline[2], sc
anline[3], | 1249 AdobeCMYK_to_sRGB1(scanline[0], scanline[1], scanline[2], sc
anline[3], |
| 1250 r, g, b); | 1250 r, g, b); |
| 1251 *scanline ++ = 0; | 1251 *scanline ++ = 0; |
| 1252 *scanline ++ = 0; | 1252 *scanline ++ = 0; |
| 1253 *scanline ++ = 0; | 1253 *scanline ++ = 0; |
| 1254 *scanline ++ = 255 - FXRGB2GRAY(r, g, b); | 1254 *scanline ++ = 255 - FXRGB2GRAY(r, g, b); |
| 1255 } | 1255 } |
| 1256 } | 1256 } |
| 1257 return TRUE; | 1257 return TRUE; |
| 1258 } | 1258 } |
| 1259 } else if (forecolor == 0 && backcolor == 0xffffff) { | 1259 } else if (forecolor == 0 && backcolor == 0xffffff) { |
| 1260 for (int row = 0; row < m_Height; row ++) { | 1260 for (int row = 0; row < m_Height; row ++) { |
| 1261 FX_LPBYTE scanline = m_pBuffer + row * m_Pitch; | 1261 FX_LPBYTE scanline = m_pBuffer + row * m_Pitch; |
| 1262 int gap = m_bpp / 8 - 2; | 1262 int gap = m_bpp / 8 - 2; |
| 1263 for (int col = 0; col < m_Width; col ++) { | 1263 for (int col = 0; col < m_Width; col ++) { |
| 1264 int gray = FXRGB2GRAY(scanline[2], scanline[1], scanline[0]); | 1264 int gray = FXRGB2GRAY(scanline[2], scanline[1], scanline[0]); |
| 1265 *scanline ++ = gray; | 1265 *scanline ++ = gray; |
| 1266 *scanline ++ = gray; | 1266 *scanline ++ = gray; |
| 1267 *scanline = gray; | 1267 *scanline = gray; |
| 1268 scanline += gap; | 1268 scanline += gap; |
| 1269 } | 1269 } |
| 1270 } | 1270 } |
| 1271 return TRUE; | 1271 return TRUE; |
| 1272 } | 1272 } |
| 1273 if (isCmykImage) { | 1273 if (isCmykImage) { |
| 1274 for (int row = 0; row < m_Height; row ++) { | 1274 for (int row = 0; row < m_Height; row ++) { |
| 1275 FX_LPBYTE scanline = m_pBuffer + row * m_Pitch; | 1275 FX_LPBYTE scanline = m_pBuffer + row * m_Pitch; |
| 1276 for (int col = 0; col < m_Width; col ++) { | 1276 for (int col = 0; col < m_Width; col ++) { |
| 1277 FX_BYTE b, g, r; | 1277 uint8_t b, g, r; |
| 1278 AdobeCMYK_to_sRGB1(scanline[0], scanline[1], scanline[2], scanli
ne[3], | 1278 AdobeCMYK_to_sRGB1(scanline[0], scanline[1], scanline[2], scanli
ne[3], |
| 1279 r, g, b); | 1279 r, g, b); |
| 1280 int gray = 255 - FXRGB2GRAY(r, g, b); | 1280 int gray = 255 - FXRGB2GRAY(r, g, b); |
| 1281 *scanline ++ = bc + (fc - bc) * gray / 255; | 1281 *scanline ++ = bc + (fc - bc) * gray / 255; |
| 1282 *scanline ++ = bm + (fm - bm) * gray / 255; | 1282 *scanline ++ = bm + (fm - bm) * gray / 255; |
| 1283 *scanline ++ = by + (fy - by) * gray / 255; | 1283 *scanline ++ = by + (fy - by) * gray / 255; |
| 1284 *scanline ++ = bk + (fk - bk) * gray / 255; | 1284 *scanline ++ = bk + (fk - bk) * gray / 255; |
| 1285 } | 1285 } |
| 1286 } | 1286 } |
| 1287 } else { | 1287 } else { |
| (...skipping 19 matching lines...) Expand all Loading... |
| 1307 if (m_bpp != 8 && m_pPalette != NULL && m_AlphaFlag != 0) { | 1307 if (m_bpp != 8 && m_pPalette != NULL && m_AlphaFlag != 0) { |
| 1308 return FALSE; | 1308 return FALSE; |
| 1309 } | 1309 } |
| 1310 if (m_Width < 4 && m_Height < 4) { | 1310 if (m_Width < 4 && m_Height < 4) { |
| 1311 return FALSE; | 1311 return FALSE; |
| 1312 } | 1312 } |
| 1313 FX_RECT rect(0, 0, m_Width, m_Height); | 1313 FX_RECT rect(0, 0, m_Width, m_Height); |
| 1314 if (pRect) { | 1314 if (pRect) { |
| 1315 rect.Intersect(*pRect); | 1315 rect.Intersect(*pRect); |
| 1316 } | 1316 } |
| 1317 FX_BYTE translate[256]; | 1317 uint8_t translate[256]; |
| 1318 for (int i = 0; i < 256; i ++) { | 1318 for (int i = 0; i < 256; i ++) { |
| 1319 int err2 = 65536; | 1319 int err2 = 65536; |
| 1320 for (int j = 0; j < pal_size; j ++) { | 1320 for (int j = 0; j < pal_size; j ++) { |
| 1321 FX_BYTE entry = (FX_BYTE)pPalette[j]; | 1321 uint8_t entry = (uint8_t)pPalette[j]; |
| 1322 int err = (int)entry - i; | 1322 int err = (int)entry - i; |
| 1323 if (err * err < err2) { | 1323 if (err * err < err2) { |
| 1324 err2 = err * err; | 1324 err2 = err * err; |
| 1325 translate[i] = entry; | 1325 translate[i] = entry; |
| 1326 } | 1326 } |
| 1327 } | 1327 } |
| 1328 } | 1328 } |
| 1329 for (int row = rect.top; row < rect.bottom; row ++) { | 1329 for (int row = rect.top; row < rect.bottom; row ++) { |
| 1330 FX_LPBYTE scan = m_pBuffer + row * m_Pitch; | 1330 FX_LPBYTE scan = m_pBuffer + row * m_Pitch; |
| 1331 FX_LPBYTE next_scan = m_pBuffer + (row + 1) * m_Pitch; | 1331 FX_LPBYTE next_scan = m_pBuffer + (row + 1) * m_Pitch; |
| 1332 for (int col = rect.left; col < rect.right; col ++) { | 1332 for (int col = rect.left; col < rect.right; col ++) { |
| 1333 int src_pixel = scan[col]; | 1333 int src_pixel = scan[col]; |
| 1334 int dest_pixel = translate[src_pixel]; | 1334 int dest_pixel = translate[src_pixel]; |
| 1335 scan[col] = (FX_BYTE)dest_pixel; | 1335 scan[col] = (uint8_t)dest_pixel; |
| 1336 int error = -dest_pixel + src_pixel; | 1336 int error = -dest_pixel + src_pixel; |
| 1337 if (col < rect.right - 1) { | 1337 if (col < rect.right - 1) { |
| 1338 int src = scan[col + 1]; | 1338 int src = scan[col + 1]; |
| 1339 src += error * 7 / 16; | 1339 src += error * 7 / 16; |
| 1340 if (src > 255) { | 1340 if (src > 255) { |
| 1341 scan[col + 1] = 255; | 1341 scan[col + 1] = 255; |
| 1342 } else if (src < 0) { | 1342 } else if (src < 0) { |
| 1343 scan[col + 1] = 0; | 1343 scan[col + 1] = 0; |
| 1344 } else { | 1344 } else { |
| 1345 scan[col + 1] = src; | 1345 scan[col + 1] = src; |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1488 FX_Free(m_pScanline); | 1488 FX_Free(m_pScanline); |
| 1489 } | 1489 } |
| 1490 } | 1490 } |
| 1491 void CFX_FilteredDIB::LoadSrc(const CFX_DIBSource* pSrc, FX_BOOL bAutoDropSrc) | 1491 void CFX_FilteredDIB::LoadSrc(const CFX_DIBSource* pSrc, FX_BOOL bAutoDropSrc) |
| 1492 { | 1492 { |
| 1493 m_pSrc = pSrc; | 1493 m_pSrc = pSrc; |
| 1494 m_bAutoDropSrc = bAutoDropSrc; | 1494 m_bAutoDropSrc = bAutoDropSrc; |
| 1495 m_Width = pSrc->GetWidth(); | 1495 m_Width = pSrc->GetWidth(); |
| 1496 m_Height = pSrc->GetHeight(); | 1496 m_Height = pSrc->GetHeight(); |
| 1497 FXDIB_Format format = GetDestFormat(); | 1497 FXDIB_Format format = GetDestFormat(); |
| 1498 m_bpp = (FX_BYTE)format; | 1498 m_bpp = (uint8_t)format; |
| 1499 m_AlphaFlag = (FX_BYTE)(format >> 8); | 1499 m_AlphaFlag = (uint8_t)(format >> 8); |
| 1500 m_Pitch = (m_Width * (format & 0xff) + 31) / 32 * 4; | 1500 m_Pitch = (m_Width * (format & 0xff) + 31) / 32 * 4; |
| 1501 m_pPalette = GetDestPalette(); | 1501 m_pPalette = GetDestPalette(); |
| 1502 m_pScanline = FX_Alloc(FX_BYTE, m_Pitch); | 1502 m_pScanline = FX_Alloc(uint8_t, m_Pitch); |
| 1503 } | 1503 } |
| 1504 FX_LPCBYTE CFX_FilteredDIB::GetScanline(int line) const | 1504 FX_LPCBYTE CFX_FilteredDIB::GetScanline(int line) const |
| 1505 { | 1505 { |
| 1506 TranslateScanline(m_pScanline, m_pSrc->GetScanline(line)); | 1506 TranslateScanline(m_pScanline, m_pSrc->GetScanline(line)); |
| 1507 return m_pScanline; | 1507 return m_pScanline; |
| 1508 } | 1508 } |
| 1509 void CFX_FilteredDIB::DownSampleScanline(int line, FX_LPBYTE dest_scan, int dest
_bpp, | 1509 void CFX_FilteredDIB::DownSampleScanline(int line, FX_LPBYTE dest_scan, int dest
_bpp, |
| 1510 int dest_width, FX_BOOL bFlipX, int clip_left, int clip_width) const | 1510 int dest_width, FX_BOOL bFlipX, int clip_left, int clip_width) const |
| 1511 { | 1511 { |
| 1512 m_pSrc->DownSampleScanline(line, dest_scan, dest_bpp, dest_width, bFlipX, cl
ip_left, clip_width); | 1512 m_pSrc->DownSampleScanline(line, dest_scan, dest_bpp, dest_width, bFlipX, cl
ip_left, clip_width); |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1604 if (pBitmap == NULL) { | 1604 if (pBitmap == NULL) { |
| 1605 return FALSE; | 1605 return FALSE; |
| 1606 } | 1606 } |
| 1607 if (pBitmap->GetBuffer() == NULL) { | 1607 if (pBitmap->GetBuffer() == NULL) { |
| 1608 delete pBitmap; | 1608 delete pBitmap; |
| 1609 return FALSE; | 1609 return FALSE; |
| 1610 } | 1610 } |
| 1611 if (pBitmap->IsAlphaMask()) { | 1611 if (pBitmap->IsAlphaMask()) { |
| 1612 if (m_BitmapAlpha != 255) { | 1612 if (m_BitmapAlpha != 255) { |
| 1613 if (m_AlphaFlag >> 8) { | 1613 if (m_AlphaFlag >> 8) { |
| 1614 m_AlphaFlag = (((FX_BYTE)((m_AlphaFlag & 0xff) * m_BitmapAlp
ha / 255)) | ((m_AlphaFlag >> 8) << 8)); | 1614 m_AlphaFlag = (((uint8_t)((m_AlphaFlag & 0xff) * m_BitmapAlp
ha / 255)) | ((m_AlphaFlag >> 8) << 8)); |
| 1615 } else { | 1615 } else { |
| 1616 m_MaskColor = FXARGB_MUL_ALPHA(m_MaskColor, m_BitmapAlpha); | 1616 m_MaskColor = FXARGB_MUL_ALPHA(m_MaskColor, m_BitmapAlpha); |
| 1617 } | 1617 } |
| 1618 } | 1618 } |
| 1619 m_pDevice->CompositeMask(m_pTransformer->m_ResultLeft, m_pTransforme
r->m_ResultTop, | 1619 m_pDevice->CompositeMask(m_pTransformer->m_ResultLeft, m_pTransforme
r->m_ResultTop, |
| 1620 pBitmap->GetWidth(), pBitmap->GetHeight(),
pBitmap, m_MaskColor, | 1620 pBitmap->GetWidth(), pBitmap->GetHeight(),
pBitmap, m_MaskColor, |
| 1621 0, 0, m_BlendType, m_pClipRgn, m_bRgbByteOr
der, m_AlphaFlag, m_pIccTransform); | 1621 0, 0, m_BlendType, m_pClipRgn, m_bRgbByteOr
der, m_AlphaFlag, m_pIccTransform); |
| 1622 } else { | 1622 } else { |
| 1623 if (m_BitmapAlpha != 255) { | 1623 if (m_BitmapAlpha != 255) { |
| 1624 pBitmap->MultiplyAlpha(m_BitmapAlpha); | 1624 pBitmap->MultiplyAlpha(m_BitmapAlpha); |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1672 if (!m_pBitmap->Create(width, height, src_format)) { | 1672 if (!m_pBitmap->Create(width, height, src_format)) { |
| 1673 delete m_pBitmap; | 1673 delete m_pBitmap; |
| 1674 m_pBitmap = NULL; | 1674 m_pBitmap = NULL; |
| 1675 return FALSE; | 1675 return FALSE; |
| 1676 } | 1676 } |
| 1677 if (pSrcPalette) { | 1677 if (pSrcPalette) { |
| 1678 m_pBitmap->CopyPalette(pSrcPalette); | 1678 m_pBitmap->CopyPalette(pSrcPalette); |
| 1679 } | 1679 } |
| 1680 return TRUE; | 1680 return TRUE; |
| 1681 } | 1681 } |
| OLD | NEW |