summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorNicolas Pena <npm@chromium.org>2017-04-04 12:12:49 -0400
committerChromium commit bot <commit-bot@chromium.org>2017-04-04 16:25:29 +0000
commit37cc5fb6b3407ce8e079bc1bdd0606713b975532 (patch)
treea816f60f67dc4deb6db42aa98b5aca4a419243ff /core
parent29479f6380942515b06240c4933bf3b4cf502013 (diff)
downloadpdfium-37cc5fb6b3407ce8e079bc1bdd0606713b975532.tar.xz
Finish splitting up fx_dib.h
After this CL, fx_dib.h only has some definitions used in multiple places. Definitions that were of restricted usage were moved out to the corresponding place. Includes in fx_dib were reduced, thus revealing other needed includes. Change-Id: I3607da0af81c491256d64c0aa085225631efbdcc Reviewed-on: https://pdfium-review.googlesource.com/3594 Commit-Queue: Nicolás Peña <npm@chromium.org> Reviewed-by: dsinclair <dsinclair@chromium.org>
Diffstat (limited to 'core')
-rw-r--r--core/fpdfapi/render/cpdf_imagerenderer.cpp2
-rw-r--r--core/fpdfapi/render/cpdf_imagerenderer.h3
-rw-r--r--core/fpdfapi/render/cpdf_transferfunc.cpp1
-rw-r--r--core/fpdfapi/render/cpdf_transferfunc.h1
-rw-r--r--core/fxcodec/codec/ccodec_tiffmodule.cpp1
-rw-r--r--core/fxcodec/codec/fx_codec_jpeg.cpp1
-rw-r--r--core/fxcodec/codec/fx_codec_progress.cpp1
-rw-r--r--core/fxge/dib/cfx_bitmapcomposer.h2
-rw-r--r--core/fxge/dib/cfx_bitmapstorer.h2
-rw-r--r--core/fxge/dib/cfx_dibitmap.cpp1
-rw-r--r--core/fxge/dib/cfx_dibsource.cpp794
-rw-r--r--core/fxge/dib/cfx_dibsource.h53
-rw-r--r--core/fxge/dib/cfx_imagestretcher.cpp9
-rw-r--r--core/fxge/dib/cfx_imagestretcher.h1
-rw-r--r--core/fxge/dib/cfx_scanlinecompositor.cpp9
-rw-r--r--core/fxge/dib/fx_dib_convert.cpp792
-rw-r--r--core/fxge/dib/fx_dib_engine.cpp3
-rw-r--r--core/fxge/dib/fx_dib_main.cpp7
-rw-r--r--core/fxge/dib/ifx_scanlinecomposer.h26
-rw-r--r--core/fxge/fx_dib.h111
-rw-r--r--core/fxge/fx_font.h1
-rw-r--r--core/fxge/ge/cfx_cliprgn.cpp2
-rw-r--r--core/fxge/ge/cfx_cliprgn.h4
-rw-r--r--core/fxge/win32/dwrite_int.h4
24 files changed, 915 insertions, 916 deletions
diff --git a/core/fpdfapi/render/cpdf_imagerenderer.cpp b/core/fpdfapi/render/cpdf_imagerenderer.cpp
index c42c781dc2..8c3cd6a23a 100644
--- a/core/fpdfapi/render/cpdf_imagerenderer.cpp
+++ b/core/fpdfapi/render/cpdf_imagerenderer.cpp
@@ -29,6 +29,8 @@
#include "core/fxcrt/fx_safe_types.h"
#include "core/fxge/cfx_fxgedevice.h"
#include "core/fxge/cfx_pathdata.h"
+#include "core/fxge/dib/cfx_dibitmap.h"
+#include "core/fxge/dib/cfx_dibsource.h"
#include "core/fxge/dib/cfx_imagestretcher.h"
#include "core/fxge/dib/cfx_imagetransformer.h"
#include "third_party/base/ptr_util.h"
diff --git a/core/fpdfapi/render/cpdf_imagerenderer.h b/core/fpdfapi/render/cpdf_imagerenderer.h
index 542325449f..00b5d41601 100644
--- a/core/fpdfapi/render/cpdf_imagerenderer.h
+++ b/core/fpdfapi/render/cpdf_imagerenderer.h
@@ -10,7 +10,10 @@
#include <memory>
#include "core/fpdfapi/render/cpdf_imageloader.h"
+#include "core/fxcrt/fx_coordinates.h"
+class CFX_DIBitmap;
+class CFX_DIBSource;
class CFX_FxgeDevice;
class CFX_ImageTransformer;
class CPDF_ImageObject;
diff --git a/core/fpdfapi/render/cpdf_transferfunc.cpp b/core/fpdfapi/render/cpdf_transferfunc.cpp
index a7ee42fa01..e9ea0576ae 100644
--- a/core/fpdfapi/render/cpdf_transferfunc.cpp
+++ b/core/fpdfapi/render/cpdf_transferfunc.cpp
@@ -8,6 +8,7 @@
#include "core/fpdfapi/parser/cpdf_document.h"
#include "core/fpdfapi/render/cpdf_dibtransferfunc.h"
+#include "core/fxge/dib/cfx_dibsource.h"
CPDF_TransferFunc::CPDF_TransferFunc(CPDF_Document* pDoc) : m_pPDFDoc(pDoc) {}
diff --git a/core/fpdfapi/render/cpdf_transferfunc.h b/core/fpdfapi/render/cpdf_transferfunc.h
index 8f94d9605d..82e7a39037 100644
--- a/core/fpdfapi/render/cpdf_transferfunc.h
+++ b/core/fpdfapi/render/cpdf_transferfunc.h
@@ -11,6 +11,7 @@
#include "core/fxge/fx_dib.h"
class CPDF_Document;
+class CFX_DIBSource;
class CPDF_TransferFunc : public CFX_Retainable {
public:
diff --git a/core/fxcodec/codec/ccodec_tiffmodule.cpp b/core/fxcodec/codec/ccodec_tiffmodule.cpp
index e4ef355f38..295f0abe34 100644
--- a/core/fxcodec/codec/ccodec_tiffmodule.cpp
+++ b/core/fxcodec/codec/ccodec_tiffmodule.cpp
@@ -12,6 +12,7 @@
#include "core/fxcodec/fx_codec.h"
#include "core/fxcrt/cfx_retain_ptr.h"
#include "core/fxcrt/fx_safe_types.h"
+#include "core/fxge/dib/cfx_dibitmap.h"
#include "core/fxge/fx_dib.h"
#include "third_party/base/ptr_util.h"
diff --git a/core/fxcodec/codec/fx_codec_jpeg.cpp b/core/fxcodec/codec/fx_codec_jpeg.cpp
index 584148d148..907d15f3fb 100644
--- a/core/fxcodec/codec/fx_codec_jpeg.cpp
+++ b/core/fxcodec/codec/fx_codec_jpeg.cpp
@@ -12,6 +12,7 @@
#include "core/fxcodec/codec/codec_int.h"
#include "core/fxcodec/fx_codec.h"
#include "core/fxcrt/fx_safe_types.h"
+#include "core/fxge/dib/cfx_dibsource.h"
#include "core/fxge/fx_dib.h"
#include "third_party/base/ptr_util.h"
diff --git a/core/fxcodec/codec/fx_codec_progress.cpp b/core/fxcodec/codec/fx_codec_progress.cpp
index d8b123b254..79f0bed415 100644
--- a/core/fxcodec/codec/fx_codec_progress.cpp
+++ b/core/fxcodec/codec/fx_codec_progress.cpp
@@ -10,6 +10,7 @@
#include <memory>
#include "core/fxcodec/fx_codec.h"
+#include "core/fxge/dib/cfx_dibitmap.h"
#include "core/fxge/fx_dib.h"
#include "third_party/base/numerics/safe_math.h"
#include "third_party/base/ptr_util.h"
diff --git a/core/fxge/dib/cfx_bitmapcomposer.h b/core/fxge/dib/cfx_bitmapcomposer.h
index eeca80ed55..6d14533b13 100644
--- a/core/fxge/dib/cfx_bitmapcomposer.h
+++ b/core/fxge/dib/cfx_bitmapcomposer.h
@@ -10,7 +10,7 @@
#include "core/fxcrt/cfx_retain_ptr.h"
#include "core/fxcrt/fx_coordinates.h"
#include "core/fxge/dib/cfx_scanlinecompositor.h"
-#include "core/fxge/fx_dib.h"
+#include "core/fxge/dib/ifx_scanlinecomposer.h"
class CFX_ClipRgn;
class CFX_DIBitmap;
diff --git a/core/fxge/dib/cfx_bitmapstorer.h b/core/fxge/dib/cfx_bitmapstorer.h
index 478d9f7f64..a574493e6e 100644
--- a/core/fxge/dib/cfx_bitmapstorer.h
+++ b/core/fxge/dib/cfx_bitmapstorer.h
@@ -13,7 +13,7 @@
#include "core/fxcrt/cfx_retain_ptr.h"
#include "core/fxcrt/fx_coordinates.h"
#include "core/fxge/dib/cfx_dibitmap.h"
-#include "core/fxge/fx_dib.h"
+#include "core/fxge/dib/ifx_scanlinecomposer.h"
#include "third_party/base/stl_util.h"
class CFX_BitmapStorer : public IFX_ScanlineComposer {
diff --git a/core/fxge/dib/cfx_dibitmap.cpp b/core/fxge/dib/cfx_dibitmap.cpp
index b97917dba7..6292a67870 100644
--- a/core/fxge/dib/cfx_dibitmap.cpp
+++ b/core/fxge/dib/cfx_dibitmap.cpp
@@ -12,6 +12,7 @@
#include "core/fxcodec/fx_codec.h"
#include "core/fxge/cfx_gemodule.h"
+#include "core/fxge/dib/cfx_scanlinecompositor.h"
#include "core/fxge/dib/dib_int.h"
#include "core/fxge/ge/cfx_cliprgn.h"
#include "third_party/base/ptr_util.h"
diff --git a/core/fxge/dib/cfx_dibsource.cpp b/core/fxge/dib/cfx_dibsource.cpp
index 1a11632759..aace10934b 100644
--- a/core/fxge/dib/cfx_dibsource.cpp
+++ b/core/fxge/dib/cfx_dibsource.cpp
@@ -10,6 +10,7 @@
#include <memory>
#include <utility>
+#include "core/fxcodec/fx_codec.h"
#include "core/fxge/dib/cfx_bitmapstorer.h"
#include "core/fxge/dib/cfx_dibitmap.h"
#include "core/fxge/dib/cfx_imagestretcher.h"
@@ -17,6 +18,653 @@
#include "core/fxge/ge/cfx_cliprgn.h"
#include "third_party/base/ptr_util.h"
+namespace {
+
+class CFX_Palette {
+ public:
+ CFX_Palette();
+ ~CFX_Palette();
+
+ bool BuildPalette(const CFX_RetainPtr<CFX_DIBSource>& pBitmap);
+ uint32_t* GetPalette() const { return m_pPalette; }
+ uint32_t* GetColorLut() const { return m_cLut; }
+ uint32_t* GetAmountLut() const { return m_aLut; }
+ int32_t Getlut() const { return m_lut; }
+
+ protected:
+ uint32_t* m_pPalette;
+ uint32_t* m_cLut;
+ uint32_t* m_aLut;
+ int m_lut;
+};
+
+int Partition(uint32_t* alut, uint32_t* clut, int l, int r) {
+ uint32_t p_a = alut[l];
+ uint32_t p_c = clut[l];
+ while (l < r) {
+ while (l < r && alut[r] >= p_a)
+ r--;
+ if (l < r) {
+ alut[l] = alut[r];
+ clut[l++] = clut[r];
+ }
+ while (l < r && alut[l] <= p_a)
+ l++;
+ if (l < r) {
+ alut[r] = alut[l];
+ clut[r--] = clut[l];
+ }
+ }
+ alut[l] = p_a;
+ clut[l] = p_c;
+ return l;
+}
+
+void Qsort(uint32_t* alut, uint32_t* clut, int l, int r) {
+ if (l < r) {
+ int pI = Partition(alut, clut, l, r);
+ Qsort(alut, clut, l, pI - 1);
+ Qsort(alut, clut, pI + 1, r);
+ }
+}
+
+void ColorDecode(uint32_t pal_v, uint8_t& r, uint8_t& g, uint8_t& b) {
+ r = static_cast<uint8_t>((pal_v & 0xf00) >> 4);
+ g = static_cast<uint8_t>(pal_v & 0x0f0);
+ b = static_cast<uint8_t>((pal_v & 0x00f) << 4);
+}
+
+void Obtain_Pal(uint32_t* aLut,
+ uint32_t* cLut,
+ uint32_t* dest_pal,
+ uint32_t lut) {
+ uint32_t lut_1 = lut - 1;
+ for (int row = 0; row < 256; row++) {
+ int lut_offset = lut_1 - row;
+ if (lut_offset < 0)
+ lut_offset += 256;
+ uint32_t color = cLut[lut_offset];
+ uint8_t r;
+ uint8_t g;
+ uint8_t b;
+ ColorDecode(color, r, g, b);
+ dest_pal[row] = (static_cast<uint32_t>(r) << 16) |
+ (static_cast<uint32_t>(g) << 8) | b | 0xff000000;
+ aLut[lut_offset] = row;
+ }
+}
+
+CFX_Palette::CFX_Palette()
+ : m_pPalette(nullptr), m_cLut(nullptr), m_aLut(nullptr), m_lut(0) {}
+
+CFX_Palette::~CFX_Palette() {
+ FX_Free(m_pPalette);
+ FX_Free(m_cLut);
+ FX_Free(m_aLut);
+}
+
+bool CFX_Palette::BuildPalette(const CFX_RetainPtr<CFX_DIBSource>& pBitmap) {
+ if (!pBitmap) {
+ return false;
+ }
+ FX_Free(m_pPalette);
+ m_pPalette = FX_Alloc(uint32_t, 256);
+ int bpp = pBitmap->GetBPP() / 8;
+ int width = pBitmap->GetWidth();
+ int height = pBitmap->GetHeight();
+ FX_Free(m_cLut);
+ m_cLut = nullptr;
+ FX_Free(m_aLut);
+ m_aLut = nullptr;
+ m_cLut = FX_Alloc(uint32_t, 4096);
+ m_aLut = FX_Alloc(uint32_t, 4096);
+ int row, col;
+ m_lut = 0;
+ for (row = 0; row < height; row++) {
+ uint8_t* scan_line = (uint8_t*)pBitmap->GetScanline(row);
+ for (col = 0; col < width; col++) {
+ uint8_t* src_port = scan_line + col * bpp;
+ uint32_t b = src_port[0] & 0xf0;
+ uint32_t g = src_port[1] & 0xf0;
+ uint32_t r = src_port[2] & 0xf0;
+ uint32_t index = (r << 4) + g + (b >> 4);
+ m_aLut[index]++;
+ }
+ }
+ for (row = 0; row < 4096; row++) {
+ if (m_aLut[row] != 0) {
+ m_aLut[m_lut] = m_aLut[row];
+ m_cLut[m_lut] = row;
+ m_lut++;
+ }
+ }
+ Qsort(m_aLut, m_cLut, 0, m_lut - 1);
+ Obtain_Pal(m_aLut, m_cLut, m_pPalette, m_lut);
+ return true;
+}
+
+bool ConvertBuffer_1bppMask2Gray(uint8_t* dest_buf,
+ int dest_pitch,
+ int width,
+ int height,
+ const CFX_RetainPtr<CFX_DIBSource>& pSrcBitmap,
+ int src_left,
+ int src_top) {
+ uint8_t set_gray, reset_gray;
+ set_gray = 0xff;
+ reset_gray = 0x00;
+ for (int row = 0; row < height; row++) {
+ uint8_t* dest_scan = dest_buf + row * dest_pitch;
+ memset(dest_scan, reset_gray, width);
+ const uint8_t* src_scan = pSrcBitmap->GetScanline(src_top + row);
+ for (int col = src_left; col < src_left + width; col++) {
+ if (src_scan[col / 8] & (1 << (7 - col % 8))) {
+ *dest_scan = set_gray;
+ }
+ dest_scan++;
+ }
+ }
+ return true;
+}
+
+bool ConvertBuffer_8bppMask2Gray(uint8_t* dest_buf,
+ int dest_pitch,
+ int width,
+ int height,
+ const CFX_RetainPtr<CFX_DIBSource>& pSrcBitmap,
+ int src_left,
+ int src_top) {
+ for (int row = 0; row < height; row++) {
+ uint8_t* dest_scan = dest_buf + row * dest_pitch;
+ const uint8_t* src_scan = pSrcBitmap->GetScanline(src_top + row) + src_left;
+ memcpy(dest_scan, src_scan, width);
+ }
+ return true;
+}
+
+bool ConvertBuffer_1bppPlt2Gray(uint8_t* dest_buf,
+ int dest_pitch,
+ int width,
+ int height,
+ const CFX_RetainPtr<CFX_DIBSource>& pSrcBitmap,
+ int src_left,
+ int src_top) {
+ uint32_t* src_plt = pSrcBitmap->GetPalette();
+ uint8_t gray[2];
+ uint8_t reset_r;
+ uint8_t reset_g;
+ uint8_t reset_b;
+ uint8_t set_r;
+ uint8_t set_g;
+ uint8_t set_b;
+ if (pSrcBitmap->IsCmykImage()) {
+ AdobeCMYK_to_sRGB1(FXSYS_GetCValue(src_plt[0]), FXSYS_GetMValue(src_plt[0]),
+ FXSYS_GetYValue(src_plt[0]), FXSYS_GetKValue(src_plt[0]),
+ reset_r, reset_g, reset_b);
+ AdobeCMYK_to_sRGB1(FXSYS_GetCValue(src_plt[1]), FXSYS_GetMValue(src_plt[1]),
+ FXSYS_GetYValue(src_plt[1]), FXSYS_GetKValue(src_plt[1]),
+ set_r, set_g, set_b);
+ } else {
+ reset_r = FXARGB_R(src_plt[0]);
+ reset_g = FXARGB_G(src_plt[0]);
+ reset_b = FXARGB_B(src_plt[0]);
+ set_r = FXARGB_R(src_plt[1]);
+ set_g = FXARGB_G(src_plt[1]);
+ set_b = FXARGB_B(src_plt[1]);
+ }
+ gray[0] = FXRGB2GRAY(reset_r, reset_g, reset_b);
+ gray[1] = FXRGB2GRAY(set_r, set_g, set_b);
+
+ for (int row = 0; row < height; row++) {
+ uint8_t* dest_scan = dest_buf + row * dest_pitch;
+ memset(dest_scan, gray[0], width);
+ const uint8_t* src_scan = pSrcBitmap->GetScanline(src_top + row);
+ for (int col = src_left; col < src_left + width; col++) {
+ if (src_scan[col / 8] & (1 << (7 - col % 8))) {
+ *dest_scan = gray[1];
+ }
+ dest_scan++;
+ }
+ }
+ return true;
+}
+
+bool ConvertBuffer_8bppPlt2Gray(uint8_t* dest_buf,
+ int dest_pitch,
+ int width,
+ int height,
+ const CFX_RetainPtr<CFX_DIBSource>& pSrcBitmap,
+ int src_left,
+ int src_top) {
+ uint32_t* src_plt = pSrcBitmap->GetPalette();
+ uint8_t gray[256];
+ if (pSrcBitmap->IsCmykImage()) {
+ uint8_t r;
+ uint8_t g;
+ uint8_t b;
+ for (size_t i = 0; i < FX_ArraySize(gray); i++) {
+ AdobeCMYK_to_sRGB1(
+ FXSYS_GetCValue(src_plt[i]), FXSYS_GetMValue(src_plt[i]),
+ FXSYS_GetYValue(src_plt[i]), FXSYS_GetKValue(src_plt[i]), r, g, b);
+ gray[i] = FXRGB2GRAY(r, g, b);
+ }
+ } else {
+ for (size_t i = 0; i < FX_ArraySize(gray); i++) {
+ gray[i] = FXRGB2GRAY(FXARGB_R(src_plt[i]), FXARGB_G(src_plt[i]),
+ FXARGB_B(src_plt[i]));
+ }
+ }
+
+ for (int row = 0; row < height; row++) {
+ uint8_t* dest_scan = dest_buf + row * dest_pitch;
+ const uint8_t* src_scan = pSrcBitmap->GetScanline(src_top + row) + src_left;
+ for (int col = 0; col < width; col++) {
+ *dest_scan++ = gray[*src_scan++];
+ }
+ }
+ return true;
+}
+
+bool ConvertBuffer_RgbOrCmyk2Gray(
+ uint8_t* dest_buf,
+ int dest_pitch,
+ int width,
+ int height,
+ const CFX_RetainPtr<CFX_DIBSource>& pSrcBitmap,
+ int src_left,
+ int src_top) {
+ int Bpp = pSrcBitmap->GetBPP() / 8;
+ if (pSrcBitmap->IsCmykImage()) {
+ for (int row = 0; row < height; row++) {
+ uint8_t* dest_scan = dest_buf + row * dest_pitch;
+ const uint8_t* src_scan =
+ pSrcBitmap->GetScanline(src_top + row) + src_left * 4;
+ for (int col = 0; col < width; col++) {
+ uint8_t r, g, b;
+ AdobeCMYK_to_sRGB1(FXSYS_GetCValue(static_cast<uint32_t>(src_scan[0])),
+ FXSYS_GetMValue(static_cast<uint32_t>(src_scan[1])),
+ FXSYS_GetYValue(static_cast<uint32_t>(src_scan[2])),
+ FXSYS_GetKValue(static_cast<uint32_t>(src_scan[3])),
+ r, g, b);
+ *dest_scan++ = FXRGB2GRAY(r, g, b);
+ src_scan += 4;
+ }
+ }
+ } else {
+ for (int row = 0; row < height; row++) {
+ uint8_t* dest_scan = dest_buf + row * dest_pitch;
+ const uint8_t* src_scan =
+ pSrcBitmap->GetScanline(src_top + row) + src_left * Bpp;
+ for (int col = 0; col < width; col++) {
+ *dest_scan++ = FXRGB2GRAY(src_scan[2], src_scan[1], src_scan[0]);
+ src_scan += Bpp;
+ }
+ }
+ }
+ return true;
+}
+
+void ConvertBuffer_IndexCopy(uint8_t* dest_buf,
+ int dest_pitch,
+ int width,
+ int height,
+ const CFX_RetainPtr<CFX_DIBSource>& pSrcBitmap,
+ int src_left,
+ int src_top) {
+ if (pSrcBitmap->GetBPP() == 1) {
+ for (int row = 0; row < height; row++) {
+ uint8_t* dest_scan = dest_buf + row * dest_pitch;
+ memset(dest_scan, 0, width);
+ const uint8_t* src_scan = pSrcBitmap->GetScanline(src_top + row);
+ for (int col = src_left; col < src_left + width; col++) {
+ if (src_scan[col / 8] & (1 << (7 - col % 8))) {
+ *dest_scan = 1;
+ }
+ dest_scan++;
+ }
+ }
+ } else {
+ for (int row = 0; row < height; row++) {
+ uint8_t* dest_scan = dest_buf + row * dest_pitch;
+ const uint8_t* src_scan =
+ pSrcBitmap->GetScanline(src_top + row) + src_left;
+ memcpy(dest_scan, src_scan, width);
+ }
+ }
+}
+
+bool ConvertBuffer_Plt2PltRgb8(uint8_t* dest_buf,
+ int dest_pitch,
+ int width,
+ int height,
+ const CFX_RetainPtr<CFX_DIBSource>& pSrcBitmap,
+ int src_left,
+ int src_top,
+ uint32_t* dst_plt) {
+ ConvertBuffer_IndexCopy(dest_buf, dest_pitch, width, height, pSrcBitmap,
+ src_left, src_top);
+ uint32_t* src_plt = pSrcBitmap->GetPalette();
+ int plt_size = pSrcBitmap->GetPaletteSize();
+ if (pSrcBitmap->IsCmykImage()) {
+ for (int i = 0; i < plt_size; i++) {
+ uint8_t r;
+ uint8_t g;
+ uint8_t b;
+ AdobeCMYK_to_sRGB1(
+ FXSYS_GetCValue(src_plt[i]), FXSYS_GetMValue(src_plt[i]),
+ FXSYS_GetYValue(src_plt[i]), FXSYS_GetKValue(src_plt[i]), r, g, b);
+ dst_plt[i] = FXARGB_MAKE(0xff, r, g, b);
+ }
+ } else {
+ memcpy(dst_plt, src_plt, plt_size * 4);
+ }
+ return true;
+}
+
+bool ConvertBuffer_Rgb2PltRgb8(uint8_t* dest_buf,
+ int dest_pitch,
+ int width,
+ int height,
+ const CFX_RetainPtr<CFX_DIBSource>& pSrcBitmap,
+ int src_left,
+ int src_top,
+ uint32_t* dst_plt) {
+ int bpp = pSrcBitmap->GetBPP() / 8;
+ CFX_Palette palette;
+ palette.BuildPalette(pSrcBitmap);
+ uint32_t* cLut = palette.GetColorLut();
+ uint32_t* aLut = palette.GetAmountLut();
+ if (!cLut || !aLut) {
+ return false;
+ }
+ int lut = palette.Getlut();
+ uint32_t* pPalette = palette.GetPalette();
+ if (lut > 256) {
+ int err;
+ int min_err;
+ int lut_256 = lut - 256;
+ for (int row = 0; row < lut_256; row++) {
+ min_err = 1000000;
+ uint8_t r;
+ uint8_t g;
+ uint8_t b;
+ ColorDecode(cLut[row], r, g, b);
+ int clrindex = 0;
+ for (int col = 0; col < 256; col++) {
+ uint32_t p_color = *(pPalette + col);
+ int d_r = r - static_cast<uint8_t>(p_color >> 16);
+ int d_g = g - static_cast<uint8_t>(p_color >> 8);
+ int d_b = b - static_cast<uint8_t>(p_color);
+ err = d_r * d_r + d_g * d_g + d_b * d_b;
+ if (err < min_err) {
+ min_err = err;
+ clrindex = col;
+ }
+ }
+ aLut[row] = clrindex;
+ }
+ }
+ int32_t lut_1 = lut - 1;
+ for (int row = 0; row < height; row++) {
+ uint8_t* src_scan =
+ const_cast<uint8_t*>(pSrcBitmap->GetScanline(src_top + row)) + src_left;
+ uint8_t* dest_scan = dest_buf + row * dest_pitch;
+ for (int col = 0; col < width; col++) {
+ uint8_t* src_port = src_scan + col * bpp;
+ int r = src_port[2] & 0xf0;
+ int g = src_port[1] & 0xf0;
+ int b = src_port[0] & 0xf0;
+ uint32_t clrindex = (r << 4) + g + (b >> 4);
+ for (int i = lut_1; i >= 0; i--)
+ if (clrindex == cLut[i]) {
+ *(dest_scan + col) = static_cast<uint8_t>(aLut[i]);
+ break;
+ }
+ }
+ }
+ memcpy(dst_plt, pPalette, sizeof(uint32_t) * 256);
+ return true;
+}
+
+bool ConvertBuffer_1bppMask2Rgb(FXDIB_Format dst_format,
+ uint8_t* dest_buf,
+ int dest_pitch,
+ int width,
+ int height,
+ const CFX_RetainPtr<CFX_DIBSource>& pSrcBitmap,
+ int src_left,
+ int src_top) {
+ int comps = (dst_format & 0xff) / 8;
+ uint8_t set_gray, reset_gray;
+ set_gray = 0xff;
+ reset_gray = 0x00;
+ for (int row = 0; row < height; row++) {
+ uint8_t* dest_scan = dest_buf + row * dest_pitch;
+ const uint8_t* src_scan = pSrcBitmap->GetScanline(src_top + row);
+ for (int col = src_left; col < src_left + width; col++) {
+ if (src_scan[col / 8] & (1 << (7 - col % 8))) {
+ dest_scan[0] = set_gray;
+ dest_scan[1] = set_gray;
+ dest_scan[2] = set_gray;
+ } else {
+ dest_scan[0] = reset_gray;
+ dest_scan[1] = reset_gray;
+ dest_scan[2] = reset_gray;
+ }
+ dest_scan += comps;
+ }
+ }
+ return true;
+}
+
+bool ConvertBuffer_8bppMask2Rgb(FXDIB_Format dst_format,
+ uint8_t* dest_buf,
+ int dest_pitch,
+ int width,
+ int height,
+ const CFX_RetainPtr<CFX_DIBSource>& pSrcBitmap,
+ int src_left,
+ int src_top) {
+ int comps = (dst_format & 0xff) / 8;
+ for (int row = 0; row < height; row++) {
+ uint8_t* dest_scan = dest_buf + row * dest_pitch;
+ const uint8_t* src_scan = pSrcBitmap->GetScanline(src_top + row) + src_left;
+ uint8_t src_pixel;
+ for (int col = 0; col < width; col++) {
+ src_pixel = *src_scan++;
+ *dest_scan++ = src_pixel;
+ *dest_scan++ = src_pixel;
+ *dest_scan = src_pixel;
+ dest_scan += comps - 2;
+ }
+ }
+ return true;
+}
+
+bool ConvertBuffer_1bppPlt2Rgb(FXDIB_Format dst_format,
+ uint8_t* dest_buf,
+ int dest_pitch,
+ int width,
+ int height,
+ const CFX_RetainPtr<CFX_DIBSource>& pSrcBitmap,
+ int src_left,
+ int src_top) {
+ int comps = (dst_format & 0xff) / 8;
+ uint32_t* src_plt = pSrcBitmap->GetPalette();
+ uint32_t plt[2];
+ uint8_t* bgr_ptr = reinterpret_cast<uint8_t*>(plt);
+ if (pSrcBitmap->IsCmykImage()) {
+ plt[0] = FXCMYK_TODIB(src_plt[0]);
+ plt[1] = FXCMYK_TODIB(src_plt[1]);
+ } else {
+ bgr_ptr[0] = FXARGB_B(src_plt[0]);
+ bgr_ptr[1] = FXARGB_G(src_plt[0]);
+ bgr_ptr[2] = FXARGB_R(src_plt[0]);
+ bgr_ptr[3] = FXARGB_B(src_plt[1]);
+ bgr_ptr[4] = FXARGB_G(src_plt[1]);
+ bgr_ptr[5] = FXARGB_R(src_plt[1]);
+ }
+
+ if (pSrcBitmap->IsCmykImage()) {
+ AdobeCMYK_to_sRGB1(FXSYS_GetCValue(src_plt[0]), FXSYS_GetMValue(src_plt[0]),
+ FXSYS_GetYValue(src_plt[0]), FXSYS_GetKValue(src_plt[0]),
+ bgr_ptr[2], bgr_ptr[1], bgr_ptr[0]);
+ AdobeCMYK_to_sRGB1(FXSYS_GetCValue(src_plt[1]), FXSYS_GetMValue(src_plt[1]),
+ FXSYS_GetYValue(src_plt[1]), FXSYS_GetKValue(src_plt[1]),
+ bgr_ptr[5], bgr_ptr[4], bgr_ptr[3]);
+ }
+
+ for (int row = 0; row < height; row++) {
+ uint8_t* dest_scan = dest_buf + row * dest_pitch;
+ const uint8_t* src_scan = pSrcBitmap->GetScanline(src_top + row);
+ for (int col = src_left; col < src_left + width; col++) {
+ if (src_scan[col / 8] & (1 << (7 - col % 8))) {
+ *dest_scan++ = bgr_ptr[3];
+ *dest_scan++ = bgr_ptr[4];
+ *dest_scan = bgr_ptr[5];
+ } else {
+ *dest_scan++ = bgr_ptr[0];
+ *dest_scan++ = bgr_ptr[1];
+ *dest_scan = bgr_ptr[2];
+ }
+ dest_scan += comps - 2;
+ }
+ }
+ return true;
+}
+
+bool ConvertBuffer_8bppPlt2Rgb(FXDIB_Format dst_format,
+ uint8_t* dest_buf,
+ int dest_pitch,
+ int width,
+ int height,
+ const CFX_RetainPtr<CFX_DIBSource>& pSrcBitmap,
+ int src_left,
+ int src_top) {
+ int comps = (dst_format & 0xff) / 8;
+ uint32_t* src_plt = pSrcBitmap->GetPalette();
+ uint32_t plt[256];
+ uint8_t* bgr_ptr = reinterpret_cast<uint8_t*>(plt);
+ if (!pSrcBitmap->IsCmykImage()) {
+ for (int i = 0; i < 256; i++) {
+ *bgr_ptr++ = FXARGB_B(src_plt[i]);
+ *bgr_ptr++ = FXARGB_G(src_plt[i]);
+ *bgr_ptr++ = FXARGB_R(src_plt[i]);
+ }
+ bgr_ptr = reinterpret_cast<uint8_t*>(plt);
+ }
+
+ if (pSrcBitmap->IsCmykImage()) {
+ for (int i = 0; i < 256; i++) {
+ AdobeCMYK_to_sRGB1(
+ FXSYS_GetCValue(src_plt[i]), FXSYS_GetMValue(src_plt[i]),
+ FXSYS_GetYValue(src_plt[i]), FXSYS_GetKValue(src_plt[i]), bgr_ptr[2],
+ bgr_ptr[1], bgr_ptr[0]);
+ bgr_ptr += 3;
+ }
+ bgr_ptr = reinterpret_cast<uint8_t*>(plt);
+ }
+
+ for (int row = 0; row < height; row++) {
+ uint8_t* dest_scan = dest_buf + row * dest_pitch;
+ const uint8_t* src_scan = pSrcBitmap->GetScanline(src_top + row) + src_left;
+ for (int col = 0; col < width; col++) {
+ uint8_t* src_pixel = bgr_ptr + 3 * (*src_scan++);
+ *dest_scan++ = *src_pixel++;
+ *dest_scan++ = *src_pixel++;
+ *dest_scan = *src_pixel++;
+ dest_scan += comps - 2;
+ }
+ }
+ return true;
+}
+
+bool ConvertBuffer_24bppRgb2Rgb24(
+ uint8_t* dest_buf,
+ int dest_pitch,
+ int width,
+ int height,
+ const CFX_RetainPtr<CFX_DIBSource>& pSrcBitmap,
+ int src_left,
+ int src_top) {
+ for (int row = 0; row < height; row++) {
+ uint8_t* dest_scan = dest_buf + row * dest_pitch;
+ const uint8_t* src_scan =
+ pSrcBitmap->GetScanline(src_top + row) + src_left * 3;
+ memcpy(dest_scan, src_scan, width * 3);
+ }
+ return true;
+}
+
+bool ConvertBuffer_32bppRgb2Rgb24(
+ uint8_t* dest_buf,
+ int dest_pitch,
+ int width,
+ int height,
+ const CFX_RetainPtr<CFX_DIBSource>& pSrcBitmap,
+ int src_left,
+ int src_top) {
+ for (int row = 0; row < height; row++) {
+ uint8_t* dest_scan = dest_buf + row * dest_pitch;
+ const uint8_t* src_scan =
+ pSrcBitmap->GetScanline(src_top + row) + src_left * 4;
+ for (int col = 0; col < width; col++) {
+ *dest_scan++ = *src_scan++;
+ *dest_scan++ = *src_scan++;
+ *dest_scan++ = *src_scan++;
+ src_scan++;
+ }
+ }
+ return true;
+}
+
+bool ConvertBuffer_Rgb2Rgb32(uint8_t* dest_buf,
+ int dest_pitch,
+ int width,
+ int height,
+ const CFX_RetainPtr<CFX_DIBSource>& pSrcBitmap,
+ int src_left,
+ int src_top) {
+ int comps = pSrcBitmap->GetBPP() / 8;
+ for (int row = 0; row < height; row++) {
+ uint8_t* dest_scan = dest_buf + row * dest_pitch;
+ const uint8_t* src_scan =
+ pSrcBitmap->GetScanline(src_top + row) + src_left * comps;
+ for (int col = 0; col < width; col++) {
+ *dest_scan++ = *src_scan++;
+ *dest_scan++ = *src_scan++;
+ *dest_scan++ = *src_scan++;
+ dest_scan++;
+ src_scan += comps - 3;
+ }
+ }
+ return true;
+}
+
+bool ConvertBuffer_32bppCmyk2Rgb32(
+ uint8_t* dest_buf,
+ int dest_pitch,
+ int width,
+ int height,
+ const CFX_RetainPtr<CFX_DIBSource>& pSrcBitmap,
+ int src_left,
+ int src_top) {
+ for (int row = 0; row < height; row++) {
+ uint8_t* dest_scan = dest_buf + row * dest_pitch;
+ const uint8_t* src_scan =
+ pSrcBitmap->GetScanline(src_top + row) + src_left * 4;
+ for (int col = 0; col < width; col++) {
+ AdobeCMYK_to_sRGB1(src_scan[0], src_scan[1], src_scan[2], src_scan[3],
+ dest_scan[2], dest_scan[1], dest_scan[0]);
+ dest_scan += 4;
+ src_scan += 4;
+ }
+ }
+ return true;
+}
+
+} // namespace
+
CFX_DIBSource::CFX_DIBSource()
: m_Width(0), m_Height(0), m_bpp(0), m_AlphaFlag(0), m_Pitch(0) {}
@@ -57,7 +705,7 @@ CFX_RetainPtr<CFX_DIBitmap> CFX_DIBSource::Clone(const FX_RECT* pClip) const {
}
} else {
int copy_len = (pNewBitmap->GetWidth() * pNewBitmap->GetBPP() + 7) / 8;
- if (m_Pitch < (uint32_t)copy_len)
+ if (m_Pitch < static_cast<uint32_t>(copy_len))
copy_len = m_Pitch;
for (int row = rect.top; row < rect.bottom; row++) {
@@ -137,15 +785,15 @@ int CFX_DIBSource::FindPalette(uint32_t color) const {
ASSERT((GetBPP() == 1 || GetBPP() == 8) && !IsAlphaMask());
if (!m_pPalette) {
if (IsCmykImage()) {
- if (GetBPP() == 1) {
- return ((uint8_t)color == 0xff) ? 0 : 1;
- }
- return 0xff - (uint8_t)color;
+ if (GetBPP() == 1)
+ return (static_cast<uint8_t>(color) == 0xff) ? 0 : 1;
+
+ return 0xff - static_cast<uint8_t>(color);
}
if (GetBPP() == 1) {
- return ((uint8_t)color == 0xff) ? 1 : 0;
+ return (static_cast<uint8_t>(color) == 0xff) ? 1 : 0;
}
- return (uint8_t)color;
+ return static_cast<uint8_t>(color);
}
int palsize = (1 << GetBPP());
for (int i = 0; i < palsize; i++)
@@ -531,3 +1179,135 @@ CFX_RetainPtr<CFX_DIBitmap> CFX_DIBSource::StretchTo(int dest_width,
return storer.Detach();
}
+
+// static
+bool CFX_DIBSource::ConvertBuffer(
+ FXDIB_Format dest_format,
+ uint8_t* dest_buf,
+ int dest_pitch,
+ int width,
+ int height,
+ const CFX_RetainPtr<CFX_DIBSource>& pSrcBitmap,
+ int src_left,
+ int src_top,
+ std::unique_ptr<uint32_t, FxFreeDeleter>* p_pal) {
+ FXDIB_Format src_format = pSrcBitmap->GetFormat();
+ switch (dest_format) {
+ case FXDIB_Invalid:
+ case FXDIB_1bppCmyk:
+ case FXDIB_1bppMask:
+ case FXDIB_1bppRgb:
+ ASSERT(false);
+ return false;
+ case FXDIB_8bppMask: {
+ if ((src_format & 0xff) == 1) {
+ if (pSrcBitmap->GetPalette()) {
+ return ConvertBuffer_1bppPlt2Gray(dest_buf, dest_pitch, width, height,
+ pSrcBitmap, src_left, src_top);
+ }
+ return ConvertBuffer_1bppMask2Gray(dest_buf, dest_pitch, width, height,
+ pSrcBitmap, src_left, src_top);
+ }
+ if ((src_format & 0xff) == 8) {
+ if (pSrcBitmap->GetPalette()) {
+ return ConvertBuffer_8bppPlt2Gray(dest_buf, dest_pitch, width, height,
+ pSrcBitmap, src_left, src_top);
+ }
+ return ConvertBuffer_8bppMask2Gray(dest_buf, dest_pitch, width, height,
+ pSrcBitmap, src_left, src_top);
+ }
+ if ((src_format & 0xff) >= 24) {
+ return ConvertBuffer_RgbOrCmyk2Gray(dest_buf, dest_pitch, width, height,
+ pSrcBitmap, src_left, src_top);
+ }
+ return false;
+ }
+ case FXDIB_8bppRgb:
+ case FXDIB_8bppRgba: {
+ if ((src_format & 0xff) == 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()) {
+ return ConvertBuffer_Plt2PltRgb8(dest_buf, dest_pitch, width, height,
+ pSrcBitmap, src_left, src_top,
+ p_pal->get());
+ }
+ if ((src_format & 0xff) >= 24) {
+ return ConvertBuffer_Rgb2PltRgb8(dest_buf, dest_pitch, width, height,
+ pSrcBitmap, src_left, src_top,
+ p_pal->get());
+ }
+ return false;
+ }
+ case FXDIB_Rgb:
+ case FXDIB_Rgba: {
+ if ((src_format & 0xff) == 1) {
+ if (pSrcBitmap->GetPalette()) {
+ return ConvertBuffer_1bppPlt2Rgb(dest_format, dest_buf, dest_pitch,
+ width, height, pSrcBitmap, src_left,
+ src_top);
+ }
+ return ConvertBuffer_1bppMask2Rgb(dest_format, dest_buf, dest_pitch,
+ width, height, pSrcBitmap, src_left,
+ src_top);
+ }
+ if ((src_format & 0xff) == 8) {
+ if (pSrcBitmap->GetPalette()) {
+ return ConvertBuffer_8bppPlt2Rgb(dest_format, dest_buf, dest_pitch,
+ width, height, pSrcBitmap, src_left,
+ src_top);
+ }
+ return ConvertBuffer_8bppMask2Rgb(dest_format, dest_buf, dest_pitch,
+ width, height, pSrcBitmap, src_left,
+ src_top);
+ }
+ if ((src_format & 0xff) == 24) {
+ return ConvertBuffer_24bppRgb2Rgb24(dest_buf, dest_pitch, width, height,
+ pSrcBitmap, src_left, src_top);
+ }
+ if ((src_format & 0xff) == 32) {
+ return ConvertBuffer_32bppRgb2Rgb24(dest_buf, dest_pitch, width, height,
+ pSrcBitmap, src_left, src_top);
+ }
+ return false;
+ }
+ case FXDIB_Argb:
+ case FXDIB_Rgb32: {
+ if ((src_format & 0xff) == 1) {
+ if (pSrcBitmap->GetPalette()) {
+ return ConvertBuffer_1bppPlt2Rgb(dest_format, dest_buf, dest_pitch,
+ width, height, pSrcBitmap, src_left,
+ src_top);
+ }
+ return ConvertBuffer_1bppMask2Rgb(dest_format, dest_buf, dest_pitch,
+ width, height, pSrcBitmap, src_left,
+ src_top);
+ }
+ if ((src_format & 0xff) == 8) {
+ if (pSrcBitmap->GetPalette()) {
+ return ConvertBuffer_8bppPlt2Rgb(dest_format, dest_buf, dest_pitch,
+ width, height, pSrcBitmap, src_left,
+ src_top);
+ }
+ return ConvertBuffer_8bppMask2Rgb(dest_format, dest_buf, dest_pitch,
+ width, height, pSrcBitmap, src_left,
+ src_top);
+ }
+ if ((src_format & 0xff) >= 24) {
+ if (src_format & 0x0400) {
+ return ConvertBuffer_32bppCmyk2Rgb32(dest_buf, dest_pitch, width,
+ height, pSrcBitmap, src_left,
+ src_top);
+ }
+ return ConvertBuffer_Rgb2Rgb32(dest_buf, dest_pitch, width, height,
+ pSrcBitmap, src_left, src_top);
+ }
+ return false;
+ }
+ default:
+ return false;
+ }
+}
diff --git a/core/fxge/dib/cfx_dibsource.h b/core/fxge/dib/cfx_dibsource.h
index 76f7009502..97af196677 100644
--- a/core/fxge/dib/cfx_dibsource.h
+++ b/core/fxge/dib/cfx_dibsource.h
@@ -12,6 +12,7 @@
#include "core/fxcrt/cfx_retain_ptr.h"
#include "core/fxcrt/fx_basic.h"
#include "core/fxcrt/fx_coordinates.h"
+#include "core/fxge/fx_dib.h"
enum FXDIB_Channel {
FXDIB_Red = 1,
@@ -24,48 +25,6 @@ enum FXDIB_Channel {
FXDIB_Alpha
};
-enum FXDIB_Format {
- FXDIB_Invalid = 0,
- FXDIB_1bppMask = 0x101,
- FXDIB_1bppRgb = 0x001,
- FXDIB_1bppCmyk = 0x401,
- FXDIB_8bppMask = 0x108,
- FXDIB_8bppRgb = 0x008,
- FXDIB_8bppRgba = 0x208,
- FXDIB_8bppCmyk = 0x408,
- FXDIB_8bppCmyka = 0x608,
- FXDIB_Rgb = 0x018,
- FXDIB_Rgba = 0x218,
- FXDIB_Rgb32 = 0x020,
- FXDIB_Argb = 0x220,
- FXDIB_Cmyk = 0x420,
- FXDIB_Cmyka = 0x620,
-};
-
-#define FXDIB_DOWNSAMPLE 0x04
-#define FXDIB_INTERPOL 0x20
-#define FXDIB_BICUBIC_INTERPOL 0x80
-#define FXDIB_NOSMOOTH 0x100
-#define FXDIB_BLEND_NORMAL 0
-#define FXDIB_BLEND_MULTIPLY 1
-#define FXDIB_BLEND_SCREEN 2
-#define FXDIB_BLEND_OVERLAY 3
-#define FXDIB_BLEND_DARKEN 4
-#define FXDIB_BLEND_LIGHTEN 5
-
-#define FXDIB_BLEND_COLORDODGE 6
-#define FXDIB_BLEND_COLORBURN 7
-#define FXDIB_BLEND_HARDLIGHT 8
-#define FXDIB_BLEND_SOFTLIGHT 9
-#define FXDIB_BLEND_DIFFERENCE 10
-#define FXDIB_BLEND_EXCLUSION 11
-#define FXDIB_BLEND_NONSEPARABLE 21
-#define FXDIB_BLEND_HUE 21
-#define FXDIB_BLEND_SATURATION 22
-#define FXDIB_BLEND_COLOR 23
-#define FXDIB_BLEND_LUMINOSITY 24
-#define FXDIB_BLEND_UNSUPPORTED -1
-
class CFX_ClipRgn;
class CFX_DIBitmap;
@@ -159,6 +118,16 @@ class CFX_DIBSource : public CFX_Retainable {
protected:
CFX_DIBSource();
+ static bool ConvertBuffer(FXDIB_Format dest_format,
+ uint8_t* dest_buf,
+ int dest_pitch,
+ int width,
+ int height,
+ const CFX_RetainPtr<CFX_DIBSource>& pSrcBitmap,
+ int src_left,
+ int src_top,
+ std::unique_ptr<uint32_t, FxFreeDeleter>* pal);
+
void BuildPalette();
bool BuildAlphaMask();
int FindPalette(uint32_t color) const;
diff --git a/core/fxge/dib/cfx_imagestretcher.cpp b/core/fxge/dib/cfx_imagestretcher.cpp
index 799b44432f..94c107b4a3 100644
--- a/core/fxge/dib/cfx_imagestretcher.cpp
+++ b/core/fxge/dib/cfx_imagestretcher.cpp
@@ -8,6 +8,8 @@
#include <climits>
+#include "core/fxge/dib/cfx_dibitmap.h"
+#include "core/fxge/dib/cfx_dibsource.h"
#include "core/fxge/dib/dib_int.h"
#include "core/fxge/fx_dib.h"
#include "third_party/base/ptr_util.h"
@@ -30,6 +32,13 @@ FXDIB_Format GetStretchedFormat(const CFX_DIBSource& src) {
return format;
}
+void CmykDecode(uint32_t cmyk, int& c, int& m, int& y, int& k) {
+ c = FXSYS_GetCValue(cmyk);
+ m = FXSYS_GetMValue(cmyk);
+ y = FXSYS_GetYValue(cmyk);
+ k = FXSYS_GetKValue(cmyk);
+}
+
} // namespace
CFX_ImageStretcher::CFX_ImageStretcher(
diff --git a/core/fxge/dib/cfx_imagestretcher.h b/core/fxge/dib/cfx_imagestretcher.h
index 785ef9b6cc..63863cd1a9 100644
--- a/core/fxge/dib/cfx_imagestretcher.h
+++ b/core/fxge/dib/cfx_imagestretcher.h
@@ -11,6 +11,7 @@
#include "core/fxcrt/cfx_retain_ptr.h"
#include "core/fxcrt/fx_coordinates.h"
+#include "core/fxge/dib/ifx_scanlinecomposer.h"
#include "core/fxge/fx_dib.h"
class CFX_DIBSource;
diff --git a/core/fxge/dib/cfx_scanlinecompositor.cpp b/core/fxge/dib/cfx_scanlinecompositor.cpp
index ff7dd06c3e..f8f0b14090 100644
--- a/core/fxge/dib/cfx_scanlinecompositor.cpp
+++ b/core/fxge/dib/cfx_scanlinecompositor.cpp
@@ -11,6 +11,15 @@
#include "core/fxcodec/fx_codec.h"
#include "core/fxge/cfx_gemodule.h"
+#define FX_CCOLOR(val) (255 - (val))
+#define FXDIB_ALPHA_UNION(dest, src) ((dest) + (src) - (dest) * (src) / 255)
+#define FXARGB_COPY(dest, src) \
+ *(dest) = *(src), *((dest) + 1) = *((src) + 1), \
+ *((dest) + 2) = *((src) + 2), *((dest) + 3) = *((src) + 3)
+#define FXARGB_RGBORDERCOPY(dest, src) \
+ *((dest) + 3) = *((src) + 3), *(dest) = *((src) + 2), \
+ *((dest) + 1) = *((src) + 1), *((dest) + 2) = *((src))
+
namespace {
const uint8_t color_sqrt[256] = {
diff --git a/core/fxge/dib/fx_dib_convert.cpp b/core/fxge/dib/fx_dib_convert.cpp
deleted file mode 100644
index 17eae7e3af..0000000000
--- a/core/fxge/dib/fx_dib_convert.cpp
+++ /dev/null
@@ -1,792 +0,0 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-
-#include <memory>
-#include <utility>
-
-#include "core/fxcodec/fx_codec.h"
-#include "core/fxcrt/cfx_maybe_owned.h"
-#include "core/fxge/fx_dib.h"
-#include "third_party/base/ptr_util.h"
-
-namespace {
-
-class CFX_Palette {
- public:
- CFX_Palette();
- ~CFX_Palette();
-
- bool BuildPalette(const CFX_RetainPtr<CFX_DIBSource>& pBitmap);
- uint32_t* GetPalette() const { return m_pPalette; }
- uint32_t* GetColorLut() const { return m_cLut; }
- uint32_t* GetAmountLut() const { return m_aLut; }
- int32_t Getlut() const { return m_lut; }
-
- protected:
- uint32_t* m_pPalette;
- uint32_t* m_cLut;
- uint32_t* m_aLut;
- int m_lut;
-};
-int _Partition(uint32_t* alut, uint32_t* clut, int l, int r) {
- uint32_t p_a = alut[l];
- uint32_t p_c = clut[l];
- while (l < r) {
- while (l < r && alut[r] >= p_a) {
- r--;
- }
- if (l < r) {
- alut[l] = alut[r];
- clut[l++] = clut[r];
- }
- while (l < r && alut[l] <= p_a) {
- l++;
- }
- if (l < r) {
- alut[r] = alut[l];
- clut[r--] = clut[l];
- }
- }
- alut[l] = p_a;
- clut[l] = p_c;
- return l;
-}
-
-void _Qsort(uint32_t* alut, uint32_t* clut, int l, int r) {
- if (l < r) {
- int pI = _Partition(alut, clut, l, r);
- _Qsort(alut, clut, l, pI - 1);
- _Qsort(alut, clut, pI + 1, r);
- }
-}
-
-void _ColorDecode(uint32_t pal_v, uint8_t& r, uint8_t& g, uint8_t& b) {
- r = (uint8_t)((pal_v & 0xf00) >> 4);
- g = (uint8_t)(pal_v & 0x0f0);
- b = (uint8_t)((pal_v & 0x00f) << 4);
-}
-
-void _Obtain_Pal(uint32_t* aLut,
- uint32_t* cLut,
- uint32_t* dest_pal,
- uint32_t lut) {
- uint32_t lut_1 = lut - 1;
- for (int row = 0; row < 256; row++) {
- int lut_offset = lut_1 - row;
- if (lut_offset < 0) {
- lut_offset += 256;
- }
- uint32_t color = cLut[lut_offset];
- uint8_t r;
- uint8_t g;
- uint8_t b;
- _ColorDecode(color, r, g, b);
- dest_pal[row] = ((uint32_t)r << 16) | ((uint32_t)g << 8) | b | 0xff000000;
- aLut[lut_offset] = row;
- }
-}
-
-CFX_Palette::CFX_Palette() {
- m_pPalette = nullptr;
- m_cLut = nullptr;
- m_aLut = nullptr;
- m_lut = 0;
-}
-
-CFX_Palette::~CFX_Palette() {
- FX_Free(m_pPalette);
- FX_Free(m_cLut);
- FX_Free(m_aLut);
- m_lut = 0;
-}
-
-bool CFX_Palette::BuildPalette(const CFX_RetainPtr<CFX_DIBSource>& pBitmap) {
- if (!pBitmap) {
- return false;
- }
- FX_Free(m_pPalette);
- m_pPalette = FX_Alloc(uint32_t, 256);
- int bpp = pBitmap->GetBPP() / 8;
- int width = pBitmap->GetWidth();
- int height = pBitmap->GetHeight();
- FX_Free(m_cLut);
- m_cLut = nullptr;
- FX_Free(m_aLut);
- m_aLut = nullptr;
- m_cLut = FX_Alloc(uint32_t, 4096);
- m_aLut = FX_Alloc(uint32_t, 4096);
- int row, col;
- m_lut = 0;
- for (row = 0; row < height; row++) {
- uint8_t* scan_line = (uint8_t*)pBitmap->GetScanline(row);
- for (col = 0; col < width; col++) {
- uint8_t* src_port = scan_line + col * bpp;
- uint32_t b = src_port[0] & 0xf0;
- uint32_t g = src_port[1] & 0xf0;
- uint32_t r = src_port[2] & 0xf0;
- uint32_t index = (r << 4) + g + (b >> 4);
- m_aLut[index]++;
- }
- }
- for (row = 0; row < 4096; row++) {
- if (m_aLut[row] != 0) {
- m_aLut[m_lut] = m_aLut[row];
- m_cLut[m_lut] = row;
- m_lut++;
- }
- }
- _Qsort(m_aLut, m_cLut, 0, m_lut - 1);
- _Obtain_Pal(m_aLut, m_cLut, m_pPalette, m_lut);
- return true;
-}
-
-bool ConvertBuffer_1bppMask2Gray(uint8_t* dest_buf,
- int dest_pitch,
- int width,
- int height,
- const CFX_RetainPtr<CFX_DIBSource>& pSrcBitmap,
- int src_left,
- int src_top) {
- uint8_t set_gray, reset_gray;
- set_gray = 0xff;
- reset_gray = 0x00;
- for (int row = 0; row < height; row++) {
- uint8_t* dest_scan = dest_buf + row * dest_pitch;
- memset(dest_scan, reset_gray, width);
- const uint8_t* src_scan = pSrcBitmap->GetScanline(src_top + row);
- for (int col = src_left; col < src_left + width; col++) {
- if (src_scan[col / 8] & (1 << (7 - col % 8))) {
- *dest_scan = set_gray;
- }
- dest_scan++;
- }
- }
- return true;
-}
-
-bool ConvertBuffer_8bppMask2Gray(uint8_t* dest_buf,
- int dest_pitch,
- int width,
- int height,
- const CFX_RetainPtr<CFX_DIBSource>& pSrcBitmap,
- int src_left,
- int src_top) {
- for (int row = 0; row < height; row++) {
- uint8_t* dest_scan = dest_buf + row * dest_pitch;
- const uint8_t* src_scan = pSrcBitmap->GetScanline(src_top + row) + src_left;
- memcpy(dest_scan, src_scan, width);
- }
- return true;
-}
-
-bool ConvertBuffer_1bppPlt2Gray(uint8_t* dest_buf,
- int dest_pitch,
- int width,
- int height,
- const CFX_RetainPtr<CFX_DIBSource>& pSrcBitmap,
- int src_left,
- int src_top) {
- uint32_t* src_plt = pSrcBitmap->GetPalette();
- uint8_t gray[2];
- uint8_t reset_r;
- uint8_t reset_g;
- uint8_t reset_b;
- uint8_t set_r;
- uint8_t set_g;
- uint8_t set_b;
- if (pSrcBitmap->IsCmykImage()) {
- AdobeCMYK_to_sRGB1(FXSYS_GetCValue(src_plt[0]), FXSYS_GetMValue(src_plt[0]),
- FXSYS_GetYValue(src_plt[0]), FXSYS_GetKValue(src_plt[0]),
- reset_r, reset_g, reset_b);
- AdobeCMYK_to_sRGB1(FXSYS_GetCValue(src_plt[1]), FXSYS_GetMValue(src_plt[1]),
- FXSYS_GetYValue(src_plt[1]), FXSYS_GetKValue(src_plt[1]),
- set_r, set_g, set_b);
- } else {
- reset_r = FXARGB_R(src_plt[0]);
- reset_g = FXARGB_G(src_plt[0]);
- reset_b = FXARGB_B(src_plt[0]);
- set_r = FXARGB_R(src_plt[1]);
- set_g = FXARGB_G(src_plt[1]);
- set_b = FXARGB_B(src_plt[1]);
- }
- gray[0] = FXRGB2GRAY(reset_r, reset_g, reset_b);
- gray[1] = FXRGB2GRAY(set_r, set_g, set_b);
-
- for (int row = 0; row < height; row++) {
- uint8_t* dest_scan = dest_buf + row * dest_pitch;
- memset(dest_scan, gray[0], width);
- const uint8_t* src_scan = pSrcBitmap->GetScanline(src_top + row);
- for (int col = src_left; col < src_left + width; col++) {
- if (src_scan[col / 8] & (1 << (7 - col % 8))) {
- *dest_scan = gray[1];
- }
- dest_scan++;
- }
- }
- return true;
-}
-
-bool ConvertBuffer_8bppPlt2Gray(uint8_t* dest_buf,
- int dest_pitch,
- int width,
- int height,
- const CFX_RetainPtr<CFX_DIBSource>& pSrcBitmap,
- int src_left,
- int src_top) {
- uint32_t* src_plt = pSrcBitmap->GetPalette();
- uint8_t gray[256];
- if (pSrcBitmap->IsCmykImage()) {
- uint8_t r;
- uint8_t g;
- uint8_t b;
- for (size_t i = 0; i < FX_ArraySize(gray); i++) {
- AdobeCMYK_to_sRGB1(
- FXSYS_GetCValue(src_plt[i]), FXSYS_GetMValue(src_plt[i]),
- FXSYS_GetYValue(src_plt[i]), FXSYS_GetKValue(src_plt[i]), r, g, b);
- gray[i] = FXRGB2GRAY(r, g, b);
- }
- } else {
- for (size_t i = 0; i < FX_ArraySize(gray); i++) {
- gray[i] = FXRGB2GRAY(FXARGB_R(src_plt[i]), FXARGB_G(src_plt[i]),
- FXARGB_B(src_plt[i]));
- }
- }
-
- for (int row = 0; row < height; row++) {
- uint8_t* dest_scan = dest_buf + row * dest_pitch;
- const uint8_t* src_scan = pSrcBitmap->GetScanline(src_top + row) + src_left;
- for (int col = 0; col < width; col++) {
- *dest_scan++ = gray[*src_scan++];
- }
- }
- return true;
-}
-
-bool ConvertBuffer_RgbOrCmyk2Gray(
- uint8_t* dest_buf,
- int dest_pitch,
- int width,
- int height,
- const CFX_RetainPtr<CFX_DIBSource>& pSrcBitmap,
- int src_left,
- int src_top) {
- int Bpp = pSrcBitmap->GetBPP() / 8;
- if (pSrcBitmap->IsCmykImage()) {
- for (int row = 0; row < height; row++) {
- uint8_t* dest_scan = dest_buf + row * dest_pitch;
- const uint8_t* src_scan =
- pSrcBitmap->GetScanline(src_top + row) + src_left * 4;
- for (int col = 0; col < width; col++) {
- uint8_t r, g, b;
- AdobeCMYK_to_sRGB1(FXSYS_GetCValue((uint32_t)src_scan[0]),
- FXSYS_GetMValue((uint32_t)src_scan[1]),
- FXSYS_GetYValue((uint32_t)src_scan[2]),
- FXSYS_GetKValue((uint32_t)src_scan[3]), r, g, b);
- *dest_scan++ = FXRGB2GRAY(r, g, b);
- src_scan += 4;
- }
- }
- } else {
- for (int row = 0; row < height; row++) {
- uint8_t* dest_scan = dest_buf + row * dest_pitch;
- const uint8_t* src_scan =
- pSrcBitmap->GetScanline(src_top + row) + src_left * Bpp;
- for (int col = 0; col < width; col++) {
- *dest_scan++ = FXRGB2GRAY(src_scan[2], src_scan[1], src_scan[0]);
- src_scan += Bpp;
- }
- }
- }
- return true;
-}
-
-void ConvertBuffer_IndexCopy(uint8_t* dest_buf,
- int dest_pitch,
- int width,
- int height,
- const CFX_RetainPtr<CFX_DIBSource>& pSrcBitmap,
- int src_left,
- int src_top) {
- if (pSrcBitmap->GetBPP() == 1) {
- for (int row = 0; row < height; row++) {
- uint8_t* dest_scan = dest_buf + row * dest_pitch;
- memset(dest_scan, 0, width);
- const uint8_t* src_scan = pSrcBitmap->GetScanline(src_top + row);
- for (int col = src_left; col < src_left + width; col++) {
- if (src_scan[col / 8] & (1 << (7 - col % 8))) {
- *dest_scan = 1;
- }
- dest_scan++;
- }
- }
- } else {
- for (int row = 0; row < height; row++) {
- uint8_t* dest_scan = dest_buf + row * dest_pitch;
- const uint8_t* src_scan =
- pSrcBitmap->GetScanline(src_top + row) + src_left;
- memcpy(dest_scan, src_scan, width);
- }
- }
-}
-
-bool ConvertBuffer_Plt2PltRgb8(uint8_t* dest_buf,
- int dest_pitch,
- int width,
- int height,
- const CFX_RetainPtr<CFX_DIBSource>& pSrcBitmap,
- int src_left,
- int src_top,
- uint32_t* dst_plt) {
- ConvertBuffer_IndexCopy(dest_buf, dest_pitch, width, height, pSrcBitmap,
- src_left, src_top);
- uint32_t* src_plt = pSrcBitmap->GetPalette();
- int plt_size = pSrcBitmap->GetPaletteSize();
- if (pSrcBitmap->IsCmykImage()) {
- for (int i = 0; i < plt_size; i++) {
- uint8_t r;
- uint8_t g;
- uint8_t b;
- AdobeCMYK_to_sRGB1(
- FXSYS_GetCValue(src_plt[i]), FXSYS_GetMValue(src_plt[i]),
- FXSYS_GetYValue(src_plt[i]), FXSYS_GetKValue(src_plt[i]), r, g, b);
- dst_plt[i] = FXARGB_MAKE(0xff, r, g, b);
- }
- } else {
- memcpy(dst_plt, src_plt, plt_size * 4);
- }
- return true;
-}
-
-bool ConvertBuffer_Rgb2PltRgb8(uint8_t* dest_buf,
- int dest_pitch,
- int width,
- int height,
- const CFX_RetainPtr<CFX_DIBSource>& pSrcBitmap,
- int src_left,
- int src_top,
- uint32_t* dst_plt) {
- int bpp = pSrcBitmap->GetBPP() / 8;
- CFX_Palette palette;
- palette.BuildPalette(pSrcBitmap);
- uint32_t* cLut = palette.GetColorLut();
- uint32_t* aLut = palette.GetAmountLut();
- if (!cLut || !aLut) {
- return false;
- }
- int lut = palette.Getlut();
- uint32_t* pPalette = palette.GetPalette();
- if (lut > 256) {
- int err, min_err;
- int lut_256 = lut - 256;
- for (int row = 0; row < lut_256; row++) {
- min_err = 1000000;
- uint8_t r, g, b;
- _ColorDecode(cLut[row], r, g, b);
- int clrindex = 0;
- for (int col = 0; col < 256; col++) {
- uint32_t p_color = *(pPalette + col);
- int d_r = r - (uint8_t)(p_color >> 16);
- int d_g = g - (uint8_t)(p_color >> 8);
- int d_b = b - (uint8_t)(p_color);
- err = d_r * d_r + d_g * d_g + d_b * d_b;
- if (err < min_err) {
- min_err = err;
- clrindex = col;
- }
- }
- aLut[row] = clrindex;
- }
- }
- int32_t lut_1 = lut - 1;
- for (int row = 0; row < height; row++) {
- uint8_t* src_scan =
- (uint8_t*)pSrcBitmap->GetScanline(src_top + row) + src_left;
- uint8_t* dest_scan = dest_buf + row * dest_pitch;
- for (int col = 0; col < width; col++) {
- uint8_t* src_port = src_scan + col * bpp;
- int r = src_port[2] & 0xf0;
- int g = src_port[1] & 0xf0;
- int b = src_port[0] & 0xf0;
- uint32_t clrindex = (r << 4) + g + (b >> 4);
- for (int i = lut_1; i >= 0; i--)
- if (clrindex == cLut[i]) {
- *(dest_scan + col) = (uint8_t)(aLut[i]);
- break;
- }
- }
- }
- memcpy(dst_plt, pPalette, sizeof(uint32_t) * 256);
- return true;
-}
-
-bool ConvertBuffer_1bppMask2Rgb(FXDIB_Format dst_format,
- uint8_t* dest_buf,
- int dest_pitch,
- int width,
- int height,
- const CFX_RetainPtr<CFX_DIBSource>& pSrcBitmap,
- int src_left,
- int src_top) {
- int comps = (dst_format & 0xff) / 8;
- uint8_t set_gray, reset_gray;
- set_gray = 0xff;
- reset_gray = 0x00;
- for (int row = 0; row < height; row++) {
- uint8_t* dest_scan = dest_buf + row * dest_pitch;
- const uint8_t* src_scan = pSrcBitmap->GetScanline(src_top + row);
- for (int col = src_left; col < src_left + width; col++) {
- if (src_scan[col / 8] & (1 << (7 - col % 8))) {
- dest_scan[0] = set_gray;
- dest_scan[1] = set_gray;
- dest_scan[2] = set_gray;
- } else {
- dest_scan[0] = reset_gray;
- dest_scan[1] = reset_gray;
- dest_scan[2] = reset_gray;
- }
- dest_scan += comps;
- }
- }
- return true;
-}
-
-bool ConvertBuffer_8bppMask2Rgb(FXDIB_Format dst_format,
- uint8_t* dest_buf,
- int dest_pitch,
- int width,
- int height,
- const CFX_RetainPtr<CFX_DIBSource>& pSrcBitmap,
- int src_left,
- int src_top) {
- int comps = (dst_format & 0xff) / 8;
- for (int row = 0; row < height; row++) {
- uint8_t* dest_scan = dest_buf + row * dest_pitch;
- const uint8_t* src_scan = pSrcBitmap->GetScanline(src_top + row) + src_left;
- uint8_t src_pixel;
- for (int col = 0; col < width; col++) {
- src_pixel = *src_scan++;
- *dest_scan++ = src_pixel;
- *dest_scan++ = src_pixel;
- *dest_scan = src_pixel;
- dest_scan += comps - 2;
- }
- }
- return true;
-}
-
-bool ConvertBuffer_1bppPlt2Rgb(FXDIB_Format dst_format,
- uint8_t* dest_buf,
- int dest_pitch,
- int width,
- int height,
- const CFX_RetainPtr<CFX_DIBSource>& pSrcBitmap,
- int src_left,
- int src_top) {
- int comps = (dst_format & 0xff) / 8;
- uint32_t* src_plt = pSrcBitmap->GetPalette();
- uint32_t plt[2];
- uint8_t* bgr_ptr = (uint8_t*)plt;
- if (pSrcBitmap->IsCmykImage()) {
- plt[0] = FXCMYK_TODIB(src_plt[0]);
- plt[1] = FXCMYK_TODIB(src_plt[1]);
- } else {
- bgr_ptr[0] = FXARGB_B(src_plt[0]);
- bgr_ptr[1] = FXARGB_G(src_plt[0]);
- bgr_ptr[2] = FXARGB_R(src_plt[0]);
- bgr_ptr[3] = FXARGB_B(src_plt[1]);
- bgr_ptr[4] = FXARGB_G(src_plt[1]);
- bgr_ptr[5] = FXARGB_R(src_plt[1]);
- }
-
- if (pSrcBitmap->IsCmykImage()) {
- AdobeCMYK_to_sRGB1(FXSYS_GetCValue(src_plt[0]), FXSYS_GetMValue(src_plt[0]),
- FXSYS_GetYValue(src_plt[0]), FXSYS_GetKValue(src_plt[0]),
- bgr_ptr[2], bgr_ptr[1], bgr_ptr[0]);
- AdobeCMYK_to_sRGB1(FXSYS_GetCValue(src_plt[1]), FXSYS_GetMValue(src_plt[1]),
- FXSYS_GetYValue(src_plt[1]), FXSYS_GetKValue(src_plt[1]),
- bgr_ptr[5], bgr_ptr[4], bgr_ptr[3]);
- }
-
- for (int row = 0; row < height; row++) {
- uint8_t* dest_scan = dest_buf + row * dest_pitch;
- const uint8_t* src_scan = pSrcBitmap->GetScanline(src_top + row);
- for (int col = src_left; col < src_left + width; col++) {
- if (src_scan[col / 8] & (1 << (7 - col % 8))) {
- *dest_scan++ = bgr_ptr[3];
- *dest_scan++ = bgr_ptr[4];
- *dest_scan = bgr_ptr[5];
- } else {
- *dest_scan++ = bgr_ptr[0];
- *dest_scan++ = bgr_ptr[1];
- *dest_scan = bgr_ptr[2];
- }
- dest_scan += comps - 2;
- }
- }
- return true;
-}
-
-bool ConvertBuffer_8bppPlt2Rgb(FXDIB_Format dst_format,
- uint8_t* dest_buf,
- int dest_pitch,
- int width,
- int height,
- const CFX_RetainPtr<CFX_DIBSource>& pSrcBitmap,
- int src_left,
- int src_top) {
- int comps = (dst_format & 0xff) / 8;
- uint32_t* src_plt = pSrcBitmap->GetPalette();
- uint32_t plt[256];
- uint8_t* bgr_ptr = (uint8_t*)plt;
- if (!pSrcBitmap->IsCmykImage()) {
- for (int i = 0; i < 256; i++) {
- *bgr_ptr++ = FXARGB_B(src_plt[i]);
- *bgr_ptr++ = FXARGB_G(src_plt[i]);
- *bgr_ptr++ = FXARGB_R(src_plt[i]);
- }
- bgr_ptr = (uint8_t*)plt;
- }
-
- if (pSrcBitmap->IsCmykImage()) {
- for (int i = 0; i < 256; i++) {
- AdobeCMYK_to_sRGB1(
- FXSYS_GetCValue(src_plt[i]), FXSYS_GetMValue(src_plt[i]),
- FXSYS_GetYValue(src_plt[i]), FXSYS_GetKValue(src_plt[i]), bgr_ptr[2],
- bgr_ptr[1], bgr_ptr[0]);
- bgr_ptr += 3;
- }
- bgr_ptr = (uint8_t*)plt;
- }
-
- for (int row = 0; row < height; row++) {
- uint8_t* dest_scan = dest_buf + row * dest_pitch;
- const uint8_t* src_scan = pSrcBitmap->GetScanline(src_top + row) + src_left;
- for (int col = 0; col < width; col++) {
- uint8_t* src_pixel = bgr_ptr + 3 * (*src_scan++);
- *dest_scan++ = *src_pixel++;
- *dest_scan++ = *src_pixel++;
- *dest_scan = *src_pixel++;
- dest_scan += comps - 2;
- }
- }
- return true;
-}
-
-bool ConvertBuffer_24bppRgb2Rgb24(
- uint8_t* dest_buf,
- int dest_pitch,
- int width,
- int height,
- const CFX_RetainPtr<CFX_DIBSource>& pSrcBitmap,
- int src_left,
- int src_top) {
- for (int row = 0; row < height; row++) {
- uint8_t* dest_scan = dest_buf + row * dest_pitch;
- const uint8_t* src_scan =
- pSrcBitmap->GetScanline(src_top + row) + src_left * 3;
- memcpy(dest_scan, src_scan, width * 3);
- }
- return true;
-}
-
-bool ConvertBuffer_32bppRgb2Rgb24(
- uint8_t* dest_buf,
- int dest_pitch,
- int width,
- int height,
- const CFX_RetainPtr<CFX_DIBSource>& pSrcBitmap,
- int src_left,
- int src_top) {
- for (int row = 0; row < height; row++) {
- uint8_t* dest_scan = dest_buf + row * dest_pitch;
- const uint8_t* src_scan =
- pSrcBitmap->GetScanline(src_top + row) + src_left * 4;
- for (int col = 0; col < width; col++) {
- *dest_scan++ = *src_scan++;
- *dest_scan++ = *src_scan++;
- *dest_scan++ = *src_scan++;
- src_scan++;
- }
- }
- return true;
-}
-
-bool ConvertBuffer_Rgb2Rgb32(uint8_t* dest_buf,
- int dest_pitch,
- int width,
- int height,
- const CFX_RetainPtr<CFX_DIBSource>& pSrcBitmap,
- int src_left,
- int src_top) {
- int comps = pSrcBitmap->GetBPP() / 8;
- for (int row = 0; row < height; row++) {
- uint8_t* dest_scan = dest_buf + row * dest_pitch;
- const uint8_t* src_scan =
- pSrcBitmap->GetScanline(src_top + row) + src_left * comps;
- for (int col = 0; col < width; col++) {
- *dest_scan++ = *src_scan++;
- *dest_scan++ = *src_scan++;
- *dest_scan++ = *src_scan++;
- dest_scan++;
- src_scan += comps - 3;
- }
- }
- return true;
-}
-
-bool ConvertBuffer_32bppCmyk2Rgb32(
- uint8_t* dest_buf,
- int dest_pitch,
- int width,
- int height,
- const CFX_RetainPtr<CFX_DIBSource>& pSrcBitmap,
- int src_left,
- int src_top) {
- for (int row = 0; row < height; row++) {
- uint8_t* dest_scan = dest_buf + row * dest_pitch;
- const uint8_t* src_scan =
- pSrcBitmap->GetScanline(src_top + row) + src_left * 4;
- for (int col = 0; col < width; col++) {
- AdobeCMYK_to_sRGB1(src_scan[0], src_scan[1], src_scan[2], src_scan[3],
- dest_scan[2], dest_scan[1], dest_scan[0]);
- dest_scan += 4;
- src_scan += 4;
- }
- }
- return true;
-}
-
-} // namespace
-
-bool ConvertBuffer(FXDIB_Format dest_format,
- uint8_t* dest_buf,
- int dest_pitch,
- int width,
- int height,
- const CFX_RetainPtr<CFX_DIBSource>& pSrcBitmap,
- int src_left,
- int src_top,
- std::unique_ptr<uint32_t, FxFreeDeleter>* p_pal) {
- FXDIB_Format src_format = pSrcBitmap->GetFormat();
- switch (dest_format) {
- case FXDIB_Invalid:
- case FXDIB_1bppCmyk:
- case FXDIB_1bppMask:
- case FXDIB_1bppRgb:
- ASSERT(false);
- return false;
- case FXDIB_8bppMask: {
- if ((src_format & 0xff) == 1) {
- if (pSrcBitmap->GetPalette()) {
- return ConvertBuffer_1bppPlt2Gray(dest_buf, dest_pitch, width, height,
- pSrcBitmap, src_left, src_top);
- }
- return ConvertBuffer_1bppMask2Gray(dest_buf, dest_pitch, width, height,
- pSrcBitmap, src_left, src_top);
- }
- if ((src_format & 0xff) == 8) {
- if (pSrcBitmap->GetPalette()) {
- return ConvertBuffer_8bppPlt2Gray(dest_buf, dest_pitch, width, height,
- pSrcBitmap, src_left, src_top);
- }
- return ConvertBuffer_8bppMask2Gray(dest_buf, dest_pitch, width, height,
- pSrcBitmap, src_left, src_top);
- }
- if ((src_format & 0xff) >= 24) {
- return ConvertBuffer_RgbOrCmyk2Gray(dest_buf, dest_pitch, width, height,
- pSrcBitmap, src_left, src_top);
- }
- return false;
- }
- case FXDIB_8bppRgb:
- case FXDIB_8bppRgba: {
- if ((src_format & 0xff) == 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()) {
- return ConvertBuffer_Plt2PltRgb8(dest_buf, dest_pitch, width, height,
- pSrcBitmap, src_left, src_top,
- p_pal->get());
- }
- if ((src_format & 0xff) >= 24) {
- return ConvertBuffer_Rgb2PltRgb8(dest_buf, dest_pitch, width, height,
- pSrcBitmap, src_left, src_top,
- p_pal->get());
- }
- return false;
- }
- case FXDIB_Rgb:
- case FXDIB_Rgba: {
- if ((src_format & 0xff) == 1) {
- if (pSrcBitmap->GetPalette()) {
- return ConvertBuffer_1bppPlt2Rgb(dest_format, dest_buf, dest_pitch,
- width, height, pSrcBitmap, src_left,
- src_top);
- }
- return ConvertBuffer_1bppMask2Rgb(dest_format, dest_buf, dest_pitch,
- width, height, pSrcBitmap, src_left,
- src_top);
- }
- if ((src_format & 0xff) == 8) {
- if (pSrcBitmap->GetPalette()) {
- return ConvertBuffer_8bppPlt2Rgb(dest_format, dest_buf, dest_pitch,
- width, height, pSrcBitmap, src_left,
- src_top);
- }
- return ConvertBuffer_8bppMask2Rgb(dest_format, dest_buf, dest_pitch,
- width, height, pSrcBitmap, src_left,
- src_top);
- }
- if ((src_format & 0xff) == 24) {
- return ConvertBuffer_24bppRgb2Rgb24(dest_buf, dest_pitch, width, height,
- pSrcBitmap, src_left, src_top);
- }
- if ((src_format & 0xff) == 32) {
- return ConvertBuffer_32bppRgb2Rgb24(dest_buf, dest_pitch, width, height,
- pSrcBitmap, src_left, src_top);
- }
- return false;
- }
- case FXDIB_Argb:
- case FXDIB_Rgb32: {
- if ((src_format & 0xff) == 1) {
- if (pSrcBitmap->GetPalette()) {
- return ConvertBuffer_1bppPlt2Rgb(dest_format, dest_buf, dest_pitch,
- width, height, pSrcBitmap, src_left,
- src_top);
- }
- return ConvertBuffer_1bppMask2Rgb(dest_format, dest_buf, dest_pitch,
- width, height, pSrcBitmap, src_left,
- src_top);
- }
- if ((src_format & 0xff) == 8) {
- if (pSrcBitmap->GetPalette()) {
- return ConvertBuffer_8bppPlt2Rgb(dest_format, dest_buf, dest_pitch,
- width, height, pSrcBitmap, src_left,
- src_top);
- }
- return ConvertBuffer_8bppMask2Rgb(dest_format, dest_buf, dest_pitch,
- width, height, pSrcBitmap, src_left,
- src_top);
- }
- if ((src_format & 0xff) >= 24) {
- if (src_format & 0x0400) {
- return ConvertBuffer_32bppCmyk2Rgb32(dest_buf, dest_pitch, width,
- height, pSrcBitmap, src_left,
- src_top);
- }
- return ConvertBuffer_Rgb2Rgb32(dest_buf, dest_pitch, width, height,
- pSrcBitmap, src_left, src_top);
- }
- return false;
- }
- default:
- return false;
- }
-}
diff --git a/core/fxge/dib/fx_dib_engine.cpp b/core/fxge/dib/fx_dib_engine.cpp
index a232142681..3ae0bf9031 100644
--- a/core/fxge/dib/fx_dib_engine.cpp
+++ b/core/fxge/dib/fx_dib_engine.cpp
@@ -8,7 +8,10 @@
#include <algorithm>
+#include "core/fxge/dib/cfx_dibitmap.h"
+#include "core/fxge/dib/cfx_dibsource.h"
#include "core/fxge/dib/dib_int.h"
+#include "core/fxge/dib/ifx_scanlinecomposer.h"
#include "core/fxge/fx_dib.h"
#include "third_party/base/ptr_util.h"
#include "third_party/base/stl_util.h"
diff --git a/core/fxge/dib/fx_dib_main.cpp b/core/fxge/dib/fx_dib_main.cpp
index 1214cc1f16..68668b92bc 100644
--- a/core/fxge/dib/fx_dib_main.cpp
+++ b/core/fxge/dib/fx_dib_main.cpp
@@ -73,13 +73,6 @@ FX_RECT FXDIB_SwapClipBox(FX_RECT& clip,
return rect;
}
-void CmykDecode(uint32_t cmyk, int& c, int& m, int& y, int& k) {
- c = FXSYS_GetCValue(cmyk);
- m = FXSYS_GetMValue(cmyk);
- y = FXSYS_GetYValue(cmyk);
- k = FXSYS_GetKValue(cmyk);
-}
-
void ArgbDecode(uint32_t argb, int& a, int& r, int& g, int& b) {
a = FXARGB_A(argb);
r = FXARGB_R(argb);
diff --git a/core/fxge/dib/ifx_scanlinecomposer.h b/core/fxge/dib/ifx_scanlinecomposer.h
new file mode 100644
index 0000000000..4df01dda23
--- /dev/null
+++ b/core/fxge/dib/ifx_scanlinecomposer.h
@@ -0,0 +1,26 @@
+// Copyright 2017 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#ifndef CORE_FXGE_DIB_IFX_SCANLINECOMPOSER_H_
+#define CORE_FXGE_DIB_IFX_SCANLINECOMPOSER_H_
+
+#include "core/fxge/fx_dib.h"
+
+class IFX_ScanlineComposer {
+ public:
+ virtual ~IFX_ScanlineComposer() {}
+
+ virtual void ComposeScanline(int line,
+ const uint8_t* scanline,
+ const uint8_t* scan_extra_alpha = nullptr) = 0;
+
+ virtual bool SetInfo(int width,
+ int height,
+ FXDIB_Format src_format,
+ uint32_t* pSrcPalette) = 0;
+};
+
+#endif // CORE_FXGE_DIB_IFX_SCANLINECOMPOSER_H_
diff --git a/core/fxge/fx_dib.h b/core/fxge/fx_dib.h
index e0018f32f5..cd6a0e6007 100644
--- a/core/fxge/fx_dib.h
+++ b/core/fxge/fx_dib.h
@@ -7,37 +7,71 @@
#ifndef CORE_FXGE_FX_DIB_H_
#define CORE_FXGE_FX_DIB_H_
-#include <memory>
-#include <vector>
+#include "core/fxcrt/fx_system.h"
-#include "core/fxcrt/cfx_retain_ptr.h"
-#include "core/fxcrt/fx_basic.h"
-#include "core/fxcrt/fx_coordinates.h"
-#include "core/fxge/dib/cfx_dibitmap.h"
-#include "core/fxge/dib/cfx_dibsource.h"
-#include "core/fxge/dib/cfx_scanlinecompositor.h"
-#include "third_party/base/stl_util.h"
+enum FXDIB_Format {
+ FXDIB_Invalid = 0,
+ FXDIB_1bppRgb = 0x001,
+ FXDIB_8bppRgb = 0x008,
+ FXDIB_Rgb = 0x018,
+ FXDIB_Rgb32 = 0x020,
+ FXDIB_1bppMask = 0x101,
+ FXDIB_8bppMask = 0x108,
+ FXDIB_8bppRgba = 0x208,
+ FXDIB_Rgba = 0x218,
+ FXDIB_Argb = 0x220,
+ FXDIB_1bppCmyk = 0x401,
+ FXDIB_8bppCmyk = 0x408,
+ FXDIB_Cmyk = 0x420,
+ FXDIB_8bppCmyka = 0x608,
+ FXDIB_Cmyka = 0x620,
+};
typedef uint32_t FX_ARGB;
typedef uint32_t FX_COLORREF;
typedef uint32_t FX_CMYK;
class CFX_ClipRgn;
+class CFX_DIBSource;
class CStretchEngine;
+#define FXDIB_DOWNSAMPLE 0x04
+#define FXDIB_INTERPOL 0x20
+#define FXDIB_BICUBIC_INTERPOL 0x80
+#define FXDIB_NOSMOOTH 0x100
+#define FXDIB_BLEND_NORMAL 0
+#define FXDIB_BLEND_MULTIPLY 1
+#define FXDIB_BLEND_SCREEN 2
+#define FXDIB_BLEND_OVERLAY 3
+#define FXDIB_BLEND_DARKEN 4
+#define FXDIB_BLEND_LIGHTEN 5
+
+#define FXDIB_BLEND_COLORDODGE 6
+#define FXDIB_BLEND_COLORBURN 7
+#define FXDIB_BLEND_HARDLIGHT 8
+#define FXDIB_BLEND_SOFTLIGHT 9
+#define FXDIB_BLEND_DIFFERENCE 10
+#define FXDIB_BLEND_EXCLUSION 11
+#define FXDIB_BLEND_NONSEPARABLE 21
+#define FXDIB_BLEND_HUE 21
+#define FXDIB_BLEND_SATURATION 22
+#define FXDIB_BLEND_COLOR 23
+#define FXDIB_BLEND_LUMINOSITY 24
+#define FXDIB_BLEND_UNSUPPORTED -1
+
#define FXSYS_RGB(r, g, b) ((r) | ((g) << 8) | ((b) << 16))
#define FXSYS_GetRValue(rgb) ((rgb)&0xff)
#define FXSYS_GetGValue(rgb) (((rgb) >> 8) & 0xff)
#define FXSYS_GetBValue(rgb) (((rgb) >> 16) & 0xff)
-#define FX_CCOLOR(val) (255 - (val))
+
#define FXSYS_CMYK(c, m, y, k) (((c) << 24) | ((m) << 16) | ((y) << 8) | (k))
#define FXSYS_GetCValue(cmyk) ((uint8_t)((cmyk) >> 24) & 0xff)
#define FXSYS_GetMValue(cmyk) ((uint8_t)((cmyk) >> 16) & 0xff)
#define FXSYS_GetYValue(cmyk) ((uint8_t)((cmyk) >> 8) & 0xff)
#define FXSYS_GetKValue(cmyk) ((uint8_t)(cmyk)&0xff)
-void CmykDecode(FX_CMYK cmyk, int& c, int& m, int& y, int& k);
inline FX_CMYK CmykEncode(int c, int m, int y, int k) {
return (c << 24) | (m << 16) | (y << 8) | k;
}
+
void ArgbDecode(FX_ARGB argb, int& a, int& r, int& g, int& b);
void ArgbDecode(FX_ARGB argb, int& a, FX_COLORREF& rgb);
inline FX_ARGB ArgbEncode(int a, int r, int g, int b) {
@@ -52,21 +86,10 @@ FX_ARGB ArgbEncode(int a, FX_COLORREF rgb);
(((uint32_t)(a) << 24) | ((r) << 16) | ((g) << 8) | (b))
#define FXARGB_MUL_ALPHA(argb, alpha) \
(((((argb) >> 24) * (alpha) / 255) << 24) | ((argb)&0xffffff))
+
#define FXRGB2GRAY(r, g, b) (((b)*11 + (g)*59 + (r)*30) / 100)
-#define FXCMYK2GRAY(c, m, y, k) \
- (((255 - (c)) * (255 - (k)) * 30 + (255 - (m)) * (255 - (k)) * 59 + \
- (255 - (y)) * (255 - (k)) * 11) / \
- 25500)
#define FXDIB_ALPHA_MERGE(backdrop, source, source_alpha) \
(((backdrop) * (255 - (source_alpha)) + (source) * (source_alpha)) / 255)
-#define FXDIB_ALPHA_UNION(dest, src) ((dest) + (src) - (dest) * (src) / 255)
-#define FXCMYK_GETDIB(p) \
- ((((uint8_t*)(p))[0] << 24 | (((uint8_t*)(p))[1] << 16) | \
- (((uint8_t*)(p))[2] << 8) | ((uint8_t*)(p))[3]))
-#define FXCMYK_SETDIB(p, cmyk) ((uint8_t*)(p))[0] = (uint8_t)((cmyk) >> 24), \
- ((uint8_t*)(p))[1] = (uint8_t)((cmyk) >> 16), \
- ((uint8_t*)(p))[2] = (uint8_t)((cmyk) >> 8), \
- ((uint8_t*)(p))[3] = (uint8_t)(cmyk))
#define FXARGB_GETDIB(p) \
((((uint8_t*)(p))[0]) | (((uint8_t*)(p))[1] << 8) | \
(((uint8_t*)(p))[2] << 16) | (((uint8_t*)(p))[3] << 24))
@@ -75,29 +98,11 @@ FX_ARGB ArgbEncode(int a, FX_COLORREF rgb);
((uint8_t*)(p))[1] = (uint8_t)((argb) >> 8), \
((uint8_t*)(p))[2] = (uint8_t)((argb) >> 16), \
((uint8_t*)(p))[3] = (uint8_t)((argb) >> 24)
-#define FXARGB_COPY(dest, src) \
- *(uint8_t*)(dest) = *(uint8_t*)(src), \
- *((uint8_t*)(dest) + 1) = *((uint8_t*)(src) + 1), \
- *((uint8_t*)(dest) + 2) = *((uint8_t*)(src) + 2), \
- *((uint8_t*)(dest) + 3) = *((uint8_t*)(src) + 3)
-#define FXCMYK_COPY(dest, src) \
- *(uint8_t*)(dest) = *(uint8_t*)(src), \
- *((uint8_t*)(dest) + 1) = *((uint8_t*)(src) + 1), \
- *((uint8_t*)(dest) + 2) = *((uint8_t*)(src) + 2), \
- *((uint8_t*)(dest) + 3) = *((uint8_t*)(src) + 3)
#define FXARGB_SETRGBORDERDIB(p, argb) \
((uint8_t*)(p))[3] = (uint8_t)(argb >> 24), \
((uint8_t*)(p))[0] = (uint8_t)((argb) >> 16), \
((uint8_t*)(p))[1] = (uint8_t)((argb) >> 8), \
((uint8_t*)(p))[2] = (uint8_t)(argb)
-#define FXARGB_GETRGBORDERDIB(p) \
- (((uint8_t*)(p))[2]) | (((uint8_t*)(p))[1] << 8) | \
- (((uint8_t*)(p))[0] << 16) | (((uint8_t*)(p))[3] << 24)
-#define FXARGB_RGBORDERCOPY(dest, src) \
- *((uint8_t*)(dest) + 3) = *((uint8_t*)(src) + 3), \
- *(uint8_t*)(dest) = *((uint8_t*)(src) + 2), \
- *((uint8_t*)(dest) + 1) = *((uint8_t*)(src) + 1), \
- *((uint8_t*)(dest) + 2) = *((uint8_t*)(src))
#define FXARGB_TODIB(argb) (argb)
#define FXCMYK_TODIB(cmyk) \
((uint8_t)((cmyk) >> 24) | ((uint8_t)((cmyk) >> 16)) << 8 | \
@@ -108,28 +113,4 @@ FX_ARGB ArgbEncode(int a, FX_COLORREF rgb);
#define FXGETFLAG_COLORTYPE(flag) (uint8_t)((flag) >> 8)
#define FXGETFLAG_ALPHA_FILL(flag) (uint8_t)(flag)
-bool ConvertBuffer(FXDIB_Format dest_format,
- uint8_t* dest_buf,
- int dest_pitch,
- int width,
- int height,
- const CFX_RetainPtr<CFX_DIBSource>& pSrcBitmap,
- int src_left,
- int src_top,
- std::unique_ptr<uint32_t, FxFreeDeleter>* pal);
-
-class IFX_ScanlineComposer {
- public:
- virtual ~IFX_ScanlineComposer() {}
-
- virtual void ComposeScanline(int line,
- const uint8_t* scanline,
- const uint8_t* scan_extra_alpha = nullptr) = 0;
-
- virtual bool SetInfo(int width,
- int height,
- FXDIB_Format src_format,
- uint32_t* pSrcPalette) = 0;
-};
-
#endif // CORE_FXGE_FX_DIB_H_
diff --git a/core/fxge/fx_font.h b/core/fxge/fx_font.h
index 880b6751e8..87f36060b7 100644
--- a/core/fxge/fx_font.h
+++ b/core/fxge/fx_font.h
@@ -13,6 +13,7 @@
#include "core/fxcrt/fx_system.h"
#include "core/fxge/cfx_substfont.h"
+#include "core/fxge/dib/cfx_dibitmap.h"
#include "core/fxge/fx_dib.h"
#include "core/fxge/fx_freetype.h"
diff --git a/core/fxge/ge/cfx_cliprgn.cpp b/core/fxge/ge/cfx_cliprgn.cpp
index 037e658de9..d2f065dba7 100644
--- a/core/fxge/ge/cfx_cliprgn.cpp
+++ b/core/fxge/ge/cfx_cliprgn.cpp
@@ -8,6 +8,8 @@
#include <utility>
+#include "core/fxge/dib/cfx_dibitmap.h"
+
CFX_ClipRgn::CFX_ClipRgn(int width, int height)
: m_Type(RectI), m_Box(0, 0, width, height) {}
diff --git a/core/fxge/ge/cfx_cliprgn.h b/core/fxge/ge/cfx_cliprgn.h
index ae12347288..800e6ddbee 100644
--- a/core/fxge/ge/cfx_cliprgn.h
+++ b/core/fxge/ge/cfx_cliprgn.h
@@ -7,7 +7,9 @@
#ifndef CORE_FXGE_GE_CFX_CLIPRGN_H_
#define CORE_FXGE_GE_CFX_CLIPRGN_H_
-#include "core/fxge/fx_dib.h"
+#include "core/fxcrt/fx_coordinates.h"
+
+class CFX_DIBitmap;
class CFX_ClipRgn {
public:
diff --git a/core/fxge/win32/dwrite_int.h b/core/fxge/win32/dwrite_int.h
index 8e8908a7a1..16be7b7d4f 100644
--- a/core/fxge/win32/dwrite_int.h
+++ b/core/fxge/win32/dwrite_int.h
@@ -7,6 +7,10 @@
#ifndef CORE_FXGE_WIN32_DWRITE_INT_H_
#define CORE_FXGE_WIN32_DWRITE_INT_H_
+#include "core/fxcrt/fx_coordinates.h"
+#include "core/fxge/dib/cfx_dibitmap.h"
+#include "core/fxge/fx_dib.h"
+
#ifndef DECLSPEC_UUID
#if (_MSC_VER >= 1100) && defined(__cplusplus)
#define DECLSPEC_UUID(x) __declspec(uuid(x))