namespace skiagm {
static void make_bm(SkBitmap* bm) {
- const SkColor colors[] = {
+ const SkColor colors[4] = {
SK_ColorRED, SK_ColorGREEN,
SK_ColorBLUE, SK_ColorWHITE
};
- SkColorTable* ctable = new SkColorTable(colors, 4);
+ SkPMColor colorsPM[4];
+ for (size_t i = 0; i < SK_ARRAY_COUNT(colors); ++i) {
+ colorsPM[i] = SkPreMultiplyColor(colors[i]);
+ }
+ SkColorTable* ctable = new SkColorTable(colorsPM, 4);
+
bm->setConfig(SkBitmap::kIndex8_Config, 2, 2);
bm->allocPixels(ctable);
ctable->unref();
-
+
*bm->getAddr8(0, 0) = 0;
*bm->getAddr8(1, 0) = 1;
*bm->getAddr8(0, 1) = 2;
canvas->translate(SkIntToScalar(48), 0);
canvas->scale(SkIntToScalar(scale), SkIntToScalar(scale));
-
+
x += draw_set(canvas, bm, 0, &paint);
paint.reset();
paint.setAlpha(0x80);
SkScalar x = SkIntToScalar(10);
SkScalar y = SkIntToScalar(10);
-
+
canvas->translate(x, y);
y = draw_row(canvas, fBM8);
canvas->translate(0, y);
canvas->translate(0, y);
draw_row(canvas, fBM32);
}
-
+
private:
typedef GM INHERITED;
};
SkBitmap sprite;
sprite.setConfig(SkBitmap::kARGB_8888_Config, 4, 4, 4*sizeof(SkColor));
- SkColor spriteData[16] = {
+ const SkColor spriteData[16] = {
SK_ColorBLACK, SK_ColorCYAN, SK_ColorMAGENTA, SK_ColorYELLOW,
SK_ColorBLACK, SK_ColorWHITE, SK_ColorBLACK, SK_ColorRED,
SK_ColorGREEN, SK_ColorBLACK, SK_ColorWHITE, SK_ColorBLUE,
SK_ColorYELLOW, SK_ColorMAGENTA, SK_ColorCYAN, SK_ColorBLACK
};
- sprite.setPixels(spriteData);
+ SkPMColor spriteDataPM[16];
+ for (size_t i = 0; i < SK_ARRAY_COUNT(spriteData); ++i) {
+ spriteDataPM[i] = SkPreMultiplyColor(spriteData[i]);
+ }
+ sprite.setPixels(spriteDataPM);
// We draw a magnified subrect of the sprite
// sample interpolation may cause color bleeding around edges