⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 multimediafadapter.cpp

📁 series60 应用程序开发的源代码 series60 应用程序开发的源代码
💻 CPP
字号:
/**
 *
 * @brief Definition of CMultiMediaFApplication
 *
 * Copyright (c) EMCC Software Ltd 2003
 * @version 1.0
 */

// INCLUDE FILES

// Class includes
#include "MultiMediaFAdapter.h"

// System includes
#include <aknutils.h>            // CompleteWithAppPath
#include <BitmapTransforms.h>    // CBitmapRotator, CBitmapScaler
#include <fbs.h>                // CFbsBitmap
#include <ImageCodecData.h>        // TJpegImageData
#include <ImageConversion.h>    // CImageDecoder, CImageEncoder
#include <ImageData.h>            // CFrameImageData
#include <MultiMediaF.mbg>        // EMbmMultimediafLogo

// User includes
#include "MultiMediaF.hrh"            // Command IDs
#include "MultimediaController.h"    // MMultimediaController

// CONSTANTS
_LIT(KPathOfGifFile, "\\system\\apps\\MultiMediaF\\GifFile.gif");
_LIT(KPathOfSaveJpgFile, "\\system\\apps\\MultiMediaF\\OutputFile.jpg");
_LIT(KMbmPath, "\\system\\apps\\MultiMediaF\\MultiMediaF.mbm");
_LIT8(KJpgMime, "image/jpeg");

const TInt KGifIndex = 0;
const TInt KScaledWidthOne = 50;
const TInt KScaledHeightOne = 50;
const TInt KScaledWidthTwo = 100;
const TInt KScaledHeightTwo = 100;
const TInt KJpgQuality = 65;

// ================= MEMBER FUNCTIONS =======================

/**
 * Symbian OS 2 phase constructor.
 * Constructs the CMultiMediaFAdapter using the NewLC method, popping
 * the constructed object from the CleanupStack before returning it.
 *
 * @param aRect The rectangle for this window
 * @return The newly constructed CMultiMediaFAdapter
 */
CMultiMediaFAdapter* CMultiMediaFAdapter::NewL(MMultimediaController& aMultimediaController, TDisplayMode aDeviceDisplayMode)
{
    CMultiMediaFAdapter* self = CMultiMediaFAdapter::NewLC(aMultimediaController, aDeviceDisplayMode);
    CleanupStack::Pop();
    return self;
}

/**
 * Symbian OS 2 phase constructor.
 * Constructs the CMultiMediaFAdapter using the constructor and ConstructL
 * method, leaving the constructed object on the CleanupStack before returning it.
 *
 * @param aRect The rectangle for this window
 * @return The newly constructed CMultiMediaFAdapter
 */
CMultiMediaFAdapter* CMultiMediaFAdapter::NewLC(MMultimediaController& aMultimediaController, TDisplayMode aDeviceDisplayMode)
{
    CMultiMediaFAdapter* self = new (ELeave) CMultiMediaFAdapter(aMultimediaController, aDeviceDisplayMode);
    CleanupStack::PushL(self);
    self->ConstructL();
    return self;
}

/**
* Symbian OS 2nd phase constructor.
* Instantiates objects for encoding, decoding, rotating and scaling.
* A bitmap is also instantiated to be used for storing the result of a manipulation
* and used later for display on the screen.
*/
void CMultiMediaFAdapter::ConstructL()
{
    iScaler = CBitmapScaler::NewL();
    iRotator = CBitmapRotator::NewL();

    ResetImageL();

    User::LeaveIfError(iFs.Connect());

    CActiveScheduler::Add(this);
}

/**
 * C++ constructor
 *
 * @param aMultimediaController The application controller object used to inform the view to redraw
 * @param aDeviceDisplayMode The display mode (number of colors supported) of the device
 */
CMultiMediaFAdapter::CMultiMediaFAdapter(MMultimediaController& aMultimediaController, TDisplayMode aDeviceDisplayMode) :
    CActive(EPriorityLow),
    iMultimediaController(aMultimediaController),
    iScaleState(EScaleDown),
    iDeviceDisplayMode(aDeviceDisplayMode)
{
}

/**
 * Destructor.
 */
CMultiMediaFAdapter::~CMultiMediaFAdapter()
{
    delete iDecoder;
    delete iEncoder;
    delete iRotator;
    delete iScaler;
    delete iImage;
    delete iJpgImageData;
    iFs.Close();
}

/**
 * Routes the commands obtained by the AppUi into the MultiMediaFAdapter to
 * perform the user desired image manipulation
 *
 * @param aCommand The command Id from the AppUi used to decided which operation to perform
 */
void CMultiMediaFAdapter::HandleCommandL(TInt aCommand)
{
    DoCancel(); // clear any pending operations
    switch(aCommand)
    {
        case EDecodeImage:
            iManipulationState = EDecode;
            DecodeOpenAndConvertL();
            break;
        case EEncodeImage:
            iManipulationState = EEncode;
            EncodeOpenAndConvertL();
            break;
        case ERotate90:
            iManipulationState = ERotating;
            Rotate90();
            break;
        case ERotate180:
            iManipulationState = ERotating;
            Rotate180();
            break;
        case ERotate270:
            iManipulationState = ERotating;
            Rotate270();
            break;
        case ERotateH:
            iManipulationState = ERotating;
            RotateMirrorH();
            break;
        case ERotateV:
            iManipulationState = ERotating;
            RotateMirrorV();
            break;
        case EScale:
            iManipulationState = EScaling;
            ScaleImage();
            break;
        case EResetImage:
            iManipulationState = EDoNothing;
            ResetImageL();
            iMultimediaController.RedrawView();
            break;
    }
}

