summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Pena <npm@chromium.org>2017-04-07 16:06:36 -0400
committerChromium commit bot <commit-bot@chromium.org>2017-04-18 20:20:31 +0000
commit9bd8b4c8687cc95bed5df131ca8764f9ce203944 (patch)
treef895695e6af71f18f120904c11d3492c42faf8ef
parent717296957c08c76473a25e4946e84e19f9d27cbf (diff)
downloadpdfium-9bd8b4c8687cc95bed5df131ca8764f9ce203944.tar.xz
Clean up unneeded code in agg and skia driver
- The agg driver never initializes an ICC transform and always uses an alpha_flag equal to 0 in a couple of methods. - The skia driver is not using CFX_Renderer. If it needs it later, we should move it out of fx_agg_driver.cpp into its own file, instead of duplicating the code. Change-Id: Ibd721cf1760270bea3f8f95d6e1e8edbc6ba1792 Reviewed-on: https://pdfium-review.googlesource.com/3952 Reviewed-by: Tom Sepez <tsepez@chromium.org> Reviewed-by: Cary Clark <caryclark@google.com> Commit-Queue: Nicolás Peña <npm@chromium.org>
-rw-r--r--core/fxge/agg/fx_agg_driver.cpp164
-rw-r--r--core/fxge/agg/fx_agg_driver.h4
-rw-r--r--core/fxge/skia/fx_skia_device.cpp831
3 files changed, 29 insertions, 970 deletions
diff --git a/core/fxge/agg/fx_agg_driver.cpp b/core/fxge/agg/fx_agg_driver.cpp
index e4fc151fab..b5ec4c5096 100644
--- a/core/fxge/agg/fx_agg_driver.cpp
+++ b/core/fxge/agg/fx_agg_driver.cpp
@@ -230,38 +230,14 @@ void RgbByteOrderTransferBitmap(const CFX_RetainPtr<CFX_DIBitmap>& pBitmap,
}
}
-FX_ARGB DefaultCMYK2ARGB(FX_CMYK cmyk, uint8_t alpha) {
- uint8_t r, g, b;
- AdobeCMYK_to_sRGB1(FXSYS_GetCValue(cmyk), FXSYS_GetMValue(cmyk),
- FXSYS_GetYValue(cmyk), FXSYS_GetKValue(cmyk), r, g, b);
- return ArgbEncode(alpha, r, g, b);
-}
-
bool DibSetPixel(const CFX_RetainPtr<CFX_DIBitmap>& pDevice,
int x,
int y,
- uint32_t color,
- int alpha_flag,
- void* pIccTransform) {
- bool bObjCMYK = !!FXGETFLAG_COLORTYPE(alpha_flag);
- int alpha = bObjCMYK ? FXGETFLAG_ALPHA_FILL(alpha_flag) : FXARGB_A(color);
- if (pIccTransform) {
- CCodec_IccModule* pIccModule =
- CFX_GEModule::Get()->GetCodecModule()->GetIccModule();
- color = bObjCMYK ? FXCMYK_TODIB(color) : FXARGB_TODIB(color);
- 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())
- color = (color & 0xffffff) | (alpha << 24);
- } else {
- if (pDevice->IsCmykImage()) {
- if (!bObjCMYK)
- return false;
- } else if (bObjCMYK) {
- color = DefaultCMYK2ARGB(color, alpha);
- }
- }
+ uint32_t color) {
+ int alpha = FXARGB_A(color);
+ if (pDevice->IsCmykImage())
+ return false;
+
pDevice->SetPixel(x, y, color);
if (pDevice->m_pAlphaMask)
pDevice->m_pAlphaMask->SetPixel(x, y, alpha << 24);
@@ -408,9 +384,7 @@ class CFX_Renderer {
const CFX_ClipRgn* pClipRgn,
uint32_t color,
bool bFullCover,
- bool bRgbByteOrder,
- int alpha_flag,
- void* pIccTransform);
+ bool bRgbByteOrder);
template <class Scanline>
void render(const Scanline& sl);
@@ -909,9 +883,7 @@ bool CFX_Renderer::Init(const CFX_RetainPtr<CFX_DIBitmap>& pDevice,
const CFX_ClipRgn* pClipRgn,
uint32_t color,
bool bFullCover,
- bool bRgbByteOrder,
- int alpha_flag,
- void* pIccTransform) {
+ bool bRgbByteOrder) {
m_pDevice = pDevice;
m_pClipRgn = pClipRgn;
composite_span = nullptr;
@@ -928,105 +900,30 @@ bool CFX_Renderer::Init(const CFX_RetainPtr<CFX_DIBitmap>& pDevice,
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();
- }
+ m_Alpha = FXARGB_A(color);
if (m_pDevice->GetBPP() == 8) {
ASSERT(!m_bRgbByteOrder);
composite_span = &CFX_Renderer::CompositeSpanGray;
- if (m_pDevice->IsAlphaMask()) {
+ 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));
- }
- }
- }
+ 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);
- }
- }
+ return false;
}
+ composite_span = (pDevice->GetFormat() == FXDIB_Argb)
+ ? &CFX_Renderer::CompositeSpanARGB
+ : &CFX_Renderer::CompositeSpanRGB;
+ 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;
@@ -1383,13 +1280,11 @@ bool CFX_AggDeviceDriver::RenderRasterizer(
agg::rasterizer_scanline_aa& rasterizer,
uint32_t color,
bool bFullCover,
- bool bGroupKnockout,
- int alpha_flag,
- void* pIccTransform) {
+ bool bGroupKnockout) {
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)) {
+ m_bRgbByteOrder)) {
return false;
}
agg::scanline_u8 scanline;
@@ -1424,8 +1319,7 @@ bool CFX_AggDeviceDriver::DrawPath(const CFX_PathData* pPathData,
? agg::fill_non_zero
: agg::fill_even_odd);
if (!RenderRasterizer(rasterizer, fill_color,
- !!(fill_mode & FXFILL_FULLCOVER), false, 0,
- nullptr)) {
+ !!(fill_mode & FXFILL_FULLCOVER), false)) {
return false;
}
}
@@ -1443,8 +1337,7 @@ bool CFX_AggDeviceDriver::DrawPath(const CFX_PathData* pPathData,
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,
- 0, nullptr);
+ !!(fill_mode & FXFILL_FULLCOVER), m_bGroupKnockout);
}
CFX_Matrix matrix1;
CFX_Matrix matrix2;
@@ -1470,8 +1363,7 @@ bool CFX_AggDeviceDriver::DrawPath(const CFX_PathData* pPathData,
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,
- nullptr);
+ !!(fill_mode & FXFILL_FULLCOVER), m_bGroupKnockout);
}
bool CFX_AggDeviceDriver::SetPixel(int x, int y, uint32_t color) {
@@ -1480,7 +1372,7 @@ bool CFX_AggDeviceDriver::SetPixel(int x, int y, uint32_t color) {
if (!m_pClipRgn) {
if (!m_bRgbByteOrder)
- return DibSetPixel(m_pBitmap, x, y, color, 0, nullptr);
+ return DibSetPixel(m_pBitmap, x, y, color);
RgbByteOrderSetPixel(m_pBitmap, x, y, color);
return true;
}
@@ -1489,7 +1381,7 @@ bool CFX_AggDeviceDriver::SetPixel(int x, int y, uint32_t color) {
if (m_pClipRgn->GetType() == CFX_ClipRgn::RectI) {
if (!m_bRgbByteOrder)
- return DibSetPixel(m_pBitmap, x, y, color, 0, nullptr);
+ return DibSetPixel(m_pBitmap, x, y, color);
RgbByteOrderSetPixel(m_pBitmap, x, y, color);
return true;
}
@@ -1503,7 +1395,7 @@ bool CFX_AggDeviceDriver::SetPixel(int x, int y, uint32_t color) {
RgbByteOrderSetPixel(m_pBitmap, x, y, color);
return true;
}
- return DibSetPixel(m_pBitmap, x, y, color, 0, nullptr);
+ return DibSetPixel(m_pBitmap, x, y, color);
}
bool CFX_AggDeviceDriver::FillRectWithBlend(const FX_RECT* pRect,
diff --git a/core/fxge/agg/fx_agg_driver.h b/core/fxge/agg/fx_agg_driver.h
index 3eb56c507e..1ce97d7853 100644
--- a/core/fxge/agg/fx_agg_driver.h
+++ b/core/fxge/agg/fx_agg_driver.h
@@ -101,9 +101,7 @@ class CFX_AggDeviceDriver : public IFX_RenderDeviceDriver {
bool RenderRasterizer(agg::rasterizer_scanline_aa& rasterizer,
uint32_t color,
bool bFullCover,
- bool bGroupKnockout,
- int alpha_flag,
- void* pIccTransform);
+ bool bGroupKnockout);
void SetClipMask(agg::rasterizer_scanline_aa& rasterizer);
diff --git a/core/fxge/skia/fx_skia_device.cpp b/core/fxge/skia/fx_skia_device.cpp
index df43c18fcc..46e284d8aa 100644
--- a/core/fxge/skia/fx_skia_device.cpp
+++ b/core/fxge/skia/fx_skia_device.cpp
@@ -2434,834 +2434,3 @@ void CFX_DIBSource::DebugVerifyBitmapIsPreMultiplied(void* opt) const {
}
#endif // SK_DEBUG
}
-
-#ifdef _SKIA_SUPPORT_PATHS_
-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_RetainPtr<CFX_DIBitmap> m_pOriDevice;
- FX_RECT m_ClipBox;
- 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,
- 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_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;
- }
- }
-
- 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 = 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();
- }
- 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;
- }
-};
-
-#endif // _SKIA_SUPPORT_PATHS_