OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2011 Google Inc. | 3 * Copyright 2011 Google Inc. |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 #include "SampleCode.h" | 8 #include "SampleCode.h" |
9 #include "SkView.h" | 9 #include "SkView.h" |
10 #include "SkCanvas.h" | 10 #include "SkCanvas.h" |
11 #include "SkData.h" | 11 #include "SkData.h" |
| 12 #include "SkEncodedFormat.h" |
12 #include "SkImageGenerator.h" | 13 #include "SkImageGenerator.h" |
13 #include "SkGradientShader.h" | 14 #include "SkGradientShader.h" |
14 #include "SkGraphics.h" | 15 #include "SkGraphics.h" |
15 #include "SkImageDecoder.h" | 16 #include "SkImageDecoder.h" |
16 #include "SkImageEncoder.h" | 17 #include "SkImageEncoder.h" |
17 #include "SkPath.h" | 18 #include "SkPath.h" |
18 #include "SkRegion.h" | 19 #include "SkRegion.h" |
19 #include "SkShader.h" | 20 #include "SkShader.h" |
20 #include "SkUtils.h" | 21 #include "SkUtils.h" |
21 #include "SkXfermode.h" | 22 #include "SkXfermode.h" |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 kN32_SkColorType, | 85 kN32_SkColorType, |
85 kRGB_565_SkColorType, | 86 kRGB_565_SkColorType, |
86 kIndex_8_SkColorType, // opaque | 87 kIndex_8_SkColorType, // opaque |
87 kIndex_8_SkColorType // alpha | 88 kIndex_8_SkColorType // alpha |
88 }; | 89 }; |
89 | 90 |
90 static const char* const gConfigLabels[] = { | 91 static const char* const gConfigLabels[] = { |
91 "8888", "565", "Index8", "Index8 alpha" | 92 "8888", "565", "Index8", "Index8 alpha" |
92 }; | 93 }; |
93 | 94 |
94 // types to encode into. Can be at most these 3. Must match up with gExt[] | 95 // types to encode into. Can be at most these 2. Must match up with gExt[] |
95 static const SkImageEncoder::Type gTypes[] = { | 96 static const SkEncodedFormat gTypes[] = { |
96 SkImageEncoder::kJPEG_Type, | 97 kJPEG_SkEncodedFormat, |
97 SkImageEncoder::kPNG_Type | 98 kPNG_SkEncodedFormat, |
98 }; | 99 }; |
99 | 100 |
100 // must match up with gTypes[] | 101 // must match up with gTypes[] |
101 static const char* const gExt[] = { | 102 static const char* const gExt[] = { |
102 ".jpg", ".png" | 103 ".jpg", ".png" |
103 }; | 104 }; |
104 | 105 |
105 #include <sys/stat.h> | 106 #include <sys/stat.h> |
106 | 107 |
107 class EncodeView : public SampleView { | 108 class EncodeView : public SampleView { |
(...skipping 18 matching lines...) Expand all Loading... |
126 SkDebugf("[%s:%d] failed to encode %s%s\n", | 127 SkDebugf("[%s:%d] failed to encode %s%s\n", |
127 __FILE__, __LINE__,gConfigLabels[i], gExt[j]); | 128 __FILE__, __LINE__,gConfigLabels[i], gExt[j]); |
128 continue; | 129 continue; |
129 } | 130 } |
130 SkAutoDataUnref data(codec->encodeData(fBitmaps[i], 100)); | 131 SkAutoDataUnref data(codec->encodeData(fBitmaps[i], 100)); |
131 if (NULL == data.get()) { | 132 if (NULL == data.get()) { |
132 SkDebugf("[%s:%d] failed to encode %s%s\n", | 133 SkDebugf("[%s:%d] failed to encode %s%s\n", |
133 __FILE__, __LINE__,gConfigLabels[i], gExt[j]); | 134 __FILE__, __LINE__,gConfigLabels[i], gExt[j]); |
134 continue; | 135 continue; |
135 } | 136 } |
136 if (SkImageEncoder::kJPEG_Type == gTypes[j]) { | 137 if (kJPEG_SkEncodedFormat == gTypes[j]) { |
137 fEncodedJPEGs[i].reset(data.detach()); | 138 fEncodedJPEGs[i].reset(data.detach()); |
138 } else if (SkImageEncoder::kPNG_Type == gTypes[j]) { | 139 } else if (kPNG_SkEncodedFormat == gTypes[j]) { |
139 fEncodedPNGs[i].reset(data.detach()); | 140 fEncodedPNGs[i].reset(data.detach()); |
140 } | 141 } |
141 } | 142 } |
142 } | 143 } |
143 this->setBGColor(0xFFDDDDDD); | 144 this->setBGColor(0xFFDDDDDD); |
144 } | 145 } |
145 | 146 |
146 virtual ~EncodeView() { | 147 virtual ~EncodeView() { |
147 delete[] fBitmaps; | 148 delete[] fBitmaps; |
148 delete[] fEncodedPNGs; | 149 delete[] fEncodedPNGs; |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
180 y = paint.getTextSize(); | 181 y = paint.getTextSize(); |
181 | 182 |
182 canvas->drawBitmap(fBitmaps[i], x, y); | 183 canvas->drawBitmap(fBitmaps[i], x, y); |
183 | 184 |
184 SkScalar yy = y; | 185 SkScalar yy = y; |
185 for (size_t j = 0; j < SK_ARRAY_COUNT(gTypes); j++) { | 186 for (size_t j = 0; j < SK_ARRAY_COUNT(gTypes); j++) { |
186 yy += SkIntToScalar(fBitmaps[i].height() + 10); | 187 yy += SkIntToScalar(fBitmaps[i].height() + 10); |
187 | 188 |
188 SkBitmap bm; | 189 SkBitmap bm; |
189 SkData* encoded = NULL; | 190 SkData* encoded = NULL; |
190 if (SkImageEncoder::kJPEG_Type == gTypes[j]) { | 191 if (kJPEG_SkEncodedFormat == gTypes[j]) { |
191 encoded = fEncodedJPEGs[i].get(); | 192 encoded = fEncodedJPEGs[i].get(); |
192 } else if (SkImageEncoder::kPNG_Type == gTypes[j]) { | 193 } else if (kPNG_SkEncodedFormat == gTypes[j]) { |
193 encoded = fEncodedPNGs[i].get(); | 194 encoded = fEncodedPNGs[i].get(); |
194 } | 195 } |
195 if (encoded) { | 196 if (encoded) { |
196 if (!SkInstallDiscardablePixelRef(encoded, &bm)) { | 197 if (!SkInstallDiscardablePixelRef(encoded, &bm)) { |
197 SkDebugf("[%s:%d] failed to decode %s%s\n", | 198 SkDebugf("[%s:%d] failed to decode %s%s\n", |
198 __FILE__, __LINE__,gConfigLabels[i], gExt[j]); | 199 __FILE__, __LINE__,gConfigLabels[i], gExt[j]); |
199 } | 200 } |
200 canvas->drawBitmap(bm, x, yy); | 201 canvas->drawBitmap(bm, x, yy); |
201 } | 202 } |
202 } | 203 } |
(...skipping 21 matching lines...) Expand all Loading... |
224 } | 225 } |
225 | 226 |
226 private: | 227 private: |
227 typedef SampleView INHERITED; | 228 typedef SampleView INHERITED; |
228 }; | 229 }; |
229 | 230 |
230 ////////////////////////////////////////////////////////////////////////////// | 231 ////////////////////////////////////////////////////////////////////////////// |
231 | 232 |
232 static SkView* MyFactory() { return new EncodeView; } | 233 static SkView* MyFactory() { return new EncodeView; } |
233 static SkViewRegister reg(MyFactory); | 234 static SkViewRegister reg(MyFactory); |
OLD | NEW |