Skip to content

Commit

Permalink
Simplify and generalize alpha image extraction in PDF
Browse files Browse the repository at this point in the history
Bug: skia:
Change-Id: I38336b3d803da8bdc9650d560145a24b05a1a457
Reviewed-on: https://skia-review.googlesource.com/c/167460
Reviewed-by: Mike Klein <[email protected]>
Commit-Queue: Brian Osman <[email protected]>
  • Loading branch information
brianosman authored and Skia Commit-Bot committed Nov 2, 2018
1 parent 13853a1 commit 30edaaa
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 53 deletions.
18 changes: 0 additions & 18 deletions src/core/SkColorData.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,6 @@ static inline int SkAlphaBlend(int src, int dst, int scale256) {
return dst + SkAlphaMul(src - dst, scale256);
}

#define SkR16Assert(r) SkASSERT((unsigned)(r) <= SK_R16_MASK)
#define SkG16Assert(g) SkASSERT((unsigned)(g) <= SK_G16_MASK)
#define SkB16Assert(b) SkASSERT((unsigned)(b) <= SK_B16_MASK)

static inline uint16_t SkPackRGB16(unsigned r, unsigned g, unsigned b) {
SkASSERT(r <= SK_R16_MASK);
SkASSERT(g <= SK_G16_MASK);
Expand All @@ -121,20 +117,6 @@ static inline uint16_t SkPackRGB16(unsigned r, unsigned g, unsigned b) {

///////////////////////////////////////////////////////////////////////////////

#ifdef SK_DEBUG
#define SkPMColorAssert(color_value) \
do { \
SkPMColor pm_color_value = (color_value); \
uint32_t alpha_color_value = SkGetPackedA32(pm_color_value); \
SkA32Assert(alpha_color_value); \
SkASSERT(SkGetPackedR32(pm_color_value) <= alpha_color_value); \
SkASSERT(SkGetPackedG32(pm_color_value) <= alpha_color_value); \
SkASSERT(SkGetPackedB32(pm_color_value) <= alpha_color_value); \
} while (false)
#else
#define SkPMColorAssert(c)
#endif

/**
* Abstract 4-byte interpolation, implemented on top of SkPMColor
* utility functions. Third parameter controls blending of the first two:
Expand Down
39 changes: 4 additions & 35 deletions src/pdf/SkPDFBitmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ static U8CPU SkGetB32Component(uint32_t value, SkColorType ct) {

// unpremultiply and extract R, G, B components.
static void pmcolor_to_rgb24(uint32_t color, uint8_t* rgb, SkColorType ct) {
SkPMColorAssert(color);
uint32_t s = SkUnPreMultiply::GetScale(SkGetA32Component(color, ct));
rgb[0] = SkUnPreMultiply::ApplyScale(s, SkGetR32Component(color, ct));
rgb[1] = SkUnPreMultiply::ApplyScale(s, SkGetG32Component(color, ct));
Expand Down Expand Up @@ -103,7 +102,6 @@ static void get_neighbor_avg_color(const SkBitmap& bm,
uint32_t* scanline = bm.getAddr32(0, y);
for (int x = xmin; x <= xmax; ++x) {
uint32_t color = scanline[x];
SkPMColorAssert(color);
a += SkGetA32Component(color, ct);
r += SkGetR32Component(color, ct);
g += SkGetG32Component(color, ct);
Expand Down Expand Up @@ -241,39 +239,10 @@ static void bitmap_alpha_to_a8(const SkBitmap& bitmap, SkWStream* out) {
fill_stream(out, '\xFF', pixel_count(bitmap));
return;
}
SkBitmap copy;
const SkBitmap& bm = supported_colortype(bitmap, &copy);
SkColorType colorType = bm.colorType();
switch (colorType) {
case kRGBA_8888_SkColorType:
case kBGRA_8888_SkColorType: {
SkAutoTMalloc<uint8_t> scanline(bm.width());
for (int y = 0; y < bm.height(); ++y) {
uint8_t* dst = scanline.get();
const SkPMColor* src = bm.getAddr32(0, y);
for (int x = 0; x < bm.width(); ++x) {
*dst++ = SkGetA32Component(*src++, colorType);
}
out->write(scanline.get(), bm.width());
}
return;
}
case kAlpha_8_SkColorType:
for (int y = 0; y < bm.height(); ++y) {
out->write(bm.getAddr8(0, y), bm.width());
}
return;
case kRGB_565_SkColorType:
case kGray_8_SkColorType:
SkDEBUGFAIL("color type has no alpha");
return;
case kARGB_4444_SkColorType:
SkDEBUGFAIL("4444 color type should have been converted to N32");
return;
case kUnknown_SkColorType:
default:
SkDEBUGFAIL("unexpected color type");
}
SkBitmap alpha;
alpha.allocPixels(SkImageInfo::MakeA8(bitmap.width(), bitmap.height()));
SkAssertResult(bitmap.readPixels(alpha.info(), alpha.getPixels(), alpha.rowBytes(), 0, 0));
out->write(alpha.getPixels(), alpha.computeByteSize());
}

static void emit_image_xobject(SkWStream* stream,
Expand Down

0 comments on commit 30edaaa

Please sign in to comment.