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

Side by Side Diff: src/effects/SkBicubicImageFilter.cpp

Issue 112803004: Make SkImageFilter crop rects relative to the primitive origin, instead of relative to their parent (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Updated to ToT Created 6 years, 11 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/SkImageFilterUtils.cpp ('k') | src/effects/SkBitmapSource.cpp » ('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 The Android Open Source Project 2 * Copyright 2013 The Android Open Source Project
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 "SkBicubicImageFilter.h" 8 #include "SkBicubicImageFilter.h"
9 #include "SkBitmap.h" 9 #include "SkBitmap.h"
10 #include "SkColorPriv.h" 10 #include "SkColorPriv.h"
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 return SkPackARGB32(SkScalarRoundToInt(a), 77 return SkPackARGB32(SkScalarRoundToInt(a),
78 SkScalarRoundToInt(SkScalarClampMax(r, a)), 78 SkScalarRoundToInt(SkScalarClampMax(r, a)),
79 SkScalarRoundToInt(SkScalarClampMax(g, a)), 79 SkScalarRoundToInt(SkScalarClampMax(g, a)),
80 SkScalarRoundToInt(SkScalarClampMax(b, a))); 80 SkScalarRoundToInt(SkScalarClampMax(b, a)));
81 } 81 }
82 82
83 bool SkBicubicImageFilter::onFilterImage(Proxy* proxy, 83 bool SkBicubicImageFilter::onFilterImage(Proxy* proxy,
84 const SkBitmap& source, 84 const SkBitmap& source,
85 const SkMatrix& matrix, 85 const SkMatrix& matrix,
86 SkBitmap* result, 86 SkBitmap* result,
87 SkIPoint* loc) { 87 SkIPoint* offset) {
88 SkBitmap src = source; 88 SkBitmap src = source;
89 if (getInput(0) && !getInput(0)->filterImage(proxy, source, matrix, &src, lo c)) { 89 SkIPoint srcOffset = SkIPoint::Make(0, 0);
90 if (getInput(0) && !getInput(0)->filterImage(proxy, source, matrix, &src, &s rcOffset)) {
90 return false; 91 return false;
91 } 92 }
92 93
93 if (src.config() != SkBitmap::kARGB_8888_Config) { 94 if (src.config() != SkBitmap::kARGB_8888_Config) {
94 return false; 95 return false;
95 } 96 }
96 97
97 SkAutoLockPixels alp(src); 98 SkAutoLockPixels alp(src);
98 if (!src.getPixels()) { 99 if (!src.getPixels()) {
99 return false; 100 return false;
100 } 101 }
101 102
102 SkRect dstRect = SkRect::MakeWH(SkScalarMul(SkIntToScalar(src.width()), fSca le.fWidth), 103 SkRect dstRect = SkRect::MakeWH(SkScalarMul(SkIntToScalar(src.width()), fSca le.fWidth),
103 SkScalarMul(SkIntToScalar(src.height()), fSc ale.fHeight)); 104 SkScalarMul(SkIntToScalar(src.height()), fSc ale.fHeight));
104 SkIRect dstIRect; 105 SkIRect dstIRect;
105 dstRect.roundOut(&dstIRect); 106 dstRect.roundOut(&dstIRect);
106 if (dstIRect.isEmpty()) { 107 if (dstIRect.isEmpty()) {
107 return false; 108 return false;
108 } 109 }
109 result->setConfig(src.config(), dstIRect.width(), dstIRect.height()); 110 result->setConfig(src.config(), dstIRect.width(), dstIRect.height());
110 result->allocPixels(); 111 result->allocPixels();
111 if (!result->getPixels()) { 112 if (!result->getPixels()) {
112 return false; 113 return false;
113 } 114 }
114 115
115 SkRect srcRect; 116 SkRect srcRect;
116 src.getBounds(&srcRect); 117 src.getBounds(&srcRect);
118 srcRect.offset(SkPoint::Make(SkIntToScalar(srcOffset.fX), SkIntToScalar(srcO ffset.fY)));
117 SkMatrix inverse; 119 SkMatrix inverse;
118 inverse.setRectToRect(dstRect, srcRect, SkMatrix::kFill_ScaleToFit); 120 inverse.setRectToRect(dstRect, srcRect, SkMatrix::kFill_ScaleToFit);
119 inverse.postTranslate(-0.5f, -0.5f); 121 inverse.postTranslate(-0.5f, -0.5f);
120 122
121 for (int y = dstIRect.fTop; y < dstIRect.fBottom; ++y) { 123 for (int y = dstIRect.fTop; y < dstIRect.fBottom; ++y) {
122 SkPMColor* dptr = result->getAddr32(dstIRect.fLeft, y); 124 SkPMColor* dptr = result->getAddr32(dstIRect.fLeft, y);
123 for (int x = dstIRect.fLeft; x < dstIRect.fRight; ++x) { 125 for (int x = dstIRect.fLeft; x < dstIRect.fRight; ++x) {
124 SkPoint srcPt, dstPt = SkPoint::Make(SkIntToScalar(x), SkIntToScalar (y)); 126 SkPoint srcPt, dstPt = SkPoint::Make(SkIntToScalar(x), SkIntToScalar (y));
125 inverse.mapPoints(&srcPt, &dstPt, 1); 127 inverse.mapPoints(&srcPt, &dstPt, 1);
126 SkScalar fractx = srcPt.fX - SkScalarFloorToScalar(srcPt.fX); 128 SkScalar fractx = srcPt.fX - SkScalarFloorToScalar(srcPt.fX);
(...skipping 24 matching lines...) Expand all
151 SkPMColor s32 = *src.getAddr32(x3, y2); 153 SkPMColor s32 = *src.getAddr32(x3, y2);
152 SkPMColor s2 = cubicBlend(fCoefficients, fractx, s02, s12, s22, s32) ; 154 SkPMColor s2 = cubicBlend(fCoefficients, fractx, s02, s12, s22, s32) ;
153 SkPMColor s03 = *src.getAddr32(x0, y3); 155 SkPMColor s03 = *src.getAddr32(x0, y3);
154 SkPMColor s13 = *src.getAddr32(x1, y3); 156 SkPMColor s13 = *src.getAddr32(x1, y3);
155 SkPMColor s23 = *src.getAddr32(x2, y3); 157 SkPMColor s23 = *src.getAddr32(x2, y3);
156 SkPMColor s33 = *src.getAddr32(x3, y3); 158 SkPMColor s33 = *src.getAddr32(x3, y3);
157 SkPMColor s3 = cubicBlend(fCoefficients, fractx, s03, s13, s23, s33) ; 159 SkPMColor s3 = cubicBlend(fCoefficients, fractx, s03, s13, s23, s33) ;
158 *dptr++ = cubicBlend(fCoefficients, fracty, s0, s1, s2, s3); 160 *dptr++ = cubicBlend(fCoefficients, fracty, s0, s1, s2, s3);
159 } 161 }
160 } 162 }
163 offset->fX = dstIRect.fLeft;
164 offset->fY = dstIRect.fTop;
161 return true; 165 return true;
162 } 166 }
163 167
164 /////////////////////////////////////////////////////////////////////////////// 168 ///////////////////////////////////////////////////////////////////////////////
165 169
166 #if SK_SUPPORT_GPU 170 #if SK_SUPPORT_GPU
167 171
168 bool SkBicubicImageFilter::filterImageGPU(Proxy* proxy, const SkBitmap& src, con st SkMatrix& ctm, 172 bool SkBicubicImageFilter::filterImageGPU(Proxy* proxy, const SkBitmap& src, con st SkMatrix& ctm,
169 SkBitmap* result, SkIPoint* offset) { 173 SkBitmap* result, SkIPoint* offset) {
170 SkBitmap srcBM; 174 SkBitmap srcBM;
(...skipping 21 matching lines...) Expand all
192 GrPaint paint; 196 GrPaint paint;
193 paint.addColorEffect(GrBicubicEffect::Create(srcTexture, fCoefficients))->un ref(); 197 paint.addColorEffect(GrBicubicEffect::Create(srcTexture, fCoefficients))->un ref();
194 SkRect srcRect; 198 SkRect srcRect;
195 srcBM.getBounds(&srcRect); 199 srcBM.getBounds(&srcRect);
196 context->drawRectToRect(paint, dstRect, srcRect); 200 context->drawRectToRect(paint, dstRect, srcRect);
197 return SkImageFilterUtils::WrapTexture(dst, desc.fWidth, desc.fHeight, resul t); 201 return SkImageFilterUtils::WrapTexture(dst, desc.fWidth, desc.fHeight, resul t);
198 } 202 }
199 #endif 203 #endif
200 204
201 /////////////////////////////////////////////////////////////////////////////// 205 ///////////////////////////////////////////////////////////////////////////////
OLDNEW
« no previous file with comments | « src/core/SkImageFilterUtils.cpp ('k') | src/effects/SkBitmapSource.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698