summaryrefslogtreecommitdiff
path: root/chromium/third_party/pdfium/core/fxge
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <allan.jensen@qt.io>2017-07-12 14:07:37 +0200
committerAllan Sandfeld Jensen <allan.jensen@qt.io>2017-07-17 10:29:26 +0000
commitec02ee4181c49b61fce1c8fb99292dbb8139cc90 (patch)
tree25cde714b2b71eb639d1cd53f5a22e9ba76e14ef /chromium/third_party/pdfium/core/fxge
parentbb09965444b5bb20b096a291445170876225268d (diff)
downloadqtwebengine-chromium-ec02ee4181c49b61fce1c8fb99292dbb8139cc90.tar.gz
BASELINE: Update Chromium to 59.0.3071.134
Change-Id: Id02ef6fb2204c5fd21668a1c3e6911c83b17585a Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
Diffstat (limited to 'chromium/third_party/pdfium/core/fxge')
-rw-r--r--chromium/third_party/pdfium/core/fxge/agg/fx_agg_driver.cpp2178
-rw-r--r--chromium/third_party/pdfium/core/fxge/agg/fx_agg_driver.h27
-rw-r--r--chromium/third_party/pdfium/core/fxge/android/cfpf_skiafont.cpp2
-rw-r--r--chromium/third_party/pdfium/core/fxge/android/cfpf_skiafont.h2
-rw-r--r--chromium/third_party/pdfium/core/fxge/android/cfpf_skiafontdescriptor.h8
-rw-r--r--chromium/third_party/pdfium/core/fxge/android/cfpf_skiafontmgr.cpp10
-rw-r--r--chromium/third_party/pdfium/core/fxge/android/cfpf_skiapathfont.h8
-rw-r--r--chromium/third_party/pdfium/core/fxge/android/cfx_androidfontinfo.cpp12
-rw-r--r--chromium/third_party/pdfium/core/fxge/android/cfx_androidfontinfo.h8
-rw-r--r--chromium/third_party/pdfium/core/fxge/android/fx_android_imp.cpp3
-rw-r--r--chromium/third_party/pdfium/core/fxge/apple/apple_int.h4
-rw-r--r--chromium/third_party/pdfium/core/fxge/apple/fx_apple_platform.cpp7
-rw-r--r--chromium/third_party/pdfium/core/fxge/apple/fx_mac_imp.cpp8
-rw-r--r--chromium/third_party/pdfium/core/fxge/apple/fx_quartz_device.cpp5
-rw-r--r--chromium/third_party/pdfium/core/fxge/cfx_fontmgr.h2
-rw-r--r--chromium/third_party/pdfium/core/fxge/cfx_fxgedevice.h13
-rw-r--r--chromium/third_party/pdfium/core/fxge/cfx_gemodule.h2
-rw-r--r--chromium/third_party/pdfium/core/fxge/cfx_graphstate.h10
-rw-r--r--chromium/third_party/pdfium/core/fxge/cfx_graphstatedata.h8
-rw-r--r--chromium/third_party/pdfium/core/fxge/cfx_pathdata.h4
-rw-r--r--chromium/third_party/pdfium/core/fxge/cfx_renderdevice.h75
-rw-r--r--chromium/third_party/pdfium/core/fxge/cfx_unicodeencodingex.h2
-rw-r--r--chromium/third_party/pdfium/core/fxge/dib/cfx_bitmapcomposer.cpp201
-rw-r--r--chromium/third_party/pdfium/core/fxge/dib/cfx_bitmapcomposer.h81
-rw-r--r--chromium/third_party/pdfium/core/fxge/dib/cfx_bitmapstorer.cpp55
-rw-r--r--chromium/third_party/pdfium/core/fxge/dib/cfx_bitmapstorer.h41
-rw-r--r--chromium/third_party/pdfium/core/fxge/dib/cfx_dibextractor.cpp27
-rw-r--r--chromium/third_party/pdfium/core/fxge/dib/cfx_dibextractor.h26
-rw-r--r--chromium/third_party/pdfium/core/fxge/dib/cfx_dibitmap.cpp1232
-rw-r--r--chromium/third_party/pdfium/core/fxge/dib/cfx_dibitmap.h120
-rw-r--r--chromium/third_party/pdfium/core/fxge/dib/cfx_dibsource.cpp (renamed from chromium/third_party/pdfium/core/fxge/dib/fx_dib_convert.cpp)975
-rw-r--r--chromium/third_party/pdfium/core/fxge/dib/cfx_dibsource.h145
-rw-r--r--chromium/third_party/pdfium/core/fxge/dib/cfx_filtereddib.cpp42
-rw-r--r--chromium/third_party/pdfium/core/fxge/dib/cfx_filtereddib.h50
-rw-r--r--chromium/third_party/pdfium/core/fxge/dib/cfx_imagerenderer.cpp137
-rw-r--r--chromium/third_party/pdfium/core/fxge/dib/cfx_imagerenderer.h56
-rw-r--r--chromium/third_party/pdfium/core/fxge/dib/cfx_imagestretcher.cpp193
-rw-r--r--chromium/third_party/pdfium/core/fxge/dib/cfx_imagestretcher.h56
-rw-r--r--chromium/third_party/pdfium/core/fxge/dib/cfx_imagetransformer.cpp (renamed from chromium/third_party/pdfium/core/fxge/dib/fx_dib_transform.cpp)267
-rw-r--r--chromium/third_party/pdfium/core/fxge/dib/cfx_imagetransformer.h47
-rw-r--r--chromium/third_party/pdfium/core/fxge/dib/cfx_scanlinecompositor.cpp (renamed from chromium/third_party/pdfium/core/fxge/dib/fx_dib_composite.cpp)2416
-rw-r--r--chromium/third_party/pdfium/core/fxge/dib/cfx_scanlinecompositor.h72
-rw-r--r--chromium/third_party/pdfium/core/fxge/dib/cstretchengine.cpp (renamed from chromium/third_party/pdfium/core/fxge/dib/fx_dib_engine.cpp)293
-rw-r--r--chromium/third_party/pdfium/core/fxge/dib/cstretchengine.h81
-rw-r--r--chromium/third_party/pdfium/core/fxge/dib/cstretchengine_unittest.cpp (renamed from chromium/third_party/pdfium/core/fxge/dib/fx_dib_engine_unittest.cpp)13
-rw-r--r--chromium/third_party/pdfium/core/fxge/dib/dib_int.h116
-rw-r--r--chromium/third_party/pdfium/core/fxge/dib/fx_dib_main.cpp1677
-rw-r--r--chromium/third_party/pdfium/core/fxge/dib/ifx_scanlinecomposer.h26
-rw-r--r--chromium/third_party/pdfium/core/fxge/freetype/DEPS2
-rw-r--r--chromium/third_party/pdfium/core/fxge/freetype/fx_freetype.cpp2
-rw-r--r--chromium/third_party/pdfium/core/fxge/fx_dib.h621
-rw-r--r--chromium/third_party/pdfium/core/fxge/fx_font.h15
-rw-r--r--chromium/third_party/pdfium/core/fxge/ge/cfx_cliprgn.cpp46
-rw-r--r--chromium/third_party/pdfium/core/fxge/ge/cfx_cliprgn.h16
-rw-r--r--chromium/third_party/pdfium/core/fxge/ge/cfx_facecache.cpp40
-rw-r--r--chromium/third_party/pdfium/core/fxge/ge/cfx_folderfontinfo.cpp60
-rw-r--r--chromium/third_party/pdfium/core/fxge/ge/cfx_folderfontinfo.h12
-rw-r--r--chromium/third_party/pdfium/core/fxge/ge/cfx_font.cpp2
-rw-r--r--chromium/third_party/pdfium/core/fxge/ge/cfx_fontcache.cpp3
-rw-r--r--chromium/third_party/pdfium/core/fxge/ge/cfx_fontmapper.cpp39
-rw-r--r--chromium/third_party/pdfium/core/fxge/ge/cfx_fontmgr.cpp2
-rw-r--r--chromium/third_party/pdfium/core/fxge/ge/cfx_gemodule.cpp4
-rw-r--r--chromium/third_party/pdfium/core/fxge/ge/cfx_graphstate.cpp12
-rw-r--r--chromium/third_party/pdfium/core/fxge/ge/cfx_graphstatedata.cpp6
-rw-r--r--chromium/third_party/pdfium/core/fxge/ge/cfx_pathdata.cpp85
-rw-r--r--chromium/third_party/pdfium/core/fxge/ge/cfx_renderdevice.cpp247
-rw-r--r--chromium/third_party/pdfium/core/fxge/ge/cfx_unicodeencodingex.cpp2
-rw-r--r--chromium/third_party/pdfium/core/fxge/ge/fx_ge_linux.cpp14
-rw-r--r--chromium/third_party/pdfium/core/fxge/ge/fx_ge_text.cpp8
-rw-r--r--chromium/third_party/pdfium/core/fxge/ge/fx_text_int.h2
-rw-r--r--chromium/third_party/pdfium/core/fxge/ifx_renderdevicedriver.cpp39
-rw-r--r--chromium/third_party/pdfium/core/fxge/ifx_renderdevicedriver.h35
-rw-r--r--chromium/third_party/pdfium/core/fxge/ifx_systemfontinfo.h8
-rw-r--r--chromium/third_party/pdfium/core/fxge/skia/fx_skia_device.cpp529
-rw-r--r--chromium/third_party/pdfium/core/fxge/skia/fx_skia_device.h46
-rw-r--r--chromium/third_party/pdfium/core/fxge/skia/fx_skia_device_unittest.cpp4
-rw-r--r--chromium/third_party/pdfium/core/fxge/win32/cfx_psrenderer.cpp89
-rw-r--r--chromium/third_party/pdfium/core/fxge/win32/cfx_psrenderer.h8
-rw-r--r--chromium/third_party/pdfium/core/fxge/win32/cfx_windowsdib.h26
-rw-r--r--chromium/third_party/pdfium/core/fxge/win32/cpsoutput.cpp6
-rw-r--r--chromium/third_party/pdfium/core/fxge/win32/cpsoutput.h2
-rw-r--r--chromium/third_party/pdfium/core/fxge/win32/dwrite_int.h15
-rw-r--r--chromium/third_party/pdfium/core/fxge/win32/fx_win32_device.cpp298
-rw-r--r--chromium/third_party/pdfium/core/fxge/win32/fx_win32_dib.cpp72
-rw-r--r--chromium/third_party/pdfium/core/fxge/win32/fx_win32_dwrite.cpp35
-rw-r--r--chromium/third_party/pdfium/core/fxge/win32/fx_win32_gdipext.cpp95
-rw-r--r--chromium/third_party/pdfium/core/fxge/win32/fx_win32_print.cpp103
-rw-r--r--chromium/third_party/pdfium/core/fxge/win32/win32_int.h80
88 files changed, 6255 insertions, 7318 deletions
diff --git a/chromium/third_party/pdfium/core/fxge/agg/fx_agg_driver.cpp b/chromium/third_party/pdfium/core/fxge/agg/fx_agg_driver.cpp
index 8c7277752ee..e4fc151fabf 100644
--- a/chromium/third_party/pdfium/core/fxge/agg/fx_agg_driver.cpp
+++ b/chromium/third_party/pdfium/core/fxge/agg/fx_agg_driver.cpp
@@ -10,16 +10,13 @@
#include <utility>
#include "core/fxcodec/fx_codec.h"
-#include "core/fxcrt/fx_memory.h"
#include "core/fxge/cfx_fxgedevice.h"
#include "core/fxge/cfx_gemodule.h"
#include "core/fxge/cfx_graphstatedata.h"
#include "core/fxge/cfx_pathdata.h"
-#include "core/fxge/cfx_renderdevice.h"
-#include "core/fxge/dib/dib_int.h"
+#include "core/fxge/dib/cfx_imagerenderer.h"
+#include "core/fxge/dib/cfx_imagestretcher.h"
#include "core/fxge/ge/cfx_cliprgn.h"
-#include "core/fxge/ge/fx_text_int.h"
-#include "core/fxge/ifx_renderdevicedriver.h"
#include "third_party/agg23/agg_conv_dash.h"
#include "third_party/agg23/agg_conv_stroke.h"
#include "third_party/agg23/agg_curves.h"
@@ -29,19 +26,25 @@
#include "third_party/agg23/agg_renderer_scanline.h"
#include "third_party/agg23/agg_scanline_u.h"
#include "third_party/base/ptr_util.h"
+#include "third_party/base/stl_util.h"
namespace {
+const float kMaxPos = 32000.0f;
+
CFX_PointF HardClip(const CFX_PointF& pos) {
- return CFX_PointF(std::max(std::min(pos.x, 50000.0f), -50000.0f),
- std::max(std::min(pos.y, 50000.0f), -50000.0f));
+ return CFX_PointF(pdfium::clamp(pos.x, -kMaxPos, kMaxPos),
+ pdfium::clamp(pos.y, -kMaxPos, kMaxPos));
}
-void RgbByteOrderSetPixel(CFX_DIBitmap* pBitmap, int x, int y, uint32_t argb) {
+void RgbByteOrderSetPixel(const CFX_RetainPtr<CFX_DIBitmap>& pBitmap,
+ int x,
+ int y,
+ uint32_t argb) {
if (x < 0 || x >= pBitmap->GetWidth() || y < 0 || y >= pBitmap->GetHeight())
return;
- uint8_t* pos = (uint8_t*)pBitmap->GetBuffer() + y * pBitmap->GetPitch() +
+ uint8_t* pos = pBitmap->GetBuffer() + y * pBitmap->GetPitch() +
x * pBitmap->GetBPP() / 8;
if (pBitmap->GetFormat() == FXDIB_Argb) {
FXARGB_SETRGBORDERDIB(pos, argb);
@@ -54,7 +57,7 @@ void RgbByteOrderSetPixel(CFX_DIBitmap* pBitmap, int x, int y, uint32_t argb) {
pos[2] = (FXARGB_B(argb) * alpha + pos[2] * (255 - alpha)) / 255;
}
-void RgbByteOrderCompositeRect(CFX_DIBitmap* pBitmap,
+void RgbByteOrderCompositeRect(const CFX_RetainPtr<CFX_DIBitmap>& pBitmap,
int left,
int top,
int width,
@@ -71,7 +74,6 @@ void RgbByteOrderCompositeRect(CFX_DIBitmap* pBitmap,
int src_g = FXARGB_G(argb);
int src_b = FXARGB_B(argb);
int Bpp = pBitmap->GetBPP() / 8;
- bool bAlpha = pBitmap->HasAlpha();
int dib_argb = FXARGB_TOBGRORDERDIB(argb);
uint8_t* pBuffer = pBitmap->GetBuffer();
if (src_alpha == 255) {
@@ -79,7 +81,7 @@ void RgbByteOrderCompositeRect(CFX_DIBitmap* pBitmap,
uint8_t* dest_scan =
pBuffer + row * pBitmap->GetPitch() + rect.left * Bpp;
if (Bpp == 4) {
- uint32_t* scan = (uint32_t*)dest_scan;
+ uint32_t* scan = reinterpret_cast<uint32_t*>(dest_scan);
for (int col = 0; col < width; col++)
*scan++ = dib_argb;
} else {
@@ -92,6 +94,7 @@ void RgbByteOrderCompositeRect(CFX_DIBitmap* pBitmap,
}
return;
}
+ bool bAlpha = pBitmap->HasAlpha();
for (int row = rect.top; row < rect.bottom; row++) {
uint8_t* dest_scan = pBuffer + row * pBitmap->GetPitch() + rect.left * Bpp;
if (bAlpha) {
@@ -114,27 +117,27 @@ void RgbByteOrderCompositeRect(CFX_DIBitmap* pBitmap,
*dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, src_b, alpha_ratio);
dest_scan += 2;
}
- } else {
- for (int col = 0; col < width; col++) {
- *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, src_r, src_alpha);
- dest_scan++;
- *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, src_g, src_alpha);
- dest_scan++;
- *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, src_b, src_alpha);
+ continue;
+ }
+ for (int col = 0; col < width; col++) {
+ *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, src_r, src_alpha);
+ dest_scan++;
+ *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, src_g, src_alpha);
+ dest_scan++;
+ *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, src_b, src_alpha);
+ dest_scan++;
+ if (Bpp == 4)
dest_scan++;
- if (Bpp == 4)
- dest_scan++;
- }
}
}
}
-void RgbByteOrderTransferBitmap(CFX_DIBitmap* pBitmap,
+void RgbByteOrderTransferBitmap(const CFX_RetainPtr<CFX_DIBitmap>& pBitmap,
int dest_left,
int dest_top,
int width,
int height,
- const CFX_DIBSource* pSrcBitmap,
+ const CFX_RetainPtr<CFX_DIBSource>& pSrcBitmap,
int src_left,
int src_top) {
if (!pBitmap)
@@ -155,7 +158,8 @@ void RgbByteOrderTransferBitmap(CFX_DIBitmap* pBitmap,
for (int row = 0; row < height; row++) {
uint8_t* dest_scan = buffer + (dest_top + row) * pitch + dest_left * Bpp;
uint8_t* src_scan =
- (uint8_t*)pSrcBitmap->GetScanline(src_top + row) + src_left * Bpp;
+ const_cast<uint8_t*>(pSrcBitmap->GetScanline(src_top + row)) +
+ src_left * Bpp;
if (Bpp == 4) {
for (int col = 0; col < width; col++) {
FXARGB_SETDIB(dest_scan, FXARGB_MAKE(src_scan[3], src_scan[0],
@@ -163,13 +167,13 @@ void RgbByteOrderTransferBitmap(CFX_DIBitmap* pBitmap,
dest_scan += 4;
src_scan += 4;
}
- } else {
- for (int col = 0; col < width; col++) {
- *dest_scan++ = src_scan[2];
- *dest_scan++ = src_scan[1];
- *dest_scan++ = src_scan[0];
- src_scan += 3;
- }
+ continue;
+ }
+ for (int col = 0; col < width; col++) {
+ *dest_scan++ = src_scan[2];
+ *dest_scan++ = src_scan[1];
+ *dest_scan++ = src_scan[0];
+ src_scan += 3;
}
}
return;
@@ -177,55 +181,53 @@ void RgbByteOrderTransferBitmap(CFX_DIBitmap* pBitmap,
uint8_t* dest_buf = buffer + dest_top * pitch + dest_left * Bpp;
if (dest_format == FXDIB_Rgb) {
- if (src_format == FXDIB_Rgb32) {
- for (int row = 0; row < height; row++) {
- uint8_t* dest_scan = dest_buf + row * pitch;
- uint8_t* src_scan =
- (uint8_t*)pSrcBitmap->GetScanline(src_top + row) + src_left * 4;
- for (int col = 0; col < width; col++) {
- *dest_scan++ = src_scan[2];
- *dest_scan++ = src_scan[1];
- *dest_scan++ = src_scan[0];
- src_scan += 4;
- }
+ ASSERT(src_format == FXDIB_Rgb32);
+ for (int row = 0; row < height; row++) {
+ uint8_t* dest_scan = dest_buf + row * pitch;
+ uint8_t* src_scan =
+ const_cast<uint8_t*>(pSrcBitmap->GetScanline(src_top + row)) +
+ src_left * 4;
+ for (int col = 0; col < width; col++) {
+ *dest_scan++ = src_scan[2];
+ *dest_scan++ = src_scan[1];
+ *dest_scan++ = src_scan[0];
+ src_scan += 4;
}
- } else {
- ASSERT(false);
}
return;
}
- if (dest_format == FXDIB_Argb || dest_format == FXDIB_Rgb32) {
- if (src_format == FXDIB_Rgb) {
- for (int row = 0; row < height; row++) {
- uint8_t* dest_scan = (uint8_t*)(dest_buf + row * pitch);
- uint8_t* src_scan =
- (uint8_t*)pSrcBitmap->GetScanline(src_top + row) + src_left * 3;
- for (int col = 0; col < width; col++) {
- FXARGB_SETDIB(dest_scan, FXARGB_MAKE(0xff, src_scan[0], src_scan[1],
- src_scan[2]));
- dest_scan += 4;
- src_scan += 3;
- }
- }
- } else if (src_format == FXDIB_Rgb32) {
- ASSERT(dest_format == FXDIB_Argb);
- for (int row = 0; row < height; row++) {
- uint8_t* dest_scan = dest_buf + row * pitch;
- uint8_t* src_scan =
- (uint8_t*)(pSrcBitmap->GetScanline(src_top + row) + src_left * 4);
- for (int col = 0; col < width; col++) {
- FXARGB_SETDIB(dest_scan, FXARGB_MAKE(0xff, src_scan[0], src_scan[1],
- src_scan[2]));
- src_scan += 4;
- dest_scan += 4;
- }
+ ASSERT(dest_format == FXDIB_Argb || dest_format == FXDIB_Rgb32);
+ if (src_format == FXDIB_Rgb) {
+ for (int row = 0; row < height; row++) {
+ uint8_t* dest_scan = dest_buf + row * pitch;
+ uint8_t* src_scan =
+ const_cast<uint8_t*>(pSrcBitmap->GetScanline(src_top + row)) +
+ src_left * 3;
+ for (int col = 0; col < width; col++) {
+ FXARGB_SETDIB(dest_scan,
+ FXARGB_MAKE(0xff, src_scan[0], src_scan[1], src_scan[2]));
+ dest_scan += 4;
+ src_scan += 3;
}
}
return;
}
-
- ASSERT(false);
+ if (src_format != FXDIB_Rgb32)
+ return;
+ ASSERT(dest_format == FXDIB_Argb);
+ for (int row = 0; row < height; row++) {
+ uint8_t* dest_scan = dest_buf + row * pitch;
+ uint8_t* src_scan =
+ const_cast<uint8_t*>(pSrcBitmap->GetScanline(src_top + row)) +
+ src_left * 4;
+ for (int col = 0; col < width; col++) {
+ FXARGB_SETDIB(dest_scan,
+ FXARGB_MAKE(0xff, src_scan[0], src_scan[1], src_scan[2]));
+ src_scan += 4;
+ dest_scan += 4;
+ }
+ }
}
FX_ARGB DefaultCMYK2ARGB(FX_CMYK cmyk, uint8_t alpha) {
@@ -235,7 +237,7 @@ FX_ARGB DefaultCMYK2ARGB(FX_CMYK cmyk, uint8_t alpha) {
return ArgbEncode(alpha, r, g, b);
}
-bool DibSetPixel(CFX_DIBitmap* pDevice,
+bool DibSetPixel(const CFX_RetainPtr<CFX_DIBitmap>& pDevice,
int x,
int y,
uint32_t color,
@@ -247,72 +249,878 @@ bool DibSetPixel(CFX_DIBitmap* pDevice,
CCodec_IccModule* pIccModule =
CFX_GEModule::Get()->GetCodecModule()->GetIccModule();
color = bObjCMYK ? FXCMYK_TODIB(color) : FXARGB_TODIB(color);
- pIccModule->TranslateScanline(pIccTransform, (uint8_t*)&color,
- (uint8_t*)&color, 1);
+ uint8_t* pColor = reinterpret_cast<uint8_t*>(&color);
+ pIccModule->TranslateScanline(pIccTransform, pColor, pColor, 1);
color = bObjCMYK ? FXCMYK_TODIB(color) : FXARGB_TODIB(color);
- if (!pDevice->IsCmykImage()) {
+ if (!pDevice->IsCmykImage())
color = (color & 0xffffff) | (alpha << 24);
- }
} else {
if (pDevice->IsCmykImage()) {
if (!bObjCMYK)
return false;
- } else {
- if (bObjCMYK)
- color = DefaultCMYK2ARGB(color, alpha);
+ } else if (bObjCMYK) {
+ color = DefaultCMYK2ARGB(color, alpha);
}
}
pDevice->SetPixel(x, y, color);
- if (pDevice->m_pAlphaMask) {
+ if (pDevice->m_pAlphaMask)
pDevice->m_pAlphaMask->SetPixel(x, y, alpha << 24);
- }
return true;
}
-} // namespace
+void RasterizeStroke(agg::rasterizer_scanline_aa* rasterizer,
+ agg::path_storage* path_data,
+ const CFX_Matrix* pObject2Device,
+ const CFX_GraphStateData* pGraphState,
+ float scale,
+ bool bStrokeAdjust,
+ bool bTextMode) {
+ agg::line_cap_e cap;
+ switch (pGraphState->m_LineCap) {
+ case CFX_GraphStateData::LineCapRound:
+ cap = agg::round_cap;
+ break;
+ case CFX_GraphStateData::LineCapSquare:
+ cap = agg::square_cap;
+ break;
+ default:
+ cap = agg::butt_cap;
+ break;
+ }
+ agg::line_join_e join;
+ switch (pGraphState->m_LineJoin) {
+ case CFX_GraphStateData::LineJoinRound:
+ join = agg::round_join;
+ break;
+ case CFX_GraphStateData::LineJoinBevel:
+ join = agg::bevel_join;
+ break;
+ default:
+ join = agg::miter_join_revert;
+ break;
+ }
+ float width = pGraphState->m_LineWidth * scale;
+ float unit = 1.0f;
+ if (pObject2Device) {
+ unit =
+ 1.0f / ((pObject2Device->GetXUnit() + pObject2Device->GetYUnit()) / 2);
+ }
+ width = std::max(width, unit);
+ if (pGraphState->m_DashArray) {
+ typedef agg::conv_dash<agg::path_storage> dash_converter;
+ dash_converter dash(*path_data);
+ for (int i = 0; i < (pGraphState->m_DashCount + 1) / 2; i++) {
+ float on = pGraphState->m_DashArray[i * 2];
+ if (on <= 0.000001f)
+ on = 1.0f / 10;
+ float off = i * 2 + 1 == pGraphState->m_DashCount
+ ? on
+ : pGraphState->m_DashArray[i * 2 + 1];
+ off = std::max(off, 0.0f);
+ dash.add_dash(on * scale, off * scale);
+ }
+ dash.dash_start(pGraphState->m_DashPhase * scale);
+ typedef agg::conv_stroke<dash_converter> dash_stroke;
+ dash_stroke stroke(dash);
+ stroke.line_join(join);
+ stroke.line_cap(cap);
+ stroke.miter_limit(pGraphState->m_MiterLimit);
+ stroke.width(width);
+ rasterizer->add_path_transformed(stroke, pObject2Device);
+ return;
+ }
+ agg::conv_stroke<agg::path_storage> stroke(*path_data);
+ stroke.line_join(join);
+ stroke.line_cap(cap);
+ stroke.miter_limit(pGraphState->m_MiterLimit);
+ stroke.width(width);
+ rasterizer->add_path_transformed(stroke, pObject2Device);
+}
-void CAgg_PathData::BuildPath(const CFX_PathData* pPathData,
- const CFX_Matrix* pObject2Device) {
- const std::vector<FX_PATHPOINT>& pPoints = pPathData->GetPoints();
- for (size_t i = 0; i < pPoints.size(); i++) {
- CFX_PointF pos = pPoints[i].m_Point;
- if (pObject2Device)
- pos = pObject2Device->Transform(pos);
+class CFX_Renderer {
+ public:
+ // Needed for agg caller
+ void prepare(unsigned) {}
- pos = HardClip(pos);
- FXPT_TYPE point_type = pPoints[i].m_Type;
- if (point_type == FXPT_TYPE::MoveTo) {
- m_PathData.move_to(pos.x, pos.y);
- } else if (point_type == FXPT_TYPE::LineTo) {
- if (pPoints[i - 1].IsTypeAndOpen(FXPT_TYPE::MoveTo) &&
- (i == pPoints.size() - 1 ||
- pPoints[i + 1].IsTypeAndOpen(FXPT_TYPE::MoveTo)) &&
- pPoints[i].m_Point == pPoints[i - 1].m_Point) {
- pos.x += 1;
+ void CompositeSpan(uint8_t* dest_scan,
+ uint8_t* ori_scan,
+ int Bpp,
+ bool bDestAlpha,
+ int span_left,
+ int span_len,
+ uint8_t* cover_scan,
+ int clip_left,
+ int clip_right,
+ uint8_t* clip_scan);
+
+ void CompositeSpan1bpp(uint8_t* dest_scan,
+ int Bpp,
+ int span_left,
+ int span_len,
+ uint8_t* cover_scan,
+ int clip_left,
+ int clip_right,
+ uint8_t* clip_scan,
+ uint8_t* dest_extra_alpha_scan);
+
+ void CompositeSpanGray(uint8_t* dest_scan,
+ int Bpp,
+ int span_left,
+ int span_len,
+ uint8_t* cover_scan,
+ int clip_left,
+ int clip_right,
+ uint8_t* clip_scan,
+ uint8_t* dest_extra_alpha_scan);
+
+ void CompositeSpanARGB(uint8_t* dest_scan,
+ int Bpp,
+ int span_left,
+ int span_len,
+ uint8_t* cover_scan,
+ int clip_left,
+ int clip_right,
+ uint8_t* clip_scan,
+ uint8_t* dest_extra_alpha_scan);
+
+ void CompositeSpanRGB(uint8_t* dest_scan,
+ int Bpp,
+ int span_left,
+ int span_len,
+ uint8_t* cover_scan,
+ int clip_left,
+ int clip_right,
+ uint8_t* clip_scan,
+ uint8_t* dest_extra_alpha_scan);
+
+ void CompositeSpanCMYK(uint8_t* dest_scan,
+ int Bpp,
+ int span_left,
+ int span_len,
+ uint8_t* cover_scan,
+ int clip_left,
+ int clip_right,
+ uint8_t* clip_scan,
+ uint8_t* dest_extra_alpha_scan);
+
+ bool Init(const CFX_RetainPtr<CFX_DIBitmap>& pDevice,
+ const CFX_RetainPtr<CFX_DIBitmap>& pOriDevice,
+ const CFX_ClipRgn* pClipRgn,
+ uint32_t color,
+ bool bFullCover,
+ bool bRgbByteOrder,
+ int alpha_flag,
+ void* pIccTransform);
+
+ template <class Scanline>
+ void render(const Scanline& sl);
+
+ private:
+ void (CFX_Renderer::*composite_span)(uint8_t*,
+ int,
+ int,
+ int,
+ uint8_t*,
+ int,
+ int,
+ uint8_t*,
+ uint8_t*);
+
+ void CompositeSpan1bppHelper(uint8_t* dest_scan,
+ int col_start,
+ int col_end,
+ const uint8_t* cover_scan,
+ const uint8_t* clip_scan,
+ int span_left);
+
+ inline int GetSrcAlpha(const uint8_t* clip_scan, int col) const {
+ return clip_scan ? m_Alpha * clip_scan[col] / 255 : m_Alpha;
+ }
+
+ inline int GetSourceAlpha(const uint8_t* cover_scan,
+ const uint8_t* clip_scan,
+ int col) const {
+ return clip_scan ? m_Alpha * cover_scan[col] * clip_scan[col] / 255 / 255
+ : m_Alpha * cover_scan[col] / 255;
+ }
+
+ inline int GetColStart(int span_left, int clip_left) const {
+ return span_left < clip_left ? clip_left - span_left : 0;
+ }
+
+ inline int GetColEnd(int span_left, int span_len, int clip_right) const {
+ return span_left + span_len < clip_right ? span_len
+ : clip_right - span_left;
+ }
+
+ int m_Alpha;
+ int m_Red;
+ int m_Green;
+ int m_Blue;
+ int m_Gray;
+ uint32_t m_Color;
+ bool m_bFullCover;
+ bool m_bRgbByteOrder;
+ FX_RECT m_ClipBox;
+ CFX_RetainPtr<CFX_DIBitmap> m_pOriDevice;
+ CFX_RetainPtr<CFX_DIBitmap> m_pClipMask;
+ CFX_RetainPtr<CFX_DIBitmap> m_pDevice;
+ const CFX_ClipRgn* m_pClipRgn;
+};
+
+void CFX_Renderer::CompositeSpan(uint8_t* dest_scan,
+ uint8_t* ori_scan,
+ int Bpp,
+ bool bDestAlpha,
+ int span_left,
+ int span_len,
+ uint8_t* cover_scan,
+ int clip_left,
+ int clip_right,
+ uint8_t* clip_scan) {
+ ASSERT(!m_pDevice->IsCmykImage());
+ int col_start = GetColStart(span_left, clip_left);
+ int col_end = GetColEnd(span_left, span_len, clip_right);
+ if (Bpp) {
+ dest_scan += col_start * Bpp;
+ ori_scan += col_start * Bpp;
+ } else {
+ dest_scan += col_start / 8;
+ ori_scan += col_start / 8;
+ }
+ if (m_bRgbByteOrder) {
+ if (Bpp == 4 && bDestAlpha) {
+ for (int col = col_start; col < col_end; col++) {
+ int src_alpha = GetSrcAlpha(clip_scan, col);
+ uint8_t dest_alpha =
+ ori_scan[3] + src_alpha - ori_scan[3] * src_alpha / 255;
+ dest_scan[3] = dest_alpha;
+ int alpha_ratio = src_alpha * 255 / dest_alpha;
+ if (m_bFullCover) {
+ *dest_scan++ = FXDIB_ALPHA_MERGE(*ori_scan++, m_Red, alpha_ratio);
+ *dest_scan++ = FXDIB_ALPHA_MERGE(*ori_scan++, m_Green, alpha_ratio);
+ *dest_scan++ = FXDIB_ALPHA_MERGE(*ori_scan++, m_Blue, alpha_ratio);
+ dest_scan++;
+ ori_scan++;
+ } else {
+ int r = FXDIB_ALPHA_MERGE(*ori_scan++, m_Red, alpha_ratio);
+ int g = FXDIB_ALPHA_MERGE(*ori_scan++, m_Green, alpha_ratio);
+ int b = FXDIB_ALPHA_MERGE(*ori_scan++, m_Blue, alpha_ratio);
+ ori_scan++;
+ *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, r, cover_scan[col]);
+ dest_scan++;
+ *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, g, cover_scan[col]);
+ dest_scan++;
+ *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, b, cover_scan[col]);
+ dest_scan += 2;
+ }
}
- m_PathData.line_to(pos.x, pos.y);
- } else if (point_type == FXPT_TYPE::BezierTo) {
- CFX_PointF pos0 = pPoints[i - 1].m_Point;
- CFX_PointF pos2 = pPoints[i + 1].m_Point;
- CFX_PointF pos3 = pPoints[i + 2].m_Point;
- if (pObject2Device) {
- pos0 = pObject2Device->Transform(pos0);
- pos2 = pObject2Device->Transform(pos2);
- pos3 = pObject2Device->Transform(pos3);
+ return;
+ }
+ if (Bpp == 3 || Bpp == 4) {
+ for (int col = col_start; col < col_end; col++) {
+ int src_alpha = GetSrcAlpha(clip_scan, col);
+ int r = FXDIB_ALPHA_MERGE(*ori_scan++, m_Red, src_alpha);
+ int g = FXDIB_ALPHA_MERGE(*ori_scan++, m_Green, src_alpha);
+ int b = FXDIB_ALPHA_MERGE(*ori_scan, m_Blue, src_alpha);
+ ori_scan += Bpp - 2;
+ *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, r, cover_scan[col]);
+ dest_scan++;
+ *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, g, cover_scan[col]);
+ dest_scan++;
+ *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, b, cover_scan[col]);
+ dest_scan += Bpp - 2;
}
- pos0 = HardClip(pos0);
- pos2 = HardClip(pos2);
- pos3 = HardClip(pos3);
- agg::curve4 curve(pos0.x, pos0.y, pos.x, pos.y, pos2.x, pos2.y, pos3.x,
- pos3.y);
- i += 2;
- m_PathData.add_path_curve(curve);
}
- if (pPoints[i].m_CloseFigure)
- m_PathData.end_poly();
+ return;
+ }
+ if (Bpp == 4 && bDestAlpha) {
+ for (int col = col_start; col < col_end; col++) {
+ int src_alpha = GetSrcAlpha(clip_scan, col);
+ int src_alpha_covered = src_alpha * cover_scan[col] / 255;
+ if (src_alpha_covered == 0) {
+ dest_scan += 4;
+ continue;
+ }
+ if (cover_scan[col] == 255) {
+ dest_scan[3] = src_alpha_covered;
+ *dest_scan++ = m_Blue;
+ *dest_scan++ = m_Green;
+ *dest_scan = m_Red;
+ dest_scan += 2;
+ continue;
+ }
+ if (dest_scan[3] == 0) {
+ dest_scan[3] = src_alpha_covered;
+ *dest_scan++ = m_Blue;
+ *dest_scan++ = m_Green;
+ *dest_scan = m_Red;
+ dest_scan += 2;
+ continue;
+ }
+ uint8_t cover = cover_scan[col];
+ dest_scan[3] = FXDIB_ALPHA_MERGE(dest_scan[3], src_alpha, cover);
+ *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, m_Blue, cover);
+ dest_scan++;
+ *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, m_Green, cover);
+ dest_scan++;
+ *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, m_Red, cover);
+ dest_scan += 2;
+ }
+ return;
+ }
+ if (Bpp == 3 || Bpp == 4) {
+ for (int col = col_start; col < col_end; col++) {
+ int src_alpha = GetSrcAlpha(clip_scan, col);
+ if (m_bFullCover) {
+ *dest_scan++ = FXDIB_ALPHA_MERGE(*ori_scan++, m_Blue, src_alpha);
+ *dest_scan++ = FXDIB_ALPHA_MERGE(*ori_scan++, m_Green, src_alpha);
+ *dest_scan = FXDIB_ALPHA_MERGE(*ori_scan, m_Red, src_alpha);
+ dest_scan += Bpp - 2;
+ ori_scan += Bpp - 2;
+ continue;
+ }
+ int b = FXDIB_ALPHA_MERGE(*ori_scan++, m_Blue, src_alpha);
+ int g = FXDIB_ALPHA_MERGE(*ori_scan++, m_Green, src_alpha);
+ int r = FXDIB_ALPHA_MERGE(*ori_scan, m_Red, src_alpha);
+ ori_scan += Bpp - 2;
+ *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, b, cover_scan[col]);
+ dest_scan++;
+ *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, g, cover_scan[col]);
+ dest_scan++;
+ *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, r, cover_scan[col]);
+ dest_scan += Bpp - 2;
+ continue;
+ }
+ return;
+ }
+ if (Bpp == 1) {
+ for (int col = col_start; col < col_end; col++) {
+ int src_alpha = GetSrcAlpha(clip_scan, col);
+ if (m_bFullCover) {
+ *dest_scan = FXDIB_ALPHA_MERGE(*ori_scan++, m_Gray, src_alpha);
+ continue;
+ }
+ int gray = FXDIB_ALPHA_MERGE(*ori_scan++, m_Gray, src_alpha);
+ *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, gray, cover_scan[col]);
+ dest_scan++;
+ }
+ return;
+ }
+ CompositeSpan1bppHelper(dest_scan, col_start, col_end, cover_scan, clip_scan,
+ span_left);
+}
+
+void CFX_Renderer::CompositeSpan1bpp(uint8_t* dest_scan,
+ int Bpp,
+ int span_left,
+ int span_len,
+ uint8_t* cover_scan,
+ int clip_left,
+ int clip_right,
+ uint8_t* clip_scan,
+ uint8_t* dest_extra_alpha_scan) {
+ ASSERT(!m_bRgbByteOrder);
+ ASSERT(!m_pDevice->IsCmykImage());
+ int col_start = GetColStart(span_left, clip_left);
+ int col_end = GetColEnd(span_left, span_len, clip_right);
+ dest_scan += col_start / 8;
+ CompositeSpan1bppHelper(dest_scan, col_start, col_end, cover_scan, clip_scan,
+ span_left);
+}
+
+void CFX_Renderer::CompositeSpanGray(uint8_t* dest_scan,
+ int Bpp,
+ int span_left,
+ int span_len,
+ uint8_t* cover_scan,
+ int clip_left,
+ int clip_right,
+ uint8_t* clip_scan,
+ uint8_t* dest_extra_alpha_scan) {
+ ASSERT(!m_bRgbByteOrder);
+ int col_start = GetColStart(span_left, clip_left);
+ int col_end = GetColEnd(span_left, span_len, clip_right);
+ dest_scan += col_start;
+ if (dest_extra_alpha_scan) {
+ for (int col = col_start; col < col_end; col++) {
+ int src_alpha = m_bFullCover ? GetSrcAlpha(clip_scan, col)
+ : GetSourceAlpha(cover_scan, clip_scan, col);
+ if (src_alpha) {
+ if (src_alpha == 255) {
+ *dest_scan = m_Gray;
+ *dest_extra_alpha_scan = m_Alpha;
+ } else {
+ uint8_t dest_alpha = (*dest_extra_alpha_scan) + src_alpha -
+ (*dest_extra_alpha_scan) * src_alpha / 255;
+ *dest_extra_alpha_scan++ = dest_alpha;
+ int alpha_ratio = src_alpha * 255 / dest_alpha;
+ *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, m_Gray, alpha_ratio);
+ dest_scan++;
+ continue;
+ }
+ }
+ dest_extra_alpha_scan++;
+ dest_scan++;
+ }
+ return;
+ }
+ for (int col = col_start; col < col_end; col++) {
+ int src_alpha = GetSourceAlpha(cover_scan, clip_scan, col);
+ if (src_alpha) {
+ if (src_alpha == 255)
+ *dest_scan = m_Gray;
+ else
+ *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, m_Gray, src_alpha);
+ }
+ dest_scan++;
+ }
+}
+
+void CFX_Renderer::CompositeSpanARGB(uint8_t* dest_scan,
+ int Bpp,
+ int span_left,
+ int span_len,
+ uint8_t* cover_scan,
+ int clip_left,
+ int clip_right,
+ uint8_t* clip_scan,
+ uint8_t* dest_extra_alpha_scan) {
+ int col_start = GetColStart(span_left, clip_left);
+ int col_end = GetColEnd(span_left, span_len, clip_right);
+ dest_scan += col_start * Bpp;
+ if (m_bRgbByteOrder) {
+ for (int col = col_start; col < col_end; col++) {
+ int src_alpha = m_bFullCover ? GetSrcAlpha(clip_scan, col)
+ : GetSourceAlpha(cover_scan, clip_scan, col);
+ if (src_alpha) {
+ if (src_alpha == 255) {
+ *(reinterpret_cast<uint32_t*>(dest_scan)) = m_Color;
+ } else {
+ uint8_t dest_alpha =
+ dest_scan[3] + src_alpha - dest_scan[3] * src_alpha / 255;
+ dest_scan[3] = dest_alpha;
+ int alpha_ratio = src_alpha * 255 / dest_alpha;
+ *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, m_Red, alpha_ratio);
+ dest_scan++;
+ *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, m_Green, alpha_ratio);
+ dest_scan++;
+ *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, m_Blue, alpha_ratio);
+ dest_scan += 2;
+ continue;
+ }
+ }
+ dest_scan += 4;
+ }
+ return;
+ }
+ for (int col = col_start; col < col_end; col++) {
+ int src_alpha = m_bFullCover ? GetSrcAlpha(clip_scan, col)
+ : GetSourceAlpha(cover_scan, clip_scan, col);
+ if (src_alpha) {
+ if (src_alpha == 255) {
+ *(reinterpret_cast<uint32_t*>(dest_scan)) = m_Color;
+ } else {
+ if (dest_scan[3] == 0) {
+ dest_scan[3] = src_alpha;
+ *dest_scan++ = m_Blue;
+ *dest_scan++ = m_Green;
+ *dest_scan = m_Red;
+ dest_scan += 2;
+ continue;
+ }
+ uint8_t dest_alpha =
+ dest_scan[3] + src_alpha - dest_scan[3] * src_alpha / 255;
+ dest_scan[3] = dest_alpha;
+ int alpha_ratio = src_alpha * 255 / dest_alpha;
+ *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, m_Blue, alpha_ratio);
+ dest_scan++;
+ *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, m_Green, alpha_ratio);
+ dest_scan++;
+ *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, m_Red, alpha_ratio);
+ dest_scan += 2;
+ continue;
+ }
+ }
+ dest_scan += Bpp;
}
}
+void CFX_Renderer::CompositeSpanRGB(uint8_t* dest_scan,
+ int Bpp,
+ int span_left,
+ int span_len,
+ uint8_t* cover_scan,
+ int clip_left,
+ int clip_right,
+ uint8_t* clip_scan,
+ uint8_t* dest_extra_alpha_scan) {
+ int col_start = GetColStart(span_left, clip_left);
+ int col_end = GetColEnd(span_left, span_len, clip_right);
+ dest_scan += col_start * Bpp;
+ if (m_bRgbByteOrder) {
+ for (int col = col_start; col < col_end; col++) {
+ int src_alpha = GetSourceAlpha(cover_scan, clip_scan, col);
+ if (src_alpha) {
+ if (src_alpha == 255) {
+ if (Bpp == 4) {
+ *(uint32_t*)dest_scan = m_Color;
+ } else if (Bpp == 3) {
+ *dest_scan++ = m_Red;
+ *dest_scan++ = m_Green;
+ *dest_scan++ = m_Blue;
+ continue;
+ }
+ } else {
+ *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, m_Red, src_alpha);
+ dest_scan++;
+ *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, m_Green, src_alpha);
+ dest_scan++;
+ *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, m_Blue, src_alpha);
+ dest_scan += Bpp - 2;
+ continue;
+ }
+ }
+ dest_scan += Bpp;
+ }
+ return;
+ }
+ if (Bpp == 3 && dest_extra_alpha_scan) {
+ for (int col = col_start; col < col_end; col++) {
+ int src_alpha = m_bFullCover ? GetSrcAlpha(clip_scan, col)
+ : GetSourceAlpha(cover_scan, clip_scan, col);
+ if (src_alpha) {
+ if (src_alpha == 255) {
+ *dest_scan++ = static_cast<uint8_t>(m_Blue);
+ *dest_scan++ = static_cast<uint8_t>(m_Green);
+ *dest_scan++ = static_cast<uint8_t>(m_Red);
+ *dest_extra_alpha_scan++ = static_cast<uint8_t>(m_Alpha);
+ continue;
+ }
+ uint8_t dest_alpha = (*dest_extra_alpha_scan) + src_alpha -
+ (*dest_extra_alpha_scan) * src_alpha / 255;
+ *dest_extra_alpha_scan++ = dest_alpha;
+ int alpha_ratio = src_alpha * 255 / dest_alpha;
+ *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, m_Blue, alpha_ratio);
+ dest_scan++;
+ *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, m_Green, alpha_ratio);
+ dest_scan++;
+ *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, m_Red, alpha_ratio);
+ dest_scan++;
+ continue;
+ }
+ dest_extra_alpha_scan++;
+ dest_scan += Bpp;
+ }
+ return;
+ }
+ for (int col = col_start; col < col_end; col++) {
+ int src_alpha = m_bFullCover ? GetSrcAlpha(clip_scan, col)
+ : GetSourceAlpha(cover_scan, clip_scan, col);
+ if (src_alpha) {
+ if (src_alpha == 255) {
+ if (Bpp == 4) {
+ *(uint32_t*)dest_scan = m_Color;
+ } else if (Bpp == 3) {
+ *dest_scan++ = m_Blue;
+ *dest_scan++ = m_Green;
+ *dest_scan++ = m_Red;
+ continue;
+ }
+ } else {
+ *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, m_Blue, src_alpha);
+ dest_scan++;
+ *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, m_Green, src_alpha);
+ dest_scan++;
+ *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, m_Red, src_alpha);
+ dest_scan += Bpp - 2;
+ continue;
+ }
+ }
+ dest_scan += Bpp;
+ }
+}
+
+void CFX_Renderer::CompositeSpanCMYK(uint8_t* dest_scan,
+ int Bpp,
+ int span_left,
+ int span_len,
+ uint8_t* cover_scan,
+ int clip_left,
+ int clip_right,
+ uint8_t* clip_scan,
+ uint8_t* dest_extra_alpha_scan) {
+ ASSERT(!m_bRgbByteOrder);
+ int col_start = GetColStart(span_left, clip_left);
+ int col_end = GetColEnd(span_left, span_len, clip_right);
+ dest_scan += col_start * 4;
+ if (dest_extra_alpha_scan) {
+ for (int col = col_start; col < col_end; col++) {
+ int src_alpha = m_bFullCover ? GetSrcAlpha(clip_scan, col)
+ : GetSourceAlpha(cover_scan, clip_scan, col);
+ if (src_alpha) {
+ if (src_alpha == 255) {
+ *(reinterpret_cast<FX_CMYK*>(dest_scan)) = m_Color;
+ *dest_extra_alpha_scan = static_cast<uint8_t>(m_Alpha);
+ } else {
+ uint8_t dest_alpha = (*dest_extra_alpha_scan) + src_alpha -
+ (*dest_extra_alpha_scan) * src_alpha / 255;
+ *dest_extra_alpha_scan++ = dest_alpha;
+ int alpha_ratio = src_alpha * 255 / dest_alpha;
+ *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, m_Red, alpha_ratio);
+ dest_scan++;
+ *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, m_Green, alpha_ratio);
+ dest_scan++;
+ *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, m_Blue, alpha_ratio);
+ dest_scan++;
+ *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, m_Gray, alpha_ratio);
+ dest_scan++;
+ continue;
+ }
+ }
+ dest_extra_alpha_scan++;
+ dest_scan += 4;
+ }
+ return;
+ }
+ for (int col = col_start; col < col_end; col++) {
+ int src_alpha = GetSourceAlpha(cover_scan, clip_scan, col);
+ if (src_alpha) {
+ if (src_alpha == 255) {
+ *(reinterpret_cast<FX_CMYK*>(dest_scan)) = m_Color;
+ } else {
+ *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, m_Red, src_alpha);
+ dest_scan++;
+ *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, m_Green, src_alpha);
+ dest_scan++;
+ *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, m_Blue, src_alpha);
+ dest_scan++;
+ *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, m_Gray, src_alpha);
+ dest_scan++;
+ continue;
+ }
+ }
+ dest_scan += 4;
+ }
+}
+
+bool CFX_Renderer::Init(const CFX_RetainPtr<CFX_DIBitmap>& pDevice,
+ const CFX_RetainPtr<CFX_DIBitmap>& pOriDevice,
+ const CFX_ClipRgn* pClipRgn,
+ uint32_t color,
+ bool bFullCover,
+ bool bRgbByteOrder,
+ int alpha_flag,
+ void* pIccTransform) {
+ m_pDevice = pDevice;
+ m_pClipRgn = pClipRgn;
+ composite_span = nullptr;
+ m_bRgbByteOrder = bRgbByteOrder;
+ m_pOriDevice = pOriDevice;
+ if (m_pClipRgn) {
+ m_ClipBox = m_pClipRgn->GetBox();
+ } else {
+ m_ClipBox.left = m_ClipBox.top = 0;
+ m_ClipBox.right = m_pDevice->GetWidth();
+ m_ClipBox.bottom = m_pDevice->GetHeight();
+ }
+ m_pClipMask = nullptr;
+ if (m_pClipRgn && m_pClipRgn->GetType() == CFX_ClipRgn::MaskF)
+ m_pClipMask = m_pClipRgn->GetMask();
+ m_bFullCover = bFullCover;
+ bool bObjectCMYK = !!FXGETFLAG_COLORTYPE(alpha_flag);
+ bool bDeviceCMYK = pDevice->IsCmykImage();
+ m_Alpha = bObjectCMYK ? FXGETFLAG_ALPHA_FILL(alpha_flag) : FXARGB_A(color);
+ CCodec_IccModule* pIccModule = nullptr;
+ if (!CFX_GEModule::Get()->GetCodecModule() ||
+ !CFX_GEModule::Get()->GetCodecModule()->GetIccModule()) {
+ pIccTransform = nullptr;
+ } else {
+ pIccModule = CFX_GEModule::Get()->GetCodecModule()->GetIccModule();
+ }
+ if (m_pDevice->GetBPP() == 8) {
+ ASSERT(!m_bRgbByteOrder);
+ composite_span = &CFX_Renderer::CompositeSpanGray;
+ if (m_pDevice->IsAlphaMask()) {
+ m_Gray = 255;
+ } else {
+ if (pIccTransform) {
+ uint8_t gray;
+ color = bObjectCMYK ? FXCMYK_TODIB(color) : FXARGB_TODIB(color);
+ pIccModule->TranslateScanline(pIccTransform, &gray,
+ (const uint8_t*)&color, 1);
+ m_Gray = gray;
+ } else {
+ if (bObjectCMYK) {
+ uint8_t r, g, b;
+ AdobeCMYK_to_sRGB1(FXSYS_GetCValue(color), FXSYS_GetMValue(color),
+ FXSYS_GetYValue(color), FXSYS_GetKValue(color), r,
+ g, b);
+ m_Gray = FXRGB2GRAY(r, g, b);
+ } else {
+ m_Gray =
+ FXRGB2GRAY(FXARGB_R(color), FXARGB_G(color), FXARGB_B(color));
+ }
+ }
+ }
+ return true;
+ }
+ if (bDeviceCMYK) {
+ ASSERT(!m_bRgbByteOrder);
+ composite_span = &CFX_Renderer::CompositeSpanCMYK;
+ if (bObjectCMYK) {
+ m_Color = FXCMYK_TODIB(color);
+ if (pIccTransform) {
+ uint8_t* pColor = reinterpret_cast<uint8_t*>(&m_Color);
+ pIccModule->TranslateScanline(pIccTransform, pColor, pColor, 1);
+ }
+ } else {
+ if (!pIccTransform)
+ return false;
+
+ color = FXARGB_TODIB(color);
+ pIccModule->TranslateScanline(
+ pIccTransform, reinterpret_cast<uint8_t*>(&m_Color),
+ reinterpret_cast<const uint8_t*>(&color), 1);
+ }
+ uint8_t* pColor = reinterpret_cast<uint8_t*>(&m_Color);
+ m_Red = pColor[0];
+ m_Green = pColor[1];
+ m_Blue = pColor[2];
+ m_Gray = pColor[3];
+ } else {
+ composite_span = (pDevice->GetFormat() == FXDIB_Argb)
+ ? &CFX_Renderer::CompositeSpanARGB
+ : &CFX_Renderer::CompositeSpanRGB;
+ if (pIccTransform) {
+ color = bObjectCMYK ? FXCMYK_TODIB(color) : FXARGB_TODIB(color);
+ pIccModule->TranslateScanline(
+ pIccTransform, reinterpret_cast<uint8_t*>(&m_Color),
+ reinterpret_cast<const uint8_t*>(&color), 1);
+ uint8_t* pColor = reinterpret_cast<uint8_t*>(&m_Color);
+ pColor[3] = m_Alpha;
+ m_Red = pColor[2];
+ m_Green = pColor[1];
+ m_Blue = pColor[0];
+ if (m_bRgbByteOrder)
+ m_Color = FXARGB_TOBGRORDERDIB(FXARGB_TODIB(m_Color));
+ } else {
+ if (bObjectCMYK) {
+ uint8_t r, g, b;
+ AdobeCMYK_to_sRGB1(FXSYS_GetCValue(color), FXSYS_GetMValue(color),
+ FXSYS_GetYValue(color), FXSYS_GetKValue(color), r, g,
+ b);
+ m_Color = FXARGB_MAKE(m_Alpha, r, g, b);
+ if (m_bRgbByteOrder)
+ m_Color = FXARGB_TOBGRORDERDIB(m_Color);
+ else
+ m_Color = FXARGB_TODIB(m_Color);
+ m_Red = r;
+ m_Green = g;
+ m_Blue = b;
+ } else {
+ if (m_bRgbByteOrder)
+ m_Color = FXARGB_TOBGRORDERDIB(color);
+ else
+ m_Color = FXARGB_TODIB(color);
+ ArgbDecode(color, m_Alpha, m_Red, m_Green, m_Blue);
+ }
+ }
+ }
+ if (m_pDevice->GetBPP() == 1)
+ composite_span = &CFX_Renderer::CompositeSpan1bpp;
+ return true;
+}
+
+template <class Scanline>
+void CFX_Renderer::render(const Scanline& sl) {
+ if (!m_pOriDevice && !composite_span)
+ return;
+
+ int y = sl.y();
+ if (y < m_ClipBox.top || y >= m_ClipBox.bottom)
+ return;
+
+ uint8_t* dest_scan = m_pDevice->GetBuffer() + m_pDevice->GetPitch() * y;
+ uint8_t* dest_scan_extra_alpha = nullptr;
+ CFX_RetainPtr<CFX_DIBitmap> pAlphaMask = m_pDevice->m_pAlphaMask;
+ if (pAlphaMask) {
+ dest_scan_extra_alpha =
+ pAlphaMask->GetBuffer() + pAlphaMask->GetPitch() * y;
+ }
+ uint8_t* ori_scan = nullptr;
+ if (m_pOriDevice)
+ ori_scan = m_pOriDevice->GetBuffer() + m_pOriDevice->GetPitch() * y;
+ int Bpp = m_pDevice->GetBPP() / 8;
+ bool bDestAlpha = m_pDevice->HasAlpha() || m_pDevice->IsAlphaMask();
+ unsigned num_spans = sl.num_spans();
+ typename Scanline::const_iterator span = sl.begin();
+ while (1) {
+ int x = span->x;
+ ASSERT(span->len > 0);
+ uint8_t* dest_pos = nullptr;
+ uint8_t* dest_extra_alpha_pos = nullptr;
+ uint8_t* ori_pos = nullptr;
+ if (Bpp) {
+ ori_pos = ori_scan ? ori_scan + x * Bpp : nullptr;
+ dest_pos = dest_scan + x * Bpp;
+ dest_extra_alpha_pos =
+ dest_scan_extra_alpha ? dest_scan_extra_alpha + x : nullptr;
+ } else {
+ dest_pos = dest_scan + x / 8;
+ ori_pos = ori_scan ? ori_scan + x / 8 : nullptr;
+ }
+ uint8_t* clip_pos = nullptr;
+ if (m_pClipMask) {
+ clip_pos = m_pClipMask->GetBuffer() +
+ (y - m_ClipBox.top) * m_pClipMask->GetPitch() + x -
+ m_ClipBox.left;
+ }
+ if (ori_pos) {
+ CompositeSpan(dest_pos, ori_pos, Bpp, bDestAlpha, x, span->len,
+ span->covers, m_ClipBox.left, m_ClipBox.right, clip_pos);
+ } else {
+ (this->*composite_span)(dest_pos, Bpp, x, span->len, span->covers,
+ m_ClipBox.left, m_ClipBox.right, clip_pos,
+ dest_extra_alpha_pos);
+ }
+ if (--num_spans == 0)
+ break;
+
+ ++span;
+ }
+}
+
+void CFX_Renderer::CompositeSpan1bppHelper(uint8_t* dest_scan,
+ int col_start,
+ int col_end,
+ const uint8_t* cover_scan,
+ const uint8_t* clip_scan,
+ int span_left) {
+ int index = 0;
+ if (m_pDevice->GetPalette()) {
+ for (int i = 0; i < 2; i++) {
+ if (FXARGB_TODIB(m_pDevice->GetPalette()[i]) == m_Color)
+ index = i;
+ }
+ } else {
+ index = (static_cast<uint8_t>(m_Color) == 0xff) ? 1 : 0;
+ }
+ uint8_t* dest_scan1 = dest_scan;
+ for (int col = col_start; col < col_end; col++) {
+ int src_alpha = GetSourceAlpha(cover_scan, clip_scan, col);
+ if (src_alpha) {
+ if (!index)
+ *dest_scan1 &= ~(1 << (7 - (col + span_left) % 8));
+ else
+ *dest_scan1 |= 1 << (7 - (col + span_left) % 8);
+ }
+ dest_scan1 = dest_scan + (span_left % 8 + col - col_start + 1) / 8;
+ }
+}
+
+} // namespace
+
namespace agg {
template <class BaseRenderer>
@@ -330,7 +1138,7 @@ class renderer_scanline_aa_offset {
int y = sl.y();
unsigned num_spans = sl.num_spans();
typename Scanline::const_iterator span = sl.begin();
- for (;;) {
+ while (1) {
int x = span->x;
if (span->len > 0) {
m_ren->blend_solid_hspan(x - m_left, y - m_top, (unsigned)span->len,
@@ -339,9 +1147,9 @@ class renderer_scanline_aa_offset {
m_ren->blend_hline(x - m_left, y - m_top, (unsigned)(x - span->len - 1),
m_color, *(span->covers));
}
- if (--num_spans == 0) {
+ if (--num_spans == 0)
break;
- }
+
++span;
}
}
@@ -354,84 +1162,53 @@ class renderer_scanline_aa_offset {
} // namespace agg
-static void RasterizeStroke(agg::rasterizer_scanline_aa& rasterizer,
- agg::path_storage& path_data,
- const CFX_Matrix* pObject2Device,
- const CFX_GraphStateData* pGraphState,
- FX_FLOAT scale = 1.0f,
- bool bStrokeAdjust = false,
- bool bTextMode = false) {
- agg::line_cap_e cap;
- switch (pGraphState->m_LineCap) {
- case CFX_GraphStateData::LineCapRound:
- cap = agg::round_cap;
- break;
- case CFX_GraphStateData::LineCapSquare:
- cap = agg::square_cap;
- break;
- default:
- cap = agg::butt_cap;
- break;
- }
- agg::line_join_e join;
- switch (pGraphState->m_LineJoin) {
- case CFX_GraphStateData::LineJoinRound:
- join = agg::round_join;
- break;
- case CFX_GraphStateData::LineJoinBevel:
- join = agg::bevel_join;
- break;
- default:
- join = agg::miter_join_revert;
- break;
- }
- FX_FLOAT width = pGraphState->m_LineWidth * scale;
- FX_FLOAT unit = 1.f;
- if (pObject2Device) {
- unit =
- 1.0f / ((pObject2Device->GetXUnit() + pObject2Device->GetYUnit()) / 2);
- }
- if (width < unit) {
- width = unit;
- }
- if (pGraphState->m_DashArray) {
- typedef agg::conv_dash<agg::path_storage> dash_converter;
- dash_converter dash(path_data);
- for (int i = 0; i < (pGraphState->m_DashCount + 1) / 2; i++) {
- FX_FLOAT on = pGraphState->m_DashArray[i * 2];
- if (on <= 0.000001f) {
- on = 1.0f / 10;
+void CAgg_PathData::BuildPath(const CFX_PathData* pPathData,
+ const CFX_Matrix* pObject2Device) {
+ const std::vector<FX_PATHPOINT>& pPoints = pPathData->GetPoints();
+ for (size_t i = 0; i < pPoints.size(); i++) {
+ CFX_PointF pos = pPoints[i].m_Point;
+ if (pObject2Device)
+ pos = pObject2Device->Transform(pos);
+
+ pos = HardClip(pos);
+ FXPT_TYPE point_type = pPoints[i].m_Type;
+ if (point_type == FXPT_TYPE::MoveTo) {
+ m_PathData.move_to(pos.x, pos.y);
+ } else if (point_type == FXPT_TYPE::LineTo) {
+ if (pPoints[i - 1].IsTypeAndOpen(FXPT_TYPE::MoveTo) &&
+ (i == pPoints.size() - 1 ||
+ pPoints[i + 1].IsTypeAndOpen(FXPT_TYPE::MoveTo)) &&
+ pPoints[i].m_Point == pPoints[i - 1].m_Point) {
+ pos.x += 1;
}
- FX_FLOAT off = i * 2 + 1 == pGraphState->m_DashCount
- ? on
- : pGraphState->m_DashArray[i * 2 + 1];
- if (off < 0) {
- off = 0;
+ m_PathData.line_to(pos.x, pos.y);
+ } else if (point_type == FXPT_TYPE::BezierTo) {
+ CFX_PointF pos0 = pPoints[i - 1].m_Point;
+ CFX_PointF pos2 = pPoints[i + 1].m_Point;
+ CFX_PointF pos3 = pPoints[i + 2].m_Point;
+ if (pObject2Device) {
+ pos0 = pObject2Device->Transform(pos0);
+ pos2 = pObject2Device->Transform(pos2);
+ pos3 = pObject2Device->Transform(pos3);
}
- dash.add_dash(on * scale, off * scale);
+ pos0 = HardClip(pos0);
+ pos2 = HardClip(pos2);
+ pos3 = HardClip(pos3);
+ agg::curve4 curve(pos0.x, pos0.y, pos.x, pos.y, pos2.x, pos2.y, pos3.x,
+ pos3.y);
+ i += 2;
+ m_PathData.add_path_curve(curve);
}
- dash.dash_start(pGraphState->m_DashPhase * scale);
- typedef agg::conv_stroke<dash_converter> dash_stroke;
- dash_stroke stroke(dash);
- stroke.line_join(join);
- stroke.line_cap(cap);
- stroke.miter_limit(pGraphState->m_MiterLimit);
- stroke.width(width);
- rasterizer.add_path_transformed(stroke, pObject2Device);
- } else {
- agg::conv_stroke<agg::path_storage> stroke(path_data);
- stroke.line_join(join);
- stroke.line_cap(cap);
- stroke.miter_limit(pGraphState->m_MiterLimit);
- stroke.width(width);
- rasterizer.add_path_transformed(stroke, pObject2Device);
+ if (pPoints[i].m_CloseFigure)
+ m_PathData.end_poly();
}
}
-CFX_AggDeviceDriver::CFX_AggDeviceDriver(CFX_DIBitmap* pBitmap,
- bool bRgbByteOrder,
- CFX_DIBitmap* pOriDevice,
- bool bGroupKnockout)
+CFX_AggDeviceDriver::CFX_AggDeviceDriver(
+ const CFX_RetainPtr<CFX_DIBitmap>& pBitmap,
+ bool bRgbByteOrder,
+ const CFX_RetainPtr<CFX_DIBitmap>& pOriDevice,
+ bool bGroupKnockout)
: m_pBitmap(pBitmap),
#if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_
m_pPlatformGraphics(nullptr),
@@ -460,7 +1237,7 @@ bool CFX_AggDeviceDriver::DrawDeviceText(int nChars,
const FXTEXT_CHARPOS* pCharPos,
CFX_Font* pFont,
const CFX_Matrix* pObject2Device,
- FX_FLOAT font_size,
+ float font_size,
uint32_t color) {
return false;
}
@@ -485,19 +1262,18 @@ int CFX_AggDeviceDriver::GetDeviceCaps(int caps_id) const {
if (m_pBitmap->HasAlpha()) {
flags |= FXRC_ALPHA_OUTPUT;
} else if (m_pBitmap->IsAlphaMask()) {
- if (m_pBitmap->GetBPP() == 1) {
+ if (m_pBitmap->GetBPP() == 1)
flags |= FXRC_BITMASK_OUTPUT;
- } else {
+ else
flags |= FXRC_BYTEMASK_OUTPUT;
- }
}
- if (m_pBitmap->IsCmykImage()) {
+ if (m_pBitmap->IsCmykImage())
flags |= FXRC_CMYK_OUTPUT;
- }
return flags;
}
+ default:
+ return 0;
}
- return 0;
}
void CFX_AggDeviceDriver::SaveState() {
@@ -526,8 +1302,7 @@ void CFX_AggDeviceDriver::SetClipMask(agg::rasterizer_scanline_aa& rasterizer) {
FX_RECT path_rect(rasterizer.min_x(), rasterizer.min_y(),
rasterizer.max_x() + 1, rasterizer.max_y() + 1);
path_rect.Intersect(m_pClipRgn->GetBox());
- CFX_DIBitmapRef mask;
- CFX_DIBitmap* pThisLayer = mask.Emplace();
+ auto pThisLayer = pdfium::MakeRetain<CFX_DIBitmap>();
pThisLayer->Create(path_rect.Width(), path_rect.Height(), FXDIB_8bppMask);
pThisLayer->Clear(0);
agg::rendering_buffer raw_buf(pThisLayer->GetBuffer(), pThisLayer->GetWidth(),
@@ -541,7 +1316,7 @@ void CFX_AggDeviceDriver::SetClipMask(agg::rasterizer_scanline_aa& rasterizer) {
agg::scanline_u8 scanline;
agg::render_scanlines(rasterizer, scanline, final_render,
(m_FillFlags & FXFILL_NOPATHSMOOTH) != 0);
- m_pClipRgn->IntersectMaskF(path_rect.left, path_rect.top, mask);
+ m_pClipRgn->IntersectMaskF(path_rect.left, path_rect.top, pThisLayer);
}
bool CFX_AggDeviceDriver::SetClip_PathFill(const CFX_PathData* pPathData,
@@ -556,9 +1331,9 @@ bool CFX_AggDeviceDriver::SetClip_PathFill(const CFX_PathData* pPathData,
if (size == 5 || size == 4) {
CFX_FloatRect rectf;
if (pPathData->IsRect(pObject2Device, &rectf)) {
- rectf.Intersect(
- CFX_FloatRect(0, 0, (FX_FLOAT)GetDeviceCaps(FXDC_PIXEL_WIDTH),
- (FX_FLOAT)GetDeviceCaps(FXDC_PIXEL_HEIGHT)));
+ rectf.Intersect(CFX_FloatRect(
+ 0, 0, static_cast<float>(GetDeviceCaps(FXDC_PIXEL_WIDTH)),
+ static_cast<float>(GetDeviceCaps(FXDC_PIXEL_HEIGHT))));
FX_RECT rect = rectf.GetOuterRect();
m_pClipRgn->IntersectRect(rect);
return true;
@@ -568,8 +1343,9 @@ bool CFX_AggDeviceDriver::SetClip_PathFill(const CFX_PathData* pPathData,
path_data.BuildPath(pPathData, pObject2Device);
path_data.m_PathData.end_poly();
agg::rasterizer_scanline_aa rasterizer;
- rasterizer.clip_box(0.0f, 0.0f, (FX_FLOAT)(GetDeviceCaps(FXDC_PIXEL_WIDTH)),
- (FX_FLOAT)(GetDeviceCaps(FXDC_PIXEL_HEIGHT)));
+ rasterizer.clip_box(0.0f, 0.0f,
+ static_cast<float>(GetDeviceCaps(FXDC_PIXEL_WIDTH)),
+ static_cast<float>(GetDeviceCaps(FXDC_PIXEL_HEIGHT)));
rasterizer.add_path(path_data.m_PathData);
rasterizer.filling_rule((fill_mode & 3) == FXFILL_WINDING
? agg::fill_non_zero
@@ -589,843 +1365,16 @@ bool CFX_AggDeviceDriver::SetClip_PathStroke(
CAgg_PathData path_data;
path_data.BuildPath(pPathData, nullptr);
agg::rasterizer_scanline_aa rasterizer;
- rasterizer.clip_box(0.0f, 0.0f, (FX_FLOAT)(GetDeviceCaps(FXDC_PIXEL_WIDTH)),
- (FX_FLOAT)(GetDeviceCaps(FXDC_PIXEL_HEIGHT)));
- RasterizeStroke(rasterizer, path_data.m_PathData, pObject2Device,
- pGraphState);
+ rasterizer.clip_box(0.0f, 0.0f,
+ static_cast<float>(GetDeviceCaps(FXDC_PIXEL_WIDTH)),
+ static_cast<float>(GetDeviceCaps(FXDC_PIXEL_HEIGHT)));
+ RasterizeStroke(&rasterizer, &path_data.m_PathData, pObject2Device,
+ pGraphState, 1.0f, false, false);
rasterizer.filling_rule(agg::fill_non_zero);
SetClipMask(rasterizer);
return true;
}
-class CFX_Renderer {
- private:
- int m_Alpha, m_Red, m_Green, m_Blue, m_Gray;
- uint32_t m_Color;
- bool m_bFullCover;
- bool m_bRgbByteOrder;
- CFX_DIBitmap* m_pOriDevice;
- FX_RECT m_ClipBox;
- const CFX_DIBitmap* m_pClipMask;
- CFX_DIBitmap* m_pDevice;
- const CFX_ClipRgn* m_pClipRgn;
- void (CFX_Renderer::*composite_span)(uint8_t*,
- int,
- int,
- int,
- uint8_t*,
- int,
- int,
- uint8_t*,
- uint8_t*);
-
- public:
- void prepare(unsigned) {}
-
- void CompositeSpan(uint8_t* dest_scan,
- uint8_t* ori_scan,
- int Bpp,
- bool bDestAlpha,
- int span_left,
- int span_len,
- uint8_t* cover_scan,
- int clip_left,
- int clip_right,
- uint8_t* clip_scan) {
- ASSERT(!m_pDevice->IsCmykImage());
- int col_start = span_left < clip_left ? clip_left - span_left : 0;
- int col_end = (span_left + span_len) < clip_right
- ? span_len
- : (clip_right - span_left);
- if (Bpp) {
- dest_scan += col_start * Bpp;
- ori_scan += col_start * Bpp;
- } else {
- dest_scan += col_start / 8;
- ori_scan += col_start / 8;
- }
- if (m_bRgbByteOrder) {
- if (Bpp == 4 && bDestAlpha) {
- for (int col = col_start; col < col_end; col++) {
- int src_alpha;
- if (clip_scan) {
- src_alpha = m_Alpha * clip_scan[col] / 255;
- } else {
- src_alpha = m_Alpha;
- }
- uint8_t dest_alpha =
- ori_scan[3] + src_alpha - ori_scan[3] * src_alpha / 255;
- dest_scan[3] = dest_alpha;
- int alpha_ratio = src_alpha * 255 / dest_alpha;
- if (m_bFullCover) {
- *dest_scan++ = FXDIB_ALPHA_MERGE(*ori_scan++, m_Red, alpha_ratio);
- *dest_scan++ = FXDIB_ALPHA_MERGE(*ori_scan++, m_Green, alpha_ratio);
- *dest_scan++ = FXDIB_ALPHA_MERGE(*ori_scan++, m_Blue, alpha_ratio);
- dest_scan++;
- ori_scan++;
- } else {
- int r = FXDIB_ALPHA_MERGE(*ori_scan++, m_Red, alpha_ratio);
- int g = FXDIB_ALPHA_MERGE(*ori_scan++, m_Green, alpha_ratio);
- int b = FXDIB_ALPHA_MERGE(*ori_scan++, m_Blue, alpha_ratio);
- ori_scan++;
- *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, r, cover_scan[col]);
- dest_scan++;
- *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, g, cover_scan[col]);
- dest_scan++;
- *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, b, cover_scan[col]);
- dest_scan += 2;
- }
- }
- return;
- }
- if (Bpp == 3 || Bpp == 4) {
- for (int col = col_start; col < col_end; col++) {
- int src_alpha;
- if (clip_scan) {
- src_alpha = m_Alpha * clip_scan[col] / 255;
- } else {
- src_alpha = m_Alpha;
- }
- int r = FXDIB_ALPHA_MERGE(*ori_scan++, m_Red, src_alpha);
- int g = FXDIB_ALPHA_MERGE(*ori_scan++, m_Green, src_alpha);
- int b = FXDIB_ALPHA_MERGE(*ori_scan, m_Blue, src_alpha);
- ori_scan += Bpp - 2;
- *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, r, cover_scan[col]);
- dest_scan++;
- *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, g, cover_scan[col]);
- dest_scan++;
- *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, b, cover_scan[col]);
- dest_scan += Bpp - 2;
- }
- }
- return;
- }
- if (Bpp == 4 && bDestAlpha) {
- for (int col = col_start; col < col_end; col++) {
- int src_alpha;
- if (clip_scan) {
- src_alpha = m_Alpha * clip_scan[col] / 255;
- } else {
- src_alpha = m_Alpha;
- }
- int src_alpha_covered = src_alpha * cover_scan[col] / 255;
- if (src_alpha_covered == 0) {
- dest_scan += 4;
- continue;
- }
- if (cover_scan[col] == 255) {
- dest_scan[3] = src_alpha_covered;
- *dest_scan++ = m_Blue;
- *dest_scan++ = m_Green;
- *dest_scan = m_Red;
- dest_scan += 2;
- continue;
- } else {
- if (dest_scan[3] == 0) {
- dest_scan[3] = src_alpha_covered;
- *dest_scan++ = m_Blue;
- *dest_scan++ = m_Green;
- *dest_scan = m_Red;
- dest_scan += 2;
- continue;
- }
- uint8_t cover = cover_scan[col];
- dest_scan[3] = FXDIB_ALPHA_MERGE(dest_scan[3], src_alpha, cover);
- *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, m_Blue, cover);
- dest_scan++;
- *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, m_Green, cover);
- dest_scan++;
- *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, m_Red, cover);
- dest_scan += 2;
- }
- }
- return;
- }
- if (Bpp == 3 || Bpp == 4) {
- for (int col = col_start; col < col_end; col++) {
- int src_alpha;
- if (clip_scan) {
- src_alpha = m_Alpha * clip_scan[col] / 255;
- } else {
- src_alpha = m_Alpha;
- }
- if (m_bFullCover) {
- *dest_scan++ = FXDIB_ALPHA_MERGE(*ori_scan++, m_Blue, src_alpha);
- *dest_scan++ = FXDIB_ALPHA_MERGE(*ori_scan++, m_Green, src_alpha);
- *dest_scan = FXDIB_ALPHA_MERGE(*ori_scan, m_Red, src_alpha);
- dest_scan += Bpp - 2;
- ori_scan += Bpp - 2;
- continue;
- }
- int b = FXDIB_ALPHA_MERGE(*ori_scan++, m_Blue, src_alpha);
- int g = FXDIB_ALPHA_MERGE(*ori_scan++, m_Green, src_alpha);
- int r = FXDIB_ALPHA_MERGE(*ori_scan, m_Red, src_alpha);
- ori_scan += Bpp - 2;
- *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, b, cover_scan[col]);
- dest_scan++;
- *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, g, cover_scan[col]);
- dest_scan++;
- *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, r, cover_scan[col]);
- dest_scan += Bpp - 2;
- continue;
- }
- return;
- }
- if (Bpp == 1) {
- for (int col = col_start; col < col_end; col++) {
- int src_alpha;
- if (clip_scan) {
- src_alpha = m_Alpha * clip_scan[col] / 255;
- } else {
- src_alpha = m_Alpha;
- }
- if (m_bFullCover) {
- *dest_scan = FXDIB_ALPHA_MERGE(*ori_scan++, m_Gray, src_alpha);
- } else {
- int gray = FXDIB_ALPHA_MERGE(*ori_scan++, m_Gray, src_alpha);
- *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, gray, cover_scan[col]);
- dest_scan++;
- }
- }
- } else {
- int index = 0;
- if (m_pDevice->GetPalette()) {
- for (int i = 0; i < 2; i++) {
- if (FXARGB_TODIB(m_pDevice->GetPalette()[i]) == m_Color) {
- index = i;
- }
- }
- } else {
- index = ((uint8_t)m_Color == 0xff) ? 1 : 0;
- }
- uint8_t* dest_scan1 = dest_scan;
- for (int col = col_start; col < col_end; col++) {
- int src_alpha;
- if (clip_scan) {
- src_alpha = m_Alpha * cover_scan[col] * clip_scan[col] / 255 / 255;
- } else {
- src_alpha = m_Alpha * cover_scan[col] / 255;
- }
- if (src_alpha) {
- if (!index) {
- *dest_scan1 &= ~(1 << (7 - (col + span_left) % 8));
- } else {
- *dest_scan1 |= 1 << (7 - (col + span_left) % 8);
- }
- }
- dest_scan1 = dest_scan + (span_left % 8 + col - col_start + 1) / 8;
- }
- }
- }
-
- void CompositeSpan1bpp(uint8_t* dest_scan,
- int Bpp,
- int span_left,
- int span_len,
- uint8_t* cover_scan,
- int clip_left,
- int clip_right,
- uint8_t* clip_scan,
- uint8_t* dest_extra_alpha_scan) {
- ASSERT(!m_bRgbByteOrder);
- ASSERT(!m_pDevice->IsCmykImage());
- int col_start = span_left < clip_left ? clip_left - span_left : 0;
- int col_end = (span_left + span_len) < clip_right
- ? span_len
- : (clip_right - span_left);
- dest_scan += col_start / 8;
- int index = 0;
- if (m_pDevice->GetPalette()) {
- for (int i = 0; i < 2; i++) {
- if (FXARGB_TODIB(m_pDevice->GetPalette()[i]) == m_Color) {
- index = i;
- }
- }
- } else {
- index = ((uint8_t)m_Color == 0xff) ? 1 : 0;
- }
- uint8_t* dest_scan1 = dest_scan;
- for (int col = col_start; col < col_end; col++) {
- int src_alpha;
- if (clip_scan) {
- src_alpha = m_Alpha * cover_scan[col] * clip_scan[col] / 255 / 255;
- } else {
- src_alpha = m_Alpha * cover_scan[col] / 255;
- }
- if (src_alpha) {
- if (!index) {
- *dest_scan1 &= ~(1 << (7 - (col + span_left) % 8));
- } else {
- *dest_scan1 |= 1 << (7 - (col + span_left) % 8);
- }
- }
- dest_scan1 = dest_scan + (span_left % 8 + col - col_start + 1) / 8;
- }
- }
-
- void CompositeSpanGray(uint8_t* dest_scan,
- int Bpp,
- int span_left,
- int span_len,
- uint8_t* cover_scan,
- int clip_left,
- int clip_right,
- uint8_t* clip_scan,
- uint8_t* dest_extra_alpha_scan) {
- ASSERT(!m_bRgbByteOrder);
- int col_start = span_left < clip_left ? clip_left - span_left : 0;
- int col_end = (span_left + span_len) < clip_right
- ? span_len
- : (clip_right - span_left);
- dest_scan += col_start;
- if (dest_extra_alpha_scan) {
- for (int col = col_start; col < col_end; col++) {
- int src_alpha;
- if (m_bFullCover) {
- if (clip_scan) {
- src_alpha = m_Alpha * clip_scan[col] / 255;
- } else {
- src_alpha = m_Alpha;
- }
- } else {
- if (clip_scan) {
- src_alpha = m_Alpha * cover_scan[col] * clip_scan[col] / 255 / 255;
- } else {
- src_alpha = m_Alpha * cover_scan[col] / 255;
- }
- }
- if (src_alpha) {
- if (src_alpha == 255) {
- *dest_scan = m_Gray;
- *dest_extra_alpha_scan = m_Alpha;
- } else {
- uint8_t dest_alpha = (*dest_extra_alpha_scan) + src_alpha -
- (*dest_extra_alpha_scan) * src_alpha / 255;
- *dest_extra_alpha_scan++ = dest_alpha;
- int alpha_ratio = src_alpha * 255 / dest_alpha;
- *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, m_Gray, alpha_ratio);
- dest_scan++;
- continue;
- }
- }
- dest_extra_alpha_scan++;
- dest_scan++;
- }
- } else {
- for (int col = col_start; col < col_end; col++) {
- int src_alpha;
- if (clip_scan) {
- src_alpha = m_Alpha * cover_scan[col] * clip_scan[col] / 255 / 255;
- } else {
- src_alpha = m_Alpha * cover_scan[col] / 255;
- }
- if (src_alpha) {
- if (src_alpha == 255) {
- *dest_scan = m_Gray;
- } else {
- *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, m_Gray, src_alpha);
- }
- }
- dest_scan++;
- }
- }
- }
-
- void CompositeSpanARGB(uint8_t* dest_scan,
- int Bpp,
- int span_left,
- int span_len,
- uint8_t* cover_scan,
- int clip_left,
- int clip_right,
- uint8_t* clip_scan,
- uint8_t* dest_extra_alpha_scan) {
- int col_start = span_left < clip_left ? clip_left - span_left : 0;
- int col_end = (span_left + span_len) < clip_right
- ? span_len
- : (clip_right - span_left);
- dest_scan += col_start * Bpp;
- if (m_bRgbByteOrder) {
- for (int col = col_start; col < col_end; col++) {
- int src_alpha;
- if (m_bFullCover) {
- if (clip_scan) {
- src_alpha = m_Alpha * clip_scan[col] / 255;
- } else {
- src_alpha = m_Alpha;
- }
- } else {
- if (clip_scan) {
- src_alpha = m_Alpha * cover_scan[col] * clip_scan[col] / 255 / 255;
- } else {
- src_alpha = m_Alpha * cover_scan[col] / 255;
- }
- }
- if (src_alpha) {
- if (src_alpha == 255) {
- *(uint32_t*)dest_scan = m_Color;
- } else {
- uint8_t dest_alpha =
- dest_scan[3] + src_alpha - dest_scan[3] * src_alpha / 255;
- dest_scan[3] = dest_alpha;
- int alpha_ratio = src_alpha * 255 / dest_alpha;
- *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, m_Red, alpha_ratio);
- dest_scan++;
- *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, m_Green, alpha_ratio);
- dest_scan++;
- *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, m_Blue, alpha_ratio);
- dest_scan += 2;
- continue;
- }
- }
- dest_scan += 4;
- }
- return;
- }
- for (int col = col_start; col < col_end; col++) {
- int src_alpha;
- if (m_bFullCover) {
- if (clip_scan) {
- src_alpha = m_Alpha * clip_scan[col] / 255;
- } else {
- src_alpha = m_Alpha;
- }
- } else {
- if (clip_scan) {
- src_alpha = m_Alpha * cover_scan[col] * clip_scan[col] / 255 / 255;
- } else {
- src_alpha = m_Alpha * cover_scan[col] / 255;
- }
- }
- if (src_alpha) {
- if (src_alpha == 255) {
- *(uint32_t*)dest_scan = m_Color;
- } else {
- if (dest_scan[3] == 0) {
- dest_scan[3] = src_alpha;
- *dest_scan++ = m_Blue;
- *dest_scan++ = m_Green;
- *dest_scan = m_Red;
- dest_scan += 2;
- continue;
- }
- uint8_t dest_alpha =
- dest_scan[3] + src_alpha - dest_scan[3] * src_alpha / 255;
- dest_scan[3] = dest_alpha;
- int alpha_ratio = src_alpha * 255 / dest_alpha;
- *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, m_Blue, alpha_ratio);
- dest_scan++;
- *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, m_Green, alpha_ratio);
- dest_scan++;
- *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, m_Red, alpha_ratio);
- dest_scan += 2;
- continue;
- }
- }
- dest_scan += Bpp;
- }
- }
-
- void CompositeSpanRGB(uint8_t* dest_scan,
- int Bpp,
- int span_left,
- int span_len,
- uint8_t* cover_scan,
- int clip_left,
- int clip_right,
- uint8_t* clip_scan,
- uint8_t* dest_extra_alpha_scan) {
- int col_start = span_left < clip_left ? clip_left - span_left : 0;
- int col_end = (span_left + span_len) < clip_right
- ? span_len
- : (clip_right - span_left);
- dest_scan += col_start * Bpp;
- if (m_bRgbByteOrder) {
- for (int col = col_start; col < col_end; col++) {
- int src_alpha;
- if (clip_scan) {
- src_alpha = m_Alpha * cover_scan[col] * clip_scan[col] / 255 / 255;
- } else {
- src_alpha = m_Alpha * cover_scan[col] / 255;
- }
- if (src_alpha) {
- if (src_alpha == 255) {
- if (Bpp == 4) {
- *(uint32_t*)dest_scan = m_Color;
- } else if (Bpp == 3) {
- *dest_scan++ = m_Red;
- *dest_scan++ = m_Green;
- *dest_scan++ = m_Blue;
- continue;
- }
- } else {
- *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, m_Red, src_alpha);
- dest_scan++;
- *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, m_Green, src_alpha);
- dest_scan++;
- *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, m_Blue, src_alpha);
- dest_scan += Bpp - 2;
- continue;
- }
- }
- dest_scan += Bpp;
- }
- return;
- }
- if (Bpp == 3 && dest_extra_alpha_scan) {
- for (int col = col_start; col < col_end; col++) {
- int src_alpha;
- if (m_bFullCover) {
- if (clip_scan) {
- src_alpha = m_Alpha * clip_scan[col] / 255;
- } else {
- src_alpha = m_Alpha;
- }
- } else {
- if (clip_scan) {
- src_alpha = m_Alpha * cover_scan[col] * clip_scan[col] / 255 / 255;
- } else {
- src_alpha = m_Alpha * cover_scan[col] / 255;
- }
- }
- if (src_alpha) {
- if (src_alpha == 255) {
- *dest_scan++ = (uint8_t)m_Blue;
- *dest_scan++ = (uint8_t)m_Green;
- *dest_scan++ = (uint8_t)m_Red;
- *dest_extra_alpha_scan++ = (uint8_t)m_Alpha;
- continue;
- } else {
- uint8_t dest_alpha = (*dest_extra_alpha_scan) + src_alpha -
- (*dest_extra_alpha_scan) * src_alpha / 255;
- *dest_extra_alpha_scan++ = dest_alpha;
- int alpha_ratio = src_alpha * 255 / dest_alpha;
- *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, m_Blue, alpha_ratio);
- dest_scan++;
- *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, m_Green, alpha_ratio);
- dest_scan++;
- *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, m_Red, alpha_ratio);
- dest_scan++;
- continue;
- }
- }
- dest_extra_alpha_scan++;
- dest_scan += Bpp;
- }
- } else {
- for (int col = col_start; col < col_end; col++) {
- int src_alpha;
- if (m_bFullCover) {
- if (clip_scan) {
- src_alpha = m_Alpha * clip_scan[col] / 255;
- } else {
- src_alpha = m_Alpha;
- }
- } else {
- if (clip_scan) {
- src_alpha = m_Alpha * cover_scan[col] * clip_scan[col] / 255 / 255;
- } else {
- src_alpha = m_Alpha * cover_scan[col] / 255;
- }
- }
- if (src_alpha) {
- if (src_alpha == 255) {
- if (Bpp == 4) {
- *(uint32_t*)dest_scan = m_Color;
- } else if (Bpp == 3) {
- *dest_scan++ = m_Blue;
- *dest_scan++ = m_Green;
- *dest_scan++ = m_Red;
- continue;
- }
- } else {
- *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, m_Blue, src_alpha);
- dest_scan++;
- *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, m_Green, src_alpha);
- dest_scan++;
- *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, m_Red, src_alpha);
- dest_scan += Bpp - 2;
- continue;
- }
- }
- dest_scan += Bpp;
- }
- }
- }
-
- void CompositeSpanCMYK(uint8_t* dest_scan,
- int Bpp,
- int span_left,
- int span_len,
- uint8_t* cover_scan,
- int clip_left,
- int clip_right,
- uint8_t* clip_scan,
- uint8_t* dest_extra_alpha_scan) {
- ASSERT(!m_bRgbByteOrder);
- int col_start = span_left < clip_left ? clip_left - span_left : 0;
- int col_end = (span_left + span_len) < clip_right
- ? span_len
- : (clip_right - span_left);
- dest_scan += col_start * 4;
- if (dest_extra_alpha_scan) {
- for (int col = col_start; col < col_end; col++) {
- int src_alpha;
- if (m_bFullCover) {
- if (clip_scan) {
- src_alpha = m_Alpha * clip_scan[col] / 255;
- } else {
- src_alpha = m_Alpha;
- }
- } else {
- if (clip_scan) {
- src_alpha = m_Alpha * cover_scan[col] * clip_scan[col] / 255 / 255;
- } else {
- src_alpha = m_Alpha * cover_scan[col] / 255;
- }
- }
- if (src_alpha) {
- if (src_alpha == 255) {
- *(FX_CMYK*)dest_scan = m_Color;
- *dest_extra_alpha_scan = (uint8_t)m_Alpha;
- } else {
- uint8_t dest_alpha = (*dest_extra_alpha_scan) + src_alpha -
- (*dest_extra_alpha_scan) * src_alpha / 255;
- *dest_extra_alpha_scan++ = dest_alpha;
- int alpha_ratio = src_alpha * 255 / dest_alpha;
- *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, m_Red, alpha_ratio);
- dest_scan++;
- *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, m_Green, alpha_ratio);
- dest_scan++;
- *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, m_Blue, alpha_ratio);
- dest_scan++;
- *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, m_Gray, alpha_ratio);
- dest_scan++;
- continue;
- }
- }
- dest_extra_alpha_scan++;
- dest_scan += 4;
- }
- } else {
- for (int col = col_start; col < col_end; col++) {
- int src_alpha;
- if (clip_scan) {
- src_alpha = m_Alpha * cover_scan[col] * clip_scan[col] / 255 / 255;
- } else {
- src_alpha = m_Alpha * cover_scan[col] / 255;
- }
- if (src_alpha) {
- if (src_alpha == 255) {
- *(FX_CMYK*)dest_scan = m_Color;
- } else {
- *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, m_Red, src_alpha);
- dest_scan++;
- *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, m_Green, src_alpha);
- dest_scan++;
- *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, m_Blue, src_alpha);
- dest_scan++;
- *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, m_Gray, src_alpha);
- dest_scan++;
- continue;
- }
- }
- dest_scan += 4;
- }
- }
- }
-
- template <class Scanline>
- void render(const Scanline& sl) {
- if (!m_pOriDevice && !composite_span) {
- return;
- }
- int y = sl.y();
- if (y < m_ClipBox.top || y >= m_ClipBox.bottom) {
- return;
- }
- uint8_t* dest_scan = m_pDevice->GetBuffer() + m_pDevice->GetPitch() * y;
- uint8_t* dest_scan_extra_alpha = nullptr;
- CFX_DIBitmap* pAlphaMask = m_pDevice->m_pAlphaMask;
- if (pAlphaMask) {
- dest_scan_extra_alpha =
- pAlphaMask->GetBuffer() + pAlphaMask->GetPitch() * y;
- }
- uint8_t* ori_scan = nullptr;
- if (m_pOriDevice) {
- ori_scan = m_pOriDevice->GetBuffer() + m_pOriDevice->GetPitch() * y;
- }
- int Bpp = m_pDevice->GetBPP() / 8;
- bool bDestAlpha = m_pDevice->HasAlpha() || m_pDevice->IsAlphaMask();
- unsigned num_spans = sl.num_spans();
- typename Scanline::const_iterator span = sl.begin();
- while (1) {
- int x = span->x;
- ASSERT(span->len > 0);
- uint8_t* dest_pos = nullptr;
- uint8_t* dest_extra_alpha_pos = nullptr;
- uint8_t* ori_pos = nullptr;
- if (Bpp) {
- ori_pos = ori_scan ? ori_scan + x * Bpp : nullptr;
- dest_pos = dest_scan + x * Bpp;
- dest_extra_alpha_pos =
- dest_scan_extra_alpha ? dest_scan_extra_alpha + x : nullptr;
- } else {
- dest_pos = dest_scan + x / 8;
- ori_pos = ori_scan ? ori_scan + x / 8 : nullptr;
- }
- uint8_t* clip_pos = nullptr;
- if (m_pClipMask) {
- clip_pos = m_pClipMask->GetBuffer() +
- (y - m_ClipBox.top) * m_pClipMask->GetPitch() + x -
- m_ClipBox.left;
- }
- if (ori_pos) {
- CompositeSpan(dest_pos, ori_pos, Bpp, bDestAlpha, x, span->len,
- span->covers, m_ClipBox.left, m_ClipBox.right, clip_pos);
- } else {
- (this->*composite_span)(dest_pos, Bpp, x, span->len, span->covers,
- m_ClipBox.left, m_ClipBox.right, clip_pos,
- dest_extra_alpha_pos);
- }
- if (--num_spans == 0) {
- break;
- }
- ++span;
- }
- }
-
- bool Init(CFX_DIBitmap* pDevice,
- CFX_DIBitmap* pOriDevice,
- const CFX_ClipRgn* pClipRgn,
- uint32_t color,
- bool bFullCover,
- bool bRgbByteOrder,
- int alpha_flag = 0,
- void* pIccTransform = nullptr) {
- m_pDevice = pDevice;
- m_pClipRgn = pClipRgn;
- composite_span = nullptr;
- m_bRgbByteOrder = bRgbByteOrder;
- m_pOriDevice = pOriDevice;
- if (m_pClipRgn) {
- m_ClipBox = m_pClipRgn->GetBox();
- } else {
- m_ClipBox.left = m_ClipBox.top = 0;
- m_ClipBox.right = m_pDevice->GetWidth();
- m_ClipBox.bottom = m_pDevice->GetHeight();
- }
- m_pClipMask = nullptr;
- if (m_pClipRgn && m_pClipRgn->GetType() == CFX_ClipRgn::MaskF) {
- m_pClipMask = m_pClipRgn->GetMask().GetObject();
- }
- m_bFullCover = bFullCover;
- bool bObjectCMYK = !!FXGETFLAG_COLORTYPE(alpha_flag);
- bool bDeviceCMYK = pDevice->IsCmykImage();
- m_Alpha = bObjectCMYK ? FXGETFLAG_ALPHA_FILL(alpha_flag) : FXARGB_A(color);
- CCodec_IccModule* pIccModule = nullptr;
- if (!CFX_GEModule::Get()->GetCodecModule() ||
- !CFX_GEModule::Get()->GetCodecModule()->GetIccModule()) {
- pIccTransform = nullptr;
- } else {
- pIccModule = CFX_GEModule::Get()->GetCodecModule()->GetIccModule();
- }
- if (m_pDevice->GetBPP() == 8) {
- ASSERT(!m_bRgbByteOrder);
- composite_span = &CFX_Renderer::CompositeSpanGray;
- if (m_pDevice->IsAlphaMask()) {
- m_Gray = 255;
- } else {
- if (pIccTransform) {
- uint8_t gray;
- color = bObjectCMYK ? FXCMYK_TODIB(color) : FXARGB_TODIB(color);
- pIccModule->TranslateScanline(pIccTransform, &gray,
- (const uint8_t*)&color, 1);
- m_Gray = gray;
- } else {
- if (bObjectCMYK) {
- uint8_t r, g, b;
- AdobeCMYK_to_sRGB1(FXSYS_GetCValue(color), FXSYS_GetMValue(color),
- FXSYS_GetYValue(color), FXSYS_GetKValue(color),
- r, g, b);
- m_Gray = FXRGB2GRAY(r, g, b);
- } else {
- m_Gray =
- FXRGB2GRAY(FXARGB_R(color), FXARGB_G(color), FXARGB_B(color));
- }
- }
- }
- return true;
- }
- if (bDeviceCMYK) {
- ASSERT(!m_bRgbByteOrder);
- composite_span = &CFX_Renderer::CompositeSpanCMYK;
- if (bObjectCMYK) {
- m_Color = FXCMYK_TODIB(color);
- if (pIccTransform) {
- pIccModule->TranslateScanline(pIccTransform, (uint8_t*)&m_Color,
- (const uint8_t*)&m_Color, 1);
- }
- } else {
- if (!pIccTransform) {
- return false;
- }
- color = FXARGB_TODIB(color);
- pIccModule->TranslateScanline(pIccTransform, (uint8_t*)&m_Color,
- (const uint8_t*)&color, 1);
- }
- m_Red = ((uint8_t*)&m_Color)[0];
- m_Green = ((uint8_t*)&m_Color)[1];
- m_Blue = ((uint8_t*)&m_Color)[2];
- m_Gray = ((uint8_t*)&m_Color)[3];
- } else {
- composite_span = (pDevice->GetFormat() == FXDIB_Argb)
- ? &CFX_Renderer::CompositeSpanARGB
- : &CFX_Renderer::CompositeSpanRGB;
- if (pIccTransform) {
- color = bObjectCMYK ? FXCMYK_TODIB(color) : FXARGB_TODIB(color);
- pIccModule->TranslateScanline(pIccTransform, (uint8_t*)&m_Color,
- (const uint8_t*)&color, 1);
- ((uint8_t*)&m_Color)[3] = m_Alpha;
- m_Red = ((uint8_t*)&m_Color)[2];
- m_Green = ((uint8_t*)&m_Color)[1];
- m_Blue = ((uint8_t*)&m_Color)[0];
- if (m_bRgbByteOrder) {
- m_Color = FXARGB_TODIB(m_Color);
- m_Color = FXARGB_TOBGRORDERDIB(m_Color);
- }
- } else {
- if (bObjectCMYK) {
- uint8_t r, g, b;
- AdobeCMYK_to_sRGB1(FXSYS_GetCValue(color), FXSYS_GetMValue(color),
- FXSYS_GetYValue(color), FXSYS_GetKValue(color), r,
- g, b);
- m_Color = FXARGB_MAKE(m_Alpha, r, g, b);
- if (m_bRgbByteOrder) {
- m_Color = FXARGB_TOBGRORDERDIB(m_Color);
- } else {
- m_Color = FXARGB_TODIB(m_Color);
- }
- m_Red = r;
- m_Green = g;
- m_Blue = b;
- } else {
- if (m_bRgbByteOrder) {
- m_Color = FXARGB_TOBGRORDERDIB(color);
- } else {
- m_Color = FXARGB_TODIB(color);
- }
- ArgbDecode(color, m_Alpha, m_Red, m_Green, m_Blue);
- }
- }
- }
- if (m_pDevice->GetBPP() == 1) {
- composite_span = &CFX_Renderer::CompositeSpan1bpp;
- }
- return true;
- }
-};
-
int CFX_AggDeviceDriver::GetDriverType() const {
return 1;
}
@@ -1437,7 +1386,7 @@ bool CFX_AggDeviceDriver::RenderRasterizer(
bool bGroupKnockout,
int alpha_flag,
void* pIccTransform) {
- CFX_DIBitmap* pt = bGroupKnockout ? m_pOriDevice : nullptr;
+ CFX_RetainPtr<CFX_DIBitmap> pt = bGroupKnockout ? m_pOriDevice : nullptr;
CFX_Renderer render;
if (!render.Init(m_pBitmap, pt, m_pClipRgn.get(), color, bFullCover,
m_bRgbByteOrder, alpha_flag, pIccTransform)) {
@@ -1467,8 +1416,9 @@ bool CFX_AggDeviceDriver::DrawPath(const CFX_PathData* pPathData,
CAgg_PathData path_data;
path_data.BuildPath(pPathData, pObject2Device);
agg::rasterizer_scanline_aa rasterizer;
- rasterizer.clip_box(0.0f, 0.0f, (FX_FLOAT)(GetDeviceCaps(FXDC_PIXEL_WIDTH)),
- (FX_FLOAT)(GetDeviceCaps(FXDC_PIXEL_HEIGHT)));
+ rasterizer.clip_box(0.0f, 0.0f,
+ static_cast<float>(GetDeviceCaps(FXDC_PIXEL_WIDTH)),
+ static_cast<float>(GetDeviceCaps(FXDC_PIXEL_HEIGHT)));
rasterizer.add_path(path_data.m_PathData);
rasterizer.filling_rule((fill_mode & 3) == FXFILL_WINDING
? agg::fill_non_zero
@@ -1487,9 +1437,10 @@ bool CFX_AggDeviceDriver::DrawPath(const CFX_PathData* pPathData,
CAgg_PathData path_data;
path_data.BuildPath(pPathData, pObject2Device);
agg::rasterizer_scanline_aa rasterizer;
- rasterizer.clip_box(0.0f, 0.0f, (FX_FLOAT)(GetDeviceCaps(FXDC_PIXEL_WIDTH)),
- (FX_FLOAT)(GetDeviceCaps(FXDC_PIXEL_HEIGHT)));
- RasterizeStroke(rasterizer, path_data.m_PathData, nullptr, pGraphState, 1,
+ rasterizer.clip_box(0.0f, 0.0f,
+ static_cast<float>(GetDeviceCaps(FXDC_PIXEL_WIDTH)),
+ static_cast<float>(GetDeviceCaps(FXDC_PIXEL_HEIGHT)));
+ RasterizeStroke(&rasterizer, &path_data.m_PathData, nullptr, pGraphState, 1,
false, !!(fill_mode & FX_STROKE_TEXT_MODE));
return RenderRasterizer(rasterizer, stroke_color,
!!(fill_mode & FXFILL_FULLCOVER), m_bGroupKnockout,
@@ -1498,8 +1449,7 @@ bool CFX_AggDeviceDriver::DrawPath(const CFX_PathData* pPathData,
CFX_Matrix matrix1;
CFX_Matrix matrix2;
if (pObject2Device) {
- matrix1.a =
- std::max(FXSYS_fabs(pObject2Device->a), FXSYS_fabs(pObject2Device->b));
+ matrix1.a = std::max(fabs(pObject2Device->a), fabs(pObject2Device->b));
matrix1.d = matrix1.a;
matrix2 = CFX_Matrix(
pObject2Device->a / matrix1.a, pObject2Device->b / matrix1.a,
@@ -1514,9 +1464,10 @@ bool CFX_AggDeviceDriver::DrawPath(const CFX_PathData* pPathData,
CAgg_PathData path_data;
path_data.BuildPath(pPathData, &matrix1);
agg::rasterizer_scanline_aa rasterizer;
- rasterizer.clip_box(0.0f, 0.0f, (FX_FLOAT)(GetDeviceCaps(FXDC_PIXEL_WIDTH)),
- (FX_FLOAT)(GetDeviceCaps(FXDC_PIXEL_HEIGHT)));
- RasterizeStroke(rasterizer, path_data.m_PathData, &matrix2, pGraphState,
+ rasterizer.clip_box(0.0f, 0.0f,
+ static_cast<float>(GetDeviceCaps(FXDC_PIXEL_WIDTH)),
+ static_cast<float>(GetDeviceCaps(FXDC_PIXEL_HEIGHT)));
+ RasterizeStroke(&rasterizer, &path_data.m_PathData, &matrix2, pGraphState,
matrix1.a, false, !!(fill_mode & FX_STROKE_TEXT_MODE));
return RenderRasterizer(rasterizer, stroke_color,
!!(fill_mode & FXFILL_FULLCOVER), m_bGroupKnockout, 0,
@@ -1545,8 +1496,8 @@ bool CFX_AggDeviceDriver::SetPixel(int x, int y, uint32_t color) {
if (m_pClipRgn->GetType() != CFX_ClipRgn::MaskF)
return true;
- const CFX_DIBitmap* pMask = m_pClipRgn->GetMask().GetObject();
- int new_alpha = FXARGB_A(color) * pMask->GetScanline(y)[x] / 255;
+ int new_alpha =
+ FXARGB_A(color) * m_pClipRgn->GetMask()->GetScanline(y)[x] / 255;
color = (color & 0xffffff) | (new_alpha << 24);
if (m_bRgbByteOrder) {
RgbByteOrderSetPixel(m_pBitmap, x, y, color);
@@ -1579,15 +1530,15 @@ bool CFX_AggDeviceDriver::FillRectWithBlend(const FX_RECT* pRect,
fill_color);
} else {
m_pBitmap->CompositeRect(draw_rect.left, draw_rect.top, draw_rect.Width(),
- draw_rect.Height(), fill_color, 0, nullptr);
+ draw_rect.Height(), fill_color, 0);
}
return true;
}
- m_pBitmap->CompositeMask(
- draw_rect.left, draw_rect.top, draw_rect.Width(), draw_rect.Height(),
- m_pClipRgn->GetMask().GetObject(), fill_color,
- draw_rect.left - clip_rect.left, draw_rect.top - clip_rect.top,
- FXDIB_BLEND_NORMAL, nullptr, m_bRgbByteOrder, 0, nullptr);
+ m_pBitmap->CompositeMask(draw_rect.left, draw_rect.top, draw_rect.Width(),
+ draw_rect.Height(), m_pClipRgn->GetMask(),
+ fill_color, draw_rect.left - clip_rect.left,
+ draw_rect.top - clip_rect.top, FXDIB_BLEND_NORMAL,
+ nullptr, m_bRgbByteOrder, 0);
return true;
}
@@ -1602,13 +1553,15 @@ bool CFX_AggDeviceDriver::GetClipBox(FX_RECT* pRect) {
return true;
}
-bool CFX_AggDeviceDriver::GetDIBits(CFX_DIBitmap* pBitmap, int left, int top) {
+bool CFX_AggDeviceDriver::GetDIBits(const CFX_RetainPtr<CFX_DIBitmap>& pBitmap,
+ int left,
+ int top) {
if (!m_pBitmap || !m_pBitmap->GetBuffer())
return true;
FX_RECT rect(left, top, left + pBitmap->GetWidth(),
top + pBitmap->GetHeight());
- std::unique_ptr<CFX_DIBitmap> pBack;
+ CFX_RetainPtr<CFX_DIBitmap> pBack;
if (m_pOriDevice) {
pBack = m_pOriDevice->Clone(&rect);
if (!pBack)
@@ -1626,18 +1579,18 @@ bool CFX_AggDeviceDriver::GetDIBits(CFX_DIBitmap* pBitmap, int left, int top) {
top = std::min(top, 0);
if (m_bRgbByteOrder) {
RgbByteOrderTransferBitmap(pBitmap, 0, 0, rect.Width(), rect.Height(),
- pBack.get(), left, top);
+ pBack, left, top);
return true;
}
- return pBitmap->TransferBitmap(0, 0, rect.Width(), rect.Height(), pBack.get(),
- left, top);
+ return pBitmap->TransferBitmap(0, 0, rect.Width(), rect.Height(), pBack, left,
+ top);
}
-CFX_DIBitmap* CFX_AggDeviceDriver::GetBackDrop() {
+CFX_RetainPtr<CFX_DIBitmap> CFX_AggDeviceDriver::GetBackDrop() {
return m_pOriDevice;
}
-bool CFX_AggDeviceDriver::SetDIBits(const CFX_DIBSource* pBitmap,
+bool CFX_AggDeviceDriver::SetDIBits(const CFX_RetainPtr<CFX_DIBSource>& pBitmap,
uint32_t argb,
const FX_RECT* pSrcRect,
int left,
@@ -1647,25 +1600,26 @@ bool CFX_AggDeviceDriver::SetDIBits(const CFX_DIBSource* pBitmap,
return true;
if (pBitmap->IsAlphaMask()) {
- return m_pBitmap->CompositeMask(
- left, top, pSrcRect->Width(), pSrcRect->Height(), pBitmap, argb,
- pSrcRect->left, pSrcRect->top, blend_type, m_pClipRgn.get(),
- m_bRgbByteOrder, 0, nullptr);
+ return m_pBitmap->CompositeMask(left, top, pSrcRect->Width(),
+ pSrcRect->Height(), pBitmap, argb,
+ pSrcRect->left, pSrcRect->top, blend_type,
+ m_pClipRgn.get(), m_bRgbByteOrder, 0);
}
return m_pBitmap->CompositeBitmap(
left, top, pSrcRect->Width(), pSrcRect->Height(), pBitmap, pSrcRect->left,
- pSrcRect->top, blend_type, m_pClipRgn.get(), m_bRgbByteOrder, nullptr);
+ pSrcRect->top, blend_type, m_pClipRgn.get(), m_bRgbByteOrder);
}
-bool CFX_AggDeviceDriver::StretchDIBits(const CFX_DIBSource* pSource,
- uint32_t argb,
- int dest_left,
- int dest_top,
- int dest_width,
- int dest_height,
- const FX_RECT* pClipRect,
- uint32_t flags,
- int blend_type) {
+bool CFX_AggDeviceDriver::StretchDIBits(
+ const CFX_RetainPtr<CFX_DIBSource>& pSource,
+ uint32_t argb,
+ int dest_left,
+ int dest_top,
+ int dest_width,
+ int dest_height,
+ const FX_RECT* pClipRect,
+ uint32_t flags,
+ int blend_type) {
if (!m_pBitmap->GetBuffer())
return true;
@@ -1681,7 +1635,7 @@ bool CFX_AggDeviceDriver::StretchDIBits(const CFX_DIBSource* pSource,
dest_clip.Intersect(*pClipRect);
CFX_BitmapComposer composer;
composer.Compose(m_pBitmap, m_pClipRgn.get(), 255, argb, dest_clip, false,
- false, false, m_bRgbByteOrder, 0, nullptr, blend_type);
+ false, false, m_bRgbByteOrder, 0, blend_type);
dest_clip.Offset(-dest_rect.left, -dest_rect.top);
CFX_ImageStretcher stretcher(&composer, pSource, dest_width, dest_height,
dest_clip, flags);
@@ -1690,45 +1644,36 @@ bool CFX_AggDeviceDriver::StretchDIBits(const CFX_DIBSource* pSource,
return true;
}
-bool CFX_AggDeviceDriver::StartDIBits(const CFX_DIBSource* pSource,
- int bitmap_alpha,
- uint32_t argb,
- const CFX_Matrix* pMatrix,
- uint32_t render_flags,
- void*& handle,
- int blend_type) {
+bool CFX_AggDeviceDriver::StartDIBits(
+ const CFX_RetainPtr<CFX_DIBSource>& pSource,
+ int bitmap_alpha,
+ uint32_t argb,
+ const CFX_Matrix* pMatrix,
+ uint32_t render_flags,
+ std::unique_ptr<CFX_ImageRenderer>* handle,
+ int blend_type) {
if (!m_pBitmap->GetBuffer())
return true;
- CFX_ImageRenderer* pRenderer = new CFX_ImageRenderer;
- pRenderer->Start(m_pBitmap, m_pClipRgn.get(), pSource, bitmap_alpha, argb,
- pMatrix, render_flags, m_bRgbByteOrder, 0, nullptr);
- handle = pRenderer;
+ *handle = pdfium::MakeUnique<CFX_ImageRenderer>();
+ (*handle)->Start(m_pBitmap, m_pClipRgn.get(), pSource, bitmap_alpha, argb,
+ pMatrix, render_flags, m_bRgbByteOrder);
return true;
}
-bool CFX_AggDeviceDriver::ContinueDIBits(void* pHandle, IFX_Pause* pPause) {
- if (!m_pBitmap->GetBuffer()) {
- return true;
- }
- return ((CFX_ImageRenderer*)pHandle)->Continue(pPause);
-}
-
-void CFX_AggDeviceDriver::CancelDIBits(void* pHandle) {
- if (!m_pBitmap->GetBuffer()) {
- return;
- }
- delete (CFX_ImageRenderer*)pHandle;
+bool CFX_AggDeviceDriver::ContinueDIBits(CFX_ImageRenderer* pHandle,
+ IFX_Pause* pPause) {
+ return m_pBitmap->GetBuffer() ? pHandle->Continue(pPause) : true;
}
#ifndef _SKIA_SUPPORT_
-CFX_FxgeDevice::CFX_FxgeDevice() {
- m_bOwnedBitmap = false;
-}
+CFX_FxgeDevice::CFX_FxgeDevice() {}
-bool CFX_FxgeDevice::Attach(CFX_DIBitmap* pBitmap,
+CFX_FxgeDevice::~CFX_FxgeDevice() {}
+
+bool CFX_FxgeDevice::Attach(const CFX_RetainPtr<CFX_DIBitmap>& pBitmap,
bool bRgbByteOrder,
- CFX_DIBitmap* pOriDevice,
+ const CFX_RetainPtr<CFX_DIBitmap>& pOriDevice,
bool bGroupKnockout) {
if (!pBitmap)
return false;
@@ -1742,22 +1687,15 @@ bool CFX_FxgeDevice::Attach(CFX_DIBitmap* pBitmap,
bool CFX_FxgeDevice::Create(int width,
int height,
FXDIB_Format format,
- CFX_DIBitmap* pOriDevice) {
- m_bOwnedBitmap = true;
- CFX_DIBitmap* pBitmap = new CFX_DIBitmap;
- if (!pBitmap->Create(width, height, format)) {
- delete pBitmap;
+ const CFX_RetainPtr<CFX_DIBitmap>& pOriDevice) {
+ auto pBitmap = pdfium::MakeRetain<CFX_DIBitmap>();
+ if (!pBitmap->Create(width, height, format))
return false;
- }
+
SetBitmap(pBitmap);
SetDeviceDriver(pdfium::MakeUnique<CFX_AggDeviceDriver>(pBitmap, false,
pOriDevice, false));
return true;
}
-CFX_FxgeDevice::~CFX_FxgeDevice() {
- if (m_bOwnedBitmap) {
- delete GetBitmap();
- }
-}
#endif
diff --git a/chromium/third_party/pdfium/core/fxge/agg/fx_agg_driver.h b/chromium/third_party/pdfium/core/fxge/agg/fx_agg_driver.h
index 8da63394a46..3eb56c507e2 100644
--- a/chromium/third_party/pdfium/core/fxge/agg/fx_agg_driver.h
+++ b/chromium/third_party/pdfium/core/fxge/agg/fx_agg_driver.h
@@ -32,9 +32,9 @@ class CAgg_PathData {
class CFX_AggDeviceDriver : public IFX_RenderDeviceDriver {
public:
- CFX_AggDeviceDriver(CFX_DIBitmap* pBitmap,
+ CFX_AggDeviceDriver(const CFX_RetainPtr<CFX_DIBitmap>& pBitmap,
bool bRgbByteOrder,
- CFX_DIBitmap* pOriDevice,
+ const CFX_RetainPtr<CFX_DIBitmap>& pOriDevice,
bool bGroupKnockout);
~CFX_AggDeviceDriver() override;
@@ -63,15 +63,17 @@ class CFX_AggDeviceDriver : public IFX_RenderDeviceDriver {
uint32_t fill_color,
int blend_type) override;
bool GetClipBox(FX_RECT* pRect) override;
- bool GetDIBits(CFX_DIBitmap* pBitmap, int left, int top) override;
- CFX_DIBitmap* GetBackDrop() override;
- bool SetDIBits(const CFX_DIBSource* pBitmap,
+ bool GetDIBits(const CFX_RetainPtr<CFX_DIBitmap>& pBitmap,
+ int left,
+ int top) override;
+ CFX_RetainPtr<CFX_DIBitmap> GetBackDrop() override;
+ bool SetDIBits(const CFX_RetainPtr<CFX_DIBSource>& pBitmap,
uint32_t color,
const FX_RECT* pSrcRect,
int left,
int top,
int blend_type) override;
- bool StretchDIBits(const CFX_DIBSource* pBitmap,
+ bool StretchDIBits(const CFX_RetainPtr<CFX_DIBSource>& pBitmap,
uint32_t color,
int dest_left,
int dest_top,
@@ -80,20 +82,19 @@ class CFX_AggDeviceDriver : public IFX_RenderDeviceDriver {
const FX_RECT* pClipRect,
uint32_t flags,
int blend_type) override;
- bool StartDIBits(const CFX_DIBSource* pBitmap,
+ bool StartDIBits(const CFX_RetainPtr<CFX_DIBSource>& pBitmap,
int bitmap_alpha,
uint32_t color,
const CFX_Matrix* pMatrix,
uint32_t flags,
- void*& handle,
+ std::unique_ptr<CFX_ImageRenderer>* handle,
int blend_type) override;
- bool ContinueDIBits(void* handle, IFX_Pause* pPause) override;
- void CancelDIBits(void* handle) override;
+ bool ContinueDIBits(CFX_ImageRenderer* handle, IFX_Pause* pPause) override;
bool DrawDeviceText(int nChars,
const FXTEXT_CHARPOS* pCharPos,
CFX_Font* pFont,
const CFX_Matrix* pObject2Device,
- FX_FLOAT font_size,
+ float font_size,
uint32_t color) override;
int GetDriverType() const override;
@@ -109,7 +110,7 @@ class CFX_AggDeviceDriver : public IFX_RenderDeviceDriver {
virtual uint8_t* GetBuffer() const;
private:
- CFX_DIBitmap* m_pBitmap;
+ CFX_RetainPtr<CFX_DIBitmap> m_pBitmap;
std::unique_ptr<CFX_ClipRgn> m_pClipRgn;
std::vector<std::unique_ptr<CFX_ClipRgn>> m_StateStack;
#if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_
@@ -117,7 +118,7 @@ class CFX_AggDeviceDriver : public IFX_RenderDeviceDriver {
#endif
int m_FillFlags;
bool m_bRgbByteOrder;
- CFX_DIBitmap* m_pOriDevice;
+ CFX_RetainPtr<CFX_DIBitmap> m_pOriDevice;
bool m_bGroupKnockout;
};
diff --git a/chromium/third_party/pdfium/core/fxge/android/cfpf_skiafont.cpp b/chromium/third_party/pdfium/core/fxge/android/cfpf_skiafont.cpp
index 5e11efae9df..e00aa840e4c 100644
--- a/chromium/third_party/pdfium/core/fxge/android/cfpf_skiafont.cpp
+++ b/chromium/third_party/pdfium/core/fxge/android/cfpf_skiafont.cpp
@@ -53,7 +53,7 @@ CFX_ByteString CFPF_SkiaFont::GetPsName() {
return FXFT_Get_Postscript_Name(m_Face);
}
-int32_t CFPF_SkiaFont::GetGlyphIndex(FX_WCHAR wUnicode) {
+int32_t CFPF_SkiaFont::GetGlyphIndex(wchar_t wUnicode) {
if (!m_Face)
return wUnicode;
if (FXFT_Select_Charmap(m_Face, FXFT_ENCODING_UNICODE))
diff --git a/chromium/third_party/pdfium/core/fxge/android/cfpf_skiafont.h b/chromium/third_party/pdfium/core/fxge/android/cfpf_skiafont.h
index b72c1111778..657ced88f25 100644
--- a/chromium/third_party/pdfium/core/fxge/android/cfpf_skiafont.h
+++ b/chromium/third_party/pdfium/core/fxge/android/cfpf_skiafont.h
@@ -25,7 +25,7 @@ class CFPF_SkiaFont {
CFX_ByteString GetPsName();
uint32_t GetFontStyle() const { return m_dwStyle; }
uint8_t GetCharset() const { return m_uCharset; }
- int32_t GetGlyphIndex(FX_WCHAR wUnicode);
+ int32_t GetGlyphIndex(wchar_t wUnicode);
int32_t GetGlyphWidth(int32_t iGlyphIndex);
int32_t GetAscent() const;
int32_t GetDescent() const;
diff --git a/chromium/third_party/pdfium/core/fxge/android/cfpf_skiafontdescriptor.h b/chromium/third_party/pdfium/core/fxge/android/cfpf_skiafontdescriptor.h
index 57b85404ad6..f653050feb0 100644
--- a/chromium/third_party/pdfium/core/fxge/android/cfpf_skiafontdescriptor.h
+++ b/chromium/third_party/pdfium/core/fxge/android/cfpf_skiafontdescriptor.h
@@ -23,14 +23,14 @@ class CFPF_SkiaFontDescriptor {
virtual int32_t GetType() const { return FPF_SKIAFONTTYPE_Unknown; }
- void SetFamily(const FX_CHAR* pFamily) {
+ void SetFamily(const char* pFamily) {
FX_Free(m_pFamily);
int32_t iSize = FXSYS_strlen(pFamily);
- m_pFamily = FX_Alloc(FX_CHAR, iSize + 1);
- FXSYS_memcpy(m_pFamily, pFamily, iSize * sizeof(FX_CHAR));
+ m_pFamily = FX_Alloc(char, iSize + 1);
+ memcpy(m_pFamily, pFamily, iSize * sizeof(char));
m_pFamily[iSize] = 0;
}
- FX_CHAR* m_pFamily;
+ char* m_pFamily;
uint32_t m_dwStyle;
int32_t m_iFaceIndex;
uint32_t m_dwCharsets;
diff --git a/chromium/third_party/pdfium/core/fxge/android/cfpf_skiafontmgr.cpp b/chromium/third_party/pdfium/core/fxge/android/cfpf_skiafontmgr.cpp
index e3511be67a1..534f41a548f 100644
--- a/chromium/third_party/pdfium/core/fxge/android/cfpf_skiafontmgr.cpp
+++ b/chromium/third_party/pdfium/core/fxge/android/cfpf_skiafontmgr.cpp
@@ -87,12 +87,12 @@ uint32_t FPF_SkiaGetSubstFont(uint32_t dwHash,
return 0;
}
-uint32_t FPF_GetHashCode_StringA(const FX_CHAR* pStr, int32_t iLength) {
+uint32_t FPF_GetHashCode_StringA(const char* pStr, int32_t iLength) {
if (!pStr)
return 0;
if (iLength < 0)
iLength = FXSYS_strlen(pStr);
- const FX_CHAR* pStrEnd = pStr + iLength;
+ const char* pStrEnd = pStr + iLength;
uint32_t uHashCode = 0;
while (pStr < pStrEnd)
uHashCode = 31 * uHashCode + FXSYS_tolower(*pStr++);
@@ -160,9 +160,9 @@ uint32_t FPF_SkiaGetCharset(uint8_t uCharset) {
uint32_t FPF_SKIANormalizeFontName(const CFX_ByteStringC& bsfamily) {
uint32_t dwHash = 0;
int32_t iLength = bsfamily.GetLength();
- const FX_CHAR* pBuffer = bsfamily.c_str();
+ const char* pBuffer = bsfamily.c_str();
for (int32_t i = 0; i < iLength; i++) {
- FX_CHAR ch = pBuffer[i];
+ char ch = pBuffer[i];
if (ch == ' ' || ch == '-' || ch == ',')
continue;
dwHash = 31 * dwHash + FXSYS_tolower(ch);
@@ -371,7 +371,7 @@ FXFT_Face CFPF_SkiaFontMgr::GetFontFace(
if (iFaceIndex < 0)
return nullptr;
FXFT_StreamRec streamRec;
- FXSYS_memset(&streamRec, 0, sizeof(FXFT_StreamRec));
+ memset(&streamRec, 0, sizeof(FXFT_StreamRec));
streamRec.size = pFileRead->GetSize();
streamRec.descriptor.pointer = static_cast<void*>(pFileRead.Get());
streamRec.read = FPF_SkiaStream_Read;
diff --git a/chromium/third_party/pdfium/core/fxge/android/cfpf_skiapathfont.h b/chromium/third_party/pdfium/core/fxge/android/cfpf_skiapathfont.h
index f1cff2574b7..8b7a4f9fb48 100644
--- a/chromium/third_party/pdfium/core/fxge/android/cfpf_skiapathfont.h
+++ b/chromium/third_party/pdfium/core/fxge/android/cfpf_skiapathfont.h
@@ -20,14 +20,14 @@ class CFPF_SkiaPathFont : public CFPF_SkiaFontDescriptor {
// CFPF_SkiaFontDescriptor
int32_t GetType() const override { return FPF_SKIAFONTTYPE_Path; }
- void SetPath(const FX_CHAR* pPath) {
+ void SetPath(const char* pPath) {
FX_Free(m_pPath);
int32_t iSize = FXSYS_strlen(pPath);
- m_pPath = FX_Alloc(FX_CHAR, iSize + 1);
- FXSYS_memcpy(m_pPath, pPath, iSize * sizeof(FX_CHAR));
+ m_pPath = FX_Alloc(char, iSize + 1);
+ memcpy(m_pPath, pPath, iSize * sizeof(char));
m_pPath[iSize] = 0;
}
- FX_CHAR* m_pPath;
+ char* m_pPath;
};
#endif // CORE_FXGE_ANDROID_CFPF_SKIAPATHFONT_H_
diff --git a/chromium/third_party/pdfium/core/fxge/android/cfx_androidfontinfo.cpp b/chromium/third_party/pdfium/core/fxge/android/cfx_androidfontinfo.cpp
index 03a7ffbd9e4..1183cdeaaa8 100644
--- a/chromium/third_party/pdfium/core/fxge/android/cfx_androidfontinfo.cpp
+++ b/chromium/third_party/pdfium/core/fxge/android/cfx_androidfontinfo.cpp
@@ -30,7 +30,7 @@ void* CFX_AndroidFontInfo::MapFont(int weight,
bool bItalic,
int charset,
int pitch_family,
- const FX_CHAR* face,
+ const char* face,
int& iExact) {
if (!m_pFontMgr)
return nullptr;
@@ -50,7 +50,7 @@ void* CFX_AndroidFontInfo::MapFont(int weight,
FPF_MATCHFONT_REPLACEANSI);
}
-void* CFX_AndroidFontInfo::GetFont(const FX_CHAR* face) {
+void* CFX_AndroidFontInfo::GetFont(const char* face) {
return nullptr;
}
@@ -63,19 +63,19 @@ uint32_t CFX_AndroidFontInfo::GetFontData(void* hFont,
return static_cast<CFPF_SkiaFont*>(hFont)->GetFontData(table, buffer, size);
}
-bool CFX_AndroidFontInfo::GetFaceName(void* hFont, CFX_ByteString& name) {
+bool CFX_AndroidFontInfo::GetFaceName(void* hFont, CFX_ByteString* name) {
if (!hFont)
return false;
- name = static_cast<CFPF_SkiaFont*>(hFont)->GetFamilyName();
+ *name = static_cast<CFPF_SkiaFont*>(hFont)->GetFamilyName();
return true;
}
-bool CFX_AndroidFontInfo::GetFontCharset(void* hFont, int& charset) {
+bool CFX_AndroidFontInfo::GetFontCharset(void* hFont, int* charset) {
if (!hFont)
return false;
- charset = static_cast<CFPF_SkiaFont*>(hFont)->GetCharset();
+ *charset = static_cast<CFPF_SkiaFont*>(hFont)->GetCharset();
return false;
}
diff --git a/chromium/third_party/pdfium/core/fxge/android/cfx_androidfontinfo.h b/chromium/third_party/pdfium/core/fxge/android/cfx_androidfontinfo.h
index 94e1db88ac0..ce08f2558a1 100644
--- a/chromium/third_party/pdfium/core/fxge/android/cfx_androidfontinfo.h
+++ b/chromium/third_party/pdfium/core/fxge/android/cfx_androidfontinfo.h
@@ -27,15 +27,15 @@ class CFX_AndroidFontInfo : public IFX_SystemFontInfo {
bool bItalic,
int charset,
int pitch_family,
- const FX_CHAR* face,
+ const char* face,
int& bExact) override;
- void* GetFont(const FX_CHAR* face) override;
+ void* GetFont(const char* face) override;
uint32_t GetFontData(void* hFont,
uint32_t table,
uint8_t* buffer,
uint32_t size) override;
- bool GetFaceName(void* hFont, CFX_ByteString& name) override;
- bool GetFontCharset(void* hFont, int& charset) override;
+ bool GetFaceName(void* hFont, CFX_ByteString* name) override;
+ bool GetFontCharset(void* hFont, int* charset) override;
void DeleteFont(void* hFont) override;
protected:
diff --git a/chromium/third_party/pdfium/core/fxge/android/fx_android_imp.cpp b/chromium/third_party/pdfium/core/fxge/android/fx_android_imp.cpp
index b8e7c5b2180..e4fdd1e131f 100644
--- a/chromium/third_party/pdfium/core/fxge/android/fx_android_imp.cpp
+++ b/chromium/third_party/pdfium/core/fxge/android/fx_android_imp.cpp
@@ -11,6 +11,7 @@
#include "core/fxge/android/cfpf_skiadevicemodule.h"
#include "core/fxge/android/cfx_androidfontinfo.h"
+#include "third_party/base/ptr_util.h"
void CFX_GEModule::InitPlatform() {
CFPF_SkiaDeviceModule* pDeviceModule = CFPF_GetSkiaDeviceModule();
@@ -19,7 +20,7 @@ void CFX_GEModule::InitPlatform() {
CFPF_SkiaFontMgr* pFontMgr = pDeviceModule->GetFontMgr();
if (pFontMgr) {
- std::unique_ptr<CFX_AndroidFontInfo> pFontInfo(new CFX_AndroidFontInfo);
+ auto pFontInfo = pdfium::MakeUnique<CFX_AndroidFontInfo>();
pFontInfo->Init(pFontMgr);
m_pFontMgr->SetSystemFontInfo(std::move(pFontInfo));
}
diff --git a/chromium/third_party/pdfium/core/fxge/apple/apple_int.h b/chromium/third_party/pdfium/core/fxge/apple/apple_int.h
index fed6abcfb09..f1b9fcf2e81 100644
--- a/chromium/third_party/pdfium/core/fxge/apple/apple_int.h
+++ b/chromium/third_party/pdfium/core/fxge/apple/apple_int.h
@@ -19,7 +19,7 @@
class CQuartz2D {
public:
- void* createGraphics(CFX_DIBitmap* bitmap);
+ void* createGraphics(const CFX_RetainPtr<CFX_DIBitmap>& bitmap);
void destroyGraphics(void* graphics);
void* CreateFont(const uint8_t* pFontData, uint32_t dwFontSize);
@@ -27,7 +27,7 @@ class CQuartz2D {
void setGraphicsTextMatrix(void* graphics, CFX_Matrix* matrix);
bool drawGraphicsString(void* graphics,
void* font,
- FX_FLOAT fontSize,
+ float fontSize,
uint16_t* glyphIndices,
CGPoint* glyphPositions,
int32_t chars,
diff --git a/chromium/third_party/pdfium/core/fxge/apple/fx_apple_platform.cpp b/chromium/third_party/pdfium/core/fxge/apple/fx_apple_platform.cpp
index f576eb0ba27..818e19e7d44 100644
--- a/chromium/third_party/pdfium/core/fxge/apple/fx_apple_platform.cpp
+++ b/chromium/third_party/pdfium/core/fxge/apple/fx_apple_platform.cpp
@@ -14,7 +14,6 @@
#include "core/fxge/cfx_facecache.h"
#include "core/fxge/cfx_gemodule.h"
#include "core/fxge/cfx_renderdevice.h"
-#include "core/fxge/dib/dib_int.h"
#include "core/fxge/fx_freetype.h"
#include "core/fxge/ge/cfx_cliprgn.h"
#include "core/fxge/ge/fx_text_int.h"
@@ -30,7 +29,7 @@ bool CGDrawGlyphRun(CGContextRef pContext,
const FXTEXT_CHARPOS* pCharPos,
CFX_Font* pFont,
const CFX_Matrix* pObject2Device,
- FX_FLOAT font_size,
+ float font_size,
uint32_t argb) {
if (nChars == 0)
return true;
@@ -102,7 +101,7 @@ bool CFX_AggDeviceDriver::DrawDeviceText(int nChars,
const FXTEXT_CHARPOS* pCharPos,
CFX_Font* pFont,
const CFX_Matrix* pObject2Device,
- FX_FLOAT font_size,
+ float font_size,
uint32_t argb) {
if (!pFont)
return false;
@@ -129,7 +128,7 @@ bool CFX_AggDeviceDriver::DrawDeviceText(int nChars,
rect_cg =
CGRectMake(m_pClipRgn->GetBox().left, m_pClipRgn->GetBox().top,
m_pClipRgn->GetBox().Width(), m_pClipRgn->GetBox().Height());
- const CFX_DIBitmap* pClipMask = m_pClipRgn->GetMask().GetObject();
+ CFX_RetainPtr<CFX_DIBitmap> pClipMask = m_pClipRgn->GetMask();
if (pClipMask) {
CGDataProviderRef pClipMaskDataProvider = CGDataProviderCreateWithData(
nullptr, pClipMask->GetBuffer(),
diff --git a/chromium/third_party/pdfium/core/fxge/apple/fx_mac_imp.cpp b/chromium/third_party/pdfium/core/fxge/apple/fx_mac_imp.cpp
index c05aea34f54..2df6e754a06 100644
--- a/chromium/third_party/pdfium/core/fxge/apple/fx_mac_imp.cpp
+++ b/chromium/third_party/pdfium/core/fxge/apple/fx_mac_imp.cpp
@@ -14,8 +14,8 @@
namespace {
const struct {
- const FX_CHAR* m_pName;
- const FX_CHAR* m_pSubstName;
+ const char* m_pName;
+ const char* m_pSubstName;
} g_Base14Substs[] = {
{"Courier", "Courier New"},
{"Courier-Bold", "Courier New Bold"},
@@ -41,7 +41,7 @@ class CFX_MacFontInfo : public CFX_FolderFontInfo {
bool bItalic,
int charset,
int pitch_family,
- const FX_CHAR* family,
+ const char* family,
int& iExact) override;
};
@@ -61,7 +61,7 @@ void* CFX_MacFontInfo::MapFont(int weight,
bool bItalic,
int charset,
int pitch_family,
- const FX_CHAR* cstr_face,
+ const char* cstr_face,
int& iExact) {
CFX_ByteString face = cstr_face;
for (size_t i = 0; i < FX_ArraySize(g_Base14Substs); ++i) {
diff --git a/chromium/third_party/pdfium/core/fxge/apple/fx_quartz_device.cpp b/chromium/third_party/pdfium/core/fxge/apple/fx_quartz_device.cpp
index 0cd5b6b93a0..eef0e0cd88d 100644
--- a/chromium/third_party/pdfium/core/fxge/apple/fx_quartz_device.cpp
+++ b/chromium/third_party/pdfium/core/fxge/apple/fx_quartz_device.cpp
@@ -15,7 +15,6 @@
#include "core/fxge/cfx_graphstatedata.h"
#include "core/fxge/cfx_pathdata.h"
#include "core/fxge/cfx_renderdevice.h"
-#include "core/fxge/dib/dib_int.h"
#include "core/fxge/fx_freetype.h"
#include "core/fxge/ge/fx_text_int.h"
#include "third_party/base/ptr_util.h"
@@ -25,7 +24,7 @@
#error Expected CGFLOAT_IS_DOUBLE to be defined by CoreGraphics headers
#endif
-void* CQuartz2D::createGraphics(CFX_DIBitmap* pBitmap) {
+void* CQuartz2D::createGraphics(const CFX_RetainPtr<CFX_DIBitmap>& pBitmap) {
if (!pBitmap)
return nullptr;
CGBitmapInfo bmpInfo = kCGBitmapByteOrder32Little;
@@ -77,7 +76,7 @@ void CQuartz2D::setGraphicsTextMatrix(void* graphics, CFX_Matrix* matrix) {
bool CQuartz2D::drawGraphicsString(void* graphics,
void* font,
- FX_FLOAT fontSize,
+ float fontSize,
uint16_t* glyphIndices,
CGPoint* glyphPositions,
int32_t charsCount,
diff --git a/chromium/third_party/pdfium/core/fxge/cfx_fontmgr.h b/chromium/third_party/pdfium/core/fxge/cfx_fontmgr.h
index 432f34b38ca..b7f2e1a032d 100644
--- a/chromium/third_party/pdfium/core/fxge/cfx_fontmgr.h
+++ b/chromium/third_party/pdfium/core/fxge/cfx_fontmgr.h
@@ -43,7 +43,7 @@ class CFX_FontMgr {
uint8_t* pData,
uint32_t size,
int font_offset);
- FXFT_Face GetFileFace(const FX_CHAR* filename, int face_index);
+ FXFT_Face GetFileFace(const char* filename, int face_index);
FXFT_Face GetFixedFace(const uint8_t* pData, uint32_t size, int face_index);
void ReleaseFace(FXFT_Face face);
void SetSystemFontInfo(std::unique_ptr<IFX_SystemFontInfo> pFontInfo);
diff --git a/chromium/third_party/pdfium/core/fxge/cfx_fxgedevice.h b/chromium/third_party/pdfium/core/fxge/cfx_fxgedevice.h
index 8358e436667..4e8a7f4f55e 100644
--- a/chromium/third_party/pdfium/core/fxge/cfx_fxgedevice.h
+++ b/chromium/third_party/pdfium/core/fxge/cfx_fxgedevice.h
@@ -17,30 +17,27 @@ class CFX_FxgeDevice : public CFX_RenderDevice {
CFX_FxgeDevice();
~CFX_FxgeDevice() override;
- bool Attach(CFX_DIBitmap* pBitmap,
+ bool Attach(const CFX_RetainPtr<CFX_DIBitmap>& pBitmap,
bool bRgbByteOrder,
- CFX_DIBitmap* pOriDevice,
+ const CFX_RetainPtr<CFX_DIBitmap>& pOriDevice,
bool bGroupKnockout);
bool Create(int width,
int height,
FXDIB_Format format,
- CFX_DIBitmap* pOriDevice);
+ const CFX_RetainPtr<CFX_DIBitmap>& pOriDevice);
#ifdef _SKIA_SUPPORT_
bool AttachRecorder(SkPictureRecorder* recorder);
void Clear(uint32_t color);
SkPictureRecorder* CreateRecorder(int size_x, int size_y);
void DebugVerifyBitmapIsPreMultiplied() const override;
- bool SetBitsWithMask(const CFX_DIBSource* pBitmap,
- const CFX_DIBSource* pMask,
+ bool SetBitsWithMask(const CFX_RetainPtr<CFX_DIBSource>& pBitmap,
+ const CFX_RetainPtr<CFX_DIBSource>& pMask,
int left,
int top,
int bitmap_alpha,
int blend_type) override;
#endif
-
- private:
- bool m_bOwnedBitmap;
};
#endif // CORE_FXGE_CFX_FXGEDEVICE_H_
diff --git a/chromium/third_party/pdfium/core/fxge/cfx_gemodule.h b/chromium/third_party/pdfium/core/fxge/cfx_gemodule.h
index c5bd8410025..587ec89e592 100644
--- a/chromium/third_party/pdfium/core/fxge/cfx_gemodule.h
+++ b/chromium/third_party/pdfium/core/fxge/cfx_gemodule.h
@@ -24,7 +24,7 @@ class CFX_GEModule {
void Init(const char** pUserFontPaths, CCodec_ModuleMgr* pCodecModule);
CFX_FontCache* GetFontCache();
CFX_FontMgr* GetFontMgr() { return m_pFontMgr.get(); }
- void SetTextGamma(FX_FLOAT gammaValue);
+ void SetTextGamma(float gammaValue);
const uint8_t* GetTextGammaTable() const;
CCodec_ModuleMgr* GetCodecModule() { return m_pCodecModule; }
diff --git a/chromium/third_party/pdfium/core/fxge/cfx_graphstate.h b/chromium/third_party/pdfium/core/fxge/cfx_graphstate.h
index a838dfc17ca..b023ce790dc 100644
--- a/chromium/third_party/pdfium/core/fxge/cfx_graphstate.h
+++ b/chromium/third_party/pdfium/core/fxge/cfx_graphstate.h
@@ -20,10 +20,10 @@ class CFX_GraphState {
void Emplace();
- void SetLineDash(CPDF_Array* pArray, FX_FLOAT phase, FX_FLOAT scale);
+ void SetLineDash(CPDF_Array* pArray, float phase, float scale);
- FX_FLOAT GetLineWidth() const;
- void SetLineWidth(FX_FLOAT width);
+ float GetLineWidth() const;
+ void SetLineWidth(float width);
CFX_GraphStateData::LineCap GetLineCap() const;
void SetLineCap(CFX_GraphStateData::LineCap cap);
@@ -31,8 +31,8 @@ class CFX_GraphState {
CFX_GraphStateData::LineJoin GetLineJoin() const;
void SetLineJoin(CFX_GraphStateData::LineJoin join);
- FX_FLOAT GetMiterLimit() const;
- void SetMiterLimit(FX_FLOAT limit);
+ float GetMiterLimit() const;
+ void SetMiterLimit(float limit);
// FIXME(tsepez): remove when all GraphStateData usage gone.
const CFX_GraphStateData* GetObject() const { return m_Ref.GetObject(); }
diff --git a/chromium/third_party/pdfium/core/fxge/cfx_graphstatedata.h b/chromium/third_party/pdfium/core/fxge/cfx_graphstatedata.h
index 03e4a8f51a9..dc0098be3e4 100644
--- a/chromium/third_party/pdfium/core/fxge/cfx_graphstatedata.h
+++ b/chromium/third_party/pdfium/core/fxge/cfx_graphstatedata.h
@@ -22,8 +22,8 @@ class CFX_GraphStateData {
LineCap m_LineCap;
int m_DashCount;
- FX_FLOAT* m_DashArray;
- FX_FLOAT m_DashPhase;
+ float* m_DashArray;
+ float m_DashPhase;
enum LineJoin {
LineJoinMiter = 0,
@@ -31,8 +31,8 @@ class CFX_GraphStateData {
LineJoinBevel = 2,
};
LineJoin m_LineJoin;
- FX_FLOAT m_MiterLimit;
- FX_FLOAT m_LineWidth;
+ float m_MiterLimit;
+ float m_LineWidth;
};
#endif // CORE_FXGE_CFX_GRAPHSTATEDATA_H_
diff --git a/chromium/third_party/pdfium/core/fxge/cfx_pathdata.h b/chromium/third_party/pdfium/core/fxge/cfx_pathdata.h
index b0e30e32ad7..bcb2b7aadf7 100644
--- a/chromium/third_party/pdfium/core/fxge/cfx_pathdata.h
+++ b/chromium/third_party/pdfium/core/fxge/cfx_pathdata.h
@@ -47,7 +47,7 @@ class CFX_PathData {
std::vector<FX_PATHPOINT>& GetPoints() { return m_Points; }
CFX_FloatRect GetBoundingBox() const;
- CFX_FloatRect GetBoundingBox(FX_FLOAT line_width, FX_FLOAT miter_limit) const;
+ CFX_FloatRect GetBoundingBox(float line_width, float miter_limit) const;
void Transform(const CFX_Matrix* pMatrix);
bool IsRect() const;
@@ -59,7 +59,7 @@ class CFX_PathData {
bool IsRect(const CFX_Matrix* pMatrix, CFX_FloatRect* rect) const;
void Append(const CFX_PathData* pSrc, const CFX_Matrix* pMatrix);
- void AppendRect(FX_FLOAT left, FX_FLOAT bottom, FX_FLOAT right, FX_FLOAT top);
+ void AppendRect(float left, float bottom, float right, float top);
void AppendPoint(const CFX_PointF& pos, FXPT_TYPE type, bool closeFigure);
void ClosePath();
diff --git a/chromium/third_party/pdfium/core/fxge/cfx_renderdevice.h b/chromium/third_party/pdfium/core/fxge/cfx_renderdevice.h
index 2e9abf9963d..794c2fec6b4 100644
--- a/chromium/third_party/pdfium/core/fxge/cfx_renderdevice.h
+++ b/chromium/third_party/pdfium/core/fxge/cfx_renderdevice.h
@@ -15,6 +15,7 @@
class CFX_Font;
class CFX_GraphStateData;
+class CFX_ImageRenderer;
class IFX_RenderDeviceDriver;
#define FXDC_DEVICE_CLASS 1
@@ -68,7 +69,7 @@ class FXTEXT_CHARPOS {
FXTEXT_CHARPOS(const FXTEXT_CHARPOS&);
~FXTEXT_CHARPOS();
- FX_FLOAT m_AdjustMatrix[4];
+ float m_AdjustMatrix[4];
CFX_PointF m_Origin;
uint32_t m_GlyphIndex;
int32_t m_FontCharWidth;
@@ -100,9 +101,13 @@ class CFX_RenderDevice {
int GetRenderCaps() const { return m_RenderCaps; }
int GetDeviceCaps(int id) const;
CFX_Matrix GetCTM() const;
- CFX_DIBitmap* GetBitmap() const { return m_pBitmap; }
- void SetBitmap(CFX_DIBitmap* pBitmap) { m_pBitmap = pBitmap; }
- bool CreateCompatibleBitmap(CFX_DIBitmap* pDIB, int width, int height) const;
+ CFX_RetainPtr<CFX_DIBitmap> GetBitmap() const { return m_pBitmap; }
+ void SetBitmap(const CFX_RetainPtr<CFX_DIBitmap>& pBitmap) {
+ m_pBitmap = pBitmap;
+ }
+ bool CreateCompatibleBitmap(const CFX_RetainPtr<CFX_DIBitmap>& pDIB,
+ int width,
+ int height) const;
const FX_RECT& GetClipBox() const { return m_ClipBox; }
bool SetClip_PathFill(const CFX_PathData* pPathData,
const CFX_Matrix* pObject2Device,
@@ -132,24 +137,26 @@ class CFX_RenderDevice {
return FillRectWithBlend(pRect, color, FXDIB_BLEND_NORMAL);
}
bool FillRectWithBlend(const FX_RECT* pRect, uint32_t color, int blend_type);
- bool DrawCosmeticLine(FX_FLOAT x1,
- FX_FLOAT y1,
- FX_FLOAT x2,
- FX_FLOAT y2,
+ bool DrawCosmeticLine(float x1,
+ float y1,
+ float x2,
+ float y2,
uint32_t color,
int fill_mode,
int blend_type);
- bool GetDIBits(CFX_DIBitmap* pBitmap, int left, int top);
- CFX_DIBitmap* GetBackDrop();
- bool SetDIBits(const CFX_DIBSource* pBitmap, int left, int top) {
+ CFX_RetainPtr<CFX_DIBitmap> GetBackDrop();
+ bool GetDIBits(const CFX_RetainPtr<CFX_DIBitmap>& pBitmap, int left, int top);
+ bool SetDIBits(const CFX_RetainPtr<CFX_DIBSource>& pBitmap,
+ int left,
+ int top) {
return SetDIBitsWithBlend(pBitmap, left, top, FXDIB_BLEND_NORMAL);
}
- bool SetDIBitsWithBlend(const CFX_DIBSource* pBitmap,
+ bool SetDIBitsWithBlend(const CFX_RetainPtr<CFX_DIBSource>& pBitmap,
int left,
int top,
int blend_type);
- bool StretchDIBits(const CFX_DIBSource* pBitmap,
+ bool StretchDIBits(const CFX_RetainPtr<CFX_DIBSource>& pBitmap,
int left,
int top,
int dest_width,
@@ -157,60 +164,60 @@ class CFX_RenderDevice {
return StretchDIBitsWithFlagsAndBlend(pBitmap, left, top, dest_width,
dest_height, 0, FXDIB_BLEND_NORMAL);
}
- bool StretchDIBitsWithFlagsAndBlend(const CFX_DIBSource* pBitmap,
- int left,
- int top,
- int dest_width,
- int dest_height,
- uint32_t flags,
- int blend_type);
- bool SetBitMask(const CFX_DIBSource* pBitmap,
+ bool StretchDIBitsWithFlagsAndBlend(
+ const CFX_RetainPtr<CFX_DIBSource>& pBitmap,
+ int left,
+ int top,
+ int dest_width,
+ int dest_height,
+ uint32_t flags,
+ int blend_type);
+ bool SetBitMask(const CFX_RetainPtr<CFX_DIBSource>& pBitmap,
int left,
int top,
uint32_t color);
- bool StretchBitMask(const CFX_DIBSource* pBitmap,
+ bool StretchBitMask(const CFX_RetainPtr<CFX_DIBSource>& pBitmap,
int left,
int top,
int dest_width,
int dest_height,
uint32_t color);
- bool StretchBitMaskWithFlags(const CFX_DIBSource* pBitmap,
+ bool StretchBitMaskWithFlags(const CFX_RetainPtr<CFX_DIBSource>& pBitmap,
int left,
int top,
int dest_width,
int dest_height,
uint32_t color,
uint32_t flags);
- bool StartDIBits(const CFX_DIBSource* pBitmap,
+ bool StartDIBits(const CFX_RetainPtr<CFX_DIBSource>& pBitmap,
int bitmap_alpha,
uint32_t color,
const CFX_Matrix* pMatrix,
uint32_t flags,
- void*& handle) {
+ std::unique_ptr<CFX_ImageRenderer>* handle) {
return StartDIBitsWithBlend(pBitmap, bitmap_alpha, color, pMatrix, flags,
handle, FXDIB_BLEND_NORMAL);
}
- bool StartDIBitsWithBlend(const CFX_DIBSource* pBitmap,
+ bool StartDIBitsWithBlend(const CFX_RetainPtr<CFX_DIBSource>& pBitmap,
int bitmap_alpha,
uint32_t color,
const CFX_Matrix* pMatrix,
uint32_t flags,
- void*& handle,
+ std::unique_ptr<CFX_ImageRenderer>* handle,
int blend_type);
- bool ContinueDIBits(void* handle, IFX_Pause* pPause);
- void CancelDIBits(void* handle);
+ bool ContinueDIBits(CFX_ImageRenderer* handle, IFX_Pause* pPause);
bool DrawNormalText(int nChars,
const FXTEXT_CHARPOS* pCharPos,
CFX_Font* pFont,
- FX_FLOAT font_size,
+ float font_size,
const CFX_Matrix* pText2Device,
uint32_t fill_color,
uint32_t text_flags);
bool DrawTextPath(int nChars,
const FXTEXT_CHARPOS* pCharPos,
CFX_Font* pFont,
- FX_FLOAT font_size,
+ float font_size,
const CFX_Matrix* pText2User,
const CFX_Matrix* pUser2Device,
const CFX_GraphStateData* pGraphState,
@@ -221,8 +228,8 @@ class CFX_RenderDevice {
#ifdef _SKIA_SUPPORT_
virtual void DebugVerifyBitmapIsPreMultiplied() const;
- virtual bool SetBitsWithMask(const CFX_DIBSource* pBitmap,
- const CFX_DIBSource* pMask,
+ virtual bool SetBitsWithMask(const CFX_RetainPtr<CFX_DIBSource>& pBitmap,
+ const CFX_RetainPtr<CFX_DIBSource>& pMask,
int left,
int top,
int bitmap_alpha,
@@ -243,7 +250,7 @@ class CFX_RenderDevice {
int fill_mode,
int blend_type);
- CFX_DIBitmap* m_pBitmap;
+ CFX_RetainPtr<CFX_DIBitmap> m_pBitmap;
int m_Width;
int m_Height;
int m_bpp;
diff --git a/chromium/third_party/pdfium/core/fxge/cfx_unicodeencodingex.h b/chromium/third_party/pdfium/core/fxge/cfx_unicodeencodingex.h
index df2edbe1bf6..21deb44d790 100644
--- a/chromium/third_party/pdfium/core/fxge/cfx_unicodeencodingex.h
+++ b/chromium/third_party/pdfium/core/fxge/cfx_unicodeencodingex.h
@@ -24,7 +24,7 @@ class CFX_UnicodeEncodingEx : public CFX_UnicodeEncoding {
// CFX_UnicodeEncoding:
uint32_t GlyphFromCharCode(uint32_t charcode) override;
- uint32_t CharCodeFromUnicode(FX_WCHAR Unicode) const;
+ uint32_t CharCodeFromUnicode(wchar_t Unicode) const;
private:
uint32_t m_nEncodingID;
diff --git a/chromium/third_party/pdfium/core/fxge/dib/cfx_bitmapcomposer.cpp b/chromium/third_party/pdfium/core/fxge/dib/cfx_bitmapcomposer.cpp
new file mode 100644
index 00000000000..bd634ad5743
--- /dev/null
+++ b/chromium/third_party/pdfium/core/fxge/dib/cfx_bitmapcomposer.cpp
@@ -0,0 +1,201 @@
+// 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
+
+#include "core/fxge/dib/cfx_bitmapcomposer.h"
+
+#include "core/fxcodec/fx_codec.h"
+#include "core/fxge/cfx_gemodule.h"
+#include "core/fxge/dib/cfx_dibitmap.h"
+#include "core/fxge/ge/cfx_cliprgn.h"
+
+CFX_BitmapComposer::CFX_BitmapComposer()
+ : m_bRgbByteOrder(false), m_BlendType(FXDIB_BLEND_NORMAL) {}
+
+CFX_BitmapComposer::~CFX_BitmapComposer() {}
+
+void CFX_BitmapComposer::Compose(const CFX_RetainPtr<CFX_DIBitmap>& pDest,
+ const CFX_ClipRgn* pClipRgn,
+ int bitmap_alpha,
+ uint32_t mask_color,
+ const FX_RECT& dest_rect,
+ bool bVertical,
+ bool bFlipX,
+ bool bFlipY,
+ bool bRgbByteOrder,
+ int alpha_flag,
+ int blend_type) {
+ m_pBitmap = pDest;
+ m_pClipRgn = pClipRgn;
+ m_DestLeft = dest_rect.left;
+ m_DestTop = dest_rect.top;
+ m_DestWidth = dest_rect.Width();
+ m_DestHeight = dest_rect.Height();
+ m_BitmapAlpha = bitmap_alpha;
+ m_MaskColor = mask_color;
+ m_pClipMask = nullptr;
+ if (pClipRgn && pClipRgn->GetType() != CFX_ClipRgn::RectI)
+ m_pClipMask = pClipRgn->GetMask();
+ m_bVertical = bVertical;
+ m_bFlipX = bFlipX;
+ m_bFlipY = bFlipY;
+ m_AlphaFlag = alpha_flag;
+ m_bRgbByteOrder = bRgbByteOrder;
+ m_BlendType = blend_type;
+}
+bool CFX_BitmapComposer::SetInfo(int width,
+ int height,
+ FXDIB_Format src_format,
+ uint32_t* pSrcPalette) {
+ m_SrcFormat = src_format;
+ if (!m_Compositor.Init(m_pBitmap->GetFormat(), src_format, width, pSrcPalette,
+ m_MaskColor, FXDIB_BLEND_NORMAL,
+ m_pClipMask != nullptr || (m_BitmapAlpha < 255),
+ m_bRgbByteOrder, m_AlphaFlag)) {
+ return false;
+ }
+ if (m_bVertical) {
+ m_pScanlineV.resize(m_pBitmap->GetBPP() / 8 * width + 4);
+ m_pClipScanV.resize(m_pBitmap->GetHeight());
+ if (m_pBitmap->m_pAlphaMask)
+ m_pScanlineAlphaV.resize(width + 4);
+ }
+ if (m_BitmapAlpha < 255) {
+ m_pAddClipScan.resize(m_bVertical ? m_pBitmap->GetHeight()
+ : m_pBitmap->GetWidth());
+ }
+ return true;
+}
+
+void CFX_BitmapComposer::DoCompose(uint8_t* dest_scan,
+ const uint8_t* src_scan,
+ int dest_width,
+ const uint8_t* clip_scan,
+ const uint8_t* src_extra_alpha,
+ uint8_t* dst_extra_alpha) {
+ uint8_t* pAddClipScan = m_pAddClipScan.data();
+ if (m_BitmapAlpha < 255) {
+ if (clip_scan) {
+ for (int i = 0; i < dest_width; ++i)
+ pAddClipScan[i] = clip_scan[i] * m_BitmapAlpha / 255;
+ } else {
+ memset(pAddClipScan, m_BitmapAlpha, dest_width);
+ }
+ clip_scan = pAddClipScan;
+ }
+ if (m_SrcFormat == FXDIB_8bppMask) {
+ m_Compositor.CompositeByteMaskLine(dest_scan, src_scan, dest_width,
+ clip_scan, dst_extra_alpha);
+ } else if ((m_SrcFormat & 0xff) == 8) {
+ m_Compositor.CompositePalBitmapLine(dest_scan, src_scan, 0, dest_width,
+ clip_scan, src_extra_alpha,
+ dst_extra_alpha);
+ } else {
+ m_Compositor.CompositeRgbBitmapLine(dest_scan, src_scan, dest_width,
+ clip_scan, src_extra_alpha,
+ dst_extra_alpha);
+ }
+}
+
+void CFX_BitmapComposer::ComposeScanline(int line,
+ const uint8_t* scanline,
+ const uint8_t* scan_extra_alpha) {
+ if (m_bVertical) {
+ ComposeScanlineV(line, scanline, scan_extra_alpha);
+ return;
+ }
+ const uint8_t* clip_scan = nullptr;
+ if (m_pClipMask)
+ clip_scan = m_pClipMask->GetBuffer() +
+ (m_DestTop + line - m_pClipRgn->GetBox().top) *
+ m_pClipMask->GetPitch() +
+ (m_DestLeft - m_pClipRgn->GetBox().left);
+ uint8_t* dest_scan =
+ const_cast<uint8_t*>(m_pBitmap->GetScanline(line + m_DestTop)) +
+ m_DestLeft * m_pBitmap->GetBPP() / 8;
+ uint8_t* dest_alpha_scan =
+ m_pBitmap->m_pAlphaMask
+ ? const_cast<uint8_t*>(
+ m_pBitmap->m_pAlphaMask->GetScanline(line + m_DestTop)) +
+ m_DestLeft
+ : nullptr;
+ DoCompose(dest_scan, scanline, m_DestWidth, clip_scan, scan_extra_alpha,
+ dest_alpha_scan);
+}
+
+void CFX_BitmapComposer::ComposeScanlineV(int line,
+ const uint8_t* scanline,
+ const uint8_t* scan_extra_alpha) {
+ int Bpp = m_pBitmap->GetBPP() / 8;
+ int dest_pitch = m_pBitmap->GetPitch();
+ int dest_alpha_pitch =
+ m_pBitmap->m_pAlphaMask ? m_pBitmap->m_pAlphaMask->GetPitch() : 0;
+ int dest_x = m_DestLeft + (m_bFlipX ? (m_DestWidth - line - 1) : line);
+ uint8_t* dest_buf =
+ m_pBitmap->GetBuffer() + dest_x * Bpp + m_DestTop * dest_pitch;
+ uint8_t* dest_alpha_buf = m_pBitmap->m_pAlphaMask
+ ? m_pBitmap->m_pAlphaMask->GetBuffer() +
+ dest_x + m_DestTop * dest_alpha_pitch
+ : nullptr;
+ if (m_bFlipY) {
+ dest_buf += dest_pitch * (m_DestHeight - 1);
+ dest_alpha_buf += dest_alpha_pitch * (m_DestHeight - 1);
+ }
+ int y_step = dest_pitch;
+ int y_alpha_step = dest_alpha_pitch;
+ if (m_bFlipY) {
+ y_step = -y_step;
+ y_alpha_step = -y_alpha_step;
+ }
+ uint8_t* src_scan = m_pScanlineV.data();
+ uint8_t* dest_scan = dest_buf;
+ for (int i = 0; i < m_DestHeight; ++i) {
+ for (int j = 0; j < Bpp; ++j)
+ *src_scan++ = dest_scan[j];
+ dest_scan += y_step;
+ }
+ uint8_t* src_alpha_scan = m_pScanlineAlphaV.data();
+ uint8_t* dest_alpha_scan = dest_alpha_buf;
+ if (dest_alpha_scan) {
+ for (int i = 0; i < m_DestHeight; ++i) {
+ *src_alpha_scan++ = *dest_alpha_scan;
+ dest_alpha_scan += y_alpha_step;
+ }
+ }
+ uint8_t* clip_scan = nullptr;
+ if (m_pClipMask) {
+ clip_scan = m_pClipScanV.data();
+ int clip_pitch = m_pClipMask->GetPitch();
+ const uint8_t* src_clip =
+ m_pClipMask->GetBuffer() +
+ (m_DestTop - m_pClipRgn->GetBox().top) * clip_pitch +
+ (dest_x - m_pClipRgn->GetBox().left);
+ if (m_bFlipY) {
+ src_clip += clip_pitch * (m_DestHeight - 1);
+ clip_pitch = -clip_pitch;
+ }
+ for (int i = 0; i < m_DestHeight; ++i) {
+ clip_scan[i] = *src_clip;
+ src_clip += clip_pitch;
+ }
+ }
+ DoCompose(m_pScanlineV.data(), scanline, m_DestHeight, clip_scan,
+ scan_extra_alpha, m_pScanlineAlphaV.data());
+ src_scan = m_pScanlineV.data();
+ dest_scan = dest_buf;
+ for (int i = 0; i < m_DestHeight; ++i) {
+ for (int j = 0; j < Bpp; ++j)
+ dest_scan[j] = *src_scan++;
+ dest_scan += y_step;
+ }
+ src_alpha_scan = m_pScanlineAlphaV.data();
+ dest_alpha_scan = dest_alpha_buf;
+ if (!dest_alpha_scan)
+ return;
+ for (int i = 0; i < m_DestHeight; ++i) {
+ *dest_alpha_scan = *src_alpha_scan++;
+ dest_alpha_scan += y_alpha_step;
+ }
+}
diff --git a/chromium/third_party/pdfium/core/fxge/dib/cfx_bitmapcomposer.h b/chromium/third_party/pdfium/core/fxge/dib/cfx_bitmapcomposer.h
new file mode 100644
index 00000000000..6e961cbd457
--- /dev/null
+++ b/chromium/third_party/pdfium/core/fxge/dib/cfx_bitmapcomposer.h
@@ -0,0 +1,81 @@
+// 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_CFX_BITMAPCOMPOSER_H_
+#define CORE_FXGE_DIB_CFX_BITMAPCOMPOSER_H_
+
+#include <vector>
+
+#include "core/fxcrt/cfx_retain_ptr.h"
+#include "core/fxcrt/fx_coordinates.h"
+#include "core/fxge/dib/cfx_scanlinecompositor.h"
+#include "core/fxge/dib/ifx_scanlinecomposer.h"
+
+class CFX_ClipRgn;
+class CFX_DIBitmap;
+
+class CFX_BitmapComposer : public IFX_ScanlineComposer {
+ public:
+ CFX_BitmapComposer();
+ ~CFX_BitmapComposer() override;
+
+ void Compose(const CFX_RetainPtr<CFX_DIBitmap>& pDest,
+ const CFX_ClipRgn* pClipRgn,
+ int bitmap_alpha,
+ uint32_t mask_color,
+ const FX_RECT& dest_rect,
+ bool bVertical,
+ bool bFlipX,
+ bool bFlipY,
+ bool bRgbByteOrder,
+ int alpha_flag,
+ int blend_type);
+
+ // IFX_ScanlineComposer
+ bool SetInfo(int width,
+ int height,
+ FXDIB_Format src_format,
+ uint32_t* pSrcPalette) override;
+
+ void ComposeScanline(int line,
+ const uint8_t* scanline,
+ const uint8_t* scan_extra_alpha) override;
+
+ private:
+ void DoCompose(uint8_t* dest_scan,
+ const uint8_t* src_scan,
+ int dest_width,
+ const uint8_t* clip_scan,
+ const uint8_t* src_extra_alpha,
+ uint8_t* dst_extra_alpha);
+ void ComposeScanlineV(int line,
+ const uint8_t* scanline,
+ const uint8_t* scan_extra_alpha);
+
+ CFX_RetainPtr<CFX_DIBitmap> m_pBitmap;
+ const CFX_ClipRgn* m_pClipRgn;
+ FXDIB_Format m_SrcFormat;
+ int m_DestLeft;
+ int m_DestTop;
+ int m_DestWidth;
+ int m_DestHeight;
+ int m_BitmapAlpha;
+ uint32_t m_MaskColor;
+ CFX_RetainPtr<CFX_DIBitmap> m_pClipMask;
+ CFX_ScanlineCompositor m_Compositor;
+ bool m_bVertical;
+ bool m_bFlipX;
+ bool m_bFlipY;
+ int m_AlphaFlag;
+ bool m_bRgbByteOrder;
+ int m_BlendType;
+ std::vector<uint8_t> m_pScanlineV;
+ std::vector<uint8_t> m_pClipScanV;
+ std::vector<uint8_t> m_pAddClipScan;
+ std::vector<uint8_t> m_pScanlineAlphaV;
+};
+
+#endif // CORE_FXGE_DIB_CFX_BITMAPCOMPOSER_H_
diff --git a/chromium/third_party/pdfium/core/fxge/dib/cfx_bitmapstorer.cpp b/chromium/third_party/pdfium/core/fxge/dib/cfx_bitmapstorer.cpp
new file mode 100644
index 00000000000..1e097080987
--- /dev/null
+++ b/chromium/third_party/pdfium/core/fxge/dib/cfx_bitmapstorer.cpp
@@ -0,0 +1,55 @@
+// 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
+
+#include "core/fxge/dib/cfx_bitmapstorer.h"
+
+#include <utility>
+
+#include "third_party/base/ptr_util.h"
+
+CFX_BitmapStorer::CFX_BitmapStorer() {}
+
+CFX_BitmapStorer::~CFX_BitmapStorer() {}
+
+CFX_RetainPtr<CFX_DIBitmap> CFX_BitmapStorer::Detach() {
+ return std::move(m_pBitmap);
+}
+
+void CFX_BitmapStorer::Replace(CFX_RetainPtr<CFX_DIBitmap>&& pBitmap) {
+ m_pBitmap = std::move(pBitmap);
+}
+
+void CFX_BitmapStorer::ComposeScanline(int line,
+ const uint8_t* scanline,
+ const uint8_t* scan_extra_alpha) {
+ uint8_t* dest_buf = const_cast<uint8_t*>(m_pBitmap->GetScanline(line));
+ uint8_t* dest_alpha_buf =
+ m_pBitmap->m_pAlphaMask
+ ? const_cast<uint8_t*>(m_pBitmap->m_pAlphaMask->GetScanline(line))
+ : nullptr;
+ if (dest_buf)
+ memcpy(dest_buf, scanline, m_pBitmap->GetPitch());
+
+ if (dest_alpha_buf) {
+ memcpy(dest_alpha_buf, scan_extra_alpha,
+ m_pBitmap->m_pAlphaMask->GetPitch());
+ }
+}
+
+bool CFX_BitmapStorer::SetInfo(int width,
+ int height,
+ FXDIB_Format src_format,
+ uint32_t* pSrcPalette) {
+ auto pBitmap = pdfium::MakeRetain<CFX_DIBitmap>();
+ if (!pBitmap->Create(width, height, src_format))
+ return false;
+
+ if (pSrcPalette)
+ pBitmap->SetPalette(pSrcPalette);
+
+ m_pBitmap = std::move(pBitmap);
+ return true;
+}
diff --git a/chromium/third_party/pdfium/core/fxge/dib/cfx_bitmapstorer.h b/chromium/third_party/pdfium/core/fxge/dib/cfx_bitmapstorer.h
new file mode 100644
index 00000000000..a574493e6e2
--- /dev/null
+++ b/chromium/third_party/pdfium/core/fxge/dib/cfx_bitmapstorer.h
@@ -0,0 +1,41 @@
+// 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_CFX_BITMAPSTORER_H_
+#define CORE_FXGE_DIB_CFX_BITMAPSTORER_H_
+
+#include <memory>
+#include <vector>
+
+#include "core/fxcrt/cfx_retain_ptr.h"
+#include "core/fxcrt/fx_coordinates.h"
+#include "core/fxge/dib/cfx_dibitmap.h"
+#include "core/fxge/dib/ifx_scanlinecomposer.h"
+#include "third_party/base/stl_util.h"
+
+class CFX_BitmapStorer : public IFX_ScanlineComposer {
+ public:
+ CFX_BitmapStorer();
+ ~CFX_BitmapStorer() override;
+
+ // IFX_ScanlineComposer
+ void ComposeScanline(int line,
+ const uint8_t* scanline,
+ const uint8_t* scan_extra_alpha) override;
+ bool SetInfo(int width,
+ int height,
+ FXDIB_Format src_format,
+ uint32_t* pSrcPalette) override;
+
+ CFX_RetainPtr<CFX_DIBitmap> GetBitmap() { return m_pBitmap; }
+ CFX_RetainPtr<CFX_DIBitmap> Detach();
+ void Replace(CFX_RetainPtr<CFX_DIBitmap>&& pBitmap);
+
+ private:
+ CFX_RetainPtr<CFX_DIBitmap> m_pBitmap;
+};
+
+#endif // CORE_FXGE_DIB_CFX_BITMAPSTORER_H_
diff --git a/chromium/third_party/pdfium/core/fxge/dib/cfx_dibextractor.cpp b/chromium/third_party/pdfium/core/fxge/dib/cfx_dibextractor.cpp
new file mode 100644
index 00000000000..8de69e2e3bc
--- /dev/null
+++ b/chromium/third_party/pdfium/core/fxge/dib/cfx_dibextractor.cpp
@@ -0,0 +1,27 @@
+// 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
+
+#include "core/fxge/dib/cfx_dibextractor.h"
+
+#include "core/fxge/dib/cfx_dibsource.h"
+
+CFX_DIBExtractor::CFX_DIBExtractor(const CFX_RetainPtr<CFX_DIBSource>& pSrc) {
+ if (!pSrc->GetBuffer()) {
+ m_pBitmap = pSrc->Clone();
+ return;
+ }
+ CFX_RetainPtr<CFX_DIBSource> pOldSrc(pSrc);
+ m_pBitmap = pdfium::MakeRetain<CFX_DIBitmap>();
+ if (!m_pBitmap->Create(pOldSrc->GetWidth(), pOldSrc->GetHeight(),
+ pOldSrc->GetFormat(), pOldSrc->GetBuffer())) {
+ m_pBitmap.Reset();
+ return;
+ }
+ m_pBitmap->SetPalette(pOldSrc->GetPalette());
+ m_pBitmap->SetAlphaMask(pOldSrc->m_pAlphaMask);
+}
+
+CFX_DIBExtractor::~CFX_DIBExtractor() {}
diff --git a/chromium/third_party/pdfium/core/fxge/dib/cfx_dibextractor.h b/chromium/third_party/pdfium/core/fxge/dib/cfx_dibextractor.h
new file mode 100644
index 00000000000..25d80ecb946
--- /dev/null
+++ b/chromium/third_party/pdfium/core/fxge/dib/cfx_dibextractor.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_CFX_DIBEXTRACTOR_H_
+#define CORE_FXGE_DIB_CFX_DIBEXTRACTOR_H_
+
+#include "core/fxcrt/cfx_retain_ptr.h"
+#include "core/fxge/dib/cfx_dibitmap.h"
+
+class CFX_DIBSource;
+
+class CFX_DIBExtractor {
+ public:
+ explicit CFX_DIBExtractor(const CFX_RetainPtr<CFX_DIBSource>& pSrc);
+ ~CFX_DIBExtractor();
+
+ CFX_RetainPtr<CFX_DIBitmap> GetBitmap() { return m_pBitmap; }
+
+ private:
+ CFX_RetainPtr<CFX_DIBitmap> m_pBitmap;
+};
+
+#endif // CORE_FXGE_DIB_CFX_DIBEXTRACTOR_H_
diff --git a/chromium/third_party/pdfium/core/fxge/dib/cfx_dibitmap.cpp b/chromium/third_party/pdfium/core/fxge/dib/cfx_dibitmap.cpp
new file mode 100644
index 00000000000..61eba3fd748
--- /dev/null
+++ b/chromium/third_party/pdfium/core/fxge/dib/cfx_dibitmap.cpp
@@ -0,0 +1,1232 @@
+// 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
+
+#include "core/fxge/dib/cfx_dibitmap.h"
+
+#include <limits>
+#include <memory>
+#include <utility>
+
+#include "core/fxcodec/fx_codec.h"
+#include "core/fxge/cfx_gemodule.h"
+#include "core/fxge/dib/cfx_scanlinecompositor.h"
+#include "core/fxge/ge/cfx_cliprgn.h"
+#include "third_party/base/ptr_util.h"
+
+#define MAX_OOM_LIMIT 12000000
+
+namespace {
+
+const int8_t g_ChannelOffset[] = {0, 2, 1, 0, 0, 1, 2, 3, 3};
+
+} // namespace
+
+CFX_DIBitmap::CFX_DIBitmap() {
+ m_pPalette = nullptr;
+#ifdef _SKIA_SUPPORT_PATHS_
+ m_nFormat = Format::kCleared;
+#endif
+}
+
+bool CFX_DIBitmap::Create(int width,
+ int height,
+ FXDIB_Format format,
+ uint8_t* pBuffer,
+ int pitch) {
+ m_pBuffer = nullptr;
+ m_bpp = static_cast<uint8_t>(format);
+ m_AlphaFlag = static_cast<uint8_t>(format >> 8);
+ m_Width = m_Height = m_Pitch = 0;
+ if (width <= 0 || height <= 0 || pitch < 0)
+ return false;
+
+ if ((INT_MAX - 31) / width < (format & 0xff))
+ return false;
+
+ if (!pitch)
+ pitch = (width * (format & 0xff) + 31) / 32 * 4;
+
+ if ((1 << 30) / pitch < height)
+ return false;
+
+ if (pBuffer) {
+ m_pBuffer.Reset(pBuffer);
+ } else {
+ int size = pitch * height + 4;
+ int oomlimit = MAX_OOM_LIMIT;
+ if (oomlimit >= 0 && size >= oomlimit) {
+ m_pBuffer =
+ std::unique_ptr<uint8_t, FxFreeDeleter>(FX_TryAlloc(uint8_t, size));
+ if (!m_pBuffer)
+ return false;
+ } else {
+ m_pBuffer =
+ std::unique_ptr<uint8_t, FxFreeDeleter>(FX_Alloc(uint8_t, size));
+ }
+ }
+ m_Width = width;
+ m_Height = height;
+ m_Pitch = pitch;
+ if (!HasAlpha() || format == FXDIB_Argb)
+ return true;
+
+ if (BuildAlphaMask())
+ return true;
+
+ if (pBuffer)
+ return true;
+
+ m_pBuffer = nullptr;
+ m_Width = 0;
+ m_Height = 0;
+ m_Pitch = 0;
+ return false;
+}
+
+bool CFX_DIBitmap::Copy(const CFX_RetainPtr<CFX_DIBSource>& pSrc) {
+ if (m_pBuffer)
+ return false;
+
+ if (!Create(pSrc->GetWidth(), pSrc->GetHeight(), pSrc->GetFormat()))
+ return false;
+
+ SetPalette(pSrc->GetPalette());
+ SetAlphaMask(pSrc->m_pAlphaMask);
+ for (int row = 0; row < pSrc->GetHeight(); row++)
+ memcpy(m_pBuffer.Get() + row * m_Pitch, pSrc->GetScanline(row), m_Pitch);
+ return true;
+}
+
+CFX_DIBitmap::~CFX_DIBitmap() {}
+
+uint8_t* CFX_DIBitmap::GetBuffer() const {
+ return m_pBuffer.Get();
+}
+
+const uint8_t* CFX_DIBitmap::GetScanline(int line) const {
+ return m_pBuffer.Get() ? m_pBuffer.Get() + line * m_Pitch : nullptr;
+}
+
+void CFX_DIBitmap::TakeOver(CFX_RetainPtr<CFX_DIBitmap>&& pSrcBitmap) {
+ m_pBuffer = std::move(pSrcBitmap->m_pBuffer);
+ m_pPalette = std::move(pSrcBitmap->m_pPalette);
+ m_pAlphaMask = pSrcBitmap->m_pAlphaMask;
+ pSrcBitmap->m_pBuffer = nullptr;
+ pSrcBitmap->m_pAlphaMask = nullptr;
+ m_bpp = pSrcBitmap->m_bpp;
+ m_AlphaFlag = pSrcBitmap->m_AlphaFlag;
+ m_Width = pSrcBitmap->m_Width;
+ m_Height = pSrcBitmap->m_Height;
+ m_Pitch = pSrcBitmap->m_Pitch;
+}
+
+void CFX_DIBitmap::Clear(uint32_t color) {
+ if (!m_pBuffer)
+ return;
+
+ uint8_t* pBuffer = m_pBuffer.Get();
+ switch (GetFormat()) {
+ case FXDIB_1bppMask:
+ memset(pBuffer, (color & 0xff000000) ? 0xff : 0, m_Pitch * m_Height);
+ break;
+ case FXDIB_1bppRgb: {
+ int index = FindPalette(color);
+ memset(pBuffer, index ? 0xff : 0, m_Pitch * m_Height);
+ break;
+ }
+ case FXDIB_8bppMask:
+ memset(pBuffer, color >> 24, m_Pitch * m_Height);
+ break;
+ case FXDIB_8bppRgb: {
+ int index = FindPalette(color);
+ memset(pBuffer, index, m_Pitch * m_Height);
+ break;
+ }
+ case FXDIB_Rgb:
+ case FXDIB_Rgba: {
+ int a, r, g, b;
+ ArgbDecode(color, a, r, g, b);
+ if (r == g && g == b) {
+ memset(pBuffer, r, m_Pitch * m_Height);
+ } else {
+ int byte_pos = 0;
+ for (int col = 0; col < m_Width; col++) {
+ pBuffer[byte_pos++] = b;
+ pBuffer[byte_pos++] = g;
+ pBuffer[byte_pos++] = r;
+ }
+ for (int row = 1; row < m_Height; row++) {
+ memcpy(pBuffer + row * m_Pitch, pBuffer, m_Pitch);
+ }
+ }
+ break;
+ }
+ case FXDIB_Rgb32:
+ case FXDIB_Argb: {
+ color = IsCmykImage() ? FXCMYK_TODIB(color) : FXARGB_TODIB(color);
+#ifdef _SKIA_SUPPORT_
+ if (FXDIB_Rgb32 == GetFormat() && !IsCmykImage())
+ color |= 0xFF000000;
+#endif
+ for (int i = 0; i < m_Width; i++)
+ reinterpret_cast<uint32_t*>(pBuffer)[i] = color;
+ for (int row = 1; row < m_Height; row++)
+ memcpy(pBuffer + row * m_Pitch, pBuffer, m_Pitch);
+ break;
+ }
+ default:
+ break;
+ }
+}
+
+bool CFX_DIBitmap::TransferBitmap(
+ int dest_left,
+ int dest_top,
+ int width,
+ int height,
+ const CFX_RetainPtr<CFX_DIBSource>& pSrcBitmap,
+ int src_left,
+ int src_top) {
+ if (!m_pBuffer)
+ return false;
+
+ GetOverlapRect(dest_left, dest_top, width, height, pSrcBitmap->GetWidth(),
+ pSrcBitmap->GetHeight(), src_left, src_top, nullptr);
+ if (width == 0 || height == 0)
+ return true;
+
+ FXDIB_Format dest_format = GetFormat();
+ FXDIB_Format src_format = pSrcBitmap->GetFormat();
+ if (dest_format == src_format) {
+ if (GetBPP() == 1) {
+ for (int row = 0; row < height; row++) {
+ uint8_t* dest_scan = m_pBuffer.Get() + (dest_top + row) * m_Pitch;
+ const uint8_t* src_scan = pSrcBitmap->GetScanline(src_top + row);
+ for (int col = 0; col < width; col++) {
+ if (src_scan[(src_left + col) / 8] &
+ (1 << (7 - (src_left + col) % 8))) {
+ dest_scan[(dest_left + col) / 8] |= 1
+ << (7 - (dest_left + col) % 8);
+ } else {
+ dest_scan[(dest_left + col) / 8] &=
+ ~(1 << (7 - (dest_left + col) % 8));
+ }
+ }
+ }
+ } else {
+ int Bpp = GetBPP() / 8;
+ for (int row = 0; row < height; row++) {
+ uint8_t* dest_scan =
+ m_pBuffer.Get() + (dest_top + row) * m_Pitch + dest_left * Bpp;
+ const uint8_t* src_scan =
+ pSrcBitmap->GetScanline(src_top + row) + src_left * Bpp;
+ memcpy(dest_scan, src_scan, width * Bpp);
+ }
+ }
+ } else {
+ if (m_pPalette)
+ return false;
+
+ if (m_bpp == 8)
+ dest_format = FXDIB_8bppMask;
+
+ uint8_t* dest_buf =
+ m_pBuffer.Get() + dest_top * m_Pitch + dest_left * GetBPP() / 8;
+ std::unique_ptr<uint32_t, FxFreeDeleter> d_plt;
+ if (!ConvertBuffer(dest_format, dest_buf, m_Pitch, width, height,
+ pSrcBitmap, src_left, src_top, &d_plt)) {
+ return false;
+ }
+ }
+ return true;
+}
+
+bool CFX_DIBitmap::LoadChannel(FXDIB_Channel destChannel,
+ const CFX_RetainPtr<CFX_DIBSource>& pSrcBitmap,
+ FXDIB_Channel srcChannel) {
+ if (!m_pBuffer)
+ return false;
+
+ CFX_RetainPtr<CFX_DIBSource> pSrcClone = pSrcBitmap;
+ int srcOffset;
+ if (srcChannel == FXDIB_Alpha) {
+ if (!pSrcBitmap->HasAlpha() && !pSrcBitmap->IsAlphaMask())
+ return false;
+
+ if (pSrcBitmap->GetBPP() == 1) {
+ pSrcClone = pSrcBitmap->CloneConvert(FXDIB_8bppMask);
+ if (!pSrcClone)
+ return false;
+ }
+ srcOffset = pSrcBitmap->GetFormat() == FXDIB_Argb ? 3 : 0;
+ } else {
+ if (pSrcBitmap->IsAlphaMask())
+ return false;
+
+ if (pSrcBitmap->GetBPP() < 24) {
+ if (pSrcBitmap->IsCmykImage()) {
+ pSrcClone = pSrcBitmap->CloneConvert(static_cast<FXDIB_Format>(
+ (pSrcBitmap->GetFormat() & 0xff00) | 0x20));
+ } else {
+ pSrcClone = pSrcBitmap->CloneConvert(static_cast<FXDIB_Format>(
+ (pSrcBitmap->GetFormat() & 0xff00) | 0x18));
+ }
+ if (!pSrcClone)
+ return false;
+ }
+ srcOffset = g_ChannelOffset[srcChannel];
+ }
+ int destOffset = 0;
+ if (destChannel == FXDIB_Alpha) {
+ if (IsAlphaMask()) {
+ if (!ConvertFormat(FXDIB_8bppMask))
+ return false;
+ } else {
+ if (!ConvertFormat(IsCmykImage() ? FXDIB_Cmyka : FXDIB_Argb))
+ return false;
+
+ if (GetFormat() == FXDIB_Argb)
+ destOffset = 3;
+ }
+ } else {
+ if (IsAlphaMask())
+ return false;
+
+ if (GetBPP() < 24) {
+ if (HasAlpha()) {
+ if (!ConvertFormat(IsCmykImage() ? FXDIB_Cmyka : FXDIB_Argb))
+ return false;
+#if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_
+ } else if (!ConvertFormat(IsCmykImage() ? FXDIB_Cmyk : FXDIB_Rgb32)) {
+#else
+ } else if (!ConvertFormat(IsCmykImage() ? FXDIB_Cmyk : FXDIB_Rgb)) {
+#endif
+ return false;
+ }
+ }
+ destOffset = g_ChannelOffset[destChannel];
+ }
+ if (srcChannel == FXDIB_Alpha && pSrcClone->m_pAlphaMask) {
+ CFX_RetainPtr<CFX_DIBSource> pAlphaMask = pSrcClone->m_pAlphaMask;
+ if (pSrcClone->GetWidth() != m_Width ||
+ pSrcClone->GetHeight() != m_Height) {
+ if (pAlphaMask) {
+ pAlphaMask = pAlphaMask->StretchTo(m_Width, m_Height);
+ if (!pAlphaMask)
+ return false;
+ }
+ }
+ pSrcClone = std::move(pAlphaMask);
+ srcOffset = 0;
+ } else if (pSrcClone->GetWidth() != m_Width ||
+ pSrcClone->GetHeight() != m_Height) {
+ CFX_RetainPtr<CFX_DIBitmap> pSrcMatched =
+ pSrcClone->StretchTo(m_Width, m_Height);
+ if (!pSrcMatched)
+ return false;
+
+ pSrcClone = std::move(pSrcMatched);
+ }
+ CFX_RetainPtr<CFX_DIBitmap> pDst(this);
+ if (destChannel == FXDIB_Alpha && m_pAlphaMask) {
+ pDst = m_pAlphaMask;
+ destOffset = 0;
+ }
+ int srcBytes = pSrcClone->GetBPP() / 8;
+ int destBytes = pDst->GetBPP() / 8;
+ for (int row = 0; row < m_Height; row++) {
+ uint8_t* dest_pos = (uint8_t*)pDst->GetScanline(row) + destOffset;
+ const uint8_t* src_pos = pSrcClone->GetScanline(row) + srcOffset;
+ for (int col = 0; col < m_Width; col++) {
+ *dest_pos = *src_pos;
+ dest_pos += destBytes;
+ src_pos += srcBytes;
+ }
+ }
+ return true;
+}
+
+bool CFX_DIBitmap::LoadChannel(FXDIB_Channel destChannel, int value) {
+ if (!m_pBuffer)
+ return false;
+
+ int destOffset;
+ if (destChannel == FXDIB_Alpha) {
+ if (IsAlphaMask()) {
+ if (!ConvertFormat(FXDIB_8bppMask)) {
+ return false;
+ }
+ destOffset = 0;
+ } else {
+ destOffset = 0;
+ if (!ConvertFormat(IsCmykImage() ? FXDIB_Cmyka : FXDIB_Argb)) {
+ return false;
+ }
+ if (GetFormat() == FXDIB_Argb) {
+ destOffset = 3;
+ }
+ }
+ } else {
+ if (IsAlphaMask()) {
+ return false;
+ }
+ if (GetBPP() < 24) {
+ if (HasAlpha()) {
+ if (!ConvertFormat(IsCmykImage() ? FXDIB_Cmyka : FXDIB_Argb)) {
+ return false;
+ }
+#if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_
+ } else if (!ConvertFormat(IsCmykImage() ? FXDIB_Cmyk : FXDIB_Rgb)) {
+#else
+ } else if (!ConvertFormat(IsCmykImage() ? FXDIB_Cmyk : FXDIB_Rgb32)) {
+#endif
+ return false;
+ }
+ }
+ destOffset = g_ChannelOffset[destChannel];
+ }
+ int Bpp = GetBPP() / 8;
+ if (Bpp == 1) {
+ memset(m_pBuffer.Get(), value, m_Height * m_Pitch);
+ return true;
+ }
+ if (destChannel == FXDIB_Alpha && m_pAlphaMask) {
+ memset(m_pAlphaMask->GetBuffer(), value,
+ m_pAlphaMask->GetHeight() * m_pAlphaMask->GetPitch());
+ return true;
+ }
+ for (int row = 0; row < m_Height; row++) {
+ uint8_t* scan_line = m_pBuffer.Get() + row * m_Pitch + destOffset;
+ for (int col = 0; col < m_Width; col++) {
+ *scan_line = value;
+ scan_line += Bpp;
+ }
+ }
+ return true;
+}
+
+bool CFX_DIBitmap::MultiplyAlpha(
+ const CFX_RetainPtr<CFX_DIBSource>& pSrcBitmap) {
+ if (!m_pBuffer)
+ return false;
+
+ ASSERT(pSrcBitmap->IsAlphaMask());
+ if (!pSrcBitmap->IsAlphaMask())
+ return false;
+
+ if (!IsAlphaMask() && !HasAlpha())
+ return LoadChannel(FXDIB_Alpha, pSrcBitmap, FXDIB_Alpha);
+
+ CFX_RetainPtr<CFX_DIBitmap> pSrcClone = pSrcBitmap.As<CFX_DIBitmap>();
+ if (pSrcBitmap->GetWidth() != m_Width ||
+ pSrcBitmap->GetHeight() != m_Height) {
+ pSrcClone = pSrcBitmap->StretchTo(m_Width, m_Height);
+ if (!pSrcClone)
+ return false;
+ }
+ if (IsAlphaMask()) {
+ if (!ConvertFormat(FXDIB_8bppMask))
+ return false;
+
+ for (int row = 0; row < m_Height; row++) {
+ uint8_t* dest_scan = m_pBuffer.Get() + m_Pitch * row;
+ uint8_t* src_scan = pSrcClone->m_pBuffer.Get() + pSrcClone->m_Pitch * row;
+ if (pSrcClone->GetBPP() == 1) {
+ for (int col = 0; col < m_Width; col++) {
+ if (!((1 << (7 - col % 8)) & src_scan[col / 8]))
+ dest_scan[col] = 0;
+ }
+ } else {
+ for (int col = 0; col < m_Width; col++) {
+ *dest_scan = (*dest_scan) * src_scan[col] / 255;
+ dest_scan++;
+ }
+ }
+ }
+ } else {
+ if (GetFormat() == FXDIB_Argb) {
+ if (pSrcClone->GetBPP() == 1)
+ return false;
+
+ for (int row = 0; row < m_Height; row++) {
+ uint8_t* dest_scan = m_pBuffer.Get() + m_Pitch * row + 3;
+ uint8_t* src_scan =
+ pSrcClone->m_pBuffer.Get() + pSrcClone->m_Pitch * row;
+ for (int col = 0; col < m_Width; col++) {
+ *dest_scan = (*dest_scan) * src_scan[col] / 255;
+ dest_scan += 4;
+ }
+ }
+ } else {
+ m_pAlphaMask->MultiplyAlpha(pSrcClone);
+ }
+ }
+ return true;
+}
+
+bool CFX_DIBitmap::MultiplyAlpha(int alpha) {
+ if (!m_pBuffer)
+ return false;
+
+ switch (GetFormat()) {
+ case FXDIB_1bppMask:
+ if (!ConvertFormat(FXDIB_8bppMask)) {
+ return false;
+ }
+ MultiplyAlpha(alpha);
+ break;
+ case FXDIB_8bppMask: {
+ for (int row = 0; row < m_Height; row++) {
+ uint8_t* scan_line = m_pBuffer.Get() + row * m_Pitch;
+ for (int col = 0; col < m_Width; col++) {
+ scan_line[col] = scan_line[col] * alpha / 255;
+ }
+ }
+ break;
+ }
+ case FXDIB_Argb: {
+ for (int row = 0; row < m_Height; row++) {
+ uint8_t* scan_line = m_pBuffer.Get() + row * m_Pitch + 3;
+ for (int col = 0; col < m_Width; col++) {
+ *scan_line = (*scan_line) * alpha / 255;
+ scan_line += 4;
+ }
+ }
+ break;
+ }
+ default:
+ if (HasAlpha()) {
+ m_pAlphaMask->MultiplyAlpha(alpha);
+ } else if (IsCmykImage()) {
+ if (!ConvertFormat((FXDIB_Format)(GetFormat() | 0x0200))) {
+ return false;
+ }
+ m_pAlphaMask->MultiplyAlpha(alpha);
+ } else {
+ if (!ConvertFormat(FXDIB_Argb)) {
+ return false;
+ }
+ MultiplyAlpha(alpha);
+ }
+ break;
+ }
+ return true;
+}
+
+uint32_t CFX_DIBitmap::GetPixel(int x, int y) const {
+ if (!m_pBuffer)
+ return 0;
+
+ uint8_t* pos = m_pBuffer.Get() + y * m_Pitch + x * GetBPP() / 8;
+ switch (GetFormat()) {
+ case FXDIB_1bppMask: {
+ if ((*pos) & (1 << (7 - x % 8))) {
+ return 0xff000000;
+ }
+ return 0;
+ }
+ case FXDIB_1bppRgb: {
+ if ((*pos) & (1 << (7 - x % 8))) {
+ return m_pPalette ? m_pPalette.get()[1] : 0xffffffff;
+ }
+ return m_pPalette ? m_pPalette.get()[0] : 0xff000000;
+ }
+ case FXDIB_8bppMask:
+ return (*pos) << 24;
+ case FXDIB_8bppRgb:
+ return m_pPalette ? m_pPalette.get()[*pos]
+ : (0xff000000 | ((*pos) * 0x10101));
+ case FXDIB_Rgb:
+ case FXDIB_Rgba:
+ case FXDIB_Rgb32:
+ return FXARGB_GETDIB(pos) | 0xff000000;
+ case FXDIB_Argb:
+ return FXARGB_GETDIB(pos);
+ default:
+ break;
+ }
+ return 0;
+}
+
+void CFX_DIBitmap::SetPixel(int x, int y, uint32_t color) {
+ if (!m_pBuffer)
+ return;
+
+ if (x < 0 || x >= m_Width || y < 0 || y >= m_Height)
+ return;
+
+ uint8_t* pos = m_pBuffer.Get() + y * m_Pitch + x * GetBPP() / 8;
+ switch (GetFormat()) {
+ case FXDIB_1bppMask:
+ if (color >> 24) {
+ *pos |= 1 << (7 - x % 8);
+ } else {
+ *pos &= ~(1 << (7 - x % 8));
+ }
+ break;
+ case FXDIB_1bppRgb:
+ if (m_pPalette) {
+ if (color == m_pPalette.get()[1]) {
+ *pos |= 1 << (7 - x % 8);
+ } else {
+ *pos &= ~(1 << (7 - x % 8));
+ }
+ } else {
+ if (color == 0xffffffff) {
+ *pos |= 1 << (7 - x % 8);
+ } else {
+ *pos &= ~(1 << (7 - x % 8));
+ }
+ }
+ break;
+ case FXDIB_8bppMask:
+ *pos = (uint8_t)(color >> 24);
+ break;
+ case FXDIB_8bppRgb: {
+ if (m_pPalette) {
+ for (int i = 0; i < 256; i++) {
+ if (m_pPalette.get()[i] == color) {
+ *pos = (uint8_t)i;
+ return;
+ }
+ }
+ *pos = 0;
+ } else {
+ *pos = FXRGB2GRAY(FXARGB_R(color), FXARGB_G(color), FXARGB_B(color));
+ }
+ break;
+ }
+ case FXDIB_Rgb:
+ case FXDIB_Rgb32: {
+ int alpha = FXARGB_A(color);
+ pos[0] = (FXARGB_B(color) * alpha + pos[0] * (255 - alpha)) / 255;
+ pos[1] = (FXARGB_G(color) * alpha + pos[1] * (255 - alpha)) / 255;
+ pos[2] = (FXARGB_R(color) * alpha + pos[2] * (255 - alpha)) / 255;
+ break;
+ }
+ case FXDIB_Rgba: {
+ pos[0] = FXARGB_B(color);
+ pos[1] = FXARGB_G(color);
+ pos[2] = FXARGB_R(color);
+ break;
+ }
+ case FXDIB_Argb:
+ FXARGB_SETDIB(pos, color);
+ break;
+ default:
+ break;
+ }
+}
+
+void CFX_DIBitmap::DownSampleScanline(int line,
+ uint8_t* dest_scan,
+ int dest_bpp,
+ int dest_width,
+ bool bFlipX,
+ int clip_left,
+ int clip_width) const {
+ if (!m_pBuffer)
+ return;
+
+ int src_Bpp = m_bpp / 8;
+ uint8_t* scanline = m_pBuffer.Get() + line * m_Pitch;
+ if (src_Bpp == 0) {
+ for (int i = 0; i < clip_width; i++) {
+ uint32_t dest_x = clip_left + i;
+ uint32_t src_x = dest_x * m_Width / dest_width;
+ if (bFlipX) {
+ src_x = m_Width - src_x - 1;
+ }
+ src_x %= m_Width;
+ dest_scan[i] = (scanline[src_x / 8] & (1 << (7 - src_x % 8))) ? 255 : 0;
+ }
+ } else if (src_Bpp == 1) {
+ for (int i = 0; i < clip_width; i++) {
+ uint32_t dest_x = clip_left + i;
+ uint32_t src_x = dest_x * m_Width / dest_width;
+ if (bFlipX) {
+ src_x = m_Width - src_x - 1;
+ }
+ src_x %= m_Width;
+ int dest_pos = i;
+ if (m_pPalette) {
+ if (!IsCmykImage()) {
+ dest_pos *= 3;
+ FX_ARGB argb = m_pPalette.get()[scanline[src_x]];
+ dest_scan[dest_pos] = FXARGB_B(argb);
+ dest_scan[dest_pos + 1] = FXARGB_G(argb);
+ dest_scan[dest_pos + 2] = FXARGB_R(argb);
+ } else {
+ dest_pos *= 4;
+ FX_CMYK cmyk = m_pPalette.get()[scanline[src_x]];
+ dest_scan[dest_pos] = FXSYS_GetCValue(cmyk);
+ dest_scan[dest_pos + 1] = FXSYS_GetMValue(cmyk);
+ dest_scan[dest_pos + 2] = FXSYS_GetYValue(cmyk);
+ dest_scan[dest_pos + 3] = FXSYS_GetKValue(cmyk);
+ }
+ } else {
+ dest_scan[dest_pos] = scanline[src_x];
+ }
+ }
+ } else {
+ for (int i = 0; i < clip_width; i++) {
+ uint32_t dest_x = clip_left + i;
+ uint32_t src_x =
+ bFlipX ? (m_Width - dest_x * m_Width / dest_width - 1) * src_Bpp
+ : (dest_x * m_Width / dest_width) * src_Bpp;
+ src_x %= m_Width * src_Bpp;
+ int dest_pos = i * src_Bpp;
+ for (int b = 0; b < src_Bpp; b++) {
+ dest_scan[dest_pos + b] = scanline[src_x + b];
+ }
+ }
+ }
+}
+
+// TODO(weili): Split this function into two for handling CMYK and RGB
+// colors separately.
+bool CFX_DIBitmap::ConvertColorScale(uint32_t forecolor, uint32_t backcolor) {
+ ASSERT(!IsAlphaMask());
+ if (!m_pBuffer || IsAlphaMask())
+ return false;
+
+ // Values used for CMYK colors.
+ int fc = 0;
+ int fm = 0;
+ int fy = 0;
+ int fk = 0;
+ int bc = 0;
+ int bm = 0;
+ int by = 0;
+ int bk = 0;
+ // Values used for RGB colors.
+ int fr = 0;
+ int fg = 0;
+ int fb = 0;
+ int br = 0;
+ int bg = 0;
+ int bb = 0;
+ bool isCmykImage = IsCmykImage();
+ if (isCmykImage) {
+ fc = FXSYS_GetCValue(forecolor);
+ fm = FXSYS_GetMValue(forecolor);
+ fy = FXSYS_GetYValue(forecolor);
+ fk = FXSYS_GetKValue(forecolor);
+ bc = FXSYS_GetCValue(backcolor);
+ bm = FXSYS_GetMValue(backcolor);
+ by = FXSYS_GetYValue(backcolor);
+ bk = FXSYS_GetKValue(backcolor);
+ } else {
+ fr = FXSYS_GetRValue(forecolor);
+ fg = FXSYS_GetGValue(forecolor);
+ fb = FXSYS_GetBValue(forecolor);
+ br = FXSYS_GetRValue(backcolor);
+ bg = FXSYS_GetGValue(backcolor);
+ bb = FXSYS_GetBValue(backcolor);
+ }
+ if (m_bpp <= 8) {
+ if (isCmykImage) {
+ if (forecolor == 0xff && backcolor == 0 && !m_pPalette) {
+ return true;
+ }
+ } else if (forecolor == 0 && backcolor == 0xffffff && !m_pPalette) {
+ return true;
+ }
+ if (!m_pPalette) {
+ BuildPalette();
+ }
+ int size = 1 << m_bpp;
+ if (isCmykImage) {
+ for (int i = 0; i < size; i++) {
+ uint8_t b, g, r;
+ AdobeCMYK_to_sRGB1(FXSYS_GetCValue(m_pPalette.get()[i]),
+ FXSYS_GetMValue(m_pPalette.get()[i]),
+ FXSYS_GetYValue(m_pPalette.get()[i]),
+ FXSYS_GetKValue(m_pPalette.get()[i]), r, g, b);
+ int gray = 255 - FXRGB2GRAY(r, g, b);
+ m_pPalette.get()[i] = CmykEncode(
+ bc + (fc - bc) * gray / 255, bm + (fm - bm) * gray / 255,
+ by + (fy - by) * gray / 255, bk + (fk - bk) * gray / 255);
+ }
+ } else {
+ for (int i = 0; i < size; i++) {
+ int gray = FXRGB2GRAY(FXARGB_R(m_pPalette.get()[i]),
+ FXARGB_G(m_pPalette.get()[i]),
+ FXARGB_B(m_pPalette.get()[i]));
+ m_pPalette.get()[i] = FXARGB_MAKE(0xff, br + (fr - br) * gray / 255,
+ bg + (fg - bg) * gray / 255,
+ bb + (fb - bb) * gray / 255);
+ }
+ }
+ return true;
+ }
+ if (isCmykImage) {
+ if (forecolor == 0xff && backcolor == 0x00) {
+ for (int row = 0; row < m_Height; row++) {
+ uint8_t* scanline = m_pBuffer.Get() + row * m_Pitch;
+ for (int col = 0; col < m_Width; col++) {
+ uint8_t b, g, r;
+ AdobeCMYK_to_sRGB1(scanline[0], scanline[1], scanline[2], scanline[3],
+ r, g, b);
+ *scanline++ = 0;
+ *scanline++ = 0;
+ *scanline++ = 0;
+ *scanline++ = 255 - FXRGB2GRAY(r, g, b);
+ }
+ }
+ return true;
+ }
+ } else if (forecolor == 0 && backcolor == 0xffffff) {
+ for (int row = 0; row < m_Height; row++) {
+ uint8_t* scanline = m_pBuffer.Get() + row * m_Pitch;
+ int gap = m_bpp / 8 - 2;
+ for (int col = 0; col < m_Width; col++) {
+ int gray = FXRGB2GRAY(scanline[2], scanline[1], scanline[0]);
+ *scanline++ = gray;
+ *scanline++ = gray;
+ *scanline = gray;
+ scanline += gap;
+ }
+ }
+ return true;
+ }
+ if (isCmykImage) {
+ for (int row = 0; row < m_Height; row++) {
+ uint8_t* scanline = m_pBuffer.Get() + row * m_Pitch;
+ for (int col = 0; col < m_Width; col++) {
+ uint8_t b, g, r;
+ AdobeCMYK_to_sRGB1(scanline[0], scanline[1], scanline[2], scanline[3],
+ r, g, b);
+ int gray = 255 - FXRGB2GRAY(r, g, b);
+ *scanline++ = bc + (fc - bc) * gray / 255;
+ *scanline++ = bm + (fm - bm) * gray / 255;
+ *scanline++ = by + (fy - by) * gray / 255;
+ *scanline++ = bk + (fk - bk) * gray / 255;
+ }
+ }
+ } else {
+ for (int row = 0; row < m_Height; row++) {
+ uint8_t* scanline = m_pBuffer.Get() + row * m_Pitch;
+ int gap = m_bpp / 8 - 2;
+ for (int col = 0; col < m_Width; col++) {
+ int gray = FXRGB2GRAY(scanline[2], scanline[1], scanline[0]);
+ *scanline++ = bb + (fb - bb) * gray / 255;
+ *scanline++ = bg + (fg - bg) * gray / 255;
+ *scanline = br + (fr - br) * gray / 255;
+ scanline += gap;
+ }
+ }
+ }
+ return true;
+}
+
+bool CFX_DIBitmap::CompositeBitmap(
+ int dest_left,
+ int dest_top,
+ int width,
+ int height,
+ const CFX_RetainPtr<CFX_DIBSource>& pSrcBitmap,
+ int src_left,
+ int src_top,
+ int blend_type,
+ const CFX_ClipRgn* pClipRgn,
+ bool bRgbByteOrder) {
+ if (!m_pBuffer)
+ return false;
+
+ ASSERT(!pSrcBitmap->IsAlphaMask());
+ ASSERT(m_bpp >= 8);
+ if (pSrcBitmap->IsAlphaMask() || m_bpp < 8) {
+ return false;
+ }
+ GetOverlapRect(dest_left, dest_top, width, height, pSrcBitmap->GetWidth(),
+ pSrcBitmap->GetHeight(), src_left, src_top, pClipRgn);
+ if (width == 0 || height == 0) {
+ return true;
+ }
+ CFX_RetainPtr<CFX_DIBitmap> pClipMask;
+ FX_RECT clip_box;
+ if (pClipRgn && pClipRgn->GetType() != CFX_ClipRgn::RectI) {
+ ASSERT(pClipRgn->GetType() == CFX_ClipRgn::MaskF);
+ pClipMask = pClipRgn->GetMask();
+ clip_box = pClipRgn->GetBox();
+ }
+ CFX_ScanlineCompositor compositor;
+ if (!compositor.Init(GetFormat(), pSrcBitmap->GetFormat(), width,
+ pSrcBitmap->GetPalette(), 0, blend_type,
+ pClipMask != nullptr, bRgbByteOrder, 0)) {
+ return false;
+ }
+ int dest_Bpp = m_bpp / 8;
+ int src_Bpp = pSrcBitmap->GetBPP() / 8;
+ bool bRgb = src_Bpp > 1 && !pSrcBitmap->IsCmykImage();
+ CFX_RetainPtr<CFX_DIBitmap> pSrcAlphaMask = pSrcBitmap->m_pAlphaMask;
+ for (int row = 0; row < height; row++) {
+ uint8_t* dest_scan =
+ m_pBuffer.Get() + (dest_top + row) * m_Pitch + dest_left * dest_Bpp;
+ const uint8_t* src_scan =
+ pSrcBitmap->GetScanline(src_top + row) + src_left * src_Bpp;
+ const uint8_t* src_scan_extra_alpha =
+ pSrcAlphaMask ? pSrcAlphaMask->GetScanline(src_top + row) + src_left
+ : nullptr;
+ uint8_t* dst_scan_extra_alpha =
+ m_pAlphaMask
+ ? (uint8_t*)m_pAlphaMask->GetScanline(dest_top + row) + dest_left
+ : nullptr;
+ const uint8_t* clip_scan = nullptr;
+ if (pClipMask) {
+ clip_scan = pClipMask->m_pBuffer.Get() +
+ (dest_top + row - clip_box.top) * pClipMask->m_Pitch +
+ (dest_left - clip_box.left);
+ }
+ if (bRgb) {
+ compositor.CompositeRgbBitmapLine(dest_scan, src_scan, width, clip_scan,
+ src_scan_extra_alpha,
+ dst_scan_extra_alpha);
+ } else {
+ compositor.CompositePalBitmapLine(dest_scan, src_scan, src_left, width,
+ clip_scan, src_scan_extra_alpha,
+ dst_scan_extra_alpha);
+ }
+ }
+ return true;
+}
+
+bool CFX_DIBitmap::CompositeMask(int dest_left,
+ int dest_top,
+ int width,
+ int height,
+ const CFX_RetainPtr<CFX_DIBSource>& pMask,
+ uint32_t color,
+ int src_left,
+ int src_top,
+ int blend_type,
+ const CFX_ClipRgn* pClipRgn,
+ bool bRgbByteOrder,
+ int alpha_flag) {
+ if (!m_pBuffer)
+ return false;
+
+ ASSERT(pMask->IsAlphaMask());
+ ASSERT(m_bpp >= 8);
+ if (!pMask->IsAlphaMask() || m_bpp < 8)
+ return false;
+
+ GetOverlapRect(dest_left, dest_top, width, height, pMask->GetWidth(),
+ pMask->GetHeight(), src_left, src_top, pClipRgn);
+ if (width == 0 || height == 0)
+ return true;
+
+ int src_alpha =
+ (uint8_t)(alpha_flag >> 8) ? (alpha_flag & 0xff) : FXARGB_A(color);
+ if (src_alpha == 0)
+ return true;
+
+ CFX_RetainPtr<CFX_DIBitmap> pClipMask;
+ FX_RECT clip_box;
+ if (pClipRgn && pClipRgn->GetType() != CFX_ClipRgn::RectI) {
+ ASSERT(pClipRgn->GetType() == CFX_ClipRgn::MaskF);
+ pClipMask = pClipRgn->GetMask();
+ clip_box = pClipRgn->GetBox();
+ }
+ int src_bpp = pMask->GetBPP();
+ int Bpp = GetBPP() / 8;
+ CFX_ScanlineCompositor compositor;
+ if (!compositor.Init(GetFormat(), pMask->GetFormat(), width, nullptr, color,
+ blend_type, pClipMask != nullptr, bRgbByteOrder,
+ alpha_flag)) {
+ return false;
+ }
+ for (int row = 0; row < height; row++) {
+ uint8_t* dest_scan =
+ m_pBuffer.Get() + (dest_top + row) * m_Pitch + dest_left * Bpp;
+ const uint8_t* src_scan = pMask->GetScanline(src_top + row);
+ uint8_t* dst_scan_extra_alpha =
+ m_pAlphaMask
+ ? (uint8_t*)m_pAlphaMask->GetScanline(dest_top + row) + dest_left
+ : nullptr;
+ const uint8_t* clip_scan = nullptr;
+ if (pClipMask) {
+ clip_scan = pClipMask->m_pBuffer.Get() +
+ (dest_top + row - clip_box.top) * pClipMask->m_Pitch +
+ (dest_left - clip_box.left);
+ }
+ if (src_bpp == 1) {
+ compositor.CompositeBitMaskLine(dest_scan, src_scan, src_left, width,
+ clip_scan, dst_scan_extra_alpha);
+ } else {
+ compositor.CompositeByteMaskLine(dest_scan, src_scan + src_left, width,
+ clip_scan, dst_scan_extra_alpha);
+ }
+ }
+ return true;
+}
+
+bool CFX_DIBitmap::CompositeRect(int left,
+ int top,
+ int width,
+ int height,
+ uint32_t color,
+ int alpha_flag) {
+ if (!m_pBuffer)
+ return false;
+
+ int src_alpha = (alpha_flag >> 8) ? (alpha_flag & 0xff) : FXARGB_A(color);
+ if (src_alpha == 0)
+ return true;
+
+ FX_RECT rect(left, top, left + width, top + height);
+ rect.Intersect(0, 0, m_Width, m_Height);
+ if (rect.IsEmpty())
+ return true;
+
+ width = rect.Width();
+ uint32_t dst_color;
+ if (alpha_flag >> 8)
+ dst_color = FXCMYK_TODIB(color);
+ else
+ dst_color = FXARGB_TODIB(color);
+ uint8_t* color_p = (uint8_t*)&dst_color;
+ if (m_bpp == 8) {
+ uint8_t gray = 255;
+ if (!IsAlphaMask()) {
+ if (alpha_flag >> 8) {
+ uint8_t r;
+ uint8_t g;
+ uint8_t b;
+ AdobeCMYK_to_sRGB1(color_p[0], color_p[1], color_p[2], color_p[3], r, g,
+ b);
+ gray = FXRGB2GRAY(r, g, b);
+ } else {
+ gray = (uint8_t)FXRGB2GRAY((int)color_p[2], color_p[1], color_p[0]);
+ }
+ if (IsCmykImage()) {
+ gray = ~gray;
+ }
+ }
+ for (int row = rect.top; row < rect.bottom; row++) {
+ uint8_t* dest_scan = m_pBuffer.Get() + row * m_Pitch + rect.left;
+ if (src_alpha == 255) {
+ memset(dest_scan, gray, width);
+ } else {
+ for (int col = 0; col < width; col++) {
+ *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, gray, src_alpha);
+ dest_scan++;
+ }
+ }
+ }
+ return true;
+ }
+ if (m_bpp == 1) {
+ ASSERT(!IsCmykImage() && static_cast<uint8_t>(alpha_flag >> 8) == 0);
+ int left_shift = rect.left % 8;
+ int right_shift = rect.right % 8;
+ int new_width = rect.right / 8 - rect.left / 8;
+ int index = 0;
+ if (m_pPalette) {
+ for (int i = 0; i < 2; i++) {
+ if (m_pPalette.get()[i] == color)
+ index = i;
+ }
+ } else {
+ index = (static_cast<uint8_t>(color) == 0xff) ? 1 : 0;
+ }
+ for (int row = rect.top; row < rect.bottom; row++) {
+ uint8_t* dest_scan_top =
+ const_cast<uint8_t*>(GetScanline(row)) + rect.left / 8;
+ uint8_t* dest_scan_top_r =
+ const_cast<uint8_t*>(GetScanline(row)) + rect.right / 8;
+ uint8_t left_flag = *dest_scan_top & (255 << (8 - left_shift));
+ uint8_t right_flag = *dest_scan_top_r & (255 >> right_shift);
+ if (new_width) {
+ memset(dest_scan_top + 1, index ? 255 : 0, new_width - 1);
+ if (!index) {
+ *dest_scan_top &= left_flag;
+ *dest_scan_top_r &= right_flag;
+ } else {
+ *dest_scan_top |= ~left_flag;
+ *dest_scan_top_r |= ~right_flag;
+ }
+ } else {
+ if (!index) {
+ *dest_scan_top &= left_flag | right_flag;
+ } else {
+ *dest_scan_top |= ~(left_flag | right_flag);
+ }
+ }
+ }
+ return true;
+ }
+ ASSERT(m_bpp >= 24);
+ if (m_bpp < 24 || (!(alpha_flag >> 8) && IsCmykImage()))
+ return false;
+ if (alpha_flag >> 8 && !IsCmykImage()) {
+ AdobeCMYK_to_sRGB1(FXSYS_GetCValue(color), FXSYS_GetMValue(color),
+ FXSYS_GetYValue(color), FXSYS_GetKValue(color),
+ color_p[2], color_p[1], color_p[0]);
+ }
+ if (!IsCmykImage())
+ color_p[3] = static_cast<uint8_t>(src_alpha);
+ int Bpp = m_bpp / 8;
+ bool bAlpha = HasAlpha();
+ bool bArgb = GetFormat() == FXDIB_Argb;
+ if (src_alpha == 255) {
+ for (int row = rect.top; row < rect.bottom; row++) {
+ uint8_t* dest_scan = m_pBuffer.Get() + row * m_Pitch + rect.left * Bpp;
+ uint8_t* dest_scan_alpha =
+ m_pAlphaMask ? (uint8_t*)m_pAlphaMask->GetScanline(row) + rect.left
+ : nullptr;
+ if (dest_scan_alpha) {
+ memset(dest_scan_alpha, 0xff, width);
+ }
+ if (Bpp == 4) {
+ uint32_t* scan = (uint32_t*)dest_scan;
+ for (int col = 0; col < width; col++) {
+ *scan++ = dst_color;
+ }
+ } else {
+ for (int col = 0; col < width; col++) {
+ *dest_scan++ = color_p[0];
+ *dest_scan++ = color_p[1];
+ *dest_scan++ = color_p[2];
+ }
+ }
+ }
+ return true;
+ }
+ for (int row = rect.top; row < rect.bottom; row++) {
+ uint8_t* dest_scan = m_pBuffer.Get() + row * m_Pitch + rect.left * Bpp;
+ if (bAlpha) {
+ if (bArgb) {
+ for (int col = 0; col < width; col++) {
+ uint8_t back_alpha = dest_scan[3];
+ if (back_alpha == 0) {
+ FXARGB_SETDIB(dest_scan, FXARGB_MAKE(src_alpha, color_p[2],
+ color_p[1], color_p[0]));
+ dest_scan += 4;
+ continue;
+ }
+ uint8_t dest_alpha =
+ back_alpha + src_alpha - back_alpha * src_alpha / 255;
+ int alpha_ratio = src_alpha * 255 / dest_alpha;
+ *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, color_p[0], alpha_ratio);
+ dest_scan++;
+ *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, color_p[1], alpha_ratio);
+ dest_scan++;
+ *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, color_p[2], alpha_ratio);
+ dest_scan++;
+ *dest_scan++ = dest_alpha;
+ }
+ } else {
+ uint8_t* dest_scan_alpha =
+ (uint8_t*)m_pAlphaMask->GetScanline(row) + rect.left;
+ for (int col = 0; col < width; col++) {
+ uint8_t back_alpha = *dest_scan_alpha;
+ if (back_alpha == 0) {
+ *dest_scan_alpha++ = src_alpha;
+ memcpy(dest_scan, color_p, Bpp);
+ dest_scan += Bpp;
+ continue;
+ }
+ uint8_t dest_alpha =
+ back_alpha + src_alpha - back_alpha * src_alpha / 255;
+ *dest_scan_alpha++ = dest_alpha;
+ int alpha_ratio = src_alpha * 255 / dest_alpha;
+ for (int comps = 0; comps < Bpp; comps++) {
+ *dest_scan =
+ FXDIB_ALPHA_MERGE(*dest_scan, color_p[comps], alpha_ratio);
+ dest_scan++;
+ }
+ }
+ }
+ } else {
+ for (int col = 0; col < width; col++) {
+ for (int comps = 0; comps < Bpp; comps++) {
+ if (comps == 3) {
+ *dest_scan++ = 255;
+ continue;
+ }
+ *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, color_p[comps], src_alpha);
+ dest_scan++;
+ }
+ }
+ }
+ }
+ return true;
+}
+
+bool CFX_DIBitmap::ConvertFormat(FXDIB_Format dest_format) {
+ FXDIB_Format src_format = GetFormat();
+ if (dest_format == src_format)
+ return true;
+
+ if (dest_format == FXDIB_8bppMask && src_format == FXDIB_8bppRgb &&
+ !m_pPalette) {
+ m_AlphaFlag = 1;
+ return true;
+ }
+ if (dest_format == FXDIB_Argb && src_format == FXDIB_Rgb32) {
+ m_AlphaFlag = 2;
+ for (int row = 0; row < m_Height; row++) {
+ uint8_t* scanline = m_pBuffer.Get() + row * m_Pitch + 3;
+ for (int col = 0; col < m_Width; col++) {
+ *scanline = 0xff;
+ scanline += 4;
+ }
+ }
+ return true;
+ }
+ int dest_bpp = dest_format & 0xff;
+ int dest_pitch = (dest_bpp * m_Width + 31) / 32 * 4;
+ std::unique_ptr<uint8_t, FxFreeDeleter> dest_buf(
+ FX_TryAlloc(uint8_t, dest_pitch * m_Height + 4));
+ if (!dest_buf)
+ return false;
+
+ CFX_RetainPtr<CFX_DIBitmap> pAlphaMask;
+ if (dest_format == FXDIB_Argb) {
+ memset(dest_buf.get(), 0xff, dest_pitch * m_Height + 4);
+ if (m_pAlphaMask) {
+ for (int row = 0; row < m_Height; row++) {
+ uint8_t* pDstScanline = dest_buf.get() + row * dest_pitch + 3;
+ const uint8_t* pSrcScanline = m_pAlphaMask->GetScanline(row);
+ for (int col = 0; col < m_Width; col++) {
+ *pDstScanline = *pSrcScanline++;
+ pDstScanline += 4;
+ }
+ }
+ }
+ } else if (dest_format & 0x0200) {
+ if (src_format == FXDIB_Argb) {
+ pAlphaMask = CloneAlphaMask();
+ if (!pAlphaMask)
+ return false;
+ } else {
+ if (!m_pAlphaMask) {
+ if (!BuildAlphaMask())
+ return false;
+ pAlphaMask = std::move(m_pAlphaMask);
+ } else {
+ pAlphaMask = m_pAlphaMask;
+ }
+ }
+ }
+ bool ret = false;
+ CFX_RetainPtr<CFX_DIBSource> holder(this);
+ std::unique_ptr<uint32_t, FxFreeDeleter> pal_8bpp;
+ ret = ConvertBuffer(dest_format, dest_buf.get(), dest_pitch, m_Width,
+ m_Height, holder, 0, 0, &pal_8bpp);
+ if (!ret)
+ return false;
+
+ m_pAlphaMask = pAlphaMask;
+ m_pPalette = std::move(pal_8bpp);
+ m_pBuffer = std::move(dest_buf);
+ m_bpp = static_cast<uint8_t>(dest_format);
+ m_AlphaFlag = static_cast<uint8_t>(dest_format >> 8);
+ m_Pitch = dest_pitch;
+ return true;
+}
diff --git a/chromium/third_party/pdfium/core/fxge/dib/cfx_dibitmap.h b/chromium/third_party/pdfium/core/fxge/dib/cfx_dibitmap.h
new file mode 100644
index 00000000000..6fd4b7c89a4
--- /dev/null
+++ b/chromium/third_party/pdfium/core/fxge/dib/cfx_dibitmap.h
@@ -0,0 +1,120 @@
+// 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_CFX_DIBITMAP_H_
+#define CORE_FXGE_DIB_CFX_DIBITMAP_H_
+
+#include "core/fxcrt/cfx_maybe_owned.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_dibsource.h"
+#include "third_party/base/stl_util.h"
+
+class CFX_DIBitmap : public CFX_DIBSource {
+ public:
+ template <typename T, typename... Args>
+ friend CFX_RetainPtr<T> pdfium::MakeRetain(Args&&... args);
+
+ ~CFX_DIBitmap() override;
+
+ bool Create(int width,
+ int height,
+ FXDIB_Format format,
+ uint8_t* pBuffer = nullptr,
+ int pitch = 0);
+
+ bool Copy(const CFX_RetainPtr<CFX_DIBSource>& pSrc);
+
+ // CFX_DIBSource
+ uint8_t* GetBuffer() const override;
+ const uint8_t* GetScanline(int line) const override;
+ void DownSampleScanline(int line,
+ uint8_t* dest_scan,
+ int dest_bpp,
+ int dest_width,
+ bool bFlipX,
+ int clip_left,
+ int clip_width) const override;
+
+ void TakeOver(CFX_RetainPtr<CFX_DIBitmap>&& pSrcBitmap);
+ bool ConvertFormat(FXDIB_Format format);
+ void Clear(uint32_t color);
+
+ uint32_t GetPixel(int x, int y) const;
+ void SetPixel(int x, int y, uint32_t color);
+
+ bool LoadChannel(FXDIB_Channel destChannel,
+ const CFX_RetainPtr<CFX_DIBSource>& pSrcBitmap,
+ FXDIB_Channel srcChannel);
+ bool LoadChannel(FXDIB_Channel destChannel, int value);
+
+ bool MultiplyAlpha(int alpha);
+ bool MultiplyAlpha(const CFX_RetainPtr<CFX_DIBSource>& pAlphaMask);
+
+ bool TransferBitmap(int dest_left,
+ int dest_top,
+ int width,
+ int height,
+ const CFX_RetainPtr<CFX_DIBSource>& pSrcBitmap,
+ int src_left,
+ int src_top);
+
+ bool CompositeBitmap(int dest_left,
+ int dest_top,
+ int width,
+ int height,
+ const CFX_RetainPtr<CFX_DIBSource>& pSrcBitmap,
+ int src_left,
+ int src_top,
+ int blend_type = FXDIB_BLEND_NORMAL,
+ const CFX_ClipRgn* pClipRgn = nullptr,
+ bool bRgbByteOrder = false);
+
+ bool CompositeMask(int dest_left,
+ int dest_top,
+ int width,
+ int height,
+ const CFX_RetainPtr<CFX_DIBSource>& pMask,
+ uint32_t color,
+ int src_left,
+ int src_top,
+ int blend_type = FXDIB_BLEND_NORMAL,
+ const CFX_ClipRgn* pClipRgn = nullptr,
+ bool bRgbByteOrder = false,
+ int alpha_flag = 0);
+
+ bool CompositeRect(int dest_left,
+ int dest_top,
+ int width,
+ int height,
+ uint32_t color,
+ int alpha_flag);
+
+ bool ConvertColorScale(uint32_t forecolor, uint32_t backcolor);
+
+#if defined _SKIA_SUPPORT_ || _SKIA_SUPPORT_PATHS_
+ void PreMultiply();
+#endif
+#if defined _SKIA_SUPPORT_PATHS_
+ void UnPreMultiply();
+#endif
+
+ protected:
+ CFX_DIBitmap();
+ CFX_DIBitmap(const CFX_DIBitmap& src);
+
+#if defined _SKIA_SUPPORT_PATHS_
+ enum class Format { kCleared, kPreMultiplied, kUnPreMultiplied };
+#endif
+
+ CFX_MaybeOwned<uint8_t, FxFreeDeleter> m_pBuffer;
+#if defined _SKIA_SUPPORT_PATHS_
+ Format m_nFormat;
+#endif
+};
+
+#endif // CORE_FXGE_DIB_CFX_DIBITMAP_H_
diff --git a/chromium/third_party/pdfium/core/fxge/dib/fx_dib_convert.cpp b/chromium/third_party/pdfium/core/fxge/dib/cfx_dibsource.cpp
index aad3f343e20..63fcc5806ac 100644
--- a/chromium/third_party/pdfium/core/fxge/dib/fx_dib_convert.cpp
+++ b/chromium/third_party/pdfium/core/fxge/dib/cfx_dibsource.cpp
@@ -1,151 +1,107 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
+// 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
+#include "core/fxge/dib/cfx_dibsource.h"
+
+#include <algorithm>
#include <memory>
#include <utility>
+#include <vector>
#include "core/fxcodec/fx_codec.h"
-#include "core/fxcrt/cfx_maybe_owned.h"
-#include "core/fxge/fx_dib.h"
+#include "core/fxge/dib/cfx_bitmapstorer.h"
+#include "core/fxge/dib/cfx_dibitmap.h"
+#include "core/fxge/dib/cfx_imagestretcher.h"
+#include "core/fxge/dib/cfx_imagetransformer.h"
+#include "core/fxge/ge/cfx_cliprgn.h"
#include "third_party/base/ptr_util.h"
+namespace {
+
class CFX_Palette {
public:
- CFX_Palette();
+ explicit CFX_Palette(const CFX_RetainPtr<CFX_DIBSource>& pBitmap);
~CFX_Palette();
- bool BuildPalette(const 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; }
+ const uint32_t* GetPalette() { return m_Palette.data(); }
+ const std::pair<uint32_t, uint32_t>* GetLuts() const { return m_Luts.data(); }
+ int32_t GetLutCount() const { return m_lut; }
+ void SetAmountLut(int row, uint32_t value) { m_Luts[row].first = value; }
- protected:
- uint32_t* m_pPalette;
- uint32_t* m_cLut;
- uint32_t* m_aLut;
+ private:
+ std::vector<uint32_t> m_Palette;
+ // (Amount, Color) pairs
+ std::vector<std::pair<uint32_t, uint32_t>> m_Luts;
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 _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) {
+void Obtain_Pal(std::pair<uint32_t, uint32_t>* luts,
+ 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) {
+ if (lut_offset < 0)
lut_offset += 256;
- }
- uint32_t color = cLut[lut_offset];
+ uint32_t color = luts[lut_offset].second;
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;
+ ColorDecode(color, &r, &g, &b);
+ dest_pal[row] = (static_cast<uint32_t>(r) << 16) |
+ (static_cast<uint32_t>(g) << 8) | b | 0xff000000;
+ luts[lut_offset].first = 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_DIBSource* pBitmap) {
- if (!pBitmap) {
- return false;
- }
- FX_Free(m_pPalette);
- m_pPalette = FX_Alloc(uint32_t, 256);
+CFX_Palette::CFX_Palette(const CFX_RetainPtr<CFX_DIBSource>& pBitmap)
+ : m_Palette(256), m_Luts(4096), m_lut(0) {
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;
+ for (int row = 0; row < height; ++row) {
+ const uint8_t* scan_line = pBitmap->GetScanline(row);
+ for (int col = 0; col < width; ++col) {
+ const 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]++;
+ m_Luts[index].first++;
}
}
- 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++;
+ // Move non-zeros to the front and count them
+ for (int row = 0; row < 4096; ++row) {
+ if (m_Luts[row].first != 0) {
+ m_Luts[m_lut].first = m_Luts[row].first;
+ m_Luts[m_lut].second = row;
+ ++m_lut;
}
}
- _Qsort(m_aLut, m_cLut, 0, m_lut - 1);
- _Obtain_Pal(m_aLut, m_cLut, m_pPalette, m_lut);
- return true;
+ std::sort(m_Luts.begin(), m_Luts.begin() + m_lut,
+ [](const std::pair<uint32_t, uint32_t>& arg1,
+ const std::pair<uint32_t, uint32_t>& arg2) {
+ return arg1.first < arg2.first;
+ });
+ Obtain_Pal(m_Luts.data(), m_Palette.data(), m_lut);
}
+CFX_Palette::~CFX_Palette() {}
+
bool ConvertBuffer_1bppMask2Gray(uint8_t* dest_buf,
int dest_pitch,
int width,
int height,
- const CFX_DIBSource* pSrcBitmap,
+ const CFX_RetainPtr<CFX_DIBSource>& pSrcBitmap,
int src_left,
int src_top) {
uint8_t set_gray, reset_gray;
@@ -153,7 +109,7 @@ bool ConvertBuffer_1bppMask2Gray(uint8_t* dest_buf,
reset_gray = 0x00;
for (int row = 0; row < height; row++) {
uint8_t* dest_scan = dest_buf + row * dest_pitch;
- FXSYS_memset(dest_scan, reset_gray, width);
+ 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))) {
@@ -169,13 +125,13 @@ bool ConvertBuffer_8bppMask2Gray(uint8_t* dest_buf,
int dest_pitch,
int width,
int height,
- const CFX_DIBSource* pSrcBitmap,
+ 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;
- FXSYS_memcpy(dest_scan, src_scan, width);
+ memcpy(dest_scan, src_scan, width);
}
return true;
}
@@ -184,7 +140,7 @@ bool ConvertBuffer_1bppPlt2Gray(uint8_t* dest_buf,
int dest_pitch,
int width,
int height,
- const CFX_DIBSource* pSrcBitmap,
+ const CFX_RetainPtr<CFX_DIBSource>& pSrcBitmap,
int src_left,
int src_top) {
uint32_t* src_plt = pSrcBitmap->GetPalette();
@@ -215,7 +171,7 @@ bool ConvertBuffer_1bppPlt2Gray(uint8_t* dest_buf,
for (int row = 0; row < height; row++) {
uint8_t* dest_scan = dest_buf + row * dest_pitch;
- FXSYS_memset(dest_scan, gray[0], width);
+ 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))) {
@@ -231,7 +187,7 @@ bool ConvertBuffer_8bppPlt2Gray(uint8_t* dest_buf,
int dest_pitch,
int width,
int height,
- const CFX_DIBSource* pSrcBitmap,
+ const CFX_RetainPtr<CFX_DIBSource>& pSrcBitmap,
int src_left,
int src_top) {
uint32_t* src_plt = pSrcBitmap->GetPalette();
@@ -263,13 +219,14 @@ bool ConvertBuffer_8bppPlt2Gray(uint8_t* dest_buf,
return true;
}
-bool ConvertBuffer_RgbOrCmyk2Gray(uint8_t* dest_buf,
- int dest_pitch,
- int width,
- int height,
- const CFX_DIBSource* pSrcBitmap,
- int src_left,
- int src_top) {
+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++) {
@@ -278,10 +235,11 @@ bool ConvertBuffer_RgbOrCmyk2Gray(uint8_t* dest_buf,
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);
+ 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;
}
@@ -304,13 +262,13 @@ void ConvertBuffer_IndexCopy(uint8_t* dest_buf,
int dest_pitch,
int width,
int height,
- const CFX_DIBSource* pSrcBitmap,
+ 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;
- FXSYS_memset(dest_scan, 0, width);
+ 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))) {
@@ -324,7 +282,7 @@ void ConvertBuffer_IndexCopy(uint8_t* dest_buf,
uint8_t* dest_scan = dest_buf + row * dest_pitch;
const uint8_t* src_scan =
pSrcBitmap->GetScanline(src_top + row) + src_left;
- FXSYS_memcpy(dest_scan, src_scan, width);
+ memcpy(dest_scan, src_scan, width);
}
}
}
@@ -333,7 +291,7 @@ bool ConvertBuffer_Plt2PltRgb8(uint8_t* dest_buf,
int dest_pitch,
int width,
int height,
- const CFX_DIBSource* pSrcBitmap,
+ const CFX_RetainPtr<CFX_DIBSource>& pSrcBitmap,
int src_left,
int src_top,
uint32_t* dst_plt) {
@@ -352,7 +310,7 @@ bool ConvertBuffer_Plt2PltRgb8(uint8_t* dest_buf,
dst_plt[i] = FXARGB_MAKE(0xff, r, g, b);
}
} else {
- FXSYS_memcpy(dst_plt, src_plt, plt_size * 4);
+ memcpy(dst_plt, src_plt, plt_size * 4);
}
return true;
}
@@ -361,46 +319,46 @@ bool ConvertBuffer_Rgb2PltRgb8(uint8_t* dest_buf,
int dest_pitch,
int width,
int height,
- const CFX_DIBSource* pSrcBitmap,
+ 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) {
+ if (!pSrcBitmap)
return false;
- }
- int lut = palette.Getlut();
- uint32_t* pPalette = palette.GetPalette();
+ CFX_Palette palette(pSrcBitmap);
+ const std::pair<uint32_t, uint32_t>* Luts = palette.GetLuts();
+ int lut = palette.GetLutCount();
+ const uint32_t* pal = palette.GetPalette();
if (lut > 256) {
- int err, min_err;
+ int err;
+ int 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;
+ uint8_t r;
+ uint8_t g;
+ uint8_t b;
+ ColorDecode(Luts[row].second, &r, &g, &b);
+ uint32_t 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);
+ uint32_t p_color = pal[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;
+ palette.SetAmountLut(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;
+ 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;
@@ -409,13 +367,13 @@ bool ConvertBuffer_Rgb2PltRgb8(uint8_t* dest_buf,
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]);
+ if (clrindex == Luts[i].second) {
+ *(dest_scan + col) = static_cast<uint8_t>(Luts[i].first);
break;
}
}
}
- FXSYS_memcpy(dst_plt, pPalette, sizeof(uint32_t) * 256);
+ memcpy(dst_plt, pal, sizeof(uint32_t) * 256);
return true;
}
@@ -424,7 +382,7 @@ bool ConvertBuffer_1bppMask2Rgb(FXDIB_Format dst_format,
int dest_pitch,
int width,
int height,
- const CFX_DIBSource* pSrcBitmap,
+ const CFX_RetainPtr<CFX_DIBSource>& pSrcBitmap,
int src_left,
int src_top) {
int comps = (dst_format & 0xff) / 8;
@@ -455,7 +413,7 @@ bool ConvertBuffer_8bppMask2Rgb(FXDIB_Format dst_format,
int dest_pitch,
int width,
int height,
- const CFX_DIBSource* pSrcBitmap,
+ const CFX_RetainPtr<CFX_DIBSource>& pSrcBitmap,
int src_left,
int src_top) {
int comps = (dst_format & 0xff) / 8;
@@ -479,13 +437,13 @@ bool ConvertBuffer_1bppPlt2Rgb(FXDIB_Format dst_format,
int dest_pitch,
int width,
int height,
- const CFX_DIBSource* pSrcBitmap,
+ 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;
+ 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]);
@@ -531,20 +489,20 @@ bool ConvertBuffer_8bppPlt2Rgb(FXDIB_Format dst_format,
int dest_pitch,
int width,
int height,
- const CFX_DIBSource* pSrcBitmap,
+ 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;
+ 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 = (uint8_t*)plt;
+ bgr_ptr = reinterpret_cast<uint8_t*>(plt);
}
if (pSrcBitmap->IsCmykImage()) {
@@ -555,7 +513,7 @@ bool ConvertBuffer_8bppPlt2Rgb(FXDIB_Format dst_format,
bgr_ptr[1], bgr_ptr[0]);
bgr_ptr += 3;
}
- bgr_ptr = (uint8_t*)plt;
+ bgr_ptr = reinterpret_cast<uint8_t*>(plt);
}
for (int row = 0; row < height; row++) {
@@ -572,29 +530,31 @@ bool ConvertBuffer_8bppPlt2Rgb(FXDIB_Format dst_format,
return true;
}
-bool ConvertBuffer_24bppRgb2Rgb24(uint8_t* dest_buf,
- int dest_pitch,
- int width,
- int height,
- const CFX_DIBSource* pSrcBitmap,
- int src_left,
- int src_top) {
+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;
- FXSYS_memcpy(dest_scan, src_scan, width * 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_DIBSource* pSrcBitmap,
- int src_left,
- int src_top) {
+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 =
@@ -613,7 +573,7 @@ bool ConvertBuffer_Rgb2Rgb32(uint8_t* dest_buf,
int dest_pitch,
int width,
int height,
- const CFX_DIBSource* pSrcBitmap,
+ const CFX_RetainPtr<CFX_DIBSource>& pSrcBitmap,
int src_left,
int src_top) {
int comps = pSrcBitmap->GetBPP() / 8;
@@ -632,13 +592,14 @@ bool ConvertBuffer_Rgb2Rgb32(uint8_t* dest_buf,
return true;
}
-bool ConvertBuffer_32bppCmyk2Rgb32(uint8_t* dest_buf,
- int dest_pitch,
- int width,
- int height,
- const CFX_DIBSource* pSrcBitmap,
- int src_left,
- int src_top) {
+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 =
@@ -653,15 +614,534 @@ bool ConvertBuffer_32bppCmyk2Rgb32(uint8_t* dest_buf,
return true;
}
-bool ConvertBuffer(FXDIB_Format dest_format,
- uint8_t* dest_buf,
- int dest_pitch,
- int width,
- int height,
- const CFX_DIBSource* pSrcBitmap,
- int src_left,
- int src_top,
- std::unique_ptr<uint32_t, FxFreeDeleter>* p_pal) {
+} // namespace
+
+CFX_DIBSource::CFX_DIBSource()
+ : m_Width(0), m_Height(0), m_bpp(0), m_AlphaFlag(0), m_Pitch(0) {}
+
+CFX_DIBSource::~CFX_DIBSource() {}
+
+uint8_t* CFX_DIBSource::GetBuffer() const {
+ return nullptr;
+}
+
+bool CFX_DIBSource::SkipToScanline(int line, IFX_Pause* pPause) const {
+ return false;
+}
+
+CFX_RetainPtr<CFX_DIBitmap> CFX_DIBSource::Clone(const FX_RECT* pClip) const {
+ FX_RECT rect(0, 0, m_Width, m_Height);
+ if (pClip) {
+ rect.Intersect(*pClip);
+ if (rect.IsEmpty())
+ return nullptr;
+ }
+ auto pNewBitmap = pdfium::MakeRetain<CFX_DIBitmap>();
+ if (!pNewBitmap->Create(rect.Width(), rect.Height(), GetFormat()))
+ return nullptr;
+
+ pNewBitmap->SetPalette(m_pPalette.get());
+ pNewBitmap->SetAlphaMask(m_pAlphaMask, pClip);
+ if (GetBPP() == 1 && rect.left % 8 != 0) {
+ int left_shift = rect.left % 32;
+ int right_shift = 32 - left_shift;
+ int dword_count = pNewBitmap->m_Pitch / 4;
+ for (int row = rect.top; row < rect.bottom; row++) {
+ uint32_t* src_scan = (uint32_t*)GetScanline(row) + rect.left / 32;
+ uint32_t* dest_scan = (uint32_t*)pNewBitmap->GetScanline(row - rect.top);
+ for (int i = 0; i < dword_count; i++) {
+ dest_scan[i] =
+ (src_scan[i] << left_shift) | (src_scan[i + 1] >> right_shift);
+ }
+ }
+ } else {
+ int copy_len = (pNewBitmap->GetWidth() * pNewBitmap->GetBPP() + 7) / 8;
+ if (m_Pitch < static_cast<uint32_t>(copy_len))
+ copy_len = m_Pitch;
+
+ for (int row = rect.top; row < rect.bottom; row++) {
+ const uint8_t* src_scan = GetScanline(row) + rect.left * m_bpp / 8;
+ uint8_t* dest_scan = (uint8_t*)pNewBitmap->GetScanline(row - rect.top);
+ memcpy(dest_scan, src_scan, copy_len);
+ }
+ }
+ return pNewBitmap;
+}
+
+void CFX_DIBSource::BuildPalette() {
+ if (m_pPalette)
+ return;
+
+ if (GetBPP() == 1) {
+ m_pPalette.reset(FX_Alloc(uint32_t, 2));
+ if (IsCmykImage()) {
+ m_pPalette.get()[0] = 0xff;
+ m_pPalette.get()[1] = 0;
+ } else {
+ m_pPalette.get()[0] = 0xff000000;
+ m_pPalette.get()[1] = 0xffffffff;
+ }
+ } else if (GetBPP() == 8) {
+ m_pPalette.reset(FX_Alloc(uint32_t, 256));
+ if (IsCmykImage()) {
+ for (int i = 0; i < 256; i++)
+ m_pPalette.get()[i] = 0xff - i;
+ } else {
+ for (int i = 0; i < 256; i++)
+ m_pPalette.get()[i] = 0xff000000 | (i * 0x10101);
+ }
+ }
+}
+
+bool CFX_DIBSource::BuildAlphaMask() {
+ if (m_pAlphaMask)
+ return true;
+
+ m_pAlphaMask = pdfium::MakeRetain<CFX_DIBitmap>();
+ if (!m_pAlphaMask->Create(m_Width, m_Height, FXDIB_8bppMask)) {
+ m_pAlphaMask = nullptr;
+ return false;
+ }
+ memset(m_pAlphaMask->GetBuffer(), 0xff,
+ m_pAlphaMask->GetHeight() * m_pAlphaMask->GetPitch());
+ return true;
+}
+
+uint32_t CFX_DIBSource::GetPaletteEntry(int index) const {
+ ASSERT((GetBPP() == 1 || GetBPP() == 8) && !IsAlphaMask());
+ if (m_pPalette) {
+ return m_pPalette.get()[index];
+ }
+ if (IsCmykImage()) {
+ if (GetBPP() == 1) {
+ return index ? 0 : 0xff;
+ }
+ return 0xff - index;
+ }
+ if (GetBPP() == 1) {
+ return index ? 0xffffffff : 0xff000000;
+ }
+ return index * 0x10101 | 0xff000000;
+}
+
+void CFX_DIBSource::SetPaletteEntry(int index, uint32_t color) {
+ ASSERT((GetBPP() == 1 || GetBPP() == 8) && !IsAlphaMask());
+ if (!m_pPalette) {
+ BuildPalette();
+ }
+ m_pPalette.get()[index] = color;
+}
+
+int CFX_DIBSource::FindPalette(uint32_t color) const {
+ ASSERT((GetBPP() == 1 || GetBPP() == 8) && !IsAlphaMask());
+ if (!m_pPalette) {
+ if (IsCmykImage()) {
+ if (GetBPP() == 1)
+ return (static_cast<uint8_t>(color) == 0xff) ? 0 : 1;
+
+ return 0xff - static_cast<uint8_t>(color);
+ }
+ if (GetBPP() == 1) {
+ return (static_cast<uint8_t>(color) == 0xff) ? 1 : 0;
+ }
+ return static_cast<uint8_t>(color);
+ }
+ int palsize = (1 << GetBPP());
+ for (int i = 0; i < palsize; i++)
+ if (m_pPalette.get()[i] == color) {
+ return i;
+ }
+ return -1;
+}
+
+void CFX_DIBSource::GetOverlapRect(int& dest_left,
+ int& dest_top,
+ int& width,
+ int& height,
+ int src_width,
+ int src_height,
+ int& src_left,
+ int& src_top,
+ const CFX_ClipRgn* pClipRgn) {
+ if (width == 0 || height == 0) {
+ return;
+ }
+ ASSERT(width > 0 && height > 0);
+ if (dest_left > m_Width || dest_top > m_Height) {
+ width = 0;
+ height = 0;
+ return;
+ }
+ int x_offset = dest_left - src_left;
+ int y_offset = dest_top - src_top;
+ FX_RECT src_rect(src_left, src_top, src_left + width, src_top + height);
+ FX_RECT src_bound(0, 0, src_width, src_height);
+ src_rect.Intersect(src_bound);
+ FX_RECT dest_rect(src_rect.left + x_offset, src_rect.top + y_offset,
+ src_rect.right + x_offset, src_rect.bottom + y_offset);
+ FX_RECT dest_bound(0, 0, m_Width, m_Height);
+ dest_rect.Intersect(dest_bound);
+ if (pClipRgn) {
+ dest_rect.Intersect(pClipRgn->GetBox());
+ }
+ dest_left = dest_rect.left;
+ dest_top = dest_rect.top;
+ src_left = dest_left - x_offset;
+ src_top = dest_top - y_offset;
+ width = dest_rect.right - dest_rect.left;
+ height = dest_rect.bottom - dest_rect.top;
+}
+
+void CFX_DIBSource::SetPalette(const uint32_t* pSrc) {
+ static const uint32_t kPaletteSize = 256;
+ if (!pSrc || GetBPP() > 8) {
+ m_pPalette.reset();
+ return;
+ }
+ uint32_t pal_size = 1 << GetBPP();
+ if (!m_pPalette)
+ m_pPalette.reset(FX_Alloc(uint32_t, pal_size));
+ pal_size = std::min(pal_size, kPaletteSize);
+ memcpy(m_pPalette.get(), pSrc, pal_size * sizeof(uint32_t));
+}
+
+void CFX_DIBSource::GetPalette(uint32_t* pal, int alpha) const {
+ ASSERT(GetBPP() <= 8 && !IsCmykImage());
+ if (GetBPP() == 1) {
+ pal[0] = ((m_pPalette ? m_pPalette.get()[0] : 0xff000000) & 0xffffff) |
+ (alpha << 24);
+ pal[1] = ((m_pPalette ? m_pPalette.get()[1] : 0xffffffff) & 0xffffff) |
+ (alpha << 24);
+ return;
+ }
+ if (m_pPalette) {
+ for (int i = 0; i < 256; i++) {
+ pal[i] = (m_pPalette.get()[i] & 0x00ffffff) | (alpha << 24);
+ }
+ } else {
+ for (int i = 0; i < 256; i++) {
+ pal[i] = (i * 0x10101) | (alpha << 24);
+ }
+ }
+}
+
+CFX_RetainPtr<CFX_DIBitmap> CFX_DIBSource::CloneAlphaMask(
+ const FX_RECT* pClip) const {
+ ASSERT(GetFormat() == FXDIB_Argb);
+ FX_RECT rect(0, 0, m_Width, m_Height);
+ if (pClip) {
+ rect.Intersect(*pClip);
+ if (rect.IsEmpty())
+ return nullptr;
+ }
+ auto pMask = pdfium::MakeRetain<CFX_DIBitmap>();
+ if (!pMask->Create(rect.Width(), rect.Height(), FXDIB_8bppMask))
+ return nullptr;
+
+ for (int row = rect.top; row < rect.bottom; row++) {
+ const uint8_t* src_scan = GetScanline(row) + rect.left * 4 + 3;
+ uint8_t* dest_scan =
+ const_cast<uint8_t*>(pMask->GetScanline(row - rect.top));
+ for (int col = rect.left; col < rect.right; col++) {
+ *dest_scan++ = *src_scan;
+ src_scan += 4;
+ }
+ }
+ return pMask;
+}
+
+bool CFX_DIBSource::SetAlphaMask(const CFX_RetainPtr<CFX_DIBSource>& pAlphaMask,
+ const FX_RECT* pClip) {
+ if (!HasAlpha() || GetFormat() == FXDIB_Argb)
+ return false;
+
+ if (!pAlphaMask) {
+ m_pAlphaMask->Clear(0xff000000);
+ return true;
+ }
+ FX_RECT rect(0, 0, pAlphaMask->m_Width, pAlphaMask->m_Height);
+ if (pClip) {
+ rect.Intersect(*pClip);
+ if (rect.IsEmpty() || rect.Width() != m_Width ||
+ rect.Height() != m_Height) {
+ return false;
+ }
+ } else {
+ if (pAlphaMask->m_Width != m_Width || pAlphaMask->m_Height != m_Height)
+ return false;
+ }
+ for (int row = 0; row < m_Height; row++) {
+ memcpy(const_cast<uint8_t*>(m_pAlphaMask->GetScanline(row)),
+ pAlphaMask->GetScanline(row + rect.top) + rect.left,
+ m_pAlphaMask->m_Pitch);
+ }
+ return true;
+}
+
+CFX_RetainPtr<CFX_DIBitmap> CFX_DIBSource::FlipImage(bool bXFlip,
+ bool bYFlip) const {
+ auto pFlipped = pdfium::MakeRetain<CFX_DIBitmap>();
+ if (!pFlipped->Create(m_Width, m_Height, GetFormat()))
+ return nullptr;
+
+ pFlipped->SetPalette(m_pPalette.get());
+ uint8_t* pDestBuffer = pFlipped->GetBuffer();
+ int Bpp = m_bpp / 8;
+ for (int row = 0; row < m_Height; row++) {
+ const uint8_t* src_scan = GetScanline(row);
+ uint8_t* dest_scan =
+ pDestBuffer + m_Pitch * (bYFlip ? (m_Height - row - 1) : row);
+ if (!bXFlip) {
+ memcpy(dest_scan, src_scan, m_Pitch);
+ continue;
+ }
+ if (m_bpp == 1) {
+ memset(dest_scan, 0, m_Pitch);
+ for (int col = 0; col < m_Width; col++)
+ if (src_scan[col / 8] & (1 << (7 - col % 8))) {
+ int dest_col = m_Width - col - 1;
+ dest_scan[dest_col / 8] |= (1 << (7 - dest_col % 8));
+ }
+ } else {
+ dest_scan += (m_Width - 1) * Bpp;
+ if (Bpp == 1) {
+ for (int col = 0; col < m_Width; col++) {
+ *dest_scan = *src_scan;
+ dest_scan--;
+ src_scan++;
+ }
+ } else if (Bpp == 3) {
+ for (int col = 0; col < m_Width; col++) {
+ dest_scan[0] = src_scan[0];
+ dest_scan[1] = src_scan[1];
+ dest_scan[2] = src_scan[2];
+ dest_scan -= 3;
+ src_scan += 3;
+ }
+ } else {
+ ASSERT(Bpp == 4);
+ for (int col = 0; col < m_Width; col++) {
+ *(uint32_t*)dest_scan = *(uint32_t*)src_scan;
+ dest_scan -= 4;
+ src_scan += 4;
+ }
+ }
+ }
+ }
+ if (m_pAlphaMask) {
+ pDestBuffer = pFlipped->m_pAlphaMask->GetBuffer();
+ uint32_t dest_pitch = pFlipped->m_pAlphaMask->GetPitch();
+ for (int row = 0; row < m_Height; row++) {
+ const uint8_t* src_scan = m_pAlphaMask->GetScanline(row);
+ uint8_t* dest_scan =
+ pDestBuffer + dest_pitch * (bYFlip ? (m_Height - row - 1) : row);
+ if (!bXFlip) {
+ memcpy(dest_scan, src_scan, dest_pitch);
+ continue;
+ }
+ dest_scan += (m_Width - 1);
+ for (int col = 0; col < m_Width; col++) {
+ *dest_scan = *src_scan;
+ dest_scan--;
+ src_scan++;
+ }
+ }
+ }
+ return pFlipped;
+}
+
+CFX_RetainPtr<CFX_DIBitmap> CFX_DIBSource::CloneConvert(
+ FXDIB_Format dest_format) {
+ if (dest_format == GetFormat())
+ return Clone(nullptr);
+
+ auto pClone = pdfium::MakeRetain<CFX_DIBitmap>();
+ if (!pClone->Create(m_Width, m_Height, dest_format))
+ return nullptr;
+
+ CFX_RetainPtr<CFX_DIBitmap> pSrcAlpha;
+ if (HasAlpha()) {
+ if (GetFormat() == FXDIB_Argb)
+ pSrcAlpha = CloneAlphaMask();
+ else
+ pSrcAlpha = m_pAlphaMask;
+
+ if (!pSrcAlpha)
+ return nullptr;
+ }
+ bool ret = true;
+ if (dest_format & 0x0200) {
+ if (dest_format == FXDIB_Argb) {
+ ret = pSrcAlpha ? pClone->LoadChannel(FXDIB_Alpha, pSrcAlpha, FXDIB_Alpha)
+ : pClone->LoadChannel(FXDIB_Alpha, 0xff);
+ } else {
+ ret = pClone->SetAlphaMask(pSrcAlpha);
+ }
+ }
+ if (!ret)
+ return nullptr;
+
+ CFX_RetainPtr<CFX_DIBSource> holder(this);
+ std::unique_ptr<uint32_t, FxFreeDeleter> pal_8bpp;
+ if (!ConvertBuffer(dest_format, pClone->GetBuffer(), pClone->GetPitch(),
+ m_Width, m_Height, holder, 0, 0, &pal_8bpp)) {
+ return nullptr;
+ }
+ if (pal_8bpp)
+ pClone->SetPalette(pal_8bpp.get());
+
+ return pClone;
+}
+
+CFX_RetainPtr<CFX_DIBitmap> CFX_DIBSource::SwapXY(
+ bool bXFlip,
+ bool bYFlip,
+ const FX_RECT* pDestClip) const {
+ FX_RECT dest_clip(0, 0, m_Height, m_Width);
+ if (pDestClip)
+ dest_clip.Intersect(*pDestClip);
+ if (dest_clip.IsEmpty())
+ return nullptr;
+
+ auto pTransBitmap = pdfium::MakeRetain<CFX_DIBitmap>();
+ int result_height = dest_clip.Height();
+ int result_width = dest_clip.Width();
+ if (!pTransBitmap->Create(result_width, result_height, GetFormat()))
+ return nullptr;
+
+ pTransBitmap->SetPalette(m_pPalette.get());
+ int dest_pitch = pTransBitmap->GetPitch();
+ uint8_t* dest_buf = pTransBitmap->GetBuffer();
+ int row_start = bXFlip ? m_Height - dest_clip.right : dest_clip.left;
+ int row_end = bXFlip ? m_Height - dest_clip.left : dest_clip.right;
+ int col_start = bYFlip ? m_Width - dest_clip.bottom : dest_clip.top;
+ int col_end = bYFlip ? m_Width - dest_clip.top : dest_clip.bottom;
+ if (GetBPP() == 1) {
+ memset(dest_buf, 0xff, dest_pitch * result_height);
+ for (int row = row_start; row < row_end; row++) {
+ const uint8_t* src_scan = GetScanline(row);
+ int dest_col = (bXFlip ? dest_clip.right - (row - row_start) - 1 : row) -
+ dest_clip.left;
+ uint8_t* dest_scan = dest_buf;
+ if (bYFlip) {
+ dest_scan += (result_height - 1) * dest_pitch;
+ }
+ int dest_step = bYFlip ? -dest_pitch : dest_pitch;
+ for (int col = col_start; col < col_end; col++) {
+ if (!(src_scan[col / 8] & (1 << (7 - col % 8)))) {
+ dest_scan[dest_col / 8] &= ~(1 << (7 - dest_col % 8));
+ }
+ dest_scan += dest_step;
+ }
+ }
+ } else {
+ int nBytes = GetBPP() / 8;
+ int dest_step = bYFlip ? -dest_pitch : dest_pitch;
+ if (nBytes == 3) {
+ dest_step -= 2;
+ }
+ for (int row = row_start; row < row_end; row++) {
+ int dest_col = (bXFlip ? dest_clip.right - (row - row_start) - 1 : row) -
+ dest_clip.left;
+ uint8_t* dest_scan = dest_buf + dest_col * nBytes;
+ if (bYFlip) {
+ dest_scan += (result_height - 1) * dest_pitch;
+ }
+ if (nBytes == 4) {
+ uint32_t* src_scan = (uint32_t*)GetScanline(row) + col_start;
+ for (int col = col_start; col < col_end; col++) {
+ *(uint32_t*)dest_scan = *src_scan++;
+ dest_scan += dest_step;
+ }
+ } else {
+ const uint8_t* src_scan = GetScanline(row) + col_start * nBytes;
+ if (nBytes == 1) {
+ for (int col = col_start; col < col_end; col++) {
+ *dest_scan = *src_scan++;
+ dest_scan += dest_step;
+ }
+ } else {
+ for (int col = col_start; col < col_end; col++) {
+ *dest_scan++ = *src_scan++;
+ *dest_scan++ = *src_scan++;
+ *dest_scan = *src_scan++;
+ dest_scan += dest_step;
+ }
+ }
+ }
+ }
+ }
+ if (m_pAlphaMask) {
+ dest_pitch = pTransBitmap->m_pAlphaMask->GetPitch();
+ dest_buf = pTransBitmap->m_pAlphaMask->GetBuffer();
+ int dest_step = bYFlip ? -dest_pitch : dest_pitch;
+ for (int row = row_start; row < row_end; row++) {
+ int dest_col = (bXFlip ? dest_clip.right - (row - row_start) - 1 : row) -
+ dest_clip.left;
+ uint8_t* dest_scan = dest_buf + dest_col;
+ if (bYFlip) {
+ dest_scan += (result_height - 1) * dest_pitch;
+ }
+ const uint8_t* src_scan = m_pAlphaMask->GetScanline(row) + col_start;
+ for (int col = col_start; col < col_end; col++) {
+ *dest_scan = *src_scan++;
+ dest_scan += dest_step;
+ }
+ }
+ }
+ return pTransBitmap;
+}
+
+CFX_RetainPtr<CFX_DIBitmap> CFX_DIBSource::TransformTo(
+ const CFX_Matrix* pDestMatrix,
+ int& result_left,
+ int& result_top,
+ uint32_t flags,
+ const FX_RECT* pDestClip) {
+ CFX_RetainPtr<CFX_DIBSource> holder(this);
+ CFX_ImageTransformer transformer(holder, pDestMatrix, flags, pDestClip);
+ transformer.Start();
+ transformer.Continue(nullptr);
+ result_left = transformer.result().left;
+ result_top = transformer.result().top;
+ return transformer.DetachBitmap();
+}
+
+CFX_RetainPtr<CFX_DIBitmap> CFX_DIBSource::StretchTo(int dest_width,
+ int dest_height,
+ uint32_t flags,
+ const FX_RECT* pClip) {
+ CFX_RetainPtr<CFX_DIBSource> holder(this);
+ FX_RECT clip_rect(0, 0, abs(dest_width), abs(dest_height));
+ if (pClip)
+ clip_rect.Intersect(*pClip);
+
+ if (clip_rect.IsEmpty())
+ return nullptr;
+
+ if (dest_width == m_Width && dest_height == m_Height)
+ return Clone(&clip_rect);
+
+ CFX_BitmapStorer storer;
+ CFX_ImageStretcher stretcher(&storer, holder, dest_width, dest_height,
+ clip_rect, flags);
+ if (stretcher.Start())
+ stretcher.Continue(nullptr);
+
+ 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:
@@ -782,130 +1262,3 @@ bool ConvertBuffer(FXDIB_Format dest_format,
return false;
}
}
-
-std::unique_ptr<CFX_DIBitmap> CFX_DIBSource::CloneConvert(
- FXDIB_Format dest_format) const {
- if (dest_format == GetFormat())
- return Clone(nullptr);
-
- std::unique_ptr<CFX_DIBitmap> pClone = pdfium::MakeUnique<CFX_DIBitmap>();
- if (!pClone->Create(m_Width, m_Height, dest_format))
- return nullptr;
-
- CFX_MaybeOwned<CFX_DIBitmap> pSrcAlpha;
- if (HasAlpha()) {
- if (GetFormat() == FXDIB_Argb)
- pSrcAlpha = CloneAlphaMask();
- else
- pSrcAlpha = m_pAlphaMask;
-
- if (!pSrcAlpha)
- return nullptr;
- }
- bool ret = true;
- if (dest_format & 0x0200) {
- if (dest_format == FXDIB_Argb) {
- ret = pSrcAlpha
- ? pClone->LoadChannel(FXDIB_Alpha, pSrcAlpha.Get(), FXDIB_Alpha)
- : pClone->LoadChannel(FXDIB_Alpha, 0xff);
- } else {
- ret = pClone->SetAlphaMask(pSrcAlpha.Get());
- }
- }
- if (!ret)
- return nullptr;
-
- std::unique_ptr<uint32_t, FxFreeDeleter> pal_8bpp;
- if (!ConvertBuffer(dest_format, pClone->GetBuffer(), pClone->GetPitch(),
- m_Width, m_Height, this, 0, 0, &pal_8bpp)) {
- return nullptr;
- }
- if (pal_8bpp)
- pClone->SetPalette(pal_8bpp.get());
-
- return pClone;
-}
-
-bool CFX_DIBitmap::ConvertFormat(FXDIB_Format dest_format) {
- FXDIB_Format src_format = GetFormat();
- if (dest_format == src_format)
- return true;
-
- if (dest_format == FXDIB_8bppMask && src_format == FXDIB_8bppRgb &&
- !m_pPalette) {
- m_AlphaFlag = 1;
- return true;
- }
- if (dest_format == FXDIB_Argb && src_format == FXDIB_Rgb32) {
- m_AlphaFlag = 2;
- for (int row = 0; row < m_Height; row++) {
- uint8_t* scanline = m_pBuffer + row * m_Pitch + 3;
- for (int col = 0; col < m_Width; col++) {
- *scanline = 0xff;
- scanline += 4;
- }
- }
- return true;
- }
- int dest_bpp = dest_format & 0xff;
- int dest_pitch = (dest_bpp * m_Width + 31) / 32 * 4;
- uint8_t* dest_buf = FX_TryAlloc(uint8_t, dest_pitch * m_Height + 4);
- if (!dest_buf) {
- return false;
- }
- CFX_DIBitmap* pAlphaMask = nullptr;
- if (dest_format == FXDIB_Argb) {
- FXSYS_memset(dest_buf, 0xff, dest_pitch * m_Height + 4);
- if (m_pAlphaMask) {
- for (int row = 0; row < m_Height; row++) {
- uint8_t* pDstScanline = dest_buf + row * dest_pitch + 3;
- const uint8_t* pSrcScanline = m_pAlphaMask->GetScanline(row);
- for (int col = 0; col < m_Width; col++) {
- *pDstScanline = *pSrcScanline++;
- pDstScanline += 4;
- }
- }
- }
- } else if (dest_format & 0x0200) {
- if (src_format == FXDIB_Argb) {
- pAlphaMask = CloneAlphaMask().release();
- if (!pAlphaMask) {
- FX_Free(dest_buf);
- return false;
- }
- } else {
- if (!m_pAlphaMask) {
- if (!BuildAlphaMask()) {
- FX_Free(dest_buf);
- return false;
- }
- pAlphaMask = m_pAlphaMask;
- m_pAlphaMask = nullptr;
- } else {
- pAlphaMask = m_pAlphaMask;
- }
- }
- }
- bool ret = false;
- std::unique_ptr<uint32_t, FxFreeDeleter> pal_8bpp;
- ret = ConvertBuffer(dest_format, dest_buf, dest_pitch, m_Width, m_Height,
- this, 0, 0, &pal_8bpp);
- if (!ret) {
- if (pAlphaMask != m_pAlphaMask)
- delete pAlphaMask;
- FX_Free(dest_buf);
- return false;
- }
- if (m_pAlphaMask && pAlphaMask != m_pAlphaMask)
- delete m_pAlphaMask;
- m_pAlphaMask = pAlphaMask;
- m_pPalette = std::move(pal_8bpp);
- if (!m_bExtBuf)
- FX_Free(m_pBuffer);
- m_bExtBuf = false;
- m_pBuffer = dest_buf;
- m_bpp = (uint8_t)dest_format;
- m_AlphaFlag = (uint8_t)(dest_format >> 8);
- m_Pitch = dest_pitch;
- return true;
-}
diff --git a/chromium/third_party/pdfium/core/fxge/dib/cfx_dibsource.h b/chromium/third_party/pdfium/core/fxge/dib/cfx_dibsource.h
new file mode 100644
index 00000000000..97af196677c
--- /dev/null
+++ b/chromium/third_party/pdfium/core/fxge/dib/cfx_dibsource.h
@@ -0,0 +1,145 @@
+// 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_CFX_DIBSOURCE_H_
+#define CORE_FXGE_DIB_CFX_DIBSOURCE_H_
+
+#include <memory>
+
+#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,
+ FXDIB_Green,
+ FXDIB_Blue,
+ FXDIB_Cyan,
+ FXDIB_Magenta,
+ FXDIB_Yellow,
+ FXDIB_Black,
+ FXDIB_Alpha
+};
+
+class CFX_ClipRgn;
+class CFX_DIBitmap;
+
+class CFX_DIBSource : public CFX_Retainable {
+ public:
+ ~CFX_DIBSource() override;
+
+ virtual uint8_t* GetBuffer() const;
+ virtual const uint8_t* GetScanline(int line) const = 0;
+ virtual bool SkipToScanline(int line, IFX_Pause* pPause) const;
+ virtual void DownSampleScanline(int line,
+ uint8_t* dest_scan,
+ int dest_bpp,
+ int dest_width,
+ bool bFlipX,
+ int clip_left,
+ int clip_width) const = 0;
+
+ int GetWidth() const { return m_Width; }
+ int GetHeight() const { return m_Height; }
+
+ FXDIB_Format GetFormat() const {
+ return (FXDIB_Format)(m_AlphaFlag * 0x100 + m_bpp);
+ }
+ uint32_t GetPitch() const { return m_Pitch; }
+ uint32_t* GetPalette() const { return m_pPalette.get(); }
+ int GetBPP() const { return m_bpp; }
+
+ // TODO(thestig): Investigate this. Given the possible values of FXDIB_Format,
+ // it feels as though this should be implemented as !!(m_AlphaFlag & 1) and
+ // IsOpaqueImage() below should never be able to return true.
+ bool IsAlphaMask() const { return m_AlphaFlag == 1; }
+ bool HasAlpha() const { return !!(m_AlphaFlag & 2); }
+ bool IsOpaqueImage() const { return !(m_AlphaFlag & 3); }
+ bool IsCmykImage() const { return !!(m_AlphaFlag & 4); }
+
+ int GetPaletteSize() const {
+ return IsAlphaMask() ? 0 : (m_bpp == 1 ? 2 : (m_bpp == 8 ? 256 : 0));
+ }
+
+ uint32_t GetPaletteEntry(int index) const;
+
+ void SetPaletteEntry(int index, uint32_t color);
+ uint32_t GetPaletteArgb(int index) const { return GetPaletteEntry(index); }
+ void SetPaletteArgb(int index, uint32_t color) {
+ SetPaletteEntry(index, color);
+ }
+
+ // Copies into internally-owned palette.
+ void SetPalette(const uint32_t* pSrcPal);
+
+ CFX_RetainPtr<CFX_DIBitmap> Clone(const FX_RECT* pClip = nullptr) const;
+ CFX_RetainPtr<CFX_DIBitmap> CloneConvert(FXDIB_Format format);
+ CFX_RetainPtr<CFX_DIBitmap> StretchTo(int dest_width,
+ int dest_height,
+ uint32_t flags = 0,
+ const FX_RECT* pClip = nullptr);
+ CFX_RetainPtr<CFX_DIBitmap> TransformTo(const CFX_Matrix* pMatrix,
+ int& left,
+ int& top,
+ uint32_t flags = 0,
+ const FX_RECT* pClip = nullptr);
+ CFX_RetainPtr<CFX_DIBitmap> SwapXY(bool bXFlip,
+ bool bYFlip,
+ const FX_RECT* pClip = nullptr) const;
+ CFX_RetainPtr<CFX_DIBitmap> FlipImage(bool bXFlip, bool bYFlip) const;
+
+ CFX_RetainPtr<CFX_DIBitmap> CloneAlphaMask(
+ const FX_RECT* pClip = nullptr) const;
+
+ // Copies into internally-owned mask.
+ bool SetAlphaMask(const CFX_RetainPtr<CFX_DIBSource>& pAlphaMask,
+ const FX_RECT* pClip = nullptr);
+
+ void GetOverlapRect(int& dest_left,
+ int& dest_top,
+ int& width,
+ int& height,
+ int src_width,
+ int src_height,
+ int& src_left,
+ int& src_top,
+ const CFX_ClipRgn* pClipRgn);
+
+#if defined _SKIA_SUPPORT_ || defined _SKIA_SUPPORT_PATHS_
+ void DebugVerifyBitmapIsPreMultiplied(void* buffer = nullptr) const;
+#endif
+
+ CFX_RetainPtr<CFX_DIBitmap> m_pAlphaMask;
+
+ 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;
+ void GetPalette(uint32_t* pal, int alpha) const;
+
+ int m_Width;
+ int m_Height;
+ int m_bpp;
+ uint32_t m_AlphaFlag;
+ uint32_t m_Pitch;
+ // TODO(weili): Use std::vector for this.
+ std::unique_ptr<uint32_t, FxFreeDeleter> m_pPalette;
+};
+
+#endif // CORE_FXGE_DIB_CFX_DIBSOURCE_H_
diff --git a/chromium/third_party/pdfium/core/fxge/dib/cfx_filtereddib.cpp b/chromium/third_party/pdfium/core/fxge/dib/cfx_filtereddib.cpp
new file mode 100644
index 00000000000..2d6edd0d60e
--- /dev/null
+++ b/chromium/third_party/pdfium/core/fxge/dib/cfx_filtereddib.cpp
@@ -0,0 +1,42 @@
+// 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
+
+#include "core/fxge/dib/cfx_filtereddib.h"
+
+#include "core/fxge/fx_dib.h"
+
+CFX_FilteredDIB::CFX_FilteredDIB() {}
+
+CFX_FilteredDIB::~CFX_FilteredDIB() {}
+
+void CFX_FilteredDIB::LoadSrc(const CFX_RetainPtr<CFX_DIBSource>& pSrc) {
+ m_pSrc = pSrc;
+ m_Width = pSrc->GetWidth();
+ m_Height = pSrc->GetHeight();
+ FXDIB_Format format = GetDestFormat();
+ m_bpp = static_cast<uint8_t>(format);
+ m_AlphaFlag = static_cast<uint8_t>(format >> 8);
+ m_Pitch = (m_Width * (format & 0xff) + 31) / 32 * 4;
+ m_pPalette.reset(GetDestPalette());
+ m_Scanline.resize(m_Pitch);
+}
+
+const uint8_t* CFX_FilteredDIB::GetScanline(int line) const {
+ TranslateScanline(m_pSrc->GetScanline(line), &m_Scanline);
+ return m_Scanline.data();
+}
+
+void CFX_FilteredDIB::DownSampleScanline(int line,
+ uint8_t* dest_scan,
+ int dest_bpp,
+ int dest_width,
+ bool bFlipX,
+ int clip_left,
+ int clip_width) const {
+ m_pSrc->DownSampleScanline(line, dest_scan, dest_bpp, dest_width, bFlipX,
+ clip_left, clip_width);
+ TranslateDownSamples(dest_scan, dest_scan, clip_width, dest_bpp);
+}
diff --git a/chromium/third_party/pdfium/core/fxge/dib/cfx_filtereddib.h b/chromium/third_party/pdfium/core/fxge/dib/cfx_filtereddib.h
new file mode 100644
index 00000000000..3a16bb07504
--- /dev/null
+++ b/chromium/third_party/pdfium/core/fxge/dib/cfx_filtereddib.h
@@ -0,0 +1,50 @@
+// 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_CFX_FILTEREDDIB_H_
+#define CORE_FXGE_DIB_CFX_FILTEREDDIB_H_
+
+#include <vector>
+
+#include "core/fxcrt/cfx_retain_ptr.h"
+#include "core/fxge/dib/cfx_dibsource.h"
+
+class CFX_FilteredDIB : public CFX_DIBSource {
+ public:
+ template <typename T, typename... Args>
+ friend CFX_RetainPtr<T> pdfium::MakeRetain(Args&&... args);
+
+ ~CFX_FilteredDIB() override;
+
+ virtual FXDIB_Format GetDestFormat() = 0;
+ virtual uint32_t* GetDestPalette() = 0;
+ virtual void TranslateScanline(const uint8_t* src_buf,
+ std::vector<uint8_t>* dest_buf) const = 0;
+ virtual void TranslateDownSamples(uint8_t* dest_buf,
+ const uint8_t* src_buf,
+ int pixels,
+ int Bpp) const = 0;
+
+ void LoadSrc(const CFX_RetainPtr<CFX_DIBSource>& pSrc);
+
+ protected:
+ CFX_FilteredDIB();
+
+ // CFX_DIBSource
+ const uint8_t* GetScanline(int line) const override;
+ void DownSampleScanline(int line,
+ uint8_t* dest_scan,
+ int dest_bpp,
+ int dest_width,
+ bool bFlipX,
+ int clip_left,
+ int clip_width) const override;
+
+ CFX_RetainPtr<CFX_DIBSource> m_pSrc;
+ mutable std::vector<uint8_t> m_Scanline;
+};
+
+#endif // CORE_FXGE_DIB_CFX_FILTEREDDIB_H_
diff --git a/chromium/third_party/pdfium/core/fxge/dib/cfx_imagerenderer.cpp b/chromium/third_party/pdfium/core/fxge/dib/cfx_imagerenderer.cpp
new file mode 100644
index 00000000000..aa818555b69
--- /dev/null
+++ b/chromium/third_party/pdfium/core/fxge/dib/cfx_imagerenderer.cpp
@@ -0,0 +1,137 @@
+// 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
+
+#include "core/fxge/dib/cfx_imagerenderer.h"
+
+#include <memory>
+
+#include "core/fxge/dib/cfx_imagestretcher.h"
+#include "core/fxge/dib/cfx_imagetransformer.h"
+#include "core/fxge/ge/cfx_cliprgn.h"
+#include "third_party/base/ptr_util.h"
+
+CFX_ImageRenderer::CFX_ImageRenderer()
+ : m_Status(0),
+ m_bRgbByteOrder(false),
+ m_BlendType(FXDIB_BLEND_NORMAL) {}
+
+CFX_ImageRenderer::~CFX_ImageRenderer() {}
+
+bool CFX_ImageRenderer::Start(const CFX_RetainPtr<CFX_DIBitmap>& pDevice,
+ const CFX_ClipRgn* pClipRgn,
+ const CFX_RetainPtr<CFX_DIBSource>& pSource,
+ int bitmap_alpha,
+ uint32_t mask_color,
+ const CFX_Matrix* pMatrix,
+ uint32_t dib_flags,
+ bool bRgbByteOrder) {
+ m_Matrix = *pMatrix;
+ CFX_FloatRect image_rect_f = m_Matrix.GetUnitRect();
+ FX_RECT image_rect = image_rect_f.GetOuterRect();
+ m_ClipBox = pClipRgn ? pClipRgn->GetBox() : FX_RECT(0, 0, pDevice->GetWidth(),
+ pDevice->GetHeight());
+ m_ClipBox.Intersect(image_rect);
+ if (m_ClipBox.IsEmpty())
+ return false;
+
+ m_pDevice = pDevice;
+ m_pClipRgn = pClipRgn;
+ m_MaskColor = mask_color;
+ m_BitmapAlpha = bitmap_alpha;
+ m_Matrix = *pMatrix;
+ m_Flags = dib_flags;
+ m_AlphaFlag = 0;
+ m_bRgbByteOrder = bRgbByteOrder;
+ m_BlendType = FXDIB_BLEND_NORMAL;
+
+ if ((fabs(m_Matrix.b) >= 0.5f || m_Matrix.a == 0) ||
+ (fabs(m_Matrix.c) >= 0.5f || m_Matrix.d == 0)) {
+ if (fabs(m_Matrix.a) < fabs(m_Matrix.b) / 20 &&
+ fabs(m_Matrix.d) < fabs(m_Matrix.c) / 20 && fabs(m_Matrix.a) < 0.5f &&
+ fabs(m_Matrix.d) < 0.5f) {
+ int dest_width = image_rect.Width();
+ int dest_height = image_rect.Height();
+ FX_RECT bitmap_clip = m_ClipBox;
+ bitmap_clip.Offset(-image_rect.left, -image_rect.top);
+ bitmap_clip = FXDIB_SwapClipBox(bitmap_clip, dest_width, dest_height,
+ m_Matrix.c > 0, m_Matrix.b < 0);
+ m_Composer.Compose(pDevice, pClipRgn, bitmap_alpha, mask_color, m_ClipBox,
+ true, m_Matrix.c > 0, m_Matrix.b < 0, m_bRgbByteOrder,
+ 0, m_BlendType);
+ m_Stretcher = pdfium::MakeUnique<CFX_ImageStretcher>(
+ &m_Composer, pSource, dest_height, dest_width, bitmap_clip,
+ dib_flags);
+ if (!m_Stretcher->Start())
+ return false;
+
+ m_Status = 1;
+ return true;
+ }
+ m_Status = 2;
+ m_pTransformer = pdfium::MakeUnique<CFX_ImageTransformer>(
+ pSource, &m_Matrix, dib_flags, &m_ClipBox);
+ m_pTransformer->Start();
+ return true;
+ }
+
+ int dest_width = image_rect.Width();
+ if (m_Matrix.a < 0)
+ dest_width = -dest_width;
+
+ int dest_height = image_rect.Height();
+ if (m_Matrix.d > 0)
+ dest_height = -dest_height;
+
+ if (dest_width == 0 || dest_height == 0)
+ return false;
+
+ FX_RECT bitmap_clip = m_ClipBox;
+ bitmap_clip.Offset(-image_rect.left, -image_rect.top);
+ m_Composer.Compose(pDevice, pClipRgn, bitmap_alpha, mask_color, m_ClipBox,
+ false, false, false, m_bRgbByteOrder, 0, m_BlendType);
+ m_Status = 1;
+ m_Stretcher = pdfium::MakeUnique<CFX_ImageStretcher>(
+ &m_Composer, pSource, dest_width, dest_height, bitmap_clip, dib_flags);
+ return m_Stretcher->Start();
+}
+
+bool CFX_ImageRenderer::Continue(IFX_Pause* pPause) {
+ if (m_Status == 1)
+ return m_Stretcher->Continue(pPause);
+
+ if (m_Status != 2)
+ return false;
+
+ if (m_pTransformer->Continue(pPause))
+ return true;
+
+ CFX_RetainPtr<CFX_DIBitmap> pBitmap = m_pTransformer->DetachBitmap();
+ if (!pBitmap || !pBitmap->GetBuffer())
+ return false;
+
+ if (pBitmap->IsAlphaMask()) {
+ if (m_BitmapAlpha != 255) {
+ if (m_AlphaFlag >> 8) {
+ m_AlphaFlag = (((uint8_t)((m_AlphaFlag & 0xff) * m_BitmapAlpha / 255)) |
+ ((m_AlphaFlag >> 8) << 8));
+ } else {
+ m_MaskColor = FXARGB_MUL_ALPHA(m_MaskColor, m_BitmapAlpha);
+ }
+ }
+ m_pDevice->CompositeMask(
+ m_pTransformer->result().left, m_pTransformer->result().top,
+ pBitmap->GetWidth(), pBitmap->GetHeight(), pBitmap, m_MaskColor, 0, 0,
+ m_BlendType, m_pClipRgn, m_bRgbByteOrder, m_AlphaFlag);
+ } else {
+ if (m_BitmapAlpha != 255)
+ pBitmap->MultiplyAlpha(m_BitmapAlpha);
+ m_pDevice->CompositeBitmap(
+ m_pTransformer->result().left, m_pTransformer->result().top,
+ pBitmap->GetWidth(), pBitmap->GetHeight(), pBitmap, 0, 0, m_BlendType,
+ m_pClipRgn, m_bRgbByteOrder);
+ }
+ return false;
+}
diff --git a/chromium/third_party/pdfium/core/fxge/dib/cfx_imagerenderer.h b/chromium/third_party/pdfium/core/fxge/dib/cfx_imagerenderer.h
new file mode 100644
index 00000000000..f3d1286dc62
--- /dev/null
+++ b/chromium/third_party/pdfium/core/fxge/dib/cfx_imagerenderer.h
@@ -0,0 +1,56 @@
+// 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_CFX_IMAGERENDERER_H_
+#define CORE_FXGE_DIB_CFX_IMAGERENDERER_H_
+
+#include <memory>
+
+#include "core/fxcrt/cfx_retain_ptr.h"
+#include "core/fxcrt/fx_coordinates.h"
+#include "core/fxge/dib/cfx_bitmapcomposer.h"
+#include "core/fxge/dib/cfx_dibitmap.h"
+#include "core/fxge/dib/cfx_dibsource.h"
+#include "core/fxge/fx_dib.h"
+#include "third_party/base/stl_util.h"
+
+class CFX_ImageTransformer;
+class CFX_ImageStretcher;
+
+class CFX_ImageRenderer {
+ public:
+ CFX_ImageRenderer();
+ ~CFX_ImageRenderer();
+
+ bool Start(const CFX_RetainPtr<CFX_DIBitmap>& pDevice,
+ const CFX_ClipRgn* pClipRgn,
+ const CFX_RetainPtr<CFX_DIBSource>& pSource,
+ int bitmap_alpha,
+ uint32_t mask_color,
+ const CFX_Matrix* pMatrix,
+ uint32_t dib_flags,
+ bool bRgbByteOrder);
+
+ bool Continue(IFX_Pause* pPause);
+
+ private:
+ CFX_RetainPtr<CFX_DIBitmap> m_pDevice;
+ const CFX_ClipRgn* m_pClipRgn;
+ int m_BitmapAlpha;
+ uint32_t m_MaskColor;
+ CFX_Matrix m_Matrix;
+ std::unique_ptr<CFX_ImageTransformer> m_pTransformer;
+ std::unique_ptr<CFX_ImageStretcher> m_Stretcher;
+ CFX_BitmapComposer m_Composer;
+ int m_Status;
+ FX_RECT m_ClipBox;
+ uint32_t m_Flags;
+ int m_AlphaFlag;
+ bool m_bRgbByteOrder;
+ int m_BlendType;
+};
+
+#endif // CORE_FXGE_DIB_CFX_IMAGERENDERER_H_
diff --git a/chromium/third_party/pdfium/core/fxge/dib/cfx_imagestretcher.cpp b/chromium/third_party/pdfium/core/fxge/dib/cfx_imagestretcher.cpp
new file mode 100644
index 00000000000..f52a62d5296
--- /dev/null
+++ b/chromium/third_party/pdfium/core/fxge/dib/cfx_imagestretcher.cpp
@@ -0,0 +1,193 @@
+// 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
+
+#include "core/fxge/dib/cfx_imagestretcher.h"
+
+#include <climits>
+
+#include "core/fxge/dib/cfx_dibitmap.h"
+#include "core/fxge/dib/cfx_dibsource.h"
+#include "core/fxge/dib/cstretchengine.h"
+#include "core/fxge/fx_dib.h"
+#include "third_party/base/ptr_util.h"
+
+namespace {
+
+bool SourceSizeWithinLimit(int width, int height) {
+ const int kMaxProgressiveStretchPixels = 1000000;
+ return !height || width < kMaxProgressiveStretchPixels / height;
+}
+
+FXDIB_Format GetStretchedFormat(const CFX_DIBSource& src) {
+ FXDIB_Format format = src.GetFormat();
+ if (format == FXDIB_1bppMask)
+ return FXDIB_8bppMask;
+ if (format == FXDIB_1bppRgb)
+ return FXDIB_8bppRgb;
+ if (format == FXDIB_8bppRgb && src.GetPalette())
+ return FXDIB_Rgb;
+ 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(
+ IFX_ScanlineComposer* pDest,
+ const CFX_RetainPtr<CFX_DIBSource>& pSource,
+ int dest_width,
+ int dest_height,
+ const FX_RECT& bitmap_rect,
+ uint32_t flags)
+ : m_pDest(pDest),
+ m_pSource(pSource),
+ m_Flags(flags),
+ m_bFlipX(false),
+ m_bFlipY(false),
+ m_DestWidth(dest_width),
+ m_DestHeight(dest_height),
+ m_ClipRect(bitmap_rect),
+ m_DestFormat(GetStretchedFormat(*pSource)),
+ m_DestBPP(m_DestFormat & 0xff),
+ m_LineIndex(0) {}
+
+CFX_ImageStretcher::~CFX_ImageStretcher() {}
+
+bool CFX_ImageStretcher::Start() {
+ if (m_DestWidth == 0 || m_DestHeight == 0)
+ return false;
+
+ if (m_pSource->GetFormat() == FXDIB_1bppRgb && m_pSource->GetPalette()) {
+ FX_ARGB pal[256];
+ int a0, r0, g0, b0, a1, r1, g1, b1;
+ ArgbDecode(m_pSource->GetPaletteEntry(0), a0, r0, g0, b0);
+ ArgbDecode(m_pSource->GetPaletteEntry(1), a1, r1, g1, b1);
+ for (int i = 0; i < 256; i++) {
+ int a = a0 + (a1 - a0) * i / 255;
+ int r = r0 + (r1 - r0) * i / 255;
+ int g = g0 + (g1 - g0) * i / 255;
+ int b = b0 + (b1 - b0) * i / 255;
+ pal[i] = ArgbEncode(a, r, g, b);
+ }
+ if (!m_pDest->SetInfo(m_ClipRect.Width(), m_ClipRect.Height(), m_DestFormat,
+ pal)) {
+ return false;
+ }
+ } else if (m_pSource->GetFormat() == FXDIB_1bppCmyk &&
+ m_pSource->GetPalette()) {
+ FX_CMYK pal[256];
+ int c0, m0, y0, k0, c1, m1, y1, k1;
+ CmykDecode(m_pSource->GetPaletteEntry(0), c0, m0, y0, k0);
+ CmykDecode(m_pSource->GetPaletteEntry(1), c1, m1, y1, k1);
+ for (int i = 0; i < 256; i++) {
+ int c = c0 + (c1 - c0) * i / 255;
+ int m = m0 + (m1 - m0) * i / 255;
+ int y = y0 + (y1 - y0) * i / 255;
+ int k = k0 + (k1 - k0) * i / 255;
+ pal[i] = CmykEncode(c, m, y, k);
+ }
+ if (!m_pDest->SetInfo(m_ClipRect.Width(), m_ClipRect.Height(), m_DestFormat,
+ pal)) {
+ return false;
+ }
+ } else if (!m_pDest->SetInfo(m_ClipRect.Width(), m_ClipRect.Height(),
+ m_DestFormat, nullptr)) {
+ return false;
+ }
+
+ if (m_Flags & FXDIB_DOWNSAMPLE)
+ return StartQuickStretch();
+ return StartStretch();
+}
+
+bool CFX_ImageStretcher::Continue(IFX_Pause* pPause) {
+ if (m_Flags & FXDIB_DOWNSAMPLE)
+ return ContinueQuickStretch(pPause);
+ return ContinueStretch(pPause);
+}
+
+bool CFX_ImageStretcher::StartStretch() {
+ m_pStretchEngine = pdfium::MakeUnique<CStretchEngine>(
+ m_pDest, m_DestFormat, m_DestWidth, m_DestHeight, m_ClipRect, m_pSource,
+ m_Flags);
+ m_pStretchEngine->StartStretchHorz();
+ if (SourceSizeWithinLimit(m_pSource->GetWidth(), m_pSource->GetHeight())) {
+ m_pStretchEngine->Continue(nullptr);
+ return false;
+ }
+ return true;
+}
+
+bool CFX_ImageStretcher::ContinueStretch(IFX_Pause* pPause) {
+ return m_pStretchEngine && m_pStretchEngine->Continue(pPause);
+}
+
+bool CFX_ImageStretcher::StartQuickStretch() {
+ if (m_DestWidth < 0) {
+ m_bFlipX = true;
+ m_DestWidth = -m_DestWidth;
+ }
+ if (m_DestHeight < 0) {
+ m_bFlipY = true;
+ m_DestHeight = -m_DestHeight;
+ }
+ uint32_t size = m_ClipRect.Width();
+ if (size && m_DestBPP > static_cast<int>(INT_MAX / size))
+ return false;
+
+ size *= m_DestBPP;
+ m_pScanline.reset(FX_Alloc(uint8_t, (size / 8 + 3) / 4 * 4));
+ if (m_pSource->m_pAlphaMask)
+ m_pMaskScanline.reset(FX_Alloc(uint8_t, (m_ClipRect.Width() + 3) / 4 * 4));
+
+ if (SourceSizeWithinLimit(m_pSource->GetWidth(), m_pSource->GetHeight())) {
+ ContinueQuickStretch(nullptr);
+ return false;
+ }
+ return true;
+}
+
+bool CFX_ImageStretcher::ContinueQuickStretch(IFX_Pause* pPause) {
+ if (!m_pScanline)
+ return false;
+
+ int result_width = m_ClipRect.Width();
+ int result_height = m_ClipRect.Height();
+ int src_height = m_pSource->GetHeight();
+ for (; m_LineIndex < result_height; m_LineIndex++) {
+ int dest_y;
+ int src_y;
+ if (m_bFlipY) {
+ dest_y = result_height - m_LineIndex - 1;
+ src_y = (m_DestHeight - (dest_y + m_ClipRect.top) - 1) * src_height /
+ m_DestHeight;
+ } else {
+ dest_y = m_LineIndex;
+ src_y = (dest_y + m_ClipRect.top) * src_height / m_DestHeight;
+ }
+ src_y = pdfium::clamp(src_y, 0, src_height - 1);
+
+ if (m_pSource->SkipToScanline(src_y, pPause))
+ return true;
+
+ m_pSource->DownSampleScanline(src_y, m_pScanline.get(), m_DestBPP,
+ m_DestWidth, m_bFlipX, m_ClipRect.left,
+ result_width);
+ if (m_pMaskScanline) {
+ m_pSource->m_pAlphaMask->DownSampleScanline(
+ src_y, m_pMaskScanline.get(), 1, m_DestWidth, m_bFlipX,
+ m_ClipRect.left, result_width);
+ }
+ m_pDest->ComposeScanline(dest_y, m_pScanline.get(), m_pMaskScanline.get());
+ }
+ return false;
+}
diff --git a/chromium/third_party/pdfium/core/fxge/dib/cfx_imagestretcher.h b/chromium/third_party/pdfium/core/fxge/dib/cfx_imagestretcher.h
new file mode 100644
index 00000000000..63863cd1a9b
--- /dev/null
+++ b/chromium/third_party/pdfium/core/fxge/dib/cfx_imagestretcher.h
@@ -0,0 +1,56 @@
+// 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_CFX_IMAGESTRETCHER_H_
+#define CORE_FXGE_DIB_CFX_IMAGESTRETCHER_H_
+
+#include <memory>
+
+#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;
+
+class CFX_ImageStretcher {
+ public:
+ CFX_ImageStretcher(IFX_ScanlineComposer* pDest,
+ const CFX_RetainPtr<CFX_DIBSource>& pSource,
+ int dest_width,
+ int dest_height,
+ const FX_RECT& bitmap_rect,
+ uint32_t flags);
+ ~CFX_ImageStretcher();
+
+ bool Start();
+ bool Continue(IFX_Pause* pPause);
+
+ CFX_RetainPtr<CFX_DIBSource> source() { return m_pSource; }
+
+ private:
+ bool StartQuickStretch();
+ bool StartStretch();
+ bool ContinueQuickStretch(IFX_Pause* pPause);
+ bool ContinueStretch(IFX_Pause* pPause);
+
+ IFX_ScanlineComposer* const m_pDest;
+ CFX_RetainPtr<CFX_DIBSource> m_pSource;
+ std::unique_ptr<CStretchEngine> m_pStretchEngine;
+ std::unique_ptr<uint8_t, FxFreeDeleter> m_pScanline;
+ std::unique_ptr<uint8_t, FxFreeDeleter> m_pMaskScanline;
+ const uint32_t m_Flags;
+ bool m_bFlipX;
+ bool m_bFlipY;
+ int m_DestWidth;
+ int m_DestHeight;
+ FX_RECT m_ClipRect;
+ const FXDIB_Format m_DestFormat;
+ const int m_DestBPP;
+ int m_LineIndex;
+};
+
+#endif // CORE_FXGE_DIB_CFX_IMAGESTRETCHER_H_
diff --git a/chromium/third_party/pdfium/core/fxge/dib/fx_dib_transform.cpp b/chromium/third_party/pdfium/core/fxge/dib/cfx_imagetransformer.cpp
index bd882729413..c5fb467ad83 100644
--- a/chromium/third_party/pdfium/core/fxge/dib/fx_dib_transform.cpp
+++ b/chromium/third_party/pdfium/core/fxge/dib/cfx_imagetransformer.cpp
@@ -1,14 +1,15 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
+// 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
-#include "core/fxge/dib/dib_int.h"
+#include "core/fxge/dib/cfx_imagetransformer.h"
#include <memory>
#include <utility>
+#include "core/fxge/dib/cfx_imagestretcher.h"
#include "core/fxge/fx_dib.h"
#include "third_party/base/ptr_util.h"
@@ -100,7 +101,7 @@ void bicubic_get_pos_weight(int pos_pixel[],
v_w[3] = SDP_Table[512 - res_y];
}
-FXDIB_Format GetTransformedFormat(const CFX_DIBSource* pDrc) {
+FXDIB_Format GetTransformedFormat(const CFX_RetainPtr<CFX_DIBSource>& pDrc) {
FXDIB_Format format = pDrc->GetFormat();
if (pDrc->IsAlphaMask()) {
format = FXDIB_8bppMask;
@@ -114,44 +115,30 @@ FXDIB_Format GetTransformedFormat(const CFX_DIBSource* pDrc) {
return format;
}
-} // namespace
+class CPDF_FixedMatrix {
+ public:
+ CPDF_FixedMatrix(const CFX_Matrix& src, int bits) {
+ base = 1 << bits;
+ a = FXSYS_round(src.a * base);
+ b = FXSYS_round(src.b * base);
+ c = FXSYS_round(src.c * base);
+ d = FXSYS_round(src.d * base);
+ e = FXSYS_round(src.e * base);
+ f = FXSYS_round(src.f * base);
+ }
+
+ inline void Transform(int x, int y, int& x1, int& y1) {
+ x1 = (a * x + c * y + e + base / 2) / base;
+ y1 = (b * x + d * y + f + base / 2) / base;
+ }
-const int16_t SDP_Table[513] = {
- 256, 256, 256, 256, 256, 256, 256, 256, 256, 255, 255, 255, 255, 255, 255,
- 254, 254, 254, 254, 253, 253, 253, 252, 252, 252, 251, 251, 251, 250, 250,
- 249, 249, 249, 248, 248, 247, 247, 246, 246, 245, 244, 244, 243, 243, 242,
- 242, 241, 240, 240, 239, 238, 238, 237, 236, 236, 235, 234, 233, 233, 232,
- 231, 230, 230, 229, 228, 227, 226, 226, 225, 224, 223, 222, 221, 220, 219,
- 218, 218, 217, 216, 215, 214, 213, 212, 211, 210, 209, 208, 207, 206, 205,
- 204, 203, 202, 201, 200, 199, 198, 196, 195, 194, 193, 192, 191, 190, 189,
- 188, 186, 185, 184, 183, 182, 181, 179, 178, 177, 176, 175, 173, 172, 171,
- 170, 169, 167, 166, 165, 164, 162, 161, 160, 159, 157, 156, 155, 154, 152,
- 151, 150, 149, 147, 146, 145, 143, 142, 141, 140, 138, 137, 136, 134, 133,
- 132, 130, 129, 128, 126, 125, 124, 122, 121, 120, 119, 117, 116, 115, 113,
- 112, 111, 109, 108, 107, 105, 104, 103, 101, 100, 99, 97, 96, 95, 93,
- 92, 91, 89, 88, 87, 85, 84, 83, 81, 80, 79, 77, 76, 75, 73,
- 72, 71, 69, 68, 67, 66, 64, 63, 62, 60, 59, 58, 57, 55, 54,
- 53, 52, 50, 49, 48, 47, 45, 44, 43, 42, 40, 39, 38, 37, 36,
- 34, 33, 32, 31, 30, 28, 27, 26, 25, 24, 23, 21, 20, 19, 18,
- 17, 16, 15, 14, 13, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2,
- 1, 0, 0, -1, -2, -3, -4, -5, -6, -7, -7, -8, -9, -10, -11,
- -12, -12, -13, -14, -15, -15, -16, -17, -17, -18, -19, -19, -20, -21, -21,
- -22, -22, -23, -24, -24, -25, -25, -26, -26, -27, -27, -27, -28, -28, -29,
- -29, -30, -30, -30, -31, -31, -31, -32, -32, -32, -33, -33, -33, -33, -34,
- -34, -34, -34, -35, -35, -35, -35, -35, -36, -36, -36, -36, -36, -36, -36,
- -36, -36, -37, -37, -37, -37, -37, -37, -37, -37, -37, -37, -37, -37, -37,
- -37, -37, -37, -37, -37, -37, -37, -37, -36, -36, -36, -36, -36, -36, -36,
- -36, -36, -35, -35, -35, -35, -35, -35, -34, -34, -34, -34, -34, -33, -33,
- -33, -33, -33, -32, -32, -32, -32, -31, -31, -31, -31, -30, -30, -30, -30,
- -29, -29, -29, -29, -28, -28, -28, -27, -27, -27, -27, -26, -26, -26, -25,
- -25, -25, -24, -24, -24, -23, -23, -23, -22, -22, -22, -22, -21, -21, -21,
- -20, -20, -20, -19, -19, -19, -18, -18, -18, -17, -17, -17, -16, -16, -16,
- -15, -15, -15, -14, -14, -14, -13, -13, -13, -12, -12, -12, -11, -11, -11,
- -10, -10, -10, -9, -9, -9, -9, -8, -8, -8, -7, -7, -7, -7, -6,
- -6, -6, -6, -5, -5, -5, -5, -4, -4, -4, -4, -3, -3, -3, -3,
- -3, -2, -2, -2, -2, -2, -1, -1, -1, -1, -1, -1, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0,
+ int a;
+ int b;
+ int c;
+ int d;
+ int e;
+ int f;
+ int base;
};
class CFX_BilinearMatrix : public CPDF_FixedMatrix {
@@ -179,172 +166,15 @@ class CFX_BilinearMatrix : public CPDF_FixedMatrix {
}
};
-std::unique_ptr<CFX_DIBitmap> CFX_DIBSource::SwapXY(
- bool bXFlip,
- bool bYFlip,
- const FX_RECT* pDestClip) const {
- FX_RECT dest_clip(0, 0, m_Height, m_Width);
- if (pDestClip)
- dest_clip.Intersect(*pDestClip);
- if (dest_clip.IsEmpty())
- return nullptr;
-
- auto pTransBitmap = pdfium::MakeUnique<CFX_DIBitmap>();
- int result_height = dest_clip.Height();
- int result_width = dest_clip.Width();
- if (!pTransBitmap->Create(result_width, result_height, GetFormat()))
- return nullptr;
-
- pTransBitmap->SetPalette(m_pPalette.get());
- int dest_pitch = pTransBitmap->GetPitch();
- uint8_t* dest_buf = pTransBitmap->GetBuffer();
- int row_start = bXFlip ? m_Height - dest_clip.right : dest_clip.left;
- int row_end = bXFlip ? m_Height - dest_clip.left : dest_clip.right;
- int col_start = bYFlip ? m_Width - dest_clip.bottom : dest_clip.top;
- int col_end = bYFlip ? m_Width - dest_clip.top : dest_clip.bottom;
- if (GetBPP() == 1) {
- FXSYS_memset(dest_buf, 0xff, dest_pitch * result_height);
- for (int row = row_start; row < row_end; row++) {
- const uint8_t* src_scan = GetScanline(row);
- int dest_col = (bXFlip ? dest_clip.right - (row - row_start) - 1 : row) -
- dest_clip.left;
- uint8_t* dest_scan = dest_buf;
- if (bYFlip) {
- dest_scan += (result_height - 1) * dest_pitch;
- }
- int dest_step = bYFlip ? -dest_pitch : dest_pitch;
- for (int col = col_start; col < col_end; col++) {
- if (!(src_scan[col / 8] & (1 << (7 - col % 8)))) {
- dest_scan[dest_col / 8] &= ~(1 << (7 - dest_col % 8));
- }
- dest_scan += dest_step;
- }
- }
- } else {
- int nBytes = GetBPP() / 8;
- int dest_step = bYFlip ? -dest_pitch : dest_pitch;
- if (nBytes == 3) {
- dest_step -= 2;
- }
- for (int row = row_start; row < row_end; row++) {
- int dest_col = (bXFlip ? dest_clip.right - (row - row_start) - 1 : row) -
- dest_clip.left;
- uint8_t* dest_scan = dest_buf + dest_col * nBytes;
- if (bYFlip) {
- dest_scan += (result_height - 1) * dest_pitch;
- }
- if (nBytes == 4) {
- uint32_t* src_scan = (uint32_t*)GetScanline(row) + col_start;
- for (int col = col_start; col < col_end; col++) {
- *(uint32_t*)dest_scan = *src_scan++;
- dest_scan += dest_step;
- }
- } else {
- const uint8_t* src_scan = GetScanline(row) + col_start * nBytes;
- if (nBytes == 1) {
- for (int col = col_start; col < col_end; col++) {
- *dest_scan = *src_scan++;
- dest_scan += dest_step;
- }
- } else {
- for (int col = col_start; col < col_end; col++) {
- *dest_scan++ = *src_scan++;
- *dest_scan++ = *src_scan++;
- *dest_scan = *src_scan++;
- dest_scan += dest_step;
- }
- }
- }
- }
- }
- if (m_pAlphaMask) {
- dest_pitch = pTransBitmap->m_pAlphaMask->GetPitch();
- dest_buf = pTransBitmap->m_pAlphaMask->GetBuffer();
- int dest_step = bYFlip ? -dest_pitch : dest_pitch;
- for (int row = row_start; row < row_end; row++) {
- int dest_col = (bXFlip ? dest_clip.right - (row - row_start) - 1 : row) -
- dest_clip.left;
- uint8_t* dest_scan = dest_buf + dest_col;
- if (bYFlip) {
- dest_scan += (result_height - 1) * dest_pitch;
- }
- const uint8_t* src_scan = m_pAlphaMask->GetScanline(row) + col_start;
- for (int col = col_start; col < col_end; col++) {
- *dest_scan = *src_scan++;
- dest_scan += dest_step;
- }
- }
- }
- return pTransBitmap;
-}
-
#define FIX16_005 0.05f
-FX_RECT FXDIB_SwapClipBox(FX_RECT& clip,
- int width,
- int height,
- bool bFlipX,
- bool bFlipY) {
- FX_RECT rect;
- if (bFlipY) {
- rect.left = height - clip.top;
- rect.right = height - clip.bottom;
- } else {
- rect.left = clip.top;
- rect.right = clip.bottom;
- }
- if (bFlipX) {
- rect.top = width - clip.left;
- rect.bottom = width - clip.right;
- } else {
- rect.top = clip.left;
- rect.bottom = clip.right;
- }
- rect.Normalize();
- return rect;
-}
-
-std::unique_ptr<CFX_DIBitmap> CFX_DIBSource::TransformTo(
- const CFX_Matrix* pDestMatrix,
- int& result_left,
- int& result_top,
- uint32_t flags,
- const FX_RECT* pDestClip) const {
- CFX_ImageTransformer transformer(this, pDestMatrix, flags, pDestClip);
- transformer.Start();
- transformer.Continue(nullptr);
- result_left = transformer.result().left;
- result_top = transformer.result().top;
- return transformer.DetachBitmap();
-}
-
-std::unique_ptr<CFX_DIBitmap> CFX_DIBSource::StretchTo(
- int dest_width,
- int dest_height,
- uint32_t flags,
- const FX_RECT* pClip) const {
- FX_RECT clip_rect(0, 0, FXSYS_abs(dest_width), FXSYS_abs(dest_height));
- if (pClip)
- clip_rect.Intersect(*pClip);
- if (clip_rect.IsEmpty())
- return nullptr;
-
- if (dest_width == m_Width && dest_height == m_Height)
- return Clone(&clip_rect);
-
- CFX_BitmapStorer storer;
- CFX_ImageStretcher stretcher(&storer, this, dest_width, dest_height,
- clip_rect, flags);
- if (stretcher.Start())
- stretcher.Continue(nullptr);
-
- return storer.Detach();
-}
+} // namespace
-CFX_ImageTransformer::CFX_ImageTransformer(const CFX_DIBSource* pSrc,
- const CFX_Matrix* pMatrix,
- int flags,
- const FX_RECT* pClip)
+CFX_ImageTransformer::CFX_ImageTransformer(
+ const CFX_RetainPtr<CFX_DIBSource>& pSrc,
+ const CFX_Matrix* pMatrix,
+ int flags,
+ const FX_RECT* pClip)
: m_pSrc(pSrc),
m_pMatrix(pMatrix),
m_pClip(pClip),
@@ -364,9 +194,9 @@ bool CFX_ImageTransformer::Start() {
return false;
m_result = result_clip;
- if (FXSYS_fabs(m_pMatrix->a) < FXSYS_fabs(m_pMatrix->b) / 20 &&
- FXSYS_fabs(m_pMatrix->d) < FXSYS_fabs(m_pMatrix->c) / 20 &&
- FXSYS_fabs(m_pMatrix->a) < 0.5f && FXSYS_fabs(m_pMatrix->d) < 0.5f) {
+ if (fabs(m_pMatrix->a) < fabs(m_pMatrix->b) / 20 &&
+ fabs(m_pMatrix->d) < fabs(m_pMatrix->c) / 20 &&
+ fabs(m_pMatrix->a) < 0.5f && fabs(m_pMatrix->d) < 0.5f) {
int dest_width = result_rect.Width();
int dest_height = result_rect.Height();
result_clip.Offset(-result_rect.left, -result_rect.top);
@@ -378,12 +208,11 @@ bool CFX_ImageTransformer::Start() {
m_Status = 1;
return true;
}
- if (FXSYS_fabs(m_pMatrix->b) < FIX16_005 &&
- FXSYS_fabs(m_pMatrix->c) < FIX16_005) {
- int dest_width = m_pMatrix->a > 0 ? (int)FXSYS_ceil(m_pMatrix->a)
- : (int)FXSYS_floor(m_pMatrix->a);
- int dest_height = m_pMatrix->d > 0 ? (int)-FXSYS_ceil(m_pMatrix->d)
- : (int)-FXSYS_floor(m_pMatrix->d);
+ if (fabs(m_pMatrix->b) < FIX16_005 && fabs(m_pMatrix->c) < FIX16_005) {
+ int dest_width =
+ m_pMatrix->a > 0 ? (int)ceil(m_pMatrix->a) : (int)floor(m_pMatrix->a);
+ int dest_height =
+ m_pMatrix->d > 0 ? (int)-ceil(m_pMatrix->d) : (int)-floor(m_pMatrix->d);
result_clip.Offset(-result_rect.left, -result_rect.top);
m_Stretcher = pdfium::MakeUnique<CFX_ImageStretcher>(
&m_Storer, m_pSrc, dest_width, dest_height, result_clip, m_Flags);
@@ -391,10 +220,10 @@ bool CFX_ImageTransformer::Start() {
m_Status = 2;
return true;
}
- int stretch_width = (int)FXSYS_ceil(FXSYS_sqrt2(m_pMatrix->a, m_pMatrix->b));
- int stretch_height = (int)FXSYS_ceil(FXSYS_sqrt2(m_pMatrix->c, m_pMatrix->d));
+ int stretch_width = (int)ceil(FXSYS_sqrt2(m_pMatrix->a, m_pMatrix->b));
+ int stretch_height = (int)ceil(FXSYS_sqrt2(m_pMatrix->c, m_pMatrix->d));
CFX_Matrix stretch2dest(1.0f, 0.0f, 0.0f, -1.0f, 0.0f,
- (FX_FLOAT)(stretch_height));
+ (float)(stretch_height));
stretch2dest.Concat(
CFX_Matrix(m_pMatrix->a / stretch_width, m_pMatrix->b / stretch_width,
m_pMatrix->c / stretch_height, m_pMatrix->d / stretch_height,
@@ -444,7 +273,7 @@ bool CFX_ImageTransformer::Continue(IFX_Pause* pPause) {
stretch_buf_mask = m_Storer.GetBitmap()->m_pAlphaMask->GetBuffer();
int stretch_pitch = m_Storer.GetBitmap()->GetPitch();
- std::unique_ptr<CFX_DIBitmap> pTransformed(new CFX_DIBitmap);
+ auto pTransformed = pdfium::MakeRetain<CFX_DIBitmap>();
FXDIB_Format transformF = GetTransformedFormat(m_Stretcher->source());
if (!pTransformed->Create(m_result.Width(), m_result.Height(), transformF))
return false;
@@ -453,8 +282,8 @@ bool CFX_ImageTransformer::Continue(IFX_Pause* pPause) {
if (pTransformed->m_pAlphaMask)
pTransformed->m_pAlphaMask->Clear(0);
- CFX_Matrix result2stretch(1.0f, 0.0f, 0.0f, 1.0f, (FX_FLOAT)(m_result.left),
- (FX_FLOAT)(m_result.top));
+ CFX_Matrix result2stretch(1.0f, 0.0f, 0.0f, 1.0f, (float)(m_result.left),
+ (float)(m_result.top));
result2stretch.Concat(m_dest2stretch);
result2stretch.Translate(-m_StretchClip.left, -m_StretchClip.top);
if (!stretch_buf_mask && pTransformed->m_pAlphaMask) {
@@ -958,6 +787,6 @@ bool CFX_ImageTransformer::Continue(IFX_Pause* pPause) {
return false;
}
-std::unique_ptr<CFX_DIBitmap> CFX_ImageTransformer::DetachBitmap() {
+CFX_RetainPtr<CFX_DIBitmap> CFX_ImageTransformer::DetachBitmap() {
return m_Storer.Detach();
}
diff --git a/chromium/third_party/pdfium/core/fxge/dib/cfx_imagetransformer.h b/chromium/third_party/pdfium/core/fxge/dib/cfx_imagetransformer.h
new file mode 100644
index 00000000000..52aca9792e4
--- /dev/null
+++ b/chromium/third_party/pdfium/core/fxge/dib/cfx_imagetransformer.h
@@ -0,0 +1,47 @@
+// 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_CFX_IMAGETRANSFORMER_H_
+#define CORE_FXGE_DIB_CFX_IMAGETRANSFORMER_H_
+
+#include <memory>
+
+#include "core/fxcrt/cfx_retain_ptr.h"
+#include "core/fxcrt/fx_coordinates.h"
+#include "core/fxge/dib/cfx_bitmapstorer.h"
+#include "core/fxge/dib/cfx_dibitmap.h"
+#include "core/fxge/dib/cfx_dibsource.h"
+
+class CFX_ImageStretcher;
+
+class CFX_ImageTransformer {
+ public:
+ CFX_ImageTransformer(const CFX_RetainPtr<CFX_DIBSource>& pSrc,
+ const CFX_Matrix* pMatrix,
+ int flags,
+ const FX_RECT* pClip);
+ ~CFX_ImageTransformer();
+
+ bool Start();
+ bool Continue(IFX_Pause* pPause);
+
+ const FX_RECT& result() const { return m_result; }
+ CFX_RetainPtr<CFX_DIBitmap> DetachBitmap();
+
+ private:
+ const CFX_RetainPtr<CFX_DIBSource> m_pSrc;
+ const CFX_Matrix* const m_pMatrix;
+ const FX_RECT* const m_pClip;
+ FX_RECT m_StretchClip;
+ FX_RECT m_result;
+ CFX_Matrix m_dest2stretch;
+ std::unique_ptr<CFX_ImageStretcher> m_Stretcher;
+ CFX_BitmapStorer m_Storer;
+ const uint32_t m_Flags;
+ int m_Status;
+};
+
+#endif // CORE_FXGE_DIB_CFX_IMAGETRANSFORMER_H_
diff --git a/chromium/third_party/pdfium/core/fxge/dib/fx_dib_composite.cpp b/chromium/third_party/pdfium/core/fxge/dib/cfx_scanlinecompositor.cpp
index 072ebbddd59..5c4625020de 100644
--- a/chromium/third_party/pdfium/core/fxge/dib/fx_dib_composite.cpp
+++ b/chromium/third_party/pdfium/core/fxge/dib/cfx_scanlinecompositor.cpp
@@ -1,13 +1,24 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
+// 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
+#include "core/fxge/dib/cfx_scanlinecompositor.h"
+
+#include <algorithm>
+
#include "core/fxcodec/fx_codec.h"
#include "core/fxge/cfx_gemodule.h"
-#include "core/fxge/dib/dib_int.h"
-#include "core/fxge/ge/cfx_cliprgn.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 {
@@ -50,29 +61,21 @@ int Blend(int blend_mode, int back_color, int src_color) {
case FXDIB_BLEND_LIGHTEN:
return src_color > back_color ? src_color : back_color;
case FXDIB_BLEND_COLORDODGE: {
- if (src_color == 255) {
+ if (src_color == 255)
return src_color;
- }
- int result = back_color * 255 / (255 - src_color);
- if (result > 255) {
- return 255;
- }
- return result;
+
+ return std::min(back_color * 255 / (255 - src_color), 255);
}
case FXDIB_BLEND_COLORBURN: {
- if (src_color == 0) {
+ if (src_color == 0)
return src_color;
- }
- int result = (255 - back_color) * 255 / src_color;
- if (result > 255) {
- result = 255;
- }
- return 255 - result;
+
+ return 255 - std::min((255 - back_color) * 255 / src_color, 255);
}
case FXDIB_BLEND_HARDLIGHT:
- if (src_color < 128) {
+ if (src_color < 128)
return (src_color * back_color * 2) / 255;
- }
+
return Blend(FXDIB_BLEND_SCREEN, back_color, 2 * src_color - 255);
case FXDIB_BLEND_SOFTLIGHT: {
if (src_color < 128) {
@@ -105,20 +108,8 @@ int Lum(RGB color) {
RGB ClipColor(RGB color) {
int l = Lum(color);
- int n = color.red;
- if (color.green < n) {
- n = color.green;
- }
- if (color.blue < n) {
- n = color.blue;
- }
- int x = color.red;
- if (color.green > x) {
- x = color.green;
- }
- if (color.blue > x) {
- x = color.blue;
- }
+ int n = std::min(color.red, std::min(color.green, color.blue));
+ int x = std::max(color.red, std::max(color.green, color.blue));
if (n < 0) {
color.red = l + ((color.red - l) * l / (l - n));
color.green = l + ((color.green - l) * l / (l - n));
@@ -141,82 +132,32 @@ RGB SetLum(RGB color, int l) {
}
int Sat(RGB color) {
- int n = color.red;
- if (color.green < n) {
- n = color.green;
- }
- if (color.blue < n) {
- n = color.blue;
- }
- int x = color.red;
- if (color.green > x) {
- x = color.green;
- }
- if (color.blue > x) {
- x = color.blue;
- }
- return x - n;
+ return std::max(color.red, std::max(color.green, color.blue)) -
+ std::min(color.red, std::min(color.green, color.blue));
}
RGB SetSat(RGB color, int s) {
- int* max = &color.red;
- int* mid = &color.red;
- int* min = &color.red;
- if (color.green > *max) {
- max = &color.green;
- }
- if (color.blue > *max) {
- max = &color.blue;
- }
- if (color.green < *min) {
- min = &color.green;
- }
- if (color.blue < *min) {
- min = &color.blue;
- }
- if (*max == *min) {
- color.red = 0;
- color.green = 0;
- color.blue = 0;
- return color;
- }
- if (max == &color.red) {
- if (min == &color.green) {
- mid = &color.blue;
- } else {
- mid = &color.green;
- }
- } else if (max == &color.green) {
- if (min == &color.red) {
- mid = &color.blue;
- } else {
- mid = &color.red;
- }
- } else {
- if (min == &color.green) {
- mid = &color.red;
- } else {
- mid = &color.green;
- }
- }
- if (*max > *min) {
- *mid = (*mid - *min) * s / (*max - *min);
- *max = s;
- *min = 0;
- }
+ int min = std::min(color.red, std::min(color.green, color.blue));
+ int max = std::max(color.red, std::max(color.green, color.blue));
+ if (min == max)
+ return {0, 0, 0};
+
+ color.red = (color.red - min) * s / (max - min);
+ color.green = (color.green - min) * s / (max - min);
+ color.blue = (color.blue - min) * s / (max - min);
return color;
}
void RGB_Blend(int blend_mode,
const uint8_t* src_scan,
- uint8_t* dest_scan,
+ const uint8_t* dest_scan,
int results[3]) {
- RGB src;
- RGB back;
RGB result = {0, 0, 0};
+ RGB src;
src.red = src_scan[2];
src.green = src_scan[1];
src.blue = src_scan[0];
+ RGB back;
back.red = dest_scan[2];
back.green = dest_scan[1];
back.blue = dest_scan[0];
@@ -239,43 +180,25 @@ void RGB_Blend(int blend_mode,
results[2] = result.red;
}
-void CompositeRow_Argb2Mask(uint8_t* dest_scan,
- const uint8_t* src_scan,
- int pixel_count,
- const uint8_t* clip_scan) {
- src_scan += 3;
- for (int col = 0; col < pixel_count; col++) {
- int src_alpha = *src_scan;
- if (clip_scan) {
- src_alpha = clip_scan[col] * src_alpha / 255;
- }
- uint8_t back_alpha = *dest_scan;
- if (!back_alpha) {
- *dest_scan = src_alpha;
- } else if (src_alpha) {
- *dest_scan = back_alpha + src_alpha - back_alpha * src_alpha / 255;
- }
- dest_scan++;
- src_scan += 4;
- }
+int GetAlpha(uint8_t src_alpha, const uint8_t* clip_scan, int col) {
+ return clip_scan ? clip_scan[col] * src_alpha / 255 : src_alpha;
}
-void CompositeRow_Rgba2Mask(uint8_t* dest_scan,
- const uint8_t* src_alpha_scan,
- int pixel_count,
- const uint8_t* clip_scan) {
- for (int col = 0; col < pixel_count; col++) {
- int src_alpha = *src_alpha_scan++;
- if (clip_scan) {
- src_alpha = clip_scan[col] * src_alpha / 255;
- }
+void CompositeRow_AlphaToMask(uint8_t* dest_scan,
+ const uint8_t* src_scan,
+ int pixel_count,
+ const uint8_t* clip_scan,
+ uint8_t stride) {
+ src_scan += stride - 1;
+ for (int col = 0; col < pixel_count; ++col) {
+ int src_alpha = GetAlpha(*src_scan, clip_scan, col);
uint8_t back_alpha = *dest_scan;
- if (!back_alpha) {
+ if (!back_alpha)
*dest_scan = src_alpha;
- } else if (src_alpha) {
+ else if (src_alpha)
*dest_scan = back_alpha + src_alpha - back_alpha * src_alpha / 255;
- }
- dest_scan++;
+ ++dest_scan;
+ src_scan += stride;
}
}
@@ -283,218 +206,76 @@ void CompositeRow_Rgb2Mask(uint8_t* dest_scan,
const uint8_t* src_scan,
int width,
const uint8_t* clip_scan) {
- if (clip_scan) {
- for (int i = 0; i < width; i++) {
- *dest_scan = FXDIB_ALPHA_UNION(*dest_scan, *clip_scan);
- dest_scan++;
- clip_scan++;
- }
- } else {
- FXSYS_memset(dest_scan, 0xff, width);
+ if (!clip_scan) {
+ memset(dest_scan, 0xff, width);
+ return;
+ }
+ for (int i = 0; i < width; ++i) {
+ *dest_scan = FXDIB_ALPHA_UNION(*dest_scan, *clip_scan);
+ ++dest_scan;
+ ++clip_scan;
}
}
+uint8_t GetGray(const uint8_t* src_scan) {
+ return FXRGB2GRAY(src_scan[2], src_scan[1], *src_scan);
+}
+
+uint8_t GetGrayWithBlend(const uint8_t* src_scan,
+ const uint8_t* dest_scan,
+ int blend_type) {
+ uint8_t gray = GetGray(src_scan);
+ if (blend_type >= FXDIB_BLEND_NONSEPARABLE)
+ gray = blend_type == FXDIB_BLEND_LUMINOSITY ? gray : *dest_scan;
+ else if (blend_type)
+ gray = Blend(blend_type, *dest_scan, gray);
+ return gray;
+}
+
void CompositeRow_Argb2Graya(uint8_t* dest_scan,
const uint8_t* src_scan,
int pixel_count,
int blend_type,
const uint8_t* clip_scan,
const uint8_t* src_alpha_scan,
- uint8_t* dst_alpha_scan,
- void* pIccTransform) {
- CCodec_IccModule* pIccModule = nullptr;
- if (pIccTransform)
- pIccModule = CFX_GEModule::Get()->GetCodecModule()->GetIccModule();
-
- if (blend_type) {
- bool bNonseparableBlend = blend_type >= FXDIB_BLEND_NONSEPARABLE;
- if (src_alpha_scan) {
- for (int col = 0; col < pixel_count; col++) {
- uint8_t back_alpha = *dst_alpha_scan;
- if (back_alpha == 0) {
- int src_alpha = *src_alpha_scan++;
- if (clip_scan)
- src_alpha = clip_scan[col] * src_alpha / 255;
-
- if (src_alpha) {
- if (pIccTransform) {
- pIccModule->TranslateScanline(pIccTransform, dest_scan, src_scan,
- 1);
- } else {
- *dest_scan = FXRGB2GRAY(src_scan[2], src_scan[1], *src_scan);
- }
- *dst_alpha_scan = src_alpha;
- }
- dest_scan++;
- dst_alpha_scan++;
- src_scan += 3;
- continue;
- }
- uint8_t src_alpha = *src_alpha_scan++;
- if (clip_scan)
- src_alpha = clip_scan[col] * src_alpha / 255;
-
- if (src_alpha == 0) {
- dest_scan++;
- dst_alpha_scan++;
- src_scan += 3;
- continue;
- }
- *dst_alpha_scan = FXDIB_ALPHA_UNION(back_alpha, src_alpha);
- int alpha_ratio = src_alpha * 255 / (*dst_alpha_scan);
- uint8_t gray;
- if (pIccTransform) {
- pIccModule->TranslateScanline(pIccTransform, &gray, src_scan, 1);
- } else {
- gray = FXRGB2GRAY(src_scan[2], src_scan[1], *src_scan);
- }
- if (bNonseparableBlend)
- gray = blend_type == FXDIB_BLEND_LUMINOSITY ? gray : *dest_scan;
- else
- gray = Blend(blend_type, *dest_scan, gray);
- *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, gray, alpha_ratio);
- dest_scan++;
- dst_alpha_scan++;
- src_scan += 3;
- }
- } else {
- for (int col = 0; col < pixel_count; col++) {
- uint8_t back_alpha = *dst_alpha_scan;
- if (back_alpha == 0) {
- int src_alpha = src_scan[3];
- if (clip_scan)
- src_alpha = clip_scan[col] * src_alpha / 255;
-
- if (src_alpha) {
- if (pIccTransform) {
- pIccModule->TranslateScanline(pIccTransform, dest_scan, src_scan,
- 1);
- } else {
- *dest_scan = FXRGB2GRAY(src_scan[2], src_scan[1], *src_scan);
- }
- *dst_alpha_scan = src_alpha;
- }
- dest_scan++;
- dst_alpha_scan++;
- src_scan += 4;
- continue;
- }
- uint8_t src_alpha = src_scan[3];
- if (clip_scan)
- src_alpha = clip_scan[col] * src_alpha / 255;
-
- if (src_alpha == 0) {
- dest_scan++;
- dst_alpha_scan++;
- src_scan += 4;
- continue;
- }
- *dst_alpha_scan = FXDIB_ALPHA_UNION(back_alpha, src_alpha);
- int alpha_ratio = src_alpha * 255 / (*dst_alpha_scan);
- uint8_t gray;
- if (pIccTransform)
- pIccModule->TranslateScanline(pIccTransform, &gray, src_scan, 1);
- else
- gray = FXRGB2GRAY(src_scan[2], src_scan[1], *src_scan);
-
- *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, gray, alpha_ratio);
- dest_scan++;
- dst_alpha_scan++;
- src_scan += 4;
+ uint8_t* dst_alpha_scan) {
+ uint8_t offset = src_alpha_scan ? 3 : 4;
+ for (int col = 0; col < pixel_count; ++col) {
+ const uint8_t* alpha_scan =
+ src_alpha_scan ? src_alpha_scan++ : &src_scan[3];
+ uint8_t back_alpha = *dst_alpha_scan;
+ if (back_alpha == 0) {
+ int src_alpha = GetAlpha(*alpha_scan, clip_scan, col);
+ if (src_alpha) {
+ *dest_scan = GetGray(src_scan);
+ *dst_alpha_scan = src_alpha;
}
+ ++dest_scan;
+ ++dst_alpha_scan;
+ src_scan += offset;
+ continue;
}
- return;
- }
- if (src_alpha_scan) {
- for (int col = 0; col < pixel_count; col++) {
- uint8_t back_alpha = *dst_alpha_scan;
- if (back_alpha == 0) {
- int src_alpha = *src_alpha_scan++;
- if (clip_scan)
- src_alpha = clip_scan[col] * src_alpha / 255;
-
- if (src_alpha) {
- if (pIccTransform) {
- pIccModule->TranslateScanline(pIccTransform, dest_scan, src_scan,
- 1);
- } else {
- *dest_scan = FXRGB2GRAY(src_scan[2], src_scan[1], *src_scan);
- }
- *dst_alpha_scan = src_alpha;
- }
- dest_scan++;
- dst_alpha_scan++;
- src_scan += 3;
- continue;
- }
- uint8_t src_alpha = *src_alpha_scan++;
- if (clip_scan)
- src_alpha = clip_scan[col] * src_alpha / 255;
-
- if (src_alpha == 0) {
- dest_scan++;
- dst_alpha_scan++;
- src_scan += 3;
- continue;
- }
- *dst_alpha_scan = FXDIB_ALPHA_UNION(back_alpha, src_alpha);
- int alpha_ratio = src_alpha * 255 / (*dst_alpha_scan);
- uint8_t gray;
- if (pIccTransform)
- pIccModule->TranslateScanline(pIccTransform, &gray, src_scan, 1);
- else
- gray = FXRGB2GRAY(src_scan[2], src_scan[1], *src_scan);
-
- *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, gray, alpha_ratio);
- dest_scan++;
- dst_alpha_scan++;
- src_scan += 3;
+ uint8_t src_alpha = GetAlpha(*alpha_scan, clip_scan, col);
+ if (src_alpha == 0) {
+ ++dest_scan;
+ ++dst_alpha_scan;
+ src_scan += offset;
+ continue;
}
- } else {
- for (int col = 0; col < pixel_count; col++) {
- uint8_t back_alpha = *dst_alpha_scan;
- if (back_alpha == 0) {
- int src_alpha = src_scan[3];
- if (clip_scan)
- src_alpha = clip_scan[col] * src_alpha / 255;
-
- if (src_alpha) {
- if (pIccTransform) {
- pIccModule->TranslateScanline(pIccTransform, dest_scan, src_scan,
- 1);
- } else {
- *dest_scan = FXRGB2GRAY(src_scan[2], src_scan[1], *src_scan);
- }
- *dst_alpha_scan = src_alpha;
- }
- dest_scan++;
- dst_alpha_scan++;
- src_scan += 4;
- continue;
- }
- uint8_t src_alpha = src_scan[3];
- if (clip_scan)
- src_alpha = clip_scan[col] * src_alpha / 255;
-
- if (src_alpha == 0) {
- dest_scan++;
- dst_alpha_scan++;
- src_scan += 4;
- continue;
- }
- *dst_alpha_scan = FXDIB_ALPHA_UNION(back_alpha, src_alpha);
- int alpha_ratio = src_alpha * 255 / (*dst_alpha_scan);
- uint8_t gray;
- if (pIccTransform)
- pIccModule->TranslateScanline(pIccTransform, &gray, src_scan, 1);
+ *dst_alpha_scan = FXDIB_ALPHA_UNION(back_alpha, src_alpha);
+ int alpha_ratio = src_alpha * 255 / (*dst_alpha_scan);
+ uint8_t gray = GetGray(src_scan);
+ // TODO(npm): Does this if really need src_alpha_scan or was that a bug?
+ if (blend_type && src_alpha_scan) {
+ if (blend_type >= FXDIB_BLEND_NONSEPARABLE)
+ gray = blend_type == FXDIB_BLEND_LUMINOSITY ? gray : *dest_scan;
else
- gray = FXRGB2GRAY(src_scan[2], src_scan[1], *src_scan);
-
- *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, gray, alpha_ratio);
- dest_scan++;
- dst_alpha_scan++;
- src_scan += 4;
+ gray = Blend(blend_type, *dest_scan, gray);
}
+ *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, gray, alpha_ratio);
+ ++dest_scan;
+ ++dst_alpha_scan;
+ src_scan += offset;
}
}
@@ -503,94 +284,19 @@ void CompositeRow_Argb2Gray(uint8_t* dest_scan,
int pixel_count,
int blend_type,
const uint8_t* clip_scan,
- const uint8_t* src_alpha_scan,
- void* pIccTransform) {
- CCodec_IccModule* pIccModule = nullptr;
+ const uint8_t* src_alpha_scan) {
uint8_t gray;
- if (pIccTransform)
- pIccModule = CFX_GEModule::Get()->GetCodecModule()->GetIccModule();
-
- if (blend_type) {
- bool bNonseparableBlend = blend_type >= FXDIB_BLEND_NONSEPARABLE;
- if (src_alpha_scan) {
- for (int col = 0; col < pixel_count; col++) {
- int src_alpha = *src_alpha_scan++;
- if (clip_scan)
- src_alpha = clip_scan[col] * src_alpha / 255;
-
- if (src_alpha) {
- if (pIccTransform)
- pIccModule->TranslateScanline(pIccTransform, &gray, src_scan, 1);
- else
- gray = FXRGB2GRAY(src_scan[2], src_scan[1], *src_scan);
-
- if (bNonseparableBlend)
- gray = blend_type == FXDIB_BLEND_LUMINOSITY ? gray : *dest_scan;
- else
- gray = Blend(blend_type, *dest_scan, gray);
- *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, gray, src_alpha);
- }
- dest_scan++;
- src_scan += 3;
- }
- } else {
- for (int col = 0; col < pixel_count; col++) {
- int src_alpha = src_scan[3];
- if (clip_scan)
- src_alpha = clip_scan[col] * src_alpha / 255;
-
- if (src_alpha) {
- if (pIccTransform)
- pIccModule->TranslateScanline(pIccTransform, &gray, src_scan, 1);
- else
- gray = FXRGB2GRAY(src_scan[2], src_scan[1], *src_scan);
-
- if (bNonseparableBlend)
- gray = blend_type == FXDIB_BLEND_LUMINOSITY ? gray : *dest_scan;
- else
- gray = Blend(blend_type, *dest_scan, gray);
- *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, gray, src_alpha);
- }
- dest_scan++;
- src_scan += 4;
- }
- }
- return;
- }
- if (src_alpha_scan) {
- for (int col = 0; col < pixel_count; col++) {
- int src_alpha = *src_alpha_scan++;
- if (clip_scan)
- src_alpha = clip_scan[col] * src_alpha / 255;
-
- if (src_alpha) {
- if (pIccTransform)
- pIccModule->TranslateScanline(pIccTransform, &gray, src_scan, 1);
- else
- gray = FXRGB2GRAY(src_scan[2], src_scan[1], *src_scan);
-
- *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, gray, src_alpha);
- }
- dest_scan++;
- src_scan += 3;
- }
- } else {
- for (int col = 0; col < pixel_count; col++) {
- int src_alpha = src_scan[3];
- if (clip_scan)
- src_alpha = clip_scan[col] * src_alpha / 255;
-
- if (src_alpha) {
- if (pIccTransform)
- pIccModule->TranslateScanline(pIccTransform, &gray, src_scan, 1);
- else
- gray = FXRGB2GRAY(src_scan[2], src_scan[1], *src_scan);
-
- *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, gray, src_alpha);
- }
- dest_scan++;
- src_scan += 4;
+ uint8_t offset = src_alpha_scan ? 3 : 4;
+ for (int col = 0; col < pixel_count; ++col) {
+ const uint8_t* alpha_scan =
+ src_alpha_scan ? src_alpha_scan++ : &src_scan[3];
+ int src_alpha = GetAlpha(*alpha_scan, clip_scan, col);
+ if (src_alpha) {
+ gray = GetGrayWithBlend(src_scan, dest_scan, blend_type);
+ *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, gray, src_alpha);
}
+ ++dest_scan;
+ src_scan += offset;
}
}
@@ -599,47 +305,15 @@ void CompositeRow_Rgb2Gray(uint8_t* dest_scan,
int src_Bpp,
int pixel_count,
int blend_type,
- const uint8_t* clip_scan,
- void* pIccTransform) {
- CCodec_IccModule* pIccModule = nullptr;
+ const uint8_t* clip_scan) {
uint8_t gray;
- if (pIccTransform) {
- pIccModule = CFX_GEModule::Get()->GetCodecModule()->GetIccModule();
- }
- if (blend_type) {
- bool bNonseparableBlend = blend_type >= FXDIB_BLEND_NONSEPARABLE;
- for (int col = 0; col < pixel_count; col++) {
- if (pIccTransform) {
- pIccModule->TranslateScanline(pIccTransform, &gray, src_scan, 1);
- } else {
- gray = FXRGB2GRAY(src_scan[2], src_scan[1], *src_scan);
- }
- if (bNonseparableBlend)
- gray = blend_type == FXDIB_BLEND_LUMINOSITY ? gray : *dest_scan;
- else
- gray = Blend(blend_type, *dest_scan, gray);
- if (clip_scan && clip_scan[col] < 255) {
- *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, gray, clip_scan[col]);
- } else {
- *dest_scan = gray;
- }
- dest_scan++;
- src_scan += src_Bpp;
- }
- return;
- }
- for (int col = 0; col < pixel_count; col++) {
- if (pIccTransform) {
- pIccModule->TranslateScanline(pIccTransform, &gray, src_scan, 1);
- } else {
- gray = FXRGB2GRAY(src_scan[2], src_scan[1], *src_scan);
- }
- if (clip_scan && clip_scan[col] < 255) {
+ for (int col = 0; col < pixel_count; ++col) {
+ gray = GetGrayWithBlend(src_scan, dest_scan, blend_type);
+ if (clip_scan && clip_scan[col] < 255)
*dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, gray, clip_scan[col]);
- } else {
+ else
*dest_scan = gray;
- }
- dest_scan++;
+ ++dest_scan;
src_scan += src_Bpp;
}
}
@@ -650,91 +324,38 @@ void CompositeRow_Rgb2Graya(uint8_t* dest_scan,
int pixel_count,
int blend_type,
const uint8_t* clip_scan,
- uint8_t* dest_alpha_scan,
- void* pIccTransform) {
- CCodec_IccModule* pIccModule = nullptr;
- if (pIccTransform) {
- pIccModule = CFX_GEModule::Get()->GetCodecModule()->GetIccModule();
- }
- if (blend_type) {
- bool bNonseparableBlend = blend_type >= FXDIB_BLEND_NONSEPARABLE;
- for (int col = 0; col < pixel_count; col++) {
- int back_alpha = *dest_alpha_scan;
- if (back_alpha == 0) {
- if (pIccTransform) {
- pIccModule->TranslateScanline(pIccTransform, dest_scan, src_scan, 1);
- } else {
- *dest_scan = FXRGB2GRAY(src_scan[2], src_scan[1], *src_scan);
- }
- dest_scan++;
- dest_alpha_scan++;
- src_scan += src_Bpp;
- continue;
- }
- int src_alpha = 255;
- if (clip_scan) {
- src_alpha = clip_scan[col];
- }
- if (src_alpha == 0) {
- dest_scan++;
- dest_alpha_scan++;
- src_scan += src_Bpp;
- continue;
- }
- uint8_t dest_alpha =
- back_alpha + src_alpha - back_alpha * src_alpha / 255;
- *dest_alpha_scan++ = dest_alpha;
- int alpha_ratio = src_alpha * 255 / dest_alpha;
- uint8_t gray;
- if (pIccTransform) {
- pIccModule->TranslateScanline(pIccTransform, &gray, src_scan, 1);
- } else {
- gray = FXRGB2GRAY(src_scan[2], src_scan[1], *src_scan);
- }
- if (bNonseparableBlend)
- gray = blend_type == FXDIB_BLEND_LUMINOSITY ? gray : *dest_scan;
- else
- gray = Blend(blend_type, *dest_scan, gray);
- *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, gray, alpha_ratio);
- dest_scan++;
+ uint8_t* dest_alpha_scan) {
+ for (int col = 0; col < pixel_count; ++col) {
+ if (blend_type && *dest_alpha_scan == 0) {
+ *dest_scan = GetGray(src_scan);
+ ++dest_scan;
+ ++dest_alpha_scan;
src_scan += src_Bpp;
+ continue;
}
- return;
- }
- for (int col = 0; col < pixel_count; col++) {
- int src_alpha = 255;
- if (clip_scan) {
- src_alpha = clip_scan[col];
- }
+ int src_alpha = clip_scan ? clip_scan[col] : 255;
if (src_alpha == 255) {
- if (pIccTransform) {
- pIccModule->TranslateScanline(pIccTransform, dest_scan, src_scan, 1);
- } else {
- *dest_scan = FXRGB2GRAY(src_scan[2], src_scan[1], *src_scan);
- }
- dest_scan++;
- *dest_alpha_scan++ = 255;
+ *dest_scan = GetGrayWithBlend(src_scan, dest_scan, blend_type);
+ ++dest_scan;
+ *dest_alpha_scan = 255;
+ ++dest_alpha_scan;
src_scan += src_Bpp;
continue;
}
if (src_alpha == 0) {
- dest_scan++;
- dest_alpha_scan++;
+ ++dest_scan;
+ ++dest_alpha_scan;
src_scan += src_Bpp;
continue;
}
int back_alpha = *dest_alpha_scan;
uint8_t dest_alpha = back_alpha + src_alpha - back_alpha * src_alpha / 255;
- *dest_alpha_scan++ = dest_alpha;
+ *dest_alpha_scan = dest_alpha;
+ ++dest_alpha_scan;
int alpha_ratio = src_alpha * 255 / dest_alpha;
- uint8_t gray;
- if (pIccTransform) {
- pIccModule->TranslateScanline(pIccTransform, &gray, src_scan, 1);
- } else {
- gray = FXRGB2GRAY(src_scan[2], src_scan[1], *src_scan);
- }
+ uint8_t gray = GetGrayWithBlend(src_scan, dest_scan, blend_type);
*dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, gray, alpha_ratio);
- dest_scan++;
+ ++dest_scan;
src_scan += src_Bpp;
}
}
@@ -747,219 +368,76 @@ void CompositeRow_Argb2Argb(uint8_t* dest_scan,
uint8_t* dest_alpha_scan,
const uint8_t* src_alpha_scan) {
int blended_colors[3];
+ uint8_t dest_offset = dest_alpha_scan ? 3 : 4;
+ uint8_t src_offset = src_alpha_scan ? 3 : 4;
bool bNonseparableBlend = blend_type >= FXDIB_BLEND_NONSEPARABLE;
- if (!dest_alpha_scan) {
- if (!src_alpha_scan) {
- uint8_t back_alpha = 0;
- for (int col = 0; col < pixel_count; col++) {
- back_alpha = dest_scan[3];
- if (back_alpha == 0) {
- if (clip_scan) {
- int src_alpha = clip_scan[col] * src_scan[3] / 255;
- FXARGB_SETDIB(dest_scan, (FXARGB_GETDIB(src_scan) & 0xffffff) |
- (src_alpha << 24));
- } else {
- FXARGB_COPY(dest_scan, src_scan);
- }
- dest_scan += 4;
- src_scan += 4;
- continue;
- }
- uint8_t src_alpha;
+ bool has_src = !!src_alpha_scan;
+ bool has_dest = !!dest_alpha_scan;
+ for (int col = 0; col < pixel_count; ++col) {
+ uint8_t back_alpha = has_dest ? *dest_alpha_scan : dest_scan[3];
+ const uint8_t* alpha_source = has_src ? src_alpha_scan++ : &src_scan[3];
+ uint8_t src_alpha = GetAlpha(*alpha_source, clip_scan, col);
+ if (back_alpha == 0) {
+ if (!has_dest && !has_src) {
if (clip_scan) {
- src_alpha = clip_scan[col] * src_scan[3] / 255;
+ FXARGB_SETDIB(dest_scan, (FXARGB_GETDIB(src_scan) & 0xffffff) |
+ (src_alpha << 24));
} else {
- src_alpha = src_scan[3];
- }
- if (src_alpha == 0) {
- dest_scan += 4;
- src_scan += 4;
- continue;
+ FXARGB_COPY(dest_scan, src_scan);
}
- uint8_t dest_alpha =
- back_alpha + src_alpha - back_alpha * src_alpha / 255;
- dest_scan[3] = dest_alpha;
- int alpha_ratio = src_alpha * 255 / dest_alpha;
- if (bNonseparableBlend) {
- RGB_Blend(blend_type, src_scan, dest_scan, blended_colors);
+ } else if (has_dest) {
+ *dest_alpha_scan = src_alpha;
+ for (int i = 0; i < 3; ++i) {
+ *dest_scan = *src_scan++;
+ ++dest_scan;
}
- for (int color = 0; color < 3; color++) {
- if (blend_type) {
- int blended = bNonseparableBlend
- ? blended_colors[color]
- : Blend(blend_type, *dest_scan, *src_scan);
- blended = FXDIB_ALPHA_MERGE(*src_scan, blended, back_alpha);
- *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, blended, alpha_ratio);
- } else {
- *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, *src_scan, alpha_ratio);
- }
- dest_scan++;
- src_scan++;
- }
- dest_scan++;
- src_scan++;
+ ++dest_alpha_scan;
+ if (!has_src)
+ ++src_scan;
+ } else {
+ FXARGB_SETDIB(dest_scan, FXARGB_MAKE((src_alpha << 24), src_scan[2],
+ src_scan[1], *src_scan));
}
- } else {
- for (int col = 0; col < pixel_count; col++) {
- uint8_t back_alpha = dest_scan[3];
- if (back_alpha == 0) {
- if (clip_scan) {
- int src_alpha = clip_scan[col] * (*src_alpha_scan) / 255;
- FXARGB_SETDIB(dest_scan, FXARGB_MAKE((src_alpha << 24), src_scan[2],
- src_scan[1], *src_scan));
- } else {
- FXARGB_SETDIB(dest_scan,
- FXARGB_MAKE((*src_alpha_scan << 24), src_scan[2],
- src_scan[1], *src_scan));
- }
- dest_scan += 4;
- src_scan += 3;
- src_alpha_scan++;
- continue;
- }
- uint8_t src_alpha;
- if (clip_scan) {
- src_alpha = clip_scan[col] * (*src_alpha_scan++) / 255;
- } else {
- src_alpha = *src_alpha_scan++;
- }
- if (src_alpha == 0) {
- dest_scan += 4;
- src_scan += 3;
- continue;
- }
- uint8_t dest_alpha =
- back_alpha + src_alpha - back_alpha * src_alpha / 255;
- dest_scan[3] = dest_alpha;
- int alpha_ratio = src_alpha * 255 / dest_alpha;
- if (bNonseparableBlend) {
- RGB_Blend(blend_type, src_scan, dest_scan, blended_colors);
- }
- for (int color = 0; color < 3; color++) {
- if (blend_type) {
- int blended = bNonseparableBlend
- ? blended_colors[color]
- : Blend(blend_type, *dest_scan, *src_scan);
- blended = FXDIB_ALPHA_MERGE(*src_scan, blended, back_alpha);
- *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, blended, alpha_ratio);
- } else {
- *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, *src_scan, alpha_ratio);
- }
- dest_scan++;
- src_scan++;
- }
- dest_scan++;
+ if (!has_dest) {
+ dest_scan += dest_offset;
+ src_scan += src_offset;
}
+ continue;
}
- } else {
- if (src_alpha_scan) {
- for (int col = 0; col < pixel_count; col++) {
- uint8_t back_alpha = *dest_alpha_scan;
- if (back_alpha == 0) {
- if (clip_scan) {
- int src_alpha = clip_scan[col] * (*src_alpha_scan) / 255;
- *dest_alpha_scan = src_alpha;
- *dest_scan++ = *src_scan++;
- *dest_scan++ = *src_scan++;
- *dest_scan++ = *src_scan++;
- } else {
- *dest_alpha_scan = *src_alpha_scan;
- *dest_scan++ = *src_scan++;
- *dest_scan++ = *src_scan++;
- *dest_scan++ = *src_scan++;
- }
- dest_alpha_scan++;
- src_alpha_scan++;
- continue;
- }
- uint8_t src_alpha;
- if (clip_scan) {
- src_alpha = clip_scan[col] * (*src_alpha_scan++) / 255;
- } else {
- src_alpha = *src_alpha_scan++;
- }
- if (src_alpha == 0) {
- dest_scan += 3;
- src_scan += 3;
- dest_alpha_scan++;
- continue;
- }
- uint8_t dest_alpha =
- back_alpha + src_alpha - back_alpha * src_alpha / 255;
- *dest_alpha_scan++ = dest_alpha;
- int alpha_ratio = src_alpha * 255 / dest_alpha;
- if (bNonseparableBlend) {
- RGB_Blend(blend_type, src_scan, dest_scan, blended_colors);
- }
- for (int color = 0; color < 3; color++) {
- if (blend_type) {
- int blended = bNonseparableBlend
- ? blended_colors[color]
- : Blend(blend_type, *dest_scan, *src_scan);
- blended = FXDIB_ALPHA_MERGE(*src_scan, blended, back_alpha);
- *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, blended, alpha_ratio);
- } else {
- *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, *src_scan, alpha_ratio);
- }
- dest_scan++;
- src_scan++;
- }
- }
+ if (src_alpha == 0) {
+ dest_scan += dest_offset;
+ src_scan += src_offset;
+ if (has_dest)
+ ++dest_alpha_scan;
+ continue;
+ }
+ uint8_t dest_alpha = back_alpha + src_alpha - back_alpha * src_alpha / 255;
+ if (has_dest) {
+ *dest_alpha_scan = dest_alpha;
+ ++dest_alpha_scan;
} else {
- for (int col = 0; col < pixel_count; col++) {
- uint8_t back_alpha = *dest_alpha_scan;
- if (back_alpha == 0) {
- if (clip_scan) {
- int src_alpha = clip_scan[col] * src_scan[3] / 255;
- *dest_alpha_scan = src_alpha;
- *dest_scan++ = *src_scan++;
- *dest_scan++ = *src_scan++;
- *dest_scan++ = *src_scan++;
- } else {
- *dest_alpha_scan = src_scan[3];
- *dest_scan++ = *src_scan++;
- *dest_scan++ = *src_scan++;
- *dest_scan++ = *src_scan++;
- }
- dest_alpha_scan++;
- src_scan++;
- continue;
- }
- uint8_t src_alpha;
- if (clip_scan) {
- src_alpha = clip_scan[col] * src_scan[3] / 255;
- } else {
- src_alpha = src_scan[3];
- }
- if (src_alpha == 0) {
- dest_scan += 3;
- src_scan += 4;
- dest_alpha_scan++;
- continue;
- }
- uint8_t dest_alpha =
- back_alpha + src_alpha - back_alpha * src_alpha / 255;
- *dest_alpha_scan++ = dest_alpha;
- int alpha_ratio = src_alpha * 255 / dest_alpha;
- if (bNonseparableBlend) {
- RGB_Blend(blend_type, src_scan, dest_scan, blended_colors);
- }
- for (int color = 0; color < 3; color++) {
- if (blend_type) {
- int blended = bNonseparableBlend
- ? blended_colors[color]
- : Blend(blend_type, *dest_scan, *src_scan);
- blended = FXDIB_ALPHA_MERGE(*src_scan, blended, back_alpha);
- *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, blended, alpha_ratio);
- } else {
- *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, *src_scan, alpha_ratio);
- }
- dest_scan++;
- src_scan++;
- }
- src_scan++;
+ dest_scan[3] = dest_alpha;
+ }
+ int alpha_ratio = src_alpha * 255 / dest_alpha;
+ if (bNonseparableBlend)
+ RGB_Blend(blend_type, src_scan, dest_scan, blended_colors);
+ for (int color = 0; color < 3; ++color) {
+ if (blend_type) {
+ int blended = bNonseparableBlend
+ ? blended_colors[color]
+ : Blend(blend_type, *dest_scan, *src_scan);
+ blended = FXDIB_ALPHA_MERGE(*src_scan, blended, back_alpha);
+ *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, blended, alpha_ratio);
+ } else {
+ *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, *src_scan, alpha_ratio);
}
+ ++dest_scan;
+ ++src_scan;
}
+ if (!has_dest)
+ ++dest_scan;
+ if (!has_src)
+ ++src_scan;
}
}
@@ -972,36 +450,18 @@ void CompositeRow_Rgb2Argb_Blend_NoClip(uint8_t* dest_scan,
int blended_colors[3];
bool bNonseparableBlend = blend_type >= FXDIB_BLEND_NONSEPARABLE;
int src_gap = src_Bpp - 3;
- if (dest_alpha_scan) {
- for (int col = 0; col < width; col++) {
- uint8_t back_alpha = *dest_alpha_scan;
- if (back_alpha == 0) {
- *dest_scan++ = *src_scan++;
- *dest_scan++ = *src_scan++;
- *dest_scan++ = *src_scan++;
- *dest_alpha_scan++ = 0xff;
- src_scan += src_gap;
- continue;
- }
- *dest_alpha_scan++ = 0xff;
- if (bNonseparableBlend) {
- RGB_Blend(blend_type, src_scan, dest_scan, blended_colors);
- }
- for (int color = 0; color < 3; color++) {
- int src_color = *src_scan;
- int blended = bNonseparableBlend
- ? blended_colors[color]
- : Blend(blend_type, *dest_scan, src_color);
- *dest_scan = FXDIB_ALPHA_MERGE(src_color, blended, back_alpha);
- dest_scan++;
- src_scan++;
- }
- src_scan += src_gap;
- }
- } else {
- for (int col = 0; col < width; col++) {
- uint8_t back_alpha = dest_scan[3];
- if (back_alpha == 0) {
+ for (int col = 0; col < width; ++col) {
+ uint8_t* dest_alpha = dest_alpha_scan ? dest_alpha_scan : &dest_scan[3];
+ uint8_t back_alpha = *dest_alpha;
+ if (back_alpha == 0) {
+ if (dest_alpha_scan) {
+ for (int i = 0; i < 3; ++i) {
+ *dest_scan = *src_scan++;
+ ++dest_scan;
+ }
+ *dest_alpha_scan = 0xff;
+ ++dest_alpha_scan;
+ } else {
if (src_Bpp == 4) {
FXARGB_SETDIB(dest_scan, 0xff000000 | FXARGB_GETDIB(src_scan));
} else {
@@ -1009,25 +469,27 @@ void CompositeRow_Rgb2Argb_Blend_NoClip(uint8_t* dest_scan,
src_scan[0]));
}
dest_scan += 4;
- src_scan += src_Bpp;
- continue;
- }
- dest_scan[3] = 0xff;
- if (bNonseparableBlend) {
- RGB_Blend(blend_type, src_scan, dest_scan, blended_colors);
- }
- for (int color = 0; color < 3; color++) {
- int src_color = *src_scan;
- int blended = bNonseparableBlend
- ? blended_colors[color]
- : Blend(blend_type, *dest_scan, src_color);
- *dest_scan = FXDIB_ALPHA_MERGE(src_color, blended, back_alpha);
- dest_scan++;
- src_scan++;
}
- dest_scan++;
- src_scan += src_gap;
+ src_scan += src_Bpp;
+ continue;
}
+ *dest_alpha = 0xff;
+ if (bNonseparableBlend)
+ RGB_Blend(blend_type, src_scan, dest_scan, blended_colors);
+ for (int color = 0; color < 3; ++color) {
+ int src_color = *src_scan;
+ int blended = bNonseparableBlend
+ ? blended_colors[color]
+ : Blend(blend_type, *dest_scan, src_color);
+ *dest_scan = FXDIB_ALPHA_MERGE(src_color, blended, back_alpha);
+ ++dest_scan;
+ ++src_scan;
+ }
+ if (dest_alpha_scan)
+ ++dest_alpha_scan;
+ else
+ ++dest_scan;
+ src_scan += src_gap;
}
}
@@ -1041,80 +503,50 @@ void CompositeRow_Rgb2Argb_Blend_Clip(uint8_t* dest_scan,
int blended_colors[3];
bool bNonseparableBlend = blend_type >= FXDIB_BLEND_NONSEPARABLE;
int src_gap = src_Bpp - 3;
- if (dest_alpha_scan) {
- for (int col = 0; col < width; col++) {
- int src_alpha = *clip_scan++;
- uint8_t back_alpha = *dest_alpha_scan;
- if (back_alpha == 0) {
- *dest_scan++ = *src_scan++;
- *dest_scan++ = *src_scan++;
- *dest_scan++ = *src_scan++;
- src_scan += src_gap;
- dest_alpha_scan++;
- continue;
+ bool has_dest = !!dest_alpha_scan;
+ for (int col = 0; col < width; ++col) {
+ int src_alpha = *clip_scan++;
+ uint8_t back_alpha = has_dest ? *dest_alpha_scan : dest_scan[3];
+ if (back_alpha == 0) {
+ for (int i = 0; i < 3; ++i) {
+ *dest_scan = *src_scan++;
+ ++dest_scan;
}
- if (src_alpha == 0) {
- dest_scan += 3;
+ src_scan += src_gap;
+ if (has_dest)
dest_alpha_scan++;
- src_scan += src_Bpp;
- continue;
- }
- uint8_t dest_alpha =
- back_alpha + src_alpha - back_alpha * src_alpha / 255;
- *dest_alpha_scan++ = dest_alpha;
- int alpha_ratio = src_alpha * 255 / dest_alpha;
- if (bNonseparableBlend) {
- RGB_Blend(blend_type, src_scan, dest_scan, blended_colors);
- }
- for (int color = 0; color < 3; color++) {
- int src_color = *src_scan;
- int blended = bNonseparableBlend
- ? blended_colors[color]
- : Blend(blend_type, *dest_scan, src_color);
- blended = FXDIB_ALPHA_MERGE(src_color, blended, back_alpha);
- *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, blended, alpha_ratio);
+ else
dest_scan++;
- src_scan++;
- }
- src_scan += src_gap;
+ continue;
}
- } else {
- for (int col = 0; col < width; col++) {
- int src_alpha = *clip_scan++;
- uint8_t back_alpha = dest_scan[3];
- if (back_alpha == 0) {
- *dest_scan++ = *src_scan++;
- *dest_scan++ = *src_scan++;
- *dest_scan++ = *src_scan++;
- src_scan += src_gap;
- dest_scan++;
- continue;
- }
- if (src_alpha == 0) {
- dest_scan += 4;
- src_scan += src_Bpp;
- continue;
- }
- uint8_t dest_alpha =
- back_alpha + src_alpha - back_alpha * src_alpha / 255;
+ if (src_alpha == 0) {
+ dest_scan += has_dest ? 3 : 4;
+ if (has_dest)
+ dest_alpha_scan++;
+ src_scan += src_Bpp;
+ continue;
+ }
+ uint8_t dest_alpha = back_alpha + src_alpha - back_alpha * src_alpha / 255;
+ if (has_dest)
+ *dest_alpha_scan++ = dest_alpha;
+ else
dest_scan[3] = dest_alpha;
- int alpha_ratio = src_alpha * 255 / dest_alpha;
- if (bNonseparableBlend) {
- RGB_Blend(blend_type, src_scan, dest_scan, blended_colors);
- }
- for (int color = 0; color < 3; color++) {
- int src_color = *src_scan;
- int blended = bNonseparableBlend
- ? blended_colors[color]
- : Blend(blend_type, *dest_scan, src_color);
- blended = FXDIB_ALPHA_MERGE(src_color, blended, back_alpha);
- *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, blended, alpha_ratio);
- dest_scan++;
- src_scan++;
- }
+ int alpha_ratio = src_alpha * 255 / dest_alpha;
+ if (bNonseparableBlend)
+ RGB_Blend(blend_type, src_scan, dest_scan, blended_colors);
+ for (int color = 0; color < 3; color++) {
+ int src_color = *src_scan;
+ int blended = bNonseparableBlend
+ ? blended_colors[color]
+ : Blend(blend_type, *dest_scan, src_color);
+ blended = FXDIB_ALPHA_MERGE(src_color, blended, back_alpha);
+ *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, blended, alpha_ratio);
dest_scan++;
- src_scan += src_gap;
+ src_scan++;
}
+ src_scan += src_gap;
+ if (!has_dest)
+ dest_scan++;
}
}
@@ -1419,7 +851,7 @@ void CompositeRow_Rgb2Rgb_NoBlend_NoClip(uint8_t* dest_scan,
int dest_Bpp,
int src_Bpp) {
if (dest_Bpp == src_Bpp) {
- FXSYS_memcpy(dest_scan, src_scan, width * dest_Bpp);
+ memcpy(dest_scan, src_scan, width * dest_Bpp);
return;
}
for (int col = 0; col < width; col++) {
@@ -1460,404 +892,6 @@ void CompositeRow_Rgb2Rgb_NoBlend_Clip(uint8_t* dest_scan,
}
}
-void CompositeRow_Argb2Argb_Transform(uint8_t* dest_scan,
- const uint8_t* src_scan,
- int pixel_count,
- int blend_type,
- const uint8_t* clip_scan,
- uint8_t* dest_alpha_scan,
- const uint8_t* src_alpha_scan,
- uint8_t* src_cache_scan,
- void* pIccTransform) {
- uint8_t* dp = src_cache_scan;
- CCodec_IccModule* pIccModule =
- CFX_GEModule::Get()->GetCodecModule()->GetIccModule();
- if (src_alpha_scan) {
- if (dest_alpha_scan) {
- pIccModule->TranslateScanline(pIccTransform, dp, src_scan, pixel_count);
- } else {
- for (int col = 0; col < pixel_count; col++) {
- pIccModule->TranslateScanline(pIccTransform, dp, src_scan, 1);
- dp[3] = *src_alpha_scan++;
- src_scan += 3;
- dp += 4;
- }
- src_alpha_scan = nullptr;
- }
- } else {
- if (dest_alpha_scan) {
- int blended_colors[3];
- bool bNonseparableBlend = blend_type >= FXDIB_BLEND_NONSEPARABLE;
- for (int col = 0; col < pixel_count; col++) {
- pIccModule->TranslateScanline(pIccTransform, src_cache_scan, src_scan,
- 1);
- uint8_t back_alpha = *dest_alpha_scan;
- if (back_alpha == 0) {
- if (clip_scan) {
- int src_alpha = clip_scan[col] * src_scan[3] / 255;
- *dest_alpha_scan = src_alpha;
- *dest_scan++ = *src_cache_scan++;
- *dest_scan++ = *src_cache_scan++;
- *dest_scan++ = *src_cache_scan++;
- } else {
- *dest_alpha_scan = src_scan[3];
- *dest_scan++ = *src_cache_scan++;
- *dest_scan++ = *src_cache_scan++;
- *dest_scan++ = *src_cache_scan++;
- }
- dest_alpha_scan++;
- src_scan += 4;
- continue;
- }
- uint8_t src_alpha;
- if (clip_scan) {
- src_alpha = clip_scan[col] * src_scan[3] / 255;
- } else {
- src_alpha = src_scan[3];
- }
- src_scan += 4;
- if (src_alpha == 0) {
- dest_scan += 3;
- src_cache_scan += 3;
- dest_alpha_scan++;
- continue;
- }
- uint8_t dest_alpha =
- back_alpha + src_alpha - back_alpha * src_alpha / 255;
- *dest_alpha_scan++ = dest_alpha;
- int alpha_ratio = src_alpha * 255 / dest_alpha;
- if (bNonseparableBlend) {
- RGB_Blend(blend_type, src_cache_scan, dest_scan, blended_colors);
- }
- for (int color = 0; color < 3; color++) {
- if (blend_type) {
- int blended = bNonseparableBlend
- ? blended_colors[color]
- : Blend(blend_type, *dest_scan, *src_cache_scan);
- blended = FXDIB_ALPHA_MERGE(*src_cache_scan, blended, back_alpha);
- *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, blended, alpha_ratio);
- } else {
- *dest_scan =
- FXDIB_ALPHA_MERGE(*dest_scan, *src_cache_scan, alpha_ratio);
- }
- dest_scan++;
- src_cache_scan++;
- }
- }
- return;
- }
- for (int col = 0; col < pixel_count; col++) {
- pIccModule->TranslateScanline(pIccTransform, dp, src_scan, 1);
- dp[3] = src_scan[3];
- src_scan += 4;
- dp += 4;
- }
- }
- CompositeRow_Argb2Argb(dest_scan, src_cache_scan, pixel_count, blend_type,
- clip_scan, dest_alpha_scan, src_alpha_scan);
-}
-
-void CompositeRow_Rgb2Argb_Blend_NoClip_Transform(uint8_t* dest_scan,
- const uint8_t* src_scan,
- int width,
- int blend_type,
- int src_Bpp,
- uint8_t* dest_alpha_scan,
- uint8_t* src_cache_scan,
- void* pIccTransform) {
- CCodec_IccModule* pIccModule =
- CFX_GEModule::Get()->GetCodecModule()->GetIccModule();
- if (src_Bpp == 3) {
- pIccModule->TranslateScanline(pIccTransform, src_cache_scan, src_scan,
- width);
- } else {
- uint8_t* dp = src_cache_scan;
- for (int col = 0; col < width; col++) {
- pIccModule->TranslateScanline(pIccTransform, dp, src_scan, 1);
- src_scan += 4;
- dp += 3;
- }
- }
- CompositeRow_Rgb2Argb_Blend_NoClip(dest_scan, src_cache_scan, width,
- blend_type, 3, dest_alpha_scan);
-}
-
-void CompositeRow_Rgb2Argb_Blend_Clip_Transform(uint8_t* dest_scan,
- const uint8_t* src_scan,
- int width,
- int blend_type,
- int src_Bpp,
- const uint8_t* clip_scan,
- uint8_t* dest_alpha_scan,
- uint8_t* src_cache_scan,
- void* pIccTransform) {
- CCodec_IccModule* pIccModule =
- CFX_GEModule::Get()->GetCodecModule()->GetIccModule();
- if (src_Bpp == 3) {
- pIccModule->TranslateScanline(pIccTransform, src_cache_scan, src_scan,
- width);
- } else {
- uint8_t* dp = src_cache_scan;
- for (int col = 0; col < width; col++) {
- pIccModule->TranslateScanline(pIccTransform, dp, src_scan, 1);
- src_scan += 4;
- dp += 3;
- }
- }
- CompositeRow_Rgb2Argb_Blend_Clip(dest_scan, src_cache_scan, width, blend_type,
- 3, clip_scan, dest_alpha_scan);
-}
-
-void CompositeRow_Rgb2Argb_NoBlend_Clip_Transform(uint8_t* dest_scan,
- const uint8_t* src_scan,
- int width,
- int src_Bpp,
- const uint8_t* clip_scan,
- uint8_t* dest_alpha_scan,
- uint8_t* src_cache_scan,
- void* pIccTransform) {
- CCodec_IccModule* pIccModule =
- CFX_GEModule::Get()->GetCodecModule()->GetIccModule();
- if (src_Bpp == 3) {
- pIccModule->TranslateScanline(pIccTransform, src_cache_scan, src_scan,
- width);
- } else {
- uint8_t* dp = src_cache_scan;
- for (int col = 0; col < width; col++) {
- pIccModule->TranslateScanline(pIccTransform, dp, src_scan, 1);
- src_scan += 4;
- dp += 3;
- }
- }
- CompositeRow_Rgb2Argb_NoBlend_Clip(dest_scan, src_cache_scan, width, 3,
- clip_scan, dest_alpha_scan);
-}
-
-void CompositeRow_Rgb2Argb_NoBlend_NoClip_Transform(uint8_t* dest_scan,
- const uint8_t* src_scan,
- int width,
- int src_Bpp,
- uint8_t* dest_alpha_scan,
- uint8_t* src_cache_scan,
- void* pIccTransform) {
- CCodec_IccModule* pIccModule =
- CFX_GEModule::Get()->GetCodecModule()->GetIccModule();
- if (src_Bpp == 3) {
- pIccModule->TranslateScanline(pIccTransform, src_cache_scan, src_scan,
- width);
- } else {
- uint8_t* dp = src_cache_scan;
- for (int col = 0; col < width; col++) {
- pIccModule->TranslateScanline(pIccTransform, dp, src_scan, 1);
- src_scan += 4;
- dp += 3;
- }
- }
- CompositeRow_Rgb2Argb_NoBlend_NoClip(dest_scan, src_cache_scan, width, 3,
- dest_alpha_scan);
-}
-
-void CompositeRow_Argb2Rgb_Blend_Transform(uint8_t* dest_scan,
- const uint8_t* src_scan,
- int width,
- int blend_type,
- int dest_Bpp,
- const uint8_t* clip_scan,
- const uint8_t* src_alpha_scan,
- uint8_t* src_cache_scan,
- void* pIccTransform) {
- CCodec_IccModule* pIccModule =
- CFX_GEModule::Get()->GetCodecModule()->GetIccModule();
- if (src_alpha_scan) {
- pIccModule->TranslateScanline(pIccTransform, src_cache_scan, src_scan,
- width);
- } else {
- int blended_colors[3];
- bool bNonseparableBlend = blend_type >= FXDIB_BLEND_NONSEPARABLE;
- int dest_gap = dest_Bpp - 3;
- for (int col = 0; col < width; col++) {
- pIccModule->TranslateScanline(pIccTransform, src_cache_scan, src_scan, 1);
- uint8_t src_alpha;
- if (clip_scan) {
- src_alpha = src_scan[3] * (*clip_scan++) / 255;
- } else {
- src_alpha = src_scan[3];
- }
- src_scan += 4;
- if (src_alpha == 0) {
- dest_scan += dest_Bpp;
- src_cache_scan += 3;
- continue;
- }
- if (bNonseparableBlend) {
- RGB_Blend(blend_type, src_cache_scan, dest_scan, blended_colors);
- }
- for (int color = 0; color < 3; color++) {
- int back_color = *dest_scan;
- int blended = bNonseparableBlend
- ? blended_colors[color]
- : Blend(blend_type, back_color, *src_cache_scan);
- *dest_scan = FXDIB_ALPHA_MERGE(back_color, blended, src_alpha);
- dest_scan++;
- src_cache_scan++;
- }
- dest_scan += dest_gap;
- }
- return;
- }
- CompositeRow_Argb2Rgb_Blend(dest_scan, src_cache_scan, width, blend_type,
- dest_Bpp, clip_scan, src_alpha_scan);
-}
-
-void CompositeRow_Argb2Rgb_NoBlend_Transform(uint8_t* dest_scan,
- const uint8_t* src_scan,
- int width,
- int dest_Bpp,
- const uint8_t* clip_scan,
- const uint8_t* src_alpha_scan,
- uint8_t* src_cache_scan,
- void* pIccTransform) {
- CCodec_IccModule* pIccModule =
- CFX_GEModule::Get()->GetCodecModule()->GetIccModule();
- if (src_alpha_scan) {
- pIccModule->TranslateScanline(pIccTransform, src_cache_scan, src_scan,
- width);
- } else {
- int dest_gap = dest_Bpp - 3;
- for (int col = 0; col < width; col++) {
- pIccModule->TranslateScanline(pIccTransform, src_cache_scan, src_scan, 1);
- uint8_t src_alpha;
- if (clip_scan) {
- src_alpha = src_scan[3] * (*clip_scan++) / 255;
- } else {
- src_alpha = src_scan[3];
- }
- src_scan += 4;
- if (src_alpha == 255) {
- *dest_scan++ = *src_cache_scan++;
- *dest_scan++ = *src_cache_scan++;
- *dest_scan++ = *src_cache_scan++;
- dest_scan += dest_gap;
- continue;
- }
- if (src_alpha == 0) {
- dest_scan += dest_Bpp;
- src_cache_scan += 3;
- continue;
- }
- for (int color = 0; color < 3; color++) {
- *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, *src_cache_scan, src_alpha);
- dest_scan++;
- src_cache_scan++;
- }
- dest_scan += dest_gap;
- }
- return;
- }
- CompositeRow_Argb2Rgb_NoBlend(dest_scan, src_cache_scan, width, dest_Bpp,
- clip_scan, src_alpha_scan);
-}
-
-void CompositeRow_Rgb2Rgb_Blend_NoClip_Transform(uint8_t* dest_scan,
- const uint8_t* src_scan,
- int width,
- int blend_type,
- int dest_Bpp,
- int src_Bpp,
- uint8_t* src_cache_scan,
- void* pIccTransform) {
- CCodec_IccModule* pIccModule =
- CFX_GEModule::Get()->GetCodecModule()->GetIccModule();
- if (src_Bpp == 3) {
- pIccModule->TranslateScanline(pIccTransform, src_cache_scan, src_scan,
- width);
- } else {
- uint8_t* dp = src_cache_scan;
- for (int col = 0; col < width; col++) {
- pIccModule->TranslateScanline(pIccTransform, dp, src_scan, 1);
- src_scan += 4;
- dp += 3;
- }
- }
- CompositeRow_Rgb2Rgb_Blend_NoClip(dest_scan, src_cache_scan, width,
- blend_type, dest_Bpp, 3);
-}
-
-void CompositeRow_Rgb2Rgb_Blend_Clip_Transform(uint8_t* dest_scan,
- const uint8_t* src_scan,
- int width,
- int blend_type,
- int dest_Bpp,
- int src_Bpp,
- const uint8_t* clip_scan,
- uint8_t* src_cache_scan,
- void* pIccTransform) {
- CCodec_IccModule* pIccModule =
- CFX_GEModule::Get()->GetCodecModule()->GetIccModule();
- if (src_Bpp == 3) {
- pIccModule->TranslateScanline(pIccTransform, src_cache_scan, src_scan,
- width);
- } else {
- uint8_t* dp = src_cache_scan;
- for (int col = 0; col < width; col++) {
- pIccModule->TranslateScanline(pIccTransform, dp, src_scan, 1);
- src_scan += 4;
- dp += 3;
- }
- }
- CompositeRow_Rgb2Rgb_Blend_Clip(dest_scan, src_cache_scan, width, blend_type,
- dest_Bpp, 3, clip_scan);
-}
-
-void CompositeRow_Rgb2Rgb_NoBlend_NoClip_Transform(uint8_t* dest_scan,
- const uint8_t* src_scan,
- int width,
- int dest_Bpp,
- int src_Bpp,
- uint8_t* src_cache_scan,
- void* pIccTransform) {
- CCodec_IccModule* pIccModule =
- CFX_GEModule::Get()->GetCodecModule()->GetIccModule();
- if (src_Bpp == 3) {
- pIccModule->TranslateScanline(pIccTransform, src_cache_scan, src_scan,
- width);
- } else {
- uint8_t* dp = src_cache_scan;
- for (int col = 0; col < width; col++) {
- pIccModule->TranslateScanline(pIccTransform, dp, src_scan, 1);
- src_scan += 4;
- dp += 3;
- }
- }
- CompositeRow_Rgb2Rgb_NoBlend_NoClip(dest_scan, src_cache_scan, width,
- dest_Bpp, 3);
-}
-
-void CompositeRow_Rgb2Rgb_NoBlend_Clip_Transform(uint8_t* dest_scan,
- const uint8_t* src_scan,
- int width,
- int dest_Bpp,
- int src_Bpp,
- const uint8_t* clip_scan,
- uint8_t* src_cache_scan,
- void* pIccTransform) {
- CCodec_IccModule* pIccModule =
- CFX_GEModule::Get()->GetCodecModule()->GetIccModule();
- if (src_Bpp == 3) {
- pIccModule->TranslateScanline(pIccTransform, src_cache_scan, src_scan,
- width);
- } else {
- uint8_t* dp = src_cache_scan;
- for (int col = 0; col < width; col++) {
- pIccModule->TranslateScanline(pIccTransform, dp, src_scan, 1);
- src_scan += 4;
- dp += 3;
- }
- }
- CompositeRow_Rgb2Rgb_NoBlend_Clip(dest_scan, src_cache_scan, width, dest_Bpp,
- 3, clip_scan);
-}
-
void CompositeRow_8bppPal2Gray(uint8_t* dest_scan,
const uint8_t* src_scan,
const uint8_t* pPalette,
@@ -1870,19 +904,15 @@ void CompositeRow_8bppPal2Gray(uint8_t* dest_scan,
bool bNonseparableBlend = blend_type >= FXDIB_BLEND_NONSEPARABLE;
for (int col = 0; col < pixel_count; col++) {
uint8_t gray = pPalette[*src_scan];
- int src_alpha = *src_alpha_scan++;
- if (clip_scan) {
- src_alpha = clip_scan[col] * src_alpha / 255;
- }
+ int src_alpha = GetAlpha(*src_alpha_scan++, clip_scan, col);
if (bNonseparableBlend)
gray = blend_type == FXDIB_BLEND_LUMINOSITY ? gray : *dest_scan;
else
gray = Blend(blend_type, *dest_scan, gray);
- if (src_alpha) {
+ if (src_alpha)
*dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, gray, src_alpha);
- } else {
+ else
*dest_scan = gray;
- }
dest_scan++;
src_scan++;
}
@@ -1890,15 +920,11 @@ void CompositeRow_8bppPal2Gray(uint8_t* dest_scan,
}
for (int col = 0; col < pixel_count; col++) {
uint8_t gray = pPalette[*src_scan];
- int src_alpha = *src_alpha_scan++;
- if (clip_scan) {
- src_alpha = clip_scan[col] * src_alpha / 255;
- }
- if (src_alpha) {
+ int src_alpha = GetAlpha(*src_alpha_scan++, clip_scan, col);
+ if (src_alpha)
*dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, gray, src_alpha);
- } else {
+ else
*dest_scan = gray;
- }
dest_scan++;
src_scan++;
}
@@ -1911,11 +937,10 @@ void CompositeRow_8bppPal2Gray(uint8_t* dest_scan,
gray = blend_type == FXDIB_BLEND_LUMINOSITY ? gray : *dest_scan;
else
gray = Blend(blend_type, *dest_scan, gray);
- if (clip_scan && clip_scan[col] < 255) {
+ if (clip_scan && clip_scan[col] < 255)
*dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, gray, clip_scan[col]);
- } else {
+ else
*dest_scan = gray;
- }
dest_scan++;
src_scan++;
}
@@ -1923,11 +948,10 @@ void CompositeRow_8bppPal2Gray(uint8_t* dest_scan,
}
for (int col = 0; col < pixel_count; col++) {
uint8_t gray = pPalette[*src_scan];
- if (clip_scan && clip_scan[col] < 255) {
+ if (clip_scan && clip_scan[col] < 255)
*dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, gray, clip_scan[col]);
- } else {
+ else
*dest_scan = gray;
- }
dest_scan++;
src_scan++;
}
@@ -1950,10 +974,7 @@ void CompositeRow_8bppPal2Graya(uint8_t* dest_scan,
src_scan++;
uint8_t back_alpha = *dest_alpha_scan;
if (back_alpha == 0) {
- int src_alpha = *src_alpha_scan++;
- if (clip_scan) {
- src_alpha = clip_scan[col] * src_alpha / 255;
- }
+ int src_alpha = GetAlpha(*src_alpha_scan++, clip_scan, col);
if (src_alpha) {
*dest_scan = gray;
*dest_alpha_scan = src_alpha;
@@ -1962,10 +983,7 @@ void CompositeRow_8bppPal2Graya(uint8_t* dest_scan,
dest_alpha_scan++;
continue;
}
- uint8_t src_alpha = *src_alpha_scan++;
- if (clip_scan) {
- src_alpha = clip_scan[col] * src_alpha / 255;
- }
+ uint8_t src_alpha = GetAlpha(*src_alpha_scan++, clip_scan, col);
if (src_alpha == 0) {
dest_scan++;
dest_alpha_scan++;
@@ -1989,10 +1007,7 @@ void CompositeRow_8bppPal2Graya(uint8_t* dest_scan,
src_scan++;
uint8_t back_alpha = *dest_alpha_scan;
if (back_alpha == 0) {
- int src_alpha = *src_alpha_scan++;
- if (clip_scan) {
- src_alpha = clip_scan[col] * src_alpha / 255;
- }
+ int src_alpha = GetAlpha(*src_alpha_scan++, clip_scan, col);
if (src_alpha) {
*dest_scan = gray;
*dest_alpha_scan = src_alpha;
@@ -2001,10 +1016,7 @@ void CompositeRow_8bppPal2Graya(uint8_t* dest_scan,
dest_alpha_scan++;
continue;
}
- uint8_t src_alpha = *src_alpha_scan++;
- if (clip_scan) {
- src_alpha = clip_scan[col] * src_alpha / 255;
- }
+ uint8_t src_alpha = GetAlpha(*src_alpha_scan++, clip_scan, col);
if (src_alpha == 0) {
dest_scan++;
dest_alpha_scan++;
@@ -3809,9 +2821,7 @@ bool ScanlineCompositor_InitSourceMask(FXDIB_Format dest_format,
int& mask_red,
int& mask_green,
int& mask_blue,
- int& mask_black,
- CCodec_IccModule* pIccModule,
- void* pIccTransform) {
+ int& mask_black) {
if (alpha_flag >> 8) {
mask_alpha = alpha_flag & 0xff;
mask_red = FXSYS_GetCValue(mask_color);
@@ -3828,36 +2838,20 @@ bool ScanlineCompositor_InitSourceMask(FXDIB_Format dest_format,
return true;
}
if ((dest_format & 0xff) == 8) {
- if (pIccTransform) {
- mask_color = (alpha_flag >> 8) ? FXCMYK_TODIB(mask_color)
- : FXARGB_TODIB(mask_color);
- uint8_t* gray_p = (uint8_t*)&mask_color;
- pIccModule->TranslateScanline(pIccTransform, gray_p, gray_p, 1);
- mask_red = dest_format & 0x0400 ? FX_CCOLOR(gray_p[0]) : gray_p[0];
+ if (alpha_flag >> 8) {
+ uint8_t r, g, b;
+ AdobeCMYK_to_sRGB1(mask_red, mask_green, mask_blue, mask_black, r, g, b);
+ mask_red = FXRGB2GRAY(r, g, b);
} else {
- if (alpha_flag >> 8) {
- uint8_t r, g, b;
- AdobeCMYK_to_sRGB1(mask_red, mask_green, mask_blue, mask_black, r, g,
- b);
- mask_red = FXRGB2GRAY(r, g, b);
- } else {
- mask_red = FXRGB2GRAY(mask_red, mask_green, mask_blue);
- }
- if (dest_format & 0x0400) {
- mask_red = FX_CCOLOR(mask_red);
- }
+ mask_red = FXRGB2GRAY(mask_red, mask_green, mask_blue);
}
+ if (dest_format & 0x0400)
+ mask_red = FX_CCOLOR(mask_red);
} else {
uint8_t* mask_color_p = (uint8_t*)&mask_color;
mask_color =
(alpha_flag >> 8) ? FXCMYK_TODIB(mask_color) : FXARGB_TODIB(mask_color);
- if (pIccTransform) {
- pIccModule->TranslateScanline(pIccTransform, mask_color_p, mask_color_p,
- 1);
- mask_red = mask_color_p[2];
- mask_green = mask_color_p[1];
- mask_blue = mask_color_p[0];
- } else if (alpha_flag >> 8) {
+ if (alpha_flag >> 8) {
AdobeCMYK_to_sRGB1(mask_color_p[0], mask_color_p[1], mask_color_p[2],
mask_color_p[3], mask_color_p[2], mask_color_p[1],
mask_color_p[0]);
@@ -3872,38 +2866,49 @@ bool ScanlineCompositor_InitSourceMask(FXDIB_Format dest_format,
void ScanlineCompositor_InitSourcePalette(FXDIB_Format src_format,
FXDIB_Format dest_format,
uint32_t*& pDestPalette,
- uint32_t* pSrcPalette,
- CCodec_IccModule* pIccModule,
- void* pIccTransform) {
+ uint32_t* pSrcPalette) {
bool isSrcCmyk = !!(src_format & 0x0400);
bool isDstCmyk = !!(dest_format & 0x0400);
pDestPalette = nullptr;
- if (pIccTransform) {
- if (pSrcPalette) {
- if ((dest_format & 0xff) == 8) {
- int pal_count = 1 << (src_format & 0xff);
- uint8_t* gray_pal = FX_Alloc(uint8_t, pal_count);
- pDestPalette = (uint32_t*)gray_pal;
+ if (pSrcPalette) {
+ if ((dest_format & 0xff) == 8) {
+ int pal_count = 1 << (src_format & 0xff);
+ uint8_t* gray_pal = FX_Alloc(uint8_t, pal_count);
+ pDestPalette = (uint32_t*)gray_pal;
+ if (isSrcCmyk) {
for (int i = 0; i < pal_count; i++) {
- uint32_t color = isSrcCmyk ? FXCMYK_TODIB(pSrcPalette[i])
- : FXARGB_TODIB(pSrcPalette[i]);
- pIccModule->TranslateScanline(pIccTransform, gray_pal,
- (const uint8_t*)&color, 1);
- gray_pal++;
+ FX_CMYK cmyk = pSrcPalette[i];
+ uint8_t r, g, b;
+ AdobeCMYK_to_sRGB1(FXSYS_GetCValue(cmyk), FXSYS_GetMValue(cmyk),
+ FXSYS_GetYValue(cmyk), FXSYS_GetKValue(cmyk), r, g,
+ b);
+ *gray_pal++ = FXRGB2GRAY(r, g, b);
}
} else {
- int palsize = 1 << (src_format & 0xff);
- pDestPalette = FX_Alloc(uint32_t, palsize);
- for (int i = 0; i < palsize; i++) {
- uint32_t color = isSrcCmyk ? FXCMYK_TODIB(pSrcPalette[i])
- : FXARGB_TODIB(pSrcPalette[i]);
- pIccModule->TranslateScanline(pIccTransform, (uint8_t*)&color,
- (const uint8_t*)&color, 1);
- pDestPalette[i] =
- isDstCmyk ? FXCMYK_TODIB(color) : FXARGB_TODIB(color);
+ for (int i = 0; i < pal_count; i++) {
+ FX_ARGB argb = pSrcPalette[i];
+ *gray_pal++ =
+ FXRGB2GRAY(FXARGB_R(argb), FXARGB_G(argb), FXARGB_B(argb));
}
}
} else {
+ int palsize = 1 << (src_format & 0xff);
+ pDestPalette = FX_Alloc(uint32_t, palsize);
+ if (isDstCmyk == isSrcCmyk) {
+ memcpy(pDestPalette, pSrcPalette, palsize * sizeof(uint32_t));
+ } else {
+ for (int i = 0; i < palsize; i++) {
+ FX_CMYK cmyk = pSrcPalette[i];
+ uint8_t r, g, b;
+ AdobeCMYK_to_sRGB1(FXSYS_GetCValue(cmyk), FXSYS_GetMValue(cmyk),
+ FXSYS_GetYValue(cmyk), FXSYS_GetKValue(cmyk), r, g,
+ b);
+ pDestPalette[i] = FXARGB_MAKE(0xff, r, g, b);
+ }
+ }
+ }
+ } else {
+ if ((dest_format & 0xff) == 8) {
int pal_count = 1 << (src_format & 0xff);
uint8_t* gray_pal = FX_Alloc(uint8_t, pal_count);
if (pal_count == 2) {
@@ -3914,92 +2919,26 @@ void ScanlineCompositor_InitSourcePalette(FXDIB_Format src_format,
gray_pal[i] = i;
}
}
- if ((dest_format & 0xff) == 8) {
- pIccModule->TranslateScanline(pIccTransform, gray_pal, gray_pal,
- pal_count);
- pDestPalette = (uint32_t*)gray_pal;
- } else {
- pDestPalette = FX_Alloc(uint32_t, pal_count);
- for (int i = 0; i < pal_count; i++) {
- pIccModule->TranslateScanline(
- pIccTransform, (uint8_t*)&pDestPalette[i], &gray_pal[i], 1);
- pDestPalette[i] = isDstCmyk ? FXCMYK_TODIB(pDestPalette[i])
- : FXARGB_TODIB(pDestPalette[i]);
- }
- FX_Free(gray_pal);
- }
- }
- } else {
- if (pSrcPalette) {
- if ((dest_format & 0xff) == 8) {
- int pal_count = 1 << (src_format & 0xff);
- uint8_t* gray_pal = FX_Alloc(uint8_t, pal_count);
- pDestPalette = (uint32_t*)gray_pal;
- if (isSrcCmyk) {
- for (int i = 0; i < pal_count; i++) {
- FX_CMYK cmyk = pSrcPalette[i];
- uint8_t r, g, b;
- AdobeCMYK_to_sRGB1(FXSYS_GetCValue(cmyk), FXSYS_GetMValue(cmyk),
- FXSYS_GetYValue(cmyk), FXSYS_GetKValue(cmyk), r,
- g, b);
- *gray_pal++ = FXRGB2GRAY(r, g, b);
- }
- } else {
- for (int i = 0; i < pal_count; i++) {
- FX_ARGB argb = pSrcPalette[i];
- *gray_pal++ =
- FXRGB2GRAY(FXARGB_R(argb), FXARGB_G(argb), FXARGB_B(argb));
- }
- }
- } else {
- int palsize = 1 << (src_format & 0xff);
- pDestPalette = FX_Alloc(uint32_t, palsize);
- if (isDstCmyk == isSrcCmyk) {
- FXSYS_memcpy(pDestPalette, pSrcPalette, palsize * sizeof(uint32_t));
- } else {
- for (int i = 0; i < palsize; i++) {
- FX_CMYK cmyk = pSrcPalette[i];
- uint8_t r, g, b;
- AdobeCMYK_to_sRGB1(FXSYS_GetCValue(cmyk), FXSYS_GetMValue(cmyk),
- FXSYS_GetYValue(cmyk), FXSYS_GetKValue(cmyk), r,
- g, b);
- pDestPalette[i] = FXARGB_MAKE(0xff, r, g, b);
- }
- }
- }
+ pDestPalette = (uint32_t*)gray_pal;
} else {
- if ((dest_format & 0xff) == 8) {
- int pal_count = 1 << (src_format & 0xff);
- uint8_t* gray_pal = FX_Alloc(uint8_t, pal_count);
- if (pal_count == 2) {
- gray_pal[0] = 0;
- gray_pal[1] = 255;
- } else {
- for (int i = 0; i < pal_count; i++) {
- gray_pal[i] = i;
- }
- }
- pDestPalette = (uint32_t*)gray_pal;
+ int palsize = 1 << (src_format & 0xff);
+ pDestPalette = FX_Alloc(uint32_t, palsize);
+ if (palsize == 2) {
+ pDestPalette[0] = isSrcCmyk ? 255 : 0xff000000;
+ pDestPalette[1] = isSrcCmyk ? 0 : 0xffffffff;
} else {
- int palsize = 1 << (src_format & 0xff);
- pDestPalette = FX_Alloc(uint32_t, palsize);
- if (palsize == 2) {
- pDestPalette[0] = isSrcCmyk ? 255 : 0xff000000;
- pDestPalette[1] = isSrcCmyk ? 0 : 0xffffffff;
- } else {
- for (int i = 0; i < palsize; i++) {
- pDestPalette[i] = isSrcCmyk ? FX_CCOLOR(i) : (i * 0x10101);
- }
+ for (int i = 0; i < palsize; i++) {
+ pDestPalette[i] = isSrcCmyk ? FX_CCOLOR(i) : (i * 0x10101);
}
- if (isSrcCmyk != isDstCmyk) {
- for (int i = 0; i < palsize; i++) {
- FX_CMYK cmyk = pDestPalette[i];
- uint8_t r, g, b;
- AdobeCMYK_to_sRGB1(FXSYS_GetCValue(cmyk), FXSYS_GetMValue(cmyk),
- FXSYS_GetYValue(cmyk), FXSYS_GetKValue(cmyk), r,
- g, b);
- pDestPalette[i] = FXARGB_MAKE(0xff, r, g, b);
- }
+ }
+ if (isSrcCmyk != isDstCmyk) {
+ for (int i = 0; i < palsize; i++) {
+ FX_CMYK cmyk = pDestPalette[i];
+ uint8_t r, g, b;
+ AdobeCMYK_to_sRGB1(FXSYS_GetCValue(cmyk), FXSYS_GetMValue(cmyk),
+ FXSYS_GetYValue(cmyk), FXSYS_GetKValue(cmyk), r, g,
+ b);
+ pDestPalette[i] = FXARGB_MAKE(0xff, r, g, b);
}
}
}
@@ -4014,7 +2953,6 @@ CFX_ScanlineCompositor::CFX_ScanlineCompositor() {
m_CacheSize = 0;
m_bRgbByteOrder = false;
m_BlendType = FXDIB_BLEND_NORMAL;
- m_pIccTransform = nullptr;
}
CFX_ScanlineCompositor::~CFX_ScanlineCompositor() {
@@ -4030,48 +2968,35 @@ bool CFX_ScanlineCompositor::Init(FXDIB_Format dest_format,
int blend_type,
bool bClip,
bool bRgbByteOrder,
- int alpha_flag,
- void* pIccTransform) {
+ int alpha_flag) {
m_SrcFormat = src_format;
m_DestFormat = dest_format;
m_BlendType = blend_type;
m_bRgbByteOrder = bRgbByteOrder;
- CCodec_IccModule* pIccModule = nullptr;
- if (CFX_GEModule::Get()->GetCodecModule()) {
- pIccModule = CFX_GEModule::Get()->GetCodecModule()->GetIccModule();
- }
- if (!pIccModule) {
- pIccTransform = nullptr;
- }
- m_pIccTransform = pIccTransform;
- if ((dest_format & 0xff) == 1) {
+ if ((dest_format & 0xff) == 1)
return false;
- }
if (m_SrcFormat == FXDIB_1bppMask || m_SrcFormat == FXDIB_8bppMask) {
return ScanlineCompositor_InitSourceMask(
dest_format, alpha_flag, mask_color, m_MaskAlpha, m_MaskRed,
- m_MaskGreen, m_MaskBlue, m_MaskBlack, pIccModule, pIccTransform);
+ m_MaskGreen, m_MaskBlue, m_MaskBlack);
}
- if (!pIccTransform && (~src_format & 0x0400) && (dest_format & 0x0400)) {
+ if ((~src_format & 0x0400) && (dest_format & 0x0400))
return false;
- }
if ((m_SrcFormat & 0xff) <= 8) {
- if (dest_format == FXDIB_8bppMask) {
+ if (dest_format == FXDIB_8bppMask)
return true;
- }
+
ScanlineCompositor_InitSourcePalette(src_format, dest_format, m_pSrcPalette,
- pSrcPalette, pIccModule,
- pIccTransform);
+ pSrcPalette);
m_Transparency =
(dest_format == FXDIB_Argb ? 1 : 0) + (dest_format & 0x0200 ? 2 : 0) +
(dest_format & 0x0400 ? 4 : 0) + ((src_format & 0xff) == 1 ? 8 : 0);
return true;
}
- m_Transparency = (src_format & 0x0200 ? 0 : 1) +
- (dest_format & 0x0200 ? 0 : 2) +
- (blend_type == FXDIB_BLEND_NORMAL ? 4 : 0) +
- (bClip ? 8 : 0) + (src_format & 0x0400 ? 16 : 0) +
- (dest_format & 0x0400 ? 32 : 0) + (pIccTransform ? 64 : 0);
+ m_Transparency =
+ (src_format & 0x0200 ? 0 : 1) + (dest_format & 0x0200 ? 0 : 2) +
+ (blend_type == FXDIB_BLEND_NORMAL ? 4 : 0) + (bClip ? 8 : 0) +
+ (src_format & 0x0400 ? 16 : 0) + (dest_format & 0x0400 ? 32 : 0);
return true;
}
@@ -4142,9 +3067,10 @@ void CFX_ScanlineCompositor::CompositeRgbBitmapLine(
if (m_DestFormat == FXDIB_8bppMask) {
if (m_SrcFormat & 0x0200) {
if (m_SrcFormat == FXDIB_Argb) {
- CompositeRow_Argb2Mask(dest_scan, src_scan, width, clip_scan);
+ CompositeRow_AlphaToMask(dest_scan, src_scan, width, clip_scan, 4);
} else {
- CompositeRow_Rgba2Mask(dest_scan, src_extra_alpha, width, clip_scan);
+ CompositeRow_AlphaToMask(dest_scan, src_extra_alpha, width, clip_scan,
+ 1);
}
} else {
CompositeRow_Rgb2Mask(dest_scan, src_scan, width, clip_scan);
@@ -4159,19 +3085,18 @@ void CFX_ScanlineCompositor::CompositeRgbBitmapLine(
if (m_SrcFormat & 0x0200) {
if (m_DestFormat & 0x0200) {
CompositeRow_Argb2Graya(dest_scan, src_scan, width, m_BlendType,
- clip_scan, src_extra_alpha, dst_extra_alpha,
- m_pIccTransform);
+ clip_scan, src_extra_alpha, dst_extra_alpha);
} else {
CompositeRow_Argb2Gray(dest_scan, src_scan, width, m_BlendType,
- clip_scan, src_extra_alpha, m_pIccTransform);
+ clip_scan, src_extra_alpha);
}
} else {
if (m_DestFormat & 0x0200) {
CompositeRow_Rgb2Graya(dest_scan, src_scan, src_Bpp, width, m_BlendType,
- clip_scan, dst_extra_alpha, m_pIccTransform);
+ clip_scan, dst_extra_alpha);
} else {
CompositeRow_Rgb2Gray(dest_scan, src_scan, src_Bpp, width, m_BlendType,
- clip_scan, m_pIccTransform);
+ clip_scan);
}
}
if (m_DestFormat & 0x0400) {
@@ -4197,109 +3122,49 @@ void CFX_ScanlineCompositor::CompositeRgbBitmapLine(
CompositeRow_Argb2Argb(dest_scan, src_scan, width, m_BlendType,
clip_scan, dst_extra_alpha, src_extra_alpha);
} break;
- case 64:
- case 4 + 64:
- case 8 + 64:
- case 4 + 8 + 64: {
- CompositeRow_Argb2Argb_Transform(
- dest_scan, src_scan, width, m_BlendType, clip_scan, dst_extra_alpha,
- src_extra_alpha, m_pCacheScanline, m_pIccTransform);
- } break;
case 1:
CompositeRow_Rgb2Argb_Blend_NoClip(
dest_scan, src_scan, width, m_BlendType, src_Bpp, dst_extra_alpha);
break;
- case 1 + 64:
- CompositeRow_Rgb2Argb_Blend_NoClip_Transform(
- dest_scan, src_scan, width, m_BlendType, src_Bpp, dst_extra_alpha,
- m_pCacheScanline, m_pIccTransform);
- break;
case 1 + 8:
CompositeRow_Rgb2Argb_Blend_Clip(dest_scan, src_scan, width,
m_BlendType, src_Bpp, clip_scan,
dst_extra_alpha);
break;
- case 1 + 8 + 64:
- CompositeRow_Rgb2Argb_Blend_Clip_Transform(
- dest_scan, src_scan, width, m_BlendType, src_Bpp, clip_scan,
- dst_extra_alpha, m_pCacheScanline, m_pIccTransform);
- break;
case 1 + 4:
CompositeRow_Rgb2Argb_NoBlend_NoClip(dest_scan, src_scan, width,
src_Bpp, dst_extra_alpha);
break;
- case 1 + 4 + 64:
- CompositeRow_Rgb2Argb_NoBlend_NoClip_Transform(
- dest_scan, src_scan, width, src_Bpp, dst_extra_alpha,
- m_pCacheScanline, m_pIccTransform);
- break;
case 1 + 4 + 8:
CompositeRow_Rgb2Argb_NoBlend_Clip(dest_scan, src_scan, width, src_Bpp,
clip_scan, dst_extra_alpha);
break;
- case 1 + 4 + 8 + 64:
- CompositeRow_Rgb2Argb_NoBlend_Clip_Transform(
- dest_scan, src_scan, width, src_Bpp, clip_scan, dst_extra_alpha,
- m_pCacheScanline, m_pIccTransform);
- break;
case 2:
case 2 + 8:
CompositeRow_Argb2Rgb_Blend(dest_scan, src_scan, width, m_BlendType,
dest_Bpp, clip_scan, src_extra_alpha);
break;
- case 2 + 64:
- case 2 + 8 + 64:
- CompositeRow_Argb2Rgb_Blend_Transform(
- dest_scan, src_scan, width, m_BlendType, dest_Bpp, clip_scan,
- src_extra_alpha, m_pCacheScanline, m_pIccTransform);
- break;
case 2 + 4:
case 2 + 4 + 8:
CompositeRow_Argb2Rgb_NoBlend(dest_scan, src_scan, width, dest_Bpp,
clip_scan, src_extra_alpha);
break;
- case 2 + 4 + 64:
- case 2 + 4 + 8 + 64:
- CompositeRow_Argb2Rgb_NoBlend_Transform(
- dest_scan, src_scan, width, dest_Bpp, clip_scan, src_extra_alpha,
- m_pCacheScanline, m_pIccTransform);
- break;
case 1 + 2:
CompositeRow_Rgb2Rgb_Blend_NoClip(dest_scan, src_scan, width,
m_BlendType, dest_Bpp, src_Bpp);
break;
- case 1 + 2 + 64:
- CompositeRow_Rgb2Rgb_Blend_NoClip_Transform(
- dest_scan, src_scan, width, m_BlendType, dest_Bpp, src_Bpp,
- m_pCacheScanline, m_pIccTransform);
- break;
case 1 + 2 + 8:
CompositeRow_Rgb2Rgb_Blend_Clip(dest_scan, src_scan, width, m_BlendType,
dest_Bpp, src_Bpp, clip_scan);
break;
- case 1 + 2 + 8 + 64:
- CompositeRow_Rgb2Rgb_Blend_Clip_Transform(
- dest_scan, src_scan, width, m_BlendType, dest_Bpp, src_Bpp,
- clip_scan, m_pCacheScanline, m_pIccTransform);
- break;
case 1 + 2 + 4:
CompositeRow_Rgb2Rgb_NoBlend_NoClip(dest_scan, src_scan, width,
dest_Bpp, src_Bpp);
break;
- case 1 + 2 + 4 + 64:
- CompositeRow_Rgb2Rgb_NoBlend_NoClip_Transform(
- dest_scan, src_scan, width, dest_Bpp, src_Bpp, m_pCacheScanline,
- m_pIccTransform);
- break;
case 1 + 2 + 4 + 8:
CompositeRow_Rgb2Rgb_NoBlend_Clip(dest_scan, src_scan, width, dest_Bpp,
src_Bpp, clip_scan);
break;
- case 1 + 2 + 4 + 8 + 64:
- CompositeRow_Rgb2Rgb_NoBlend_Clip_Transform(
- dest_scan, src_scan, width, dest_Bpp, src_Bpp, clip_scan,
- m_pCacheScanline, m_pIccTransform);
- break;
}
}
}
@@ -4481,560 +3346,3 @@ void CFX_ScanlineCompositor::CompositeBitMaskLine(uint8_t* dest_scan,
src_left, width, m_BlendType, (m_DestFormat & 0xff) >> 3, clip_scan);
}
}
-
-bool CFX_DIBitmap::CompositeBitmap(int dest_left,
- int dest_top,
- int width,
- int height,
- const CFX_DIBSource* pSrcBitmap,
- int src_left,
- int src_top,
- int blend_type,
- const CFX_ClipRgn* pClipRgn,
- bool bRgbByteOrder,
- void* pIccTransform) {
- if (!m_pBuffer) {
- return false;
- }
- ASSERT(!pSrcBitmap->IsAlphaMask());
- ASSERT(m_bpp >= 8);
- if (pSrcBitmap->IsAlphaMask() || m_bpp < 8) {
- return false;
- }
- GetOverlapRect(dest_left, dest_top, width, height, pSrcBitmap->GetWidth(),
- pSrcBitmap->GetHeight(), src_left, src_top, pClipRgn);
- if (width == 0 || height == 0) {
- return true;
- }
- const CFX_DIBitmap* pClipMask = nullptr;
- FX_RECT clip_box;
- if (pClipRgn && pClipRgn->GetType() != CFX_ClipRgn::RectI) {
- ASSERT(pClipRgn->GetType() == CFX_ClipRgn::MaskF);
- pClipMask = pClipRgn->GetMask().GetObject();
- clip_box = pClipRgn->GetBox();
- }
- CFX_ScanlineCompositor compositor;
- if (!compositor.Init(GetFormat(), pSrcBitmap->GetFormat(), width,
- pSrcBitmap->GetPalette(), 0, blend_type,
- pClipMask != nullptr, bRgbByteOrder, 0, pIccTransform)) {
- return false;
- }
- int dest_Bpp = m_bpp / 8;
- int src_Bpp = pSrcBitmap->GetBPP() / 8;
- bool bRgb = src_Bpp > 1 && !pSrcBitmap->IsCmykImage();
- CFX_DIBitmap* pSrcAlphaMask = pSrcBitmap->m_pAlphaMask;
- for (int row = 0; row < height; row++) {
- uint8_t* dest_scan =
- m_pBuffer + (dest_top + row) * m_Pitch + dest_left * dest_Bpp;
- const uint8_t* src_scan =
- pSrcBitmap->GetScanline(src_top + row) + src_left * src_Bpp;
- const uint8_t* src_scan_extra_alpha =
- pSrcAlphaMask ? pSrcAlphaMask->GetScanline(src_top + row) + src_left
- : nullptr;
- uint8_t* dst_scan_extra_alpha =
- m_pAlphaMask
- ? (uint8_t*)m_pAlphaMask->GetScanline(dest_top + row) + dest_left
- : nullptr;
- const uint8_t* clip_scan = nullptr;
- if (pClipMask) {
- clip_scan = pClipMask->m_pBuffer +
- (dest_top + row - clip_box.top) * pClipMask->m_Pitch +
- (dest_left - clip_box.left);
- }
- if (bRgb) {
- compositor.CompositeRgbBitmapLine(dest_scan, src_scan, width, clip_scan,
- src_scan_extra_alpha,
- dst_scan_extra_alpha);
- } else {
- compositor.CompositePalBitmapLine(dest_scan, src_scan, src_left, width,
- clip_scan, src_scan_extra_alpha,
- dst_scan_extra_alpha);
- }
- }
- return true;
-}
-
-bool CFX_DIBitmap::CompositeMask(int dest_left,
- int dest_top,
- int width,
- int height,
- const CFX_DIBSource* pMask,
- uint32_t color,
- int src_left,
- int src_top,
- int blend_type,
- const CFX_ClipRgn* pClipRgn,
- bool bRgbByteOrder,
- int alpha_flag,
- void* pIccTransform) {
- if (!m_pBuffer) {
- return false;
- }
- ASSERT(pMask->IsAlphaMask());
- ASSERT(m_bpp >= 8);
- if (!pMask->IsAlphaMask() || m_bpp < 8) {
- return false;
- }
- GetOverlapRect(dest_left, dest_top, width, height, pMask->GetWidth(),
- pMask->GetHeight(), src_left, src_top, pClipRgn);
- if (width == 0 || height == 0) {
- return true;
- }
- int src_alpha =
- (uint8_t)(alpha_flag >> 8) ? (alpha_flag & 0xff) : FXARGB_A(color);
- if (src_alpha == 0) {
- return true;
- }
- const CFX_DIBitmap* pClipMask = nullptr;
- FX_RECT clip_box;
- if (pClipRgn && pClipRgn->GetType() != CFX_ClipRgn::RectI) {
- ASSERT(pClipRgn->GetType() == CFX_ClipRgn::MaskF);
- pClipMask = pClipRgn->GetMask().GetObject();
- clip_box = pClipRgn->GetBox();
- }
- int src_bpp = pMask->GetBPP();
- int Bpp = GetBPP() / 8;
- CFX_ScanlineCompositor compositor;
- if (!compositor.Init(GetFormat(), pMask->GetFormat(), width, nullptr, color,
- blend_type, pClipMask != nullptr, bRgbByteOrder,
- alpha_flag, pIccTransform)) {
- return false;
- }
- for (int row = 0; row < height; row++) {
- uint8_t* dest_scan =
- m_pBuffer + (dest_top + row) * m_Pitch + dest_left * Bpp;
- const uint8_t* src_scan = pMask->GetScanline(src_top + row);
- uint8_t* dst_scan_extra_alpha =
- m_pAlphaMask
- ? (uint8_t*)m_pAlphaMask->GetScanline(dest_top + row) + dest_left
- : nullptr;
- const uint8_t* clip_scan = nullptr;
- if (pClipMask) {
- clip_scan = pClipMask->m_pBuffer +
- (dest_top + row - clip_box.top) * pClipMask->m_Pitch +
- (dest_left - clip_box.left);
- }
- if (src_bpp == 1) {
- compositor.CompositeBitMaskLine(dest_scan, src_scan, src_left, width,
- clip_scan, dst_scan_extra_alpha);
- } else {
- compositor.CompositeByteMaskLine(dest_scan, src_scan + src_left, width,
- clip_scan, dst_scan_extra_alpha);
- }
- }
- return true;
-}
-
-bool CFX_DIBitmap::CompositeRect(int left,
- int top,
- int width,
- int height,
- uint32_t color,
- int alpha_flag,
- void* pIccTransform) {
- if (!m_pBuffer) {
- return false;
- }
- int src_alpha = (alpha_flag >> 8) ? (alpha_flag & 0xff) : FXARGB_A(color);
- if (src_alpha == 0) {
- return true;
- }
- FX_RECT rect(left, top, left + width, top + height);
- rect.Intersect(0, 0, m_Width, m_Height);
- if (rect.IsEmpty()) {
- return true;
- }
- width = rect.Width();
- uint32_t dst_color;
- if (alpha_flag >> 8) {
- dst_color = FXCMYK_TODIB(color);
- } else {
- dst_color = FXARGB_TODIB(color);
- }
- uint8_t* color_p = (uint8_t*)&dst_color;
- if (m_bpp == 8) {
- uint8_t gray = 255;
- if (!IsAlphaMask()) {
- if (pIccTransform && CFX_GEModule::Get()->GetCodecModule() &&
- CFX_GEModule::Get()->GetCodecModule()->GetIccModule()) {
- CCodec_IccModule* pIccModule =
- CFX_GEModule::Get()->GetCodecModule()->GetIccModule();
- pIccModule->TranslateScanline(pIccTransform, &gray, color_p, 1);
- } else {
- if (alpha_flag >> 8) {
- uint8_t r, g, b;
- AdobeCMYK_to_sRGB1(color_p[0], color_p[1], color_p[2], color_p[3], r,
- g, b);
- gray = FXRGB2GRAY(r, g, b);
- } else {
- gray = (uint8_t)FXRGB2GRAY((int)color_p[2], color_p[1], color_p[0]);
- }
- }
- if (IsCmykImage()) {
- gray = ~gray;
- }
- }
- for (int row = rect.top; row < rect.bottom; row++) {
- uint8_t* dest_scan = m_pBuffer + row * m_Pitch + rect.left;
- if (src_alpha == 255) {
- FXSYS_memset(dest_scan, gray, width);
- } else {
- for (int col = 0; col < width; col++) {
- *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, gray, src_alpha);
- dest_scan++;
- }
- }
- }
- return true;
- }
- if (m_bpp == 1) {
- ASSERT(!IsCmykImage() && (uint8_t)(alpha_flag >> 8) == 0);
- int left_shift = rect.left % 8;
- int right_shift = rect.right % 8;
- int new_width = rect.right / 8 - rect.left / 8;
- int index = 0;
- if (m_pPalette) {
- for (int i = 0; i < 2; i++) {
- if (m_pPalette.get()[i] == color) {
- index = i;
- }
- }
- } else {
- index = ((uint8_t)color == 0xff) ? 1 : 0;
- }
- for (int row = rect.top; row < rect.bottom; row++) {
- uint8_t* dest_scan_top = (uint8_t*)GetScanline(row) + rect.left / 8;
- uint8_t* dest_scan_top_r = (uint8_t*)GetScanline(row) + rect.right / 8;
- uint8_t left_flag = *dest_scan_top & (255 << (8 - left_shift));
- uint8_t right_flag = *dest_scan_top_r & (255 >> right_shift);
- if (new_width) {
- FXSYS_memset(dest_scan_top + 1, index ? 255 : 0, new_width - 1);
- if (!index) {
- *dest_scan_top &= left_flag;
- *dest_scan_top_r &= right_flag;
- } else {
- *dest_scan_top |= ~left_flag;
- *dest_scan_top_r |= ~right_flag;
- }
- } else {
- if (!index) {
- *dest_scan_top &= left_flag | right_flag;
- } else {
- *dest_scan_top |= ~(left_flag | right_flag);
- }
- }
- }
- return true;
- }
- ASSERT(m_bpp >= 24);
- if (m_bpp < 24) {
- return false;
- }
- if (pIccTransform && CFX_GEModule::Get()->GetCodecModule()) {
- CCodec_IccModule* pIccModule =
- CFX_GEModule::Get()->GetCodecModule()->GetIccModule();
- pIccModule->TranslateScanline(pIccTransform, color_p, color_p, 1);
- } else {
- if (alpha_flag >> 8 && !IsCmykImage()) {
- AdobeCMYK_to_sRGB1(FXSYS_GetCValue(color), FXSYS_GetMValue(color),
- FXSYS_GetYValue(color), FXSYS_GetKValue(color),
- color_p[2], color_p[1], color_p[0]);
- } else if (!(alpha_flag >> 8) && IsCmykImage()) {
- return false;
- }
- }
- if (!IsCmykImage()) {
- color_p[3] = (uint8_t)src_alpha;
- }
- int Bpp = m_bpp / 8;
- bool bAlpha = HasAlpha();
- bool bArgb = GetFormat() == FXDIB_Argb;
- if (src_alpha == 255) {
- for (int row = rect.top; row < rect.bottom; row++) {
- uint8_t* dest_scan = m_pBuffer + row * m_Pitch + rect.left * Bpp;
- uint8_t* dest_scan_alpha =
- m_pAlphaMask ? (uint8_t*)m_pAlphaMask->GetScanline(row) + rect.left
- : nullptr;
- if (dest_scan_alpha) {
- FXSYS_memset(dest_scan_alpha, 0xff, width);
- }
- if (Bpp == 4) {
- uint32_t* scan = (uint32_t*)dest_scan;
- for (int col = 0; col < width; col++) {
- *scan++ = dst_color;
- }
- } else {
- for (int col = 0; col < width; col++) {
- *dest_scan++ = color_p[0];
- *dest_scan++ = color_p[1];
- *dest_scan++ = color_p[2];
- }
- }
- }
- return true;
- }
- for (int row = rect.top; row < rect.bottom; row++) {
- uint8_t* dest_scan = m_pBuffer + row * m_Pitch + rect.left * Bpp;
- if (bAlpha) {
- if (bArgb) {
- for (int col = 0; col < width; col++) {
- uint8_t back_alpha = dest_scan[3];
- if (back_alpha == 0) {
- FXARGB_SETDIB(dest_scan, FXARGB_MAKE(src_alpha, color_p[2],
- color_p[1], color_p[0]));
- dest_scan += 4;
- continue;
- }
- uint8_t dest_alpha =
- back_alpha + src_alpha - back_alpha * src_alpha / 255;
- int alpha_ratio = src_alpha * 255 / dest_alpha;
- *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, color_p[0], alpha_ratio);
- dest_scan++;
- *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, color_p[1], alpha_ratio);
- dest_scan++;
- *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, color_p[2], alpha_ratio);
- dest_scan++;
- *dest_scan++ = dest_alpha;
- }
- } else {
- uint8_t* dest_scan_alpha =
- (uint8_t*)m_pAlphaMask->GetScanline(row) + rect.left;
- for (int col = 0; col < width; col++) {
- uint8_t back_alpha = *dest_scan_alpha;
- if (back_alpha == 0) {
- *dest_scan_alpha++ = src_alpha;
- FXSYS_memcpy(dest_scan, color_p, Bpp);
- dest_scan += Bpp;
- continue;
- }
- uint8_t dest_alpha =
- back_alpha + src_alpha - back_alpha * src_alpha / 255;
- *dest_scan_alpha++ = dest_alpha;
- int alpha_ratio = src_alpha * 255 / dest_alpha;
- for (int comps = 0; comps < Bpp; comps++) {
- *dest_scan =
- FXDIB_ALPHA_MERGE(*dest_scan, color_p[comps], alpha_ratio);
- dest_scan++;
- }
- }
- }
- } else {
- for (int col = 0; col < width; col++) {
- for (int comps = 0; comps < Bpp; comps++) {
- if (comps == 3) {
- *dest_scan++ = 255;
- continue;
- }
- *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, color_p[comps], src_alpha);
- dest_scan++;
- }
- }
- }
- }
- return true;
-}
-
-CFX_BitmapComposer::CFX_BitmapComposer() {
- m_pScanlineV = nullptr;
- m_pScanlineAlphaV = nullptr;
- m_pClipScanV = nullptr;
- m_pAddClipScan = nullptr;
- m_bRgbByteOrder = false;
- m_BlendType = FXDIB_BLEND_NORMAL;
-}
-
-CFX_BitmapComposer::~CFX_BitmapComposer() {
- FX_Free(m_pScanlineV);
- FX_Free(m_pScanlineAlphaV);
- FX_Free(m_pClipScanV);
- FX_Free(m_pAddClipScan);
-}
-
-void CFX_BitmapComposer::Compose(CFX_DIBitmap* pDest,
- const CFX_ClipRgn* pClipRgn,
- int bitmap_alpha,
- uint32_t mask_color,
- FX_RECT& dest_rect,
- bool bVertical,
- bool bFlipX,
- bool bFlipY,
- bool bRgbByteOrder,
- int alpha_flag,
- void* pIccTransform,
- int blend_type) {
- m_pBitmap = pDest;
- m_pClipRgn = pClipRgn;
- m_DestLeft = dest_rect.left;
- m_DestTop = dest_rect.top;
- m_DestWidth = dest_rect.Width();
- m_DestHeight = dest_rect.Height();
- m_BitmapAlpha = bitmap_alpha;
- m_MaskColor = mask_color;
- m_pClipMask = nullptr;
- if (pClipRgn && pClipRgn->GetType() != CFX_ClipRgn::RectI) {
- m_pClipMask = pClipRgn->GetMask().GetObject();
- }
- m_bVertical = bVertical;
- m_bFlipX = bFlipX;
- m_bFlipY = bFlipY;
- m_AlphaFlag = alpha_flag;
- m_pIccTransform = pIccTransform;
- m_bRgbByteOrder = bRgbByteOrder;
- m_BlendType = blend_type;
-}
-bool CFX_BitmapComposer::SetInfo(int width,
- int height,
- FXDIB_Format src_format,
- uint32_t* pSrcPalette) {
- m_SrcFormat = src_format;
- if (!m_Compositor.Init(m_pBitmap->GetFormat(), src_format, width, pSrcPalette,
- m_MaskColor, FXDIB_BLEND_NORMAL,
- m_pClipMask != nullptr || (m_BitmapAlpha < 255),
- m_bRgbByteOrder, m_AlphaFlag, m_pIccTransform)) {
- return false;
- }
- if (m_bVertical) {
- m_pScanlineV = FX_Alloc(uint8_t, m_pBitmap->GetBPP() / 8 * width + 4);
- m_pClipScanV = FX_Alloc(uint8_t, m_pBitmap->GetHeight());
- if (m_pBitmap->m_pAlphaMask) {
- m_pScanlineAlphaV = FX_Alloc(uint8_t, width + 4);
- }
- }
- if (m_BitmapAlpha < 255) {
- m_pAddClipScan = FX_Alloc(
- uint8_t, m_bVertical ? m_pBitmap->GetHeight() : m_pBitmap->GetWidth());
- }
- return true;
-}
-
-void CFX_BitmapComposer::DoCompose(uint8_t* dest_scan,
- const uint8_t* src_scan,
- int dest_width,
- const uint8_t* clip_scan,
- const uint8_t* src_extra_alpha,
- uint8_t* dst_extra_alpha) {
- if (m_BitmapAlpha < 255) {
- if (clip_scan) {
- for (int i = 0; i < dest_width; i++) {
- m_pAddClipScan[i] = clip_scan[i] * m_BitmapAlpha / 255;
- }
- } else {
- FXSYS_memset(m_pAddClipScan, m_BitmapAlpha, dest_width);
- }
- clip_scan = m_pAddClipScan;
- }
- if (m_SrcFormat == FXDIB_8bppMask) {
- m_Compositor.CompositeByteMaskLine(dest_scan, src_scan, dest_width,
- clip_scan, dst_extra_alpha);
- } else if ((m_SrcFormat & 0xff) == 8) {
- m_Compositor.CompositePalBitmapLine(dest_scan, src_scan, 0, dest_width,
- clip_scan, src_extra_alpha,
- dst_extra_alpha);
- } else {
- m_Compositor.CompositeRgbBitmapLine(dest_scan, src_scan, dest_width,
- clip_scan, src_extra_alpha,
- dst_extra_alpha);
- }
-}
-
-void CFX_BitmapComposer::ComposeScanline(int line,
- const uint8_t* scanline,
- const uint8_t* scan_extra_alpha) {
- if (m_bVertical) {
- ComposeScanlineV(line, scanline, scan_extra_alpha);
- return;
- }
- const uint8_t* clip_scan = nullptr;
- if (m_pClipMask)
- clip_scan = m_pClipMask->GetBuffer() +
- (m_DestTop + line - m_pClipRgn->GetBox().top) *
- m_pClipMask->GetPitch() +
- (m_DestLeft - m_pClipRgn->GetBox().left);
- uint8_t* dest_scan = (uint8_t*)m_pBitmap->GetScanline(line + m_DestTop) +
- m_DestLeft * m_pBitmap->GetBPP() / 8;
- uint8_t* dest_alpha_scan =
- m_pBitmap->m_pAlphaMask
- ? (uint8_t*)m_pBitmap->m_pAlphaMask->GetScanline(line + m_DestTop) +
- m_DestLeft
- : nullptr;
- DoCompose(dest_scan, scanline, m_DestWidth, clip_scan, scan_extra_alpha,
- dest_alpha_scan);
-}
-
-void CFX_BitmapComposer::ComposeScanlineV(int line,
- const uint8_t* scanline,
- const uint8_t* scan_extra_alpha) {
- int i;
- int Bpp = m_pBitmap->GetBPP() / 8;
- int dest_pitch = m_pBitmap->GetPitch();
- int dest_alpha_pitch =
- m_pBitmap->m_pAlphaMask ? m_pBitmap->m_pAlphaMask->GetPitch() : 0;
- int dest_x = m_DestLeft + (m_bFlipX ? (m_DestWidth - line - 1) : line);
- uint8_t* dest_buf =
- m_pBitmap->GetBuffer() + dest_x * Bpp + m_DestTop * dest_pitch;
- uint8_t* dest_alpha_buf = m_pBitmap->m_pAlphaMask
- ? m_pBitmap->m_pAlphaMask->GetBuffer() +
- dest_x + m_DestTop * dest_alpha_pitch
- : nullptr;
- if (m_bFlipY) {
- dest_buf += dest_pitch * (m_DestHeight - 1);
- dest_alpha_buf += dest_alpha_pitch * (m_DestHeight - 1);
- }
- int y_step = dest_pitch;
- int y_alpha_step = dest_alpha_pitch;
- if (m_bFlipY) {
- y_step = -y_step;
- y_alpha_step = -y_alpha_step;
- }
- uint8_t* src_scan = m_pScanlineV;
- uint8_t* dest_scan = dest_buf;
- for (i = 0; i < m_DestHeight; i++) {
- for (int j = 0; j < Bpp; j++) {
- *src_scan++ = dest_scan[j];
- }
- dest_scan += y_step;
- }
- uint8_t* src_alpha_scan = m_pScanlineAlphaV;
- uint8_t* dest_alpha_scan = dest_alpha_buf;
- if (dest_alpha_scan) {
- for (i = 0; i < m_DestHeight; i++) {
- *src_alpha_scan++ = *dest_alpha_scan;
- dest_alpha_scan += y_alpha_step;
- }
- }
- uint8_t* clip_scan = nullptr;
- if (m_pClipMask) {
- clip_scan = m_pClipScanV;
- int clip_pitch = m_pClipMask->GetPitch();
- const uint8_t* src_clip =
- m_pClipMask->GetBuffer() +
- (m_DestTop - m_pClipRgn->GetBox().top) * clip_pitch +
- (dest_x - m_pClipRgn->GetBox().left);
- if (m_bFlipY) {
- src_clip += clip_pitch * (m_DestHeight - 1);
- clip_pitch = -clip_pitch;
- }
- for (i = 0; i < m_DestHeight; i++) {
- clip_scan[i] = *src_clip;
- src_clip += clip_pitch;
- }
- }
- DoCompose(m_pScanlineV, scanline, m_DestHeight, clip_scan, scan_extra_alpha,
- m_pScanlineAlphaV);
- src_scan = m_pScanlineV;
- dest_scan = dest_buf;
- for (i = 0; i < m_DestHeight; i++) {
- for (int j = 0; j < Bpp; j++) {
- dest_scan[j] = *src_scan++;
- }
- dest_scan += y_step;
- }
- src_alpha_scan = m_pScanlineAlphaV;
- dest_alpha_scan = dest_alpha_buf;
- if (dest_alpha_scan) {
- for (i = 0; i < m_DestHeight; i++) {
- *dest_alpha_scan = *src_alpha_scan++;
- dest_alpha_scan += y_alpha_step;
- }
- }
-}
diff --git a/chromium/third_party/pdfium/core/fxge/dib/cfx_scanlinecompositor.h b/chromium/third_party/pdfium/core/fxge/dib/cfx_scanlinecompositor.h
new file mode 100644
index 00000000000..a933a89b46d
--- /dev/null
+++ b/chromium/third_party/pdfium/core/fxge/dib/cfx_scanlinecompositor.h
@@ -0,0 +1,72 @@
+// 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_CFX_SCANLINECOMPOSITOR_H_
+#define CORE_FXGE_DIB_CFX_SCANLINECOMPOSITOR_H_
+
+#include "core/fxge/dib/cfx_dibsource.h"
+
+class CFX_ScanlineCompositor {
+ public:
+ CFX_ScanlineCompositor();
+
+ ~CFX_ScanlineCompositor();
+
+ bool Init(FXDIB_Format dest_format,
+ FXDIB_Format src_format,
+ int32_t width,
+ uint32_t* pSrcPalette,
+ uint32_t mask_color,
+ int blend_type,
+ bool bClip,
+ bool bRgbByteOrder = false,
+ int alpha_flag = 0);
+
+ void CompositeRgbBitmapLine(uint8_t* dest_scan,
+ const uint8_t* src_scan,
+ int width,
+ const uint8_t* clip_scan,
+ const uint8_t* src_extra_alpha = nullptr,
+ uint8_t* dst_extra_alpha = nullptr);
+
+ void CompositePalBitmapLine(uint8_t* dest_scan,
+ const uint8_t* src_scan,
+ int src_left,
+ int width,
+ const uint8_t* clip_scan,
+ const uint8_t* src_extra_alpha = nullptr,
+ uint8_t* dst_extra_alpha = nullptr);
+
+ void CompositeByteMaskLine(uint8_t* dest_scan,
+ const uint8_t* src_scan,
+ int width,
+ const uint8_t* clip_scan,
+ uint8_t* dst_extra_alpha = nullptr);
+
+ void CompositeBitMaskLine(uint8_t* dest_scan,
+ const uint8_t* src_scan,
+ int src_left,
+ int width,
+ const uint8_t* clip_scan,
+ uint8_t* dst_extra_alpha = nullptr);
+
+ private:
+ int m_Transparency;
+ FXDIB_Format m_SrcFormat;
+ FXDIB_Format m_DestFormat;
+ uint32_t* m_pSrcPalette;
+ int m_MaskAlpha;
+ int m_MaskRed;
+ int m_MaskGreen;
+ int m_MaskBlue;
+ int m_MaskBlack;
+ int m_BlendType;
+ uint8_t* m_pCacheScanline;
+ int m_CacheSize;
+ bool m_bRgbByteOrder;
+};
+
+#endif // CORE_FXGE_DIB_CFX_SCANLINECOMPOSITOR_H_
diff --git a/chromium/third_party/pdfium/core/fxge/dib/fx_dib_engine.cpp b/chromium/third_party/pdfium/core/fxge/dib/cstretchengine.cpp
index c004aac538d..00253314867 100644
--- a/chromium/third_party/pdfium/core/fxge/dib/fx_dib_engine.cpp
+++ b/chromium/third_party/pdfium/core/fxge/dib/cstretchengine.cpp
@@ -1,67 +1,45 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
+// 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
-#include <limits.h>
+#include "core/fxge/dib/cstretchengine.h"
-#include <algorithm>
-
-#include "core/fxge/dib/dib_int.h"
+#include "core/fxge/dib/cfx_dibitmap.h"
+#include "core/fxge/dib/cfx_dibsource.h"
+#include "core/fxge/dib/ifx_scanlinecomposer.h"
#include "core/fxge/fx_dib.h"
-#include "third_party/base/ptr_util.h"
-
-namespace {
-
-bool SourceSizeWithinLimit(int width, int height) {
- const int kMaxProgressiveStretchPixels = 1000000;
- return !height || width < kMaxProgressiveStretchPixels / height;
-}
-
-FXDIB_Format GetStretchedFormat(const CFX_DIBSource& src) {
- FXDIB_Format format = src.GetFormat();
- if (format == FXDIB_1bppMask)
- return FXDIB_8bppMask;
- if (format == FXDIB_1bppRgb)
- return FXDIB_8bppRgb;
- if (format == FXDIB_8bppRgb && src.GetPalette())
- return FXDIB_Rgb;
- return format;
-}
-
-} // namespace
-CWeightTable::CWeightTable()
+CStretchEngine::CWeightTable::CWeightTable()
: m_DestMin(0),
m_ItemSize(0),
m_pWeightTables(nullptr),
m_dwWeightTablesSize(0) {}
-CWeightTable::~CWeightTable() {
+CStretchEngine::CWeightTable::~CWeightTable() {
FX_Free(m_pWeightTables);
}
-size_t CWeightTable::GetPixelWeightSize() const {
+size_t CStretchEngine::CWeightTable::GetPixelWeightSize() const {
return m_ItemSize / sizeof(int) - 2;
}
-bool CWeightTable::Calc(int dest_len,
- int dest_min,
- int dest_max,
- int src_len,
- int src_min,
- int src_max,
- int flags) {
+bool CStretchEngine::CWeightTable::Calc(int dest_len,
+ int dest_min,
+ int dest_max,
+ int src_len,
+ int src_min,
+ int src_max,
+ int flags) {
FX_Free(m_pWeightTables);
m_pWeightTables = nullptr;
m_dwWeightTablesSize = 0;
- const double scale = (FX_FLOAT)src_len / (FX_FLOAT)dest_len;
- const double base = dest_len < 0 ? (FX_FLOAT)(src_len) : 0;
+ const double scale = (float)src_len / (float)dest_len;
+ const double base = dest_len < 0 ? (float)(src_len) : 0;
const int ext_size = flags & FXDIB_BICUBIC_INTERPOL ? 3 : 1;
- m_ItemSize =
- sizeof(int) * 2 +
- (int)(sizeof(int) * (FXSYS_ceil(FXSYS_fabs((FX_FLOAT)scale)) + ext_size));
+ m_ItemSize = sizeof(int) * 2 +
+ (int)(sizeof(int) * (ceil(fabs((float)scale)) + ext_size));
m_DestMin = dest_min;
if ((dest_max - dest_min) > (int)((1U << 30) - 4) / m_ItemSize)
return false;
@@ -71,14 +49,13 @@ bool CWeightTable::Calc(int dest_len,
if (!m_pWeightTables)
return false;
- if ((flags & FXDIB_NOSMOOTH) != 0 || FXSYS_fabs((FX_FLOAT)scale) < 1.0f) {
+ if ((flags & FXDIB_NOSMOOTH) != 0 || fabs((float)scale) < 1.0f) {
for (int dest_pixel = dest_min; dest_pixel < dest_max; dest_pixel++) {
PixelWeight& pixel_weights = *GetPixelWeight(dest_pixel);
double src_pos = dest_pixel * scale + scale / 2 + base;
if (flags & FXDIB_INTERPOL) {
- pixel_weights.m_SrcStart =
- (int)FXSYS_floor((FX_FLOAT)src_pos - 1.0f / 2);
- pixel_weights.m_SrcEnd = (int)FXSYS_floor((FX_FLOAT)src_pos + 1.0f / 2);
+ pixel_weights.m_SrcStart = (int)floor((float)src_pos - 1.0f / 2);
+ pixel_weights.m_SrcEnd = (int)floor((float)src_pos + 1.0f / 2);
if (pixel_weights.m_SrcStart < src_min) {
pixel_weights.m_SrcStart = src_min;
}
@@ -89,14 +66,12 @@ bool CWeightTable::Calc(int dest_len,
pixel_weights.m_Weights[0] = 65536;
} else {
pixel_weights.m_Weights[1] = FXSYS_round(
- (FX_FLOAT)(src_pos - pixel_weights.m_SrcStart - 1.0f / 2) *
- 65536);
+ (float)(src_pos - pixel_weights.m_SrcStart - 1.0f / 2) * 65536);
pixel_weights.m_Weights[0] = 65536 - pixel_weights.m_Weights[1];
}
} else if (flags & FXDIB_BICUBIC_INTERPOL) {
- pixel_weights.m_SrcStart =
- (int)FXSYS_floor((FX_FLOAT)src_pos - 1.0f / 2);
- pixel_weights.m_SrcEnd = (int)FXSYS_floor((FX_FLOAT)src_pos + 1.0f / 2);
+ pixel_weights.m_SrcStart = (int)floor((float)src_pos - 1.0f / 2);
+ pixel_weights.m_SrcEnd = (int)floor((float)src_pos + 1.0f / 2);
int start = pixel_weights.m_SrcStart - 1;
int end = pixel_weights.m_SrcEnd + 1;
if (start < src_min) {
@@ -114,7 +89,7 @@ bool CWeightTable::Calc(int dest_len,
}
int weight;
weight = FXSYS_round(
- (FX_FLOAT)(src_pos - pixel_weights.m_SrcStart - 1.0f / 2) * 256);
+ (float)(src_pos - pixel_weights.m_SrcStart - 1.0f / 2) * 256);
if (start == end) {
pixel_weights.m_Weights[0] =
(SDP_Table[256 + weight] + SDP_Table[weight] +
@@ -179,7 +154,7 @@ bool CWeightTable::Calc(int dest_len,
}
} else {
pixel_weights.m_SrcStart = pixel_weights.m_SrcEnd =
- (int)FXSYS_floor((FX_FLOAT)src_pos);
+ (int)floor((float)src_pos);
if (pixel_weights.m_SrcStart < src_min) {
pixel_weights.m_SrcStart = src_min;
}
@@ -198,11 +173,11 @@ bool CWeightTable::Calc(int dest_len,
double src_end = src_start + scale;
int start_i, end_i;
if (src_start < src_end) {
- start_i = (int)FXSYS_floor((FX_FLOAT)src_start);
- end_i = (int)FXSYS_ceil((FX_FLOAT)src_end);
+ start_i = (int)floor((float)src_start);
+ end_i = (int)ceil((float)src_end);
} else {
- start_i = (int)FXSYS_floor((FX_FLOAT)src_end);
- end_i = (int)FXSYS_ceil((FX_FLOAT)src_start);
+ start_i = (int)floor((float)src_end);
+ end_i = (int)ceil((float)src_start);
}
if (start_i < src_min) {
start_i = src_min;
@@ -221,18 +196,17 @@ bool CWeightTable::Calc(int dest_len,
pixel_weights.m_SrcStart = start_i;
pixel_weights.m_SrcEnd = end_i;
for (int j = start_i; j <= end_i; j++) {
- double dest_start = ((FX_FLOAT)j - base) / scale;
- double dest_end = ((FX_FLOAT)(j + 1) - base) / scale;
+ double dest_start = ((float)j - base) / scale;
+ double dest_end = ((float)(j + 1) - base) / scale;
if (dest_start > dest_end) {
double temp = dest_start;
dest_start = dest_end;
dest_end = temp;
}
- double area_start = dest_start > (FX_FLOAT)(dest_pixel)
- ? dest_start
- : (FX_FLOAT)(dest_pixel);
- double area_end = dest_end > (FX_FLOAT)(dest_pixel + 1)
- ? (FX_FLOAT)(dest_pixel + 1)
+ double area_start =
+ dest_start > (float)(dest_pixel) ? dest_start : (float)(dest_pixel);
+ double area_end = dest_end > (float)(dest_pixel + 1)
+ ? (float)(dest_pixel + 1)
: dest_end;
double weight = area_start >= area_end ? 0.0f : area_end - area_start;
if (weight == 0 && j == end_i) {
@@ -242,20 +216,20 @@ bool CWeightTable::Calc(int dest_len,
size_t idx = j - start_i;
if (idx >= GetPixelWeightSize())
return false;
- pixel_weights.m_Weights[idx] = FXSYS_round((FX_FLOAT)(weight * 65536));
+ pixel_weights.m_Weights[idx] = FXSYS_round((float)(weight * 65536));
}
}
return true;
}
-PixelWeight* CWeightTable::GetPixelWeight(int pixel) const {
+PixelWeight* CStretchEngine::CWeightTable::GetPixelWeight(int pixel) const {
ASSERT(pixel >= m_DestMin);
return reinterpret_cast<PixelWeight*>(m_pWeightTables +
(pixel - m_DestMin) * m_ItemSize);
}
-int* CWeightTable::GetValueFromPixelWeight(PixelWeight* pWeight,
- int index) const {
+int* CStretchEngine::CWeightTable::GetValueFromPixelWeight(PixelWeight* pWeight,
+ int index) const {
if (index < pWeight->m_SrcStart)
return nullptr;
@@ -268,7 +242,7 @@ CStretchEngine::CStretchEngine(IFX_ScanlineComposer* pDestBitmap,
int dest_width,
int dest_height,
const FX_RECT& clip_rect,
- const CFX_DIBSource* pSrcBitmap,
+ const CFX_RetainPtr<CFX_DIBSource>& pSrcBitmap,
int flags) {
m_State = 0;
m_DestFormat = dest_format;
@@ -298,7 +272,7 @@ CStretchEngine::CStretchEngine(IFX_ScanlineComposer* pDestBitmap,
return;
}
if (dest_format == FXDIB_Rgb32) {
- FXSYS_memset(m_pDestScanline, 255, size);
+ memset(m_pDestScanline, 255, size);
}
m_InterPitch = (m_DestClip.Width() * m_DestBpp + 31) / 32 * 4;
m_ExtraMaskPitch = (m_DestClip.Width() * 8 + 31) / 32 * 4;
@@ -309,9 +283,9 @@ CStretchEngine::CStretchEngine(IFX_ScanlineComposer* pDestBitmap,
m_SrcPitch = (m_SrcWidth * m_SrcBpp + 31) / 32 * 4;
if ((flags & FXDIB_NOSMOOTH) == 0) {
bool bInterpol = flags & FXDIB_INTERPOL || flags & FXDIB_BICUBIC_INTERPOL;
- if (!bInterpol && FXSYS_abs(dest_width) != 0 &&
- FXSYS_abs(dest_height) / 8 < static_cast<long long>(m_SrcWidth) *
- m_SrcHeight / FXSYS_abs(dest_width)) {
+ if (!bInterpol && abs(dest_width) != 0 &&
+ abs(dest_height) / 8 < static_cast<long long>(m_SrcWidth) *
+ m_SrcHeight / abs(dest_width)) {
flags = FXDIB_INTERPOL;
}
m_Flags = flags;
@@ -321,14 +295,14 @@ CStretchEngine::CStretchEngine(IFX_ScanlineComposer* pDestBitmap,
m_Flags |= FXDIB_DOWNSAMPLE;
}
}
- double scale_x = (FX_FLOAT)m_SrcWidth / (FX_FLOAT)m_DestWidth;
- double scale_y = (FX_FLOAT)m_SrcHeight / (FX_FLOAT)m_DestHeight;
- double base_x = m_DestWidth > 0 ? 0.0f : (FX_FLOAT)(m_DestWidth);
- double base_y = m_DestHeight > 0 ? 0.0f : (FX_FLOAT)(m_DestHeight);
- double src_left = scale_x * ((FX_FLOAT)(clip_rect.left) + base_x);
- double src_right = scale_x * ((FX_FLOAT)(clip_rect.right) + base_x);
- double src_top = scale_y * ((FX_FLOAT)(clip_rect.top) + base_y);
- double src_bottom = scale_y * ((FX_FLOAT)(clip_rect.bottom) + base_y);
+ double scale_x = (float)m_SrcWidth / (float)m_DestWidth;
+ double scale_y = (float)m_SrcHeight / (float)m_DestHeight;
+ double base_x = m_DestWidth > 0 ? 0.0f : (float)(m_DestWidth);
+ double base_y = m_DestHeight > 0 ? 0.0f : (float)(m_DestHeight);
+ double src_left = scale_x * ((float)(clip_rect.left) + base_x);
+ double src_right = scale_x * ((float)(clip_rect.right) + base_x);
+ double src_top = scale_y * ((float)(clip_rect.top) + base_y);
+ double src_bottom = scale_y * ((float)(clip_rect.bottom) + base_y);
if (src_left > src_right) {
double temp = src_left;
src_left = src_right;
@@ -339,10 +313,10 @@ CStretchEngine::CStretchEngine(IFX_ScanlineComposer* pDestBitmap,
src_top = src_bottom;
src_bottom = temp;
}
- m_SrcClip.left = (int)FXSYS_floor((FX_FLOAT)src_left);
- m_SrcClip.right = (int)FXSYS_ceil((FX_FLOAT)src_right);
- m_SrcClip.top = (int)FXSYS_floor((FX_FLOAT)src_top);
- m_SrcClip.bottom = (int)FXSYS_ceil((FX_FLOAT)src_bottom);
+ m_SrcClip.left = (int)floor((float)src_left);
+ m_SrcClip.right = (int)ceil((float)src_right);
+ m_SrcClip.top = (int)floor((float)src_top);
+ m_SrcClip.bottom = (int)ceil((float)src_bottom);
FX_RECT src_rect(0, 0, m_SrcWidth, m_SrcHeight);
m_SrcClip.Intersect(src_rect);
if (m_SrcBpp == 1) {
@@ -854,154 +828,3 @@ void CStretchEngine::StretchVert() {
m_pDestMaskScanline);
}
}
-
-CFX_ImageStretcher::CFX_ImageStretcher(IFX_ScanlineComposer* pDest,
- const CFX_DIBSource* pSource,
- int dest_width,
- int dest_height,
- const FX_RECT& bitmap_rect,
- uint32_t flags)
- : m_pDest(pDest),
- m_pSource(pSource),
- m_Flags(flags),
- m_bFlipX(false),
- m_bFlipY(false),
- m_DestWidth(dest_width),
- m_DestHeight(dest_height),
- m_ClipRect(bitmap_rect),
- m_DestFormat(GetStretchedFormat(*pSource)),
- m_DestBPP(m_DestFormat & 0xff),
- m_LineIndex(0) {}
-
-CFX_ImageStretcher::~CFX_ImageStretcher() {
-}
-
-bool CFX_ImageStretcher::Start() {
- if (m_DestWidth == 0 || m_DestHeight == 0)
- return false;
-
- if (m_pSource->GetFormat() == FXDIB_1bppRgb && m_pSource->GetPalette()) {
- FX_ARGB pal[256];
- int a0, r0, g0, b0, a1, r1, g1, b1;
- ArgbDecode(m_pSource->GetPaletteEntry(0), a0, r0, g0, b0);
- ArgbDecode(m_pSource->GetPaletteEntry(1), a1, r1, g1, b1);
- for (int i = 0; i < 256; i++) {
- int a = a0 + (a1 - a0) * i / 255;
- int r = r0 + (r1 - r0) * i / 255;
- int g = g0 + (g1 - g0) * i / 255;
- int b = b0 + (b1 - b0) * i / 255;
- pal[i] = ArgbEncode(a, r, g, b);
- }
- if (!m_pDest->SetInfo(m_ClipRect.Width(), m_ClipRect.Height(), m_DestFormat,
- pal)) {
- return false;
- }
- } else if (m_pSource->GetFormat() == FXDIB_1bppCmyk &&
- m_pSource->GetPalette()) {
- FX_CMYK pal[256];
- int c0, m0, y0, k0, c1, m1, y1, k1;
- CmykDecode(m_pSource->GetPaletteEntry(0), c0, m0, y0, k0);
- CmykDecode(m_pSource->GetPaletteEntry(1), c1, m1, y1, k1);
- for (int i = 0; i < 256; i++) {
- int c = c0 + (c1 - c0) * i / 255;
- int m = m0 + (m1 - m0) * i / 255;
- int y = y0 + (y1 - y0) * i / 255;
- int k = k0 + (k1 - k0) * i / 255;
- pal[i] = CmykEncode(c, m, y, k);
- }
- if (!m_pDest->SetInfo(m_ClipRect.Width(), m_ClipRect.Height(), m_DestFormat,
- pal)) {
- return false;
- }
- } else if (!m_pDest->SetInfo(m_ClipRect.Width(), m_ClipRect.Height(),
- m_DestFormat, nullptr)) {
- return false;
- }
-
- if (m_Flags & FXDIB_DOWNSAMPLE)
- return StartQuickStretch();
- return StartStretch();
-}
-
-bool CFX_ImageStretcher::Continue(IFX_Pause* pPause) {
- if (m_Flags & FXDIB_DOWNSAMPLE)
- return ContinueQuickStretch(pPause);
- return ContinueStretch(pPause);
-}
-
-bool CFX_ImageStretcher::StartStretch() {
- m_pStretchEngine = pdfium::MakeUnique<CStretchEngine>(
- m_pDest, m_DestFormat, m_DestWidth, m_DestHeight, m_ClipRect, m_pSource,
- m_Flags);
- m_pStretchEngine->StartStretchHorz();
- if (SourceSizeWithinLimit(m_pSource->GetWidth(), m_pSource->GetHeight())) {
- m_pStretchEngine->Continue(nullptr);
- return false;
- }
- return true;
-}
-
-bool CFX_ImageStretcher::ContinueStretch(IFX_Pause* pPause) {
- return m_pStretchEngine && m_pStretchEngine->Continue(pPause);
-}
-
-bool CFX_ImageStretcher::StartQuickStretch() {
- if (m_DestWidth < 0) {
- m_bFlipX = true;
- m_DestWidth = -m_DestWidth;
- }
- if (m_DestHeight < 0) {
- m_bFlipY = true;
- m_DestHeight = -m_DestHeight;
- }
- uint32_t size = m_ClipRect.Width();
- if (size && m_DestBPP > (int)(INT_MAX / size)) {
- return false;
- }
- size *= m_DestBPP;
- m_pScanline.reset(FX_Alloc(uint8_t, (size / 8 + 3) / 4 * 4));
- if (m_pSource->m_pAlphaMask)
- m_pMaskScanline.reset(FX_Alloc(uint8_t, (m_ClipRect.Width() + 3) / 4 * 4));
-
- if (SourceSizeWithinLimit(m_pSource->GetWidth(), m_pSource->GetHeight())) {
- ContinueQuickStretch(nullptr);
- return false;
- }
- return true;
-}
-
-bool CFX_ImageStretcher::ContinueQuickStretch(IFX_Pause* pPause) {
- if (!m_pScanline)
- return false;
-
- int result_width = m_ClipRect.Width();
- int result_height = m_ClipRect.Height();
- int src_height = m_pSource->GetHeight();
- for (; m_LineIndex < result_height; m_LineIndex++) {
- int dest_y;
- int src_y;
- if (m_bFlipY) {
- dest_y = result_height - m_LineIndex - 1;
- src_y = (m_DestHeight - (dest_y + m_ClipRect.top) - 1) * src_height /
- m_DestHeight;
- } else {
- dest_y = m_LineIndex;
- src_y = (dest_y + m_ClipRect.top) * src_height / m_DestHeight;
- }
- src_y = std::max(std::min(src_y, src_height - 1), 0);
-
- if (m_pSource->SkipToScanline(src_y, pPause))
- return true;
-
- m_pSource->DownSampleScanline(src_y, m_pScanline.get(), m_DestBPP,
- m_DestWidth, m_bFlipX, m_ClipRect.left,
- result_width);
- if (m_pMaskScanline) {
- m_pSource->m_pAlphaMask->DownSampleScanline(
- src_y, m_pMaskScanline.get(), 1, m_DestWidth, m_bFlipX,
- m_ClipRect.left, result_width);
- }
- m_pDest->ComposeScanline(dest_y, m_pScanline.get(), m_pMaskScanline.get());
- }
- return false;
-}
diff --git a/chromium/third_party/pdfium/core/fxge/dib/cstretchengine.h b/chromium/third_party/pdfium/core/fxge/dib/cstretchengine.h
new file mode 100644
index 00000000000..0d9457fb9db
--- /dev/null
+++ b/chromium/third_party/pdfium/core/fxge/dib/cstretchengine.h
@@ -0,0 +1,81 @@
+// 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_CSTRETCHENGINE_H_
+#define CORE_FXGE_DIB_CSTRETCHENGINE_H_
+
+#include "core/fxcrt/fx_coordinates.h"
+#include "core/fxge/fx_dib.h"
+
+class IFX_ScanlineComposer;
+
+class CStretchEngine {
+ public:
+ CStretchEngine(IFX_ScanlineComposer* pDestBitmap,
+ FXDIB_Format dest_format,
+ int dest_width,
+ int dest_height,
+ const FX_RECT& clip_rect,
+ const CFX_RetainPtr<CFX_DIBSource>& pSrcBitmap,
+ int flags);
+ ~CStretchEngine();
+
+ bool Continue(IFX_Pause* pPause);
+
+ bool StartStretchHorz();
+ bool ContinueStretchHorz(IFX_Pause* pPause);
+ void StretchVert();
+
+ class CWeightTable {
+ public:
+ CWeightTable();
+ ~CWeightTable();
+
+ bool Calc(int dest_len,
+ int dest_min,
+ int dest_max,
+ int src_len,
+ int src_min,
+ int src_max,
+ int flags);
+ PixelWeight* GetPixelWeight(int pixel) const;
+ int* GetValueFromPixelWeight(PixelWeight* pWeight, int index) const;
+ size_t GetPixelWeightSize() const;
+
+ private:
+ int m_DestMin;
+ int m_ItemSize;
+ uint8_t* m_pWeightTables;
+ size_t m_dwWeightTablesSize;
+ };
+
+ FXDIB_Format m_DestFormat;
+ int m_DestBpp;
+ int m_SrcBpp;
+ int m_bHasAlpha;
+ IFX_ScanlineComposer* m_pDestBitmap;
+ int m_DestWidth, m_DestHeight;
+ FX_RECT m_DestClip;
+ uint8_t* m_pDestScanline;
+ uint8_t* m_pDestMaskScanline;
+ FX_RECT m_SrcClip;
+ CFX_RetainPtr<CFX_DIBSource> m_pSource;
+ uint32_t* m_pSrcPalette;
+ int m_SrcWidth;
+ int m_SrcHeight;
+ int m_SrcPitch;
+ int m_InterPitch;
+ int m_ExtraMaskPitch;
+ uint8_t* m_pInterBuf;
+ uint8_t* m_pExtraAlphaBuf;
+ int m_TransMethod;
+ int m_Flags;
+ CWeightTable m_WeightTable;
+ int m_CurRow;
+ int m_State;
+};
+
+#endif // CORE_FXGE_DIB_CSTRETCHENGINE_H_
diff --git a/chromium/third_party/pdfium/core/fxge/dib/fx_dib_engine_unittest.cpp b/chromium/third_party/pdfium/core/fxge/dib/cstretchengine_unittest.cpp
index 705d761ca83..2c7e0342deb 100644
--- a/chromium/third_party/pdfium/core/fxge/dib/fx_dib_engine_unittest.cpp
+++ b/chromium/third_party/pdfium/core/fxge/dib/cstretchengine_unittest.cpp
@@ -1,7 +1,9 @@
-// Copyright 2016 PDFium Authors. All rights reserved.
+// 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.
+#include "core/fxge/dib/cstretchengine.h"
+
#include <memory>
#include <utility>
@@ -10,7 +12,6 @@
#include "core/fpdfapi/parser/cpdf_stream.h"
#include "core/fpdfapi/render/cpdf_dibsource.h"
#include "core/fxcrt/fx_memory.h"
-#include "core/fxge/dib/dib_int.h"
#include "core/fxge/fx_dib.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/base/ptr_util.h"
@@ -23,9 +24,9 @@ TEST(CStretchEngine, OverflowInCtor) {
dict_obj->SetNewFor<CPDF_Number>("Height", 12500);
std::unique_ptr<CPDF_Stream> stream =
pdfium::MakeUnique<CPDF_Stream>(nullptr, 0, std::move(dict_obj));
- CPDF_DIBSource dib_source;
- dib_source.Load(nullptr, stream.get());
- CStretchEngine engine(nullptr, FXDIB_8bppRgb, 500, 500, clip_rect,
- &dib_source, 0);
+ auto dib_source = pdfium::MakeRetain<CPDF_DIBSource>();
+ dib_source->Load(nullptr, stream.get());
+ CStretchEngine engine(nullptr, FXDIB_8bppRgb, 500, 500, clip_rect, dib_source,
+ 0);
EXPECT_EQ(FXDIB_INTERPOL, engine.m_Flags);
}
diff --git a/chromium/third_party/pdfium/core/fxge/dib/dib_int.h b/chromium/third_party/pdfium/core/fxge/dib/dib_int.h
deleted file mode 100644
index 000003a9c6e..00000000000
--- a/chromium/third_party/pdfium/core/fxge/dib/dib_int.h
+++ /dev/null
@@ -1,116 +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
-
-#ifndef CORE_FXGE_DIB_DIB_INT_H_
-#define CORE_FXGE_DIB_DIB_INT_H_
-
-#include <stdint.h>
-
-#include "core/fxcrt/fx_coordinates.h"
-#include "core/fxge/fx_dib.h"
-
-class IFX_ScanlineComposer;
-
-extern const int16_t SDP_Table[513];
-
-class CPDF_FixedMatrix {
- public:
- CPDF_FixedMatrix(const CFX_Matrix& src, int bits) {
- base = 1 << bits;
- a = FXSYS_round(src.a * base);
- b = FXSYS_round(src.b * base);
- c = FXSYS_round(src.c * base);
- d = FXSYS_round(src.d * base);
- e = FXSYS_round(src.e * base);
- f = FXSYS_round(src.f * base);
- }
- inline void Transform(int x, int y, int& x1, int& y1) {
- x1 = (a * x + c * y + e + base / 2) / base;
- y1 = (b * x + d * y + f + base / 2) / base;
- }
- int a, b, c, d, e, f;
- int base;
-};
-#define FPDF_HUGE_IMAGE_SIZE 60000000
-struct PixelWeight {
- int m_SrcStart;
- int m_SrcEnd;
- int m_Weights[1];
-};
-
-class CWeightTable {
- public:
- CWeightTable();
- ~CWeightTable();
-
- bool Calc(int dest_len,
- int dest_min,
- int dest_max,
- int src_len,
- int src_min,
- int src_max,
- int flags);
- PixelWeight* GetPixelWeight(int pixel) const;
- int* GetValueFromPixelWeight(PixelWeight* pWeight, int index) const;
- size_t GetPixelWeightSize() const;
-
- private:
- int m_DestMin;
- int m_ItemSize;
- uint8_t* m_pWeightTables;
- size_t m_dwWeightTablesSize;
-};
-
-class CStretchEngine {
- public:
- CStretchEngine(IFX_ScanlineComposer* pDestBitmap,
- FXDIB_Format dest_format,
- int dest_width,
- int dest_height,
- const FX_RECT& clip_rect,
- const CFX_DIBSource* pSrcBitmap,
- int flags);
- ~CStretchEngine();
-
- bool Continue(IFX_Pause* pPause);
-
- bool StartStretchHorz();
- bool ContinueStretchHorz(IFX_Pause* pPause);
- void StretchVert();
-
- FXDIB_Format m_DestFormat;
- int m_DestBpp;
- int m_SrcBpp;
- int m_bHasAlpha;
- IFX_ScanlineComposer* m_pDestBitmap;
- int m_DestWidth, m_DestHeight;
- FX_RECT m_DestClip;
- uint8_t* m_pDestScanline;
- uint8_t* m_pDestMaskScanline;
- FX_RECT m_SrcClip;
- const CFX_DIBSource* m_pSource;
- uint32_t* m_pSrcPalette;
- int m_SrcWidth;
- int m_SrcHeight;
- int m_SrcPitch;
- int m_InterPitch;
- int m_ExtraMaskPitch;
- uint8_t* m_pInterBuf;
- uint8_t* m_pExtraAlphaBuf;
- int m_TransMethod;
- int m_Flags;
- CWeightTable m_WeightTable;
- int m_CurRow;
- int m_State;
-};
-
-FX_RECT FXDIB_SwapClipBox(FX_RECT& clip,
- int width,
- int height,
- bool bFlipX,
- bool bFlipY);
-
-#endif // CORE_FXGE_DIB_DIB_INT_H_
diff --git a/chromium/third_party/pdfium/core/fxge/dib/fx_dib_main.cpp b/chromium/third_party/pdfium/core/fxge/dib/fx_dib_main.cpp
index 96cae9d4e7b..97b1aa7ccab 100644
--- a/chromium/third_party/pdfium/core/fxge/dib/fx_dib_main.cpp
+++ b/chromium/third_party/pdfium/core/fxge/dib/fx_dib_main.cpp
@@ -6,24 +6,70 @@
#include "core/fxge/fx_dib.h"
-#include <limits.h>
-
-#include <algorithm>
-#include <memory>
#include <utility>
-#include "core/fxcodec/fx_codec.h"
-#include "core/fxcrt/cfx_maybe_owned.h"
-#include "core/fxge/cfx_gemodule.h"
-#include "core/fxge/dib/dib_int.h"
-#include "core/fxge/ge/cfx_cliprgn.h"
#include "third_party/base/ptr_util.h"
-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);
+const int16_t SDP_Table[513] = {
+ 256, 256, 256, 256, 256, 256, 256, 256, 256, 255, 255, 255, 255, 255, 255,
+ 254, 254, 254, 254, 253, 253, 253, 252, 252, 252, 251, 251, 251, 250, 250,
+ 249, 249, 249, 248, 248, 247, 247, 246, 246, 245, 244, 244, 243, 243, 242,
+ 242, 241, 240, 240, 239, 238, 238, 237, 236, 236, 235, 234, 233, 233, 232,
+ 231, 230, 230, 229, 228, 227, 226, 226, 225, 224, 223, 222, 221, 220, 219,
+ 218, 218, 217, 216, 215, 214, 213, 212, 211, 210, 209, 208, 207, 206, 205,
+ 204, 203, 202, 201, 200, 199, 198, 196, 195, 194, 193, 192, 191, 190, 189,
+ 188, 186, 185, 184, 183, 182, 181, 179, 178, 177, 176, 175, 173, 172, 171,
+ 170, 169, 167, 166, 165, 164, 162, 161, 160, 159, 157, 156, 155, 154, 152,
+ 151, 150, 149, 147, 146, 145, 143, 142, 141, 140, 138, 137, 136, 134, 133,
+ 132, 130, 129, 128, 126, 125, 124, 122, 121, 120, 119, 117, 116, 115, 113,
+ 112, 111, 109, 108, 107, 105, 104, 103, 101, 100, 99, 97, 96, 95, 93,
+ 92, 91, 89, 88, 87, 85, 84, 83, 81, 80, 79, 77, 76, 75, 73,
+ 72, 71, 69, 68, 67, 66, 64, 63, 62, 60, 59, 58, 57, 55, 54,
+ 53, 52, 50, 49, 48, 47, 45, 44, 43, 42, 40, 39, 38, 37, 36,
+ 34, 33, 32, 31, 30, 28, 27, 26, 25, 24, 23, 21, 20, 19, 18,
+ 17, 16, 15, 14, 13, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2,
+ 1, 0, 0, -1, -2, -3, -4, -5, -6, -7, -7, -8, -9, -10, -11,
+ -12, -12, -13, -14, -15, -15, -16, -17, -17, -18, -19, -19, -20, -21, -21,
+ -22, -22, -23, -24, -24, -25, -25, -26, -26, -27, -27, -27, -28, -28, -29,
+ -29, -30, -30, -30, -31, -31, -31, -32, -32, -32, -33, -33, -33, -33, -34,
+ -34, -34, -34, -35, -35, -35, -35, -35, -36, -36, -36, -36, -36, -36, -36,
+ -36, -36, -37, -37, -37, -37, -37, -37, -37, -37, -37, -37, -37, -37, -37,
+ -37, -37, -37, -37, -37, -37, -37, -37, -36, -36, -36, -36, -36, -36, -36,
+ -36, -36, -35, -35, -35, -35, -35, -35, -34, -34, -34, -34, -34, -33, -33,
+ -33, -33, -33, -32, -32, -32, -32, -31, -31, -31, -31, -30, -30, -30, -30,
+ -29, -29, -29, -29, -28, -28, -28, -27, -27, -27, -27, -26, -26, -26, -25,
+ -25, -25, -24, -24, -24, -23, -23, -23, -22, -22, -22, -22, -21, -21, -21,
+ -20, -20, -20, -19, -19, -19, -18, -18, -18, -17, -17, -17, -16, -16, -16,
+ -15, -15, -15, -14, -14, -14, -13, -13, -13, -12, -12, -12, -11, -11, -11,
+ -10, -10, -10, -9, -9, -9, -9, -8, -8, -8, -7, -7, -7, -7, -6,
+ -6, -6, -6, -5, -5, -5, -5, -4, -4, -4, -4, -3, -3, -3, -3,
+ -3, -2, -2, -2, -2, -2, -1, -1, -1, -1, -1, -1, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0,
+};
+
+FX_RECT FXDIB_SwapClipBox(FX_RECT& clip,
+ int width,
+ int height,
+ bool bFlipX,
+ bool bFlipY) {
+ FX_RECT rect;
+ if (bFlipY) {
+ rect.left = height - clip.top;
+ rect.right = height - clip.bottom;
+ } else {
+ rect.left = clip.top;
+ rect.right = clip.bottom;
+ }
+ if (bFlipX) {
+ rect.top = width - clip.left;
+ rect.bottom = width - clip.right;
+ } else {
+ rect.top = clip.left;
+ rect.bottom = clip.right;
+ }
+ rect.Normalize();
+ return rect;
}
void ArgbDecode(uint32_t argb, int& a, int& r, int& g, int& b) {
@@ -42,1606 +88,3 @@ uint32_t ArgbEncode(int a, FX_COLORREF rgb) {
return FXARGB_MAKE(a, FXSYS_GetRValue(rgb), FXSYS_GetGValue(rgb),
FXSYS_GetBValue(rgb));
}
-
-CFX_DIBSource::CFX_DIBSource()
- : m_pAlphaMask(nullptr),
- m_Width(0),
- m_Height(0),
- m_bpp(0),
- m_AlphaFlag(0),
- m_Pitch(0) {}
-
-CFX_DIBSource::~CFX_DIBSource() {
- delete m_pAlphaMask;
-}
-
-uint8_t* CFX_DIBSource::GetBuffer() const {
- return nullptr;
-}
-
-bool CFX_DIBSource::SkipToScanline(int line, IFX_Pause* pPause) const {
- return false;
-}
-
-CFX_DIBitmap::CFX_DIBitmap() {
- m_bExtBuf = false;
- m_pBuffer = nullptr;
- m_pPalette = nullptr;
-#ifdef _SKIA_SUPPORT_PATHS_
- m_nFormat = Format::kCleared;
-#endif
-}
-
-#define _MAX_OOM_LIMIT_ 12000000
-bool CFX_DIBitmap::Create(int width,
- int height,
- FXDIB_Format format,
- uint8_t* pBuffer,
- int pitch) {
- m_pBuffer = nullptr;
- m_bpp = (uint8_t)format;
- m_AlphaFlag = (uint8_t)(format >> 8);
- m_Width = m_Height = m_Pitch = 0;
- if (width <= 0 || height <= 0 || pitch < 0) {
- return false;
- }
- if ((INT_MAX - 31) / width < (format & 0xff)) {
- return false;
- }
- if (!pitch) {
- pitch = (width * (format & 0xff) + 31) / 32 * 4;
- }
- if ((1 << 30) / pitch < height) {
- return false;
- }
- if (pBuffer) {
- m_pBuffer = pBuffer;
- m_bExtBuf = true;
- } else {
- int size = pitch * height + 4;
- int oomlimit = _MAX_OOM_LIMIT_;
- if (oomlimit >= 0 && size >= oomlimit) {
- m_pBuffer = FX_TryAlloc(uint8_t, size);
- if (!m_pBuffer) {
- return false;
- }
- } else {
- m_pBuffer = FX_Alloc(uint8_t, size);
- }
- }
- m_Width = width;
- m_Height = height;
- m_Pitch = pitch;
- if (HasAlpha() && format != FXDIB_Argb) {
- bool ret = true;
- ret = BuildAlphaMask();
- if (!ret) {
- if (!m_bExtBuf) {
- FX_Free(m_pBuffer);
- m_pBuffer = nullptr;
- m_Width = m_Height = m_Pitch = 0;
- return false;
- }
- }
- }
- return true;
-}
-
-bool CFX_DIBitmap::Copy(const CFX_DIBSource* pSrc) {
- if (m_pBuffer)
- return false;
-
- if (!Create(pSrc->GetWidth(), pSrc->GetHeight(), pSrc->GetFormat()))
- return false;
-
- SetPalette(pSrc->GetPalette());
- SetAlphaMask(pSrc->m_pAlphaMask);
- for (int row = 0; row < pSrc->GetHeight(); row++)
- FXSYS_memcpy(m_pBuffer + row * m_Pitch, pSrc->GetScanline(row), m_Pitch);
-
- return true;
-}
-
-CFX_DIBitmap::~CFX_DIBitmap() {
- if (!m_bExtBuf)
- FX_Free(m_pBuffer);
-
- m_pBuffer = nullptr;
-}
-
-uint8_t* CFX_DIBitmap::GetBuffer() const {
- return m_pBuffer;
-}
-
-const uint8_t* CFX_DIBitmap::GetScanline(int line) const {
- return m_pBuffer ? m_pBuffer + line * m_Pitch : nullptr;
-}
-
-void CFX_DIBitmap::TakeOver(CFX_DIBitmap* pSrcBitmap) {
- if (!m_bExtBuf)
- FX_Free(m_pBuffer);
-
- delete m_pAlphaMask;
- m_pBuffer = pSrcBitmap->m_pBuffer;
- m_pPalette = std::move(pSrcBitmap->m_pPalette);
- m_pAlphaMask = pSrcBitmap->m_pAlphaMask;
- pSrcBitmap->m_pBuffer = nullptr;
- pSrcBitmap->m_pAlphaMask = nullptr;
- m_bpp = pSrcBitmap->m_bpp;
- m_bExtBuf = pSrcBitmap->m_bExtBuf;
- m_AlphaFlag = pSrcBitmap->m_AlphaFlag;
- m_Width = pSrcBitmap->m_Width;
- m_Height = pSrcBitmap->m_Height;
- m_Pitch = pSrcBitmap->m_Pitch;
-}
-
-std::unique_ptr<CFX_DIBitmap> CFX_DIBSource::Clone(const FX_RECT* pClip) const {
- FX_RECT rect(0, 0, m_Width, m_Height);
- if (pClip) {
- rect.Intersect(*pClip);
- if (rect.IsEmpty())
- return nullptr;
- }
- auto pNewBitmap = pdfium::MakeUnique<CFX_DIBitmap>();
- if (!pNewBitmap->Create(rect.Width(), rect.Height(), GetFormat()))
- return nullptr;
-
- pNewBitmap->SetPalette(m_pPalette.get());
- pNewBitmap->SetAlphaMask(m_pAlphaMask, pClip);
- if (GetBPP() == 1 && rect.left % 8 != 0) {
- int left_shift = rect.left % 32;
- int right_shift = 32 - left_shift;
- int dword_count = pNewBitmap->m_Pitch / 4;
- for (int row = rect.top; row < rect.bottom; row++) {
- uint32_t* src_scan = (uint32_t*)GetScanline(row) + rect.left / 32;
- uint32_t* dest_scan = (uint32_t*)pNewBitmap->GetScanline(row - rect.top);
- for (int i = 0; i < dword_count; i++) {
- dest_scan[i] =
- (src_scan[i] << left_shift) | (src_scan[i + 1] >> right_shift);
- }
- }
- } else {
- int copy_len = (pNewBitmap->GetWidth() * pNewBitmap->GetBPP() + 7) / 8;
- if (m_Pitch < (uint32_t)copy_len)
- copy_len = m_Pitch;
-
- for (int row = rect.top; row < rect.bottom; row++) {
- const uint8_t* src_scan = GetScanline(row) + rect.left * m_bpp / 8;
- uint8_t* dest_scan = (uint8_t*)pNewBitmap->GetScanline(row - rect.top);
- FXSYS_memcpy(dest_scan, src_scan, copy_len);
- }
- }
- return pNewBitmap;
-}
-
-void CFX_DIBSource::BuildPalette() {
- if (m_pPalette)
- return;
-
- if (GetBPP() == 1) {
- m_pPalette.reset(FX_Alloc(uint32_t, 2));
- if (IsCmykImage()) {
- m_pPalette.get()[0] = 0xff;
- m_pPalette.get()[1] = 0;
- } else {
- m_pPalette.get()[0] = 0xff000000;
- m_pPalette.get()[1] = 0xffffffff;
- }
- } else if (GetBPP() == 8) {
- m_pPalette.reset(FX_Alloc(uint32_t, 256));
- if (IsCmykImage()) {
- for (int i = 0; i < 256; i++)
- m_pPalette.get()[i] = 0xff - i;
- } else {
- for (int i = 0; i < 256; i++)
- m_pPalette.get()[i] = 0xff000000 | (i * 0x10101);
- }
- }
-}
-
-bool CFX_DIBSource::BuildAlphaMask() {
- if (m_pAlphaMask) {
- return true;
- }
- m_pAlphaMask = new CFX_DIBitmap;
- if (!m_pAlphaMask->Create(m_Width, m_Height, FXDIB_8bppMask)) {
- delete m_pAlphaMask;
- m_pAlphaMask = nullptr;
- return false;
- }
- FXSYS_memset(m_pAlphaMask->GetBuffer(), 0xff,
- m_pAlphaMask->GetHeight() * m_pAlphaMask->GetPitch());
- return true;
-}
-
-uint32_t CFX_DIBSource::GetPaletteEntry(int index) const {
- ASSERT((GetBPP() == 1 || GetBPP() == 8) && !IsAlphaMask());
- if (m_pPalette) {
- return m_pPalette.get()[index];
- }
- if (IsCmykImage()) {
- if (GetBPP() == 1) {
- return index ? 0 : 0xff;
- }
- return 0xff - index;
- }
- if (GetBPP() == 1) {
- return index ? 0xffffffff : 0xff000000;
- }
- return index * 0x10101 | 0xff000000;
-}
-
-void CFX_DIBSource::SetPaletteEntry(int index, uint32_t color) {
- ASSERT((GetBPP() == 1 || GetBPP() == 8) && !IsAlphaMask());
- if (!m_pPalette) {
- BuildPalette();
- }
- m_pPalette.get()[index] = color;
-}
-
-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 ((uint8_t)color == 0xff) ? 1 : 0;
- }
- return (uint8_t)color;
- }
- int palsize = (1 << GetBPP());
- for (int i = 0; i < palsize; i++)
- if (m_pPalette.get()[i] == color) {
- return i;
- }
- return -1;
-}
-
-void CFX_DIBitmap::Clear(uint32_t color) {
- if (!m_pBuffer) {
- return;
- }
- switch (GetFormat()) {
- case FXDIB_1bppMask:
- FXSYS_memset(m_pBuffer, (color & 0xff000000) ? 0xff : 0,
- m_Pitch * m_Height);
- break;
- case FXDIB_1bppRgb: {
- int index = FindPalette(color);
- FXSYS_memset(m_pBuffer, index ? 0xff : 0, m_Pitch * m_Height);
- break;
- }
- case FXDIB_8bppMask:
- FXSYS_memset(m_pBuffer, color >> 24, m_Pitch * m_Height);
- break;
- case FXDIB_8bppRgb: {
- int index = FindPalette(color);
- FXSYS_memset(m_pBuffer, index, m_Pitch * m_Height);
- break;
- }
- case FXDIB_Rgb:
- case FXDIB_Rgba: {
- int a, r, g, b;
- ArgbDecode(color, a, r, g, b);
- if (r == g && g == b) {
- FXSYS_memset(m_pBuffer, r, m_Pitch * m_Height);
- } else {
- int byte_pos = 0;
- for (int col = 0; col < m_Width; col++) {
- m_pBuffer[byte_pos++] = b;
- m_pBuffer[byte_pos++] = g;
- m_pBuffer[byte_pos++] = r;
- }
- for (int row = 1; row < m_Height; row++) {
- FXSYS_memcpy(m_pBuffer + row * m_Pitch, m_pBuffer, m_Pitch);
- }
- }
- break;
- }
- case FXDIB_Rgb32:
- case FXDIB_Argb: {
- color = IsCmykImage() ? FXCMYK_TODIB(color) : FXARGB_TODIB(color);
-#ifdef _SKIA_SUPPORT_
- if (FXDIB_Rgb32 == GetFormat() && !IsCmykImage()) {
- color |= 0xFF000000;
- }
-#endif
- for (int i = 0; i < m_Width; i++) {
- ((uint32_t*)m_pBuffer)[i] = color;
- }
- for (int row = 1; row < m_Height; row++) {
- FXSYS_memcpy(m_pBuffer + row * m_Pitch, m_pBuffer, m_Pitch);
- }
- break;
- }
- default:
- break;
- }
-}
-
-void CFX_DIBSource::GetOverlapRect(int& dest_left,
- int& dest_top,
- int& width,
- int& height,
- int src_width,
- int src_height,
- int& src_left,
- int& src_top,
- const CFX_ClipRgn* pClipRgn) {
- if (width == 0 || height == 0) {
- return;
- }
- ASSERT(width > 0 && height > 0);
- if (dest_left > m_Width || dest_top > m_Height) {
- width = 0;
- height = 0;
- return;
- }
- int x_offset = dest_left - src_left;
- int y_offset = dest_top - src_top;
- FX_RECT src_rect(src_left, src_top, src_left + width, src_top + height);
- FX_RECT src_bound(0, 0, src_width, src_height);
- src_rect.Intersect(src_bound);
- FX_RECT dest_rect(src_rect.left + x_offset, src_rect.top + y_offset,
- src_rect.right + x_offset, src_rect.bottom + y_offset);
- FX_RECT dest_bound(0, 0, m_Width, m_Height);
- dest_rect.Intersect(dest_bound);
- if (pClipRgn) {
- dest_rect.Intersect(pClipRgn->GetBox());
- }
- dest_left = dest_rect.left;
- dest_top = dest_rect.top;
- src_left = dest_left - x_offset;
- src_top = dest_top - y_offset;
- width = dest_rect.right - dest_rect.left;
- height = dest_rect.bottom - dest_rect.top;
-}
-
-bool CFX_DIBitmap::TransferBitmap(int dest_left,
- int dest_top,
- int width,
- int height,
- const CFX_DIBSource* pSrcBitmap,
- int src_left,
- int src_top) {
- if (!m_pBuffer)
- return false;
-
- GetOverlapRect(dest_left, dest_top, width, height, pSrcBitmap->GetWidth(),
- pSrcBitmap->GetHeight(), src_left, src_top, nullptr);
- if (width == 0 || height == 0)
- return true;
-
- FXDIB_Format dest_format = GetFormat();
- FXDIB_Format src_format = pSrcBitmap->GetFormat();
- if (dest_format == src_format) {
- if (GetBPP() == 1) {
- for (int row = 0; row < height; row++) {
- uint8_t* dest_scan = m_pBuffer + (dest_top + row) * m_Pitch;
- const uint8_t* src_scan = pSrcBitmap->GetScanline(src_top + row);
- for (int col = 0; col < width; col++) {
- if (src_scan[(src_left + col) / 8] &
- (1 << (7 - (src_left + col) % 8))) {
- dest_scan[(dest_left + col) / 8] |= 1
- << (7 - (dest_left + col) % 8);
- } else {
- dest_scan[(dest_left + col) / 8] &=
- ~(1 << (7 - (dest_left + col) % 8));
- }
- }
- }
- } else {
- int Bpp = GetBPP() / 8;
- for (int row = 0; row < height; row++) {
- uint8_t* dest_scan =
- m_pBuffer + (dest_top + row) * m_Pitch + dest_left * Bpp;
- const uint8_t* src_scan =
- pSrcBitmap->GetScanline(src_top + row) + src_left * Bpp;
- FXSYS_memcpy(dest_scan, src_scan, width * Bpp);
- }
- }
- } else {
- if (m_pPalette)
- return false;
-
- if (m_bpp == 8)
- dest_format = FXDIB_8bppMask;
-
- uint8_t* dest_buf =
- m_pBuffer + dest_top * m_Pitch + dest_left * GetBPP() / 8;
- std::unique_ptr<uint32_t, FxFreeDeleter> d_plt;
- if (!ConvertBuffer(dest_format, dest_buf, m_Pitch, width, height,
- pSrcBitmap, src_left, src_top, &d_plt)) {
- return false;
- }
- }
- return true;
-}
-
-bool CFX_DIBitmap::TransferMask(int dest_left,
- int dest_top,
- int width,
- int height,
- const CFX_DIBSource* pMask,
- uint32_t color,
- int src_left,
- int src_top,
- int alpha_flag,
- void* pIccTransform) {
- if (!m_pBuffer) {
- return false;
- }
- ASSERT(HasAlpha() && (m_bpp >= 24));
- ASSERT(pMask->IsAlphaMask());
- if (!HasAlpha() || !pMask->IsAlphaMask() || m_bpp < 24) {
- return false;
- }
- GetOverlapRect(dest_left, dest_top, width, height, pMask->GetWidth(),
- pMask->GetHeight(), src_left, src_top, nullptr);
- if (width == 0 || height == 0) {
- return true;
- }
- int src_bpp = pMask->GetBPP();
- int alpha;
- uint32_t dst_color;
- if (alpha_flag >> 8) {
- alpha = alpha_flag & 0xff;
- dst_color = FXCMYK_TODIB(color);
- } else {
- alpha = FXARGB_A(color);
- dst_color = FXARGB_TODIB(color);
- }
- uint8_t* color_p = (uint8_t*)&dst_color;
- if (pIccTransform && CFX_GEModule::Get()->GetCodecModule() &&
- CFX_GEModule::Get()->GetCodecModule()->GetIccModule()) {
- CCodec_IccModule* pIccModule =
- CFX_GEModule::Get()->GetCodecModule()->GetIccModule();
- pIccModule->TranslateScanline(pIccTransform, color_p, color_p, 1);
- } else {
- if (alpha_flag >> 8 && !IsCmykImage()) {
- AdobeCMYK_to_sRGB1(FXSYS_GetCValue(color), FXSYS_GetMValue(color),
- FXSYS_GetYValue(color), FXSYS_GetKValue(color),
- color_p[2], color_p[1], color_p[0]);
- } else if (!(alpha_flag >> 8) && IsCmykImage()) {
- return false;
- }
- }
- if (!IsCmykImage()) {
- color_p[3] = (uint8_t)alpha;
- }
- if (GetFormat() == FXDIB_Argb) {
- for (int row = 0; row < height; row++) {
- uint32_t* dest_pos =
- (uint32_t*)(m_pBuffer + (dest_top + row) * m_Pitch + dest_left * 4);
- const uint8_t* src_scan = pMask->GetScanline(src_top + row);
- if (src_bpp == 1) {
- for (int col = 0; col < width; col++) {
- int src_bitpos = src_left + col;
- if (src_scan[src_bitpos / 8] & (1 << (7 - src_bitpos % 8))) {
- *dest_pos = dst_color;
- } else {
- *dest_pos = 0;
- }
- dest_pos++;
- }
- } else {
- src_scan += src_left;
- dst_color = FXARGB_TODIB(dst_color);
- dst_color &= 0xffffff;
- for (int col = 0; col < width; col++) {
- FXARGB_SETDIB(dest_pos++,
- dst_color | ((alpha * (*src_scan++) / 255) << 24));
- }
- }
- }
- } else {
- int comps = m_bpp / 8;
- for (int row = 0; row < height; row++) {
- uint8_t* dest_color_pos =
- m_pBuffer + (dest_top + row) * m_Pitch + dest_left * comps;
- uint8_t* dest_alpha_pos =
- (uint8_t*)m_pAlphaMask->GetScanline(dest_top + row) + dest_left;
- const uint8_t* src_scan = pMask->GetScanline(src_top + row);
- if (src_bpp == 1) {
- for (int col = 0; col < width; col++) {
- int src_bitpos = src_left + col;
- if (src_scan[src_bitpos / 8] & (1 << (7 - src_bitpos % 8))) {
- FXSYS_memcpy(dest_color_pos, color_p, comps);
- *dest_alpha_pos = 0xff;
- } else {
- FXSYS_memset(dest_color_pos, 0, comps);
- *dest_alpha_pos = 0;
- }
- dest_color_pos += comps;
- dest_alpha_pos++;
- }
- } else {
- src_scan += src_left;
- for (int col = 0; col < width; col++) {
- FXSYS_memcpy(dest_color_pos, color_p, comps);
- dest_color_pos += comps;
- *dest_alpha_pos++ = (alpha * (*src_scan++) / 255);
- }
- }
- }
- }
- return true;
-}
-
-void CFX_DIBSource::SetPalette(const uint32_t* pSrc) {
- static const uint32_t kPaletteSize = 256;
- if (!pSrc || GetBPP() > 8) {
- m_pPalette.reset();
- return;
- }
- uint32_t pal_size = 1 << GetBPP();
- if (!m_pPalette)
- m_pPalette.reset(FX_Alloc(uint32_t, pal_size));
- pal_size = std::min(pal_size, kPaletteSize);
- FXSYS_memcpy(m_pPalette.get(), pSrc, pal_size * sizeof(uint32_t));
-}
-
-void CFX_DIBSource::GetPalette(uint32_t* pal, int alpha) const {
- ASSERT(GetBPP() <= 8 && !IsCmykImage());
- if (GetBPP() == 1) {
- pal[0] = ((m_pPalette ? m_pPalette.get()[0] : 0xff000000) & 0xffffff) |
- (alpha << 24);
- pal[1] = ((m_pPalette ? m_pPalette.get()[1] : 0xffffffff) & 0xffffff) |
- (alpha << 24);
- return;
- }
- if (m_pPalette) {
- for (int i = 0; i < 256; i++) {
- pal[i] = (m_pPalette.get()[i] & 0x00ffffff) | (alpha << 24);
- }
- } else {
- for (int i = 0; i < 256; i++) {
- pal[i] = (i * 0x10101) | (alpha << 24);
- }
- }
-}
-
-std::unique_ptr<CFX_DIBitmap> CFX_DIBSource::CloneAlphaMask(
- const FX_RECT* pClip) const {
- ASSERT(GetFormat() == FXDIB_Argb);
- FX_RECT rect(0, 0, m_Width, m_Height);
- if (pClip) {
- rect.Intersect(*pClip);
- if (rect.IsEmpty())
- return nullptr;
- }
- auto pMask = pdfium::MakeUnique<CFX_DIBitmap>();
- if (!pMask->Create(rect.Width(), rect.Height(), FXDIB_8bppMask))
- return nullptr;
-
- for (int row = rect.top; row < rect.bottom; row++) {
- const uint8_t* src_scan = GetScanline(row) + rect.left * 4 + 3;
- uint8_t* dest_scan =
- const_cast<uint8_t*>(pMask->GetScanline(row - rect.top));
- for (int col = rect.left; col < rect.right; col++) {
- *dest_scan++ = *src_scan;
- src_scan += 4;
- }
- }
- return pMask;
-}
-
-bool CFX_DIBSource::SetAlphaMask(const CFX_DIBSource* pAlphaMask,
- const FX_RECT* pClip) {
- if (!HasAlpha() || GetFormat() == FXDIB_Argb)
- return false;
-
- if (!pAlphaMask) {
- m_pAlphaMask->Clear(0xff000000);
- return true;
- }
- FX_RECT rect(0, 0, pAlphaMask->m_Width, pAlphaMask->m_Height);
- if (pClip) {
- rect.Intersect(*pClip);
- if (rect.IsEmpty() || rect.Width() != m_Width ||
- rect.Height() != m_Height) {
- return false;
- }
- } else {
- if (pAlphaMask->m_Width != m_Width || pAlphaMask->m_Height != m_Height)
- return false;
- }
- for (int row = 0; row < m_Height; row++) {
- FXSYS_memcpy(const_cast<uint8_t*>(m_pAlphaMask->GetScanline(row)),
- pAlphaMask->GetScanline(row + rect.top) + rect.left,
- m_pAlphaMask->m_Pitch);
- }
- return true;
-}
-
-const int g_ChannelOffset[] = {0, 2, 1, 0, 0, 1, 2, 3, 3};
-bool CFX_DIBitmap::LoadChannel(FXDIB_Channel destChannel,
- CFX_DIBSource* pSrcBitmap,
- FXDIB_Channel srcChannel) {
- if (!m_pBuffer)
- return false;
-
- CFX_MaybeOwned<CFX_DIBSource> pSrcClone(pSrcBitmap);
- int srcOffset;
- if (srcChannel == FXDIB_Alpha) {
- if (!pSrcBitmap->HasAlpha() && !pSrcBitmap->IsAlphaMask())
- return false;
-
- if (pSrcBitmap->GetBPP() == 1) {
- pSrcClone = pSrcBitmap->CloneConvert(FXDIB_8bppMask);
- if (!pSrcClone)
- return false;
- }
- srcOffset = pSrcBitmap->GetFormat() == FXDIB_Argb ? 3 : 0;
- } else {
- if (pSrcBitmap->IsAlphaMask())
- return false;
-
- if (pSrcBitmap->GetBPP() < 24) {
- if (pSrcBitmap->IsCmykImage()) {
- pSrcClone = pSrcBitmap->CloneConvert(static_cast<FXDIB_Format>(
- (pSrcBitmap->GetFormat() & 0xff00) | 0x20));
- } else {
- pSrcClone = pSrcBitmap->CloneConvert(static_cast<FXDIB_Format>(
- (pSrcBitmap->GetFormat() & 0xff00) | 0x18));
- }
- if (!pSrcClone)
- return false;
- }
- srcOffset = g_ChannelOffset[srcChannel];
- }
- int destOffset = 0;
- if (destChannel == FXDIB_Alpha) {
- if (IsAlphaMask()) {
- if (!ConvertFormat(FXDIB_8bppMask))
- return false;
- } else {
- if (!ConvertFormat(IsCmykImage() ? FXDIB_Cmyka : FXDIB_Argb))
- return false;
-
- if (GetFormat() == FXDIB_Argb)
- destOffset = 3;
- }
- } else {
- if (IsAlphaMask())
- return false;
-
- if (GetBPP() < 24) {
- if (HasAlpha()) {
- if (!ConvertFormat(IsCmykImage() ? FXDIB_Cmyka : FXDIB_Argb))
- return false;
-#if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_
- } else if (!ConvertFormat(IsCmykImage() ? FXDIB_Cmyk : FXDIB_Rgb32)) {
-#else
- } else if (!ConvertFormat(IsCmykImage() ? FXDIB_Cmyk : FXDIB_Rgb)) {
-#endif
- return false;
- }
- }
- destOffset = g_ChannelOffset[destChannel];
- }
- if (srcChannel == FXDIB_Alpha && pSrcClone->m_pAlphaMask) {
- CFX_MaybeOwned<CFX_DIBSource> pAlphaMask(pSrcClone->m_pAlphaMask);
- if (pSrcClone->GetWidth() != m_Width ||
- pSrcClone->GetHeight() != m_Height) {
- if (pAlphaMask) {
- pAlphaMask = pAlphaMask->StretchTo(m_Width, m_Height);
- if (!pAlphaMask)
- return false;
- }
- }
- pSrcClone = std::move(pAlphaMask);
- srcOffset = 0;
- } else if (pSrcClone->GetWidth() != m_Width ||
- pSrcClone->GetHeight() != m_Height) {
- std::unique_ptr<CFX_DIBitmap> pSrcMatched =
- pSrcClone->StretchTo(m_Width, m_Height);
- if (!pSrcMatched)
- return false;
-
- pSrcClone = std::move(pSrcMatched);
- }
- CFX_DIBitmap* pDst = this;
- if (destChannel == FXDIB_Alpha && m_pAlphaMask) {
- pDst = m_pAlphaMask;
- destOffset = 0;
- }
- int srcBytes = pSrcClone->GetBPP() / 8;
- int destBytes = pDst->GetBPP() / 8;
- for (int row = 0; row < m_Height; row++) {
- uint8_t* dest_pos = (uint8_t*)pDst->GetScanline(row) + destOffset;
- const uint8_t* src_pos = pSrcClone->GetScanline(row) + srcOffset;
- for (int col = 0; col < m_Width; col++) {
- *dest_pos = *src_pos;
- dest_pos += destBytes;
- src_pos += srcBytes;
- }
- }
- return true;
-}
-
-bool CFX_DIBitmap::LoadChannel(FXDIB_Channel destChannel, int value) {
- if (!m_pBuffer) {
- return false;
- }
- int destOffset;
- if (destChannel == FXDIB_Alpha) {
- if (IsAlphaMask()) {
- if (!ConvertFormat(FXDIB_8bppMask)) {
- return false;
- }
- destOffset = 0;
- } else {
- destOffset = 0;
- if (!ConvertFormat(IsCmykImage() ? FXDIB_Cmyka : FXDIB_Argb)) {
- return false;
- }
- if (GetFormat() == FXDIB_Argb) {
- destOffset = 3;
- }
- }
- } else {
- if (IsAlphaMask()) {
- return false;
- }
- if (GetBPP() < 24) {
- if (HasAlpha()) {
- if (!ConvertFormat(IsCmykImage() ? FXDIB_Cmyka : FXDIB_Argb)) {
- return false;
- }
-#if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_
- } else if (!ConvertFormat(IsCmykImage() ? FXDIB_Cmyk : FXDIB_Rgb)) {
-#else
- } else if (!ConvertFormat(IsCmykImage() ? FXDIB_Cmyk : FXDIB_Rgb32)) {
-#endif
- return false;
- }
- }
- destOffset = g_ChannelOffset[destChannel];
- }
- int Bpp = GetBPP() / 8;
- if (Bpp == 1) {
- FXSYS_memset(m_pBuffer, value, m_Height * m_Pitch);
- return true;
- }
- if (destChannel == FXDIB_Alpha && m_pAlphaMask) {
- FXSYS_memset(m_pAlphaMask->GetBuffer(), value,
- m_pAlphaMask->GetHeight() * m_pAlphaMask->GetPitch());
- return true;
- }
- for (int row = 0; row < m_Height; row++) {
- uint8_t* scan_line = m_pBuffer + row * m_Pitch + destOffset;
- for (int col = 0; col < m_Width; col++) {
- *scan_line = value;
- scan_line += Bpp;
- }
- }
- return true;
-}
-
-bool CFX_DIBitmap::MultiplyAlpha(CFX_DIBSource* pSrcBitmap) {
- if (!m_pBuffer)
- return false;
-
- ASSERT(pSrcBitmap->IsAlphaMask());
- if (!pSrcBitmap->IsAlphaMask())
- return false;
-
- if (!IsAlphaMask() && !HasAlpha())
- return LoadChannel(FXDIB_Alpha, pSrcBitmap, FXDIB_Alpha);
-
- CFX_MaybeOwned<CFX_DIBitmap> pSrcClone(
- static_cast<CFX_DIBitmap*>(pSrcBitmap));
- if (pSrcBitmap->GetWidth() != m_Width ||
- pSrcBitmap->GetHeight() != m_Height) {
- pSrcClone = pSrcBitmap->StretchTo(m_Width, m_Height);
- if (!pSrcClone)
- return false;
- }
- if (IsAlphaMask()) {
- if (!ConvertFormat(FXDIB_8bppMask))
- return false;
-
- for (int row = 0; row < m_Height; row++) {
- uint8_t* dest_scan = m_pBuffer + m_Pitch * row;
- uint8_t* src_scan = pSrcClone->m_pBuffer + pSrcClone->m_Pitch * row;
- if (pSrcClone->GetBPP() == 1) {
- for (int col = 0; col < m_Width; col++) {
- if (!((1 << (7 - col % 8)) & src_scan[col / 8]))
- dest_scan[col] = 0;
- }
- } else {
- for (int col = 0; col < m_Width; col++) {
- *dest_scan = (*dest_scan) * src_scan[col] / 255;
- dest_scan++;
- }
- }
- }
- } else {
- if (GetFormat() == FXDIB_Argb) {
- if (pSrcClone->GetBPP() == 1)
- return false;
-
- for (int row = 0; row < m_Height; row++) {
- uint8_t* dest_scan = m_pBuffer + m_Pitch * row + 3;
- uint8_t* src_scan = pSrcClone->m_pBuffer + pSrcClone->m_Pitch * row;
- for (int col = 0; col < m_Width; col++) {
- *dest_scan = (*dest_scan) * src_scan[col] / 255;
- dest_scan += 4;
- }
- }
- } else {
- m_pAlphaMask->MultiplyAlpha(pSrcClone.Get());
- }
- }
- return true;
-}
-
-bool CFX_DIBitmap::GetGrayData(void* pIccTransform) {
- if (!m_pBuffer) {
- return false;
- }
- switch (GetFormat()) {
- case FXDIB_1bppRgb: {
- if (!m_pPalette) {
- return false;
- }
- uint8_t gray[2];
- for (int i = 0; i < 2; i++) {
- int r = static_cast<uint8_t>(m_pPalette.get()[i] >> 16);
- int g = static_cast<uint8_t>(m_pPalette.get()[i] >> 8);
- int b = static_cast<uint8_t>(m_pPalette.get()[i]);
- gray[i] = static_cast<uint8_t>(FXRGB2GRAY(r, g, b));
- }
- CFX_DIBitmap* pMask = new CFX_DIBitmap;
- if (!pMask->Create(m_Width, m_Height, FXDIB_8bppMask)) {
- delete pMask;
- return false;
- }
- FXSYS_memset(pMask->GetBuffer(), gray[0], pMask->GetPitch() * m_Height);
- for (int row = 0; row < m_Height; row++) {
- uint8_t* src_pos = m_pBuffer + row * m_Pitch;
- uint8_t* dest_pos = (uint8_t*)pMask->GetScanline(row);
- for (int col = 0; col < m_Width; col++) {
- if (src_pos[col / 8] & (1 << (7 - col % 8))) {
- *dest_pos = gray[1];
- }
- dest_pos++;
- }
- }
- TakeOver(pMask);
- delete pMask;
- break;
- }
- case FXDIB_8bppRgb: {
- if (!m_pPalette) {
- return false;
- }
- uint8_t gray[256];
- for (int i = 0; i < 256; i++) {
- int r = static_cast<uint8_t>(m_pPalette.get()[i] >> 16);
- int g = static_cast<uint8_t>(m_pPalette.get()[i] >> 8);
- int b = static_cast<uint8_t>(m_pPalette.get()[i]);
- gray[i] = static_cast<uint8_t>(FXRGB2GRAY(r, g, b));
- }
- CFX_DIBitmap* pMask = new CFX_DIBitmap;
- if (!pMask->Create(m_Width, m_Height, FXDIB_8bppMask)) {
- delete pMask;
- return false;
- }
- for (int row = 0; row < m_Height; row++) {
- uint8_t* dest_pos = pMask->GetBuffer() + row * pMask->GetPitch();
- uint8_t* src_pos = m_pBuffer + row * m_Pitch;
- for (int col = 0; col < m_Width; col++) {
- *dest_pos++ = gray[*src_pos++];
- }
- }
- TakeOver(pMask);
- delete pMask;
- break;
- }
- case FXDIB_Rgb: {
- CFX_DIBitmap* pMask = new CFX_DIBitmap;
- if (!pMask->Create(m_Width, m_Height, FXDIB_8bppMask)) {
- delete pMask;
- return false;
- }
- for (int row = 0; row < m_Height; row++) {
- uint8_t* src_pos = m_pBuffer + row * m_Pitch;
- uint8_t* dest_pos = pMask->GetBuffer() + row * pMask->GetPitch();
- for (int col = 0; col < m_Width; col++) {
- *dest_pos++ = FXRGB2GRAY(src_pos[2], src_pos[1], *src_pos);
- src_pos += 3;
- }
- }
- TakeOver(pMask);
- delete pMask;
- break;
- }
- case FXDIB_Rgb32: {
- CFX_DIBitmap* pMask = new CFX_DIBitmap;
- if (!pMask->Create(m_Width, m_Height, FXDIB_8bppMask)) {
- delete pMask;
- return false;
- }
- for (int row = 0; row < m_Height; row++) {
- uint8_t* src_pos = m_pBuffer + row * m_Pitch;
- uint8_t* dest_pos = pMask->GetBuffer() + row * pMask->GetPitch();
- for (int col = 0; col < m_Width; col++) {
- *dest_pos++ = FXRGB2GRAY(src_pos[2], src_pos[1], *src_pos);
- src_pos += 4;
- }
- }
- TakeOver(pMask);
- delete pMask;
- break;
- }
- default:
- return false;
- }
- return true;
-}
-
-bool CFX_DIBitmap::MultiplyAlpha(int alpha) {
- if (!m_pBuffer) {
- return false;
- }
- switch (GetFormat()) {
- case FXDIB_1bppMask:
- if (!ConvertFormat(FXDIB_8bppMask)) {
- return false;
- }
- MultiplyAlpha(alpha);
- break;
- case FXDIB_8bppMask: {
- for (int row = 0; row < m_Height; row++) {
- uint8_t* scan_line = m_pBuffer + row * m_Pitch;
- for (int col = 0; col < m_Width; col++) {
- scan_line[col] = scan_line[col] * alpha / 255;
- }
- }
- break;
- }
- case FXDIB_Argb: {
- for (int row = 0; row < m_Height; row++) {
- uint8_t* scan_line = m_pBuffer + row * m_Pitch + 3;
- for (int col = 0; col < m_Width; col++) {
- *scan_line = (*scan_line) * alpha / 255;
- scan_line += 4;
- }
- }
- break;
- }
- default:
- if (HasAlpha()) {
- m_pAlphaMask->MultiplyAlpha(alpha);
- } else if (IsCmykImage()) {
- if (!ConvertFormat((FXDIB_Format)(GetFormat() | 0x0200))) {
- return false;
- }
- m_pAlphaMask->MultiplyAlpha(alpha);
- } else {
- if (!ConvertFormat(FXDIB_Argb)) {
- return false;
- }
- MultiplyAlpha(alpha);
- }
- break;
- }
- return true;
-}
-
-uint32_t CFX_DIBitmap::GetPixel(int x, int y) const {
- if (!m_pBuffer) {
- return 0;
- }
- uint8_t* pos = m_pBuffer + y * m_Pitch + x * GetBPP() / 8;
- switch (GetFormat()) {
- case FXDIB_1bppMask: {
- if ((*pos) & (1 << (7 - x % 8))) {
- return 0xff000000;
- }
- return 0;
- }
- case FXDIB_1bppRgb: {
- if ((*pos) & (1 << (7 - x % 8))) {
- return m_pPalette ? m_pPalette.get()[1] : 0xffffffff;
- }
- return m_pPalette ? m_pPalette.get()[0] : 0xff000000;
- }
- case FXDIB_8bppMask:
- return (*pos) << 24;
- case FXDIB_8bppRgb:
- return m_pPalette ? m_pPalette.get()[*pos]
- : (0xff000000 | ((*pos) * 0x10101));
- case FXDIB_Rgb:
- case FXDIB_Rgba:
- case FXDIB_Rgb32:
- return FXARGB_GETDIB(pos) | 0xff000000;
- case FXDIB_Argb:
- return FXARGB_GETDIB(pos);
- default:
- break;
- }
- return 0;
-}
-
-void CFX_DIBitmap::SetPixel(int x, int y, uint32_t color) {
- if (!m_pBuffer) {
- return;
- }
- if (x < 0 || x >= m_Width || y < 0 || y >= m_Height) {
- return;
- }
- uint8_t* pos = m_pBuffer + y * m_Pitch + x * GetBPP() / 8;
- switch (GetFormat()) {
- case FXDIB_1bppMask:
- if (color >> 24) {
- *pos |= 1 << (7 - x % 8);
- } else {
- *pos &= ~(1 << (7 - x % 8));
- }
- break;
- case FXDIB_1bppRgb:
- if (m_pPalette) {
- if (color == m_pPalette.get()[1]) {
- *pos |= 1 << (7 - x % 8);
- } else {
- *pos &= ~(1 << (7 - x % 8));
- }
- } else {
- if (color == 0xffffffff) {
- *pos |= 1 << (7 - x % 8);
- } else {
- *pos &= ~(1 << (7 - x % 8));
- }
- }
- break;
- case FXDIB_8bppMask:
- *pos = (uint8_t)(color >> 24);
- break;
- case FXDIB_8bppRgb: {
- if (m_pPalette) {
- for (int i = 0; i < 256; i++) {
- if (m_pPalette.get()[i] == color) {
- *pos = (uint8_t)i;
- return;
- }
- }
- *pos = 0;
- } else {
- *pos = FXRGB2GRAY(FXARGB_R(color), FXARGB_G(color), FXARGB_B(color));
- }
- break;
- }
- case FXDIB_Rgb:
- case FXDIB_Rgb32: {
- int alpha = FXARGB_A(color);
- pos[0] = (FXARGB_B(color) * alpha + pos[0] * (255 - alpha)) / 255;
- pos[1] = (FXARGB_G(color) * alpha + pos[1] * (255 - alpha)) / 255;
- pos[2] = (FXARGB_R(color) * alpha + pos[2] * (255 - alpha)) / 255;
- break;
- }
- case FXDIB_Rgba: {
- pos[0] = FXARGB_B(color);
- pos[1] = FXARGB_G(color);
- pos[2] = FXARGB_R(color);
- break;
- }
- case FXDIB_Argb:
- FXARGB_SETDIB(pos, color);
- break;
- default:
- break;
- }
-}
-
-void CFX_DIBitmap::DownSampleScanline(int line,
- uint8_t* dest_scan,
- int dest_bpp,
- int dest_width,
- bool bFlipX,
- int clip_left,
- int clip_width) const {
- if (!m_pBuffer) {
- return;
- }
- int src_Bpp = m_bpp / 8;
- uint8_t* scanline = m_pBuffer + line * m_Pitch;
- if (src_Bpp == 0) {
- for (int i = 0; i < clip_width; i++) {
- uint32_t dest_x = clip_left + i;
- uint32_t src_x = dest_x * m_Width / dest_width;
- if (bFlipX) {
- src_x = m_Width - src_x - 1;
- }
- src_x %= m_Width;
- dest_scan[i] = (scanline[src_x / 8] & (1 << (7 - src_x % 8))) ? 255 : 0;
- }
- } else if (src_Bpp == 1) {
- for (int i = 0; i < clip_width; i++) {
- uint32_t dest_x = clip_left + i;
- uint32_t src_x = dest_x * m_Width / dest_width;
- if (bFlipX) {
- src_x = m_Width - src_x - 1;
- }
- src_x %= m_Width;
- int dest_pos = i;
- if (m_pPalette) {
- if (!IsCmykImage()) {
- dest_pos *= 3;
- FX_ARGB argb = m_pPalette.get()[scanline[src_x]];
- dest_scan[dest_pos] = FXARGB_B(argb);
- dest_scan[dest_pos + 1] = FXARGB_G(argb);
- dest_scan[dest_pos + 2] = FXARGB_R(argb);
- } else {
- dest_pos *= 4;
- FX_CMYK cmyk = m_pPalette.get()[scanline[src_x]];
- dest_scan[dest_pos] = FXSYS_GetCValue(cmyk);
- dest_scan[dest_pos + 1] = FXSYS_GetMValue(cmyk);
- dest_scan[dest_pos + 2] = FXSYS_GetYValue(cmyk);
- dest_scan[dest_pos + 3] = FXSYS_GetKValue(cmyk);
- }
- } else {
- dest_scan[dest_pos] = scanline[src_x];
- }
- }
- } else {
- for (int i = 0; i < clip_width; i++) {
- uint32_t dest_x = clip_left + i;
- uint32_t src_x =
- bFlipX ? (m_Width - dest_x * m_Width / dest_width - 1) * src_Bpp
- : (dest_x * m_Width / dest_width) * src_Bpp;
- src_x %= m_Width * src_Bpp;
- int dest_pos = i * src_Bpp;
- for (int b = 0; b < src_Bpp; b++) {
- dest_scan[dest_pos + b] = scanline[src_x + b];
- }
- }
- }
-}
-
-// TODO(weili): Split this function into two for handling CMYK and RGB
-// colors separately.
-bool CFX_DIBitmap::ConvertColorScale(uint32_t forecolor, uint32_t backcolor) {
- ASSERT(!IsAlphaMask());
- if (!m_pBuffer || IsAlphaMask()) {
- return false;
- }
- // Values used for CMYK colors.
- int fc = 0;
- int fm = 0;
- int fy = 0;
- int fk = 0;
- int bc = 0;
- int bm = 0;
- int by = 0;
- int bk = 0;
- // Values used for RGB colors.
- int fr = 0;
- int fg = 0;
- int fb = 0;
- int br = 0;
- int bg = 0;
- int bb = 0;
- bool isCmykImage = IsCmykImage();
- if (isCmykImage) {
- fc = FXSYS_GetCValue(forecolor);
- fm = FXSYS_GetMValue(forecolor);
- fy = FXSYS_GetYValue(forecolor);
- fk = FXSYS_GetKValue(forecolor);
- bc = FXSYS_GetCValue(backcolor);
- bm = FXSYS_GetMValue(backcolor);
- by = FXSYS_GetYValue(backcolor);
- bk = FXSYS_GetKValue(backcolor);
- } else {
- fr = FXSYS_GetRValue(forecolor);
- fg = FXSYS_GetGValue(forecolor);
- fb = FXSYS_GetBValue(forecolor);
- br = FXSYS_GetRValue(backcolor);
- bg = FXSYS_GetGValue(backcolor);
- bb = FXSYS_GetBValue(backcolor);
- }
- if (m_bpp <= 8) {
- if (isCmykImage) {
- if (forecolor == 0xff && backcolor == 0 && !m_pPalette) {
- return true;
- }
- } else if (forecolor == 0 && backcolor == 0xffffff && !m_pPalette) {
- return true;
- }
- if (!m_pPalette) {
- BuildPalette();
- }
- int size = 1 << m_bpp;
- if (isCmykImage) {
- for (int i = 0; i < size; i++) {
- uint8_t b, g, r;
- AdobeCMYK_to_sRGB1(FXSYS_GetCValue(m_pPalette.get()[i]),
- FXSYS_GetMValue(m_pPalette.get()[i]),
- FXSYS_GetYValue(m_pPalette.get()[i]),
- FXSYS_GetKValue(m_pPalette.get()[i]), r, g, b);
- int gray = 255 - FXRGB2GRAY(r, g, b);
- m_pPalette.get()[i] = CmykEncode(
- bc + (fc - bc) * gray / 255, bm + (fm - bm) * gray / 255,
- by + (fy - by) * gray / 255, bk + (fk - bk) * gray / 255);
- }
- } else {
- for (int i = 0; i < size; i++) {
- int gray = FXRGB2GRAY(FXARGB_R(m_pPalette.get()[i]),
- FXARGB_G(m_pPalette.get()[i]),
- FXARGB_B(m_pPalette.get()[i]));
- m_pPalette.get()[i] = FXARGB_MAKE(0xff, br + (fr - br) * gray / 255,
- bg + (fg - bg) * gray / 255,
- bb + (fb - bb) * gray / 255);
- }
- }
- return true;
- }
- if (isCmykImage) {
- if (forecolor == 0xff && backcolor == 0x00) {
- for (int row = 0; row < m_Height; row++) {
- uint8_t* scanline = m_pBuffer + row * m_Pitch;
- for (int col = 0; col < m_Width; col++) {
- uint8_t b, g, r;
- AdobeCMYK_to_sRGB1(scanline[0], scanline[1], scanline[2], scanline[3],
- r, g, b);
- *scanline++ = 0;
- *scanline++ = 0;
- *scanline++ = 0;
- *scanline++ = 255 - FXRGB2GRAY(r, g, b);
- }
- }
- return true;
- }
- } else if (forecolor == 0 && backcolor == 0xffffff) {
- for (int row = 0; row < m_Height; row++) {
- uint8_t* scanline = m_pBuffer + row * m_Pitch;
- int gap = m_bpp / 8 - 2;
- for (int col = 0; col < m_Width; col++) {
- int gray = FXRGB2GRAY(scanline[2], scanline[1], scanline[0]);
- *scanline++ = gray;
- *scanline++ = gray;
- *scanline = gray;
- scanline += gap;
- }
- }
- return true;
- }
- if (isCmykImage) {
- for (int row = 0; row < m_Height; row++) {
- uint8_t* scanline = m_pBuffer + row * m_Pitch;
- for (int col = 0; col < m_Width; col++) {
- uint8_t b, g, r;
- AdobeCMYK_to_sRGB1(scanline[0], scanline[1], scanline[2], scanline[3],
- r, g, b);
- int gray = 255 - FXRGB2GRAY(r, g, b);
- *scanline++ = bc + (fc - bc) * gray / 255;
- *scanline++ = bm + (fm - bm) * gray / 255;
- *scanline++ = by + (fy - by) * gray / 255;
- *scanline++ = bk + (fk - bk) * gray / 255;
- }
- }
- } else {
- for (int row = 0; row < m_Height; row++) {
- uint8_t* scanline = m_pBuffer + row * m_Pitch;
- int gap = m_bpp / 8 - 2;
- for (int col = 0; col < m_Width; col++) {
- int gray = FXRGB2GRAY(scanline[2], scanline[1], scanline[0]);
- *scanline++ = bb + (fb - bb) * gray / 255;
- *scanline++ = bg + (fg - bg) * gray / 255;
- *scanline = br + (fr - br) * gray / 255;
- scanline += gap;
- }
- }
- }
- return true;
-}
-
-std::unique_ptr<CFX_DIBitmap> CFX_DIBSource::FlipImage(bool bXFlip,
- bool bYFlip) const {
- auto pFlipped = pdfium::MakeUnique<CFX_DIBitmap>();
- if (!pFlipped->Create(m_Width, m_Height, GetFormat()))
- return nullptr;
-
- pFlipped->SetPalette(m_pPalette.get());
- uint8_t* pDestBuffer = pFlipped->GetBuffer();
- int Bpp = m_bpp / 8;
- for (int row = 0; row < m_Height; row++) {
- const uint8_t* src_scan = GetScanline(row);
- uint8_t* dest_scan =
- pDestBuffer + m_Pitch * (bYFlip ? (m_Height - row - 1) : row);
- if (!bXFlip) {
- FXSYS_memcpy(dest_scan, src_scan, m_Pitch);
- continue;
- }
- if (m_bpp == 1) {
- FXSYS_memset(dest_scan, 0, m_Pitch);
- for (int col = 0; col < m_Width; col++)
- if (src_scan[col / 8] & (1 << (7 - col % 8))) {
- int dest_col = m_Width - col - 1;
- dest_scan[dest_col / 8] |= (1 << (7 - dest_col % 8));
- }
- } else {
- dest_scan += (m_Width - 1) * Bpp;
- if (Bpp == 1) {
- for (int col = 0; col < m_Width; col++) {
- *dest_scan = *src_scan;
- dest_scan--;
- src_scan++;
- }
- } else if (Bpp == 3) {
- for (int col = 0; col < m_Width; col++) {
- dest_scan[0] = src_scan[0];
- dest_scan[1] = src_scan[1];
- dest_scan[2] = src_scan[2];
- dest_scan -= 3;
- src_scan += 3;
- }
- } else {
- ASSERT(Bpp == 4);
- for (int col = 0; col < m_Width; col++) {
- *(uint32_t*)dest_scan = *(uint32_t*)src_scan;
- dest_scan -= 4;
- src_scan += 4;
- }
- }
- }
- }
- if (m_pAlphaMask) {
- pDestBuffer = pFlipped->m_pAlphaMask->GetBuffer();
- uint32_t dest_pitch = pFlipped->m_pAlphaMask->GetPitch();
- for (int row = 0; row < m_Height; row++) {
- const uint8_t* src_scan = m_pAlphaMask->GetScanline(row);
- uint8_t* dest_scan =
- pDestBuffer + dest_pitch * (bYFlip ? (m_Height - row - 1) : row);
- if (!bXFlip) {
- FXSYS_memcpy(dest_scan, src_scan, dest_pitch);
- continue;
- }
- dest_scan += (m_Width - 1);
- for (int col = 0; col < m_Width; col++) {
- *dest_scan = *src_scan;
- dest_scan--;
- src_scan++;
- }
- }
- }
- return pFlipped;
-}
-
-CFX_DIBExtractor::CFX_DIBExtractor(const CFX_DIBSource* pSrc) {
- if (pSrc->GetBuffer()) {
- m_pBitmap = pdfium::MakeUnique<CFX_DIBitmap>();
- if (!m_pBitmap->Create(pSrc->GetWidth(), pSrc->GetHeight(),
- pSrc->GetFormat(), pSrc->GetBuffer())) {
- m_pBitmap.reset();
- return;
- }
- m_pBitmap->SetPalette(pSrc->GetPalette());
- m_pBitmap->SetAlphaMask(pSrc->m_pAlphaMask);
- } else {
- m_pBitmap = pSrc->Clone();
- }
-}
-
-CFX_DIBExtractor::~CFX_DIBExtractor() {}
-
-CFX_FilteredDIB::CFX_FilteredDIB() : m_pSrc(nullptr) {}
-
-CFX_FilteredDIB::~CFX_FilteredDIB() {
- if (m_bAutoDropSrc) {
- delete m_pSrc;
- }
-}
-
-void CFX_FilteredDIB::LoadSrc(const CFX_DIBSource* pSrc, bool bAutoDropSrc) {
- m_pSrc = pSrc;
- m_bAutoDropSrc = bAutoDropSrc;
- m_Width = pSrc->GetWidth();
- m_Height = pSrc->GetHeight();
- FXDIB_Format format = GetDestFormat();
- m_bpp = (uint8_t)format;
- m_AlphaFlag = (uint8_t)(format >> 8);
- m_Pitch = (m_Width * (format & 0xff) + 31) / 32 * 4;
- m_pPalette.reset(GetDestPalette());
- m_Scanline.resize(m_Pitch);
-}
-
-const uint8_t* CFX_FilteredDIB::GetScanline(int line) const {
- TranslateScanline(m_pSrc->GetScanline(line), &m_Scanline);
- return m_Scanline.data();
-}
-
-void CFX_FilteredDIB::DownSampleScanline(int line,
- uint8_t* dest_scan,
- int dest_bpp,
- int dest_width,
- bool bFlipX,
- int clip_left,
- int clip_width) const {
- m_pSrc->DownSampleScanline(line, dest_scan, dest_bpp, dest_width, bFlipX,
- clip_left, clip_width);
- TranslateDownSamples(dest_scan, dest_scan, clip_width, dest_bpp);
-}
-
-CFX_ImageRenderer::CFX_ImageRenderer() {
- m_Status = 0;
- m_pIccTransform = nullptr;
- m_bRgbByteOrder = false;
- m_BlendType = FXDIB_BLEND_NORMAL;
-}
-
-CFX_ImageRenderer::~CFX_ImageRenderer() {}
-
-bool CFX_ImageRenderer::Start(CFX_DIBitmap* pDevice,
- const CFX_ClipRgn* pClipRgn,
- const CFX_DIBSource* pSource,
- int bitmap_alpha,
- uint32_t mask_color,
- const CFX_Matrix* pMatrix,
- uint32_t dib_flags,
- bool bRgbByteOrder,
- int alpha_flag,
- void* pIccTransform,
- int blend_type) {
- m_Matrix = *pMatrix;
- CFX_FloatRect image_rect_f = m_Matrix.GetUnitRect();
- FX_RECT image_rect = image_rect_f.GetOuterRect();
- m_ClipBox = pClipRgn ? pClipRgn->GetBox() : FX_RECT(0, 0, pDevice->GetWidth(),
- pDevice->GetHeight());
- m_ClipBox.Intersect(image_rect);
- if (m_ClipBox.IsEmpty())
- return false;
-
- m_pDevice = pDevice;
- m_pClipRgn = pClipRgn;
- m_MaskColor = mask_color;
- m_BitmapAlpha = bitmap_alpha;
- m_Matrix = *pMatrix;
- m_Flags = dib_flags;
- m_AlphaFlag = alpha_flag;
- m_pIccTransform = pIccTransform;
- m_bRgbByteOrder = bRgbByteOrder;
- m_BlendType = blend_type;
-
- if ((FXSYS_fabs(m_Matrix.b) >= 0.5f || m_Matrix.a == 0) ||
- (FXSYS_fabs(m_Matrix.c) >= 0.5f || m_Matrix.d == 0)) {
- if (FXSYS_fabs(m_Matrix.a) < FXSYS_fabs(m_Matrix.b) / 20 &&
- FXSYS_fabs(m_Matrix.d) < FXSYS_fabs(m_Matrix.c) / 20 &&
- FXSYS_fabs(m_Matrix.a) < 0.5f && FXSYS_fabs(m_Matrix.d) < 0.5f) {
- int dest_width = image_rect.Width();
- int dest_height = image_rect.Height();
- FX_RECT bitmap_clip = m_ClipBox;
- bitmap_clip.Offset(-image_rect.left, -image_rect.top);
- bitmap_clip = FXDIB_SwapClipBox(bitmap_clip, dest_width, dest_height,
- m_Matrix.c > 0, m_Matrix.b < 0);
- m_Composer.Compose(pDevice, pClipRgn, bitmap_alpha, mask_color, m_ClipBox,
- true, m_Matrix.c > 0, m_Matrix.b < 0, m_bRgbByteOrder,
- alpha_flag, pIccTransform, m_BlendType);
- m_Stretcher = pdfium::MakeUnique<CFX_ImageStretcher>(
- &m_Composer, pSource, dest_height, dest_width, bitmap_clip,
- dib_flags);
- if (!m_Stretcher->Start())
- return false;
-
- m_Status = 1;
- return true;
- }
- m_Status = 2;
- m_pTransformer.reset(
- new CFX_ImageTransformer(pSource, &m_Matrix, dib_flags, &m_ClipBox));
- m_pTransformer->Start();
- return true;
- }
-
- int dest_width = image_rect.Width();
- if (m_Matrix.a < 0)
- dest_width = -dest_width;
-
- int dest_height = image_rect.Height();
- if (m_Matrix.d > 0)
- dest_height = -dest_height;
-
- if (dest_width == 0 || dest_height == 0)
- return false;
-
- FX_RECT bitmap_clip = m_ClipBox;
- bitmap_clip.Offset(-image_rect.left, -image_rect.top);
- m_Composer.Compose(pDevice, pClipRgn, bitmap_alpha, mask_color, m_ClipBox,
- false, false, false, m_bRgbByteOrder, alpha_flag,
- pIccTransform, m_BlendType);
- m_Status = 1;
- m_Stretcher = pdfium::MakeUnique<CFX_ImageStretcher>(
- &m_Composer, pSource, dest_width, dest_height, bitmap_clip, dib_flags);
- return m_Stretcher->Start();
-}
-
-bool CFX_ImageRenderer::Continue(IFX_Pause* pPause) {
- if (m_Status == 1)
- return m_Stretcher->Continue(pPause);
-
- if (m_Status == 2) {
- if (m_pTransformer->Continue(pPause))
- return true;
-
- std::unique_ptr<CFX_DIBitmap> pBitmap(m_pTransformer->DetachBitmap());
- if (!pBitmap || !pBitmap->GetBuffer())
- return false;
-
- if (pBitmap->IsAlphaMask()) {
- if (m_BitmapAlpha != 255) {
- if (m_AlphaFlag >> 8) {
- m_AlphaFlag =
- (((uint8_t)((m_AlphaFlag & 0xff) * m_BitmapAlpha / 255)) |
- ((m_AlphaFlag >> 8) << 8));
- } else {
- m_MaskColor = FXARGB_MUL_ALPHA(m_MaskColor, m_BitmapAlpha);
- }
- }
- m_pDevice->CompositeMask(
- m_pTransformer->result().left, m_pTransformer->result().top,
- pBitmap->GetWidth(), pBitmap->GetHeight(), pBitmap.get(), m_MaskColor,
- 0, 0, m_BlendType, m_pClipRgn, m_bRgbByteOrder, m_AlphaFlag,
- m_pIccTransform);
- } else {
- if (m_BitmapAlpha != 255)
- pBitmap->MultiplyAlpha(m_BitmapAlpha);
- m_pDevice->CompositeBitmap(
- m_pTransformer->result().left, m_pTransformer->result().top,
- pBitmap->GetWidth(), pBitmap->GetHeight(), pBitmap.get(), 0, 0,
- m_BlendType, m_pClipRgn, m_bRgbByteOrder, m_pIccTransform);
- }
- return false;
- }
- return false;
-}
-
-CFX_BitmapStorer::CFX_BitmapStorer() {
-}
-
-CFX_BitmapStorer::~CFX_BitmapStorer() {
-}
-
-std::unique_ptr<CFX_DIBitmap> CFX_BitmapStorer::Detach() {
- return std::move(m_pBitmap);
-}
-
-void CFX_BitmapStorer::Replace(std::unique_ptr<CFX_DIBitmap> pBitmap) {
- m_pBitmap = std::move(pBitmap);
-}
-
-void CFX_BitmapStorer::ComposeScanline(int line,
- const uint8_t* scanline,
- const uint8_t* scan_extra_alpha) {
- uint8_t* dest_buf = const_cast<uint8_t*>(m_pBitmap->GetScanline(line));
- uint8_t* dest_alpha_buf =
- m_pBitmap->m_pAlphaMask
- ? const_cast<uint8_t*>(m_pBitmap->m_pAlphaMask->GetScanline(line))
- : nullptr;
- if (dest_buf)
- FXSYS_memcpy(dest_buf, scanline, m_pBitmap->GetPitch());
-
- if (dest_alpha_buf) {
- FXSYS_memcpy(dest_alpha_buf, scan_extra_alpha,
- m_pBitmap->m_pAlphaMask->GetPitch());
- }
-}
-
-bool CFX_BitmapStorer::SetInfo(int width,
- int height,
- FXDIB_Format src_format,
- uint32_t* pSrcPalette) {
- m_pBitmap = pdfium::MakeUnique<CFX_DIBitmap>();
- if (!m_pBitmap->Create(width, height, src_format)) {
- m_pBitmap.reset();
- return false;
- }
- if (pSrcPalette)
- m_pBitmap->SetPalette(pSrcPalette);
- return true;
-}
diff --git a/chromium/third_party/pdfium/core/fxge/dib/ifx_scanlinecomposer.h b/chromium/third_party/pdfium/core/fxge/dib/ifx_scanlinecomposer.h
new file mode 100644
index 00000000000..7b070c02ff8
--- /dev/null
+++ b/chromium/third_party/pdfium/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) = 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/chromium/third_party/pdfium/core/fxge/freetype/DEPS b/chromium/third_party/pdfium/core/fxge/freetype/DEPS
index 26546f7920c..38478a5b4a5 100644
--- a/chromium/third_party/pdfium/core/fxge/freetype/DEPS
+++ b/chromium/third_party/pdfium/core/fxge/freetype/DEPS
@@ -1,3 +1,3 @@
include_rules = [
- '+third_party/freetype/src'
+ '+third_party/freetype/src/src'
]
diff --git a/chromium/third_party/pdfium/core/fxge/freetype/fx_freetype.cpp b/chromium/third_party/pdfium/core/fxge/freetype/fx_freetype.cpp
index 6aa59fee68a..0ae207b0212 100644
--- a/chromium/third_party/pdfium/core/fxge/freetype/fx_freetype.cpp
+++ b/chromium/third_party/pdfium/core/fxge/freetype/fx_freetype.cpp
@@ -6,7 +6,7 @@
#include "core/fxge/fx_freetype.h"
-#include "third_party/freetype/src/psnames/pstables.h"
+#include "third_party/freetype/src/src/psnames/pstables.h"
static int xyq_search_node(char* glyph_name,
int name_offset,
diff --git a/chromium/third_party/pdfium/core/fxge/fx_dib.h b/chromium/third_party/pdfium/core/fxge/fx_dib.h
index 14be05fafe8..17c7c8fd0a2 100644
--- a/chromium/third_party/pdfium/core/fxge/fx_dib.h
+++ b/chromium/third_party/pdfium/core/fxge/fx_dib.h
@@ -7,42 +7,41 @@
#ifndef CORE_FXGE_FX_DIB_H_
#define CORE_FXGE_FX_DIB_H_
-#include <memory>
-#include <vector>
-
-#include "core/fxcrt/cfx_shared_copy_on_write.h"
-#include "core/fxcrt/fx_basic.h"
#include "core/fxcrt/fx_coordinates.h"
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_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,
};
-enum FXDIB_Channel {
- FXDIB_Red = 1,
- FXDIB_Green,
- FXDIB_Blue,
- FXDIB_Cyan,
- FXDIB_Magenta,
- FXDIB_Yellow,
- FXDIB_Black,
- FXDIB_Alpha
+struct PixelWeight {
+ int m_SrcStart;
+ int m_SrcEnd;
+ int m_Weights[1];
};
+typedef uint32_t FX_ARGB;
+typedef uint32_t FX_COLORREF;
+typedef uint32_t FX_CMYK;
+class CFX_ClipRgn;
+class CFX_DIBSource;
+class CStretchEngine;
+
+extern const int16_t SDP_Table[513];
+
#define FXDIB_DOWNSAMPLE 0x04
#define FXDIB_INTERPOL 0x20
#define FXDIB_BICUBIC_INTERPOL 0x80
@@ -66,28 +65,21 @@ enum FXDIB_Channel {
#define FXDIB_BLEND_COLOR 23
#define FXDIB_BLEND_LUMINOSITY 24
#define FXDIB_BLEND_UNSUPPORTED -1
-typedef uint32_t FX_ARGB;
-typedef uint32_t FX_COLORREF;
-typedef uint32_t FX_CMYK;
-class CFX_ClipRgn;
-class CFX_DIBSource;
-class CFX_DIBitmap;
-class CStretchEngine;
#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) {
@@ -102,21 +94,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))
@@ -125,29 +106,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 | \
@@ -158,540 +121,10 @@ 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_DIBSource* pSrcBitmap,
- int src_left,
- int src_top,
- std::unique_ptr<uint32_t, FxFreeDeleter>* pal);
-
-class CFX_DIBSource {
- public:
- virtual ~CFX_DIBSource();
-
- virtual uint8_t* GetBuffer() const;
- virtual const uint8_t* GetScanline(int line) const = 0;
- virtual bool SkipToScanline(int line, IFX_Pause* pPause) const;
- virtual void DownSampleScanline(int line,
- uint8_t* dest_scan,
- int dest_bpp,
- int dest_width,
- bool bFlipX,
- int clip_left,
- int clip_width) const = 0;
-
- int GetWidth() const { return m_Width; }
- int GetHeight() const { return m_Height; }
-
- FXDIB_Format GetFormat() const {
- return (FXDIB_Format)(m_AlphaFlag * 0x100 + m_bpp);
- }
- uint32_t GetPitch() const { return m_Pitch; }
- uint32_t* GetPalette() const { return m_pPalette.get(); }
- int GetBPP() const { return m_bpp; }
-
- // TODO(thestig): Investigate this. Given the possible values of FXDIB_Format,
- // it feels as though this should be implemented as !!(m_AlphaFlag & 1) and
- // IsOpaqueImage() below should never be able to return true.
- bool IsAlphaMask() const { return m_AlphaFlag == 1; }
- bool HasAlpha() const { return !!(m_AlphaFlag & 2); }
- bool IsOpaqueImage() const { return !(m_AlphaFlag & 3); }
- bool IsCmykImage() const { return !!(m_AlphaFlag & 4); }
-
- int GetPaletteSize() const {
- return IsAlphaMask() ? 0 : (m_bpp == 1 ? 2 : (m_bpp == 8 ? 256 : 0));
- }
-
- uint32_t GetPaletteEntry(int index) const;
-
- void SetPaletteEntry(int index, uint32_t color);
- uint32_t GetPaletteArgb(int index) const { return GetPaletteEntry(index); }
- void SetPaletteArgb(int index, uint32_t color) {
- SetPaletteEntry(index, color);
- }
-
- // Copies into internally-owned palette.
- void SetPalette(const uint32_t* pSrcPal);
-
- std::unique_ptr<CFX_DIBitmap> Clone(const FX_RECT* pClip = nullptr) const;
- std::unique_ptr<CFX_DIBitmap> CloneConvert(FXDIB_Format format) const;
- std::unique_ptr<CFX_DIBitmap> StretchTo(int dest_width,
- int dest_height,
- uint32_t flags = 0,
- const FX_RECT* pClip = nullptr) const;
- std::unique_ptr<CFX_DIBitmap> TransformTo(
- const CFX_Matrix* pMatrix,
- int& left,
- int& top,
- uint32_t flags = 0,
- const FX_RECT* pClip = nullptr) const;
- std::unique_ptr<CFX_DIBitmap> SwapXY(bool bXFlip,
- bool bYFlip,
- const FX_RECT* pClip = nullptr) const;
- std::unique_ptr<CFX_DIBitmap> FlipImage(bool bXFlip, bool bYFlip) const;
-
- std::unique_ptr<CFX_DIBitmap> CloneAlphaMask(
- const FX_RECT* pClip = nullptr) const;
-
- // Copies into internally-owned mask.
- bool SetAlphaMask(const CFX_DIBSource* pAlphaMask,
- const FX_RECT* pClip = nullptr);
-
-
- void GetOverlapRect(int& dest_left,
- int& dest_top,
- int& width,
- int& height,
- int src_width,
- int src_height,
- int& src_left,
- int& src_top,
- const CFX_ClipRgn* pClipRgn);
-
-#if defined _SKIA_SUPPORT_ || defined _SKIA_SUPPORT_PATHS_
- void DebugVerifyBitmapIsPreMultiplied(void* buffer = nullptr) const;
-#endif
-
- CFX_DIBitmap* m_pAlphaMask;
-
- protected:
- CFX_DIBSource();
-
- void BuildPalette();
- bool BuildAlphaMask();
- int FindPalette(uint32_t color) const;
- void GetPalette(uint32_t* pal, int alpha) const;
-
- int m_Width;
- int m_Height;
- int m_bpp;
- uint32_t m_AlphaFlag;
- uint32_t m_Pitch;
- // TODO(weili): Use std::vector for this.
- std::unique_ptr<uint32_t, FxFreeDeleter> m_pPalette;
-};
-
-class CFX_DIBitmap : public CFX_DIBSource {
- public:
- CFX_DIBitmap();
- explicit CFX_DIBitmap(const CFX_DIBitmap& src);
- ~CFX_DIBitmap() override;
-
- bool Create(int width,
- int height,
- FXDIB_Format format,
- uint8_t* pBuffer = nullptr,
- int pitch = 0);
-
- bool Copy(const CFX_DIBSource* pSrc);
-
- // CFX_DIBSource
- uint8_t* GetBuffer() const override;
- const uint8_t* GetScanline(int line) const override;
- void DownSampleScanline(int line,
- uint8_t* dest_scan,
- int dest_bpp,
- int dest_width,
- bool bFlipX,
- int clip_left,
- int clip_width) const override;
-
- void TakeOver(CFX_DIBitmap* pSrcBitmap);
-
- bool ConvertFormat(FXDIB_Format format);
-
- void Clear(uint32_t color);
-
- uint32_t GetPixel(int x, int y) const;
-
- void SetPixel(int x, int y, uint32_t color);
-
- bool LoadChannel(FXDIB_Channel destChannel,
- CFX_DIBSource* pSrcBitmap,
- FXDIB_Channel srcChannel);
-
- bool LoadChannel(FXDIB_Channel destChannel, int value);
-
- bool MultiplyAlpha(int alpha);
-
- bool MultiplyAlpha(CFX_DIBSource* pAlphaMask);
-
- bool TransferBitmap(int dest_left,
- int dest_top,
- int width,
- int height,
- const CFX_DIBSource* pSrcBitmap,
- int src_left,
- int src_top);
-
- bool CompositeBitmap(int dest_left,
- int dest_top,
- int width,
- int height,
- const CFX_DIBSource* pSrcBitmap,
- int src_left,
- int src_top,
- int blend_type = FXDIB_BLEND_NORMAL,
- const CFX_ClipRgn* pClipRgn = nullptr,
- bool bRgbByteOrder = false,
- void* pIccTransform = nullptr);
-
- bool TransferMask(int dest_left,
- int dest_top,
- int width,
- int height,
- const CFX_DIBSource* pMask,
- uint32_t color,
- int src_left,
- int src_top,
- int alpha_flag = 0,
- void* pIccTransform = nullptr);
-
- bool CompositeMask(int dest_left,
- int dest_top,
- int width,
- int height,
- const CFX_DIBSource* pMask,
- uint32_t color,
- int src_left,
- int src_top,
- int blend_type = FXDIB_BLEND_NORMAL,
- const CFX_ClipRgn* pClipRgn = nullptr,
- bool bRgbByteOrder = false,
- int alpha_flag = 0,
- void* pIccTransform = nullptr);
-
- bool CompositeRect(int dest_left,
- int dest_top,
- int width,
- int height,
- uint32_t color,
- int alpha_flag = 0,
- void* pIccTransform = nullptr);
-
- bool ConvertColorScale(uint32_t forecolor, uint32_t backcolor);
-
-#if defined _SKIA_SUPPORT_ || _SKIA_SUPPORT_PATHS_
- void PreMultiply();
-#endif
-#if defined _SKIA_SUPPORT_PATHS_
- void UnPreMultiply();
-#endif
-
- protected:
- bool GetGrayData(void* pIccTransform = nullptr);
-
-#if defined _SKIA_SUPPORT_PATHS_
- enum class Format { kCleared, kPreMultiplied, kUnPreMultiplied };
-#endif
-
- uint8_t* m_pBuffer;
-#if defined _SKIA_SUPPORT_PATHS_
- Format m_nFormat;
-#endif
- bool m_bExtBuf;
-};
-
-class CFX_DIBExtractor {
- public:
- explicit CFX_DIBExtractor(const CFX_DIBSource* pSrc);
- ~CFX_DIBExtractor();
-
- CFX_DIBitmap* GetBitmap() { return m_pBitmap.get(); }
-
- private:
- std::unique_ptr<CFX_DIBitmap> m_pBitmap;
-};
-
-typedef CFX_SharedCopyOnWrite<CFX_DIBitmap> CFX_DIBitmapRef;
-
-class CFX_FilteredDIB : public CFX_DIBSource {
- public:
- CFX_FilteredDIB();
- ~CFX_FilteredDIB() override;
-
- void LoadSrc(const CFX_DIBSource* pSrc, bool bAutoDropSrc = false);
-
- virtual FXDIB_Format GetDestFormat() = 0;
-
- virtual uint32_t* GetDestPalette() = 0;
-
- virtual void TranslateScanline(const uint8_t* src_buf,
- std::vector<uint8_t>* dest_buf) const = 0;
-
- virtual void TranslateDownSamples(uint8_t* dest_buf,
- const uint8_t* src_buf,
- int pixels,
- int Bpp) const = 0;
-
- protected:
- // CFX_DIBSource
- const uint8_t* GetScanline(int line) const override;
- void DownSampleScanline(int line,
- uint8_t* dest_scan,
- int dest_bpp,
- int dest_width,
+FX_RECT FXDIB_SwapClipBox(FX_RECT& clip,
+ int width,
+ int height,
bool bFlipX,
- int clip_left,
- int clip_width) const override;
-
- const CFX_DIBSource* m_pSrc;
- bool m_bAutoDropSrc;
- mutable std::vector<uint8_t> m_Scanline;
-};
-
-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;
-};
-
-class CFX_ScanlineCompositor {
- public:
- CFX_ScanlineCompositor();
-
- ~CFX_ScanlineCompositor();
-
- bool Init(FXDIB_Format dest_format,
- FXDIB_Format src_format,
- int32_t width,
- uint32_t* pSrcPalette,
- uint32_t mask_color,
- int blend_type,
- bool bClip,
- bool bRgbByteOrder = false,
- int alpha_flag = 0,
- void* pIccTransform = nullptr);
-
- void CompositeRgbBitmapLine(uint8_t* dest_scan,
- const uint8_t* src_scan,
- int width,
- const uint8_t* clip_scan,
- const uint8_t* src_extra_alpha = nullptr,
- uint8_t* dst_extra_alpha = nullptr);
-
- void CompositePalBitmapLine(uint8_t* dest_scan,
- const uint8_t* src_scan,
- int src_left,
- int width,
- const uint8_t* clip_scan,
- const uint8_t* src_extra_alpha = nullptr,
- uint8_t* dst_extra_alpha = nullptr);
-
- void CompositeByteMaskLine(uint8_t* dest_scan,
- const uint8_t* src_scan,
- int width,
- const uint8_t* clip_scan,
- uint8_t* dst_extra_alpha = nullptr);
-
- void CompositeBitMaskLine(uint8_t* dest_scan,
- const uint8_t* src_scan,
- int src_left,
- int width,
- const uint8_t* clip_scan,
- uint8_t* dst_extra_alpha = nullptr);
-
- protected:
- int m_Transparency;
- FXDIB_Format m_SrcFormat, m_DestFormat;
- uint32_t* m_pSrcPalette;
-
- int m_MaskAlpha, m_MaskRed, m_MaskGreen, m_MaskBlue, m_MaskBlack;
- int m_BlendType;
- void* m_pIccTransform;
- uint8_t* m_pCacheScanline;
- int m_CacheSize;
- bool m_bRgbByteOrder;
-};
-
-class CFX_BitmapComposer : public IFX_ScanlineComposer {
- public:
- CFX_BitmapComposer();
- ~CFX_BitmapComposer() override;
-
- void Compose(CFX_DIBitmap* pDest,
- const CFX_ClipRgn* pClipRgn,
- int bitmap_alpha,
- uint32_t mask_color,
- FX_RECT& dest_rect,
- bool bVertical,
- bool bFlipX,
- bool bFlipY,
- bool bRgbByteOrder = false,
- int alpha_flag = 0,
- void* pIccTransform = nullptr,
- int blend_type = FXDIB_BLEND_NORMAL);
-
- // IFX_ScanlineComposer
- bool SetInfo(int width,
- int height,
- FXDIB_Format src_format,
- uint32_t* pSrcPalette) override;
-
- void ComposeScanline(int line,
- const uint8_t* scanline,
- const uint8_t* scan_extra_alpha) override;
-
- protected:
- void DoCompose(uint8_t* dest_scan,
- const uint8_t* src_scan,
- int dest_width,
- const uint8_t* clip_scan,
- const uint8_t* src_extra_alpha = nullptr,
- uint8_t* dst_extra_alpha = nullptr);
- CFX_DIBitmap* m_pBitmap;
- const CFX_ClipRgn* m_pClipRgn;
- FXDIB_Format m_SrcFormat;
- int m_DestLeft, m_DestTop, m_DestWidth, m_DestHeight, m_BitmapAlpha;
- uint32_t m_MaskColor;
- const CFX_DIBitmap* m_pClipMask;
- CFX_ScanlineCompositor m_Compositor;
- bool m_bVertical, m_bFlipX, m_bFlipY;
- int m_AlphaFlag;
- void* m_pIccTransform;
- bool m_bRgbByteOrder;
- int m_BlendType;
- void ComposeScanlineV(int line,
- const uint8_t* scanline,
- const uint8_t* scan_extra_alpha = nullptr);
- uint8_t* m_pScanlineV;
- uint8_t* m_pClipScanV;
- uint8_t* m_pAddClipScan;
- uint8_t* m_pScanlineAlphaV;
-};
-
-class CFX_BitmapStorer : public IFX_ScanlineComposer {
- public:
- CFX_BitmapStorer();
- ~CFX_BitmapStorer() override;
-
- // IFX_ScanlineComposer
- void ComposeScanline(int line,
- const uint8_t* scanline,
- const uint8_t* scan_extra_alpha) override;
- bool SetInfo(int width,
- int height,
- FXDIB_Format src_format,
- uint32_t* pSrcPalette) override;
-
- CFX_DIBitmap* GetBitmap() { return m_pBitmap.get(); }
- std::unique_ptr<CFX_DIBitmap> Detach();
- void Replace(std::unique_ptr<CFX_DIBitmap> pBitmap);
-
- private:
- std::unique_ptr<CFX_DIBitmap> m_pBitmap;
-};
-
-class CFX_ImageStretcher {
- public:
- CFX_ImageStretcher(IFX_ScanlineComposer* pDest,
- const CFX_DIBSource* pSource,
- int dest_width,
- int dest_height,
- const FX_RECT& bitmap_rect,
- uint32_t flags);
- ~CFX_ImageStretcher();
-
- bool Start();
- bool Continue(IFX_Pause* pPause);
-
- const CFX_DIBSource* source() { return m_pSource; }
-
- private:
- bool StartQuickStretch();
- bool StartStretch();
- bool ContinueQuickStretch(IFX_Pause* pPause);
- bool ContinueStretch(IFX_Pause* pPause);
-
- IFX_ScanlineComposer* const m_pDest;
- const CFX_DIBSource* const m_pSource;
- std::unique_ptr<CStretchEngine> m_pStretchEngine;
- std::unique_ptr<uint8_t, FxFreeDeleter> m_pScanline;
- std::unique_ptr<uint8_t, FxFreeDeleter> m_pMaskScanline;
- const uint32_t m_Flags;
- bool m_bFlipX;
- bool m_bFlipY;
- int m_DestWidth;
- int m_DestHeight;
- FX_RECT m_ClipRect;
- const FXDIB_Format m_DestFormat;
- const int m_DestBPP;
- int m_LineIndex;
-};
-
-class CFX_ImageTransformer {
- public:
- CFX_ImageTransformer(const CFX_DIBSource* pSrc,
- const CFX_Matrix* pMatrix,
- int flags,
- const FX_RECT* pClip);
- ~CFX_ImageTransformer();
-
- bool Start();
- bool Continue(IFX_Pause* pPause);
-
- const FX_RECT& result() const { return m_result; }
- std::unique_ptr<CFX_DIBitmap> DetachBitmap();
-
- private:
- const CFX_DIBSource* const m_pSrc;
- const CFX_Matrix* const m_pMatrix;
- const FX_RECT* const m_pClip;
- FX_RECT m_StretchClip;
- FX_RECT m_result;
- CFX_Matrix m_dest2stretch;
- std::unique_ptr<CFX_ImageStretcher> m_Stretcher;
- CFX_BitmapStorer m_Storer;
- const uint32_t m_Flags;
- int m_Status;
-};
-
-class CFX_ImageRenderer {
- public:
- CFX_ImageRenderer();
- ~CFX_ImageRenderer();
-
- bool Start(CFX_DIBitmap* pDevice,
- const CFX_ClipRgn* pClipRgn,
- const CFX_DIBSource* pSource,
- int bitmap_alpha,
- uint32_t mask_color,
- const CFX_Matrix* pMatrix,
- uint32_t dib_flags,
- bool bRgbByteOrder = false,
- int alpha_flag = 0,
- void* pIccTransform = nullptr,
- int blend_type = FXDIB_BLEND_NORMAL);
-
- bool Continue(IFX_Pause* pPause);
-
- protected:
- CFX_DIBitmap* m_pDevice;
- const CFX_ClipRgn* m_pClipRgn;
- int m_BitmapAlpha;
- uint32_t m_MaskColor;
- CFX_Matrix m_Matrix;
- std::unique_ptr<CFX_ImageTransformer> m_pTransformer;
- std::unique_ptr<CFX_ImageStretcher> m_Stretcher;
- CFX_BitmapComposer m_Composer;
- int m_Status;
- FX_RECT m_ClipBox;
- uint32_t m_Flags;
- int m_AlphaFlag;
- void* m_pIccTransform;
- bool m_bRgbByteOrder;
- int m_BlendType;
-};
+ bool bFlipY);
#endif // CORE_FXGE_FX_DIB_H_
diff --git a/chromium/third_party/pdfium/core/fxge/fx_font.h b/chromium/third_party/pdfium/core/fxge/fx_font.h
index 07392fa07f3..87f36060b78 100644
--- a/chromium/third_party/pdfium/core/fxge/fx_font.h
+++ b/chromium/third_party/pdfium/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"
@@ -222,11 +223,19 @@ class CFX_FontFaceInfo {
class CFX_GlyphBitmap {
public:
+ CFX_GlyphBitmap();
+ ~CFX_GlyphBitmap();
+
int m_Top;
int m_Left;
- CFX_DIBitmap m_Bitmap;
+ CFX_RetainPtr<CFX_DIBitmap> m_pBitmap;
};
+inline CFX_GlyphBitmap::CFX_GlyphBitmap()
+ : m_pBitmap(pdfium::MakeRetain<CFX_DIBitmap>()) {}
+
+inline CFX_GlyphBitmap::~CFX_GlyphBitmap() {}
+
class FXTEXT_GLYPHPOS {
public:
FXTEXT_GLYPHPOS();
@@ -240,8 +249,8 @@ class FXTEXT_GLYPHPOS {
FX_RECT FXGE_GetGlyphsBBox(const std::vector<FXTEXT_GLYPHPOS>& glyphs,
int anti_alias,
- FX_FLOAT retinaScaleX = 1.0f,
- FX_FLOAT retinaScaleY = 1.0f);
+ float retinaScaleX = 1.0f,
+ float retinaScaleY = 1.0f);
CFX_ByteString GetNameFromTT(const uint8_t* name_table,
uint32_t name_table_size,
diff --git a/chromium/third_party/pdfium/core/fxge/ge/cfx_cliprgn.cpp b/chromium/third_party/pdfium/core/fxge/ge/cfx_cliprgn.cpp
index ea3eb51f182..d2f065dba76 100644
--- a/chromium/third_party/pdfium/core/fxge/ge/cfx_cliprgn.cpp
+++ b/chromium/third_party/pdfium/core/fxge/ge/cfx_cliprgn.cpp
@@ -6,6 +6,10 @@
#include "core/fxge/ge/cfx_cliprgn.h"
+#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) {}
@@ -20,7 +24,7 @@ CFX_ClipRgn::~CFX_ClipRgn() {}
void CFX_ClipRgn::Reset(const FX_RECT& rect) {
m_Type = RectI;
m_Box = rect;
- m_Mask.SetNull();
+ m_Mask = nullptr;
}
void CFX_ClipRgn::IntersectRect(const FX_RECT& rect) {
@@ -36,8 +40,7 @@ void CFX_ClipRgn::IntersectRect(const FX_RECT& rect) {
void CFX_ClipRgn::IntersectMaskRect(FX_RECT rect,
FX_RECT mask_rect,
- CFX_DIBitmapRef Mask) {
- const CFX_DIBitmap* mask_dib = Mask.GetObject();
+ const CFX_RetainPtr<CFX_DIBitmap>& pMask) {
m_Type = MaskF;
m_Box = rect;
m_Box.Intersect(mask_rect);
@@ -46,28 +49,30 @@ void CFX_ClipRgn::IntersectMaskRect(FX_RECT rect,
return;
}
if (m_Box == mask_rect) {
- m_Mask = Mask;
+ m_Mask = pMask;
return;
}
- CFX_DIBitmap* new_dib = m_Mask.Emplace();
- new_dib->Create(m_Box.Width(), m_Box.Height(), FXDIB_8bppMask);
+ CFX_RetainPtr<CFX_DIBitmap> pOldMask(pMask);
+ m_Mask = pdfium::MakeRetain<CFX_DIBitmap>();
+ m_Mask->Create(m_Box.Width(), m_Box.Height(), FXDIB_8bppMask);
for (int row = m_Box.top; row < m_Box.bottom; row++) {
uint8_t* dest_scan =
- new_dib->GetBuffer() + new_dib->GetPitch() * (row - m_Box.top);
+ m_Mask->GetBuffer() + m_Mask->GetPitch() * (row - m_Box.top);
uint8_t* src_scan =
- mask_dib->GetBuffer() + mask_dib->GetPitch() * (row - mask_rect.top);
+ pOldMask->GetBuffer() + pOldMask->GetPitch() * (row - mask_rect.top);
for (int col = m_Box.left; col < m_Box.right; col++)
dest_scan[col - m_Box.left] = src_scan[col - mask_rect.left];
}
}
-void CFX_ClipRgn::IntersectMaskF(int left, int top, CFX_DIBitmapRef Mask) {
- const CFX_DIBitmap* mask_dib = Mask.GetObject();
- ASSERT(mask_dib->GetFormat() == FXDIB_8bppMask);
- FX_RECT mask_box(left, top, left + mask_dib->GetWidth(),
- top + mask_dib->GetHeight());
+void CFX_ClipRgn::IntersectMaskF(int left,
+ int top,
+ const CFX_RetainPtr<CFX_DIBitmap>& pMask) {
+ ASSERT(pMask->GetFormat() == FXDIB_8bppMask);
+ FX_RECT mask_box(left, top, left + pMask->GetWidth(),
+ top + pMask->GetHeight());
if (m_Type == RectI) {
- IntersectMaskRect(m_Box, mask_box, Mask);
+ IntersectMaskRect(m_Box, mask_box, pMask);
return;
}
if (m_Type == MaskF) {
@@ -75,19 +80,16 @@ void CFX_ClipRgn::IntersectMaskF(int left, int top, CFX_DIBitmapRef Mask) {
new_box.Intersect(mask_box);
if (new_box.IsEmpty()) {
m_Type = RectI;
- m_Mask.SetNull();
+ m_Mask = nullptr;
m_Box = new_box;
return;
}
- CFX_DIBitmapRef new_mask;
- CFX_DIBitmap* new_dib = new_mask.Emplace();
+ auto new_dib = pdfium::MakeRetain<CFX_DIBitmap>();
new_dib->Create(new_box.Width(), new_box.Height(), FXDIB_8bppMask);
- const CFX_DIBitmap* old_dib = m_Mask.GetObject();
for (int row = new_box.top; row < new_box.bottom; row++) {
uint8_t* old_scan =
- old_dib->GetBuffer() + (row - m_Box.top) * old_dib->GetPitch();
- uint8_t* mask_scan =
- mask_dib->GetBuffer() + (row - top) * mask_dib->GetPitch();
+ m_Mask->GetBuffer() + (row - m_Box.top) * m_Mask->GetPitch();
+ uint8_t* mask_scan = pMask->GetBuffer() + (row - top) * pMask->GetPitch();
uint8_t* new_scan =
new_dib->GetBuffer() + (row - new_box.top) * new_dib->GetPitch();
for (int col = new_box.left; col < new_box.right; col++) {
@@ -96,7 +98,7 @@ void CFX_ClipRgn::IntersectMaskF(int left, int top, CFX_DIBitmapRef Mask) {
}
}
m_Box = new_box;
- m_Mask = new_mask;
+ m_Mask = std::move(new_dib);
return;
}
ASSERT(false);
diff --git a/chromium/third_party/pdfium/core/fxge/ge/cfx_cliprgn.h b/chromium/third_party/pdfium/core/fxge/ge/cfx_cliprgn.h
index f3fd5856b6e..800e6ddbeef 100644
--- a/chromium/third_party/pdfium/core/fxge/ge/cfx_cliprgn.h
+++ b/chromium/third_party/pdfium/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:
@@ -19,18 +21,22 @@ class CFX_ClipRgn {
ClipType GetType() const { return m_Type; }
const FX_RECT& GetBox() const { return m_Box; }
- CFX_DIBitmapRef GetMask() const { return m_Mask; }
+ CFX_RetainPtr<CFX_DIBitmap> GetMask() const { return m_Mask; }
void Reset(const FX_RECT& rect);
void IntersectRect(const FX_RECT& rect);
- void IntersectMaskF(int left, int top, CFX_DIBitmapRef Mask);
+ void IntersectMaskF(int left,
+ int top,
+ const CFX_RetainPtr<CFX_DIBitmap>& Mask);
private:
- void IntersectMaskRect(FX_RECT rect, FX_RECT mask_box, CFX_DIBitmapRef Mask);
+ void IntersectMaskRect(FX_RECT rect,
+ FX_RECT mask_box,
+ const CFX_RetainPtr<CFX_DIBitmap>& Mask);
ClipType m_Type;
FX_RECT m_Box;
- CFX_DIBitmapRef m_Mask;
+ CFX_RetainPtr<CFX_DIBitmap> m_Mask;
};
#endif // CORE_FXGE_GE_CFX_CLIPRGN_H_
diff --git a/chromium/third_party/pdfium/core/fxge/ge/cfx_facecache.cpp b/chromium/third_party/pdfium/core/fxge/ge/cfx_facecache.cpp
index 314c95b8b20..2a8e71acf53 100644
--- a/chromium/third_party/pdfium/core/fxge/ge/cfx_facecache.cpp
+++ b/chromium/third_party/pdfium/core/fxge/ge/cfx_facecache.cpp
@@ -21,6 +21,11 @@
#if defined _SKIA_SUPPORT_ || _SKIA_SUPPORT_PATHS_
#include "third_party/skia/include/core/SkStream.h"
#include "third_party/skia/include/core/SkTypeface.h"
+
+#if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_
+#include "third_party/skia/include/ports/SkFontMgr.h"
+#include "third_party/skia/include/ports/SkFontMgr_empty.h"
+#endif
#endif
namespace {
@@ -44,7 +49,7 @@ void ContrastAdjust(uint8_t* pDataIn,
int nDstRowBytes) {
int col, row, temp;
int max = 0, min = 255;
- FX_FLOAT rate;
+ float rate;
for (row = 0; row < nHeight; row++) {
uint8_t* pRow = pDataIn + row * nSrcRowBytes;
for (col = 0; col < nWidth; col++) {
@@ -55,10 +60,10 @@ void ContrastAdjust(uint8_t* pDataIn,
}
temp = max - min;
if (temp == 0 || temp == 255) {
- int rowbytes = std::min(FXSYS_abs(nSrcRowBytes), nDstRowBytes);
+ int rowbytes = std::min(abs(nSrcRowBytes), nDstRowBytes);
for (row = 0; row < nHeight; row++) {
- FXSYS_memcpy(pDataOut + row * nDstRowBytes, pDataIn + row * nSrcRowBytes,
- rowbytes);
+ memcpy(pDataOut + row * nDstRowBytes, pDataIn + row * nSrcRowBytes,
+ rowbytes);
}
return;
}
@@ -165,8 +170,9 @@ CFX_GlyphBitmap* CFX_FaceCache::RenderGlyph(const CFX_Font* pFont,
else
level = CFX_Font::s_WeightPow_11[index];
- level = level * (FXSYS_abs(static_cast<int>(ft_matrix.xx)) +
- FXSYS_abs(static_cast<int>(ft_matrix.xy))) /
+ level = level *
+ (abs(static_cast<int>(ft_matrix.xx)) +
+ abs(static_cast<int>(ft_matrix.xy))) /
36655;
FXFT_Outline_Embolden(FXFT_Get_Glyph_Outline(m_Face),
level.ValueOrDefault(0));
@@ -182,14 +188,14 @@ CFX_GlyphBitmap* CFX_FaceCache::RenderGlyph(const CFX_Font* pFont,
return nullptr;
int dib_width = bmwidth;
CFX_GlyphBitmap* pGlyphBitmap = new CFX_GlyphBitmap;
- pGlyphBitmap->m_Bitmap.Create(
+ pGlyphBitmap->m_pBitmap->Create(
dib_width, bmheight,
anti_alias == FXFT_RENDER_MODE_MONO ? FXDIB_1bppMask : FXDIB_8bppMask);
pGlyphBitmap->m_Left = FXFT_Get_Glyph_BitmapLeft(m_Face);
pGlyphBitmap->m_Top = FXFT_Get_Glyph_BitmapTop(m_Face);
- int dest_pitch = pGlyphBitmap->m_Bitmap.GetPitch();
+ int dest_pitch = pGlyphBitmap->m_pBitmap->GetPitch();
int src_pitch = FXFT_Get_Bitmap_Pitch(FXFT_Get_Glyph_Bitmap(m_Face));
- uint8_t* pDestBuf = pGlyphBitmap->m_Bitmap.GetBuffer();
+ uint8_t* pDestBuf = pGlyphBitmap->m_pBitmap->GetBuffer();
uint8_t* pSrcBuf =
(uint8_t*)FXFT_Get_Bitmap_Buffer(FXFT_Get_Glyph_Bitmap(m_Face));
if (anti_alias != FXFT_RENDER_MODE_MONO &&
@@ -205,15 +211,14 @@ CFX_GlyphBitmap* CFX_FaceCache::RenderGlyph(const CFX_Font* pFont,
}
}
} else {
- FXSYS_memset(pDestBuf, 0, dest_pitch * bmheight);
+ memset(pDestBuf, 0, dest_pitch * bmheight);
if (anti_alias == FXFT_RENDER_MODE_MONO &&
FXFT_Get_Bitmap_PixelMode(FXFT_Get_Glyph_Bitmap(m_Face)) ==
FXFT_PIXEL_MODE_MONO) {
- int rowbytes =
- FXSYS_abs(src_pitch) > dest_pitch ? dest_pitch : FXSYS_abs(src_pitch);
+ int rowbytes = abs(src_pitch) > dest_pitch ? dest_pitch : abs(src_pitch);
for (int row = 0; row < bmheight; row++) {
- FXSYS_memcpy(pDestBuf + row * dest_pitch, pSrcBuf + row * src_pitch,
- rowbytes);
+ memcpy(pDestBuf + row * dest_pitch, pSrcBuf + row * src_pitch,
+ rowbytes);
}
} else {
ContrastAdjust(pSrcBuf, pDestBuf, bmwidth, bmheight, src_pitch,
@@ -359,6 +364,13 @@ CFX_TypeFace* CFX_FaceCache::GetDeviceCache(const CFX_Font* pFont) {
new SkMemoryStream(pFont->GetFontData(), pFont->GetSize()))
.release();
}
+#if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_
+ if (!m_pTypeface) {
+ sk_sp<SkFontMgr> customMgr(SkFontMgr_New_Custom_Empty());
+ m_pTypeface = customMgr->createFromStream(
+ new SkMemoryStream(pFont->GetFontData(), pFont->GetSize()));
+ }
+#endif
return m_pTypeface;
}
#endif
diff --git a/chromium/third_party/pdfium/core/fxge/ge/cfx_folderfontinfo.cpp b/chromium/third_party/pdfium/core/fxge/ge/cfx_folderfontinfo.cpp
index 776a37319b3..ff8cc4c29f0 100644
--- a/chromium/third_party/pdfium/core/fxge/ge/cfx_folderfontinfo.cpp
+++ b/chromium/third_party/pdfium/core/fxge/ge/cfx_folderfontinfo.cpp
@@ -16,8 +16,8 @@
namespace {
const struct {
- const FX_CHAR* m_pName;
- const FX_CHAR* m_pSubstName;
+ const char* m_pName;
+ const char* m_pSubstName;
} Base14Substs[] = {
{"Courier", "Courier New"},
{"Courier-Bold", "Courier New Bold"},
@@ -33,15 +33,15 @@ const struct {
{"Times-Italic", "Times New Roman Italic"},
};
-CFX_ByteString FPDF_ReadStringFromFile(FXSYS_FILE* pFile, uint32_t size) {
+CFX_ByteString FPDF_ReadStringFromFile(FILE* pFile, uint32_t size) {
CFX_ByteString buffer;
- if (!FXSYS_fread(buffer.GetBuffer(size), size, 1, pFile))
+ if (!fread(buffer.GetBuffer(size), size, 1, pFile))
return CFX_ByteString();
buffer.ReleaseBuffer(size);
return buffer;
}
-CFX_ByteString FPDF_LoadTableFromTT(FXSYS_FILE* pFile,
+CFX_ByteString FPDF_LoadTableFromTT(FILE* pFile,
const uint8_t* pTables,
uint32_t nTables,
uint32_t tag) {
@@ -50,7 +50,7 @@ CFX_ByteString FPDF_LoadTableFromTT(FXSYS_FILE* pFile,
if (GET_TT_LONG(p) == tag) {
uint32_t offset = GET_TT_LONG(p + 8);
uint32_t size = GET_TT_LONG(p + 12);
- FXSYS_fseek(pFile, offset, FXSYS_SEEK_SET);
+ fseek(pFile, offset, SEEK_SET);
return FPDF_ReadStringFromFile(pFile, size);
}
}
@@ -149,34 +149,34 @@ void CFX_FolderFontInfo::ScanPath(const CFX_ByteString& path) {
}
void CFX_FolderFontInfo::ScanFile(const CFX_ByteString& path) {
- FXSYS_FILE* pFile = FXSYS_fopen(path.c_str(), "rb");
+ FILE* pFile = fopen(path.c_str(), "rb");
if (!pFile)
return;
- FXSYS_fseek(pFile, 0, FXSYS_SEEK_END);
+ fseek(pFile, 0, SEEK_END);
- uint32_t filesize = FXSYS_ftell(pFile);
+ uint32_t filesize = ftell(pFile);
uint8_t buffer[16];
- FXSYS_fseek(pFile, 0, FXSYS_SEEK_SET);
+ fseek(pFile, 0, SEEK_SET);
- size_t readCnt = FXSYS_fread(buffer, 12, 1, pFile);
+ size_t readCnt = fread(buffer, 12, 1, pFile);
if (readCnt != 1) {
- FXSYS_fclose(pFile);
+ fclose(pFile);
return;
}
if (GET_TT_LONG(buffer) == kTableTTCF) {
uint32_t nFaces = GET_TT_LONG(buffer + 8);
if (nFaces > std::numeric_limits<uint32_t>::max() / 4) {
- FXSYS_fclose(pFile);
+ fclose(pFile);
return;
}
uint32_t face_bytes = nFaces * 4;
uint8_t* offsets = FX_Alloc(uint8_t, face_bytes);
- readCnt = FXSYS_fread(offsets, 1, face_bytes, pFile);
+ readCnt = fread(offsets, 1, face_bytes, pFile);
if (readCnt != face_bytes) {
FX_Free(offsets);
- FXSYS_fclose(pFile);
+ fclose(pFile);
return;
}
for (uint32_t i = 0; i < nFaces; i++) {
@@ -187,16 +187,16 @@ void CFX_FolderFontInfo::ScanFile(const CFX_ByteString& path) {
} else {
ReportFace(path, pFile, filesize, 0);
}
- FXSYS_fclose(pFile);
+ fclose(pFile);
}
void CFX_FolderFontInfo::ReportFace(const CFX_ByteString& path,
- FXSYS_FILE* pFile,
+ FILE* pFile,
uint32_t filesize,
uint32_t offset) {
- FXSYS_fseek(pFile, offset, FXSYS_SEEK_SET);
+ fseek(pFile, offset, SEEK_SET);
char buffer[16];
- if (!FXSYS_fread(buffer, 12, 1, pFile))
+ if (!fread(buffer, 12, 1, pFile))
return;
uint32_t nTables = GET_TT_SHORT(buffer + 4);
@@ -275,7 +275,7 @@ void* CFX_FolderFontInfo::FindFont(int weight,
bool bItalic,
int charset,
int pitch_family,
- const FX_CHAR* family,
+ const char* family,
bool bMatchName) {
CFX_FontFaceInfo* pFind = nullptr;
if (charset == FXFONT_ANSI_CHARSET && (pitch_family & FXFONT_FF_FIXEDPITCH))
@@ -306,7 +306,7 @@ void* CFX_FolderFontInfo::MapFont(int weight,
bool bItalic,
int charset,
int pitch_family,
- const FX_CHAR* family,
+ const char* family,
int& iExact) {
return nullptr;
}
@@ -320,7 +320,7 @@ void* CFX_FolderFontInfo::MapFontByUnicode(uint32_t dwUnicode,
}
#endif // PDF_ENABLE_XFA
-void* CFX_FolderFontInfo::GetFont(const FX_CHAR* face) {
+void* CFX_FolderFontInfo::GetFont(const char* face) {
auto it = m_FontList.find(face);
return it != m_FontList.end() ? it->second : nullptr;
}
@@ -353,27 +353,27 @@ uint32_t CFX_FolderFontInfo::GetFontData(void* hFont,
if (!datasize || size < datasize)
return datasize;
- FXSYS_FILE* pFile = FXSYS_fopen(pFont->m_FilePath.c_str(), "rb");
+ FILE* pFile = fopen(pFont->m_FilePath.c_str(), "rb");
if (!pFile)
return 0;
- if (FXSYS_fseek(pFile, offset, FXSYS_SEEK_SET) < 0 ||
- FXSYS_fread(buffer, datasize, 1, pFile) != 1) {
+ if (fseek(pFile, offset, SEEK_SET) < 0 ||
+ fread(buffer, datasize, 1, pFile) != 1) {
datasize = 0;
}
- FXSYS_fclose(pFile);
+ fclose(pFile);
return datasize;
}
void CFX_FolderFontInfo::DeleteFont(void* hFont) {}
-bool CFX_FolderFontInfo::GetFaceName(void* hFont, CFX_ByteString& name) {
+
+bool CFX_FolderFontInfo::GetFaceName(void* hFont, CFX_ByteString* name) {
if (!hFont)
return false;
- CFX_FontFaceInfo* pFont = (CFX_FontFaceInfo*)hFont;
- name = pFont->m_FaceName;
+ *name = static_cast<CFX_FontFaceInfo*>(hFont)->m_FaceName;
return true;
}
-bool CFX_FolderFontInfo::GetFontCharset(void* hFont, int& charset) {
+bool CFX_FolderFontInfo::GetFontCharset(void* hFont, int* charset) {
return false;
}
diff --git a/chromium/third_party/pdfium/core/fxge/ge/cfx_folderfontinfo.h b/chromium/third_party/pdfium/core/fxge/ge/cfx_folderfontinfo.h
index d031eef3d06..ab2468ade0b 100644
--- a/chromium/third_party/pdfium/core/fxge/ge/cfx_folderfontinfo.h
+++ b/chromium/third_party/pdfium/core/fxge/ge/cfx_folderfontinfo.h
@@ -27,7 +27,7 @@ class CFX_FolderFontInfo : public IFX_SystemFontInfo {
bool bItalic,
int charset,
int pitch_family,
- const FX_CHAR* face,
+ const char* face,
int& bExact) override;
#ifdef PDF_ENABLE_XFA
void* MapFontByUnicode(uint32_t dwUnicode,
@@ -35,20 +35,20 @@ class CFX_FolderFontInfo : public IFX_SystemFontInfo {
bool bItalic,
int pitch_family) override;
#endif // PDF_ENABLE_XFA
- void* GetFont(const FX_CHAR* face) override;
+ void* GetFont(const char* face) override;
uint32_t GetFontData(void* hFont,
uint32_t table,
uint8_t* buffer,
uint32_t size) override;
void DeleteFont(void* hFont) override;
- bool GetFaceName(void* hFont, CFX_ByteString& name) override;
- bool GetFontCharset(void* hFont, int& charset) override;
+ bool GetFaceName(void* hFont, CFX_ByteString* name) override;
+ bool GetFontCharset(void* hFont, int* charset) override;
protected:
void ScanPath(const CFX_ByteString& path);
void ScanFile(const CFX_ByteString& path);
void ReportFace(const CFX_ByteString& path,
- FXSYS_FILE* pFile,
+ FILE* pFile,
uint32_t filesize,
uint32_t offset);
void* GetSubstFont(const CFX_ByteString& face);
@@ -56,7 +56,7 @@ class CFX_FolderFontInfo : public IFX_SystemFontInfo {
bool bItalic,
int charset,
int pitch_family,
- const FX_CHAR* family,
+ const char* family,
bool bMatchName);
std::map<CFX_ByteString, CFX_FontFaceInfo*> m_FontList;
diff --git a/chromium/third_party/pdfium/core/fxge/ge/cfx_font.cpp b/chromium/third_party/pdfium/core/fxge/ge/cfx_font.cpp
index 87157b01011..068f0b032ca 100644
--- a/chromium/third_party/pdfium/core/fxge/ge/cfx_font.cpp
+++ b/chromium/third_party/pdfium/core/fxge/ge/cfx_font.cpp
@@ -31,7 +31,7 @@ typedef struct {
CFX_PathData* m_pPath;
int m_CurX;
int m_CurY;
- FX_FLOAT m_CoordUnit;
+ float m_CoordUnit;
} OUTLINE_PARAMS;
#ifdef PDF_ENABLE_XFA
diff --git a/chromium/third_party/pdfium/core/fxge/ge/cfx_fontcache.cpp b/chromium/third_party/pdfium/core/fxge/ge/cfx_fontcache.cpp
index 58cee06d42c..1599c30b933 100644
--- a/chromium/third_party/pdfium/core/fxge/ge/cfx_fontcache.cpp
+++ b/chromium/third_party/pdfium/core/fxge/ge/cfx_fontcache.cpp
@@ -12,6 +12,7 @@
#include "core/fxge/cfx_facecache.h"
#include "core/fxge/fx_font.h"
#include "core/fxge/fx_freetype.h"
+#include "third_party/base/ptr_util.h"
CFX_FontCache::CountedFaceCache::CountedFaceCache() {}
@@ -35,7 +36,7 @@ CFX_FaceCache* CFX_FontCache::GetCachedFace(const CFX_Font* pFont) {
return counted_face_cache->m_Obj.get();
}
- std::unique_ptr<CountedFaceCache> counted_face_cache(new CountedFaceCache);
+ auto counted_face_cache = pdfium::MakeUnique<CountedFaceCache>();
counted_face_cache->m_nCount = 2;
CFX_FaceCache* face_cache = new CFX_FaceCache(bExternal ? nullptr : face);
counted_face_cache->m_Obj.reset(face_cache);
diff --git a/chromium/third_party/pdfium/core/fxge/ge/cfx_fontmapper.cpp b/chromium/third_party/pdfium/core/fxge/ge/cfx_fontmapper.cpp
index 064fc9610aa..0cff3445991 100644
--- a/chromium/third_party/pdfium/core/fxge/ge/cfx_fontmapper.cpp
+++ b/chromium/third_party/pdfium/core/fxge/ge/cfx_fontmapper.cpp
@@ -25,7 +25,7 @@ namespace {
const int kNumStandardFonts = 14;
-const FX_CHAR* const g_Base14FontNames[kNumStandardFonts] = {
+const char* const g_Base14FontNames[kNumStandardFonts] = {
"Courier",
"Courier-Bold",
"Courier-BoldOblique",
@@ -43,7 +43,7 @@ const FX_CHAR* const g_Base14FontNames[kNumStandardFonts] = {
};
const struct AltFontName {
- const FX_CHAR* m_pName;
+ const char* m_pName;
int m_Index;
} g_AltFontNames[] = {
{"Arial", 4},
@@ -138,8 +138,8 @@ const struct AltFontName {
};
const struct AltFontFamily {
- const FX_CHAR* m_pFontName;
- const FX_CHAR* m_pFontFamily;
+ const char* m_pFontName;
+ const char* m_pFontFamily;
} g_AltFontFamilies[] = {
{"AGaramondPro", "Adobe Garamond Pro"},
{"BankGothicBT-Medium", "BankGothic Md BT"},
@@ -147,7 +147,7 @@ const struct AltFontFamily {
};
const struct FX_FontStyle {
- const FX_CHAR* style;
+ const char* style;
int32_t len;
} g_FontStyles[] = {
{"Bold", 4}, {"Italic", 6}, {"BoldItalic", 10}, {"Reg", 3}, {"Regular", 7},
@@ -167,20 +167,19 @@ const struct CODEPAGE_MAP {
};
int CompareFontFamilyString(const void* key, const void* element) {
- CFX_ByteString str_key((const FX_CHAR*)key);
+ CFX_ByteString str_key((const char*)key);
const AltFontFamily* family = reinterpret_cast<const AltFontFamily*>(element);
if (str_key.Find(family->m_pFontName) != -1)
return 0;
- return FXSYS_stricmp(reinterpret_cast<const FX_CHAR*>(key),
- family->m_pFontName);
+ return FXSYS_stricmp(reinterpret_cast<const char*>(key), family->m_pFontName);
}
int CompareString(const void* key, const void* element) {
- return FXSYS_stricmp(reinterpret_cast<const FX_CHAR*>(key),
+ return FXSYS_stricmp(reinterpret_cast<const char*>(key),
reinterpret_cast<const AltFontName*>(element)->m_pName);
}
-CFX_ByteString TT_NormalizeName(const FX_CHAR* family) {
+CFX_ByteString TT_NormalizeName(const char* family) {
CFX_ByteString norm(family);
norm.Remove(' ');
norm.Remove('-');
@@ -217,13 +216,13 @@ CFX_ByteString GetFontFamily(CFX_ByteString fontName, int nStyle) {
fontName = "FreeStyleScript";
return fontName;
}
- AltFontFamily* found = reinterpret_cast<AltFontFamily*>(FXSYS_bsearch(
+ AltFontFamily* found = reinterpret_cast<AltFontFamily*>(bsearch(
fontName.c_str(), g_AltFontFamilies, FX_ArraySize(g_AltFontFamilies),
sizeof(AltFontFamily), CompareFontFamilyString));
return found ? CFX_ByteString(found->m_pFontFamily) : fontName;
}
-CFX_ByteString ParseStyle(const FX_CHAR* pStyle, int iLen, int iIndex) {
+CFX_ByteString ParseStyle(const char* pStyle, int iLen, int iIndex) {
CFX_ByteTextBuf buf;
if (!iLen || iLen <= iIndex)
return buf.MakeString();
@@ -281,7 +280,7 @@ CFX_FontMapper::CFX_FontMapper(CFX_FontMgr* mgr)
: m_bListLoaded(false), m_pFontMgr(mgr) {
m_MMFaces[0] = nullptr;
m_MMFaces[1] = nullptr;
- FXSYS_memset(m_FoxitFaces, 0, sizeof(m_FoxitFaces));
+ memset(m_FoxitFaces, 0, sizeof(m_FoxitFaces));
}
CFX_FontMapper::~CFX_FontMapper() {
@@ -505,7 +504,7 @@ FXFT_Face CFX_FontMapper::FindSubstFont(const CFX_ByteString& name,
}
if (!style.IsEmpty()) {
int nLen = style.GetLength();
- const FX_CHAR* pStyle = style.c_str();
+ const char* pStyle = style.c_str();
int i = 0;
bool bFirstItem = true;
CFX_ByteString buf;
@@ -678,9 +677,9 @@ FXFT_Face CFX_FontMapper::FindSubstFont(const CFX_ByteString& name,
if (!hFont)
return nullptr;
- m_pFontInfo->GetFaceName(hFont, SubstName);
+ m_pFontInfo->GetFaceName(hFont, &SubstName);
if (Charset == FXFONT_DEFAULT_CHARSET)
- m_pFontInfo->GetFontCharset(hFont, Charset);
+ m_pFontInfo->GetFontCharset(hFont, &Charset);
uint32_t ttc_size = m_pFontInfo->GetFontData(hFont, kTableTTCF, nullptr, 0);
uint32_t font_size = m_pFontInfo->GetFontData(hFont, 0, nullptr, 0);
if (font_size == 0 && ttc_size == 0) {
@@ -708,7 +707,7 @@ FXFT_Face CFX_FontMapper::FindSubstFont(const CFX_ByteString& name,
if (bItalic && !FXFT_Is_Face_Italic(face)) {
if (italic_angle == 0)
italic_angle = -12;
- else if (FXSYS_abs(italic_angle) < 5)
+ else if (abs(italic_angle) < 5)
italic_angle = 0;
pSubstFont->m_ItalicAngle = italic_angle;
}
@@ -743,7 +742,7 @@ FXFT_Face CFX_FontMapper::FindSubstFontByUnicode(uint32_t dwUnicode,
face = GetCachedTTCFace(hFont, 0x74746366, ttc_size, font_size);
} else {
CFX_ByteString SubstName;
- m_pFontInfo->GetFaceName(hFont, SubstName);
+ m_pFontInfo->GetFaceName(hFont, &SubstName);
face = GetCachedFace(hFont, SubstName, weight, bItalic, font_size);
}
m_pFontInfo->DeleteFont(hFont);
@@ -810,8 +809,8 @@ FXFT_Face CFX_FontMapper::GetCachedFace(void* hFont,
int PDF_GetStandardFontName(CFX_ByteString* name) {
AltFontName* found = static_cast<AltFontName*>(
- FXSYS_bsearch(name->c_str(), g_AltFontNames, FX_ArraySize(g_AltFontNames),
- sizeof(AltFontName), CompareString));
+ bsearch(name->c_str(), g_AltFontNames, FX_ArraySize(g_AltFontNames),
+ sizeof(AltFontName), CompareString));
if (!found)
return -1;
diff --git a/chromium/third_party/pdfium/core/fxge/ge/cfx_fontmgr.cpp b/chromium/third_party/pdfium/core/fxge/ge/cfx_fontmgr.cpp
index 64f647e3f60..97d143804ba 100644
--- a/chromium/third_party/pdfium/core/fxge/ge/cfx_fontmgr.cpp
+++ b/chromium/third_party/pdfium/core/fxge/ge/cfx_fontmgr.cpp
@@ -215,7 +215,7 @@ FXFT_Face CFX_FontMgr::GetFixedFace(const uint8_t* pData,
return FXFT_Set_Pixel_Sizes(face, 64, 64) ? nullptr : face;
}
-FXFT_Face CFX_FontMgr::GetFileFace(const FX_CHAR* filename, int face_index) {
+FXFT_Face CFX_FontMgr::GetFileFace(const char* filename, int face_index) {
InitFTLibrary();
FXFT_Library library = m_FTLibrary;
FXFT_Face face = nullptr;
diff --git a/chromium/third_party/pdfium/core/fxge/ge/cfx_gemodule.cpp b/chromium/third_party/pdfium/core/fxge/ge/cfx_gemodule.cpp
index ed6d6cb32e6..790b670e4f5 100644
--- a/chromium/third_party/pdfium/core/fxge/ge/cfx_gemodule.cpp
+++ b/chromium/third_party/pdfium/core/fxge/ge/cfx_gemodule.cpp
@@ -59,11 +59,11 @@ CFX_FontCache* CFX_GEModule::GetFontCache() {
return m_pFontCache;
}
-void CFX_GEModule::SetTextGamma(FX_FLOAT gammaValue) {
+void CFX_GEModule::SetTextGamma(float gammaValue) {
gammaValue /= 2.2f;
for (int i = 0; i < 256; ++i) {
m_GammaValue[i] = static_cast<uint8_t>(
- FXSYS_pow(static_cast<FX_FLOAT>(i) / 255, gammaValue) * 255.0f + 0.5f);
+ FXSYS_pow(static_cast<float>(i) / 255, gammaValue) * 255.0f + 0.5f);
}
}
diff --git a/chromium/third_party/pdfium/core/fxge/ge/cfx_graphstate.cpp b/chromium/third_party/pdfium/core/fxge/ge/cfx_graphstate.cpp
index 6357aa51a41..54443b96365 100644
--- a/chromium/third_party/pdfium/core/fxge/ge/cfx_graphstate.cpp
+++ b/chromium/third_party/pdfium/core/fxge/ge/cfx_graphstate.cpp
@@ -19,9 +19,7 @@ void CFX_GraphState::Emplace() {
m_Ref.Emplace();
}
-void CFX_GraphState::SetLineDash(CPDF_Array* pArray,
- FX_FLOAT phase,
- FX_FLOAT scale) {
+void CFX_GraphState::SetLineDash(CPDF_Array* pArray, float phase, float scale) {
CFX_GraphStateData* pData = m_Ref.GetPrivateCopy();
pData->m_DashPhase = phase * scale;
pData->SetDashCount(static_cast<int>(pArray->GetCount()));
@@ -29,11 +27,11 @@ void CFX_GraphState::SetLineDash(CPDF_Array* pArray,
pData->m_DashArray[i] = pArray->GetNumberAt(i) * scale;
}
-FX_FLOAT CFX_GraphState::GetLineWidth() const {
+float CFX_GraphState::GetLineWidth() const {
return m_Ref.GetObject() ? m_Ref.GetObject()->m_LineWidth : 1.f;
}
-void CFX_GraphState::SetLineWidth(FX_FLOAT width) {
+void CFX_GraphState::SetLineWidth(float width) {
m_Ref.GetPrivateCopy()->m_LineWidth = width;
}
@@ -52,10 +50,10 @@ void CFX_GraphState::SetLineJoin(CFX_GraphStateData::LineJoin join) {
m_Ref.GetPrivateCopy()->m_LineJoin = join;
}
-FX_FLOAT CFX_GraphState::GetMiterLimit() const {
+float CFX_GraphState::GetMiterLimit() const {
return m_Ref.GetObject() ? m_Ref.GetObject()->m_MiterLimit : 10.f;
}
-void CFX_GraphState::SetMiterLimit(FX_FLOAT limit) {
+void CFX_GraphState::SetMiterLimit(float limit) {
m_Ref.GetPrivateCopy()->m_MiterLimit = limit;
}
diff --git a/chromium/third_party/pdfium/core/fxge/ge/cfx_graphstatedata.cpp b/chromium/third_party/pdfium/core/fxge/ge/cfx_graphstatedata.cpp
index 03798a63200..82fede176a5 100644
--- a/chromium/third_party/pdfium/core/fxge/ge/cfx_graphstatedata.cpp
+++ b/chromium/third_party/pdfium/core/fxge/ge/cfx_graphstatedata.cpp
@@ -33,8 +33,8 @@ void CFX_GraphStateData::Copy(const CFX_GraphStateData& src) {
m_MiterLimit = src.m_MiterLimit;
m_LineWidth = src.m_LineWidth;
if (m_DashCount) {
- m_DashArray = FX_Alloc(FX_FLOAT, m_DashCount);
- FXSYS_memcpy(m_DashArray, src.m_DashArray, m_DashCount * sizeof(FX_FLOAT));
+ m_DashArray = FX_Alloc(float, m_DashCount);
+ memcpy(m_DashArray, src.m_DashArray, m_DashCount * sizeof(float));
}
}
@@ -48,5 +48,5 @@ void CFX_GraphStateData::SetDashCount(int count) {
m_DashCount = count;
if (count == 0)
return;
- m_DashArray = FX_Alloc(FX_FLOAT, count);
+ m_DashArray = FX_Alloc(float, count);
}
diff --git a/chromium/third_party/pdfium/core/fxge/ge/cfx_pathdata.cpp b/chromium/third_party/pdfium/core/fxge/ge/cfx_pathdata.cpp
index 9fa2cd2aacf..75e4faf0ef2 100644
--- a/chromium/third_party/pdfium/core/fxge/ge/cfx_pathdata.cpp
+++ b/chromium/third_party/pdfium/core/fxge/ge/cfx_pathdata.cpp
@@ -14,7 +14,7 @@ namespace {
void UpdateLineEndPoints(CFX_FloatRect* rect,
const CFX_PointF& start_pos,
const CFX_PointF& end_pos,
- FX_FLOAT hw) {
+ float hw) {
if (start_pos.x == end_pos.x) {
if (start_pos.y == end_pos.y) {
rect->UpdateRect(end_pos.x + hw, end_pos.y + hw);
@@ -22,7 +22,7 @@ void UpdateLineEndPoints(CFX_FloatRect* rect,
return;
}
- FX_FLOAT point_y;
+ float point_y;
if (end_pos.y < start_pos.y)
point_y = end_pos.y - hw;
else
@@ -34,7 +34,7 @@ void UpdateLineEndPoints(CFX_FloatRect* rect,
}
if (start_pos.y == end_pos.y) {
- FX_FLOAT point_x;
+ float point_x;
if (end_pos.x < start_pos.x)
point_x = end_pos.x - hw;
else
@@ -46,11 +46,11 @@ void UpdateLineEndPoints(CFX_FloatRect* rect,
}
CFX_PointF diff = end_pos - start_pos;
- FX_FLOAT ll = FXSYS_sqrt2(diff.x, diff.y);
- FX_FLOAT mx = end_pos.x + hw * diff.x / ll;
- FX_FLOAT my = end_pos.y + hw * diff.y / ll;
- FX_FLOAT dx1 = hw * diff.y / ll;
- FX_FLOAT dy1 = hw * diff.x / ll;
+ float ll = FXSYS_sqrt2(diff.x, diff.y);
+ float mx = end_pos.x + hw * diff.x / ll;
+ float my = end_pos.y + hw * diff.y / ll;
+ float dx1 = hw * diff.y / ll;
+ float dy1 = hw * diff.x / ll;
rect->UpdateRect(mx - dx1, my + dy1);
rect->UpdateRect(mx + dx1, my - dy1);
}
@@ -59,23 +59,23 @@ void UpdateLineJoinPoints(CFX_FloatRect* rect,
const CFX_PointF& start_pos,
const CFX_PointF& mid_pos,
const CFX_PointF& end_pos,
- FX_FLOAT half_width,
- FX_FLOAT miter_limit) {
- FX_FLOAT start_k = 0;
- FX_FLOAT start_c = 0;
- FX_FLOAT end_k = 0;
- FX_FLOAT end_c = 0;
- FX_FLOAT start_len = 0;
- FX_FLOAT start_dc = 0;
- FX_FLOAT end_len = 0;
- FX_FLOAT end_dc = 0;
- FX_FLOAT one_twentieth = 1.0f / 20;
-
- bool bStartVert = FXSYS_fabs(start_pos.x - mid_pos.x) < one_twentieth;
- bool bEndVert = FXSYS_fabs(mid_pos.x - end_pos.x) < one_twentieth;
+ float half_width,
+ float miter_limit) {
+ float start_k = 0;
+ float start_c = 0;
+ float end_k = 0;
+ float end_c = 0;
+ float start_len = 0;
+ float start_dc = 0;
+ float end_len = 0;
+ float end_dc = 0;
+ float one_twentieth = 1.0f / 20;
+
+ bool bStartVert = fabs(start_pos.x - mid_pos.x) < one_twentieth;
+ bool bEndVert = fabs(mid_pos.x - end_pos.x) < one_twentieth;
if (bStartVert && bEndVert) {
int start_dir = mid_pos.y > start_pos.y ? 1 : -1;
- FX_FLOAT point_y = mid_pos.y + half_width * start_dir;
+ float point_y = mid_pos.y + half_width * start_dir;
rect->UpdateRect(mid_pos.x + half_width, point_y);
rect->UpdateRect(mid_pos.x - half_width, point_y);
return;
@@ -86,16 +86,15 @@ void UpdateLineJoinPoints(CFX_FloatRect* rect,
start_k = (mid_pos.y - start_pos.y) / (mid_pos.x - start_pos.x);
start_c = mid_pos.y - (start_k * mid_pos.x);
start_len = FXSYS_sqrt2(start_to_mid.x, start_to_mid.y);
- start_dc = static_cast<FX_FLOAT>(
- FXSYS_fabs(half_width * start_len / start_to_mid.x));
+ start_dc =
+ static_cast<float>(fabs(half_width * start_len / start_to_mid.x));
}
if (!bEndVert) {
CFX_PointF end_to_mid = end_pos - mid_pos;
end_k = end_to_mid.y / end_to_mid.x;
end_c = mid_pos.y - (end_k * mid_pos.x);
end_len = FXSYS_sqrt2(end_to_mid.x, end_to_mid.y);
- end_dc =
- static_cast<FX_FLOAT>(FXSYS_fabs(half_width * end_len / end_to_mid.x));
+ end_dc = static_cast<float>(fabs(half_width * end_len / end_to_mid.x));
}
if (bStartVert) {
CFX_PointF outside(start_pos.x, 0);
@@ -129,7 +128,7 @@ void UpdateLineJoinPoints(CFX_FloatRect* rect,
return;
}
- if (FXSYS_fabs(start_k - end_k) < one_twentieth) {
+ if (fabs(start_k - end_k) < one_twentieth) {
int start_dir = mid_pos.x > start_pos.x ? 1 : -1;
int end_dir = end_pos.x > mid_pos.x ? 1 : -1;
if (start_dir == end_dir)
@@ -139,20 +138,20 @@ void UpdateLineJoinPoints(CFX_FloatRect* rect,
return;
}
- FX_FLOAT start_outside_c = start_c;
+ float start_outside_c = start_c;
if (end_pos.y < (start_k * end_pos.x) + start_c)
start_outside_c += start_dc;
else
start_outside_c -= start_dc;
- FX_FLOAT end_outside_c = end_c;
+ float end_outside_c = end_c;
if (start_pos.y < (end_k * start_pos.x) + end_c)
end_outside_c += end_dc;
else
end_outside_c -= end_dc;
- FX_FLOAT join_x = (end_outside_c - start_outside_c) / (start_k - end_k);
- FX_FLOAT join_y = start_k * join_x + start_outside_c;
+ float join_x = (end_outside_c - start_outside_c) / (start_k - end_k);
+ float join_y = start_k * join_x + start_outside_c;
rect->UpdateRect(join_x, join_y);
}
@@ -203,10 +202,10 @@ void CFX_PathData::AppendPoint(const CFX_PointF& point,
m_Points.push_back(FX_PATHPOINT(point, type, closeFigure));
}
-void CFX_PathData::AppendRect(FX_FLOAT left,
- FX_FLOAT bottom,
- FX_FLOAT right,
- FX_FLOAT top) {
+void CFX_PathData::AppendRect(float left,
+ float bottom,
+ float right,
+ float top) {
m_Points.push_back(
FX_PATHPOINT(CFX_PointF(left, bottom), FXPT_TYPE::MoveTo, false));
m_Points.push_back(
@@ -230,11 +229,11 @@ CFX_FloatRect CFX_PathData::GetBoundingBox() const {
return rect;
}
-CFX_FloatRect CFX_PathData::GetBoundingBox(FX_FLOAT line_width,
- FX_FLOAT miter_limit) const {
+CFX_FloatRect CFX_PathData::GetBoundingBox(float line_width,
+ float miter_limit) const {
CFX_FloatRect rect(100000.0f, 100000.0f, -100000.0f, -100000.0f);
size_t iPoint = 0;
- FX_FLOAT half_width = line_width;
+ float half_width = line_width;
int iStartPoint = 0;
int iEndPoint = 0;
int iMiddlePoint = 0;
@@ -360,8 +359,8 @@ bool CFX_PathData::GetZeroAreaPath(const CFX_Matrix* pMatrix,
(m_Points[i].m_Point.y - m_Points[next].m_Point.y) >
0)) {
int pre = i;
- if (FXSYS_fabs(m_Points[i].m_Point.y - m_Points[i - 1].m_Point.y) <
- FXSYS_fabs(m_Points[i].m_Point.y - m_Points[next].m_Point.y)) {
+ if (fabs(m_Points[i].m_Point.y - m_Points[i - 1].m_Point.y) <
+ fabs(m_Points[i].m_Point.y - m_Points[next].m_Point.y)) {
pre--;
next--;
}
@@ -375,8 +374,8 @@ bool CFX_PathData::GetZeroAreaPath(const CFX_Matrix* pMatrix,
(m_Points[i].m_Point.x - m_Points[next].m_Point.x) >
0)) {
int pre = i;
- if (FXSYS_fabs(m_Points[i].m_Point.x - m_Points[i - 1].m_Point.x) <
- FXSYS_fabs(m_Points[i].m_Point.x - m_Points[next].m_Point.x)) {
+ if (fabs(m_Points[i].m_Point.x - m_Points[i - 1].m_Point.x) <
+ fabs(m_Points[i].m_Point.x - m_Points[next].m_Point.x)) {
pre--;
next--;
}
diff --git a/chromium/third_party/pdfium/core/fxge/ge/cfx_renderdevice.cpp b/chromium/third_party/pdfium/core/fxge/ge/cfx_renderdevice.cpp
index daa67ccc91b..46127ccb07a 100644
--- a/chromium/third_party/pdfium/core/fxge/ge/cfx_renderdevice.cpp
+++ b/chromium/third_party/pdfium/core/fxge/ge/cfx_renderdevice.cpp
@@ -16,6 +16,7 @@
#include "core/fxge/cfx_fxgedevice.h"
#include "core/fxge/cfx_graphstatedata.h"
#include "core/fxge/cfx_pathdata.h"
+#include "core/fxge/dib/cfx_imagerenderer.h"
#include "core/fxge/ifx_renderdevicedriver.h"
#if defined _SKIA_SUPPORT_ || defined _SKIA_SUPPORT_PATHS_
@@ -34,17 +35,16 @@ void AdjustGlyphSpace(std::vector<FXTEXT_GLYPHPOS>* pGlyphAndPos) {
for (size_t i = glyphs.size() - 1; i > 1; --i) {
FXTEXT_GLYPHPOS& next = glyphs[i];
int next_origin = bVertical ? next.m_Origin.y : next.m_Origin.x;
- FX_FLOAT next_origin_f = bVertical ? next.m_fOrigin.y : next.m_fOrigin.x;
+ float next_origin_f = bVertical ? next.m_fOrigin.y : next.m_fOrigin.x;
FXTEXT_GLYPHPOS& current = glyphs[i - 1];
int& current_origin = bVertical ? current.m_Origin.y : current.m_Origin.x;
- FX_FLOAT current_origin_f =
+ float current_origin_f =
bVertical ? current.m_fOrigin.y : current.m_fOrigin.x;
int space = next_origin - current_origin;
- FX_FLOAT space_f = next_origin_f - current_origin_f;
- FX_FLOAT error =
- FXSYS_fabs(space_f) - FXSYS_fabs(static_cast<FX_FLOAT>(space));
+ float space_f = next_origin_f - current_origin_f;
+ float error = fabs(space_f) - fabs(static_cast<float>(space));
if (error > 0.5f)
current_origin += space > 0 ? -1 : 1;
}
@@ -195,8 +195,8 @@ void SetAlpha(uint8_t* alpha) {
void SetAlphaDoNothing(uint8_t* alpha) {}
-void DrawNormalTextHelper(CFX_DIBitmap* bitmap,
- const CFX_DIBitmap* pGlyph,
+void DrawNormalTextHelper(const CFX_RetainPtr<CFX_DIBitmap>& bitmap,
+ const CFX_RetainPtr<CFX_DIBitmap>& pGlyph,
int nrows,
int left,
int top,
@@ -417,9 +417,10 @@ CFX_Matrix CFX_RenderDevice::GetCTM() const {
return m_pDeviceDriver->GetCTM();
}
-bool CFX_RenderDevice::CreateCompatibleBitmap(CFX_DIBitmap* pDIB,
- int width,
- int height) const {
+bool CFX_RenderDevice::CreateCompatibleBitmap(
+ const CFX_RetainPtr<CFX_DIBitmap>& pDIB,
+ int width,
+ int height) const {
if (m_RenderCaps & FXRC_CMYK_OUTPUT) {
return pDIB->Create(width, height, m_RenderCaps & FXRC_ALPHA_OUTPUT
? FXDIB_Cmyka
@@ -513,29 +514,29 @@ bool CFX_RenderDevice::DrawPathWithBlend(const CFX_PathData* pPathData,
if (!rect_i.Valid())
return false;
- int width = (int)FXSYS_ceil(rect_f.right - rect_f.left);
+ int width = (int)ceil(rect_f.right - rect_f.left);
if (width < 1) {
width = 1;
if (rect_i.left == rect_i.right)
rect_i.right++;
}
- int height = (int)FXSYS_ceil(rect_f.top - rect_f.bottom);
+ int height = (int)ceil(rect_f.top - rect_f.bottom);
if (height < 1) {
height = 1;
if (rect_i.bottom == rect_i.top)
rect_i.bottom++;
}
if (rect_i.Width() >= width + 1) {
- if (rect_f.left - (FX_FLOAT)(rect_i.left) >
- (FX_FLOAT)(rect_i.right) - rect_f.right) {
+ if (rect_f.left - (float)(rect_i.left) >
+ (float)(rect_i.right) - rect_f.right) {
rect_i.left++;
} else {
rect_i.right--;
}
}
if (rect_i.Height() >= height + 1) {
- if (rect_f.top - (FX_FLOAT)(rect_i.top) >
- (FX_FLOAT)(rect_i.bottom) - rect_f.bottom) {
+ if (rect_f.top - (float)(rect_i.top) >
+ (float)(rect_i.bottom) - rect_f.bottom) {
rect_i.top++;
} else {
rect_i.bottom--;
@@ -608,24 +609,26 @@ bool CFX_RenderDevice::DrawFillStrokePath(const CFX_PathData* pPathData,
pObject2Device->TransformRect(bbox);
CFX_Matrix ctm = GetCTM();
- FX_FLOAT fScaleX = FXSYS_fabs(ctm.a);
- FX_FLOAT fScaleY = FXSYS_fabs(ctm.d);
+ float fScaleX = fabs(ctm.a);
+ float fScaleY = fabs(ctm.d);
FX_RECT rect = bbox.GetOuterRect();
- CFX_DIBitmap bitmap, Backdrop;
- if (!CreateCompatibleBitmap(&bitmap, FXSYS_round(rect.Width() * fScaleX),
+ auto bitmap = pdfium::MakeRetain<CFX_DIBitmap>();
+ auto Backdrop = pdfium::MakeRetain<CFX_DIBitmap>();
+ if (!CreateCompatibleBitmap(bitmap, FXSYS_round(rect.Width() * fScaleX),
FXSYS_round(rect.Height() * fScaleY))) {
return false;
}
- if (bitmap.HasAlpha()) {
- bitmap.Clear(0);
- Backdrop.Copy(&bitmap);
+ if (bitmap->HasAlpha()) {
+ bitmap->Clear(0);
+ Backdrop->Copy(bitmap);
} else {
- if (!m_pDeviceDriver->GetDIBits(&bitmap, rect.left, rect.top))
+ if (!m_pDeviceDriver->GetDIBits(bitmap, rect.left, rect.top))
return false;
- Backdrop.Copy(&bitmap);
+ Backdrop->Copy(bitmap);
}
CFX_FxgeDevice bitmap_device;
- bitmap_device.Attach(&bitmap, false, &Backdrop, true);
+ bitmap_device.Attach(bitmap, false, Backdrop, true);
+
CFX_Matrix matrix;
if (pObject2Device)
matrix = *pObject2Device;
@@ -641,7 +644,7 @@ bool CFX_RenderDevice::DrawFillStrokePath(const CFX_PathData* pPathData,
#endif
FX_RECT src_rect(0, 0, FXSYS_round(rect.Width() * fScaleX),
FXSYS_round(rect.Height() * fScaleY));
- return m_pDeviceDriver->SetDIBits(&bitmap, 0, &src_rect, rect.left, rect.top,
+ return m_pDeviceDriver->SetDIBits(bitmap, 0, &src_rect, rect.left, rect.top,
FXDIB_BLEND_NORMAL);
}
@@ -662,27 +665,27 @@ bool CFX_RenderDevice::FillRectWithBlend(const FX_RECT* pRect,
if (!(m_RenderCaps & FXRC_GET_BITS))
return false;
- CFX_DIBitmap bitmap;
- if (!CreateCompatibleBitmap(&bitmap, pRect->Width(), pRect->Height()))
+ auto bitmap = pdfium::MakeRetain<CFX_DIBitmap>();
+ if (!CreateCompatibleBitmap(bitmap, pRect->Width(), pRect->Height()))
return false;
- if (!m_pDeviceDriver->GetDIBits(&bitmap, pRect->left, pRect->top))
+ if (!m_pDeviceDriver->GetDIBits(bitmap, pRect->left, pRect->top))
return false;
- if (!bitmap.CompositeRect(0, 0, pRect->Width(), pRect->Height(), fill_color,
- 0, nullptr)) {
+ if (!bitmap->CompositeRect(0, 0, pRect->Width(), pRect->Height(), fill_color,
+ 0)) {
return false;
}
FX_RECT src_rect(0, 0, pRect->Width(), pRect->Height());
- m_pDeviceDriver->SetDIBits(&bitmap, 0, &src_rect, pRect->left, pRect->top,
+ m_pDeviceDriver->SetDIBits(bitmap, 0, &src_rect, pRect->left, pRect->top,
FXDIB_BLEND_NORMAL);
return true;
}
-bool CFX_RenderDevice::DrawCosmeticLine(FX_FLOAT x1,
- FX_FLOAT y1,
- FX_FLOAT x2,
- FX_FLOAT y2,
+bool CFX_RenderDevice::DrawCosmeticLine(float x1,
+ float y1,
+ float x2,
+ float y2,
uint32_t color,
int fill_mode,
int blend_type) {
@@ -698,30 +701,34 @@ bool CFX_RenderDevice::DrawCosmeticLine(FX_FLOAT x1,
fill_mode, blend_type);
}
-bool CFX_RenderDevice::GetDIBits(CFX_DIBitmap* pBitmap, int left, int top) {
+bool CFX_RenderDevice::GetDIBits(const CFX_RetainPtr<CFX_DIBitmap>& pBitmap,
+ int left,
+ int top) {
if (!(m_RenderCaps & FXRC_GET_BITS))
return false;
return m_pDeviceDriver->GetDIBits(pBitmap, left, top);
}
-CFX_DIBitmap* CFX_RenderDevice::GetBackDrop() {
+CFX_RetainPtr<CFX_DIBitmap> CFX_RenderDevice::GetBackDrop() {
return m_pDeviceDriver->GetBackDrop();
}
-bool CFX_RenderDevice::SetDIBitsWithBlend(const CFX_DIBSource* pBitmap,
- int left,
- int top,
- int blend_mode) {
+bool CFX_RenderDevice::SetDIBitsWithBlend(
+ const CFX_RetainPtr<CFX_DIBSource>& pBitmap,
+ int left,
+ int top,
+ int blend_mode) {
ASSERT(!pBitmap->IsAlphaMask());
CFX_Matrix ctm = GetCTM();
- FX_FLOAT fScaleX = FXSYS_fabs(ctm.a);
- FX_FLOAT fScaleY = FXSYS_fabs(ctm.d);
+ float fScaleX = fabs(ctm.a);
+ float fScaleY = fabs(ctm.d);
FX_RECT dest_rect(left, top,
FXSYS_round(left + pBitmap->GetWidth() / fScaleX),
FXSYS_round(top + pBitmap->GetHeight() / fScaleY));
dest_rect.Intersect(m_ClipBox);
if (dest_rect.IsEmpty())
return true;
+
FX_RECT src_rect(dest_rect.left - left, dest_rect.top - top,
dest_rect.left - left + dest_rect.Width(),
dest_rect.top - top + dest_rect.Height());
@@ -733,25 +740,26 @@ bool CFX_RenderDevice::SetDIBitsWithBlend(const CFX_DIBSource* pBitmap,
(pBitmap->HasAlpha() && !(m_RenderCaps & FXRC_ALPHA_IMAGE))) {
if (!(m_RenderCaps & FXRC_GET_BITS))
return false;
+
int bg_pixel_width = FXSYS_round(dest_rect.Width() * fScaleX);
int bg_pixel_height = FXSYS_round(dest_rect.Height() * fScaleY);
- CFX_DIBitmap background;
- if (!background.Create(
+ auto background = pdfium::MakeRetain<CFX_DIBitmap>();
+ if (!background->Create(
bg_pixel_width, bg_pixel_height,
(m_RenderCaps & FXRC_CMYK_OUTPUT) ? FXDIB_Cmyk : FXDIB_Rgb32)) {
return false;
}
- if (!m_pDeviceDriver->GetDIBits(&background, dest_rect.left,
+ if (!m_pDeviceDriver->GetDIBits(background, dest_rect.left,
dest_rect.top)) {
return false;
}
- if (!background.CompositeBitmap(0, 0, bg_pixel_width, bg_pixel_height,
- pBitmap, src_rect.left, src_rect.top,
- blend_mode, nullptr, false, nullptr)) {
+ if (!background->CompositeBitmap(0, 0, bg_pixel_width, bg_pixel_height,
+ pBitmap, src_rect.left, src_rect.top,
+ blend_mode, nullptr, false)) {
return false;
}
FX_RECT rect(0, 0, bg_pixel_width, bg_pixel_height);
- return m_pDeviceDriver->SetDIBits(&background, 0, &rect, dest_rect.left,
+ return m_pDeviceDriver->SetDIBits(background, 0, &rect, dest_rect.left,
dest_rect.top, FXDIB_BLEND_NORMAL);
}
return m_pDeviceDriver->SetDIBits(pBitmap, 0, &src_rect, dest_rect.left,
@@ -759,7 +767,7 @@ bool CFX_RenderDevice::SetDIBitsWithBlend(const CFX_DIBSource* pBitmap,
}
bool CFX_RenderDevice::StretchDIBitsWithFlagsAndBlend(
- const CFX_DIBSource* pBitmap,
+ const CFX_RetainPtr<CFX_DIBSource>& pBitmap,
int left,
int top,
int dest_width,
@@ -776,7 +784,7 @@ bool CFX_RenderDevice::StretchDIBitsWithFlagsAndBlend(
blend_mode);
}
-bool CFX_RenderDevice::SetBitMask(const CFX_DIBSource* pBitmap,
+bool CFX_RenderDevice::SetBitMask(const CFX_RetainPtr<CFX_DIBSource>& pBitmap,
int left,
int top,
uint32_t argb) {
@@ -785,23 +793,25 @@ bool CFX_RenderDevice::SetBitMask(const CFX_DIBSource* pBitmap,
FXDIB_BLEND_NORMAL);
}
-bool CFX_RenderDevice::StretchBitMask(const CFX_DIBSource* pBitmap,
- int left,
- int top,
- int dest_width,
- int dest_height,
- uint32_t color) {
+bool CFX_RenderDevice::StretchBitMask(
+ const CFX_RetainPtr<CFX_DIBSource>& pBitmap,
+ int left,
+ int top,
+ int dest_width,
+ int dest_height,
+ uint32_t color) {
return StretchBitMaskWithFlags(pBitmap, left, top, dest_width, dest_height,
color, 0);
}
-bool CFX_RenderDevice::StretchBitMaskWithFlags(const CFX_DIBSource* pBitmap,
- int left,
- int top,
- int dest_width,
- int dest_height,
- uint32_t argb,
- uint32_t flags) {
+bool CFX_RenderDevice::StretchBitMaskWithFlags(
+ const CFX_RetainPtr<CFX_DIBSource>& pBitmap,
+ int left,
+ int top,
+ int dest_width,
+ int dest_height,
+ uint32_t argb,
+ uint32_t flags) {
FX_RECT dest_rect(left, top, left + dest_width, top + dest_height);
FX_RECT clip_box = m_ClipBox;
clip_box.Intersect(dest_rect);
@@ -810,36 +820,35 @@ bool CFX_RenderDevice::StretchBitMaskWithFlags(const CFX_DIBSource* pBitmap,
FXDIB_BLEND_NORMAL);
}
-bool CFX_RenderDevice::StartDIBitsWithBlend(const CFX_DIBSource* pBitmap,
- int bitmap_alpha,
- uint32_t argb,
- const CFX_Matrix* pMatrix,
- uint32_t flags,
- void*& handle,
- int blend_mode) {
+bool CFX_RenderDevice::StartDIBitsWithBlend(
+ const CFX_RetainPtr<CFX_DIBSource>& pBitmap,
+ int bitmap_alpha,
+ uint32_t argb,
+ const CFX_Matrix* pMatrix,
+ uint32_t flags,
+ std::unique_ptr<CFX_ImageRenderer>* handle,
+ int blend_mode) {
return m_pDeviceDriver->StartDIBits(pBitmap, bitmap_alpha, argb, pMatrix,
flags, handle, blend_mode);
}
-bool CFX_RenderDevice::ContinueDIBits(void* handle, IFX_Pause* pPause) {
+bool CFX_RenderDevice::ContinueDIBits(CFX_ImageRenderer* handle,
+ IFX_Pause* pPause) {
return m_pDeviceDriver->ContinueDIBits(handle, pPause);
}
-void CFX_RenderDevice::CancelDIBits(void* handle) {
- m_pDeviceDriver->CancelDIBits(handle);
-}
-
#ifdef _SKIA_SUPPORT_
void CFX_RenderDevice::DebugVerifyBitmapIsPreMultiplied() const {
SkASSERT(0);
}
-bool CFX_RenderDevice::SetBitsWithMask(const CFX_DIBSource* pBitmap,
- const CFX_DIBSource* pMask,
- int left,
- int top,
- int bitmap_alpha,
- int blend_type) {
+bool CFX_RenderDevice::SetBitsWithMask(
+ const CFX_RetainPtr<CFX_DIBSource>& pBitmap,
+ const CFX_RetainPtr<CFX_DIBSource>& pMask,
+ int left,
+ int top,
+ int bitmap_alpha,
+ int blend_type) {
return m_pDeviceDriver->SetBitsWithMask(pBitmap, pMask, left, top,
bitmap_alpha, blend_type);
}
@@ -848,7 +857,7 @@ bool CFX_RenderDevice::SetBitsWithMask(const CFX_DIBSource* pBitmap,
bool CFX_RenderDevice::DrawNormalText(int nChars,
const FXTEXT_CHARPOS* pCharPos,
CFX_Font* pFont,
- FX_FLOAT font_size,
+ float font_size,
const CFX_Matrix* pText2Device,
uint32_t fill_color,
uint32_t text_flags) {
@@ -878,7 +887,7 @@ bool CFX_RenderDevice::DrawNormalText(int nChars,
}
char2device.Scale(font_size, -font_size);
- if (FXSYS_fabs(char2device.a) + FXSYS_fabs(char2device.b) > 50 * 1.0f ||
+ if (fabs(char2device.a) + fabs(char2device.b) > 50 * 1.0f ||
((m_DeviceClass == FXDC_PRINTER) &&
!(text_flags & FXTEXT_PRINTIMAGETEXT))) {
if (pFont->GetFace()) {
@@ -916,8 +925,8 @@ bool CFX_RenderDevice::DrawNormalText(int nChars,
}
std::vector<FXTEXT_GLYPHPOS> glyphs(nChars);
CFX_Matrix matrixCTM = GetCTM();
- FX_FLOAT scale_x = FXSYS_fabs(matrixCTM.a);
- FX_FLOAT scale_y = FXSYS_fabs(matrixCTM.d);
+ float scale_x = fabs(matrixCTM.a);
+ float scale_y = fabs(matrixCTM.d);
CFX_Matrix deviceCtm = char2device;
CFX_Matrix m(scale_x, 0, 0, scale_y, 0, 0);
deviceCtm.Concat(m);
@@ -931,7 +940,7 @@ bool CFX_RenderDevice::DrawNormalText(int nChars,
if (anti_alias < FXFT_RENDER_MODE_LCD)
glyph.m_Origin.x = FXSYS_round(glyph.m_fOrigin.x);
else
- glyph.m_Origin.x = static_cast<int>(FXSYS_floor(glyph.m_fOrigin.x));
+ glyph.m_Origin.x = static_cast<int>(floor(glyph.m_fOrigin.x));
glyph.m_Origin.y = FXSYS_round(glyph.m_fOrigin.y);
if (charpos.m_bGlyphAdjust) {
@@ -958,49 +967,50 @@ bool CFX_RenderDevice::DrawNormalText(int nChars,
bmp_rect1.right++;
bmp_rect1.bottom++;
}
- FX_RECT bmp_rect(FXSYS_round((FX_FLOAT)(bmp_rect1.left) / scale_x),
- FXSYS_round((FX_FLOAT)(bmp_rect1.top) / scale_y),
- FXSYS_round((FX_FLOAT)bmp_rect1.right / scale_x),
- FXSYS_round((FX_FLOAT)bmp_rect1.bottom / scale_y));
+ FX_RECT bmp_rect(FXSYS_round((float)(bmp_rect1.left) / scale_x),
+ FXSYS_round((float)(bmp_rect1.top) / scale_y),
+ FXSYS_round((float)bmp_rect1.right / scale_x),
+ FXSYS_round((float)bmp_rect1.bottom / scale_y));
bmp_rect.Intersect(m_ClipBox);
if (bmp_rect.IsEmpty())
return true;
+
int pixel_width = FXSYS_round(bmp_rect.Width() * scale_x);
int pixel_height = FXSYS_round(bmp_rect.Height() * scale_y);
int pixel_left = FXSYS_round(bmp_rect.left * scale_x);
int pixel_top = FXSYS_round(bmp_rect.top * scale_y);
if (anti_alias == FXFT_RENDER_MODE_MONO) {
- CFX_DIBitmap bitmap;
- if (!bitmap.Create(pixel_width, pixel_height, FXDIB_1bppMask))
+ auto bitmap = pdfium::MakeRetain<CFX_DIBitmap>();
+ if (!bitmap->Create(pixel_width, pixel_height, FXDIB_1bppMask))
return false;
- bitmap.Clear(0);
+ bitmap->Clear(0);
for (const FXTEXT_GLYPHPOS& glyph : glyphs) {
if (!glyph.m_pGlyph)
continue;
- const CFX_DIBitmap* pGlyph = &glyph.m_pGlyph->m_Bitmap;
- bitmap.TransferBitmap(
+ CFX_RetainPtr<CFX_DIBitmap> pGlyph = glyph.m_pGlyph->m_pBitmap;
+ bitmap->TransferBitmap(
glyph.m_Origin.x + glyph.m_pGlyph->m_Left - pixel_left,
glyph.m_Origin.y - glyph.m_pGlyph->m_Top - pixel_top,
pGlyph->GetWidth(), pGlyph->GetHeight(), pGlyph, 0, 0);
}
- return SetBitMask(&bitmap, bmp_rect.left, bmp_rect.top, fill_color);
+ return SetBitMask(bitmap, bmp_rect.left, bmp_rect.top, fill_color);
}
- CFX_DIBitmap bitmap;
+ auto bitmap = pdfium::MakeRetain<CFX_DIBitmap>();
if (m_bpp == 8) {
- if (!bitmap.Create(pixel_width, pixel_height, FXDIB_8bppMask))
+ if (!bitmap->Create(pixel_width, pixel_height, FXDIB_8bppMask))
return false;
} else {
- if (!CreateCompatibleBitmap(&bitmap, pixel_width, pixel_height))
+ if (!CreateCompatibleBitmap(bitmap, pixel_width, pixel_height))
return false;
}
- if (!bitmap.HasAlpha() && !bitmap.IsAlphaMask()) {
- bitmap.Clear(0xFFFFFFFF);
- if (!GetDIBits(&bitmap, bmp_rect.left, bmp_rect.top))
+ if (!bitmap->HasAlpha() && !bitmap->IsAlphaMask()) {
+ bitmap->Clear(0xFFFFFFFF);
+ if (!GetDIBits(bitmap, bmp_rect.left, bmp_rect.top))
return false;
} else {
- bitmap.Clear(0);
- if (bitmap.m_pAlphaMask)
- bitmap.m_pAlphaMask->Clear(0);
+ bitmap->Clear(0);
+ if (bitmap->m_pAlphaMask)
+ bitmap->m_pAlphaMask->Clear(0);
}
int dest_width = pixel_width;
int a = 0;
@@ -1026,14 +1036,13 @@ bool CFX_RenderDevice::DrawNormalText(int nChars,
if (!top.IsValid())
return false;
- const CFX_DIBitmap* pGlyph = &glyph.m_pGlyph->m_Bitmap;
+ CFX_RetainPtr<CFX_DIBitmap> pGlyph = glyph.m_pGlyph->m_pBitmap;
int ncols = pGlyph->GetWidth();
int nrows = pGlyph->GetHeight();
if (anti_alias == FXFT_RENDER_MODE_NORMAL) {
- if (!bitmap.CompositeMask(left.ValueOrDie(), top.ValueOrDie(), ncols,
- nrows, pGlyph, fill_color, 0, 0,
- FXDIB_BLEND_NORMAL, nullptr, false, 0,
- nullptr)) {
+ if (!bitmap->CompositeMask(left.ValueOrDie(), top.ValueOrDie(), ncols,
+ nrows, pGlyph, fill_color, 0, 0,
+ FXDIB_BLEND_NORMAL, nullptr, false, 0)) {
return false;
}
continue;
@@ -1053,21 +1062,21 @@ bool CFX_RenderDevice::DrawNormalText(int nChars,
if (start_col >= end_col)
continue;
- DrawNormalTextHelper(&bitmap, pGlyph, nrows, left.ValueOrDie(),
+ DrawNormalTextHelper(bitmap, pGlyph, nrows, left.ValueOrDie(),
top.ValueOrDie(), start_col, end_col, bNormal,
bBGRStripe, x_subpixel, a, r, g, b);
}
- if (bitmap.IsAlphaMask())
- SetBitMask(&bitmap, bmp_rect.left, bmp_rect.top, fill_color);
+ if (bitmap->IsAlphaMask())
+ SetBitMask(bitmap, bmp_rect.left, bmp_rect.top, fill_color);
else
- SetDIBits(&bitmap, bmp_rect.left, bmp_rect.top);
+ SetDIBits(bitmap, bmp_rect.left, bmp_rect.top);
return true;
}
bool CFX_RenderDevice::DrawTextPath(int nChars,
const FXTEXT_CHARPOS* pCharPos,
CFX_Font* pFont,
- FX_FLOAT font_size,
+ float font_size,
const CFX_Matrix* pText2User,
const CFX_Matrix* pUser2Device,
const CFX_GraphStateData* pGraphState,
diff --git a/chromium/third_party/pdfium/core/fxge/ge/cfx_unicodeencodingex.cpp b/chromium/third_party/pdfium/core/fxge/ge/cfx_unicodeencodingex.cpp
index c7e3303f026..cd7625fb17d 100644
--- a/chromium/third_party/pdfium/core/fxge/ge/cfx_unicodeencodingex.cpp
+++ b/chromium/third_party/pdfium/core/fxge/ge/cfx_unicodeencodingex.cpp
@@ -62,7 +62,7 @@ uint32_t CFX_UnicodeEncodingEx::GlyphFromCharCode(uint32_t charcode) {
return 0;
}
-uint32_t CFX_UnicodeEncodingEx::CharCodeFromUnicode(FX_WCHAR Unicode) const {
+uint32_t CFX_UnicodeEncodingEx::CharCodeFromUnicode(wchar_t Unicode) const {
if (m_nEncodingID == FXFM_ENCODING_UNICODE ||
m_nEncodingID == FXFM_ENCODING_MS_SYMBOL) {
return Unicode;
diff --git a/chromium/third_party/pdfium/core/fxge/ge/fx_ge_linux.cpp b/chromium/third_party/pdfium/core/fxge/ge/fx_ge_linux.cpp
index e7086bb4e0a..502a3674aba 100644
--- a/chromium/third_party/pdfium/core/fxge/ge/fx_ge_linux.cpp
+++ b/chromium/third_party/pdfium/core/fxge/ge/fx_ge_linux.cpp
@@ -15,7 +15,7 @@ namespace {
const size_t kLinuxGpNameSize = 6;
-const FX_CHAR* const g_LinuxGpFontList[][kLinuxGpNameSize] = {
+const char* const g_LinuxGpFontList[][kLinuxGpNameSize] = {
{"TakaoPGothic", "VL PGothic", "IPAPGothic", "VL Gothic", "Kochi Gothic",
"VL Gothic regular"},
{"TakaoGothic", "VL Gothic", "IPAGothic", "Kochi Gothic", nullptr,
@@ -26,19 +26,19 @@ const FX_CHAR* const g_LinuxGpFontList[][kLinuxGpNameSize] = {
"VL Gothic regular"},
};
-const FX_CHAR* const g_LinuxGbFontList[] = {
+const char* const g_LinuxGbFontList[] = {
"AR PL UMing CN Light", "WenQuanYi Micro Hei", "AR PL UKai CN",
};
-const FX_CHAR* const g_LinuxB5FontList[] = {
+const char* const g_LinuxB5FontList[] = {
"AR PL UMing TW Light", "WenQuanYi Micro Hei", "AR PL UKai TW",
};
-const FX_CHAR* const g_LinuxHGFontList[] = {
+const char* const g_LinuxHGFontList[] = {
"UnDotum",
};
-size_t GetJapanesePreference(const FX_CHAR* facearr,
+size_t GetJapanesePreference(const char* facearr,
int weight,
int pitch_family) {
CFX_ByteString face = facearr;
@@ -72,7 +72,7 @@ class CFX_LinuxFontInfo : public CFX_FolderFontInfo {
bool bItalic,
int charset,
int pitch_family,
- const FX_CHAR* family,
+ const char* family,
int& iExact) override;
bool ParseFontCfg(const char** pUserPaths);
};
@@ -81,7 +81,7 @@ void* CFX_LinuxFontInfo::MapFont(int weight,
bool bItalic,
int charset,
int pitch_family,
- const FX_CHAR* cstr_face,
+ const char* cstr_face,
int& iExact) {
void* font = GetSubstFont(cstr_face);
if (font) {
diff --git a/chromium/third_party/pdfium/core/fxge/ge/fx_ge_text.cpp b/chromium/third_party/pdfium/core/fxge/ge/fx_ge_text.cpp
index 669969db0bc..b451b543fcd 100644
--- a/chromium/third_party/pdfium/core/fxge/ge/fx_ge_text.cpp
+++ b/chromium/third_party/pdfium/core/fxge/ge/fx_ge_text.cpp
@@ -45,8 +45,8 @@ ScopedFontTransform::~ScopedFontTransform() {
FX_RECT FXGE_GetGlyphsBBox(const std::vector<FXTEXT_GLYPHPOS>& glyphs,
int anti_alias,
- FX_FLOAT retinaScaleX,
- FX_FLOAT retinaScaleY) {
+ float retinaScaleX,
+ float retinaScaleY) {
FX_RECT rect(0, 0, 0, 0);
bool bStarted = false;
for (const FXTEXT_GLYPHPOS& glyph : glyphs) {
@@ -59,7 +59,7 @@ FX_RECT FXGE_GetGlyphsBBox(const std::vector<FXTEXT_GLYPHPOS>& glyphs,
if (!char_left.IsValid())
continue;
- FX_SAFE_INT32 char_width = pGlyph->m_Bitmap.GetWidth();
+ FX_SAFE_INT32 char_width = pGlyph->m_pBitmap->GetWidth();
char_width /= retinaScaleX;
if (anti_alias == FXFT_RENDER_MODE_LCD)
char_width /= 3;
@@ -75,7 +75,7 @@ FX_RECT FXGE_GetGlyphsBBox(const std::vector<FXTEXT_GLYPHPOS>& glyphs,
if (!char_top.IsValid())
continue;
- FX_SAFE_INT32 char_height = pGlyph->m_Bitmap.GetHeight();
+ FX_SAFE_INT32 char_height = pGlyph->m_pBitmap->GetHeight();
char_height /= retinaScaleY;
if (!char_height.IsValid())
continue;
diff --git a/chromium/third_party/pdfium/core/fxge/ge/fx_text_int.h b/chromium/third_party/pdfium/core/fxge/ge/fx_text_int.h
index 4de6587d411..8ea01f91d67 100644
--- a/chromium/third_party/pdfium/core/fxge/ge/fx_text_int.h
+++ b/chromium/third_party/pdfium/core/fxge/ge/fx_text_int.h
@@ -14,7 +14,7 @@
struct _CFX_UniqueKeyGen {
void Generate(int count, ...);
- FX_CHAR m_Key[128];
+ char m_Key[128];
int m_KeyLen;
};
diff --git a/chromium/third_party/pdfium/core/fxge/ifx_renderdevicedriver.cpp b/chromium/third_party/pdfium/core/fxge/ifx_renderdevicedriver.cpp
index 77af00f4306..fae86cbfc65 100644
--- a/chromium/third_party/pdfium/core/fxge/ifx_renderdevicedriver.cpp
+++ b/chromium/third_party/pdfium/core/fxge/ifx_renderdevicedriver.cpp
@@ -39,36 +39,36 @@ bool IFX_RenderDeviceDriver::FillRectWithBlend(const FX_RECT* pRect,
return false;
}
-bool IFX_RenderDeviceDriver::DrawCosmeticLine(FX_FLOAT x1,
- FX_FLOAT y1,
- FX_FLOAT x2,
- FX_FLOAT y2,
+bool IFX_RenderDeviceDriver::DrawCosmeticLine(float x1,
+ float y1,
+ float x2,
+ float y2,
uint32_t color,
int blend_type) {
return false;
}
-bool IFX_RenderDeviceDriver::GetDIBits(CFX_DIBitmap* pBitmap,
- int left,
- int top) {
+bool IFX_RenderDeviceDriver::GetDIBits(
+ const CFX_RetainPtr<CFX_DIBitmap>& pBitmap,
+ int left,
+ int top) {
return false;
}
-CFX_DIBitmap* IFX_RenderDeviceDriver::GetBackDrop() {
- return nullptr;
+CFX_RetainPtr<CFX_DIBitmap> IFX_RenderDeviceDriver::GetBackDrop() {
+ return CFX_RetainPtr<CFX_DIBitmap>();
}
-bool IFX_RenderDeviceDriver::ContinueDIBits(void* handle, IFX_Pause* pPause) {
+bool IFX_RenderDeviceDriver::ContinueDIBits(CFX_ImageRenderer* handle,
+ IFX_Pause* pPause) {
return false;
}
-void IFX_RenderDeviceDriver::CancelDIBits(void* handle) {}
-
bool IFX_RenderDeviceDriver::DrawDeviceText(int nChars,
const FXTEXT_CHARPOS* pCharPos,
CFX_Font* pFont,
const CFX_Matrix* pObject2Device,
- FX_FLOAT font_size,
+ float font_size,
uint32_t color) {
return false;
}
@@ -91,12 +91,13 @@ bool IFX_RenderDeviceDriver::DrawShading(const CPDF_ShadingPattern* pPattern,
return false;
}
-bool IFX_RenderDeviceDriver::SetBitsWithMask(const CFX_DIBSource* pBitmap,
- const CFX_DIBSource* pMask,
- int left,
- int top,
- int bitmap_alpha,
- int blend_type) {
+bool IFX_RenderDeviceDriver::SetBitsWithMask(
+ const CFX_RetainPtr<CFX_DIBSource>& pBitmap,
+ const CFX_RetainPtr<CFX_DIBSource>& pMask,
+ int left,
+ int top,
+ int bitmap_alpha,
+ int blend_type) {
return false;
}
diff --git a/chromium/third_party/pdfium/core/fxge/ifx_renderdevicedriver.h b/chromium/third_party/pdfium/core/fxge/ifx_renderdevicedriver.h
index fd35149e42e..97f35b641b3 100644
--- a/chromium/third_party/pdfium/core/fxge/ifx_renderdevicedriver.h
+++ b/chromium/third_party/pdfium/core/fxge/ifx_renderdevicedriver.h
@@ -7,12 +7,16 @@
#ifndef CORE_FXGE_IFX_RENDERDEVICEDRIVER_H_
#define CORE_FXGE_IFX_RENDERDEVICEDRIVER_H_
+#include <memory>
+
+#include "core/fxcrt/cfx_retain_ptr.h"
#include "core/fxcrt/fx_system.h"
class CFX_DIBitmap;
class CFX_DIBSource;
class CFX_Font;
class CFX_GraphStateData;
+class CFX_ImageRenderer;
class CFX_Matrix;
class CFX_PathData;
class CPDF_ShadingPattern;
@@ -49,23 +53,25 @@ class IFX_RenderDeviceDriver {
virtual bool FillRectWithBlend(const FX_RECT* pRect,
uint32_t fill_color,
int blend_type);
- virtual bool DrawCosmeticLine(FX_FLOAT x1,
- FX_FLOAT y1,
- FX_FLOAT x2,
- FX_FLOAT y2,
+ virtual bool DrawCosmeticLine(float x1,
+ float y1,
+ float x2,
+ float y2,
uint32_t color,
int blend_type);
virtual bool GetClipBox(FX_RECT* pRect) = 0;
- virtual bool GetDIBits(CFX_DIBitmap* pBitmap, int left, int top);
- virtual CFX_DIBitmap* GetBackDrop();
- virtual bool SetDIBits(const CFX_DIBSource* pBitmap,
+ virtual bool GetDIBits(const CFX_RetainPtr<CFX_DIBitmap>& pBitmap,
+ int left,
+ int top);
+ virtual CFX_RetainPtr<CFX_DIBitmap> GetBackDrop();
+ virtual bool SetDIBits(const CFX_RetainPtr<CFX_DIBSource>& pBitmap,
uint32_t color,
const FX_RECT* pSrcRect,
int dest_left,
int dest_top,
int blend_type) = 0;
- virtual bool StretchDIBits(const CFX_DIBSource* pBitmap,
+ virtual bool StretchDIBits(const CFX_RetainPtr<CFX_DIBSource>& pBitmap,
uint32_t color,
int dest_left,
int dest_top,
@@ -74,20 +80,19 @@ class IFX_RenderDeviceDriver {
const FX_RECT* pClipRect,
uint32_t flags,
int blend_type) = 0;
- virtual bool StartDIBits(const CFX_DIBSource* pBitmap,
+ virtual bool StartDIBits(const CFX_RetainPtr<CFX_DIBSource>& pBitmap,
int bitmap_alpha,
uint32_t color,
const CFX_Matrix* pMatrix,
uint32_t flags,
- void*& handle,
+ std::unique_ptr<CFX_ImageRenderer>* handle,
int blend_type) = 0;
- virtual bool ContinueDIBits(void* handle, IFX_Pause* pPause);
- virtual void CancelDIBits(void* handle);
+ virtual bool ContinueDIBits(CFX_ImageRenderer* handle, IFX_Pause* pPause);
virtual bool DrawDeviceText(int nChars,
const FXTEXT_CHARPOS* pCharPos,
CFX_Font* pFont,
const CFX_Matrix* pObject2Device,
- FX_FLOAT font_size,
+ float font_size,
uint32_t color);
virtual void* GetPlatformSurface() const;
virtual int GetDriverType() const;
@@ -97,8 +102,8 @@ class IFX_RenderDeviceDriver {
const FX_RECT& clip_rect,
int alpha,
bool bAlphaMode);
- virtual bool SetBitsWithMask(const CFX_DIBSource* pBitmap,
- const CFX_DIBSource* pMask,
+ virtual bool SetBitsWithMask(const CFX_RetainPtr<CFX_DIBSource>& pBitmap,
+ const CFX_RetainPtr<CFX_DIBSource>& pMask,
int left,
int top,
int bitmap_alpha,
diff --git a/chromium/third_party/pdfium/core/fxge/ifx_systemfontinfo.h b/chromium/third_party/pdfium/core/fxge/ifx_systemfontinfo.h
index 1ab0ab677c5..ca7ca2c4557 100644
--- a/chromium/third_party/pdfium/core/fxge/ifx_systemfontinfo.h
+++ b/chromium/third_party/pdfium/core/fxge/ifx_systemfontinfo.h
@@ -27,7 +27,7 @@ class IFX_SystemFontInfo {
bool bItalic,
int charset,
int pitch_family,
- const FX_CHAR* face,
+ const char* face,
int& iExact) = 0;
#ifdef PDF_ENABLE_XFA
@@ -37,13 +37,13 @@ class IFX_SystemFontInfo {
int pitch_family);
#endif // PDF_ENABLE_XFA
- virtual void* GetFont(const FX_CHAR* face) = 0;
+ virtual void* GetFont(const char* face) = 0;
virtual uint32_t GetFontData(void* hFont,
uint32_t table,
uint8_t* buffer,
uint32_t size) = 0;
- virtual bool GetFaceName(void* hFont, CFX_ByteString& name) = 0;
- virtual bool GetFontCharset(void* hFont, int& charset) = 0;
+ virtual bool GetFaceName(void* hFont, CFX_ByteString* name) = 0;
+ virtual bool GetFontCharset(void* hFont, int* charset) = 0;
virtual int GetFaceIndex(void* hFont);
virtual void DeleteFont(void* hFont) = 0;
};
diff --git a/chromium/third_party/pdfium/core/fxge/skia/fx_skia_device.cpp b/chromium/third_party/pdfium/core/fxge/skia/fx_skia_device.cpp
index 7e23f97287c..df43c18fcc8 100644
--- a/chromium/third_party/pdfium/core/fxge/skia/fx_skia_device.cpp
+++ b/chromium/third_party/pdfium/core/fxge/skia/fx_skia_device.cpp
@@ -19,6 +19,9 @@
#include "core/fxge/cfx_graphstatedata.h"
#include "core/fxge/cfx_pathdata.h"
#include "core/fxge/cfx_renderdevice.h"
+#include "core/fxge/dib/cfx_bitmapcomposer.h"
+#include "core/fxge/dib/cfx_imagerenderer.h"
+#include "core/fxge/dib/cfx_imagestretcher.h"
#include "core/fxge/skia/fx_skia_device.h"
#ifdef _SKIA_SUPPORT_PATHS_
@@ -48,12 +51,12 @@
namespace {
#ifdef _SKIA_SUPPORT_PATHS_
-void RgbByteOrderTransferBitmap(CFX_DIBitmap* pBitmap,
+void RgbByteOrderTransferBitmap(const CFX_RetainPtr<CFX_DIBitmap>& pBitmap,
int dest_left,
int dest_top,
int width,
int height,
- const CFX_DIBSource* pSrcBitmap,
+ const CFX_RetainPtr<CFX_DIBSource>& pSrcBitmap,
int src_left,
int src_top) {
if (!pBitmap)
@@ -150,6 +153,9 @@ void RgbByteOrderTransferBitmap(CFX_DIBitmap* pBitmap,
#endif // _SKIA_SUPPORT_PATHS_
#define SHOW_SKIA_PATH 0 // set to 1 to print the path contents
+#if SHOW_SKIA_PATH
+#define SHOW_SKIA_PATH_SHORTHAND 0 // set to 1 for abbreviated path contents
+#endif
#define DRAW_SKIA_CLIP 0 // set to 1 to draw a green rectangle around the clip
#if SHOW_SKIA_PATH
@@ -173,38 +179,31 @@ void DebugShowCanvasMatrix(const SkCanvas* canvas) {
void DebugShowSkiaPath(const SkPath& path) {
#if SHOW_SKIA_PATH
- char buffer[4096];
- sk_bzero(buffer, sizeof(buffer));
- SkMemoryWStream stream(buffer, sizeof(buffer));
+#if SHOW_SKIA_PATH_SHORTHAND
+ printf(" **\n");
+#else
+ SkDynamicMemoryWStream stream;
path.dump(&stream, false, false);
- printf("%s", buffer);
+ std::unique_ptr<char, FxFreeDeleter> storage;
+ storage.reset(FX_Alloc(char, stream.bytesWritten()));
+ stream.copyTo(storage.get());
+ printf("%.*s", (int)stream.bytesWritten(), storage.get());
+#endif // SHOW_SKIA_PATH_SHORTHAND
#endif // SHOW_SKIA_PATH
}
void DebugShowCanvasClip(const SkCanvas* canvas) {
#if SHOW_SKIA_PATH
- SkRect local;
- SkIRect device;
- canvas->getClipBounds(&local);
+ SkRect local = canvas->getLocalClipBounds();
+ SkIRect device = canvas->getDeviceClipBounds();
+
printf("local bounds %g %g %g %g\n", local.fLeft, local.fTop, local.fRight,
local.fBottom);
- canvas->getClipDeviceBounds(&device);
printf("device bounds %d %d %d %d\n", device.fLeft, device.fTop,
device.fRight, device.fBottom);
#endif // SHOW_SKIA_PATH
}
-#if SHOW_SKIA_PATH
-void DebugShowSkiaPaint(const SkPaint& paint) {
- if (SkPaint::kFill_Style == paint.getStyle()) {
- printf("fill 0x%08x\n", paint.getColor());
- } else {
- printf("stroke 0x%08x width %g\n", paint.getColor(),
- paint.getStrokeWidth());
- }
-}
-#endif // SHOW_SKIA_PATH
-
void DebugShowSkiaDrawPath(const SkCanvas* canvas,
const SkPaint& paint,
const SkPath& path) {
@@ -258,8 +257,8 @@ void DebugDrawSkiaClipPath(SkCanvas* canvas, const SkPath& path) {}
#endif // DRAW_SKIA_CLIP
#ifdef _SKIA_SUPPORT_
-static void DebugValidate(const CFX_DIBitmap* bitmap,
- const CFX_DIBitmap* device) {
+static void DebugValidate(const CFX_RetainPtr<CFX_DIBitmap>& bitmap,
+ const CFX_RetainPtr<CFX_DIBitmap>& device) {
if (bitmap) {
SkASSERT(bitmap->GetBPP() == 8 || bitmap->GetBPP() == 32);
if (bitmap->GetBPP() == 32) {
@@ -368,7 +367,7 @@ bool AddColors(const CPDF_ExpIntFunc* pFunc, SkTDArray<SkColor>* skColors) {
return true;
}
-uint8_t FloatToByte(FX_FLOAT f) {
+uint8_t FloatToByte(float f) {
ASSERT(0 <= f && f <= 1);
return (uint8_t)(f * 255.99f);
}
@@ -395,25 +394,25 @@ bool AddSamples(const CPDF_SampledFunc* pFunc,
if (pFunc->GetSampleStream()->GetSize() < sampleCount * 3 * sampleSize / 8)
return false;
- FX_FLOAT colorsMin[3];
- FX_FLOAT colorsMax[3];
+ float colorsMin[3];
+ float colorsMax[3];
for (int i = 0; i < 3; ++i) {
colorsMin[i] = pFunc->GetRange(i * 2);
colorsMax[i] = pFunc->GetRange(i * 2 + 1);
}
const uint8_t* pSampleData = pFunc->GetSampleStream()->GetData();
for (uint32_t i = 0; i < sampleCount; ++i) {
- FX_FLOAT floatColors[3];
+ float floatColors[3];
for (uint32_t j = 0; j < 3; ++j) {
int sample = GetBits32(pSampleData, (i * 3 + j) * sampleSize, sampleSize);
- FX_FLOAT interp = (FX_FLOAT)sample / (sampleCount - 1);
+ float interp = (float)sample / (sampleCount - 1);
floatColors[j] = colorsMin[j] + (colorsMax[j] - colorsMin[j]) * interp;
}
SkColor color =
SkPackARGB32(0xFF, FloatToByte(floatColors[0]),
FloatToByte(floatColors[1]), FloatToByte(floatColors[2]));
skColors->push(color);
- skPos->push((FX_FLOAT)i / (sampleCount - 1));
+ skPos->push((float)i / (sampleCount - 1));
}
return true;
}
@@ -421,7 +420,7 @@ bool AddSamples(const CPDF_SampledFunc* pFunc,
bool AddStitching(const CPDF_StitchFunc* pFunc,
SkTDArray<SkColor>* skColors,
SkTDArray<SkScalar>* skPos) {
- FX_FLOAT boundsStart = pFunc->GetDomain(0);
+ float boundsStart = pFunc->GetDomain(0);
const auto& subFunctions = pFunc->GetSubFunctions();
int subFunctionCount = subFunctions.size();
@@ -431,7 +430,7 @@ bool AddStitching(const CPDF_StitchFunc* pFunc,
return false;
if (!AddColors(pSubFunc, skColors))
return false;
- FX_FLOAT boundsEnd =
+ float boundsEnd =
i < subFunctionCount - 1 ? pFunc->GetBound(i + 1) : pFunc->GetDomain(1);
skPos->push(boundsStart);
skPos->push(boundsEnd);
@@ -523,7 +522,9 @@ void ClipAngledGradient(const SkPoint pts[2],
}
}
ASSERT(minBounds >= 0);
- ASSERT(maxBounds != minBounds && maxBounds >= 0);
+ ASSERT(maxBounds >= 0);
+ if (minBounds == maxBounds)
+ return;
// construct a clip parallel to the gradient that goes through
// rectPts[minBounds] and rectPts[maxBounds] and perpendicular to the
// gradient that goes through startEdgePt, endEdgePt.
@@ -558,7 +559,7 @@ void SetBitmapPaint(bool isAlphaMask,
paint->setAlpha(bitmap_alpha);
}
-bool Upsample(const CFX_DIBSource* pSource,
+bool Upsample(const CFX_RetainPtr<CFX_DIBSource>& pSource,
std::unique_ptr<uint8_t, FxFreeDeleter>& dst8Storage,
std::unique_ptr<uint32_t, FxFreeDeleter>& dst32Storage,
SkColorTable** ctPtr,
@@ -657,7 +658,7 @@ class SkiaState {
// mark all cached state as uninitialized
explicit SkiaState(CFX_SkiaDeviceDriver* pDriver)
: m_pDriver(pDriver),
- m_pFont(nullptr),
+ m_pTypeFace(nullptr),
m_fontSize(0),
m_fillColor(0),
m_strokeColor(0),
@@ -771,7 +772,7 @@ class SkiaState {
const FXTEXT_CHARPOS* pCharPos,
CFX_Font* pFont,
const CFX_Matrix* pMatrix,
- FX_FLOAT font_size,
+ float font_size,
uint32_t color) {
if (m_debugDisable)
return false;
@@ -785,7 +786,7 @@ class SkiaState {
if (Accumulator::kText != m_type) {
m_positions.setCount(0);
m_glyphs.setCount(0);
- m_pFont = pFont;
+ m_pTypeFace = pFont->GetFace() ? pFont->GetDeviceCache() : nullptr;
m_fontSize = font_size;
m_fillColor = color;
m_drawMatrix = *pMatrix;
@@ -818,8 +819,8 @@ class SkiaState {
SkPaint skPaint;
skPaint.setAntiAlias(true);
skPaint.setColor(m_fillColor);
- if (m_pFont->GetFace()) { // exclude placeholder test fonts
- sk_sp<SkTypeface> typeface(SkSafeRef(m_pFont->GetDeviceCache()));
+ if (m_pTypeFace) { // exclude placeholder test fonts
+ sk_sp<SkTypeface> typeface(SkSafeRef(m_pTypeFace));
skPaint.setTypeface(typeface);
}
skPaint.setTextEncoding(SkPaint::kGlyphID_TextEncoding);
@@ -841,6 +842,8 @@ class SkiaState {
m_type = Accumulator::kNone;
}
+ bool IsEmpty() { return !m_commands.count(); }
+
bool SetClipFill(const CFX_PathData* pPathData,
const CFX_Matrix* pMatrix,
int fill_mode) {
@@ -929,20 +932,20 @@ class SkiaState {
Dump(__func__);
int count = m_commands.count();
if (m_commandIndex < count - 1) {
- if (Clip::kSave == m_commands[m_commandIndex + 1]) {
+ if (Clip::kSave == m_commands[m_commandIndex]) {
++m_commandIndex;
return true;
}
Flush();
AdjustClip(m_commandIndex);
- m_commands[++m_commandIndex] = Clip::kSave;
+ m_commands[m_commandIndex] = Clip::kSave;
m_clips[m_commandIndex] = m_skEmptyPath;
} else {
AdjustClip(m_commandIndex);
m_commands.push(Clip::kSave);
m_clips.push_back(m_skEmptyPath);
- ++m_commandIndex;
}
+ ++m_commandIndex;
return true;
}
@@ -973,9 +976,11 @@ class SkiaState {
bool FontChanged(CFX_Font* pFont,
const CFX_Matrix* pMatrix,
- FX_FLOAT font_size,
+ float font_size,
uint32_t color) const {
- return pFont != m_pFont || MatrixChanged(pMatrix, m_drawMatrix) ||
+ CFX_TypeFace* typeface =
+ pFont->GetFace() ? pFont->GetDeviceCache() : nullptr;
+ return typeface != m_pTypeFace || MatrixChanged(pMatrix, m_drawMatrix) ||
font_size != m_fontSize || color != m_fillColor;
}
@@ -1077,34 +1082,177 @@ class SkiaState {
void Dump(const char* where) const {
#if SHOW_SKIA_PATH
- printf("\n%s\nSkia Save Count %d:\n", where,
- m_pDriver->m_pCanvas->getSaveCount());
+ if (m_debugDisable)
+ return;
+ printf(
+ "\n%s\nSkia Save Count %d Agg Save Count %d"
+ " Cache Save Count %d\n",
+ where, m_pDriver->m_pCanvas->getSaveCount(),
+ (int)m_pDriver->m_StateStack.size(), m_commandIndex);
printf("Cache:\n");
+#if SHOW_SKIA_PATH_SHORTHAND
+ bool dumpedPath = false;
+#endif
for (int index = 0; index < m_commands.count(); ++index) {
+#if SHOW_SKIA_PATH_SHORTHAND
+ if (Clip::kSave == m_commands[index] && dumpedPath) {
+ printf("\n");
+ dumpedPath = false;
+ }
+#endif
DumpPrefix(index);
switch (m_commands[index]) {
case Clip::kSave:
printf("Save %d\n", ++m_debugSaveCounter);
break;
case Clip::kPath:
+#if SHOW_SKIA_PATH_SHORTHAND
+ printf("*");
+ dumpedPath = true;
+#else
m_clips[index].dump();
+#endif
break;
default:
printf("unknown\n");
}
}
+#if SHOW_SKIA_PATH_SHORTHAND
+ if (dumpedPath)
+ printf("\n");
+#endif
DumpEndPrefix();
-#endif // SHOW_SKIA_PATH
-#ifdef SK_DEBUG
int skCanvasSaveCount = m_pDriver->m_pCanvas->getSaveCount();
int cacheSaveCount = 1;
SkASSERT(m_clipIndex <= m_commands.count());
for (int index = 0; index < m_clipIndex; ++index)
cacheSaveCount += Clip::kSave == m_commands[index];
SkASSERT(skCanvasSaveCount == cacheSaveCount);
-#endif
+#endif // SHOW_SKIA_PATH
+ }
+
+ void DebugCheckClip() {
+#if SHOW_SKIA_PATH
+ if (m_debugDisable)
+ return;
+ int aggSaveCount = 0;
+ FX_RECT last;
+ bool foundLast = false;
+ for (int index = 0; index < (int)m_pDriver->m_StateStack.size(); ++index) {
+ if (!m_pDriver->m_StateStack[index]) {
+ continue;
+ }
+ if (m_pDriver->m_StateStack[index]->GetType() != CFX_ClipRgn::RectI) {
+ aggSaveCount += 1;
+ foundLast = false;
+ continue;
+ }
+ if (!foundLast || memcmp(&last, &m_pDriver->m_StateStack[index]->GetBox(),
+ sizeof(FX_RECT))) {
+ aggSaveCount += 1;
+ foundLast = true;
+ last = m_pDriver->m_StateStack[index]->GetBox();
+ }
+ }
+ if (m_pDriver->m_pClipRgn) {
+ CFX_ClipRgn::ClipType clipType = m_pDriver->m_pClipRgn->GetType();
+ if (clipType != CFX_ClipRgn::RectI || !foundLast ||
+ memcmp(&last, &m_pDriver->m_pClipRgn->GetBox(), sizeof(FX_RECT))) {
+ aggSaveCount += 1;
+ }
+ }
+ int cacheSaveCount = 0;
+ SkASSERT(m_clipIndex <= m_commands.count());
+ bool newPath = false;
+ for (int index = 0; index < m_commandIndex; ++index) {
+ if (Clip::kSave == m_commands[index]) {
+ newPath = true;
+ } else if (newPath) {
+ ++cacheSaveCount;
+ newPath = false;
+ }
+ }
+ if (aggSaveCount != cacheSaveCount) {
+ DumpClipStacks();
+ SkASSERT(0);
+ return;
+ }
+ for (int aggIndex = 0; aggIndex < (int)m_pDriver->m_StateStack.size();
+ ++aggIndex) {
+ if (!m_pDriver->m_StateStack[aggIndex])
+ continue;
+ if (m_pDriver->m_StateStack[aggIndex]->GetType() != CFX_ClipRgn::RectI)
+ continue;
+ const FX_RECT& aggRect = m_pDriver->m_StateStack[aggIndex]->GetBox();
+ SkRect skRect = SkRect::MakeLTRB(aggRect.left, aggRect.top, aggRect.right,
+ aggRect.bottom);
+ bool foundMatch = false;
+ for (int skIndex = 0; skIndex < m_commandIndex; ++skIndex) {
+ if (Clip::kPath != m_commands[skIndex])
+ continue;
+ const SkPath& clip = m_clips[skIndex];
+ SkRect bounds;
+ if (!clip.isRect(&bounds))
+ continue;
+ bounds.roundOut(&bounds);
+ if (skRect == bounds) {
+ foundMatch = true;
+ break;
+ }
+ }
+ if (!foundMatch) {
+ DumpClipStacks();
+ SkASSERT(0);
+ }
+ }
+#endif // SHOW_SKIA_PATH
}
+#if SHOW_SKIA_PATH
+ void DumpClipStacks() const {
+ if (m_debugDisable)
+ return;
+ printf("\ncache\n");
+ for (int index = 0; index < m_commandIndex; ++index) {
+ DumpPrefix(index);
+ switch (m_commands[index]) {
+ case Clip::kSave:
+ printf("Save\n");
+ break;
+ case Clip::kPath:
+ m_clips[index].dump();
+ break;
+ default:
+ printf("unknown\n");
+ }
+ }
+ printf("\nagg\n");
+ for (int index = 0; index < (int)m_pDriver->m_StateStack.size(); ++index) {
+ if (!m_pDriver->m_StateStack[index]) {
+ printf("null\n");
+ continue;
+ }
+ CFX_ClipRgn::ClipType clipType =
+ m_pDriver->m_StateStack[index]->GetType();
+ const FX_RECT& box = m_pDriver->m_StateStack[index]->GetBox();
+ printf("stack rect: %d,%d,%d,%d mask=%s\n", box.left, box.top, box.right,
+ box.bottom,
+ CFX_ClipRgn::MaskF == clipType
+ ? "1"
+ : CFX_ClipRgn::RectI == clipType ? "0" : "?");
+ }
+ if (m_pDriver->m_pClipRgn) {
+ const FX_RECT& box = m_pDriver->m_pClipRgn->GetBox();
+ CFX_ClipRgn::ClipType clipType = m_pDriver->m_pClipRgn->GetType();
+ printf("clip rect: %d,%d,%d,%d mask=%s\n", box.left, box.top, box.right,
+ box.bottom,
+ CFX_ClipRgn::MaskF == clipType
+ ? "1"
+ : CFX_ClipRgn::RectI == clipType ? "0" : "?");
+ }
+ }
+#endif // SHOW_SKIA_PATH
+
private:
SkTArray<SkPath> m_clips; // stack of clips that may be reused
SkTDArray<Clip> m_commands; // stack of clip-related commands
@@ -1117,8 +1265,8 @@ class SkiaState {
CFX_GraphStateData m_drawState;
CFX_Matrix m_clipMatrix;
CFX_SkiaDeviceDriver* m_pDriver;
- CFX_Font* m_pFont;
- FX_FLOAT m_fontSize;
+ CFX_TypeFace* m_pTypeFace;
+ float m_fontSize;
uint32_t m_fillColor;
uint32_t m_strokeColor;
int m_blendType;
@@ -1131,10 +1279,16 @@ class SkiaState {
bool m_groupKnockout;
bool m_debugDisable; // turn off cache for debugging
#if SHOW_SKIA_PATH
+ public:
mutable int m_debugSaveCounter;
+ static int m_debugInitCounter;
#endif
};
+#if SHOW_SKIA_PATH
+int SkiaState::m_debugInitCounter;
+#endif
+
// convert a stroking path to scanlines
void CFX_SkiaDeviceDriver::PaintStroke(SkPaint* spaint,
const CFX_GraphStateData* pGraphState,
@@ -1170,27 +1324,28 @@ void CFX_SkiaDeviceDriver::PaintStroke(SkPaint* spaint,
inverse.set(SkMatrix::kMTransY, 0);
SkVector deviceUnits[2] = {{0, 1}, {1, 0}};
inverse.mapPoints(deviceUnits, SK_ARRAY_COUNT(deviceUnits));
- FX_FLOAT width =
+ float width =
SkTMax(pGraphState->m_LineWidth,
SkTMin(deviceUnits[0].length(), deviceUnits[1].length()));
if (pGraphState->m_DashArray) {
int count = (pGraphState->m_DashCount + 1) / 2;
- SkScalar* intervals = FX_Alloc2D(SkScalar, count, sizeof(SkScalar));
+ std::unique_ptr<SkScalar, FxFreeDeleter> intervals(
+ FX_Alloc2D(SkScalar, count, sizeof(SkScalar)));
// Set dash pattern
for (int i = 0; i < count; i++) {
- FX_FLOAT on = pGraphState->m_DashArray[i * 2];
+ float on = pGraphState->m_DashArray[i * 2];
if (on <= 0.000001f)
on = 1.f / 10;
- FX_FLOAT off = i * 2 + 1 == pGraphState->m_DashCount
- ? on
- : pGraphState->m_DashArray[i * 2 + 1];
+ float off = i * 2 + 1 == pGraphState->m_DashCount
+ ? on
+ : pGraphState->m_DashArray[i * 2 + 1];
if (off < 0)
off = 0;
- intervals[i * 2] = on;
- intervals[i * 2 + 1] = off;
+ intervals.get()[i * 2] = on;
+ intervals.get()[i * 2 + 1] = off;
}
- spaint->setPathEffect(
- SkDashPathEffect::Make(intervals, count * 2, pGraphState->m_DashPhase));
+ spaint->setPathEffect(SkDashPathEffect::Make(intervals.get(), count * 2,
+ pGraphState->m_DashPhase));
}
spaint->setStyle(SkPaint::kStroke_Style);
spaint->setAntiAlias(true);
@@ -1200,10 +1355,11 @@ void CFX_SkiaDeviceDriver::PaintStroke(SkPaint* spaint,
spaint->setStrokeJoin(join);
}
-CFX_SkiaDeviceDriver::CFX_SkiaDeviceDriver(CFX_DIBitmap* pBitmap,
- bool bRgbByteOrder,
- CFX_DIBitmap* pOriDevice,
- bool bGroupKnockout)
+CFX_SkiaDeviceDriver::CFX_SkiaDeviceDriver(
+ const CFX_RetainPtr<CFX_DIBitmap>& pBitmap,
+ bool bRgbByteOrder,
+ const CFX_RetainPtr<CFX_DIBitmap>& pOriDevice,
+ bool bGroupKnockout)
: m_pBitmap(pBitmap),
m_pOriDevice(pOriDevice),
m_pRecorder(nullptr),
@@ -1261,7 +1417,7 @@ bool CFX_SkiaDeviceDriver::DrawDeviceText(int nChars,
const FXTEXT_CHARPOS* pCharPos,
CFX_Font* pFont,
const CFX_Matrix* pObject2Device,
- FX_FLOAT font_size,
+ float font_size,
uint32_t color) {
if (m_pCache->DrawText(nChars, pCharPos, pFont, pObject2Device, font_size,
color)) {
@@ -1354,10 +1510,14 @@ int CFX_SkiaDeviceDriver::GetDeviceCaps(int caps_id) const {
}
void CFX_SkiaDeviceDriver::SaveState() {
+ m_pCache->DebugCheckClip();
if (!m_pCache->ClipSave())
m_pCanvas->save();
#ifdef _SKIA_SUPPORT_PATHS_
+#if SHOW_SKIA_PATH
+ printf("SaveState %zd\n", m_StateStack.size());
+#endif
std::unique_ptr<CFX_ClipRgn> pClip;
if (m_pClipRgn)
pClip = pdfium::MakeUnique<CFX_ClipRgn>(*m_pClipRgn);
@@ -1366,16 +1526,24 @@ void CFX_SkiaDeviceDriver::SaveState() {
}
void CFX_SkiaDeviceDriver::RestoreState(bool bKeepSaved) {
- if (!m_pCache->ClipRestore())
- m_pCanvas->restore();
- if (bKeepSaved && !m_pCache->ClipSave())
- m_pCanvas->save();
#ifdef _SKIA_SUPPORT_PATHS_
m_pClipRgn.reset();
if (m_StateStack.empty())
return;
-
+#else
+ if (m_pCache->IsEmpty())
+ return;
+#endif
+ if (!m_pCache->ClipRestore())
+ m_pCanvas->restore();
+ if (bKeepSaved && !m_pCache->ClipSave())
+ m_pCanvas->save();
+#ifdef _SKIA_SUPPORT_PATHS_
+#if SHOW_SKIA_PATH
+ printf("RestoreState %zd %s\n", m_StateStack.size(),
+ bKeepSaved ? "bKeepSaved" : "");
+#endif
if (bKeepSaved) {
if (m_StateStack.back())
m_pClipRgn = pdfium::MakeUnique<CFX_ClipRgn>(*m_StateStack.back());
@@ -1383,6 +1551,7 @@ void CFX_SkiaDeviceDriver::RestoreState(bool bKeepSaved) {
m_pClipRgn = std::move(m_StateStack.back());
m_StateStack.pop_back();
}
+ m_pCache->DebugCheckClip();
#endif // _SKIA_SUPPORT_PATHS_
}
@@ -1392,8 +1561,7 @@ void CFX_SkiaDeviceDriver::SetClipMask(const FX_RECT& clipBox,
FX_RECT path_rect(clipBox.left, clipBox.top, clipBox.right + 1,
clipBox.bottom + 1);
path_rect.Intersect(m_pClipRgn->GetBox());
- CFX_DIBitmapRef mask;
- CFX_DIBitmap* pThisLayer = mask.Emplace();
+ auto pThisLayer = pdfium::MakeRetain<CFX_DIBitmap>();
pThisLayer->Create(path_rect.Width(), path_rect.Height(), FXDIB_8bppMask);
pThisLayer->Clear(0);
@@ -1403,15 +1571,14 @@ void CFX_SkiaDeviceDriver::SetClipMask(const FX_RECT& clipBox,
SkBitmap bitmap;
bitmap.installPixels(imageInfo, pThisLayer->GetBuffer(),
pThisLayer->GetPitch(), nullptr, nullptr, nullptr);
- SkCanvas* canvas = new SkCanvas(bitmap);
+ auto canvas = pdfium::MakeUnique<SkCanvas>(bitmap);
canvas->translate(
-path_rect.left,
-path_rect.top); // FIXME(caryclark) wrong sign(s)? upside down?
SkPaint paint;
paint.setAntiAlias((m_FillFlags & FXFILL_NOPATHSMOOTH) == 0);
canvas->drawPath(path, paint);
- m_pClipRgn->IntersectMaskF(path_rect.left, path_rect.top, mask);
- delete canvas;
+ m_pClipRgn->IntersectMaskF(path_rect.left, path_rect.top, pThisLayer);
}
#endif // _SKIA_SUPPORT_PATHS_
@@ -1435,9 +1602,9 @@ bool CFX_SkiaDeviceDriver::SetClip_PathFill(
pPathData->GetPoints().size() == 4) {
CFX_FloatRect rectf;
if (pPathData->IsRect(deviceMatrix, &rectf)) {
- rectf.Intersect(
- CFX_FloatRect(0, 0, (FX_FLOAT)GetDeviceCaps(FXDC_PIXEL_WIDTH),
- (FX_FLOAT)GetDeviceCaps(FXDC_PIXEL_HEIGHT)));
+ rectf.Intersect(CFX_FloatRect(0, 0,
+ (float)GetDeviceCaps(FXDC_PIXEL_WIDTH),
+ (float)GetDeviceCaps(FXDC_PIXEL_HEIGHT)));
// note that PDF's y-axis goes up; Skia's y-axis goes down
if (!cached) {
SkRect skClipRect =
@@ -1573,10 +1740,10 @@ bool CFX_SkiaDeviceDriver::DrawPath(
return true;
}
-bool CFX_SkiaDeviceDriver::DrawCosmeticLine(FX_FLOAT x1,
- FX_FLOAT y1,
- FX_FLOAT x2,
- FX_FLOAT y2,
+bool CFX_SkiaDeviceDriver::DrawCosmeticLine(float x1,
+ float y1,
+ float x2,
+ float y2,
uint32_t color,
int blend_type) {
return false;
@@ -1661,10 +1828,10 @@ bool CFX_SkiaDeviceDriver::DrawShading(const CPDF_ShadingPattern* pPattern,
SkPath skClip;
SkPath skPath;
if (kAxialShading == shadingType) {
- FX_FLOAT start_x = pCoords->GetNumberAt(0);
- FX_FLOAT start_y = pCoords->GetNumberAt(1);
- FX_FLOAT end_x = pCoords->GetNumberAt(2);
- FX_FLOAT end_y = pCoords->GetNumberAt(3);
+ float start_x = pCoords->GetNumberAt(0);
+ float start_y = pCoords->GetNumberAt(1);
+ float end_x = pCoords->GetNumberAt(2);
+ float end_y = pCoords->GetNumberAt(3);
SkPoint pts[] = {{start_x, start_y}, {end_x, end_y}};
skMatrix.mapPoints(pts, SK_ARRAY_COUNT(pts));
paint.setShader(SkGradientShader::MakeLinear(
@@ -1701,12 +1868,12 @@ bool CFX_SkiaDeviceDriver::DrawShading(const CPDF_ShadingPattern* pPattern,
skPath.addRect(skRect);
skMatrix.setIdentity();
} else if (kRadialShading == shadingType) {
- FX_FLOAT start_x = pCoords->GetNumberAt(0);
- FX_FLOAT start_y = pCoords->GetNumberAt(1);
- FX_FLOAT start_r = pCoords->GetNumberAt(2);
- FX_FLOAT end_x = pCoords->GetNumberAt(3);
- FX_FLOAT end_y = pCoords->GetNumberAt(4);
- FX_FLOAT end_r = pCoords->GetNumberAt(5);
+ float start_x = pCoords->GetNumberAt(0);
+ float start_y = pCoords->GetNumberAt(1);
+ float start_r = pCoords->GetNumberAt(2);
+ float end_x = pCoords->GetNumberAt(3);
+ float end_y = pCoords->GetNumberAt(4);
+ float end_r = pCoords->GetNumberAt(5);
SkPoint pts[] = {{start_x, start_y}, {end_x, end_y}};
paint.setShader(SkGradientShader::MakeTwoPointConical(
@@ -1749,11 +1916,11 @@ bool CFX_SkiaDeviceDriver::DrawShading(const CPDF_ShadingPattern* pPattern,
SkPoint tempCubics[4];
for (int i = 0; i < (int)SK_ARRAY_COUNT(tempCubics); i++)
tempCubics[i] = cubics[(flag * 3 + i) % 12];
- FXSYS_memcpy(cubics, tempCubics, sizeof(tempCubics));
+ memcpy(cubics, tempCubics, sizeof(tempCubics));
SkColor tempColors[2];
tempColors[0] = colors[flag];
tempColors[1] = colors[(flag + 1) % 4];
- FXSYS_memcpy(colors, tempColors, sizeof(tempColors));
+ memcpy(colors, tempColors, sizeof(tempColors));
}
for (int i = iStartPoint; i < (int)SK_ARRAY_COUNT(cubics); i++) {
CFX_PointF point = stream.ReadCoords();
@@ -1761,9 +1928,9 @@ bool CFX_SkiaDeviceDriver::DrawShading(const CPDF_ShadingPattern* pPattern,
cubics[i].fY = point.y;
}
for (int i = iStartColor; i < (int)SK_ARRAY_COUNT(colors); i++) {
- FX_FLOAT r;
- FX_FLOAT g;
- FX_FLOAT b;
+ float r;
+ float g;
+ float b;
std::tie(r, g, b) = stream.ReadColor();
colors[i] = SkColorSetARGBInline(0xFF, (U8CPU)(r * 255),
(U8CPU)(g * 255), (U8CPU)(b * 255));
@@ -1796,7 +1963,9 @@ bool CFX_SkiaDeviceDriver::GetClipBox(FX_RECT* pRect) {
return true;
}
-bool CFX_SkiaDeviceDriver::GetDIBits(CFX_DIBitmap* pBitmap, int left, int top) {
+bool CFX_SkiaDeviceDriver::GetDIBits(const CFX_RetainPtr<CFX_DIBitmap>& pBitmap,
+ int left,
+ int top) {
if (!m_pBitmap)
return true;
uint8_t* srcBuffer = m_pBitmap->GetBuffer();
@@ -1833,7 +2002,7 @@ bool CFX_SkiaDeviceDriver::GetDIBits(CFX_DIBitmap* pBitmap, int left, int top) {
m_pBitmap->UnPreMultiply();
FX_RECT rect(left, top, left + pBitmap->GetWidth(),
top + pBitmap->GetHeight());
- std::unique_ptr<CFX_DIBitmap> pBack;
+ CFX_RetainPtr<CFX_DIBitmap> pBack;
if (m_pOriDevice) {
pBack = m_pOriDevice->Clone(&rect);
if (!pBack)
@@ -1852,58 +2021,60 @@ bool CFX_SkiaDeviceDriver::GetDIBits(CFX_DIBitmap* pBitmap, int left, int top) {
top = std::min(top, 0);
if (m_bRgbByteOrder) {
RgbByteOrderTransferBitmap(pBitmap, 0, 0, rect.Width(), rect.Height(),
- pBack.get(), left, top);
+ pBack, left, top);
} else {
- bRet = pBitmap->TransferBitmap(0, 0, rect.Width(), rect.Height(),
- pBack.get(), left, top);
+ bRet = pBitmap->TransferBitmap(0, 0, rect.Width(), rect.Height(), pBack,
+ left, top);
}
return bRet;
#endif // _SKIA_SUPPORT_PATHS_
}
-CFX_DIBitmap* CFX_SkiaDeviceDriver::GetBackDrop() {
+CFX_RetainPtr<CFX_DIBitmap> CFX_SkiaDeviceDriver::GetBackDrop() {
return m_pOriDevice;
}
-bool CFX_SkiaDeviceDriver::SetDIBits(const CFX_DIBSource* pBitmap,
- uint32_t argb,
- const FX_RECT* pSrcRect,
- int left,
- int top,
- int blend_type) {
+bool CFX_SkiaDeviceDriver::SetDIBits(
+ const CFX_RetainPtr<CFX_DIBSource>& pBitmap,
+ uint32_t argb,
+ const FX_RECT* pSrcRect,
+ int left,
+ int top,
+ int blend_type) {
if (!m_pBitmap || !m_pBitmap->GetBuffer())
return true;
#ifdef _SKIA_SUPPORT_
CFX_Matrix m(pBitmap->GetWidth(), 0, 0, -pBitmap->GetHeight(), left,
top + pBitmap->GetHeight());
- void* dummy;
- return StartDIBits(pBitmap, 0xFF, argb, &m, 0, dummy, blend_type);
+ std::unique_ptr<CFX_ImageRenderer> dummy;
+ return StartDIBits(pBitmap, 0xFF, argb, &m, 0, &dummy, blend_type);
#endif // _SKIA_SUPPORT_
#ifdef _SKIA_SUPPORT_PATHS_
Flush();
if (pBitmap->IsAlphaMask()) {
- return m_pBitmap->CompositeMask(
- left, top, pSrcRect->Width(), pSrcRect->Height(), pBitmap, argb,
- pSrcRect->left, pSrcRect->top, blend_type, m_pClipRgn.get(),
- m_bRgbByteOrder, 0, nullptr);
+ return m_pBitmap->CompositeMask(left, top, pSrcRect->Width(),
+ pSrcRect->Height(), pBitmap, argb,
+ pSrcRect->left, pSrcRect->top, blend_type,
+ m_pClipRgn.get(), m_bRgbByteOrder, 0);
}
return m_pBitmap->CompositeBitmap(
left, top, pSrcRect->Width(), pSrcRect->Height(), pBitmap, pSrcRect->left,
- pSrcRect->top, blend_type, m_pClipRgn.get(), m_bRgbByteOrder, nullptr);
+ pSrcRect->top, blend_type, m_pClipRgn.get(), m_bRgbByteOrder);
#endif // _SKIA_SUPPORT_PATHS_
}
-bool CFX_SkiaDeviceDriver::StretchDIBits(const CFX_DIBSource* pSource,
- uint32_t argb,
- int dest_left,
- int dest_top,
- int dest_width,
- int dest_height,
- const FX_RECT* pClipRect,
- uint32_t flags,
- int blend_type) {
+bool CFX_SkiaDeviceDriver::StretchDIBits(
+ const CFX_RetainPtr<CFX_DIBSource>& pSource,
+ uint32_t argb,
+ int dest_left,
+ int dest_top,
+ int dest_width,
+ int dest_height,
+ const FX_RECT* pClipRect,
+ uint32_t flags,
+ int blend_type) {
#ifdef _SKIA_SUPPORT_
m_pCache->FlushForDraw();
if (!m_pBitmap->GetBuffer())
@@ -1915,8 +2086,8 @@ bool CFX_SkiaDeviceDriver::StretchDIBits(const CFX_DIBSource* pSource,
SkRect skClipRect = SkRect::MakeLTRB(pClipRect->left, pClipRect->bottom,
pClipRect->right, pClipRect->top);
m_pCanvas->clipRect(skClipRect, SkClipOp::kIntersect, true);
- void* dummy;
- bool result = StartDIBits(pSource, 0xFF, argb, &m, 0, dummy, blend_type);
+ std::unique_ptr<CFX_ImageRenderer> dummy;
+ bool result = StartDIBits(pSource, 0xFF, argb, &m, 0, &dummy, blend_type);
m_pCanvas->restore();
return result;
@@ -1936,7 +2107,7 @@ bool CFX_SkiaDeviceDriver::StretchDIBits(const CFX_DIBSource* pSource,
dest_clip.Intersect(*pClipRect);
CFX_BitmapComposer composer;
composer.Compose(m_pBitmap, m_pClipRgn.get(), 255, argb, dest_clip, false,
- false, false, m_bRgbByteOrder, 0, nullptr, blend_type);
+ false, false, m_bRgbByteOrder, 0, blend_type);
dest_clip.Offset(-dest_rect.left, -dest_rect.top);
CFX_ImageStretcher stretcher(&composer, pSource, dest_width, dest_height,
dest_clip, flags);
@@ -1946,13 +2117,14 @@ bool CFX_SkiaDeviceDriver::StretchDIBits(const CFX_DIBSource* pSource,
#endif // _SKIA_SUPPORT_PATHS_
}
-bool CFX_SkiaDeviceDriver::StartDIBits(const CFX_DIBSource* pSource,
- int bitmap_alpha,
- uint32_t argb,
- const CFX_Matrix* pMatrix,
- uint32_t render_flags,
- void*& handle,
- int blend_type) {
+bool CFX_SkiaDeviceDriver::StartDIBits(
+ const CFX_RetainPtr<CFX_DIBSource>& pSource,
+ int bitmap_alpha,
+ uint32_t argb,
+ const CFX_Matrix* pMatrix,
+ uint32_t render_flags,
+ std::unique_ptr<CFX_ImageRenderer>* handle,
+ int blend_type) {
#ifdef _SKIA_SUPPORT_
m_pCache->FlushForDraw();
DebugValidate(m_pBitmap, m_pOriDevice);
@@ -2000,15 +2172,15 @@ bool CFX_SkiaDeviceDriver::StartDIBits(const CFX_DIBSource* pSource,
if (!m_pBitmap->GetBuffer())
return true;
m_pBitmap->UnPreMultiply();
- CFX_ImageRenderer* pRenderer = new CFX_ImageRenderer;
- pRenderer->Start(m_pBitmap, m_pClipRgn.get(), pSource, bitmap_alpha, argb,
- pMatrix, render_flags, m_bRgbByteOrder, 0, nullptr);
- handle = pRenderer;
+ *handle = pdfium::MakeUnique<CFX_ImageRenderer>();
+ (*handle)->Start(m_pBitmap, m_pClipRgn.get(), pSource, bitmap_alpha, argb,
+ pMatrix, render_flags, m_bRgbByteOrder);
#endif // _SKIA_SUPPORT_PATHS_
return true;
}
-bool CFX_SkiaDeviceDriver::ContinueDIBits(void* handle, IFX_Pause* pPause) {
+bool CFX_SkiaDeviceDriver::ContinueDIBits(CFX_ImageRenderer* handle,
+ IFX_Pause* pPause) {
#ifdef _SKIA_SUPPORT_
m_pCache->FlushForDraw();
return false;
@@ -2019,12 +2191,13 @@ bool CFX_SkiaDeviceDriver::ContinueDIBits(void* handle, IFX_Pause* pPause) {
if (!m_pBitmap->GetBuffer()) {
return true;
}
- return static_cast<CFX_ImageRenderer*>(handle)->Continue(pPause);
+ return handle->Continue(pPause);
#endif // _SKIA_SUPPORT_PATHS_
}
#if defined _SKIA_SUPPORT_
-void CFX_SkiaDeviceDriver::PreMultiply(CFX_DIBitmap* pDIBitmap) {
+void CFX_SkiaDeviceDriver::PreMultiply(
+ const CFX_RetainPtr<CFX_DIBitmap>& pDIBitmap) {
pDIBitmap->PreMultiply();
}
#endif // _SKIA_SUPPORT_
@@ -2080,11 +2253,12 @@ void CFX_DIBitmap::UnPreMultiply() {
#endif // _SKIA_SUPPORT_PATHS_
#ifdef _SKIA_SUPPORT_
-bool CFX_SkiaDeviceDriver::DrawBitsWithMask(const CFX_DIBSource* pSource,
- const CFX_DIBSource* pMask,
- int bitmap_alpha,
- const CFX_Matrix* pMatrix,
- int blend_type) {
+bool CFX_SkiaDeviceDriver::DrawBitsWithMask(
+ const CFX_RetainPtr<CFX_DIBSource>& pSource,
+ const CFX_RetainPtr<CFX_DIBSource>& pMask,
+ int bitmap_alpha,
+ const CFX_Matrix* pMatrix,
+ int blend_type) {
DebugValidate(m_pBitmap, m_pOriDevice);
SkColorTable* srcCt = nullptr;
SkColorTable* maskCt = nullptr;
@@ -2124,12 +2298,13 @@ bool CFX_SkiaDeviceDriver::DrawBitsWithMask(const CFX_DIBSource* pSource,
return true;
}
-bool CFX_SkiaDeviceDriver::SetBitsWithMask(const CFX_DIBSource* pBitmap,
- const CFX_DIBSource* pMask,
- int dest_left,
- int dest_top,
- int bitmap_alpha,
- int blend_type) {
+bool CFX_SkiaDeviceDriver::SetBitsWithMask(
+ const CFX_RetainPtr<CFX_DIBSource>& pBitmap,
+ const CFX_RetainPtr<CFX_DIBSource>& pMask,
+ int dest_left,
+ int dest_top,
+ int bitmap_alpha,
+ int blend_type) {
if (!m_pBitmap || !m_pBitmap->GetBuffer())
return true;
CFX_Matrix m(pBitmap->GetWidth(), 0, 0, -pBitmap->GetHeight(), dest_left,
@@ -2156,11 +2331,7 @@ void CFX_SkiaDeviceDriver::DebugVerifyBitmapIsPreMultiplied() const {
}
#endif // _SKIA_SUPPORT_
-CFX_FxgeDevice::CFX_FxgeDevice() {
-#ifdef _SKIA_SUPPORT_
- m_bOwnedBitmap = false;
-#endif // _SKIA_SUPPORT_
-}
+CFX_FxgeDevice::CFX_FxgeDevice() {}
#ifdef _SKIA_SUPPORT_
void CFX_FxgeDevice::Clear(uint32_t color) {
@@ -2176,9 +2347,9 @@ SkPictureRecorder* CFX_FxgeDevice::CreateRecorder(int size_x, int size_y) {
}
#endif // _SKIA_SUPPORT_
-bool CFX_FxgeDevice::Attach(CFX_DIBitmap* pBitmap,
+bool CFX_FxgeDevice::Attach(const CFX_RetainPtr<CFX_DIBitmap>& pBitmap,
bool bRgbByteOrder,
- CFX_DIBitmap* pOriDevice,
+ const CFX_RetainPtr<CFX_DIBitmap>& pOriDevice,
bool bGroupKnockout) {
if (!pBitmap)
return false;
@@ -2200,11 +2371,9 @@ bool CFX_FxgeDevice::AttachRecorder(SkPictureRecorder* recorder) {
bool CFX_FxgeDevice::Create(int width,
int height,
FXDIB_Format format,
- CFX_DIBitmap* pOriDevice) {
- m_bOwnedBitmap = true;
- CFX_DIBitmap* pBitmap = new CFX_DIBitmap;
+ const CFX_RetainPtr<CFX_DIBitmap>& pOriDevice) {
+ auto pBitmap = pdfium::MakeRetain<CFX_DIBitmap>();
if (!pBitmap->Create(width, height, format)) {
- delete pBitmap;
return false;
}
SetBitmap(pBitmap);
@@ -2214,12 +2383,7 @@ bool CFX_FxgeDevice::Create(int width,
}
CFX_FxgeDevice::~CFX_FxgeDevice() {
-#ifdef _SKIA_SUPPORT_
Flush();
- // call destructor of CFX_RenderDevice / CFX_SkiaDeviceDriver immediately
- if (m_bOwnedBitmap && GetBitmap())
- delete GetBitmap();
-#endif // _SKIA_SUPPORT_
}
#ifdef _SKIA_SUPPORT_
@@ -2232,12 +2396,13 @@ void CFX_FxgeDevice::DebugVerifyBitmapIsPreMultiplied() const {
#endif // SK_DEBUG
}
-bool CFX_FxgeDevice::SetBitsWithMask(const CFX_DIBSource* pBitmap,
- const CFX_DIBSource* pMask,
- int left,
- int top,
- int bitmap_alpha,
- int blend_type) {
+bool CFX_FxgeDevice::SetBitsWithMask(
+ const CFX_RetainPtr<CFX_DIBSource>& pBitmap,
+ const CFX_RetainPtr<CFX_DIBSource>& pMask,
+ int left,
+ int top,
+ int bitmap_alpha,
+ int blend_type) {
CFX_SkiaDeviceDriver* skDriver =
static_cast<CFX_SkiaDeviceDriver*>(GetDeviceDriver());
if (skDriver)
@@ -2277,10 +2442,10 @@ class CFX_Renderer {
uint32_t m_Color;
bool m_bFullCover;
bool m_bRgbByteOrder;
- CFX_DIBitmap* m_pOriDevice;
+ CFX_RetainPtr<CFX_DIBitmap> m_pOriDevice;
FX_RECT m_ClipBox;
- const CFX_DIBitmap* m_pClipMask;
- CFX_DIBitmap* m_pDevice;
+ CFX_RetainPtr<CFX_DIBitmap> m_pClipMask;
+ CFX_RetainPtr<CFX_DIBitmap> m_pDevice;
const CFX_ClipRgn* m_pClipRgn;
void (CFX_Renderer::*composite_span)(uint8_t*,
int,
@@ -2919,7 +3084,7 @@ class CFX_Renderer {
}
uint8_t* dest_scan = m_pDevice->GetBuffer() + m_pDevice->GetPitch() * y;
uint8_t* dest_scan_extra_alpha = nullptr;
- CFX_DIBitmap* pAlphaMask = m_pDevice->m_pAlphaMask;
+ CFX_RetainPtr<CFX_DIBitmap> pAlphaMask = m_pDevice->m_pAlphaMask;
if (pAlphaMask) {
dest_scan_extra_alpha =
pAlphaMask->GetBuffer() + pAlphaMask->GetPitch() * y;
@@ -2968,8 +3133,8 @@ class CFX_Renderer {
}
}
- bool Init(CFX_DIBitmap* pDevice,
- CFX_DIBitmap* pOriDevice,
+ bool Init(const CFX_RetainPtr<CFX_DIBitmap>& pDevice,
+ const CFX_RetainPtr<CFX_DIBitmap>& pOriDevice,
const CFX_ClipRgn* pClipRgn,
uint32_t color,
bool bFullCover,
@@ -2990,7 +3155,7 @@ class CFX_Renderer {
}
m_pClipMask = nullptr;
if (m_pClipRgn && m_pClipRgn->GetType() == CFX_ClipRgn::MaskF) {
- m_pClipMask = m_pClipRgn->GetMask().GetObject();
+ m_pClipMask = m_pClipRgn->GetMask();
}
m_bFullCover = bFullCover;
bool bObjectCMYK = !!FXGETFLAG_COLORTYPE(alpha_flag);
diff --git a/chromium/third_party/pdfium/core/fxge/skia/fx_skia_device.h b/chromium/third_party/pdfium/core/fxge/skia/fx_skia_device.h
index ecb11045182..cde05eba67d 100644
--- a/chromium/third_party/pdfium/core/fxge/skia/fx_skia_device.h
+++ b/chromium/third_party/pdfium/core/fxge/skia/fx_skia_device.h
@@ -24,9 +24,9 @@ struct SkIRect;
class CFX_SkiaDeviceDriver : public IFX_RenderDeviceDriver {
public:
- CFX_SkiaDeviceDriver(CFX_DIBitmap* pBitmap,
+ CFX_SkiaDeviceDriver(const CFX_RetainPtr<CFX_DIBitmap>& pBitmap,
bool bRgbByteOrder,
- CFX_DIBitmap* pOriDevice,
+ const CFX_RetainPtr<CFX_DIBitmap>& pOriDevice,
bool bGroupKnockout);
#ifdef _SKIA_SUPPORT_
explicit CFX_SkiaDeviceDriver(SkPictureRecorder* recorder);
@@ -69,29 +69,31 @@ class CFX_SkiaDeviceDriver : public IFX_RenderDeviceDriver {
int blend_type) override;
/** Draw a single pixel (device dependant) line */
- bool DrawCosmeticLine(FX_FLOAT x1,
- FX_FLOAT y1,
- FX_FLOAT x2,
- FX_FLOAT y2,
+ bool DrawCosmeticLine(float x1,
+ float y1,
+ float x2,
+ float y2,
uint32_t color,
int blend_type) override;
bool GetClipBox(FX_RECT* pRect) override;
/** Load device buffer into a DIB */
- bool GetDIBits(CFX_DIBitmap* pBitmap, int left, int top) override;
+ bool GetDIBits(const CFX_RetainPtr<CFX_DIBitmap>& pBitmap,
+ int left,
+ int top) override;
- CFX_DIBitmap* GetBackDrop() override;
+ CFX_RetainPtr<CFX_DIBitmap> GetBackDrop() override;
- bool SetDIBits(const CFX_DIBSource* pBitmap,
+ bool SetDIBits(const CFX_RetainPtr<CFX_DIBSource>& pBitmap,
uint32_t color,
const FX_RECT* pSrcRect,
int dest_left,
int dest_top,
int blend_type) override;
#ifdef _SKIA_SUPPORT_
- bool SetBitsWithMask(const CFX_DIBSource* pBitmap,
- const CFX_DIBSource* pMask,
+ bool SetBitsWithMask(const CFX_RetainPtr<CFX_DIBSource>& pBitmap,
+ const CFX_RetainPtr<CFX_DIBSource>& pMask,
int dest_left,
int dest_top,
int bitmap_alpha,
@@ -102,7 +104,7 @@ class CFX_SkiaDeviceDriver : public IFX_RenderDeviceDriver {
void SetClipMask(const FX_RECT& clipBox, const SkPath& skClipPath);
#endif
- bool StretchDIBits(const CFX_DIBSource* pBitmap,
+ bool StretchDIBits(const CFX_RetainPtr<CFX_DIBSource>& pBitmap,
uint32_t color,
int dest_left,
int dest_top,
@@ -112,20 +114,18 @@ class CFX_SkiaDeviceDriver : public IFX_RenderDeviceDriver {
uint32_t flags,
int blend_type) override;
- bool StartDIBits(const CFX_DIBSource* pBitmap,
+ bool StartDIBits(const CFX_RetainPtr<CFX_DIBSource>& pBitmap,
int bitmap_alpha,
uint32_t color,
const CFX_Matrix* pMatrix,
uint32_t flags,
- void*& handle,
+ std::unique_ptr<CFX_ImageRenderer>* handle,
int blend_type) override;
- bool ContinueDIBits(void* handle, IFX_Pause* pPause) override;
+ bool ContinueDIBits(CFX_ImageRenderer* handle, IFX_Pause* pPause) override;
- void CancelDIBits(void* handle) override {}
-
- bool DrawBitsWithMask(const CFX_DIBSource* pBitmap,
- const CFX_DIBSource* pMask,
+ bool DrawBitsWithMask(const CFX_RetainPtr<CFX_DIBSource>& pBitmap,
+ const CFX_RetainPtr<CFX_DIBSource>& pMask,
int bitmap_alpha,
const CFX_Matrix* pMatrix,
int blend_type);
@@ -134,7 +134,7 @@ class CFX_SkiaDeviceDriver : public IFX_RenderDeviceDriver {
const FXTEXT_CHARPOS* pCharPos,
CFX_Font* pFont,
const CFX_Matrix* pObject2Device,
- FX_FLOAT font_size,
+ float font_size,
uint32_t color) override;
bool DrawShading(const CPDF_ShadingPattern* pPattern,
@@ -152,7 +152,7 @@ class CFX_SkiaDeviceDriver : public IFX_RenderDeviceDriver {
void Flush() override;
SkPictureRecorder* GetRecorder() const { return m_pRecorder; }
void PreMultiply() { m_pBitmap->PreMultiply(); }
- static void PreMultiply(CFX_DIBitmap* pDIBitmap);
+ static void PreMultiply(const CFX_RetainPtr<CFX_DIBitmap>& pDIBitmap);
SkCanvas* SkiaCanvas() { return m_pCanvas; }
void DebugVerifyBitmapIsPreMultiplied() const;
void Dump() const;
@@ -160,8 +160,8 @@ class CFX_SkiaDeviceDriver : public IFX_RenderDeviceDriver {
private:
friend class SkiaState;
- CFX_DIBitmap* m_pBitmap;
- CFX_DIBitmap* m_pOriDevice;
+ CFX_RetainPtr<CFX_DIBitmap> m_pBitmap;
+ CFX_RetainPtr<CFX_DIBitmap> m_pOriDevice;
SkCanvas* m_pCanvas;
SkPictureRecorder* const m_pRecorder;
std::unique_ptr<SkiaState> m_pCache;
diff --git a/chromium/third_party/pdfium/core/fxge/skia/fx_skia_device_unittest.cpp b/chromium/third_party/pdfium/core/fxge/skia/fx_skia_device_unittest.cpp
index afd47780d7f..a47a50c8369 100644
--- a/chromium/third_party/pdfium/core/fxge/skia/fx_skia_device_unittest.cpp
+++ b/chromium/third_party/pdfium/core/fxge/skia/fx_skia_device_unittest.cpp
@@ -41,7 +41,7 @@ void CommonTest(CFX_SkiaDeviceDriver* driver, const State& state) {
charPos[0].m_FontCharWidth = 4;
CFX_Font font;
- FX_FLOAT fontSize = 1;
+ float fontSize = 1;
CFX_PathData clipPath, clipPath2;
clipPath.AppendRect(0, 0, 3, 1);
clipPath2.AppendRect(0, 0, 2, 1);
@@ -125,7 +125,7 @@ void Harness(void (*Test)(CFX_SkiaDeviceDriver*, const State&),
return;
FPDFBitmap_FillRect(bitmap, 0, 0, w, h, 0x00000000);
CFX_FxgeDevice geDevice;
- CFX_DIBitmap* pBitmap = CFXBitmapFromFPDFBitmap(bitmap);
+ CFX_RetainPtr<CFX_DIBitmap> pBitmap(CFXBitmapFromFPDFBitmap(bitmap));
geDevice.Attach(pBitmap, false, nullptr, false);
CFX_SkiaDeviceDriver* driver =
static_cast<CFX_SkiaDeviceDriver*>(geDevice.GetDeviceDriver());
diff --git a/chromium/third_party/pdfium/core/fxge/win32/cfx_psrenderer.cpp b/chromium/third_party/pdfium/core/fxge/win32/cfx_psrenderer.cpp
index 74fae088d98..46af33710c7 100644
--- a/chromium/third_party/pdfium/core/fxge/win32/cfx_psrenderer.cpp
+++ b/chromium/third_party/pdfium/core/fxge/win32/cfx_psrenderer.cpp
@@ -14,6 +14,7 @@
#include "core/fxge/cfx_fontcache.h"
#include "core/fxge/cfx_pathdata.h"
#include "core/fxge/cfx_renderdevice.h"
+#include "core/fxge/dib/cfx_dibextractor.h"
#include "core/fxge/ge/fx_text_int.h"
#include "core/fxge/win32/cpsoutput.h"
#include "third_party/base/ptr_util.h"
@@ -22,7 +23,7 @@ struct PSGlyph {
CFX_Font* m_pFont;
uint32_t m_GlyphIndex;
bool m_bGlyphAdjust;
- FX_FLOAT m_AdjustMatrix[4];
+ float m_AdjustMatrix[4];
};
class CPSFont {
@@ -147,7 +148,7 @@ void CFX_PSRenderer::OutputPath(const CFX_PathData* pPathData,
}
}
}
- m_pOutput->OutputPS((const FX_CHAR*)buf.GetBuffer(), buf.GetSize());
+ m_pOutput->OutputPS((const char*)buf.GetBuffer(), buf.GetSize());
}
void CFX_PSRenderer::SetClip_PathFill(const CFX_PathData* pPathData,
@@ -180,7 +181,7 @@ void CFX_PSRenderer::SetClip_PathStroke(const CFX_PathData* pPathData,
buf << "mx Cm [" << pObject2Device->a << " " << pObject2Device->b << " "
<< pObject2Device->c << " " << pObject2Device->d << " "
<< pObject2Device->e << " " << pObject2Device->f << "]cm ";
- m_pOutput->OutputPS((const FX_CHAR*)buf.GetBuffer(), buf.GetSize());
+ m_pOutput->OutputPS((const char*)buf.GetBuffer(), buf.GetSize());
}
OutputPath(pPathData, nullptr);
CFX_FloatRect rect = pPathData->GetBoundingBox(pGraphState->m_LineWidth,
@@ -219,7 +220,7 @@ bool CFX_PSRenderer::DrawPath(const CFX_PathData* pPathData,
buf << "mx Cm [" << pObject2Device->a << " " << pObject2Device->b << " "
<< pObject2Device->c << " " << pObject2Device->d << " "
<< pObject2Device->e << " " << pObject2Device->f << "]cm ";
- m_pOutput->OutputPS((const FX_CHAR*)buf.GetBuffer(), buf.GetSize());
+ m_pOutput->OutputPS((const char*)buf.GetBuffer(), buf.GetSize());
}
}
OutputPath(pPathData, stroke_alpha ? nullptr : pObject2Device);
@@ -259,8 +260,8 @@ void CFX_PSRenderer::SetGraphState(const CFX_GraphStateData* pGraphState) {
}
if (!m_bGraphStateSet ||
m_CurGraphState.m_DashCount != pGraphState->m_DashCount ||
- FXSYS_memcmp(m_CurGraphState.m_DashArray, pGraphState->m_DashArray,
- sizeof(FX_FLOAT) * m_CurGraphState.m_DashCount)) {
+ memcmp(m_CurGraphState.m_DashArray, pGraphState->m_DashArray,
+ sizeof(float) * m_CurGraphState.m_DashCount)) {
buf << "[";
for (int i = 0; i < pGraphState->m_DashCount; ++i) {
buf << pGraphState->m_DashArray[i] << " ";
@@ -282,7 +283,7 @@ void CFX_PSRenderer::SetGraphState(const CFX_GraphStateData* pGraphState) {
m_CurGraphState.Copy(*pGraphState);
m_bGraphStateSet = true;
if (buf.GetSize()) {
- m_pOutput->OutputPS((const FX_CHAR*)buf.GetBuffer(), buf.GetSize());
+ m_pOutput->OutputPS((const char*)buf.GetBuffer(), buf.GetSize());
}
}
@@ -306,7 +307,7 @@ static void PSCompressData(int PSLevel,
uint32_t src_size,
uint8_t** output_buf,
uint32_t* output_size,
- const FX_CHAR** filter) {
+ const char** filter) {
*output_buf = src_buf;
*output_size = src_size;
*filter = "";
@@ -338,18 +339,18 @@ static void PSCompressData(int PSLevel,
}
}
-bool CFX_PSRenderer::SetDIBits(const CFX_DIBSource* pSource,
+bool CFX_PSRenderer::SetDIBits(const CFX_RetainPtr<CFX_DIBSource>& pSource,
uint32_t color,
int left,
int top) {
StartRendering();
- CFX_Matrix matrix((FX_FLOAT)(pSource->GetWidth()), 0.0f, 0.0f,
- -(FX_FLOAT)(pSource->GetHeight()), (FX_FLOAT)(left),
- (FX_FLOAT)(top + pSource->GetHeight()));
+ CFX_Matrix matrix((float)(pSource->GetWidth()), 0.0f, 0.0f,
+ -(float)(pSource->GetHeight()), (float)(left),
+ (float)(top + pSource->GetHeight()));
return DrawDIBits(pSource, color, &matrix, 0);
}
-bool CFX_PSRenderer::StretchDIBits(const CFX_DIBSource* pSource,
+bool CFX_PSRenderer::StretchDIBits(const CFX_RetainPtr<CFX_DIBSource>& pSource,
uint32_t color,
int dest_left,
int dest_top,
@@ -357,13 +358,12 @@ bool CFX_PSRenderer::StretchDIBits(const CFX_DIBSource* pSource,
int dest_height,
uint32_t flags) {
StartRendering();
- CFX_Matrix matrix((FX_FLOAT)(dest_width), 0.0f, 0.0f,
- (FX_FLOAT)(-dest_height), (FX_FLOAT)(dest_left),
- (FX_FLOAT)(dest_top + dest_height));
+ CFX_Matrix matrix((float)(dest_width), 0.0f, 0.0f, (float)(-dest_height),
+ (float)(dest_left), (float)(dest_top + dest_height));
return DrawDIBits(pSource, color, &matrix, flags);
}
-bool CFX_PSRenderer::DrawDIBits(const CFX_DIBSource* pSource,
+bool CFX_PSRenderer::DrawDIBits(const CFX_RetainPtr<CFX_DIBSource>& pSource,
uint32_t color,
const CFX_Matrix* pMatrix,
uint32_t flags) {
@@ -392,7 +392,7 @@ bool CFX_PSRenderer::DrawDIBits(const CFX_DIBSource* pSource,
uint8_t* src_buf = FX_Alloc(uint8_t, src_size);
for (int row = 0; row < height; row++) {
const uint8_t* src_scan = pSource->GetScanline(row);
- FXSYS_memcpy(src_buf + row * pitch, src_scan, pitch);
+ memcpy(src_buf + row * pitch, src_scan, pitch);
}
std::unique_ptr<uint8_t, FxFreeDeleter> output_buf;
uint32_t output_size;
@@ -415,30 +415,30 @@ bool CFX_PSRenderer::DrawDIBits(const CFX_DIBSource* pSource,
} else {
buf << "false 1 colorimage\n";
}
- m_pOutput->OutputPS((const FX_CHAR*)buf.GetBuffer(), buf.GetSize());
+ m_pOutput->OutputPS((const char*)buf.GetBuffer(), buf.GetSize());
WritePSBinary(output_buf.get(), output_size);
output_buf.release();
} else {
CFX_DIBExtractor source_extractor(pSource);
- CFX_MaybeOwned<CFX_DIBSource> pConverted(source_extractor.GetBitmap());
- if (!pConverted.Get())
+ CFX_RetainPtr<CFX_DIBSource> pConverted = source_extractor.GetBitmap();
+ if (!pConverted)
return false;
switch (pSource->GetFormat()) {
case FXDIB_1bppRgb:
case FXDIB_Rgb32:
- pConverted = pConverted->CloneConvert(FXDIB_Rgb).release();
+ pConverted = pConverted->CloneConvert(FXDIB_Rgb);
break;
case FXDIB_8bppRgb:
if (pSource->GetPalette()) {
- pConverted = pConverted->CloneConvert(FXDIB_Rgb).release();
+ pConverted = pConverted->CloneConvert(FXDIB_Rgb);
}
break;
case FXDIB_1bppCmyk:
- pConverted = pConverted->CloneConvert(FXDIB_Cmyk).release();
+ pConverted = pConverted->CloneConvert(FXDIB_Cmyk);
break;
case FXDIB_8bppCmyk:
if (pSource->GetPalette()) {
- pConverted = pConverted->CloneConvert(FXDIB_Cmyk).release();
+ pConverted = pConverted->CloneConvert(FXDIB_Cmyk);
}
break;
default:
@@ -451,10 +451,9 @@ bool CFX_PSRenderer::DrawDIBits(const CFX_DIBSource* pSource,
int bpp = pConverted->GetBPP() / 8;
uint8_t* output_buf = nullptr;
FX_STRSIZE output_size = 0;
- const FX_CHAR* filter = nullptr;
+ const char* filter = nullptr;
if ((m_PSLevel == 2 || flags & FXRENDER_IMAGE_LOSSY) &&
- CCodec_JpegModule::JpegEncode(pConverted.Get(), &output_buf,
- &output_size)) {
+ CCodec_JpegModule::JpegEncode(pConverted, &output_buf, &output_size)) {
filter = "/DCTDecode filter ";
}
if (!filter) {
@@ -472,7 +471,7 @@ bool CFX_PSRenderer::DrawDIBits(const CFX_DIBSource* pSource,
src_scan += 3;
}
} else {
- FXSYS_memcpy(dest_scan, src_scan, src_pitch);
+ memcpy(dest_scan, src_scan, src_pitch);
}
}
uint8_t* compressed_buf;
@@ -493,7 +492,7 @@ bool CFX_PSRenderer::DrawDIBits(const CFX_DIBSource* pSource,
}
buf << "false " << bpp;
buf << " colorimage\n";
- m_pOutput->OutputPS((const FX_CHAR*)buf.GetBuffer(), buf.GetSize());
+ m_pOutput->OutputPS((const char*)buf.GetBuffer(), buf.GetSize());
WritePSBinary(output_buf, output_size);
FX_Free(output_buf);
}
@@ -518,7 +517,7 @@ void CFX_PSRenderer::SetColor(uint32_t color) {
m_bColorSet = true;
m_LastColor = color;
}
- m_pOutput->OutputPS((const FX_CHAR*)buf.GetBuffer(), buf.GetSize());
+ m_pOutput->OutputPS((const char*)buf.GetBuffer(), buf.GetSize());
}
}
@@ -534,14 +533,14 @@ void CFX_PSRenderer::FindPSFontGlyph(CFX_FaceCache* pFaceCache,
pPSFont->m_Glyphs[j].m_GlyphIndex == charpos.m_GlyphIndex &&
((!pPSFont->m_Glyphs[j].m_bGlyphAdjust && !charpos.m_bGlyphAdjust) ||
(pPSFont->m_Glyphs[j].m_bGlyphAdjust && charpos.m_bGlyphAdjust &&
- (FXSYS_fabs(pPSFont->m_Glyphs[j].m_AdjustMatrix[0] -
- charpos.m_AdjustMatrix[0]) < 0.01 &&
- FXSYS_fabs(pPSFont->m_Glyphs[j].m_AdjustMatrix[1] -
- charpos.m_AdjustMatrix[1]) < 0.01 &&
- FXSYS_fabs(pPSFont->m_Glyphs[j].m_AdjustMatrix[2] -
- charpos.m_AdjustMatrix[2]) < 0.01 &&
- FXSYS_fabs(pPSFont->m_Glyphs[j].m_AdjustMatrix[3] -
- charpos.m_AdjustMatrix[3]) < 0.01)))) {
+ (fabs(pPSFont->m_Glyphs[j].m_AdjustMatrix[0] -
+ charpos.m_AdjustMatrix[0]) < 0.01 &&
+ fabs(pPSFont->m_Glyphs[j].m_AdjustMatrix[1] -
+ charpos.m_AdjustMatrix[1]) < 0.01 &&
+ fabs(pPSFont->m_Glyphs[j].m_AdjustMatrix[2] -
+ charpos.m_AdjustMatrix[2]) < 0.01 &&
+ fabs(pPSFont->m_Glyphs[j].m_AdjustMatrix[3] -
+ charpos.m_AdjustMatrix[3]) < 0.01)))) {
*ps_fontnum = i;
*ps_glyphindex = j;
return;
@@ -564,7 +563,7 @@ void CFX_PSRenderer::FindPSFontGlyph(CFX_FaceCache* pFaceCache,
"currentdict end\n";
buf << "/X" << static_cast<uint32_t>(m_PSFontList.size() - 1)
<< " exch definefont pop\n";
- m_pOutput->OutputPS((const FX_CHAR*)buf.GetBuffer(), buf.GetSize());
+ m_pOutput->OutputPS((const char*)buf.GetBuffer(), buf.GetSize());
buf.Clear();
}
*ps_fontnum = m_PSFontList.size() - 1;
@@ -625,14 +624,14 @@ void CFX_PSRenderer::FindPSFontGlyph(CFX_FaceCache* pFaceCache,
buf << "f}bind def end\n";
buf << "/X" << *ps_fontnum << " Ff/Encoding get " << glyphindex << "/"
<< glyphindex << " put\n";
- m_pOutput->OutputPS((const FX_CHAR*)buf.GetBuffer(), buf.GetSize());
+ m_pOutput->OutputPS((const char*)buf.GetBuffer(), buf.GetSize());
}
bool CFX_PSRenderer::DrawText(int nChars,
const FXTEXT_CHARPOS* pCharPos,
CFX_Font* pFont,
const CFX_Matrix* pObject2Device,
- FX_FLOAT font_size,
+ float font_size,
uint32_t color) {
StartRendering();
int alpha = FXARGB_A(color);
@@ -666,7 +665,7 @@ bool CFX_PSRenderer::DrawText(int nChars,
buf << hex.AsStringC() << "Tj\n";
}
buf << "Q\n";
- m_pOutput->OutputPS((const FX_CHAR*)buf.GetBuffer(), buf.GetSize());
+ m_pOutput->OutputPS((const char*)buf.GetBuffer(), buf.GetSize());
pCache->ReleaseCachedFace(pFont);
return true;
}
@@ -678,9 +677,9 @@ void CFX_PSRenderer::WritePSBinary(const uint8_t* data, int len) {
if (pEncoders &&
pEncoders->GetBasicModule()->A85Encode(data, len, &dest_buf,
&dest_size)) {
- m_pOutput->OutputPS((const FX_CHAR*)dest_buf, dest_size);
+ m_pOutput->OutputPS((const char*)dest_buf, dest_size);
FX_Free(dest_buf);
} else {
- m_pOutput->OutputPS((const FX_CHAR*)data, len);
+ m_pOutput->OutputPS((const char*)data, len);
}
}
diff --git a/chromium/third_party/pdfium/core/fxge/win32/cfx_psrenderer.h b/chromium/third_party/pdfium/core/fxge/win32/cfx_psrenderer.h
index 163c6180af4..5768d0770f4 100644
--- a/chromium/third_party/pdfium/core/fxge/win32/cfx_psrenderer.h
+++ b/chromium/third_party/pdfium/core/fxge/win32/cfx_psrenderer.h
@@ -51,18 +51,18 @@ class CFX_PSRenderer {
uint32_t fill_color,
uint32_t stroke_color,
int fill_mode);
- bool SetDIBits(const CFX_DIBSource* pBitmap,
+ bool SetDIBits(const CFX_RetainPtr<CFX_DIBSource>& pBitmap,
uint32_t color,
int dest_left,
int dest_top);
- bool StretchDIBits(const CFX_DIBSource* pBitmap,
+ bool StretchDIBits(const CFX_RetainPtr<CFX_DIBSource>& pBitmap,
uint32_t color,
int dest_left,
int dest_top,
int dest_width,
int dest_height,
uint32_t flags);
- bool DrawDIBits(const CFX_DIBSource* pBitmap,
+ bool DrawDIBits(const CFX_RetainPtr<CFX_DIBSource>& pBitmap,
uint32_t color,
const CFX_Matrix* pMatrix,
uint32_t flags);
@@ -70,7 +70,7 @@ class CFX_PSRenderer {
const FXTEXT_CHARPOS* pCharPos,
CFX_Font* pFont,
const CFX_Matrix* pObject2Device,
- FX_FLOAT font_size,
+ float font_size,
uint32_t color);
private:
diff --git a/chromium/third_party/pdfium/core/fxge/win32/cfx_windowsdib.h b/chromium/third_party/pdfium/core/fxge/win32/cfx_windowsdib.h
index 2564b7fa36a..e59e9d60a4e 100644
--- a/chromium/third_party/pdfium/core/fxge/win32/cfx_windowsdib.h
+++ b/chromium/third_party/pdfium/core/fxge/win32/cfx_windowsdib.h
@@ -10,6 +10,9 @@
#ifndef _WINDOWS_
#include <windows.h>
#endif
+
+#include "core/fxge/fx_dib.h"
+
#define WINDIB_OPEN_MEMORY 0x1
#define WINDIB_OPEN_PATHNAME 0x2
@@ -20,20 +23,25 @@ typedef struct WINDIB_Open_Args_ {
size_t memory_size;
- const FX_WCHAR* path_name;
+ const wchar_t* path_name;
} WINDIB_Open_Args_;
class CFX_WindowsDIB : public CFX_DIBitmap {
public:
- CFX_WindowsDIB(HDC hDC, int width, int height);
+ template <typename T, typename... Args>
+ friend CFX_RetainPtr<T> pdfium::MakeRetain(Args&&... args);
+
~CFX_WindowsDIB() override;
- static CFX_ByteString GetBitmapInfo(const CFX_DIBitmap* pBitmap);
- static CFX_DIBitmap* LoadFromBuf(BITMAPINFO* pbmi, void* pData);
- static HBITMAP GetDDBitmap(const CFX_DIBitmap* pBitmap, HDC hDC);
- static CFX_DIBitmap* LoadFromFile(const FX_WCHAR* filename);
- static CFX_DIBitmap* LoadFromFile(const FX_CHAR* filename);
- static CFX_DIBitmap* LoadDIBitmap(WINDIB_Open_Args_ args);
+ static CFX_ByteString GetBitmapInfo(
+ const CFX_RetainPtr<CFX_DIBitmap>& pBitmap);
+ static HBITMAP GetDDBitmap(const CFX_RetainPtr<CFX_DIBitmap>& pBitmap,
+ HDC hDC);
+
+ static CFX_RetainPtr<CFX_DIBitmap> LoadFromBuf(BITMAPINFO* pbmi, void* pData);
+ static CFX_RetainPtr<CFX_DIBitmap> LoadFromFile(const wchar_t* filename);
+ static CFX_RetainPtr<CFX_DIBitmap> LoadFromFile(const char* filename);
+ static CFX_RetainPtr<CFX_DIBitmap> LoadDIBitmap(WINDIB_Open_Args_ args);
HDC GetDC() const { return m_hMemDC; }
HBITMAP GetWindowsBitmap() const { return m_hBitmap; }
@@ -42,6 +50,8 @@ class CFX_WindowsDIB : public CFX_DIBitmap {
void SetToDevice(HDC hDC, int left, int top);
protected:
+ CFX_WindowsDIB(HDC hDC, int width, int height);
+
HDC m_hMemDC;
HBITMAP m_hBitmap;
HBITMAP m_hOldBitmap;
diff --git a/chromium/third_party/pdfium/core/fxge/win32/cpsoutput.cpp b/chromium/third_party/pdfium/core/fxge/win32/cpsoutput.cpp
index 76b37d7dacf..7a8434ec33a 100644
--- a/chromium/third_party/pdfium/core/fxge/win32/cpsoutput.cpp
+++ b/chromium/third_party/pdfium/core/fxge/win32/cpsoutput.cpp
@@ -20,16 +20,16 @@ void CPSOutput::Release() {
delete this;
}
-void CPSOutput::OutputPS(const FX_CHAR* str, int len) {
+void CPSOutput::OutputPS(const char* str, int len) {
if (len < 0)
len = static_cast<int>(FXSYS_strlen(str));
int sent_len = 0;
while (len > 0) {
- FX_CHAR buffer[1026];
+ char buffer[1026];
int send_len = std::min(len, 1024);
*(reinterpret_cast<uint16_t*>(buffer)) = send_len;
- FXSYS_memcpy(buffer + 2, str + sent_len, send_len);
+ memcpy(buffer + 2, str + sent_len, send_len);
// TODO(thestig/rbpotter): Do PASSTHROUGH for non-Chromium usage.
// ExtEscape(m_hDC, PASSTHROUGH, send_len + 2, buffer, 0, nullptr);
diff --git a/chromium/third_party/pdfium/core/fxge/win32/cpsoutput.h b/chromium/third_party/pdfium/core/fxge/win32/cpsoutput.h
index bc9225bd7e8..1a4709b36b5 100644
--- a/chromium/third_party/pdfium/core/fxge/win32/cpsoutput.h
+++ b/chromium/third_party/pdfium/core/fxge/win32/cpsoutput.h
@@ -18,7 +18,7 @@ class CPSOutput {
// IFX_PSOutput
void Release();
- void OutputPS(const FX_CHAR* str, int len);
+ void OutputPS(const char* str, int len);
HDC m_hDC;
};
diff --git a/chromium/third_party/pdfium/core/fxge/win32/dwrite_int.h b/chromium/third_party/pdfium/core/fxge/win32/dwrite_int.h
index 86ead89947a..16be7b7d4fa 100644
--- a/chromium/third_party/pdfium/core/fxge/win32/dwrite_int.h
+++ b/chromium/third_party/pdfium/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))
@@ -39,21 +43,22 @@ class CDWriteExt {
void* DwCreateFontFaceFromStream(uint8_t* pData,
uint32_t size,
int simulation_style);
- bool DwCreateRenderingTarget(CFX_DIBitmap* pSrc, void** renderTarget);
+ bool DwCreateRenderingTarget(const CFX_RetainPtr<CFX_DIBitmap>& pSrc,
+ void** renderTarget);
void DwDeleteRenderingTarget(void* renderTarget);
bool DwRendingString(void* renderTarget,
CFX_ClipRgn* pClipRgn,
FX_RECT& stringRect,
CFX_Matrix* pMatrix,
void* font,
- FX_FLOAT font_size,
+ float font_size,
FX_ARGB text_color,
int glyph_count,
unsigned short* glyph_indices,
- FX_FLOAT baselineOriginX,
- FX_FLOAT baselineOriginY,
+ float baselineOriginX,
+ float baselineOriginY,
void* glyph_offsets,
- FX_FLOAT* glyph_advances);
+ float* glyph_advances);
void DwDeleteFont(void* pFont);
protected:
diff --git a/chromium/third_party/pdfium/core/fxge/win32/fx_win32_device.cpp b/chromium/third_party/pdfium/core/fxge/win32/fx_win32_device.cpp
index 92e9b41e064..73a1ac6a0e8 100644
--- a/chromium/third_party/pdfium/core/fxge/win32/fx_win32_device.cpp
+++ b/chromium/third_party/pdfium/core/fxge/win32/fx_win32_device.cpp
@@ -15,7 +15,9 @@
#include "core/fxcrt/fx_memory.h"
#include "core/fxcrt/fx_system.h"
#include "core/fxge/cfx_windowsdevice.h"
-#include "core/fxge/dib/dib_int.h"
+#include "core/fxge/dib/cfx_dibextractor.h"
+#include "core/fxge/dib/cfx_imagerenderer.h"
+#include "core/fxge/dib/cstretchengine.h"
#include "core/fxge/fx_font.h"
#include "core/fxge/fx_freetype.h"
#include "core/fxge/ge/cfx_folderfontinfo.h"
@@ -34,15 +36,15 @@
namespace {
const struct {
- const FX_CHAR* m_pFaceName;
- const FX_CHAR* m_pVariantName;
+ const char* m_pFaceName;
+ const char* m_pVariantName;
} g_VariantNames[] = {
{"DFKai-SB", "\x19\x6A\x77\x69\xD4\x9A"},
};
const struct {
- const FX_CHAR* m_pName;
- const FX_CHAR* m_pWinName;
+ const char* m_pName;
+ const char* m_pWinName;
bool m_bBold;
bool m_bItalic;
} g_Base14Substs[] = {
@@ -61,8 +63,8 @@ const struct {
};
struct FontNameMap {
- const FX_CHAR* m_pSubFontName;
- const FX_CHAR* m_pSrcFontName;
+ const char* m_pSubFontName;
+ const char* m_pSrcFontName;
};
const FontNameMap g_JpFontNameMap[] = {
{"MS Mincho", "Heiseimin-W3"},
@@ -91,12 +93,11 @@ bool IsGDIEnabled() {
HPEN CreatePen(const CFX_GraphStateData* pGraphState,
const CFX_Matrix* pMatrix,
uint32_t argb) {
- FX_FLOAT width;
- FX_FLOAT scale = 1.f;
+ float width;
+ float scale = 1.f;
if (pMatrix)
- scale = FXSYS_fabs(pMatrix->a) > FXSYS_fabs(pMatrix->b)
- ? FXSYS_fabs(pMatrix->a)
- : FXSYS_fabs(pMatrix->b);
+ scale = fabs(pMatrix->a) > fabs(pMatrix->b) ? fabs(pMatrix->a)
+ : fabs(pMatrix->b);
if (pGraphState) {
width = scale * pGraphState->m_LineWidth;
} else {
@@ -150,7 +151,7 @@ HPEN CreatePen(const CFX_GraphStateData* pGraphState,
dashes[i] = std::max(dashes[i], 1U);
}
}
- return ExtCreatePen(PenStyle, (DWORD)FXSYS_ceil(width), &lb,
+ return ExtCreatePen(PenStyle, (DWORD)ceil(width), &lb,
pGraphState->m_DashCount,
reinterpret_cast<const DWORD*>(dashes.data()));
}
@@ -215,26 +216,26 @@ void SetPathToDC(HDC hDC,
// altogether and replace by Skia code.
struct rect_base {
- FX_FLOAT x1;
- FX_FLOAT y1;
- FX_FLOAT x2;
- FX_FLOAT y2;
+ float x1;
+ float y1;
+ float x2;
+ float y2;
};
-unsigned clip_liang_barsky(FX_FLOAT x1,
- FX_FLOAT y1,
- FX_FLOAT x2,
- FX_FLOAT y2,
+unsigned clip_liang_barsky(float x1,
+ float y1,
+ float x2,
+ float y2,
const rect_base& clip_box,
- FX_FLOAT* x,
- FX_FLOAT* y) {
- const FX_FLOAT nearzero = 1e-30f;
- FX_FLOAT deltax = x2 - x1;
- FX_FLOAT deltay = y2 - y1;
+ float* x,
+ float* y) {
+ const float nearzero = 1e-30f;
+ float deltax = x2 - x1;
+ float deltay = y2 - y1;
unsigned np = 0;
if (deltax == 0)
deltax = (x1 > clip_box.x1) ? -nearzero : nearzero;
- FX_FLOAT xin, xout;
+ float xin, xout;
if (deltax > 0) {
xin = clip_box.x1;
xout = clip_box.x2;
@@ -242,10 +243,10 @@ unsigned clip_liang_barsky(FX_FLOAT x1,
xin = clip_box.x2;
xout = clip_box.x1;
}
- FX_FLOAT tinx = (xin - x1) / deltax;
+ float tinx = (xin - x1) / deltax;
if (deltay == 0)
deltay = (y1 > clip_box.y1) ? -nearzero : nearzero;
- FX_FLOAT yin, yout;
+ float yin, yout;
if (deltay > 0) {
yin = clip_box.y1;
yout = clip_box.y2;
@@ -253,8 +254,8 @@ unsigned clip_liang_barsky(FX_FLOAT x1,
yin = clip_box.y2;
yout = clip_box.y1;
}
- FX_FLOAT tiny = (yin - y1) / deltay;
- FX_FLOAT tin1, tin2;
+ float tiny = (yin - y1) / deltay;
+ float tin1, tin2;
if (tinx < tiny) {
tin1 = tinx;
tin2 = tiny;
@@ -269,9 +270,9 @@ unsigned clip_liang_barsky(FX_FLOAT x1,
++np;
}
if (tin2 <= 1.0f) {
- FX_FLOAT toutx = (xout - x1) / deltax;
- FX_FLOAT touty = (yout - y1) / deltay;
- FX_FLOAT tout1 = (toutx < touty) ? toutx : touty;
+ float toutx = (xout - x1) / deltax;
+ float touty = (yout - y1) / deltay;
+ float tout1 = (toutx < touty) ? toutx : touty;
if (tin2 > 0 || tout1 > 0) {
if (tin2 <= tout1) {
if (tin2 > 0) {
@@ -324,7 +325,7 @@ class CFX_Win32FallbackFontInfo final : public CFX_FolderFontInfo {
bool bItalic,
int charset,
int pitch_family,
- const FX_CHAR* family,
+ const char* family,
int& iExact) override;
};
@@ -339,15 +340,15 @@ class CFX_Win32FontInfo final : public IFX_SystemFontInfo {
bool bItalic,
int charset,
int pitch_family,
- const FX_CHAR* face,
+ const char* face,
int& iExact) override;
- void* GetFont(const FX_CHAR* face) override { return nullptr; }
+ void* GetFont(const char* face) override { return nullptr; }
uint32_t GetFontData(void* hFont,
uint32_t table,
uint8_t* buffer,
uint32_t size) override;
- bool GetFaceName(void* hFont, CFX_ByteString& name) override;
- bool GetFontCharset(void* hFont, int& charset) override;
+ bool GetFaceName(void* hFont, CFX_ByteString* name) override;
+ bool GetFontCharset(void* hFont, int* charset) override;
void DeleteFont(void* hFont) override;
bool IsOpenTypeFromDiv(const LOGFONTA* plf);
@@ -446,7 +447,7 @@ void CFX_Win32FontInfo::AddInstalledFont(const LOGFONTA* plf,
bool CFX_Win32FontInfo::EnumFontList(CFX_FontMapper* pMapper) {
m_pMapper = pMapper;
LOGFONTA lf;
- FXSYS_memset(&lf, 0, sizeof(LOGFONTA));
+ memset(&lf, 0, sizeof(LOGFONTA));
lf.lfCharSet = FXFONT_DEFAULT_CHARSET;
lf.lfFaceName[0] = 0;
lf.lfPitchAndFamily = 0;
@@ -476,7 +477,7 @@ void* CFX_Win32FallbackFontInfo::MapFont(int weight,
bool bItalic,
int charset,
int pitch_family,
- const FX_CHAR* cstr_face,
+ const char* cstr_face,
int& iExact) {
void* font = GetSubstFont(cstr_face);
if (font) {
@@ -569,7 +570,7 @@ void* CFX_Win32FontInfo::MapFont(int weight,
bool bItalic,
int charset,
int pitch_family,
- const FX_CHAR* cstr_face,
+ const char* cstr_face,
int& iExact) {
CFX_ByteString face = cstr_face;
int iBaseFont;
@@ -663,7 +664,7 @@ uint32_t CFX_Win32FontInfo::GetFontData(void* hFont,
return size;
}
-bool CFX_Win32FontInfo::GetFaceName(void* hFont, CFX_ByteString& name) {
+bool CFX_Win32FontInfo::GetFaceName(void* hFont, CFX_ByteString* name) {
char facebuf[100];
HFONT hOldFont = (HFONT)::SelectObject(m_hDC, (HFONT)hFont);
int ret = ::GetTextFaceA(m_hDC, 100, facebuf);
@@ -671,16 +672,16 @@ bool CFX_Win32FontInfo::GetFaceName(void* hFont, CFX_ByteString& name) {
if (ret == 0) {
return false;
}
- name = facebuf;
+ *name = facebuf;
return true;
}
-bool CFX_Win32FontInfo::GetFontCharset(void* hFont, int& charset) {
+bool CFX_Win32FontInfo::GetFontCharset(void* hFont, int* charset) {
TEXTMETRIC tm;
HFONT hOldFont = (HFONT)::SelectObject(m_hDC, (HFONT)hFont);
::GetTextMetrics(m_hDC, &tm);
::SelectObject(m_hDC, hOldFont);
- charset = tm.tmCharSet;
+ *charset = tm.tmCharSet;
return true;
}
@@ -782,12 +783,13 @@ void CGdiDeviceDriver::RestoreState(bool bKeepSaved) {
SaveDC(m_hDC);
}
-bool CGdiDeviceDriver::GDI_SetDIBits(CFX_DIBitmap* pBitmap1,
- const FX_RECT* pSrcRect,
- int left,
- int top) {
+bool CGdiDeviceDriver::GDI_SetDIBits(
+ const CFX_RetainPtr<CFX_DIBitmap>& pBitmap1,
+ const FX_RECT* pSrcRect,
+ int left,
+ int top) {
if (m_DeviceClass == FXDC_PRINTER) {
- std::unique_ptr<CFX_DIBitmap> pBitmap = pBitmap1->FlipImage(false, true);
+ CFX_RetainPtr<CFX_DIBitmap> pBitmap = pBitmap1->FlipImage(false, true);
if (!pBitmap)
return false;
@@ -796,7 +798,7 @@ bool CGdiDeviceDriver::GDI_SetDIBits(CFX_DIBitmap* pBitmap1,
int width = pSrcRect->Width(), height = pSrcRect->Height();
LPBYTE pBuffer = pBitmap->GetBuffer();
- CFX_ByteString info = CFX_WindowsDIB::GetBitmapInfo(pBitmap.get());
+ CFX_ByteString info = CFX_WindowsDIB::GetBitmapInfo(pBitmap);
((BITMAPINFOHEADER*)info.c_str())->biHeight *= -1;
FX_RECT dst_rect(0, 0, width, height);
dst_rect.Intersect(0, 0, pBitmap->GetWidth(), pBitmap->GetHeight());
@@ -806,15 +808,15 @@ bool CGdiDeviceDriver::GDI_SetDIBits(CFX_DIBitmap* pBitmap1,
dst_height, pBuffer, (BITMAPINFO*)info.c_str(),
DIB_RGB_COLORS, SRCCOPY);
} else {
- CFX_MaybeOwned<CFX_DIBitmap> pBitmap(pBitmap1);
+ CFX_RetainPtr<CFX_DIBitmap> pBitmap = pBitmap1;
if (pBitmap->IsCmykImage()) {
- pBitmap = pBitmap->CloneConvert(FXDIB_Rgb).release();
+ pBitmap = pBitmap->CloneConvert(FXDIB_Rgb);
if (!pBitmap)
return false;
}
int width = pSrcRect->Width(), height = pSrcRect->Height();
LPBYTE pBuffer = pBitmap->GetBuffer();
- CFX_ByteString info = CFX_WindowsDIB::GetBitmapInfo(pBitmap.Get());
+ CFX_ByteString info = CFX_WindowsDIB::GetBitmapInfo(pBitmap);
::SetDIBitsToDevice(m_hDC, left, top, width, height, pSrcRect->left,
pBitmap->GetHeight() - pSrcRect->bottom, 0,
pBitmap->GetHeight(), pBuffer,
@@ -823,13 +825,14 @@ bool CGdiDeviceDriver::GDI_SetDIBits(CFX_DIBitmap* pBitmap1,
return true;
}
-bool CGdiDeviceDriver::GDI_StretchDIBits(CFX_DIBitmap* pBitmap1,
- int dest_left,
- int dest_top,
- int dest_width,
- int dest_height,
- uint32_t flags) {
- CFX_DIBitmap* pBitmap = pBitmap1;
+bool CGdiDeviceDriver::GDI_StretchDIBits(
+ const CFX_RetainPtr<CFX_DIBitmap>& pBitmap1,
+ int dest_left,
+ int dest_top,
+ int dest_width,
+ int dest_height,
+ uint32_t flags) {
+ CFX_RetainPtr<CFX_DIBitmap> pBitmap = pBitmap1;
if (!pBitmap || dest_width == 0 || dest_height == 0)
return false;
@@ -844,14 +847,14 @@ bool CGdiDeviceDriver::GDI_StretchDIBits(CFX_DIBitmap* pBitmap1,
} else {
SetStretchBltMode(m_hDC, COLORONCOLOR);
}
- CFX_MaybeOwned<CFX_DIBitmap> pToStrechBitmap(pBitmap);
+ CFX_RetainPtr<CFX_DIBitmap> pToStrechBitmap = pBitmap;
if (m_DeviceClass == FXDC_PRINTER &&
((int64_t)pBitmap->GetWidth() * pBitmap->GetHeight() >
(int64_t)abs(dest_width) * abs(dest_height))) {
pToStrechBitmap = pBitmap->StretchTo(dest_width, dest_height);
}
CFX_ByteString toStrechBitmapInfo =
- CFX_WindowsDIB::GetBitmapInfo(pToStrechBitmap.Get());
+ CFX_WindowsDIB::GetBitmapInfo(pToStrechBitmap);
::StretchDIBits(m_hDC, dest_left, dest_top, dest_width, dest_height, 0, 0,
pToStrechBitmap->GetWidth(), pToStrechBitmap->GetHeight(),
pToStrechBitmap->GetBuffer(),
@@ -860,14 +863,15 @@ bool CGdiDeviceDriver::GDI_StretchDIBits(CFX_DIBitmap* pBitmap1,
return true;
}
-bool CGdiDeviceDriver::GDI_StretchBitMask(CFX_DIBitmap* pBitmap1,
- int dest_left,
- int dest_top,
- int dest_width,
- int dest_height,
- uint32_t bitmap_color,
- uint32_t flags) {
- CFX_DIBitmap* pBitmap = pBitmap1;
+bool CGdiDeviceDriver::GDI_StretchBitMask(
+ const CFX_RetainPtr<CFX_DIBitmap>& pBitmap1,
+ int dest_left,
+ int dest_top,
+ int dest_width,
+ int dest_height,
+ uint32_t bitmap_color,
+ uint32_t flags) {
+ CFX_RetainPtr<CFX_DIBitmap> pBitmap = pBitmap1;
if (!pBitmap || dest_width == 0 || dest_height == 0)
return false;
@@ -876,7 +880,7 @@ bool CGdiDeviceDriver::GDI_StretchBitMask(CFX_DIBitmap* pBitmap1,
BITMAPINFOHEADER bmiHeader;
uint32_t bmiColors[2];
} bmi;
- FXSYS_memset(&bmi.bmiHeader, 0, sizeof(BITMAPINFOHEADER));
+ memset(&bmi.bmiHeader, 0, sizeof(BITMAPINFOHEADER));
bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
bmi.bmiHeader.biBitCount = 1;
bmi.bmiHeader.biCompression = BI_RGB;
@@ -928,10 +932,7 @@ void* CGdiDeviceDriver::GetPlatformSurface() const {
return (void*)m_hDC;
}
-void CGdiDeviceDriver::DrawLine(FX_FLOAT x1,
- FX_FLOAT y1,
- FX_FLOAT x2,
- FX_FLOAT y2) {
+void CGdiDeviceDriver::DrawLine(float x1, float y1, float x2, float y2) {
if (!m_bMetafileDCType) { // EMF drawing is not bound to the DC.
int startOutOfBoundsFlag = (x1 < 0) | ((x1 > m_Width) << 1) |
((y1 < 0) << 2) | ((y1 > m_Height) << 3);
@@ -941,18 +942,18 @@ void CGdiDeviceDriver::DrawLine(FX_FLOAT x1,
return;
if (startOutOfBoundsFlag || endOutOfBoundsFlag) {
- FX_FLOAT x[2];
- FX_FLOAT y[2];
+ float x[2];
+ float y[2];
int np;
#ifdef _SKIA_SUPPORT_
// TODO(caryclark) temporary replacement of antigrain in line function
// to permit removing antigrain altogether
- rect_base rect = {0.0f, 0.0f, (FX_FLOAT)(m_Width), (FX_FLOAT)(m_Height)};
+ rect_base rect = {0.0f, 0.0f, (float)(m_Width), (float)(m_Height)};
np = clip_liang_barsky(x1, y1, x2, y2, rect, x, y);
#else
- agg::rect_base<FX_FLOAT> rect(0.0f, 0.0f, (FX_FLOAT)(m_Width),
- (FX_FLOAT)(m_Height));
- np = agg::clip_liang_barsky<FX_FLOAT>(x1, y1, x2, y2, rect, x, y);
+ agg::rect_base<float> rect(0.0f, 0.0f, (float)(m_Width),
+ (float)(m_Height));
+ np = agg::clip_liang_barsky<float>(x1, y1, x2, y2, rect, x, y);
#endif
if (np == 0)
return;
@@ -994,13 +995,13 @@ bool CGdiDeviceDriver::DrawPath(const CFX_PathData* pPathData,
FX_RECT bbox = bbox_f.GetInnerRect();
if (bbox.Width() <= 0) {
- return DrawCosmeticLine(
- (FX_FLOAT)(bbox.left), (FX_FLOAT)(bbox.top), (FX_FLOAT)(bbox.left),
- (FX_FLOAT)(bbox.bottom + 1), fill_color, FXDIB_BLEND_NORMAL);
+ return DrawCosmeticLine((float)(bbox.left), (float)(bbox.top),
+ (float)(bbox.left), (float)(bbox.bottom + 1),
+ fill_color, FXDIB_BLEND_NORMAL);
}
if (bbox.Height() <= 0) {
- return DrawCosmeticLine((FX_FLOAT)(bbox.left), (FX_FLOAT)(bbox.top),
- (FX_FLOAT)(bbox.right + 1), (FX_FLOAT)(bbox.top),
+ return DrawCosmeticLine((float)(bbox.left), (float)(bbox.top),
+ (float)(bbox.right + 1), (float)(bbox.top),
fill_color, FXDIB_BLEND_NORMAL);
}
}
@@ -1133,10 +1134,10 @@ bool CGdiDeviceDriver::SetClip_PathStroke(
return ret;
}
-bool CGdiDeviceDriver::DrawCosmeticLine(FX_FLOAT x1,
- FX_FLOAT y1,
- FX_FLOAT x2,
- FX_FLOAT y2,
+bool CGdiDeviceDriver::DrawCosmeticLine(float x1,
+ float y1,
+ float x2,
+ float y2,
uint32_t color,
int blend_type) {
if (blend_type != FXDIB_BLEND_NORMAL)
@@ -1168,7 +1169,9 @@ CGdiDisplayDriver::CGdiDisplayDriver(HDC hDC)
CGdiDisplayDriver::~CGdiDisplayDriver() {}
-bool CGdiDisplayDriver::GetDIBits(CFX_DIBitmap* pBitmap, int left, int top) {
+bool CGdiDisplayDriver::GetDIBits(const CFX_RetainPtr<CFX_DIBitmap>& pBitmap,
+ int left,
+ int top) {
bool ret = false;
int width = pBitmap->GetWidth();
int height = pBitmap->GetHeight();
@@ -1178,7 +1181,7 @@ bool CGdiDisplayDriver::GetDIBits(CFX_DIBitmap* pBitmap, int left, int top) {
BitBlt(hDCMemory, 0, 0, width, height, m_hDC, left, top, SRCCOPY);
SelectObject(hDCMemory, holdbmp);
BITMAPINFO bmi;
- FXSYS_memset(&bmi, 0, sizeof bmi);
+ memset(&bmi, 0, sizeof bmi);
bmi.bmiHeader.biSize = sizeof bmi.bmiHeader;
bmi.bmiHeader.biBitCount = pBitmap->GetBPP();
bmi.bmiHeader.biHeight = -height;
@@ -1188,12 +1191,12 @@ bool CGdiDisplayDriver::GetDIBits(CFX_DIBitmap* pBitmap, int left, int top) {
ret = ::GetDIBits(hDCMemory, hbmp, 0, height, pBitmap->GetBuffer(), &bmi,
DIB_RGB_COLORS) == height;
} else {
- CFX_DIBitmap bitmap;
- if (bitmap.Create(width, height, FXDIB_Rgb)) {
+ auto bitmap = pdfium::MakeRetain<CFX_DIBitmap>();
+ if (bitmap->Create(width, height, FXDIB_Rgb)) {
bmi.bmiHeader.biBitCount = 24;
- ::GetDIBits(hDCMemory, hbmp, 0, height, bitmap.GetBuffer(), &bmi,
+ ::GetDIBits(hDCMemory, hbmp, 0, height, bitmap->GetBuffer(), &bmi,
DIB_RGB_COLORS);
- ret = pBitmap->TransferBitmap(0, 0, width, height, &bitmap, 0, 0);
+ ret = pBitmap->TransferBitmap(0, 0, width, height, bitmap, 0, 0);
} else {
ret = false;
}
@@ -1206,7 +1209,7 @@ bool CGdiDisplayDriver::GetDIBits(CFX_DIBitmap* pBitmap, int left, int top) {
return ret;
}
-bool CGdiDisplayDriver::SetDIBits(const CFX_DIBSource* pSource,
+bool CGdiDisplayDriver::SetDIBits(const CFX_RetainPtr<CFX_DIBSource>& pSource,
uint32_t color,
const FX_RECT* pSrcRect,
int left,
@@ -1217,17 +1220,15 @@ bool CGdiDisplayDriver::SetDIBits(const CFX_DIBSource* pSource,
int width = pSource->GetWidth(), height = pSource->GetHeight();
int alpha = FXARGB_A(color);
if (pSource->GetBPP() != 1 || alpha != 255) {
- CFX_DIBitmap background;
- if (!background.Create(width, height, FXDIB_Rgb32) ||
- !GetDIBits(&background, left, top) ||
- !background.CompositeMask(0, 0, width, height, pSource, color, 0, 0,
- FXDIB_BLEND_NORMAL, nullptr, false, 0,
- nullptr)) {
+ auto background = pdfium::MakeRetain<CFX_DIBitmap>();
+ if (!background->Create(width, height, FXDIB_Rgb32) ||
+ !GetDIBits(background, left, top) ||
+ !background->CompositeMask(0, 0, width, height, pSource, color, 0, 0,
+ FXDIB_BLEND_NORMAL, nullptr, false, 0)) {
return false;
}
FX_RECT src_rect(0, 0, width, height);
- return SetDIBits(&background, 0, &src_rect, left, top,
- FXDIB_BLEND_NORMAL);
+ return SetDIBits(background, 0, &src_rect, left, top, FXDIB_BLEND_NORMAL);
}
FX_RECT clip_rect(left, top, left + pSrcRect->Width(),
top + pSrcRect->Height());
@@ -1237,32 +1238,33 @@ bool CGdiDisplayDriver::SetDIBits(const CFX_DIBSource* pSource,
}
int width = pSrcRect->Width(), height = pSrcRect->Height();
if (pSource->HasAlpha()) {
- CFX_DIBitmap bitmap;
- if (!bitmap.Create(width, height, FXDIB_Rgb) ||
- !GetDIBits(&bitmap, left, top) ||
- !bitmap.CompositeBitmap(0, 0, width, height, pSource, pSrcRect->left,
- pSrcRect->top, FXDIB_BLEND_NORMAL, nullptr,
- false, nullptr)) {
+ auto bitmap = pdfium::MakeRetain<CFX_DIBitmap>();
+ if (!bitmap->Create(width, height, FXDIB_Rgb) ||
+ !GetDIBits(bitmap, left, top) ||
+ !bitmap->CompositeBitmap(0, 0, width, height, pSource, pSrcRect->left,
+ pSrcRect->top, FXDIB_BLEND_NORMAL, nullptr,
+ false)) {
return false;
}
FX_RECT src_rect(0, 0, width, height);
- return SetDIBits(&bitmap, 0, &src_rect, left, top, FXDIB_BLEND_NORMAL);
+ return SetDIBits(bitmap, 0, &src_rect, left, top, FXDIB_BLEND_NORMAL);
}
CFX_DIBExtractor temp(pSource);
- CFX_DIBitmap* pBitmap = temp.GetBitmap();
+ CFX_RetainPtr<CFX_DIBitmap> pBitmap = temp.GetBitmap();
if (!pBitmap)
return false;
return GDI_SetDIBits(pBitmap, pSrcRect, left, top);
}
-bool CGdiDisplayDriver::UseFoxitStretchEngine(const CFX_DIBSource* pSource,
- uint32_t color,
- int dest_left,
- int dest_top,
- int dest_width,
- int dest_height,
- const FX_RECT* pClipRect,
- int render_flags) {
+bool CGdiDisplayDriver::UseFoxitStretchEngine(
+ const CFX_RetainPtr<CFX_DIBSource>& pSource,
+ uint32_t color,
+ int dest_left,
+ int dest_top,
+ int dest_width,
+ int dest_height,
+ const FX_RECT* pClipRect,
+ int render_flags) {
FX_RECT bitmap_clip = *pClipRect;
if (dest_width < 0)
dest_left += dest_width;
@@ -1271,25 +1273,26 @@ bool CGdiDisplayDriver::UseFoxitStretchEngine(const CFX_DIBSource* pSource,
dest_top += dest_height;
bitmap_clip.Offset(-dest_left, -dest_top);
- std::unique_ptr<CFX_DIBitmap> pStretched(
- pSource->StretchTo(dest_width, dest_height, render_flags, &bitmap_clip));
+ CFX_RetainPtr<CFX_DIBitmap> pStretched =
+ pSource->StretchTo(dest_width, dest_height, render_flags, &bitmap_clip);
if (!pStretched)
return true;
FX_RECT src_rect(0, 0, pStretched->GetWidth(), pStretched->GetHeight());
- return SetDIBits(pStretched.get(), color, &src_rect, pClipRect->left,
+ return SetDIBits(pStretched, color, &src_rect, pClipRect->left,
pClipRect->top, FXDIB_BLEND_NORMAL);
}
-bool CGdiDisplayDriver::StretchDIBits(const CFX_DIBSource* pSource,
- uint32_t color,
- int dest_left,
- int dest_top,
- int dest_width,
- int dest_height,
- const FX_RECT* pClipRect,
- uint32_t flags,
- int blend_type) {
+bool CGdiDisplayDriver::StretchDIBits(
+ const CFX_RetainPtr<CFX_DIBSource>& pSource,
+ uint32_t color,
+ int dest_left,
+ int dest_top,
+ int dest_width,
+ int dest_height,
+ const FX_RECT* pClipRect,
+ uint32_t flags,
+ int blend_type) {
ASSERT(pSource && pClipRect);
if (flags || dest_width > 10000 || dest_width < -10000 ||
dest_height > 10000 || dest_height < -10000) {
@@ -1306,24 +1309,23 @@ bool CGdiDisplayDriver::StretchDIBits(const CFX_DIBSource* pSource,
clip_rect.Intersect(*pClipRect);
clip_rect.Offset(-image_rect.left, -image_rect.top);
int clip_width = clip_rect.Width(), clip_height = clip_rect.Height();
- std::unique_ptr<CFX_DIBitmap> pStretched(
+ CFX_RetainPtr<CFX_DIBitmap> pStretched(
pSource->StretchTo(dest_width, dest_height, flags, &clip_rect));
if (!pStretched)
return true;
- CFX_DIBitmap background;
- if (!background.Create(clip_width, clip_height, FXDIB_Rgb32) ||
- !GetDIBits(&background, image_rect.left + clip_rect.left,
+ auto background = pdfium::MakeRetain<CFX_DIBitmap>();
+ if (!background->Create(clip_width, clip_height, FXDIB_Rgb32) ||
+ !GetDIBits(background, image_rect.left + clip_rect.left,
image_rect.top + clip_rect.top) ||
- !background.CompositeMask(
- 0, 0, clip_width, clip_height, pStretched.get(), color, 0, 0,
- FXDIB_BLEND_NORMAL, nullptr, false, 0, nullptr)) {
+ !background->CompositeMask(0, 0, clip_width, clip_height, pStretched,
+ color, 0, 0, FXDIB_BLEND_NORMAL, nullptr,
+ false, 0)) {
return false;
}
FX_RECT src_rect(0, 0, clip_width, clip_height);
- return SetDIBits(&background, 0, &src_rect,
- image_rect.left + clip_rect.left,
+ return SetDIBits(background, 0, &src_rect, image_rect.left + clip_rect.left,
image_rect.top + clip_rect.top, FXDIB_BLEND_NORMAL);
}
if (pSource->HasAlpha()) {
@@ -1331,7 +1333,7 @@ bool CGdiDisplayDriver::StretchDIBits(const CFX_DIBSource* pSource,
(CWin32Platform*)CFX_GEModule::Get()->GetPlatformData();
if (pPlatform->m_GdiplusExt.IsAvailable() && !pSource->IsCmykImage()) {
CFX_DIBExtractor temp(pSource);
- CFX_DIBitmap* pBitmap = temp.GetBitmap();
+ CFX_RetainPtr<CFX_DIBitmap> pBitmap = temp.GetBitmap();
if (!pBitmap)
return false;
return pPlatform->m_GdiplusExt.StretchDIBits(
@@ -1342,19 +1344,19 @@ bool CGdiDisplayDriver::StretchDIBits(const CFX_DIBSource* pSource,
dest_width, dest_height, pClipRect, flags);
}
CFX_DIBExtractor temp(pSource);
- CFX_DIBitmap* pBitmap = temp.GetBitmap();
+ CFX_RetainPtr<CFX_DIBitmap> pBitmap = temp.GetBitmap();
if (!pBitmap)
return false;
return GDI_StretchDIBits(pBitmap, dest_left, dest_top, dest_width,
dest_height, flags);
}
-bool CGdiDisplayDriver::StartDIBits(const CFX_DIBSource* pBitmap,
+bool CGdiDisplayDriver::StartDIBits(const CFX_RetainPtr<CFX_DIBSource>& pBitmap,
int bitmap_alpha,
uint32_t color,
const CFX_Matrix* pMatrix,
uint32_t render_flags,
- void*& handle,
+ std::unique_ptr<CFX_ImageRenderer>* handle,
int blend_type) {
return false;
}
diff --git a/chromium/third_party/pdfium/core/fxge/win32/fx_win32_dib.cpp b/chromium/third_party/pdfium/core/fxge/win32/fx_win32_dib.cpp
index 40c9ca6e311..677fb3ab806 100644
--- a/chromium/third_party/pdfium/core/fxge/win32/fx_win32_dib.cpp
+++ b/chromium/third_party/pdfium/core/fxge/win32/fx_win32_dib.cpp
@@ -11,14 +11,15 @@
#include "core/fxge/win32/cfx_windowsdib.h"
#include "core/fxge/win32/win32_int.h"
-CFX_ByteString CFX_WindowsDIB::GetBitmapInfo(const CFX_DIBitmap* pBitmap) {
+CFX_ByteString CFX_WindowsDIB::GetBitmapInfo(
+ const CFX_RetainPtr<CFX_DIBitmap>& pBitmap) {
CFX_ByteString result;
int len = sizeof(BITMAPINFOHEADER);
if (pBitmap->GetBPP() == 1 || pBitmap->GetBPP() == 8) {
len += sizeof(DWORD) * (int)(1 << pBitmap->GetBPP());
}
BITMAPINFOHEADER* pbmih = (BITMAPINFOHEADER*)result.GetBuffer(len);
- FXSYS_memset(pbmih, 0, sizeof(BITMAPINFOHEADER));
+ memset(pbmih, 0, sizeof(BITMAPINFOHEADER));
pbmih->biSize = sizeof(BITMAPINFOHEADER);
pbmih->biBitCount = pBitmap->GetBPP();
pbmih->biCompression = BI_RGB;
@@ -51,9 +52,9 @@ CFX_ByteString CFX_WindowsDIB::GetBitmapInfo(const CFX_DIBitmap* pBitmap) {
return result;
}
-CFX_DIBitmap* _FX_WindowsDIB_LoadFromBuf(BITMAPINFO* pbmi,
- LPVOID pData,
- bool bAlpha) {
+CFX_RetainPtr<CFX_DIBitmap> _FX_WindowsDIB_LoadFromBuf(BITMAPINFO* pbmi,
+ LPVOID pData,
+ bool bAlpha) {
int width = pbmi->bmiHeader.biWidth;
int height = pbmi->bmiHeader.biHeight;
BOOL bBottomUp = true;
@@ -62,24 +63,22 @@ CFX_DIBitmap* _FX_WindowsDIB_LoadFromBuf(BITMAPINFO* pbmi,
bBottomUp = false;
}
int pitch = (width * pbmi->bmiHeader.biBitCount + 31) / 32 * 4;
- CFX_DIBitmap* pBitmap = new CFX_DIBitmap;
+ auto pBitmap = pdfium::MakeRetain<CFX_DIBitmap>();
FXDIB_Format format = bAlpha
? (FXDIB_Format)(pbmi->bmiHeader.biBitCount + 0x200)
: (FXDIB_Format)pbmi->bmiHeader.biBitCount;
- bool ret = pBitmap->Create(width, height, format);
- if (!ret) {
- delete pBitmap;
+ if (!pBitmap->Create(width, height, format))
return nullptr;
- }
- FXSYS_memcpy(pBitmap->GetBuffer(), pData, pitch * height);
+
+ memcpy(pBitmap->GetBuffer(), pData, pitch * height);
if (bBottomUp) {
uint8_t* temp_buf = FX_Alloc(uint8_t, pitch);
int top = 0, bottom = height - 1;
while (top < bottom) {
- FXSYS_memcpy(temp_buf, pBitmap->GetBuffer() + top * pitch, pitch);
- FXSYS_memcpy(pBitmap->GetBuffer() + top * pitch,
- pBitmap->GetBuffer() + bottom * pitch, pitch);
- FXSYS_memcpy(pBitmap->GetBuffer() + bottom * pitch, temp_buf, pitch);
+ memcpy(temp_buf, pBitmap->GetBuffer() + top * pitch, pitch);
+ memcpy(pBitmap->GetBuffer() + top * pitch,
+ pBitmap->GetBuffer() + bottom * pitch, pitch);
+ memcpy(pBitmap->GetBuffer() + bottom * pitch, temp_buf, pitch);
top++;
bottom--;
}
@@ -98,11 +97,13 @@ CFX_DIBitmap* _FX_WindowsDIB_LoadFromBuf(BITMAPINFO* pbmi,
return pBitmap;
}
-CFX_DIBitmap* CFX_WindowsDIB::LoadFromBuf(BITMAPINFO* pbmi, LPVOID pData) {
+CFX_RetainPtr<CFX_DIBitmap> CFX_WindowsDIB::LoadFromBuf(BITMAPINFO* pbmi,
+ LPVOID pData) {
return _FX_WindowsDIB_LoadFromBuf(pbmi, pData, false);
}
-HBITMAP CFX_WindowsDIB::GetDDBitmap(const CFX_DIBitmap* pBitmap, HDC hDC) {
+HBITMAP CFX_WindowsDIB::GetDDBitmap(const CFX_RetainPtr<CFX_DIBitmap>& pBitmap,
+ HDC hDC) {
CFX_ByteString info = GetBitmapInfo(pBitmap);
return CreateDIBitmap(hDC, (BITMAPINFOHEADER*)info.c_str(), CBM_INIT,
pBitmap->GetBuffer(), (BITMAPINFO*)info.c_str(),
@@ -116,7 +117,8 @@ void GetBitmapSize(HBITMAP hBitmap, int& w, int& h) {
h = bmp.bmHeight;
}
-CFX_DIBitmap* CFX_WindowsDIB::LoadFromFile(const FX_WCHAR* filename) {
+CFX_RetainPtr<CFX_DIBitmap> CFX_WindowsDIB::LoadFromFile(
+ const wchar_t* filename) {
CWin32Platform* pPlatform =
(CWin32Platform*)CFX_GEModule::Get()->GetPlatformData();
if (pPlatform->m_GdiplusExt.IsAvailable()) {
@@ -131,30 +133,29 @@ CFX_DIBitmap* CFX_WindowsDIB::LoadFromFile(const FX_WCHAR* filename) {
return nullptr;
}
HDC hDC = CreateCompatibleDC(nullptr);
- int width, height;
+ int width;
+ int height;
GetBitmapSize(hBitmap, width, height);
- CFX_DIBitmap* pDIBitmap = new CFX_DIBitmap;
+ auto pDIBitmap = pdfium::MakeRetain<CFX_DIBitmap>();
if (!pDIBitmap->Create(width, height, FXDIB_Rgb)) {
- delete pDIBitmap;
DeleteDC(hDC);
return nullptr;
}
CFX_ByteString info = GetBitmapInfo(pDIBitmap);
int ret = GetDIBits(hDC, hBitmap, 0, height, pDIBitmap->GetBuffer(),
(BITMAPINFO*)info.c_str(), DIB_RGB_COLORS);
- if (!ret) {
- delete pDIBitmap;
- pDIBitmap = nullptr;
- }
DeleteDC(hDC);
+ if (!ret)
+ return nullptr;
return pDIBitmap;
}
-CFX_DIBitmap* CFX_WindowsDIB::LoadFromFile(const FX_CHAR* filename) {
+CFX_RetainPtr<CFX_DIBitmap> CFX_WindowsDIB::LoadFromFile(const char* filename) {
return LoadFromFile(CFX_WideString::FromLocal(filename).c_str());
}
-CFX_DIBitmap* CFX_WindowsDIB::LoadDIBitmap(WINDIB_Open_Args_ args) {
+CFX_RetainPtr<CFX_DIBitmap> CFX_WindowsDIB::LoadDIBitmap(
+ WINDIB_Open_Args_ args) {
CWin32Platform* pPlatform =
(CWin32Platform*)CFX_GEModule::Get()->GetPlatformData();
if (pPlatform->m_GdiplusExt.IsAvailable()) {
@@ -171,34 +172,33 @@ CFX_DIBitmap* CFX_WindowsDIB::LoadDIBitmap(WINDIB_Open_Args_ args) {
HDC hDC = CreateCompatibleDC(nullptr);
int width, height;
GetBitmapSize(hBitmap, width, height);
- CFX_DIBitmap* pDIBitmap = new CFX_DIBitmap;
+ auto pDIBitmap = pdfium::MakeRetain<CFX_DIBitmap>();
if (!pDIBitmap->Create(width, height, FXDIB_Rgb)) {
- delete pDIBitmap;
DeleteDC(hDC);
return nullptr;
}
CFX_ByteString info = GetBitmapInfo(pDIBitmap);
int ret = GetDIBits(hDC, hBitmap, 0, height, pDIBitmap->GetBuffer(),
(BITMAPINFO*)info.c_str(), DIB_RGB_COLORS);
- if (!ret) {
- delete pDIBitmap;
- pDIBitmap = nullptr;
- }
DeleteDC(hDC);
+ if (!ret)
+ return nullptr;
return pDIBitmap;
}
CFX_WindowsDIB::CFX_WindowsDIB(HDC hDC, int width, int height) {
Create(width, height, FXDIB_Rgb, (uint8_t*)1);
BITMAPINFOHEADER bmih;
- FXSYS_memset(&bmih, 0, sizeof bmih);
+ memset(&bmih, 0, sizeof bmih);
bmih.biSize = sizeof bmih;
bmih.biBitCount = 24;
bmih.biHeight = -height;
bmih.biPlanes = 1;
bmih.biWidth = width;
- m_hBitmap = CreateDIBSection(hDC, (BITMAPINFO*)&bmih, DIB_RGB_COLORS,
- (LPVOID*)&m_pBuffer, nullptr, 0);
+ LPVOID pData = nullptr;
+ m_hBitmap = CreateDIBSection(hDC, (BITMAPINFO*)&bmih, DIB_RGB_COLORS, &pData,
+ nullptr, 0);
+ m_pBuffer.Reset(static_cast<uint8_t*>(pData));
m_hMemDC = CreateCompatibleDC(hDC);
m_hOldBitmap = (HBITMAP)SelectObject(m_hMemDC, m_hBitmap);
}
diff --git a/chromium/third_party/pdfium/core/fxge/win32/fx_win32_dwrite.cpp b/chromium/third_party/pdfium/core/fxge/win32/fx_win32_dwrite.cpp
index dc0f5ed7459..91fb465af4c 100644
--- a/chromium/third_party/pdfium/core/fxge/win32/fx_win32_dwrite.cpp
+++ b/chromium/third_party/pdfium/core/fxge/win32/fx_win32_dwrite.cpp
@@ -103,7 +103,7 @@ class CDwFontContext {
class CDwGdiTextRenderer {
public:
- CDwGdiTextRenderer(CFX_DIBitmap* pBitmap,
+ CDwGdiTextRenderer(const CFX_RetainPtr<CFX_DIBitmap>& pBitmap,
IDWriteBitmapRenderTarget* bitmapRenderTarget,
IDWriteRenderingParams* renderingParams);
~CDwGdiTextRenderer();
@@ -118,7 +118,7 @@ class CDwGdiTextRenderer {
const COLORREF& textColor);
private:
- CFX_DIBitmap* pBitmap_;
+ CFX_RetainPtr<CFX_DIBitmap> pBitmap_;
IDWriteBitmapRenderTarget* pRenderTarget_;
IDWriteRenderingParams* pRenderingParams_;
};
@@ -180,8 +180,9 @@ failed:
return nullptr;
}
-bool CDWriteExt::DwCreateRenderingTarget(CFX_DIBitmap* pBitmap,
- void** renderTarget) {
+bool CDWriteExt::DwCreateRenderingTarget(
+ const CFX_RetainPtr<CFX_DIBitmap>& pBitmap,
+ void** renderTarget) {
if (pBitmap->GetFormat() > FXDIB_Argb) {
return false;
}
@@ -227,14 +228,14 @@ bool CDWriteExt::DwRendingString(void* renderTarget,
FX_RECT& stringRect,
CFX_Matrix* pMatrix,
void* font,
- FX_FLOAT font_size,
+ float font_size,
FX_ARGB text_color,
int glyph_count,
unsigned short* glyph_indices,
- FX_FLOAT baselineOriginX,
- FX_FLOAT baselineOriginY,
+ float baselineOriginX,
+ float baselineOriginY,
void* glyph_offsets,
- FX_FLOAT* glyph_advances) {
+ float* glyph_advances) {
if (!renderTarget) {
return true;
}
@@ -395,7 +396,7 @@ HRESULT CDwFontContext::Initialize() {
}
CDwGdiTextRenderer::CDwGdiTextRenderer(
- CFX_DIBitmap* pBitmap,
+ const CFX_RetainPtr<CFX_DIBitmap>& pBitmap,
IDWriteBitmapRenderTarget* bitmapRenderTarget,
IDWriteRenderingParams* renderingParams)
: pBitmap_(pBitmap),
@@ -426,13 +427,13 @@ STDMETHODIMP CDwGdiTextRenderer::DrawGlyphRun(
HBITMAP hBitmap = (HBITMAP)::GetCurrentObject(hDC, OBJ_BITMAP);
BITMAP bitmap;
GetObject(hBitmap, sizeof bitmap, &bitmap);
- CFX_DIBitmap dib;
- dib.Create(bitmap.bmWidth, bitmap.bmHeight,
- bitmap.bmBitsPixel == 24 ? FXDIB_Rgb : FXDIB_Rgb32,
- (uint8_t*)bitmap.bmBits);
- dib.CompositeBitmap(text_bbox.left, text_bbox.top, text_bbox.Width(),
- text_bbox.Height(), pBitmap_, text_bbox.left,
- text_bbox.top, FXDIB_BLEND_NORMAL, nullptr);
+ auto dib = pdfium::MakeRetain<CFX_DIBitmap>();
+ dib->Create(bitmap.bmWidth, bitmap.bmHeight,
+ bitmap.bmBitsPixel == 24 ? FXDIB_Rgb : FXDIB_Rgb32,
+ (uint8_t*)bitmap.bmBits);
+ dib->CompositeBitmap(text_bbox.left, text_bbox.top, text_bbox.Width(),
+ text_bbox.Height(), pBitmap_, text_bbox.left,
+ text_bbox.top, FXDIB_BLEND_NORMAL, nullptr);
hr = pRenderTarget_->DrawGlyphRun(baselineOriginX, baselineOriginY,
measuringMode, glyphRun, pRenderingParams_,
textColor);
@@ -440,7 +441,7 @@ STDMETHODIMP CDwGdiTextRenderer::DrawGlyphRun(
return hr;
}
pBitmap_->CompositeBitmap(text_bbox.left, text_bbox.top, text_bbox.Width(),
- text_bbox.Height(), &dib, text_bbox.left,
+ text_bbox.Height(), dib, text_bbox.left,
text_bbox.top, FXDIB_BLEND_NORMAL, pClipRgn);
return hr;
}
diff --git a/chromium/third_party/pdfium/core/fxge/win32/fx_win32_gdipext.cpp b/chromium/third_party/pdfium/core/fxge/win32/fx_win32_gdipext.cpp
index 1be2a54b18f..6a3527f3933 100644
--- a/chromium/third_party/pdfium/core/fxge/win32/fx_win32_gdipext.cpp
+++ b/chromium/third_party/pdfium/core/fxge/win32/fx_win32_gdipext.cpp
@@ -461,10 +461,10 @@ static GpBrush* _GdipCreateBrush(DWORD argb) {
return solidBrush;
}
-static std::unique_ptr<CFX_DIBitmap> StretchMonoToGray(
+static CFX_RetainPtr<CFX_DIBitmap> StretchMonoToGray(
int dest_width,
int dest_height,
- const CFX_DIBitmap* pSource,
+ const CFX_RetainPtr<CFX_DIBitmap>& pSource,
FX_RECT* pClipRect) {
bool bFlipX = dest_width < 0;
if (bFlipX)
@@ -477,7 +477,7 @@ static std::unique_ptr<CFX_DIBitmap> StretchMonoToGray(
int result_width = pClipRect->Width();
int result_height = pClipRect->Height();
int result_pitch = (result_width + 3) / 4 * 4;
- auto pStretched = pdfium::MakeUnique<CFX_DIBitmap>();
+ auto pStretched = pdfium::MakeRetain<CFX_DIBitmap>();
if (!pStretched->Create(result_width, result_height, FXDIB_8bppRgb))
return nullptr;
@@ -518,7 +518,7 @@ static std::unique_ptr<CFX_DIBitmap> StretchMonoToGray(
static void OutputImageMask(GpGraphics* pGraphics,
BOOL bMonoDevice,
- const CFX_DIBitmap* pBitmap,
+ const CFX_RetainPtr<CFX_DIBitmap>& pBitmap,
int dest_left,
int dest_top,
int dest_width,
@@ -562,7 +562,7 @@ static void OutputImageMask(GpGraphics* pGraphics,
return;
}
image_clip.Offset(-image_rect.left, -image_rect.top);
- std::unique_ptr<CFX_DIBitmap> pStretched;
+ CFX_RetainPtr<CFX_DIBitmap> pStretched;
if (src_width * src_height > 10000) {
pStretched =
StretchMonoToGray(dest_width, dest_height, pBitmap, &image_clip);
@@ -602,7 +602,7 @@ static void OutputImageMask(GpGraphics* pGraphics,
CallFunc(GdipDisposeImage)(bitmap);
}
static void OutputImage(GpGraphics* pGraphics,
- const CFX_DIBitmap* pBitmap,
+ const CFX_RetainPtr<CFX_DIBitmap>& pBitmap,
const FX_RECT* pSrcRect,
int dest_left,
int dest_top,
@@ -613,11 +613,11 @@ static void OutputImage(GpGraphics* pGraphics,
((CWin32Platform*)CFX_GEModule::Get()->GetPlatformData())->m_GdiplusExt;
if (pBitmap->GetBPP() == 1 && (pSrcRect->left % 8)) {
FX_RECT new_rect(0, 0, src_width, src_height);
- std::unique_ptr<CFX_DIBitmap> pCloned = pBitmap->Clone(pSrcRect);
+ CFX_RetainPtr<CFX_DIBitmap> pCloned = pBitmap->Clone(pSrcRect);
if (!pCloned)
return;
- OutputImage(pGraphics, pCloned.get(), &new_rect, dest_left, dest_top,
- dest_width, dest_height);
+ OutputImage(pGraphics, pCloned, &new_rect, dest_left, dest_top, dest_width,
+ dest_height);
return;
}
int src_pitch = pBitmap->GetPitch();
@@ -680,7 +680,7 @@ CGdiplusExt::CGdiplusExt() {
}
void CGdiplusExt::Load() {
CFX_ByteString strPlusPath = "";
- FX_CHAR buf[MAX_PATH];
+ char buf[MAX_PATH];
GetSystemDirectoryA(buf, MAX_PATH);
strPlusPath += buf;
strPlusPath += "\\";
@@ -730,7 +730,8 @@ void CGdiplusExt::DeleteMemFont(LPVOID pCollection) {
((CWin32Platform*)CFX_GEModule::Get()->GetPlatformData())->m_GdiplusExt;
CallFunc(GdipDeletePrivateFontCollection)((GpFontCollection**)&pCollection);
}
-bool CGdiplusExt::GdipCreateBitmap(CFX_DIBitmap* pBitmap, void** bitmap) {
+bool CGdiplusExt::GdipCreateBitmap(const CFX_RetainPtr<CFX_DIBitmap>& pBitmap,
+ void** bitmap) {
CGdiplusExt& GdiplusExt =
((CWin32Platform*)CFX_GEModule::Get()->GetPlatformData())->m_GdiplusExt;
PixelFormat format;
@@ -765,7 +766,7 @@ bool CGdiplusExt::GdipCreateFromImage(void* bitmap, void** graphics) {
}
return false;
}
-bool CGdiplusExt::GdipCreateFontFamilyFromName(const FX_WCHAR* name,
+bool CGdiplusExt::GdipCreateFontFamilyFromName(const wchar_t* name,
void* pFontCollection,
void** pFamily) {
CGdiplusExt& GdiplusExt =
@@ -779,7 +780,7 @@ bool CGdiplusExt::GdipCreateFontFamilyFromName(const FX_WCHAR* name,
return false;
}
bool CGdiplusExt::GdipCreateFontFromFamily(void* pFamily,
- FX_FLOAT font_size,
+ float font_size,
int fontstyle,
int flag,
void** pFont) {
@@ -793,13 +794,13 @@ bool CGdiplusExt::GdipCreateFontFromFamily(void* pFamily,
}
return false;
}
-void CGdiplusExt::GdipGetFontSize(void* pFont, FX_FLOAT* size) {
+void CGdiplusExt::GdipGetFontSize(void* pFont, float* size) {
REAL get_size;
CGdiplusExt& GdiplusExt =
((CWin32Platform*)CFX_GEModule::Get()->GetPlatformData())->m_GdiplusExt;
GpStatus status = CallFunc(GdipGetFontSize)((GpFont*)pFont, (REAL*)&get_size);
if (status == Ok) {
- *size = (FX_FLOAT)get_size;
+ *size = (float)get_size;
} else {
*size = 0;
}
@@ -845,7 +846,7 @@ void CGdiplusExt::GdipDeleteBrush(void* pBrush) {
CallFunc(GdipDeleteBrush)((GpSolidFill*)pBrush);
}
void* CGdiplusExt::GdipCreateFontFromCollection(void* pFontCollection,
- FX_FLOAT font_size,
+ float font_size,
int fontstyle) {
CGdiplusExt& GdiplusExt =
((CWin32Platform*)CFX_GEModule::Get()->GetPlatformData())->m_GdiplusExt;
@@ -869,12 +870,12 @@ void* CGdiplusExt::GdipCreateFontFromCollection(void* pFontCollection,
}
return pFont;
}
-void CGdiplusExt::GdipCreateMatrix(FX_FLOAT a,
- FX_FLOAT b,
- FX_FLOAT c,
- FX_FLOAT d,
- FX_FLOAT e,
- FX_FLOAT f,
+void CGdiplusExt::GdipCreateMatrix(float a,
+ float b,
+ float c,
+ float d,
+ float e,
+ float f,
void** matrix) {
CGdiplusExt& GdiplusExt =
((CWin32Platform*)CFX_GEModule::Get()->GetPlatformData())->m_GdiplusExt;
@@ -912,7 +913,7 @@ void CGdiplusExt::GdipDeleteGraphics(void* graphics) {
}
bool CGdiplusExt::StretchBitMask(HDC hDC,
BOOL bMonoDevice,
- const CFX_DIBitmap* pBitmap,
+ const CFX_RetainPtr<CFX_DIBitmap>& pBitmap,
int dest_left,
int dest_top,
int dest_width,
@@ -938,7 +939,7 @@ bool CGdiplusExt::StretchBitMask(HDC hDC,
return true;
}
bool CGdiplusExt::StretchDIBits(HDC hDC,
- const CFX_DIBitmap* pBitmap,
+ const CFX_RetainPtr<CFX_DIBitmap>& pBitmap,
int dest_left,
int dest_top,
int dest_width,
@@ -972,11 +973,11 @@ static GpPen* _GdipCreatePen(const CFX_GraphStateData* pGraphState,
bool bTextMode = false) {
CGdiplusExt& GdiplusExt =
((CWin32Platform*)CFX_GEModule::Get()->GetPlatformData())->m_GdiplusExt;
- FX_FLOAT width = pGraphState ? pGraphState->m_LineWidth : 1.0f;
+ float width = pGraphState ? pGraphState->m_LineWidth : 1.0f;
if (!bTextMode) {
- FX_FLOAT unit =
- pMatrix ? 1.0f / ((pMatrix->GetXUnit() + pMatrix->GetYUnit()) / 2)
- : 1.0f;
+ float unit = pMatrix
+ ? 1.0f / ((pMatrix->GetXUnit() + pMatrix->GetYUnit()) / 2)
+ : 1.0f;
if (width < unit) {
width = unit;
}
@@ -1015,13 +1016,13 @@ static GpPen* _GdipCreatePen(const CFX_GraphStateData* pGraphState,
}
CallFunc(GdipSetPenLineJoin)(pPen, lineJoin);
if (pGraphState->m_DashCount) {
- FX_FLOAT* pDashArray = FX_Alloc(
- FX_FLOAT, pGraphState->m_DashCount + pGraphState->m_DashCount % 2);
+ float* pDashArray = FX_Alloc(
+ float, pGraphState->m_DashCount + pGraphState->m_DashCount % 2);
int nCount = 0;
- FX_FLOAT on_leftover = 0, off_leftover = 0;
+ float on_leftover = 0, off_leftover = 0;
for (int i = 0; i < pGraphState->m_DashCount; i += 2) {
- FX_FLOAT on_phase = pGraphState->m_DashArray[i];
- FX_FLOAT off_phase;
+ float on_phase = pGraphState->m_DashArray[i];
+ float off_phase;
if (i == pGraphState->m_DashCount - 1) {
off_phase = on_phase;
} else {
@@ -1057,7 +1058,7 @@ static GpPen* _GdipCreatePen(const CFX_GraphStateData* pGraphState,
}
}
CallFunc(GdipSetPenDashArray)(pPen, pDashArray, nCount);
- FX_FLOAT phase = pGraphState->m_DashPhase;
+ float phase = pGraphState->m_DashPhase;
if (bDashExtend) {
if (phase < 0.5f) {
phase = 0;
@@ -1089,7 +1090,7 @@ static bool IsSmallTriangle(PointF* points,
}
CFX_PointF diff = p1 - p2;
- FX_FLOAT distance_square = (diff.x * diff.x) + (diff.y * diff.y);
+ float distance_square = (diff.x * diff.x) + (diff.y * diff.y);
if (distance_square < (1.0f * 2 + 1.0f / 4)) {
v1 = i;
v2 = pair1;
@@ -1296,7 +1297,7 @@ class GpStream final : public IStream {
}
bytes_left = m_InterStream.GetLength() - m_ReadPos;
bytes_out = std::min(pdfium::base::checked_cast<size_t>(cb), bytes_left);
- FXSYS_memcpy(Output, m_InterStream.GetBuffer() + m_ReadPos, bytes_out);
+ memcpy(Output, m_InterStream.GetBuffer() + m_ReadPos, bytes_out);
m_ReadPos += (int32_t)bytes_out;
if (pcbRead) {
*pcbRead = (ULONG)bytes_out;
@@ -1492,27 +1493,29 @@ static void FreeDIBitmap(PREVIEW3_DIBITMAP* pInfo) {
FX_Free(pInfo);
}
-CFX_DIBitmap* _FX_WindowsDIB_LoadFromBuf(BITMAPINFO* pbmi,
- LPVOID pData,
- bool bAlpha);
-CFX_DIBitmap* CGdiplusExt::LoadDIBitmap(WINDIB_Open_Args_ args) {
+// TODO(tsepez): Really? Really? Move to header.
+CFX_RetainPtr<CFX_DIBitmap> _FX_WindowsDIB_LoadFromBuf(BITMAPINFO* pbmi,
+ LPVOID pData,
+ bool bAlpha);
+
+CFX_RetainPtr<CFX_DIBitmap> CGdiplusExt::LoadDIBitmap(WINDIB_Open_Args_ args) {
PREVIEW3_DIBITMAP* pInfo = ::LoadDIBitmap(args);
- if (!pInfo) {
+ if (!pInfo)
return nullptr;
- }
+
int height = abs(pInfo->pbmi->bmiHeader.biHeight);
int width = pInfo->pbmi->bmiHeader.biWidth;
int dest_pitch = (width * pInfo->pbmi->bmiHeader.biBitCount + 31) / 32 * 4;
LPBYTE pData = FX_Alloc2D(BYTE, dest_pitch, height);
if (dest_pitch == pInfo->Stride) {
- FXSYS_memcpy(pData, pInfo->pScan0, dest_pitch * height);
+ memcpy(pData, pInfo->pScan0, dest_pitch * height);
} else {
for (int i = 0; i < height; i++) {
- FXSYS_memcpy(pData + dest_pitch * i, pInfo->pScan0 + pInfo->Stride * i,
- dest_pitch);
+ memcpy(pData + dest_pitch * i, pInfo->pScan0 + pInfo->Stride * i,
+ dest_pitch);
}
}
- CFX_DIBitmap* pDIBitmap = _FX_WindowsDIB_LoadFromBuf(
+ CFX_RetainPtr<CFX_DIBitmap> pDIBitmap = _FX_WindowsDIB_LoadFromBuf(
pInfo->pbmi, pData, pInfo->pbmi->bmiHeader.biBitCount == 32);
FX_Free(pData);
FreeDIBitmap(pInfo);
diff --git a/chromium/third_party/pdfium/core/fxge/win32/fx_win32_print.cpp b/chromium/third_party/pdfium/core/fxge/win32/fx_win32_print.cpp
index cda83ebc95a..e5df6edd418 100644
--- a/chromium/third_party/pdfium/core/fxge/win32/fx_win32_print.cpp
+++ b/chromium/third_party/pdfium/core/fxge/win32/fx_win32_print.cpp
@@ -12,7 +12,9 @@
#include "core/fxcrt/fx_system.h"
#include "core/fxge/cfx_windowsdevice.h"
-#include "core/fxge/dib/dib_int.h"
+#include "core/fxge/dib/cfx_dibextractor.h"
+#include "core/fxge/dib/cfx_imagerenderer.h"
+#include "core/fxge/dib/cstretchengine.h"
#include "core/fxge/fx_freetype.h"
#include "core/fxge/ge/fx_text_int.h"
#include "core/fxge/win32/cpsoutput.h"
@@ -67,7 +69,7 @@ int CGdiPrinterDriver::GetDeviceCaps(int caps_id) const {
return CGdiDeviceDriver::GetDeviceCaps(caps_id);
}
-bool CGdiPrinterDriver::SetDIBits(const CFX_DIBSource* pSource,
+bool CGdiPrinterDriver::SetDIBits(const CFX_RetainPtr<CFX_DIBSource>& pSource,
uint32_t color,
const FX_RECT* pSrcRect,
int left,
@@ -87,29 +89,30 @@ bool CGdiPrinterDriver::SetDIBits(const CFX_DIBSource* pSource,
return false;
CFX_DIBExtractor temp(pSource);
- CFX_DIBitmap* pBitmap = temp.GetBitmap();
+ CFX_RetainPtr<CFX_DIBitmap> pBitmap = temp.GetBitmap();
if (!pBitmap)
return false;
return GDI_SetDIBits(pBitmap, pSrcRect, left, top);
}
-bool CGdiPrinterDriver::StretchDIBits(const CFX_DIBSource* pSource,
- uint32_t color,
- int dest_left,
- int dest_top,
- int dest_width,
- int dest_height,
- const FX_RECT* pClipRect,
- uint32_t flags,
- int blend_type) {
+bool CGdiPrinterDriver::StretchDIBits(
+ const CFX_RetainPtr<CFX_DIBSource>& pSource,
+ uint32_t color,
+ int dest_left,
+ int dest_top,
+ int dest_width,
+ int dest_height,
+ const FX_RECT* pClipRect,
+ uint32_t flags,
+ int blend_type) {
if (pSource->IsAlphaMask()) {
int alpha = FXARGB_A(color);
if (pSource->GetBPP() != 1 || alpha != 255)
return false;
if (dest_width < 0 || dest_height < 0) {
- std::unique_ptr<CFX_DIBitmap> pFlipped =
+ CFX_RetainPtr<CFX_DIBitmap> pFlipped =
pSource->FlipImage(dest_width < 0, dest_height < 0);
if (!pFlipped)
return false;
@@ -119,13 +122,12 @@ bool CGdiPrinterDriver::StretchDIBits(const CFX_DIBSource* pSource,
if (dest_height < 0)
dest_top += dest_height;
- return GDI_StretchBitMask(pFlipped.get(), dest_left, dest_top,
- abs(dest_width), abs(dest_height), color,
- flags);
+ return GDI_StretchBitMask(pFlipped, dest_left, dest_top, abs(dest_width),
+ abs(dest_height), color, flags);
}
CFX_DIBExtractor temp(pSource);
- CFX_DIBitmap* pBitmap = temp.GetBitmap();
+ CFX_RetainPtr<CFX_DIBitmap> pBitmap = temp.GetBitmap();
if (!pBitmap)
return false;
return GDI_StretchBitMask(pBitmap, dest_left, dest_top, dest_width,
@@ -136,7 +138,7 @@ bool CGdiPrinterDriver::StretchDIBits(const CFX_DIBSource* pSource,
return false;
if (dest_width < 0 || dest_height < 0) {
- std::unique_ptr<CFX_DIBitmap> pFlipped =
+ CFX_RetainPtr<CFX_DIBitmap> pFlipped =
pSource->FlipImage(dest_width < 0, dest_height < 0);
if (!pFlipped)
return false;
@@ -146,24 +148,24 @@ bool CGdiPrinterDriver::StretchDIBits(const CFX_DIBSource* pSource,
if (dest_height < 0)
dest_top += dest_height;
- return GDI_StretchDIBits(pFlipped.get(), dest_left, dest_top,
- abs(dest_width), abs(dest_height), flags);
+ return GDI_StretchDIBits(pFlipped, dest_left, dest_top, abs(dest_width),
+ abs(dest_height), flags);
}
CFX_DIBExtractor temp(pSource);
- CFX_DIBitmap* pBitmap = temp.GetBitmap();
+ CFX_RetainPtr<CFX_DIBitmap> pBitmap = temp.GetBitmap();
if (!pBitmap)
return false;
return GDI_StretchDIBits(pBitmap, dest_left, dest_top, dest_width,
dest_height, flags);
}
-bool CGdiPrinterDriver::StartDIBits(const CFX_DIBSource* pSource,
+bool CGdiPrinterDriver::StartDIBits(const CFX_RetainPtr<CFX_DIBSource>& pSource,
int bitmap_alpha,
uint32_t color,
const CFX_Matrix* pMatrix,
uint32_t render_flags,
- void*& handle,
+ std::unique_ptr<CFX_ImageRenderer>* handle,
int blend_type) {
if (bitmap_alpha < 255 || pSource->HasAlpha() ||
(pSource->IsAlphaMask() && (pSource->GetBPP() != 1))) {
@@ -171,8 +173,8 @@ bool CGdiPrinterDriver::StartDIBits(const CFX_DIBSource* pSource,
}
CFX_FloatRect unit_rect = pMatrix->GetUnitRect();
FX_RECT full_rect = unit_rect.GetOuterRect();
- if (FXSYS_fabs(pMatrix->b) < 0.5f && pMatrix->a != 0 &&
- FXSYS_fabs(pMatrix->c) < 0.5f && pMatrix->d != 0) {
+ if (fabs(pMatrix->b) < 0.5f && pMatrix->a != 0 && fabs(pMatrix->c) < 0.5f &&
+ pMatrix->d != 0) {
bool bFlipX = pMatrix->a < 0;
bool bFlipY = pMatrix->d > 0;
return StretchDIBits(pSource, color,
@@ -182,15 +184,15 @@ bool CGdiPrinterDriver::StartDIBits(const CFX_DIBSource* pSource,
bFlipY ? -full_rect.Height() : full_rect.Height(),
nullptr, 0, blend_type);
}
- if (FXSYS_fabs(pMatrix->a) >= 0.5f || FXSYS_fabs(pMatrix->d) >= 0.5f)
+ if (fabs(pMatrix->a) >= 0.5f || fabs(pMatrix->d) >= 0.5f)
return false;
- std::unique_ptr<CFX_DIBitmap> pTransformed =
+ CFX_RetainPtr<CFX_DIBitmap> pTransformed =
pSource->SwapXY(pMatrix->c > 0, pMatrix->b < 0);
if (!pTransformed)
return false;
- return StretchDIBits(pTransformed.get(), color, full_rect.left, full_rect.top,
+ return StretchDIBits(pTransformed, color, full_rect.left, full_rect.top,
full_rect.Width(), full_rect.Height(), nullptr, 0,
blend_type);
}
@@ -199,7 +201,7 @@ bool CGdiPrinterDriver::DrawDeviceText(int nChars,
const FXTEXT_CHARPOS* pCharPos,
CFX_Font* pFont,
const CFX_Matrix* pObject2Device,
- FX_FLOAT font_size,
+ float font_size,
uint32_t color) {
#if defined(PDFIUM_PRINT_TEXT_WITH_GDI)
if (!g_pdfium_print_text_with_gdi)
@@ -287,7 +289,7 @@ bool CGdiPrinterDriver::DrawDeviceText(int nChars,
// Text
CFX_WideString wsText;
std::vector<INT> spacing(nChars);
- FX_FLOAT fPreviousOriginX = 0;
+ float fPreviousOriginX = 0;
for (int i = 0; i < nChars; ++i) {
// Only works with PDFs from Skia's PDF generator. Cannot handle arbitrary
// values from PDFs.
@@ -300,8 +302,8 @@ bool CGdiPrinterDriver::DrawDeviceText(int nChars,
// Round the spacing to the nearest integer, but keep track of the rounding
// error for calculating the next spacing value.
- FX_FLOAT fOriginX = charpos.m_Origin.x * kScaleFactor;
- FX_FLOAT fPixelSpacing = fOriginX - fPreviousOriginX;
+ float fOriginX = charpos.m_Origin.x * kScaleFactor;
+ float fPixelSpacing = fOriginX - fPreviousOriginX;
spacing[i] = FXSYS_round(fPixelSpacing);
fPreviousOriginX = fOriginX - (fPixelSpacing - spacing[i]);
@@ -349,10 +351,10 @@ CPSPrinterDriver::CPSPrinterDriver(HDC hDC, int pslevel, bool bCmykOutput)
for (uint32_t i = 0; i < pData->rdh.nCount; i++) {
RECT* pRect =
reinterpret_cast<RECT*>(pData->Buffer + pData->rdh.nRgnSize * i);
- path.AppendRect(static_cast<FX_FLOAT>(pRect->left),
- static_cast<FX_FLOAT>(pRect->bottom),
- static_cast<FX_FLOAT>(pRect->right),
- static_cast<FX_FLOAT>(pRect->top));
+ path.AppendRect(static_cast<float>(pRect->left),
+ static_cast<float>(pRect->bottom),
+ static_cast<float>(pRect->right),
+ static_cast<float>(pRect->top));
}
m_PSRenderer.SetClip_PathFill(&path, nullptr, FXFILL_WINDING);
}
@@ -436,7 +438,7 @@ bool CPSPrinterDriver::GetClipBox(FX_RECT* pRect) {
return true;
}
-bool CPSPrinterDriver::SetDIBits(const CFX_DIBSource* pBitmap,
+bool CPSPrinterDriver::SetDIBits(const CFX_RetainPtr<CFX_DIBSource>& pBitmap,
uint32_t color,
const FX_RECT* pSrcRect,
int left,
@@ -447,27 +449,28 @@ bool CPSPrinterDriver::SetDIBits(const CFX_DIBSource* pBitmap,
return m_PSRenderer.SetDIBits(pBitmap, color, left, top);
}
-bool CPSPrinterDriver::StretchDIBits(const CFX_DIBSource* pBitmap,
- uint32_t color,
- int dest_left,
- int dest_top,
- int dest_width,
- int dest_height,
- const FX_RECT* pClipRect,
- uint32_t flags,
- int blend_type) {
+bool CPSPrinterDriver::StretchDIBits(
+ const CFX_RetainPtr<CFX_DIBSource>& pBitmap,
+ uint32_t color,
+ int dest_left,
+ int dest_top,
+ int dest_width,
+ int dest_height,
+ const FX_RECT* pClipRect,
+ uint32_t flags,
+ int blend_type) {
if (blend_type != FXDIB_BLEND_NORMAL)
return false;
return m_PSRenderer.StretchDIBits(pBitmap, color, dest_left, dest_top,
dest_width, dest_height, flags);
}
-bool CPSPrinterDriver::StartDIBits(const CFX_DIBSource* pBitmap,
+bool CPSPrinterDriver::StartDIBits(const CFX_RetainPtr<CFX_DIBSource>& pBitmap,
int bitmap_alpha,
uint32_t color,
const CFX_Matrix* pMatrix,
uint32_t render_flags,
- void*& handle,
+ std::unique_ptr<CFX_ImageRenderer>* handle,
int blend_type) {
if (blend_type != FXDIB_BLEND_NORMAL)
return false;
@@ -475,7 +478,7 @@ bool CPSPrinterDriver::StartDIBits(const CFX_DIBSource* pBitmap,
if (bitmap_alpha < 255)
return false;
- handle = nullptr;
+ *handle = nullptr;
return m_PSRenderer.DrawDIBits(pBitmap, color, pMatrix, render_flags);
}
@@ -483,7 +486,7 @@ bool CPSPrinterDriver::DrawDeviceText(int nChars,
const FXTEXT_CHARPOS* pCharPos,
CFX_Font* pFont,
const CFX_Matrix* pObject2Device,
- FX_FLOAT font_size,
+ float font_size,
uint32_t color) {
return m_PSRenderer.DrawText(nChars, pCharPos, pFont, pObject2Device,
font_size, color);
diff --git a/chromium/third_party/pdfium/core/fxge/win32/win32_int.h b/chromium/third_party/pdfium/core/fxge/win32/win32_int.h
index f8eae873087..a5fc853de52 100644
--- a/chromium/third_party/pdfium/core/fxge/win32/win32_int.h
+++ b/chromium/third_party/pdfium/core/fxge/win32/win32_int.h
@@ -17,6 +17,7 @@
#include "core/fxge/win32/cpsoutput.h"
#include "core/fxge/win32/dwrite_int.h"
+class CFX_ImageRenderer;
class FXTEXT_CHARPOS;
struct WINDIB_Open_Args_;
@@ -34,7 +35,7 @@ class CGdiplusExt {
bool IsAvailable() { return !!m_hModule; }
bool StretchBitMask(HDC hDC,
BOOL bMonoDevice,
- const CFX_DIBitmap* pBitmap,
+ const CFX_RetainPtr<CFX_DIBitmap>& pBitmap,
int dest_left,
int dest_top,
int dest_width,
@@ -43,7 +44,7 @@ class CGdiplusExt {
const FX_RECT* pClipRect,
int flags);
bool StretchDIBits(HDC hDC,
- const CFX_DIBitmap* pBitmap,
+ const CFX_RetainPtr<CFX_DIBitmap>& pBitmap,
int dest_left,
int dest_top,
int dest_width,
@@ -75,36 +76,37 @@ class CGdiplusExt {
const void* matrix);
void GdipCreateBrush(uint32_t fill_argb, void** pBrush);
void GdipDeleteBrush(void* pBrush);
- void GdipCreateMatrix(FX_FLOAT a,
- FX_FLOAT b,
- FX_FLOAT c,
- FX_FLOAT d,
- FX_FLOAT e,
- FX_FLOAT f,
+ void GdipCreateMatrix(float a,
+ float b,
+ float c,
+ float d,
+ float e,
+ float f,
void** matrix);
void GdipDeleteMatrix(void* matrix);
- bool GdipCreateFontFamilyFromName(const FX_WCHAR* name,
+ bool GdipCreateFontFamilyFromName(const wchar_t* name,
void* pFontCollection,
void** pFamily);
void GdipDeleteFontFamily(void* pFamily);
bool GdipCreateFontFromFamily(void* pFamily,
- FX_FLOAT font_size,
+ float font_size,
int fontstyle,
int flag,
void** pFont);
void* GdipCreateFontFromCollection(void* pFontCollection,
- FX_FLOAT font_size,
+ float font_size,
int fontstyle);
void GdipDeleteFont(void* pFont);
- bool GdipCreateBitmap(CFX_DIBitmap* pBitmap, void** bitmap);
+ bool GdipCreateBitmap(const CFX_RetainPtr<CFX_DIBitmap>& pBitmap,
+ void** bitmap);
void GdipDisposeImage(void* bitmap);
- void GdipGetFontSize(void* pFont, FX_FLOAT* size);
+ void GdipGetFontSize(void* pFont, float* size);
void* GdiAddFontMemResourceEx(void* pFontdata,
uint32_t size,
void* pdv,
uint32_t* num_face);
bool GdiRemoveFontMemResourceEx(void* handle);
- CFX_DIBitmap* LoadDIBitmap(WINDIB_Open_Args_ args);
+ CFX_RetainPtr<CFX_DIBitmap> LoadDIBitmap(WINDIB_Open_Args_ args);
FARPROC m_Functions[100];
FuncType_GdiAddFontMemResourceEx m_pGdiAddFontMemResourceEx;
@@ -147,28 +149,28 @@ class CGdiDeviceDriver : public IFX_RenderDeviceDriver {
bool FillRectWithBlend(const FX_RECT* pRect,
uint32_t fill_color,
int blend_type) override;
- bool DrawCosmeticLine(FX_FLOAT x1,
- FX_FLOAT y1,
- FX_FLOAT x2,
- FX_FLOAT y2,
+ bool DrawCosmeticLine(float x1,
+ float y1,
+ float x2,
+ float y2,
uint32_t color,
int blend_type) override;
bool GetClipBox(FX_RECT* pRect) override;
void* GetPlatformSurface() const override;
- void DrawLine(FX_FLOAT x1, FX_FLOAT y1, FX_FLOAT x2, FX_FLOAT y2);
+ void DrawLine(float x1, float y1, float x2, float y2);
- bool GDI_SetDIBits(CFX_DIBitmap* pBitmap,
+ bool GDI_SetDIBits(const CFX_RetainPtr<CFX_DIBitmap>& pBitmap,
const FX_RECT* pSrcRect,
int left,
int top);
- bool GDI_StretchDIBits(CFX_DIBitmap* pBitmap,
+ bool GDI_StretchDIBits(const CFX_RetainPtr<CFX_DIBitmap>& pBitmap,
int dest_left,
int dest_top,
int dest_width,
int dest_height,
uint32_t flags);
- bool GDI_StretchBitMask(CFX_DIBitmap* pBitmap,
+ bool GDI_StretchBitMask(const CFX_RetainPtr<CFX_DIBitmap>& pBitmap,
int dest_left,
int dest_top,
int dest_width,
@@ -191,14 +193,16 @@ class CGdiDisplayDriver : public CGdiDeviceDriver {
~CGdiDisplayDriver() override;
protected:
- bool GetDIBits(CFX_DIBitmap* pBitmap, int left, int top) override;
- bool SetDIBits(const CFX_DIBSource* pBitmap,
+ bool GetDIBits(const CFX_RetainPtr<CFX_DIBitmap>& pBitmap,
+ int left,
+ int top) override;
+ bool SetDIBits(const CFX_RetainPtr<CFX_DIBSource>& pBitmap,
uint32_t color,
const FX_RECT* pSrcRect,
int left,
int top,
int blend_type) override;
- bool StretchDIBits(const CFX_DIBSource* pBitmap,
+ bool StretchDIBits(const CFX_RetainPtr<CFX_DIBSource>& pBitmap,
uint32_t color,
int dest_left,
int dest_top,
@@ -207,14 +211,14 @@ class CGdiDisplayDriver : public CGdiDeviceDriver {
const FX_RECT* pClipRect,
uint32_t flags,
int blend_type) override;
- bool StartDIBits(const CFX_DIBSource* pBitmap,
+ bool StartDIBits(const CFX_RetainPtr<CFX_DIBSource>& pBitmap,
int bitmap_alpha,
uint32_t color,
const CFX_Matrix* pMatrix,
uint32_t render_flags,
- void*& handle,
+ std::unique_ptr<CFX_ImageRenderer>* handle,
int blend_type) override;
- bool UseFoxitStretchEngine(const CFX_DIBSource* pSource,
+ bool UseFoxitStretchEngine(const CFX_RetainPtr<CFX_DIBSource>& pSource,
uint32_t color,
int dest_left,
int dest_top,
@@ -231,13 +235,13 @@ class CGdiPrinterDriver : public CGdiDeviceDriver {
protected:
int GetDeviceCaps(int caps_id) const override;
- bool SetDIBits(const CFX_DIBSource* pBitmap,
+ bool SetDIBits(const CFX_RetainPtr<CFX_DIBSource>& pBitmap,
uint32_t color,
const FX_RECT* pSrcRect,
int left,
int top,
int blend_type) override;
- bool StretchDIBits(const CFX_DIBSource* pBitmap,
+ bool StretchDIBits(const CFX_RetainPtr<CFX_DIBSource>& pBitmap,
uint32_t color,
int dest_left,
int dest_top,
@@ -246,18 +250,18 @@ class CGdiPrinterDriver : public CGdiDeviceDriver {
const FX_RECT* pClipRect,
uint32_t flags,
int blend_type) override;
- bool StartDIBits(const CFX_DIBSource* pBitmap,
+ bool StartDIBits(const CFX_RetainPtr<CFX_DIBSource>& pBitmap,
int bitmap_alpha,
uint32_t color,
const CFX_Matrix* pMatrix,
uint32_t render_flags,
- void*& handle,
+ std::unique_ptr<CFX_ImageRenderer>* handle,
int blend_type) override;
bool DrawDeviceText(int nChars,
const FXTEXT_CHARPOS* pCharPos,
CFX_Font* pFont,
const CFX_Matrix* pObject2Device,
- FX_FLOAT font_size,
+ float font_size,
uint32_t color) override;
const int m_HorzSize;
@@ -290,13 +294,13 @@ class CPSPrinterDriver : public IFX_RenderDeviceDriver {
int fill_mode,
int blend_type) override;
bool GetClipBox(FX_RECT* pRect) override;
- bool SetDIBits(const CFX_DIBSource* pBitmap,
+ bool SetDIBits(const CFX_RetainPtr<CFX_DIBSource>& pBitmap,
uint32_t color,
const FX_RECT* pSrcRect,
int left,
int top,
int blend_type) override;
- bool StretchDIBits(const CFX_DIBSource* pBitmap,
+ bool StretchDIBits(const CFX_RetainPtr<CFX_DIBSource>& pBitmap,
uint32_t color,
int dest_left,
int dest_top,
@@ -305,18 +309,18 @@ class CPSPrinterDriver : public IFX_RenderDeviceDriver {
const FX_RECT* pClipRect,
uint32_t flags,
int blend_type) override;
- bool StartDIBits(const CFX_DIBSource* pBitmap,
+ bool StartDIBits(const CFX_RetainPtr<CFX_DIBSource>& pBitmap,
int bitmap_alpha,
uint32_t color,
const CFX_Matrix* pMatrix,
uint32_t render_flags,
- void*& handle,
+ std::unique_ptr<CFX_ImageRenderer>* handle,
int blend_type) override;
bool DrawDeviceText(int nChars,
const FXTEXT_CHARPOS* pCharPos,
CFX_Font* pFont,
const CFX_Matrix* pObject2Device,
- FX_FLOAT font_size,
+ float font_size,
uint32_t color) override;
void* GetPlatformSurface() const override;