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

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

Issue 1172793002: Merge to XFA: Use stdint.h types throughout PDFium. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@xfa
Patch Set: Created 5 years, 6 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
« no previous file with comments | « core/src/fxge/dib/fx_dib_composite.cpp ('k') | core/src/fxge/dib/fx_dib_engine.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 } 110 }
111 111
112 FX_DWORD* GetColorLut()const 112 FX_DWORD* GetColorLut()const
113 { 113 {
114 return m_cLut; 114 return m_cLut;
115 } 115 }
116 FX_DWORD* GetAmountLut()const 116 FX_DWORD* GetAmountLut()const
117 { 117 {
118 return m_aLut; 118 return m_aLut;
119 } 119 }
120 FX_INT32 Getlut()const 120 int32_t Getlut()const
121 { 121 {
122 return m_lut; 122 return m_lut;
123 } 123 }
124 protected: 124 protected:
125 FX_DWORD* m_pPalette; 125 FX_DWORD* m_pPalette;
126 FX_DWORD* m_cLut; 126 FX_DWORD* m_cLut;
127 FX_DWORD* m_aLut; 127 FX_DWORD* m_aLut;
128 int m_lut; 128 int m_lut;
129 }; 129 };
130 int _Partition(FX_DWORD* alut, FX_DWORD* clut, int l, int r) 130 int _Partition(FX_DWORD* alut, FX_DWORD* clut, int l, int r)
(...skipping 21 matching lines...) Expand all
152 return l; 152 return l;
153 } 153 }
154 void _Qsort(FX_DWORD* alut, FX_DWORD* clut, int l, int r) 154 void _Qsort(FX_DWORD* alut, FX_DWORD* clut, int l, int r)
155 { 155 {
156 if(l < r) { 156 if(l < r) {
157 int pI = _Partition(alut, clut, l, r); 157 int pI = _Partition(alut, clut, l, r);
158 _Qsort(alut, clut, l, pI - 1); 158 _Qsort(alut, clut, l, pI - 1);
159 _Qsort(alut, clut, pI + 1, r); 159 _Qsort(alut, clut, pI + 1, r);
160 } 160 }
161 } 161 }
162 void _ColorDecode(FX_DWORD pal_v, FX_BYTE& r, FX_BYTE& g, FX_BYTE& b) 162 void _ColorDecode(FX_DWORD pal_v, uint8_t& r, uint8_t& g, uint8_t& b)
163 { 163 {
164 r = (FX_BYTE)((pal_v & 0xf00) >> 4); 164 r = (uint8_t)((pal_v & 0xf00) >> 4);
165 g = (FX_BYTE)(pal_v & 0x0f0); 165 g = (uint8_t)(pal_v & 0x0f0);
166 b = (FX_BYTE)((pal_v & 0x00f) << 4); 166 b = (uint8_t)((pal_v & 0x00f) << 4);
167 } 167 }
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) 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)
169 { 169 {
170 int row, col; 170 int row, col;
171 FX_DWORD lut_1 = lut - 1; 171 FX_DWORD lut_1 = lut - 1;
172 if (pal_type == FXDIB_PALETTE_LOC) { 172 if (pal_type == FXDIB_PALETTE_LOC) {
173 for (row = 0; row < 256; row++) { 173 for (row = 0; row < 256; row++) {
174 int lut_offset = lut_1 - row; 174 int lut_offset = lut_1 - row;
175 if (lut_offset < 0) { 175 if (lut_offset < 0) {
176 lut_offset += 256; 176 lut_offset += 256;
177 } 177 }
178 FX_DWORD color = cLut[lut_offset]; 178 FX_DWORD color = cLut[lut_offset];
179 FX_BYTE r, g, b; 179 uint8_t r, g, b;
180 _ColorDecode(color, r, g, b); 180 _ColorDecode(color, r, g, b);
181 dest_pal[row] = ((FX_DWORD)r << 16) | ((FX_DWORD)g << 8) | b | 0xff0 00000; 181 dest_pal[row] = ((FX_DWORD)r << 16) | ((FX_DWORD)g << 8) | b | 0xff0 00000;
182 aLut[lut_offset] = row; 182 aLut[lut_offset] = row;
183 } 183 }
184 } else { 184 } else {
185 for (row = 0; row < 256; row++) { 185 for (row = 0; row < 256; row++) {
186 int lut_offset = lut_1 - row; 186 int lut_offset = lut_1 - row;
187 if (lut_offset < 0) { 187 if (lut_offset < 0) {
188 lut_offset += 256; 188 lut_offset += 256;
189 } 189 }
190 FX_BYTE r, g, b; 190 uint8_t r, g, b;
191 _ColorDecode(cLut[lut_offset], r, g, b); 191 _ColorDecode(cLut[lut_offset], r, g, b);
192 int error, min_error = 1000000; 192 int error, min_error = 1000000;
193 int c_index = 0; 193 int c_index = 0;
194 for (col = 0; col < 256; col++) { 194 for (col = 0; col < 256; col++) {
195 FX_DWORD p_color = win_mac_pal[col]; 195 FX_DWORD p_color = win_mac_pal[col];
196 int d_r = r - (FX_BYTE)(p_color >> 16); 196 int d_r = r - (uint8_t)(p_color >> 16);
197 int d_g = g - (FX_BYTE)(p_color >> 8); 197 int d_g = g - (uint8_t)(p_color >> 8);
198 int d_b = b - (FX_BYTE)p_color; 198 int d_b = b - (uint8_t)p_color;
199 error = d_r * d_r + d_g * d_g + d_b * d_b; 199 error = d_r * d_r + d_g * d_g + d_b * d_b;
200 if (error < min_error) { 200 if (error < min_error) {
201 min_error = error; 201 min_error = error;
202 c_index = col; 202 c_index = col;
203 } 203 }
204 } 204 }
205 dest_pal[row] = win_mac_pal[c_index]; 205 dest_pal[row] = win_mac_pal[c_index];
206 aLut[lut_offset] = row; 206 aLut[lut_offset] = row;
207 } 207 }
208 } 208 }
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
245 } 245 }
246 if (m_aLut) { 246 if (m_aLut) {
247 FX_Free(m_aLut); 247 FX_Free(m_aLut);
248 m_aLut = NULL; 248 m_aLut = NULL;
249 } 249 }
250 m_cLut = FX_Alloc(FX_DWORD, 4096); 250 m_cLut = FX_Alloc(FX_DWORD, 4096);
251 m_aLut = FX_Alloc(FX_DWORD, 4096); 251 m_aLut = FX_Alloc(FX_DWORD, 4096);
252 int row, col; 252 int row, col;
253 m_lut = 0; 253 m_lut = 0;
254 for (row = 0; row < height; row++) { 254 for (row = 0; row < height; row++) {
255 FX_BYTE* scan_line = (FX_BYTE*)pBitmap->GetScanline(row); 255 uint8_t* scan_line = (uint8_t*)pBitmap->GetScanline(row);
256 for (col = 0; col < width; col++) { 256 for (col = 0; col < width; col++) {
257 FX_BYTE* src_port = scan_line + col * bpp; 257 uint8_t* src_port = scan_line + col * bpp;
258 FX_DWORD b = src_port[0] & 0xf0; 258 FX_DWORD b = src_port[0] & 0xf0;
259 FX_DWORD g = src_port[1] & 0xf0; 259 FX_DWORD g = src_port[1] & 0xf0;
260 FX_DWORD r = src_port[2] & 0xf0; 260 FX_DWORD r = src_port[2] & 0xf0;
261 FX_DWORD index = (r << 4) + g + (b >> 4); 261 FX_DWORD index = (r << 4) + g + (b >> 4);
262 m_aLut[index]++; 262 m_aLut[index]++;
263 } 263 }
264 } 264 }
265 for (row = 0; row < 4096; row++) { 265 for (row = 0; row < 4096; row++) {
266 if (m_aLut[row] != 0) { 266 if (m_aLut[row] != 0) {
267 m_aLut[m_lut] = m_aLut[row]; 267 m_aLut[m_lut] = m_aLut[row];
268 m_cLut[m_lut] = row; 268 m_cLut[m_lut] = row;
269 m_lut++; 269 m_lut++;
270 } 270 }
271 } 271 }
272 _Qsort(m_aLut, m_cLut, 0, m_lut - 1); 272 _Qsort(m_aLut, m_cLut, 0, m_lut - 1);
273 FX_DWORD* win_mac_pal = NULL; 273 FX_DWORD* win_mac_pal = NULL;
274 if (pal_type == FXDIB_PALETTE_WIN) { 274 if (pal_type == FXDIB_PALETTE_WIN) {
275 win_mac_pal = (FX_DWORD*)g_dwWinPalette; 275 win_mac_pal = (FX_DWORD*)g_dwWinPalette;
276 } else if (pal_type == FXDIB_PALETTE_MAC) { 276 } else if (pal_type == FXDIB_PALETTE_MAC) {
277 win_mac_pal = (FX_DWORD*)g_dwMacPalette; 277 win_mac_pal = (FX_DWORD*)g_dwMacPalette;
278 } 278 }
279 _Obtain_Pal(m_aLut, m_cLut, m_pPalette, pal_type, win_mac_pal, m_lut); 279 _Obtain_Pal(m_aLut, m_cLut, m_pPalette, pal_type, win_mac_pal, m_lut);
280 return TRUE; 280 return TRUE;
281 } 281 }
282 FX_BOOL _ConvertBuffer_1bppMask2Gray(FX_LPBYTE dest_buf, int dest_pitch, int wid th, int height, 282 FX_BOOL _ConvertBuffer_1bppMask2Gray(FX_LPBYTE dest_buf, int dest_pitch, int wid th, int height,
283 const CFX_DIBSource* pSrcBitmap, int src_le ft, int src_top) 283 const CFX_DIBSource* pSrcBitmap, int src_le ft, int src_top)
284 { 284 {
285 FX_BYTE set_gray, reset_gray; 285 uint8_t set_gray, reset_gray;
286 set_gray = 0xff; 286 set_gray = 0xff;
287 reset_gray = 0x00; 287 reset_gray = 0x00;
288 for (int row = 0; row < height; row ++) { 288 for (int row = 0; row < height; row ++) {
289 FX_LPBYTE dest_scan = dest_buf + row * dest_pitch; 289 FX_LPBYTE dest_scan = dest_buf + row * dest_pitch;
290 FXSYS_memset8(dest_scan, reset_gray, width); 290 FXSYS_memset8(dest_scan, reset_gray, width);
291 FX_LPCBYTE src_scan = pSrcBitmap->GetScanline(src_top + row); 291 FX_LPCBYTE src_scan = pSrcBitmap->GetScanline(src_top + row);
292 for (int col = src_left; col < src_left + width; col ++) { 292 for (int col = src_left; col < src_left + width; col ++) {
293 if (src_scan[col / 8] & (1 << (7 - col % 8))) { 293 if (src_scan[col / 8] & (1 << (7 - col % 8))) {
294 *dest_scan = set_gray; 294 *dest_scan = set_gray;
295 } 295 }
296 dest_scan ++; 296 dest_scan ++;
297 } 297 }
298 } 298 }
299 return TRUE; 299 return TRUE;
300 } 300 }
301 FX_BOOL _ConvertBuffer_8bppMask2Gray(FX_LPBYTE dest_buf, int dest_pitch, int wid th, int height, 301 FX_BOOL _ConvertBuffer_8bppMask2Gray(FX_LPBYTE dest_buf, int dest_pitch, int wid th, int height,
302 const CFX_DIBSource* pSrcBitmap, int src_le ft, int src_top) 302 const CFX_DIBSource* pSrcBitmap, int src_le ft, int src_top)
303 { 303 {
304 for (int row = 0; row < height; row ++) { 304 for (int row = 0; row < height; row ++) {
305 FX_LPBYTE dest_scan = dest_buf + row * dest_pitch; 305 FX_LPBYTE dest_scan = dest_buf + row * dest_pitch;
306 FX_LPCBYTE src_scan = pSrcBitmap->GetScanline(src_top + row) + src_left; 306 FX_LPCBYTE src_scan = pSrcBitmap->GetScanline(src_top + row) + src_left;
307 FXSYS_memcpy32(dest_scan, src_scan, width); 307 FXSYS_memcpy32(dest_scan, src_scan, width);
308 } 308 }
309 return TRUE; 309 return TRUE;
310 } 310 }
311 FX_BOOL _ConvertBuffer_1bppPlt2Gray(FX_LPBYTE dest_buf, int dest_pitch, int widt h, int height, 311 FX_BOOL _ConvertBuffer_1bppPlt2Gray(FX_LPBYTE dest_buf, int dest_pitch, int widt h, int height,
312 const CFX_DIBSource* pSrcBitmap, int src_lef t, int src_top, void* pIccTransform) 312 const CFX_DIBSource* pSrcBitmap, int src_lef t, int src_top, void* pIccTransform)
313 { 313 {
314 FX_DWORD* src_plt = pSrcBitmap->GetPalette(); 314 FX_DWORD* src_plt = pSrcBitmap->GetPalette();
315 FX_BYTE gray[2]; 315 uint8_t gray[2];
316 if (pIccTransform) { 316 if (pIccTransform) {
317 FX_DWORD plt[2]; 317 FX_DWORD plt[2];
318 if (pSrcBitmap->IsCmykImage()) { 318 if (pSrcBitmap->IsCmykImage()) {
319 plt[0] = FXCMYK_TODIB(src_plt[0]); 319 plt[0] = FXCMYK_TODIB(src_plt[0]);
320 plt[1] = FXCMYK_TODIB(src_plt[1]); 320 plt[1] = FXCMYK_TODIB(src_plt[1]);
321 } else { 321 } else {
322 FX_LPBYTE bgr_ptr = (FX_LPBYTE)plt; 322 FX_LPBYTE bgr_ptr = (FX_LPBYTE)plt;
323 bgr_ptr[0] = FXARGB_B(src_plt[0]); 323 bgr_ptr[0] = FXARGB_B(src_plt[0]);
324 bgr_ptr[1] = FXARGB_G(src_plt[0]); 324 bgr_ptr[1] = FXARGB_G(src_plt[0]);
325 bgr_ptr[2] = FXARGB_R(src_plt[0]); 325 bgr_ptr[2] = FXARGB_R(src_plt[0]);
326 bgr_ptr[3] = FXARGB_B(src_plt[1]); 326 bgr_ptr[3] = FXARGB_B(src_plt[1]);
327 bgr_ptr[4] = FXARGB_G(src_plt[1]); 327 bgr_ptr[4] = FXARGB_G(src_plt[1]);
328 bgr_ptr[5] = FXARGB_R(src_plt[1]); 328 bgr_ptr[5] = FXARGB_R(src_plt[1]);
329 } 329 }
330 ICodec_IccModule* pIccModule = CFX_GEModule::Get()->GetCodecModule()->Ge tIccModule(); 330 ICodec_IccModule* pIccModule = CFX_GEModule::Get()->GetCodecModule()->Ge tIccModule();
331 pIccModule->TranslateScanline(pIccTransform, gray, (FX_LPCBYTE)plt, 2); 331 pIccModule->TranslateScanline(pIccTransform, gray, (FX_LPCBYTE)plt, 2);
332 } else { 332 } else {
333 FX_BYTE reset_r, reset_g, reset_b, 333 uint8_t reset_r, reset_g, reset_b,
334 set_r, set_g, set_b; 334 set_r, set_g, set_b;
335 if (pSrcBitmap->IsCmykImage()) { 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]), 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); 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]), 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); 339 set_r, set_g, set_b);
340 } else { 340 } else {
341 reset_r = FXARGB_R(src_plt[0]); 341 reset_r = FXARGB_R(src_plt[0]);
342 reset_g = FXARGB_G(src_plt[0]); 342 reset_g = FXARGB_G(src_plt[0]);
343 reset_b = FXARGB_B(src_plt[0]); 343 reset_b = FXARGB_B(src_plt[0]);
(...skipping 14 matching lines...) Expand all
358 } 358 }
359 dest_scan ++; 359 dest_scan ++;
360 } 360 }
361 } 361 }
362 return TRUE; 362 return TRUE;
363 } 363 }
364 FX_BOOL _ConvertBuffer_8bppPlt2Gray(FX_LPBYTE dest_buf, int dest_pitch, int widt h, int height, 364 FX_BOOL _ConvertBuffer_8bppPlt2Gray(FX_LPBYTE dest_buf, int dest_pitch, int widt h, int height,
365 const CFX_DIBSource* pSrcBitmap, int src_lef t, int src_top, void* pIccTransform) 365 const CFX_DIBSource* pSrcBitmap, int src_lef t, int src_top, void* pIccTransform)
366 { 366 {
367 FX_DWORD* src_plt = pSrcBitmap->GetPalette(); 367 FX_DWORD* src_plt = pSrcBitmap->GetPalette();
368 FX_BYTE gray[256]; 368 uint8_t gray[256];
369 if (pIccTransform) { 369 if (pIccTransform) {
370 FX_DWORD plt[256]; 370 FX_DWORD plt[256];
371 if (pSrcBitmap->IsCmykImage()) { 371 if (pSrcBitmap->IsCmykImage()) {
372 for (int i = 0; i < 256; i ++) { 372 for (int i = 0; i < 256; i ++) {
373 plt[i] = FXCMYK_TODIB(src_plt[i]); 373 plt[i] = FXCMYK_TODIB(src_plt[i]);
374 } 374 }
375 } else { 375 } else {
376 FX_LPBYTE bgr_ptr = (FX_LPBYTE)plt; 376 FX_LPBYTE bgr_ptr = (FX_LPBYTE)plt;
377 for (int i = 0; i < 256; i ++) { 377 for (int i = 0; i < 256; i ++) {
378 *bgr_ptr++ = FXARGB_B(src_plt[i]); 378 *bgr_ptr++ = FXARGB_B(src_plt[i]);
379 *bgr_ptr++ = FXARGB_G(src_plt[i]); 379 *bgr_ptr++ = FXARGB_G(src_plt[i]);
380 *bgr_ptr++ = FXARGB_R(src_plt[i]); 380 *bgr_ptr++ = FXARGB_R(src_plt[i]);
381 } 381 }
382 } 382 }
383 ICodec_IccModule* pIccModule = CFX_GEModule::Get()->GetCodecModule()->Ge tIccModule(); 383 ICodec_IccModule* pIccModule = CFX_GEModule::Get()->GetCodecModule()->Ge tIccModule();
384 pIccModule->TranslateScanline(pIccTransform, gray, (FX_LPCBYTE)plt, 256) ; 384 pIccModule->TranslateScanline(pIccTransform, gray, (FX_LPCBYTE)plt, 256) ;
385 } else { 385 } else {
386 if (pSrcBitmap->IsCmykImage()) { 386 if (pSrcBitmap->IsCmykImage()) {
387 FX_BYTE r, g, b; 387 uint8_t r, g, b;
388 for (int i = 0; i < 256; i ++) { 388 for (int i = 0; i < 256; i ++) {
389 AdobeCMYK_to_sRGB1(FXSYS_GetCValue(src_plt[i]), FXSYS_GetMValue( src_plt[i]), FXSYS_GetYValue(src_plt[i]), FXSYS_GetKValue(src_plt[i]), 389 AdobeCMYK_to_sRGB1(FXSYS_GetCValue(src_plt[i]), FXSYS_GetMValue( src_plt[i]), FXSYS_GetYValue(src_plt[i]), FXSYS_GetKValue(src_plt[i]),
390 r, g, b); 390 r, g, b);
391 gray[i] = FXRGB2GRAY(r, g, b); 391 gray[i] = FXRGB2GRAY(r, g, b);
392 } 392 }
393 } else 393 } else
394 for (int i = 0; i < 256; i ++) { 394 for (int i = 0; i < 256; i ++) {
395 gray[i] = FXRGB2GRAY(FXARGB_R(src_plt[i]), FXARGB_G(src_plt[i]), FXARGB_B(src_plt[i])); 395 gray[i] = FXRGB2GRAY(FXARGB_R(src_plt[i]), FXARGB_G(src_plt[i]), FXARGB_B(src_plt[i]));
396 } 396 }
397 } 397 }
(...skipping 28 matching lines...) Expand all
426 src_scan += 4; 426 src_scan += 4;
427 } 427 }
428 } 428 }
429 } 429 }
430 } else { 430 } else {
431 if (pSrcBitmap->IsCmykImage()) { 431 if (pSrcBitmap->IsCmykImage()) {
432 for (int row = 0; row < height; row ++) { 432 for (int row = 0; row < height; row ++) {
433 FX_LPBYTE dest_scan = dest_buf + row * dest_pitch; 433 FX_LPBYTE dest_scan = dest_buf + row * dest_pitch;
434 FX_LPCBYTE src_scan = pSrcBitmap->GetScanline(src_top + row) + s rc_left * 4; 434 FX_LPCBYTE src_scan = pSrcBitmap->GetScanline(src_top + row) + s rc_left * 4;
435 for (int col = 0; col < width; col ++) { 435 for (int col = 0; col < width; col ++) {
436 FX_BYTE r, g, b; 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]), 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); 438 r, g, b);
439 *dest_scan++ = FXRGB2GRAY(r, g, b); 439 *dest_scan++ = FXRGB2GRAY(r, g, b);
440 src_scan += 4; 440 src_scan += 4;
441 } 441 }
442 } 442 }
443 } else { 443 } else {
444 for (int row = 0; row < height; row ++) { 444 for (int row = 0; row < height; row ++) {
445 FX_LPBYTE dest_scan = dest_buf + row * dest_pitch; 445 FX_LPBYTE dest_scan = dest_buf + row * dest_pitch;
446 FX_LPCBYTE src_scan = pSrcBitmap->GetScanline(src_top + row) + s rc_left * Bpp; 446 FX_LPCBYTE src_scan = pSrcBitmap->GetScanline(src_top + row) + s rc_left * Bpp;
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
499 } 499 }
500 ICodec_IccModule* pIccModule = CFX_GEModule::Get()->GetCodecModule()->Ge tIccModule(); 500 ICodec_IccModule* pIccModule = CFX_GEModule::Get()->GetCodecModule()->Ge tIccModule();
501 pIccModule->TranslateScanline(pIccTransform, (FX_LPBYTE)plt, (FX_LPCBYTE )plt, plt_size); 501 pIccModule->TranslateScanline(pIccTransform, (FX_LPBYTE)plt, (FX_LPCBYTE )plt, plt_size);
502 for (int i = 0; i < plt_size; i ++) { 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]); 503 dst_plt[i] = FXARGB_MAKE(0xff, bgr_ptr[2], bgr_ptr[1], bgr_ptr[0]);
504 bgr_ptr += 3; 504 bgr_ptr += 3;
505 } 505 }
506 } else { 506 } else {
507 if (pSrcBitmap->IsCmykImage()) { 507 if (pSrcBitmap->IsCmykImage()) {
508 for (int i = 0; i < plt_size; i ++) { 508 for (int i = 0; i < plt_size; i ++) {
509 FX_BYTE r, g, b; 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]), 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); 511 r, g, b);
512 dst_plt[i] = FXARGB_MAKE(0xff, r, g, b); 512 dst_plt[i] = FXARGB_MAKE(0xff, r, g, b);
513 } 513 }
514 } else { 514 } else {
515 FXSYS_memcpy32(dst_plt, src_plt, plt_size * 4); 515 FXSYS_memcpy32(dst_plt, src_plt, plt_size * 4);
516 } 516 }
517 } 517 }
518 return TRUE; 518 return TRUE;
519 } 519 }
520 inline FX_BOOL _ConvertBuffer_Rgb2PltRgb8_NoTransform(FX_LPBYTE dest_buf, int de st_pitch, int width, int height, 520 inline FX_BOOL _ConvertBuffer_Rgb2PltRgb8_NoTransform(FX_LPBYTE dest_buf, int de st_pitch, int width, int height,
521 const CFX_DIBSource* pSrcBitmap, int src_left, int src_top, FX_DWORD* ds t_plt) 521 const CFX_DIBSource* pSrcBitmap, int src_left, int src_top, FX_DWORD* ds t_plt)
522 { 522 {
523 int bpp = pSrcBitmap->GetBPP() / 8; 523 int bpp = pSrcBitmap->GetBPP() / 8;
524 int row, col; 524 int row, col;
525 CFX_Palette palette; 525 CFX_Palette palette;
526 palette.BuildPalette(pSrcBitmap, FXDIB_PALETTE_LOC); 526 palette.BuildPalette(pSrcBitmap, FXDIB_PALETTE_LOC);
527 FX_DWORD* cLut = palette.GetColorLut(); 527 FX_DWORD* cLut = palette.GetColorLut();
528 FX_DWORD* aLut = palette.GetAmountLut(); 528 FX_DWORD* aLut = palette.GetAmountLut();
529 if (cLut == NULL || aLut == NULL) { 529 if (cLut == NULL || aLut == NULL) {
530 return FALSE; 530 return FALSE;
531 } 531 }
532 int lut = palette.Getlut(); 532 int lut = palette.Getlut();
533 FX_DWORD* pPalette = palette.GetPalette(); 533 FX_DWORD* pPalette = palette.GetPalette();
534 if (lut > 256) { 534 if (lut > 256) {
535 int err, min_err; 535 int err, min_err;
536 int lut_256 = lut - 256; 536 int lut_256 = lut - 256;
537 for (row = 0; row < lut_256; row++) { 537 for (row = 0; row < lut_256; row++) {
538 min_err = 1000000; 538 min_err = 1000000;
539 FX_BYTE r, g, b; 539 uint8_t r, g, b;
540 _ColorDecode(cLut[row], r, g, b); 540 _ColorDecode(cLut[row], r, g, b);
541 int clrindex = 0; 541 int clrindex = 0;
542 for (int col = 0; col < 256; col++) { 542 for (int col = 0; col < 256; col++) {
543 FX_DWORD p_color = *(pPalette + col); 543 FX_DWORD p_color = *(pPalette + col);
544 int d_r = r - (FX_BYTE)(p_color >> 16); 544 int d_r = r - (uint8_t)(p_color >> 16);
545 int d_g = g - (FX_BYTE)(p_color >> 8); 545 int d_g = g - (uint8_t)(p_color >> 8);
546 int d_b = b - (FX_BYTE)(p_color); 546 int d_b = b - (uint8_t)(p_color);
547 err = d_r * d_r + d_g * d_g + d_b * d_b; 547 err = d_r * d_r + d_g * d_g + d_b * d_b;
548 if (err < min_err) { 548 if (err < min_err) {
549 min_err = err; 549 min_err = err;
550 clrindex = col; 550 clrindex = col;
551 } 551 }
552 } 552 }
553 aLut[row] = clrindex; 553 aLut[row] = clrindex;
554 } 554 }
555 } 555 }
556 FX_INT32 lut_1 = lut - 1; 556 int32_t lut_1 = lut - 1;
557 for (row = 0; row < height; row ++) { 557 for (row = 0; row < height; row ++) {
558 FX_BYTE* src_scan = (FX_BYTE*)pSrcBitmap->GetScanline(src_top + row) + s rc_left; 558 uint8_t* src_scan = (uint8_t*)pSrcBitmap->GetScanline(src_top + row) + s rc_left;
559 FX_BYTE* dest_scan = dest_buf + row * dest_pitch; 559 uint8_t* dest_scan = dest_buf + row * dest_pitch;
560 for (col = 0; col < width; col++) { 560 for (col = 0; col < width; col++) {
561 FX_BYTE* src_port = src_scan + col * bpp; 561 uint8_t* src_port = src_scan + col * bpp;
562 int r = src_port[2] & 0xf0; 562 int r = src_port[2] & 0xf0;
563 int g = src_port[1] & 0xf0; 563 int g = src_port[1] & 0xf0;
564 int b = src_port[0] & 0xf0; 564 int b = src_port[0] & 0xf0;
565 FX_DWORD clrindex = (r << 4) + g + (b >> 4); 565 FX_DWORD clrindex = (r << 4) + g + (b >> 4);
566 for (int i = lut_1; i >= 0; i--) 566 for (int i = lut_1; i >= 0; i--)
567 if (clrindex == cLut[i]) { 567 if (clrindex == cLut[i]) {
568 *(dest_scan + col) = (FX_BYTE)(aLut[i]); 568 *(dest_scan + col) = (uint8_t)(aLut[i]);
569 break; 569 break;
570 } 570 }
571 } 571 }
572 } 572 }
573 FXSYS_memcpy32(dst_plt, pPalette, sizeof(FX_DWORD) * 256); 573 FXSYS_memcpy32(dst_plt, pPalette, sizeof(FX_DWORD) * 256);
574 return TRUE; 574 return TRUE;
575 } 575 }
576 FX_BOOL _ConvertBuffer_Rgb2PltRgb8(FX_LPBYTE dest_buf, int dest_pitch, int width , int height, 576 FX_BOOL _ConvertBuffer_Rgb2PltRgb8(FX_LPBYTE 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) 577 const CFX_DIBSource* pSrcBitmap, int src_left , int src_top, FX_DWORD* dst_plt, void* pIccTransform)
578 { 578 {
(...skipping 10 matching lines...) Expand all
589 pIccModule->TranslateScanline(pIccTransform, (FX_LPBYTE)&plt_entry, (FX_LPCBYTE)&plt_entry, 1); 589 pIccModule->TranslateScanline(pIccTransform, (FX_LPBYTE)&plt_entry, (FX_LPCBYTE)&plt_entry, 1);
590 *plt = FXARGB_TODIB(plt_entry); 590 *plt = FXARGB_TODIB(plt_entry);
591 } 591 }
592 } 592 }
593 return ret; 593 return ret;
594 } 594 }
595 FX_BOOL _ConvertBuffer_1bppMask2Rgb(FXDIB_Format dst_format, FX_LPBYTE dest_buf, int dest_pitch, int width, int height, 595 FX_BOOL _ConvertBuffer_1bppMask2Rgb(FXDIB_Format dst_format, FX_LPBYTE dest_buf, int dest_pitch, int width, int height,
596 const CFX_DIBSource* pSrcBitmap, int src_lef t, int src_top) 596 const CFX_DIBSource* pSrcBitmap, int src_lef t, int src_top)
597 { 597 {
598 int comps = (dst_format & 0xff) / 8; 598 int comps = (dst_format & 0xff) / 8;
599 FX_BYTE set_gray, reset_gray; 599 uint8_t set_gray, reset_gray;
600 set_gray = 0xff; 600 set_gray = 0xff;
601 reset_gray = 0x00; 601 reset_gray = 0x00;
602 for (int row = 0; row < height; row ++) { 602 for (int row = 0; row < height; row ++) {
603 FX_LPBYTE dest_scan = dest_buf + row * dest_pitch; 603 FX_LPBYTE dest_scan = dest_buf + row * dest_pitch;
604 FX_LPCBYTE src_scan = pSrcBitmap->GetScanline(src_top + row); 604 FX_LPCBYTE src_scan = pSrcBitmap->GetScanline(src_top + row);
605 for (int col = src_left; col < src_left + width; col ++) { 605 for (int col = src_left; col < src_left + width; col ++) {
606 if (src_scan[col / 8] & (1 << (7 - col % 8))) { 606 if (src_scan[col / 8] & (1 << (7 - col % 8))) {
607 dest_scan[0] = set_gray; 607 dest_scan[0] = set_gray;
608 dest_scan[1] = set_gray; 608 dest_scan[1] = set_gray;
609 dest_scan[2] = set_gray; 609 dest_scan[2] = set_gray;
610 } else { 610 } else {
611 dest_scan[0] = reset_gray; 611 dest_scan[0] = reset_gray;
612 dest_scan[1] = reset_gray; 612 dest_scan[1] = reset_gray;
613 dest_scan[2] = reset_gray; 613 dest_scan[2] = reset_gray;
614 } 614 }
615 dest_scan += comps; 615 dest_scan += comps;
616 } 616 }
617 } 617 }
618 return TRUE; 618 return TRUE;
619 } 619 }
620 FX_BOOL _ConvertBuffer_8bppMask2Rgb(FXDIB_Format dst_format, FX_LPBYTE dest_buf, int dest_pitch, int width, int height, 620 FX_BOOL _ConvertBuffer_8bppMask2Rgb(FXDIB_Format dst_format, FX_LPBYTE dest_buf, int dest_pitch, int width, int height,
621 const CFX_DIBSource* pSrcBitmap, int src_lef t, int src_top) 621 const CFX_DIBSource* pSrcBitmap, int src_lef t, int src_top)
622 { 622 {
623 int comps = (dst_format & 0xff) / 8; 623 int comps = (dst_format & 0xff) / 8;
624 for (int row = 0; row < height; row ++) { 624 for (int row = 0; row < height; row ++) {
625 FX_LPBYTE dest_scan = dest_buf + row * dest_pitch; 625 FX_LPBYTE dest_scan = dest_buf + row * dest_pitch;
626 FX_LPCBYTE src_scan = pSrcBitmap->GetScanline(src_top + row) + src_left; 626 FX_LPCBYTE src_scan = pSrcBitmap->GetScanline(src_top + row) + src_left;
627 FX_BYTE src_pixel; 627 uint8_t src_pixel;
628 for (int col = 0; col < width; col ++) { 628 for (int col = 0; col < width; col ++) {
629 src_pixel = *src_scan++; 629 src_pixel = *src_scan++;
630 *dest_scan++ = src_pixel; 630 *dest_scan++ = src_pixel;
631 *dest_scan++ = src_pixel; 631 *dest_scan++ = src_pixel;
632 *dest_scan = src_pixel; 632 *dest_scan = src_pixel;
633 dest_scan += comps - 2; 633 dest_scan += comps - 2;
634 } 634 }
635 } 635 }
636 return TRUE; 636 return TRUE;
637 } 637 }
(...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after
996 FX_LPBYTE scanline = m_pBuffer + row * m_Pitch + 3; 996 FX_LPBYTE scanline = m_pBuffer + row * m_Pitch + 3;
997 for (int col = 0; col < m_Width; col ++) { 997 for (int col = 0; col < m_Width; col ++) {
998 *scanline = 0xff; 998 *scanline = 0xff;
999 scanline += 4; 999 scanline += 4;
1000 } 1000 }
1001 } 1001 }
1002 return TRUE; 1002 return TRUE;
1003 } 1003 }
1004 int dest_bpp = dest_format & 0xff; 1004 int dest_bpp = dest_format & 0xff;
1005 int dest_pitch = (dest_bpp * m_Width + 31) / 32 * 4; 1005 int dest_pitch = (dest_bpp * m_Width + 31) / 32 * 4;
1006 FX_LPBYTE dest_buf = FX_TryAlloc(FX_BYTE, dest_pitch * m_Height + 4); 1006 FX_LPBYTE dest_buf = FX_TryAlloc(uint8_t, dest_pitch * m_Height + 4);
1007 if (dest_buf == NULL) { 1007 if (dest_buf == NULL) {
1008 return FALSE; 1008 return FALSE;
1009 } 1009 }
1010 CFX_DIBitmap* pAlphaMask = NULL; 1010 CFX_DIBitmap* pAlphaMask = NULL;
1011 if (dest_format == FXDIB_Argb) { 1011 if (dest_format == FXDIB_Argb) {
1012 FXSYS_memset8(dest_buf, 0xff, dest_pitch * m_Height + 4); 1012 FXSYS_memset8(dest_buf, 0xff, dest_pitch * m_Height + 4);
1013 if (m_pAlphaMask) { 1013 if (m_pAlphaMask) {
1014 for (int row = 0; row < m_Height; row ++) { 1014 for (int row = 0; row < m_Height; row ++) {
1015 FX_LPBYTE pDstScanline = dest_buf + row * dest_pitch + 3; 1015 FX_LPBYTE pDstScanline = dest_buf + row * dest_pitch + 3;
1016 FX_LPCBYTE pSrcScanline = m_pAlphaMask->GetScanline(row); 1016 FX_LPCBYTE pSrcScanline = m_pAlphaMask->GetScanline(row);
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
1061 m_pAlphaMask = pAlphaMask; 1061 m_pAlphaMask = pAlphaMask;
1062 if (m_pPalette) { 1062 if (m_pPalette) {
1063 FX_Free(m_pPalette); 1063 FX_Free(m_pPalette);
1064 } 1064 }
1065 m_pPalette = pal_8bpp; 1065 m_pPalette = pal_8bpp;
1066 if (!m_bExtBuf) { 1066 if (!m_bExtBuf) {
1067 FX_Free(m_pBuffer); 1067 FX_Free(m_pBuffer);
1068 } 1068 }
1069 m_bExtBuf = FALSE; 1069 m_bExtBuf = FALSE;
1070 m_pBuffer = dest_buf; 1070 m_pBuffer = dest_buf;
1071 m_bpp = (FX_BYTE)dest_format; 1071 m_bpp = (uint8_t)dest_format;
1072 m_AlphaFlag = (FX_BYTE)(dest_format >> 8); 1072 m_AlphaFlag = (uint8_t)(dest_format >> 8);
1073 m_Pitch = dest_pitch; 1073 m_Pitch = dest_pitch;
1074 return TRUE; 1074 return TRUE;
1075 } 1075 }
OLDNEW
« no previous file with comments | « core/src/fxge/dib/fx_dib_composite.cpp ('k') | core/src/fxge/dib/fx_dib_engine.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698