/**
* From CActive derivation.
* Used to inform client code that a conversion, rotation or scaling operation
* has completed.
* Following this the view is informed to redraw
*
*/
void CMultiMediaFAdapter::RunL()
{
    switch (iManipulationState)
    {
        case EDecode:
        case EEncode:
        case ERotating:
        case EScaling:
        {
            iManipulationState = EDoNothing;
            iMultimediaController.RedrawView();
            break;
        }
       default:
            break;
    }
}

/**
 * From CActive derivation
 */

void CMultiMediaFAdapter::DoCancel()
{
    if (iEncoder)
    {
        iEncoder->Cancel();
    }
    if (iDecoder)
    {
        iDecoder->Cancel();
    }
    iRotator->Cancel();
    iScaler->Cancel();
}

/**
* From MImageModel derivation
* Image that has been manipulated to be used for rendering by the view
* @return The manipulated image for display
*/
CFbsBitmap& CMultiMediaFAdapter::Image() const
{
    return *iImage;
}

/**
* Opens up a handle to an existing GIF file and converts it.
* Uses synchronous CImageDecoder::NewFileL and converts using CImageDecoder::ConvertL
* A CFbsBitmap is the destination of the conversion
* RunL() will be called when this is finished
*/
void CMultiMediaFAdapter::DecodeOpenAndConvertL()
{
    delete iDecoder;
    iDecoder = 0;

    iDecoder = CImageDecoder::FileNewL(iFs, KPathOfGifFile);

    TFrameInfo frmInfo = iDecoder->FrameInfo(KGifIndex);
    TRect rectOfImage = frmInfo.iFrameCoordsInPixels;

    delete iImage;
    iImage = 0;
    iImage = new (ELeave) CFbsBitmap();
    iImage->Create(rectOfImage.Size(), iDeviceDisplayMode);

    iDecoder->Convert(&iStatus, *iImage, KGifIndex);

    SetActive();
}

/**
* Creates a new JPG file in preparation for data from a CFbsBitmap.
* Converts CFbsBitmap data into a JPG
* RunL() will be called when this operation is finished
*/
void CMultiMediaFAdapter::EncodeOpenAndConvertL()
{
    // Create a new file ready for encoding.
    delete iEncoder;
    iEncoder = 0;
    iEncoder = CImageEncoder::FileNewL(iFs, KPathOfSaveJpgFile(), KJpgMime(), CImageEncoder::EOptionNone);

    // Setup the jpg saving information that is required.
    TJpegImageData* jpgData = new (ELeave) TJpegImageData();
    CleanupStack::PushL(jpgData);    // jpgData will be deleted by the Multi Media Framework

    jpgData->iQualityFactor = KJpgQuality;
    jpgData->iSampleScheme = TJpegImageData::EColor420;

    // Create the new image data.
    delete iJpgImageData;
    iJpgImageData = 0;
    iJpgImageData = CFrameImageData::NewL();

    // Set the saving information.
    User::LeaveIfError(iJpgImageData->AppendImageData(jpgData));    // Passes ownership if successful.
    CleanupStack::Pop(jpgData); // jpgData now owned by iJpgImageData.

    // Begin conversion process
    iEncoder->Convert(&iStatus, *iImage, iJpgImageData);
    SetActive();
}

/**
* Rotates the image 90 degrees in a clockwise direction
* RunL wil be called when this operation is finished
*/
void CMultiMediaFAdapter::Rotate90()
{
    iRotator->Rotate(&iStatus, *iImage, CBitmapRotator::ERotation90DegreesClockwise);
    SetActive();
}

/**
* Rotates the image 180 degrees in a clockwise direction
* RunL wil be called when this operation is finished
*/
void CMultiMediaFAdapter::Rotate180()
{
    iRotator->Rotate(&iStatus, *iImage, CBitmapRotator::ERotation180DegreesClockwise);
    SetActive();
}

/**
* Rotates the image 270 degrees in a clockwise direction
* RunL wil be called when this operation is finished
*/
void CMultiMediaFAdapter::Rotate270()
{
    iRotator->Rotate(&iStatus, *iImage, CBitmapRotator::ERotation270DegreesClockwise);
    SetActive();
}

/**
* Mirrors the image along the horizontal axis.
* RunL wil be called when this operation is finished
*/
void CMultiMediaFAdapter::RotateMirrorH()
{
    iRotator->Rotate(&iStatus, *iImage, CBitmapRotator::EMirrorHorizontalAxis);
    SetActive();
}

/**
* Mirrors the image along the vertical axis.
* RunL wil be called when this operation is finished
*/
void CMultiMediaFAdapter::RotateMirrorV()
{
    iRotator->Rotate(&iStatus, *iImage, CBitmapRotator::EMirrorVerticalAxis);
    SetActive();
}

/**
* Enlarges or shrinks the image. Choice is the opposite of the last scale operation.
* RunL wil be called when this operation is finished
*/
void CMultiMediaFAdapter::ScaleImage()
{
    if(iScaleState == EScaleDown)
    {
        iScaler->Scale(&iStatus, *iImage, TSize(KScaledWidthOne, KScaledHeightOne));
        iScaleState = EScaleUp;
    }
    else
    {
        iScaler->Scale(&iStatus, *iImage, TSize(KScaledWidthTwo, KScaledHeightTwo));
        iScaleState = EScaleDown;
    }
    SetActive();
}

/**
* Resets the image back to its original state
*/
void CMultiMediaFAdapter::ResetImageL()
{
    delete iImage;
    iImage = 0;
    iImage = new (ELeave) CFbsBitmap();

    TFileName fullname = KMbmPath();
    CompleteWithAppPath(fullname);    // Get drive application is installed on.

    iImage->Load(fullname, EMbmMultimediafLogo);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -