summaryrefslogtreecommitdiff
path: root/vcl/source/gdi/salmisc.cxx
blob: d32176875d805e5f3afd05cbfe8c791a6aceaea8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
/*************************************************************************
 *
 *  $RCSfile: salmisc.cxx,v $
 *
 *  $Revision: 1.3 $
 *
 *  last change: $Author: ka $ $Date: 2002-01-17 15:35:33 $
 *
 *  The Contents of this file are made available subject to the terms of
 *  either of the following licenses
 *
 *         - GNU Lesser General Public License Version 2.1
 *         - Sun Industry Standards Source License Version 1.1
 *
 *  Sun Microsystems Inc., October, 2000
 *
 *  GNU Lesser General Public License Version 2.1
 *  =============================================
 *  Copyright 2000 by Sun Microsystems, Inc.
 *  901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public
 *  License version 2.1, as published by the Free Software Foundation.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this library; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *  MA  02111-1307  USA
 *
 *
 *  Sun Industry Standards Source License Version 1.1
 *  =================================================
 *  The contents of this file are subject to the Sun Industry Standards
 *  Source License Version 1.1 (the "License"); You may not use this file
 *  except in compliance with the License. You may obtain a copy of the
 *  License at http://www.openoffice.org/license.html.
 *
 *  Software provided under this License is provided on an "AS IS" basis,
 *  WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
 *  WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
 *  MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
 *  See the License for the specific provisions governing your rights and
 *  obligations concerning the Software.
 *
 *  The Initial Developer of the Original Code is: Sun Microsystems, Inc.
 *
 *  Copyright: 2000 by Sun Microsystems, Inc.
 *
 *  All Rights Reserved.
 *
 *  Contributor(s): _______________________________________
 *
 *
 ************************************************************************/

#ifndef _RTL_MEMORY_H_
#include <rtl/memory.h>
#endif
#include <bmpacc.hxx>
#include <salbtype.hxx>

// -----------
// - Defines -
// -----------

