From 68758aed88b16d67658f634e8dcd855404fedb8a Mon Sep 17 00:00:00 2001 From: msarett Date: Mon, 25 Apr 2016 11:41:15 -0700 Subject: [PATCH] Remove SkEncodedInfo kPreSwizzled_Color from public API BUG=skia: GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1918943002 Review URL: https://codereview.chromium.org/1918943002 --- include/codec/SkEncodedInfo.h | 4 - src/codec/SkJpegCodec.cpp | 7 +- src/codec/SkSwizzler.cpp | 584 +++++++++++++++++----------------- src/codec/SkSwizzler.h | 5 +- 4 files changed, 305 insertions(+), 295 deletions(-) diff --git a/include/codec/SkEncodedInfo.h b/include/codec/SkEncodedInfo.h index 27511e1e93..0c5bd0b421 100644 --- a/include/codec/SkEncodedInfo.h +++ b/include/codec/SkEncodedInfo.h @@ -64,10 +64,6 @@ public: // be treated as inverted CMYK. kInvertedCMYK_Color, kYCCK_Color, - - // Used internally to indicate that the decoding library has - // pre-swizzled to the desired output format. - kPreSwizzled_Color, }; static SkEncodedInfo Make(Color color, Alpha alpha, int bitsPerComponent) { diff --git a/src/codec/SkJpegCodec.cpp b/src/codec/SkJpegCodec.cpp index 7de97b39ab..07ece6c95b 100644 --- a/src/codec/SkJpegCodec.cpp +++ b/src/codec/SkJpegCodec.cpp @@ -518,15 +518,17 @@ void SkJpegCodec::initializeSwizzler(const SkImageInfo& dstInfo, const Options& // libjpeg-turbo may have already performed color conversion. We must indicate the // appropriate format to the swizzler. SkEncodedInfo swizzlerInfo = this->getEncodedInfo(); + bool preSwizzled = true; switch (fDecoderMgr->dinfo()->out_color_space) { case JCS_RGB: + preSwizzled = false; swizzlerInfo.setColor(SkEncodedInfo::kRGB_Color); break; case JCS_CMYK: + preSwizzled = false; swizzlerInfo.setColor(SkEncodedInfo::kInvertedCMYK_Color); break; default: - swizzlerInfo.setColor(SkEncodedInfo::kPreSwizzled_Color); break; } @@ -539,7 +541,8 @@ void SkJpegCodec::initializeSwizzler(const SkImageInfo& dstInfo, const Options& fSwizzlerSubset.width() == options.fSubset->width()); swizzlerOptions.fSubset = &fSwizzlerSubset; } - fSwizzler.reset(SkSwizzler::CreateSwizzler(swizzlerInfo, nullptr, dstInfo, swizzlerOptions)); + fSwizzler.reset(SkSwizzler::CreateSwizzler(swizzlerInfo, nullptr, dstInfo, swizzlerOptions, + nullptr, preSwizzled)); SkASSERT(fSwizzler); fStorage.reset(get_row_bytes(fDecoderMgr->dinfo())); fSrcRow = fStorage.get(); diff --git a/src/codec/SkSwizzler.cpp b/src/codec/SkSwizzler.cpp index f242421424..c9eb923053 100644 --- a/src/codec/SkSwizzler.cpp +++ b/src/codec/SkSwizzler.cpp @@ -651,318 +651,326 @@ SkSwizzler* SkSwizzler::CreateSwizzler(const SkEncodedInfo& encodedInfo, const SkPMColor* ctable, const SkImageInfo& dstInfo, const SkCodec::Options& options, - const SkIRect* frame) { + const SkIRect* frame, + bool preSwizzled) { if (SkEncodedInfo::kPalette_Color == encodedInfo.color() && nullptr == ctable) { return nullptr; } RowProc fastProc = nullptr; RowProc proc = nullptr; - SkCodec::ZeroInitialized zeroInit = options.fZeroInitialized; - const bool premultiply = (SkEncodedInfo::kOpaque_Alpha != encodedInfo.alpha()) && - (kPremul_SkAlphaType == dstInfo.alphaType()); - switch (encodedInfo.color()) { - case SkEncodedInfo::kGray_Color: - switch (encodedInfo.bitsPerComponent()) { - case 1: - switch (dstInfo.colorType()) { - case kRGBA_8888_SkColorType: - case kBGRA_8888_SkColorType: - proc = &swizzle_bit_to_n32; - break; - case kIndex_8_SkColorType: - proc = &swizzle_bit_to_index; - break; - case kRGB_565_SkColorType: - proc = &swizzle_bit_to_565; - break; - case kGray_8_SkColorType: - proc = &swizzle_bit_to_grayscale; - break; - default: - return nullptr; - } - break; - case 8: - switch (dstInfo.colorType()) { - case kRGBA_8888_SkColorType: - case kBGRA_8888_SkColorType: - proc = &swizzle_gray_to_n32; - fastProc = &fast_swizzle_gray_to_n32; - break; - case kGray_8_SkColorType: - proc = &sample1; - fastProc = © - break; - case kRGB_565_SkColorType: - proc = &swizzle_gray_to_565; - break; - default: - return nullptr; - } - break; - default: - return nullptr; - } - break; - case SkEncodedInfo::kGrayAlpha_Color: - switch (dstInfo.colorType()) { - case kRGBA_8888_SkColorType: - case kBGRA_8888_SkColorType: - if (premultiply) { - if (SkCodec::kYes_ZeroInitialized == zeroInit) { - proc = &SkipLeadingGrayAlphaZerosThen; - fastProc = &SkipLeadingGrayAlphaZerosThen - ; - } else { - proc = &swizzle_grayalpha_to_n32_premul; - fastProc = &fast_swizzle_grayalpha_to_n32_premul; + if (preSwizzled) { + switch (dstInfo.colorType()) { + case kGray_8_SkColorType: + proc = &sample1; + fastProc = © + break; + case kRGB_565_SkColorType: + proc = &sample2; + fastProc = © + break; + case kRGBA_8888_SkColorType: + case kBGRA_8888_SkColorType: + proc = &sample4; + fastProc = © + break; + default: + return nullptr; + } + } else { + SkCodec::ZeroInitialized zeroInit = options.fZeroInitialized; + const bool premultiply = (SkEncodedInfo::kOpaque_Alpha != encodedInfo.alpha()) && + (kPremul_SkAlphaType == dstInfo.alphaType()); + + switch (encodedInfo.color()) { + case SkEncodedInfo::kGray_Color: + switch (encodedInfo.bitsPerComponent()) { + case 1: + switch (dstInfo.colorType()) { + case kRGBA_8888_SkColorType: + case kBGRA_8888_SkColorType: + proc = &swizzle_bit_to_n32; + break; + case kIndex_8_SkColorType: + proc = &swizzle_bit_to_index; + break; + case kRGB_565_SkColorType: + proc = &swizzle_bit_to_565; + break; + case kGray_8_SkColorType: + proc = &swizzle_bit_to_grayscale; + break; + default: + return nullptr; } - } else { - if (SkCodec::kYes_ZeroInitialized == zeroInit) { - proc = &SkipLeadingGrayAlphaZerosThen - ; - fastProc = &SkipLeadingGrayAlphaZerosThen - ; - } else { - proc = &swizzle_grayalpha_to_n32_unpremul; - fastProc = &fast_swizzle_grayalpha_to_n32_unpremul; + break; + case 8: + switch (dstInfo.colorType()) { + case kRGBA_8888_SkColorType: + case kBGRA_8888_SkColorType: + proc = &swizzle_gray_to_n32; + fastProc = &fast_swizzle_gray_to_n32; + break; + case kGray_8_SkColorType: + proc = &sample1; + fastProc = © + break; + case kRGB_565_SkColorType: + proc = &swizzle_gray_to_565; + break; + default: + return nullptr; } - } - break; - default: - return nullptr; - } - break; - case SkEncodedInfo::kPalette_Color: - // We assume that the color table is premultiplied and swizzled - // as desired. - switch (encodedInfo.bitsPerComponent()) { - case 1: - case 2: - case 4: - switch (dstInfo.colorType()) { - case kRGBA_8888_SkColorType: - case kBGRA_8888_SkColorType: - proc = &swizzle_small_index_to_n32; - break; - case kRGB_565_SkColorType: - proc = &swizzle_small_index_to_565; - break; - case kIndex_8_SkColorType: - proc = &swizzle_small_index_to_index; - break; - default: - return nullptr; - } - break; - case 8: - switch (dstInfo.colorType()) { - case kRGBA_8888_SkColorType: - case kBGRA_8888_SkColorType: + break; + default: + return nullptr; + } + break; + case SkEncodedInfo::kGrayAlpha_Color: + switch (dstInfo.colorType()) { + case kRGBA_8888_SkColorType: + case kBGRA_8888_SkColorType: + if (premultiply) { if (SkCodec::kYes_ZeroInitialized == zeroInit) { - proc = &swizzle_index_to_n32_skipZ; + proc = &SkipLeadingGrayAlphaZerosThen + ; + fastProc = &SkipLeadingGrayAlphaZerosThen + ; } else { - proc = &swizzle_index_to_n32; + proc = &swizzle_grayalpha_to_n32_premul; + fastProc = &fast_swizzle_grayalpha_to_n32_premul; } - break; - case kRGB_565_SkColorType: - proc = &swizzle_index_to_565; - break; - case kIndex_8_SkColorType: - proc = &sample1; - fastProc = © - break; - default: - return nullptr; - } - break; - default: - return nullptr; - } - break; - case SkEncodedInfo::kRGB_Color: - switch (dstInfo.colorType()) { - case kRGBA_8888_SkColorType: - proc = &swizzle_rgb_to_rgba; - fastProc = &fast_swizzle_rgb_to_rgba; - break; - case kBGRA_8888_SkColorType: - proc = &swizzle_rgb_to_bgra; - fastProc = &fast_swizzle_rgb_to_bgra; - break; - case kRGB_565_SkColorType: - proc = &swizzle_rgb_to_565; - break; - default: - return nullptr; - } - break; - case SkEncodedInfo::kRGBA_Color: - switch (dstInfo.colorType()) { - case kRGBA_8888_SkColorType: - if (premultiply) { - if (SkCodec::kYes_ZeroInitialized == zeroInit) { - proc = &SkipLeading8888ZerosThen; - fastProc = &SkipLeading8888ZerosThen; } else { - proc = &swizzle_rgba_to_rgba_premul; - fastProc = &fast_swizzle_rgba_to_rgba_premul; + if (SkCodec::kYes_ZeroInitialized == zeroInit) { + proc = &SkipLeadingGrayAlphaZerosThen + ; + fastProc = &SkipLeadingGrayAlphaZerosThen + ; + } else { + proc = &swizzle_grayalpha_to_n32_unpremul; + fastProc = &fast_swizzle_grayalpha_to_n32_unpremul; + } } - } else { - if (SkCodec::kYes_ZeroInitialized == zeroInit) { - proc = &SkipLeading8888ZerosThen; - fastProc = &SkipLeading8888ZerosThen; + break; + default: + return nullptr; + } + break; + case SkEncodedInfo::kPalette_Color: + // We assume that the color table is premultiplied and swizzled + // as desired. + switch (encodedInfo.bitsPerComponent()) { + case 1: + case 2: + case 4: + switch (dstInfo.colorType()) { + case kRGBA_8888_SkColorType: + case kBGRA_8888_SkColorType: + proc = &swizzle_small_index_to_n32; + break; + case kRGB_565_SkColorType: + proc = &swizzle_small_index_to_565; + break; + case kIndex_8_SkColorType: + proc = &swizzle_small_index_to_index; + break; + default: + return nullptr; + } + break; + case 8: + switch (dstInfo.colorType()) { + case kRGBA_8888_SkColorType: + case kBGRA_8888_SkColorType: + if (SkCodec::kYes_ZeroInitialized == zeroInit) { + proc = &swizzle_index_to_n32_skipZ; + } else { + proc = &swizzle_index_to_n32; + } + break; + case kRGB_565_SkColorType: + proc = &swizzle_index_to_565; + break; + case kIndex_8_SkColorType: + proc = &sample1; + fastProc = © + break; + default: + return nullptr; + } + break; + default: + return nullptr; + } + break; + case SkEncodedInfo::kRGB_Color: + switch (dstInfo.colorType()) { + case kRGBA_8888_SkColorType: + proc = &swizzle_rgb_to_rgba; + fastProc = &fast_swizzle_rgb_to_rgba; + break; + case kBGRA_8888_SkColorType: + proc = &swizzle_rgb_to_bgra; + fastProc = &fast_swizzle_rgb_to_bgra; + break; + case kRGB_565_SkColorType: + proc = &swizzle_rgb_to_565; + break; + default: + return nullptr; + } + break; + case SkEncodedInfo::kRGBA_Color: + switch (dstInfo.colorType()) { + case kRGBA_8888_SkColorType: + if (premultiply) { + if (SkCodec::kYes_ZeroInitialized == zeroInit) { + proc = &SkipLeading8888ZerosThen; + fastProc = &SkipLeading8888ZerosThen + ; + } else { + proc = &swizzle_rgba_to_rgba_premul; + fastProc = &fast_swizzle_rgba_to_rgba_premul; + } } else { - proc = &sample4; - fastProc = © + if (SkCodec::kYes_ZeroInitialized == zeroInit) { + proc = &SkipLeading8888ZerosThen; + fastProc = &SkipLeading8888ZerosThen; + } else { + proc = &sample4; + fastProc = © + } } - } - break; - case kBGRA_8888_SkColorType: - if (premultiply) { - if (SkCodec::kYes_ZeroInitialized == zeroInit) { - proc = &SkipLeading8888ZerosThen; - fastProc = &SkipLeading8888ZerosThen; + break; + case kBGRA_8888_SkColorType: + if (premultiply) { + if (SkCodec::kYes_ZeroInitialized == zeroInit) { + proc = &SkipLeading8888ZerosThen; + fastProc = &SkipLeading8888ZerosThen + ; + } else { + proc = &swizzle_rgba_to_bgra_premul; + fastProc = &fast_swizzle_rgba_to_bgra_premul; + } } else { - proc = &swizzle_rgba_to_bgra_premul; - fastProc = &fast_swizzle_rgba_to_bgra_premul; + if (SkCodec::kYes_ZeroInitialized == zeroInit) { + proc = &SkipLeading8888ZerosThen; + fastProc = &SkipLeading8888ZerosThen + ; + } else { + proc = &swizzle_rgba_to_bgra_unpremul; + fastProc = &fast_swizzle_rgba_to_bgra_unpremul; + } } - } else { - if (SkCodec::kYes_ZeroInitialized == zeroInit) { - proc = &SkipLeading8888ZerosThen; - fastProc = &SkipLeading8888ZerosThen - ; + break; + default: + return nullptr; + } + break; + case SkEncodedInfo::kBGR_Color: + switch (dstInfo.colorType()) { + case kBGRA_8888_SkColorType: + proc = &swizzle_rgb_to_rgba; + fastProc = &fast_swizzle_rgb_to_rgba; + break; + case kRGBA_8888_SkColorType: + proc = &swizzle_rgb_to_bgra; + fastProc = &fast_swizzle_rgb_to_bgra; + break; + case kRGB_565_SkColorType: + proc = &swizzle_bgr_to_565; + break; + default: + return nullptr; + } + break; + case SkEncodedInfo::kBGRX_Color: + switch (dstInfo.colorType()) { + case kBGRA_8888_SkColorType: + proc = &swizzle_rgb_to_rgba; + break; + case kRGBA_8888_SkColorType: + proc = &swizzle_rgb_to_bgra; + break; + case kRGB_565_SkColorType: + proc = &swizzle_bgr_to_565; + break; + default: + return nullptr; + } + break; + case SkEncodedInfo::kBGRA_Color: + switch (dstInfo.colorType()) { + case kBGRA_8888_SkColorType: + if (premultiply) { + if (SkCodec::kYes_ZeroInitialized == zeroInit) { + proc = &SkipLeading8888ZerosThen; + fastProc = &SkipLeading8888ZerosThen + ; + } else { + proc = &swizzle_rgba_to_rgba_premul; + fastProc = &fast_swizzle_rgba_to_rgba_premul; + } } else { - proc = &swizzle_rgba_to_bgra_unpremul; - fastProc = &fast_swizzle_rgba_to_bgra_unpremul; + if (SkCodec::kYes_ZeroInitialized == zeroInit) { + proc = &SkipLeading8888ZerosThen; + fastProc = &SkipLeading8888ZerosThen; + } else { + proc = &sample4; + fastProc = © + } } - } - break; - default: - return nullptr; - } - break; - case SkEncodedInfo::kBGR_Color: - switch (dstInfo.colorType()) { - case kBGRA_8888_SkColorType: - proc = &swizzle_rgb_to_rgba; - fastProc = &fast_swizzle_rgb_to_rgba; - break; - case kRGBA_8888_SkColorType: - proc = &swizzle_rgb_to_bgra; - fastProc = &fast_swizzle_rgb_to_bgra; - break; - case kRGB_565_SkColorType: - proc = &swizzle_bgr_to_565; - break; - default: - return nullptr; - } - break; - case SkEncodedInfo::kBGRX_Color: - switch (dstInfo.colorType()) { - case kBGRA_8888_SkColorType: - proc = &swizzle_rgb_to_rgba; - break; - case kRGBA_8888_SkColorType: - proc = &swizzle_rgb_to_bgra; - break; - case kRGB_565_SkColorType: - proc = &swizzle_bgr_to_565; - break; - default: - return nullptr; - } - break; - case SkEncodedInfo::kBGRA_Color: - switch (dstInfo.colorType()) { - case kBGRA_8888_SkColorType: - if (premultiply) { - if (SkCodec::kYes_ZeroInitialized == zeroInit) { - proc = &SkipLeading8888ZerosThen; - fastProc = &SkipLeading8888ZerosThen; + break; + case kRGBA_8888_SkColorType: + if (premultiply) { + if (SkCodec::kYes_ZeroInitialized == zeroInit) { + proc = &SkipLeading8888ZerosThen; + fastProc = &SkipLeading8888ZerosThen + ; + } else { + proc = &swizzle_rgba_to_bgra_premul; + fastProc = &fast_swizzle_rgba_to_bgra_premul; + } } else { - proc = &swizzle_rgba_to_rgba_premul; - fastProc = &fast_swizzle_rgba_to_rgba_premul; + if (SkCodec::kYes_ZeroInitialized == zeroInit) { + proc = &SkipLeading8888ZerosThen; + fastProc = &SkipLeading8888ZerosThen + ; + } else { + proc = &swizzle_rgba_to_bgra_unpremul; + fastProc = &fast_swizzle_rgba_to_bgra_unpremul; + } } - } else { - if (SkCodec::kYes_ZeroInitialized == zeroInit) { - proc = &SkipLeading8888ZerosThen; - fastProc = &SkipLeading8888ZerosThen; - } else { - proc = &sample4; - fastProc = © - } - } - break; - case kRGBA_8888_SkColorType: - if (premultiply) { - if (SkCodec::kYes_ZeroInitialized == zeroInit) { - proc = &SkipLeading8888ZerosThen; - fastProc = &SkipLeading8888ZerosThen; - } else { - proc = &swizzle_rgba_to_bgra_premul; - fastProc = &fast_swizzle_rgba_to_bgra_premul; - } - } else { - if (SkCodec::kYes_ZeroInitialized == zeroInit) { - proc = &SkipLeading8888ZerosThen; - fastProc = &SkipLeading8888ZerosThen - ; - } else { - proc = &swizzle_rgba_to_bgra_unpremul; - fastProc = &fast_swizzle_rgba_to_bgra_unpremul; - } - } - break; - default: - return nullptr; - } - break; - case SkEncodedInfo::kInvertedCMYK_Color: - switch (dstInfo.colorType()) { - case kRGBA_8888_SkColorType: - proc = &swizzle_cmyk_to_rgba; - fastProc = &fast_swizzle_cmyk_to_rgba; - break; - case kBGRA_8888_SkColorType: - proc = &swizzle_cmyk_to_bgra; - fastProc = &fast_swizzle_cmyk_to_bgra; - break; - case kRGB_565_SkColorType: - proc = &swizzle_cmyk_to_565; - break; - default: - return nullptr; - } - break; - case SkEncodedInfo::kPreSwizzled_Color: - switch (dstInfo.colorType()) { - case kGray_8_SkColorType: - proc = &sample1; - fastProc = © - break; - case kRGB_565_SkColorType: - proc = &sample2; - fastProc = © - break; - case kRGBA_8888_SkColorType: - case kBGRA_8888_SkColorType: - proc = &sample4; - fastProc = © - break; - default: - return nullptr; - } - break; - default: - return nullptr; + break; + default: + return nullptr; + } + break; + case SkEncodedInfo::kInvertedCMYK_Color: + switch (dstInfo.colorType()) { + case kRGBA_8888_SkColorType: + proc = &swizzle_cmyk_to_rgba; + fastProc = &fast_swizzle_cmyk_to_rgba; + break; + case kBGRA_8888_SkColorType: + proc = &swizzle_cmyk_to_bgra; + fastProc = &fast_swizzle_cmyk_to_bgra; + break; + case kRGB_565_SkColorType: + proc = &swizzle_cmyk_to_565; + break; + default: + return nullptr; + } + break; + default: + return nullptr; + } } - int dstBPP = SkColorTypeBytesPerPixel(dstInfo.colorType()); int srcBPP; - if (SkEncodedInfo::kPreSwizzled_Color == encodedInfo.color()) { + const int dstBPP = SkColorTypeBytesPerPixel(dstInfo.colorType()); + if (preSwizzled) { srcBPP = dstBPP; } else { // Store bpp in bytes if it is an even multiple, otherwise use bits diff --git a/src/codec/SkSwizzler.h b/src/codec/SkSwizzler.h index 070652cc8a..4845047048 100644 --- a/src/codec/SkSwizzler.h +++ b/src/codec/SkSwizzler.h @@ -27,6 +27,9 @@ public: * Contains partial scanline information. * @param frame Is non-NULL if the source pixels are part of an image * frame that is a subset of the full image. + * @param preSwizzled Indicates that the codec has already swizzled to the + * destination format. The swizzler only needs to sample + * and/or subset. * * Note that a deeper discussion of partial scanline subsets and image frame * subsets is below. Currently, we do not support both simultaneously. If @@ -36,7 +39,7 @@ public: */ static SkSwizzler* CreateSwizzler(const SkEncodedInfo& encodedInfo, const SkPMColor* ctable, const SkImageInfo& dstInfo, const SkCodec::Options&, - const SkIRect* frame = nullptr); + const SkIRect* frame = nullptr, bool preSwizzled = false); /** * Swizzle a line. Generally this will be called height times, once