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 "GrSurface.h" | 8 #include "GrSurface.h" |
9 | 9 |
10 #include "SkBitmap.h" | 10 #include "SkBitmap.h" |
11 #include "SkGr.h" | 11 #include "SkGr.h" |
12 #include "SkImageEncoder.h" | 12 #include "SkImageEncoder.h" |
13 #include <stdio.h> | 13 #include <stdio.h> |
14 | 14 |
15 SkImageInfo GrSurface::info() const { | 15 SkImageInfo GrSurface::info() const { |
16 SkImageInfo info; | 16 SkColorType colorType; |
17 if (!GrPixelConfig2ColorType(this->config(), &info.fColorType)) { | 17 if (!GrPixelConfig2ColorType(this->config(), &colorType)) { |
18 sk_throw(); | 18 sk_throw(); |
19 } | 19 } |
20 info.fWidth = this->width(); | 20 return SkImageInfo::Make(this->width(), this->height(), colorType, kPremul_S
kAlphaType); |
21 info.fHeight = this->height(); | |
22 info.fAlphaType = kPremul_SkAlphaType; | |
23 return info; | |
24 } | 21 } |
25 | 22 |
26 bool GrSurface::savePixels(const char* filename) { | 23 bool GrSurface::savePixels(const char* filename) { |
27 SkBitmap bm; | 24 SkBitmap bm; |
28 if (!bm.tryAllocPixels(SkImageInfo::MakeN32Premul(this->width(), this->heigh
t()))) { | 25 if (!bm.tryAllocPixels(SkImageInfo::MakeN32Premul(this->width(), this->heigh
t()))) { |
29 return false; | 26 return false; |
30 } | 27 } |
31 | 28 |
32 bool result = readPixels(0, 0, this->width(), this->height(), kSkia8888_GrPi
xelConfig, | 29 bool result = readPixels(0, 0, this->width(), this->height(), kSkia8888_GrPi
xelConfig, |
33 bm.getPixels()); | 30 bm.getPixels()); |
34 if (!result) { | 31 if (!result) { |
35 SkDebugf("------ failed to read pixels for %s\n", filename); | 32 SkDebugf("------ failed to read pixels for %s\n", filename); |
36 return false; | 33 return false; |
37 } | 34 } |
38 | 35 |
39 // remove any previous version of this file | 36 // remove any previous version of this file |
40 remove(filename); | 37 remove(filename); |
41 | 38 |
42 if (!SkImageEncoder::EncodeFile(filename, bm, SkImageEncoder::kPNG_Type, 100
)) { | 39 if (!SkImageEncoder::EncodeFile(filename, bm, SkImageEncoder::kPNG_Type, 100
)) { |
43 SkDebugf("------ failed to encode %s\n", filename); | 40 SkDebugf("------ failed to encode %s\n", filename); |
44 remove(filename); // remove any partial file | 41 remove(filename); // remove any partial file |
45 return false; | 42 return false; |
46 } | 43 } |
47 | 44 |
48 return true; | 45 return true; |
49 } | 46 } |
OLD | NEW |