#define IMPL_CASE_GET_FORMAT( Format )                          \
case( BMP_FORMAT##Format ):                                 \
    pFncGetPixel = BitmapReadAccess::GetPixelFor##Format;       \
break

// -----------------------------------------------------------------------------

#define IMPL_CASE_SET_FORMAT( Format, BitCount )                \
case( BMP_FORMAT##Format ):                                 \
{                                                               \
    pFncSetPixel = BitmapReadAccess::SetPixelFor##Format;       \
    pDstBuffer->mnBitCount = BitCount;                          \
}                                                               \
break

// -----------------------------------------------------------------------------

#define DOUBLE_SCANLINES()                                                      \
while( ( nActY < nHeight1 ) && ( pMapY[ nActY + 1 ] == nMapY ) )                \
{                                                                               \
    HMEMCPY( pDstScanMap[ nActY + 1L ], pDstScan, rDstBuffer.mnScanlineSize );  \
    nActY++;                                                                    \
}

// -----------
// - Inlines -
// -----------

#define TC_TO_PAL_COLORS    4096

static long ImplIndexFromColor( const BitmapColor& rCol )
{
#if TC_TO_PAL_COLORS == 4096

    return( ( ( (long) rCol.GetBlue() >> 4L) << 8L ) |
            ( ( (long) rCol.GetGreen() >> 4L ) << 4L ) |
            ( (long) rCol.GetRed() >> 4L ) );

#elif TC_TO_PAL_COLORS == 32768

    return( ( ( (long) rCol.GetBlue() >> 3L) << 10L ) |
            ( ( (long) rCol.GetGreen() >> 3L ) << 5L ) |
            ( (long) rCol.GetRed() >> 3L ) );

#endif
}


#define COLOR_TO_INDEX( _def_rCol )

// ------------------------
// - conversion functions -
// ------------------------

static void ImplPALToPAL( const BitmapBuffer& rSrcBuffer, BitmapBuffer& rDstBuffer,
                          FncGetPixel pFncGetPixel, FncSetPixel pFncSetPixel,
                          Scanline* pSrcScanMap, Scanline* pDstScanMap, long* pMapX, long* pMapY )
{
    const long          nWidth = rDstBuffer.mnWidth, nHeight = rDstBuffer.mnHeight, nHeight1 = nHeight - 1;
    const ColorMask&    rSrcMask = rSrcBuffer.maColorMask;
    const ColorMask&    rDstMask = rDstBuffer.maColorMask;
    BitmapPalette       aColMap( rSrcBuffer.maPalette.GetEntryCount() );
    BitmapColor*        pColMapBuf = aColMap.ImplGetColorBuffer();
    BitmapColor         aIndex( 0 );

    for( USHORT i = 0, nSrcCount = aColMap.GetEntryCount(), nDstCount = rDstBuffer.maPalette.GetEntryCount(); i < nSrcCount; i++ )
    {
        if( ( i < nDstCount ) && ( rSrcBuffer.maPalette[ i ] == rDstBuffer.maPalette[ i ] ) )
            aIndex.SetIndex( i );
        else
            aIndex.SetIndex( rDstBuffer.maPalette.GetBestIndex( rSrcBuffer.maPalette[ i ] ) );

        pColMapBuf[ i ] = aIndex;
    }

    for( long nActY = 0, nMapY; nActY < nHeight; nActY++ )
    {
        Scanline pSrcScan( pSrcScanMap[ nMapY = pMapY[ nActY ] ] ), pDstScan( pDstScanMap[ nActY ] );

        for( long nX = 0L; nX < nWidth; nX++ )
            pFncSetPixel( pDstScan, nX, pColMapBuf[ pFncGetPixel( pSrcScan, pMapX[ nX ], rSrcMask ).GetIndex() ], rDstMask );

        DOUBLE_SCANLINES();
    }
}

// -----------------------------------------------------------------------------

static void ImplPALToTC( const BitmapBuffer& rSrcBuffer, BitmapBuffer& rDstBuffer,
                         FncGetPixel pFncGetPixel, FncSetPixel pFncSetPixel,
                         Scanline* pSrcScanMap, Scanline* pDstScanMap, long* pMapX, long* pMapY )
{
    const long          nWidth = rDstBuffer.mnWidth, nHeight = rDstBuffer.mnHeight, nHeight1 = nHeight - 1;
    const ColorMask&    rSrcMask = rSrcBuffer.maColorMask;
    const ColorMask&    rDstMask = rDstBuffer.maColorMask;
    const BitmapColor*  pColBuf = rSrcBuffer.maPalette.ImplGetColorBuffer();

    if( BMP_SCANLINE_FORMAT( rSrcBuffer.mnFormat ) == BMP_FORMAT_1BIT_MSB_PAL )
    {
        const BitmapColor   aCol0( pColBuf[ 0 ] );
        const BitmapColor   aCol1( pColBuf[ 1 ] );
        long                nMapX;

        for( long nActY = 0, nMapY; nActY < nHeight; nActY++ )
        {
            Scanline pSrcScan( pSrcScanMap[ nMapY = pMapY[ nActY ] ] ), pDstScan( pDstScanMap[ nActY ] );

            for( long nX = 0L; nX < nWidth; )
            {
                nMapX = pMapX[ nX ];
                pFncSetPixel( pDstScan, nX++,
                              pSrcScan[ nMapX >> 3 ] & ( 1 << ( 7 - ( nMapX & 7 ) ) ) ? aCol1 : aCol0,
                              rDstMask );
            }

            DOUBLE_SCANLINES();
        }
    }
    else if( BMP_SCANLINE_FORMAT( rSrcBuffer.mnFormat ) == BMP_FORMAT_4BIT_MSN_PAL )
    {
        long nMapX;

        for( long nActY = 0, nMapY; nActY < nHeight; nActY++ )
        {
            Scanline pSrcScan( pSrcScanMap[ nMapY = pMapY[ nActY ] ] ), pDstScan( pDstScanMap[ nActY ] );

            for( long nX = 0L; nX < nWidth; )
            {
                nMapX = pMapX[ nX ];
                pFncSetPixel( pDstScan, nX++,
                              pColBuf[ ( pSrcScan[ nMapX >> 1 ] >> ( nMapX & 1 ? 0 : 4 ) ) & 0x0f ],
                              rDstMask );
            }

            DOUBLE_SCANLINES();
        }
    }
    else if( BMP_SCANLINE_FORMAT( rSrcBuffer.mnFormat ) == BMP_FORMAT_8BIT_PAL )
    {
        for( long nActY = 0, nMapY; nActY < nHeight; nActY++ )
        {
            Scanline pSrcScan( pSrcScanMap[ nMapY = pMapY[ nActY ] ] ), pDstScan( pDstScanMap[ nActY ] );

            for( long nX = 0L; nX < nWidth; nX++ )
                pFncSetPixel( pDstScan, nX, pColBuf[ pSrcScan[ pMapX[ nX ] ] ], rDstMask );

            DOUBLE_SCANLINES();
        }
    }
    else
    {
        for( long nActY = 0, nMapY; nActY < nHeight; nActY++ )
        {
            Scanline pSrcScan( pSrcScanMap[ nMapY = pMapY[ nActY ] ] ), pDstScan( pDstScanMap[ nActY ] );

            for( long nX = 0L; nX < nWidth; nX++ )
                pFncSetPixel( pDstScan, nX, pColBuf[ pFncGetPixel( pSrcScan, pMapX[ nX ], rSrcMask ).GetIndex() ], rDstMask );

            DOUBLE_SCANLINES();
        }
    }
}

// -----------------------------------------------------------------------------

static void ImplTCToTC( const BitmapBuffer& rSrcBuffer, BitmapBuffer& rDstBuffer,
                        FncGetPixel pFncGetPixel, FncSetPixel pFncSetPixel,
                        Scanline* pSrcScanMap, Scanline* pDstScanMap, long* pMapX, long* pMapY )
{
    const long          nWidth = rDstBuffer.mnWidth, nHeight = rDstBuffer.mnHeight, nHeight1 = nHeight - 1;
    const ColorMask&    rSrcMask = rSrcBuffer.maColorMask;
    const ColorMask&    rDstMask = rDstBuffer.maColorMask;

    if( BMP_SCANLINE_FORMAT( rSrcBuffer.mnFormat ) == BMP_FORMAT_24BIT_TC_BGR )
    {
        BitmapColor aCol;
        BYTE*       pPixel;

        for( long nActY = 0, nMapY; nActY < nHeight; nActY++ )
        {
            Scanline pSrcScan( pSrcScanMap[ nMapY = pMapY[ nActY ] ] ), pDstScan( pDstScanMap[ nActY ] );

            for( long nX = 0L; nX < nWidth; nX++ )
            {
                aCol.SetBlue( *( pPixel = ( pSrcScan + pMapX[ nX ] * 3 ) )++ );
                aCol.SetGreen( *pPixel++ );
                aCol.SetRed( *pPixel );
                pFncSetPixel( pDstScan, nX, aCol, rDstMask );
            }

            DOUBLE_SCANLINES()
        }
    }
    else
    {
        for( long nActY = 0, nMapY; nActY < nHeight; nActY++ )
        {
            Scanline pSrcScan( pSrcScanMap[ nMapY = pMapY[ nActY ] ] ), pDstScan( pDstScanMap[ nActY ] );

            for( long nX = 0L; nX < nWidth; nX++ )
                pFncSetPixel( pDstScan, nX, pFncGetPixel( pSrcScan, pMapX[ nX ], rSrcMask ), rDstMask );

            DOUBLE_SCANLINES();
        }
    }
}

// -----------------------------------------------------------------------------

static void ImplTCToPAL( const BitmapBuffer& rSrcBuffer, BitmapBuffer& rDstBuffer,
                         FncGetPixel pFncGetPixel, FncSetPixel pFncSetPixel,
                         Scanline* pSrcScanMap, Scanline* pDstScanMap, long* pMapX, long* pMapY )
{
    const long          nWidth = rDstBuffer.mnWidth, nHeight = rDstBuffer.mnHeight, nHeight1 = nHeight - 1;
    const ColorMask&    rSrcMask = rSrcBuffer.maColorMask;
    const ColorMask&    rDstMask = rDstBuffer.maColorMask;
    BitmapPalette       aColMap( rSrcBuffer.maPalette.GetEntryCount() );
    BYTE*               pColToPalMap = new BYTE[ TC_TO_PAL_COLORS ];
    BitmapColor         aIndex( 0 );

    for( long nR = 0; nR < 16; nR++ )
    {
        for( long nG = 0; nG < 16; nG++ )
        {
            for( long nB = 0; nB < 16; nB++ )
            {
                BitmapColor aCol( nR << 4, nG << 4, nB << 4 );
                pColToPalMap[ ImplIndexFromColor( aCol ) ] = (BYTE) rDstBuffer.maPalette.GetBestIndex( aCol );
            }
        }
    }

    for( long nActY = 0, nMapY; nActY < nHeight; nActY++ )
    {
        Scanline pSrcScan( pSrcScanMap[ nMapY = pMapY[ nActY ] ] ), pDstScan( pDstScanMap[ nActY ] );

        for( long nX = 0L; nX < nWidth; nX++ )
        {
            aIndex.SetIndex( pColToPalMap[ ImplIndexFromColor( pFncGetPixel( pSrcScan, pMapX[ nX ], rSrcMask ) ) ] );
            pFncSetPixel( pDstScan, nX, aIndex, rDstMask );
        }

        DOUBLE_SCANLINES();
    }

    delete[] pColToPalMap;
}

// ---------------------
// - StretchAndConvert -
// ---------------------

BitmapBuffer* StretchAndConvert( const BitmapBuffer& rSrcBuffer, const SalTwoRect& rTwoRect,
                                 ULONG nDstBitmapFormat, BitmapPalette* pDstPal, ColorMask* pDstMask )
{
    FncGetPixel     pFncGetPixel;
    FncSetPixel     pFncSetPixel;
    BitmapBuffer*   pDstBuffer = new BitmapBuffer;
    const ULONG     nDstScanlineFormat = BMP_SCANLINE_FORMAT( nDstBitmapFormat );
    const long      nSrcX = rTwoRect.mnSrcX, nSrcY = rTwoRect.mnSrcY;
    const long      nSrcDX = rTwoRect.mnSrcWidth, nSrcDY = rTwoRect.mnSrcHeight;
    const long      nDstDX = rTwoRect.mnDestWidth, nDstDY = rTwoRect.mnDestHeight;
    Scanline*       pSrcScan = new Scanline[ rSrcBuffer.mnHeight ];
    Scanline*       pDstScan = new Scanline[ nDstDY ];
    long*           pMapX = new long[ nDstDX ];
    long*           pMapY = new long[ nDstDY ];
    Scanline        pTmpScan;
    long            i, nTmp, nOffset;

    // set function for getting pixels
    switch( BMP_SCANLINE_FORMAT( rSrcBuffer.mnFormat ) )
    {
        IMPL_CASE_GET_FORMAT( _1BIT_MSB_PAL );
        IMPL_CASE_GET_FORMAT( _1BIT_LSB_PAL );
        IMPL_CASE_GET_FORMAT( _4BIT_MSN_PAL );
        IMPL_CASE_GET_FORMAT( _4BIT_LSN_PAL );
        IMPL_CASE_GET_FORMAT( _8BIT_PAL );
        IMPL_CASE_GET_FORMAT( _8BIT_TC_MASK );
        IMPL_CASE_GET_FORMAT( _16BIT_TC_MSB_MASK );
        IMPL_CASE_GET_FORMAT( _16BIT_TC_LSB_MASK );
        IMPL_CASE_GET_FORMAT( _24BIT_TC_BGR );
        IMPL_CASE_GET_FORMAT( _24BIT_TC_RGB );
        IMPL_CASE_GET_FORMAT( _24BIT_TC_MASK );
        IMPL_CASE_GET_FORMAT( _32BIT_TC_ABGR );
        IMPL_CASE_GET_FORMAT( _32BIT_TC_ARGB );
        IMPL_CASE_GET_FORMAT( _32BIT_TC_BGRA );
        IMPL_CASE_GET_FORMAT( _32BIT_TC_RGBA );
        IMPL_CASE_GET_FORMAT( _32BIT_TC_MASK );

        default:
            DBG_ERROR( "unknown read format" );
        break;
    }

    // set function for setting pixels
    switch( nDstScanlineFormat )
    {
        IMPL_CASE_SET_FORMAT( _1BIT_MSB_PAL, 1 );
        IMPL_CASE_SET_FORMAT( _1BIT_LSB_PAL, 1 );
        IMPL_CASE_SET_FORMAT( _4BIT_MSN_PAL, 1 );
        IMPL_CASE_SET_FORMAT( _4BIT_LSN_PAL, 4 );
        IMPL_CASE_SET_FORMAT( _8BIT_PAL, 8 );
        IMPL_CASE_SET_FORMAT( _8BIT_TC_MASK, 8 );
        IMPL_CASE_SET_FORMAT( _16BIT_TC_MSB_MASK, 16 );
        IMPL_CASE_SET_FORMAT( _16BIT_TC_LSB_MASK, 16 );
        IMPL_CASE_SET_FORMAT( _24BIT_TC_BGR, 24 );
        IMPL_CASE_SET_FORMAT( _24BIT_TC_RGB, 24 );
        IMPL_CASE_SET_FORMAT( _24BIT_TC_MASK, 24 );
        IMPL_CASE_SET_FORMAT( _32BIT_TC_ABGR, 32 );
        IMPL_CASE_SET_FORMAT( _32BIT_TC_ARGB, 32 );
        IMPL_CASE_SET_FORMAT( _32BIT_TC_BGRA, 32 );
        IMPL_CASE_SET_FORMAT( _32BIT_TC_RGBA, 32 );
        IMPL_CASE_SET_FORMAT( _32BIT_TC_MASK, 32 );

        default:
            DBG_ERROR( "unknown write format" );
        break;
    }

    // fill destination buffer
    pDstBuffer->mnFormat = nDstBitmapFormat;
    pDstBuffer->mnWidth = nDstDX;
    pDstBuffer->mnHeight = nDstDY;
    pDstBuffer->mnScanlineSize = AlignedWidth4Bytes( pDstBuffer->mnBitCount * nDstDX );
    pDstBuffer->mpBits = new BYTE[ pDstBuffer->mnScanlineSize * nDstDY ];
    rtl_zeroMemory( pDstBuffer->mpBits, pDstBuffer->mnScanlineSize * nDstDY );

    // do we need a destination palette or color mask?
    if( ( nDstScanlineFormat == BMP_FORMAT_1BIT_MSB_PAL ) ||
        ( nDstScanlineFormat == BMP_FORMAT_1BIT_LSB_PAL ) ||
        ( nDstScanlineFormat == BMP_FORMAT_4BIT_MSN_PAL ) ||
        ( nDstScanlineFormat == BMP_FORMAT_4BIT_LSN_PAL ) ||
        ( nDstScanlineFormat == BMP_FORMAT_8BIT_PAL ) )
    {
        DBG_ASSERT( pDstPal, "destination buffer requires palette" );
        pDstBuffer->maPalette = *pDstPal;
    }
    else if( ( nDstScanlineFormat == BMP_FORMAT_8BIT_TC_MASK ) ||
             ( nDstScanlineFormat == BMP_FORMAT_16BIT_TC_MSB_MASK ) ||
             ( nDstScanlineFormat == BMP_FORMAT_16BIT_TC_LSB_MASK ) ||
             ( nDstScanlineFormat == BMP_FORMAT_24BIT_TC_MASK ) ||
             ( nDstScanlineFormat == BMP_FORMAT_32BIT_TC_MASK ) )
    {
        DBG_ASSERT( pDstMask, "destination buffer requires color mask" );
        pDstBuffer->maColorMask = *pDstMask;
    }

    // horizontal mapping table
    if( nDstDX != nSrcDX )
    {
        const double fFactorX = ( nDstDX > 1 ) ? (double) ( nSrcDX - 1 ) / ( nDstDX - 1 ) : 0.0;

        for( i = 0L; i < nDstDX; i++ )
            pMapX[ i ] = nSrcX + FRound( i * fFactorX );
    }
    else
    {
        for( i = 0L, nTmp = nSrcX; i < nDstDX; i++ )
            pMapX[ i ] = nTmp++;
    }

    // vertical mapping table
    if( nDstDY != nSrcDY )
    {
        const double fFactorY = ( nDstDY > 1 ) ? (double) ( nSrcDY - 1 ) / ( nDstDY - 1 ) : 0.0;

        for( i = 0L; i < nDstDY; i++ )
            pMapY[ i ] = nSrcY + FRound( i * fFactorY );
    }
    else
    {
        for( i = 0L, nTmp = nSrcY; i < nDstDY; i++ )
            pMapY[ i ] = nTmp++;
    }

    // source scanline buffer
    if( BMP_SCANLINE_ADJUSTMENT( rSrcBuffer.mnFormat ) == BMP_FORMAT_TOP_DOWN )
        pTmpScan = rSrcBuffer.mpBits, nOffset = rSrcBuffer.mnScanlineSize;
    else
    {
        pTmpScan = rSrcBuffer.mpBits + ( rSrcBuffer.mnHeight - 1 ) * rSrcBuffer.mnScanlineSize;
        nOffset = -rSrcBuffer.mnScanlineSize;
    }

    for( i = 0L; i < rSrcBuffer.mnHeight; i++, pTmpScan += nOffset )
        pSrcScan[ i ] = pTmpScan;

    // destination scanline buffer
    if( BMP_SCANLINE_ADJUSTMENT( pDstBuffer->mnFormat ) == BMP_FORMAT_TOP_DOWN )
        pTmpScan = pDstBuffer->mpBits, nOffset = pDstBuffer->mnScanlineSize;
    else
    {
        pTmpScan = pDstBuffer->mpBits + ( nDstDY - 1 ) * pDstBuffer->mnScanlineSize;
        nOffset = -pDstBuffer->mnScanlineSize;
    }

    for( i = 0L; i < nDstDY; i++, pTmpScan += nOffset )
        pDstScan[ i ] = pTmpScan;

    // do buffer scaling and conversion
    if( rSrcBuffer.mnBitCount <= 8 && pDstBuffer->mnBitCount <= 8 )
    {
        ImplPALToPAL( rSrcBuffer, *pDstBuffer, pFncGetPixel, pFncSetPixel,
                      pSrcScan, pDstScan, pMapX, pMapY );
    }
    else if( rSrcBuffer.mnBitCount <= 8 && pDstBuffer->mnBitCount > 8 )
    {
        ImplPALToTC( rSrcBuffer, *pDstBuffer, pFncGetPixel, pFncSetPixel,
                     pSrcScan, pDstScan, pMapX, pMapY );
    }
    else if( rSrcBuffer.mnBitCount > 8 && pDstBuffer->mnBitCount > 8 )
    {
        ImplTCToTC( rSrcBuffer, *pDstBuffer, pFncGetPixel, pFncSetPixel,
                    pSrcScan, pDstScan, pMapX, pMapY );
    }
    else
    {
        ImplTCToPAL( rSrcBuffer, *pDstBuffer, pFncGetPixel, pFncSetPixel,
                     pSrcScan, pDstScan, pMapX, pMapY );
    }

    // cleanup
    delete[] pSrcScan;
    delete[] pDstScan;
    delete[] pMapX;
    delete[] pMapY;

    return pDstBuffer;
}