webengine/osswebengine/WebCore/platform/symbian/bitmap/MaskedBitmap.cpp
branchRCL_3
changeset 48 79859ed3eea9
parent 47 e1bea15f9a39
child 49 919f36ff910f
equal deleted inserted replaced
47:e1bea15f9a39 48:79859ed3eea9
    32 // -----------------------------------------------------------------------------
    32 // -----------------------------------------------------------------------------
    33 // CMaskedBitmap::CopyBitmap
    33 // CMaskedBitmap::CopyBitmap
    34 // -----------------------------------------------------------------------------
    34 // -----------------------------------------------------------------------------
    35 TInt BitmapUtil::CopyBitmap( const CFbsBitmap& aSource, CFbsBitmap& aDestination )
    35 TInt BitmapUtil::CopyBitmap( const CFbsBitmap& aSource, CFbsBitmap& aDestination )
    36     {
    36     {
    37     // TODO - how to check if source or destination is null reference
       
    38     TSize size( aSource.SizeInPixels() );
    37     TSize size( aSource.SizeInPixels() );
    39     TDisplayMode displayMode( aSource.DisplayMode() );
    38     TDisplayMode displayMode( aSource.DisplayMode() );
    40     TInt err( aDestination.Create( size, displayMode ) );
    39     TInt err( aDestination.Create( size, displayMode ) );
    41     if( !err )
    40     if( !err )
    42         {
    41         {
    53 // CMaskedBitmap::CopyBitmapData
    52 // CMaskedBitmap::CopyBitmapData
    54 // -----------------------------------------------------------------------------
    53 // -----------------------------------------------------------------------------
    55 TInt BitmapUtil::CopyBitmapData( const CFbsBitmap& aSource, CFbsBitmap& aDestination,
    54 TInt BitmapUtil::CopyBitmapData( const CFbsBitmap& aSource, CFbsBitmap& aDestination,
    56                                    const TSize& aSize, const TDisplayMode& aDisplayMode )
    55                                    const TSize& aSize, const TDisplayMode& aDisplayMode )
    57     {
    56     {
    58     // TODO - how to check if source or destination is null reference
       
    59     HBufC8* scanLine = HBufC8::New( aSource.ScanLineLength( aSize.iWidth, aDisplayMode ) );
    57     HBufC8* scanLine = HBufC8::New( aSource.ScanLineLength( aSize.iWidth, aDisplayMode ) );
    60     if( scanLine )
    58     if( scanLine )
    61         {
    59         {
    62         TPtr8 scanPtr( scanLine->Des() );
    60         TPtr8 scanPtr( scanLine->Des() );
    63         TPoint pp;
    61         TPoint pp;
    81     {
    79     {
    82     }
    80     }
    83 
    81 
    84 
    82 
    85 CMaskedBitmap::CMaskedBitmap(CFbsBitmap* aBitmap, CFbsBitmap* aMask)
    83 CMaskedBitmap::CMaskedBitmap(CFbsBitmap* aBitmap, CFbsBitmap* aMask)
    86 : iBitmap(aBitmap),iMask(aMask),i_DecodingCompleted(ETrue)
    84 : iBitmap(aBitmap),iMask(aMask)
    87     {
    85     {
    88     }
    86     }
    89 
    87 
    90 // ----------------------------------------------------------------------------
    88 // ----------------------------------------------------------------------------
    91 //
    89 //
   184         else
   182         else
   185             {
   183             {
   186             err = BitmapUtil::CopyBitmap( aBitmap, *iBitmap );
   184             err = BitmapUtil::CopyBitmap( aBitmap, *iBitmap );
   187             }
   185             }
   188         }
   186         }
   189     if(!err)
       
   190         SetInitialisationCompletionStatus(ETrue);
       
   191     return err;
   187     return err;
   192     }
   188     }
   193 
   189 
   194 // -----------------------------------------------------------------------------
   190 // -----------------------------------------------------------------------------
   195 // CMaskedBitmap::Copy
   191 // CMaskedBitmap::Copy
   217             {
   213             {
   218             err = BitmapUtil::CopyBitmap( aBitmap, *iBitmap );
   214             err = BitmapUtil::CopyBitmap( aBitmap, *iBitmap );
   219             }
   215             }
   220         }
   216         }
   221 
   217 
   222     if( !err && maskHandle && iMask)
   218     if( !err && maskHandle )
   223         {
   219         {
   224         if( aDuplicate )
   220         if( aDuplicate )
   225             {
   221             {
   226             err = iMask->Duplicate( maskHandle );
   222             err = iMask->Duplicate( maskHandle );
   227             }
   223             }
   232         if( err )
   228         if( err )
   233             {
   229             {
   234             iBitmap->Reset();
   230             iBitmap->Reset();
   235             }
   231             }
   236         }
   232         }
   237     if(!err)
       
   238         SetInitialisationCompletionStatus(ETrue);
       
   239     return err;
   233     return err;
   240     }
   234     }
   241 
   235 
   242 // -----------------------------------------------------------------------------
   236 // -----------------------------------------------------------------------------
   243 // CMaskedBitmap::Copy
   237 // CMaskedBitmap::Copy
   251 // CMaskedBitmap::Reset
   245 // CMaskedBitmap::Reset
   252 // -----------------------------------------------------------------------------
   246 // -----------------------------------------------------------------------------
   253 void CMaskedBitmap::Reset()
   247 void CMaskedBitmap::Reset()
   254     {
   248     {
   255     iBitmap->Reset();
   249     iBitmap->Reset();
   256     if(iMask) iMask->Reset();
   250     iMask->Reset();
   257     SetInitialisationCompletionStatus(EFalse);
       
   258     }
   251     }
   259 
   252 
   260 
   253 
   261 // -----------------------------------------------------------------------------
   254 // -----------------------------------------------------------------------------
   262 // CMaskedBitmap::IsCreated
   255 // CMaskedBitmap::IsCreated
   277 // -----------------------------------------------------------------------------
   270 // -----------------------------------------------------------------------------
   278 // CMaskedBitmap::HasMask
   271 // CMaskedBitmap::HasMask
   279 // -----------------------------------------------------------------------------
   272 // -----------------------------------------------------------------------------
   280 TBool CMaskedBitmap::HasMask() const
   273 TBool CMaskedBitmap::HasMask() const
   281     {
   274     {
   282     return (iMask && iMask->Handle()!=0 );
   275     return ( iMask->Handle() != 0 );
   283     }
   276     }
   284 
   277 
   285 // -----------------------------------------------------------------------------
   278 // -----------------------------------------------------------------------------
   286 // CMaskedBitmap::Mask
   279 // CMaskedBitmap::Mask
   287 // -----------------------------------------------------------------------------
   280 // -----------------------------------------------------------------------------
   300         {
   293         {
   301         return;
   294         return;
   302         }
   295         }
   303     if( iBitmap->Handle() )
   296     if( iBitmap->Handle() )
   304         {
   297         {
   305         if( HasMask() )
   298         if( iMask->Handle() )
   306             {
   299             {
   307             aContext.BitBltMasked( aPoint, iBitmap, s, iMask, iInvertMask );
   300             aContext.BitBltMasked( aPoint, iBitmap, s, iMask, iInvertMask );
   308             }
   301             }
   309         else
   302         else
   310             {
   303             {
   322         {
   315         {
   323         return;
   316         return;
   324         }
   317         }
   325     if( iBitmap->Handle() )
   318     if( iBitmap->Handle() )
   326         {
   319         {
   327         if( HasMask() )
   320         if( iMask->Handle() )
   328             {
   321             {
   329 
   322 
   330             aContext.BitBltMasked( aPoint, iBitmap, aSource, iMask, iInvertMask );
   323             aContext.BitBltMasked( aPoint, iBitmap, aSource, iMask, iInvertMask );
   331             }
   324             }
   332         else
   325         else
   347         return;
   340         return;
   348         }
   341         }
   349     if( iBitmap->Handle() )
   342     if( iBitmap->Handle() )
   350         {
   343         {
   351         // ### FIXME DrawBitmapMasked is too buggy to use 2.8/week52, so no transparency with scaling
   344         // ### FIXME DrawBitmapMasked is too buggy to use 2.8/week52, so no transparency with scaling
   352         if( HasMask() )
   345         if( iMask->Handle() )
   353             {
   346             {
   354             aContext.DrawBitmapMasked( aTarget, iBitmap, s, iMask, iInvertMask );
   347             aContext.DrawBitmapMasked( aTarget, iBitmap, s, iMask, iInvertMask );
   355             }
   348             }
   356         else
   349         else
   357             {
   350             {
   370         return;
   363         return;
   371         }
   364         }
   372     if( iBitmap->Handle() )
   365     if( iBitmap->Handle() )
   373         {
   366         {
   374         // ### FIXME DrawBitmapMasked is too buggy to use 2.8/week52, so no transparency with scaling
   367         // ### FIXME DrawBitmapMasked is too buggy to use 2.8/week52, so no transparency with scaling
   375         if( HasMask() )
   368         if( iMask->Handle() )
   376             {
   369             {
   377             aContext.DrawBitmapMasked( aTarget, iBitmap, aSource, iMask, iInvertMask );
   370             aContext.DrawBitmapMasked( aTarget, iBitmap, aSource, iMask, iInvertMask );
   378             }
   371             }
   379         else
   372         else
   380             {
   373             {
   446 // CMaskedBitmap::Resize
   439 // CMaskedBitmap::Resize
   447 // -----------------------------------------------------------------------------
   440 // -----------------------------------------------------------------------------
   448 void CMaskedBitmap::Resize(TSize aSize)
   441 void CMaskedBitmap::Resize(TSize aSize)
   449     {
   442     {
   450     iBitmap->Resize(aSize);
   443     iBitmap->Resize(aSize);
   451     if (HasMask())
   444     if (iMask)
       
   445         {
   452         iMask->Resize(aSize);
   446         iMask->Resize(aSize);
       
   447         }
   453     }
   448     }
   454 
   449 
   455 // -----------------------------------------------------------------------------
   450 // -----------------------------------------------------------------------------
   456 // CMaskedBitmap::TileInBitmapRect
   451 // CMaskedBitmap::TileInBitmapRect
   457 // -----------------------------------------------------------------------------
   452 // -----------------------------------------------------------------------------
   475         }
   470         }
   476     else 
   471     else 
   477         {
   472         {
   478         gc.SetBrushStyle(CGraphicsContext::ENullBrush);
   473         gc.SetBrushStyle(CGraphicsContext::ENullBrush);
   479         TPoint off(srcPt.iX, srcPt.iY);
   474         TPoint off(srcPt.iX, srcPt.iY);
   480 
       
   481         for (TInt x = off.iX; x<bmpRect.iBr.iX; x+=SizeInPixels().iWidth) 
   475         for (TInt x = off.iX; x<bmpRect.iBr.iX; x+=SizeInPixels().iWidth) 
   482             {
   476             {
   483             for (TInt y = off.iY; y<bmpRect.iBr.iY; y+=SizeInPixels().iHeight) 
   477             for (TInt y = off.iY; y<bmpRect.iBr.iY; y+=SizeInPixels().iHeight) 
   484                 {
   478                 {
   485                 TRect rect(TPoint(x,y), SizeInPixels());
   479                 TRect rect(TPoint(x,y), SizeInPixels());
   490     }
   484     }
   491 
   485 
   492 void CMaskedBitmap::TileInBitmapRect( CFbsBitmap* trgBmp, const TRect& aTrgRect, const TPoint& aOffset )
   486 void CMaskedBitmap::TileInBitmapRect( CFbsBitmap* trgBmp, const TRect& aTrgRect, const TPoint& aOffset )
   493     {
   487     {
   494     trgBmp->LockHeap();
   488     trgBmp->LockHeap();
   495     
   489 
   496     if ( aTrgRect.Width() < 0 || aTrgRect.Height() < 0 )
       
   497         {
       
   498         trgBmp->UnlockHeap();
       
   499         return; 
       
   500         }
       
   501     TSize sz = trgBmp->SizeInPixels();
   490     TSize sz = trgBmp->SizeInPixels();
   502     TUint32* buf = (TUint32*)(trgBmp->DataAddress());
   491     TUint32* buf = (TUint32*)(trgBmp->DataAddress());
   503 
   492 
   504     // bitmap with 32-bit depth doesn't need padding for a scanline.
   493     // bitmap with 32-bit depth doesn't need padding for a scanline.
   505     TInt padding = trgBmp->DisplayMode() == EColor16MU ? 0 : (sz.iWidth & 1);
   494     TInt padding = trgBmp->DisplayMode() == EColor16MU ? 0 : (sz.iWidth & 1);
   598     }
   587     }
   599 
   588 
   600 
   589 
   601 TBool CMaskedBitmap::IsFullyTransparent()
   590 TBool CMaskedBitmap::IsFullyTransparent()
   602     {
   591     {
   603     if (!HasMask())
   592     if (!iMask || !iMask->Handle())
       
   593         {
   604         return EFalse;
   594         return EFalse;
       
   595         }
   605 
   596 
   606     if( iMask->DisplayMode() != EGray2 )
   597     if( iMask->DisplayMode() != EGray2 )
   607         {
   598         {
   608         return EFalse; // fully transparent png? rare, dont bother
   599         return EFalse; // fully transparent png? rare, dont bother
   609         }
   600         }
   637     {
   628     {
   638     
   629     
   639 		if ( iBitmap && iBitmap->Handle() ) 
   630 		if ( iBitmap && iBitmap->Handle() ) 
   640 			iBitmap->CompressInBackground();
   631 			iBitmap->CompressInBackground();
   641 		
   632 		
   642         if ( HasMask() )
   633         if ( iMask && iMask->Handle() )
   643             iMask->CompressInBackground();
   634             iMask->CompressInBackground();
   644         
   635         
   645     }
   636     }
   646 
   637 
   647 CMaskedBitmap* CMaskedBitmap::ScaleImageToSize( TSize newSize, bool storeScaledImage)
   638 CMaskedBitmap* CMaskedBitmap::ScaleImageToSize( TSize newSize )
   648 {
   639 {
   649     
   640     if (iScaledBitmap && iScaledBitmap->SizeInPixels() == newSize)
   650     if (storeScaledImage && iScaledBitmap && iScaledBitmap->SizeInPixels() == newSize)
       
   651         return iScaledBitmap;
   641         return iScaledBitmap;
   652 
   642 
   653     CMaskedBitmap* scaledBitmap = CMaskedBitmap::NewL();
   643     delete iScaledBitmap;
   654 
   644     iScaledBitmap = NULL;
   655     CFbsBitmap& bmp = scaledBitmap->BitmapModifyable();
   645     iScaledBitmap = CMaskedBitmap::NewL();
       
   646 
       
   647     CFbsBitmap& bmp = iScaledBitmap->BitmapModifyable();
   656     bmp.Create(newSize, iBitmap->DisplayMode());
   648     bmp.Create(newSize, iBitmap->DisplayMode());
   657 
   649 
   658     // scale the image quickly
   650     // scale the image quickly
   659     CFbsBitGc* bitGc;
   651     CFbsBitGc* bitGc;
   660     CFbsBitmapDevice* bitDevice = CFbsBitmapDevice::NewL( &bmp );
   652     CFbsBitmapDevice* bitDevice = CFbsBitmapDevice::NewL( &bmp );
   662     User::LeaveIfError( bitDevice->CreateContext( bitGc ) );
   654     User::LeaveIfError( bitDevice->CreateContext( bitGc ) );
   663     CleanupStack::PushL( bitGc );
   655     CleanupStack::PushL( bitGc );
   664     bitGc->DrawBitmap(TRect(TPoint(0,0), newSize), iBitmap, iBitmap->SizeInPixels());
   656     bitGc->DrawBitmap(TRect(TPoint(0,0), newSize), iBitmap, iBitmap->SizeInPixels());
   665     CleanupStack::PopAndDestroy(2);
   657     CleanupStack::PopAndDestroy(2);
   666 
   658 
   667     CFbsBitmap& msk = scaledBitmap->MaskModifyable();
   659     CFbsBitmap& msk = iScaledBitmap->MaskModifyable();
   668     if( HasMask() ) {
   660     if( HasMask() ) {
   669         msk.Create(newSize, iMask->DisplayMode());
   661         msk.Create(newSize, iMask->DisplayMode());
   670 
   662 
   671         // scale the image quickly
   663         // scale the image quickly
   672         CFbsBitGc* bitGc;
   664         CFbsBitGc* bitGc;
   675         User::LeaveIfError( bitDevice->CreateContext( bitGc ) );
   667         User::LeaveIfError( bitDevice->CreateContext( bitGc ) );
   676         CleanupStack::PushL( bitGc );
   668         CleanupStack::PushL( bitGc );
   677         bitGc->DrawBitmap(TRect(TPoint(0,0), newSize), iMask, iMask->SizeInPixels());
   669         bitGc->DrawBitmap(TRect(TPoint(0,0), newSize), iMask, iMask->SizeInPixels());
   678         CleanupStack::PopAndDestroy(2);
   670         CleanupStack::PopAndDestroy(2);
   679     }
   671     }
   680     if (storeScaledImage) {
   672 
   681         delete iScaledBitmap;
   673     return iScaledBitmap;
   682         iScaledBitmap = NULL;
       
   683         iScaledBitmap = scaledBitmap;
       
   684     }
       
   685     return scaledBitmap;
       
   686 }
   674 }
   687 
   675 
   688 void CMaskedBitmap::SetInitialisationCompletionStatus(TBool aDecodingCompleted)
       
   689 {
       
   690     i_DecodingCompleted = aDecodingCompleted;
       
   691 }
       
   692 
       
   693 
       
   694 TBool CMaskedBitmap::IsCompletlyInitialised()
       
   695 {
       
   696     return i_DecodingCompleted;
       
   697 }
       
   698 
       
   699 
       
   700 //  End of File
   676 //  End of File