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 "dib_int.h" | 8 #include "dib_int.h" |
9 int SDP_Table[513] = { | 9 int SDP_Table[513] = { |
10 256, 256, 256, 256, 256, 256, 256, 256, 256, 255, 255, 255, 255, 255, 255, 2
54, 254, 254, 254, | 10 256, 256, 256, 256, 256, 256, 256, 256, 256, 255, 255, 255, 255, 255, 255, 2
54, 254, 254, 254, |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 if (res_x < 0 && res_x > -base) { | 47 if (res_x < 0 && res_x > -base) { |
48 res_x = base + res_x; | 48 res_x = base + res_x; |
49 } | 49 } |
50 if (res_y < 0 && res_x > -base) { | 50 if (res_y < 0 && res_x > -base) { |
51 res_y = base + res_y; | 51 res_y = base + res_y; |
52 } | 52 } |
53 x1 /= base; | 53 x1 /= base; |
54 y1 /= base; | 54 y1 /= base; |
55 } | 55 } |
56 }; | 56 }; |
57 CFX_DIBitmap* CFX_DIBSource::SwapXY(FX_BOOL bXFlip, FX_BOOL bYFlip, const FX_REC
T* pDestClip) const | 57 CFX_DIBitmap* CFX_DIBSource::SwapXY(bool bXFlip, bool bYFlip, const FX_RECT* pDe
stClip) const |
58 { | 58 { |
59 FX_RECT dest_clip(0, 0, m_Height, m_Width); | 59 FX_RECT dest_clip(0, 0, m_Height, m_Width); |
60 if (pDestClip) { | 60 if (pDestClip) { |
61 dest_clip.Intersect(*pDestClip); | 61 dest_clip.Intersect(*pDestClip); |
62 } | 62 } |
63 if (dest_clip.IsEmpty()) { | 63 if (dest_clip.IsEmpty()) { |
64 return NULL; | 64 return NULL; |
65 } | 65 } |
66 CFX_DIBitmap* pTransBitmap = new CFX_DIBitmap; | 66 CFX_DIBitmap* pTransBitmap = new CFX_DIBitmap; |
67 int result_height = dest_clip.Height(), result_width = dest_clip.Width(); | 67 int result_height = dest_clip.Height(), result_width = dest_clip.Width(); |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
141 const uint8_t* src_scan = m_pAlphaMask->GetScanline(row) + col_start
; | 141 const uint8_t* src_scan = m_pAlphaMask->GetScanline(row) + col_start
; |
142 for (int col = col_start; col < col_end; col ++) { | 142 for (int col = col_start; col < col_end; col ++) { |
143 *dest_scan = *src_scan++; | 143 *dest_scan = *src_scan++; |
144 dest_scan += dest_step; | 144 dest_scan += dest_step; |
145 } | 145 } |
146 } | 146 } |
147 } | 147 } |
148 return pTransBitmap; | 148 return pTransBitmap; |
149 } | 149 } |
150 #define FIX16_005 0.05f | 150 #define FIX16_005 0.05f |
151 FX_RECT _FXDIB_SwapClipBox(FX_RECT& clip, int width, int height, FX_BOOL bFlipX,
FX_BOOL bFlipY) | 151 FX_RECT _FXDIB_SwapClipBox(FX_RECT& clip, int width, int height, bool bFlipX, bo
ol bFlipY) |
152 { | 152 { |
153 FX_RECT rect; | 153 FX_RECT rect; |
154 if (bFlipY) { | 154 if (bFlipY) { |
155 rect.left = height - clip.top; | 155 rect.left = height - clip.top; |
156 rect.right = height - clip.bottom; | 156 rect.right = height - clip.bottom; |
157 } else { | 157 } else { |
158 rect.left = clip.top; | 158 rect.left = clip.top; |
159 rect.right = clip.bottom; | 159 rect.right = clip.bottom; |
160 } | 160 } |
161 if (bFlipX) { | 161 if (bFlipX) { |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
199 return storer.Detach(); | 199 return storer.Detach(); |
200 } | 200 } |
201 CFX_ImageTransformer::CFX_ImageTransformer() | 201 CFX_ImageTransformer::CFX_ImageTransformer() |
202 { | 202 { |
203 m_Status = 0; | 203 m_Status = 0; |
204 m_pMatrix = NULL; | 204 m_pMatrix = NULL; |
205 } | 205 } |
206 CFX_ImageTransformer::~CFX_ImageTransformer() | 206 CFX_ImageTransformer::~CFX_ImageTransformer() |
207 { | 207 { |
208 } | 208 } |
209 FX_BOOL CFX_ImageTransformer::Start(const CFX_DIBSource* pSrc, const CFX_AffineM
atrix* pDestMatrix, int flags, const FX_RECT* pDestClip) | 209 bool CFX_ImageTransformer::Start(const CFX_DIBSource* pSrc, const CFX_AffineMatr
ix* pDestMatrix, int flags, const FX_RECT* pDestClip) |
210 { | 210 { |
211 m_pMatrix = (CFX_AffineMatrix*)pDestMatrix; | 211 m_pMatrix = (CFX_AffineMatrix*)pDestMatrix; |
212 CFX_FloatRect unit_rect = pDestMatrix->GetUnitRect(); | 212 CFX_FloatRect unit_rect = pDestMatrix->GetUnitRect(); |
213 FX_RECT result_rect = unit_rect.GetClosestRect(); | 213 FX_RECT result_rect = unit_rect.GetClosestRect(); |
214 FX_RECT result_clip = result_rect; | 214 FX_RECT result_clip = result_rect; |
215 if (pDestClip) { | 215 if (pDestClip) { |
216 result_clip.Intersect(*pDestClip); | 216 result_clip.Intersect(*pDestClip); |
217 } | 217 } |
218 if (result_clip.IsEmpty()) { | 218 if (result_clip.IsEmpty()) { |
219 return FALSE; | 219 return false; |
220 } | 220 } |
221 m_ResultLeft = result_clip.left; | 221 m_ResultLeft = result_clip.left; |
222 m_ResultTop = result_clip.top; | 222 m_ResultTop = result_clip.top; |
223 m_ResultWidth = result_clip.Width(); | 223 m_ResultWidth = result_clip.Width(); |
224 m_ResultHeight = result_clip.Height(); | 224 m_ResultHeight = result_clip.Height(); |
225 m_Flags = flags; | 225 m_Flags = flags; |
226 if (FXSYS_fabs(pDestMatrix->a) < FXSYS_fabs(pDestMatrix->b) / 20 && | 226 if (FXSYS_fabs(pDestMatrix->a) < FXSYS_fabs(pDestMatrix->b) / 20 && |
227 FXSYS_fabs(pDestMatrix->d) < FXSYS_fabs(pDestMatrix->c) / 20 && | 227 FXSYS_fabs(pDestMatrix->d) < FXSYS_fabs(pDestMatrix->c) / 20 && |
228 FXSYS_fabs(pDestMatrix->a) < 0.5f && FXSYS_fabs(pDestMatrix->d) < 0.
5f) { | 228 FXSYS_fabs(pDestMatrix->a) < 0.5f && FXSYS_fabs(pDestMatrix->d) < 0.
5f) { |
229 int dest_width = result_rect.Width(); | 229 int dest_width = result_rect.Width(); |
230 int dest_height = result_rect.Height(); | 230 int dest_height = result_rect.Height(); |
231 result_clip.Offset(-result_rect.left, -result_rect.top); | 231 result_clip.Offset(-result_rect.left, -result_rect.top); |
232 result_clip = _FXDIB_SwapClipBox(result_clip, dest_width, dest_height, p
DestMatrix->c > 0, pDestMatrix->b < 0); | 232 result_clip = _FXDIB_SwapClipBox(result_clip, dest_width, dest_height, p
DestMatrix->c > 0, pDestMatrix->b < 0); |
233 m_Stretcher.Start(&m_Storer, pSrc, dest_height, dest_width, result_clip,
flags); | 233 m_Stretcher.Start(&m_Storer, pSrc, dest_height, dest_width, result_clip,
flags); |
234 m_Status = 1; | 234 m_Status = 1; |
235 return TRUE; | 235 return true; |
236 } | 236 } |
237 if (FXSYS_fabs(pDestMatrix->b) < FIX16_005 && FXSYS_fabs(pDestMatrix->c) < F
IX16_005) { | 237 if (FXSYS_fabs(pDestMatrix->b) < FIX16_005 && FXSYS_fabs(pDestMatrix->c) < F
IX16_005) { |
238 int dest_width = pDestMatrix->a > 0 ? (int)FXSYS_ceil(pDestMatrix->a) :
(int)FXSYS_floor(pDestMatrix->a); | 238 int dest_width = pDestMatrix->a > 0 ? (int)FXSYS_ceil(pDestMatrix->a) :
(int)FXSYS_floor(pDestMatrix->a); |
239 int dest_height = pDestMatrix->d > 0 ? (int) - FXSYS_ceil(pDestMatrix->d
) : (int) - FXSYS_floor(pDestMatrix->d); | 239 int dest_height = pDestMatrix->d > 0 ? (int) - FXSYS_ceil(pDestMatrix->d
) : (int) - FXSYS_floor(pDestMatrix->d); |
240 result_clip.Offset(-result_rect.left, -result_rect.top); | 240 result_clip.Offset(-result_rect.left, -result_rect.top); |
241 m_Stretcher.Start(&m_Storer, pSrc, dest_width, dest_height, result_clip,
flags); | 241 m_Stretcher.Start(&m_Storer, pSrc, dest_width, dest_height, result_clip,
flags); |
242 m_Status = 2; | 242 m_Status = 2; |
243 return TRUE; | 243 return true; |
244 } | 244 } |
245 int stretch_width = (int)FXSYS_ceil(FXSYS_sqrt2(pDestMatrix->a, pDestMatrix-
>b)); | 245 int stretch_width = (int)FXSYS_ceil(FXSYS_sqrt2(pDestMatrix->a, pDestMatrix-
>b)); |
246 int stretch_height = (int)FXSYS_ceil(FXSYS_sqrt2(pDestMatrix->c, pDestMatrix
->d)); | 246 int stretch_height = (int)FXSYS_ceil(FXSYS_sqrt2(pDestMatrix->c, pDestMatrix
->d)); |
247 CFX_AffineMatrix stretch2dest(1.0f, 0.0f, 0.0f, -1.0f, 0.0f, (FX_FLOAT)(stre
tch_height)); | 247 CFX_AffineMatrix stretch2dest(1.0f, 0.0f, 0.0f, -1.0f, 0.0f, (FX_FLOAT)(stre
tch_height)); |
248 stretch2dest.Concat(pDestMatrix->a / stretch_width, pDestMatrix->b / stretch
_width, | 248 stretch2dest.Concat(pDestMatrix->a / stretch_width, pDestMatrix->b / stretch
_width, |
249 pDestMatrix->c / stretch_height, pDestMatrix->d / stretc
h_height, pDestMatrix->e, pDestMatrix->f); | 249 pDestMatrix->c / stretch_height, pDestMatrix->d / stretc
h_height, pDestMatrix->e, pDestMatrix->f); |
250 m_dest2stretch.SetReverse(stretch2dest); | 250 m_dest2stretch.SetReverse(stretch2dest); |
251 CFX_FloatRect clip_rect_f(result_clip); | 251 CFX_FloatRect clip_rect_f(result_clip); |
252 clip_rect_f.Transform(&m_dest2stretch); | 252 clip_rect_f.Transform(&m_dest2stretch); |
253 m_StretchClip = clip_rect_f.GetOutterRect(); | 253 m_StretchClip = clip_rect_f.GetOutterRect(); |
254 m_StretchClip.Intersect(0, 0, stretch_width, stretch_height); | 254 m_StretchClip.Intersect(0, 0, stretch_width, stretch_height); |
255 m_Stretcher.Start(&m_Storer, pSrc, stretch_width, stretch_height, m_StretchC
lip, flags); | 255 m_Stretcher.Start(&m_Storer, pSrc, stretch_width, stretch_height, m_StretchC
lip, flags); |
256 m_Status = 3; | 256 m_Status = 3; |
257 return TRUE; | 257 return true; |
258 } | 258 } |
259 uint8_t _bilinear_interpol(const uint8_t* buf, int row_offset_l, int row_offset_
r, | 259 uint8_t _bilinear_interpol(const uint8_t* buf, int row_offset_l, int row_offset_
r, |
260 int src_col_l, int src_col_r, int res_x, int res_y, | 260 int src_col_l, int src_col_r, int res_x, int res_y, |
261 int bpp, int c_offset) | 261 int bpp, int c_offset) |
262 { | 262 { |
263 int i_resx = 255 - res_x; | 263 int i_resx = 255 - res_x; |
264 int col_bpp_l = src_col_l * bpp; | 264 int col_bpp_l = src_col_l * bpp; |
265 int col_bpp_r = src_col_r * bpp; | 265 int col_bpp_r = src_col_r * bpp; |
266 const uint8_t* buf_u = buf + row_offset_l + c_offset; | 266 const uint8_t* buf_u = buf + row_offset_l + c_offset; |
267 const uint8_t* buf_d = buf + row_offset_r + c_offset; | 267 const uint8_t* buf_d = buf + row_offset_r + c_offset; |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
328 format = FXDIB_8bppMask; | 328 format = FXDIB_8bppMask; |
329 } else if (format >= 1025) { | 329 } else if (format >= 1025) { |
330 format = FXDIB_Cmyka; | 330 format = FXDIB_Cmyka; |
331 } else if (format <= 32 || format == FXDIB_Argb) { | 331 } else if (format <= 32 || format == FXDIB_Argb) { |
332 format = FXDIB_Argb; | 332 format = FXDIB_Argb; |
333 } else { | 333 } else { |
334 format = FXDIB_Rgba; | 334 format = FXDIB_Rgba; |
335 } | 335 } |
336 return format; | 336 return format; |
337 } | 337 } |
338 FX_BOOL CFX_ImageTransformer::Continue(IFX_Pause* pPause) | 338 bool CFX_ImageTransformer::Continue(IFX_Pause* pPause) |
339 { | 339 { |
340 if (m_Status == 1) { | 340 if (m_Status == 1) { |
341 if (m_Stretcher.Continue(pPause)) { | 341 if (m_Stretcher.Continue(pPause)) { |
342 return TRUE; | 342 return true; |
343 } | 343 } |
344 if (m_Storer.GetBitmap()) { | 344 if (m_Storer.GetBitmap()) { |
345 m_Storer.Replace(m_Storer.GetBitmap()->SwapXY(m_pMatrix->c > 0, m_pM
atrix->b < 0)); | 345 m_Storer.Replace(m_Storer.GetBitmap()->SwapXY(m_pMatrix->c > 0, m_pM
atrix->b < 0)); |
346 } | 346 } |
347 return FALSE; | 347 return false; |
348 } | 348 } |
349 if (m_Status == 2) { | 349 if (m_Status == 2) { |
350 return m_Stretcher.Continue(pPause); | 350 return m_Stretcher.Continue(pPause); |
351 } | 351 } |
352 if (m_Status != 3) { | 352 if (m_Status != 3) { |
353 return FALSE; | 353 return false; |
354 } | 354 } |
355 if (m_Stretcher.Continue(pPause)) { | 355 if (m_Stretcher.Continue(pPause)) { |
356 return TRUE; | 356 return true; |
357 } | 357 } |
358 int stretch_width = m_StretchClip.Width(); | 358 int stretch_width = m_StretchClip.Width(); |
359 int stretch_height = m_StretchClip.Height(); | 359 int stretch_height = m_StretchClip.Height(); |
360 if (m_Storer.GetBitmap() == NULL) { | 360 if (m_Storer.GetBitmap() == NULL) { |
361 return FALSE; | 361 return false; |
362 } | 362 } |
363 const uint8_t* stretch_buf = m_Storer.GetBitmap()->GetBuffer(); | 363 const uint8_t* stretch_buf = m_Storer.GetBitmap()->GetBuffer(); |
364 const uint8_t* stretch_buf_mask = NULL; | 364 const uint8_t* stretch_buf_mask = NULL; |
365 if (m_Storer.GetBitmap()->m_pAlphaMask) { | 365 if (m_Storer.GetBitmap()->m_pAlphaMask) { |
366 stretch_buf_mask = m_Storer.GetBitmap()->m_pAlphaMask->GetBuffer(); | 366 stretch_buf_mask = m_Storer.GetBitmap()->m_pAlphaMask->GetBuffer(); |
367 } | 367 } |
368 int stretch_pitch = m_Storer.GetBitmap()->GetPitch(); | 368 int stretch_pitch = m_Storer.GetBitmap()->GetPitch(); |
369 CFX_DIBitmap* pTransformed = new CFX_DIBitmap; | 369 CFX_DIBitmap* pTransformed = new CFX_DIBitmap; |
370 FXDIB_Format transformF = _GetTransformedFormat(m_Stretcher.m_pSource); | 370 FXDIB_Format transformF = _GetTransformedFormat(m_Stretcher.m_pSource); |
371 if (!pTransformed->Create(m_ResultWidth, m_ResultHeight, transformF)) { | 371 if (!pTransformed->Create(m_ResultWidth, m_ResultHeight, transformF)) { |
372 delete pTransformed; | 372 delete pTransformed; |
373 return FALSE; | 373 return false; |
374 } | 374 } |
375 pTransformed->Clear(0); | 375 pTransformed->Clear(0); |
376 if (pTransformed->m_pAlphaMask) { | 376 if (pTransformed->m_pAlphaMask) { |
377 pTransformed->m_pAlphaMask->Clear(0); | 377 pTransformed->m_pAlphaMask->Clear(0); |
378 } | 378 } |
379 CFX_AffineMatrix result2stretch(1.0f, 0.0f, 0.0f, 1.0f, (FX_FLOAT)(m_ResultL
eft), (FX_FLOAT)(m_ResultTop)); | 379 CFX_AffineMatrix result2stretch(1.0f, 0.0f, 0.0f, 1.0f, (FX_FLOAT)(m_ResultL
eft), (FX_FLOAT)(m_ResultTop)); |
380 result2stretch.Concat(m_dest2stretch); | 380 result2stretch.Concat(m_dest2stretch); |
381 result2stretch.TranslateI(-m_StretchClip.left, -m_StretchClip.top); | 381 result2stretch.TranslateI(-m_StretchClip.left, -m_StretchClip.top); |
382 if (stretch_buf_mask == NULL && pTransformed->m_pAlphaMask) { | 382 if (stretch_buf_mask == NULL && pTransformed->m_pAlphaMask) { |
383 pTransformed->m_pAlphaMask->Clear(0xff000000); | 383 pTransformed->m_pAlphaMask->Clear(0xff000000); |
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
634 dest_pos[2] = (uint8_t)(r_bgra_cmyk >> 8); | 634 dest_pos[2] = (uint8_t)(r_bgra_cmyk >> 8); |
635 } else { | 635 } else { |
636 *(FX_DWORD*)dest_pos = r_bgra_cmyk; | 636 *(FX_DWORD*)dest_pos = r_bgra_cmyk; |
637 } | 637 } |
638 } | 638 } |
639 dest_pos += destBpp; | 639 dest_pos += destBpp; |
640 } | 640 } |
641 } | 641 } |
642 } | 642 } |
643 } else { | 643 } else { |
644 FX_BOOL bHasAlpha = m_Storer.GetBitmap()->HasAlpha(); | 644 bool bHasAlpha = m_Storer.GetBitmap()->HasAlpha(); |
645 int destBpp = pTransformed->GetBPP() / 8; | 645 int destBpp = pTransformed->GetBPP() / 8; |
646 if (!(m_Flags & FXDIB_DOWNSAMPLE) && !(m_Flags & FXDIB_BICUBIC_INTER
POL)) { | 646 if (!(m_Flags & FXDIB_DOWNSAMPLE) && !(m_Flags & FXDIB_BICUBIC_INTER
POL)) { |
647 CFX_BilinearMatrix result2stretch_fix(result2stretch, 8); | 647 CFX_BilinearMatrix result2stretch_fix(result2stretch, 8); |
648 for (int row = 0; row < m_ResultHeight; row ++) { | 648 for (int row = 0; row < m_ResultHeight; row ++) { |
649 uint8_t* dest_pos = (uint8_t*)pTransformed->GetScanline(row)
; | 649 uint8_t* dest_pos = (uint8_t*)pTransformed->GetScanline(row)
; |
650 for (int col = 0; col < m_ResultWidth; col ++) { | 650 for (int col = 0; col < m_ResultWidth; col ++) { |
651 int src_col_l, src_row_l, res_x, res_y, r_pos_k_r = 0; | 651 int src_col_l, src_row_l, res_x, res_y, r_pos_k_r = 0; |
652 result2stretch_fix.Transform(col, row, src_col_l, src_ro
w_l, res_x, res_y); | 652 result2stretch_fix.Transform(col, row, src_col_l, src_ro
w_l, res_x, res_y); |
653 if (src_col_l >= 0 && src_col_l <= stretch_width && src_
row_l >= 0 && src_row_l <= stretch_height) { | 653 if (src_col_l >= 0 && src_col_l <= stretch_width && src_
row_l >= 0 && src_row_l <= stretch_height) { |
654 if (src_col_l == stretch_width) { | 654 if (src_col_l == stretch_width) { |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
779 } | 779 } |
780 } | 780 } |
781 } | 781 } |
782 dest_pos += destBpp; | 782 dest_pos += destBpp; |
783 } | 783 } |
784 } | 784 } |
785 } | 785 } |
786 } | 786 } |
787 } | 787 } |
788 m_Storer.Replace(pTransformed); | 788 m_Storer.Replace(pTransformed); |
789 return FALSE; | 789 return false; |
790 } | 790 } |
OLD | NEW |