| 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/include/fxcodec/fx_codec.h" | 7 #include "core/include/fxcodec/fx_codec.h" |
| 8 #include "core/include/fxge/fx_dib.h" | 8 #include "core/include/fxge/fx_dib.h" |
| 9 #include "core/include/fxge/fx_ge.h" | 9 #include "core/include/fxge/fx_ge.h" |
| 10 | 10 |
| 11 class CFX_Palette { | 11 class CFX_Palette { |
| 12 public: | 12 public: |
| 13 CFX_Palette(); | 13 CFX_Palette(); |
| 14 ~CFX_Palette(); | 14 ~CFX_Palette(); |
| 15 | 15 |
| 16 FX_BOOL BuildPalette(const CFX_DIBSource* pBitmap); | 16 FX_BOOL BuildPalette(const CFX_DIBSource* pBitmap); |
| 17 FX_DWORD* GetPalette() const { return m_pPalette; } | 17 uint32_t* GetPalette() const { return m_pPalette; } |
| 18 FX_DWORD* GetColorLut() const { return m_cLut; } | 18 uint32_t* GetColorLut() const { return m_cLut; } |
| 19 FX_DWORD* GetAmountLut() const { return m_aLut; } | 19 uint32_t* GetAmountLut() const { return m_aLut; } |
| 20 int32_t Getlut() const { return m_lut; } | 20 int32_t Getlut() const { return m_lut; } |
| 21 | 21 |
| 22 protected: | 22 protected: |
| 23 FX_DWORD* m_pPalette; | 23 uint32_t* m_pPalette; |
| 24 FX_DWORD* m_cLut; | 24 uint32_t* m_cLut; |
| 25 FX_DWORD* m_aLut; | 25 uint32_t* m_aLut; |
| 26 int m_lut; | 26 int m_lut; |
| 27 }; | 27 }; |
| 28 int _Partition(FX_DWORD* alut, FX_DWORD* clut, int l, int r) { | 28 int _Partition(uint32_t* alut, uint32_t* clut, int l, int r) { |
| 29 FX_DWORD p_a = alut[l]; | 29 uint32_t p_a = alut[l]; |
| 30 FX_DWORD p_c = clut[l]; | 30 uint32_t p_c = clut[l]; |
| 31 while (l < r) { | 31 while (l < r) { |
| 32 while (l < r && alut[r] >= p_a) { | 32 while (l < r && alut[r] >= p_a) { |
| 33 r--; | 33 r--; |
| 34 } | 34 } |
| 35 if (l < r) { | 35 if (l < r) { |
| 36 alut[l] = alut[r]; | 36 alut[l] = alut[r]; |
| 37 clut[l++] = clut[r]; | 37 clut[l++] = clut[r]; |
| 38 } | 38 } |
| 39 while (l < r && alut[l] <= p_a) { | 39 while (l < r && alut[l] <= p_a) { |
| 40 l++; | 40 l++; |
| 41 } | 41 } |
| 42 if (l < r) { | 42 if (l < r) { |
| 43 alut[r] = alut[l]; | 43 alut[r] = alut[l]; |
| 44 clut[r--] = clut[l]; | 44 clut[r--] = clut[l]; |
| 45 } | 45 } |
| 46 } | 46 } |
| 47 alut[l] = p_a; | 47 alut[l] = p_a; |
| 48 clut[l] = p_c; | 48 clut[l] = p_c; |
| 49 return l; | 49 return l; |
| 50 } | 50 } |
| 51 void _Qsort(FX_DWORD* alut, FX_DWORD* clut, int l, int r) { | 51 void _Qsort(uint32_t* alut, uint32_t* clut, int l, int r) { |
| 52 if (l < r) { | 52 if (l < r) { |
| 53 int pI = _Partition(alut, clut, l, r); | 53 int pI = _Partition(alut, clut, l, r); |
| 54 _Qsort(alut, clut, l, pI - 1); | 54 _Qsort(alut, clut, l, pI - 1); |
| 55 _Qsort(alut, clut, pI + 1, r); | 55 _Qsort(alut, clut, pI + 1, r); |
| 56 } | 56 } |
| 57 } | 57 } |
| 58 void _ColorDecode(FX_DWORD pal_v, uint8_t& r, uint8_t& g, uint8_t& b) { | 58 void _ColorDecode(uint32_t pal_v, uint8_t& r, uint8_t& g, uint8_t& b) { |
| 59 r = (uint8_t)((pal_v & 0xf00) >> 4); | 59 r = (uint8_t)((pal_v & 0xf00) >> 4); |
| 60 g = (uint8_t)(pal_v & 0x0f0); | 60 g = (uint8_t)(pal_v & 0x0f0); |
| 61 b = (uint8_t)((pal_v & 0x00f) << 4); | 61 b = (uint8_t)((pal_v & 0x00f) << 4); |
| 62 } | 62 } |
| 63 void _Obtain_Pal(FX_DWORD* aLut, | 63 void _Obtain_Pal(uint32_t* aLut, |
| 64 FX_DWORD* cLut, | 64 uint32_t* cLut, |
| 65 FX_DWORD* dest_pal, | 65 uint32_t* dest_pal, |
| 66 FX_DWORD lut) { | 66 uint32_t lut) { |
| 67 FX_DWORD lut_1 = lut - 1; | 67 uint32_t lut_1 = lut - 1; |
| 68 for (int row = 0; row < 256; row++) { | 68 for (int row = 0; row < 256; row++) { |
| 69 int lut_offset = lut_1 - row; | 69 int lut_offset = lut_1 - row; |
| 70 if (lut_offset < 0) { | 70 if (lut_offset < 0) { |
| 71 lut_offset += 256; | 71 lut_offset += 256; |
| 72 } | 72 } |
| 73 FX_DWORD color = cLut[lut_offset]; | 73 uint32_t color = cLut[lut_offset]; |
| 74 uint8_t r; | 74 uint8_t r; |
| 75 uint8_t g; | 75 uint8_t g; |
| 76 uint8_t b; | 76 uint8_t b; |
| 77 _ColorDecode(color, r, g, b); | 77 _ColorDecode(color, r, g, b); |
| 78 dest_pal[row] = ((FX_DWORD)r << 16) | ((FX_DWORD)g << 8) | b | 0xff000000; | 78 dest_pal[row] = ((uint32_t)r << 16) | ((uint32_t)g << 8) | b | 0xff000000; |
| 79 aLut[lut_offset] = row; | 79 aLut[lut_offset] = row; |
| 80 } | 80 } |
| 81 } | 81 } |
| 82 | 82 |
| 83 CFX_Palette::CFX_Palette() { | 83 CFX_Palette::CFX_Palette() { |
| 84 m_pPalette = NULL; | 84 m_pPalette = NULL; |
| 85 m_cLut = NULL; | 85 m_cLut = NULL; |
| 86 m_aLut = NULL; | 86 m_aLut = NULL; |
| 87 m_lut = 0; | 87 m_lut = 0; |
| 88 } | 88 } |
| 89 CFX_Palette::~CFX_Palette() { | 89 CFX_Palette::~CFX_Palette() { |
| 90 FX_Free(m_pPalette); | 90 FX_Free(m_pPalette); |
| 91 FX_Free(m_cLut); | 91 FX_Free(m_cLut); |
| 92 FX_Free(m_aLut); | 92 FX_Free(m_aLut); |
| 93 m_lut = 0; | 93 m_lut = 0; |
| 94 } | 94 } |
| 95 FX_BOOL CFX_Palette::BuildPalette(const CFX_DIBSource* pBitmap) { | 95 FX_BOOL CFX_Palette::BuildPalette(const CFX_DIBSource* pBitmap) { |
| 96 if (!pBitmap) { | 96 if (!pBitmap) { |
| 97 return FALSE; | 97 return FALSE; |
| 98 } | 98 } |
| 99 FX_Free(m_pPalette); | 99 FX_Free(m_pPalette); |
| 100 m_pPalette = FX_Alloc(FX_DWORD, 256); | 100 m_pPalette = FX_Alloc(uint32_t, 256); |
| 101 int bpp = pBitmap->GetBPP() / 8; | 101 int bpp = pBitmap->GetBPP() / 8; |
| 102 int width = pBitmap->GetWidth(); | 102 int width = pBitmap->GetWidth(); |
| 103 int height = pBitmap->GetHeight(); | 103 int height = pBitmap->GetHeight(); |
| 104 FX_Free(m_cLut); | 104 FX_Free(m_cLut); |
| 105 m_cLut = NULL; | 105 m_cLut = NULL; |
| 106 FX_Free(m_aLut); | 106 FX_Free(m_aLut); |
| 107 m_aLut = NULL; | 107 m_aLut = NULL; |
| 108 m_cLut = FX_Alloc(FX_DWORD, 4096); | 108 m_cLut = FX_Alloc(uint32_t, 4096); |
| 109 m_aLut = FX_Alloc(FX_DWORD, 4096); | 109 m_aLut = FX_Alloc(uint32_t, 4096); |
| 110 int row, col; | 110 int row, col; |
| 111 m_lut = 0; | 111 m_lut = 0; |
| 112 for (row = 0; row < height; row++) { | 112 for (row = 0; row < height; row++) { |
| 113 uint8_t* scan_line = (uint8_t*)pBitmap->GetScanline(row); | 113 uint8_t* scan_line = (uint8_t*)pBitmap->GetScanline(row); |
| 114 for (col = 0; col < width; col++) { | 114 for (col = 0; col < width; col++) { |
| 115 uint8_t* src_port = scan_line + col * bpp; | 115 uint8_t* src_port = scan_line + col * bpp; |
| 116 FX_DWORD b = src_port[0] & 0xf0; | 116 uint32_t b = src_port[0] & 0xf0; |
| 117 FX_DWORD g = src_port[1] & 0xf0; | 117 uint32_t g = src_port[1] & 0xf0; |
| 118 FX_DWORD r = src_port[2] & 0xf0; | 118 uint32_t r = src_port[2] & 0xf0; |
| 119 FX_DWORD index = (r << 4) + g + (b >> 4); | 119 uint32_t index = (r << 4) + g + (b >> 4); |
| 120 m_aLut[index]++; | 120 m_aLut[index]++; |
| 121 } | 121 } |
| 122 } | 122 } |
| 123 for (row = 0; row < 4096; row++) { | 123 for (row = 0; row < 4096; row++) { |
| 124 if (m_aLut[row] != 0) { | 124 if (m_aLut[row] != 0) { |
| 125 m_aLut[m_lut] = m_aLut[row]; | 125 m_aLut[m_lut] = m_aLut[row]; |
| 126 m_cLut[m_lut] = row; | 126 m_cLut[m_lut] = row; |
| 127 m_lut++; | 127 m_lut++; |
| 128 } | 128 } |
| 129 } | 129 } |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 169 return TRUE; | 169 return TRUE; |
| 170 } | 170 } |
| 171 FX_BOOL ConvertBuffer_1bppPlt2Gray(uint8_t* dest_buf, | 171 FX_BOOL ConvertBuffer_1bppPlt2Gray(uint8_t* dest_buf, |
| 172 int dest_pitch, | 172 int dest_pitch, |
| 173 int width, | 173 int width, |
| 174 int height, | 174 int height, |
| 175 const CFX_DIBSource* pSrcBitmap, | 175 const CFX_DIBSource* pSrcBitmap, |
| 176 int src_left, | 176 int src_left, |
| 177 int src_top, | 177 int src_top, |
| 178 void* pIccTransform) { | 178 void* pIccTransform) { |
| 179 FX_DWORD* src_plt = pSrcBitmap->GetPalette(); | 179 uint32_t* src_plt = pSrcBitmap->GetPalette(); |
| 180 uint8_t gray[2]; | 180 uint8_t gray[2]; |
| 181 if (pIccTransform) { | 181 if (pIccTransform) { |
| 182 FX_DWORD plt[2]; | 182 uint32_t plt[2]; |
| 183 if (pSrcBitmap->IsCmykImage()) { | 183 if (pSrcBitmap->IsCmykImage()) { |
| 184 plt[0] = FXCMYK_TODIB(src_plt[0]); | 184 plt[0] = FXCMYK_TODIB(src_plt[0]); |
| 185 plt[1] = FXCMYK_TODIB(src_plt[1]); | 185 plt[1] = FXCMYK_TODIB(src_plt[1]); |
| 186 } else { | 186 } else { |
| 187 uint8_t* bgr_ptr = (uint8_t*)plt; | 187 uint8_t* bgr_ptr = (uint8_t*)plt; |
| 188 bgr_ptr[0] = FXARGB_B(src_plt[0]); | 188 bgr_ptr[0] = FXARGB_B(src_plt[0]); |
| 189 bgr_ptr[1] = FXARGB_G(src_plt[0]); | 189 bgr_ptr[1] = FXARGB_G(src_plt[0]); |
| 190 bgr_ptr[2] = FXARGB_R(src_plt[0]); | 190 bgr_ptr[2] = FXARGB_R(src_plt[0]); |
| 191 bgr_ptr[3] = FXARGB_B(src_plt[1]); | 191 bgr_ptr[3] = FXARGB_B(src_plt[1]); |
| 192 bgr_ptr[4] = FXARGB_G(src_plt[1]); | 192 bgr_ptr[4] = FXARGB_G(src_plt[1]); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 231 return TRUE; | 231 return TRUE; |
| 232 } | 232 } |
| 233 FX_BOOL ConvertBuffer_8bppPlt2Gray(uint8_t* dest_buf, | 233 FX_BOOL ConvertBuffer_8bppPlt2Gray(uint8_t* dest_buf, |
| 234 int dest_pitch, | 234 int dest_pitch, |
| 235 int width, | 235 int width, |
| 236 int height, | 236 int height, |
| 237 const CFX_DIBSource* pSrcBitmap, | 237 const CFX_DIBSource* pSrcBitmap, |
| 238 int src_left, | 238 int src_left, |
| 239 int src_top, | 239 int src_top, |
| 240 void* pIccTransform) { | 240 void* pIccTransform) { |
| 241 FX_DWORD* src_plt = pSrcBitmap->GetPalette(); | 241 uint32_t* src_plt = pSrcBitmap->GetPalette(); |
| 242 uint8_t gray[256]; | 242 uint8_t gray[256]; |
| 243 if (pIccTransform) { | 243 if (pIccTransform) { |
| 244 FX_DWORD plt[256]; | 244 uint32_t plt[256]; |
| 245 if (pSrcBitmap->IsCmykImage()) { | 245 if (pSrcBitmap->IsCmykImage()) { |
| 246 for (int i = 0; i < 256; i++) { | 246 for (int i = 0; i < 256; i++) { |
| 247 plt[i] = FXCMYK_TODIB(src_plt[i]); | 247 plt[i] = FXCMYK_TODIB(src_plt[i]); |
| 248 } | 248 } |
| 249 } else { | 249 } else { |
| 250 uint8_t* bgr_ptr = (uint8_t*)plt; | 250 uint8_t* bgr_ptr = (uint8_t*)plt; |
| 251 for (int i = 0; i < 256; i++) { | 251 for (int i = 0; i < 256; i++) { |
| 252 *bgr_ptr++ = FXARGB_B(src_plt[i]); | 252 *bgr_ptr++ = FXARGB_B(src_plt[i]); |
| 253 *bgr_ptr++ = FXARGB_G(src_plt[i]); | 253 *bgr_ptr++ = FXARGB_G(src_plt[i]); |
| 254 *bgr_ptr++ = FXARGB_R(src_plt[i]); | 254 *bgr_ptr++ = FXARGB_R(src_plt[i]); |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 316 } | 316 } |
| 317 } | 317 } |
| 318 } else { | 318 } else { |
| 319 if (pSrcBitmap->IsCmykImage()) { | 319 if (pSrcBitmap->IsCmykImage()) { |
| 320 for (int row = 0; row < height; row++) { | 320 for (int row = 0; row < height; row++) { |
| 321 uint8_t* dest_scan = dest_buf + row * dest_pitch; | 321 uint8_t* dest_scan = dest_buf + row * dest_pitch; |
| 322 const uint8_t* src_scan = | 322 const uint8_t* src_scan = |
| 323 pSrcBitmap->GetScanline(src_top + row) + src_left * 4; | 323 pSrcBitmap->GetScanline(src_top + row) + src_left * 4; |
| 324 for (int col = 0; col < width; col++) { | 324 for (int col = 0; col < width; col++) { |
| 325 uint8_t r, g, b; | 325 uint8_t r, g, b; |
| 326 AdobeCMYK_to_sRGB1(FXSYS_GetCValue((FX_DWORD)src_scan[0]), | 326 AdobeCMYK_to_sRGB1(FXSYS_GetCValue((uint32_t)src_scan[0]), |
| 327 FXSYS_GetMValue((FX_DWORD)src_scan[1]), | 327 FXSYS_GetMValue((uint32_t)src_scan[1]), |
| 328 FXSYS_GetYValue((FX_DWORD)src_scan[2]), | 328 FXSYS_GetYValue((uint32_t)src_scan[2]), |
| 329 FXSYS_GetKValue((FX_DWORD)src_scan[3]), r, g, b); | 329 FXSYS_GetKValue((uint32_t)src_scan[3]), r, g, b); |
| 330 *dest_scan++ = FXRGB2GRAY(r, g, b); | 330 *dest_scan++ = FXRGB2GRAY(r, g, b); |
| 331 src_scan += 4; | 331 src_scan += 4; |
| 332 } | 332 } |
| 333 } | 333 } |
| 334 } else { | 334 } else { |
| 335 for (int row = 0; row < height; row++) { | 335 for (int row = 0; row < height; row++) { |
| 336 uint8_t* dest_scan = dest_buf + row * dest_pitch; | 336 uint8_t* dest_scan = dest_buf + row * dest_pitch; |
| 337 const uint8_t* src_scan = | 337 const uint8_t* src_scan = |
| 338 pSrcBitmap->GetScanline(src_top + row) + src_left * Bpp; | 338 pSrcBitmap->GetScanline(src_top + row) + src_left * Bpp; |
| 339 for (int col = 0; col < width; col++) { | 339 for (int col = 0; col < width; col++) { |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 373 } | 373 } |
| 374 } | 374 } |
| 375 } | 375 } |
| 376 FX_BOOL ConvertBuffer_Plt2PltRgb8(uint8_t* dest_buf, | 376 FX_BOOL ConvertBuffer_Plt2PltRgb8(uint8_t* dest_buf, |
| 377 int dest_pitch, | 377 int dest_pitch, |
| 378 int width, | 378 int width, |
| 379 int height, | 379 int height, |
| 380 const CFX_DIBSource* pSrcBitmap, | 380 const CFX_DIBSource* pSrcBitmap, |
| 381 int src_left, | 381 int src_left, |
| 382 int src_top, | 382 int src_top, |
| 383 FX_DWORD* dst_plt, | 383 uint32_t* dst_plt, |
| 384 void* pIccTransform) { | 384 void* pIccTransform) { |
| 385 ConvertBuffer_IndexCopy(dest_buf, dest_pitch, width, height, pSrcBitmap, | 385 ConvertBuffer_IndexCopy(dest_buf, dest_pitch, width, height, pSrcBitmap, |
| 386 src_left, src_top); | 386 src_left, src_top); |
| 387 FX_DWORD* src_plt = pSrcBitmap->GetPalette(); | 387 uint32_t* src_plt = pSrcBitmap->GetPalette(); |
| 388 int plt_size = pSrcBitmap->GetPaletteSize(); | 388 int plt_size = pSrcBitmap->GetPaletteSize(); |
| 389 if (pIccTransform) { | 389 if (pIccTransform) { |
| 390 FX_DWORD plt[256]; | 390 uint32_t plt[256]; |
| 391 uint8_t* bgr_ptr = (uint8_t*)plt; | 391 uint8_t* bgr_ptr = (uint8_t*)plt; |
| 392 if (pSrcBitmap->IsCmykImage()) { | 392 if (pSrcBitmap->IsCmykImage()) { |
| 393 for (int i = 0; i < plt_size; i++) { | 393 for (int i = 0; i < plt_size; i++) { |
| 394 plt[i] = FXCMYK_TODIB(src_plt[i]); | 394 plt[i] = FXCMYK_TODIB(src_plt[i]); |
| 395 } | 395 } |
| 396 } else { | 396 } else { |
| 397 for (int i = 0; i < plt_size; i++) { | 397 for (int i = 0; i < plt_size; i++) { |
| 398 *bgr_ptr++ = FXARGB_B(src_plt[i]); | 398 *bgr_ptr++ = FXARGB_B(src_plt[i]); |
| 399 *bgr_ptr++ = FXARGB_G(src_plt[i]); | 399 *bgr_ptr++ = FXARGB_G(src_plt[i]); |
| 400 *bgr_ptr++ = FXARGB_R(src_plt[i]); | 400 *bgr_ptr++ = FXARGB_R(src_plt[i]); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 424 } | 424 } |
| 425 return TRUE; | 425 return TRUE; |
| 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 FX_DWORD* dst_plt) { | 434 uint32_t* dst_plt) { |
| 435 int bpp = pSrcBitmap->GetBPP() / 8; | 435 int bpp = pSrcBitmap->GetBPP() / 8; |
| 436 int row, col; | 436 int row, col; |
| 437 CFX_Palette palette; | 437 CFX_Palette palette; |
| 438 palette.BuildPalette(pSrcBitmap); | 438 palette.BuildPalette(pSrcBitmap); |
| 439 FX_DWORD* cLut = palette.GetColorLut(); | 439 uint32_t* cLut = palette.GetColorLut(); |
| 440 FX_DWORD* aLut = palette.GetAmountLut(); | 440 uint32_t* aLut = palette.GetAmountLut(); |
| 441 if (!cLut || !aLut) { | 441 if (!cLut || !aLut) { |
| 442 return FALSE; | 442 return FALSE; |
| 443 } | 443 } |
| 444 int lut = palette.Getlut(); | 444 int lut = palette.Getlut(); |
| 445 FX_DWORD* pPalette = palette.GetPalette(); | 445 uint32_t* pPalette = palette.GetPalette(); |
| 446 if (lut > 256) { | 446 if (lut > 256) { |
| 447 int err, min_err; | 447 int err, min_err; |
| 448 int lut_256 = lut - 256; | 448 int lut_256 = lut - 256; |
| 449 for (row = 0; row < lut_256; row++) { | 449 for (row = 0; row < lut_256; row++) { |
| 450 min_err = 1000000; | 450 min_err = 1000000; |
| 451 uint8_t r, g, b; | 451 uint8_t r, g, b; |
| 452 _ColorDecode(cLut[row], r, g, b); | 452 _ColorDecode(cLut[row], r, g, b); |
| 453 int clrindex = 0; | 453 int clrindex = 0; |
| 454 for (int col = 0; col < 256; col++) { | 454 for (int col = 0; col < 256; col++) { |
| 455 FX_DWORD p_color = *(pPalette + col); | 455 uint32_t p_color = *(pPalette + col); |
| 456 int d_r = r - (uint8_t)(p_color >> 16); | 456 int d_r = r - (uint8_t)(p_color >> 16); |
| 457 int d_g = g - (uint8_t)(p_color >> 8); | 457 int d_g = g - (uint8_t)(p_color >> 8); |
| 458 int d_b = b - (uint8_t)(p_color); | 458 int d_b = b - (uint8_t)(p_color); |
| 459 err = d_r * d_r + d_g * d_g + d_b * d_b; | 459 err = d_r * d_r + d_g * d_g + d_b * d_b; |
| 460 if (err < min_err) { | 460 if (err < min_err) { |
| 461 min_err = err; | 461 min_err = err; |
| 462 clrindex = col; | 462 clrindex = col; |
| 463 } | 463 } |
| 464 } | 464 } |
| 465 aLut[row] = clrindex; | 465 aLut[row] = clrindex; |
| 466 } | 466 } |
| 467 } | 467 } |
| 468 int32_t lut_1 = lut - 1; | 468 int32_t lut_1 = lut - 1; |
| 469 for (row = 0; row < height; row++) { | 469 for (row = 0; row < height; row++) { |
| 470 uint8_t* src_scan = | 470 uint8_t* src_scan = |
| 471 (uint8_t*)pSrcBitmap->GetScanline(src_top + row) + src_left; | 471 (uint8_t*)pSrcBitmap->GetScanline(src_top + row) + src_left; |
| 472 uint8_t* dest_scan = dest_buf + row * dest_pitch; | 472 uint8_t* dest_scan = dest_buf + row * dest_pitch; |
| 473 for (col = 0; col < width; col++) { | 473 for (col = 0; col < width; col++) { |
| 474 uint8_t* src_port = src_scan + col * bpp; | 474 uint8_t* src_port = src_scan + col * bpp; |
| 475 int r = src_port[2] & 0xf0; | 475 int r = src_port[2] & 0xf0; |
| 476 int g = src_port[1] & 0xf0; | 476 int g = src_port[1] & 0xf0; |
| 477 int b = src_port[0] & 0xf0; | 477 int b = src_port[0] & 0xf0; |
| 478 FX_DWORD clrindex = (r << 4) + g + (b >> 4); | 478 uint32_t clrindex = (r << 4) + g + (b >> 4); |
| 479 for (int i = lut_1; i >= 0; i--) | 479 for (int i = lut_1; i >= 0; i--) |
| 480 if (clrindex == cLut[i]) { | 480 if (clrindex == cLut[i]) { |
| 481 *(dest_scan + col) = (uint8_t)(aLut[i]); | 481 *(dest_scan + col) = (uint8_t)(aLut[i]); |
| 482 break; | 482 break; |
| 483 } | 483 } |
| 484 } | 484 } |
| 485 } | 485 } |
| 486 FXSYS_memcpy(dst_plt, pPalette, sizeof(FX_DWORD) * 256); | 486 FXSYS_memcpy(dst_plt, pPalette, sizeof(uint32_t) * 256); |
| 487 return TRUE; | 487 return TRUE; |
| 488 } | 488 } |
| 489 FX_BOOL ConvertBuffer_Rgb2PltRgb8(uint8_t* dest_buf, | 489 FX_BOOL ConvertBuffer_Rgb2PltRgb8(uint8_t* dest_buf, |
| 490 int dest_pitch, | 490 int dest_pitch, |
| 491 int width, | 491 int width, |
| 492 int height, | 492 int height, |
| 493 const CFX_DIBSource* pSrcBitmap, | 493 const CFX_DIBSource* pSrcBitmap, |
| 494 int src_left, | 494 int src_left, |
| 495 int src_top, | 495 int src_top, |
| 496 FX_DWORD* dst_plt, | 496 uint32_t* dst_plt, |
| 497 void* pIccTransform) { | 497 void* pIccTransform) { |
| 498 FX_BOOL ret = ConvertBuffer_Rgb2PltRgb8_NoTransform( | 498 FX_BOOL ret = ConvertBuffer_Rgb2PltRgb8_NoTransform( |
| 499 dest_buf, dest_pitch, width, height, pSrcBitmap, src_left, src_top, | 499 dest_buf, dest_pitch, width, height, pSrcBitmap, src_left, src_top, |
| 500 dst_plt); | 500 dst_plt); |
| 501 if (ret && pIccTransform) { | 501 if (ret && pIccTransform) { |
| 502 ICodec_IccModule* pIccModule = | 502 ICodec_IccModule* pIccModule = |
| 503 CFX_GEModule::Get()->GetCodecModule()->GetIccModule(); | 503 CFX_GEModule::Get()->GetCodecModule()->GetIccModule(); |
| 504 for (int i = 0; i < 256; i++) { | 504 for (int i = 0; i < 256; i++) { |
| 505 FX_ARGB* plt = dst_plt + i; | 505 FX_ARGB* plt = dst_plt + i; |
| 506 FX_ARGB plt_entry = FXARGB_TODIB(*plt); | 506 FX_ARGB plt_entry = FXARGB_TODIB(*plt); |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 567 FX_BOOL ConvertBuffer_1bppPlt2Rgb(FXDIB_Format dst_format, | 567 FX_BOOL ConvertBuffer_1bppPlt2Rgb(FXDIB_Format dst_format, |
| 568 uint8_t* dest_buf, | 568 uint8_t* dest_buf, |
| 569 int dest_pitch, | 569 int dest_pitch, |
| 570 int width, | 570 int width, |
| 571 int height, | 571 int height, |
| 572 const CFX_DIBSource* pSrcBitmap, | 572 const CFX_DIBSource* pSrcBitmap, |
| 573 int src_left, | 573 int src_left, |
| 574 int src_top, | 574 int src_top, |
| 575 void* pIccTransform) { | 575 void* pIccTransform) { |
| 576 int comps = (dst_format & 0xff) / 8; | 576 int comps = (dst_format & 0xff) / 8; |
| 577 FX_DWORD* src_plt = pSrcBitmap->GetPalette(); | 577 uint32_t* src_plt = pSrcBitmap->GetPalette(); |
| 578 FX_DWORD plt[2]; | 578 uint32_t plt[2]; |
| 579 uint8_t* bgr_ptr = (uint8_t*)plt; | 579 uint8_t* bgr_ptr = (uint8_t*)plt; |
| 580 if (pSrcBitmap->IsCmykImage()) { | 580 if (pSrcBitmap->IsCmykImage()) { |
| 581 plt[0] = FXCMYK_TODIB(src_plt[0]); | 581 plt[0] = FXCMYK_TODIB(src_plt[0]); |
| 582 plt[1] = FXCMYK_TODIB(src_plt[1]); | 582 plt[1] = FXCMYK_TODIB(src_plt[1]); |
| 583 } else { | 583 } else { |
| 584 bgr_ptr[0] = FXARGB_B(src_plt[0]); | 584 bgr_ptr[0] = FXARGB_B(src_plt[0]); |
| 585 bgr_ptr[1] = FXARGB_G(src_plt[0]); | 585 bgr_ptr[1] = FXARGB_G(src_plt[0]); |
| 586 bgr_ptr[2] = FXARGB_R(src_plt[0]); | 586 bgr_ptr[2] = FXARGB_R(src_plt[0]); |
| 587 bgr_ptr[3] = FXARGB_B(src_plt[1]); | 587 bgr_ptr[3] = FXARGB_B(src_plt[1]); |
| 588 bgr_ptr[4] = FXARGB_G(src_plt[1]); | 588 bgr_ptr[4] = FXARGB_G(src_plt[1]); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 626 FX_BOOL ConvertBuffer_8bppPlt2Rgb(FXDIB_Format dst_format, | 626 FX_BOOL ConvertBuffer_8bppPlt2Rgb(FXDIB_Format dst_format, |
| 627 uint8_t* dest_buf, | 627 uint8_t* dest_buf, |
| 628 int dest_pitch, | 628 int dest_pitch, |
| 629 int width, | 629 int width, |
| 630 int height, | 630 int height, |
| 631 const CFX_DIBSource* pSrcBitmap, | 631 const CFX_DIBSource* pSrcBitmap, |
| 632 int src_left, | 632 int src_left, |
| 633 int src_top, | 633 int src_top, |
| 634 void* pIccTransform) { | 634 void* pIccTransform) { |
| 635 int comps = (dst_format & 0xff) / 8; | 635 int comps = (dst_format & 0xff) / 8; |
| 636 FX_DWORD* src_plt = pSrcBitmap->GetPalette(); | 636 uint32_t* src_plt = pSrcBitmap->GetPalette(); |
| 637 FX_DWORD plt[256]; | 637 uint32_t plt[256]; |
| 638 uint8_t* bgr_ptr = (uint8_t*)plt; | 638 uint8_t* bgr_ptr = (uint8_t*)plt; |
| 639 if (!pSrcBitmap->IsCmykImage()) { | 639 if (!pSrcBitmap->IsCmykImage()) { |
| 640 for (int i = 0; i < 256; i++) { | 640 for (int i = 0; i < 256; i++) { |
| 641 *bgr_ptr++ = FXARGB_B(src_plt[i]); | 641 *bgr_ptr++ = FXARGB_B(src_plt[i]); |
| 642 *bgr_ptr++ = FXARGB_G(src_plt[i]); | 642 *bgr_ptr++ = FXARGB_G(src_plt[i]); |
| 643 *bgr_ptr++ = FXARGB_R(src_plt[i]); | 643 *bgr_ptr++ = FXARGB_R(src_plt[i]); |
| 644 } | 644 } |
| 645 bgr_ptr = (uint8_t*)plt; | 645 bgr_ptr = (uint8_t*)plt; |
| 646 } | 646 } |
| 647 if (pIccTransform) { | 647 if (pIccTransform) { |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 810 return TRUE; | 810 return TRUE; |
| 811 } | 811 } |
| 812 FX_BOOL ConvertBuffer(FXDIB_Format dest_format, | 812 FX_BOOL ConvertBuffer(FXDIB_Format dest_format, |
| 813 uint8_t* dest_buf, | 813 uint8_t* dest_buf, |
| 814 int dest_pitch, | 814 int dest_pitch, |
| 815 int width, | 815 int width, |
| 816 int height, | 816 int height, |
| 817 const CFX_DIBSource* pSrcBitmap, | 817 const CFX_DIBSource* pSrcBitmap, |
| 818 int src_left, | 818 int src_left, |
| 819 int src_top, | 819 int src_top, |
| 820 FX_DWORD*& d_pal, | 820 uint32_t*& d_pal, |
| 821 void* pIccTransform) { | 821 void* pIccTransform) { |
| 822 FXDIB_Format src_format = pSrcBitmap->GetFormat(); | 822 FXDIB_Format src_format = pSrcBitmap->GetFormat(); |
| 823 if (!CFX_GEModule::Get()->GetCodecModule() || | 823 if (!CFX_GEModule::Get()->GetCodecModule() || |
| 824 !CFX_GEModule::Get()->GetCodecModule()->GetIccModule()) { | 824 !CFX_GEModule::Get()->GetCodecModule()->GetIccModule()) { |
| 825 pIccTransform = NULL; | 825 pIccTransform = NULL; |
| 826 } | 826 } |
| 827 switch (dest_format) { | 827 switch (dest_format) { |
| 828 case FXDIB_Invalid: | 828 case FXDIB_Invalid: |
| 829 case FXDIB_1bppCmyk: | 829 case FXDIB_1bppCmyk: |
| 830 case FXDIB_1bppMask: | 830 case FXDIB_1bppMask: |
| (...skipping 26 matching lines...) Expand all Loading... |
| 857 } | 857 } |
| 858 return FALSE; | 858 return FALSE; |
| 859 } | 859 } |
| 860 case FXDIB_8bppRgb: | 860 case FXDIB_8bppRgb: |
| 861 case FXDIB_8bppRgba: { | 861 case FXDIB_8bppRgba: { |
| 862 if ((src_format & 0xff) == 8 && !pSrcBitmap->GetPalette()) { | 862 if ((src_format & 0xff) == 8 && !pSrcBitmap->GetPalette()) { |
| 863 return ConvertBuffer(FXDIB_8bppMask, dest_buf, dest_pitch, width, | 863 return ConvertBuffer(FXDIB_8bppMask, dest_buf, dest_pitch, width, |
| 864 height, pSrcBitmap, src_left, src_top, d_pal, | 864 height, pSrcBitmap, src_left, src_top, d_pal, |
| 865 pIccTransform); | 865 pIccTransform); |
| 866 } | 866 } |
| 867 d_pal = FX_Alloc(FX_DWORD, 256); | 867 d_pal = FX_Alloc(uint32_t, 256); |
| 868 if (((src_format & 0xff) == 1 || (src_format & 0xff) == 8) && | 868 if (((src_format & 0xff) == 1 || (src_format & 0xff) == 8) && |
| 869 pSrcBitmap->GetPalette()) { | 869 pSrcBitmap->GetPalette()) { |
| 870 return ConvertBuffer_Plt2PltRgb8(dest_buf, dest_pitch, width, height, | 870 return ConvertBuffer_Plt2PltRgb8(dest_buf, dest_pitch, width, height, |
| 871 pSrcBitmap, src_left, src_top, d_pal, | 871 pSrcBitmap, src_left, src_top, d_pal, |
| 872 pIccTransform); | 872 pIccTransform); |
| 873 } | 873 } |
| 874 if ((src_format & 0xff) >= 24) { | 874 if ((src_format & 0xff) >= 24) { |
| 875 return ConvertBuffer_Rgb2PltRgb8(dest_buf, dest_pitch, width, height, | 875 return ConvertBuffer_Rgb2PltRgb8(dest_buf, dest_pitch, width, height, |
| 876 pSrcBitmap, src_left, src_top, d_pal, | 876 pSrcBitmap, src_left, src_top, d_pal, |
| 877 pIccTransform); | 877 pIccTransform); |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 990 } | 990 } |
| 991 } | 991 } |
| 992 if (pSrcAlpha && pSrcAlpha != m_pAlphaMask) { | 992 if (pSrcAlpha && pSrcAlpha != m_pAlphaMask) { |
| 993 delete pSrcAlpha; | 993 delete pSrcAlpha; |
| 994 pSrcAlpha = NULL; | 994 pSrcAlpha = NULL; |
| 995 } | 995 } |
| 996 if (!ret) { | 996 if (!ret) { |
| 997 delete pClone; | 997 delete pClone; |
| 998 return NULL; | 998 return NULL; |
| 999 } | 999 } |
| 1000 FX_DWORD* pal_8bpp = NULL; | 1000 uint32_t* pal_8bpp = NULL; |
| 1001 ret = ConvertBuffer(dest_format, pClone->GetBuffer(), pClone->GetPitch(), | 1001 ret = ConvertBuffer(dest_format, pClone->GetBuffer(), pClone->GetPitch(), |
| 1002 m_Width, m_Height, this, 0, 0, pal_8bpp, pIccTransform); | 1002 m_Width, m_Height, this, 0, 0, pal_8bpp, pIccTransform); |
| 1003 if (!ret) { | 1003 if (!ret) { |
| 1004 FX_Free(pal_8bpp); | 1004 FX_Free(pal_8bpp); |
| 1005 delete pClone; | 1005 delete pClone; |
| 1006 return NULL; | 1006 return NULL; |
| 1007 } | 1007 } |
| 1008 if (pal_8bpp) { | 1008 if (pal_8bpp) { |
| 1009 pClone->CopyPalette(pal_8bpp); | 1009 pClone->CopyPalette(pal_8bpp); |
| 1010 FX_Free(pal_8bpp); | 1010 FX_Free(pal_8bpp); |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1068 return FALSE; | 1068 return FALSE; |
| 1069 } | 1069 } |
| 1070 pAlphaMask = m_pAlphaMask; | 1070 pAlphaMask = m_pAlphaMask; |
| 1071 m_pAlphaMask = NULL; | 1071 m_pAlphaMask = NULL; |
| 1072 } else { | 1072 } else { |
| 1073 pAlphaMask = m_pAlphaMask; | 1073 pAlphaMask = m_pAlphaMask; |
| 1074 } | 1074 } |
| 1075 } | 1075 } |
| 1076 } | 1076 } |
| 1077 FX_BOOL ret = FALSE; | 1077 FX_BOOL ret = FALSE; |
| 1078 FX_DWORD* pal_8bpp = NULL; | 1078 uint32_t* pal_8bpp = NULL; |
| 1079 ret = ConvertBuffer(dest_format, dest_buf, dest_pitch, m_Width, m_Height, | 1079 ret = ConvertBuffer(dest_format, dest_buf, dest_pitch, m_Width, m_Height, |
| 1080 this, 0, 0, pal_8bpp, pIccTransform); | 1080 this, 0, 0, pal_8bpp, pIccTransform); |
| 1081 if (!ret) { | 1081 if (!ret) { |
| 1082 FX_Free(pal_8bpp); | 1082 FX_Free(pal_8bpp); |
| 1083 if (pAlphaMask != m_pAlphaMask) { | 1083 if (pAlphaMask != m_pAlphaMask) { |
| 1084 delete pAlphaMask; | 1084 delete pAlphaMask; |
| 1085 } | 1085 } |
| 1086 FX_Free(dest_buf); | 1086 FX_Free(dest_buf); |
| 1087 return FALSE; | 1087 return FALSE; |
| 1088 } | 1088 } |
| 1089 if (m_pAlphaMask && pAlphaMask != m_pAlphaMask) { | 1089 if (m_pAlphaMask && pAlphaMask != m_pAlphaMask) { |
| 1090 delete m_pAlphaMask; | 1090 delete m_pAlphaMask; |
| 1091 } | 1091 } |
| 1092 m_pAlphaMask = pAlphaMask; | 1092 m_pAlphaMask = pAlphaMask; |
| 1093 FX_Free(m_pPalette); | 1093 FX_Free(m_pPalette); |
| 1094 m_pPalette = pal_8bpp; | 1094 m_pPalette = pal_8bpp; |
| 1095 if (!m_bExtBuf) { | 1095 if (!m_bExtBuf) { |
| 1096 FX_Free(m_pBuffer); | 1096 FX_Free(m_pBuffer); |
| 1097 } | 1097 } |
| 1098 m_bExtBuf = FALSE; | 1098 m_bExtBuf = FALSE; |
| 1099 m_pBuffer = dest_buf; | 1099 m_pBuffer = dest_buf; |
| 1100 m_bpp = (uint8_t)dest_format; | 1100 m_bpp = (uint8_t)dest_format; |
| 1101 m_AlphaFlag = (uint8_t)(dest_format >> 8); | 1101 m_AlphaFlag = (uint8_t)(dest_format >> 8); |
| 1102 m_Pitch = dest_pitch; | 1102 m_Pitch = dest_pitch; |
| 1103 return TRUE; | 1103 return TRUE; |
| 1104 } | 1104 } |
| OLD | NEW |