OLD | NEW |
1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
6 | 6 |
7 #include "core/fxcodec/include/fx_codec.h" | 7 #include "core/fxcodec/include/fx_codec.h" |
8 #include "core/fxge/include/fx_dib.h" | 8 #include "core/fxge/include/fx_dib.h" |
9 #include "core/fxge/include/fx_ge.h" | 9 #include "core/fxge/include/fx_ge.h" |
10 | 10 |
(...skipping 415 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
426 } | 426 } |
427 FX_BOOL ConvertBuffer_Rgb2PltRgb8_NoTransform(uint8_t* dest_buf, | 427 FX_BOOL ConvertBuffer_Rgb2PltRgb8_NoTransform(uint8_t* dest_buf, |
428 int dest_pitch, | 428 int dest_pitch, |
429 int width, | 429 int width, |
430 int height, | 430 int height, |
431 const CFX_DIBSource* pSrcBitmap, | 431 const CFX_DIBSource* pSrcBitmap, |
432 int src_left, | 432 int src_left, |
433 int src_top, | 433 int src_top, |
434 uint32_t* dst_plt) { | 434 uint32_t* dst_plt) { |
435 int bpp = pSrcBitmap->GetBPP() / 8; | 435 int bpp = pSrcBitmap->GetBPP() / 8; |
436 int row, col; | |
437 CFX_Palette palette; | 436 CFX_Palette palette; |
438 palette.BuildPalette(pSrcBitmap); | 437 palette.BuildPalette(pSrcBitmap); |
439 uint32_t* cLut = palette.GetColorLut(); | 438 uint32_t* cLut = palette.GetColorLut(); |
440 uint32_t* aLut = palette.GetAmountLut(); | 439 uint32_t* aLut = palette.GetAmountLut(); |
441 if (!cLut || !aLut) { | 440 if (!cLut || !aLut) { |
442 return FALSE; | 441 return FALSE; |
443 } | 442 } |
444 int lut = palette.Getlut(); | 443 int lut = palette.Getlut(); |
445 uint32_t* pPalette = palette.GetPalette(); | 444 uint32_t* pPalette = palette.GetPalette(); |
446 if (lut > 256) { | 445 if (lut > 256) { |
447 int err, min_err; | 446 int err, min_err; |
448 int lut_256 = lut - 256; | 447 int lut_256 = lut - 256; |
449 for (row = 0; row < lut_256; row++) { | 448 for (int row = 0; row < lut_256; row++) { |
450 min_err = 1000000; | 449 min_err = 1000000; |
451 uint8_t r, g, b; | 450 uint8_t r, g, b; |
452 _ColorDecode(cLut[row], r, g, b); | 451 _ColorDecode(cLut[row], r, g, b); |
453 int clrindex = 0; | 452 int clrindex = 0; |
454 for (int col = 0; col < 256; col++) { | 453 for (int col = 0; col < 256; col++) { |
455 uint32_t p_color = *(pPalette + col); | 454 uint32_t p_color = *(pPalette + col); |
456 int d_r = r - (uint8_t)(p_color >> 16); | 455 int d_r = r - (uint8_t)(p_color >> 16); |
457 int d_g = g - (uint8_t)(p_color >> 8); | 456 int d_g = g - (uint8_t)(p_color >> 8); |
458 int d_b = b - (uint8_t)(p_color); | 457 int d_b = b - (uint8_t)(p_color); |
459 err = d_r * d_r + d_g * d_g + d_b * d_b; | 458 err = d_r * d_r + d_g * d_g + d_b * d_b; |
460 if (err < min_err) { | 459 if (err < min_err) { |
461 min_err = err; | 460 min_err = err; |
462 clrindex = col; | 461 clrindex = col; |
463 } | 462 } |
464 } | 463 } |
465 aLut[row] = clrindex; | 464 aLut[row] = clrindex; |
466 } | 465 } |
467 } | 466 } |
468 int32_t lut_1 = lut - 1; | 467 int32_t lut_1 = lut - 1; |
469 for (row = 0; row < height; row++) { | 468 for (int row = 0; row < height; row++) { |
470 uint8_t* src_scan = | 469 uint8_t* src_scan = |
471 (uint8_t*)pSrcBitmap->GetScanline(src_top + row) + src_left; | 470 (uint8_t*)pSrcBitmap->GetScanline(src_top + row) + src_left; |
472 uint8_t* dest_scan = dest_buf + row * dest_pitch; | 471 uint8_t* dest_scan = dest_buf + row * dest_pitch; |
473 for (col = 0; col < width; col++) { | 472 for (int col = 0; col < width; col++) { |
474 uint8_t* src_port = src_scan + col * bpp; | 473 uint8_t* src_port = src_scan + col * bpp; |
475 int r = src_port[2] & 0xf0; | 474 int r = src_port[2] & 0xf0; |
476 int g = src_port[1] & 0xf0; | 475 int g = src_port[1] & 0xf0; |
477 int b = src_port[0] & 0xf0; | 476 int b = src_port[0] & 0xf0; |
478 uint32_t clrindex = (r << 4) + g + (b >> 4); | 477 uint32_t clrindex = (r << 4) + g + (b >> 4); |
479 for (int i = lut_1; i >= 0; i--) | 478 for (int i = lut_1; i >= 0; i--) |
480 if (clrindex == cLut[i]) { | 479 if (clrindex == cLut[i]) { |
481 *(dest_scan + col) = (uint8_t)(aLut[i]); | 480 *(dest_scan + col) = (uint8_t)(aLut[i]); |
482 break; | 481 break; |
483 } | 482 } |
(...skipping 611 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1095 if (!m_bExtBuf) { | 1094 if (!m_bExtBuf) { |
1096 FX_Free(m_pBuffer); | 1095 FX_Free(m_pBuffer); |
1097 } | 1096 } |
1098 m_bExtBuf = FALSE; | 1097 m_bExtBuf = FALSE; |
1099 m_pBuffer = dest_buf; | 1098 m_pBuffer = dest_buf; |
1100 m_bpp = (uint8_t)dest_format; | 1099 m_bpp = (uint8_t)dest_format; |
1101 m_AlphaFlag = (uint8_t)(dest_format >> 8); | 1100 m_AlphaFlag = (uint8_t)(dest_format >> 8); |
1102 m_Pitch = dest_pitch; | 1101 m_Pitch = dest_pitch; |
1103 return TRUE; | 1102 return TRUE; |
1104 } | 1103 } |
OLD | NEW |