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

Side by Side Diff: skia/ext/convolver.h

Issue 6674050: Fix for windows shared build compile failure. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 9 years, 9 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) 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 #include "base/cpu.h"
14 #include "third_party/skia/include/core/SkTypes.h"
14 15
15 #if defined(ARCH_CPU_X86_FAMILY) 16 #if defined(ARCH_CPU_X86_FAMILY)
16 #if defined(__x86_64__) || defined(_M_X64) || defined(__SSE2__) || _M_IX86_FP==2 17 #if defined(__x86_64__) || defined(_M_X64) || defined(__SSE2__) || _M_IX86_FP==2
17 // This is where we had compiler support for SSE2 instructions. 18 // This is where we had compiler support for SSE2 instructions.
18 #define SIMD_SSE2 1 19 #define SIMD_SSE2 1
19 #endif 20 #endif
20 #endif 21 #endif
21 22
22 // avoid confusion with Mac OS X's math library (Carbon) 23 // avoid confusion with Mac OS X's math library (Carbon)
23 #if defined(__APPLE__) 24 #if defined(__APPLE__)
(...skipping 11 matching lines...) Expand all
35 // ConvolutionFilter1D, then convolving each column by another one. 36 // ConvolutionFilter1D, then convolving each column by another one.
36 // 37 //
37 // Entries are stored in fixed point, shifted left by kShiftBits. 38 // Entries are stored in fixed point, shifted left by kShiftBits.
38 class ConvolutionFilter1D { 39 class ConvolutionFilter1D {
39 public: 40 public:
40 typedef short Fixed; 41 typedef short Fixed;
41 42
42 // The number of bits that fixed point values are shifted by. 43 // The number of bits that fixed point values are shifted by.
43 enum { kShiftBits = 14 }; 44 enum { kShiftBits = 14 };
44 45
45 ConvolutionFilter1D(); 46 SK_API ConvolutionFilter1D();
46 ~ConvolutionFilter1D(); 47 SK_API ~ConvolutionFilter1D();
47 48
48 // Convert between floating point and our fixed point representation. 49 // Convert between floating point and our fixed point representation.
49 static Fixed FloatToFixed(float f) { 50 static Fixed FloatToFixed(float f) {
50 return static_cast<Fixed>(f * (1 << kShiftBits)); 51 return static_cast<Fixed>(f * (1 << kShiftBits));
51 } 52 }
52 static unsigned char FixedToChar(Fixed x) { 53 static unsigned char FixedToChar(Fixed x) {
53 return static_cast<unsigned char>(x >> kShiftBits); 54 return static_cast<unsigned char>(x >> kShiftBits);
54 } 55 }
55 static float FixedToFloat(Fixed x) { 56 static float FixedToFloat(Fixed x) {
56 // The cast relies on Fixed being a short, implying that on 57 // The cast relies on Fixed being a short, implying that on
(...skipping 16 matching lines...) Expand all
73 // the scaling factors start. The scaling factors apply to the source pixels 74 // the scaling factors start. The scaling factors apply to the source pixels
74 // starting from this position, and going for the next |filter_length| pixels. 75 // starting from this position, and going for the next |filter_length| pixels.
75 // 76 //
76 // You will probably want to make sure your input is normalized (that is, 77 // You will probably want to make sure your input is normalized (that is,
77 // all entries in |filter_values| sub to one) to prevent affecting the overall 78 // all entries in |filter_values| sub to one) to prevent affecting the overall
78 // brighness of the image. 79 // brighness of the image.
79 // 80 //
80 // The filter_length must be > 0. 81 // The filter_length must be > 0.
81 // 82 //
82 // This version will automatically convert your input to fixed point. 83 // This version will automatically convert your input to fixed point.
83 void AddFilter(int filter_offset, 84 SK_API void AddFilter(int filter_offset,
84 const float* filter_values, 85 const float* filter_values,
85 int filter_length); 86 int filter_length);
86 87
87 // Same as the above version, but the input is already fixed point. 88 // Same as the above version, but the input is already fixed point.
88 void AddFilter(int filter_offset, 89 void AddFilter(int filter_offset,
89 const Fixed* filter_values, 90 const Fixed* filter_values,
90 int filter_length); 91 int filter_length);
91 92
92 // Retrieves a filter for the given |value_offset|, a position in the output 93 // Retrieves a filter for the given |value_offset|, a position in the output
93 // image in the direction we're convolving. The offset and length of the 94 // image in the direction we're convolving. The offset and length of the
94 // filter values are put into the corresponding out arguments (see AddFilter 95 // filter values are put into the corresponding out arguments (see AddFilter
95 // above for what these mean), and a pointer to the first scaling factor is 96 // above for what these mean), and a pointer to the first scaling factor is
(...skipping 15 matching lines...) Expand all
111 // Padding |padding_count| of more dummy coefficients after the coefficients 112 // Padding |padding_count| of more dummy coefficients after the coefficients
112 // of last filter to prevent SIMD instructions which load 8 or 16 bytes 113 // of last filter to prevent SIMD instructions which load 8 or 16 bytes
113 // together to access invalid memory areas. We are not trying to align the 114 // together to access invalid memory areas. We are not trying to align the
114 // coefficients right now due to the opaqueness of <vector> implementation. 115 // coefficients right now due to the opaqueness of <vector> implementation.
115 // This has to be done after all |AddFilter| calls. 116 // This has to be done after all |AddFilter| calls.
116 for (int i = 0; i < padding_count; ++i) 117 for (int i = 0; i < padding_count; ++i)
117 filter_values_.push_back(static_cast<Fixed>(0)); 118 filter_values_.push_back(static_cast<Fixed>(0));
118 } 119 }
119 120
120 private: 121 private:
121 struct FilterInstance { 122 struct SK_API FilterInstance {
122 // Offset within filter_values for this instance of the filter. 123 // Offset within filter_values for this instance of the filter.
123 int data_location; 124 int data_location;
124 125
125 // Distance from the left of the filter to the center. IN PIXELS 126 // Distance from the left of the filter to the center. IN PIXELS
126 int offset; 127 int offset;
127 128
128 // Number of values in this filter instance. 129 // Number of values in this filter instance.
129 int length; 130 int length;
130 }; 131 };
131 132
(...skipping 20 matching lines...) Expand all
152 // size will be xfilter.num_values() * yfilter.num_values() pixels. It will be 153 // size will be xfilter.num_values() * yfilter.num_values() pixels. It will be
153 // in rows of exactly xfilter.num_values() * 4 bytes. 154 // in rows of exactly xfilter.num_values() * 4 bytes.
154 // 155 //
155 // |source_has_alpha| is a hint that allows us to avoid doing computations on 156 // |source_has_alpha| is a hint that allows us to avoid doing computations on
156 // the alpha channel if the image is opaque. If you don't know, set this to 157 // the alpha channel if the image is opaque. If you don't know, set this to
157 // true and it will work properly, but setting this to false will be a few 158 // true and it will work properly, but setting this to false will be a few
158 // percent faster if you know the image is opaque. 159 // percent faster if you know the image is opaque.
159 // 160 //
160 // The layout in memory is assumed to be 4-bytes per pixel in B-G-R-A order 161 // The layout in memory is assumed to be 4-bytes per pixel in B-G-R-A order
161 // (this is ARGB when loaded into 32-bit words on a little-endian machine). 162 // (this is ARGB when loaded into 32-bit words on a little-endian machine).
162 void BGRAConvolve2D(const unsigned char* source_data, 163 SK_API void BGRAConvolve2D(const unsigned char* source_data,
163 int source_byte_row_stride, 164 int source_byte_row_stride,
164 bool source_has_alpha, 165 bool source_has_alpha,
165 const ConvolutionFilter1D& xfilter, 166 const ConvolutionFilter1D& xfilter,
166 const ConvolutionFilter1D& yfilter, 167 const ConvolutionFilter1D& yfilter,
167 int output_byte_row_stride, 168 int output_byte_row_stride,
168 unsigned char* output, 169 unsigned char* output,
169 bool use_sse2); 170 bool use_sse2);
170 } // namespace skia 171 } // namespace skia
171 172
172 #endif // SKIA_EXT_CONVOLVER_H_ 173 #endif // SKIA_EXT_CONVOLVER_H_
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