OLD | NEW |
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 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
171 surface->getCanvas()->scale(newWidth / src.width(), newHeight / src.height()
); | 171 surface->getCanvas()->scale(newWidth / src.width(), newHeight / src.height()
); |
172 surface->getCanvas()->translate(-src.x(), -src.y()); | 172 surface->getCanvas()->translate(-src.x(), -src.y()); |
173 | 173 |
174 SkPaint paint; | 174 SkPaint paint; |
175 paint.setXfermodeMode(SkXfermode::kSrc_Mode); | 175 paint.setXfermodeMode(SkXfermode::kSrc_Mode); |
176 paint.setFilterQuality(quality); | 176 paint.setFilterQuality(quality); |
177 surface->getCanvas()->drawImage(this, 0, 0, &paint); | 177 surface->getCanvas()->drawImage(this, 0, 0, &paint); |
178 return surface->newImageSnapshot(); | 178 return surface->newImageSnapshot(); |
179 } | 179 } |
180 | 180 |
| 181 inline static bool read_image_as_n32_bitmap(const SkImage* image, SkBitmap* bitm
ap) { |
| 182 SkBitmap tmp; |
| 183 if (!as_IB(image)->getROPixels(&tmp)) { |
| 184 return false; |
| 185 } |
| 186 if (tmp.colorType() != kN32_SkColorType) { |
| 187 return false; |
| 188 } |
181 | 189 |
| 190 tmp.lockPixels(); |
| 191 bitmap->swap(tmp); |
| 192 return true; |
| 193 } |
| 194 |
| 195 SkAutoAdoptImageAsN32Bitmap::SkAutoAdoptImageAsN32Bitmap(SkAutoTUnref<const SkIm
age>& image, |
| 196 SkBitmap* bitmap) |
| 197 : fBitmap(NULL) { |
| 198 if (read_image_as_n32_bitmap(image, bitmap)) { |
| 199 fBitmap = bitmap; |
| 200 image.reset(NULL); |
| 201 } |
| 202 } |
| 203 |
| 204 SkAutoImageAsN32Bitmap::SkAutoImageAsN32Bitmap(const SkImage* image, SkBitmap* b
itmap) |
| 205 : fBitmap(NULL) { |
| 206 if (read_image_as_n32_bitmap(image, bitmap)) { |
| 207 fBitmap = bitmap; |
| 208 } |
| 209 } |
| 210 |
| 211 |
| 212 |
OLD | NEW |