diff options
author | brettw@google.com <brettw@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-12-10 16:16:35 +0000 |
---|---|---|
committer | brettw@google.com <brettw@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-12-10 16:16:35 +0000 |
commit | c4b347b36152d693f2914f13c3b6f83f16a6d9b8 (patch) | |
tree | 9ef3b6ea138959fb4f59f97a791c0c4c4efebecd /skia | |
parent | f3750b3846cc639d75046be16826ff1cf109d76e (diff) | |
download | chromium_src-c4b347b36152d693f2914f13c3b6f83f16a6d9b8.zip chromium_src-c4b347b36152d693f2914f13c3b6f83f16a6d9b8.tar.gz chromium_src-c4b347b36152d693f2914f13c3b6f83f16a6d9b8.tar.bz2 |
Reverting 6709,6708,6706.
Review URL: http://codereview.chromium.org/13345
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@6710 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'skia')
-rw-r--r-- | skia/ext/convolver.cc | 59 | ||||
-rw-r--r-- | skia/ext/convolver.h | 24 | ||||
-rw-r--r-- | skia/ext/convolver_unittest.cc | 2 | ||||
-rw-r--r-- | skia/ext/image_operations.cc | 132 | ||||
-rw-r--r-- | skia/ext/image_operations.h | 17 | ||||
-rw-r--r-- | skia/ext/image_operations_unittest.cc | 24 |
6 files changed, 135 insertions, 123 deletions
diff --git a/skia/ext/convolver.cc b/skia/ext/convolver.cc index 8733c59..f5a429a 100644 --- a/skia/ext/convolver.cc +++ b/skia/ext/convolver.cc @@ -4,17 +4,18 @@ #include <algorithm> +#include "base/basictypes.h" +#include "base/logging.h" #include "skia/ext/convolver.h" -#include "SkTypes.h" -namespace skia { +namespace gfx { namespace { // Converts the argument to an 8-bit unsigned value by clamping to the range // 0-255. -inline unsigned int ClampTo8(int a) { - if (static_cast<int>(a) < 256) +inline uint8 ClampTo8(int32 a) { + if (static_cast<uint32>(a) < 256) return a; // Avoid the extra check in the common case. if (a < 0) return 0; @@ -44,8 +45,8 @@ class CircularRowBuffer { // Moves to the next row in the buffer, returning a pointer to the beginning // of it. - unsigned char* AdvanceRow() { - unsigned char* row = &buffer_[next_row_ * row_byte_width_]; + uint8* AdvanceRow() { + uint8* row = &buffer_[next_row_ * row_byte_width_]; next_row_coordinate_++; // Set the pointer to the next row to use, wrapping around if necessary. @@ -61,7 +62,7 @@ class CircularRowBuffer { // // The |first_row_index_| may be negative. This means the circular buffer // starts before the top of the image (it hasn't been filled yet). - unsigned char* const* GetRowAddresses(int* first_row_index) { + uint8* const* GetRowAddresses(int* first_row_index) { // Example for a 4-element circular buffer holding coords 6-9. // Row 0 Coord 8 // Row 1 Coord 9 @@ -88,7 +89,7 @@ class CircularRowBuffer { private: // The buffer storing the rows. They are packed, each one row_byte_width_. - std::vector<unsigned char> buffer_; + std::vector<uint8> buffer_; // Number of bytes per row in the |buffer_|. int row_byte_width_; @@ -105,13 +106,13 @@ class CircularRowBuffer { int next_row_coordinate_; // Buffer used by GetRowAddresses(). - std::vector<unsigned char*> row_addresses_; + std::vector<uint8*> row_addresses_; }; // Convolves horizontally along a single row. The row data is given in // |src_data| and continues for the num_values() of the filter. template<bool has_alpha> -void ConvolveHorizontally(const unsigned char* src_data, +void ConvolveHorizontally(const uint8* src_data, const ConvolusionFilter1D& filter, unsigned char* out_row) { // Loop over each pixel on this row in the output image. @@ -119,17 +120,17 @@ void ConvolveHorizontally(const unsigned char* src_data, for (int out_x = 0; out_x < num_values; out_x++) { // Get the filter that determines the current output pixel. int filter_offset, filter_length; - const short* filter_values = + const int16* filter_values = filter.FilterForValue(out_x, &filter_offset, &filter_length); // Compute the first pixel in this row that the filter affects. It will // touch |filter_length| pixels (4 bytes each) after this. - const unsigned char* row_to_filter = &src_data[filter_offset * 4]; + const uint8* row_to_filter = &src_data[filter_offset * 4]; // Apply the filter to the row to get the destination pixel in |accum|. - int accum[4] = {0}; + int32 accum[4] = {0}; for (int filter_x = 0; filter_x < filter_length; filter_x++) { - short cur_filter = filter_values[filter_x]; + int16 cur_filter = filter_values[filter_x]; accum[0] += cur_filter * row_to_filter[filter_x * 4 + 0]; accum[1] += cur_filter * row_to_filter[filter_x * 4 + 1]; accum[2] += cur_filter * row_to_filter[filter_x * 4 + 2]; @@ -161,11 +162,11 @@ void ConvolveHorizontally(const unsigned char* src_data, // // The output must have room for |pixel_width * 4| bytes. template<bool has_alpha> -void ConvolveVertically(const short* filter_values, +void ConvolveVertically(const int16* filter_values, int filter_length, - unsigned char* const* source_data_rows, + uint8* const* source_data_rows, int pixel_width, - unsigned char* out_row) { + uint8* out_row) { // We go through each column in the output and do a vertical convolusion, // generating one output pixel each time. for (int out_x = 0; out_x < pixel_width; out_x++) { @@ -174,9 +175,9 @@ void ConvolveVertically(const short* filter_values, int byte_offset = out_x * 4; // Apply the filter to one column of pixels. - int accum[4] = {0}; + int32 accum[4] = {0}; for (int filter_y = 0; filter_y < filter_length; filter_y++) { - short cur_filter = filter_values[filter_y]; + int16 cur_filter = filter_values[filter_y]; accum[0] += cur_filter * source_data_rows[filter_y][byte_offset + 0]; accum[1] += cur_filter * source_data_rows[filter_y][byte_offset + 1]; accum[2] += cur_filter * source_data_rows[filter_y][byte_offset + 2]; @@ -197,7 +198,7 @@ void ConvolveVertically(const short* filter_values, out_row[byte_offset + 1] = ClampTo8(accum[1]); out_row[byte_offset + 2] = ClampTo8(accum[2]); if (has_alpha) { - unsigned char alpha = ClampTo8(accum[3]); + uint8 alpha = ClampTo8(accum[3]); // Make sure the alpha channel doesn't come out larger than any of the // color channels. We use premultipled alpha channels, so this should @@ -232,7 +233,7 @@ void ConvolusionFilter1D::AddFilter(int filter_offset, instance.length = filter_length; filters_.push_back(instance); - SkASSERT(filter_length > 0); + DCHECK(filter_length > 0); for (int i = 0; i < filter_length; i++) filter_values_.push_back(FloatToFixed(filter_values[i])); @@ -240,7 +241,7 @@ void ConvolusionFilter1D::AddFilter(int filter_offset, } void ConvolusionFilter1D::AddFilter(int filter_offset, - const short* filter_values, + const int16* filter_values, int filter_length) { FilterInstance instance; instance.data_location = static_cast<int>(filter_values_.size()); @@ -248,7 +249,7 @@ void ConvolusionFilter1D::AddFilter(int filter_offset, instance.length = filter_length; filters_.push_back(instance); - SkASSERT(filter_length > 0); + DCHECK(filter_length > 0); for (int i = 0; i < filter_length; i++) filter_values_.push_back(filter_values[i]); @@ -257,12 +258,12 @@ void ConvolusionFilter1D::AddFilter(int filter_offset, // BGRAConvolve2D ------------------------------------------------------------- -void BGRAConvolve2D(const unsigned char* source_data, +void BGRAConvolve2D(const uint8* source_data, int source_byte_row_stride, bool source_has_alpha, const ConvolusionFilter1D& filter_x, const ConvolusionFilter1D& filter_y, - unsigned char* output) { + uint8* output) { int max_y_filter_size = filter_y.max_filter(); // The next row in the input that we will generate a horizontally @@ -271,7 +272,7 @@ void BGRAConvolve2D(const unsigned char* source_data, // don't want to generate any output rows before that. Compute the starting // row for convolusion as the first pixel for the first vertical filter. int filter_offset, filter_length; - const short* filter_values = + const int16* filter_values = filter_y.FilterForValue(0, &filter_offset, &filter_length); int next_x_row = filter_offset; @@ -306,16 +307,16 @@ void BGRAConvolve2D(const unsigned char* source_data, } // Compute where in the output image this row of final data will go. - unsigned char* cur_output_row = &output[out_y * output_row_byte_width]; + uint8* cur_output_row = &output[out_y * output_row_byte_width]; // Get the list of rows that the circular buffer has, in order. int first_row_in_circular_buffer; - unsigned char* const* rows_to_convolve = + uint8* const* rows_to_convolve = row_buffer.GetRowAddresses(&first_row_in_circular_buffer); // Now compute the start of the subset of those rows that the filter // needs. - unsigned char* const* first_row_for_filter = + uint8* const* first_row_for_filter = &rows_to_convolve[filter_offset - first_row_in_circular_buffer]; if (source_has_alpha) { diff --git a/skia/ext/convolver.h b/skia/ext/convolver.h index 2932a29..3ae84cd 100644 --- a/skia/ext/convolver.h +++ b/skia/ext/convolver.h @@ -7,12 +7,14 @@ #include <vector> +#include "base/basictypes.h" + // avoid confusion with Mac OS X's math library (Carbon) -#if defined(__APPLE__) +#if defined(OS_MACOSX) #undef FloatToFixed #endif -namespace skia { +namespace gfx { // Represents a filter in one dimension. Each output pixel has one entry in this // object for the filter values contributing to it. You build up the filter @@ -31,10 +33,10 @@ class ConvolusionFilter1D { } // Convert between floating point and our fixed point representation. - static short FloatToFixed(float f) { - return static_cast<short>(f * (1 << kShiftBits)); + static inline int16 FloatToFixed(float f) { + return static_cast<int16>(f * (1 << kShiftBits)); } - static unsigned char FixedToChar(short x) { + static inline unsigned char FixedToChar(int16 x) { return static_cast<unsigned char>(x >> kShiftBits); } @@ -63,7 +65,7 @@ class ConvolusionFilter1D { // Same as the above version, but the input is already fixed point. void AddFilter(int filter_offset, - const short* filter_values, + const int16* filter_values, int filter_length); // Retrieves a filter for the given |value_offset|, a position in the output @@ -71,7 +73,7 @@ class ConvolusionFilter1D { // filter values are put into the corresponding out arguments (see AddFilter // above for what these mean), and a pointer to the first scaling factor is // returned. There will be |filter_length| values in this array. - inline const short* FilterForValue(int value_offset, + inline const int16* FilterForValue(int value_offset, int* filter_offset, int* filter_length) const { const FilterInstance& filter = filters_[value_offset]; @@ -98,7 +100,7 @@ class ConvolusionFilter1D { // We store all the filter values in this flat list, indexed by // |FilterInstance.data_location| to avoid the mallocs required for storing // each one separately. - std::vector<short> filter_values_; + std::vector<int16> filter_values_; // The maximum size of any filter we've added. int max_filter_; @@ -122,14 +124,14 @@ class ConvolusionFilter1D { // // The layout in memory is assumed to be 4-bytes per pixel in B-G-R-A order // (this is ARGB when loaded into 32-bit words on a little-endian machine). -void BGRAConvolve2D(const unsigned char* source_data, +void BGRAConvolve2D(const uint8* source_data, int source_byte_row_stride, bool source_has_alpha, const ConvolusionFilter1D& xfilter, const ConvolusionFilter1D& yfilter, - unsigned char* output); + uint8* output); -} // namespace skia +} // namespace gfx #endif // SKIA_EXT_CONVOLVER_H_ diff --git a/skia/ext/convolver_unittest.cc b/skia/ext/convolver_unittest.cc index 7ca1567..6f85552 100644 --- a/skia/ext/convolver_unittest.cc +++ b/skia/ext/convolver_unittest.cc @@ -9,7 +9,7 @@ #include "skia/ext/convolver.h" #include "testing/gtest/include/gtest/gtest.h" -namespace skia { +namespace gfx { namespace { diff --git a/skia/ext/image_operations.cc b/skia/ext/image_operations.cc index fb0bd40..5e6c3ab 100644 --- a/skia/ext/image_operations.cc +++ b/skia/ext/image_operations.cc @@ -9,11 +9,14 @@ #include "skia/ext/image_operations.h" +#include "base/gfx/rect.h" +#include "base/gfx/size.h" +#include "base/logging.h" +#include "base/stack_container.h" #include "SkBitmap.h" -#include "SkRect.h" #include "skia/ext/convolver.h" -namespace skia { +namespace gfx { namespace { @@ -59,13 +62,13 @@ float EvalLanczos(int filter_size, float x) { class ResizeFilter { public: ResizeFilter(ImageOperations::ResizeMethod method, - int src_full_width, int src_full_height, - int dest_width, int dest_height, - const SkIRect& dest_subset); + const Size& src_full_size, + const Size& dest_size, + const Rect& dest_subset); // Returns the bounds in the input bitmap of data that is used in the output. // The filter offsets are within this rectangle. - const SkIRect& src_depend() { return src_depend_; } + const Rect& src_depend() { return src_depend_; } // Returns the filled filter values. const ConvolusionFilter1D& x_filter() { return x_filter_; } @@ -84,7 +87,7 @@ class ResizeFilter { // each direction as the size of the window = 3 for Lanczos3. return 3.0f; default: - SkASSERT(false); + NOTREACHED(); return 1.0f; } } @@ -112,7 +115,7 @@ class ResizeFilter { case ImageOperations::RESIZE_LANCZOS3: return EvalLanczos(3, pos); default: - SkASSERT(false); + NOTREACHED(); return 0; } } @@ -120,7 +123,7 @@ class ResizeFilter { ImageOperations::ResizeMethod method_; // Subset of source the filters will touch. - SkIRect src_depend_; + Rect src_depend_; // Size of the filter support on one side only in the destination space. // See GetFilterSupport. @@ -128,38 +131,40 @@ class ResizeFilter { float y_filter_support_; // Subset of scaled destination bitmap to compute. - SkIRect out_bounds_; + Rect out_bounds_; ConvolusionFilter1D x_filter_; ConvolusionFilter1D y_filter_; + + DISALLOW_EVIL_CONSTRUCTORS(ResizeFilter); }; ResizeFilter::ResizeFilter(ImageOperations::ResizeMethod method, - int src_full_width, int src_full_height, - int dest_width, int dest_height, - const SkIRect& dest_subset) + const Size& src_full_size, + const Size& dest_size, + const Rect& dest_subset) : method_(method), out_bounds_(dest_subset) { - float scale_x = static_cast<float>(dest_width) / - static_cast<float>(src_full_width); - float scale_y = static_cast<float>(dest_height) / - static_cast<float>(src_full_height); + float scale_x = static_cast<float>(dest_size.width()) / + static_cast<float>(src_full_size.width()); + float scale_y = static_cast<float>(dest_size.height()) / + static_cast<float>(src_full_size.height()); x_filter_support_ = GetFilterSupport(scale_x); y_filter_support_ = GetFilterSupport(scale_y); - SkIRect src_full = {0, 0, src_full_width, src_full_height}; - SkIRect dest_full = {0, 0, - static_cast<int>(src_full_width * scale_x + 0.5), - static_cast<int>(src_full_height * scale_y + 0.5)}; + gfx::Rect src_full(0, 0, src_full_size.width(), src_full_size.height()); + gfx::Rect dest_full(0, 0, + static_cast<int>(src_full_size.width() * scale_x + 0.5), + static_cast<int>(src_full_size.height() * scale_y + 0.5)); // Support of the filter in source space. float src_x_support = x_filter_support_ / scale_x; float src_y_support = y_filter_support_ / scale_y; - ComputeFilters(src_full_width, dest_subset.fLeft, dest_subset.width(), + ComputeFilters(src_full_size.width(), dest_subset.x(), dest_subset.width(), scale_x, src_x_support, &x_filter_); - ComputeFilters(src_full_height, dest_subset.fTop, dest_subset.height(), + ComputeFilters(src_full_size.height(), dest_subset.y(), dest_subset.height(), scale_y, src_y_support, &y_filter_); } @@ -179,10 +184,8 @@ void ResizeFilter::ComputeFilters(int src_size, // Speed up the divisions below by turning them into multiplies. float inv_scale = 1.0f / scale; - std::vector<float> filter_values; - filter_values.reserve(64); - std::vector<short> fixed_filter_values; - fixed_filter_values.reserve(64); + StackVector<float, 64> filter_values; + StackVector<int16, 64> fixed_filter_values; // Loop over all pixels in the output range. We will generate one set of // filter values for each one. Those values will tell us how to blend the @@ -191,8 +194,8 @@ void ResizeFilter::ComputeFilters(int src_size, dest_subset_i++) { // Reset the arrays. We don't declare them inside so they can re-use the // same malloc-ed buffer. - filter_values.clear(); - fixed_filter_values.clear(); + filter_values->clear(); + fixed_filter_values->clear(); // This is the pixel in the source directly under the pixel in the dest. float src_pixel = dest_subset_i * inv_scale; @@ -215,19 +218,19 @@ void ResizeFilter::ComputeFilters(int src_size, // Compute the filter value at that location. float filter_value = ComputeFilter(dest_filter_pos); - filter_values.push_back(filter_value); + filter_values->push_back(filter_value); filter_sum += filter_value; } - SkASSERT(!filter_values->empty()); + DCHECK(!filter_values->empty()) << "We should always get a filter!"; // The filter must be normalized so that we don't affect the brightness of // the image. Convert to normalized fixed point. - short fixed_sum = 0; - for (size_t i = 0; i < filter_values.size(); i++) { - short cur_fixed = output->FloatToFixed(filter_values[i] / filter_sum); + int16 fixed_sum = 0; + for (size_t i = 0; i < filter_values->size(); i++) { + int16 cur_fixed = output->FloatToFixed(filter_values[i] / filter_sum); fixed_sum += cur_fixed; - fixed_filter_values.push_back(cur_fixed); + fixed_filter_values->push_back(cur_fixed); } // The conversion to fixed point will leave some rounding errors, which @@ -235,12 +238,12 @@ void ResizeFilter::ComputeFilters(int src_size, // arbitrarily add this to the center of the filter array (this won't always // be the center of the filter function since it could get clipped on the // edges, but it doesn't matter enough to worry about that case). - short leftovers = output->FloatToFixed(1.0f) - fixed_sum; - fixed_filter_values[fixed_filter_values.size() / 2] += leftovers; + int16 leftovers = output->FloatToFixed(1.0f) - fixed_sum; + fixed_filter_values[fixed_filter_values->size() / 2] += leftovers; // Now it's ready to go. output->AddFilter(src_begin, &fixed_filter_values[0], - static_cast<int>(fixed_filter_values.size())); + static_cast<int>(fixed_filter_values->size())); } } @@ -251,24 +254,27 @@ void ResizeFilter::ComputeFilters(int src_size, // static SkBitmap ImageOperations::Resize(const SkBitmap& source, ResizeMethod method, - int dest_width, int dest_height, - const SkIRect& dest_subset) { + const Size& dest_size, + const Rect& dest_subset) { + DCHECK(Rect(dest_size.width(), dest_size.height()).Contains(dest_subset)) << + "The supplied subset does not fall within the destination image."; + // If the size of source or destination is 0, i.e. 0x0, 0xN or Nx0, just // return empty if (source.width() < 1 || source.height() < 1 || - dest_width < 1 || dest_height < 1) - return SkBitmap(); + dest_size.width() < 1 || dest_size.height() < 1) + return SkBitmap(); SkAutoLockPixels locker(source); - ResizeFilter filter(method, source.width(), source.height(), - dest_width, dest_height, dest_subset); + ResizeFilter filter(method, Size(source.width(), source.height()), + dest_size, dest_subset); // Get a source bitmap encompassing this touched area. We construct the // offsets and row strides such that it looks like a new bitmap, while // referring to the old data. - const unsigned char* source_subset = - reinterpret_cast<const unsigned char*>(source.getPixels()); + const uint8* source_subset = + reinterpret_cast<const uint8*>(source.getPixels()); // Convolve into the result. SkBitmap result; @@ -288,28 +294,29 @@ SkBitmap ImageOperations::Resize(const SkBitmap& source, // static SkBitmap ImageOperations::Resize(const SkBitmap& source, ResizeMethod method, - int dest_width, int dest_height) { - SkIRect dest_subset = {0, 0, dest_width, dest_height}; - return Resize(source, method, dest_width, dest_height, dest_subset); + const Size& dest_size) { + Rect dest_subset(0, 0, dest_size.width(), dest_size.height()); + return Resize(source, method, dest_size, dest_subset); } // static SkBitmap ImageOperations::CreateBlendedBitmap(const SkBitmap& first, const SkBitmap& second, double alpha) { - SkASSERT(alpha <= 1 && alpha >= 0); - SkASSERT(first.width() == second.width()); - SkASSERT(first.height() == second.height()); - SkASSERT(first.bytesPerPixel() == second.bytesPerPixel()); - SkASSERT(first.config() == SkBitmap::kARGB_8888_Config); + DCHECK(alpha <= 1 && alpha >= 0); + DCHECK(first.width() == second.width()); + DCHECK(first.height() == second.height()); + DCHECK(first.bytesPerPixel() == second.bytesPerPixel()); + DCHECK(first.config() == SkBitmap::kARGB_8888_Config); // Optimize for case where we won't need to blend anything. static const double alpha_min = 1.0 / 255; static const double alpha_max = 254.0 / 255; - if (alpha < alpha_min) + if (alpha < alpha_min) { return first; - else if (alpha > alpha_max) + } else if (alpha > alpha_max) { return second; + } SkAutoLockPixels lock_first(first); SkAutoLockPixels lock_second(second); @@ -323,13 +330,13 @@ SkBitmap ImageOperations::CreateBlendedBitmap(const SkBitmap& first, double first_alpha = 1 - alpha; for (int y = 0; y < first.height(); y++) { - uint32_t* first_row = first.getAddr32(0, y); - uint32_t* second_row = second.getAddr32(0, y); - uint32_t* dst_row = blended.getAddr32(0, y); + uint32* first_row = first.getAddr32(0, y); + uint32* second_row = second.getAddr32(0, y); + uint32* dst_row = blended.getAddr32(0, y); for (int x = 0; x < first.width(); x++) { - uint32_t first_pixel = first_row[x]; - uint32_t second_pixel = second_row[x]; + uint32 first_pixel = first_row[x]; + uint32 second_pixel = second_row[x]; int a = static_cast<int>( SkColorGetA(first_pixel) * first_alpha + @@ -351,4 +358,5 @@ SkBitmap ImageOperations::CreateBlendedBitmap(const SkBitmap& first, return blended; } -} // namespace skia +} // namespace gfx + diff --git a/skia/ext/image_operations.h b/skia/ext/image_operations.h index 22d5320..73c6b53 100644 --- a/skia/ext/image_operations.h +++ b/skia/ext/image_operations.h @@ -5,10 +5,12 @@ #ifndef SKIA_EXT_IMAGE_OPERATIONS_H_ #define SKIA_EXT_IMAGE_OPERATIONS_H_ +#include "base/basictypes.h" +#include "base/gfx/rect.h" + class SkBitmap; -struct SkIRect; -namespace skia { +namespace gfx { class ImageOperations { public: @@ -35,14 +37,14 @@ class ImageOperations { // The destination subset must be smaller than the destination image. static SkBitmap Resize(const SkBitmap& source, ResizeMethod method, - int dest_width, int dest_height, - const SkIRect& dest_subset); + const Size& dest_size, + const Rect& dest_subset); // Alternate version for resizing and returning the entire bitmap rather than // a subset. static SkBitmap Resize(const SkBitmap& source, ResizeMethod method, - int dest_width, int dest_height); + const Size& dest_size); // Create a bitmap that is a blend of two others. The alpha argument @@ -55,6 +57,7 @@ class ImageOperations { ImageOperations(); // Class for scoping only. }; -} // namespace skia +} // namespace gfx + +#endif // SKIA_EXT_IMAGE_OPERATIONS_H__ -#endif // SKIA_EXT_IMAGE_OPERATIONS_H_ diff --git a/skia/ext/image_operations_unittest.cc b/skia/ext/image_operations_unittest.cc index c8f365f..e6ecda9 100644 --- a/skia/ext/image_operations_unittest.cc +++ b/skia/ext/image_operations_unittest.cc @@ -6,9 +6,7 @@ #include "skia/ext/image_operations.h" #include "testing/gtest/include/gtest/gtest.h" - #include "SkBitmap.h" -#include "SkRect.h" namespace { @@ -69,8 +67,8 @@ TEST(ImageOperations, Halve) { FillDataToBitmap(src_w, src_h, &src); // Do a halving of the full bitmap. - SkBitmap actual_results = skia::ImageOperations::Resize( - src, skia::ImageOperations::RESIZE_BOX, src_w / 2, src_h / 2); + SkBitmap actual_results = gfx::ImageOperations::Resize( + src, gfx::ImageOperations::RESIZE_BOX, gfx::Size(src_w / 2, src_h / 2)); ASSERT_EQ(src_w / 2, actual_results.width()); ASSERT_EQ(src_h / 2, actual_results.height()); @@ -98,17 +96,17 @@ TEST(ImageOperations, HalveSubset) { FillDataToBitmap(src_w, src_h, &src); // Do a halving of the full bitmap. - SkBitmap full_results = skia::ImageOperations::Resize( - src, skia::ImageOperations::RESIZE_BOX, src_w / 2, src_h / 2); + SkBitmap full_results = gfx::ImageOperations::Resize( + src, gfx::ImageOperations::RESIZE_BOX, gfx::Size(src_w / 2, src_h / 2)); ASSERT_EQ(src_w / 2, full_results.width()); ASSERT_EQ(src_h / 2, full_results.height()); // Now do a halving of a a subset, recall the destination subset is in the // destination coordinate system (max = half of the original image size). - SkIRect subset_rect = {2, 3, 5, 9}; - SkBitmap subset_results = skia::ImageOperations::Resize( - src, skia::ImageOperations::RESIZE_BOX, - src_w / 2, src_h / 2, subset_rect); + gfx::Rect subset_rect(2, 3, 3, 6); + SkBitmap subset_results = gfx::ImageOperations::Resize( + src, gfx::ImageOperations::RESIZE_BOX, + gfx::Size(src_w / 2, src_h / 2), subset_rect); ASSERT_EQ(subset_rect.width(), subset_results.width()); ASSERT_EQ(subset_rect.height(), subset_results.height()); @@ -119,7 +117,7 @@ TEST(ImageOperations, HalveSubset) { for (int y = 0; y < subset_rect.height(); y++) { for (int x = 0; x < subset_rect.width(); x++) { ASSERT_EQ( - *full_results.getAddr32(x + subset_rect.fLeft, y + subset_rect.fTop), + *full_results.getAddr32(x + subset_rect.x(), y + subset_rect.y()), *subset_results.getAddr32(x, y)); } } @@ -134,8 +132,8 @@ TEST(ImageOperations, ResampleToSame) { // Do a resize of the full bitmap to the same size. The lanczos filter is good // enough that we should get exactly the same image for output. - SkBitmap results = skia::ImageOperations::Resize( - src, skia::ImageOperations::RESIZE_LANCZOS3, src_w, src_h); + SkBitmap results = gfx::ImageOperations::Resize( + src, gfx::ImageOperations::RESIZE_LANCZOS3, gfx::Size(src_w, src_h)); ASSERT_EQ(src_w, results.width()); ASSERT_EQ(src_h, results.height()); |