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 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
266 BuildPalette(); | 266 BuildPalette(); |
267 } | 267 } |
268 m_pPalette[index] = color; | 268 m_pPalette[index] = color; |
269 } | 269 } |
270 int CFX_DIBSource::FindPalette(FX_DWORD color) const | 270 int CFX_DIBSource::FindPalette(FX_DWORD color) const |
271 { | 271 { |
272 ASSERT((GetBPP() == 1 || GetBPP() == 8) && !IsAlphaMask()); | 272 ASSERT((GetBPP() == 1 || GetBPP() == 8) && !IsAlphaMask()); |
273 if (m_pPalette == NULL) { | 273 if (m_pPalette == NULL) { |
274 if (IsCmykImage()) { | 274 if (IsCmykImage()) { |
275 if (GetBPP() == 1) { | 275 if (GetBPP() == 1) { |
276 return ((FX_BYTE)color == 0xff) ? 0 : 1; | 276 return ((uint8_t)color == 0xff) ? 0 : 1; |
277 } | 277 } |
278 return 0xff - (FX_BYTE)color; | 278 return 0xff - (uint8_t)color; |
279 } | 279 } |
280 if (GetBPP() == 1) { | 280 if (GetBPP() == 1) { |
281 return ((FX_BYTE)color == 0xff) ? 1 : 0; | 281 return ((uint8_t)color == 0xff) ? 1 : 0; |
282 } | 282 } |
283 return (FX_BYTE)color; | 283 return (uint8_t)color; |
284 } | 284 } |
285 int palsize = (1 << GetBPP()); | 285 int palsize = (1 << GetBPP()); |
286 for (int i = 0; i < palsize; i ++) | 286 for (int i = 0; i < palsize; i ++) |
287 if (m_pPalette[i] == color) { | 287 if (m_pPalette[i] == color) { |
288 return i; | 288 return i; |
289 } | 289 } |
290 return -1; | 290 return -1; |
291 } | 291 } |
292 void CFX_DIBitmap::Clear(FX_DWORD color) | 292 void CFX_DIBitmap::Clear(FX_DWORD color) |
293 { | 293 { |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
456 pIccModule->TranslateScanline(pIccTransform, color_p, color_p, 1); | 456 pIccModule->TranslateScanline(pIccTransform, color_p, color_p, 1); |
457 } else { | 457 } else { |
458 if (alpha_flag >> 8 && !IsCmykImage()) | 458 if (alpha_flag >> 8 && !IsCmykImage()) |
459 AdobeCMYK_to_sRGB1(FXSYS_GetCValue(color), FXSYS_GetMValue(color), F
XSYS_GetYValue(color), FXSYS_GetKValue(color), | 459 AdobeCMYK_to_sRGB1(FXSYS_GetCValue(color), FXSYS_GetMValue(color), F
XSYS_GetYValue(color), FXSYS_GetKValue(color), |
460 color_p[2], color_p[1], color_p[0]); | 460 color_p[2], color_p[1], color_p[0]); |
461 else if (!(alpha_flag >> 8) && IsCmykImage()) { | 461 else if (!(alpha_flag >> 8) && IsCmykImage()) { |
462 return FALSE; | 462 return FALSE; |
463 } | 463 } |
464 } | 464 } |
465 if(!IsCmykImage()) { | 465 if(!IsCmykImage()) { |
466 color_p[3] = (FX_BYTE)alpha; | 466 color_p[3] = (uint8_t)alpha; |
467 } | 467 } |
468 if (GetFormat() == FXDIB_Argb) { | 468 if (GetFormat() == FXDIB_Argb) { |
469 for (int row = 0; row < height; row ++) { | 469 for (int row = 0; row < height; row ++) { |
470 FX_DWORD* dest_pos = (FX_DWORD*)(m_pBuffer + (dest_top + row) * m_Pi
tch + dest_left * 4); | 470 FX_DWORD* dest_pos = (FX_DWORD*)(m_pBuffer + (dest_top + row) * m_Pi
tch + dest_left * 4); |
471 FX_LPCBYTE src_scan = pMask->GetScanline(src_top + row); | 471 FX_LPCBYTE src_scan = pMask->GetScanline(src_top + row); |
472 if (src_bpp == 1) { | 472 if (src_bpp == 1) { |
473 for (int col = 0; col < width; col ++) { | 473 for (int col = 0; col < width; col ++) { |
474 int src_bitpos = src_left + col; | 474 int src_bitpos = src_left + col; |
475 if (src_scan[src_bitpos / 8] & (1 << (7 - src_bitpos % 8)))
{ | 475 if (src_scan[src_bitpos / 8] & (1 << (7 - src_bitpos % 8)))
{ |
476 *dest_pos = dst_color; | 476 *dest_pos = dst_color; |
(...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
879 FX_BOOL CFX_DIBitmap::GetGrayData(void* pIccTransform) | 879 FX_BOOL CFX_DIBitmap::GetGrayData(void* pIccTransform) |
880 { | 880 { |
881 if (m_pBuffer == NULL) { | 881 if (m_pBuffer == NULL) { |
882 return FALSE; | 882 return FALSE; |
883 } | 883 } |
884 switch (GetFormat()) { | 884 switch (GetFormat()) { |
885 case FXDIB_1bppRgb: { | 885 case FXDIB_1bppRgb: { |
886 if (m_pPalette == NULL) { | 886 if (m_pPalette == NULL) { |
887 return FALSE; | 887 return FALSE; |
888 } | 888 } |
889 FX_BYTE gray[2]; | 889 uint8_t gray[2]; |
890 for (int i = 0; i < 2; i ++) { | 890 for (int i = 0; i < 2; i ++) { |
891 int r = (FX_BYTE)(m_pPalette[i] >> 16); | 891 int r = (uint8_t)(m_pPalette[i] >> 16); |
892 int g = (FX_BYTE)(m_pPalette[i] >> 8); | 892 int g = (uint8_t)(m_pPalette[i] >> 8); |
893 int b = (FX_BYTE)m_pPalette[i]; | 893 int b = (uint8_t)m_pPalette[i]; |
894 gray[i] = (FX_BYTE)FXRGB2GRAY(r, g, b); | 894 gray[i] = (uint8_t)FXRGB2GRAY(r, g, b); |
895 } | 895 } |
896 CFX_DIBitmap* pMask = FX_NEW CFX_DIBitmap; | 896 CFX_DIBitmap* pMask = FX_NEW CFX_DIBitmap; |
897 if (!pMask) { | 897 if (!pMask) { |
898 return FALSE; | 898 return FALSE; |
899 } | 899 } |
900 if (!pMask->Create(m_Width, m_Height, FXDIB_8bppMask)) { | 900 if (!pMask->Create(m_Width, m_Height, FXDIB_8bppMask)) { |
901 delete pMask; | 901 delete pMask; |
902 return FALSE; | 902 return FALSE; |
903 } | 903 } |
904 FXSYS_memset8(pMask->GetBuffer(), gray[0], pMask->GetPitch() * m
_Height); | 904 FXSYS_memset8(pMask->GetBuffer(), gray[0], pMask->GetPitch() * m
_Height); |
905 for (int row = 0; row < m_Height; row ++) { | 905 for (int row = 0; row < m_Height; row ++) { |
906 FX_LPBYTE src_pos = m_pBuffer + row * m_Pitch; | 906 FX_LPBYTE src_pos = m_pBuffer + row * m_Pitch; |
907 FX_LPBYTE dest_pos = (FX_LPBYTE)pMask->GetScanline(row); | 907 FX_LPBYTE dest_pos = (FX_LPBYTE)pMask->GetScanline(row); |
908 for (int col = 0; col < m_Width; col ++) { | 908 for (int col = 0; col < m_Width; col ++) { |
909 if (src_pos[col / 8] & (1 << (7 - col % 8))) { | 909 if (src_pos[col / 8] & (1 << (7 - col % 8))) { |
910 *dest_pos = gray[1]; | 910 *dest_pos = gray[1]; |
911 } | 911 } |
912 dest_pos ++; | 912 dest_pos ++; |
913 } | 913 } |
914 } | 914 } |
915 TakeOver(pMask); | 915 TakeOver(pMask); |
916 delete pMask; | 916 delete pMask; |
917 break; | 917 break; |
918 } | 918 } |
919 case FXDIB_8bppRgb: { | 919 case FXDIB_8bppRgb: { |
920 if (m_pPalette == NULL) { | 920 if (m_pPalette == NULL) { |
921 return FALSE; | 921 return FALSE; |
922 } | 922 } |
923 FX_BYTE gray[256]; | 923 uint8_t gray[256]; |
924 for (int i = 0; i < 256; i ++) { | 924 for (int i = 0; i < 256; i ++) { |
925 int r = (FX_BYTE)(m_pPalette[i] >> 16); | 925 int r = (uint8_t)(m_pPalette[i] >> 16); |
926 int g = (FX_BYTE)(m_pPalette[i] >> 8); | 926 int g = (uint8_t)(m_pPalette[i] >> 8); |
927 int b = (FX_BYTE)m_pPalette[i]; | 927 int b = (uint8_t)m_pPalette[i]; |
928 gray[i] = (FX_BYTE)FXRGB2GRAY(r, g, b); | 928 gray[i] = (uint8_t)FXRGB2GRAY(r, g, b); |
929 } | 929 } |
930 CFX_DIBitmap* pMask = FX_NEW CFX_DIBitmap; | 930 CFX_DIBitmap* pMask = FX_NEW CFX_DIBitmap; |
931 if (!pMask) { | 931 if (!pMask) { |
932 return FALSE; | 932 return FALSE; |
933 } | 933 } |
934 if (!pMask->Create(m_Width, m_Height, FXDIB_8bppMask)) { | 934 if (!pMask->Create(m_Width, m_Height, FXDIB_8bppMask)) { |
935 delete pMask; | 935 delete pMask; |
936 return FALSE; | 936 return FALSE; |
937 } | 937 } |
938 for (int row = 0; row < m_Height; row ++) { | 938 for (int row = 0; row < m_Height; row ++) { |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1104 } | 1104 } |
1105 } else { | 1105 } else { |
1106 if (color == 0xffffffff) { | 1106 if (color == 0xffffffff) { |
1107 *pos |= 1 << (7 - x % 8); | 1107 *pos |= 1 << (7 - x % 8); |
1108 } else { | 1108 } else { |
1109 *pos &= ~(1 << (7 - x % 8)); | 1109 *pos &= ~(1 << (7 - x % 8)); |
1110 } | 1110 } |
1111 } | 1111 } |
1112 break; | 1112 break; |
1113 case FXDIB_8bppMask: | 1113 case FXDIB_8bppMask: |
1114 *pos = (FX_BYTE)(color >> 24); | 1114 *pos = (uint8_t)(color >> 24); |
1115 break; | 1115 break; |
1116 case FXDIB_8bppRgb: { | 1116 case FXDIB_8bppRgb: { |
1117 if (m_pPalette) { | 1117 if (m_pPalette) { |
1118 for (int i = 0; i < 256; i ++) { | 1118 for (int i = 0; i < 256; i ++) { |
1119 if (m_pPalette[i] == color) { | 1119 if (m_pPalette[i] == color) { |
1120 *pos = (FX_BYTE)i; | 1120 *pos = (uint8_t)i; |
1121 return; | 1121 return; |
1122 } | 1122 } |
1123 } | 1123 } |
1124 *pos = 0; | 1124 *pos = 0; |
1125 } else { | 1125 } else { |
1126 *pos = FXRGB2GRAY(FXARGB_R(color), FXARGB_G(color), FXARGB_B
(color)); | 1126 *pos = FXRGB2GRAY(FXARGB_R(color), FXARGB_G(color), FXARGB_B
(color)); |
1127 } | 1127 } |
1128 break; | 1128 break; |
1129 } | 1129 } |
1130 case FXDIB_Rgb: | 1130 case FXDIB_Rgb: |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1239 } | 1239 } |
1240 } else if (forecolor == 0 && backcolor == 0xffffff && m_pPalette == NULL
) { | 1240 } else if (forecolor == 0 && backcolor == 0xffffff && m_pPalette == NULL
) { |
1241 return TRUE; | 1241 return TRUE; |
1242 } | 1242 } |
1243 if (m_pPalette == NULL) { | 1243 if (m_pPalette == NULL) { |
1244 BuildPalette(); | 1244 BuildPalette(); |
1245 } | 1245 } |
1246 int size = 1 << m_bpp; | 1246 int size = 1 << m_bpp; |
1247 if (isCmykImage) { | 1247 if (isCmykImage) { |
1248 for (int i = 0; i < size; i ++) { | 1248 for (int i = 0; i < size; i ++) { |
1249 FX_BYTE b, g, r; | 1249 uint8_t b, g, r; |
1250 AdobeCMYK_to_sRGB1(FXSYS_GetCValue(m_pPalette[i]), FXSYS_GetMVal
ue(m_pPalette[i]), FXSYS_GetYValue(m_pPalette[i]), FXSYS_GetKValue(m_pPalette[i]
), | 1250 AdobeCMYK_to_sRGB1(FXSYS_GetCValue(m_pPalette[i]), FXSYS_GetMVal
ue(m_pPalette[i]), FXSYS_GetYValue(m_pPalette[i]), FXSYS_GetKValue(m_pPalette[i]
), |
1251 r, g, b); | 1251 r, g, b); |
1252 int gray = 255 - FXRGB2GRAY(r, g, b); | 1252 int gray = 255 - FXRGB2GRAY(r, g, b); |
1253 m_pPalette[i] = CmykEncode(bc + (fc - bc) * gray / 255, bm + (fm
- bm) * gray / 255, | 1253 m_pPalette[i] = CmykEncode(bc + (fc - bc) * gray / 255, bm + (fm
- bm) * gray / 255, |
1254 by + (fy - by) * gray / 255, bk + (fk
- bk) * gray / 255); | 1254 by + (fy - by) * gray / 255, bk + (fk
- bk) * gray / 255); |
1255 } | 1255 } |
1256 } else | 1256 } else |
1257 for (int i = 0; i < size; i ++) { | 1257 for (int i = 0; i < size; i ++) { |
1258 int gray = FXRGB2GRAY(FXARGB_R(m_pPalette[i]), FXARGB_G(m_pPalet
te[i]), FXARGB_B(m_pPalette[i])); | 1258 int gray = FXRGB2GRAY(FXARGB_R(m_pPalette[i]), FXARGB_G(m_pPalet
te[i]), FXARGB_B(m_pPalette[i])); |
1259 m_pPalette[i] = FXARGB_MAKE(0xff, br + (fr - br) * gray / 255, b
g + (fg - bg) * gray / 255, | 1259 m_pPalette[i] = FXARGB_MAKE(0xff, br + (fr - br) * gray / 255, b
g + (fg - bg) * gray / 255, |
1260 bb + (fb - bb) * gray / 255); | 1260 bb + (fb - bb) * gray / 255); |
1261 } | 1261 } |
1262 return TRUE; | 1262 return TRUE; |
1263 } | 1263 } |
1264 if (isCmykImage) { | 1264 if (isCmykImage) { |
1265 if (forecolor == 0xff && backcolor == 0x00) { | 1265 if (forecolor == 0xff && backcolor == 0x00) { |
1266 for (int row = 0; row < m_Height; row ++) { | 1266 for (int row = 0; row < m_Height; row ++) { |
1267 FX_LPBYTE scanline = m_pBuffer + row * m_Pitch; | 1267 FX_LPBYTE scanline = m_pBuffer + row * m_Pitch; |
1268 for (int col = 0; col < m_Width; col ++) { | 1268 for (int col = 0; col < m_Width; col ++) { |
1269 FX_BYTE b, g, r; | 1269 uint8_t b, g, r; |
1270 AdobeCMYK_to_sRGB1(scanline[0], scanline[1], scanline[2], sc
anline[3], | 1270 AdobeCMYK_to_sRGB1(scanline[0], scanline[1], scanline[2], sc
anline[3], |
1271 r, g, b); | 1271 r, g, b); |
1272 *scanline ++ = 0; | 1272 *scanline ++ = 0; |
1273 *scanline ++ = 0; | 1273 *scanline ++ = 0; |
1274 *scanline ++ = 0; | 1274 *scanline ++ = 0; |
1275 *scanline ++ = 255 - FXRGB2GRAY(r, g, b); | 1275 *scanline ++ = 255 - FXRGB2GRAY(r, g, b); |
1276 } | 1276 } |
1277 } | 1277 } |
1278 return TRUE; | 1278 return TRUE; |
1279 } | 1279 } |
1280 } else if (forecolor == 0 && backcolor == 0xffffff) { | 1280 } else if (forecolor == 0 && backcolor == 0xffffff) { |
1281 for (int row = 0; row < m_Height; row ++) { | 1281 for (int row = 0; row < m_Height; row ++) { |
1282 FX_LPBYTE scanline = m_pBuffer + row * m_Pitch; | 1282 FX_LPBYTE scanline = m_pBuffer + row * m_Pitch; |
1283 int gap = m_bpp / 8 - 2; | 1283 int gap = m_bpp / 8 - 2; |
1284 for (int col = 0; col < m_Width; col ++) { | 1284 for (int col = 0; col < m_Width; col ++) { |
1285 int gray = FXRGB2GRAY(scanline[2], scanline[1], scanline[0]); | 1285 int gray = FXRGB2GRAY(scanline[2], scanline[1], scanline[0]); |
1286 *scanline ++ = gray; | 1286 *scanline ++ = gray; |
1287 *scanline ++ = gray; | 1287 *scanline ++ = gray; |
1288 *scanline = gray; | 1288 *scanline = gray; |
1289 scanline += gap; | 1289 scanline += gap; |
1290 } | 1290 } |
1291 } | 1291 } |
1292 return TRUE; | 1292 return TRUE; |
1293 } | 1293 } |
1294 if (isCmykImage) { | 1294 if (isCmykImage) { |
1295 for (int row = 0; row < m_Height; row ++) { | 1295 for (int row = 0; row < m_Height; row ++) { |
1296 FX_LPBYTE scanline = m_pBuffer + row * m_Pitch; | 1296 FX_LPBYTE scanline = m_pBuffer + row * m_Pitch; |
1297 for (int col = 0; col < m_Width; col ++) { | 1297 for (int col = 0; col < m_Width; col ++) { |
1298 FX_BYTE b, g, r; | 1298 uint8_t b, g, r; |
1299 AdobeCMYK_to_sRGB1(scanline[0], scanline[1], scanline[2], scanli
ne[3], | 1299 AdobeCMYK_to_sRGB1(scanline[0], scanline[1], scanline[2], scanli
ne[3], |
1300 r, g, b); | 1300 r, g, b); |
1301 int gray = 255 - FXRGB2GRAY(r, g, b); | 1301 int gray = 255 - FXRGB2GRAY(r, g, b); |
1302 *scanline ++ = bc + (fc - bc) * gray / 255; | 1302 *scanline ++ = bc + (fc - bc) * gray / 255; |
1303 *scanline ++ = bm + (fm - bm) * gray / 255; | 1303 *scanline ++ = bm + (fm - bm) * gray / 255; |
1304 *scanline ++ = by + (fy - by) * gray / 255; | 1304 *scanline ++ = by + (fy - by) * gray / 255; |
1305 *scanline ++ = bk + (fk - bk) * gray / 255; | 1305 *scanline ++ = bk + (fk - bk) * gray / 255; |
1306 } | 1306 } |
1307 } | 1307 } |
1308 } else { | 1308 } else { |
(...skipping 19 matching lines...) Expand all Loading... |
1328 if (m_bpp != 8 && m_pPalette != NULL && m_AlphaFlag != 0) { | 1328 if (m_bpp != 8 && m_pPalette != NULL && m_AlphaFlag != 0) { |
1329 return FALSE; | 1329 return FALSE; |
1330 } | 1330 } |
1331 if (m_Width < 4 && m_Height < 4) { | 1331 if (m_Width < 4 && m_Height < 4) { |
1332 return FALSE; | 1332 return FALSE; |
1333 } | 1333 } |
1334 FX_RECT rect(0, 0, m_Width, m_Height); | 1334 FX_RECT rect(0, 0, m_Width, m_Height); |
1335 if (pRect) { | 1335 if (pRect) { |
1336 rect.Intersect(*pRect); | 1336 rect.Intersect(*pRect); |
1337 } | 1337 } |
1338 FX_BYTE translate[256]; | 1338 uint8_t translate[256]; |
1339 for (int i = 0; i < 256; i ++) { | 1339 for (int i = 0; i < 256; i ++) { |
1340 int err2 = 65536; | 1340 int err2 = 65536; |
1341 for (int j = 0; j < pal_size; j ++) { | 1341 for (int j = 0; j < pal_size; j ++) { |
1342 FX_BYTE entry = (FX_BYTE)pPalette[j]; | 1342 uint8_t entry = (uint8_t)pPalette[j]; |
1343 int err = (int)entry - i; | 1343 int err = (int)entry - i; |
1344 if (err * err < err2) { | 1344 if (err * err < err2) { |
1345 err2 = err * err; | 1345 err2 = err * err; |
1346 translate[i] = entry; | 1346 translate[i] = entry; |
1347 } | 1347 } |
1348 } | 1348 } |
1349 } | 1349 } |
1350 for (int row = rect.top; row < rect.bottom; row ++) { | 1350 for (int row = rect.top; row < rect.bottom; row ++) { |
1351 FX_LPBYTE scan = m_pBuffer + row * m_Pitch; | 1351 FX_LPBYTE scan = m_pBuffer + row * m_Pitch; |
1352 FX_LPBYTE next_scan = m_pBuffer + (row + 1) * m_Pitch; | 1352 FX_LPBYTE next_scan = m_pBuffer + (row + 1) * m_Pitch; |
1353 for (int col = rect.left; col < rect.right; col ++) { | 1353 for (int col = rect.left; col < rect.right; col ++) { |
1354 int src_pixel = scan[col]; | 1354 int src_pixel = scan[col]; |
1355 int dest_pixel = translate[src_pixel]; | 1355 int dest_pixel = translate[src_pixel]; |
1356 scan[col] = (FX_BYTE)dest_pixel; | 1356 scan[col] = (uint8_t)dest_pixel; |
1357 int error = -dest_pixel + src_pixel; | 1357 int error = -dest_pixel + src_pixel; |
1358 if (col < rect.right - 1) { | 1358 if (col < rect.right - 1) { |
1359 int src = scan[col + 1]; | 1359 int src = scan[col + 1]; |
1360 src += error * 7 / 16; | 1360 src += error * 7 / 16; |
1361 if (src > 255) { | 1361 if (src > 255) { |
1362 scan[col + 1] = 255; | 1362 scan[col + 1] = 255; |
1363 } else if (src < 0) { | 1363 } else if (src < 0) { |
1364 scan[col + 1] = 0; | 1364 scan[col + 1] = 0; |
1365 } else { | 1365 } else { |
1366 scan[col + 1] = src; | 1366 scan[col + 1] = src; |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1515 FX_Free(m_pScanline); | 1515 FX_Free(m_pScanline); |
1516 } | 1516 } |
1517 } | 1517 } |
1518 void CFX_FilteredDIB::LoadSrc(const CFX_DIBSource* pSrc, FX_BOOL bAutoDropSrc) | 1518 void CFX_FilteredDIB::LoadSrc(const CFX_DIBSource* pSrc, FX_BOOL bAutoDropSrc) |
1519 { | 1519 { |
1520 m_pSrc = pSrc; | 1520 m_pSrc = pSrc; |
1521 m_bAutoDropSrc = bAutoDropSrc; | 1521 m_bAutoDropSrc = bAutoDropSrc; |
1522 m_Width = pSrc->GetWidth(); | 1522 m_Width = pSrc->GetWidth(); |
1523 m_Height = pSrc->GetHeight(); | 1523 m_Height = pSrc->GetHeight(); |
1524 FXDIB_Format format = GetDestFormat(); | 1524 FXDIB_Format format = GetDestFormat(); |
1525 m_bpp = (FX_BYTE)format; | 1525 m_bpp = (uint8_t)format; |
1526 m_AlphaFlag = (FX_BYTE)(format >> 8); | 1526 m_AlphaFlag = (uint8_t)(format >> 8); |
1527 m_Pitch = (m_Width * (format & 0xff) + 31) / 32 * 4; | 1527 m_Pitch = (m_Width * (format & 0xff) + 31) / 32 * 4; |
1528 m_pPalette = GetDestPalette(); | 1528 m_pPalette = GetDestPalette(); |
1529 m_pScanline = FX_Alloc(FX_BYTE, m_Pitch); | 1529 m_pScanline = FX_Alloc(uint8_t, m_Pitch); |
1530 } | 1530 } |
1531 FX_LPCBYTE CFX_FilteredDIB::GetScanline(int line) const | 1531 FX_LPCBYTE CFX_FilteredDIB::GetScanline(int line) const |
1532 { | 1532 { |
1533 TranslateScanline(m_pScanline, m_pSrc->GetScanline(line)); | 1533 TranslateScanline(m_pScanline, m_pSrc->GetScanline(line)); |
1534 return m_pScanline; | 1534 return m_pScanline; |
1535 } | 1535 } |
1536 void CFX_FilteredDIB::DownSampleScanline(int line, FX_LPBYTE dest_scan, int dest
_bpp, | 1536 void CFX_FilteredDIB::DownSampleScanline(int line, FX_LPBYTE dest_scan, int dest
_bpp, |
1537 int dest_width, FX_BOOL bFlipX, int clip_left, int clip_width) const | 1537 int dest_width, FX_BOOL bFlipX, int clip_left, int clip_width) const |
1538 { | 1538 { |
1539 m_pSrc->DownSampleScanline(line, dest_scan, dest_bpp, dest_width, bFlipX, cl
ip_left, clip_width); | 1539 m_pSrc->DownSampleScanline(line, dest_scan, dest_bpp, dest_width, bFlipX, cl
ip_left, clip_width); |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1634 if (pBitmap == NULL) { | 1634 if (pBitmap == NULL) { |
1635 return FALSE; | 1635 return FALSE; |
1636 } | 1636 } |
1637 if (pBitmap->GetBuffer() == NULL) { | 1637 if (pBitmap->GetBuffer() == NULL) { |
1638 delete pBitmap; | 1638 delete pBitmap; |
1639 return FALSE; | 1639 return FALSE; |
1640 } | 1640 } |
1641 if (pBitmap->IsAlphaMask()) { | 1641 if (pBitmap->IsAlphaMask()) { |
1642 if (m_BitmapAlpha != 255) { | 1642 if (m_BitmapAlpha != 255) { |
1643 if (m_AlphaFlag >> 8) { | 1643 if (m_AlphaFlag >> 8) { |
1644 m_AlphaFlag = (((FX_BYTE)((m_AlphaFlag & 0xff) * m_BitmapAlp
ha / 255)) | ((m_AlphaFlag >> 8) << 8)); | 1644 m_AlphaFlag = (((uint8_t)((m_AlphaFlag & 0xff) * m_BitmapAlp
ha / 255)) | ((m_AlphaFlag >> 8) << 8)); |
1645 } else { | 1645 } else { |
1646 m_MaskColor = FXARGB_MUL_ALPHA(m_MaskColor, m_BitmapAlpha); | 1646 m_MaskColor = FXARGB_MUL_ALPHA(m_MaskColor, m_BitmapAlpha); |
1647 } | 1647 } |
1648 } | 1648 } |
1649 m_pDevice->CompositeMask(m_pTransformer->m_ResultLeft, m_pTransforme
r->m_ResultTop, | 1649 m_pDevice->CompositeMask(m_pTransformer->m_ResultLeft, m_pTransforme
r->m_ResultTop, |
1650 pBitmap->GetWidth(), pBitmap->GetHeight(),
pBitmap, m_MaskColor, | 1650 pBitmap->GetWidth(), pBitmap->GetHeight(),
pBitmap, m_MaskColor, |
1651 0, 0, m_BlendType, m_pClipRgn, m_bRgbByteOr
der, m_AlphaFlag, m_pIccTransform); | 1651 0, 0, m_BlendType, m_pClipRgn, m_bRgbByteOr
der, m_AlphaFlag, m_pIccTransform); |
1652 } else { | 1652 } else { |
1653 if (m_BitmapAlpha != 255) { | 1653 if (m_BitmapAlpha != 255) { |
1654 pBitmap->MultiplyAlpha(m_BitmapAlpha); | 1654 pBitmap->MultiplyAlpha(m_BitmapAlpha); |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1705 if (!m_pBitmap->Create(width, height, src_format)) { | 1705 if (!m_pBitmap->Create(width, height, src_format)) { |
1706 delete m_pBitmap; | 1706 delete m_pBitmap; |
1707 m_pBitmap = NULL; | 1707 m_pBitmap = NULL; |
1708 return FALSE; | 1708 return FALSE; |
1709 } | 1709 } |
1710 if (pSrcPalette) { | 1710 if (pSrcPalette) { |
1711 m_pBitmap->CopyPalette(pSrcPalette); | 1711 m_pBitmap->CopyPalette(pSrcPalette); |
1712 } | 1712 } |
1713 return TRUE; | 1713 return TRUE; |
1714 } | 1714 } |
OLD | NEW |