| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #ifndef SKIA_EXT_CONVOLVER_H_ | 5 #ifndef SKIA_EXT_CONVOLVER_H_ |
| 6 #define SKIA_EXT_CONVOLVER_H_ | 6 #define SKIA_EXT_CONVOLVER_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <cmath> | 9 #include <cmath> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
| 13 #include "base/cpu.h" |
| 13 | 14 |
| 14 // avoid confusion with Mac OS X's math library (Carbon) | 15 // avoid confusion with Mac OS X's math library (Carbon) |
| 15 #if defined(__APPLE__) | 16 #if defined(__APPLE__) |
| 16 #undef FloatToFixed | 17 #undef FloatToFixed |
| 17 #undef FixedToFloat | 18 #undef FixedToFloat |
| 18 #endif | 19 #endif |
| 19 | 20 |
| 20 namespace skia { | 21 namespace skia { |
| 21 | 22 |
| 22 // Represents a filter in one dimension. Each output pixel has one entry in this | 23 // Represents a filter in one dimension. Each output pixel has one entry in this |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 int* filter_length) const { | 92 int* filter_length) const { |
| 92 const FilterInstance& filter = filters_[value_offset]; | 93 const FilterInstance& filter = filters_[value_offset]; |
| 93 *filter_offset = filter.offset; | 94 *filter_offset = filter.offset; |
| 94 *filter_length = filter.length; | 95 *filter_length = filter.length; |
| 95 if (filter.length == 0) { | 96 if (filter.length == 0) { |
| 96 return NULL; | 97 return NULL; |
| 97 } | 98 } |
| 98 return &filter_values_[filter.data_location]; | 99 return &filter_values_[filter.data_location]; |
| 99 } | 100 } |
| 100 | 101 |
| 102 |
| 103 inline void PaddingForSIMD(int padding_count) { |
| 104 // Padding |padding_count| of more dummy coefficients after the coefficients |
| 105 // of last filter to prevent SIMD instructions which load 8 or 16 bytes |
| 106 // together to access invalid memory areas. We are not trying to align the |
| 107 // coefficients right now due to the opaqueness of <vector> implementation. |
| 108 // This has to be done after all |AddFilter| calls. |
| 109 for (int i = 0; i < padding_count; ++i) |
| 110 filter_values_.push_back(static_cast<Fixed>(0)); |
| 111 } |
| 112 |
| 101 private: | 113 private: |
| 102 struct FilterInstance { | 114 struct FilterInstance { |
| 103 // Offset within filter_values for this instance of the filter. | 115 // Offset within filter_values for this instance of the filter. |
| 104 int data_location; | 116 int data_location; |
| 105 | 117 |
| 106 // Distance from the left of the filter to the center. IN PIXELS | 118 // Distance from the left of the filter to the center. IN PIXELS |
| 107 int offset; | 119 int offset; |
| 108 | 120 |
| 109 // Number of values in this filter instance. | 121 // Number of values in this filter instance. |
| 110 int length; | 122 int length; |
| (...skipping 28 matching lines...) Expand all Loading... |
| 139 // percent faster if you know the image is opaque. | 151 // percent faster if you know the image is opaque. |
| 140 // | 152 // |
| 141 // The layout in memory is assumed to be 4-bytes per pixel in B-G-R-A order | 153 // The layout in memory is assumed to be 4-bytes per pixel in B-G-R-A order |
| 142 // (this is ARGB when loaded into 32-bit words on a little-endian machine). | 154 // (this is ARGB when loaded into 32-bit words on a little-endian machine). |
| 143 void BGRAConvolve2D(const unsigned char* source_data, | 155 void BGRAConvolve2D(const unsigned char* source_data, |
| 144 int source_byte_row_stride, | 156 int source_byte_row_stride, |
| 145 bool source_has_alpha, | 157 bool source_has_alpha, |
| 146 const ConvolutionFilter1D& xfilter, | 158 const ConvolutionFilter1D& xfilter, |
| 147 const ConvolutionFilter1D& yfilter, | 159 const ConvolutionFilter1D& yfilter, |
| 148 int output_byte_row_stride, | 160 int output_byte_row_stride, |
| 149 unsigned char* output); | 161 unsigned char* output, |
| 150 | 162 bool use_sse2); |
| 151 } // namespace skia | 163 } // namespace skia |
| 152 | 164 |
| 153 #endif // SKIA_EXT_CONVOLVER_H_ | 165 #endif // SKIA_EXT_CONVOLVER_H_ |
| OLD | NEW |