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/salbtype.hxx>
21 : #include <vcl/bitmap.hxx>
22 : #include <vcl/bmpacc.hxx>
23 :
24 : #include <impbmp.hxx>
25 :
26 : #include <osl/diagnose.h>
27 :
28 : #include <string.h>
29 :
30 886567 : BitmapInfoAccess::BitmapInfoAccess( Bitmap& rBitmap, BitmapAccessMode nMode ) :
31 : mpBuffer ( NULL ),
32 886567 : mnAccessMode ( nMode )
33 : {
34 886567 : ImplCreate( rBitmap );
35 886567 : }
36 :
37 912 : BitmapInfoAccess::BitmapInfoAccess( Bitmap& rBitmap ) :
38 : mpBuffer ( NULL ),
39 912 : mnAccessMode ( BITMAP_INFO_ACCESS )
40 : {
41 912 : ImplCreate( rBitmap );
42 912 : }
43 :
44 1775870 : BitmapInfoAccess::~BitmapInfoAccess()
45 : {
46 887479 : ImplDestroy();
47 888391 : }
48 :
49 887479 : void BitmapInfoAccess::ImplCreate( Bitmap& rBitmap )
50 : {
51 887479 : ImpBitmap* pImpBmp = rBitmap.ImplGetImpBitmap();
52 :
53 : DBG_ASSERT( pImpBmp, "Forbidden Access to empty bitmap!" );
54 :
55 887479 : if( pImpBmp )
56 : {
57 887478 : if( mnAccessMode == BITMAP_WRITE_ACCESS && !maBitmap.ImplGetImpBitmap() )
58 : {
59 382077 : rBitmap.ImplMakeUnique();
60 382077 : pImpBmp = rBitmap.ImplGetImpBitmap();
61 : }
62 : else
63 : {
64 : DBG_ASSERT( mnAccessMode != BITMAP_WRITE_ACCESS ||
65 : pImpBmp->ImplGetRefCount() == 2,
66 : "Unpredictable results: bitmap is referenced more than once!" );
67 : }
68 :
69 887478 : mpBuffer = pImpBmp->ImplAcquireBuffer( mnAccessMode );
70 :
71 887478 : if( !mpBuffer )
72 : {
73 3 : ImpBitmap* pNewImpBmp = new ImpBitmap;
74 :
75 3 : if( pNewImpBmp->ImplCreate( *pImpBmp, rBitmap.GetBitCount() ) )
76 : {
77 0 : pImpBmp = pNewImpBmp;
78 0 : rBitmap.ImplSetImpBitmap( pImpBmp );
79 0 : mpBuffer = pImpBmp->ImplAcquireBuffer( mnAccessMode );
80 : }
81 : else
82 3 : delete pNewImpBmp;
83 : }
84 :
85 887478 : maBitmap = rBitmap;
86 : }
87 887479 : }
88 :
89 887479 : void BitmapInfoAccess::ImplDestroy()
90 : {
91 887479 : ImpBitmap* pImpBmp = maBitmap.ImplGetImpBitmap();
92 :
93 887479 : if( mpBuffer && pImpBmp )
94 : {
95 887475 : pImpBmp->ImplReleaseBuffer( mpBuffer, mnAccessMode );
96 887475 : mpBuffer = NULL;
97 : }
98 887479 : }
99 :
100 1419855 : sal_uInt16 BitmapInfoAccess::GetBestPaletteIndex( const BitmapColor& rBitmapColor ) const
101 : {
102 1419855 : return( HasPalette() ? mpBuffer->maPalette.GetBestIndex( rBitmapColor ) : 0 );
103 : }
104 :
105 382077 : BitmapReadAccess::BitmapReadAccess( Bitmap& rBitmap, BitmapAccessMode nMode ) :
106 : BitmapInfoAccess( rBitmap, nMode ),
107 : mpScanBuf ( NULL ),
108 : mFncGetPixel ( NULL ),
109 382077 : mFncSetPixel ( NULL )
110 : {
111 382077 : ImplInitScanBuffer( rBitmap );
112 382077 : }
113 :
114 504490 : BitmapReadAccess::BitmapReadAccess( Bitmap& rBitmap ) :
115 : BitmapInfoAccess( rBitmap, BITMAP_READ_ACCESS ),
116 : mpScanBuf ( NULL ),
117 : mFncGetPixel ( NULL ),
118 504490 : mFncSetPixel ( NULL )
119 : {
120 504490 : ImplInitScanBuffer( rBitmap );
121 504490 : }
122 :
123 2277624 : BitmapReadAccess::~BitmapReadAccess()
124 : {
125 886567 : ImplClearScanBuffer();
126 1391057 : }
127 :
128 886567 : void BitmapReadAccess::ImplInitScanBuffer( Bitmap& rBitmap )
129 : {
130 886567 : ImpBitmap* pImpBmp = rBitmap.ImplGetImpBitmap();
131 :
132 886567 : if( pImpBmp && mpBuffer )
133 : {
134 886563 : const long nHeight = mpBuffer->mnHeight;
135 886563 : Scanline pTmpLine = mpBuffer->mpBits;
136 :
137 886563 : mpScanBuf = new Scanline[ nHeight ];
138 886563 : maColorMask = mpBuffer->maColorMask;
139 :
140 886563 : if( BMP_SCANLINE_ADJUSTMENT( mpBuffer->mnFormat ) == BMP_FORMAT_TOP_DOWN )
141 : {
142 3777 : for( long nY = 0L; nY < nHeight; nY++, pTmpLine += mpBuffer->mnScanlineSize )
143 3772 : mpScanBuf[ nY ] = pTmpLine;
144 : }
145 : else
146 : {
147 77089687 : for( long nY = nHeight - 1; nY >= 0; nY--, pTmpLine += mpBuffer->mnScanlineSize )
148 76203129 : mpScanBuf[ nY ] = pTmpLine;
149 : }
150 :
151 886563 : if( !ImplSetAccessPointers( BMP_SCANLINE_FORMAT( mpBuffer->mnFormat ) ) )
152 : {
153 0 : delete[] mpScanBuf;
154 0 : mpScanBuf = NULL;
155 :
156 0 : pImpBmp->ImplReleaseBuffer( mpBuffer, mnAccessMode );
157 0 : mpBuffer = NULL;
158 : }
159 : }
160 886567 : }
161 :
162 886567 : void BitmapReadAccess::ImplClearScanBuffer()
163 : {
164 886567 : delete[] mpScanBuf;
165 886567 : mpScanBuf = NULL;
166 886567 : }
167 :
168 886563 : bool BitmapReadAccess::ImplSetAccessPointers( sal_uLong nFormat )
169 : {
170 886563 : bool bRet = true;
171 :
172 886563 : switch( nFormat )
173 : {
174 : case BMP_FORMAT_1BIT_MSB_PAL:
175 : {
176 4510 : mFncGetPixel = GetPixelFor_1BIT_MSB_PAL;
177 4510 : mFncSetPixel = SetPixelFor_1BIT_MSB_PAL;
178 : }
179 4510 : break;
180 : case BMP_FORMAT_1BIT_LSB_PAL:
181 : {
182 0 : mFncGetPixel = GetPixelFor_1BIT_LSB_PAL;
183 0 : mFncSetPixel = SetPixelFor_1BIT_LSB_PAL;
184 : }
185 0 : break;
186 : case BMP_FORMAT_4BIT_MSN_PAL:
187 : {
188 272 : mFncGetPixel = GetPixelFor_4BIT_MSN_PAL;
189 272 : mFncSetPixel = SetPixelFor_4BIT_MSN_PAL;
190 : }
191 272 : break;
192 : case BMP_FORMAT_4BIT_LSN_PAL:
193 : {
194 0 : mFncGetPixel = GetPixelFor_4BIT_LSN_PAL;
195 0 : mFncSetPixel = SetPixelFor_4BIT_LSN_PAL;
196 : }
197 0 : break;
198 : case BMP_FORMAT_8BIT_PAL:
199 : {
200 460822 : mFncGetPixel = GetPixelFor_8BIT_PAL;
201 460822 : mFncSetPixel = SetPixelFor_8BIT_PAL;
202 : }
203 460822 : break;
204 : case BMP_FORMAT_8BIT_TC_MASK:
205 : {
206 0 : mFncGetPixel = GetPixelFor_8BIT_TC_MASK;
207 0 : mFncSetPixel = SetPixelFor_8BIT_TC_MASK;
208 : }
209 0 : break;
210 : case BMP_FORMAT_16BIT_TC_MSB_MASK:
211 : {
212 0 : mFncGetPixel = GetPixelFor_16BIT_TC_MSB_MASK;
213 0 : mFncSetPixel = SetPixelFor_16BIT_TC_MSB_MASK;
214 : }
215 0 : break;
216 : case BMP_FORMAT_16BIT_TC_LSB_MASK:
217 : {
218 11 : mFncGetPixel = GetPixelFor_16BIT_TC_LSB_MASK;
219 11 : mFncSetPixel = SetPixelFor_16BIT_TC_LSB_MASK;
220 : }
221 11 : break;
222 : case BMP_FORMAT_24BIT_TC_BGR:
223 : {
224 96 : mFncGetPixel = GetPixelFor_24BIT_TC_BGR;
225 96 : mFncSetPixel = SetPixelFor_24BIT_TC_BGR;
226 : }
227 96 : break;
228 : case BMP_FORMAT_24BIT_TC_RGB:
229 : {
230 0 : mFncGetPixel = GetPixelFor_24BIT_TC_RGB;
231 0 : mFncSetPixel = SetPixelFor_24BIT_TC_RGB;
232 : }
233 0 : break;
234 : case BMP_FORMAT_24BIT_TC_MASK:
235 : {
236 0 : mFncGetPixel = GetPixelFor_24BIT_TC_MASK;
237 0 : mFncSetPixel = SetPixelFor_24BIT_TC_MASK;
238 : }
239 0 : break;
240 : case BMP_FORMAT_32BIT_TC_ABGR:
241 : {
242 0 : mFncGetPixel = GetPixelFor_32BIT_TC_ABGR;
243 0 : mFncSetPixel = SetPixelFor_32BIT_TC_ABGR;
244 : }
245 0 : break;
246 : case BMP_FORMAT_32BIT_TC_ARGB:
247 : {
248 0 : mFncGetPixel = GetPixelFor_32BIT_TC_ARGB;
249 0 : mFncSetPixel = SetPixelFor_32BIT_TC_ARGB;
250 : }
251 0 : break;
252 : case BMP_FORMAT_32BIT_TC_BGRA:
253 : {
254 5 : mFncGetPixel = GetPixelFor_32BIT_TC_BGRA;
255 5 : mFncSetPixel = SetPixelFor_32BIT_TC_BGRA;
256 : }
257 5 : break;
258 : case BMP_FORMAT_32BIT_TC_RGBA:
259 : {
260 0 : mFncGetPixel = GetPixelFor_32BIT_TC_RGBA;
261 0 : mFncSetPixel = SetPixelFor_32BIT_TC_RGBA;
262 : }
263 0 : break;
264 : case BMP_FORMAT_32BIT_TC_MASK:
265 : {
266 420847 : mFncGetPixel = GetPixelFor_32BIT_TC_MASK;
267 420847 : mFncSetPixel = SetPixelFor_32BIT_TC_MASK;
268 : }
269 420847 : break;
270 :
271 : default:
272 0 : bRet = false;
273 0 : break;
274 : }
275 :
276 886563 : return bRet;
277 : }
278 :
279 1623 : void BitmapReadAccess::ImplZeroInitUnusedBits()
280 : {
281 1623 : const sal_uInt32 nWidth = Width(), nHeight = Height(), nScanSize = GetScanlineSize();
282 :
283 1623 : if( nWidth && nHeight && nScanSize && GetBuffer() )
284 : {
285 : sal_uInt32 nBits;
286 : bool bMsb;
287 :
288 1623 : const sal_uLong nScanlineFormat = GetScanlineFormat();
289 1623 : switch( nScanlineFormat )
290 : {
291 : case( BMP_FORMAT_1BIT_MSB_PAL ):
292 191 : nBits = 1;
293 191 : bMsb = true;
294 191 : break;
295 :
296 : case( BMP_FORMAT_1BIT_LSB_PAL ):
297 0 : nBits = 1;
298 0 : bMsb = false;
299 0 : break;
300 :
301 : case( BMP_FORMAT_4BIT_MSN_PAL ):
302 41 : nBits = 4;
303 41 : bMsb = true;
304 41 : break;
305 :
306 : case( BMP_FORMAT_4BIT_LSN_PAL ):
307 0 : nBits = 4;
308 0 : bMsb = false;
309 0 : break;
310 :
311 : case( BMP_FORMAT_8BIT_PAL ):
312 : case( BMP_FORMAT_8BIT_TC_MASK ):
313 712 : bMsb = true;
314 712 : nBits = 8;
315 712 : break;
316 :
317 : case( BMP_FORMAT_16BIT_TC_MSB_MASK ):
318 : case( BMP_FORMAT_16BIT_TC_LSB_MASK ):
319 0 : bMsb = true;
320 0 : nBits = 16;
321 0 : break;
322 :
323 : case( BMP_FORMAT_24BIT_TC_BGR ):
324 : case( BMP_FORMAT_24BIT_TC_RGB ):
325 : case( BMP_FORMAT_24BIT_TC_MASK ):
326 0 : bMsb = true;
327 0 : nBits = 24;
328 0 : break;
329 :
330 : case( BMP_FORMAT_32BIT_TC_ABGR ):
331 : case( BMP_FORMAT_32BIT_TC_ARGB ):
332 : case( BMP_FORMAT_32BIT_TC_BGRA ):
333 : case( BMP_FORMAT_32BIT_TC_RGBA ):
334 : case( BMP_FORMAT_32BIT_TC_MASK ):
335 679 : bMsb = true;
336 679 : nBits = 32;
337 679 : break;
338 :
339 : default:
340 : {
341 : OSL_FAIL( "BitmapWriteAccess::ZeroInitUnusedBits: Unsupported pixel format");
342 0 : nBits = 0;
343 0 : bMsb = true;
344 : }
345 0 : break;
346 : }
347 :
348 1623 : nBits *= nWidth;
349 1623 : if( nScanSize % 4 || !bMsb )
350 : {
351 : DBG_ASSERT( 8*nScanSize >= nBits,
352 : "BitmapWriteAccess::ZeroInitUnusedBits: span size smaller than width?!");
353 490 : const sal_uInt32 nLeftOverBits = 8*sizeof(sal_uInt8)*nScanSize - nBits;
354 490 : if( nLeftOverBits != 0 ) // else there is really nothing to do
355 : {
356 104 : const sal_uInt32 nBytes = (nLeftOverBits + 7U) >> 3U;
357 : sal_uInt8 nMask;
358 :
359 104 : if( bMsb )
360 104 : nMask = static_cast<sal_uInt8>(0xffU << (nLeftOverBits & 3UL));
361 : else
362 0 : nMask = static_cast<sal_uInt8>(0xffU >> (nLeftOverBits & 3UL));
363 :
364 104 : sal_uInt8* pLastBytes = reinterpret_cast<sal_uInt8*>(GetBuffer()) + ( nScanSize - nBytes );
365 2422 : for( sal_uInt32 i = 0; i < nHeight; i++, pLastBytes += nScanSize )
366 : {
367 2318 : *pLastBytes &= nMask;
368 2318 : for( sal_uInt32 j = 1; j < nBytes; j++ )
369 0 : pLastBytes[j] = 0;
370 : }
371 490 : }
372 : }
373 1133 : else if( nBits & 0x1f )
374 : {
375 16 : sal_uInt32 nMask = 0xffffffff << ( ( nScanSize << 3 ) - nBits );
376 16 : sal_uInt8* pLast4Bytes = reinterpret_cast<sal_uInt8*>(GetBuffer()) + ( nScanSize - 4 );
377 :
378 : #ifdef OSL_LITENDIAN
379 16 : nMask = OSL_SWAPDWORD( nMask );
380 : #endif
381 4394 : for( sal_uInt32 i = 0; i < nHeight; i++, pLast4Bytes += nScanSize )
382 4378 : *reinterpret_cast<sal_uInt32*>(pLast4Bytes) &= nMask;
383 : }
384 : }
385 1623 : }
386 :
387 1524200 : BitmapColor BitmapReadAccess::GetInterpolatedColorWithFallback( double fY, double fX, const BitmapColor& rFallback ) const
388 : {
389 : // ask directly doubles >= 0.0 here to avoid rounded values of 0 at small negative
390 : // double values, e.g. static_cast< sal_Int32 >(-0.25) is 0, not -1, but *has* to be outside (!)
391 1524200 : if(mpBuffer && fX >= 0.0 && fY >= 0.0)
392 : {
393 1490708 : const sal_Int32 nX(static_cast< sal_Int32 >(fX));
394 1490708 : const sal_Int32 nY(static_cast< sal_Int32 >(fY));
395 :
396 1490708 : if(nX < mpBuffer->mnWidth && nY < mpBuffer->mnHeight)
397 : {
398 : // get base-return value from inside pixel
399 1475236 : BitmapColor aRetval(GetColor(nY, nX));
400 :
401 : // calculate deltas and indices for neighbour accesses
402 1475236 : sal_Int16 nDeltaX((fX - (nX + 0.5)) * 255.0); // [-255 .. 255]
403 1475236 : sal_Int16 nDeltaY((fY - (nY + 0.5)) * 255.0); // [-255 .. 255]
404 1475236 : sal_Int16 nIndX(0);
405 1475236 : sal_Int16 nIndY(0);
406 :
407 1475236 : if(nDeltaX > 0)
408 : {
409 735212 : nIndX = nX + 1;
410 : }
411 : else
412 : {
413 740024 : nIndX = nX - 1;
414 740024 : nDeltaX = -nDeltaX;
415 : }
416 :
417 1475236 : if(nDeltaY > 0)
418 : {
419 730660 : nIndY = nY + 1;
420 : }
421 : else
422 : {
423 744576 : nIndY = nY - 1;
424 744576 : nDeltaY = -nDeltaY;
425 : }
426 :
427 : // get right/left neighbour
428 2950472 : BitmapColor aXCol(rFallback);
429 :
430 1475236 : if(nDeltaX && nIndX >= 0 && nIndX < mpBuffer->mnWidth)
431 : {
432 1461896 : aXCol = GetColor(nY, nIndX);
433 : }
434 :
435 : // get top/bottom neighbour
436 2950472 : BitmapColor aYCol(rFallback);
437 :
438 1475236 : if(nDeltaY && nIndY >= 0 && nIndY < mpBuffer->mnHeight)
439 : {
440 1463148 : aYCol = GetColor(nIndY, nX);
441 : }
442 :
443 : // get one of four edge neighbours
444 2950472 : BitmapColor aXYCol(rFallback);
445 :
446 1475236 : if(nDeltaX && nDeltaY && nIndX >=0 && nIndY >= 0 && nIndX < mpBuffer->mnWidth && nIndY < mpBuffer->mnHeight)
447 : {
448 1449924 : aXYCol = GetColor(nIndY, nIndX);
449 : }
450 :
451 : // merge return value with right/left neighbour
452 1475236 : if(aXCol != aRetval)
453 : {
454 240036 : aRetval.Merge(aXCol, 255 - nDeltaX);
455 : }
456 :
457 : // merge top/bottom neighbour with edge
458 1475236 : if(aYCol != aXYCol)
459 : {
460 238320 : aYCol.Merge(aXYCol, 255 - nDeltaX);
461 : }
462 :
463 : // merge return value with already merged top/bottom neighbour
464 1475236 : if(aRetval != aYCol)
465 : {
466 238270 : aRetval.Merge(aYCol, 255 - nDeltaY);
467 : }
468 :
469 2950472 : return aRetval;
470 : }
471 : }
472 :
473 48964 : return rFallback;
474 : }
475 :
476 0 : BitmapColor BitmapReadAccess::GetColorWithFallback( double fY, double fX, const BitmapColor& rFallback ) const
477 : {
478 : // ask directly doubles >= 0.0 here to avoid rounded values of 0 at small negative
479 : // double values, e.g. static_cast< sal_Int32 >(-0.25) is 0, not -1, but *has* to be outside (!)
480 0 : if(mpBuffer && fX >= 0.0 && fY >= 0.0)
481 : {
482 0 : const sal_Int32 nX(static_cast< sal_Int32 >(fX));
483 0 : const sal_Int32 nY(static_cast< sal_Int32 >(fY));
484 :
485 0 : if(nX < mpBuffer->mnWidth && nY < mpBuffer->mnHeight)
486 : {
487 0 : return GetColor(nY, nX);
488 : }
489 : }
490 :
491 0 : return rFallback;
492 : }
493 :
494 382077 : BitmapWriteAccess::BitmapWriteAccess(Bitmap& rBitmap)
495 : : BitmapReadAccess(rBitmap, BITMAP_WRITE_ACCESS)
496 : , mpLineColor()
497 382077 : , mpFillColor()
498 : {
499 382077 : }
500 :
501 764154 : BitmapWriteAccess::~BitmapWriteAccess()
502 : {
503 764154 : }
504 :
505 0 : void BitmapWriteAccess::CopyScanline( long nY, const BitmapReadAccess& rReadAcc )
506 : {
507 : assert(nY >= 0 && nY < mpBuffer->mnHeight && "y-coordinate in destination out of range!");
508 : DBG_ASSERT( nY < rReadAcc.Height(), "y-coordinate in source out of range!" );
509 : DBG_ASSERT( ( HasPalette() && rReadAcc.HasPalette() ) || ( !HasPalette() && !rReadAcc.HasPalette() ), "No copying possible between palette bitmap and TC bitmap!" );
510 :
511 0 : if( ( GetScanlineFormat() == rReadAcc.GetScanlineFormat() ) &&
512 0 : ( GetScanlineSize() >= rReadAcc.GetScanlineSize() ) )
513 : {
514 0 : memcpy( mpScanBuf[ nY ], rReadAcc.GetScanline( nY ), rReadAcc.GetScanlineSize() );
515 : }
516 : else
517 : // TODO: use fastbmp infrastructure
518 0 : for( long nX = 0L, nWidth = std::min( mpBuffer->mnWidth, rReadAcc.Width() ); nX < nWidth; nX++ )
519 0 : SetPixel( nY, nX, rReadAcc.GetPixel( nY, nX ) );
520 0 : }
521 :
522 786789 : void BitmapWriteAccess::CopyScanline( long nY, ConstScanline aSrcScanline,
523 : sal_uLong nSrcScanlineFormat, sal_uLong nSrcScanlineSize )
524 : {
525 786789 : const sal_uLong nFormat = BMP_SCANLINE_FORMAT( nSrcScanlineFormat );
526 :
527 : assert(nY >= 0 && nY < mpBuffer->mnHeight && "y-coordinate in destination out of range!");
528 : DBG_ASSERT( ( HasPalette() && nFormat <= BMP_FORMAT_8BIT_PAL ) ||
529 : ( !HasPalette() && nFormat > BMP_FORMAT_8BIT_PAL ),
530 : "No copying possible between palette and non palette scanlines!" );
531 :
532 786789 : const sal_uLong nCount = std::min( GetScanlineSize(), nSrcScanlineSize );
533 :
534 786789 : if( nCount )
535 : {
536 786789 : if( GetScanlineFormat() == BMP_SCANLINE_FORMAT( nSrcScanlineFormat ) )
537 309309 : memcpy( mpScanBuf[ nY ], aSrcScanline, nCount );
538 : else
539 : {
540 : DBG_ASSERT( nFormat != BMP_FORMAT_8BIT_TC_MASK &&
541 : nFormat != BMP_FORMAT_16BIT_TC_MSB_MASK && nFormat != BMP_FORMAT_16BIT_TC_LSB_MASK &&
542 : nFormat != BMP_FORMAT_24BIT_TC_MASK && nFormat != BMP_FORMAT_32BIT_TC_MASK,
543 : "No support for pixel formats with color masks yet!" );
544 :
545 : // TODO: use fastbmp infrastructure
546 : FncGetPixel pFncGetPixel;
547 :
548 477480 : switch( nFormat )
549 : {
550 0 : case( BMP_FORMAT_1BIT_MSB_PAL ): pFncGetPixel = GetPixelFor_1BIT_MSB_PAL; break;
551 0 : case( BMP_FORMAT_1BIT_LSB_PAL ): pFncGetPixel = GetPixelFor_1BIT_LSB_PAL; break;
552 0 : case( BMP_FORMAT_4BIT_MSN_PAL ): pFncGetPixel = GetPixelFor_4BIT_MSN_PAL; break;
553 0 : case( BMP_FORMAT_4BIT_LSN_PAL ): pFncGetPixel = GetPixelFor_4BIT_LSN_PAL; break;
554 0 : case( BMP_FORMAT_8BIT_PAL ): pFncGetPixel = GetPixelFor_8BIT_PAL; break;
555 0 : case( BMP_FORMAT_8BIT_TC_MASK ): pFncGetPixel = GetPixelFor_8BIT_TC_MASK; break;
556 0 : case( BMP_FORMAT_16BIT_TC_MSB_MASK ): pFncGetPixel = GetPixelFor_16BIT_TC_MSB_MASK; break;
557 0 : case( BMP_FORMAT_16BIT_TC_LSB_MASK ): pFncGetPixel = GetPixelFor_16BIT_TC_LSB_MASK; break;
558 477480 : case( BMP_FORMAT_24BIT_TC_BGR ): pFncGetPixel = GetPixelFor_24BIT_TC_BGR; break;
559 0 : case( BMP_FORMAT_24BIT_TC_RGB ): pFncGetPixel = GetPixelFor_24BIT_TC_RGB; break;
560 0 : case( BMP_FORMAT_24BIT_TC_MASK ): pFncGetPixel = GetPixelFor_24BIT_TC_MASK; break;
561 0 : case( BMP_FORMAT_32BIT_TC_ABGR ): pFncGetPixel = GetPixelFor_32BIT_TC_ABGR; break;
562 0 : case( BMP_FORMAT_32BIT_TC_ARGB ): pFncGetPixel = GetPixelFor_32BIT_TC_ARGB; break;
563 0 : case( BMP_FORMAT_32BIT_TC_BGRA ): pFncGetPixel = GetPixelFor_32BIT_TC_BGRA; break;
564 0 : case( BMP_FORMAT_32BIT_TC_RGBA ): pFncGetPixel = GetPixelFor_32BIT_TC_RGBA; break;
565 0 : case( BMP_FORMAT_32BIT_TC_MASK ): pFncGetPixel = GetPixelFor_32BIT_TC_MASK; break;
566 :
567 : default:
568 0 : pFncGetPixel = NULL;
569 0 : break;
570 : }
571 :
572 477480 : if( pFncGetPixel )
573 : {
574 477480 : const ColorMask aDummyMask;
575 :
576 202235396 : for( long nX = 0L, nWidth = mpBuffer->mnWidth; nX < nWidth; nX++ )
577 202235396 : SetPixel( nY, nX, pFncGetPixel( aSrcScanline, nX, aDummyMask ) );
578 : }
579 : }
580 : }
581 786789 : }
582 :
583 0 : void BitmapWriteAccess::CopyBuffer( const BitmapReadAccess& rReadAcc )
584 : {
585 : DBG_ASSERT( ( HasPalette() && rReadAcc.HasPalette() ) || ( !HasPalette() && !rReadAcc.HasPalette() ), "No copying possible between palette bitmap and TC bitmap!" );
586 :
587 0 : if( ( GetScanlineFormat() == rReadAcc.GetScanlineFormat() ) &&
588 0 : ( GetScanlineSize() == rReadAcc.GetScanlineSize() ) )
589 : {
590 0 : const long nHeight = std::min( mpBuffer->mnHeight, rReadAcc.Height() );
591 0 : const sal_uLong nCount = nHeight * mpBuffer->mnScanlineSize;
592 :
593 0 : memcpy( mpBuffer->mpBits, rReadAcc.GetBuffer(), nCount );
594 : }
595 : else
596 0 : for( long nY = 0L, nHeight = std::min( mpBuffer->mnHeight, rReadAcc.Height() ); nY < nHeight; nY++ )
597 0 : CopyScanline( nY, rReadAcc );
598 0 : }
599 :
600 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|