static void copyFT2LCD16(const SkGlyph& glyph, const FT_Bitmap& bitmap, int lcdIsBGR, bool lcdIsVert, const uint8_t* tableR, const uint8_t* tableG, const uint8_t* tableB) { if (lcdIsVert) { SkASSERT(3 * glyph.fHeight == bitmap.rows); } else { SkASSERT(glyph.fHeight == bitmap.rows); } uint16_t* dst = reinterpret_cast<uint16_t*>(glyph.fImage); const size_t dstRB = glyph.rowBytes(); const int width = glyph.fWidth; const uint8_t* src = bitmap.buffer; switch (bitmap.pixel_mode) { case FT_PIXEL_MODE_MONO: { for (int y = 0; y < glyph.fHeight; ++y) { for (int x = 0; x < width; ++x) { dst[x] = -bittst(src, x); } dst = (uint16_t*)((char*)dst + dstRB); src += bitmap.pitch; } } break; case FT_PIXEL_MODE_GRAY: { for (int y = 0; y < glyph.fHeight; ++y) { for (int x = 0; x < width; ++x) { dst[x] = grayToRGB16(src[x]); } dst = (uint16_t*)((char*)dst + dstRB); src += bitmap.pitch; } } break; default: { SkASSERT(lcdIsVert || (glyph.fWidth * 3 == bitmap.width)); for (int y = 0; y < glyph.fHeight; y++) { if (lcdIsVert) { // vertical stripes const uint8_t* srcR = src; const uint8_t* srcG = srcR + bitmap.pitch; const uint8_t* srcB = srcG + bitmap.pitch; if (lcdIsBGR) { SkTSwap(srcR, srcB); } for (int x = 0; x < width; x++) { dst[x] = packTriple(sk_apply_lut_if<APPLY_PREBLEND>(*srcR++, tableR), sk_apply_lut_if<APPLY_PREBLEND>(*srcG++, tableG), sk_apply_lut_if<APPLY_PREBLEND>(*srcB++, tableB)); } src += 3 * bitmap.pitch; } else { // horizontal stripes const uint8_t* triple = src; if (lcdIsBGR) { for (int x = 0; x < width; x++) { dst[x] = packTriple(sk_apply_lut_if<APPLY_PREBLEND>(triple[2], tableR), sk_apply_lut_if<APPLY_PREBLEND>(triple[1], tableG), sk_apply_lut_if<APPLY_PREBLEND>(triple[0], tableB)); triple += 3; } } else { for (int x = 0; x < width; x++) { dst[x] = packTriple(sk_apply_lut_if<APPLY_PREBLEND>(triple[0], tableR), sk_apply_lut_if<APPLY_PREBLEND>(triple[1], tableG), sk_apply_lut_if<APPLY_PREBLEND>(triple[2], tableB)); triple += 3; } } src += bitmap.pitch; } dst = (uint16_t*)((char*)dst + dstRB); } } break; } }
static void copyFT2LCD16(const FT_Bitmap& bitmap, const SkMask& mask, int lcdIsBGR, const uint8_t* tableR, const uint8_t* tableG, const uint8_t* tableB) { SkASSERT(SkMask::kLCD16_Format == mask.fFormat); if (FT_PIXEL_MODE_LCD != bitmap.pixel_mode) { SkASSERT(mask.fBounds.width() == static_cast<int>(bitmap.width)); } if (FT_PIXEL_MODE_LCD_V != bitmap.pixel_mode) { SkASSERT(mask.fBounds.height() == static_cast<int>(bitmap.rows)); } const uint8_t* src = bitmap.buffer; uint16_t* dst = reinterpret_cast<uint16_t*>(mask.fImage); const size_t dstRB = mask.fRowBytes; const int width = mask.fBounds.width(); const int height = mask.fBounds.height(); switch (bitmap.pixel_mode) { case FT_PIXEL_MODE_MONO: for (int y = height; y --> 0;) { for (int x = 0; x < width; ++x) { dst[x] = -bittst(src, x); } dst = (uint16_t*)((char*)dst + dstRB); src += bitmap.pitch; } break; case FT_PIXEL_MODE_GRAY: for (int y = height; y --> 0;) { for (int x = 0; x < width; ++x) { dst[x] = grayToRGB16(src[x]); } dst = (uint16_t*)((char*)dst + dstRB); src += bitmap.pitch; } break; case FT_PIXEL_MODE_LCD: SkASSERT(3 * mask.fBounds.width() == static_cast<int>(bitmap.width)); for (int y = height; y --> 0;) { const uint8_t* triple = src; if (lcdIsBGR) { for (int x = 0; x < width; x++) { dst[x] = packTriple(sk_apply_lut_if<APPLY_PREBLEND>(triple[2], tableR), sk_apply_lut_if<APPLY_PREBLEND>(triple[1], tableG), sk_apply_lut_if<APPLY_PREBLEND>(triple[0], tableB)); triple += 3; } } else { for (int x = 0; x < width; x++) { dst[x] = packTriple(sk_apply_lut_if<APPLY_PREBLEND>(triple[0], tableR), sk_apply_lut_if<APPLY_PREBLEND>(triple[1], tableG), sk_apply_lut_if<APPLY_PREBLEND>(triple[2], tableB)); triple += 3; } } src += bitmap.pitch; dst = (uint16_t*)((char*)dst + dstRB); } break; case FT_PIXEL_MODE_LCD_V: SkASSERT(3 * mask.fBounds.height() == static_cast<int>(bitmap.rows)); for (int y = height; y --> 0;) { const uint8_t* srcR = src; const uint8_t* srcG = srcR + bitmap.pitch; const uint8_t* srcB = srcG + bitmap.pitch; if (lcdIsBGR) { SkTSwap(srcR, srcB); } for (int x = 0; x < width; x++) { dst[x] = packTriple(sk_apply_lut_if<APPLY_PREBLEND>(*srcR++, tableR), sk_apply_lut_if<APPLY_PREBLEND>(*srcG++, tableG), sk_apply_lut_if<APPLY_PREBLEND>(*srcB++, tableB)); } src += 3 * bitmap.pitch; dst = (uint16_t*)((char*)dst + dstRB); } break; default: SkDEBUGF(("FT_Pixel_Mode %d", bitmap.pixel_mode)); SkDEBUGFAIL("unsupported FT_Pixel_Mode for LCD16"); break; } }