summaryrefslogtreecommitdiff
path: root/core/fxge/dib
diff options
context:
space:
mode:
Diffstat (limited to 'core/fxge/dib')
-rw-r--r--core/fxge/dib/cfx_dibitmap.cpp17
-rw-r--r--core/fxge/dib/cfx_dibsource.cpp69
-rw-r--r--core/fxge/dib/cfx_filtereddib.cpp4
-rw-r--r--core/fxge/dib/cfx_scanlinecompositor.cpp49
-rw-r--r--core/fxge/dib/cstretchengine.cpp4
-rw-r--r--core/fxge/dib/fx_dib_main.cpp11
6 files changed, 78 insertions, 76 deletions
diff --git a/core/fxge/dib/cfx_dibitmap.cpp b/core/fxge/dib/cfx_dibitmap.cpp
index ae9bf244f0..9fa9776df0 100644
--- a/core/fxge/dib/cfx_dibitmap.cpp
+++ b/core/fxge/dib/cfx_dibitmap.cpp
@@ -19,7 +19,7 @@
namespace {
-const int8_t g_ChannelOffset[] = {0, 2, 1, 0, 0, 1, 2, 3, 3};
+const int8_t kChannelOffset[] = {0, 2, 1, 0, 0, 1, 2, 3, 3};
} // namespace
@@ -274,7 +274,7 @@ bool CFX_DIBitmap::LoadChannel(FXDIB_Channel destChannel,
if (!pSrcClone)
return false;
}
- srcOffset = g_ChannelOffset[srcChannel];
+ srcOffset = kChannelOffset[srcChannel];
}
int destOffset = 0;
if (destChannel == FXDIB_Alpha) {
@@ -304,7 +304,7 @@ bool CFX_DIBitmap::LoadChannel(FXDIB_Channel destChannel,
return false;
}
}
- destOffset = g_ChannelOffset[destChannel];
+ destOffset = kChannelOffset[destChannel];
}
if (srcChannel == FXDIB_Alpha && pSrcClone->m_pAlphaMask) {
RetainPtr<CFX_DIBSource> pAlphaMask = pSrcClone->m_pAlphaMask;
@@ -383,7 +383,7 @@ bool CFX_DIBitmap::LoadChannel(FXDIB_Channel destChannel, int value) {
return false;
}
}
- destOffset = g_ChannelOffset[destChannel];
+ destOffset = kChannelOffset[destChannel];
}
int Bpp = GetBPP() / 8;
if (Bpp == 1) {
@@ -819,14 +819,15 @@ bool CFX_DIBitmap::CalculatePitchAndSize(int height,
if (width <= 0 || height <= 0)
return false;
- if (!(format & 0xff))
+ int bpp = GetBppFromFormat(format);
+ if (!bpp)
return false;
- if ((INT_MAX - 31) / width < (format & 0xff))
+ if ((INT_MAX - 31) / width < bpp)
return false;
if (!*pitch)
- *pitch = static_cast<uint32_t>((width * (format & 0xff) + 31) / 32 * 4);
+ *pitch = static_cast<uint32_t>((width * bpp + 31) / 32 * 4);
if ((1 << 30) / *pitch < static_cast<uint32_t>(height))
return false;
@@ -1190,7 +1191,7 @@ bool CFX_DIBitmap::ConvertFormat(FXDIB_Format dest_format) {
}
return true;
}
- int dest_bpp = dest_format & 0xff;
+ int dest_bpp = GetBppFromFormat(dest_format);
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));
diff --git a/core/fxge/dib/cfx_dibsource.cpp b/core/fxge/dib/cfx_dibsource.cpp
index 86bec23c67..f140a5e838 100644
--- a/core/fxge/dib/cfx_dibsource.cpp
+++ b/core/fxge/dib/cfx_dibsource.cpp
@@ -22,23 +22,6 @@
namespace {
-class CFX_Palette {
- public:
- explicit CFX_Palette(const RetainPtr<CFX_DIBSource>& pBitmap);
- ~CFX_Palette();
-
- 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; }
-
- private:
- std::vector<uint32_t> m_Palette;
- // (Amount, Color) pairs
- std::vector<std::pair<uint32_t, uint32_t>> m_Luts;
- int m_lut;
-};
-
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);
@@ -64,6 +47,23 @@ void Obtain_Pal(std::pair<uint32_t, uint32_t>* luts,
}
}
+class CFX_Palette {
+ public:
+ explicit CFX_Palette(const RetainPtr<CFX_DIBSource>& pBitmap);
+ ~CFX_Palette();
+
+ 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; }
+
+ private:
+ std::vector<uint32_t> m_Palette;
+ // (Amount, Color) pairs
+ std::vector<std::pair<uint32_t, uint32_t>> m_Luts;
+ int m_lut;
+};
+
CFX_Palette::CFX_Palette(const RetainPtr<CFX_DIBSource>& pBitmap)
: m_Palette(256), m_Luts(4096), m_lut(0) {
int bpp = pBitmap->GetBPP() / 8;
@@ -368,7 +368,7 @@ void ConvertBuffer_Rgb2PltRgb8(uint8_t* dest_buf,
memcpy(dst_plt, pal, sizeof(uint32_t) * 256);
}
-void ConvertBuffer_1bppMask2Rgb(FXDIB_Format dst_format,
+void ConvertBuffer_1bppMask2Rgb(FXDIB_Format dest_format,
uint8_t* dest_buf,
int dest_pitch,
int width,
@@ -376,29 +376,28 @@ void ConvertBuffer_1bppMask2Rgb(FXDIB_Format dst_format,
const RetainPtr<CFX_DIBSource>& pSrcBitmap,
int src_left,
int src_top) {
- int comps = (dst_format & 0xff) / 8;
- uint8_t set_gray, reset_gray;
- set_gray = 0xff;
- reset_gray = 0x00;
+ int comps = GetCompsFromFormat(dest_format);
+ static constexpr uint8_t kSetGray = 0xff;
+ static constexpr uint8_t kResetGray = 0x00;
for (int row = 0; row < height; ++row) {
uint8_t* dest_scan = dest_buf + row * dest_pitch;
const uint8_t* src_scan = pSrcBitmap->GetScanline(src_top + row);
for (int col = src_left; col < src_left + width; ++col) {
if (src_scan[col / 8] & (1 << (7 - col % 8))) {
- dest_scan[0] = set_gray;
- dest_scan[1] = set_gray;
- dest_scan[2] = set_gray;
+ dest_scan[0] = kSetGray;
+ dest_scan[1] = kSetGray;
+ dest_scan[2] = kSetGray;
} else {
- dest_scan[0] = reset_gray;
- dest_scan[1] = reset_gray;
- dest_scan[2] = reset_gray;
+ dest_scan[0] = kResetGray;
+ dest_scan[1] = kResetGray;
+ dest_scan[2] = kResetGray;
}
dest_scan += comps;
}
}
}
-void ConvertBuffer_8bppMask2Rgb(FXDIB_Format dst_format,
+void ConvertBuffer_8bppMask2Rgb(FXDIB_Format dest_format,
uint8_t* dest_buf,
int dest_pitch,
int width,
@@ -406,7 +405,7 @@ void ConvertBuffer_8bppMask2Rgb(FXDIB_Format dst_format,
const RetainPtr<CFX_DIBSource>& pSrcBitmap,
int src_left,
int src_top) {
- int comps = (dst_format & 0xff) / 8;
+ int comps = GetCompsFromFormat(dest_format);
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;
@@ -421,7 +420,7 @@ void ConvertBuffer_8bppMask2Rgb(FXDIB_Format dst_format,
}
}
-void ConvertBuffer_1bppPlt2Rgb(FXDIB_Format dst_format,
+void ConvertBuffer_1bppPlt2Rgb(FXDIB_Format dest_format,
uint8_t* dest_buf,
int dest_pitch,
int width,
@@ -429,7 +428,7 @@ void ConvertBuffer_1bppPlt2Rgb(FXDIB_Format dst_format,
const RetainPtr<CFX_DIBSource>& pSrcBitmap,
int src_left,
int src_top) {
- int comps = (dst_format & 0xff) / 8;
+ int comps = GetCompsFromFormat(dest_format);
uint32_t* src_plt = pSrcBitmap->GetPalette();
uint32_t plt[2];
uint8_t* bgr_ptr = reinterpret_cast<uint8_t*>(plt);
@@ -472,7 +471,7 @@ void ConvertBuffer_1bppPlt2Rgb(FXDIB_Format dst_format,
}
}
-void ConvertBuffer_8bppPlt2Rgb(FXDIB_Format dst_format,
+void ConvertBuffer_8bppPlt2Rgb(FXDIB_Format dest_format,
uint8_t* dest_buf,
int dest_pitch,
int width,
@@ -480,7 +479,7 @@ void ConvertBuffer_8bppPlt2Rgb(FXDIB_Format dst_format,
const RetainPtr<CFX_DIBSource>& pSrcBitmap,
int src_left,
int src_top) {
- int comps = (dst_format & 0xff) / 8;
+ int comps = GetCompsFromFormat(dest_format);
uint32_t* src_plt = pSrcBitmap->GetPalette();
uint32_t plt[256];
uint8_t* bgr_ptr = reinterpret_cast<uint8_t*>(plt);
@@ -1218,7 +1217,7 @@ bool CFX_DIBSource::ConvertBuffer(
int src_top,
std::unique_ptr<uint32_t, FxFreeDeleter>* p_pal) {
FXDIB_Format src_format = pSrcBitmap->GetFormat();
- const int bpp = src_format & 0xff;
+ const int bpp = GetBppFromFormat(src_format);
switch (dest_format) {
case FXDIB_8bppMask: {
return ConvertBuffer_8bppMask(bpp, dest_buf, dest_pitch, width, height,
diff --git a/core/fxge/dib/cfx_filtereddib.cpp b/core/fxge/dib/cfx_filtereddib.cpp
index 96fc8062a0..1d5ed6200c 100644
--- a/core/fxge/dib/cfx_filtereddib.cpp
+++ b/core/fxge/dib/cfx_filtereddib.cpp
@@ -17,9 +17,9 @@ void CFX_FilteredDIB::LoadSrc(const RetainPtr<CFX_DIBSource>& pSrc) {
m_Width = pSrc->GetWidth();
m_Height = pSrc->GetHeight();
FXDIB_Format format = GetDestFormat();
- m_bpp = static_cast<uint8_t>(format);
+ m_bpp = GetBppFromFormat(format);
m_AlphaFlag = static_cast<uint8_t>(format >> 8);
- m_Pitch = (m_Width * (format & 0xff) + 31) / 32 * 4;
+ m_Pitch = (m_Width * m_bpp + 31) / 32 * 4;
m_pPalette.reset(GetDestPalette());
m_Scanline.resize(m_Pitch);
}
diff --git a/core/fxge/dib/cfx_scanlinecompositor.cpp b/core/fxge/dib/cfx_scanlinecompositor.cpp
index a1254e2116..ae27ee0246 100644
--- a/core/fxge/dib/cfx_scanlinecompositor.cpp
+++ b/core/fxge/dib/cfx_scanlinecompositor.cpp
@@ -2833,7 +2833,7 @@ bool CFX_ScanlineCompositor::Init(FXDIB_Format dest_format,
m_DestFormat = dest_format;
m_BlendType = blend_type;
m_bRgbByteOrder = bRgbByteOrder;
- if ((dest_format & 0xff) == 1)
+ if (GetBppFromFormat(dest_format) == 1)
return false;
if (m_SrcFormat == FXDIB_1bppMask || m_SrcFormat == FXDIB_8bppMask) {
InitSourceMask(alpha_flag, mask_color);
@@ -2846,9 +2846,10 @@ bool CFX_ScanlineCompositor::Init(FXDIB_Format dest_format,
return true;
InitSourcePalette(src_format, dest_format, pSrcPalette);
- m_iTransparency =
- (dest_format == FXDIB_Argb ? 1 : 0) + (dest_format & 0x0200 ? 2 : 0) +
- (dest_format & 0x0400 ? 4 : 0) + ((src_format & 0xff) == 1 ? 8 : 0);
+ m_iTransparency = (dest_format == FXDIB_Argb ? 1 : 0) +
+ (dest_format & 0x0200 ? 2 : 0) +
+ (dest_format & 0x0400 ? 4 : 0) +
+ (GetBppFromFormat(src_format) == 1 ? 8 : 0);
return true;
}
m_iTransparency =
@@ -2907,15 +2908,16 @@ void CFX_ScanlineCompositor::InitSourceMask(int alpha_flag,
void CFX_ScanlineCompositor::InitSourcePalette(FXDIB_Format src_format,
FXDIB_Format dest_format,
const uint32_t* pSrcPalette) {
- bool isSrcCmyk = !!(src_format & 0x0400);
- bool isDstCmyk = !!(dest_format & 0x0400);
+ bool bIsSrcCmyk = !!(src_format & 0x0400);
+ bool bIsDstCmyk = !!(dest_format & 0x0400);
+ bool bIsDestBpp8 = GetBppFromFormat(dest_format) == 8;
+ int pal_count = 1 << GetBppFromFormat(src_format);
m_pSrcPalette = nullptr;
if (pSrcPalette) {
- if ((dest_format & 0xff) == 8) {
- int pal_count = 1 << (src_format & 0xff);
+ if (bIsDestBpp8) {
uint8_t* gray_pal = FX_Alloc(uint8_t, pal_count);
m_pSrcPalette.reset(reinterpret_cast<uint32_t*>(gray_pal));
- if (isSrcCmyk) {
+ if (bIsSrcCmyk) {
for (int i = 0; i < pal_count; ++i) {
FX_CMYK cmyk = pSrcPalette[i];
uint8_t r;
@@ -2935,13 +2937,12 @@ void CFX_ScanlineCompositor::InitSourcePalette(FXDIB_Format src_format,
}
return;
}
- int palsize = 1 << (src_format & 0xff);
- m_pSrcPalette.reset(FX_Alloc(uint32_t, palsize));
+ m_pSrcPalette.reset(FX_Alloc(uint32_t, pal_count));
uint32_t* pPalette = m_pSrcPalette.get();
- if (isDstCmyk == isSrcCmyk) {
- memcpy(pPalette, pSrcPalette, palsize * sizeof(uint32_t));
+ if (bIsDstCmyk == bIsSrcCmyk) {
+ memcpy(pPalette, pSrcPalette, pal_count * sizeof(uint32_t));
} else {
- for (int i = 0; i < palsize; ++i) {
+ for (int i = 0; i < pal_count; ++i) {
FX_CMYK cmyk = pSrcPalette[i];
uint8_t r;
uint8_t g;
@@ -2954,8 +2955,7 @@ void CFX_ScanlineCompositor::InitSourcePalette(FXDIB_Format src_format,
}
return;
}
- if ((dest_format & 0xff) == 8) {
- int pal_count = 1 << (src_format & 0xff);
+ if (bIsDestBpp8) {
uint8_t* gray_pal = FX_Alloc(uint8_t, pal_count);
if (pal_count == 2) {
gray_pal[0] = 0;
@@ -2967,18 +2967,17 @@ void CFX_ScanlineCompositor::InitSourcePalette(FXDIB_Format src_format,
m_pSrcPalette.reset(reinterpret_cast<uint32_t*>(gray_pal));
return;
}
- int palsize = 1 << (src_format & 0xff);
- m_pSrcPalette.reset(FX_Alloc(uint32_t, palsize));
+ m_pSrcPalette.reset(FX_Alloc(uint32_t, pal_count));
uint32_t* pPalette = m_pSrcPalette.get();
- if (palsize == 2) {
- pPalette[0] = isSrcCmyk ? 255 : 0xff000000;
- pPalette[1] = isSrcCmyk ? 0 : 0xffffffff;
+ if (pal_count == 2) {
+ pPalette[0] = bIsSrcCmyk ? 255 : 0xff000000;
+ pPalette[1] = bIsSrcCmyk ? 0 : 0xffffffff;
} else {
- for (int i = 0; i < palsize; ++i)
- pPalette[i] = isSrcCmyk ? FX_CCOLOR(i) : (i * 0x10101);
+ for (int i = 0; i < pal_count; ++i)
+ pPalette[i] = bIsSrcCmyk ? FX_CCOLOR(i) : (i * 0x10101);
}
- if (isSrcCmyk != isDstCmyk) {
- for (int i = 0; i < palsize; ++i) {
+ if (bIsSrcCmyk != bIsDstCmyk) {
+ for (int i = 0; i < pal_count; ++i) {
FX_CMYK cmyk = pPalette[i];
uint8_t r;
uint8_t g;
diff --git a/core/fxge/dib/cstretchengine.cpp b/core/fxge/dib/cstretchengine.cpp
index b7aa672a46..9d3923adab 100644
--- a/core/fxge/dib/cstretchengine.cpp
+++ b/core/fxge/dib/cstretchengine.cpp
@@ -229,8 +229,8 @@ CStretchEngine::CStretchEngine(ScanlineComposerIface* pDestBitmap,
const RetainPtr<CFX_DIBSource>& pSrcBitmap,
int flags)
: m_DestFormat(dest_format),
- m_DestBpp(dest_format & 0xff),
- m_SrcBpp(pSrcBitmap->GetFormat() & 0xff),
+ m_DestBpp(GetBppFromFormat(dest_format)),
+ m_SrcBpp(GetBppFromFormat(pSrcBitmap->GetFormat())),
m_bHasAlpha(pSrcBitmap->GetFormat() & 0x200),
m_pSource(pSrcBitmap),
m_pSrcPalette(pSrcBitmap->GetPalette()),
diff --git a/core/fxge/dib/fx_dib_main.cpp b/core/fxge/dib/fx_dib_main.cpp
index 002fc2e394..546198b7a9 100644
--- a/core/fxge/dib/fx_dib_main.cpp
+++ b/core/fxge/dib/fx_dib_main.cpp
@@ -50,7 +50,7 @@ const int16_t SDP_Table[513] = {
0, 0, 0,
};
-FX_RECT FXDIB_SwapClipBox(FX_RECT& clip,
+FX_RECT FXDIB_SwapClipBox(const FX_RECT& clip,
int width,
int height,
bool bFlipX,
@@ -93,9 +93,9 @@ FX_ARGB AlphaAndColorRefToArgb(int a, FX_COLORREF colorref) {
}
FX_ARGB StringToFXARGB(const WideStringView& wsValue) {
- uint8_t r = 0, g = 0, b = 0;
+ static constexpr FX_ARGB kDefaultValue = 0xff000000;
if (wsValue.GetLength() == 0)
- return 0xff000000;
+ return kDefaultValue;
int cc = 0;
const wchar_t* str = wsValue.unterminated_c_str();
@@ -104,8 +104,11 @@ FX_ARGB StringToFXARGB(const WideStringView& wsValue) {
cc++;
if (cc >= len)
- return 0xff000000;
+ return kDefaultValue;
+ uint8_t r = 0;
+ uint8_t g = 0;
+ uint8_t b = 0;
while (cc < len) {
if (str[cc] == ',' || !FXSYS_isDecimalDigit(str[cc]))
break;