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

Side by Side Diff: src/image/SkImage.cpp

Issue 1390913005: add applyFilter() to SkImage (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: rebase to new effect factories, use stroke to show image bounds Created 5 years, 2 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
OLDNEW
1 /* 1 /*
2 * Copyright 2012 Google Inc. 2 * Copyright 2012 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 "SkBitmap.h" 8 #include "SkBitmap.h"
9 #include "SkBitmapCache.h" 9 #include "SkBitmapCache.h"
10 #include "SkCanvas.h" 10 #include "SkCanvas.h"
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 // For now, and to maintain parity w/ previous pixelref behavior, we just fo rce the image 60 // For now, and to maintain parity w/ previous pixelref behavior, we just fo rce the image
61 // to produce a cached raster-bitmap form, so that drawing to a raster canva s should be fast. 61 // to produce a cached raster-bitmap form, so that drawing to a raster canva s should be fast.
62 // 62 //
63 SkBitmap bm; 63 SkBitmap bm;
64 if (as_IB(this)->getROPixels(&bm)) { 64 if (as_IB(this)->getROPixels(&bm)) {
65 bm.lockPixels(); 65 bm.lockPixels();
66 bm.unlockPixels(); 66 bm.unlockPixels();
67 } 67 }
68 } 68 }
69 69
70 SkImage* SkImage::applyFilter(SkImageFilter* filter, SkIPoint* offset,
71 bool forceResultToOriginalSize) const {
72 if (!filter) {
73 return nullptr;
74 }
75
76 SkIPoint offsetStorage;
77 if (!offset) {
78 offset = &offsetStorage;
79 }
80 return as_IB(this)->onApplyFilter(filter, offset, forceResultToOriginalSize) ;
81 }
82
83 //////////////////////////////////////////////////////////////////////////////// ///////////////////
84
85 #include "SkImageFilter.h"
86 #include "SkBitmapDevice.h"
87
88 static SkIRect compute_fast_ibounds(SkImageFilter* filter, const SkIRect& srcBou nds) {
89 SkRect fastBounds;
90 fastBounds.set(srcBounds);
91 filter->computeFastBounds(fastBounds, &fastBounds);
92 return fastBounds.roundOut();
93 }
94
95 class SkRasterImageFilterProxy : public SkImageFilter::Proxy {
96 public:
97 SkBaseDevice* createDevice(int width, int height) override {
98 return SkBitmapDevice::Create(SkImageInfo::MakeN32Premul(width, height)) ;
99 }
100
101 bool filterImage(const SkImageFilter*, const SkBitmap&, const SkImageFilter: :Context&,
102 SkBitmap*, SkIPoint*) override {
103 return false;
104 }
105 };
106
107 SkImage* SkImage_Base::onApplyFilter(SkImageFilter* filter, SkIPoint* offsetResu lt,
108 bool forceResultToOriginalSize) const {
109 SkBitmap src;
110 if (!this->getROPixels(&src)) {
111 return nullptr;
112 }
113
114 const SkIRect srcBounds = SkIRect::MakeWH(this->width(), this->height());
115
116 if (forceResultToOriginalSize) {
117 const SkIRect clipBounds = srcBounds;
118 SkRasterImageFilterProxy proxy;
119 SkImageFilter::Context ctx(SkMatrix::I(), clipBounds, SkImageFilter::Cac he::Get());
120
121 SkBitmap dst;
122 if (filter->filterImage(&proxy, src, ctx, &dst, offsetResult)) {
123 dst.setImmutable();
124 return SkImage::NewFromBitmap(dst);
125 }
126 } else {
127 const SkIRect dstR = compute_fast_ibounds(filter, srcBounds);
128
129 SkImageInfo info = SkImageInfo::MakeN32Premul(dstR.width(), dstR.height( ));
130 SkAutoTUnref<SkSurface> surface(this->onNewSurface(info));
131
132 SkPaint paint;
133 paint.setImageFilter(filter);
134 surface->getCanvas()->drawImage(this, SkIntToScalar(-dstR.x()), SkIntToS calar(-dstR.y()),
135 &paint);
136
137 offsetResult->set(dstR.x(), dstR.y());
138 return surface->newImageSnapshot();
139 }
140 return nullptr;
141 }
142
143 //////////////////////////////////////////////////////////////////////////////// ///////////////////
144
70 SkShader* SkImage::newShader(SkShader::TileMode tileX, 145 SkShader* SkImage::newShader(SkShader::TileMode tileX,
71 SkShader::TileMode tileY, 146 SkShader::TileMode tileY,
72 const SkMatrix* localMatrix) const { 147 const SkMatrix* localMatrix) const {
73 return SkImageShader::Create(this, tileX, tileY, localMatrix); 148 return SkImageShader::Create(this, tileX, tileY, localMatrix);
74 } 149 }
75 150
76 SkData* SkImage::encode(SkImageEncoder::Type type, int quality) const { 151 SkData* SkImage::encode(SkImageEncoder::Type type, int quality) const {
77 SkBitmap bm; 152 SkBitmap bm;
78 if (as_IB(this)->getROPixels(&bm)) { 153 if (as_IB(this)->getROPixels(&bm)) {
79 return SkImageEncoder::EncodeData(bm, type, quality); 154 return SkImageEncoder::EncodeData(bm, type, quality);
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after
320 395
321 SkImage* SkImage::NewFromAdoptedTexture(GrContext*, const GrBackendTextureDesc&, SkAlphaType) { 396 SkImage* SkImage::NewFromAdoptedTexture(GrContext*, const GrBackendTextureDesc&, SkAlphaType) {
322 return nullptr; 397 return nullptr;
323 } 398 }
324 399
325 SkImage* SkImage::NewFromTextureCopy(GrContext*, const GrBackendTextureDesc&, Sk AlphaType) { 400 SkImage* SkImage::NewFromTextureCopy(GrContext*, const GrBackendTextureDesc&, Sk AlphaType) {
326 return nullptr; 401 return nullptr;
327 } 402 }
328 403
329 #endif 404 #endif
OLDNEW
« no previous file with comments | « src/gpu/SkGpuDevice.cpp ('k') | src/image/SkImage_Base.h » ('j') | src/image/SkImage_Gpu.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698