diff options
author | Lei Zhang <thestig@chromium.org> | 2018-03-21 17:24:46 +0000 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2018-03-21 17:24:46 +0000 |
commit | 3851aff62c7ad2f9c942b4d5d095ec0e6610bb84 (patch) | |
tree | c15c662f2f9ac851c33fe1603057088d4eb319b5 /core | |
parent | bf85feeafdd8791f9dab7bfcd14ff850e015be26 (diff) | |
download | pdfium-3851aff62c7ad2f9c942b4d5d095ec0e6610bb84.tar.xz |
Add helpers to work with FXDIB_Format.
Helper functions make getting the bpp and component count more readable.
Change-Id: Ie0f97d52136d11ef5251f6e22748e87aea289ae1
Reviewed-on: https://pdfium-review.googlesource.com/28572
Commit-Queue: Lei Zhang <thestig@chromium.org>
Reviewed-by: Henrique Nakashima <hnakashima@chromium.org>
Diffstat (limited to 'core')
-rw-r--r-- | core/fxcodec/codec/fx_codec_progress.cpp | 28 | ||||
-rw-r--r-- | core/fxge/dib/cfx_dibitmap.cpp | 17 | ||||
-rw-r--r-- | core/fxge/dib/cfx_dibsource.cpp | 69 | ||||
-rw-r--r-- | core/fxge/dib/cfx_filtereddib.cpp | 4 | ||||
-rw-r--r-- | core/fxge/dib/cfx_scanlinecompositor.cpp | 49 | ||||
-rw-r--r-- | core/fxge/dib/cstretchengine.cpp | 4 | ||||
-rw-r--r-- | core/fxge/dib/fx_dib_main.cpp | 11 | ||||
-rw-r--r-- | core/fxge/fx_dib.h | 10 |
8 files changed, 100 insertions, 92 deletions
diff --git a/core/fxcodec/codec/fx_codec_progress.cpp b/core/fxcodec/codec/fx_codec_progress.cpp index 7e29524b2f..8807879e6e 100644 --- a/core/fxcodec/codec/fx_codec_progress.cpp +++ b/core/fxcodec/codec/fx_codec_progress.cpp @@ -1478,12 +1478,10 @@ void CCodec_ProgressiveDecoder::ReSampleScanline( int des_left = m_startX; uint8_t* des_scan = pDeviceBitmap->GetBuffer() + des_line * pDeviceBitmap->GetPitch(); - int src_bpp = src_format & 0xff; - int des_bpp = pDeviceBitmap->GetBPP(); - int src_Bpp = src_bpp >> 3; - int des_Bpp = des_bpp >> 3; - src_scan += src_left * src_Bpp; - des_scan += des_left * des_Bpp; + int src_bytes_per_pixel = (src_format & 0xff) / 8; + int dest_bytes_per_pixel = pDeviceBitmap->GetBPP() / 8; + src_scan += src_left * src_bytes_per_pixel; + des_scan += des_left * dest_bytes_per_pixel; for (int des_col = 0; des_col < m_sizeX; des_col++) { PixelWeight* pPixelWeights = m_WeightHorz.GetPixelWeight(des_col); switch (m_TransMethod) { @@ -1523,7 +1521,7 @@ void CCodec_ProgressiveDecoder::ReSampleScanline( j++) { int pixel_weight = pPixelWeights->m_Weights[j - pPixelWeights->m_SrcStart]; - const uint8_t* src_pixel = src_scan + j * src_Bpp; + const uint8_t* src_pixel = src_scan + j * src_bytes_per_pixel; des_b += pixel_weight * (*src_pixel++); des_g += pixel_weight * (*src_pixel++); des_r += pixel_weight * (*src_pixel); @@ -1537,7 +1535,7 @@ void CCodec_ProgressiveDecoder::ReSampleScanline( j++) { int pixel_weight = pPixelWeights->m_Weights[j - pPixelWeights->m_SrcStart]; - const uint8_t* src_pixel = src_scan + j * src_Bpp; + const uint8_t* src_pixel = src_scan + j * src_bytes_per_pixel; uint8_t src_b = 0; uint8_t src_g = 0; uint8_t src_r = 0; @@ -1562,7 +1560,7 @@ void CCodec_ProgressiveDecoder::ReSampleScanline( des_g += pixel_weight * src_scan[j]; } memset(des_scan, (uint8_t)(des_g >> 16), 3); - des_scan += des_Bpp; + des_scan += dest_bytes_per_pixel; } break; case 8: { int des_r = 0, des_g = 0, des_b = 0; @@ -1578,7 +1576,7 @@ void CCodec_ProgressiveDecoder::ReSampleScanline( *des_scan++ = (uint8_t)((des_b) >> 16); *des_scan++ = (uint8_t)((des_g) >> 16); *des_scan++ = (uint8_t)((des_r) >> 16); - des_scan += des_Bpp - 3; + des_scan += dest_bytes_per_pixel - 3; } break; case 12: { if (m_pBmpContext) { @@ -1620,7 +1618,7 @@ void CCodec_ProgressiveDecoder::ReSampleScanline( j++) { int pixel_weight = pPixelWeights->m_Weights[j - pPixelWeights->m_SrcStart]; - const uint8_t* src_pixel = src_scan + j * src_Bpp; + const uint8_t* src_pixel = src_scan + j * src_bytes_per_pixel; des_b += pixel_weight * (*src_pixel++); des_g += pixel_weight * (*src_pixel++); des_r += pixel_weight * (*src_pixel); @@ -1628,7 +1626,7 @@ void CCodec_ProgressiveDecoder::ReSampleScanline( *des_scan++ = (uint8_t)((des_b) >> 16); *des_scan++ = (uint8_t)((des_g) >> 16); *des_scan++ = (uint8_t)((des_r) >> 16); - des_scan += des_Bpp - 3; + des_scan += dest_bytes_per_pixel - 3; } break; case 10: { uint32_t des_b = 0, des_g = 0, des_r = 0; @@ -1636,7 +1634,7 @@ void CCodec_ProgressiveDecoder::ReSampleScanline( j++) { int pixel_weight = pPixelWeights->m_Weights[j - pPixelWeights->m_SrcStart]; - const uint8_t* src_pixel = src_scan + j * src_Bpp; + const uint8_t* src_pixel = src_scan + j * src_bytes_per_pixel; uint8_t src_b = 0; uint8_t src_g = 0; uint8_t src_r = 0; @@ -1650,7 +1648,7 @@ void CCodec_ProgressiveDecoder::ReSampleScanline( *des_scan++ = (uint8_t)((des_b) >> 16); *des_scan++ = (uint8_t)((des_g) >> 16); *des_scan++ = (uint8_t)((des_r) >> 16); - des_scan += des_Bpp - 3; + des_scan += dest_bytes_per_pixel - 3; } break; case 11: { uint32_t des_alpha = 0, des_r = 0, des_g = 0, des_b = 0; @@ -1658,7 +1656,7 @@ void CCodec_ProgressiveDecoder::ReSampleScanline( j++) { int pixel_weight = pPixelWeights->m_Weights[j - pPixelWeights->m_SrcStart]; - const uint8_t* src_pixel = src_scan + j * src_Bpp; + const uint8_t* src_pixel = src_scan + j * src_bytes_per_pixel; pixel_weight = pixel_weight * src_pixel[3] / 255; des_b += pixel_weight * (*src_pixel++); des_g += pixel_weight * (*src_pixel++); 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; diff --git a/core/fxge/fx_dib.h b/core/fxge/fx_dib.h index 9acfa51bbe..57e844b946 100644 --- a/core/fxge/fx_dib.h +++ b/core/fxge/fx_dib.h @@ -95,6 +95,14 @@ constexpr uint8_t FXSYS_GetBValue(uint32_t bgr) { #define FXSYS_GetYValue(cmyk) ((uint8_t)((cmyk) >> 8) & 0xff) #define FXSYS_GetKValue(cmyk) ((uint8_t)(cmyk)&0xff) +inline int GetBppFromFormat(FXDIB_Format format) { + return format & 0xff; +} + +inline int GetCompsFromFormat(FXDIB_Format format) { + return (format & 0xff) / 8; +} + inline FX_CMYK CmykEncode(int c, int m, int y, int k) { return (c << 24) | (m << 16) | (y << 8) | k; } @@ -149,7 +157,7 @@ FX_ARGB StringToFXARGB(const WideStringView& view); ((uint8_t)(argb >> 16) | ((uint8_t)(argb >> 8)) << 8 | \ ((uint8_t)(argb)) << 16 | ((uint8_t)(argb >> 24) << 24)) -FX_RECT FXDIB_SwapClipBox(FX_RECT& clip, +FX_RECT FXDIB_SwapClipBox(const FX_RECT& clip, int width, int height, bool bFlipX, |