bitmap4.cxx (c1e8cc3a) | bitmap4.cxx (f2e5373e) |
---|---|
1/************************************************************** | 1/************************************************************** |
2 * | 2 * |
3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at | 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at |
10 * | 10 * |
11 * http://www.apache.org/licenses/LICENSE-2.0 | 11 * http://www.apache.org/licenses/LICENSE-2.0 |
12 * | 12 * |
13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. | 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. |
19 * | 19 * |
20 *************************************************************/ 21 22 23 24// MARKER(update_precomp.py): autogen include statement, do not remove 25#include "precompiled_vcl.hxx" 26 27#include <stdlib.h> --- 106 unchanged lines hidden (view full) --- 134 // create LUT of products of matrix value and possible color component values 135 for( nY = 0; nY < 9; nY++ ) 136 for( nX = nTmp = 0, nMatrixVal = pMatrix[ nY ]; nX < 256; nX++, nTmp += nMatrixVal ) 137 pKoeff[ nY ][ nX ] = nTmp; 138 139 // create column LUT 140 for( i = 0; i < nWidth2; i++ ) 141 pColm[ i ] = ( i > 0 ) ? ( i - 1 ) : 0; | 20 *************************************************************/ 21 22 23 24// MARKER(update_precomp.py): autogen include statement, do not remove 25#include "precompiled_vcl.hxx" 26 27#include <stdlib.h> --- 106 unchanged lines hidden (view full) --- 134 // create LUT of products of matrix value and possible color component values 135 for( nY = 0; nY < 9; nY++ ) 136 for( nX = nTmp = 0, nMatrixVal = pMatrix[ nY ]; nX < 256; nX++, nTmp += nMatrixVal ) 137 pKoeff[ nY ][ nX ] = nTmp; 138 139 // create column LUT 140 for( i = 0; i < nWidth2; i++ ) 141 pColm[ i ] = ( i > 0 ) ? ( i - 1 ) : 0; |
142 | 142 |
143 pColm[ nWidth + 1 ] = pColm[ nWidth ]; 144 145 // create row LUT 146 for( i = 0; i < nHeight2; i++ ) 147 pRows[ i ] = ( i > 0 ) ? ( i - 1 ) : 0; | 143 pColm[ nWidth + 1 ] = pColm[ nWidth ]; 144 145 // create row LUT 146 for( i = 0; i < nHeight2; i++ ) 147 pRows[ i ] = ( i > 0 ) ? ( i - 1 ) : 0; |
148 | 148 |
149 pRows[ nHeight + 1 ] = pRows[ nHeight ]; 150 151 // read first three rows of bitmap color 152 for( i = 0; i < nWidth2; i++ ) 153 { 154 pColRow1[ i ] = pReadAcc->GetColor( pRows[ 0 ], pColm[ i ] ); 155 pColRow2[ i ] = pReadAcc->GetColor( pRows[ 1 ], pColm[ i ] ); 156 pColRow3[ i ] = pReadAcc->GetColor( pRows[ 2 ], pColm[ i ] ); --- 120 unchanged lines hidden (view full) --- 277 long nY, nX, i; 278 long nR1, nR2, nR3, nR4, nR5, nR6, nR7, nR8, nR9; 279 long nG1, nG2, nG3, nG4, nG5, nG6, nG7, nG8, nG9; 280 long nB1, nB2, nB3, nB4, nB5, nB6, nB7, nB8, nB9; 281 282 // create column LUT 283 for( i = 0; i < nWidth2; i++ ) 284 pColm[ i ] = ( i > 0 ) ? ( i - 1 ) : 0; | 149 pRows[ nHeight + 1 ] = pRows[ nHeight ]; 150 151 // read first three rows of bitmap color 152 for( i = 0; i < nWidth2; i++ ) 153 { 154 pColRow1[ i ] = pReadAcc->GetColor( pRows[ 0 ], pColm[ i ] ); 155 pColRow2[ i ] = pReadAcc->GetColor( pRows[ 1 ], pColm[ i ] ); 156 pColRow3[ i ] = pReadAcc->GetColor( pRows[ 2 ], pColm[ i ] ); --- 120 unchanged lines hidden (view full) --- 277 long nY, nX, i; 278 long nR1, nR2, nR3, nR4, nR5, nR6, nR7, nR8, nR9; 279 long nG1, nG2, nG3, nG4, nG5, nG6, nG7, nG8, nG9; 280 long nB1, nB2, nB3, nB4, nB5, nB6, nB7, nB8, nB9; 281 282 // create column LUT 283 for( i = 0; i < nWidth2; i++ ) 284 pColm[ i ] = ( i > 0 ) ? ( i - 1 ) : 0; |
285 | 285 |
286 pColm[ nWidth + 1 ] = pColm[ nWidth ]; 287 288 // create row LUT 289 for( i = 0; i < nHeight2; i++ ) 290 pRows[ i ] = ( i > 0 ) ? ( i - 1 ) : 0; | 286 pColm[ nWidth + 1 ] = pColm[ nWidth ]; 287 288 // create row LUT 289 for( i = 0; i < nHeight2; i++ ) 290 pRows[ i ] = ( i > 0 ) ? ( i - 1 ) : 0; |
291 | 291 |
292 pRows[ nHeight + 1 ] = pRows[ nHeight ]; 293 294 // read first three rows of bitmap color 295 if (nHeight2 > 2) 296 { | 292 pRows[ nHeight + 1 ] = pRows[ nHeight ]; 293 294 // read first three rows of bitmap color 295 if (nHeight2 > 2) 296 { |
297 for( i = 0; i < nWidth2; i++ ) 298 { 299 pColRow1[ i ] = pReadAcc->GetColor( pRows[ 0 ], pColm[ i ] ); 300 pColRow2[ i ] = pReadAcc->GetColor( pRows[ 1 ], pColm[ i ] ); 301 pColRow3[ i ] = pReadAcc->GetColor( pRows[ 2 ], pColm[ i ] ); 302 } | 297 for( i = 0; i < nWidth2; i++ ) 298 { 299 pColRow1[ i ] = pReadAcc->GetColor( pRows[ 0 ], pColm[ i ] ); 300 pColRow2[ i ] = pReadAcc->GetColor( pRows[ 1 ], pColm[ i ] ); 301 pColRow3[ i ] = pReadAcc->GetColor( pRows[ 2 ], pColm[ i ] ); 302 } |
303 } 304 305 // do median filtering 306 for( nY = 0; nY < nHeight; ) 307 { 308 for( nX = 0; nX < nWidth; nX++ ) 309 { 310 nR1 = ( pColor = pRowTmp1 + nX )->GetRed(), nG1 = pColor->GetGreen(), nB1 = pColor->GetBlue(); 311 nR2 = ( ++pColor )->GetRed(), nG2 = pColor->GetGreen(), nB2 = pColor->GetBlue(); 312 nR3 = ( ++pColor )->GetRed(), nG3 = pColor->GetGreen(), nB3 = pColor->GetBlue(); | 303 } 304 305 // do median filtering 306 for( nY = 0; nY < nHeight; ) 307 { 308 for( nX = 0; nX < nWidth; nX++ ) 309 { 310 nR1 = ( pColor = pRowTmp1 + nX )->GetRed(), nG1 = pColor->GetGreen(), nB1 = pColor->GetBlue(); 311 nR2 = ( ++pColor )->GetRed(), nG2 = pColor->GetGreen(), nB2 = pColor->GetBlue(); 312 nR3 = ( ++pColor )->GetRed(), nG3 = pColor->GetGreen(), nB3 = pColor->GetBlue(); |
313 | 313 |
314 nR4 = ( pColor = pRowTmp2 + nX )->GetRed(), nG4 = pColor->GetGreen(), nB4 = pColor->GetBlue(); 315 nR5 = ( ++pColor )->GetRed(), nG5 = pColor->GetGreen(), nB5 = pColor->GetBlue(); 316 nR6 = ( ++pColor )->GetRed(), nG6 = pColor->GetGreen(), nB6 = pColor->GetBlue(); 317 318 nR7 = ( pColor = pRowTmp3 + nX )->GetRed(), nG7 = pColor->GetGreen(), nB7 = pColor->GetBlue(); 319 nR8 = ( ++pColor )->GetRed(), nG8 = pColor->GetGreen(), nB8 = pColor->GetBlue(); 320 nR9 = ( ++pColor )->GetRed(), nG9 = pColor->GetGreen(), nB9 = pColor->GetBlue(); | 314 nR4 = ( pColor = pRowTmp2 + nX )->GetRed(), nG4 = pColor->GetGreen(), nB4 = pColor->GetBlue(); 315 nR5 = ( ++pColor )->GetRed(), nG5 = pColor->GetGreen(), nB5 = pColor->GetBlue(); 316 nR6 = ( ++pColor )->GetRed(), nG6 = pColor->GetGreen(), nB6 = pColor->GetBlue(); 317 318 nR7 = ( pColor = pRowTmp3 + nX )->GetRed(), nG7 = pColor->GetGreen(), nB7 = pColor->GetBlue(); 319 nR8 = ( ++pColor )->GetRed(), nG8 = pColor->GetGreen(), nB8 = pColor->GetBlue(); 320 nR9 = ( ++pColor )->GetRed(), nG9 = pColor->GetGreen(), nB9 = pColor->GetBlue(); |
321 | 321 |
322 MNMX6( nR1, nR2, nR3, nR4, nR5, nR6 ); | 322 MNMX6( nR1, nR2, nR3, nR4, nR5, nR6 ); |
323 MNMX5( nR7, nR2, nR3, nR4, nR5 ); 324 MNMX4( nR8, nR2, nR3, nR4 ); 325 MNMX3( nR9, nR2, nR3 ); | 323 MNMX5( nR7, nR2, nR3, nR4, nR5 ); 324 MNMX4( nR8, nR2, nR3, nR4 ); 325 MNMX3( nR9, nR2, nR3 ); |
326 327 MNMX6( nG1, nG2, nG3, nG4, nG5, nG6 ); | 326 327 MNMX6( nG1, nG2, nG3, nG4, nG5, nG6 ); |
328 MNMX5( nG7, nG2, nG3, nG4, nG5 ); 329 MNMX4( nG8, nG2, nG3, nG4 ); 330 MNMX3( nG9, nG2, nG3 ); | 328 MNMX5( nG7, nG2, nG3, nG4, nG5 ); 329 MNMX4( nG8, nG2, nG3, nG4 ); 330 MNMX3( nG9, nG2, nG3 ); |
331 332 MNMX6( nB1, nB2, nB3, nB4, nB5, nB6 ); | 331 332 MNMX6( nB1, nB2, nB3, nB4, nB5, nB6 ); |
333 MNMX5( nB7, nB2, nB3, nB4, nB5 ); 334 MNMX4( nB8, nB2, nB3, nB4 ); 335 MNMX3( nB9, nB2, nB3 ); 336 | 333 MNMX5( nB7, nB2, nB3, nB4, nB5 ); 334 MNMX4( nB8, nB2, nB3, nB4 ); 335 MNMX3( nB9, nB2, nB3 ); 336 |
337 // set destination color 338 pWriteAcc->SetPixel( nY, nX, BitmapColor( (sal_uInt8) nR2, (sal_uInt8) nG2, (sal_uInt8) nB2 ) ); 339 } 340 341 if( ++nY < nHeight ) 342 { 343 if( pRowTmp1 == pColRow1 ) 344 pRowTmp1 = pColRow2, pRowTmp2 = pColRow3, pRowTmp3 = pColRow1; --- 41 unchanged lines hidden (view full) --- 386{ 387 sal_Bool bRet = ImplMakeGreyscales( 256 ); 388 389 if( bRet ) 390 { 391 bRet = sal_False; 392 393 BitmapReadAccess* pReadAcc = AcquireReadAccess(); | 337 // set destination color 338 pWriteAcc->SetPixel( nY, nX, BitmapColor( (sal_uInt8) nR2, (sal_uInt8) nG2, (sal_uInt8) nB2 ) ); 339 } 340 341 if( ++nY < nHeight ) 342 { 343 if( pRowTmp1 == pColRow1 ) 344 pRowTmp1 = pColRow2, pRowTmp2 = pColRow3, pRowTmp3 = pColRow1; --- 41 unchanged lines hidden (view full) --- 386{ 387 sal_Bool bRet = ImplMakeGreyscales( 256 ); 388 389 if( bRet ) 390 { 391 bRet = sal_False; 392 393 BitmapReadAccess* pReadAcc = AcquireReadAccess(); |
394 | 394 |
395 if( pReadAcc ) 396 { 397 Bitmap aNewBmp( GetSizePixel(), 8, &pReadAcc->GetPalette() ); 398 BitmapWriteAccess* pWriteAcc = aNewBmp.AcquireWriteAccess(); 399 400 if( pWriteAcc ) 401 { 402 BitmapColor aGrey( (sal_uInt8) 0 ); --- 111 unchanged lines hidden (view full) --- 514{ 515 sal_Bool bRet = ImplMakeGreyscales( 256 ); 516 517 if( bRet ) 518 { 519 bRet = sal_False; 520 521 BitmapReadAccess* pReadAcc = AcquireReadAccess(); | 395 if( pReadAcc ) 396 { 397 Bitmap aNewBmp( GetSizePixel(), 8, &pReadAcc->GetPalette() ); 398 BitmapWriteAccess* pWriteAcc = aNewBmp.AcquireWriteAccess(); 399 400 if( pWriteAcc ) 401 { 402 BitmapColor aGrey( (sal_uInt8) 0 ); --- 111 unchanged lines hidden (view full) --- 514{ 515 sal_Bool bRet = ImplMakeGreyscales( 256 ); 516 517 if( bRet ) 518 { 519 bRet = sal_False; 520 521 BitmapReadAccess* pReadAcc = AcquireReadAccess(); |
522 | 522 |
523 if( pReadAcc ) 524 { 525 Bitmap aNewBmp( GetSizePixel(), 8, &pReadAcc->GetPalette() ); 526 BitmapWriteAccess* pWriteAcc = aNewBmp.AcquireWriteAccess(); 527 528 if( pWriteAcc ) 529 { 530 BitmapColor aGrey( (sal_uInt8) 0 ); --- 48 unchanged lines hidden (view full) --- 579 aGrey.SetIndex( cLz ); 580 else if( ( nDotL = nNx * nLx + nNy * nLy +nNzLz ) < 0 ) 581 aGrey.SetIndex( 0 ); 582 else 583 { 584 const double fGrey = nDotL / sqrt( (double)(nNx * nNx + nNy * nNy + nZ2) ); 585 aGrey.SetIndex( (sal_uInt8) VOS_BOUND( fGrey, 0, 255 ) ); 586 } | 523 if( pReadAcc ) 524 { 525 Bitmap aNewBmp( GetSizePixel(), 8, &pReadAcc->GetPalette() ); 526 BitmapWriteAccess* pWriteAcc = aNewBmp.AcquireWriteAccess(); 527 528 if( pWriteAcc ) 529 { 530 BitmapColor aGrey( (sal_uInt8) 0 ); --- 48 unchanged lines hidden (view full) --- 579 aGrey.SetIndex( cLz ); 580 else if( ( nDotL = nNx * nLx + nNy * nLy +nNzLz ) < 0 ) 581 aGrey.SetIndex( 0 ); 582 else 583 { 584 const double fGrey = nDotL / sqrt( (double)(nNx * nNx + nNy * nNy + nZ2) ); 585 aGrey.SetIndex( (sal_uInt8) VOS_BOUND( fGrey, 0, 255 ) ); 586 } |
587 | 587 |
588 pWriteAcc->SetPixel( nY, nX, aGrey ); 589 590 if( nX < ( nWidth - 1 ) ) 591 { 592 const long nNextX = pHMap[ nX + 3 ]; 593 594 nGrey11 = nGrey12; nGrey12 = nGrey13; nGrey13 = pReadAcc->GetPixel( pVMap[ nY ], nNextX ).GetIndex(); 595 nGrey21 = nGrey22; nGrey22 = nGrey23; nGrey23 = pReadAcc->GetPixel( pVMap[ nY + 1 ], nNextX ).GetIndex(); --- 27 unchanged lines hidden (view full) --- 623} 624 625// ----------------------------------------------------------------------------- 626 627sal_Bool Bitmap::ImplSolarize( const BmpFilterParam* pFilterParam, const Link* /*pProgress*/ ) 628{ 629 sal_Bool bRet = sal_False; 630 BitmapWriteAccess* pWriteAcc = AcquireWriteAccess(); | 588 pWriteAcc->SetPixel( nY, nX, aGrey ); 589 590 if( nX < ( nWidth - 1 ) ) 591 { 592 const long nNextX = pHMap[ nX + 3 ]; 593 594 nGrey11 = nGrey12; nGrey12 = nGrey13; nGrey13 = pReadAcc->GetPixel( pVMap[ nY ], nNextX ).GetIndex(); 595 nGrey21 = nGrey22; nGrey22 = nGrey23; nGrey23 = pReadAcc->GetPixel( pVMap[ nY + 1 ], nNextX ).GetIndex(); --- 27 unchanged lines hidden (view full) --- 623} 624 625// ----------------------------------------------------------------------------- 626 627sal_Bool Bitmap::ImplSolarize( const BmpFilterParam* pFilterParam, const Link* /*pProgress*/ ) 628{ 629 sal_Bool bRet = sal_False; 630 BitmapWriteAccess* pWriteAcc = AcquireWriteAccess(); |
631 | 631 |
632 if( pWriteAcc ) 633 { | 632 if( pWriteAcc ) 633 { |
634 const sal_uInt8 cThreshold = ( pFilterParam && pFilterParam->meFilter == BMP_FILTER_SOLARIZE ) ? | 634 const sal_uInt8 cThreshold = ( pFilterParam && pFilterParam->meFilter == BMP_FILTER_SOLARIZE ) ? |
635 pFilterParam->mcSolarGreyThreshold : 128; 636 637 if( pWriteAcc->HasPalette() ) 638 { 639 const BitmapPalette& rPal = pWriteAcc->GetPalette(); 640 641 for( sal_uInt16 i = 0, nCount = rPal.GetEntryCount(); i < nCount; i++ ) 642 { --- 10 unchanged lines hidden (view full) --- 653 const long nWidth = pWriteAcc->Width(); 654 const long nHeight = pWriteAcc->Height(); 655 656 for( long nY = 0; nY < nHeight ; nY++ ) 657 { 658 for( long nX = 0; nX < nWidth; nX++ ) 659 { 660 aCol = pWriteAcc->GetPixel( nY, nX ); | 635 pFilterParam->mcSolarGreyThreshold : 128; 636 637 if( pWriteAcc->HasPalette() ) 638 { 639 const BitmapPalette& rPal = pWriteAcc->GetPalette(); 640 641 for( sal_uInt16 i = 0, nCount = rPal.GetEntryCount(); i < nCount; i++ ) 642 { --- 10 unchanged lines hidden (view full) --- 653 const long nWidth = pWriteAcc->Width(); 654 const long nHeight = pWriteAcc->Height(); 655 656 for( long nY = 0; nY < nHeight ; nY++ ) 657 { 658 for( long nX = 0; nX < nWidth; nX++ ) 659 { 660 aCol = pWriteAcc->GetPixel( nY, nX ); |
661 | 661 |
662 if( aCol.GetLuminance() >= cThreshold ) 663 pWriteAcc->SetPixel( nY, nX, aCol.Invert() ); 664 } 665 } 666 } 667 668 ReleaseAccess( pWriteAcc ); 669 bRet = sal_True; 670 } 671 672 return bRet; 673} 674 675// ----------------------------------------------------------------------------- 676 677sal_Bool Bitmap::ImplSepia( const BmpFilterParam* pFilterParam, const Link* /*pProgress*/ ) 678{ 679 BitmapReadAccess* pReadAcc = AcquireReadAccess(); 680 sal_Bool bRet = sal_False; | 662 if( aCol.GetLuminance() >= cThreshold ) 663 pWriteAcc->SetPixel( nY, nX, aCol.Invert() ); 664 } 665 } 666 } 667 668 ReleaseAccess( pWriteAcc ); 669 bRet = sal_True; 670 } 671 672 return bRet; 673} 674 675// ----------------------------------------------------------------------------- 676 677sal_Bool Bitmap::ImplSepia( const BmpFilterParam* pFilterParam, const Link* /*pProgress*/ ) 678{ 679 BitmapReadAccess* pReadAcc = AcquireReadAccess(); 680 sal_Bool bRet = sal_False; |
681 | 681 |
682 if( pReadAcc ) 683 { | 682 if( pReadAcc ) 683 { |
684 long nSepiaPercent = ( pFilterParam && pFilterParam->meFilter == BMP_FILTER_SEPIA ) ? 685 pFilterParam->mcSolarGreyThreshold : 10; | 684 long nSepiaPercent = ( pFilterParam && pFilterParam->meFilter == BMP_FILTER_SEPIA ) ? 685 pFilterParam->mcSolarGreyThreshold : 10; |
686 const long nSepia = 10000 - 100 * VOS_BOUND( nSepiaPercent, 0, 100 ); 687 BitmapPalette aSepiaPal( 256 ); 688 689 DBG_ASSERT( nSepiaPercent <= 100, "Bitmap::ImplSepia(): sepia value out of range; defaulting to 100%" ); 690 691 for( sal_uInt16 i = 0; i < 256; i++ ) 692 { 693 BitmapColor& rCol = aSepiaPal[ i ]; --- 64 unchanged lines hidden (view full) --- 758 759 return bRet; 760} 761 762// ----------------------------------------------------------------------------- 763 764sal_Bool Bitmap::ImplMosaic( const BmpFilterParam* pFilterParam, const Link* /*pProgress*/ ) 765{ | 686 const long nSepia = 10000 - 100 * VOS_BOUND( nSepiaPercent, 0, 100 ); 687 BitmapPalette aSepiaPal( 256 ); 688 689 DBG_ASSERT( nSepiaPercent <= 100, "Bitmap::ImplSepia(): sepia value out of range; defaulting to 100%" ); 690 691 for( sal_uInt16 i = 0; i < 256; i++ ) 692 { 693 BitmapColor& rCol = aSepiaPal[ i ]; --- 64 unchanged lines hidden (view full) --- 758 759 return bRet; 760} 761 762// ----------------------------------------------------------------------------- 763 764sal_Bool Bitmap::ImplMosaic( const BmpFilterParam* pFilterParam, const Link* /*pProgress*/ ) 765{ |
766 sal_uLong nTileWidth = ( pFilterParam && pFilterParam->meFilter == BMP_FILTER_MOSAIC ) ? 767 pFilterParam->maMosaicTileSize.mnTileWidth : 4; 768 sal_uLong nTileHeight = ( pFilterParam && pFilterParam->meFilter == BMP_FILTER_MOSAIC ) ? 769 pFilterParam->maMosaicTileSize.mnTileHeight : 4; | 766 sal_uLong nTileWidth = ( pFilterParam && pFilterParam->meFilter == BMP_FILTER_MOSAIC ) ? 767 pFilterParam->maMosaicTileSize.mnTileWidth : 4; 768 sal_uLong nTileHeight = ( pFilterParam && pFilterParam->meFilter == BMP_FILTER_MOSAIC ) ? 769 pFilterParam->maMosaicTileSize.mnTileHeight : 4; |
770 sal_Bool bRet = sal_False; 771 772 if( !nTileWidth ) 773 nTileWidth = 1; 774 775 if( !nTileHeight ) 776 nTileHeight = 1; 777 --- 9 unchanged lines hidden (view full) --- 787 pReadAcc = pWriteAcc = AcquireWriteAccess(); 788 } 789 else 790 { 791 pNewBmp = new Bitmap( GetSizePixel(), 24 ); 792 pReadAcc = AcquireReadAccess(); 793 pWriteAcc = pNewBmp->AcquireWriteAccess(); 794 } | 770 sal_Bool bRet = sal_False; 771 772 if( !nTileWidth ) 773 nTileWidth = 1; 774 775 if( !nTileHeight ) 776 nTileHeight = 1; 777 --- 9 unchanged lines hidden (view full) --- 787 pReadAcc = pWriteAcc = AcquireWriteAccess(); 788 } 789 else 790 { 791 pNewBmp = new Bitmap( GetSizePixel(), 24 ); 792 pReadAcc = AcquireReadAccess(); 793 pWriteAcc = pNewBmp->AcquireWriteAccess(); 794 } |
795 | 795 |
796 if( pReadAcc && pWriteAcc ) 797 { 798 BitmapColor aCol; 799 long nWidth = pReadAcc->Width(); 800 long nHeight = pReadAcc->Height(); 801 long nX, nY, nX1, nX2, nY1, nY2, nSumR, nSumG, nSumB; 802 double fArea_1; 803 804 nY1 = 0; nY2 = nTileHeight - 1; 805 806 if( nY2 >= nHeight ) 807 nY2 = nHeight - 1; 808 809 do 810 { 811 nX1 = 0; nX2 = nTileWidth - 1; 812 813 if( nX2 >= nWidth ) 814 nX2 = nWidth - 1; | 796 if( pReadAcc && pWriteAcc ) 797 { 798 BitmapColor aCol; 799 long nWidth = pReadAcc->Width(); 800 long nHeight = pReadAcc->Height(); 801 long nX, nY, nX1, nX2, nY1, nY2, nSumR, nSumG, nSumB; 802 double fArea_1; 803 804 nY1 = 0; nY2 = nTileHeight - 1; 805 806 if( nY2 >= nHeight ) 807 nY2 = nHeight - 1; 808 809 do 810 { 811 nX1 = 0; nX2 = nTileWidth - 1; 812 813 if( nX2 >= nWidth ) 814 nX2 = nWidth - 1; |
815 | 815 |
816 fArea_1 = 1.0 / ( ( nX2 - nX1 + 1 ) * ( nY2 - nY1 + 1 ) ); 817 818 if( !pNewBmp ) 819 { 820 do 821 { 822 for( nY = nY1, nSumR = nSumG = nSumB = 0; nY <= nY2; nY++ ) 823 { --- 85 unchanged lines hidden (view full) --- 909 maPrefSize = aSize; 910 } 911 912 delete pNewBmp; 913 } 914 } 915 else 916 bRet = sal_True; | 816 fArea_1 = 1.0 / ( ( nX2 - nX1 + 1 ) * ( nY2 - nY1 + 1 ) ); 817 818 if( !pNewBmp ) 819 { 820 do 821 { 822 for( nY = nY1, nSumR = nSumG = nSumB = 0; nY <= nY2; nY++ ) 823 { --- 85 unchanged lines hidden (view full) --- 909 maPrefSize = aSize; 910 } 911 912 delete pNewBmp; 913 } 914 } 915 else 916 bRet = sal_True; |
917 | 917 |
918 return bRet; 919} 920 921// ----------------------------------------------------------------------------- 922 923struct PopArtEntry 924{ 925 sal_uInt32 mnIndex; 926 sal_uInt32 mnCount; 927}; 928 929// ------------------------------------------------------------------------ 930 931extern "C" int __LOADONCALLAPI ImplPopArtCmpFnc( const void* p1, const void* p2 ) 932{ 933 int nRet; 934 935 if( ( (PopArtEntry*) p1 )->mnCount < ( (PopArtEntry*) p2 )->mnCount ) 936 nRet = 1; | 918 return bRet; 919} 920 921// ----------------------------------------------------------------------------- 922 923struct PopArtEntry 924{ 925 sal_uInt32 mnIndex; 926 sal_uInt32 mnCount; 927}; 928 929// ------------------------------------------------------------------------ 930 931extern "C" int __LOADONCALLAPI ImplPopArtCmpFnc( const void* p1, const void* p2 ) 932{ 933 int nRet; 934 935 if( ( (PopArtEntry*) p1 )->mnCount < ( (PopArtEntry*) p2 )->mnCount ) 936 nRet = 1; |
937 else if( ( (PopArtEntry*) p1 )->mnCount == ( (PopArtEntry*) p2 )->mnCount ) | 937 else if( ( (PopArtEntry*) p1 )->mnCount == ( (PopArtEntry*) p2 )->mnCount ) |
938 nRet = 0; 939 else 940 nRet = -1; | 938 nRet = 0; 939 else 940 nRet = -1; |
941 | 941 |
942 return nRet; 943} 944 945// ------------------------------------------------------------------------ 946 947sal_Bool Bitmap::ImplPopArt( const BmpFilterParam* /*pFilterParam*/, const Link* /*pProgress*/ ) 948{ 949 sal_Bool bRet = ( GetBitCount() > 8 ) ? Convert( BMP_CONVERSION_8BIT_COLORS ) : sal_True; --- 21 unchanged lines hidden (view full) --- 971 972 // get pixel count for each palette entry 973 for( long nY = 0; nY < nHeight ; nY++ ) 974 for( long nX = 0; nX < nWidth; nX++ ) 975 pPopArtTable[ pWriteAcc->GetPixel( nY, nX ).GetIndex() ].mnCount++; 976 977 // sort table 978 qsort( pPopArtTable, nEntryCount, sizeof( PopArtEntry ), ImplPopArtCmpFnc ); | 942 return nRet; 943} 944 945// ------------------------------------------------------------------------ 946 947sal_Bool Bitmap::ImplPopArt( const BmpFilterParam* /*pFilterParam*/, const Link* /*pProgress*/ ) 948{ 949 sal_Bool bRet = ( GetBitCount() > 8 ) ? Convert( BMP_CONVERSION_8BIT_COLORS ) : sal_True; --- 21 unchanged lines hidden (view full) --- 971 972 // get pixel count for each palette entry 973 for( long nY = 0; nY < nHeight ; nY++ ) 974 for( long nX = 0; nX < nWidth; nX++ ) 975 pPopArtTable[ pWriteAcc->GetPixel( nY, nX ).GetIndex() ].mnCount++; 976 977 // sort table 978 qsort( pPopArtTable, nEntryCount, sizeof( PopArtEntry ), ImplPopArtCmpFnc ); |
979 | 979 |
980 // get last used entry 981 sal_uLong nFirstEntry; 982 sal_uLong nLastEntry = 0; 983 984 for( n = 0; n < nEntryCount; n++ ) 985 if( pPopArtTable[ n ].mnCount ) 986 nLastEntry = n; 987 988 // rotate palette (one entry) 989 const BitmapColor aFirstCol( pWriteAcc->GetPaletteColor( sal::static_int_cast<sal_uInt16>(pPopArtTable[ 0 ].mnIndex) ) ); 990 for( nFirstEntry = 0; nFirstEntry < nLastEntry; nFirstEntry++ ) 991 { | 980 // get last used entry 981 sal_uLong nFirstEntry; 982 sal_uLong nLastEntry = 0; 983 984 for( n = 0; n < nEntryCount; n++ ) 985 if( pPopArtTable[ n ].mnCount ) 986 nLastEntry = n; 987 988 // rotate palette (one entry) 989 const BitmapColor aFirstCol( pWriteAcc->GetPaletteColor( sal::static_int_cast<sal_uInt16>(pPopArtTable[ 0 ].mnIndex) ) ); 990 for( nFirstEntry = 0; nFirstEntry < nLastEntry; nFirstEntry++ ) 991 { |
992 pWriteAcc->SetPaletteColor( sal::static_int_cast<sal_uInt16>(pPopArtTable[ nFirstEntry ].mnIndex), | 992 pWriteAcc->SetPaletteColor( sal::static_int_cast<sal_uInt16>(pPopArtTable[ nFirstEntry ].mnIndex), |
993 pWriteAcc->GetPaletteColor( sal::static_int_cast<sal_uInt16>(pPopArtTable[ nFirstEntry + 1 ].mnIndex) ) ); 994 } 995 pWriteAcc->SetPaletteColor( sal::static_int_cast<sal_uInt16>(pPopArtTable[ nLastEntry ].mnIndex), aFirstCol ); 996 997 // cleanup 998 delete[] pPopArtTable; 999 ReleaseAccess( pWriteAcc ); 1000 bRet = sal_True; 1001 } 1002 } 1003 1004 return bRet; 1005} 1006 | 993 pWriteAcc->GetPaletteColor( sal::static_int_cast<sal_uInt16>(pPopArtTable[ nFirstEntry + 1 ].mnIndex) ) ); 994 } 995 pWriteAcc->SetPaletteColor( sal::static_int_cast<sal_uInt16>(pPopArtTable[ nLastEntry ].mnIndex), aFirstCol ); 996 997 // cleanup 998 delete[] pPopArtTable; 999 ReleaseAccess( pWriteAcc ); 1000 bRet = sal_True; 1001 } 1002 } 1003 1004 return bRet; 1005} 1006 |
1007// ----------------------------------------------------------------------------- 1008// eof | 1007/* vim: set noet sw=4 ts=4: */ |