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/ext/convolver.cc | |
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/ext/convolver.cc')
-rw-r--r-- | skia/ext/convolver.cc | 59 |
1 files changed, 30 insertions, 29 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) { |