summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLei Zhang <thestig@chromium.org>2018-03-01 15:40:47 +0000
committerChromium commit bot <commit-bot@chromium.org>2018-03-01 15:40:47 +0000
commit98037a0f758b4ebd3b9bedf571ae4ef791251276 (patch)
treea8ff570e36f6c19155984a34356a0182fbdc6491
parent198792b7e860702840287e8d561a21dfa973aaa4 (diff)
downloadpdfium-98037a0f758b4ebd3b9bedf571ae4ef791251276.tar.xz
Break up CFX_DIBSource::ConvertBuffer().
Change-Id: If93b4782016c7f27c1533417d019f3271c807941 Reviewed-on: https://pdfium-review.googlesource.com/27813 Commit-Queue: dsinclair <dsinclair@chromium.org> Reviewed-by: dsinclair <dsinclair@chromium.org>
-rw-r--r--core/fxge/dib/cfx_dibsource.cpp230
1 files changed, 133 insertions, 97 deletions
diff --git a/core/fxge/dib/cfx_dibsource.cpp b/core/fxge/dib/cfx_dibsource.cpp
index c91cd849a8..f96ca1e074 100644
--- a/core/fxge/dib/cfx_dibsource.cpp
+++ b/core/fxge/dib/cfx_dibsource.cpp
@@ -593,6 +593,128 @@ void ConvertBuffer_32bppCmyk2Rgb32(uint8_t* dest_buf,
}
}
+bool ConvertBuffer_8bppMask(int bpp,
+ uint8_t* dest_buf,
+ int dest_pitch,
+ int width,
+ int height,
+ const RetainPtr<CFX_DIBSource>& pSrcBitmap,
+ int src_left,
+ int src_top) {
+ switch (bpp) {
+ case 1:
+ if (pSrcBitmap->GetPalette()) {
+ ConvertBuffer_1bppPlt2Gray(dest_buf, dest_pitch, width, height,
+ pSrcBitmap, src_left, src_top);
+ } else {
+ ConvertBuffer_1bppMask2Gray(dest_buf, dest_pitch, width, height,
+ pSrcBitmap, src_left, src_top);
+ }
+ return true;
+ case 8:
+ if (pSrcBitmap->GetPalette()) {
+ ConvertBuffer_8bppPlt2Gray(dest_buf, dest_pitch, width, height,
+ pSrcBitmap, src_left, src_top);
+ } else {
+ ConvertBuffer_8bppMask2Gray(dest_buf, dest_pitch, width, height,
+ pSrcBitmap, src_left, src_top);
+ }
+ return true;
+ case 24:
+ case 32:
+ ConvertBuffer_RgbOrCmyk2Gray(dest_buf, dest_pitch, width, height,
+ pSrcBitmap, src_left, src_top);
+ return true;
+ default:
+ return false;
+ }
+}
+
+bool ConvertBuffer_Rgb(int bpp,
+ FXDIB_Format dest_format,
+ uint8_t* dest_buf,
+ int dest_pitch,
+ int width,
+ int height,
+ const RetainPtr<CFX_DIBSource>& pSrcBitmap,
+ int src_left,
+ int src_top) {
+ switch (bpp) {
+ case 1:
+ if (pSrcBitmap->GetPalette()) {
+ ConvertBuffer_1bppPlt2Rgb(dest_format, dest_buf, dest_pitch, width,
+ height, pSrcBitmap, src_left, src_top);
+ } else {
+ ConvertBuffer_1bppMask2Rgb(dest_format, dest_buf, dest_pitch, width,
+ height, pSrcBitmap, src_left, src_top);
+ }
+ return true;
+ case 8:
+ if (pSrcBitmap->GetPalette()) {
+ ConvertBuffer_8bppPlt2Rgb(dest_format, dest_buf, dest_pitch, width,
+ height, pSrcBitmap, src_left, src_top);
+ } else {
+ ConvertBuffer_8bppMask2Rgb(dest_format, dest_buf, dest_pitch, width,
+ height, pSrcBitmap, src_left, src_top);
+ }
+ return true;
+ case 24:
+ ConvertBuffer_24bppRgb2Rgb24(dest_buf, dest_pitch, width, height,
+ pSrcBitmap, src_left, src_top);
+ return true;
+ case 32:
+ ConvertBuffer_32bppRgb2Rgb24(dest_buf, dest_pitch, width, height,
+ pSrcBitmap, src_left, src_top);
+ return true;
+ default:
+ return false;
+ }
+}
+
+bool ConvertBuffer_Argb(int bpp,
+ bool cmyk,
+ FXDIB_Format dest_format,
+ uint8_t* dest_buf,
+ int dest_pitch,
+ int width,
+ int height,
+ const RetainPtr<CFX_DIBSource>& pSrcBitmap,
+ int src_left,
+ int src_top) {
+ switch (bpp) {
+ case 1:
+ if (pSrcBitmap->GetPalette()) {
+ ConvertBuffer_1bppPlt2Rgb(dest_format, dest_buf, dest_pitch, width,
+ height, pSrcBitmap, src_left, src_top);
+ } else {
+ ConvertBuffer_1bppMask2Rgb(dest_format, dest_buf, dest_pitch, width,
+ height, pSrcBitmap, src_left, src_top);
+ }
+ return true;
+ case 8:
+ if (pSrcBitmap->GetPalette()) {
+ ConvertBuffer_8bppPlt2Rgb(dest_format, dest_buf, dest_pitch, width,
+ height, pSrcBitmap, src_left, src_top);
+ } else {
+ ConvertBuffer_8bppMask2Rgb(dest_format, dest_buf, dest_pitch, width,
+ height, pSrcBitmap, src_left, src_top);
+ }
+ return true;
+ case 24:
+ case 32:
+ if (cmyk) {
+ ConvertBuffer_32bppCmyk2Rgb32(dest_buf, dest_pitch, width, height,
+ pSrcBitmap, src_left, src_top);
+ } else {
+ ConvertBuffer_Rgb2Rgb32(dest_buf, dest_pitch, width, height, pSrcBitmap,
+ src_left, src_top);
+ }
+ return true;
+ default:
+ return false;
+ }
+}
+
} // namespace
CFX_DIBSource::CFX_DIBSource()
@@ -1095,55 +1217,25 @@ bool CFX_DIBSource::ConvertBuffer(
int src_top,
std::unique_ptr<uint32_t, FxFreeDeleter>* p_pal) {
FXDIB_Format src_format = pSrcBitmap->GetFormat();
+ const int bpp = src_format & 0xff;
switch (dest_format) {
- case FXDIB_Invalid:
- case FXDIB_1bppCmyk:
- case FXDIB_1bppMask:
- case FXDIB_1bppRgb:
- NOTREACHED();
- return false;
case FXDIB_8bppMask: {
- if ((src_format & 0xff) == 1) {
- if (pSrcBitmap->GetPalette()) {
- ConvertBuffer_1bppPlt2Gray(dest_buf, dest_pitch, width, height,
- pSrcBitmap, src_left, src_top);
- return true;
- }
- ConvertBuffer_1bppMask2Gray(dest_buf, dest_pitch, width, height,
+ return ConvertBuffer_8bppMask(bpp, dest_buf, dest_pitch, width, height,
pSrcBitmap, src_left, src_top);
- return true;
- }
- if ((src_format & 0xff) == 8) {
- if (pSrcBitmap->GetPalette()) {
- ConvertBuffer_8bppPlt2Gray(dest_buf, dest_pitch, width, height,
- pSrcBitmap, src_left, src_top);
- return true;
- }
- ConvertBuffer_8bppMask2Gray(dest_buf, dest_pitch, width, height,
- pSrcBitmap, src_left, src_top);
- return true;
- }
- if ((src_format & 0xff) >= 24) {
- ConvertBuffer_RgbOrCmyk2Gray(dest_buf, dest_pitch, width, height,
- pSrcBitmap, src_left, src_top);
- return true;
- }
- return false;
}
case FXDIB_8bppRgb:
case FXDIB_8bppRgba: {
- if ((src_format & 0xff) == 8 && !pSrcBitmap->GetPalette()) {
+ if (bpp == 8 && !pSrcBitmap->GetPalette()) {
return ConvertBuffer(FXDIB_8bppMask, dest_buf, dest_pitch, width,
height, pSrcBitmap, src_left, src_top, p_pal);
}
p_pal->reset(FX_Alloc(uint32_t, 256));
- if (((src_format & 0xff) == 1 || (src_format & 0xff) == 8) &&
- pSrcBitmap->GetPalette()) {
+ if ((bpp == 1 || bpp == 8) && pSrcBitmap->GetPalette()) {
ConvertBuffer_Plt2PltRgb8(dest_buf, dest_pitch, width, height,
pSrcBitmap, src_left, src_top, p_pal->get());
return true;
}
- if ((src_format & 0xff) >= 24) {
+ if (bpp >= 24) {
ConvertBuffer_Rgb2PltRgb8(dest_buf, dest_pitch, width, height,
pSrcBitmap, src_left, src_top, p_pal->get());
return true;
@@ -1152,73 +1244,17 @@ bool CFX_DIBSource::ConvertBuffer(
}
case FXDIB_Rgb:
case FXDIB_Rgba: {
- if ((src_format & 0xff) == 1) {
- if (pSrcBitmap->GetPalette()) {
- ConvertBuffer_1bppPlt2Rgb(dest_format, dest_buf, dest_pitch, width,
- height, pSrcBitmap, src_left, src_top);
- return true;
- }
- ConvertBuffer_1bppMask2Rgb(dest_format, dest_buf, dest_pitch, width,
- height, pSrcBitmap, src_left, src_top);
- return true;
- }
- if ((src_format & 0xff) == 8) {
- if (pSrcBitmap->GetPalette()) {
- ConvertBuffer_8bppPlt2Rgb(dest_format, dest_buf, dest_pitch, width,
- height, pSrcBitmap, src_left, src_top);
- return true;
- }
- ConvertBuffer_8bppMask2Rgb(dest_format, dest_buf, dest_pitch, width,
- height, pSrcBitmap, src_left, src_top);
- return true;
- }
- if ((src_format & 0xff) == 24) {
- ConvertBuffer_24bppRgb2Rgb24(dest_buf, dest_pitch, width, height,
- pSrcBitmap, src_left, src_top);
- return true;
- }
- if ((src_format & 0xff) == 32) {
- ConvertBuffer_32bppRgb2Rgb24(dest_buf, dest_pitch, width, height,
- pSrcBitmap, src_left, src_top);
- return true;
- }
- return false;
+ return ConvertBuffer_Rgb(bpp, dest_format, dest_buf, dest_pitch, width,
+ height, pSrcBitmap, src_left, src_top);
}
case FXDIB_Argb:
case FXDIB_Rgb32: {
- if ((src_format & 0xff) == 1) {
- if (pSrcBitmap->GetPalette()) {
- ConvertBuffer_1bppPlt2Rgb(dest_format, dest_buf, dest_pitch, width,
- height, pSrcBitmap, src_left, src_top);
- return true;
- }
- ConvertBuffer_1bppMask2Rgb(dest_format, dest_buf, dest_pitch, width,
- height, pSrcBitmap, src_left, src_top);
- return true;
- }
- if ((src_format & 0xff) == 8) {
- if (pSrcBitmap->GetPalette()) {
- ConvertBuffer_8bppPlt2Rgb(dest_format, dest_buf, dest_pitch, width,
- height, pSrcBitmap, src_left, src_top);
- return true;
- }
- ConvertBuffer_8bppMask2Rgb(dest_format, dest_buf, dest_pitch, width,
- height, pSrcBitmap, src_left, src_top);
- return true;
- }
- if ((src_format & 0xff) >= 24) {
- if (src_format & 0x0400) {
- ConvertBuffer_32bppCmyk2Rgb32(dest_buf, dest_pitch, width, height,
- pSrcBitmap, src_left, src_top);
- return true;
- }
- ConvertBuffer_Rgb2Rgb32(dest_buf, dest_pitch, width, height, pSrcBitmap,
- src_left, src_top);
- return true;
- }
- return false;
+ const bool cmyk = src_format & 0x0400;
+ return ConvertBuffer_Argb(bpp, cmyk, dest_format, dest_buf, dest_pitch,
+ width, height, pSrcBitmap, src_left, src_top);
}
default:
+ NOTREACHED();
return false;
}
}