phoneuis/BubbleManager/Src/BMImageReader.cpp
changeset 0 5f000ab63145
equal deleted inserted replaced
-1:000000000000 0:5f000ab63145
       
     1 /*
       
     2 * Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  Reader for JPEG/GIF/BMP images (ImageHandlingLib wrapper)
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <coemain.h>
       
    20 #include <IHLImageFactory.h>
       
    21 #include <IHLViewerFactory.h>
       
    22 #include <MIHLFileImage.h>
       
    23 #include <MIHLBitmap.h>
       
    24 #include <MIHLImageViewer.h>
       
    25 #include <IHLBitmapUtil.h>
       
    26 
       
    27 #include "BMImageReader.h"
       
    28 
       
    29 // ======== MEMBER FUNCTIONS ========
       
    30 
       
    31 // ---------------------------------------------------------------------------
       
    32 // C++ constructor
       
    33 // ---------------------------------------------------------------------------
       
    34 //
       
    35 CBubbleImageReader::CBubbleImageReader()                                          
       
    36     {
       
    37     }
       
    38 
       
    39 
       
    40 // ---------------------------------------------------------------------------
       
    41 // ConstructL
       
    42 // ---------------------------------------------------------------------------
       
    43 //
       
    44 void CBubbleImageReader::ConstructL( const TDesC& aFileName )
       
    45     {
       
    46     iSourceImage = IHLImageFactory::OpenFileImageL( 
       
    47         CCoeEnv::Static()->FsSession(),
       
    48         aFileName );
       
    49     }
       
    50 
       
    51 
       
    52 // ---------------------------------------------------------------------------
       
    53 // NewL
       
    54 // ---------------------------------------------------------------------------
       
    55 //
       
    56 CBubbleImageReader* CBubbleImageReader::NewL(
       
    57     const TDesC& aFileName )
       
    58     {
       
    59     CBubbleImageReader* self = new( ELeave ) CBubbleImageReader();
       
    60     CleanupStack::PushL( self );
       
    61     self->ConstructL( aFileName );
       
    62     CleanupStack::Pop( self );
       
    63     return self;
       
    64     }
       
    65 
       
    66 // ---------------------------------------------------------------------------
       
    67 // Destructor
       
    68 // ---------------------------------------------------------------------------
       
    69 //
       
    70 CBubbleImageReader::~CBubbleImageReader()
       
    71     {
       
    72     delete iViewerEngine;
       
    73     delete iDestinationBitmap;
       
    74     delete iSourceImage;
       
    75     }
       
    76 
       
    77 
       
    78 // ---------------------------------------------------------------------------
       
    79 // StartReadingL
       
    80 // ---------------------------------------------------------------------------
       
    81 //    
       
    82 void CBubbleImageReader::StartReadingL(
       
    83     const TSize& aTargetSize,
       
    84     const TReal& aScaleFactor,
       
    85     const TRect& aClipRect, 
       
    86     MBubbleMediaReaderObserver* aObserver )
       
    87     {
       
    88     iObserver = aObserver;
       
    89     
       
    90     iDestinationBitmap = IHLBitmap::CreateL();
       
    91     
       
    92     iViewerEngine = IHLViewerFactory::CreateImageViewerL(
       
    93        aTargetSize,
       
    94        *iSourceImage,
       
    95        *iDestinationBitmap,
       
    96        *this );
       
    97        
       
    98     iViewerEngine->SetZoomRatio( aScaleFactor );
       
    99     iViewerEngine->SetViewerSize( aTargetSize );
       
   100     iViewerEngine->SetSourceRectPosition( aClipRect.iTl );
       
   101     }
       
   102 
       
   103 
       
   104 // ---------------------------------------------------------------------------
       
   105 // SetScaleAndClip
       
   106 // ---------------------------------------------------------------------------
       
   107 //
       
   108 TInt CBubbleImageReader::SetScaleAndClip(
       
   109     const TSize& aTargetSize,
       
   110     const TReal& aScaleFactor,
       
   111     const TRect& aClipRect )
       
   112     {
       
   113     TInt err = KErrNone;
       
   114     
       
   115     if ( iViewerEngine )
       
   116         {
       
   117         iViewerEngine->SetZoomRatio( aScaleFactor );
       
   118         iViewerEngine->SetViewerSize( aTargetSize );
       
   119         iViewerEngine->SetSourceRectPosition( aClipRect.iTl );
       
   120         }
       
   121     else
       
   122         {
       
   123         err = KErrNotReady;    
       
   124         }        
       
   125     
       
   126     return err;
       
   127     }
       
   128 
       
   129 // ---------------------------------------------------------------------------
       
   130 // CancelReadingL
       
   131 // ---------------------------------------------------------------------------
       
   132 //    
       
   133 void CBubbleImageReader::CancelReading()
       
   134     {
       
   135     delete iViewerEngine;
       
   136     iViewerEngine = NULL;
       
   137     }
       
   138     
       
   139 // ---------------------------------------------------------------------------
       
   140 // CancelReadingL
       
   141 // ---------------------------------------------------------------------------
       
   142 //
       
   143 const TSize CBubbleImageReader::SourceSize() const 
       
   144     { 
       
   145     return iSourceImage->Size(); 
       
   146     }
       
   147 
       
   148 // ---------------------------------------------------------------------------
       
   149 // CancelReadingL
       
   150 // ---------------------------------------------------------------------------
       
   151 //
       
   152 TBool CBubbleImageReader::IsAnimation() const
       
   153     { 
       
   154     //return iSourceImage->IsAnimation();
       
   155     return EFalse; // Not supported. 
       
   156     };    
       
   157 
       
   158 // ---------------------------------------------------------------------------
       
   159 // Play
       
   160 // ---------------------------------------------------------------------------
       
   161 //
       
   162 void CBubbleImageReader::Play()
       
   163     {
       
   164     iViewerEngine->Play();
       
   165     }
       
   166 
       
   167 // ---------------------------------------------------------------------------
       
   168 // Stop
       
   169 // ---------------------------------------------------------------------------
       
   170 //
       
   171 void CBubbleImageReader::Stop()
       
   172     {
       
   173     iViewerEngine->Stop();
       
   174     } 
       
   175 
       
   176 // ---------------------------------------------------------------------------
       
   177 // ViewerBitmapChangedL
       
   178 // ---------------------------------------------------------------------------
       
   179 //    
       
   180 void CBubbleImageReader::ViewerBitmapChangedL()
       
   181     {
       
   182     iFrameBuffer = &iDestinationBitmap->Bitmap();
       
   183     iMask = iDestinationBitmap->HasMask() ? &iDestinationBitmap->Mask() :
       
   184         NULL;
       
   185 
       
   186     HandleReadingComplete();    
       
   187     }
       
   188 
       
   189 // ---------------------------------------------------------------------------
       
   190 // ViewerError
       
   191 // ---------------------------------------------------------------------------
       
   192 //
       
   193 void CBubbleImageReader::ViewerError( TInt aError )
       
   194     {
       
   195     HandleReadingError( aError );    
       
   196     }
       
   197