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

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 SkFilterQuality option 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 "SkImagePriv.h" 10 #include "SkImagePriv.h"
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 return NULL; 71 return NULL;
72 } 72 }
73 73
74 SkSurface* SkImage::newSurface(const SkImageInfo& info, const SkSurfaceProps* pr ops) const { 74 SkSurface* SkImage::newSurface(const SkImageInfo& info, const SkSurfaceProps* pr ops) const {
75 if (NULL == props) { 75 if (NULL == props) {
76 props = &as_IB(this)->props(); 76 props = &as_IB(this)->props();
77 } 77 }
78 return as_IB(this)->onNewSurface(info, *props); 78 return as_IB(this)->onNewSurface(info, *props);
79 } 79 }
80 80
81 SkImage* SkImage::newImage(int newWidth, int newHeight, const SkIRect* subset,
82 SkFilterQuality quality) const {
83 if (newWidth < 0 || newHeight < 0) {
84 return NULL;
85 }
86 if (subset && !SkIRect::MakeWH(this->width(), this->height()).contains(*subs et)) {
87 return NULL;
88 }
89
90 if (NULL == subset && this->width() == newWidth && this->height() == newHeig ht) {
91 return SkRef(const_cast<SkImage*>(this));
92 }
93
94 return as_IB(this)->onNewImage(newWidth, newHeight, subset, quality);
95 }
96
81 /////////////////////////////////////////////////////////////////////////////// 97 ///////////////////////////////////////////////////////////////////////////////
82 98
83 static bool raster_canvas_supports(const SkImageInfo& info) { 99 static bool raster_canvas_supports(const SkImageInfo& info) {
84 switch (info.colorType()) { 100 switch (info.colorType()) {
85 case kN32_SkColorType: 101 case kN32_SkColorType:
86 return kUnpremul_SkAlphaType != info.alphaType(); 102 return kUnpremul_SkAlphaType != info.alphaType();
87 case kRGB_565_SkColorType: 103 case kRGB_565_SkColorType:
88 return true; 104 return true;
89 case kAlpha_8_SkColorType: 105 case kAlpha_8_SkColorType:
90 return true; 106 return true;
(...skipping 12 matching lines...) Expand all
103 SkBitmap bm; 119 SkBitmap bm;
104 bm.installPixels(dstInfo, dstPixels, dstRowBytes); 120 bm.installPixels(dstInfo, dstPixels, dstRowBytes);
105 SkCanvas canvas(bm); 121 SkCanvas canvas(bm);
106 122
107 SkPaint paint; 123 SkPaint paint;
108 paint.setXfermodeMode(SkXfermode::kSrc_Mode); 124 paint.setXfermodeMode(SkXfermode::kSrc_Mode);
109 canvas.drawImage(this, -SkIntToScalar(srcX), -SkIntToScalar(srcY), &paint); 125 canvas.drawImage(this, -SkIntToScalar(srcX), -SkIntToScalar(srcY), &paint);
110 126
111 return true; 127 return true;
112 } 128 }
129
130 SkImage* SkImage_Base::onNewImage(int newWidth, int newHeight, const SkIRect* su bset,
131 SkFilterQuality quality) const {
132 const bool opaque = this->isOpaque();
133 const SkImageInfo info = SkImageInfo::Make(newWidth, newHeight, kN32_SkColor Type,
134 opaque ? kOpaque_SkAlphaType : kP remul_SkAlphaType);
scroggo 2015/01/05 16:15:33 If this image is unpremul, does this work properly
reed1 2015/01/05 21:58:14 This is the "base" implementation, which may chang
scroggo 2015/01/05 22:12:02 +1 to the more optimal subclass overrides. In the
reed1 2015/01/20 22:23:08 unpremul : good point, have to think about that ca
135 SkAutoTUnref<SkSurface> surface(this->newSurface(info, NULL));
136 if (!surface.get()) {
137 return NULL;
138 }
139
140 SkRect src;
141 if (subset) {
142 src.set(*subset);
143 } else {
144 src = SkRect::MakeWH(SkIntToScalar(this->width()), SkIntToScalar(this->h eight()));
145 }
146
147 surface->getCanvas()->scale(newWidth / src.width(), newHeight / src.height() );
148 surface->getCanvas()->translate(-src.x(), -src.y());
149
150 SkPaint paint;
151 paint.setXfermodeMode(SkXfermode::kSrc_Mode);
152 paint.setFilterQuality(quality);
153 surface->getCanvas()->drawImage(this, 0, 0, &paint);
154 return surface->newImageSnapshot();
155 }
156
157
OLDNEW
« include/core/SkPaint.h ('K') | « include/core/SkPaint.h ('k') | src/image/SkImage_Base.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698