summaryrefslogtreecommitdiff
path: root/core/fxge/dib/fx_dib_composite.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'core/fxge/dib/fx_dib_composite.cpp')
-rw-r--r--core/fxge/dib/fx_dib_composite.cpp353
1 files changed, 0 insertions, 353 deletions
diff --git a/core/fxge/dib/fx_dib_composite.cpp b/core/fxge/dib/fx_dib_composite.cpp
index 86be539008..e7912e5a1b 100644
--- a/core/fxge/dib/fx_dib_composite.cpp
+++ b/core/fxge/dib/fx_dib_composite.cpp
@@ -10,359 +10,6 @@
#include "core/fxge/cfx_gemodule.h"
#include "core/fxge/ge/cfx_cliprgn.h"
-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,
- 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;
- }
- 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, pIccTransform)) {
- 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 + (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_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,
- 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;
- }
- 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, 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;