aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--gm/bitmappremul.cpp131
-rw-r--r--gyp/gmslides.gypi1
-rw-r--r--src/pdf/SkPDFImage.cpp88
3 files changed, 20 insertions, 200 deletions
diff --git a/gm/bitmappremul.cpp b/gm/bitmappremul.cpp
deleted file mode 100644
index 9f0c1e8cb9..0000000000
--- a/gm/bitmappremul.cpp
+++ /dev/null
@@ -1,131 +0,0 @@
-/*
- * Copyright 2013 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-#include "gm.h"
-#include "SkBitmap.h"
-#include "SkCanvas.h"
-#include "SkColorPriv.h"
-
-/**
- * This GM checks that bitmap pixels are unpremultiplied before being exported
- * to other formats. If unpremultiplication is implemented properly, this
- * GM should come out completely white. If not, this GM looks like a row of two
- * greyscale gradients above a row of grey lines.
- * This tests both the ARGB4444 and ARGB8888 bitmap configurations.
- */
-
-static const int SLIDE_SIZE = 256;
-static const int PIXEL_SIZE_8888 = SLIDE_SIZE / 256;
-static const int PIXEL_SIZE_4444 = SLIDE_SIZE / 16;
-
-static SkBitmap init_bitmap(SkBitmap::Config config) {
- SkBitmap bitmap;
- bitmap.setConfig(config, SLIDE_SIZE, SLIDE_SIZE);
- bitmap.allocPixels();
- bitmap.eraseColor(SK_ColorWHITE);
- return bitmap;
-}
-
-static SkBitmap make_argb8888_gradient() {
- SkBitmap bitmap = init_bitmap(SkBitmap::kARGB_8888_Config);
- uint8_t rowColor = 0;
- for (int y = 0; y < SLIDE_SIZE; y++) {
- uint32_t* dst = bitmap.getAddr32(0, y);
- for (int x = 0; x < SLIDE_SIZE; x++) {
- dst[x] = SkPackARGB32(rowColor, rowColor,
- rowColor, rowColor);
- }
- if (y % PIXEL_SIZE_8888 == PIXEL_SIZE_8888 - 1) {
- rowColor++;
- }
- }
- return bitmap;
-}
-
-static SkBitmap make_argb4444_gradient() {
- SkBitmap bitmap = init_bitmap(SkBitmap::kARGB_4444_Config);
- uint8_t rowColor = 0;
- for (int y = 0; y < SLIDE_SIZE; y++) {
- uint16_t* dst = bitmap.getAddr16(0, y);
- for (int x = 0; x < SLIDE_SIZE; x++) {
- dst[x] = SkPackARGB4444(rowColor, rowColor,
- rowColor, rowColor);
- }
- if (y % PIXEL_SIZE_4444 == PIXEL_SIZE_4444 - 1) {
- rowColor++;
- }
- }
- return bitmap;
-}
-
-static SkBitmap make_argb8888_stripes() {
- SkBitmap bitmap = init_bitmap(SkBitmap::kARGB_8888_Config);
- uint8_t rowColor = 0;
- for (int y = 0; y < SLIDE_SIZE; y++) {
- uint32_t* dst = bitmap.getAddr32(0, y);
- for (int x = 0; x < SLIDE_SIZE; x++) {
- dst[x] = SkPackARGB32(rowColor, rowColor,
- rowColor, rowColor);
- }
- if (rowColor == 0) {
- rowColor = 255;
- } else {
- rowColor = 0;
- }
- }
- return bitmap;
-}
-
-static SkBitmap make_argb4444_stripes() {
- SkBitmap bitmap = init_bitmap(SkBitmap::kARGB_4444_Config);
- uint8_t rowColor = 0;;
- for (int y = 0; y < SLIDE_SIZE; y++) {
- uint16_t* dst = bitmap.getAddr16(0, y);
- for (int x = 0; x < SLIDE_SIZE; x++) {
- dst[x] = SkPackARGB4444(rowColor, rowColor,
- rowColor, rowColor);
- }
- if (rowColor == 0) {
- rowColor = 15;
- } else {
- rowColor = 0;
- }
- }
- return bitmap;
-}
-
-namespace skiagm {
-
-class BitmapPremulGM : public GM {
-public:
- BitmapPremulGM() {
- this->setBGColor(0xFFFFFFFF);
- }
-
-protected:
- SkString onShortName() SK_OVERRIDE {
- return SkString("bitmap_premul");
- }
-
- virtual SkISize onISize() SK_OVERRIDE {
- return SkISize::Make(512, 512);
- }
-
- virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE {
- SkScalar slideSize = SLIDE_SIZE;
- canvas->drawBitmap(make_argb8888_gradient(), 0, 0);
- canvas->drawBitmap(make_argb4444_gradient(), slideSize, 0);
- canvas->drawBitmap(make_argb8888_stripes(), 0, slideSize);
- canvas->drawBitmap(make_argb4444_stripes(), slideSize, slideSize);
- }
-
-private:
- typedef GM INHERITED;
-};
-
-DEF_GM( return new BitmapPremulGM; )
-}
diff --git a/gyp/gmslides.gypi b/gyp/gmslides.gypi
index 524d63a2a7..bc0fc65415 100644
--- a/gyp/gmslides.gypi
+++ b/gyp/gmslides.gypi
@@ -12,7 +12,6 @@
'../gm/bitmapcopy.cpp',
'../gm/bitmapmatrix.cpp',
'../gm/bitmapfilters.cpp',
- '../gm/bitmappremul.cpp',
'../gm/bitmaprect.cpp',
'../gm/bitmaprecttest.cpp',
'../gm/bitmapscroll.cpp',
diff --git a/src/pdf/SkPDFImage.cpp b/src/pdf/SkPDFImage.cpp
index a4872e25f8..a5cb4c20d1 100644
--- a/src/pdf/SkPDFImage.cpp
+++ b/src/pdf/SkPDFImage.cpp
@@ -18,57 +18,6 @@
namespace {
-static void unpremultiply_and_pack_argb8888(uint32_t src, uint8_t dst[3]) {
- uint8_t alpha = SkGetPackedA32(src);
- if (alpha != SK_AlphaOPAQUE) {
- SkColor unpremul = SkUnPreMultiply::PMColorToColor(src);
- dst[0] = SkColorGetR(unpremul);
- dst[1] = SkColorGetG(unpremul);
- dst[2] = SkColorGetB(unpremul);
- } else {
- dst[0] = SkGetPackedR32(src);
- dst[1] = SkGetPackedG32(src);
- dst[2] = SkGetPackedB32(src);
- }
-}
-
-static void unpremultiply_and_pack_argb4444(uint16_t src0, uint16_t src1,
- uint8_t dst[3]) {
- // Unpack and transform the alpha values from 4 bits to 8 bits.
- // This is necessary since the unpremultiply functions expect to work in
- // 8-bit space, but we are passing in 4-bit values. Since we scale up
- // the alpha, we scale down the amount the value is increased by, so that
- // the results are correct for 4-bit color components.
- uint8_t alpha0 = SkGetPackedA4444(src0);
- alpha0 = alpha0 | (alpha0 << 4);
- if (alpha0 != SK_AlphaOPAQUE) {
- SkUnPreMultiply::Scale scale0 = SkUnPreMultiply::GetScale(alpha0);
- dst[0] = SkUnPreMultiply::ApplyScale(scale0,
- SkGetPackedR4444(src0)) << 4;
- dst[0] |= SkUnPreMultiply::ApplyScale(scale0, SkGetPackedG4444(src0));
- dst[1] = SkUnPreMultiply::ApplyScale(scale0,
- SkGetPackedB4444(src0)) << 4;
- } else {
- dst[0] = SkGetPackedR4444(src0) << 4;
- dst[0] |= SkGetPackedG4444(src0);
- dst[1] = SkGetPackedB4444(src0) << 4;
- }
-
- uint8_t alpha1 = SkGetPackedA4444(src1);
- alpha1 = alpha1 | (alpha1 << 4);
- if (alpha1 != SK_AlphaOPAQUE) {
- SkUnPreMultiply::Scale scale1 = SkUnPreMultiply::GetScale(alpha1);
- dst[1] |= SkUnPreMultiply::ApplyScale(scale1, SkGetPackedR4444(src1));
- dst[2] = SkUnPreMultiply::ApplyScale(scale1,
- SkGetPackedG4444(src1)) << 4;
- dst[2] |= SkUnPreMultiply::ApplyScale(scale1, SkGetPackedB4444(src1));
- } else {
- dst[1] |= SkGetPackedR4444(src1);
- dst[2] = SkGetPackedG4444(src1) << 4;
- dst[2] |= SkGetPackedB4444(src1);
- }
-}
-
void extractImageData(const SkBitmap& bitmap, const SkIRect& srcRect,
SkStream** imageData, SkStream** alphaData) {
SkMemoryStream* image = NULL;
@@ -100,35 +49,36 @@ void extractImageData(const SkBitmap& bitmap, const SkIRect& srcRect,
uint16_t* src = bitmap.getAddr16(0, y);
int x;
for (x = srcRect.fLeft; x + 1 < srcRect.fRight; x += 2) {
+ dst[0] = (SkGetPackedR4444(src[x]) << 4) |
+ SkGetPackedG4444(src[x]);
+ dst[1] = (SkGetPackedB4444(src[x]) << 4) |
+ SkGetPackedR4444(src[x + 1]);
+ dst[2] = (SkGetPackedG4444(src[x + 1]) << 4) |
+ SkGetPackedB4444(src[x + 1]);
+ dst += 3;
alphaDst[0] = (SkGetPackedA4444(src[x]) << 4) |
- SkGetPackedA4444(src[x + 1]);
- if (alphaDst[0] != SK_AlphaOPAQUE) {
+ SkGetPackedA4444(src[x + 1]);
+ if (alphaDst[0] != 0xFF) {
hasAlpha = true;
}
if (alphaDst[0]) {
isTransparent = false;
}
- unpremultiply_and_pack_argb4444(src[x], src[x + 1], dst);
alphaDst++;
- dst += 3;
}
if (srcRect.width() & 1) {
- alphaDst[0] = SkGetPackedA4444(src[x]) << 4;
- // Use a buffer to translate from the usual 2 4444 values
- // in 3 bytes to the single 4444 value in 2 bytes.
- uint8_t buffer[3];
+ dst[0] = (SkGetPackedR4444(src[x]) << 4) |
+ SkGetPackedG4444(src[x]);
+ dst[1] = (SkGetPackedB4444(src[x]) << 4);
+ dst += 2;
+ alphaDst[0] = (SkGetPackedA4444(src[x]) << 4);
if (alphaDst[0] != 0xF0) {
hasAlpha = true;
}
if (alphaDst[0] & 0xF0) {
isTransparent = false;
}
- unpremultiply_and_pack_argb4444(src[x], 0x00, buffer);
- dst[0] = buffer[0];
- dst[1] = buffer[1];
-
alphaDst++;
- dst += 2;
}
}
break;
@@ -158,16 +108,18 @@ void extractImageData(const SkBitmap& bitmap, const SkIRect& srcRect,
for (int y = srcRect.fTop; y < srcRect.fBottom; y++) {
uint32_t* src = bitmap.getAddr32(0, y);
for (int x = srcRect.fLeft; x < srcRect.fRight; x++) {
+ dst[0] = SkGetPackedR32(src[x]);
+ dst[1] = SkGetPackedG32(src[x]);
+ dst[2] = SkGetPackedB32(src[x]);
+ dst += 3;
alphaDst[0] = SkGetPackedA32(src[x]);
- if (alphaDst[0] != SK_AlphaOPAQUE) {
+ if (alphaDst[0] != 0xFF) {
hasAlpha = true;
}
- if (alphaDst[0] != SK_AlphaTRANSPARENT) {
+ if (alphaDst[0]) {
isTransparent = false;
}
- unpremultiply_and_pack_argb8888(src[x], dst);
alphaDst++;
- dst += 3;
}
}
break;