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

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

Issue 821083002: add newImage API (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: add gm Created 5 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
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 "SkCanvas.h" 9 #include "SkCanvas.h"
10 #include "SkImageGenerator.h" 10 #include "SkImageGenerator.h"
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 } 87 }
88 return as_IB(this)->onNewSurface(info, *props); 88 return as_IB(this)->onNewSurface(info, *props);
89 } 89 }
90 90
91 const char* SkImage::toString(SkString* str) const { 91 const char* SkImage::toString(SkString* str) const {
92 str->appendf("image: (id:%d (%d, %d) %s)", this->uniqueID(), this->width(), this->height(), 92 str->appendf("image: (id:%d (%d, %d) %s)", this->uniqueID(), this->width(), this->height(),
93 this->isOpaque() ? "opaque" : ""); 93 this->isOpaque() ? "opaque" : "");
94 return str->c_str(); 94 return str->c_str();
95 } 95 }
96 96
97 SkImage* SkImage::newImage(int newWidth, int newHeight, const SkIRect* subset,
98 SkFilterQuality quality) const {
99 if (newWidth < 0 || newHeight < 0) {
100 return NULL;
101 }
102 if (subset && !SkIRect::MakeWH(this->width(), this->height()).contains(*subs et)) {
103 return NULL;
104 }
105
106 if (NULL == subset && this->width() == newWidth && this->height() == newHeig ht) {
107 return SkRef(const_cast<SkImage*>(this));
108 }
109
110 return as_IB(this)->onNewImage(newWidth, newHeight, subset, quality);
111 }
112
97 /////////////////////////////////////////////////////////////////////////////// 113 ///////////////////////////////////////////////////////////////////////////////
98 114
99 static bool raster_canvas_supports(const SkImageInfo& info) { 115 static bool raster_canvas_supports(const SkImageInfo& info) {
100 switch (info.colorType()) { 116 switch (info.colorType()) {
101 case kN32_SkColorType: 117 case kN32_SkColorType:
102 return kUnpremul_SkAlphaType != info.alphaType(); 118 return kUnpremul_SkAlphaType != info.alphaType();
103 case kRGB_565_SkColorType: 119 case kRGB_565_SkColorType:
104 return true; 120 return true;
105 case kAlpha_8_SkColorType: 121 case kAlpha_8_SkColorType:
106 return true; 122 return true;
(...skipping 12 matching lines...) Expand all
119 SkBitmap bm; 135 SkBitmap bm;
120 bm.installPixels(dstInfo, dstPixels, dstRowBytes); 136 bm.installPixels(dstInfo, dstPixels, dstRowBytes);
121 SkCanvas canvas(bm); 137 SkCanvas canvas(bm);
122 138
123 SkPaint paint; 139 SkPaint paint;
124 paint.setXfermodeMode(SkXfermode::kSrc_Mode); 140 paint.setXfermodeMode(SkXfermode::kSrc_Mode);
125 canvas.drawImage(this, -SkIntToScalar(srcX), -SkIntToScalar(srcY), &paint); 141 canvas.drawImage(this, -SkIntToScalar(srcX), -SkIntToScalar(srcY), &paint);
126 142
127 return true; 143 return true;
128 } 144 }
145
146 SkImage* SkImage_Base::onNewImage(int newWidth, int newHeight, const SkIRect* su bset,
147 SkFilterQuality quality) const {
148 const bool opaque = this->isOpaque();
149 const SkImageInfo info = SkImageInfo::Make(newWidth, newHeight, kN32_SkColor Type,
scroggo 2015/01/21 22:24:57 As discussed in person, we don't actually know the
150 opaque ? kOpaque_SkAlphaType : kP remul_SkAlphaType);
151 SkAutoTUnref<SkSurface> surface(this->newSurface(info, NULL));
152 if (!surface.get()) {
153 return NULL;
154 }
155
156 SkRect src;
157 if (subset) {
158 src.set(*subset);
159 } else {
160 src = SkRect::MakeWH(SkIntToScalar(this->width()), SkIntToScalar(this->h eight()));
161 }
162
163 surface->getCanvas()->scale(newWidth / src.width(), newHeight / src.height() );
164 surface->getCanvas()->translate(-src.x(), -src.y());
165
166 SkPaint paint;
167 paint.setXfermodeMode(SkXfermode::kSrc_Mode);
168 paint.setFilterQuality(quality);
169 surface->getCanvas()->drawImage(this, 0, 0, &paint);
170 return surface->newImageSnapshot();
171 }
172
173
OLDNEW
« include/core/SkImage.h ('K') | « src/core/SkPaint.cpp ('k') | src/image/SkImage_Base.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698