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" |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 case kIndex_8_SkColorType: { | 58 case kIndex_8_SkColorType: { |
59 SkPMColor colors[256]; | 59 SkPMColor colors[256]; |
60 for (int i = 0; i < 256; i++) { | 60 for (int i = 0; i < 256; i++) { |
61 if (configIndex & 1) { | 61 if (configIndex & 1) { |
62 colors[i] = SkPackARGB32(255-i, 0, 0, 255-i); | 62 colors[i] = SkPackARGB32(255-i, 0, 0, 255-i); |
63 } else { | 63 } else { |
64 colors[i] = SkPackARGB32(0xFF, i, 0, 255-i); | 64 colors[i] = SkPackARGB32(0xFF, i, 0, 255-i); |
65 } | 65 } |
66 } | 66 } |
67 SkColorTable* ctable = new SkColorTable(colors, 256); | 67 SkColorTable* ctable = new SkColorTable(colors, 256); |
68 bm->allocPixels(info, NULL, ctable); | 68 bm->allocPixels(info, nullptr, ctable); |
69 ctable->unref(); | 69 ctable->unref(); |
70 for (int y = 0; y < height; y++) { | 70 for (int y = 0; y < height; y++) { |
71 for (int x = 0; x < width; x++) { | 71 for (int x = 0; x < width; x++) { |
72 *bm->getAddr8(x, y) = SkGetPackedR32(*device.getAddr32(x, y)
); | 72 *bm->getAddr8(x, y) = SkGetPackedR32(*device.getAddr32(x, y)
); |
73 } | 73 } |
74 } | 74 } |
75 break; | 75 break; |
76 } | 76 } |
77 default: | 77 default: |
78 SkASSERT(0); | 78 SkASSERT(0); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 fBitmapCount = SK_ARRAY_COUNT(gColorTypes); | 115 fBitmapCount = SK_ARRAY_COUNT(gColorTypes); |
116 fBitmaps = new SkBitmap[fBitmapCount]; | 116 fBitmaps = new SkBitmap[fBitmapCount]; |
117 fEncodedPNGs = new SkAutoDataUnref[fBitmapCount]; | 117 fEncodedPNGs = new SkAutoDataUnref[fBitmapCount]; |
118 fEncodedJPEGs = new SkAutoDataUnref[fBitmapCount]; | 118 fEncodedJPEGs = new SkAutoDataUnref[fBitmapCount]; |
119 for (int i = 0; i < fBitmapCount; i++) { | 119 for (int i = 0; i < fBitmapCount; i++) { |
120 make_image(&fBitmaps[i], gColorTypes[i], i); | 120 make_image(&fBitmaps[i], gColorTypes[i], i); |
121 | 121 |
122 for (size_t j = 0; j < SK_ARRAY_COUNT(gTypes); j++) { | 122 for (size_t j = 0; j < SK_ARRAY_COUNT(gTypes); j++) { |
123 SkAutoTDelete<SkImageEncoder> codec( | 123 SkAutoTDelete<SkImageEncoder> codec( |
124 SkImageEncoder::Create(gTypes[j])); | 124 SkImageEncoder::Create(gTypes[j])); |
125 if (NULL == codec.get()) { | 125 if (nullptr == codec.get()) { |
126 SkDebugf("[%s:%d] failed to encode %s%s\n", | 126 SkDebugf("[%s:%d] failed to encode %s%s\n", |
127 __FILE__, __LINE__,gConfigLabels[i], gExt[j]); | 127 __FILE__, __LINE__,gConfigLabels[i], gExt[j]); |
128 continue; | 128 continue; |
129 } | 129 } |
130 SkAutoDataUnref data(codec->encodeData(fBitmaps[i], 100)); | 130 SkAutoDataUnref data(codec->encodeData(fBitmaps[i], 100)); |
131 if (NULL == data.get()) { | 131 if (nullptr == data.get()) { |
132 SkDebugf("[%s:%d] failed to encode %s%s\n", | 132 SkDebugf("[%s:%d] failed to encode %s%s\n", |
133 __FILE__, __LINE__,gConfigLabels[i], gExt[j]); | 133 __FILE__, __LINE__,gConfigLabels[i], gExt[j]); |
134 continue; | 134 continue; |
135 } | 135 } |
136 if (SkImageEncoder::kJPEG_Type == gTypes[j]) { | 136 if (SkImageEncoder::kJPEG_Type == gTypes[j]) { |
137 fEncodedJPEGs[i].reset(data.detach()); | 137 fEncodedJPEGs[i].reset(data.detach()); |
138 } else if (SkImageEncoder::kPNG_Type == gTypes[j]) { | 138 } else if (SkImageEncoder::kPNG_Type == gTypes[j]) { |
139 fEncodedPNGs[i].reset(data.detach()); | 139 fEncodedPNGs[i].reset(data.detach()); |
140 } | 140 } |
141 } | 141 } |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
179 paint); | 179 paint); |
180 y = paint.getTextSize(); | 180 y = paint.getTextSize(); |
181 | 181 |
182 canvas->drawBitmap(fBitmaps[i], x, y); | 182 canvas->drawBitmap(fBitmaps[i], x, y); |
183 | 183 |
184 SkScalar yy = y; | 184 SkScalar yy = y; |
185 for (size_t j = 0; j < SK_ARRAY_COUNT(gTypes); j++) { | 185 for (size_t j = 0; j < SK_ARRAY_COUNT(gTypes); j++) { |
186 yy += SkIntToScalar(fBitmaps[i].height() + 10); | 186 yy += SkIntToScalar(fBitmaps[i].height() + 10); |
187 | 187 |
188 SkBitmap bm; | 188 SkBitmap bm; |
189 SkData* encoded = NULL; | 189 SkData* encoded = nullptr; |
190 if (SkImageEncoder::kJPEG_Type == gTypes[j]) { | 190 if (SkImageEncoder::kJPEG_Type == gTypes[j]) { |
191 encoded = fEncodedJPEGs[i].get(); | 191 encoded = fEncodedJPEGs[i].get(); |
192 } else if (SkImageEncoder::kPNG_Type == gTypes[j]) { | 192 } else if (SkImageEncoder::kPNG_Type == gTypes[j]) { |
193 encoded = fEncodedPNGs[i].get(); | 193 encoded = fEncodedPNGs[i].get(); |
194 } | 194 } |
195 if (encoded) { | 195 if (encoded) { |
196 if (!SkInstallDiscardablePixelRef(encoded, &bm)) { | 196 if (!SkInstallDiscardablePixelRef(encoded, &bm)) { |
197 SkDebugf("[%s:%d] failed to decode %s%s\n", | 197 SkDebugf("[%s:%d] failed to decode %s%s\n", |
198 __FILE__, __LINE__,gConfigLabels[i], gExt[j]); | 198 __FILE__, __LINE__,gConfigLabels[i], gExt[j]); |
199 } | 199 } |
(...skipping 12 matching lines...) Expand all Loading... |
212 paint.setTextAlign(SkPaint::kLeft_Align); | 212 paint.setTextAlign(SkPaint::kLeft_Align); |
213 | 213 |
214 for (size_t j = 0; j < SK_ARRAY_COUNT(gExt); j++) { | 214 for (size_t j = 0; j < SK_ARRAY_COUNT(gExt); j++) { |
215 canvas->drawText(gExt[j], strlen(gExt[j]), x, y, paint); | 215 canvas->drawText(gExt[j], strlen(gExt[j]), x, y, paint); |
216 y += SkIntToScalar(fBitmaps[0].height() + SPACER); | 216 y += SkIntToScalar(fBitmaps[0].height() + SPACER); |
217 } | 217 } |
218 } | 218 } |
219 | 219 |
220 virtual SkView::Click* onFindClickHandler(SkScalar x, SkScalar y, | 220 virtual SkView::Click* onFindClickHandler(SkScalar x, SkScalar y, |
221 unsigned modi) { | 221 unsigned modi) { |
222 this->inval(NULL); | 222 this->inval(nullptr); |
223 return this->INHERITED::onFindClickHandler(x, y, modi); | 223 return this->INHERITED::onFindClickHandler(x, y, modi); |
224 } | 224 } |
225 | 225 |
226 private: | 226 private: |
227 typedef SampleView INHERITED; | 227 typedef SampleView INHERITED; |
228 }; | 228 }; |
229 | 229 |
230 ////////////////////////////////////////////////////////////////////////////// | 230 ////////////////////////////////////////////////////////////////////////////// |
231 | 231 |
232 static SkView* MyFactory() { return new EncodeView; } | 232 static SkView* MyFactory() { return new EncodeView; } |
233 static SkViewRegister reg(MyFactory); | 233 static SkViewRegister reg(MyFactory); |
OLD | NEW |