Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(780)

Side by Side Diff: core/src/fxge/dib/fx_dib_convert.cpp

Issue 1265503005: clang-format all pdfium code. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: sigh Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 0xffFF5FAA, 0xffFF5FFF, 0xffFF7F00, 0xffFF7F55, 0xffFF7FAA, 0xffFF7FFF, 43 0xffFF5FAA, 0xffFF5FFF, 0xffFF7F00, 0xffFF7F55, 0xffFF7FAA, 0xffFF7FFF,
44 0xffFF9F00, 0xffFF9F55, 0xffFF9FAA, 0xffFF9FFF, 0xffFFBF00, 0xffFFBF55, 44 0xffFF9F00, 0xffFF9F55, 0xffFF9FAA, 0xffFF9FFF, 0xffFFBF00, 0xffFFBF55,
45 0xffFFBFAA, 0xffFFBFFF, 0xffFFDF00, 0xffFFDF55, 0xffFFDFAA, 0xffFFDFFF, 45 0xffFFBFAA, 0xffFFBFFF, 0xffFFDF00, 0xffFFDF55, 0xffFFDFAA, 0xffFFDFFF,
46 0xffFFFF55, 0xffFFFFAA, 0xffCCCCFF, 0xffFFCCFF, 0xff33FFFF, 0xff66FFFF, 46 0xffFFFF55, 0xffFFFFAA, 0xffCCCCFF, 0xffFFCCFF, 0xff33FFFF, 0xff66FFFF,
47 0xff99FFFF, 0xffCCFFFF, 0xff007F00, 0xff007F55, 0xff007FAA, 0xff007FFF, 47 0xff99FFFF, 0xffCCFFFF, 0xff007F00, 0xff007F55, 0xff007FAA, 0xff007FFF,
48 0xff009F00, 0xff009F55, 0xff009FAA, 0xff009FFF, 0xff00BF00, 0xff00BF55, 48 0xff009F00, 0xff009F55, 0xff009FAA, 0xff009FFF, 0xff00BF00, 0xff00BF55,
49 0xff00BFAA, 0xff00BFFF, 0xff00DF00, 0xff00DF55, 0xff00DFAA, 0xff00DFFF, 49 0xff00BFAA, 0xff00BFFF, 0xff00DF00, 0xff00DF55, 0xff00DFAA, 0xff00DFFF,
50 0xff00FF55, 0xff00FFAA, 0xff2A0000, 0xff2A0055, 0xff2A00AA, 0xff2A00FF, 50 0xff00FF55, 0xff00FFAA, 0xff2A0000, 0xff2A0055, 0xff2A00AA, 0xff2A00FF,
51 0xff2A1F00, 0xff2A1F55, 0xff2A1FAA, 0xff2A1FFF, 0xff2A3F00, 0xff2A3F55, 51 0xff2A1F00, 0xff2A1F55, 0xff2A1FAA, 0xff2A1FFF, 0xff2A3F00, 0xff2A3F55,
52 0xffFFFBF0, 0xffA0A0A4, 0xff808080, 0xffFF0000, 0xff00FF00, 0xffFF0000, 52 0xffFFFBF0, 0xffA0A0A4, 0xff808080, 0xffFF0000, 0xff00FF00, 0xffFF0000,
53 0xff0000FF, 0xffFF00FF, 0xff00FFFF, 0xffFFFFFF 53 0xff0000FF, 0xffFF00FF, 0xff00FFFF, 0xffFFFFFF};
54 };
55 const FX_DWORD g_dwMacPalette[256] = { 54 const FX_DWORD g_dwMacPalette[256] = {
56 0xffFFFFFF, 0xffFFFFCC, 0xffFFFF99, 0xffFFFF66, 0xffFFFF33, 0xffFFFF00, 55 0xffFFFFFF, 0xffFFFFCC, 0xffFFFF99, 0xffFFFF66, 0xffFFFF33, 0xffFFFF00,
57 0xffFFCCFF, 0xffFFCCCC, 0xffFFCC99, 0xffFFCC66, 0xffFFCC33, 0xffFFCC00, 56 0xffFFCCFF, 0xffFFCCCC, 0xffFFCC99, 0xffFFCC66, 0xffFFCC33, 0xffFFCC00,
58 0xffFF99FF, 0xffFF99CC, 0xffFF9999, 0xffFF9966, 0xffFF9933, 0xffFF9900, 57 0xffFF99FF, 0xffFF99CC, 0xffFF9999, 0xffFF9966, 0xffFF9933, 0xffFF9900,
59 0xffFF66FF, 0xffFF66CC, 0xffFF6699, 0xffFF6666, 0xffFF6633, 0xffFF6600, 58 0xffFF66FF, 0xffFF66CC, 0xffFF6699, 0xffFF6666, 0xffFF6633, 0xffFF6600,
60 0xffFF33FF, 0xffFF33CC, 0xffFF3399, 0xffFF3366, 0xffFF3333, 0xffFF3300, 59 0xffFF33FF, 0xffFF33CC, 0xffFF3399, 0xffFF3366, 0xffFF3333, 0xffFF3300,
61 0xffFF00FF, 0xffFF00CC, 0xffFF0099, 0xffFF0066, 0xffFF0033, 0xffFF0000, 60 0xffFF00FF, 0xffFF00CC, 0xffFF0099, 0xffFF0066, 0xffFF0033, 0xffFF0000,
62 0xffCCFFFF, 0xffCCFFCC, 0xffCCFF99, 0xffCCFF66, 0xffCCFF33, 0xffCCFF00, 61 0xffCCFFFF, 0xffCCFFCC, 0xffCCFF99, 0xffCCFF66, 0xffCCFF33, 0xffCCFF00,
63 0xffCCCCFF, 0xffCCCCCC, 0xffCCCC99, 0xffCCCC66, 0xffCCCC33, 0xffCCCC00, 62 0xffCCCCFF, 0xffCCCCCC, 0xffCCCC99, 0xffCCCC66, 0xffCCCC33, 0xffCCCC00,
64 0xffCC99FF, 0xffCC99CC, 0xffCC9999, 0xffCC9966, 0xffCC9933, 0xffCC9900, 63 0xffCC99FF, 0xffCC99CC, 0xffCC9999, 0xffCC9966, 0xffCC9933, 0xffCC9900,
(...skipping 16 matching lines...) Expand all
81 0xff33CCFF, 0xff33CCCC, 0xff33CC99, 0xff33CC66, 0xff33CC33, 0xff33CC00, 80 0xff33CCFF, 0xff33CCCC, 0xff33CC99, 0xff33CC66, 0xff33CC33, 0xff33CC00,
82 0xff3399FF, 0xff3399CC, 0xff339999, 0xff339966, 0xff339933, 0xff339900, 81 0xff3399FF, 0xff3399CC, 0xff339999, 0xff339966, 0xff339933, 0xff339900,
83 0xff3366FF, 0xff3366CC, 0xff336699, 0xff336666, 0xff336633, 0xff336600, 82 0xff3366FF, 0xff3366CC, 0xff336699, 0xff336666, 0xff336633, 0xff336600,
84 0xff3333FF, 0xff3333CC, 0xff333399, 0xff333366, 0xff333333, 0xff333300, 83 0xff3333FF, 0xff3333CC, 0xff333399, 0xff333366, 0xff333333, 0xff333300,
85 0xff3300FF, 0xff3300CC, 0xff330099, 0xff330066, 0xff330033, 0xff330000, 84 0xff3300FF, 0xff3300CC, 0xff330099, 0xff330066, 0xff330033, 0xff330000,
86 0xff00FFFF, 0xff00FFCC, 0xff00FF99, 0xff00FF66, 0xff00FF33, 0xff00FF00, 85 0xff00FFFF, 0xff00FFCC, 0xff00FF99, 0xff00FF66, 0xff00FF33, 0xff00FF00,
87 0xff00CCFF, 0xff00CCCC, 0xff00CC99, 0xff00CC66, 0xff00CC33, 0xff00CC00, 86 0xff00CCFF, 0xff00CCCC, 0xff00CC99, 0xff00CC66, 0xff00CC33, 0xff00CC00,
88 0xff0099FF, 0xff0099CC, 0xff009999, 0xff009966, 0xff009933, 0xff009900, 87 0xff0099FF, 0xff0099CC, 0xff009999, 0xff009966, 0xff009933, 0xff009900,
89 0xff0066FF, 0xff0066CC, 0xff006699, 0xff006666, 0xff006633, 0xff006600, 88 0xff0066FF, 0xff0066CC, 0xff006699, 0xff006666, 0xff006633, 0xff006600,
90 0xff0033FF, 0xff0033CC, 0xff003399, 0xff003366, 0xff003333, 0xff003300, 89 0xff0033FF, 0xff0033CC, 0xff003399, 0xff003366, 0xff003333, 0xff003300,
91 0xff0000FF, 0xff0000CC, 0xff000099, 0xff000066, 0xff000033, 90 0xff0000FF, 0xff0000CC, 0xff000099, 0xff000066, 0xff000033, 0xffEE0000,
92 0xffEE0000, 0xffDD0000, 0xffBB0000, 0xffAA0000, 0xff880000, 0xff770000, 91 0xffDD0000, 0xffBB0000, 0xffAA0000, 0xff880000, 0xff770000, 0xff550000,
93 0xff550000, 0xff440000, 0xff220000, 0xff110000, 0xff00EE00, 0xff00DD00, 92 0xff440000, 0xff220000, 0xff110000, 0xff00EE00, 0xff00DD00, 0xff00BB00,
94 0xff00BB00, 0xff00AA00, 0xff008800, 0xff007700, 0xff005500, 0xff004400, 93 0xff00AA00, 0xff008800, 0xff007700, 0xff005500, 0xff004400, 0xff002200,
95 0xff002200, 0xff001100, 0xff0000EE, 0xff0000DD, 0xff0000BB, 0xff0000AA, 94 0xff001100, 0xff0000EE, 0xff0000DD, 0xff0000BB, 0xff0000AA, 0xff000088,
96 0xff000088, 0xff000077, 0xff000055, 0xff000044, 0xff000022, 0xff000011, 95 0xff000077, 0xff000055, 0xff000044, 0xff000022, 0xff000011, 0xffEEEEEE,
97 0xffEEEEEE, 0xffDDDDDD, 0xffBBBBBB, 0xffAAAAAA, 0xff888888, 0xff777777, 96 0xffDDDDDD, 0xffBBBBBB, 0xffAAAAAA, 0xff888888, 0xff777777, 0xff555555,
98 0xff555555, 0xff444444, 0xff222222, 0xff111111, 0xff000000 97 0xff444444, 0xff222222, 0xff111111, 0xff000000};
98 class CFX_Palette {
99 public:
100 CFX_Palette();
101 ~CFX_Palette();
102
103 public:
104 FX_BOOL BuildPalette(const CFX_DIBSource* pBitmap, int dwPaletteType);
105 FX_DWORD* GetPalette() const { return m_pPalette; }
106
107 FX_DWORD* GetColorLut() const { return m_cLut; }
108 FX_DWORD* GetAmountLut() const { return m_aLut; }
109 int32_t Getlut() const { return m_lut; }
110
111 protected:
112 FX_DWORD* m_pPalette;
113 FX_DWORD* m_cLut;
114 FX_DWORD* m_aLut;
115 int m_lut;
99 }; 116 };
100 class CFX_Palette 117 int _Partition(FX_DWORD* alut, FX_DWORD* clut, int l, int r) {
101 { 118 FX_DWORD p_a = alut[l];
102 public: 119 FX_DWORD p_c = clut[l];
103 CFX_Palette(); 120 while (l < r) {
104 ~CFX_Palette(); 121 while (l < r && alut[r] >= p_a) {
105 public: 122 r--;
106 FX_BOOL BuildPalette(const CFX_DIBSource* pBitmap, int dwPaletteType); 123 }
107 FX_DWORD* GetPalette() const 124 if (l < r) {
108 { 125 alut[l] = alut[r];
109 return m_pPalette; 126 clut[l++] = clut[r];
110 } 127 }
111 128 while (l < r && alut[l] <= p_a) {
112 FX_DWORD* GetColorLut()const 129 l++;
113 { 130 }
114 return m_cLut; 131 if (l < r) {
115 } 132 alut[r] = alut[l];
116 FX_DWORD* GetAmountLut()const 133 clut[r--] = clut[l];
117 { 134 }
118 return m_aLut; 135 }
119 } 136 alut[l] = p_a;
120 int32_t Getlut()const 137 clut[l] = p_c;
121 { 138 return l;
122 return m_lut; 139 }
123 } 140 void _Qsort(FX_DWORD* alut, FX_DWORD* clut, int l, int r) {
124 protected: 141 if (l < r) {
125 FX_DWORD* m_pPalette; 142 int pI = _Partition(alut, clut, l, r);
126 FX_DWORD* m_cLut; 143 _Qsort(alut, clut, l, pI - 1);
127 FX_DWORD* m_aLut; 144 _Qsort(alut, clut, pI + 1, r);
128 int m_lut; 145 }
129 }; 146 }
130 int _Partition(FX_DWORD* alut, FX_DWORD* clut, int l, int r) 147 void _ColorDecode(FX_DWORD pal_v, uint8_t& r, uint8_t& g, uint8_t& b) {
131 { 148 r = (uint8_t)((pal_v & 0xf00) >> 4);
132 FX_DWORD p_a = alut[l]; 149 g = (uint8_t)(pal_v & 0x0f0);
133 FX_DWORD p_c = clut[l]; 150 b = (uint8_t)((pal_v & 0x00f) << 4);
134 while(l < r) { 151 }
135 while(l < r && alut[r] >= p_a) { 152 void _Obtain_Pal(FX_DWORD* aLut,
136 r--; 153 FX_DWORD* cLut,
137 } 154 FX_DWORD* dest_pal,
138 if (l < r) { 155 int pal_type,
139 alut[l] = alut[r]; 156 FX_DWORD* win_mac_pal,
140 clut[l++] = clut[r]; 157 FX_DWORD lut) {
141 } 158 int row, col;
142 while(l < r && alut[l] <= p_a) { 159 FX_DWORD lut_1 = lut - 1;
143 l++; 160 if (pal_type == FXDIB_PALETTE_LOC) {
144 } 161 for (row = 0; row < 256; row++) {
145 if (l < r) { 162 int lut_offset = lut_1 - row;
146 alut[r] = alut[l]; 163 if (lut_offset < 0) {
147 clut[r--] = clut[l]; 164 lut_offset += 256;
148 } 165 }
149 } 166 FX_DWORD color = cLut[lut_offset];
150 alut[l] = p_a; 167 uint8_t r, g, b;
151 clut[l] = p_c; 168 _ColorDecode(color, r, g, b);
152 return l; 169 dest_pal[row] = ((FX_DWORD)r << 16) | ((FX_DWORD)g << 8) | b | 0xff000000;
153 } 170 aLut[lut_offset] = row;
154 void _Qsort(FX_DWORD* alut, FX_DWORD* clut, int l, int r) 171 }
155 { 172 } else {
156 if(l < r) { 173 for (row = 0; row < 256; row++) {
157 int pI = _Partition(alut, clut, l, r); 174 int lut_offset = lut_1 - row;
158 _Qsort(alut, clut, l, pI - 1); 175 if (lut_offset < 0) {
159 _Qsort(alut, clut, pI + 1, r); 176 lut_offset += 256;
160 } 177 }
161 } 178 uint8_t r, g, b;
162 void _ColorDecode(FX_DWORD pal_v, uint8_t& r, uint8_t& g, uint8_t& b) 179 _ColorDecode(cLut[lut_offset], r, g, b);
163 { 180 int error, min_error = 1000000;
164 r = (uint8_t)((pal_v & 0xf00) >> 4); 181 int c_index = 0;
165 g = (uint8_t)(pal_v & 0x0f0); 182 for (col = 0; col < 256; col++) {
166 b = (uint8_t)((pal_v & 0x00f) << 4); 183 FX_DWORD p_color = win_mac_pal[col];
167 } 184 int d_r = r - (uint8_t)(p_color >> 16);
168 void _Obtain_Pal(FX_DWORD* aLut, FX_DWORD*cLut, FX_DWORD* dest_pal, int pal_type , FX_DWORD* win_mac_pal, FX_DWORD lut) 185 int d_g = g - (uint8_t)(p_color >> 8);
169 { 186 int d_b = b - (uint8_t)p_color;
170 int row, col; 187 error = d_r * d_r + d_g * d_g + d_b * d_b;
171 FX_DWORD lut_1 = lut - 1; 188 if (error < min_error) {
172 if (pal_type == FXDIB_PALETTE_LOC) { 189 min_error = error;
173 for (row = 0; row < 256; row++) { 190 c_index = col;
174 int lut_offset = lut_1 - row; 191 }
175 if (lut_offset < 0) { 192 }
176 lut_offset += 256; 193 dest_pal[row] = win_mac_pal[c_index];
177 } 194 aLut[lut_offset] = row;
178 FX_DWORD color = cLut[lut_offset]; 195 }
179 uint8_t r, g, b; 196 }
180 _ColorDecode(color, r, g, b); 197 }
181 dest_pal[row] = ((FX_DWORD)r << 16) | ((FX_DWORD)g << 8) | b | 0xff0 00000; 198 CFX_Palette::CFX_Palette() {
182 aLut[lut_offset] = row; 199 m_pPalette = NULL;
183 } 200 m_cLut = NULL;
201 m_aLut = NULL;
202 m_lut = 0;
203 }
204 CFX_Palette::~CFX_Palette() {
205 if (m_pPalette) {
206 FX_Free(m_pPalette);
207 }
208 if (m_cLut) {
209 FX_Free(m_cLut);
210 }
211 if (m_aLut) {
212 FX_Free(m_aLut);
213 }
214 m_lut = 0;
215 }
216 FX_BOOL CFX_Palette::BuildPalette(const CFX_DIBSource* pBitmap, int pal_type) {
217 if (pBitmap == NULL) {
218 return FALSE;
219 }
220 if (m_pPalette != NULL) {
221 FX_Free(m_pPalette);
222 }
223 m_pPalette = FX_Alloc(FX_DWORD, 256);
224 int bpp = pBitmap->GetBPP() / 8;
225 int width = pBitmap->GetWidth();
226 int height = pBitmap->GetHeight();
227 if (m_cLut) {
228 FX_Free(m_cLut);
229 m_cLut = NULL;
230 }
231 if (m_aLut) {
232 FX_Free(m_aLut);
233 m_aLut = NULL;
234 }
235 m_cLut = FX_Alloc(FX_DWORD, 4096);
236 m_aLut = FX_Alloc(FX_DWORD, 4096);
237 int row, col;
238 m_lut = 0;
239 for (row = 0; row < height; row++) {
240 uint8_t* scan_line = (uint8_t*)pBitmap->GetScanline(row);
241 for (col = 0; col < width; col++) {
242 uint8_t* src_port = scan_line + col * bpp;
243 FX_DWORD b = src_port[0] & 0xf0;
244 FX_DWORD g = src_port[1] & 0xf0;
245 FX_DWORD r = src_port[2] & 0xf0;
246 FX_DWORD index = (r << 4) + g + (b >> 4);
247 m_aLut[index]++;
248 }
249 }
250 for (row = 0; row < 4096; row++) {
251 if (m_aLut[row] != 0) {
252 m_aLut[m_lut] = m_aLut[row];
253 m_cLut[m_lut] = row;
254 m_lut++;
255 }
256 }
257 _Qsort(m_aLut, m_cLut, 0, m_lut - 1);
258 FX_DWORD* win_mac_pal = NULL;
259 if (pal_type == FXDIB_PALETTE_WIN) {
260 win_mac_pal = (FX_DWORD*)g_dwWinPalette;
261 } else if (pal_type == FXDIB_PALETTE_MAC) {
262 win_mac_pal = (FX_DWORD*)g_dwMacPalette;
263 }
264 _Obtain_Pal(m_aLut, m_cLut, m_pPalette, pal_type, win_mac_pal, m_lut);
265 return TRUE;
266 }
267 FX_BOOL _ConvertBuffer_1bppMask2Gray(uint8_t* dest_buf,
268 int dest_pitch,
269 int width,
270 int height,
271 const CFX_DIBSource* pSrcBitmap,
272 int src_left,
273 int src_top) {
274 uint8_t set_gray, reset_gray;
275 set_gray = 0xff;
276 reset_gray = 0x00;
277 for (int row = 0; row < height; row++) {
278 uint8_t* dest_scan = dest_buf + row * dest_pitch;
279 FXSYS_memset(dest_scan, reset_gray, width);
280 const uint8_t* src_scan = pSrcBitmap->GetScanline(src_top + row);
281 for (int col = src_left; col < src_left + width; col++) {
282 if (src_scan[col / 8] & (1 << (7 - col % 8))) {
283 *dest_scan = set_gray;
284 }
285 dest_scan++;
286 }
287 }
288 return TRUE;
289 }
290 FX_BOOL _ConvertBuffer_8bppMask2Gray(uint8_t* dest_buf,
291 int dest_pitch,
292 int width,
293 int height,
294 const CFX_DIBSource* pSrcBitmap,
295 int src_left,
296 int src_top) {
297 for (int row = 0; row < height; row++) {
298 uint8_t* dest_scan = dest_buf + row * dest_pitch;
299 const uint8_t* src_scan = pSrcBitmap->GetScanline(src_top + row) + src_left;
300 FXSYS_memcpy(dest_scan, src_scan, width);
301 }
302 return TRUE;
303 }
304 FX_BOOL _ConvertBuffer_1bppPlt2Gray(uint8_t* dest_buf,
305 int dest_pitch,
306 int width,
307 int height,
308 const CFX_DIBSource* pSrcBitmap,
309 int src_left,
310 int src_top,
311 void* pIccTransform) {
312 FX_DWORD* src_plt = pSrcBitmap->GetPalette();
313 uint8_t gray[2];
314 if (pIccTransform) {
315 FX_DWORD plt[2];
316 if (pSrcBitmap->IsCmykImage()) {
317 plt[0] = FXCMYK_TODIB(src_plt[0]);
318 plt[1] = FXCMYK_TODIB(src_plt[1]);
184 } else { 319 } else {
185 for (row = 0; row < 256; row++) { 320 uint8_t* bgr_ptr = (uint8_t*)plt;
186 int lut_offset = lut_1 - row; 321 bgr_ptr[0] = FXARGB_B(src_plt[0]);
187 if (lut_offset < 0) { 322 bgr_ptr[1] = FXARGB_G(src_plt[0]);
188 lut_offset += 256; 323 bgr_ptr[2] = FXARGB_R(src_plt[0]);
189 } 324 bgr_ptr[3] = FXARGB_B(src_plt[1]);
190 uint8_t r, g, b; 325 bgr_ptr[4] = FXARGB_G(src_plt[1]);
191 _ColorDecode(cLut[lut_offset], r, g, b); 326 bgr_ptr[5] = FXARGB_R(src_plt[1]);
192 int error, min_error = 1000000; 327 }
193 int c_index = 0; 328 ICodec_IccModule* pIccModule =
194 for (col = 0; col < 256; col++) { 329 CFX_GEModule::Get()->GetCodecModule()->GetIccModule();
195 FX_DWORD p_color = win_mac_pal[col]; 330 pIccModule->TranslateScanline(pIccTransform, gray, (const uint8_t*)plt, 2);
196 int d_r = r - (uint8_t)(p_color >> 16); 331 } else {
197 int d_g = g - (uint8_t)(p_color >> 8); 332 uint8_t reset_r, reset_g, reset_b, set_r, set_g, set_b;
198 int d_b = b - (uint8_t)p_color; 333 if (pSrcBitmap->IsCmykImage()) {
199 error = d_r * d_r + d_g * d_g + d_b * d_b; 334 AdobeCMYK_to_sRGB1(
200 if (error < min_error) { 335 FXSYS_GetCValue(src_plt[0]), FXSYS_GetMValue(src_plt[0]),
201 min_error = error; 336 FXSYS_GetYValue(src_plt[0]), FXSYS_GetKValue(src_plt[0]), reset_r,
202 c_index = col; 337 reset_g, reset_b);
203 } 338 AdobeCMYK_to_sRGB1(FXSYS_GetCValue(src_plt[1]),
204 } 339 FXSYS_GetMValue(src_plt[1]),
205 dest_pal[row] = win_mac_pal[c_index]; 340 FXSYS_GetYValue(src_plt[1]),
206 aLut[lut_offset] = row; 341 FXSYS_GetKValue(src_plt[1]), set_r, set_g, set_b);
207 } 342 } else {
208 } 343 reset_r = FXARGB_R(src_plt[0]);
209 } 344 reset_g = FXARGB_G(src_plt[0]);
210 CFX_Palette::CFX_Palette() 345 reset_b = FXARGB_B(src_plt[0]);
211 { 346 set_r = FXARGB_R(src_plt[1]);
212 m_pPalette = NULL; 347 set_g = FXARGB_G(src_plt[1]);
213 m_cLut = NULL; 348 set_b = FXARGB_B(src_plt[1]);
214 m_aLut = NULL; 349 }
215 m_lut = 0; 350 gray[0] = FXRGB2GRAY(reset_r, reset_g, reset_b);
216 } 351 gray[1] = FXRGB2GRAY(set_r, set_g, set_b);
217 CFX_Palette::~CFX_Palette() 352 }
218 { 353 for (int row = 0; row < height; row++) {
219 if (m_pPalette) { 354 uint8_t* dest_scan = dest_buf + row * dest_pitch;
220 FX_Free(m_pPalette); 355 FXSYS_memset(dest_scan, gray[0], width);
221 } 356 const uint8_t* src_scan = pSrcBitmap->GetScanline(src_top + row);
222 if (m_cLut) { 357 for (int col = src_left; col < src_left + width; col++) {
223 FX_Free(m_cLut); 358 if (src_scan[col / 8] & (1 << (7 - col % 8))) {
224 } 359 *dest_scan = gray[1];
225 if (m_aLut) { 360 }
226 FX_Free(m_aLut); 361 dest_scan++;
227 } 362 }
228 m_lut = 0; 363 }
229 } 364 return TRUE;
230 FX_BOOL CFX_Palette::BuildPalette(const CFX_DIBSource* pBitmap, int pal_type) 365 }
231 { 366 FX_BOOL _ConvertBuffer_8bppPlt2Gray(uint8_t* dest_buf,
232 if (pBitmap == NULL) { 367 int dest_pitch,
233 return FALSE; 368 int width,
234 } 369 int height,
235 if (m_pPalette != NULL) { 370 const CFX_DIBSource* pSrcBitmap,
236 FX_Free(m_pPalette); 371 int src_left,
237 } 372 int src_top,
238 m_pPalette = FX_Alloc(FX_DWORD, 256); 373 void* pIccTransform) {
239 int bpp = pBitmap->GetBPP() / 8; 374 FX_DWORD* src_plt = pSrcBitmap->GetPalette();
240 int width = pBitmap->GetWidth(); 375 uint8_t gray[256];
241 int height = pBitmap->GetHeight(); 376 if (pIccTransform) {
242 if (m_cLut) { 377 FX_DWORD plt[256];
243 FX_Free(m_cLut); 378 if (pSrcBitmap->IsCmykImage()) {
244 m_cLut = NULL; 379 for (int i = 0; i < 256; i++) {
245 } 380 plt[i] = FXCMYK_TODIB(src_plt[i]);
246 if (m_aLut) { 381 }
247 FX_Free(m_aLut); 382 } else {
248 m_aLut = NULL; 383 uint8_t* bgr_ptr = (uint8_t*)plt;
249 } 384 for (int i = 0; i < 256; i++) {
250 m_cLut = FX_Alloc(FX_DWORD, 4096); 385 *bgr_ptr++ = FXARGB_B(src_plt[i]);
251 m_aLut = FX_Alloc(FX_DWORD, 4096); 386 *bgr_ptr++ = FXARGB_G(src_plt[i]);
252 int row, col; 387 *bgr_ptr++ = FXARGB_R(src_plt[i]);
253 m_lut = 0; 388 }
254 for (row = 0; row < height; row++) { 389 }
255 uint8_t* scan_line = (uint8_t*)pBitmap->GetScanline(row); 390 ICodec_IccModule* pIccModule =
256 for (col = 0; col < width; col++) { 391 CFX_GEModule::Get()->GetCodecModule()->GetIccModule();
257 uint8_t* src_port = scan_line + col * bpp; 392 pIccModule->TranslateScanline(pIccTransform, gray, (const uint8_t*)plt,
258 FX_DWORD b = src_port[0] & 0xf0; 393 256);
259 FX_DWORD g = src_port[1] & 0xf0; 394 } else {
260 FX_DWORD r = src_port[2] & 0xf0; 395 if (pSrcBitmap->IsCmykImage()) {
261 FX_DWORD index = (r << 4) + g + (b >> 4); 396 uint8_t r, g, b;
262 m_aLut[index]++; 397 for (int i = 0; i < 256; i++) {
263 } 398 AdobeCMYK_to_sRGB1(
264 } 399 FXSYS_GetCValue(src_plt[i]), FXSYS_GetMValue(src_plt[i]),
265 for (row = 0; row < 4096; row++) { 400 FXSYS_GetYValue(src_plt[i]), FXSYS_GetKValue(src_plt[i]), r, g, b);
266 if (m_aLut[row] != 0) { 401 gray[i] = FXRGB2GRAY(r, g, b);
267 m_aLut[m_lut] = m_aLut[row]; 402 }
268 m_cLut[m_lut] = row; 403 } else
269 m_lut++; 404 for (int i = 0; i < 256; i++) {
270 } 405 gray[i] = FXRGB2GRAY(FXARGB_R(src_plt[i]), FXARGB_G(src_plt[i]),
271 } 406 FXARGB_B(src_plt[i]));
272 _Qsort(m_aLut, m_cLut, 0, m_lut - 1); 407 }
273 FX_DWORD* win_mac_pal = NULL; 408 }
274 if (pal_type == FXDIB_PALETTE_WIN) { 409 for (int row = 0; row < height; row++) {
275 win_mac_pal = (FX_DWORD*)g_dwWinPalette; 410 uint8_t* dest_scan = dest_buf + row * dest_pitch;
276 } else if (pal_type == FXDIB_PALETTE_MAC) { 411 const uint8_t* src_scan = pSrcBitmap->GetScanline(src_top + row) + src_left;
277 win_mac_pal = (FX_DWORD*)g_dwMacPalette; 412 for (int col = 0; col < width; col++) {
278 } 413 *dest_scan++ = gray[*src_scan++];
279 _Obtain_Pal(m_aLut, m_cLut, m_pPalette, pal_type, win_mac_pal, m_lut); 414 }
280 return TRUE; 415 }
281 } 416 return TRUE;
282 FX_BOOL _ConvertBuffer_1bppMask2Gray(uint8_t* dest_buf, int dest_pitch, int widt h, int height, 417 }
283 const CFX_DIBSource* pSrcBitmap, int src_le ft, int src_top) 418 FX_BOOL _ConvertBuffer_RgbOrCmyk2Gray(uint8_t* dest_buf,
284 { 419 int dest_pitch,
285 uint8_t set_gray, reset_gray; 420 int width,
286 set_gray = 0xff; 421 int height,
287 reset_gray = 0x00; 422 const CFX_DIBSource* pSrcBitmap,
288 for (int row = 0; row < height; row ++) { 423 int src_left,
424 int src_top,
425 void* pIccTransform) {
426 int Bpp = pSrcBitmap->GetBPP() / 8;
427 if (pIccTransform) {
428 ICodec_IccModule* pIccModule =
429 CFX_GEModule::Get()->GetCodecModule()->GetIccModule();
430 if (Bpp == 3 || pSrcBitmap->IsCmykImage()) {
431 for (int row = 0; row < height; row++) {
289 uint8_t* dest_scan = dest_buf + row * dest_pitch; 432 uint8_t* dest_scan = dest_buf + row * dest_pitch;
290 FXSYS_memset(dest_scan, reset_gray, width); 433 const uint8_t* src_scan =
291 const uint8_t* src_scan = pSrcBitmap->GetScanline(src_top + row); 434 pSrcBitmap->GetScanline(src_top + row) + src_left * Bpp;
292 for (int col = src_left; col < src_left + width; col ++) { 435 pIccModule->TranslateScanline(pIccTransform, dest_scan, src_scan,
293 if (src_scan[col / 8] & (1 << (7 - col % 8))) { 436 width);
294 *dest_scan = set_gray; 437 }
295 } 438 } else {
296 dest_scan ++; 439 for (int row = 0; row < height; row++) {
297 }
298 }
299 return TRUE;
300 }
301 FX_BOOL _ConvertBuffer_8bppMask2Gray(uint8_t* dest_buf, int dest_pitch, int widt h, int height,
302 const CFX_DIBSource* pSrcBitmap, int src_le ft, int src_top)
303 {
304 for (int row = 0; row < height; row ++) {
305 uint8_t* dest_scan = dest_buf + row * dest_pitch; 440 uint8_t* dest_scan = dest_buf + row * dest_pitch;
306 const uint8_t* src_scan = pSrcBitmap->GetScanline(src_top + row) + src_l eft; 441 const uint8_t* src_scan =
307 FXSYS_memcpy(dest_scan, src_scan, width); 442 pSrcBitmap->GetScanline(src_top + row) + src_left * 4;
308 } 443 for (int col = 0; col < width; col++) {
309 return TRUE; 444 pIccModule->TranslateScanline(pIccTransform, dest_scan, src_scan, 1);
310 } 445 dest_scan++;
311 FX_BOOL _ConvertBuffer_1bppPlt2Gray(uint8_t* dest_buf, int dest_pitch, int width , int height, 446 src_scan += 4;
312 const CFX_DIBSource* pSrcBitmap, int src_lef t, int src_top, void* pIccTransform) 447 }
313 { 448 }
314 FX_DWORD* src_plt = pSrcBitmap->GetPalette(); 449 }
315 uint8_t gray[2]; 450 } else {
316 if (pIccTransform) { 451 if (pSrcBitmap->IsCmykImage()) {
317 FX_DWORD plt[2]; 452 for (int row = 0; row < height; row++) {
318 if (pSrcBitmap->IsCmykImage()) { 453 uint8_t* dest_scan = dest_buf + row * dest_pitch;
319 plt[0] = FXCMYK_TODIB(src_plt[0]); 454 const uint8_t* src_scan =
320 plt[1] = FXCMYK_TODIB(src_plt[1]); 455 pSrcBitmap->GetScanline(src_top + row) + src_left * 4;
321 } else { 456 for (int col = 0; col < width; col++) {
322 uint8_t* bgr_ptr = (uint8_t*)plt; 457 uint8_t r, g, b;
323 bgr_ptr[0] = FXARGB_B(src_plt[0]); 458 AdobeCMYK_to_sRGB1(FXSYS_GetCValue((FX_DWORD)src_scan[0]),
324 bgr_ptr[1] = FXARGB_G(src_plt[0]); 459 FXSYS_GetMValue((FX_DWORD)src_scan[1]),
325 bgr_ptr[2] = FXARGB_R(src_plt[0]); 460 FXSYS_GetYValue((FX_DWORD)src_scan[2]),
326 bgr_ptr[3] = FXARGB_B(src_plt[1]); 461 FXSYS_GetKValue((FX_DWORD)src_scan[3]), r, g, b);
327 bgr_ptr[4] = FXARGB_G(src_plt[1]); 462 *dest_scan++ = FXRGB2GRAY(r, g, b);
328 bgr_ptr[5] = FXARGB_R(src_plt[1]); 463 src_scan += 4;
329 } 464 }
330 ICodec_IccModule* pIccModule = CFX_GEModule::Get()->GetCodecModule()->Ge tIccModule(); 465 }
331 pIccModule->TranslateScanline(pIccTransform, gray, (const uint8_t*)plt, 2);
332 } else { 466 } else {
333 uint8_t reset_r, reset_g, reset_b, 467 for (int row = 0; row < height; row++) {
334 set_r, set_g, set_b;
335 if (pSrcBitmap->IsCmykImage()) {
336 AdobeCMYK_to_sRGB1(FXSYS_GetCValue(src_plt[0]), FXSYS_GetMValue(src_ plt[0]), FXSYS_GetYValue(src_plt[0]), FXSYS_GetKValue(src_plt[0]),
337 reset_r, reset_g, reset_b);
338 AdobeCMYK_to_sRGB1(FXSYS_GetCValue(src_plt[1]), FXSYS_GetMValue(src_ plt[1]), FXSYS_GetYValue(src_plt[1]), FXSYS_GetKValue(src_plt[1]),
339 set_r, set_g, set_b);
340 } else {
341 reset_r = FXARGB_R(src_plt[0]);
342 reset_g = FXARGB_G(src_plt[0]);
343 reset_b = FXARGB_B(src_plt[0]);
344 set_r = FXARGB_R(src_plt[1]);
345 set_g = FXARGB_G(src_plt[1]);
346 set_b = FXARGB_B(src_plt[1]);
347 }
348 gray[0] = FXRGB2GRAY(reset_r, reset_g, reset_b);
349 gray[1] = FXRGB2GRAY(set_r, set_g, set_b);
350 }
351 for (int row = 0; row < height; row ++) {
352 uint8_t* dest_scan = dest_buf + row * dest_pitch; 468 uint8_t* dest_scan = dest_buf + row * dest_pitch;
353 FXSYS_memset(dest_scan, gray[0], width); 469 const uint8_t* src_scan =
354 const uint8_t* src_scan = pSrcBitmap->GetScanline(src_top + row); 470 pSrcBitmap->GetScanline(src_top + row) + src_left * Bpp;
355 for (int col = src_left; col < src_left + width; col ++) { 471 for (int col = 0; col < width; col++) {
356 if (src_scan[col / 8] & (1 << (7 - col % 8))) { 472 *dest_scan++ = FXRGB2GRAY(src_scan[2], src_scan[1], src_scan[0]);
357 *dest_scan = gray[1]; 473 src_scan += Bpp;
358 } 474 }
359 dest_scan ++; 475 }
360 } 476 }
361 } 477 }
362 return TRUE; 478 return TRUE;
363 } 479 }
364 FX_BOOL _ConvertBuffer_8bppPlt2Gray(uint8_t* dest_buf, int dest_pitch, int width , int height, 480 inline void _ConvertBuffer_IndexCopy(uint8_t* dest_buf,
365 const CFX_DIBSource* pSrcBitmap, int src_lef t, int src_top, void* pIccTransform) 481 int dest_pitch,
366 { 482 int width,
367 FX_DWORD* src_plt = pSrcBitmap->GetPalette(); 483 int height,
368 uint8_t gray[256]; 484 const CFX_DIBSource* pSrcBitmap,
369 if (pIccTransform) { 485 int src_left,
370 FX_DWORD plt[256]; 486 int src_top) {
371 if (pSrcBitmap->IsCmykImage()) { 487 if (pSrcBitmap->GetBPP() == 1) {
372 for (int i = 0; i < 256; i ++) { 488 for (int row = 0; row < height; row++) {
373 plt[i] = FXCMYK_TODIB(src_plt[i]); 489 uint8_t* dest_scan = dest_buf + row * dest_pitch;
374 } 490 FXSYS_memset(dest_scan, 0, width);
375 } else { 491 const uint8_t* src_scan = pSrcBitmap->GetScanline(src_top + row);
376 uint8_t* bgr_ptr = (uint8_t*)plt; 492 for (int col = src_left; col < src_left + width; col++) {
377 for (int i = 0; i < 256; i ++) { 493 if (src_scan[col / 8] & (1 << (7 - col % 8))) {
378 *bgr_ptr++ = FXARGB_B(src_plt[i]); 494 *dest_scan = 1;
379 *bgr_ptr++ = FXARGB_G(src_plt[i]); 495 }
380 *bgr_ptr++ = FXARGB_R(src_plt[i]); 496 dest_scan++;
381 } 497 }
382 } 498 }
383 ICodec_IccModule* pIccModule = CFX_GEModule::Get()->GetCodecModule()->Ge tIccModule(); 499 } else {
384 pIccModule->TranslateScanline(pIccTransform, gray, (const uint8_t*)plt, 256); 500 for (int row = 0; row < height; row++) {
385 } else { 501 uint8_t* dest_scan = dest_buf + row * dest_pitch;
386 if (pSrcBitmap->IsCmykImage()) { 502 const uint8_t* src_scan =
387 uint8_t r, g, b; 503 pSrcBitmap->GetScanline(src_top + row) + src_left;
388 for (int i = 0; i < 256; i ++) { 504 FXSYS_memcpy(dest_scan, src_scan, width);
389 AdobeCMYK_to_sRGB1(FXSYS_GetCValue(src_plt[i]), FXSYS_GetMValue( src_plt[i]), FXSYS_GetYValue(src_plt[i]), FXSYS_GetKValue(src_plt[i]), 505 }
390 r, g, b); 506 }
391 gray[i] = FXRGB2GRAY(r, g, b); 507 }
392 } 508 FX_BOOL _ConvertBuffer_Plt2PltRgb8(uint8_t* dest_buf,
393 } else 509 int dest_pitch,
394 for (int i = 0; i < 256; i ++) { 510 int width,
395 gray[i] = FXRGB2GRAY(FXARGB_R(src_plt[i]), FXARGB_G(src_plt[i]), FXARGB_B(src_plt[i])); 511 int height,
396 } 512 const CFX_DIBSource* pSrcBitmap,
397 } 513 int src_left,
398 for (int row = 0; row < height; row ++) { 514 int src_top,
399 uint8_t* dest_scan = dest_buf + row * dest_pitch; 515 FX_DWORD* dst_plt,
400 const uint8_t* src_scan = pSrcBitmap->GetScanline(src_top + row) + src_l eft; 516 void* pIccTransform) {
401 for (int col = 0; col < width; col ++) { 517 _ConvertBuffer_IndexCopy(dest_buf, dest_pitch, width, height, pSrcBitmap,
402 *dest_scan++ = gray[*src_scan++]; 518 src_left, src_top);
403 } 519 FX_DWORD* src_plt = pSrcBitmap->GetPalette();
404 } 520 int plt_size = pSrcBitmap->GetPaletteSize();
405 return TRUE; 521 if (pIccTransform) {
406 } 522 FX_DWORD plt[256];
407 FX_BOOL _ConvertBuffer_RgbOrCmyk2Gray(uint8_t* dest_buf, int dest_pitch, int wid th, int height,
408 const CFX_DIBSource* pSrcBitmap, int src_l eft, int src_top, void* pIccTransform)
409 {
410 int Bpp = pSrcBitmap->GetBPP() / 8;
411 if (pIccTransform) {
412 ICodec_IccModule* pIccModule = CFX_GEModule::Get()->GetCodecModule()->Ge tIccModule();
413 if (Bpp == 3 || pSrcBitmap->IsCmykImage()) {
414 for (int row = 0; row < height; row ++) {
415 uint8_t* dest_scan = dest_buf + row * dest_pitch;
416 const uint8_t* src_scan = pSrcBitmap->GetScanline(src_top + row) + src_left * Bpp;
417 pIccModule->TranslateScanline(pIccTransform, dest_scan, src_scan , width);
418 }
419 } else {
420 for (int row = 0; row < height; row ++) {
421 uint8_t* dest_scan = dest_buf + row * dest_pitch;
422 const uint8_t* src_scan = pSrcBitmap->GetScanline(src_top + row) + src_left * 4;
423 for (int col = 0; col < width; col ++) {
424 pIccModule->TranslateScanline(pIccTransform, dest_scan, src_ scan, 1);
425 dest_scan++;
426 src_scan += 4;
427 }
428 }
429 }
430 } else {
431 if (pSrcBitmap->IsCmykImage()) {
432 for (int row = 0; row < height; row ++) {
433 uint8_t* dest_scan = dest_buf + row * dest_pitch;
434 const uint8_t* src_scan = pSrcBitmap->GetScanline(src_top + row) + src_left * 4;
435 for (int col = 0; col < width; col ++) {
436 uint8_t r, g, b;
437 AdobeCMYK_to_sRGB1(FXSYS_GetCValue((FX_DWORD)src_scan[0]), F XSYS_GetMValue((FX_DWORD)src_scan[1]), FXSYS_GetYValue((FX_DWORD)src_scan[2]), F XSYS_GetKValue((FX_DWORD)src_scan[3]),
438 r, g, b);
439 *dest_scan++ = FXRGB2GRAY(r, g, b);
440 src_scan += 4;
441 }
442 }
443 } else {
444 for (int row = 0; row < height; row ++) {
445 uint8_t* dest_scan = dest_buf + row * dest_pitch;
446 const uint8_t* src_scan = pSrcBitmap->GetScanline(src_top + row) + src_left * Bpp;
447 for (int col = 0; col < width; col ++) {
448 *dest_scan++ = FXRGB2GRAY(src_scan[2], src_scan[1], src_scan [0]);
449 src_scan += Bpp;
450 }
451 }
452 }
453 }
454 return TRUE;
455 }
456 inline void _ConvertBuffer_IndexCopy(uint8_t* dest_buf, int dest_pitch, int widt h, int height,
457 const CFX_DIBSource* pSrcBitmap, int src_le ft, int src_top)
458 {
459 if (pSrcBitmap->GetBPP() == 1) {
460 for (int row = 0; row < height; row ++) {
461 uint8_t* dest_scan = dest_buf + row * dest_pitch;
462 FXSYS_memset(dest_scan, 0, width);
463 const uint8_t* src_scan = pSrcBitmap->GetScanline(src_top + row);
464 for (int col = src_left; col < src_left + width; col ++) {
465 if (src_scan[col / 8] & (1 << (7 - col % 8))) {
466 *dest_scan = 1;
467 }
468 dest_scan ++;
469 }
470 }
471 } else {
472 for (int row = 0; row < height; row ++) {
473 uint8_t* dest_scan = dest_buf + row * dest_pitch;
474 const uint8_t* src_scan = pSrcBitmap->GetScanline(src_top + row) + s rc_left;
475 FXSYS_memcpy(dest_scan, src_scan, width);
476 }
477 }
478 }
479 FX_BOOL _ConvertBuffer_Plt2PltRgb8(uint8_t* dest_buf, int dest_pitch, int width, int height,
480 const CFX_DIBSource* pSrcBitmap, int src_left , int src_top, FX_DWORD* dst_plt, void* pIccTransform)
481 {
482 _ConvertBuffer_IndexCopy(dest_buf, dest_pitch, width, height, pSrcBitmap, sr c_left, src_top);
483 FX_DWORD* src_plt = pSrcBitmap->GetPalette();
484 int plt_size = pSrcBitmap->GetPaletteSize();
485 if (pIccTransform) {
486 FX_DWORD plt[256];
487 uint8_t* bgr_ptr = (uint8_t*)plt;
488 if (pSrcBitmap->IsCmykImage()) {
489 for (int i = 0; i < plt_size; i ++) {
490 plt[i] = FXCMYK_TODIB(src_plt[i]);
491 }
492 } else {
493 for (int i = 0; i < plt_size; i ++) {
494 *bgr_ptr++ = FXARGB_B(src_plt[i]);
495 *bgr_ptr++ = FXARGB_G(src_plt[i]);
496 *bgr_ptr++ = FXARGB_R(src_plt[i]);
497 }
498 bgr_ptr = (uint8_t*)plt;
499 }
500 ICodec_IccModule* pIccModule = CFX_GEModule::Get()->GetCodecModule()->Ge tIccModule();
501 pIccModule->TranslateScanline(pIccTransform, (uint8_t*)plt, (const uint8 _t*)plt, plt_size);
502 for (int i = 0; i < plt_size; i ++) {
503 dst_plt[i] = FXARGB_MAKE(0xff, bgr_ptr[2], bgr_ptr[1], bgr_ptr[0]);
504 bgr_ptr += 3;
505 }
506 } else {
507 if (pSrcBitmap->IsCmykImage()) {
508 for (int i = 0; i < plt_size; i ++) {
509 uint8_t r, g, b;
510 AdobeCMYK_to_sRGB1(FXSYS_GetCValue(src_plt[i]), FXSYS_GetMValue( src_plt[i]), FXSYS_GetYValue(src_plt[i]), FXSYS_GetKValue(src_plt[i]),
511 r, g, b);
512 dst_plt[i] = FXARGB_MAKE(0xff, r, g, b);
513 }
514 } else {
515 FXSYS_memcpy(dst_plt, src_plt, plt_size * 4);
516 }
517 }
518 return TRUE;
519 }
520 inline FX_BOOL _ConvertBuffer_Rgb2PltRgb8_NoTransform(uint8_t* dest_buf, int des t_pitch, int width, int height,
521 const CFX_DIBSource* pSrcBitmap, int src_left, int src_top, FX_DWORD* ds t_plt)
522 {
523 int bpp = pSrcBitmap->GetBPP() / 8;
524 int row, col;
525 CFX_Palette palette;
526 palette.BuildPalette(pSrcBitmap, FXDIB_PALETTE_LOC);
527 FX_DWORD* cLut = palette.GetColorLut();
528 FX_DWORD* aLut = palette.GetAmountLut();
529 if (cLut == NULL || aLut == NULL) {
530 return FALSE;
531 }
532 int lut = palette.Getlut();
533 FX_DWORD* pPalette = palette.GetPalette();
534 if (lut > 256) {
535 int err, min_err;
536 int lut_256 = lut - 256;
537 for (row = 0; row < lut_256; row++) {
538 min_err = 1000000;
539 uint8_t r, g, b;
540 _ColorDecode(cLut[row], r, g, b);
541 int clrindex = 0;
542 for (int col = 0; col < 256; col++) {
543 FX_DWORD p_color = *(pPalette + col);
544 int d_r = r - (uint8_t)(p_color >> 16);
545 int d_g = g - (uint8_t)(p_color >> 8);
546 int d_b = b - (uint8_t)(p_color);
547 err = d_r * d_r + d_g * d_g + d_b * d_b;
548 if (err < min_err) {
549 min_err = err;
550 clrindex = col;
551 }
552 }
553 aLut[row] = clrindex;
554 }
555 }
556 int32_t lut_1 = lut - 1;
557 for (row = 0; row < height; row ++) {
558 uint8_t* src_scan = (uint8_t*)pSrcBitmap->GetScanline(src_top + row) + s rc_left;
559 uint8_t* dest_scan = dest_buf + row * dest_pitch;
560 for (col = 0; col < width; col++) {
561 uint8_t* src_port = src_scan + col * bpp;
562 int r = src_port[2] & 0xf0;
563 int g = src_port[1] & 0xf0;
564 int b = src_port[0] & 0xf0;
565 FX_DWORD clrindex = (r << 4) + g + (b >> 4);
566 for (int i = lut_1; i >= 0; i--)
567 if (clrindex == cLut[i]) {
568 *(dest_scan + col) = (uint8_t)(aLut[i]);
569 break;
570 }
571 }
572 }
573 FXSYS_memcpy(dst_plt, pPalette, sizeof(FX_DWORD) * 256);
574 return TRUE;
575 }
576 FX_BOOL _ConvertBuffer_Rgb2PltRgb8(uint8_t* dest_buf, int dest_pitch, int width, int height,
577 const CFX_DIBSource* pSrcBitmap, int src_left , int src_top, FX_DWORD* dst_plt, void* pIccTransform)
578 {
579 FX_BOOL ret = _ConvertBuffer_Rgb2PltRgb8_NoTransform(dest_buf, dest_pitch, w idth, height, pSrcBitmap, src_left, src_top, dst_plt);
580 if (ret && pIccTransform) {
581 ICodec_IccModule* pIccModule = CFX_GEModule::Get()->GetCodecModule()->Ge tIccModule();
582 for (int i = 0; i < 256; i++) {
583 FX_ARGB* plt = dst_plt + i;
584 FX_ARGB plt_entry = FXARGB_TODIB(*plt);
585 pIccModule->TranslateScanline(pIccTransform, (uint8_t*)&plt_entry, ( const uint8_t*)&plt_entry, 1);
586 *plt = FXARGB_TODIB(plt_entry);
587 }
588 }
589 return ret;
590 }
591 FX_BOOL _ConvertBuffer_1bppMask2Rgb(FXDIB_Format dst_format, uint8_t* dest_buf, int dest_pitch, int width, int height,
592 const CFX_DIBSource* pSrcBitmap, int src_lef t, int src_top)
593 {
594 int comps = (dst_format & 0xff) / 8;
595 uint8_t set_gray, reset_gray;
596 set_gray = 0xff;
597 reset_gray = 0x00;
598 for (int row = 0; row < height; row ++) {
599 uint8_t* dest_scan = dest_buf + row * dest_pitch;
600 const uint8_t* src_scan = pSrcBitmap->GetScanline(src_top + row);
601 for (int col = src_left; col < src_left + width; col ++) {
602 if (src_scan[col / 8] & (1 << (7 - col % 8))) {
603 dest_scan[0] = set_gray;
604 dest_scan[1] = set_gray;
605 dest_scan[2] = set_gray;
606 } else {
607 dest_scan[0] = reset_gray;
608 dest_scan[1] = reset_gray;
609 dest_scan[2] = reset_gray;
610 }
611 dest_scan += comps;
612 }
613 }
614 return TRUE;
615 }
616 FX_BOOL _ConvertBuffer_8bppMask2Rgb(FXDIB_Format dst_format, uint8_t* dest_buf, int dest_pitch, int width, int height,
617 const CFX_DIBSource* pSrcBitmap, int src_lef t, int src_top)
618 {
619 int comps = (dst_format & 0xff) / 8;
620 for (int row = 0; row < height; row ++) {
621 uint8_t* dest_scan = dest_buf + row * dest_pitch;
622 const uint8_t* src_scan = pSrcBitmap->GetScanline(src_top + row) + src_l eft;
623 uint8_t src_pixel;
624 for (int col = 0; col < width; col ++) {
625 src_pixel = *src_scan++;
626 *dest_scan++ = src_pixel;
627 *dest_scan++ = src_pixel;
628 *dest_scan = src_pixel;
629 dest_scan += comps - 2;
630 }
631 }
632 return TRUE;
633 }
634 FX_BOOL _ConvertBuffer_1bppPlt2Rgb(FXDIB_Format dst_format, uint8_t* dest_buf, i nt dest_pitch, int width, int height,
635 const CFX_DIBSource* pSrcBitmap, int src_left , int src_top, void* pIccTransform)
636 {
637 int comps = (dst_format & 0xff) / 8;
638 FX_DWORD* src_plt = pSrcBitmap->GetPalette();
639 FX_DWORD plt[2];
640 uint8_t* bgr_ptr = (uint8_t*)plt; 523 uint8_t* bgr_ptr = (uint8_t*)plt;
641 if (pSrcBitmap->IsCmykImage()) { 524 if (pSrcBitmap->IsCmykImage()) {
642 plt[0] = FXCMYK_TODIB(src_plt[0]); 525 for (int i = 0; i < plt_size; i++) {
643 plt[1] = FXCMYK_TODIB(src_plt[1]); 526 plt[i] = FXCMYK_TODIB(src_plt[i]);
527 }
644 } else { 528 } else {
645 bgr_ptr[0] = FXARGB_B(src_plt[0]); 529 for (int i = 0; i < plt_size; i++) {
646 bgr_ptr[1] = FXARGB_G(src_plt[0]); 530 *bgr_ptr++ = FXARGB_B(src_plt[i]);
647 bgr_ptr[2] = FXARGB_R(src_plt[0]); 531 *bgr_ptr++ = FXARGB_G(src_plt[i]);
648 bgr_ptr[3] = FXARGB_B(src_plt[1]); 532 *bgr_ptr++ = FXARGB_R(src_plt[i]);
649 bgr_ptr[4] = FXARGB_G(src_plt[1]); 533 }
650 bgr_ptr[5] = FXARGB_R(src_plt[1]); 534 bgr_ptr = (uint8_t*)plt;
651 } 535 }
652 if (pIccTransform) { 536 ICodec_IccModule* pIccModule =
653 ICodec_IccModule* pIccModule = CFX_GEModule::Get()->GetCodecModule()->Ge tIccModule(); 537 CFX_GEModule::Get()->GetCodecModule()->GetIccModule();
654 pIccModule->TranslateScanline(pIccTransform, (uint8_t*)plt, (const uint8 _t*)plt, 2); 538 pIccModule->TranslateScanline(pIccTransform, (uint8_t*)plt,
539 (const uint8_t*)plt, plt_size);
540 for (int i = 0; i < plt_size; i++) {
541 dst_plt[i] = FXARGB_MAKE(0xff, bgr_ptr[2], bgr_ptr[1], bgr_ptr[0]);
542 bgr_ptr += 3;
543 }
544 } else {
545 if (pSrcBitmap->IsCmykImage()) {
546 for (int i = 0; i < plt_size; i++) {
547 uint8_t r, g, b;
548 AdobeCMYK_to_sRGB1(
549 FXSYS_GetCValue(src_plt[i]), FXSYS_GetMValue(src_plt[i]),
550 FXSYS_GetYValue(src_plt[i]), FXSYS_GetKValue(src_plt[i]), r, g, b);
551 dst_plt[i] = FXARGB_MAKE(0xff, r, g, b);
552 }
655 } else { 553 } else {
656 if (pSrcBitmap->IsCmykImage()) { 554 FXSYS_memcpy(dst_plt, src_plt, plt_size * 4);
657 AdobeCMYK_to_sRGB1(FXSYS_GetCValue(src_plt[0]), FXSYS_GetMValue(src_ plt[0]), FXSYS_GetYValue(src_plt[0]), FXSYS_GetKValue(src_plt[0]), 555 }
658 bgr_ptr[2], bgr_ptr[1], bgr_ptr[0]); 556 }
659 AdobeCMYK_to_sRGB1(FXSYS_GetCValue(src_plt[1]), FXSYS_GetMValue(src_ plt[1]), FXSYS_GetYValue(src_plt[1]), FXSYS_GetKValue(src_plt[1]), 557 return TRUE;
660 bgr_ptr[5], bgr_ptr[4], bgr_ptr[3]); 558 }
661 } 559 inline FX_BOOL _ConvertBuffer_Rgb2PltRgb8_NoTransform(
662 } 560 uint8_t* dest_buf,
663 for (int row = 0; row < height; row ++) { 561 int dest_pitch,
664 uint8_t* dest_scan = dest_buf + row * dest_pitch; 562 int width,
665 const uint8_t* src_scan = pSrcBitmap->GetScanline(src_top + row); 563 int height,
666 for (int col = src_left; col < src_left + width; col ++) { 564 const CFX_DIBSource* pSrcBitmap,
667 if (src_scan[col / 8] & (1 << (7 - col % 8))) { 565 int src_left,
668 *dest_scan++ = bgr_ptr[3]; 566 int src_top,
669 *dest_scan++ = bgr_ptr[4]; 567 FX_DWORD* dst_plt) {
670 *dest_scan = bgr_ptr[5]; 568 int bpp = pSrcBitmap->GetBPP() / 8;
671 } else { 569 int row, col;
672 *dest_scan++ = bgr_ptr[0]; 570 CFX_Palette palette;
673 *dest_scan++ = bgr_ptr[1]; 571 palette.BuildPalette(pSrcBitmap, FXDIB_PALETTE_LOC);
674 *dest_scan = bgr_ptr[2]; 572 FX_DWORD* cLut = palette.GetColorLut();
675 } 573 FX_DWORD* aLut = palette.GetAmountLut();
676 dest_scan += comps - 2; 574 if (cLut == NULL || aLut == NULL) {
677 } 575 return FALSE;
678 } 576 }
577 int lut = palette.Getlut();
578 FX_DWORD* pPalette = palette.GetPalette();
579 if (lut > 256) {
580 int err, min_err;
581 int lut_256 = lut - 256;
582 for (row = 0; row < lut_256; row++) {
583 min_err = 1000000;
584 uint8_t r, g, b;
585 _ColorDecode(cLut[row], r, g, b);
586 int clrindex = 0;
587 for (int col = 0; col < 256; col++) {
588 FX_DWORD p_color = *(pPalette + col);
589 int d_r = r - (uint8_t)(p_color >> 16);
590 int d_g = g - (uint8_t)(p_color >> 8);
591 int d_b = b - (uint8_t)(p_color);
592 err = d_r * d_r + d_g * d_g + d_b * d_b;
593 if (err < min_err) {
594 min_err = err;
595 clrindex = col;
596 }
597 }
598 aLut[row] = clrindex;
599 }
600 }
601 int32_t lut_1 = lut - 1;
602 for (row = 0; row < height; row++) {
603 uint8_t* src_scan =
604 (uint8_t*)pSrcBitmap->GetScanline(src_top + row) + src_left;
605 uint8_t* dest_scan = dest_buf + row * dest_pitch;
606 for (col = 0; col < width; col++) {
607 uint8_t* src_port = src_scan + col * bpp;
608 int r = src_port[2] & 0xf0;
609 int g = src_port[1] & 0xf0;
610 int b = src_port[0] & 0xf0;
611 FX_DWORD clrindex = (r << 4) + g + (b >> 4);
612 for (int i = lut_1; i >= 0; i--)
613 if (clrindex == cLut[i]) {
614 *(dest_scan + col) = (uint8_t)(aLut[i]);
615 break;
616 }
617 }
618 }
619 FXSYS_memcpy(dst_plt, pPalette, sizeof(FX_DWORD) * 256);
620 return TRUE;
621 }
622 FX_BOOL _ConvertBuffer_Rgb2PltRgb8(uint8_t* dest_buf,
623 int dest_pitch,
624 int width,
625 int height,
626 const CFX_DIBSource* pSrcBitmap,
627 int src_left,
628 int src_top,
629 FX_DWORD* dst_plt,
630 void* pIccTransform) {
631 FX_BOOL ret = _ConvertBuffer_Rgb2PltRgb8_NoTransform(
632 dest_buf, dest_pitch, width, height, pSrcBitmap, src_left, src_top,
633 dst_plt);
634 if (ret && pIccTransform) {
635 ICodec_IccModule* pIccModule =
636 CFX_GEModule::Get()->GetCodecModule()->GetIccModule();
637 for (int i = 0; i < 256; i++) {
638 FX_ARGB* plt = dst_plt + i;
639 FX_ARGB plt_entry = FXARGB_TODIB(*plt);
640 pIccModule->TranslateScanline(pIccTransform, (uint8_t*)&plt_entry,
641 (const uint8_t*)&plt_entry, 1);
642 *plt = FXARGB_TODIB(plt_entry);
643 }
644 }
645 return ret;
646 }
647 FX_BOOL _ConvertBuffer_1bppMask2Rgb(FXDIB_Format dst_format,
648 uint8_t* dest_buf,
649 int dest_pitch,
650 int width,
651 int height,
652 const CFX_DIBSource* pSrcBitmap,
653 int src_left,
654 int src_top) {
655 int comps = (dst_format & 0xff) / 8;
656 uint8_t set_gray, reset_gray;
657 set_gray = 0xff;
658 reset_gray = 0x00;
659 for (int row = 0; row < height; row++) {
660 uint8_t* dest_scan = dest_buf + row * dest_pitch;
661 const uint8_t* src_scan = pSrcBitmap->GetScanline(src_top + row);
662 for (int col = src_left; col < src_left + width; col++) {
663 if (src_scan[col / 8] & (1 << (7 - col % 8))) {
664 dest_scan[0] = set_gray;
665 dest_scan[1] = set_gray;
666 dest_scan[2] = set_gray;
667 } else {
668 dest_scan[0] = reset_gray;
669 dest_scan[1] = reset_gray;
670 dest_scan[2] = reset_gray;
671 }
672 dest_scan += comps;
673 }
674 }
675 return TRUE;
676 }
677 FX_BOOL _ConvertBuffer_8bppMask2Rgb(FXDIB_Format dst_format,
678 uint8_t* dest_buf,
679 int dest_pitch,
680 int width,
681 int height,
682 const CFX_DIBSource* pSrcBitmap,
683 int src_left,
684 int src_top) {
685 int comps = (dst_format & 0xff) / 8;
686 for (int row = 0; row < height; row++) {
687 uint8_t* dest_scan = dest_buf + row * dest_pitch;
688 const uint8_t* src_scan = pSrcBitmap->GetScanline(src_top + row) + src_left;
689 uint8_t src_pixel;
690 for (int col = 0; col < width; col++) {
691 src_pixel = *src_scan++;
692 *dest_scan++ = src_pixel;
693 *dest_scan++ = src_pixel;
694 *dest_scan = src_pixel;
695 dest_scan += comps - 2;
696 }
697 }
698 return TRUE;
699 }
700 FX_BOOL _ConvertBuffer_1bppPlt2Rgb(FXDIB_Format dst_format,
701 uint8_t* dest_buf,
702 int dest_pitch,
703 int width,
704 int height,
705 const CFX_DIBSource* pSrcBitmap,
706 int src_left,
707 int src_top,
708 void* pIccTransform) {
709 int comps = (dst_format & 0xff) / 8;
710 FX_DWORD* src_plt = pSrcBitmap->GetPalette();
711 FX_DWORD plt[2];
712 uint8_t* bgr_ptr = (uint8_t*)plt;
713 if (pSrcBitmap->IsCmykImage()) {
714 plt[0] = FXCMYK_TODIB(src_plt[0]);
715 plt[1] = FXCMYK_TODIB(src_plt[1]);
716 } else {
717 bgr_ptr[0] = FXARGB_B(src_plt[0]);
718 bgr_ptr[1] = FXARGB_G(src_plt[0]);
719 bgr_ptr[2] = FXARGB_R(src_plt[0]);
720 bgr_ptr[3] = FXARGB_B(src_plt[1]);
721 bgr_ptr[4] = FXARGB_G(src_plt[1]);
722 bgr_ptr[5] = FXARGB_R(src_plt[1]);
723 }
724 if (pIccTransform) {
725 ICodec_IccModule* pIccModule =
726 CFX_GEModule::Get()->GetCodecModule()->GetIccModule();
727 pIccModule->TranslateScanline(pIccTransform, (uint8_t*)plt,
728 (const uint8_t*)plt, 2);
729 } else {
730 if (pSrcBitmap->IsCmykImage()) {
731 AdobeCMYK_to_sRGB1(
732 FXSYS_GetCValue(src_plt[0]), FXSYS_GetMValue(src_plt[0]),
733 FXSYS_GetYValue(src_plt[0]), FXSYS_GetKValue(src_plt[0]), bgr_ptr[2],
734 bgr_ptr[1], bgr_ptr[0]);
735 AdobeCMYK_to_sRGB1(
736 FXSYS_GetCValue(src_plt[1]), FXSYS_GetMValue(src_plt[1]),
737 FXSYS_GetYValue(src_plt[1]), FXSYS_GetKValue(src_plt[1]), bgr_ptr[5],
738 bgr_ptr[4], bgr_ptr[3]);
739 }
740 }
741 for (int row = 0; row < height; row++) {
742 uint8_t* dest_scan = dest_buf + row * dest_pitch;
743 const uint8_t* src_scan = pSrcBitmap->GetScanline(src_top + row);
744 for (int col = src_left; col < src_left + width; col++) {
745 if (src_scan[col / 8] & (1 << (7 - col % 8))) {
746 *dest_scan++ = bgr_ptr[3];
747 *dest_scan++ = bgr_ptr[4];
748 *dest_scan = bgr_ptr[5];
749 } else {
750 *dest_scan++ = bgr_ptr[0];
751 *dest_scan++ = bgr_ptr[1];
752 *dest_scan = bgr_ptr[2];
753 }
754 dest_scan += comps - 2;
755 }
756 }
757 return TRUE;
758 }
759 FX_BOOL _ConvertBuffer_8bppPlt2Rgb(FXDIB_Format dst_format,
760 uint8_t* dest_buf,
761 int dest_pitch,
762 int width,
763 int height,
764 const CFX_DIBSource* pSrcBitmap,
765 int src_left,
766 int src_top,
767 void* pIccTransform) {
768 int comps = (dst_format & 0xff) / 8;
769 FX_DWORD* src_plt = pSrcBitmap->GetPalette();
770 FX_DWORD plt[256];
771 uint8_t* bgr_ptr = (uint8_t*)plt;
772 if (!pSrcBitmap->IsCmykImage()) {
773 for (int i = 0; i < 256; i++) {
774 *bgr_ptr++ = FXARGB_B(src_plt[i]);
775 *bgr_ptr++ = FXARGB_G(src_plt[i]);
776 *bgr_ptr++ = FXARGB_R(src_plt[i]);
777 }
778 bgr_ptr = (uint8_t*)plt;
779 }
780 if (pIccTransform) {
781 if (pSrcBitmap->IsCmykImage()) {
782 for (int i = 0; i < 256; i++) {
783 plt[i] = FXCMYK_TODIB(src_plt[i]);
784 }
785 }
786 ICodec_IccModule* pIccModule =
787 CFX_GEModule::Get()->GetCodecModule()->GetIccModule();
788 pIccModule->TranslateScanline(pIccTransform, (uint8_t*)plt,
789 (const uint8_t*)plt, 256);
790 } else {
791 if (pSrcBitmap->IsCmykImage()) {
792 for (int i = 0; i < 256; i++) {
793 AdobeCMYK_to_sRGB1(
794 FXSYS_GetCValue(src_plt[i]), FXSYS_GetMValue(src_plt[i]),
795 FXSYS_GetYValue(src_plt[i]), FXSYS_GetKValue(src_plt[i]),
796 bgr_ptr[2], bgr_ptr[1], bgr_ptr[0]);
797 bgr_ptr += 3;
798 }
799 bgr_ptr = (uint8_t*)plt;
800 }
801 }
802 for (int row = 0; row < height; row++) {
803 uint8_t* dest_scan = dest_buf + row * dest_pitch;
804 const uint8_t* src_scan = pSrcBitmap->GetScanline(src_top + row) + src_left;
805 for (int col = 0; col < width; col++) {
806 uint8_t* src_pixel = bgr_ptr + 3 * (*src_scan++);
807 *dest_scan++ = *src_pixel++;
808 *dest_scan++ = *src_pixel++;
809 *dest_scan = *src_pixel++;
810 dest_scan += comps - 2;
811 }
812 }
813 return TRUE;
814 }
815 FX_BOOL _ConvertBuffer_24bppRgb2Rgb24(uint8_t* dest_buf,
816 int dest_pitch,
817 int width,
818 int height,
819 const CFX_DIBSource* pSrcBitmap,
820 int src_left,
821 int src_top,
822 void* pIccTransform) {
823 if (pIccTransform) {
824 ICodec_IccModule* pIccModule =
825 CFX_GEModule::Get()->GetCodecModule()->GetIccModule();
826 for (int row = 0; row < height; row++) {
827 uint8_t* dest_scan = dest_buf + row * dest_pitch;
828 const uint8_t* src_scan =
829 pSrcBitmap->GetScanline(src_top + row) + src_left * 3;
830 pIccModule->TranslateScanline(pIccTransform, dest_scan, src_scan, width);
831 }
832 } else {
833 for (int row = 0; row < height; row++) {
834 uint8_t* dest_scan = dest_buf + row * dest_pitch;
835 const uint8_t* src_scan =
836 pSrcBitmap->GetScanline(src_top + row) + src_left * 3;
837 FXSYS_memcpy(dest_scan, src_scan, width * 3);
838 }
839 }
840 return TRUE;
841 }
842 FX_BOOL _ConvertBuffer_32bppRgb2Rgb24(uint8_t* dest_buf,
843 int dest_pitch,
844 int width,
845 int height,
846 const CFX_DIBSource* pSrcBitmap,
847 int src_left,
848 int src_top,
849 void* pIccTransform) {
850 for (int row = 0; row < height; row++) {
851 uint8_t* dest_scan = dest_buf + row * dest_pitch;
852 const uint8_t* src_scan =
853 pSrcBitmap->GetScanline(src_top + row) + src_left * 4;
854 for (int col = 0; col < width; col++) {
855 *dest_scan++ = *src_scan++;
856 *dest_scan++ = *src_scan++;
857 *dest_scan++ = *src_scan++;
858 src_scan++;
859 }
860 }
861 if (pIccTransform) {
862 ICodec_IccModule* pIccModule =
863 CFX_GEModule::Get()->GetCodecModule()->GetIccModule();
864 for (int row = 0; row < height; row++) {
865 uint8_t* dest_scan = dest_buf + row * dest_pitch;
866 pIccModule->TranslateScanline(pIccTransform, dest_scan, dest_scan, width);
867 }
868 }
869 return TRUE;
870 }
871 FX_BOOL _ConvertBuffer_Rgb2Rgb32(uint8_t* dest_buf,
872 int dest_pitch,
873 int width,
874 int height,
875 const CFX_DIBSource* pSrcBitmap,
876 int src_left,
877 int src_top,
878 void* pIccTransform) {
879 int comps = pSrcBitmap->GetBPP() / 8;
880 if (pIccTransform) {
881 ICodec_IccModule* pIccModule =
882 CFX_GEModule::Get()->GetCodecModule()->GetIccModule();
883 for (int row = 0; row < height; row++) {
884 uint8_t* dest_scan = dest_buf + row * dest_pitch;
885 const uint8_t* src_scan =
886 pSrcBitmap->GetScanline(src_top + row) + src_left * comps;
887 for (int col = 0; col < width; col++) {
888 pIccModule->TranslateScanline(pIccTransform, dest_scan, src_scan, 1);
889 dest_scan += 4;
890 src_scan += comps;
891 }
892 }
893 } else {
894 for (int row = 0; row < height; row++) {
895 uint8_t* dest_scan = dest_buf + row * dest_pitch;
896 const uint8_t* src_scan =
897 pSrcBitmap->GetScanline(src_top + row) + src_left * comps;
898 for (int col = 0; col < width; col++) {
899 *dest_scan++ = *src_scan++;
900 *dest_scan++ = *src_scan++;
901 *dest_scan++ = *src_scan++;
902 dest_scan++;
903 src_scan += comps - 3;
904 }
905 }
906 }
907 return TRUE;
908 }
909 FX_BOOL _ConvertBuffer_32bppCmyk2Rgb32(uint8_t* dest_buf,
910 int dest_pitch,
911 int width,
912 int height,
913 const CFX_DIBSource* pSrcBitmap,
914 int src_left,
915 int src_top,
916 void* pIccTransform) {
917 if (pIccTransform) {
918 ICodec_IccModule* pIccModule =
919 CFX_GEModule::Get()->GetCodecModule()->GetIccModule();
920 for (int row = 0; row < height; row++) {
921 uint8_t* dest_scan = dest_buf + row * dest_pitch;
922 const uint8_t* src_scan =
923 pSrcBitmap->GetScanline(src_top + row) + src_left * 4;
924 for (int col = 0; col < width; col++) {
925 pIccModule->TranslateScanline(pIccTransform, dest_scan, src_scan, 1);
926 dest_scan += 4;
927 src_scan += 4;
928 }
929 }
930 } else {
931 for (int row = 0; row < height; row++) {
932 uint8_t* dest_scan = dest_buf + row * dest_pitch;
933 const uint8_t* src_scan =
934 pSrcBitmap->GetScanline(src_top + row) + src_left * 4;
935 for (int col = 0; col < width; col++) {
936 AdobeCMYK_to_sRGB1(src_scan[0], src_scan[1], src_scan[2], src_scan[3],
937 dest_scan[2], dest_scan[1], dest_scan[0]);
938 dest_scan += 4;
939 src_scan += 4;
940 }
941 }
942 }
943 return TRUE;
944 }
945 FX_BOOL ConvertBuffer(FXDIB_Format dest_format,
946 uint8_t* dest_buf,
947 int dest_pitch,
948 int width,
949 int height,
950 const CFX_DIBSource* pSrcBitmap,
951 int src_left,
952 int src_top,
953 FX_DWORD*& d_pal,
954 void* pIccTransform) {
955 FXDIB_Format src_format = pSrcBitmap->GetFormat();
956 if (!CFX_GEModule::Get()->GetCodecModule() ||
957 !CFX_GEModule::Get()->GetCodecModule()->GetIccModule()) {
958 pIccTransform = NULL;
959 }
960 switch (dest_format) {
961 case FXDIB_Invalid:
962 case FXDIB_1bppCmyk:
963 case FXDIB_1bppMask:
964 case FXDIB_1bppRgb:
965 ASSERT(FALSE);
966 return FALSE;
967 case FXDIB_8bppMask: {
968 if ((src_format & 0xff) == 1) {
969 if (pSrcBitmap->GetPalette()) {
970 return _ConvertBuffer_1bppPlt2Gray(dest_buf, dest_pitch, width,
971 height, pSrcBitmap, src_left,
972 src_top, pIccTransform);
973 }
974 return _ConvertBuffer_1bppMask2Gray(dest_buf, dest_pitch, width, height,
975 pSrcBitmap, src_left, src_top);
976 }
977 if ((src_format & 0xff) == 8) {
978 if (pSrcBitmap->GetPalette()) {
979 return _ConvertBuffer_8bppPlt2Gray(dest_buf, dest_pitch, width,
980 height, pSrcBitmap, src_left,
981 src_top, pIccTransform);
982 }
983 return _ConvertBuffer_8bppMask2Gray(dest_buf, dest_pitch, width, height,
984 pSrcBitmap, src_left, src_top);
985 }
986 if ((src_format & 0xff) >= 24) {
987 return _ConvertBuffer_RgbOrCmyk2Gray(dest_buf, dest_pitch, width,
988 height, pSrcBitmap, src_left,
989 src_top, pIccTransform);
990 }
991 return FALSE;
992 }
993 case FXDIB_8bppRgb:
994 case FXDIB_8bppRgba: {
995 if ((src_format & 0xff) == 8 && pSrcBitmap->GetPalette() == NULL) {
996 return ConvertBuffer(FXDIB_8bppMask, dest_buf, dest_pitch, width,
997 height, pSrcBitmap, src_left, src_top, d_pal,
998 pIccTransform);
999 }
1000 d_pal = FX_Alloc(FX_DWORD, 256);
1001 if (((src_format & 0xff) == 1 || (src_format & 0xff) == 8) &&
1002 pSrcBitmap->GetPalette()) {
1003 return _ConvertBuffer_Plt2PltRgb8(dest_buf, dest_pitch, width, height,
1004 pSrcBitmap, src_left, src_top, d_pal,
1005 pIccTransform);
1006 }
1007 if ((src_format & 0xff) >= 24) {
1008 return _ConvertBuffer_Rgb2PltRgb8(dest_buf, dest_pitch, width, height,
1009 pSrcBitmap, src_left, src_top, d_pal,
1010 pIccTransform);
1011 }
1012 return FALSE;
1013 }
1014 case FXDIB_Rgb:
1015 case FXDIB_Rgba: {
1016 if ((src_format & 0xff) == 1) {
1017 if (pSrcBitmap->GetPalette()) {
1018 return _ConvertBuffer_1bppPlt2Rgb(dest_format, dest_buf, dest_pitch,
1019 width, height, pSrcBitmap, src_left,
1020 src_top, pIccTransform);
1021 }
1022 return _ConvertBuffer_1bppMask2Rgb(dest_format, dest_buf, dest_pitch,
1023 width, height, pSrcBitmap, src_left,
1024 src_top);
1025 }
1026 if ((src_format & 0xff) == 8) {
1027 if (pSrcBitmap->GetPalette()) {
1028 return _ConvertBuffer_8bppPlt2Rgb(dest_format, dest_buf, dest_pitch,
1029 width, height, pSrcBitmap, src_left,
1030 src_top, pIccTransform);
1031 }
1032 return _ConvertBuffer_8bppMask2Rgb(dest_format, dest_buf, dest_pitch,
1033 width, height, pSrcBitmap, src_left,
1034 src_top);
1035 }
1036 if ((src_format & 0xff) == 24) {
1037 return _ConvertBuffer_24bppRgb2Rgb24(dest_buf, dest_pitch, width,
1038 height, pSrcBitmap, src_left,
1039 src_top, pIccTransform);
1040 }
1041 if ((src_format & 0xff) == 32) {
1042 return _ConvertBuffer_32bppRgb2Rgb24(dest_buf, dest_pitch, width,
1043 height, pSrcBitmap, src_left,
1044 src_top, pIccTransform);
1045 }
1046 return FALSE;
1047 }
1048 case FXDIB_Argb:
1049 case FXDIB_Rgb32: {
1050 if ((src_format & 0xff) == 1) {
1051 if (pSrcBitmap->GetPalette()) {
1052 return _ConvertBuffer_1bppPlt2Rgb(dest_format, dest_buf, dest_pitch,
1053 width, height, pSrcBitmap, src_left,
1054 src_top, pIccTransform);
1055 }
1056 return _ConvertBuffer_1bppMask2Rgb(dest_format, dest_buf, dest_pitch,
1057 width, height, pSrcBitmap, src_left,
1058 src_top);
1059 }
1060 if ((src_format & 0xff) == 8) {
1061 if (pSrcBitmap->GetPalette()) {
1062 return _ConvertBuffer_8bppPlt2Rgb(dest_format, dest_buf, dest_pitch,
1063 width, height, pSrcBitmap, src_left,
1064 src_top, pIccTransform);
1065 }
1066 return _ConvertBuffer_8bppMask2Rgb(dest_format, dest_buf, dest_pitch,
1067 width, height, pSrcBitmap, src_left,
1068 src_top);
1069 }
1070 if ((src_format & 0xff) >= 24) {
1071 if (src_format & 0x0400) {
1072 return _ConvertBuffer_32bppCmyk2Rgb32(dest_buf, dest_pitch, width,
1073 height, pSrcBitmap, src_left,
1074 src_top, pIccTransform);
1075 }
1076 return _ConvertBuffer_Rgb2Rgb32(dest_buf, dest_pitch, width, height,
1077 pSrcBitmap, src_left, src_top,
1078 pIccTransform);
1079 }
1080 return FALSE;
1081 }
1082 default:
1083 return FALSE;
1084 }
1085 return FALSE;
1086 }
1087 CFX_DIBitmap* CFX_DIBSource::CloneConvert(FXDIB_Format dest_format,
1088 const FX_RECT* pClip,
1089 void* pIccTransform) const {
1090 if (dest_format == GetFormat() && pIccTransform == NULL) {
1091 return Clone(pClip);
1092 }
1093 if (pClip) {
1094 CFX_DIBitmap* pClone = Clone(pClip);
1095 if (pClone == NULL) {
1096 return NULL;
1097 }
1098 if (!pClone->ConvertFormat(dest_format, pIccTransform)) {
1099 delete pClone;
1100 return NULL;
1101 }
1102 return pClone;
1103 }
1104 CFX_DIBitmap* pClone = new CFX_DIBitmap;
1105 if (!pClone->Create(m_Width, m_Height, dest_format)) {
1106 delete pClone;
1107 return NULL;
1108 }
1109 FX_BOOL ret = TRUE;
1110 CFX_DIBitmap* pSrcAlpha = NULL;
1111 if (m_AlphaFlag & 2) {
1112 pSrcAlpha = (GetFormat() == FXDIB_Argb) ? GetAlphaMask() : m_pAlphaMask;
1113 if (pSrcAlpha == NULL) {
1114 delete pClone;
1115 return NULL;
1116 }
1117 }
1118 if (dest_format & 0x0200) {
1119 if (dest_format == FXDIB_Argb)
1120 ret = pSrcAlpha ? pClone->LoadChannel(FXDIB_Alpha, pSrcAlpha, FXDIB_Alpha)
1121 : pClone->LoadChannel(FXDIB_Alpha, 0xff);
1122 else {
1123 ret = pClone->CopyAlphaMask(pSrcAlpha);
1124 }
1125 }
1126 if (pSrcAlpha && pSrcAlpha != m_pAlphaMask) {
1127 delete pSrcAlpha;
1128 pSrcAlpha = NULL;
1129 }
1130 if (!ret) {
1131 delete pClone;
1132 return NULL;
1133 }
1134 FX_DWORD* pal_8bpp = NULL;
1135 ret = ConvertBuffer(dest_format, pClone->GetBuffer(), pClone->GetPitch(),
1136 m_Width, m_Height, this, 0, 0, pal_8bpp, pIccTransform);
1137 if (!ret) {
1138 if (pal_8bpp) {
1139 FX_Free(pal_8bpp);
1140 }
1141 delete pClone;
1142 return NULL;
1143 }
1144 if (pal_8bpp) {
1145 pClone->CopyPalette(pal_8bpp);
1146 FX_Free(pal_8bpp);
1147 pal_8bpp = NULL;
1148 }
1149 return pClone;
1150 }
1151 FX_BOOL CFX_DIBitmap::ConvertFormat(FXDIB_Format dest_format,
1152 void* pIccTransform) {
1153 FXDIB_Format src_format = GetFormat();
1154 if (dest_format == src_format && pIccTransform == NULL) {
679 return TRUE; 1155 return TRUE;
680 } 1156 }
681 FX_BOOL _ConvertBuffer_8bppPlt2Rgb(FXDIB_Format dst_format, uint8_t* dest_buf, i nt dest_pitch, int width, int height, 1157 if (dest_format == FXDIB_8bppMask && src_format == FXDIB_8bppRgb &&
682 const CFX_DIBSource* pSrcBitmap, int src_left , int src_top, void* pIccTransform) 1158 m_pPalette == NULL) {
683 { 1159 m_AlphaFlag = 1;
684 int comps = (dst_format & 0xff) / 8; 1160 return TRUE;
685 FX_DWORD* src_plt = pSrcBitmap->GetPalette(); 1161 }
686 FX_DWORD plt[256]; 1162 if (dest_format == FXDIB_Argb && src_format == FXDIB_Rgb32 &&
687 uint8_t* bgr_ptr = (uint8_t*)plt; 1163 pIccTransform == NULL) {
688 if (!pSrcBitmap->IsCmykImage()) { 1164 m_AlphaFlag = 2;
689 for (int i = 0; i < 256; i++) { 1165 for (int row = 0; row < m_Height; row++) {
690 *bgr_ptr++ = FXARGB_B(src_plt[i]); 1166 uint8_t* scanline = m_pBuffer + row * m_Pitch + 3;
691 *bgr_ptr++ = FXARGB_G(src_plt[i]); 1167 for (int col = 0; col < m_Width; col++) {
692 *bgr_ptr++ = FXARGB_R(src_plt[i]); 1168 *scanline = 0xff;
693 } 1169 scanline += 4;
694 bgr_ptr = (uint8_t*)plt; 1170 }
695 } 1171 }
696 if (pIccTransform) { 1172 return TRUE;
697 if (pSrcBitmap->IsCmykImage()) { 1173 }
698 for (int i = 0; i < 256; i++) { 1174 int dest_bpp = dest_format & 0xff;
699 plt[i] = FXCMYK_TODIB(src_plt[i]); 1175 int dest_pitch = (dest_bpp * m_Width + 31) / 32 * 4;
700 } 1176 uint8_t* dest_buf = FX_TryAlloc(uint8_t, dest_pitch * m_Height + 4);
701 } 1177 if (dest_buf == NULL) {
702 ICodec_IccModule* pIccModule = CFX_GEModule::Get()->GetCodecModule()->Ge tIccModule(); 1178 return FALSE;
703 pIccModule->TranslateScanline(pIccTransform, (uint8_t*)plt, (const uint8 _t*)plt, 256); 1179 }
1180 CFX_DIBitmap* pAlphaMask = NULL;
1181 if (dest_format == FXDIB_Argb) {
1182 FXSYS_memset(dest_buf, 0xff, dest_pitch * m_Height + 4);
1183 if (m_pAlphaMask) {
1184 for (int row = 0; row < m_Height; row++) {
1185 uint8_t* pDstScanline = dest_buf + row * dest_pitch + 3;
1186 const uint8_t* pSrcScanline = m_pAlphaMask->GetScanline(row);
1187 for (int col = 0; col < m_Width; col++) {
1188 *pDstScanline = *pSrcScanline++;
1189 pDstScanline += 4;
1190 }
1191 }
1192 }
1193 } else if (dest_format & 0x0200) {
1194 if (src_format == FXDIB_Argb) {
1195 pAlphaMask = GetAlphaMask();
1196 if (pAlphaMask == NULL) {
1197 FX_Free(dest_buf);
1198 return FALSE;
1199 }
704 } else { 1200 } else {
705 if (pSrcBitmap->IsCmykImage()) { 1201 if (m_pAlphaMask == NULL) {
706 for (int i = 0; i < 256; i++) { 1202 if (!BuildAlphaMask()) {
707 AdobeCMYK_to_sRGB1(FXSYS_GetCValue(src_plt[i]), FXSYS_GetMValue( src_plt[i]), FXSYS_GetYValue(src_plt[i]), FXSYS_GetKValue(src_plt[i]), 1203 FX_Free(dest_buf);
708 bgr_ptr[2], bgr_ptr[1], bgr_ptr[0]); 1204 return FALSE;
709 bgr_ptr += 3; 1205 }
710 } 1206 pAlphaMask = m_pAlphaMask;
711 bgr_ptr = (uint8_t*)plt; 1207 m_pAlphaMask = NULL;
712 } 1208 } else {
713 } 1209 pAlphaMask = m_pAlphaMask;
714 for (int row = 0; row < height; row ++) { 1210 }
715 uint8_t* dest_scan = dest_buf + row * dest_pitch; 1211 }
716 const uint8_t* src_scan = pSrcBitmap->GetScanline(src_top + row) + src_l eft; 1212 }
717 for (int col = 0; col < width; col ++) { 1213 FX_BOOL ret = FALSE;
718 uint8_t* src_pixel = bgr_ptr + 3 * (*src_scan++); 1214 FX_DWORD* pal_8bpp = NULL;
719 *dest_scan++ = *src_pixel++; 1215 ret = ConvertBuffer(dest_format, dest_buf, dest_pitch, m_Width, m_Height,
720 *dest_scan++ = *src_pixel++; 1216 this, 0, 0, pal_8bpp, pIccTransform);
721 *dest_scan = *src_pixel++; 1217 if (!ret) {
722 dest_scan += comps - 2; 1218 if (pal_8bpp) {
723 } 1219 FX_Free(pal_8bpp);
724 } 1220 }
725 return TRUE; 1221 if (pAlphaMask != m_pAlphaMask) {
726 } 1222 delete pAlphaMask;
727 FX_BOOL _ConvertBuffer_24bppRgb2Rgb24(uint8_t* dest_buf, int dest_pitch, int wid th, int height, 1223 }
728 const CFX_DIBSource* pSrcBitmap, int src_l eft, int src_top, void* pIccTransform) 1224 if (dest_buf) {
729 { 1225 FX_Free(dest_buf);
730 if (pIccTransform) {
731 ICodec_IccModule* pIccModule = CFX_GEModule::Get()->GetCodecModule()->Ge tIccModule();
732 for (int row = 0; row < height; row ++) {
733 uint8_t* dest_scan = dest_buf + row * dest_pitch;
734 const uint8_t* src_scan = pSrcBitmap->GetScanline(src_top + row) + s rc_left * 3;
735 pIccModule->TranslateScanline(pIccTransform, dest_scan, src_scan, wi dth);
736 }
737 } else {
738 for (int row = 0; row < height; row ++) {
739 uint8_t* dest_scan = dest_buf + row * dest_pitch;
740 const uint8_t* src_scan = pSrcBitmap->GetScanline(src_top + row) + s rc_left * 3;
741 FXSYS_memcpy(dest_scan, src_scan, width * 3);
742 }
743 }
744 return TRUE;
745 }
746 FX_BOOL _ConvertBuffer_32bppRgb2Rgb24(uint8_t* dest_buf, int dest_pitch, int wid th, int height,
747 const CFX_DIBSource* pSrcBitmap, int src_l eft, int src_top, void* pIccTransform)
748 {
749 for (int row = 0; row < height; row ++) {
750 uint8_t* dest_scan = dest_buf + row * dest_pitch;
751 const uint8_t* src_scan = pSrcBitmap->GetScanline(src_top + row) + src_l eft * 4;
752 for (int col = 0; col < width; col ++) {
753 *dest_scan++ = *src_scan++;
754 *dest_scan++ = *src_scan++;
755 *dest_scan++ = *src_scan++;
756 src_scan++;
757 }
758 }
759 if (pIccTransform) {
760 ICodec_IccModule* pIccModule = CFX_GEModule::Get()->GetCodecModule()->Ge tIccModule();
761 for (int row = 0; row < height; row ++) {
762 uint8_t* dest_scan = dest_buf + row * dest_pitch;
763 pIccModule->TranslateScanline(pIccTransform, dest_scan, dest_scan, w idth);
764 }
765 }
766 return TRUE;
767 }
768 FX_BOOL _ConvertBuffer_Rgb2Rgb32(uint8_t* dest_buf, int dest_pitch, int width, i nt height,
769 const CFX_DIBSource* pSrcBitmap, int src_left, int src_top, void* pIccTransform)
770 {
771 int comps = pSrcBitmap->GetBPP() / 8;
772 if (pIccTransform) {
773 ICodec_IccModule* pIccModule = CFX_GEModule::Get()->GetCodecModule()->Ge tIccModule();
774 for (int row = 0; row < height; row ++) {
775 uint8_t* dest_scan = dest_buf + row * dest_pitch;
776 const uint8_t* src_scan = pSrcBitmap->GetScanline(src_top + row) + s rc_left * comps;
777 for (int col = 0; col < width; col ++) {
778 pIccModule->TranslateScanline(pIccTransform, dest_scan, src_scan , 1);
779 dest_scan += 4;
780 src_scan += comps;
781 }
782 }
783 } else {
784 for (int row = 0; row < height; row ++) {
785 uint8_t* dest_scan = dest_buf + row * dest_pitch;
786 const uint8_t* src_scan = pSrcBitmap->GetScanline(src_top + row) + s rc_left * comps;
787 for (int col = 0; col < width; col ++) {
788 *dest_scan++ = *src_scan++;
789 *dest_scan++ = *src_scan++;
790 *dest_scan++ = *src_scan++;
791 dest_scan++;
792 src_scan += comps - 3;
793 }
794 }
795 }
796 return TRUE;
797 }
798 FX_BOOL _ConvertBuffer_32bppCmyk2Rgb32(uint8_t* dest_buf, int dest_pitch, int wi dth, int height,
799 const CFX_DIBSource* pSrcBitmap, int src_ left, int src_top, void* pIccTransform)
800 {
801 if (pIccTransform) {
802 ICodec_IccModule* pIccModule = CFX_GEModule::Get()->GetCodecModule()->Ge tIccModule();
803 for (int row = 0; row < height; row ++) {
804 uint8_t* dest_scan = dest_buf + row * dest_pitch;
805 const uint8_t* src_scan = pSrcBitmap->GetScanline(src_top + row) + s rc_left * 4;
806 for (int col = 0; col < width; col ++) {
807 pIccModule->TranslateScanline(pIccTransform, dest_scan, src_scan , 1);
808 dest_scan += 4;
809 src_scan += 4;
810 }
811 }
812 } else {
813 for (int row = 0; row < height; row ++) {
814 uint8_t* dest_scan = dest_buf + row * dest_pitch;
815 const uint8_t* src_scan = pSrcBitmap->GetScanline(src_top + row) + s rc_left * 4;
816 for (int col = 0; col < width; col ++) {
817 AdobeCMYK_to_sRGB1(src_scan[0], src_scan[1], src_scan[2], src_sc an[3],
818 dest_scan[2], dest_scan[1], dest_scan[0]);
819 dest_scan += 4;
820 src_scan += 4;
821 }
822 }
823 }
824 return TRUE;
825 }
826 FX_BOOL ConvertBuffer(FXDIB_Format dest_format, uint8_t* dest_buf, int dest_pitc h, int width, int height,
827 const CFX_DIBSource* pSrcBitmap, int src_left, int src_top , FX_DWORD*& d_pal, void* pIccTransform)
828 {
829 FXDIB_Format src_format = pSrcBitmap->GetFormat();
830 if (!CFX_GEModule::Get()->GetCodecModule() || !CFX_GEModule::Get()->GetCodec Module()->GetIccModule()) {
831 pIccTransform = NULL;
832 }
833 switch (dest_format) {
834 case FXDIB_Invalid:
835 case FXDIB_1bppCmyk:
836 case FXDIB_1bppMask:
837 case FXDIB_1bppRgb:
838 ASSERT(FALSE);
839 return FALSE;
840 case FXDIB_8bppMask: {
841 if ((src_format & 0xff) == 1) {
842 if (pSrcBitmap->GetPalette()) {
843 return _ConvertBuffer_1bppPlt2Gray(dest_buf, dest_pitch, width, height, pSrcBitmap, src_left, src_top, pIccTransform);
844 }
845 return _ConvertBuffer_1bppMask2Gray(dest_buf, dest_pitch, wi dth, height, pSrcBitmap, src_left, src_top);
846 }
847 if ((src_format & 0xff) == 8) {
848 if (pSrcBitmap->GetPalette()) {
849 return _ConvertBuffer_8bppPlt2Gray(dest_buf, dest_pitch, width, height, pSrcBitmap, src_left, src_top, pIccTransform);
850 }
851 return _ConvertBuffer_8bppMask2Gray(dest_buf, dest_pitch, wi dth, height, pSrcBitmap, src_left, src_top);
852 }
853 if ((src_format & 0xff) >= 24) {
854 return _ConvertBuffer_RgbOrCmyk2Gray(dest_buf, dest_pitch, w idth, height, pSrcBitmap, src_left, src_top, pIccTransform);
855 }
856 return FALSE;
857 }
858 case FXDIB_8bppRgb:
859 case FXDIB_8bppRgba: {
860 if ((src_format & 0xff) == 8 && pSrcBitmap->GetPalette() == NULL ) {
861 return ConvertBuffer(FXDIB_8bppMask, dest_buf, dest_pitch, w idth, height, pSrcBitmap, src_left, src_top, d_pal, pIccTransform);
862 }
863 d_pal = FX_Alloc(FX_DWORD, 256);
864 if (((src_format & 0xff) == 1 || (src_format & 0xff) == 8) && pS rcBitmap->GetPalette()) {
865 return _ConvertBuffer_Plt2PltRgb8(dest_buf, dest_pitch, widt h, height, pSrcBitmap, src_left, src_top, d_pal, pIccTransform);
866 }
867 if ((src_format & 0xff) >= 24) {
868 return _ConvertBuffer_Rgb2PltRgb8(dest_buf, dest_pitch, widt h, height, pSrcBitmap, src_left, src_top, d_pal, pIccTransform);
869 }
870 return FALSE;
871 }
872 case FXDIB_Rgb:
873 case FXDIB_Rgba: {
874 if ((src_format & 0xff) == 1) {
875 if (pSrcBitmap->GetPalette()) {
876 return _ConvertBuffer_1bppPlt2Rgb(dest_format, dest_buf, dest_pitch, width, height, pSrcBitmap, src_left, src_top, pIccTransform);
877 }
878 return _ConvertBuffer_1bppMask2Rgb(dest_format, dest_buf, de st_pitch, width, height, pSrcBitmap, src_left, src_top);
879 }
880 if ((src_format & 0xff) == 8) {
881 if (pSrcBitmap->GetPalette()) {
882 return _ConvertBuffer_8bppPlt2Rgb(dest_format, dest_buf, dest_pitch, width, height, pSrcBitmap, src_left, src_top, pIccTransform);
883 }
884 return _ConvertBuffer_8bppMask2Rgb(dest_format, dest_buf, de st_pitch, width, height, pSrcBitmap, src_left, src_top);
885 }
886 if ((src_format & 0xff) == 24) {
887 return _ConvertBuffer_24bppRgb2Rgb24(dest_buf, dest_pitch, w idth, height, pSrcBitmap, src_left, src_top, pIccTransform);
888 }
889 if ((src_format & 0xff) == 32) {
890 return _ConvertBuffer_32bppRgb2Rgb24(dest_buf, dest_pitch, w idth, height, pSrcBitmap, src_left, src_top, pIccTransform);
891 }
892 return FALSE;
893 }
894 case FXDIB_Argb:
895 case FXDIB_Rgb32: {
896 if ((src_format & 0xff) == 1) {
897 if (pSrcBitmap->GetPalette()) {
898 return _ConvertBuffer_1bppPlt2Rgb(dest_format, dest_buf, dest_pitch, width, height, pSrcBitmap, src_left, src_top, pIccTransform);
899 }
900 return _ConvertBuffer_1bppMask2Rgb(dest_format, dest_buf, de st_pitch, width, height, pSrcBitmap, src_left, src_top);
901 }
902 if ((src_format & 0xff) == 8) {
903 if (pSrcBitmap->GetPalette()) {
904 return _ConvertBuffer_8bppPlt2Rgb(dest_format, dest_buf, dest_pitch, width, height, pSrcBitmap, src_left, src_top, pIccTransform);
905 }
906 return _ConvertBuffer_8bppMask2Rgb(dest_format, dest_buf, de st_pitch, width, height, pSrcBitmap, src_left, src_top);
907 }
908 if ((src_format & 0xff) >= 24) {
909 if (src_format & 0x0400) {
910 return _ConvertBuffer_32bppCmyk2Rgb32(dest_buf, dest_pit ch, width, height, pSrcBitmap, src_left, src_top, pIccTransform);
911 }
912 return _ConvertBuffer_Rgb2Rgb32(dest_buf, dest_pitch, width, height, pSrcBitmap, src_left, src_top, pIccTransform);
913 }
914 return FALSE;
915 }
916 default:
917 return FALSE;
918 } 1226 }
919 return FALSE; 1227 return FALSE;
920 } 1228 }
921 CFX_DIBitmap* CFX_DIBSource::CloneConvert(FXDIB_Format dest_format, const FX_REC T* pClip, void* pIccTransform) const 1229 if (m_pAlphaMask && pAlphaMask != m_pAlphaMask) {
922 { 1230 delete m_pAlphaMask;
923 if(dest_format == GetFormat() && pIccTransform == NULL) { 1231 }
924 return Clone(pClip); 1232 m_pAlphaMask = pAlphaMask;
925 } 1233 if (m_pPalette) {
926 if (pClip) { 1234 FX_Free(m_pPalette);
927 CFX_DIBitmap* pClone = Clone(pClip); 1235 }
928 if (pClone == NULL) { 1236 m_pPalette = pal_8bpp;
929 return NULL; 1237 if (!m_bExtBuf) {
930 } 1238 FX_Free(m_pBuffer);
931 if(!pClone->ConvertFormat(dest_format, pIccTransform)) { 1239 }
932 delete pClone; 1240 m_bExtBuf = FALSE;
933 return NULL; 1241 m_pBuffer = dest_buf;
934 } 1242 m_bpp = (uint8_t)dest_format;
935 return pClone; 1243 m_AlphaFlag = (uint8_t)(dest_format >> 8);
936 } 1244 m_Pitch = dest_pitch;
937 CFX_DIBitmap* pClone = new CFX_DIBitmap; 1245 return TRUE;
938 if(!pClone->Create(m_Width, m_Height, dest_format)) { 1246 }
939 delete pClone;
940 return NULL;
941 }
942 FX_BOOL ret = TRUE;
943 CFX_DIBitmap* pSrcAlpha = NULL;
944 if (m_AlphaFlag & 2) {
945 pSrcAlpha = (GetFormat() == FXDIB_Argb) ? GetAlphaMask() : m_pAlphaMask;
946 if (pSrcAlpha == NULL) {
947 delete pClone;
948 return NULL;
949 }
950 }
951 if (dest_format & 0x0200) {
952 if (dest_format == FXDIB_Argb)
953 ret = pSrcAlpha ?
954 pClone->LoadChannel(FXDIB_Alpha, pSrcAlpha, FXDIB_Alpha) :
955 pClone->LoadChannel(FXDIB_Alpha, 0xff);
956 else {
957 ret = pClone->CopyAlphaMask(pSrcAlpha);
958 }
959 }
960 if (pSrcAlpha && pSrcAlpha != m_pAlphaMask) {
961 delete pSrcAlpha;
962 pSrcAlpha = NULL;
963 }
964 if (!ret) {
965 delete pClone;
966 return NULL;
967 }
968 FX_DWORD* pal_8bpp = NULL;
969 ret = ConvertBuffer(dest_format, pClone->GetBuffer(), pClone->GetPitch(), m_ Width, m_Height, this, 0, 0, pal_8bpp, pIccTransform);
970 if (!ret) {
971 if (pal_8bpp) {
972 FX_Free(pal_8bpp);
973 }
974 delete pClone;
975 return NULL;
976 }
977 if (pal_8bpp) {
978 pClone->CopyPalette(pal_8bpp);
979 FX_Free(pal_8bpp);
980 pal_8bpp = NULL;
981 }
982 return pClone;
983 }
984 FX_BOOL CFX_DIBitmap::ConvertFormat(FXDIB_Format dest_format, void* pIccTransfor m)
985 {
986 FXDIB_Format src_format = GetFormat();
987 if (dest_format == src_format && pIccTransform == NULL) {
988 return TRUE;
989 }
990 if (dest_format == FXDIB_8bppMask && src_format == FXDIB_8bppRgb && m_pPalet te == NULL) {
991 m_AlphaFlag = 1;
992 return TRUE;
993 }
994 if (dest_format == FXDIB_Argb && src_format == FXDIB_Rgb32 && pIccTransform == NULL) {
995 m_AlphaFlag = 2;
996 for (int row = 0; row < m_Height; row ++) {
997 uint8_t* scanline = m_pBuffer + row * m_Pitch + 3;
998 for (int col = 0; col < m_Width; col ++) {
999 *scanline = 0xff;
1000 scanline += 4;
1001 }
1002 }
1003 return TRUE;
1004 }
1005 int dest_bpp = dest_format & 0xff;
1006 int dest_pitch = (dest_bpp * m_Width + 31) / 32 * 4;
1007 uint8_t* dest_buf = FX_TryAlloc(uint8_t, dest_pitch * m_Height + 4);
1008 if (dest_buf == NULL) {
1009 return FALSE;
1010 }
1011 CFX_DIBitmap* pAlphaMask = NULL;
1012 if (dest_format == FXDIB_Argb) {
1013 FXSYS_memset(dest_buf, 0xff, dest_pitch * m_Height + 4);
1014 if (m_pAlphaMask) {
1015 for (int row = 0; row < m_Height; row ++) {
1016 uint8_t* pDstScanline = dest_buf + row * dest_pitch + 3;
1017 const uint8_t* pSrcScanline = m_pAlphaMask->GetScanline(row);
1018 for (int col = 0; col < m_Width; col ++) {
1019 *pDstScanline = *pSrcScanline++;
1020 pDstScanline += 4;
1021 }
1022 }
1023 }
1024 } else if (dest_format & 0x0200) {
1025 if (src_format == FXDIB_Argb) {
1026 pAlphaMask = GetAlphaMask();
1027 if (pAlphaMask == NULL) {
1028 FX_Free(dest_buf);
1029 return FALSE;
1030 }
1031 } else {
1032 if (m_pAlphaMask == NULL) {
1033 if (!BuildAlphaMask()) {
1034 FX_Free(dest_buf);
1035 return FALSE;
1036 }
1037 pAlphaMask = m_pAlphaMask;
1038 m_pAlphaMask = NULL;
1039 } else {
1040 pAlphaMask = m_pAlphaMask;
1041 }
1042 }
1043 }
1044 FX_BOOL ret = FALSE;
1045 FX_DWORD* pal_8bpp = NULL;
1046 ret = ConvertBuffer(dest_format, dest_buf, dest_pitch, m_Width, m_Height, th is, 0, 0, pal_8bpp, pIccTransform);
1047 if (!ret) {
1048 if (pal_8bpp) {
1049 FX_Free(pal_8bpp);
1050 }
1051 if (pAlphaMask != m_pAlphaMask) {
1052 delete pAlphaMask;
1053 }
1054 if (dest_buf) {
1055 FX_Free(dest_buf);
1056 }
1057 return FALSE;
1058 }
1059 if (m_pAlphaMask && pAlphaMask != m_pAlphaMask) {
1060 delete m_pAlphaMask;
1061 }
1062 m_pAlphaMask = pAlphaMask;
1063 if (m_pPalette) {
1064 FX_Free(m_pPalette);
1065 }
1066 m_pPalette = pal_8bpp;
1067 if (!m_bExtBuf) {
1068 FX_Free(m_pBuffer);
1069 }
1070 m_bExtBuf = FALSE;
1071 m_pBuffer = dest_buf;
1072 m_bpp = (uint8_t)dest_format;
1073 m_AlphaFlag = (uint8_t)(dest_format >> 8);
1074 m_Pitch = dest_pitch;
1075 return TRUE;
1076 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698