| Index: samplecode/SampleEncode.cpp
|
| diff --git a/samplecode/SampleEncode.cpp b/samplecode/SampleEncode.cpp
|
| index 7af47a697ec6a21d4092b4a766fbbd030d976bde..4769fbb0a87f0e2d97eb8be1f0db2c87e57ca0a9 100644
|
| --- a/samplecode/SampleEncode.cpp
|
| +++ b/samplecode/SampleEncode.cpp
|
| @@ -26,14 +26,13 @@
|
|
|
| #include "SkStream.h"
|
|
|
| -static void make_image(SkBitmap* bm, SkBitmap::Config config, int configIndex) {
|
| +static void make_image(SkBitmap* bm, SkColorType ct, int configIndex) {
|
| const int width = 98;
|
| const int height = 100;
|
| - SkBitmap device;
|
| -
|
| - device.setConfig(SkBitmap::kARGB_8888_Config, width, height);
|
| - device.allocPixels();
|
| + const SkImageInfo info = SkImageInfo::Make(width, height, ct, kPremul_SkAlphaType);
|
|
|
| + SkBitmap device;
|
| + device.allocN32Pixels(width, height);
|
| SkCanvas canvas(device);
|
| SkPaint paint;
|
|
|
| @@ -43,13 +42,12 @@ static void make_image(SkBitmap* bm, SkBitmap::Config config, int configIndex) {
|
| canvas.drawCircle(SkIntToScalar(width)/2, SkIntToScalar(height)/2,
|
| SkIntToScalar(width)/2, paint);
|
|
|
| - bm->setConfig(config, width, height);
|
| - switch (config) {
|
| - case SkBitmap::kARGB_8888_Config:
|
| + switch (ct) {
|
| + case kPMColor_SkColorType:
|
| bm->swap(device);
|
| break;
|
| - case SkBitmap::kRGB_565_Config: {
|
| - bm->allocPixels();
|
| + case kRGB_565_SkColorType: {
|
| + bm->allocPixels(info);
|
| for (int y = 0; y < height; y++) {
|
| for (int x = 0; x < width; x++) {
|
| *bm->getAddr16(x, y) = SkPixel32ToPixel16(*device.getAddr32(x, y));
|
| @@ -57,7 +55,7 @@ static void make_image(SkBitmap* bm, SkBitmap::Config config, int configIndex) {
|
| }
|
| break;
|
| }
|
| - case SkBitmap::kIndex8_Config: {
|
| + case kIndex_8_SkColorType: {
|
| SkPMColor colors[256];
|
| for (int i = 0; i < 256; i++) {
|
| if (configIndex & 1) {
|
| @@ -67,9 +65,8 @@ static void make_image(SkBitmap* bm, SkBitmap::Config config, int configIndex) {
|
| }
|
| }
|
| SkColorTable* ctable = new SkColorTable(colors, 256);
|
| - bm->allocPixels(ctable);
|
| + bm->allocPixels(info, NULL, ctable);
|
| ctable->unref();
|
| -
|
| for (int y = 0; y < height; y++) {
|
| for (int x = 0; x < width; x++) {
|
| *bm->getAddr8(x, y) = SkGetPackedR32(*device.getAddr32(x, y));
|
| @@ -78,16 +75,16 @@ static void make_image(SkBitmap* bm, SkBitmap::Config config, int configIndex) {
|
| break;
|
| }
|
| default:
|
| - break;
|
| + SkASSERT(0);
|
| }
|
| }
|
|
|
| // configs to build the original bitmap in. Can be at most these 3
|
| -static const SkBitmap::Config gConfigs[] = {
|
| - SkBitmap::kARGB_8888_Config,
|
| - SkBitmap::kRGB_565_Config,
|
| - SkBitmap::kIndex8_Config, // opaque
|
| - SkBitmap::kIndex8_Config // alpha
|
| +static const SkColorType gColorTypes[] = {
|
| + kPMColor_SkColorType,
|
| + kRGB_565_SkColorType,
|
| + kIndex_8_SkColorType, // opaque
|
| + kIndex_8_SkColorType // alpha
|
| };
|
|
|
| static const char* const gConfigLabels[] = {
|
| @@ -115,13 +112,12 @@ public:
|
| int fBitmapCount;
|
|
|
| EncodeView() {
|
| - #if 1
|
| - fBitmapCount = SK_ARRAY_COUNT(gConfigs);
|
| + fBitmapCount = SK_ARRAY_COUNT(gColorTypes);
|
| fBitmaps = new SkBitmap[fBitmapCount];
|
| fEncodedPNGs = new SkAutoDataUnref[fBitmapCount];
|
| fEncodedJPEGs = new SkAutoDataUnref[fBitmapCount];
|
| for (int i = 0; i < fBitmapCount; i++) {
|
| - make_image(&fBitmaps[i], gConfigs[i], i);
|
| + make_image(&fBitmaps[i], gColorTypes[i], i);
|
|
|
| for (size_t j = 0; j < SK_ARRAY_COUNT(gTypes); j++) {
|
| SkAutoTDelete<SkImageEncoder> codec(
|
| @@ -144,10 +140,6 @@ public:
|
| }
|
| }
|
| }
|
| - #else
|
| - fBitmaps = NULL;
|
| - fBitmapCount = 0;
|
| - #endif
|
| this->setBGColor(0xFFDDDDDD);
|
| }
|
|
|
|
|