mpxmusicplayer/commonui/src/mpximageutil.cpp
author Simon Howkins <simonh@symbian.org>
Mon, 22 Nov 2010 16:33:08 +0000
branchRCL_3
changeset 69 1a9731de4f7b
parent 53 3de6c4cf6b67
permissions -rw-r--r--
Adjusted to avoid exports, etc, from a top-level bld.inf
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
53
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
     1
/*
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
     2
* Copyright (c) 2006 Nokia Corporation and/or its subsidiary(-ies).
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
     3
* All rights reserved.
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
     4
* This component and the accompanying materials are made available
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
     5
* under the terms of "Eclipse Public License v1.0"
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
     6
* which accompanies this distribution, and is available
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
     8
*
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
     9
* Initial Contributors:
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    10
* Nokia Corporation - initial contribution.
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    11
*
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    12
* Contributors:
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    13
*
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    14
* Description:  Implementation of CMPXImageUtil.
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    15
*
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    16
*/
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    17
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    18
// INCLUDE FILES
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    19
#include <e32std.h>
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    20
#include <e32base.h>
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    21
#include <bitmaptransforms.h>
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    22
#include <mda/common/video.h>
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    23
#include <eikenv.h>
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    24
#include <icl/imagedata.h>
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    25
#include <imageconversion.h>
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    26
#include <IclExtJpegApi.h>
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    27
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    28
#include "mpximageutil.h"
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    29
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    30
//This value is used to stretch so the image fills the container.
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    31
const TReal MaxStretchRatio = 1.1f;
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    32
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    33
LOCAL_C TInt Stretch (TInt aValue, TInt aLimit)
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    34
    {
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    35
    TInt ret( aValue * MaxStretchRatio );
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    36
    ret = (ret>aLimit) ? aLimit : ret;
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    37
    return ret;
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    38
    }
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    39
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    40
// ============================ MEMBER FUNCTIONS ===============================
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    41
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    42
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    43
// -----------------------------------------------------------------------------
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    44
// Two-phased constructor.
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    45
// -----------------------------------------------------------------------------
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    46
//
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    47
CMPXImageUtil* CMPXImageUtil::NewL(
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    48
                                    MMPXAlbumArtUtilObserver& aObserver)
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    49
    {
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    50
    CMPXImageUtil* self = new ( ELeave ) CMPXImageUtil(aObserver);
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    51
    CleanupStack::PushL( self );
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    52
    self->ConstructL();
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    53
    CleanupStack::Pop(); // self
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    54
    return self; 
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    55
    }
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    56
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    57
// -----------------------------------------------------------------------------
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    58
// C++ default constructor can NOT contain any code, that
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    59
// might leave.
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    60
// -----------------------------------------------------------------------------
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    61
//
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    62
CMPXImageUtil::CMPXImageUtil(MMPXAlbumArtUtilObserver& aObserver) 
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    63
:   CActive(EPriorityStandard), iObserver(aObserver) 
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    64
    {
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    65
    iBitmap = NULL;
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    66
    iState = EIdle;
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    67
    }
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    68
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    69
// -----------------------------------------------------------------------------
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    70
// Symbian 2nd phase constructor can leave.
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    71
// -----------------------------------------------------------------------------
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    72
//
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    73
void CMPXImageUtil::ConstructL()
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    74
    {
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    75
    iScaler = CBitmapScaler::NewL();
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    76
    User::LeaveIfError(iFs.Connect());
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    77
    CActiveScheduler::Add( this );
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    78
    }
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    79
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    80
// -----------------------------------------------------------------------------
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    81
// Destructor
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    82
// -----------------------------------------------------------------------------
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    83
//
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    84
CMPXImageUtil::~CMPXImageUtil()
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    85
    {
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    86
    Cancel();
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    87
    delete iImageDecoder; // CImageDecoder must be deleted before the 
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    88
    delete iScaler;
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    89
    iFs.Close();
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    90
    delete iImageData;
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    91
    }
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    92
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    93
// -----------------------------------------------------------------------------
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    94
// Starts to decode an image from a file. 
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    95
// -----------------------------------------------------------------------------
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    96
//
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    97
void CMPXImageUtil::StartToDecodeL(const TDesC& aFileName, 
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    98
                                      const TSize& aSize, 
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    99
                                      TDisplayMode aDisplayMode /*=EColor64K*/)
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   100
    {
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   101
    if(iState)
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   102
        {
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   103
        User::Leave(KErrNotReady);
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   104
        }
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   105
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   106
    delete iImageDecoder; 
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   107
    iImageDecoder = NULL;
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   108
    delete iBitmap; 
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   109
    iBitmap = NULL;
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   110
    delete iImageData;
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   111
    iImageData = NULL;
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   112
    
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   113
    // create the decoder
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   114
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   115
    TRAPD( err, iImageDecoder = CExtJpegDecoder::FileNewL( 
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   116
            CExtJpegDecoder::EHwImplementation, 
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   117
            iFs, 
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   118
            aFileName, 
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   119
            CImageDecoder::EOptionNone ) );
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   120
    if (KErrNone != err)
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   121
        {
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   122
            TRAP(err,iImageDecoder = CExtJpegDecoder::FileNewL( 
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   123
                    CExtJpegDecoder::ESwImplementation, 
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   124
                    iFs, 
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   125
                    aFileName, 
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   126
                    CImageDecoder::EOptionNone ) );
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   127
        if (KErrNone != err)
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   128
            {
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   129
            iImageDecoder = CImageDecoder::FileNewL(
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   130
                    iFs, 
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   131
                    aFileName,
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   132
                    CImageDecoder::EOptionNone);
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   133
            }
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   134
        }
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   135
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   136
    // Get image size
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   137
    TSize bitmapSize = CalculateDecodeSize(aSize);
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   138
    // create the destination bitmap
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   139
    iBitmap = new (ELeave) CFbsBitmap();
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   140
    User::LeaveIfError(iBitmap->Create(bitmapSize, aDisplayMode)); 
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   141
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   142
    // start conversion to bitmap
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   143
    iState = EDecoding;
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   144
    iImageDecoder->Convert(&iStatus, *iBitmap);
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   145
    
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   146
    iObserver.ExtractAlbumArtStarted();
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   147
    SetActive();
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   148
    }
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   149
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   150
// -----------------------------------------------------------------------------
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   151
// CMPXImageUtil::DoCancel
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   152
// Implementation of CActive
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   153
// -----------------------------------------------------------------------------
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   154
//
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   155
void CMPXImageUtil::DoCancel()
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   156
    {
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   157
    switch ( iState )
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   158
        {
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   159
        case EDecoding:
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   160
            {
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   161
            iImageDecoder->Cancel();
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   162
            // need to delete bitmap as we have are still the owner until the 
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   163
            // operation completes
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   164
            if ( iBitmap )
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   165
                {
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   166
                delete iBitmap;
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   167
                iBitmap = NULL;
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   168
                }
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   169
            break;
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   170
            }
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   171
        case EScaling:
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   172
            {
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   173
            iScaler->Cancel();
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   174
            if ( iBitmap )
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   175
                {
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   176
                delete iBitmap;
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   177
                iBitmap = NULL;
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   178
                }
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   179
            break;
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   180
            }
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   181
        default: // No Asynchronous events are taking place, do nothing.
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   182
            {
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   183
            break;
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   184
            }
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   185
        }
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   186
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   187
    delete iImageData;
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   188
    iImageData = NULL;
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   189
    delete iImageDecoder;
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   190
    iImageDecoder = NULL;
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   191
    }
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   192
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   193
// -----------------------------------------------------------------------------
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   194
// Implementation of CActive
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   195
// -----------------------------------------------------------------------------
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   196
//
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   197
void CMPXImageUtil::RunL()
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   198
    {
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   199
    TInt deleteDecoder( ETrue );
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   200
    switch( iState ) 
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   201
        {
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   202
        case EDecoding:
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   203
            {
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   204
            if( iStatus == KErrNone ) 
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   205
                {
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   206
                if ( !iScaleRquired )
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   207
                    {   
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   208
                    iState = EIdle;
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   209
                    iObserver.ExtractAlbumArtCompleted(iBitmap,KErrNone);
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   210
                    iBitmap = NULL;
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   211
                    }
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   212
                else 
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   213
                    {
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   214
                    deleteDecoder = EFalse;
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   215
                    ScaleL();
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   216
                    }
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   217
                break;
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   218
                }
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   219
            else
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   220
                {
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   221
                // some error
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   222
                if ( iBitmap )
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   223
                    {
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   224
                    delete iBitmap;
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   225
                    iBitmap = NULL;                        
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   226
                    }
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   227
                iState = EIdle;
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   228
                iObserver.ExtractAlbumArtCompleted(iBitmap, iStatus.Int());
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   229
                break;   
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   230
                }
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   231
            }
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   232
        case EScaling:
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   233
            {
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   234
            iState = EIdle;
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   235
            iObserver.ExtractAlbumArtCompleted(iBitmap,iStatus.Int());
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   236
            iBitmap = NULL; 
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   237
            }
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   238
            break;
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   239
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   240
        default: // some error
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   241
            {
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   242
            iState = EIdle;
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   243
            if ( iBitmap )
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   244
                {
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   245
                delete iBitmap;
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   246
                iBitmap = NULL;                        
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   247
                }
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   248
            iObserver.ExtractAlbumArtCompleted(iBitmap,iStatus.Int());
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   249
            break;
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   250
            }
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   251
        }
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   252
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   253
    // It's safe to destroy iImageData here
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   254
    delete iImageData;
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   255
    iImageData = NULL;
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   256
    
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   257
    if ( deleteDecoder )
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   258
        {
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   259
        delete iImageDecoder;
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   260
        iImageDecoder = NULL;
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   261
        }
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   262
    }
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   263
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   264
// -----------------------------------------------------------------------------
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   265
// Scales iBitmap by iSize
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   266
// -----------------------------------------------------------------------------
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   267
//
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   268
void CMPXImageUtil::ScaleL()
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   269
    {
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   270
    iScaler->Scale(&iStatus, *iBitmap, iSize, EFalse);
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   271
    iState = EScaling;
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   272
    SetActive();
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   273
    }
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   274
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   275
// -----------------------------------------------------------------------------
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   276
// Starts to decode an image from a buffer. 
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   277
// -----------------------------------------------------------------------------
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   278
//
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   279
void CMPXImageUtil::StartToDecodeL( const TSize& aSize,
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   280
        HBufC8* aAlbumArt, TDisplayMode aDisplayMode/*=EColor64K*/ )
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   281
    {
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   282
    if(iState)
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   283
        {
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   284
        User::Leave( KErrNotReady );
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   285
        }
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   286
                               
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   287
    delete iImageDecoder; 
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   288
    iImageDecoder = NULL;
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   289
    delete iBitmap; 
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   290
    iBitmap = NULL;
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   291
    delete iImageData;
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   292
    iImageData = NULL;
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   293
    // storing the pointer to aAlbumArt, ownership was transferred to us.
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   294
    iImageData = aAlbumArt;
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   295
    // create the decoder
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   296
    
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   297
    
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   298
    TRAPD( err, iImageDecoder = CExtJpegDecoder::DataNewL( 
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   299
            CExtJpegDecoder::EHwImplementation, 
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   300
            iFs, 
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   301
            *iImageData, 
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   302
            CImageDecoder::EOptionNone ) );
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   303
    if ( KErrNone != err )
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   304
        {
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   305
        TRAP(err,iImageDecoder = CExtJpegDecoder::DataNewL( 
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   306
                CExtJpegDecoder::ESwImplementation, 
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   307
                iFs, 
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   308
                *iImageData, 
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   309
                CImageDecoder::EOptionNone ) );
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   310
        if ( KErrNone != err )
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   311
            {
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   312
            iImageDecoder = CImageDecoder::DataNewL( 
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   313
                    iFs, 
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   314
                    *iImageData, 
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   315
                    CImageDecoder::EOptionNone );
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   316
            }
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   317
        }
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   318
    
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   319
    
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   320
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   321
    
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   322
    TSize bitmapSize = CalculateDecodeSize( aSize );
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   323
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   324
    // create the destination bitmap
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   325
    iBitmap = new ( ELeave ) CFbsBitmap();
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   326
    User::LeaveIfError( iBitmap->Create( bitmapSize, aDisplayMode ) );
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   327
    // start conversion to bitmap
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   328
    iState = EDecoding;
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   329
    iImageDecoder->Convert( &iStatus, *iBitmap );
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   330
    
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   331
    iObserver.ExtractAlbumArtStarted();
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   332
    SetActive();
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   333
    }
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   334
// -----------------------------------------------------------------------------
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   335
// Calculates the decode size and prepares members for scaling. 
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   336
// -----------------------------------------------------------------------------
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   337
//
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   338
TSize CMPXImageUtil::CalculateDecodeSize(const TSize& aSize)
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   339
    {
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   340
    const TFrameInfo& frameInfo = iImageDecoder->FrameInfo();
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   341
    TSize bitmapSize = frameInfo.iOverallSizeInPixels;
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   342
    TReal sourceAspectRatio( TReal( bitmapSize.iWidth) / bitmapSize.iHeight );
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   343
    TReal destinationAspectRatio( TReal( aSize.iWidth ) / aSize.iHeight );
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   344
    TReal xScale = TReal( bitmapSize.iWidth ) / aSize.iWidth;
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   345
    TReal yScale = TReal( bitmapSize.iHeight ) / aSize.iHeight;
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   346
    TReal scale(0.0f);
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   347
    
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   348
    if ( sourceAspectRatio > destinationAspectRatio )
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   349
        {
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   350
        scale = xScale;
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   351
        iSize.iWidth = aSize.iWidth;
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   352
        iSize.iHeight = Stretch( TReal( bitmapSize.iHeight ) / scale , 
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   353
                                 aSize.iHeight );
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   354
        }
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   355
    else
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   356
        {
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   357
        scale = yScale;
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   358
        iSize.iWidth = Stretch( TReal( bitmapSize.iWidth ) / scale ,
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   359
                                aSize.iWidth);
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   360
        iSize.iHeight = aSize.iHeight;
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   361
        }
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   362
     
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   363
    if ((frameInfo.iFlags & TFrameInfo::EFullyScaleable))
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   364
        {
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   365
        iScaleRquired = EFalse;
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   366
        bitmapSize = iSize;
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   367
        }
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   368
    else
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   369
        //Decoder only supports 2, 4 and 8 scallyng, the image will need 
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   370
        //to be reescaled after decoding.
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   371
        //Decoding to a scale that is just a bit bigger thant the target,
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   372
        //this will save memory and resources and we will get a sharp image 
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   373
        //after scaling.
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   374
        {
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   375
        TInt intscale = ( scale >= 8 ) ? 8 : 
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   376
                ( scale >= 4 ) ? 4 :
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   377
                ( scale >= 2 ) ? 2 : 1;
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   378
        TUint xCorrection = ( bitmapSize.iWidth % intscale ) ? 1 : 0;
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   379
        TUint yCorrection = ( bitmapSize.iHeight % intscale ) ? 1 : 0;
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   380
        bitmapSize.iWidth /= intscale;
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   381
        bitmapSize.iHeight /= intscale;
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   382
        bitmapSize += TSize( xCorrection, yCorrection );
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   383
        iScaleRquired = ETrue;
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   384
        }
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   385
    return bitmapSize;
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   386
    }
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   387
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   388
// -----------------------------------------------------------------------------
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   389
// CMPXImageUtil::CancelRequest
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   390
// Cancel Asynch requests
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   391
// -----------------------------------------------------------------------------
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   392
//
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   393
void CMPXImageUtil::CancelRequest()
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   394
    {
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   395
    Cancel();
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   396
    }
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   397
3de6c4cf6b67 Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   398
//  End of File