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

Side by Side Diff: skia/ext/image_operations.cc

Issue 118456: Fix a unit test failure. One of the tests sends an empty bitmap through this... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 11 years, 6 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 The Chromium 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 #define _USE_MATH_DEFINES 5 #define _USE_MATH_DEFINES
6 #include <cmath> 6 #include <cmath>
7 #include <limits> 7 #include <limits>
8 #include <vector> 8 #include <vector>
9 9
10 #include "skia/ext/image_operations.h" 10 #include "skia/ext/image_operations.h"
(...skipping 608 matching lines...) Expand 10 before | Expand all | Expand 10 after
619 619
620 dst_row[x] = source_row[x_pix]; 620 dst_row[x] = source_row[x_pix];
621 } 621 }
622 } 622 }
623 623
624 return cropped; 624 return cropped;
625 } 625 }
626 626
627 // static 627 // static
628 SkBitmap ImageOperations::DownsampleByTwo(const SkBitmap& bitmap) { 628 SkBitmap ImageOperations::DownsampleByTwo(const SkBitmap& bitmap) {
629 DCHECK(bitmap.getConfig() == SkBitmap::kARGB_8888_Config);
Peter Kasting 2009/06/09 21:10:46 Instead of removing this, the right fix seems like
630
631 // Handle the nop case. 629 // Handle the nop case.
632 if (bitmap.width() <= 1 || bitmap.height() <= 1) 630 if (bitmap.width() <= 1 || bitmap.height() <= 1)
633 return bitmap; 631 return bitmap;
634 632
635 SkBitmap result; 633 SkBitmap result;
636 result.setConfig(SkBitmap::kARGB_8888_Config, 634 result.setConfig(SkBitmap::kARGB_8888_Config,
637 (bitmap.width() + 1) / 2, 635 (bitmap.width() + 1) / 2,
638 (bitmap.height() + 1) / 2); 636 (bitmap.height() + 1) / 2);
639 result.allocPixels(); 637 result.allocPixels();
640 638
(...skipping 30 matching lines...) Expand all
671 ag += (tmp >> 8) & 0xFF00FF; 669 ag += (tmp >> 8) & 0xFF00FF;
672 rb += tmp & 0xFF00FF; 670 rb += tmp & 0xFF00FF;
673 if (src_x < bitmap.width() - 1) 671 if (src_x < bitmap.width() - 1)
674 cur_src += 1; 672 cur_src += 1;
675 673
676 // Bottom right pixel of the 2x2 block. 674 // Bottom right pixel of the 2x2 block.
677 tmp = *cur_src; 675 tmp = *cur_src;
678 ag += (tmp >> 8) & 0xFF00FF; 676 ag += (tmp >> 8) & 0xFF00FF;
679 rb += tmp & 0xFF00FF; 677 rb += tmp & 0xFF00FF;
680 678
681 // PUt the channels back together, dividing each by 4 to get the average. 679 // Put the channels back together, dividing each by 4 to get the average.
682 // |ag| has the alpha and green channels shifted right by 8 bits from 680 // |ag| has the alpha and green channels shifted right by 8 bits from
683 // there they should end up, so shifting left by 6 gives them in the 681 // there they should end up, so shifting left by 6 gives them in the
684 // correct position divided by 4. 682 // correct position divided by 4.
685 *result.getAddr32(dest_x, dest_y) = 683 *result.getAddr32(dest_x, dest_y) =
686 ((rb >> 2) & 0xFF00FF) | ((ag << 6) & 0xFF00FF00); 684 ((rb >> 2) & 0xFF00FF) | ((ag << 6) & 0xFF00FF00);
687 } 685 }
688 } 686 }
689 687
690 return result; 688 return result;
691 } 689 }
692 690
693 // static 691 // static
694 SkBitmap ImageOperations::DownsampleByTwoUntilSize(const SkBitmap& bitmap, 692 SkBitmap ImageOperations::DownsampleByTwoUntilSize(const SkBitmap& bitmap,
695 int min_w, int min_h) { 693 int min_w, int min_h) {
696 if (bitmap.width() <= min_w || bitmap.height() <= min_h || 694 if (bitmap.width() <= min_w || bitmap.height() <= min_h ||
697 min_w < 0 || min_h < 0) 695 min_w < 0 || min_h < 0)
698 return bitmap; 696 return bitmap;
699 697
700 // Since bitmaps are refcounted, this copy will be fast. 698 // Since bitmaps are refcounted, this copy will be fast.
701 SkBitmap current = bitmap; 699 SkBitmap current = bitmap;
702 while (current.width() >= min_w * 2 && current.height() >= min_h * 2 && 700 while (current.width() >= min_w * 2 && current.height() >= min_h * 2 &&
703 current.width() > 1 && current.height() > 1) 701 current.width() > 1 && current.height() > 1)
704 current = DownsampleByTwo(current); 702 current = DownsampleByTwo(current);
705 return current; 703 return current;
706 } 704 }
707 705
708 } // namespace skia 706 } // namespace skia
709 707
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698