| OLD | NEW |
| 1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
| 6 | 6 |
| 7 #include "../../../include/fxge/fx_dib.h" | 7 #include "../../../include/fxge/fx_dib.h" |
| 8 #include "../../../include/fxge/fx_ge.h" | 8 #include "../../../include/fxge/fx_ge.h" |
| 9 #include "../../../include/fxcodec/fx_codec.h" | 9 #include "../../../include/fxcodec/fx_codec.h" |
| 10 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 Loading... |
| 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 Loading... |
| 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 Loading... |
| 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 Loading... |
| 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 Loading... |
| 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 Loading... |
| 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 { |
| 579 FX_BOOL ret = _ConvertBuffer_Rgb2PltRgb8_NoTransform(dest_buf, dest_pitch, w
idth, height, pSrcBitmap, src_left, src_top, dst_plt); | 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) { | 580 if (ret && pIccTransform) { |
| 581 ICodec_IccModule* pIccModule = CFX_GEModule::Get()->GetCodecModule()->Ge
tIccModule(); | 581 ICodec_IccModule* pIccModule = CFX_GEModule::Get()->GetCodecModule()->Ge
tIccModule(); |
| 582 for (int i = 0; i < 256; i++) { | 582 for (int i = 0; i < 256; i++) { |
| 583 FX_ARGB* plt = dst_plt + i; | 583 FX_ARGB* plt = dst_plt + i; |
| 584 FX_ARGB plt_entry = FXARGB_TODIB(*plt); | 584 FX_ARGB plt_entry = FXARGB_TODIB(*plt); |
| 585 pIccModule->TranslateScanline(pIccTransform, (FX_LPBYTE)&plt_entry,
(FX_LPCBYTE)&plt_entry, 1); | 585 pIccModule->TranslateScanline(pIccTransform, (FX_LPBYTE)&plt_entry,
(FX_LPCBYTE)&plt_entry, 1); |
| 586 *plt = FXARGB_TODIB(plt_entry); | 586 *plt = FXARGB_TODIB(plt_entry); |
| 587 } | 587 } |
| 588 } | 588 } |
| 589 return ret; | 589 return ret; |
| 590 } | 590 } |
| 591 FX_BOOL _ConvertBuffer_1bppMask2Rgb(FXDIB_Format dst_format, FX_LPBYTE dest_buf,
int dest_pitch, int width, int height, | 591 FX_BOOL _ConvertBuffer_1bppMask2Rgb(FXDIB_Format dst_format, FX_LPBYTE dest_buf,
int dest_pitch, int width, int height, |
| 592 const CFX_DIBSource* pSrcBitmap, int src_lef
t, int src_top) | 592 const CFX_DIBSource* pSrcBitmap, int src_lef
t, int src_top) |
| 593 { | 593 { |
| 594 int comps = (dst_format & 0xff) / 8; | 594 int comps = (dst_format & 0xff) / 8; |
| 595 FX_BYTE set_gray, reset_gray; | 595 uint8_t set_gray, reset_gray; |
| 596 set_gray = 0xff; | 596 set_gray = 0xff; |
| 597 reset_gray = 0x00; | 597 reset_gray = 0x00; |
| 598 for (int row = 0; row < height; row ++) { | 598 for (int row = 0; row < height; row ++) { |
| 599 FX_LPBYTE dest_scan = dest_buf + row * dest_pitch; | 599 FX_LPBYTE dest_scan = dest_buf + row * dest_pitch; |
| 600 FX_LPCBYTE src_scan = pSrcBitmap->GetScanline(src_top + row); | 600 FX_LPCBYTE src_scan = pSrcBitmap->GetScanline(src_top + row); |
| 601 for (int col = src_left; col < src_left + width; col ++) { | 601 for (int col = src_left; col < src_left + width; col ++) { |
| 602 if (src_scan[col / 8] & (1 << (7 - col % 8))) { | 602 if (src_scan[col / 8] & (1 << (7 - col % 8))) { |
| 603 dest_scan[0] = set_gray; | 603 dest_scan[0] = set_gray; |
| 604 dest_scan[1] = set_gray; | 604 dest_scan[1] = set_gray; |
| 605 dest_scan[2] = set_gray; | 605 dest_scan[2] = set_gray; |
| 606 } else { | 606 } else { |
| 607 dest_scan[0] = reset_gray; | 607 dest_scan[0] = reset_gray; |
| 608 dest_scan[1] = reset_gray; | 608 dest_scan[1] = reset_gray; |
| 609 dest_scan[2] = reset_gray; | 609 dest_scan[2] = reset_gray; |
| 610 } | 610 } |
| 611 dest_scan += comps; | 611 dest_scan += comps; |
| 612 } | 612 } |
| 613 } | 613 } |
| 614 return TRUE; | 614 return TRUE; |
| 615 } | 615 } |
| 616 FX_BOOL _ConvertBuffer_8bppMask2Rgb(FXDIB_Format dst_format, FX_LPBYTE dest_buf,
int dest_pitch, int width, int height, | 616 FX_BOOL _ConvertBuffer_8bppMask2Rgb(FXDIB_Format dst_format, FX_LPBYTE dest_buf,
int dest_pitch, int width, int height, |
| 617 const CFX_DIBSource* pSrcBitmap, int src_lef
t, int src_top) | 617 const CFX_DIBSource* pSrcBitmap, int src_lef
t, int src_top) |
| 618 { | 618 { |
| 619 int comps = (dst_format & 0xff) / 8; | 619 int comps = (dst_format & 0xff) / 8; |
| 620 for (int row = 0; row < height; row ++) { | 620 for (int row = 0; row < height; row ++) { |
| 621 FX_LPBYTE dest_scan = dest_buf + row * dest_pitch; | 621 FX_LPBYTE dest_scan = dest_buf + row * dest_pitch; |
| 622 FX_LPCBYTE src_scan = pSrcBitmap->GetScanline(src_top + row) + src_left; | 622 FX_LPCBYTE src_scan = pSrcBitmap->GetScanline(src_top + row) + src_left; |
| 623 FX_BYTE src_pixel; | 623 uint8_t src_pixel; |
| 624 for (int col = 0; col < width; col ++) { | 624 for (int col = 0; col < width; col ++) { |
| 625 src_pixel = *src_scan++; | 625 src_pixel = *src_scan++; |
| 626 *dest_scan++ = src_pixel; | 626 *dest_scan++ = src_pixel; |
| 627 *dest_scan++ = src_pixel; | 627 *dest_scan++ = src_pixel; |
| 628 *dest_scan = src_pixel; | 628 *dest_scan = src_pixel; |
| 629 dest_scan += comps - 2; | 629 dest_scan += comps - 2; |
| 630 } | 630 } |
| 631 } | 631 } |
| 632 return TRUE; | 632 return TRUE; |
| 633 } | 633 } |
| (...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 989 FX_LPBYTE scanline = m_pBuffer + row * m_Pitch + 3; | 989 FX_LPBYTE scanline = m_pBuffer + row * m_Pitch + 3; |
| 990 for (int col = 0; col < m_Width; col ++) { | 990 for (int col = 0; col < m_Width; col ++) { |
| 991 *scanline = 0xff; | 991 *scanline = 0xff; |
| 992 scanline += 4; | 992 scanline += 4; |
| 993 } | 993 } |
| 994 } | 994 } |
| 995 return TRUE; | 995 return TRUE; |
| 996 } | 996 } |
| 997 int dest_bpp = dest_format & 0xff; | 997 int dest_bpp = dest_format & 0xff; |
| 998 int dest_pitch = (dest_bpp * m_Width + 31) / 32 * 4; | 998 int dest_pitch = (dest_bpp * m_Width + 31) / 32 * 4; |
| 999 FX_LPBYTE dest_buf = FX_TryAlloc(FX_BYTE, dest_pitch * m_Height + 4); | 999 FX_LPBYTE dest_buf = FX_TryAlloc(uint8_t, dest_pitch * m_Height + 4); |
| 1000 if (dest_buf == NULL) { | 1000 if (dest_buf == NULL) { |
| 1001 return FALSE; | 1001 return FALSE; |
| 1002 } | 1002 } |
| 1003 CFX_DIBitmap* pAlphaMask = NULL; | 1003 CFX_DIBitmap* pAlphaMask = NULL; |
| 1004 if (dest_format == FXDIB_Argb) { | 1004 if (dest_format == FXDIB_Argb) { |
| 1005 FXSYS_memset8(dest_buf, 0xff, dest_pitch * m_Height + 4); | 1005 FXSYS_memset8(dest_buf, 0xff, dest_pitch * m_Height + 4); |
| 1006 if (m_pAlphaMask) { | 1006 if (m_pAlphaMask) { |
| 1007 for (int row = 0; row < m_Height; row ++) { | 1007 for (int row = 0; row < m_Height; row ++) { |
| 1008 FX_LPBYTE pDstScanline = dest_buf + row * dest_pitch + 3; | 1008 FX_LPBYTE pDstScanline = dest_buf + row * dest_pitch + 3; |
| 1009 FX_LPCBYTE pSrcScanline = m_pAlphaMask->GetScanline(row); | 1009 FX_LPCBYTE pSrcScanline = m_pAlphaMask->GetScanline(row); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1054 m_pAlphaMask = pAlphaMask; | 1054 m_pAlphaMask = pAlphaMask; |
| 1055 if (m_pPalette) { | 1055 if (m_pPalette) { |
| 1056 FX_Free(m_pPalette); | 1056 FX_Free(m_pPalette); |
| 1057 } | 1057 } |
| 1058 m_pPalette = pal_8bpp; | 1058 m_pPalette = pal_8bpp; |
| 1059 if (!m_bExtBuf) { | 1059 if (!m_bExtBuf) { |
| 1060 FX_Free(m_pBuffer); | 1060 FX_Free(m_pBuffer); |
| 1061 } | 1061 } |
| 1062 m_bExtBuf = FALSE; | 1062 m_bExtBuf = FALSE; |
| 1063 m_pBuffer = dest_buf; | 1063 m_pBuffer = dest_buf; |
| 1064 m_bpp = (FX_BYTE)dest_format; | 1064 m_bpp = (uint8_t)dest_format; |
| 1065 m_AlphaFlag = (FX_BYTE)(dest_format >> 8); | 1065 m_AlphaFlag = (uint8_t)(dest_format >> 8); |
| 1066 m_Pitch = dest_pitch; | 1066 m_Pitch = dest_pitch; |
| 1067 return TRUE; | 1067 return TRUE; |
| 1068 } | 1068 } |
| OLD | NEW |