Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(264)

Side by Side Diff: core/fxge/dib/fx_dib_transform.cpp

Issue 1973913002: Clean up CFX_ImageTransformer. (Closed) Base URL: https://pdfium.googlesource.com/pdfium@master
Patch Set: address comments Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « core/fxge/dib/fx_dib_main.cpp ('k') | core/fxge/include/fx_dib.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/include/fx_dib.h" 9 #include "core/fxge/include/fx_dib.h"
10 10
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after
289 if (bFlipX) { 289 if (bFlipX) {
290 rect.top = width - clip.left; 290 rect.top = width - clip.left;
291 rect.bottom = width - clip.right; 291 rect.bottom = width - clip.right;
292 } else { 292 } else {
293 rect.top = clip.left; 293 rect.top = clip.left;
294 rect.bottom = clip.right; 294 rect.bottom = clip.right;
295 } 295 }
296 rect.Normalize(); 296 rect.Normalize();
297 return rect; 297 return rect;
298 } 298 }
299
299 CFX_DIBitmap* CFX_DIBSource::TransformTo(const CFX_Matrix* pDestMatrix, 300 CFX_DIBitmap* CFX_DIBSource::TransformTo(const CFX_Matrix* pDestMatrix,
300 int& result_left, 301 int& result_left,
301 int& result_top, 302 int& result_top,
302 uint32_t flags, 303 uint32_t flags,
303 const FX_RECT* pDestClip) const { 304 const FX_RECT* pDestClip) const {
304 CFX_ImageTransformer transformer; 305 CFX_ImageTransformer transformer(this, pDestMatrix, flags, pDestClip);
305 transformer.Start(this, pDestMatrix, flags, pDestClip); 306 transformer.Start();
306 transformer.Continue(NULL); 307 transformer.Continue(nullptr);
307 result_left = transformer.m_ResultLeft; 308 result_left = transformer.result().left;
308 result_top = transformer.m_ResultTop; 309 result_top = transformer.result().top;
309 CFX_DIBitmap* pTransformed = transformer.m_Storer.Detach(); 310 return transformer.DetachBitmap().release();
310 return pTransformed;
311 } 311 }
312 312
313 CFX_DIBitmap* CFX_DIBSource::StretchTo(int dest_width, 313 CFX_DIBitmap* CFX_DIBSource::StretchTo(int dest_width,
314 int dest_height, 314 int dest_height,
315 uint32_t flags, 315 uint32_t flags,
316 const FX_RECT* pClip) const { 316 const FX_RECT* pClip) const {
317 FX_RECT clip_rect(0, 0, FXSYS_abs(dest_width), FXSYS_abs(dest_height)); 317 FX_RECT clip_rect(0, 0, FXSYS_abs(dest_width), FXSYS_abs(dest_height));
318 if (pClip) 318 if (pClip)
319 clip_rect.Intersect(*pClip); 319 clip_rect.Intersect(*pClip);
320 320
321 if (clip_rect.IsEmpty()) 321 if (clip_rect.IsEmpty())
322 return nullptr; 322 return nullptr;
323 323
324 if (dest_width == m_Width && dest_height == m_Height) 324 if (dest_width == m_Width && dest_height == m_Height)
325 return Clone(&clip_rect); 325 return Clone(&clip_rect);
326 326
327 CFX_BitmapStorer storer; 327 CFX_BitmapStorer storer;
328 CFX_ImageStretcher stretcher(&storer, this, dest_width, dest_height, 328 CFX_ImageStretcher stretcher(&storer, this, dest_width, dest_height,
329 clip_rect, flags); 329 clip_rect, flags);
330 if (stretcher.Start()) 330 if (stretcher.Start())
331 stretcher.Continue(nullptr); 331 stretcher.Continue(nullptr);
332 return storer.Detach(); 332 return storer.Detach().release();
333 } 333 }
334 334
335 CFX_ImageTransformer::CFX_ImageTransformer() { 335 CFX_ImageTransformer::CFX_ImageTransformer(const CFX_DIBSource* pSrc,
336 m_Status = 0; 336 const CFX_Matrix* pMatrix,
337 m_pMatrix = NULL; 337 int flags,
338 } 338 const FX_RECT* pClip)
339 : m_pSrc(pSrc),
340 m_pMatrix(pMatrix),
341 m_pClip(pClip),
342 m_Flags(flags),
343 m_Status(0) {}
339 344
340 CFX_ImageTransformer::~CFX_ImageTransformer() {} 345 CFX_ImageTransformer::~CFX_ImageTransformer() {}
341 346
342 FX_BOOL CFX_ImageTransformer::Start(const CFX_DIBSource* pSrc, 347 FX_BOOL CFX_ImageTransformer::Start() {
343 const CFX_Matrix* pDestMatrix, 348 CFX_FloatRect unit_rect = m_pMatrix->GetUnitRect();
344 int flags,
345 const FX_RECT* pDestClip) {
346 m_pMatrix = (CFX_Matrix*)pDestMatrix;
347 CFX_FloatRect unit_rect = pDestMatrix->GetUnitRect();
348 FX_RECT result_rect = unit_rect.GetClosestRect(); 349 FX_RECT result_rect = unit_rect.GetClosestRect();
349 FX_RECT result_clip = result_rect; 350 FX_RECT result_clip = result_rect;
350 if (pDestClip) 351 if (m_pClip)
351 result_clip.Intersect(*pDestClip); 352 result_clip.Intersect(*m_pClip);
352 353
353 if (result_clip.IsEmpty()) 354 if (result_clip.IsEmpty())
354 return FALSE; 355 return FALSE;
355 356
356 m_ResultLeft = result_clip.left; 357 m_result = result_clip;
357 m_ResultTop = result_clip.top; 358 if (FXSYS_fabs(m_pMatrix->a) < FXSYS_fabs(m_pMatrix->b) / 20 &&
358 m_ResultWidth = result_clip.Width(); 359 FXSYS_fabs(m_pMatrix->d) < FXSYS_fabs(m_pMatrix->c) / 20 &&
359 m_ResultHeight = result_clip.Height(); 360 FXSYS_fabs(m_pMatrix->a) < 0.5f && FXSYS_fabs(m_pMatrix->d) < 0.5f) {
360 m_Flags = flags;
361 if (FXSYS_fabs(pDestMatrix->a) < FXSYS_fabs(pDestMatrix->b) / 20 &&
362 FXSYS_fabs(pDestMatrix->d) < FXSYS_fabs(pDestMatrix->c) / 20 &&
363 FXSYS_fabs(pDestMatrix->a) < 0.5f && FXSYS_fabs(pDestMatrix->d) < 0.5f) {
364 int dest_width = result_rect.Width(); 361 int dest_width = result_rect.Width();
365 int dest_height = result_rect.Height(); 362 int dest_height = result_rect.Height();
366 result_clip.Offset(-result_rect.left, -result_rect.top); 363 result_clip.Offset(-result_rect.left, -result_rect.top);
367 result_clip = FXDIB_SwapClipBox(result_clip, dest_width, dest_height, 364 result_clip = FXDIB_SwapClipBox(result_clip, dest_width, dest_height,
368 pDestMatrix->c > 0, pDestMatrix->b < 0); 365 m_pMatrix->c > 0, m_pMatrix->b < 0);
369 m_Stretcher.reset(new CFX_ImageStretcher(&m_Storer, pSrc, dest_height, 366 m_Stretcher.reset(new CFX_ImageStretcher(&m_Storer, m_pSrc, dest_height,
370 dest_width, result_clip, flags)); 367 dest_width, result_clip, m_Flags));
371 m_Stretcher->Start(); 368 m_Stretcher->Start();
372 m_Status = 1; 369 m_Status = 1;
373 return TRUE; 370 return TRUE;
374 } 371 }
375 if (FXSYS_fabs(pDestMatrix->b) < FIX16_005 && 372 if (FXSYS_fabs(m_pMatrix->b) < FIX16_005 &&
376 FXSYS_fabs(pDestMatrix->c) < FIX16_005) { 373 FXSYS_fabs(m_pMatrix->c) < FIX16_005) {
377 int dest_width = pDestMatrix->a > 0 ? (int)FXSYS_ceil(pDestMatrix->a) 374 int dest_width = m_pMatrix->a > 0 ? (int)FXSYS_ceil(m_pMatrix->a)
378 : (int)FXSYS_floor(pDestMatrix->a); 375 : (int)FXSYS_floor(m_pMatrix->a);
379 int dest_height = pDestMatrix->d > 0 ? (int)-FXSYS_ceil(pDestMatrix->d) 376 int dest_height = m_pMatrix->d > 0 ? (int)-FXSYS_ceil(m_pMatrix->d)
380 : (int)-FXSYS_floor(pDestMatrix->d); 377 : (int)-FXSYS_floor(m_pMatrix->d);
381 result_clip.Offset(-result_rect.left, -result_rect.top); 378 result_clip.Offset(-result_rect.left, -result_rect.top);
382 m_Stretcher.reset(new CFX_ImageStretcher(&m_Storer, pSrc, dest_width, 379 m_Stretcher.reset(new CFX_ImageStretcher(
383 dest_height, result_clip, flags)); 380 &m_Storer, m_pSrc, dest_width, dest_height, result_clip, m_Flags));
384 m_Stretcher->Start(); 381 m_Stretcher->Start();
385 m_Status = 2; 382 m_Status = 2;
386 return TRUE; 383 return TRUE;
387 } 384 }
388 int stretch_width = 385 int stretch_width = (int)FXSYS_ceil(FXSYS_sqrt2(m_pMatrix->a, m_pMatrix->b));
389 (int)FXSYS_ceil(FXSYS_sqrt2(pDestMatrix->a, pDestMatrix->b)); 386 int stretch_height = (int)FXSYS_ceil(FXSYS_sqrt2(m_pMatrix->c, m_pMatrix->d));
390 int stretch_height =
391 (int)FXSYS_ceil(FXSYS_sqrt2(pDestMatrix->c, pDestMatrix->d));
392 CFX_Matrix stretch2dest(1.0f, 0.0f, 0.0f, -1.0f, 0.0f, 387 CFX_Matrix stretch2dest(1.0f, 0.0f, 0.0f, -1.0f, 0.0f,
393 (FX_FLOAT)(stretch_height)); 388 (FX_FLOAT)(stretch_height));
394 stretch2dest.Concat( 389 stretch2dest.Concat(
395 pDestMatrix->a / stretch_width, pDestMatrix->b / stretch_width, 390 m_pMatrix->a / stretch_width, m_pMatrix->b / stretch_width,
396 pDestMatrix->c / stretch_height, pDestMatrix->d / stretch_height, 391 m_pMatrix->c / stretch_height, m_pMatrix->d / stretch_height,
397 pDestMatrix->e, pDestMatrix->f); 392 m_pMatrix->e, m_pMatrix->f);
398 m_dest2stretch.SetReverse(stretch2dest); 393 m_dest2stretch.SetReverse(stretch2dest);
399 CFX_FloatRect clip_rect_f(result_clip); 394 CFX_FloatRect clip_rect_f(result_clip);
400 clip_rect_f.Transform(&m_dest2stretch); 395 clip_rect_f.Transform(&m_dest2stretch);
401 m_StretchClip = clip_rect_f.GetOutterRect(); 396 m_StretchClip = clip_rect_f.GetOutterRect();
402 m_StretchClip.Intersect(0, 0, stretch_width, stretch_height); 397 m_StretchClip.Intersect(0, 0, stretch_width, stretch_height);
403 m_Stretcher.reset(new CFX_ImageStretcher( 398 m_Stretcher.reset(new CFX_ImageStretcher(&m_Storer, m_pSrc, stretch_width,
404 &m_Storer, pSrc, stretch_width, stretch_height, m_StretchClip, flags)); 399 stretch_height, m_StretchClip,
400 m_Flags));
405 m_Stretcher->Start(); 401 m_Stretcher->Start();
406 m_Status = 3; 402 m_Status = 3;
407 return TRUE; 403 return TRUE;
408 } 404 }
409 405
410 FX_BOOL CFX_ImageTransformer::Continue(IFX_Pause* pPause) { 406 FX_BOOL CFX_ImageTransformer::Continue(IFX_Pause* pPause) {
411 if (m_Status == 1) { 407 if (m_Status == 1) {
412 if (m_Stretcher->Continue(pPause)) 408 if (m_Stretcher->Continue(pPause))
413 return TRUE; 409 return TRUE;
414 410
415 if (m_Storer.GetBitmap()) { 411 if (m_Storer.GetBitmap()) {
416 m_Storer.Replace( 412 std::unique_ptr<CFX_DIBitmap> swapped(
417 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));
418 } 415 }
419 return FALSE; 416 return FALSE;
420 } 417 }
421 418
422 if (m_Status == 2) 419 if (m_Status == 2)
423 return m_Stretcher->Continue(pPause); 420 return m_Stretcher->Continue(pPause);
424 421
425 if (m_Status != 3) 422 if (m_Status != 3)
426 return FALSE; 423 return FALSE;
427 424
428 if (m_Stretcher->Continue(pPause)) 425 if (m_Stretcher->Continue(pPause))
429 return TRUE; 426 return TRUE;
430 427
431 int stretch_width = m_StretchClip.Width(); 428 int stretch_width = m_StretchClip.Width();
432 int stretch_height = m_StretchClip.Height(); 429 int stretch_height = m_StretchClip.Height();
433 if (!m_Storer.GetBitmap()) 430 if (!m_Storer.GetBitmap())
434 return FALSE; 431 return FALSE;
435 432
436 const uint8_t* stretch_buf = m_Storer.GetBitmap()->GetBuffer(); 433 const uint8_t* stretch_buf = m_Storer.GetBitmap()->GetBuffer();
437 const uint8_t* stretch_buf_mask = nullptr; 434 const uint8_t* stretch_buf_mask = nullptr;
438 if (m_Storer.GetBitmap()->m_pAlphaMask) 435 if (m_Storer.GetBitmap()->m_pAlphaMask)
439 stretch_buf_mask = m_Storer.GetBitmap()->m_pAlphaMask->GetBuffer(); 436 stretch_buf_mask = m_Storer.GetBitmap()->m_pAlphaMask->GetBuffer();
440 437
441 int stretch_pitch = m_Storer.GetBitmap()->GetPitch(); 438 int stretch_pitch = m_Storer.GetBitmap()->GetPitch();
442 std::unique_ptr<CFX_DIBitmap> pTransformed(new CFX_DIBitmap); 439 std::unique_ptr<CFX_DIBitmap> pTransformed(new CFX_DIBitmap);
443 FXDIB_Format transformF = GetTransformedFormat(m_Stretcher->source()); 440 FXDIB_Format transformF = GetTransformedFormat(m_Stretcher->source());
444 if (!pTransformed->Create(m_ResultWidth, m_ResultHeight, transformF)) 441 if (!pTransformed->Create(m_result.Width(), m_result.Height(), transformF))
445 return FALSE; 442 return FALSE;
446 443
447 pTransformed->Clear(0); 444 pTransformed->Clear(0);
448 if (pTransformed->m_pAlphaMask) 445 if (pTransformed->m_pAlphaMask)
449 pTransformed->m_pAlphaMask->Clear(0); 446 pTransformed->m_pAlphaMask->Clear(0);
450 447
451 CFX_Matrix result2stretch(1.0f, 0.0f, 0.0f, 1.0f, (FX_FLOAT)(m_ResultLeft), 448 CFX_Matrix result2stretch(1.0f, 0.0f, 0.0f, 1.0f, (FX_FLOAT)(m_result.left),
452 (FX_FLOAT)(m_ResultTop)); 449 (FX_FLOAT)(m_result.top));
453 result2stretch.Concat(m_dest2stretch); 450 result2stretch.Concat(m_dest2stretch);
454 result2stretch.TranslateI(-m_StretchClip.left, -m_StretchClip.top); 451 result2stretch.TranslateI(-m_StretchClip.left, -m_StretchClip.top);
455 if (!stretch_buf_mask && pTransformed->m_pAlphaMask) { 452 if (!stretch_buf_mask && pTransformed->m_pAlphaMask) {
456 pTransformed->m_pAlphaMask->Clear(0xff000000); 453 pTransformed->m_pAlphaMask->Clear(0xff000000);
457 } else if (pTransformed->m_pAlphaMask) { 454 } else if (pTransformed->m_pAlphaMask) {
458 int stretch_pitch_mask = m_Storer.GetBitmap()->m_pAlphaMask->GetPitch(); 455 int stretch_pitch_mask = m_Storer.GetBitmap()->m_pAlphaMask->GetPitch();
459 if (!(m_Flags & FXDIB_DOWNSAMPLE) && !(m_Flags & FXDIB_BICUBIC_INTERPOL)) { 456 if (!(m_Flags & FXDIB_DOWNSAMPLE) && !(m_Flags & FXDIB_BICUBIC_INTERPOL)) {
460 CFX_BilinearMatrix result2stretch_fix(result2stretch, 8); 457 CFX_BilinearMatrix result2stretch_fix(result2stretch, 8);
461 for (int row = 0; row < m_ResultHeight; row++) { 458 for (int row = 0; row < m_result.Height(); row++) {
462 uint8_t* dest_pos_mask = 459 uint8_t* dest_pos_mask =
463 (uint8_t*)pTransformed->m_pAlphaMask->GetScanline(row); 460 (uint8_t*)pTransformed->m_pAlphaMask->GetScanline(row);
464 for (int col = 0; col < m_ResultWidth; col++) { 461 for (int col = 0; col < m_result.Width(); col++) {
465 int src_col_l, src_row_l, res_x, res_y; 462 int src_col_l, src_row_l, res_x, res_y;
466 result2stretch_fix.Transform(col, row, src_col_l, src_row_l, res_x, 463 result2stretch_fix.Transform(col, row, src_col_l, src_row_l, res_x,
467 res_y); 464 res_y);
468 if (src_col_l >= 0 && src_col_l <= stretch_width && src_row_l >= 0 && 465 if (src_col_l >= 0 && src_col_l <= stretch_width && src_row_l >= 0 &&
469 src_row_l <= stretch_height) { 466 src_row_l <= stretch_height) {
470 if (src_col_l == stretch_width) { 467 if (src_col_l == stretch_width) {
471 src_col_l--; 468 src_col_l--;
472 } 469 }
473 if (src_row_l == stretch_height) { 470 if (src_row_l == stretch_height) {
474 src_row_l--; 471 src_row_l--;
(...skipping 10 matching lines...) Expand all
485 int row_offset_r = src_row_r * stretch_pitch_mask; 482 int row_offset_r = src_row_r * stretch_pitch_mask;
486 *dest_pos_mask = 483 *dest_pos_mask =
487 bilinear_interpol(stretch_buf_mask, row_offset_l, row_offset_r, 484 bilinear_interpol(stretch_buf_mask, row_offset_l, row_offset_r,
488 src_col_l, src_col_r, res_x, res_y, 1, 0); 485 src_col_l, src_col_r, res_x, res_y, 1, 0);
489 } 486 }
490 dest_pos_mask++; 487 dest_pos_mask++;
491 } 488 }
492 } 489 }
493 } else if (m_Flags & FXDIB_BICUBIC_INTERPOL) { 490 } else if (m_Flags & FXDIB_BICUBIC_INTERPOL) {
494 CFX_BilinearMatrix result2stretch_fix(result2stretch, 8); 491 CFX_BilinearMatrix result2stretch_fix(result2stretch, 8);
495 for (int row = 0; row < m_ResultHeight; row++) { 492 for (int row = 0; row < m_result.Height(); row++) {
496 uint8_t* dest_pos_mask = 493 uint8_t* dest_pos_mask =
497 (uint8_t*)pTransformed->m_pAlphaMask->GetScanline(row); 494 (uint8_t*)pTransformed->m_pAlphaMask->GetScanline(row);
498 for (int col = 0; col < m_ResultWidth; col++) { 495 for (int col = 0; col < m_result.Width(); col++) {
499 int src_col_l, src_row_l, res_x, res_y; 496 int src_col_l, src_row_l, res_x, res_y;
500 result2stretch_fix.Transform(col, row, src_col_l, src_row_l, res_x, 497 result2stretch_fix.Transform(col, row, src_col_l, src_row_l, res_x,
501 res_y); 498 res_y);
502 if (src_col_l >= 0 && src_col_l <= stretch_width && src_row_l >= 0 && 499 if (src_col_l >= 0 && src_col_l <= stretch_width && src_row_l >= 0 &&
503 src_row_l <= stretch_height) { 500 src_row_l <= stretch_height) {
504 int pos_pixel[8]; 501 int pos_pixel[8];
505 int u_w[4], v_w[4]; 502 int u_w[4], v_w[4];
506 if (src_col_l == stretch_width) { 503 if (src_col_l == stretch_width) {
507 src_col_l--; 504 src_col_l--;
508 } 505 }
509 if (src_row_l == stretch_height) { 506 if (src_row_l == stretch_height) {
510 src_row_l--; 507 src_row_l--;
511 } 508 }
512 bicubic_get_pos_weight(pos_pixel, u_w, v_w, src_col_l, src_row_l, 509 bicubic_get_pos_weight(pos_pixel, u_w, v_w, src_col_l, src_row_l,
513 res_x, res_y, stretch_width, stretch_height); 510 res_x, res_y, stretch_width, stretch_height);
514 *dest_pos_mask = 511 *dest_pos_mask =
515 bicubic_interpol(stretch_buf_mask, stretch_pitch_mask, 512 bicubic_interpol(stretch_buf_mask, stretch_pitch_mask,
516 pos_pixel, u_w, v_w, res_x, res_y, 1, 0); 513 pos_pixel, u_w, v_w, res_x, res_y, 1, 0);
517 } 514 }
518 dest_pos_mask++; 515 dest_pos_mask++;
519 } 516 }
520 } 517 }
521 } else { 518 } else {
522 CPDF_FixedMatrix result2stretch_fix(result2stretch, 8); 519 CPDF_FixedMatrix result2stretch_fix(result2stretch, 8);
523 for (int row = 0; row < m_ResultHeight; row++) { 520 for (int row = 0; row < m_result.Height(); row++) {
524 uint8_t* dest_pos_mask = 521 uint8_t* dest_pos_mask =
525 (uint8_t*)pTransformed->m_pAlphaMask->GetScanline(row); 522 (uint8_t*)pTransformed->m_pAlphaMask->GetScanline(row);
526 for (int col = 0; col < m_ResultWidth; col++) { 523 for (int col = 0; col < m_result.Width(); col++) {
527 int src_col, src_row; 524 int src_col, src_row;
528 result2stretch_fix.Transform(col, row, src_col, src_row); 525 result2stretch_fix.Transform(col, row, src_col, src_row);
529 if (src_col >= 0 && src_col <= stretch_width && src_row >= 0 && 526 if (src_col >= 0 && src_col <= stretch_width && src_row >= 0 &&
530 src_row <= stretch_height) { 527 src_row <= stretch_height) {
531 if (src_col == stretch_width) { 528 if (src_col == stretch_width) {
532 src_col--; 529 src_col--;
533 } 530 }
534 if (src_row == stretch_height) { 531 if (src_row == stretch_height) {
535 src_row--; 532 src_row--;
536 } 533 }
537 *dest_pos_mask = 534 *dest_pos_mask =
538 stretch_buf_mask[src_row * stretch_pitch_mask + src_col]; 535 stretch_buf_mask[src_row * stretch_pitch_mask + src_col];
539 } 536 }
540 dest_pos_mask++; 537 dest_pos_mask++;
541 } 538 }
542 } 539 }
543 } 540 }
544 } 541 }
545 if (m_Storer.GetBitmap()->IsAlphaMask()) { 542 if (m_Storer.GetBitmap()->IsAlphaMask()) {
546 if (!(m_Flags & FXDIB_DOWNSAMPLE) && !(m_Flags & FXDIB_BICUBIC_INTERPOL)) { 543 if (!(m_Flags & FXDIB_DOWNSAMPLE) && !(m_Flags & FXDIB_BICUBIC_INTERPOL)) {
547 CFX_BilinearMatrix result2stretch_fix(result2stretch, 8); 544 CFX_BilinearMatrix result2stretch_fix(result2stretch, 8);
548 for (int row = 0; row < m_ResultHeight; row++) { 545 for (int row = 0; row < m_result.Height(); row++) {
549 uint8_t* dest_scan = (uint8_t*)pTransformed->GetScanline(row); 546 uint8_t* dest_scan = (uint8_t*)pTransformed->GetScanline(row);
550 for (int col = 0; col < m_ResultWidth; col++) { 547 for (int col = 0; col < m_result.Width(); col++) {
551 int src_col_l, src_row_l, res_x, res_y; 548 int src_col_l, src_row_l, res_x, res_y;
552 result2stretch_fix.Transform(col, row, src_col_l, src_row_l, res_x, 549 result2stretch_fix.Transform(col, row, src_col_l, src_row_l, res_x,
553 res_y); 550 res_y);
554 if (src_col_l >= 0 && src_col_l <= stretch_width && src_row_l >= 0 && 551 if (src_col_l >= 0 && src_col_l <= stretch_width && src_row_l >= 0 &&
555 src_row_l <= stretch_height) { 552 src_row_l <= stretch_height) {
556 if (src_col_l == stretch_width) { 553 if (src_col_l == stretch_width) {
557 src_col_l--; 554 src_col_l--;
558 } 555 }
559 if (src_row_l == stretch_height) { 556 if (src_row_l == stretch_height) {
560 src_row_l--; 557 src_row_l--;
(...skipping 10 matching lines...) Expand all
571 int row_offset_r = src_row_r * stretch_pitch; 568 int row_offset_r = src_row_r * stretch_pitch;
572 *dest_scan = 569 *dest_scan =
573 bilinear_interpol(stretch_buf, row_offset_l, row_offset_r, 570 bilinear_interpol(stretch_buf, row_offset_l, row_offset_r,
574 src_col_l, src_col_r, res_x, res_y, 1, 0); 571 src_col_l, src_col_r, res_x, res_y, 1, 0);
575 } 572 }
576 dest_scan++; 573 dest_scan++;
577 } 574 }
578 } 575 }
579 } else if (m_Flags & FXDIB_BICUBIC_INTERPOL) { 576 } else if (m_Flags & FXDIB_BICUBIC_INTERPOL) {
580 CFX_BilinearMatrix result2stretch_fix(result2stretch, 8); 577 CFX_BilinearMatrix result2stretch_fix(result2stretch, 8);
581 for (int row = 0; row < m_ResultHeight; row++) { 578 for (int row = 0; row < m_result.Height(); row++) {
582 uint8_t* dest_scan = (uint8_t*)pTransformed->GetScanline(row); 579 uint8_t* dest_scan = (uint8_t*)pTransformed->GetScanline(row);
583 for (int col = 0; col < m_ResultWidth; col++) { 580 for (int col = 0; col < m_result.Width(); col++) {
584 int src_col_l, src_row_l, res_x, res_y; 581 int src_col_l, src_row_l, res_x, res_y;
585 result2stretch_fix.Transform(col, row, src_col_l, src_row_l, res_x, 582 result2stretch_fix.Transform(col, row, src_col_l, src_row_l, res_x,
586 res_y); 583 res_y);
587 if (src_col_l >= 0 && src_col_l <= stretch_width && src_row_l >= 0 && 584 if (src_col_l >= 0 && src_col_l <= stretch_width && src_row_l >= 0 &&
588 src_row_l <= stretch_height) { 585 src_row_l <= stretch_height) {
589 int pos_pixel[8]; 586 int pos_pixel[8];
590 int u_w[4], v_w[4]; 587 int u_w[4], v_w[4];
591 if (src_col_l == stretch_width) { 588 if (src_col_l == stretch_width) {
592 src_col_l--; 589 src_col_l--;
593 } 590 }
594 if (src_row_l == stretch_height) { 591 if (src_row_l == stretch_height) {
595 src_row_l--; 592 src_row_l--;
596 } 593 }
597 bicubic_get_pos_weight(pos_pixel, u_w, v_w, src_col_l, src_row_l, 594 bicubic_get_pos_weight(pos_pixel, u_w, v_w, src_col_l, src_row_l,
598 res_x, res_y, stretch_width, stretch_height); 595 res_x, res_y, stretch_width, stretch_height);
599 *dest_scan = bicubic_interpol(stretch_buf, stretch_pitch, pos_pixel, 596 *dest_scan = bicubic_interpol(stretch_buf, stretch_pitch, pos_pixel,
600 u_w, v_w, res_x, res_y, 1, 0); 597 u_w, v_w, res_x, res_y, 1, 0);
601 } 598 }
602 dest_scan++; 599 dest_scan++;
603 } 600 }
604 } 601 }
605 } else { 602 } else {
606 CPDF_FixedMatrix result2stretch_fix(result2stretch, 8); 603 CPDF_FixedMatrix result2stretch_fix(result2stretch, 8);
607 for (int row = 0; row < m_ResultHeight; row++) { 604 for (int row = 0; row < m_result.Height(); row++) {
608 uint8_t* dest_scan = (uint8_t*)pTransformed->GetScanline(row); 605 uint8_t* dest_scan = (uint8_t*)pTransformed->GetScanline(row);
609 for (int col = 0; col < m_ResultWidth; col++) { 606 for (int col = 0; col < m_result.Width(); col++) {
610 int src_col, src_row; 607 int src_col, src_row;
611 result2stretch_fix.Transform(col, row, src_col, src_row); 608 result2stretch_fix.Transform(col, row, src_col, src_row);
612 if (src_col >= 0 && src_col <= stretch_width && src_row >= 0 && 609 if (src_col >= 0 && src_col <= stretch_width && src_row >= 0 &&
613 src_row <= stretch_height) { 610 src_row <= stretch_height) {
614 if (src_col == stretch_width) { 611 if (src_col == stretch_width) {
615 src_col--; 612 src_col--;
616 } 613 }
617 if (src_row == stretch_height) { 614 if (src_row == stretch_height) {
618 src_row--; 615 src_row--;
619 } 616 }
(...skipping 22 matching lines...) Expand all
642 } 639 }
643 } else { 640 } else {
644 for (int i = 0; i < 256; i++) { 641 for (int i = 0; i < 256; i++) {
645 argb[i] = 0xff000000 | (i * 0x010101); 642 argb[i] = 0xff000000 | (i * 0x010101);
646 } 643 }
647 } 644 }
648 } 645 }
649 if (!(m_Flags & FXDIB_DOWNSAMPLE) && 646 if (!(m_Flags & FXDIB_DOWNSAMPLE) &&
650 !(m_Flags & FXDIB_BICUBIC_INTERPOL)) { 647 !(m_Flags & FXDIB_BICUBIC_INTERPOL)) {
651 CFX_BilinearMatrix result2stretch_fix(result2stretch, 8); 648 CFX_BilinearMatrix result2stretch_fix(result2stretch, 8);
652 for (int row = 0; row < m_ResultHeight; row++) { 649 for (int row = 0; row < m_result.Height(); row++) {
653 uint8_t* dest_pos = (uint8_t*)pTransformed->GetScanline(row); 650 uint8_t* dest_pos = (uint8_t*)pTransformed->GetScanline(row);
654 for (int col = 0; col < m_ResultWidth; col++) { 651 for (int col = 0; col < m_result.Width(); col++) {
655 int src_col_l, src_row_l, res_x, res_y; 652 int src_col_l, src_row_l, res_x, res_y;
656 result2stretch_fix.Transform(col, row, src_col_l, src_row_l, res_x, 653 result2stretch_fix.Transform(col, row, src_col_l, src_row_l, res_x,
657 res_y); 654 res_y);
658 if (src_col_l >= 0 && src_col_l <= stretch_width && 655 if (src_col_l >= 0 && src_col_l <= stretch_width &&
659 src_row_l >= 0 && src_row_l <= stretch_height) { 656 src_row_l >= 0 && src_row_l <= stretch_height) {
660 if (src_col_l == stretch_width) { 657 if (src_col_l == stretch_width) {
661 src_col_l--; 658 src_col_l--;
662 } 659 }
663 if (src_row_l == stretch_height) { 660 if (src_row_l == stretch_height) {
664 src_row_l--; 661 src_row_l--;
(...skipping 17 matching lines...) Expand all
682 dest_pos[2] = (uint8_t)(r_bgra_cmyk >> 8); 679 dest_pos[2] = (uint8_t)(r_bgra_cmyk >> 8);
683 } else { 680 } else {
684 *(uint32_t*)dest_pos = r_bgra_cmyk; 681 *(uint32_t*)dest_pos = r_bgra_cmyk;
685 } 682 }
686 } 683 }
687 dest_pos += destBpp; 684 dest_pos += destBpp;
688 } 685 }
689 } 686 }
690 } else if (m_Flags & FXDIB_BICUBIC_INTERPOL) { 687 } else if (m_Flags & FXDIB_BICUBIC_INTERPOL) {
691 CFX_BilinearMatrix result2stretch_fix(result2stretch, 8); 688 CFX_BilinearMatrix result2stretch_fix(result2stretch, 8);
692 for (int row = 0; row < m_ResultHeight; row++) { 689 for (int row = 0; row < m_result.Height(); row++) {
693 uint8_t* dest_pos = (uint8_t*)pTransformed->GetScanline(row); 690 uint8_t* dest_pos = (uint8_t*)pTransformed->GetScanline(row);
694 for (int col = 0; col < m_ResultWidth; col++) { 691 for (int col = 0; col < m_result.Width(); col++) {
695 int src_col_l, src_row_l, res_x, res_y; 692 int src_col_l, src_row_l, res_x, res_y;
696 result2stretch_fix.Transform(col, row, src_col_l, src_row_l, res_x, 693 result2stretch_fix.Transform(col, row, src_col_l, src_row_l, res_x,
697 res_y); 694 res_y);
698 if (src_col_l >= 0 && src_col_l <= stretch_width && 695 if (src_col_l >= 0 && src_col_l <= stretch_width &&
699 src_row_l >= 0 && src_row_l <= stretch_height) { 696 src_row_l >= 0 && src_row_l <= stretch_height) {
700 int pos_pixel[8]; 697 int pos_pixel[8];
701 int u_w[4], v_w[4]; 698 int u_w[4], v_w[4];
702 if (src_col_l == stretch_width) { 699 if (src_col_l == stretch_width) {
703 src_col_l--; 700 src_col_l--;
704 } 701 }
(...skipping 12 matching lines...) Expand all
717 dest_pos[2] = (uint8_t)(r_bgra_cmyk >> 8); 714 dest_pos[2] = (uint8_t)(r_bgra_cmyk >> 8);
718 } else { 715 } else {
719 *(uint32_t*)dest_pos = r_bgra_cmyk; 716 *(uint32_t*)dest_pos = r_bgra_cmyk;
720 } 717 }
721 } 718 }
722 dest_pos += destBpp; 719 dest_pos += destBpp;
723 } 720 }
724 } 721 }
725 } else { 722 } else {
726 CPDF_FixedMatrix result2stretch_fix(result2stretch, 8); 723 CPDF_FixedMatrix result2stretch_fix(result2stretch, 8);
727 for (int row = 0; row < m_ResultHeight; row++) { 724 for (int row = 0; row < m_result.Height(); row++) {
728 uint8_t* dest_pos = (uint8_t*)pTransformed->GetScanline(row); 725 uint8_t* dest_pos = (uint8_t*)pTransformed->GetScanline(row);
729 for (int col = 0; col < m_ResultWidth; col++) { 726 for (int col = 0; col < m_result.Width(); col++) {
730 int src_col, src_row; 727 int src_col, src_row;
731 result2stretch_fix.Transform(col, row, src_col, src_row); 728 result2stretch_fix.Transform(col, row, src_col, src_row);
732 if (src_col >= 0 && src_col <= stretch_width && src_row >= 0 && 729 if (src_col >= 0 && src_col <= stretch_width && src_row >= 0 &&
733 src_row <= stretch_height) { 730 src_row <= stretch_height) {
734 if (src_col == stretch_width) { 731 if (src_col == stretch_width) {
735 src_col--; 732 src_col--;
736 } 733 }
737 if (src_row == stretch_height) { 734 if (src_row == stretch_height) {
738 src_row--; 735 src_row--;
739 } 736 }
(...skipping 10 matching lines...) Expand all
750 dest_pos += destBpp; 747 dest_pos += destBpp;
751 } 748 }
752 } 749 }
753 } 750 }
754 } else { 751 } else {
755 FX_BOOL bHasAlpha = m_Storer.GetBitmap()->HasAlpha(); 752 FX_BOOL bHasAlpha = m_Storer.GetBitmap()->HasAlpha();
756 int destBpp = pTransformed->GetBPP() / 8; 753 int destBpp = pTransformed->GetBPP() / 8;
757 if (!(m_Flags & FXDIB_DOWNSAMPLE) && 754 if (!(m_Flags & FXDIB_DOWNSAMPLE) &&
758 !(m_Flags & FXDIB_BICUBIC_INTERPOL)) { 755 !(m_Flags & FXDIB_BICUBIC_INTERPOL)) {
759 CFX_BilinearMatrix result2stretch_fix(result2stretch, 8); 756 CFX_BilinearMatrix result2stretch_fix(result2stretch, 8);
760 for (int row = 0; row < m_ResultHeight; row++) { 757 for (int row = 0; row < m_result.Height(); row++) {
761 uint8_t* dest_pos = (uint8_t*)pTransformed->GetScanline(row); 758 uint8_t* dest_pos = (uint8_t*)pTransformed->GetScanline(row);
762 for (int col = 0; col < m_ResultWidth; col++) { 759 for (int col = 0; col < m_result.Width(); col++) {
763 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;
764 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,
765 res_y); 762 res_y);
766 if (src_col_l >= 0 && src_col_l <= stretch_width && 763 if (src_col_l >= 0 && src_col_l <= stretch_width &&
767 src_row_l >= 0 && src_row_l <= stretch_height) { 764 src_row_l >= 0 && src_row_l <= stretch_height) {
768 if (src_col_l == stretch_width) { 765 if (src_col_l == stretch_width) {
769 src_col_l--; 766 src_col_l--;
770 } 767 }
771 if (src_row_l == stretch_height) { 768 if (src_row_l == stretch_height) {
772 src_row_l--; 769 src_row_l--;
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
826 FXARGB_MAKE(r_pos_k_r, r_pos_red_y_r, r_pos_green_m_r, 823 FXARGB_MAKE(r_pos_k_r, r_pos_red_y_r, r_pos_green_m_r,
827 r_pos_blue_c_r)); 824 r_pos_blue_c_r));
828 } 825 }
829 } 826 }
830 } 827 }
831 dest_pos += destBpp; 828 dest_pos += destBpp;
832 } 829 }
833 } 830 }
834 } else if (m_Flags & FXDIB_BICUBIC_INTERPOL) { 831 } else if (m_Flags & FXDIB_BICUBIC_INTERPOL) {
835 CFX_BilinearMatrix result2stretch_fix(result2stretch, 8); 832 CFX_BilinearMatrix result2stretch_fix(result2stretch, 8);
836 for (int row = 0; row < m_ResultHeight; row++) { 833 for (int row = 0; row < m_result.Height(); row++) {
837 uint8_t* dest_pos = (uint8_t*)pTransformed->GetScanline(row); 834 uint8_t* dest_pos = (uint8_t*)pTransformed->GetScanline(row);
838 for (int col = 0; col < m_ResultWidth; col++) { 835 for (int col = 0; col < m_result.Width(); col++) {
839 int src_col_l, src_row_l, res_x, res_y, r_pos_k_r = 0; 836 int src_col_l, src_row_l, res_x, res_y, r_pos_k_r = 0;
840 result2stretch_fix.Transform(col, row, src_col_l, src_row_l, res_x, 837 result2stretch_fix.Transform(col, row, src_col_l, src_row_l, res_x,
841 res_y); 838 res_y);
842 if (src_col_l >= 0 && src_col_l <= stretch_width && 839 if (src_col_l >= 0 && src_col_l <= stretch_width &&
843 src_row_l >= 0 && src_row_l <= stretch_height) { 840 src_row_l >= 0 && src_row_l <= stretch_height) {
844 int pos_pixel[8]; 841 int pos_pixel[8];
845 int u_w[4], v_w[4]; 842 int u_w[4], v_w[4];
846 if (src_col_l == stretch_width) { 843 if (src_col_l == stretch_width) {
847 src_col_l--; 844 src_col_l--;
848 } 845 }
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
897 FXARGB_MAKE(r_pos_k_r, r_pos_red_y_r, r_pos_green_m_r, 894 FXARGB_MAKE(r_pos_k_r, r_pos_red_y_r, r_pos_green_m_r,
898 r_pos_blue_c_r)); 895 r_pos_blue_c_r));
899 } 896 }
900 } 897 }
901 } 898 }
902 dest_pos += destBpp; 899 dest_pos += destBpp;
903 } 900 }
904 } 901 }
905 } else { 902 } else {
906 CPDF_FixedMatrix result2stretch_fix(result2stretch, 8); 903 CPDF_FixedMatrix result2stretch_fix(result2stretch, 8);
907 for (int row = 0; row < m_ResultHeight; row++) { 904 for (int row = 0; row < m_result.Height(); row++) {
908 uint8_t* dest_pos = (uint8_t*)pTransformed->GetScanline(row); 905 uint8_t* dest_pos = (uint8_t*)pTransformed->GetScanline(row);
909 for (int col = 0; col < m_ResultWidth; col++) { 906 for (int col = 0; col < m_result.Width(); col++) {
910 int src_col, src_row; 907 int src_col, src_row;
911 result2stretch_fix.Transform(col, row, src_col, src_row); 908 result2stretch_fix.Transform(col, row, src_col, src_row);
912 if (src_col >= 0 && src_col <= stretch_width && src_row >= 0 && 909 if (src_col >= 0 && src_col <= stretch_width && src_row >= 0 &&
913 src_row <= stretch_height) { 910 src_row <= stretch_height) {
914 if (src_col == stretch_width) { 911 if (src_col == stretch_width) {
915 src_col--; 912 src_col--;
916 } 913 }
917 if (src_row == stretch_height) { 914 if (src_row == stretch_height) {
918 src_row--; 915 src_row--;
919 } 916 }
(...skipping 22 matching lines...) Expand all
942 FXARGB_MAKE(0xff, src_pos[2], src_pos[1], src_pos[0])); 939 FXARGB_MAKE(0xff, src_pos[2], src_pos[1], src_pos[0]));
943 } 940 }
944 } 941 }
945 } 942 }
946 dest_pos += destBpp; 943 dest_pos += destBpp;
947 } 944 }
948 } 945 }
949 } 946 }
950 } 947 }
951 } 948 }
952 m_Storer.Replace(pTransformed.release()); 949 m_Storer.Replace(std::move(pTransformed));
953 return FALSE; 950 return FALSE;
954 } 951 }
952
953 std::unique_ptr<CFX_DIBitmap> CFX_ImageTransformer::DetachBitmap() {
954 return m_Storer.Detach();
955 }
OLDNEW
« no previous file with comments | « core/fxge/dib/fx_dib_main.cpp ('k') | core/fxge/include/fx_dib.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698