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

Side by Side Diff: src/opts/SkBitmapFilter_opts_SSE2.cpp

Issue 18978014: Working plumb of image scaling: (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: nits from robert Created 7 years, 5 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 | « src/core/SkBitmapProcState_shaderproc.h ('k') | src/opts/SkBitmapProcState_matrix_clamp_neon.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2013 Google Inc. 2 * Copyright 2013 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "SkBitmapProcState.h" 8 #include "SkBitmapProcState.h"
9 #include "SkBitmap.h" 9 #include "SkBitmap.h"
10 #include "SkColor.h" 10 #include "SkColor.h"
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 int debug_y = 255; 48 int debug_y = 255;
49 49
50 void highQualityFilter_SSE2(const SkBitmapProcState& s, int x, int y, 50 void highQualityFilter_SSE2(const SkBitmapProcState& s, int x, int y,
51 SkPMColor* SK_RESTRICT colors, int count) { 51 SkPMColor* SK_RESTRICT colors, int count) {
52 52
53 const int maxX = s.fBitmap->width() - 1; 53 const int maxX = s.fBitmap->width() - 1;
54 const int maxY = s.fBitmap->height() - 1; 54 const int maxY = s.fBitmap->height() - 1;
55 55
56 while (count-- > 0) { 56 while (count-- > 0) {
57 SkPoint srcPt; 57 SkPoint srcPt;
58 s.fInvProc(*s.fInvMatrix, SkIntToScalar(x), 58 s.fInvProc(s.fInvMatrix, SkIntToScalar(x),
59 SkIntToScalar(y), &srcPt); 59 SkIntToScalar(y), &srcPt);
60 srcPt.fX -= SK_ScalarHalf; 60 srcPt.fX -= SK_ScalarHalf;
61 srcPt.fY -= SK_ScalarHalf; 61 srcPt.fY -= SK_ScalarHalf;
62 62
63 int sx = SkScalarFloorToInt(srcPt.fX); 63 int sx = SkScalarFloorToInt(srcPt.fX);
64 int sy = SkScalarFloorToInt(srcPt.fY); 64 int sy = SkScalarFloorToInt(srcPt.fY);
65 65
66 __m128 weight = _mm_setzero_ps(); 66 __m128 weight = _mm_setzero_ps();
67 __m128 accum = _mm_setzero_ps(); 67 __m128 accum = _mm_setzero_ps();
68 68
69 int y0 = SkTMax(0, int(ceil(sy-s.getBitmapFilter()->width() + 0.5f))); 69 int y0 = SkTMax(0, int(ceil(sy-s.getBitmapFilter()->width() + 0.5f)));
70 int y1 = SkTMin(maxY, int(floor(sy+s.getBitmapFilter()->width() + 0.5f)) ); 70 int y1 = SkTMin(maxY, int(floor(sy+s.getBitmapFilter()->width() + 0.5f)) );
71 int x0 = SkTMax(0, int(ceil(sx-s.getBitmapFilter()->width() + 0.5f))); 71 int x0 = SkTMax(0, int(ceil(sx-s.getBitmapFilter()->width() + 0.5f)));
72 int x1 = SkTMin(maxX, int(floor(sx+s.getBitmapFilter()->width() + 0.5f)) ); 72 int x1 = SkTMin(maxX, int(floor(sx+s.getBitmapFilter()->width() + 0.5f)) );
73 73
74 for (int src_y = y0; src_y <= y1; src_y++) { 74 for (int src_y = y0; src_y <= y1; src_y++) {
75 float yweight = s.getBitmapFilter()->lookupFloat( (srcPt.fY - src_y) ); 75 float yweight = SkScalarToFloat(s.getBitmapFilter()->lookupScalar(sr cPt.fY - src_y));
76 76
77 for (int src_x = x0; src_x <= x1 ; src_x++) { 77 for (int src_x = x0; src_x <= x1 ; src_x++) {
78 float xweight = s.getBitmapFilter()->lookupFloat( (srcPt.fX - sr c_x) ); 78 float xweight = SkScalarToFloat(s.getBitmapFilter()->lookupScala r(srcPt.fX - src_x));
79 79
80 float combined_weight = xweight * yweight; 80 float combined_weight = xweight * yweight;
81 81
82 SkPMColor color = *s.fBitmap->getAddr32(src_x, src_y); 82 SkPMColor color = *s.fBitmap->getAddr32(src_x, src_y);
83 83
84 __m128i c = _mm_cvtsi32_si128( color ); 84 __m128i c = _mm_cvtsi32_si128( color );
85 c = _mm_unpacklo_epi8(c, _mm_setzero_si128()); 85 c = _mm_unpacklo_epi8(c, _mm_setzero_si128());
86 c = _mm_unpacklo_epi16(c, _mm_setzero_si128()); 86 c = _mm_unpacklo_epi16(c, _mm_setzero_si128());
87 87
88 __m128 cfloat = _mm_cvtepi32_ps( c ); 88 __m128 cfloat = _mm_cvtepi32_ps( c );
(...skipping 22 matching lines...) Expand all
111 x++; 111 x++;
112 } 112 }
113 } 113 }
114 114
115 void highQualityFilter_ScaleOnly_SSE2(const SkBitmapProcState &s, int x, int y, 115 void highQualityFilter_ScaleOnly_SSE2(const SkBitmapProcState &s, int x, int y,
116 SkPMColor *SK_RESTRICT colors, int count) { 116 SkPMColor *SK_RESTRICT colors, int count) {
117 const int maxX = s.fBitmap->width() - 1; 117 const int maxX = s.fBitmap->width() - 1;
118 const int maxY = s.fBitmap->height() - 1; 118 const int maxY = s.fBitmap->height() - 1;
119 119
120 SkPoint srcPt; 120 SkPoint srcPt;
121 s.fInvProc(*s.fInvMatrix, SkIntToScalar(x), 121 s.fInvProc(s.fInvMatrix, SkIntToScalar(x),
122 SkIntToScalar(y), &srcPt); 122 SkIntToScalar(y), &srcPt);
123 srcPt.fY -= SK_ScalarHalf; 123 srcPt.fY -= SK_ScalarHalf;
124 int sy = SkScalarFloorToInt(srcPt.fY); 124 int sy = SkScalarFloorToInt(srcPt.fY);
125 125
126 int y0 = SkTMax(0, int(ceil(sy-s.getBitmapFilter()->width() + 0.5f))); 126 int y0 = SkTMax(0, int(ceil(sy-s.getBitmapFilter()->width() + 0.5f)));
127 int y1 = SkTMin(maxY, int(floor(sy+s.getBitmapFilter()->width() + 0.5f))); 127 int y1 = SkTMin(maxY, int(floor(sy+s.getBitmapFilter()->width() + 0.5f)));
128 128
129 while (count-- > 0) { 129 while (count-- > 0) {
130 srcPt.fX -= SK_ScalarHalf; 130 srcPt.fX -= SK_ScalarHalf;
131 srcPt.fY -= SK_ScalarHalf; 131 srcPt.fY -= SK_ScalarHalf;
132 132
133 int sx = SkScalarFloorToInt(srcPt.fX); 133 int sx = SkScalarFloorToInt(srcPt.fX);
134 134
135 float weight = 0; 135 float weight = 0;
136 __m128 accum = _mm_setzero_ps(); 136 __m128 accum = _mm_setzero_ps();
137 137
138 int x0 = SkTMax(0, int(ceil(sx-s.getBitmapFilter()->width() + 0.5f))); 138 int x0 = SkTMax(0, int(ceil(sx-s.getBitmapFilter()->width() + 0.5f)));
139 int x1 = SkTMin(maxX, int(floor(sx+s.getBitmapFilter()->width() + 0.5f)) ); 139 int x1 = SkTMin(maxX, int(floor(sx+s.getBitmapFilter()->width() + 0.5f)) );
140 140
141 for (int src_y = y0; src_y <= y1; src_y++) { 141 for (int src_y = y0; src_y <= y1; src_y++) {
142 float yweight = s.getBitmapFilter()->lookupFloat( (srcPt.fY - src_y) ); 142 float yweight = SkScalarToFloat(s.getBitmapFilter()->lookupScalar(sr cPt.fY - src_y));
143 143
144 for (int src_x = x0; src_x <= x1 ; src_x++) { 144 for (int src_x = x0; src_x <= x1 ; src_x++) {
145 float xweight = s.getBitmapFilter()->lookupFloat( (srcPt.fX - sr c_x) ); 145 float xweight = SkScalarToFloat(s.getBitmapFilter()->lookupScala r(srcPt.fX - src_x));
146 146
147 float combined_weight = xweight * yweight; 147 float combined_weight = xweight * yweight;
148 148
149 SkPMColor color = *s.fBitmap->getAddr32(src_x, src_y); 149 SkPMColor color = *s.fBitmap->getAddr32(src_x, src_y);
150 150
151 __m128 c = _mm_set_ps((float)SkGetPackedB32(color), 151 __m128 c = _mm_set_ps((float)SkGetPackedB32(color),
152 (float)SkGetPackedG32(color), 152 (float)SkGetPackedG32(color),
153 (float)SkGetPackedR32(color), 153 (float)SkGetPackedR32(color),
154 (float)SkGetPackedA32(color)); 154 (float)SkGetPackedA32(color));
155 155
(...skipping 12 matching lines...) Expand all
168 _mm_storeu_ps(localResult, accum); 168 _mm_storeu_ps(localResult, accum);
169 int a = SkClampMax(int(localResult[0]), 255); 169 int a = SkClampMax(int(localResult[0]), 255);
170 int r = SkClampMax(int(localResult[1]), a); 170 int r = SkClampMax(int(localResult[1]), a);
171 int g = SkClampMax(int(localResult[2]), a); 171 int g = SkClampMax(int(localResult[2]), a);
172 int b = SkClampMax(int(localResult[3]), a); 172 int b = SkClampMax(int(localResult[3]), a);
173 173
174 *colors++ = SkPackARGB32(a, r, g, b); 174 *colors++ = SkPackARGB32(a, r, g, b);
175 175
176 x++; 176 x++;
177 177
178 s.fInvProc(*s.fInvMatrix, SkIntToScalar(x), 178 s.fInvProc(s.fInvMatrix, SkIntToScalar(x),
179 SkIntToScalar(y), &srcPt); 179 SkIntToScalar(y), &srcPt);
180 180
181 } 181 }
182 } 182 }
OLDNEW
« no previous file with comments | « src/core/SkBitmapProcState_shaderproc.h ('k') | src/opts/SkBitmapProcState_matrix_clamp_neon.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698