1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 29*cdf0e10cSrcweir #include "precompiled_vcl.hxx" 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir #include <bmpfast.hxx> 32*cdf0e10cSrcweir 33*cdf0e10cSrcweir #ifndef NO_OPTIMIZED_BITMAP_ACCESS 34*cdf0e10cSrcweir 35*cdf0e10cSrcweir #include <tools/debug.hxx> 36*cdf0e10cSrcweir #include <vcl/bmpacc.hxx> 37*cdf0e10cSrcweir 38*cdf0e10cSrcweir #define FAST_ARGB_BGRA 39*cdf0e10cSrcweir 40*cdf0e10cSrcweir #include <stdlib.h> 41*cdf0e10cSrcweir static bool bDisableFastBitops = (getenv( "SAL_DISABLE_BITMAPS_OPTS" ) != NULL); 42*cdf0e10cSrcweir 43*cdf0e10cSrcweir typedef unsigned char PIXBYTE; 44*cdf0e10cSrcweir 45*cdf0e10cSrcweir class BasePixelPtr 46*cdf0e10cSrcweir { 47*cdf0e10cSrcweir public: 48*cdf0e10cSrcweir BasePixelPtr( PIXBYTE* p = NULL ) : mpPixel( p ) {} 49*cdf0e10cSrcweir void SetRawPtr( PIXBYTE* pRawPtr ) { mpPixel = pRawPtr; } 50*cdf0e10cSrcweir PIXBYTE* GetRawPtr( void ) const { return mpPixel; } 51*cdf0e10cSrcweir void AddByteOffset( int nByteOffset ) { mpPixel += nByteOffset; } 52*cdf0e10cSrcweir bool operator<( const BasePixelPtr& rCmp ) const { return (mpPixel < rCmp.mpPixel); } 53*cdf0e10cSrcweir 54*cdf0e10cSrcweir protected: 55*cdf0e10cSrcweir PIXBYTE* mpPixel; 56*cdf0e10cSrcweir }; 57*cdf0e10cSrcweir 58*cdf0e10cSrcweir template <sal_uLong PIXFMT> 59*cdf0e10cSrcweir class TrueColorPixelPtr : public BasePixelPtr 60*cdf0e10cSrcweir { 61*cdf0e10cSrcweir public: 62*cdf0e10cSrcweir PIXBYTE GetRed() const; 63*cdf0e10cSrcweir PIXBYTE GetGreen() const; 64*cdf0e10cSrcweir PIXBYTE GetBlue() const; 65*cdf0e10cSrcweir PIXBYTE GetAlpha() const; 66*cdf0e10cSrcweir 67*cdf0e10cSrcweir void SetColor( PIXBYTE r, PIXBYTE g, PIXBYTE b ) const; 68*cdf0e10cSrcweir void SetAlpha( PIXBYTE a ) const; 69*cdf0e10cSrcweir void operator++(int); 70*cdf0e10cSrcweir }; 71*cdf0e10cSrcweir 72*cdf0e10cSrcweir // ======================================================================= 73*cdf0e10cSrcweir // template specializations for truecolor pixel formats 74*cdf0e10cSrcweir 75*cdf0e10cSrcweir template <> 76*cdf0e10cSrcweir class TrueColorPixelPtr<BMP_FORMAT_24BIT_TC_RGB> : public BasePixelPtr 77*cdf0e10cSrcweir { 78*cdf0e10cSrcweir public: 79*cdf0e10cSrcweir void operator++() { mpPixel += 3; } 80*cdf0e10cSrcweir 81*cdf0e10cSrcweir PIXBYTE GetRed() const { return mpPixel[0]; } 82*cdf0e10cSrcweir PIXBYTE GetGreen() const { return mpPixel[1]; } 83*cdf0e10cSrcweir PIXBYTE GetBlue() const { return mpPixel[2]; } 84*cdf0e10cSrcweir PIXBYTE GetAlpha() const { return 0; } 85*cdf0e10cSrcweir void SetAlpha( PIXBYTE ) const {} 86*cdf0e10cSrcweir 87*cdf0e10cSrcweir void SetColor( PIXBYTE r, PIXBYTE g, PIXBYTE b ) const 88*cdf0e10cSrcweir { 89*cdf0e10cSrcweir mpPixel[0] = r; 90*cdf0e10cSrcweir mpPixel[1] = g; 91*cdf0e10cSrcweir mpPixel[2] = b; 92*cdf0e10cSrcweir } 93*cdf0e10cSrcweir }; 94*cdf0e10cSrcweir 95*cdf0e10cSrcweir template <> 96*cdf0e10cSrcweir class TrueColorPixelPtr<BMP_FORMAT_24BIT_TC_BGR> : public BasePixelPtr 97*cdf0e10cSrcweir { 98*cdf0e10cSrcweir public: 99*cdf0e10cSrcweir void operator++() { mpPixel += 3; } 100*cdf0e10cSrcweir 101*cdf0e10cSrcweir PIXBYTE GetRed() const { return mpPixel[2]; } 102*cdf0e10cSrcweir PIXBYTE GetGreen() const { return mpPixel[1]; } 103*cdf0e10cSrcweir PIXBYTE GetBlue() const { return mpPixel[0]; } 104*cdf0e10cSrcweir PIXBYTE GetAlpha() const { return 0; } 105*cdf0e10cSrcweir void SetAlpha( PIXBYTE ) const {} 106*cdf0e10cSrcweir 107*cdf0e10cSrcweir void SetColor( PIXBYTE r, PIXBYTE g, PIXBYTE b ) const 108*cdf0e10cSrcweir { 109*cdf0e10cSrcweir mpPixel[0] = b; 110*cdf0e10cSrcweir mpPixel[1] = g; 111*cdf0e10cSrcweir mpPixel[2] = r; 112*cdf0e10cSrcweir } 113*cdf0e10cSrcweir }; 114*cdf0e10cSrcweir 115*cdf0e10cSrcweir template <> 116*cdf0e10cSrcweir class TrueColorPixelPtr<BMP_FORMAT_32BIT_TC_ARGB> : public BasePixelPtr 117*cdf0e10cSrcweir { 118*cdf0e10cSrcweir public: 119*cdf0e10cSrcweir void operator++() { mpPixel += 4; } 120*cdf0e10cSrcweir 121*cdf0e10cSrcweir PIXBYTE GetRed() const { return mpPixel[1]; } 122*cdf0e10cSrcweir PIXBYTE GetGreen() const { return mpPixel[2]; } 123*cdf0e10cSrcweir PIXBYTE GetBlue() const { return mpPixel[3]; } 124*cdf0e10cSrcweir PIXBYTE GetAlpha() const { return mpPixel[0]; } 125*cdf0e10cSrcweir void SetAlpha( PIXBYTE a ) const { mpPixel[0] = a; } 126*cdf0e10cSrcweir 127*cdf0e10cSrcweir void SetColor( PIXBYTE r, PIXBYTE g, PIXBYTE b ) const 128*cdf0e10cSrcweir { 129*cdf0e10cSrcweir mpPixel[1] = r; 130*cdf0e10cSrcweir mpPixel[2] = g; 131*cdf0e10cSrcweir mpPixel[3] = b; 132*cdf0e10cSrcweir } 133*cdf0e10cSrcweir }; 134*cdf0e10cSrcweir 135*cdf0e10cSrcweir template <> 136*cdf0e10cSrcweir class TrueColorPixelPtr<BMP_FORMAT_32BIT_TC_ABGR> : public BasePixelPtr 137*cdf0e10cSrcweir { 138*cdf0e10cSrcweir public: 139*cdf0e10cSrcweir void operator++() { mpPixel += 4; } 140*cdf0e10cSrcweir 141*cdf0e10cSrcweir PIXBYTE GetRed() const { return mpPixel[3]; } 142*cdf0e10cSrcweir PIXBYTE GetGreen() const { return mpPixel[2]; } 143*cdf0e10cSrcweir PIXBYTE GetBlue() const { return mpPixel[1]; } 144*cdf0e10cSrcweir PIXBYTE GetAlpha() const { return mpPixel[0]; } 145*cdf0e10cSrcweir void SetAlpha( PIXBYTE a ) const { mpPixel[0] = a; } 146*cdf0e10cSrcweir 147*cdf0e10cSrcweir void SetColor( PIXBYTE r, PIXBYTE g, PIXBYTE b ) const 148*cdf0e10cSrcweir { 149*cdf0e10cSrcweir mpPixel[1] = b; 150*cdf0e10cSrcweir mpPixel[2] = g; 151*cdf0e10cSrcweir mpPixel[3] = r; 152*cdf0e10cSrcweir } 153*cdf0e10cSrcweir }; 154*cdf0e10cSrcweir 155*cdf0e10cSrcweir template <> 156*cdf0e10cSrcweir class TrueColorPixelPtr<BMP_FORMAT_32BIT_TC_RGBA> : public BasePixelPtr 157*cdf0e10cSrcweir { 158*cdf0e10cSrcweir public: 159*cdf0e10cSrcweir void operator++() { mpPixel += 4; } 160*cdf0e10cSrcweir 161*cdf0e10cSrcweir PIXBYTE GetRed() const { return mpPixel[0]; } 162*cdf0e10cSrcweir PIXBYTE GetGreen() const { return mpPixel[1]; } 163*cdf0e10cSrcweir PIXBYTE GetBlue() const { return mpPixel[2]; } 164*cdf0e10cSrcweir PIXBYTE GetAlpha() const { return mpPixel[3]; } 165*cdf0e10cSrcweir void SetAlpha( PIXBYTE a ) const{ mpPixel[3] = a; } 166*cdf0e10cSrcweir 167*cdf0e10cSrcweir void SetColor( PIXBYTE r, PIXBYTE g, PIXBYTE b ) const 168*cdf0e10cSrcweir { 169*cdf0e10cSrcweir mpPixel[0] = r; 170*cdf0e10cSrcweir mpPixel[1] = g; 171*cdf0e10cSrcweir mpPixel[2] = b; 172*cdf0e10cSrcweir } 173*cdf0e10cSrcweir }; 174*cdf0e10cSrcweir 175*cdf0e10cSrcweir template <> 176*cdf0e10cSrcweir class TrueColorPixelPtr<BMP_FORMAT_32BIT_TC_BGRA> : public BasePixelPtr 177*cdf0e10cSrcweir { 178*cdf0e10cSrcweir public: 179*cdf0e10cSrcweir void operator++() { mpPixel += 4; } 180*cdf0e10cSrcweir 181*cdf0e10cSrcweir PIXBYTE GetRed() const { return mpPixel[2]; } 182*cdf0e10cSrcweir PIXBYTE GetGreen() const { return mpPixel[1]; } 183*cdf0e10cSrcweir PIXBYTE GetBlue() const { return mpPixel[0]; } 184*cdf0e10cSrcweir PIXBYTE GetAlpha() const { return mpPixel[3]; } 185*cdf0e10cSrcweir void SetAlpha( PIXBYTE a ) const{ mpPixel[3] = a; } 186*cdf0e10cSrcweir 187*cdf0e10cSrcweir void SetColor( PIXBYTE r, PIXBYTE g, PIXBYTE b ) const 188*cdf0e10cSrcweir { 189*cdf0e10cSrcweir mpPixel[0] = b; 190*cdf0e10cSrcweir mpPixel[1] = g; 191*cdf0e10cSrcweir mpPixel[2] = r; 192*cdf0e10cSrcweir } 193*cdf0e10cSrcweir }; 194*cdf0e10cSrcweir 195*cdf0e10cSrcweir template <> 196*cdf0e10cSrcweir class TrueColorPixelPtr<BMP_FORMAT_16BIT_TC_MSB_MASK> : public BasePixelPtr 197*cdf0e10cSrcweir { 198*cdf0e10cSrcweir public: 199*cdf0e10cSrcweir void operator++() { mpPixel += 2; } 200*cdf0e10cSrcweir 201*cdf0e10cSrcweir // TODO: non565-RGB 202*cdf0e10cSrcweir PIXBYTE GetRed() const { return (mpPixel[0] & 0xF8U); } 203*cdf0e10cSrcweir PIXBYTE GetGreen() const { return (mpPixel[0]<<5U) | ((mpPixel[1]>>3U)&28U); } 204*cdf0e10cSrcweir PIXBYTE GetBlue() const { return (mpPixel[1]<<3U); } 205*cdf0e10cSrcweir PIXBYTE GetAlpha() const { return 0; } 206*cdf0e10cSrcweir void SetAlpha( PIXBYTE ) const {} 207*cdf0e10cSrcweir 208*cdf0e10cSrcweir void SetColor( PIXBYTE r, PIXBYTE g, PIXBYTE b ) const 209*cdf0e10cSrcweir { 210*cdf0e10cSrcweir mpPixel[0] = ((g >> 5U) & 7U) | (r & 0xF8U); 211*cdf0e10cSrcweir mpPixel[1] = ((g & 28U)<< 3U) | (b >> 3U); 212*cdf0e10cSrcweir } 213*cdf0e10cSrcweir }; 214*cdf0e10cSrcweir 215*cdf0e10cSrcweir template <> 216*cdf0e10cSrcweir class TrueColorPixelPtr<BMP_FORMAT_16BIT_TC_LSB_MASK> : public BasePixelPtr 217*cdf0e10cSrcweir { 218*cdf0e10cSrcweir public: 219*cdf0e10cSrcweir void operator++() { mpPixel += 2; } 220*cdf0e10cSrcweir 221*cdf0e10cSrcweir // TODO: non565-RGB 222*cdf0e10cSrcweir PIXBYTE GetRed() const { return (mpPixel[1] & 0xF8U); } 223*cdf0e10cSrcweir PIXBYTE GetGreen() const { return (mpPixel[1]<<5U) | ((mpPixel[0]>>3U)&28U); } 224*cdf0e10cSrcweir PIXBYTE GetBlue() const { return (mpPixel[0]<<3U); } 225*cdf0e10cSrcweir PIXBYTE GetAlpha() const { return 0; } 226*cdf0e10cSrcweir void SetAlpha( PIXBYTE ) const {} 227*cdf0e10cSrcweir 228*cdf0e10cSrcweir void SetColor( PIXBYTE r, PIXBYTE g, PIXBYTE b ) const 229*cdf0e10cSrcweir { 230*cdf0e10cSrcweir mpPixel[0] = ((g & 28U)<< 3U) | (b >> 3U); 231*cdf0e10cSrcweir mpPixel[1] = ((g >> 5U) & 7U) | (r & 0xF8U); 232*cdf0e10cSrcweir } 233*cdf0e10cSrcweir }; 234*cdf0e10cSrcweir 235*cdf0e10cSrcweir // ----------------------------------------------------------------------- 236*cdf0e10cSrcweir 237*cdf0e10cSrcweir template <> 238*cdf0e10cSrcweir class TrueColorPixelPtr<BMP_FORMAT_8BIT_TC_MASK> : public BasePixelPtr 239*cdf0e10cSrcweir { 240*cdf0e10cSrcweir public: 241*cdf0e10cSrcweir void operator++() { mpPixel += 1; } 242*cdf0e10cSrcweir PIXBYTE GetAlpha() const { return mpPixel[0]; } 243*cdf0e10cSrcweir void SetAlpha( PIXBYTE a ) const { mpPixel[0] = a; } 244*cdf0e10cSrcweir void SetColor( PIXBYTE, PIXBYTE, PIXBYTE ) const {} 245*cdf0e10cSrcweir }; 246*cdf0e10cSrcweir 247*cdf0e10cSrcweir // TODO: for some reason many Alpha maps are BMP_FORMAT_8BIT_PAL 248*cdf0e10cSrcweir // they should be BMP_FORMAT_8BIT_TC_MASK 249*cdf0e10cSrcweir template <> 250*cdf0e10cSrcweir class TrueColorPixelPtr<BMP_FORMAT_8BIT_PAL> 251*cdf0e10cSrcweir : public TrueColorPixelPtr<BMP_FORMAT_8BIT_TC_MASK> 252*cdf0e10cSrcweir {}; 253*cdf0e10cSrcweir 254*cdf0e10cSrcweir #if 0 255*cdf0e10cSrcweir template <> 256*cdf0e10cSrcweir class TrueColorPixelPtr<BMP_FORMAT_24BIT_TC_MASK> : public BasePixelPtr 257*cdf0e10cSrcweir { 258*cdf0e10cSrcweir public: 259*cdf0e10cSrcweir void operator++() { mpPixel += 3; } 260*cdf0e10cSrcweir 261*cdf0e10cSrcweir unsigned GetAlpha() const 262*cdf0e10cSrcweir { 263*cdf0e10cSrcweir unsigned nAlpha = mpPixel[0]; 264*cdf0e10cSrcweir nAlpha |= mpPixel[1] << 8U; 265*cdf0e10cSrcweir nAlpha |= mpPixel[2] << 16U; 266*cdf0e10cSrcweir return nAlpha; 267*cdf0e10cSrcweir } 268*cdf0e10cSrcweir 269*cdf0e10cSrcweir void SetAlpha( unsigned nAlpha ) const 270*cdf0e10cSrcweir { 271*cdf0e10cSrcweir mpPixel[0] = nAlpha; 272*cdf0e10cSrcweir mpPixel[1] = nAlpha >> 8U; 273*cdf0e10cSrcweir mpPixel[2] = nAlpha >> 16U; 274*cdf0e10cSrcweir } 275*cdf0e10cSrcweir }; 276*cdf0e10cSrcweir 277*cdf0e10cSrcweir template <> 278*cdf0e10cSrcweir class TrueColorPixelPtr<BMP_FORMAT_32BIT_TC_MASK> : public BasePixelPtr 279*cdf0e10cSrcweir { 280*cdf0e10cSrcweir public: 281*cdf0e10cSrcweir void operator++() { mpPixel += 4; } 282*cdf0e10cSrcweir 283*cdf0e10cSrcweir unsigned GetAlpha() const 284*cdf0e10cSrcweir { 285*cdf0e10cSrcweir #ifdef OSL_BIGENDIAN 286*cdf0e10cSrcweir unsigned nAlpha = *reinterpret_cast<unsigned*>( mpPixel ); 287*cdf0e10cSrcweir #else 288*cdf0e10cSrcweir unsigned nAlpha = mpPixel[0]; 289*cdf0e10cSrcweir nAlpha |= mpPixel[1] << 8U; 290*cdf0e10cSrcweir nAlpha |= mpPixel[2] << 16U; 291*cdf0e10cSrcweir nAlpha |= mpPixel[3] << 24U; 292*cdf0e10cSrcweir #endif 293*cdf0e10cSrcweir return nAlpha; 294*cdf0e10cSrcweir } 295*cdf0e10cSrcweir 296*cdf0e10cSrcweir void SetAlpha( unsigned nAlpha ) const 297*cdf0e10cSrcweir { 298*cdf0e10cSrcweir #ifdef OSL_BIGENDIAN 299*cdf0e10cSrcweir *reinterpret_cast<unsigned*>( mpPixel ) = nAlpha; 300*cdf0e10cSrcweir #else 301*cdf0e10cSrcweir mpPixel[0] = nAlpha; 302*cdf0e10cSrcweir mpPixel[1] = nAlpha >> 8U; 303*cdf0e10cSrcweir mpPixel[2] = nAlpha >> 16U; 304*cdf0e10cSrcweir mpPixel[3] = nAlpha >> 24U; 305*cdf0e10cSrcweir #endif 306*cdf0e10cSrcweir } 307*cdf0e10cSrcweir }; 308*cdf0e10cSrcweir 309*cdf0e10cSrcweir #endif 310*cdf0e10cSrcweir 311*cdf0e10cSrcweir // ======================================================================= 312*cdf0e10cSrcweir // converting truecolor formats 313*cdf0e10cSrcweir 314*cdf0e10cSrcweir template <sal_uLong SRCFMT, sal_uLong DSTFMT> 315*cdf0e10cSrcweir inline void ImplConvertPixel( const TrueColorPixelPtr<DSTFMT>& rDst, 316*cdf0e10cSrcweir const TrueColorPixelPtr<SRCFMT>& rSrc ) 317*cdf0e10cSrcweir { 318*cdf0e10cSrcweir rDst.SetColor( rSrc.GetRed(), rSrc.GetGreen(), rSrc.GetBlue() ); 319*cdf0e10cSrcweir rDst.SetAlpha( rSrc.GetAlpha() ); 320*cdf0e10cSrcweir } 321*cdf0e10cSrcweir 322*cdf0e10cSrcweir // ----------------------------------------------------------------------- 323*cdf0e10cSrcweir 324*cdf0e10cSrcweir template <> 325*cdf0e10cSrcweir inline void ImplConvertPixel<BMP_FORMAT_16BIT_TC_LSB_MASK, BMP_FORMAT_16BIT_TC_MSB_MASK> ( 326*cdf0e10cSrcweir const TrueColorPixelPtr<BMP_FORMAT_16BIT_TC_MSB_MASK>& rDst, 327*cdf0e10cSrcweir const TrueColorPixelPtr<BMP_FORMAT_16BIT_TC_LSB_MASK>& rSrc ) 328*cdf0e10cSrcweir { 329*cdf0e10cSrcweir // byte swapping 330*cdf0e10cSrcweir const PIXBYTE* pSrc = rSrc.GetRawPtr(); 331*cdf0e10cSrcweir PIXBYTE* pDst = rDst.GetRawPtr(); 332*cdf0e10cSrcweir pDst[1] = pSrc[0]; 333*cdf0e10cSrcweir pDst[0] = pSrc[1]; 334*cdf0e10cSrcweir } 335*cdf0e10cSrcweir 336*cdf0e10cSrcweir // ----------------------------------------------------------------------- 337*cdf0e10cSrcweir 338*cdf0e10cSrcweir template <sal_uLong SRCFMT, sal_uLong DSTFMT> 339*cdf0e10cSrcweir inline void ImplConvertLine( const TrueColorPixelPtr<DSTFMT>& rDst, 340*cdf0e10cSrcweir const TrueColorPixelPtr<SRCFMT>& rSrc, int nPixelCount ) 341*cdf0e10cSrcweir { 342*cdf0e10cSrcweir TrueColorPixelPtr<DSTFMT> aDst( rDst ); 343*cdf0e10cSrcweir TrueColorPixelPtr<SRCFMT> aSrc( rSrc ); 344*cdf0e10cSrcweir while( --nPixelCount >= 0 ) 345*cdf0e10cSrcweir { 346*cdf0e10cSrcweir ImplConvertPixel( aDst, aSrc ); 347*cdf0e10cSrcweir ++aSrc; 348*cdf0e10cSrcweir ++aDst; 349*cdf0e10cSrcweir } 350*cdf0e10cSrcweir } 351*cdf0e10cSrcweir 352*cdf0e10cSrcweir // ======================================================================= 353*cdf0e10cSrcweir // alpha blending truecolor pixels 354*cdf0e10cSrcweir 355*cdf0e10cSrcweir template <unsigned ALPHABITS, sal_uLong SRCFMT, sal_uLong DSTFMT> 356*cdf0e10cSrcweir inline void ImplBlendPixels( const TrueColorPixelPtr<DSTFMT>& rDst, 357*cdf0e10cSrcweir const TrueColorPixelPtr<SRCFMT>& rSrc, unsigned nAlphaVal ) 358*cdf0e10cSrcweir { 359*cdf0e10cSrcweir if( !nAlphaVal ) 360*cdf0e10cSrcweir ImplConvertPixel( rDst, rSrc ); 361*cdf0e10cSrcweir else if( nAlphaVal != ~(~0 << ALPHABITS) ) 362*cdf0e10cSrcweir { 363*cdf0e10cSrcweir static const unsigned nAlphaShift = (ALPHABITS > 8) ? 8 : ALPHABITS; 364*cdf0e10cSrcweir if( ALPHABITS > nAlphaShift ) 365*cdf0e10cSrcweir nAlphaVal >>= ALPHABITS - nAlphaShift; 366*cdf0e10cSrcweir 367*cdf0e10cSrcweir int nR = rDst.GetRed(); 368*cdf0e10cSrcweir int nS = rSrc.GetRed(); 369*cdf0e10cSrcweir nR = nS + (((nR - nS) * nAlphaVal) >> nAlphaShift); 370*cdf0e10cSrcweir 371*cdf0e10cSrcweir int nG = rDst.GetGreen(); 372*cdf0e10cSrcweir nS = rSrc.GetGreen(); 373*cdf0e10cSrcweir nG = nS + (((nG - nS) * nAlphaVal) >> nAlphaShift); 374*cdf0e10cSrcweir 375*cdf0e10cSrcweir int nB = rDst.GetBlue(); 376*cdf0e10cSrcweir nS = rSrc.GetBlue(); 377*cdf0e10cSrcweir nB = nS + (((nB - nS) * nAlphaVal) >> nAlphaShift); 378*cdf0e10cSrcweir 379*cdf0e10cSrcweir rDst.SetColor( sal::static_int_cast<PIXBYTE>(nR), 380*cdf0e10cSrcweir sal::static_int_cast<PIXBYTE>(nG), 381*cdf0e10cSrcweir sal::static_int_cast<PIXBYTE>(nB) ); 382*cdf0e10cSrcweir } 383*cdf0e10cSrcweir } 384*cdf0e10cSrcweir 385*cdf0e10cSrcweir // ----------------------------------------------------------------------- 386*cdf0e10cSrcweir 387*cdf0e10cSrcweir template <unsigned ALPHABITS, sal_uLong MASKFMT, sal_uLong SRCFMT, sal_uLong DSTFMT> 388*cdf0e10cSrcweir inline void ImplBlendLines( const TrueColorPixelPtr<DSTFMT>& rDst, 389*cdf0e10cSrcweir const TrueColorPixelPtr<SRCFMT>& rSrc, const TrueColorPixelPtr<MASKFMT>& rMsk, 390*cdf0e10cSrcweir int nPixelCount ) 391*cdf0e10cSrcweir { 392*cdf0e10cSrcweir TrueColorPixelPtr<MASKFMT> aMsk( rMsk ); 393*cdf0e10cSrcweir TrueColorPixelPtr<DSTFMT> aDst( rDst ); 394*cdf0e10cSrcweir TrueColorPixelPtr<SRCFMT> aSrc( rSrc ); 395*cdf0e10cSrcweir while( --nPixelCount >= 0 ) 396*cdf0e10cSrcweir { 397*cdf0e10cSrcweir ImplBlendPixels<ALPHABITS>( aDst, aSrc, aMsk.GetAlpha() ); 398*cdf0e10cSrcweir ++aDst; 399*cdf0e10cSrcweir ++aSrc; 400*cdf0e10cSrcweir ++aMsk; 401*cdf0e10cSrcweir } 402*cdf0e10cSrcweir } 403*cdf0e10cSrcweir 404*cdf0e10cSrcweir // ----------------------------------------------------------------------- 405*cdf0e10cSrcweir 406*cdf0e10cSrcweir template <unsigned ALPHABITS, sal_uLong SRCFMT, sal_uLong DSTFMT> 407*cdf0e10cSrcweir inline void ImplBlendLines( const TrueColorPixelPtr<DSTFMT>& rDst, 408*cdf0e10cSrcweir const TrueColorPixelPtr<SRCFMT>& rSrc, unsigned nAlphaVal, 409*cdf0e10cSrcweir int nPixelCount ) 410*cdf0e10cSrcweir { 411*cdf0e10cSrcweir if( nAlphaVal == ~(~0 << ALPHABITS) ) 412*cdf0e10cSrcweir ImplConvertLine( rDst, rSrc, nPixelCount ); 413*cdf0e10cSrcweir else if( nAlphaVal ) 414*cdf0e10cSrcweir { 415*cdf0e10cSrcweir TrueColorPixelPtr<SRCFMT> aSrc( rSrc ); 416*cdf0e10cSrcweir TrueColorPixelPtr<DSTFMT> aDst( rDst ); 417*cdf0e10cSrcweir while( --nPixelCount >= 0 ) 418*cdf0e10cSrcweir { 419*cdf0e10cSrcweir ImplBlendPixels<ALPHABITS>( aDst, aSrc, nAlphaVal ); 420*cdf0e10cSrcweir ++aDst; 421*cdf0e10cSrcweir ++aSrc; 422*cdf0e10cSrcweir } 423*cdf0e10cSrcweir } 424*cdf0e10cSrcweir } 425*cdf0e10cSrcweir 426*cdf0e10cSrcweir // ======================================================================= 427*cdf0e10cSrcweir 428*cdf0e10cSrcweir static bool ImplCopyImage( BitmapBuffer& rDstBuffer, const BitmapBuffer& rSrcBuffer ) 429*cdf0e10cSrcweir { 430*cdf0e10cSrcweir const int nSrcLinestep = rSrcBuffer.mnScanlineSize; 431*cdf0e10cSrcweir int nDstLinestep = rDstBuffer.mnScanlineSize; 432*cdf0e10cSrcweir 433*cdf0e10cSrcweir const PIXBYTE* pRawSrc = rSrcBuffer.mpBits; 434*cdf0e10cSrcweir PIXBYTE* pRawDst = rDstBuffer.mpBits; 435*cdf0e10cSrcweir 436*cdf0e10cSrcweir // source and destination don't match upside down 437*cdf0e10cSrcweir if( BMP_FORMAT_TOP_DOWN & (rSrcBuffer.mnFormat ^ rDstBuffer.mnFormat) ) 438*cdf0e10cSrcweir { 439*cdf0e10cSrcweir pRawDst += (rSrcBuffer.mnHeight - 1) * nDstLinestep; 440*cdf0e10cSrcweir nDstLinestep = -rDstBuffer.mnScanlineSize; 441*cdf0e10cSrcweir } 442*cdf0e10cSrcweir else if( nSrcLinestep == nDstLinestep ) 443*cdf0e10cSrcweir { 444*cdf0e10cSrcweir memcpy( pRawDst, pRawSrc, rSrcBuffer.mnHeight * nDstLinestep ); 445*cdf0e10cSrcweir return true; 446*cdf0e10cSrcweir } 447*cdf0e10cSrcweir 448*cdf0e10cSrcweir int nByteWidth = nSrcLinestep; 449*cdf0e10cSrcweir if( nByteWidth > rDstBuffer.mnScanlineSize ) 450*cdf0e10cSrcweir nByteWidth = rDstBuffer.mnScanlineSize; 451*cdf0e10cSrcweir 452*cdf0e10cSrcweir for( int y = rSrcBuffer.mnHeight; --y >= 0; ) 453*cdf0e10cSrcweir { 454*cdf0e10cSrcweir memcpy( pRawDst, pRawSrc, nByteWidth ); 455*cdf0e10cSrcweir pRawSrc += nSrcLinestep; 456*cdf0e10cSrcweir pRawDst += nDstLinestep; 457*cdf0e10cSrcweir } 458*cdf0e10cSrcweir 459*cdf0e10cSrcweir return true; 460*cdf0e10cSrcweir } 461*cdf0e10cSrcweir 462*cdf0e10cSrcweir // ----------------------------------------------------------------------- 463*cdf0e10cSrcweir 464*cdf0e10cSrcweir template <sal_uLong DSTFMT,sal_uLong SRCFMT> 465*cdf0e10cSrcweir bool ImplConvertToBitmap( TrueColorPixelPtr<SRCFMT>& rSrcLine, 466*cdf0e10cSrcweir BitmapBuffer& rDstBuffer, const BitmapBuffer& rSrcBuffer ) 467*cdf0e10cSrcweir { 468*cdf0e10cSrcweir // help the compiler to avoid instantiations of unneeded conversions 469*cdf0e10cSrcweir DBG_ASSERT( SRCFMT != DSTFMT, "ImplConvertToBitmap into same format"); 470*cdf0e10cSrcweir if( SRCFMT == DSTFMT ) 471*cdf0e10cSrcweir return false; 472*cdf0e10cSrcweir 473*cdf0e10cSrcweir const int nSrcLinestep = rSrcBuffer.mnScanlineSize; 474*cdf0e10cSrcweir int nDstLinestep = rDstBuffer.mnScanlineSize; 475*cdf0e10cSrcweir 476*cdf0e10cSrcweir TrueColorPixelPtr<DSTFMT> aDstLine; aDstLine.SetRawPtr( rDstBuffer.mpBits ); 477*cdf0e10cSrcweir 478*cdf0e10cSrcweir // source and destination don't match upside down 479*cdf0e10cSrcweir if( BMP_FORMAT_TOP_DOWN & (rSrcBuffer.mnFormat ^ rDstBuffer.mnFormat) ) 480*cdf0e10cSrcweir { 481*cdf0e10cSrcweir aDstLine.AddByteOffset( (rSrcBuffer.mnHeight - 1) * nDstLinestep ); 482*cdf0e10cSrcweir nDstLinestep = -nDstLinestep; 483*cdf0e10cSrcweir } 484*cdf0e10cSrcweir 485*cdf0e10cSrcweir for( int y = rSrcBuffer.mnHeight; --y >= 0; ) 486*cdf0e10cSrcweir { 487*cdf0e10cSrcweir ImplConvertLine( aDstLine, rSrcLine, rSrcBuffer.mnWidth ); 488*cdf0e10cSrcweir rSrcLine.AddByteOffset( nSrcLinestep ); 489*cdf0e10cSrcweir aDstLine.AddByteOffset( nDstLinestep ); 490*cdf0e10cSrcweir } 491*cdf0e10cSrcweir 492*cdf0e10cSrcweir return true; 493*cdf0e10cSrcweir } 494*cdf0e10cSrcweir 495*cdf0e10cSrcweir // ----------------------------------------------------------------------- 496*cdf0e10cSrcweir 497*cdf0e10cSrcweir template <sal_uLong SRCFMT> 498*cdf0e10cSrcweir inline bool ImplConvertFromBitmap( BitmapBuffer& rDst, const BitmapBuffer& rSrc ) 499*cdf0e10cSrcweir { 500*cdf0e10cSrcweir TrueColorPixelPtr<SRCFMT> aSrcType; aSrcType.SetRawPtr( rSrc.mpBits ); 501*cdf0e10cSrcweir 502*cdf0e10cSrcweir // select the matching instantiation for the destination's bitmap format 503*cdf0e10cSrcweir switch( rDst.mnFormat & ~BMP_FORMAT_TOP_DOWN ) 504*cdf0e10cSrcweir { 505*cdf0e10cSrcweir case BMP_FORMAT_1BIT_MSB_PAL: 506*cdf0e10cSrcweir case BMP_FORMAT_1BIT_LSB_PAL: 507*cdf0e10cSrcweir case BMP_FORMAT_4BIT_MSN_PAL: 508*cdf0e10cSrcweir case BMP_FORMAT_4BIT_LSN_PAL: 509*cdf0e10cSrcweir case BMP_FORMAT_8BIT_PAL: 510*cdf0e10cSrcweir break; 511*cdf0e10cSrcweir 512*cdf0e10cSrcweir case BMP_FORMAT_8BIT_TC_MASK: 513*cdf0e10cSrcweir // return ImplConvertToBitmap<BMP_FORMAT_8BIT_TC_MASK>( aSrcType, rDst, rSrc ); 514*cdf0e10cSrcweir case BMP_FORMAT_24BIT_TC_MASK: 515*cdf0e10cSrcweir // return ImplConvertToBitmap<BMP_FORMAT_24BIT_TC_MASK>( aSrcType, rDst, rSrc ); 516*cdf0e10cSrcweir case BMP_FORMAT_32BIT_TC_MASK: 517*cdf0e10cSrcweir // return ImplConvertToBitmap<BMP_FORMAT_32BIT_TC_MASK>( aSrcType, rDst, rSrc ); 518*cdf0e10cSrcweir break; 519*cdf0e10cSrcweir 520*cdf0e10cSrcweir case BMP_FORMAT_16BIT_TC_MSB_MASK: 521*cdf0e10cSrcweir return ImplConvertToBitmap<BMP_FORMAT_16BIT_TC_MSB_MASK>( aSrcType, rDst, rSrc ); 522*cdf0e10cSrcweir case BMP_FORMAT_16BIT_TC_LSB_MASK: 523*cdf0e10cSrcweir return ImplConvertToBitmap<BMP_FORMAT_16BIT_TC_LSB_MASK>( aSrcType, rDst, rSrc ); 524*cdf0e10cSrcweir 525*cdf0e10cSrcweir case BMP_FORMAT_24BIT_TC_BGR: 526*cdf0e10cSrcweir return ImplConvertToBitmap<BMP_FORMAT_24BIT_TC_BGR>( aSrcType, rDst, rSrc ); 527*cdf0e10cSrcweir case BMP_FORMAT_24BIT_TC_RGB: 528*cdf0e10cSrcweir return ImplConvertToBitmap<BMP_FORMAT_24BIT_TC_RGB>( aSrcType, rDst, rSrc ); 529*cdf0e10cSrcweir 530*cdf0e10cSrcweir case BMP_FORMAT_32BIT_TC_ABGR: 531*cdf0e10cSrcweir return ImplConvertToBitmap<BMP_FORMAT_32BIT_TC_ABGR>( aSrcType, rDst, rSrc ); 532*cdf0e10cSrcweir #ifdef FAST_ARGB_BGRA 533*cdf0e10cSrcweir case BMP_FORMAT_32BIT_TC_ARGB: 534*cdf0e10cSrcweir return ImplConvertToBitmap<BMP_FORMAT_32BIT_TC_ARGB>( aSrcType, rDst, rSrc ); 535*cdf0e10cSrcweir case BMP_FORMAT_32BIT_TC_BGRA: 536*cdf0e10cSrcweir return ImplConvertToBitmap<BMP_FORMAT_32BIT_TC_BGRA>( aSrcType, rDst, rSrc ); 537*cdf0e10cSrcweir #endif 538*cdf0e10cSrcweir case BMP_FORMAT_32BIT_TC_RGBA: 539*cdf0e10cSrcweir return ImplConvertToBitmap<BMP_FORMAT_32BIT_TC_RGBA>( aSrcType, rDst, rSrc ); 540*cdf0e10cSrcweir } 541*cdf0e10cSrcweir 542*cdf0e10cSrcweir #ifdef DEBUG 543*cdf0e10cSrcweir static int nNotAccelerated = 0; 544*cdf0e10cSrcweir if( rSrc.mnWidth * rSrc.mnHeight >= 4000 ) 545*cdf0e10cSrcweir if( ++nNotAccelerated == 100 ) 546*cdf0e10cSrcweir { 547*cdf0e10cSrcweir int foo = 0; (void)foo; // so no warning is created when building on pro with debug 548*cdf0e10cSrcweir DBG_WARNING2( "ImplConvertFromBitmap for not accelerated case (0x%04X->0x%04X)", 549*cdf0e10cSrcweir rSrc.mnFormat, rDst.mnFormat ); 550*cdf0e10cSrcweir } 551*cdf0e10cSrcweir #endif 552*cdf0e10cSrcweir 553*cdf0e10cSrcweir return false; 554*cdf0e10cSrcweir } 555*cdf0e10cSrcweir 556*cdf0e10cSrcweir // ======================================================================= 557*cdf0e10cSrcweir 558*cdf0e10cSrcweir // an universal stretching conversion is overkill in most common situations 559*cdf0e10cSrcweir // => performance benefits for speeding up the non-stretching cases 560*cdf0e10cSrcweir bool ImplFastBitmapConversion( BitmapBuffer& rDst, const BitmapBuffer& rSrc, 561*cdf0e10cSrcweir const SalTwoRect& rTR ) 562*cdf0e10cSrcweir { 563*cdf0e10cSrcweir if( bDisableFastBitops ) 564*cdf0e10cSrcweir return false; 565*cdf0e10cSrcweir 566*cdf0e10cSrcweir // horizontal mirroring not implemented yet 567*cdf0e10cSrcweir if( rTR.mnDestWidth < 0 ) 568*cdf0e10cSrcweir return false; 569*cdf0e10cSrcweir // vertical mirroring 570*cdf0e10cSrcweir if( rTR.mnDestHeight < 0 ) 571*cdf0e10cSrcweir // TODO: rDst.mnFormat ^= BMP_FORMAT_TOP_DOWN; 572*cdf0e10cSrcweir return false; 573*cdf0e10cSrcweir 574*cdf0e10cSrcweir // offseted conversion is not implemented yet 575*cdf0e10cSrcweir if( rTR.mnSrcX || rTR.mnSrcY ) 576*cdf0e10cSrcweir return false; 577*cdf0e10cSrcweir if( rTR.mnDestX || rTR.mnDestY ) 578*cdf0e10cSrcweir return false; 579*cdf0e10cSrcweir 580*cdf0e10cSrcweir // stretched conversion is not implemented yet 581*cdf0e10cSrcweir if( rTR.mnDestWidth != rTR.mnSrcWidth ) 582*cdf0e10cSrcweir return false; 583*cdf0e10cSrcweir if( rTR.mnDestHeight!= rTR.mnSrcHeight ) 584*cdf0e10cSrcweir return false; 585*cdf0e10cSrcweir 586*cdf0e10cSrcweir // check source image size 587*cdf0e10cSrcweir if( rSrc.mnWidth < rTR.mnSrcX + rTR.mnSrcWidth ) 588*cdf0e10cSrcweir return false; 589*cdf0e10cSrcweir if( rSrc.mnHeight < rTR.mnSrcY + rTR.mnSrcHeight ) 590*cdf0e10cSrcweir return false; 591*cdf0e10cSrcweir 592*cdf0e10cSrcweir // check dest image size 593*cdf0e10cSrcweir if( rDst.mnWidth < rTR.mnDestX + rTR.mnDestWidth ) 594*cdf0e10cSrcweir return false; 595*cdf0e10cSrcweir if( rDst.mnHeight < rTR.mnDestY + rTR.mnDestHeight ) 596*cdf0e10cSrcweir return false; 597*cdf0e10cSrcweir 598*cdf0e10cSrcweir const sal_uLong nSrcFormat = rSrc.mnFormat & ~BMP_FORMAT_TOP_DOWN; 599*cdf0e10cSrcweir const sal_uLong nDstFormat = rDst.mnFormat & ~BMP_FORMAT_TOP_DOWN; 600*cdf0e10cSrcweir 601*cdf0e10cSrcweir // TODO: also implement conversions for 16bit colormasks with non-565 format 602*cdf0e10cSrcweir if( nSrcFormat & (BMP_FORMAT_16BIT_TC_LSB_MASK | BMP_FORMAT_16BIT_TC_MSB_MASK) ) 603*cdf0e10cSrcweir if( rSrc.maColorMask.GetRedMask() != 0xF800 604*cdf0e10cSrcweir || rSrc.maColorMask.GetGreenMask()!= 0x07E0 605*cdf0e10cSrcweir || rSrc.maColorMask.GetBlueMask() != 0x001F ) 606*cdf0e10cSrcweir return false; 607*cdf0e10cSrcweir if( nDstFormat & (BMP_FORMAT_16BIT_TC_LSB_MASK | BMP_FORMAT_16BIT_TC_MSB_MASK) ) 608*cdf0e10cSrcweir if( rDst.maColorMask.GetRedMask() != 0xF800 609*cdf0e10cSrcweir || rDst.maColorMask.GetGreenMask()!= 0x07E0 610*cdf0e10cSrcweir || rDst.maColorMask.GetBlueMask() != 0x001F ) 611*cdf0e10cSrcweir return false; 612*cdf0e10cSrcweir 613*cdf0e10cSrcweir // special handling of trivial cases 614*cdf0e10cSrcweir if( nSrcFormat == nDstFormat ) 615*cdf0e10cSrcweir { 616*cdf0e10cSrcweir // accelerated palette conversions not yet implemented 617*cdf0e10cSrcweir if( rSrc.maPalette != rDst.maPalette ) 618*cdf0e10cSrcweir return false; 619*cdf0e10cSrcweir return ImplCopyImage( rDst, rSrc ); 620*cdf0e10cSrcweir } 621*cdf0e10cSrcweir 622*cdf0e10cSrcweir // select the matching instantiation for the source's bitmap format 623*cdf0e10cSrcweir switch( nSrcFormat ) 624*cdf0e10cSrcweir { 625*cdf0e10cSrcweir case BMP_FORMAT_1BIT_MSB_PAL: 626*cdf0e10cSrcweir case BMP_FORMAT_1BIT_LSB_PAL: 627*cdf0e10cSrcweir case BMP_FORMAT_4BIT_MSN_PAL: 628*cdf0e10cSrcweir case BMP_FORMAT_4BIT_LSN_PAL: 629*cdf0e10cSrcweir case BMP_FORMAT_8BIT_PAL: 630*cdf0e10cSrcweir break; 631*cdf0e10cSrcweir 632*cdf0e10cSrcweir case BMP_FORMAT_8BIT_TC_MASK: 633*cdf0e10cSrcweir // return ImplConvertFromBitmap<BMP_FORMAT_8BIT_TC_MASK>( rDst, rSrc ); 634*cdf0e10cSrcweir case BMP_FORMAT_24BIT_TC_MASK: 635*cdf0e10cSrcweir // return ImplConvertFromBitmap<BMP_FORMAT_24BIT_TC_MASK>( rDst, rSrc ); 636*cdf0e10cSrcweir case BMP_FORMAT_32BIT_TC_MASK: 637*cdf0e10cSrcweir // return ImplConvertFromBitmap<BMP_FORMAT_32BIT_TC_MASK>( rDst, rSrc ); 638*cdf0e10cSrcweir break; 639*cdf0e10cSrcweir 640*cdf0e10cSrcweir case BMP_FORMAT_16BIT_TC_MSB_MASK: 641*cdf0e10cSrcweir return ImplConvertFromBitmap<BMP_FORMAT_16BIT_TC_MSB_MASK>( rDst, rSrc ); 642*cdf0e10cSrcweir case BMP_FORMAT_16BIT_TC_LSB_MASK: 643*cdf0e10cSrcweir return ImplConvertFromBitmap<BMP_FORMAT_16BIT_TC_LSB_MASK>( rDst, rSrc ); 644*cdf0e10cSrcweir 645*cdf0e10cSrcweir case BMP_FORMAT_24BIT_TC_BGR: 646*cdf0e10cSrcweir return ImplConvertFromBitmap<BMP_FORMAT_24BIT_TC_BGR>( rDst, rSrc ); 647*cdf0e10cSrcweir case BMP_FORMAT_24BIT_TC_RGB: 648*cdf0e10cSrcweir return ImplConvertFromBitmap<BMP_FORMAT_24BIT_TC_RGB>( rDst, rSrc ); 649*cdf0e10cSrcweir 650*cdf0e10cSrcweir case BMP_FORMAT_32BIT_TC_ABGR: 651*cdf0e10cSrcweir return ImplConvertFromBitmap<BMP_FORMAT_32BIT_TC_ABGR>( rDst, rSrc ); 652*cdf0e10cSrcweir #ifdef FAST_ARGB_BGRA 653*cdf0e10cSrcweir case BMP_FORMAT_32BIT_TC_ARGB: 654*cdf0e10cSrcweir return ImplConvertFromBitmap<BMP_FORMAT_32BIT_TC_ARGB>( rDst, rSrc ); 655*cdf0e10cSrcweir case BMP_FORMAT_32BIT_TC_BGRA: 656*cdf0e10cSrcweir return ImplConvertFromBitmap<BMP_FORMAT_32BIT_TC_BGRA>( rDst, rSrc ); 657*cdf0e10cSrcweir #endif 658*cdf0e10cSrcweir case BMP_FORMAT_32BIT_TC_RGBA: 659*cdf0e10cSrcweir return ImplConvertFromBitmap<BMP_FORMAT_32BIT_TC_RGBA>( rDst, rSrc ); 660*cdf0e10cSrcweir } 661*cdf0e10cSrcweir 662*cdf0e10cSrcweir #ifdef DEBUG 663*cdf0e10cSrcweir static int nNotAccelerated = 0; 664*cdf0e10cSrcweir if( rSrc.mnWidth * rSrc.mnHeight >= 4000 ) 665*cdf0e10cSrcweir { 666*cdf0e10cSrcweir if( ++nNotAccelerated == 100 ) 667*cdf0e10cSrcweir { 668*cdf0e10cSrcweir int foo = 0; (void)foo; // so no warning is created when building on pro with debug 669*cdf0e10cSrcweir DBG_WARNING2( "ImplFastBitmapConversion for not accelerated case (0x%04X->0x%04X)", rSrc.mnFormat, rDst.mnFormat ); 670*cdf0e10cSrcweir } 671*cdf0e10cSrcweir } 672*cdf0e10cSrcweir #endif 673*cdf0e10cSrcweir 674*cdf0e10cSrcweir return false; 675*cdf0e10cSrcweir } 676*cdf0e10cSrcweir 677*cdf0e10cSrcweir // ======================================================================= 678*cdf0e10cSrcweir 679*cdf0e10cSrcweir template <sal_uLong DSTFMT,sal_uLong SRCFMT> //,sal_uLong MSKFMT> 680*cdf0e10cSrcweir bool ImplBlendToBitmap( TrueColorPixelPtr<SRCFMT>& rSrcLine, 681*cdf0e10cSrcweir BitmapBuffer& rDstBuffer, const BitmapBuffer& rSrcBuffer, 682*cdf0e10cSrcweir const BitmapBuffer& rMskBuffer ) 683*cdf0e10cSrcweir { 684*cdf0e10cSrcweir //DBG_ASSERT( rMskBuffer.mnFormat == MSKFMT, "FastBmp BlendImage: wrong MSKFMT" ); 685*cdf0e10cSrcweir DBG_ASSERT( rMskBuffer.mnFormat == BMP_FORMAT_8BIT_PAL, "FastBmp BlendImage: unusual MSKFMT" ); 686*cdf0e10cSrcweir 687*cdf0e10cSrcweir const int nSrcLinestep = rSrcBuffer.mnScanlineSize; 688*cdf0e10cSrcweir int nMskLinestep = rMskBuffer.mnScanlineSize; 689*cdf0e10cSrcweir int nDstLinestep = rDstBuffer.mnScanlineSize; 690*cdf0e10cSrcweir 691*cdf0e10cSrcweir TrueColorPixelPtr<BMP_FORMAT_8BIT_PAL> aMskLine; aMskLine.SetRawPtr( rMskBuffer.mpBits ); 692*cdf0e10cSrcweir TrueColorPixelPtr<DSTFMT> aDstLine; aDstLine.SetRawPtr( rDstBuffer.mpBits ); 693*cdf0e10cSrcweir 694*cdf0e10cSrcweir // special case for single line masks 695*cdf0e10cSrcweir if( rMskBuffer.mnHeight == 1 ) 696*cdf0e10cSrcweir nMskLinestep = 0; 697*cdf0e10cSrcweir 698*cdf0e10cSrcweir // source and mask don't match: upside down 699*cdf0e10cSrcweir if( (rSrcBuffer.mnFormat ^ rMskBuffer.mnFormat) & BMP_FORMAT_TOP_DOWN ) 700*cdf0e10cSrcweir { 701*cdf0e10cSrcweir aMskLine.AddByteOffset( (rSrcBuffer.mnHeight - 1) * nMskLinestep ); 702*cdf0e10cSrcweir nMskLinestep = -nMskLinestep; 703*cdf0e10cSrcweir } 704*cdf0e10cSrcweir 705*cdf0e10cSrcweir // source and destination don't match: upside down 706*cdf0e10cSrcweir if( (rSrcBuffer.mnFormat ^ rDstBuffer.mnFormat) & BMP_FORMAT_TOP_DOWN ) 707*cdf0e10cSrcweir { 708*cdf0e10cSrcweir aDstLine.AddByteOffset( (rSrcBuffer.mnHeight - 1) * nDstLinestep ); 709*cdf0e10cSrcweir nDstLinestep = -nDstLinestep; 710*cdf0e10cSrcweir } 711*cdf0e10cSrcweir 712*cdf0e10cSrcweir for( int y = rSrcBuffer.mnHeight; --y >= 0; ) 713*cdf0e10cSrcweir { 714*cdf0e10cSrcweir ImplBlendLines<8>( aDstLine, rSrcLine, aMskLine, rDstBuffer.mnWidth ); 715*cdf0e10cSrcweir aDstLine.AddByteOffset( nDstLinestep ); 716*cdf0e10cSrcweir rSrcLine.AddByteOffset( nSrcLinestep ); 717*cdf0e10cSrcweir aMskLine.AddByteOffset( nMskLinestep ); 718*cdf0e10cSrcweir } 719*cdf0e10cSrcweir 720*cdf0e10cSrcweir return true; 721*cdf0e10cSrcweir } 722*cdf0e10cSrcweir 723*cdf0e10cSrcweir // some specializations to reduce the code size 724*cdf0e10cSrcweir template <> 725*cdf0e10cSrcweir inline bool ImplBlendToBitmap<BMP_FORMAT_24BIT_TC_BGR,BMP_FORMAT_24BIT_TC_BGR>( 726*cdf0e10cSrcweir TrueColorPixelPtr<BMP_FORMAT_24BIT_TC_BGR>&, 727*cdf0e10cSrcweir BitmapBuffer& rDstBuffer, const BitmapBuffer& rSrcBuffer, 728*cdf0e10cSrcweir const BitmapBuffer& rMskBuffer ) 729*cdf0e10cSrcweir { 730*cdf0e10cSrcweir TrueColorPixelPtr<BMP_FORMAT_24BIT_TC_RGB> aSrcType; aSrcType.SetRawPtr( rSrcBuffer.mpBits ); 731*cdf0e10cSrcweir return ImplBlendToBitmap<BMP_FORMAT_24BIT_TC_RGB>( aSrcType, rDstBuffer, rSrcBuffer, rMskBuffer ); 732*cdf0e10cSrcweir } 733*cdf0e10cSrcweir 734*cdf0e10cSrcweir template <> 735*cdf0e10cSrcweir inline bool ImplBlendToBitmap<BMP_FORMAT_32BIT_TC_ABGR,BMP_FORMAT_32BIT_TC_ABGR>( 736*cdf0e10cSrcweir TrueColorPixelPtr<BMP_FORMAT_32BIT_TC_ABGR>&, 737*cdf0e10cSrcweir BitmapBuffer& rDstBuffer, const BitmapBuffer& rSrcBuffer, 738*cdf0e10cSrcweir const BitmapBuffer& rMskBuffer ) 739*cdf0e10cSrcweir { 740*cdf0e10cSrcweir TrueColorPixelPtr<BMP_FORMAT_32BIT_TC_ARGB> aSrcType; aSrcType.SetRawPtr( rSrcBuffer.mpBits ); 741*cdf0e10cSrcweir return ImplBlendToBitmap<BMP_FORMAT_32BIT_TC_ARGB>( aSrcType, rDstBuffer, rSrcBuffer, rMskBuffer ); 742*cdf0e10cSrcweir } 743*cdf0e10cSrcweir 744*cdf0e10cSrcweir template <> 745*cdf0e10cSrcweir inline bool ImplBlendToBitmap<BMP_FORMAT_32BIT_TC_BGRA,BMP_FORMAT_32BIT_TC_BGRA>( 746*cdf0e10cSrcweir TrueColorPixelPtr<BMP_FORMAT_32BIT_TC_BGRA>&, 747*cdf0e10cSrcweir BitmapBuffer& rDstBuffer, const BitmapBuffer& rSrcBuffer, 748*cdf0e10cSrcweir const BitmapBuffer& rMskBuffer ) 749*cdf0e10cSrcweir { 750*cdf0e10cSrcweir TrueColorPixelPtr<BMP_FORMAT_32BIT_TC_RGBA> aSrcType; aSrcType.SetRawPtr( rSrcBuffer.mpBits ); 751*cdf0e10cSrcweir return ImplBlendToBitmap<BMP_FORMAT_32BIT_TC_RGBA>( aSrcType, rDstBuffer, rSrcBuffer, rMskBuffer ); 752*cdf0e10cSrcweir } 753*cdf0e10cSrcweir 754*cdf0e10cSrcweir // ----------------------------------------------------------------------- 755*cdf0e10cSrcweir 756*cdf0e10cSrcweir template <sal_uLong SRCFMT> 757*cdf0e10cSrcweir bool ImplBlendFromBitmap( BitmapBuffer& rDst, const BitmapBuffer& rSrc, const BitmapBuffer& rMsk ) 758*cdf0e10cSrcweir { 759*cdf0e10cSrcweir TrueColorPixelPtr<SRCFMT> aSrcType; aSrcType.SetRawPtr( rSrc.mpBits ); 760*cdf0e10cSrcweir 761*cdf0e10cSrcweir // select the matching instantiation for the destination's bitmap format 762*cdf0e10cSrcweir switch( rDst.mnFormat & ~BMP_FORMAT_TOP_DOWN ) 763*cdf0e10cSrcweir { 764*cdf0e10cSrcweir case BMP_FORMAT_1BIT_MSB_PAL: 765*cdf0e10cSrcweir case BMP_FORMAT_1BIT_LSB_PAL: 766*cdf0e10cSrcweir case BMP_FORMAT_4BIT_MSN_PAL: 767*cdf0e10cSrcweir case BMP_FORMAT_4BIT_LSN_PAL: 768*cdf0e10cSrcweir case BMP_FORMAT_8BIT_PAL: 769*cdf0e10cSrcweir break; 770*cdf0e10cSrcweir 771*cdf0e10cSrcweir case BMP_FORMAT_8BIT_TC_MASK: 772*cdf0e10cSrcweir // return ImplBlendToBitmap<BMP_FORMAT_8BIT_TC_MASK>( aSrcType, rDst, rSrc, rMsk ); 773*cdf0e10cSrcweir case BMP_FORMAT_24BIT_TC_MASK: 774*cdf0e10cSrcweir // return ImplBlendToBitmap<BMP_FORMAT_24BIT_TC_MASK>( aSrcType, rDst, rSrc, rMsk ); 775*cdf0e10cSrcweir case BMP_FORMAT_32BIT_TC_MASK: 776*cdf0e10cSrcweir // return ImplBlendToBitmap<BMP_FORMAT_32BIT_TC_MASK>( aSrcType, rDst, rSrc, rMsk ); 777*cdf0e10cSrcweir break; 778*cdf0e10cSrcweir 779*cdf0e10cSrcweir case BMP_FORMAT_16BIT_TC_MSB_MASK: 780*cdf0e10cSrcweir return ImplBlendToBitmap<BMP_FORMAT_16BIT_TC_MSB_MASK>( aSrcType, rDst, rSrc, rMsk ); 781*cdf0e10cSrcweir case BMP_FORMAT_16BIT_TC_LSB_MASK: 782*cdf0e10cSrcweir return ImplBlendToBitmap<BMP_FORMAT_16BIT_TC_LSB_MASK>( aSrcType, rDst, rSrc, rMsk ); 783*cdf0e10cSrcweir 784*cdf0e10cSrcweir case BMP_FORMAT_24BIT_TC_BGR: 785*cdf0e10cSrcweir return ImplBlendToBitmap<BMP_FORMAT_24BIT_TC_BGR>( aSrcType, rDst, rSrc, rMsk ); 786*cdf0e10cSrcweir case BMP_FORMAT_24BIT_TC_RGB: 787*cdf0e10cSrcweir return ImplBlendToBitmap<BMP_FORMAT_24BIT_TC_RGB>( aSrcType, rDst, rSrc, rMsk ); 788*cdf0e10cSrcweir 789*cdf0e10cSrcweir case BMP_FORMAT_32BIT_TC_ABGR: 790*cdf0e10cSrcweir return ImplBlendToBitmap<BMP_FORMAT_32BIT_TC_ABGR>( aSrcType, rDst, rSrc, rMsk ); 791*cdf0e10cSrcweir #ifdef FAST_ARGB_BGRA 792*cdf0e10cSrcweir case BMP_FORMAT_32BIT_TC_ARGB: 793*cdf0e10cSrcweir return ImplBlendToBitmap<BMP_FORMAT_32BIT_TC_ARGB>( aSrcType, rDst, rSrc, rMsk ); 794*cdf0e10cSrcweir case BMP_FORMAT_32BIT_TC_BGRA: 795*cdf0e10cSrcweir return ImplBlendToBitmap<BMP_FORMAT_32BIT_TC_BGRA>( aSrcType, rDst, rSrc, rMsk ); 796*cdf0e10cSrcweir #endif 797*cdf0e10cSrcweir case BMP_FORMAT_32BIT_TC_RGBA: 798*cdf0e10cSrcweir return ImplBlendToBitmap<BMP_FORMAT_32BIT_TC_RGBA>( aSrcType, rDst, rSrc, rMsk ); 799*cdf0e10cSrcweir } 800*cdf0e10cSrcweir 801*cdf0e10cSrcweir #ifdef DEBUG 802*cdf0e10cSrcweir static int nNotAccelerated = 0; 803*cdf0e10cSrcweir if( rSrc.mnWidth * rSrc.mnHeight >= 4000 ) 804*cdf0e10cSrcweir if( ++nNotAccelerated == 100 ) 805*cdf0e10cSrcweir { 806*cdf0e10cSrcweir int foo = 0; (void)foo; // so no warning is created when building on pro with debug 807*cdf0e10cSrcweir DBG_WARNING3( "ImplBlendFromBitmap for not accelerated case (0x%04X*0x%04X->0x%04X)", 808*cdf0e10cSrcweir rSrc.mnFormat, rMsk.mnFormat, rDst.mnFormat ); 809*cdf0e10cSrcweir } 810*cdf0e10cSrcweir #endif 811*cdf0e10cSrcweir 812*cdf0e10cSrcweir return false; 813*cdf0e10cSrcweir } 814*cdf0e10cSrcweir 815*cdf0e10cSrcweir // ----------------------------------------------------------------------- 816*cdf0e10cSrcweir 817*cdf0e10cSrcweir bool ImplFastBitmapBlending( BitmapWriteAccess& rDstWA, 818*cdf0e10cSrcweir const BitmapReadAccess& rSrcRA, const BitmapReadAccess& rMskRA, 819*cdf0e10cSrcweir const SalTwoRect& rTR ) 820*cdf0e10cSrcweir { 821*cdf0e10cSrcweir if( bDisableFastBitops ) 822*cdf0e10cSrcweir return false; 823*cdf0e10cSrcweir 824*cdf0e10cSrcweir // accelerated blending of paletted bitmaps not implemented yet 825*cdf0e10cSrcweir if( rSrcRA.HasPalette() ) 826*cdf0e10cSrcweir return false; 827*cdf0e10cSrcweir if( rDstWA.HasPalette() ) 828*cdf0e10cSrcweir return false; 829*cdf0e10cSrcweir // TODO: either get rid of mask's use of 8BIT_PAL or check the palette 830*cdf0e10cSrcweir 831*cdf0e10cSrcweir // horizontal mirroring not implemented yet 832*cdf0e10cSrcweir if( rTR.mnDestWidth < 0 ) 833*cdf0e10cSrcweir return false; 834*cdf0e10cSrcweir // vertical mirroring 835*cdf0e10cSrcweir if( rTR.mnDestHeight < 0 ) 836*cdf0e10cSrcweir // TODO: rDst.mnFormat ^= BMP_FORMAT_TOP_DOWN; 837*cdf0e10cSrcweir return false; 838*cdf0e10cSrcweir 839*cdf0e10cSrcweir // offseted blending is not implemented yet 840*cdf0e10cSrcweir if( rTR.mnSrcX || rTR.mnSrcY ) 841*cdf0e10cSrcweir return false; 842*cdf0e10cSrcweir if( rTR.mnDestX || rTR.mnDestY ) 843*cdf0e10cSrcweir return false; 844*cdf0e10cSrcweir 845*cdf0e10cSrcweir // stretched blending is not implemented yet 846*cdf0e10cSrcweir if( rTR.mnDestWidth != rTR.mnSrcWidth ) 847*cdf0e10cSrcweir return false; 848*cdf0e10cSrcweir if( rTR.mnDestHeight!= rTR.mnSrcHeight ) 849*cdf0e10cSrcweir return false; 850*cdf0e10cSrcweir 851*cdf0e10cSrcweir // check source image size 852*cdf0e10cSrcweir if( rSrcRA.Width() < rTR.mnSrcX + rTR.mnSrcWidth ) 853*cdf0e10cSrcweir return false; 854*cdf0e10cSrcweir if( rSrcRA.Height() < rTR.mnSrcY + rTR.mnSrcHeight ) 855*cdf0e10cSrcweir return false; 856*cdf0e10cSrcweir 857*cdf0e10cSrcweir // check mask image size 858*cdf0e10cSrcweir if( rMskRA.Width() < rTR.mnSrcX + rTR.mnSrcWidth ) 859*cdf0e10cSrcweir return false; 860*cdf0e10cSrcweir if( rMskRA.Height() < rTR.mnSrcY + rTR.mnSrcHeight ) 861*cdf0e10cSrcweir if( rMskRA.Height() != 1 ) 862*cdf0e10cSrcweir return false; 863*cdf0e10cSrcweir 864*cdf0e10cSrcweir // check dest image size 865*cdf0e10cSrcweir if( rDstWA.Width() < rTR.mnDestX + rTR.mnDestWidth ) 866*cdf0e10cSrcweir return false; 867*cdf0e10cSrcweir if( rDstWA.Height() < rTR.mnDestY + rTR.mnDestHeight ) 868*cdf0e10cSrcweir return false; 869*cdf0e10cSrcweir 870*cdf0e10cSrcweir BitmapBuffer& rDst = *rDstWA.ImplGetBitmapBuffer(); 871*cdf0e10cSrcweir const BitmapBuffer& rSrc = *rSrcRA.ImplGetBitmapBuffer(); 872*cdf0e10cSrcweir const BitmapBuffer& rMsk = *rMskRA.ImplGetBitmapBuffer(); 873*cdf0e10cSrcweir 874*cdf0e10cSrcweir const sal_uLong nSrcFormat = rSrc.mnFormat & ~BMP_FORMAT_TOP_DOWN; 875*cdf0e10cSrcweir const sal_uLong nDstFormat = rDst.mnFormat & ~BMP_FORMAT_TOP_DOWN; 876*cdf0e10cSrcweir 877*cdf0e10cSrcweir // accelerated conversions for 16bit colormasks with non-565 format are not yet implemented 878*cdf0e10cSrcweir if( nSrcFormat & (BMP_FORMAT_16BIT_TC_LSB_MASK | BMP_FORMAT_16BIT_TC_MSB_MASK) ) 879*cdf0e10cSrcweir if( rSrc.maColorMask.GetRedMask() != 0xF800 880*cdf0e10cSrcweir || rSrc.maColorMask.GetGreenMask()!= 0x07E0 881*cdf0e10cSrcweir || rSrc.maColorMask.GetBlueMask() != 0x001F) 882*cdf0e10cSrcweir return false; 883*cdf0e10cSrcweir if( nDstFormat & (BMP_FORMAT_16BIT_TC_LSB_MASK | BMP_FORMAT_16BIT_TC_MSB_MASK) ) 884*cdf0e10cSrcweir if( rDst.maColorMask.GetRedMask() != 0xF800 885*cdf0e10cSrcweir || rDst.maColorMask.GetGreenMask()!= 0x07E0 886*cdf0e10cSrcweir || rDst.maColorMask.GetBlueMask() != 0x001F) 887*cdf0e10cSrcweir return false; 888*cdf0e10cSrcweir 889*cdf0e10cSrcweir // select the matching instantiation for the source's bitmap format 890*cdf0e10cSrcweir switch( nSrcFormat ) 891*cdf0e10cSrcweir { 892*cdf0e10cSrcweir case BMP_FORMAT_1BIT_MSB_PAL: 893*cdf0e10cSrcweir case BMP_FORMAT_1BIT_LSB_PAL: 894*cdf0e10cSrcweir case BMP_FORMAT_4BIT_MSN_PAL: 895*cdf0e10cSrcweir case BMP_FORMAT_4BIT_LSN_PAL: 896*cdf0e10cSrcweir case BMP_FORMAT_8BIT_PAL: 897*cdf0e10cSrcweir break; 898*cdf0e10cSrcweir 899*cdf0e10cSrcweir case BMP_FORMAT_8BIT_TC_MASK: 900*cdf0e10cSrcweir // return ImplBlendFromBitmap<BMP_FORMAT_8BIT_TC_MASK>( rDst, rSrc ); 901*cdf0e10cSrcweir case BMP_FORMAT_24BIT_TC_MASK: 902*cdf0e10cSrcweir // return ImplBlendFromBitmap<BMP_FORMAT_24BIT_TC_MASK>( rDst, rSrc ); 903*cdf0e10cSrcweir case BMP_FORMAT_32BIT_TC_MASK: 904*cdf0e10cSrcweir // return ImplBlendFromBitmap<BMP_FORMAT_32BIT_TC_MASK>( rDst, rSrc ); 905*cdf0e10cSrcweir break; 906*cdf0e10cSrcweir 907*cdf0e10cSrcweir case BMP_FORMAT_16BIT_TC_MSB_MASK: 908*cdf0e10cSrcweir return ImplBlendFromBitmap<BMP_FORMAT_16BIT_TC_MSB_MASK>( rDst, rSrc, rMsk ); 909*cdf0e10cSrcweir case BMP_FORMAT_16BIT_TC_LSB_MASK: 910*cdf0e10cSrcweir return ImplBlendFromBitmap<BMP_FORMAT_16BIT_TC_LSB_MASK>( rDst, rSrc, rMsk ); 911*cdf0e10cSrcweir 912*cdf0e10cSrcweir case BMP_FORMAT_24BIT_TC_BGR: 913*cdf0e10cSrcweir return ImplBlendFromBitmap<BMP_FORMAT_24BIT_TC_BGR>( rDst, rSrc, rMsk ); 914*cdf0e10cSrcweir case BMP_FORMAT_24BIT_TC_RGB: 915*cdf0e10cSrcweir return ImplBlendFromBitmap<BMP_FORMAT_24BIT_TC_RGB>( rDst, rSrc, rMsk ); 916*cdf0e10cSrcweir 917*cdf0e10cSrcweir case BMP_FORMAT_32BIT_TC_ABGR: 918*cdf0e10cSrcweir return ImplBlendFromBitmap<BMP_FORMAT_32BIT_TC_ABGR>( rDst, rSrc, rMsk ); 919*cdf0e10cSrcweir #ifdef FAST_ARGB_BGRA 920*cdf0e10cSrcweir case BMP_FORMAT_32BIT_TC_ARGB: 921*cdf0e10cSrcweir return ImplBlendFromBitmap<BMP_FORMAT_32BIT_TC_ARGB>( rDst, rSrc, rMsk ); 922*cdf0e10cSrcweir case BMP_FORMAT_32BIT_TC_BGRA: 923*cdf0e10cSrcweir return ImplBlendFromBitmap<BMP_FORMAT_32BIT_TC_BGRA>( rDst, rSrc, rMsk ); 924*cdf0e10cSrcweir #endif 925*cdf0e10cSrcweir case BMP_FORMAT_32BIT_TC_RGBA: 926*cdf0e10cSrcweir return ImplBlendFromBitmap<BMP_FORMAT_32BIT_TC_RGBA>( rDst, rSrc, rMsk ); 927*cdf0e10cSrcweir } 928*cdf0e10cSrcweir 929*cdf0e10cSrcweir #ifdef DEBUG 930*cdf0e10cSrcweir static int nNotAccelerated = 0; 931*cdf0e10cSrcweir if( rSrc.mnWidth * rSrc.mnHeight >= 4000 ) 932*cdf0e10cSrcweir if( ++nNotAccelerated == 100 ) 933*cdf0e10cSrcweir { 934*cdf0e10cSrcweir int foo = 0; (void)foo; // so no warning is created when building on pro with debug 935*cdf0e10cSrcweir DBG_WARNING3( "ImplFastBlend for not accelerated case (0x%04X*0x%04X->0x%04X)", 936*cdf0e10cSrcweir rSrc.mnFormat, rMsk.mnFormat, rDst.mnFormat ); 937*cdf0e10cSrcweir } 938*cdf0e10cSrcweir #endif 939*cdf0e10cSrcweir 940*cdf0e10cSrcweir return false; 941*cdf0e10cSrcweir } 942*cdf0e10cSrcweir 943*cdf0e10cSrcweir bool ImplFastEraseBitmap( BitmapBuffer& rDst, const BitmapColor& rColor ) 944*cdf0e10cSrcweir { 945*cdf0e10cSrcweir if( bDisableFastBitops ) 946*cdf0e10cSrcweir return false; 947*cdf0e10cSrcweir 948*cdf0e10cSrcweir const sal_uLong nDstFormat = rDst.mnFormat & ~BMP_FORMAT_TOP_DOWN; 949*cdf0e10cSrcweir 950*cdf0e10cSrcweir // erasing a bitmap is often just a byte-wise memory fill 951*cdf0e10cSrcweir bool bByteFill = true; 952*cdf0e10cSrcweir sal_uInt8 nFillByte; 953*cdf0e10cSrcweir 954*cdf0e10cSrcweir switch( nDstFormat ) 955*cdf0e10cSrcweir { 956*cdf0e10cSrcweir case BMP_FORMAT_1BIT_MSB_PAL: 957*cdf0e10cSrcweir case BMP_FORMAT_1BIT_LSB_PAL: 958*cdf0e10cSrcweir nFillByte = rColor.GetIndex(); 959*cdf0e10cSrcweir nFillByte = static_cast<sal_uInt8>( -(nFillByte & 1) ); // 0x00 or 0xFF 960*cdf0e10cSrcweir break; 961*cdf0e10cSrcweir case BMP_FORMAT_4BIT_MSN_PAL: 962*cdf0e10cSrcweir case BMP_FORMAT_4BIT_LSN_PAL: 963*cdf0e10cSrcweir nFillByte = rColor.GetIndex(); 964*cdf0e10cSrcweir nFillByte &= 0x0F; 965*cdf0e10cSrcweir nFillByte |= (nFillByte << 4); 966*cdf0e10cSrcweir break; 967*cdf0e10cSrcweir case BMP_FORMAT_8BIT_PAL: 968*cdf0e10cSrcweir case BMP_FORMAT_8BIT_TC_MASK: 969*cdf0e10cSrcweir nFillByte = rColor.GetIndex(); 970*cdf0e10cSrcweir break; 971*cdf0e10cSrcweir 972*cdf0e10cSrcweir case BMP_FORMAT_24BIT_TC_MASK: 973*cdf0e10cSrcweir case BMP_FORMAT_24BIT_TC_BGR: 974*cdf0e10cSrcweir case BMP_FORMAT_24BIT_TC_RGB: 975*cdf0e10cSrcweir nFillByte = rColor.GetRed(); 976*cdf0e10cSrcweir if( (nFillByte != rColor.GetGreen()) 977*cdf0e10cSrcweir || (nFillByte != rColor.GetBlue()) ) 978*cdf0e10cSrcweir bByteFill = false; 979*cdf0e10cSrcweir break; 980*cdf0e10cSrcweir 981*cdf0e10cSrcweir default: 982*cdf0e10cSrcweir bByteFill = false; 983*cdf0e10cSrcweir nFillByte = 0x00; 984*cdf0e10cSrcweir break; 985*cdf0e10cSrcweir } 986*cdf0e10cSrcweir 987*cdf0e10cSrcweir if( bByteFill ) 988*cdf0e10cSrcweir { 989*cdf0e10cSrcweir long nByteCount = rDst.mnHeight * rDst.mnScanlineSize; 990*cdf0e10cSrcweir rtl_fillMemory( rDst.mpBits, nByteCount, nFillByte ); 991*cdf0e10cSrcweir return true; 992*cdf0e10cSrcweir } 993*cdf0e10cSrcweir 994*cdf0e10cSrcweir // TODO: handle other bitmap formats 995*cdf0e10cSrcweir switch( nDstFormat ) 996*cdf0e10cSrcweir { 997*cdf0e10cSrcweir case BMP_FORMAT_32BIT_TC_MASK: 998*cdf0e10cSrcweir case BMP_FORMAT_16BIT_TC_MSB_MASK: 999*cdf0e10cSrcweir case BMP_FORMAT_16BIT_TC_LSB_MASK: 1000*cdf0e10cSrcweir 1001*cdf0e10cSrcweir case BMP_FORMAT_24BIT_TC_BGR: 1002*cdf0e10cSrcweir case BMP_FORMAT_24BIT_TC_RGB: 1003*cdf0e10cSrcweir 1004*cdf0e10cSrcweir case BMP_FORMAT_32BIT_TC_ABGR: 1005*cdf0e10cSrcweir #ifdef FAST_ARGB_BGRA 1006*cdf0e10cSrcweir case BMP_FORMAT_32BIT_TC_ARGB: 1007*cdf0e10cSrcweir case BMP_FORMAT_32BIT_TC_BGRA: 1008*cdf0e10cSrcweir #endif 1009*cdf0e10cSrcweir case BMP_FORMAT_32BIT_TC_RGBA: 1010*cdf0e10cSrcweir break; 1011*cdf0e10cSrcweir 1012*cdf0e10cSrcweir default: 1013*cdf0e10cSrcweir break; 1014*cdf0e10cSrcweir } 1015*cdf0e10cSrcweir 1016*cdf0e10cSrcweir return false; 1017*cdf0e10cSrcweir } 1018*cdf0e10cSrcweir 1019*cdf0e10cSrcweir // ======================================================================= 1020*cdf0e10cSrcweir 1021*cdf0e10cSrcweir #else // NO_OPTIMIZED_BITMAP_ACCESS 1022*cdf0e10cSrcweir 1023*cdf0e10cSrcweir bool ImplFastBitmapConversion( BitmapBuffer&, const BitmapBuffer& ) 1024*cdf0e10cSrcweir { 1025*cdf0e10cSrcweir return false; 1026*cdf0e10cSrcweir } 1027*cdf0e10cSrcweir 1028*cdf0e10cSrcweir bool ImplFastBitmapBlending( BitmapWriteAccess&, 1029*cdf0e10cSrcweir const BitmapReadAccess&, const BitmapReadAccess&, 1030*cdf0e10cSrcweir const Size&, const Point& ) 1031*cdf0e10cSrcweir { 1032*cdf0e10cSrcweir return false; 1033*cdf0e10cSrcweir } 1034*cdf0e10cSrcweir 1035*cdf0e10cSrcweir bool ImplFastEraseBitmap( BitmapBuffer&, const BitmapColor& ) 1036*cdf0e10cSrcweir { 1037*cdf0e10cSrcweir return false; 1038*cdf0e10cSrcweir } 1039*cdf0e10cSrcweir 1040*cdf0e10cSrcweir #endif 1041