SkARGB4444_Blitter::SkARGB4444_Blitter(const SkBitmap& device, const SkPaint& paint) : INHERITED(device) { // cache premultiplied versions in 4444 SkPMColor c = SkPreMultiplyColor(paint.getColor()); fPMColor16 = SkPixel32ToPixel4444(c); if (paint.isDither()) { fPMColor16Other = SkDitherPixel32To4444(c); } else { fPMColor16Other = fPMColor16; } // cache raw versions in 4444 fRawColor16 = SkPackARGB4444(0xFF >> 4, SkColorGetR(c) >> 4, SkColorGetG(c) >> 4, SkColorGetB(c) >> 4); if (paint.isDither()) { fRawColor16Other = SkDitherARGB32To4444(0xFF, SkColorGetR(c), SkColorGetG(c), SkColorGetB(c)); } else { fRawColor16Other = fRawColor16; } fScale16 = SkAlpha15To16(SkGetPackedA4444(fPMColor16Other)); if (16 == fScale16) { // force the original to also be opaque fPMColor16 |= (0xF << SK_A4444_SHIFT); } }
SkARGB4444_Blitter::SkARGB4444_Blitter(const SkBitmap& device, const SkPaint& paint) : INHERITED(device) { // cache premultiplied versions in 4444 SkPMColor c = SkPreMultiplyColor(paint.getColor()); fPMColor16 = SkPixel32ToPixel4444(c); if (paint.isDither()) { fPMColor16Other = SkDitherPixel32To4444(c); } else { fPMColor16Other = fPMColor16; } // cache raw versions in 4444 fRawColor16 = SkPackARGB4444(0xFF >> 4, SkColorGetR(c) >> 4, SkColorGetG(c) >> 4, SkColorGetB(c) >> 4); if (paint.isDither()) { fRawColor16Other = SkDitherARGB32To4444(0xFF, SkColorGetR(c), SkColorGetG(c), SkColorGetB(c)); } else { fRawColor16Other = fRawColor16; } #if 0 /// don't think this assertion is true, but need it be? // our dithered color will be the same or more opaque than the original // so use dithered to compute our scale SkASSERT(SkGetPackedA4444(fPMColor16Other) >= SkGetPackedA4444(fPMColor16)); #endif fScale16 = SkAlpha15To16(SkGetPackedA4444(fPMColor16Other)); if (16 == fScale16) { // force the original to also be opaque fPMColor16 |= (0xF << SK_A4444_SHIFT); } }
static void FromColor_D4444(void* dst, const SkColor src[], int width, int x, int y) { SkPMColor16* d = (SkPMColor16*)dst; DITHER_4444_SCAN(y); for (int stop = x + width; x < stop; x++) { SkPMColor c = SkPreMultiplyColor(*src++); *d++ = SkDitherARGB32To4444(c, DITHER_VALUE(x)); // *d++ = SkPixel32ToPixel4444(c); } }
static void FromColor_D4444_Raw(void* dst, const SkColor src[], int width, int x, int y) { SkPMColor16* d = (SkPMColor16*)dst; DITHER_4444_SCAN(y); for (int stop = x + width; x < stop; x++) { SkColor c = *src++; // SkPMColor is used because the ordering is ARGB32, even though the target actually premultiplied SkPMColor pmc = SkPackARGB32NoCheck(SkColorGetA(c), SkColorGetR(c), SkColorGetG(c), SkColorGetB(c)); *d++ = SkDitherARGB32To4444(pmc, DITHER_VALUE(x)); // *d++ = SkPixel32ToPixel4444(pmc); } }
bool SkPixelInfo::CopyPixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dstRB, const SkImageInfo& srcInfo, const void* srcPixels, size_t srcRB, SkColorTable* ctable) { if (srcInfo.dimensions() != dstInfo.dimensions()) { return false; } const int width = srcInfo.width(); const int height = srcInfo.height(); // Handle fancy alpha swizzling if both are ARGB32 if (4 == srcInfo.bytesPerPixel() && 4 == dstInfo.bytesPerPixel()) { SkDstPixelInfo dstPI; dstPI.fColorType = dstInfo.colorType(); dstPI.fAlphaType = dstInfo.alphaType(); dstPI.fPixels = dstPixels; dstPI.fRowBytes = dstRB; SkSrcPixelInfo srcPI; srcPI.fColorType = srcInfo.colorType(); srcPI.fAlphaType = srcInfo.alphaType(); srcPI.fPixels = srcPixels; srcPI.fRowBytes = srcRB; return srcPI.convertPixelsTo(&dstPI, width, height); } // If they agree on colorType and the alphaTypes are compatible, then we just memcpy. // Note: we've already taken care of 32bit colortypes above. if (srcInfo.colorType() == dstInfo.colorType()) { switch (srcInfo.colorType()) { case kRGB_565_SkColorType: case kAlpha_8_SkColorType: break; case kIndex_8_SkColorType: case kARGB_4444_SkColorType: if (srcInfo.alphaType() != dstInfo.alphaType()) { return false; } break; default: return false; } rect_memcpy(dstPixels, dstRB, srcPixels, srcRB, width * srcInfo.bytesPerPixel(), height); return true; } /* * Begin section where we try to change colorTypes along the way. Not all combinations * are supported. */ // Can no longer draw directly into 4444, but we can manually whack it for a few combinations if (kARGB_4444_SkColorType == dstInfo.colorType() && (kN32_SkColorType == srcInfo.colorType() || kIndex_8_SkColorType == srcInfo.colorType())) { if (srcInfo.alphaType() == kUnpremul_SkAlphaType) { // Our method for converting to 4444 assumes premultiplied. return false; } const SkPMColor* table = NULL; if (kIndex_8_SkColorType == srcInfo.colorType()) { if (NULL == ctable) { return false; } table = ctable->readColors(); } for (int y = 0; y < height; ++y) { DITHER_4444_SCAN(y); SkPMColor16* SK_RESTRICT dstRow = (SkPMColor16*)dstPixels; if (table) { const uint8_t* SK_RESTRICT srcRow = (const uint8_t*)srcPixels; for (int x = 0; x < width; ++x) { dstRow[x] = SkDitherARGB32To4444(table[srcRow[x]], DITHER_VALUE(x)); } } else { const SkPMColor* SK_RESTRICT srcRow = (const SkPMColor*)srcPixels; for (int x = 0; x < width; ++x) { dstRow[x] = SkDitherARGB32To4444(srcRow[x], DITHER_VALUE(x)); } } dstPixels = (char*)dstPixels + dstRB; srcPixels = (const char*)srcPixels + srcRB; } return true; }