24#include <osl/diagnose.h>
29#define IMPL_CASE_SET_FORMAT( Format, BitCount ) \
30case( ScanlineFormat::Format ): \
32 pFncSetPixel = BitmapReadAccess::SetPixelFor##Format; \
33 pDstBuffer->mnBitCount = BitCount; \
37#define DOUBLE_SCANLINES() \
38while( ( nActY < nHeight1 ) && ( pMapY[ nActY + 1 ] == nMapY ) ) \
40 memcpy( pDstScanMap[ nActY + 1 ], pDstScan, rDstBuffer.mnScanlineSize ); \
55 Scanline* pSrcScanMap,
Scanline* pDstScanMap, sal_Int32
const * pMapX,
const sal_Int32* pMapY )
67 aIndex.SetIndex( sal::static_int_cast<sal_uInt8>(
i) );
77 Scanline pSrcScan(pSrcScanMap[nMapY]), pDstScan(pDstScanMap[nActY]);
80 pFncSetPixel( pDstScan, nX, pColMapBuf[ pFncGetPixel( pSrcScan, pMapX[ nX ], rSrcMask ).GetIndex() ], rDstMask );
88 Scanline* pSrcScanMap,
Scanline* pDstScanMap, sal_Int32
const * pMapX,
const sal_Int32* pMapY )
104 Scanline pSrcScan(pSrcScanMap[nMapY]), pDstScan(pDstScanMap[nActY]);
109 pFncSetPixel( pDstScan, nX++,
110 pSrcScan[ nMapX >> 3 ] & ( 1 << ( 7 - ( nMapX & 7 ) ) ) ? aCol1 : aCol0,
122 Scanline pSrcScan(pSrcScanMap[nMapY]), pDstScan(pDstScanMap[nActY]);
125 pFncSetPixel( pDstScan, nX, pColBuf[ pSrcScan[ pMapX[ nX ] ] ], rDstMask );
135 Scanline pSrcScan(pSrcScanMap[nMapY]), pDstScan(pDstScanMap[nActY]);
138 pFncSetPixel( pDstScan, nX, pColBuf[ pFncGetPixel( pSrcScan, pMapX[ nX ], rSrcMask ).GetIndex() ], rDstMask );
147 Scanline* pSrcScanMap,
Scanline* pDstScanMap, sal_Int32
const * pMapX,
const sal_Int32* pMapY )
161 Scanline pSrcScan(pSrcScanMap[nMapY]), pDstScan(pDstScanMap[nActY]);
165 pPixel = pSrcScan + pMapX[ nX ] * 3;
169 pFncSetPixel( pDstScan, nX, aCol, rDstMask );
180 Scanline pSrcScan(pSrcScanMap[nMapY]), pDstScan(pDstScanMap[nActY]);
183 pFncSetPixel( pDstScan, nX, pFncGetPixel( pSrcScan, pMapX[ nX ], rSrcMask ), rDstMask );
192 Scanline* pSrcScanMap,
Scanline* pDstScanMap, sal_Int32
const * pMapX,
const sal_Int32* pMapY )
206 BitmapColor aCol( sal::static_int_cast<sal_uInt8>(nR << 4),
207 sal::static_int_cast<sal_uInt8>(nG << 4),
208 sal::static_int_cast<sal_uInt8>(nB << 4) );
217 Scanline pSrcScan(pSrcScanMap[nMapY]), pDstScan(pDstScanMap[nActY]);
222 pFncSetPixel( pDstScan, nX,
aIndex, rDstMask );
235 std::unique_ptr<BitmapBuffer> pDstBuffer(
new BitmapBuffer);
245 OSL_FAIL(
"unknown read format" );
250 switch( nDstScanlineFormat )
267 pDstBuffer->mnBitCount = 1;
268 OSL_FAIL(
"unknown write format" );
273 pDstBuffer->mnFormat = nDstBitmapFormat;
277 bool bFail = o3tl::checked_multiply<tools::Long>(pDstBuffer->mnBitCount, pDstBuffer->mnWidth, nScanlineBase);
280 SAL_WARN(
"vcl.gdi",
"checked multiply failed");
281 pDstBuffer->mpBits =
nullptr;
285 if (pDstBuffer->mnScanlineSize < nScanlineBase/8)
287 SAL_WARN(
"vcl.gdi",
"scanline calculation wraparound");
288 pDstBuffer->mpBits =
nullptr;
293 pDstBuffer->mpBits =
new sal_uInt8[ pDstBuffer->mnScanlineSize * pDstBuffer->mnHeight ];
295 catch(
const std::bad_alloc& )
298 pDstBuffer->mpBits =
nullptr;
306 assert(pDstPal &&
"destination buffer requires palette");
311 pDstBuffer->maPalette = *pDstPal;
315 assert(pDstMask &&
"destination buffer requires color mask");
320 pDstBuffer->maColorMask = *pDstMask;
328 std::unique_ptr<Scanline[]> pSrcScan;
329 std::unique_ptr<Scanline[]> pDstScan;
330 std::unique_ptr<sal_Int32[]> pMapX;
331 std::unique_ptr<sal_Int32[]> pMapY;
336 pDstScan.reset(
new Scanline[pDstBuffer->mnHeight]);
337 pMapX.reset(
new sal_Int32[pDstBuffer->mnWidth]);
338 pMapY.reset(
new sal_Int32[pDstBuffer->mnHeight]);
340 catch(
const std::bad_alloc& )
349 if( (pDstBuffer->mnWidth != rTwoRect.
mnSrcWidth) && (pDstBuffer->mnWidth != 0) )
351 const double fFactorX =
static_cast<double>(rTwoRect.
mnSrcWidth) / pDstBuffer->mnWidth;
354 pMapX[
i ] = rTwoRect.
mnSrcX +
static_cast<int>(
i * fFactorX );
363 if( (pDstBuffer->mnHeight != rTwoRect.
mnSrcHeight) && (pDstBuffer->mnHeight != 0) )
365 const double fFactorY =
static_cast<double>(rTwoRect.
mnSrcHeight) / pDstBuffer->mnHeight;
368 pMapY[
i ] = rTwoRect.
mnSrcY +
static_cast<int>(
i * fFactorY );
381 pTmpScan = rSrcBuffer.
mpBits;
391 pSrcScan[
i ] = pTmpScan;
396 pTmpScan = pDstBuffer->mpBits;
397 nOffset = pDstBuffer->mnScanlineSize;
401 pTmpScan = pDstBuffer->mpBits + ( pDstBuffer->mnHeight - 1 ) * pDstBuffer->mnScanlineSize;
402 nOffset = -pDstBuffer->mnScanlineSize;
405 for (
tools::Long i = 0;
i < pDstBuffer->mnHeight;
i++, pTmpScan += nOffset)
406 pDstScan[
i ] = pTmpScan;
409 if( rSrcBuffer.
mnBitCount <= 8 && pDstBuffer->mnBitCount <= 8 )
411 ImplPALToPAL( rSrcBuffer, *pDstBuffer, pFncGetPixel, pFncSetPixel,
412 pSrcScan.get(), pDstScan.get(), pMapX.get(), pMapY.get() );
414 else if( rSrcBuffer.
mnBitCount <= 8 && pDstBuffer->mnBitCount > 8 )
416 ImplPALToTC( rSrcBuffer, *pDstBuffer, pFncGetPixel, pFncSetPixel,
417 pSrcScan.get(), pDstScan.get(), pMapX.get(), pMapY.get() );
419 else if( rSrcBuffer.
mnBitCount > 8 && pDstBuffer->mnBitCount > 8 )
421 ImplTCToTC( rSrcBuffer, *pDstBuffer, pFncGetPixel, pFncSetPixel,
422 pSrcScan.get(), pDstScan.get(), pMapX.get(), pMapY.get() );
426 ImplTCToPAL( rSrcBuffer, *pDstBuffer, pFncGetPixel, pFncSetPixel,
427 pSrcScan.get(), pDstScan.get(), pMapX.get(), pMapY.get() );
void(* FncSetPixel)(Scanline pScanline, tools::Long nX, const BitmapColor &rBitmapColor, const ColorMask &rMask)
BitmapColor(* FncGetPixel)(ConstScanline pScanline, tools::Long nX, const ColorMask &rMask)
ScanlineFormat RemoveScanline(ScanlineFormat nFormat)
bool ImplFastBitmapConversion(BitmapBuffer &rDst, const BitmapBuffer &rSrc, const SalTwoRect &rTR)
sal_uInt16 GetEntryCount() const
sal_uInt16 GetBestIndex(const BitmapColor &rCol) const
SAL_DLLPRIVATE const BitmapColor * ImplGetColorBuffer() const
static FncGetPixel GetPixelFunction(ScanlineFormat nFormat)
static void SetPixelForN1BitMsbPal(Scanline pScanline, tools::Long nX, const BitmapColor &rBitmapColor, const ColorMask &rMask)
static BitmapColor GetPixelForN1BitMsbPal(ConstScanline pScanline, tools::Long nX, const ColorMask &rMask)
sal_uInt8 GetBlue() const
void SetGreen(sal_uInt8 nGreen)
void SetRed(sal_uInt8 nRed)
sal_uInt8 GetGreen() const
void SetBlue(sal_uInt8 nBlue)
std::deque< AttacherIndex_Impl > aIndex
sal_uInt32 AlignedWidth4Bytes(sal_uInt32 nWidthBits)
#define SAL_WARN(area, stream)
static void ImplTCToTC(const BitmapBuffer &rSrcBuffer, BitmapBuffer const &rDstBuffer, FncGetPixel pFncGetPixel, FncSetPixel pFncSetPixel, Scanline *pSrcScanMap, Scanline *pDstScanMap, sal_Int32 const *pMapX, const sal_Int32 *pMapY)
constexpr int TC_TO_PAL_COLORS
#define IMPL_CASE_SET_FORMAT(Format, BitCount)
static tools::Long ImplIndexFromColor(const BitmapColor &rCol)
static void ImplPALToPAL(const BitmapBuffer &rSrcBuffer, BitmapBuffer &rDstBuffer, FncGetPixel pFncGetPixel, FncSetPixel pFncSetPixel, Scanline *pSrcScanMap, Scanline *pDstScanMap, sal_Int32 const *pMapX, const sal_Int32 *pMapY)
#define DOUBLE_SCANLINES()
static void ImplPALToTC(const BitmapBuffer &rSrcBuffer, BitmapBuffer const &rDstBuffer, FncGetPixel pFncGetPixel, FncSetPixel pFncSetPixel, Scanline *pSrcScanMap, Scanline *pDstScanMap, sal_Int32 const *pMapX, const sal_Int32 *pMapY)
static void ImplTCToPAL(const BitmapBuffer &rSrcBuffer, BitmapBuffer const &rDstBuffer, FncGetPixel pFncGetPixel, FncSetPixel pFncSetPixel, Scanline *pSrcScanMap, Scanline *pDstScanMap, sal_Int32 const *pMapX, const sal_Int32 *pMapY)
std::unique_ptr< BitmapBuffer > StretchAndConvert(const BitmapBuffer &rSrcBuffer, const SalTwoRect &rTwoRect, ScanlineFormat nDstBitmapFormat, std::optional< BitmapPalette > pDstPal, const ColorMask *pDstMask)
tools::Long mnScanlineSize