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/fxge/dib/dib_int.h" | 7 #include "core/fxge/dib/dib_int.h" |
8 | 8 |
9 #include "core/fxge/fx_dib.h" | 9 #include "core/fxge/fx_dib.h" |
10 #include "third_party/base/ptr_util.h" | 10 #include "third_party/base/ptr_util.h" |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 if (res_x < 0 && res_x > -base) { | 168 if (res_x < 0 && res_x > -base) { |
169 res_x = base + res_x; | 169 res_x = base + res_x; |
170 } | 170 } |
171 if (res_y < 0 && res_x > -base) { | 171 if (res_y < 0 && res_x > -base) { |
172 res_y = base + res_y; | 172 res_y = base + res_y; |
173 } | 173 } |
174 x1 /= base; | 174 x1 /= base; |
175 y1 /= base; | 175 y1 /= base; |
176 } | 176 } |
177 }; | 177 }; |
178 CFX_DIBitmap* CFX_DIBSource::SwapXY(FX_BOOL bXFlip, | 178 CFX_DIBitmap* CFX_DIBSource::SwapXY(bool bXFlip, |
179 FX_BOOL bYFlip, | 179 bool bYFlip, |
180 const FX_RECT* pDestClip) const { | 180 const FX_RECT* pDestClip) const { |
181 FX_RECT dest_clip(0, 0, m_Height, m_Width); | 181 FX_RECT dest_clip(0, 0, m_Height, m_Width); |
182 if (pDestClip) { | 182 if (pDestClip) { |
183 dest_clip.Intersect(*pDestClip); | 183 dest_clip.Intersect(*pDestClip); |
184 } | 184 } |
185 if (dest_clip.IsEmpty()) { | 185 if (dest_clip.IsEmpty()) { |
186 return nullptr; | 186 return nullptr; |
187 } | 187 } |
188 CFX_DIBitmap* pTransBitmap = new CFX_DIBitmap; | 188 CFX_DIBitmap* pTransBitmap = new CFX_DIBitmap; |
189 int result_height = dest_clip.Height(), result_width = dest_clip.Width(); | 189 int result_height = dest_clip.Height(), result_width = dest_clip.Width(); |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
270 dest_scan += dest_step; | 270 dest_scan += dest_step; |
271 } | 271 } |
272 } | 272 } |
273 } | 273 } |
274 return pTransBitmap; | 274 return pTransBitmap; |
275 } | 275 } |
276 #define FIX16_005 0.05f | 276 #define FIX16_005 0.05f |
277 FX_RECT FXDIB_SwapClipBox(FX_RECT& clip, | 277 FX_RECT FXDIB_SwapClipBox(FX_RECT& clip, |
278 int width, | 278 int width, |
279 int height, | 279 int height, |
280 FX_BOOL bFlipX, | 280 bool bFlipX, |
281 FX_BOOL bFlipY) { | 281 bool bFlipY) { |
282 FX_RECT rect; | 282 FX_RECT rect; |
283 if (bFlipY) { | 283 if (bFlipY) { |
284 rect.left = height - clip.top; | 284 rect.left = height - clip.top; |
285 rect.right = height - clip.bottom; | 285 rect.right = height - clip.bottom; |
286 } else { | 286 } else { |
287 rect.left = clip.top; | 287 rect.left = clip.top; |
288 rect.right = clip.bottom; | 288 rect.right = clip.bottom; |
289 } | 289 } |
290 if (bFlipX) { | 290 if (bFlipX) { |
291 rect.top = width - clip.left; | 291 rect.top = width - clip.left; |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
338 int flags, | 338 int flags, |
339 const FX_RECT* pClip) | 339 const FX_RECT* pClip) |
340 : m_pSrc(pSrc), | 340 : m_pSrc(pSrc), |
341 m_pMatrix(pMatrix), | 341 m_pMatrix(pMatrix), |
342 m_pClip(pClip), | 342 m_pClip(pClip), |
343 m_Flags(flags), | 343 m_Flags(flags), |
344 m_Status(0) {} | 344 m_Status(0) {} |
345 | 345 |
346 CFX_ImageTransformer::~CFX_ImageTransformer() {} | 346 CFX_ImageTransformer::~CFX_ImageTransformer() {} |
347 | 347 |
348 FX_BOOL CFX_ImageTransformer::Start() { | 348 bool CFX_ImageTransformer::Start() { |
349 CFX_FloatRect unit_rect = m_pMatrix->GetUnitRect(); | 349 CFX_FloatRect unit_rect = m_pMatrix->GetUnitRect(); |
350 FX_RECT result_rect = unit_rect.GetClosestRect(); | 350 FX_RECT result_rect = unit_rect.GetClosestRect(); |
351 FX_RECT result_clip = result_rect; | 351 FX_RECT result_clip = result_rect; |
352 if (m_pClip) | 352 if (m_pClip) |
353 result_clip.Intersect(*m_pClip); | 353 result_clip.Intersect(*m_pClip); |
354 | 354 |
355 if (result_clip.IsEmpty()) | 355 if (result_clip.IsEmpty()) |
356 return FALSE; | 356 return false; |
357 | 357 |
358 m_result = result_clip; | 358 m_result = result_clip; |
359 if (FXSYS_fabs(m_pMatrix->a) < FXSYS_fabs(m_pMatrix->b) / 20 && | 359 if (FXSYS_fabs(m_pMatrix->a) < FXSYS_fabs(m_pMatrix->b) / 20 && |
360 FXSYS_fabs(m_pMatrix->d) < FXSYS_fabs(m_pMatrix->c) / 20 && | 360 FXSYS_fabs(m_pMatrix->d) < FXSYS_fabs(m_pMatrix->c) / 20 && |
361 FXSYS_fabs(m_pMatrix->a) < 0.5f && FXSYS_fabs(m_pMatrix->d) < 0.5f) { | 361 FXSYS_fabs(m_pMatrix->a) < 0.5f && FXSYS_fabs(m_pMatrix->d) < 0.5f) { |
362 int dest_width = result_rect.Width(); | 362 int dest_width = result_rect.Width(); |
363 int dest_height = result_rect.Height(); | 363 int dest_height = result_rect.Height(); |
364 result_clip.Offset(-result_rect.left, -result_rect.top); | 364 result_clip.Offset(-result_rect.left, -result_rect.top); |
365 result_clip = FXDIB_SwapClipBox(result_clip, dest_width, dest_height, | 365 result_clip = FXDIB_SwapClipBox(result_clip, dest_width, dest_height, |
366 m_pMatrix->c > 0, m_pMatrix->b < 0); | 366 m_pMatrix->c > 0, m_pMatrix->b < 0); |
367 m_Stretcher = pdfium::MakeUnique<CFX_ImageStretcher>( | 367 m_Stretcher = pdfium::MakeUnique<CFX_ImageStretcher>( |
368 &m_Storer, m_pSrc, dest_height, dest_width, result_clip, m_Flags); | 368 &m_Storer, m_pSrc, dest_height, dest_width, result_clip, m_Flags); |
369 m_Stretcher->Start(); | 369 m_Stretcher->Start(); |
370 m_Status = 1; | 370 m_Status = 1; |
371 return TRUE; | 371 return true; |
372 } | 372 } |
373 if (FXSYS_fabs(m_pMatrix->b) < FIX16_005 && | 373 if (FXSYS_fabs(m_pMatrix->b) < FIX16_005 && |
374 FXSYS_fabs(m_pMatrix->c) < FIX16_005) { | 374 FXSYS_fabs(m_pMatrix->c) < FIX16_005) { |
375 int dest_width = m_pMatrix->a > 0 ? (int)FXSYS_ceil(m_pMatrix->a) | 375 int dest_width = m_pMatrix->a > 0 ? (int)FXSYS_ceil(m_pMatrix->a) |
376 : (int)FXSYS_floor(m_pMatrix->a); | 376 : (int)FXSYS_floor(m_pMatrix->a); |
377 int dest_height = m_pMatrix->d > 0 ? (int)-FXSYS_ceil(m_pMatrix->d) | 377 int dest_height = m_pMatrix->d > 0 ? (int)-FXSYS_ceil(m_pMatrix->d) |
378 : (int)-FXSYS_floor(m_pMatrix->d); | 378 : (int)-FXSYS_floor(m_pMatrix->d); |
379 result_clip.Offset(-result_rect.left, -result_rect.top); | 379 result_clip.Offset(-result_rect.left, -result_rect.top); |
380 m_Stretcher = pdfium::MakeUnique<CFX_ImageStretcher>( | 380 m_Stretcher = pdfium::MakeUnique<CFX_ImageStretcher>( |
381 &m_Storer, m_pSrc, dest_width, dest_height, result_clip, m_Flags); | 381 &m_Storer, m_pSrc, dest_width, dest_height, result_clip, m_Flags); |
382 m_Stretcher->Start(); | 382 m_Stretcher->Start(); |
383 m_Status = 2; | 383 m_Status = 2; |
384 return TRUE; | 384 return true; |
385 } | 385 } |
386 int stretch_width = (int)FXSYS_ceil(FXSYS_sqrt2(m_pMatrix->a, m_pMatrix->b)); | 386 int stretch_width = (int)FXSYS_ceil(FXSYS_sqrt2(m_pMatrix->a, m_pMatrix->b)); |
387 int stretch_height = (int)FXSYS_ceil(FXSYS_sqrt2(m_pMatrix->c, m_pMatrix->d)); | 387 int stretch_height = (int)FXSYS_ceil(FXSYS_sqrt2(m_pMatrix->c, m_pMatrix->d)); |
388 CFX_Matrix stretch2dest(1.0f, 0.0f, 0.0f, -1.0f, 0.0f, | 388 CFX_Matrix stretch2dest(1.0f, 0.0f, 0.0f, -1.0f, 0.0f, |
389 (FX_FLOAT)(stretch_height)); | 389 (FX_FLOAT)(stretch_height)); |
390 stretch2dest.Concat( | 390 stretch2dest.Concat( |
391 m_pMatrix->a / stretch_width, m_pMatrix->b / stretch_width, | 391 m_pMatrix->a / stretch_width, m_pMatrix->b / stretch_width, |
392 m_pMatrix->c / stretch_height, m_pMatrix->d / stretch_height, | 392 m_pMatrix->c / stretch_height, m_pMatrix->d / stretch_height, |
393 m_pMatrix->e, m_pMatrix->f); | 393 m_pMatrix->e, m_pMatrix->f); |
394 m_dest2stretch.SetReverse(stretch2dest); | 394 m_dest2stretch.SetReverse(stretch2dest); |
395 CFX_FloatRect clip_rect_f(result_clip); | 395 CFX_FloatRect clip_rect_f(result_clip); |
396 clip_rect_f.Transform(&m_dest2stretch); | 396 clip_rect_f.Transform(&m_dest2stretch); |
397 m_StretchClip = clip_rect_f.GetOuterRect(); | 397 m_StretchClip = clip_rect_f.GetOuterRect(); |
398 m_StretchClip.Intersect(0, 0, stretch_width, stretch_height); | 398 m_StretchClip.Intersect(0, 0, stretch_width, stretch_height); |
399 m_Stretcher = pdfium::MakeUnique<CFX_ImageStretcher>( | 399 m_Stretcher = pdfium::MakeUnique<CFX_ImageStretcher>( |
400 &m_Storer, m_pSrc, stretch_width, stretch_height, m_StretchClip, m_Flags); | 400 &m_Storer, m_pSrc, stretch_width, stretch_height, m_StretchClip, m_Flags); |
401 m_Stretcher->Start(); | 401 m_Stretcher->Start(); |
402 m_Status = 3; | 402 m_Status = 3; |
403 return TRUE; | 403 return true; |
404 } | 404 } |
405 | 405 |
406 FX_BOOL CFX_ImageTransformer::Continue(IFX_Pause* pPause) { | 406 bool CFX_ImageTransformer::Continue(IFX_Pause* pPause) { |
407 if (m_Status == 1) { | 407 if (m_Status == 1) { |
408 if (m_Stretcher->Continue(pPause)) | 408 if (m_Stretcher->Continue(pPause)) |
409 return TRUE; | 409 return true; |
410 | 410 |
411 if (m_Storer.GetBitmap()) { | 411 if (m_Storer.GetBitmap()) { |
412 std::unique_ptr<CFX_DIBitmap> swapped( | 412 std::unique_ptr<CFX_DIBitmap> swapped( |
413 m_Storer.GetBitmap()->SwapXY(m_pMatrix->c > 0, m_pMatrix->b < 0)); | 413 m_Storer.GetBitmap()->SwapXY(m_pMatrix->c > 0, m_pMatrix->b < 0)); |
414 m_Storer.Replace(std::move(swapped)); | 414 m_Storer.Replace(std::move(swapped)); |
415 } | 415 } |
416 return FALSE; | 416 return false; |
417 } | 417 } |
418 | 418 |
419 if (m_Status == 2) | 419 if (m_Status == 2) |
420 return m_Stretcher->Continue(pPause); | 420 return m_Stretcher->Continue(pPause); |
421 | 421 |
422 if (m_Status != 3) | 422 if (m_Status != 3) |
423 return FALSE; | 423 return false; |
424 | 424 |
425 if (m_Stretcher->Continue(pPause)) | 425 if (m_Stretcher->Continue(pPause)) |
426 return TRUE; | 426 return true; |
427 | 427 |
428 int stretch_width = m_StretchClip.Width(); | 428 int stretch_width = m_StretchClip.Width(); |
429 int stretch_height = m_StretchClip.Height(); | 429 int stretch_height = m_StretchClip.Height(); |
430 if (!m_Storer.GetBitmap()) | 430 if (!m_Storer.GetBitmap()) |
431 return FALSE; | 431 return false; |
432 | 432 |
433 const uint8_t* stretch_buf = m_Storer.GetBitmap()->GetBuffer(); | 433 const uint8_t* stretch_buf = m_Storer.GetBitmap()->GetBuffer(); |
434 const uint8_t* stretch_buf_mask = nullptr; | 434 const uint8_t* stretch_buf_mask = nullptr; |
435 if (m_Storer.GetBitmap()->m_pAlphaMask) | 435 if (m_Storer.GetBitmap()->m_pAlphaMask) |
436 stretch_buf_mask = m_Storer.GetBitmap()->m_pAlphaMask->GetBuffer(); | 436 stretch_buf_mask = m_Storer.GetBitmap()->m_pAlphaMask->GetBuffer(); |
437 | 437 |
438 int stretch_pitch = m_Storer.GetBitmap()->GetPitch(); | 438 int stretch_pitch = m_Storer.GetBitmap()->GetPitch(); |
439 std::unique_ptr<CFX_DIBitmap> pTransformed(new CFX_DIBitmap); | 439 std::unique_ptr<CFX_DIBitmap> pTransformed(new CFX_DIBitmap); |
440 FXDIB_Format transformF = GetTransformedFormat(m_Stretcher->source()); | 440 FXDIB_Format transformF = GetTransformedFormat(m_Stretcher->source()); |
441 if (!pTransformed->Create(m_result.Width(), m_result.Height(), transformF)) | 441 if (!pTransformed->Create(m_result.Width(), m_result.Height(), transformF)) |
442 return FALSE; | 442 return false; |
443 | 443 |
444 pTransformed->Clear(0); | 444 pTransformed->Clear(0); |
445 if (pTransformed->m_pAlphaMask) | 445 if (pTransformed->m_pAlphaMask) |
446 pTransformed->m_pAlphaMask->Clear(0); | 446 pTransformed->m_pAlphaMask->Clear(0); |
447 | 447 |
448 CFX_Matrix result2stretch(1.0f, 0.0f, 0.0f, 1.0f, (FX_FLOAT)(m_result.left), | 448 CFX_Matrix result2stretch(1.0f, 0.0f, 0.0f, 1.0f, (FX_FLOAT)(m_result.left), |
449 (FX_FLOAT)(m_result.top)); | 449 (FX_FLOAT)(m_result.top)); |
450 result2stretch.Concat(m_dest2stretch); | 450 result2stretch.Concat(m_dest2stretch); |
451 result2stretch.TranslateI(-m_StretchClip.left, -m_StretchClip.top); | 451 result2stretch.TranslateI(-m_StretchClip.left, -m_StretchClip.top); |
452 if (!stretch_buf_mask && pTransformed->m_pAlphaMask) { | 452 if (!stretch_buf_mask && pTransformed->m_pAlphaMask) { |
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
742 dest_pos[2] = (uint8_t)(r_bgra_cmyk >> 8); | 742 dest_pos[2] = (uint8_t)(r_bgra_cmyk >> 8); |
743 } else { | 743 } else { |
744 *(uint32_t*)dest_pos = r_bgra_cmyk; | 744 *(uint32_t*)dest_pos = r_bgra_cmyk; |
745 } | 745 } |
746 } | 746 } |
747 dest_pos += destBpp; | 747 dest_pos += destBpp; |
748 } | 748 } |
749 } | 749 } |
750 } | 750 } |
751 } else { | 751 } else { |
752 FX_BOOL bHasAlpha = m_Storer.GetBitmap()->HasAlpha(); | 752 bool bHasAlpha = m_Storer.GetBitmap()->HasAlpha(); |
753 int destBpp = pTransformed->GetBPP() / 8; | 753 int destBpp = pTransformed->GetBPP() / 8; |
754 if (!(m_Flags & FXDIB_DOWNSAMPLE) && | 754 if (!(m_Flags & FXDIB_DOWNSAMPLE) && |
755 !(m_Flags & FXDIB_BICUBIC_INTERPOL)) { | 755 !(m_Flags & FXDIB_BICUBIC_INTERPOL)) { |
756 CFX_BilinearMatrix result2stretch_fix(result2stretch, 8); | 756 CFX_BilinearMatrix result2stretch_fix(result2stretch, 8); |
757 for (int row = 0; row < m_result.Height(); row++) { | 757 for (int row = 0; row < m_result.Height(); row++) { |
758 uint8_t* dest_pos = (uint8_t*)pTransformed->GetScanline(row); | 758 uint8_t* dest_pos = (uint8_t*)pTransformed->GetScanline(row); |
759 for (int col = 0; col < m_result.Width(); col++) { | 759 for (int col = 0; col < m_result.Width(); col++) { |
760 int src_col_l, src_row_l, res_x, res_y, r_pos_k_r = 0; | 760 int src_col_l, src_row_l, res_x, res_y, r_pos_k_r = 0; |
761 result2stretch_fix.Transform(col, row, src_col_l, src_row_l, res_x, | 761 result2stretch_fix.Transform(col, row, src_col_l, src_row_l, res_x, |
762 res_y); | 762 res_y); |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
940 } | 940 } |
941 } | 941 } |
942 } | 942 } |
943 dest_pos += destBpp; | 943 dest_pos += destBpp; |
944 } | 944 } |
945 } | 945 } |
946 } | 946 } |
947 } | 947 } |
948 } | 948 } |
949 m_Storer.Replace(std::move(pTransformed)); | 949 m_Storer.Replace(std::move(pTransformed)); |
950 return FALSE; | 950 return false; |
951 } | 951 } |
952 | 952 |
953 std::unique_ptr<CFX_DIBitmap> CFX_ImageTransformer::DetachBitmap() { | 953 std::unique_ptr<CFX_DIBitmap> CFX_ImageTransformer::DetachBitmap() { |
954 return m_Storer.Detach(); | 954 return m_Storer.Detach(); |
955 } | 955 } |
OLD | NEW |