Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #include <vcl/bmpacc.hxx>
21 : #include <vcl/salbtype.hxx>
22 : #include <bmpfast.hxx>
23 :
24 : // -----------
25 : // - Defines -
26 : // -----------
27 :
28 : #define IMPL_CASE_GET_FORMAT( Format ) \
29 : case( BMP_FORMAT##Format ): \
30 : pFncGetPixel = BitmapReadAccess::GetPixelFor##Format; \
31 : break
32 :
33 : // -----------------------------------------------------------------------------
34 :
35 : #define IMPL_CASE_SET_FORMAT( Format, BitCount ) \
36 : case( BMP_FORMAT##Format ): \
37 : { \
38 : pFncSetPixel = BitmapReadAccess::SetPixelFor##Format; \
39 : pDstBuffer->mnBitCount = BitCount; \
40 : } \
41 : break
42 :
43 : // -----------------------------------------------------------------------------
44 :
45 : #define DOUBLE_SCANLINES() \
46 : while( ( nActY < nHeight1 ) && ( pMapY[ nActY + 1 ] == nMapY ) ) \
47 : { \
48 : memcpy( pDstScanMap[ nActY + 1L ], pDstScan, rDstBuffer.mnScanlineSize ); \
49 : nActY++; \
50 : }
51 :
52 : // -----------
53 : // - Inlines -
54 : // -----------
55 :
56 : #define TC_TO_PAL_COLORS 4096
57 :
58 0 : static long ImplIndexFromColor( const BitmapColor& rCol )
59 : {
60 : #if TC_TO_PAL_COLORS == 4096
61 :
62 0 : return( ( ( (long) rCol.GetBlue() >> 4L) << 8L ) |
63 0 : ( ( (long) rCol.GetGreen() >> 4L ) << 4L ) |
64 0 : ( (long) rCol.GetRed() >> 4L ) );
65 :
66 : #elif TC_TO_PAL_COLORS == 32768
67 :
68 : return( ( ( (long) rCol.GetBlue() >> 3L) << 10L ) |
69 : ( ( (long) rCol.GetGreen() >> 3L ) << 5L ) |
70 : ( (long) rCol.GetRed() >> 3L ) );
71 :
72 : #endif
73 : }
74 :
75 : // ------------------------
76 : // - conversion functions -
77 : // ------------------------
78 :
79 0 : static void ImplPALToPAL( const BitmapBuffer& rSrcBuffer, BitmapBuffer& rDstBuffer,
80 : FncGetPixel pFncGetPixel, FncSetPixel pFncSetPixel,
81 : Scanline* pSrcScanMap, Scanline* pDstScanMap, long* pMapX, long* pMapY )
82 : {
83 0 : const long nWidth = rDstBuffer.mnWidth, nHeight = rDstBuffer.mnHeight, nHeight1 = nHeight - 1;
84 0 : const ColorMask& rSrcMask = rSrcBuffer.maColorMask;
85 0 : const ColorMask& rDstMask = rDstBuffer.maColorMask;
86 0 : BitmapPalette aColMap( rSrcBuffer.maPalette.GetEntryCount() );
87 0 : BitmapColor* pColMapBuf = aColMap.ImplGetColorBuffer();
88 0 : BitmapColor aIndex( 0 );
89 :
90 0 : for( sal_uInt16 i = 0, nSrcCount = aColMap.GetEntryCount(), nDstCount = rDstBuffer.maPalette.GetEntryCount(); i < nSrcCount; i++ )
91 : {
92 0 : if( ( i < nDstCount ) && ( rSrcBuffer.maPalette[ i ] == rDstBuffer.maPalette[ i ] ) )
93 0 : aIndex.SetIndex( sal::static_int_cast<sal_uInt8>(i) );
94 : else
95 0 : aIndex.SetIndex( sal::static_int_cast<sal_uInt8>(rDstBuffer.maPalette.GetBestIndex( rSrcBuffer.maPalette[ i ] )) );
96 :
97 0 : pColMapBuf[ i ] = aIndex;
98 : }
99 :
100 0 : for( long nActY = 0, nMapY; nActY < nHeight; nActY++ )
101 : {
102 0 : Scanline pSrcScan( pSrcScanMap[ nMapY = pMapY[ nActY ] ] ), pDstScan( pDstScanMap[ nActY ] );
103 :
104 0 : for( long nX = 0L; nX < nWidth; nX++ )
105 0 : pFncSetPixel( pDstScan, nX, pColMapBuf[ pFncGetPixel( pSrcScan, pMapX[ nX ], rSrcMask ).GetIndex() ], rDstMask );
106 :
107 0 : DOUBLE_SCANLINES();
108 0 : }
109 0 : }
110 :
111 : // -----------------------------------------------------------------------------
112 :
113 0 : static void ImplPALToTC( const BitmapBuffer& rSrcBuffer, BitmapBuffer& rDstBuffer,
114 : FncGetPixel pFncGetPixel, FncSetPixel pFncSetPixel,
115 : Scanline* pSrcScanMap, Scanline* pDstScanMap, long* pMapX, long* pMapY )
116 : {
117 0 : const long nWidth = rDstBuffer.mnWidth, nHeight = rDstBuffer.mnHeight, nHeight1 = nHeight - 1;
118 0 : const ColorMask& rSrcMask = rSrcBuffer.maColorMask;
119 0 : const ColorMask& rDstMask = rDstBuffer.maColorMask;
120 0 : const BitmapColor* pColBuf = rSrcBuffer.maPalette.ImplGetColorBuffer();
121 :
122 0 : if( BMP_SCANLINE_FORMAT( rSrcBuffer.mnFormat ) == BMP_FORMAT_1BIT_MSB_PAL )
123 : {
124 0 : const BitmapColor aCol0( pColBuf[ 0 ] );
125 0 : const BitmapColor aCol1( pColBuf[ 1 ] );
126 : long nMapX;
127 :
128 0 : for( long nActY = 0, nMapY; nActY < nHeight; nActY++ )
129 : {
130 0 : Scanline pSrcScan( pSrcScanMap[ nMapY = pMapY[ nActY ] ] ), pDstScan( pDstScanMap[ nActY ] );
131 :
132 0 : for( long nX = 0L; nX < nWidth; )
133 : {
134 0 : nMapX = pMapX[ nX ];
135 : pFncSetPixel( pDstScan, nX++,
136 0 : pSrcScan[ nMapX >> 3 ] & ( 1 << ( 7 - ( nMapX & 7 ) ) ) ? aCol1 : aCol0,
137 0 : rDstMask );
138 : }
139 :
140 0 : DOUBLE_SCANLINES();
141 0 : }
142 : }
143 0 : else if( BMP_SCANLINE_FORMAT( rSrcBuffer.mnFormat ) == BMP_FORMAT_4BIT_MSN_PAL )
144 : {
145 : long nMapX;
146 :
147 0 : for( long nActY = 0, nMapY; nActY < nHeight; nActY++ )
148 : {
149 0 : Scanline pSrcScan( pSrcScanMap[ nMapY = pMapY[ nActY ] ] ), pDstScan( pDstScanMap[ nActY ] );
150 :
151 0 : for( long nX = 0L; nX < nWidth; )
152 : {
153 0 : nMapX = pMapX[ nX ];
154 : pFncSetPixel( pDstScan, nX++,
155 0 : pColBuf[ ( pSrcScan[ nMapX >> 1 ] >> ( nMapX & 1 ? 0 : 4 ) ) & 0x0f ],
156 0 : rDstMask );
157 : }
158 :
159 0 : DOUBLE_SCANLINES();
160 : }
161 : }
162 0 : else if( BMP_SCANLINE_FORMAT( rSrcBuffer.mnFormat ) == BMP_FORMAT_8BIT_PAL )
163 : {
164 0 : for( long nActY = 0, nMapY; nActY < nHeight; nActY++ )
165 : {
166 0 : Scanline pSrcScan( pSrcScanMap[ nMapY = pMapY[ nActY ] ] ), pDstScan( pDstScanMap[ nActY ] );
167 :
168 0 : for( long nX = 0L; nX < nWidth; nX++ )
169 0 : pFncSetPixel( pDstScan, nX, pColBuf[ pSrcScan[ pMapX[ nX ] ] ], rDstMask );
170 :
171 0 : DOUBLE_SCANLINES();
172 : }
173 : }
174 : else
175 : {
176 0 : for( long nActY = 0, nMapY; nActY < nHeight; nActY++ )
177 : {
178 0 : Scanline pSrcScan( pSrcScanMap[ nMapY = pMapY[ nActY ] ] ), pDstScan( pDstScanMap[ nActY ] );
179 :
180 0 : for( long nX = 0L; nX < nWidth; nX++ )
181 0 : pFncSetPixel( pDstScan, nX, pColBuf[ pFncGetPixel( pSrcScan, pMapX[ nX ], rSrcMask ).GetIndex() ], rDstMask );
182 :
183 0 : DOUBLE_SCANLINES();
184 : }
185 : }
186 0 : }
187 :
188 : // -----------------------------------------------------------------------------
189 :
190 0 : static void ImplTCToTC( const BitmapBuffer& rSrcBuffer, BitmapBuffer& rDstBuffer,
191 : FncGetPixel pFncGetPixel, FncSetPixel pFncSetPixel,
192 : Scanline* pSrcScanMap, Scanline* pDstScanMap, long* pMapX, long* pMapY )
193 : {
194 0 : const long nWidth = rDstBuffer.mnWidth, nHeight = rDstBuffer.mnHeight, nHeight1 = nHeight - 1;
195 0 : const ColorMask& rSrcMask = rSrcBuffer.maColorMask;
196 0 : const ColorMask& rDstMask = rDstBuffer.maColorMask;
197 :
198 0 : if( BMP_SCANLINE_FORMAT( rSrcBuffer.mnFormat ) == BMP_FORMAT_24BIT_TC_BGR )
199 : {
200 0 : BitmapColor aCol;
201 0 : sal_uInt8* pPixel = NULL;
202 :
203 0 : for( long nActY = 0, nMapY; nActY < nHeight; nActY++ )
204 : {
205 0 : Scanline pSrcScan( pSrcScanMap[ nMapY = pMapY[ nActY ] ] ), pDstScan( pDstScanMap[ nActY ] );
206 :
207 0 : for( long nX = 0L; nX < nWidth; nX++ )
208 : {
209 0 : aCol.SetBlue( *( pPixel = ( pSrcScan + pMapX[ nX ] * 3 ) )++ );
210 0 : aCol.SetGreen( *pPixel++ );
211 0 : aCol.SetRed( *pPixel );
212 0 : pFncSetPixel( pDstScan, nX, aCol, rDstMask );
213 : }
214 :
215 0 : DOUBLE_SCANLINES()
216 0 : }
217 : }
218 : else
219 : {
220 0 : for( long nActY = 0, nMapY; nActY < nHeight; nActY++ )
221 : {
222 0 : Scanline pSrcScan( pSrcScanMap[ nMapY = pMapY[ nActY ] ] ), pDstScan( pDstScanMap[ nActY ] );
223 :
224 0 : for( long nX = 0L; nX < nWidth; nX++ )
225 0 : pFncSetPixel( pDstScan, nX, pFncGetPixel( pSrcScan, pMapX[ nX ], rSrcMask ), rDstMask );
226 :
227 0 : DOUBLE_SCANLINES();
228 : }
229 : }
230 0 : }
231 :
232 : // -----------------------------------------------------------------------------
233 :
234 0 : static void ImplTCToPAL( const BitmapBuffer& rSrcBuffer, BitmapBuffer& rDstBuffer,
235 : FncGetPixel pFncGetPixel, FncSetPixel pFncSetPixel,
236 : Scanline* pSrcScanMap, Scanline* pDstScanMap, long* pMapX, long* pMapY )
237 : {
238 0 : const long nWidth = rDstBuffer.mnWidth, nHeight = rDstBuffer.mnHeight, nHeight1 = nHeight - 1;
239 0 : const ColorMask& rSrcMask = rSrcBuffer.maColorMask;
240 0 : const ColorMask& rDstMask = rDstBuffer.maColorMask;
241 0 : BitmapPalette aColMap( rSrcBuffer.maPalette.GetEntryCount() );
242 0 : sal_uInt8* pColToPalMap = new sal_uInt8[ TC_TO_PAL_COLORS ];
243 0 : BitmapColor aIndex( 0 );
244 :
245 0 : for( long nR = 0; nR < 16; nR++ )
246 : {
247 0 : for( long nG = 0; nG < 16; nG++ )
248 : {
249 0 : for( long nB = 0; nB < 16; nB++ )
250 : {
251 0 : BitmapColor aCol( sal::static_int_cast<sal_uInt8>(nR << 4),
252 0 : sal::static_int_cast<sal_uInt8>(nG << 4),
253 0 : sal::static_int_cast<sal_uInt8>(nB << 4) );
254 0 : pColToPalMap[ ImplIndexFromColor( aCol ) ] = (sal_uInt8) rDstBuffer.maPalette.GetBestIndex( aCol );
255 0 : }
256 : }
257 : }
258 :
259 0 : for( long nActY = 0, nMapY; nActY < nHeight; nActY++ )
260 : {
261 0 : Scanline pSrcScan( pSrcScanMap[ nMapY = pMapY[ nActY ] ] ), pDstScan( pDstScanMap[ nActY ] );
262 :
263 0 : for( long nX = 0L; nX < nWidth; nX++ )
264 : {
265 0 : aIndex.SetIndex( pColToPalMap[ ImplIndexFromColor( pFncGetPixel( pSrcScan, pMapX[ nX ], rSrcMask ) ) ] );
266 0 : pFncSetPixel( pDstScan, nX, aIndex, rDstMask );
267 : }
268 :
269 0 : DOUBLE_SCANLINES();
270 : }
271 :
272 0 : delete[] pColToPalMap;
273 0 : }
274 :
275 : // -----------------------------------------------------------------------------
276 :
277 : // ---------------------
278 : // - StretchAndConvert -
279 : // ---------------------
280 :
281 0 : BitmapBuffer* StretchAndConvert( const BitmapBuffer& rSrcBuffer, const SalTwoRect& rTwoRect,
282 : sal_uLong nDstBitmapFormat, BitmapPalette* pDstPal, ColorMask* pDstMask )
283 : {
284 : FncGetPixel pFncGetPixel;
285 : FncSetPixel pFncSetPixel;
286 0 : BitmapBuffer* pDstBuffer = new BitmapBuffer;
287 : long i;
288 :
289 : // set function for getting pixels
290 0 : switch( BMP_SCANLINE_FORMAT( rSrcBuffer.mnFormat ) )
291 : {
292 0 : IMPL_CASE_GET_FORMAT( _1BIT_MSB_PAL );
293 0 : IMPL_CASE_GET_FORMAT( _1BIT_LSB_PAL );
294 0 : IMPL_CASE_GET_FORMAT( _4BIT_MSN_PAL );
295 0 : IMPL_CASE_GET_FORMAT( _4BIT_LSN_PAL );
296 0 : IMPL_CASE_GET_FORMAT( _8BIT_PAL );
297 0 : IMPL_CASE_GET_FORMAT( _8BIT_TC_MASK );
298 0 : IMPL_CASE_GET_FORMAT( _16BIT_TC_MSB_MASK );
299 0 : IMPL_CASE_GET_FORMAT( _16BIT_TC_LSB_MASK );
300 0 : IMPL_CASE_GET_FORMAT( _24BIT_TC_BGR );
301 0 : IMPL_CASE_GET_FORMAT( _24BIT_TC_RGB );
302 0 : IMPL_CASE_GET_FORMAT( _24BIT_TC_MASK );
303 0 : IMPL_CASE_GET_FORMAT( _32BIT_TC_ABGR );
304 0 : IMPL_CASE_GET_FORMAT( _32BIT_TC_ARGB );
305 0 : IMPL_CASE_GET_FORMAT( _32BIT_TC_BGRA );
306 0 : IMPL_CASE_GET_FORMAT( _32BIT_TC_RGBA );
307 0 : IMPL_CASE_GET_FORMAT( _32BIT_TC_MASK );
308 :
309 : default:
310 : // should never come here
311 : // initialize pFncGetPixel to something valid that is
312 : // least likely to crash
313 0 : pFncGetPixel = BitmapReadAccess::GetPixelFor_1BIT_MSB_PAL;
314 : OSL_FAIL( "unknown read format" );
315 0 : break;
316 : }
317 :
318 : // set function for setting pixels
319 0 : const sal_uLong nDstScanlineFormat = BMP_SCANLINE_FORMAT( nDstBitmapFormat );
320 0 : switch( nDstScanlineFormat )
321 : {
322 0 : IMPL_CASE_SET_FORMAT( _1BIT_MSB_PAL, 1 );
323 0 : IMPL_CASE_SET_FORMAT( _1BIT_LSB_PAL, 1 );
324 0 : IMPL_CASE_SET_FORMAT( _4BIT_MSN_PAL, 1 );
325 0 : IMPL_CASE_SET_FORMAT( _4BIT_LSN_PAL, 4 );
326 0 : IMPL_CASE_SET_FORMAT( _8BIT_PAL, 8 );
327 0 : IMPL_CASE_SET_FORMAT( _8BIT_TC_MASK, 8 );
328 0 : IMPL_CASE_SET_FORMAT( _16BIT_TC_MSB_MASK, 16 );
329 0 : IMPL_CASE_SET_FORMAT( _16BIT_TC_LSB_MASK, 16 );
330 0 : IMPL_CASE_SET_FORMAT( _24BIT_TC_BGR, 24 );
331 0 : IMPL_CASE_SET_FORMAT( _24BIT_TC_RGB, 24 );
332 0 : IMPL_CASE_SET_FORMAT( _24BIT_TC_MASK, 24 );
333 0 : IMPL_CASE_SET_FORMAT( _32BIT_TC_ABGR, 32 );
334 0 : IMPL_CASE_SET_FORMAT( _32BIT_TC_ARGB, 32 );
335 0 : IMPL_CASE_SET_FORMAT( _32BIT_TC_BGRA, 32 );
336 0 : IMPL_CASE_SET_FORMAT( _32BIT_TC_RGBA, 32 );
337 0 : IMPL_CASE_SET_FORMAT( _32BIT_TC_MASK, 32 );
338 :
339 : default:
340 : // should never come here
341 : // initialize pFncSetPixel to something valid that is
342 : // least likely to crash
343 0 : pFncSetPixel = BitmapReadAccess::SetPixelFor_1BIT_MSB_PAL;
344 0 : pDstBuffer->mnBitCount = 1;
345 : OSL_FAIL( "unknown write format" );
346 0 : break;
347 : }
348 :
349 : // fill destination buffer
350 0 : pDstBuffer->mnFormat = nDstBitmapFormat;
351 0 : pDstBuffer->mnWidth = rTwoRect.mnDestWidth;
352 0 : pDstBuffer->mnHeight = rTwoRect.mnDestHeight;
353 0 : pDstBuffer->mnScanlineSize = AlignedWidth4Bytes( pDstBuffer->mnBitCount * pDstBuffer->mnWidth );
354 : try
355 : {
356 0 : pDstBuffer->mpBits = new sal_uInt8[ pDstBuffer->mnScanlineSize * pDstBuffer->mnHeight ];
357 : }
358 0 : catch( const std::bad_alloc& )
359 : {
360 : // memory exception, clean up
361 0 : pDstBuffer->mpBits = NULL;
362 0 : delete pDstBuffer;
363 0 : return NULL;
364 : }
365 :
366 : // do we need a destination palette or color mask?
367 0 : if( ( nDstScanlineFormat == BMP_FORMAT_1BIT_MSB_PAL ) ||
368 : ( nDstScanlineFormat == BMP_FORMAT_1BIT_LSB_PAL ) ||
369 : ( nDstScanlineFormat == BMP_FORMAT_4BIT_MSN_PAL ) ||
370 : ( nDstScanlineFormat == BMP_FORMAT_4BIT_LSN_PAL ) ||
371 : ( nDstScanlineFormat == BMP_FORMAT_8BIT_PAL ) )
372 : {
373 : DBG_ASSERT( pDstPal, "destination buffer requires palette" );
374 0 : pDstBuffer->maPalette = *pDstPal;
375 : }
376 0 : else if( ( nDstScanlineFormat == BMP_FORMAT_8BIT_TC_MASK ) ||
377 : ( nDstScanlineFormat == BMP_FORMAT_16BIT_TC_MSB_MASK ) ||
378 : ( nDstScanlineFormat == BMP_FORMAT_16BIT_TC_LSB_MASK ) ||
379 : ( nDstScanlineFormat == BMP_FORMAT_24BIT_TC_MASK ) ||
380 : ( nDstScanlineFormat == BMP_FORMAT_32BIT_TC_MASK ) )
381 : {
382 : DBG_ASSERT( pDstMask, "destination buffer requires color mask" );
383 0 : pDstBuffer->maColorMask = *pDstMask;
384 : }
385 :
386 : // short circuit the most important conversions
387 0 : bool bFastConvert = ImplFastBitmapConversion( *pDstBuffer, rSrcBuffer, rTwoRect );
388 0 : if( bFastConvert )
389 0 : return pDstBuffer;
390 :
391 0 : const long nSrcX = rTwoRect.mnSrcX, nSrcY = rTwoRect.mnSrcY;
392 0 : const long nSrcDX = rTwoRect.mnSrcWidth, nSrcDY = rTwoRect.mnSrcHeight;
393 0 : const long nDstDX = rTwoRect.mnDestWidth, nDstDY = rTwoRect.mnDestHeight;
394 0 : Scanline* pSrcScan = NULL;
395 0 : Scanline* pDstScan = NULL;
396 0 : long* pMapX = NULL;
397 0 : long* pMapY = NULL;
398 : long nTmp, nOffset;
399 :
400 : try
401 : {
402 0 : pSrcScan = new Scanline[ rSrcBuffer.mnHeight ];
403 0 : pDstScan = new Scanline[ nDstDY ];
404 0 : pMapX = new long[ nDstDX ];
405 0 : pMapY = new long[ nDstDY ];
406 : }
407 0 : catch( const std::bad_alloc& )
408 : {
409 : // memory exception, clean up
410 : // remark: the buffer ptr causing the exception
411 : // is still NULL here
412 0 : delete[] pSrcScan;
413 0 : delete[] pDstScan;
414 0 : delete[] pMapX;
415 0 : delete[] pMapY;
416 0 : delete pDstBuffer;
417 0 : return NULL;
418 : }
419 :
420 : // horizontal mapping table
421 0 : if( nDstDX != nSrcDX )
422 : {
423 0 : const double fFactorX = ( nDstDX > 1 ) ? (double) ( nSrcDX - 1 ) / ( nDstDX - 1 ) : 0.0;
424 :
425 0 : for( i = 0L; i < nDstDX; i++ )
426 0 : pMapX[ i ] = nSrcX + FRound( i * fFactorX );
427 : }
428 : else
429 : {
430 0 : for( i = 0L, nTmp = nSrcX; i < nDstDX; i++ )
431 0 : pMapX[ i ] = nTmp++;
432 : }
433 :
434 : // vertical mapping table
435 0 : if( nDstDY != nSrcDY )
436 : {
437 0 : const double fFactorY = ( nDstDY > 1 ) ? (double) ( nSrcDY - 1 ) / ( nDstDY - 1 ) : 0.0;
438 :
439 0 : for( i = 0L; i < nDstDY; i++ )
440 0 : pMapY[ i ] = nSrcY + FRound( i * fFactorY );
441 : }
442 : else
443 : {
444 0 : for( i = 0L, nTmp = nSrcY; i < nDstDY; i++ )
445 0 : pMapY[ i ] = nTmp++;
446 : }
447 :
448 : // source scanline buffer
449 : Scanline pTmpScan;
450 0 : if( BMP_SCANLINE_ADJUSTMENT( rSrcBuffer.mnFormat ) == BMP_FORMAT_TOP_DOWN )
451 0 : pTmpScan = rSrcBuffer.mpBits, nOffset = rSrcBuffer.mnScanlineSize;
452 : else
453 : {
454 0 : pTmpScan = rSrcBuffer.mpBits + ( rSrcBuffer.mnHeight - 1 ) * rSrcBuffer.mnScanlineSize;
455 0 : nOffset = -rSrcBuffer.mnScanlineSize;
456 : }
457 :
458 0 : for( i = 0L; i < rSrcBuffer.mnHeight; i++, pTmpScan += nOffset )
459 0 : pSrcScan[ i ] = pTmpScan;
460 :
461 : // destination scanline buffer
462 0 : if( BMP_SCANLINE_ADJUSTMENT( pDstBuffer->mnFormat ) == BMP_FORMAT_TOP_DOWN )
463 0 : pTmpScan = pDstBuffer->mpBits, nOffset = pDstBuffer->mnScanlineSize;
464 : else
465 : {
466 0 : pTmpScan = pDstBuffer->mpBits + ( nDstDY - 1 ) * pDstBuffer->mnScanlineSize;
467 0 : nOffset = -pDstBuffer->mnScanlineSize;
468 : }
469 :
470 0 : for( i = 0L; i < nDstDY; i++, pTmpScan += nOffset )
471 0 : pDstScan[ i ] = pTmpScan;
472 :
473 : // do buffer scaling and conversion
474 0 : if( rSrcBuffer.mnBitCount <= 8 && pDstBuffer->mnBitCount <= 8 )
475 : {
476 : ImplPALToPAL( rSrcBuffer, *pDstBuffer, pFncGetPixel, pFncSetPixel,
477 0 : pSrcScan, pDstScan, pMapX, pMapY );
478 : }
479 0 : else if( rSrcBuffer.mnBitCount <= 8 && pDstBuffer->mnBitCount > 8 )
480 : {
481 : ImplPALToTC( rSrcBuffer, *pDstBuffer, pFncGetPixel, pFncSetPixel,
482 0 : pSrcScan, pDstScan, pMapX, pMapY );
483 : }
484 0 : else if( rSrcBuffer.mnBitCount > 8 && pDstBuffer->mnBitCount > 8 )
485 : {
486 : ImplTCToTC( rSrcBuffer, *pDstBuffer, pFncGetPixel, pFncSetPixel,
487 0 : pSrcScan, pDstScan, pMapX, pMapY );
488 : }
489 : else
490 : {
491 : ImplTCToPAL( rSrcBuffer, *pDstBuffer, pFncGetPixel, pFncSetPixel,
492 0 : pSrcScan, pDstScan, pMapX, pMapY );
493 : }
494 :
495 : // cleanup
496 0 : delete[] pSrcScan;
497 0 : delete[] pDstScan;
498 0 : delete[] pMapX;
499 0 : delete[] pMapY;
500 :
501 0 : return pDstBuffer;
502 : }
503 :
504 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|