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

📄 imagemanipadapter.cpp

📁 鲜为人知的symbian s60 2rd图形图像处理源代码
💻 CPP
字号:
/**
 *
 * @brief Definition of CImageManipApplication
 *
 * Copyright (c) EMCC Software Ltd 2003
 * @version 1.0
 */

// INCLUDE FILES

// Class includes
#include "ImageManipAdapter.h"

// System includes
#include <aknutils.h>		// CompletePathWithAppPath()
#include <fbs.h>			// CFbsBitmap
#include <ImageManip.mbg>	// EMbmImagemanipLogo

// User includes
#include "ImageManip.hrh"
#include "MultimediaController.h"

// CONSTANTS
_LIT(KPathOfGifFile, "\\system\\apps\\ImageManip\\GifFile.gif");
_LIT(KPathOfSaveJpgFile, "\\system\\apps\\ImageManip\\OutputFile.jpg");
_LIT(KMbmPath, "\\system\\apps\\ImageManip\\ImageManip.mbm");

const TInt KGifIndex = 0;
const TInt KJpgIndex = 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 CImageManipAdapter 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 CImageManipAdapter
 */
CImageManipAdapter* CImageManipAdapter::NewL(MMultimediaController& aMultimediaController, TDisplayMode aDeviceDisplayMode)
	{
	CImageManipAdapter* self = CImageManipAdapter::NewLC(aMultimediaController, aDeviceDisplayMode);
	CleanupStack::Pop();
	return self;
	}

/**
 * Symbian OS 2 phase constructor.
 * Constructs the CImageManipAdapter 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 CImageManipAdapter
 */
CImageManipAdapter* CImageManipAdapter::NewLC(MMultimediaController& aMultimediaController, TDisplayMode aDeviceDisplayMode)
	{
	CImageManipAdapter* self = new (ELeave) CImageManipAdapter(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 CImageManipAdapter::ConstructL()
	{
	iFileToBitmap = CMdaImageFileToBitmapUtility::NewL(*this);
	iBitmapToFile = CMdaImageBitmapToFileUtility::NewL(*this);
	iScaler = CMdaBitmapScaler::NewL();
	iRotator = CMdaBitmapRotator::NewL();

	ResetImageL();

	iJpgFormat = new (ELeave) TMdaJfifClipFormat();
	}

/**
* 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
*/
CImageManipAdapter::CImageManipAdapter(MMultimediaController& aMultimediaController, TDisplayMode aDeviceDisplayMode)
 :	iMultimediaController(aMultimediaController),
	iScaleState(EScaleDown),
	iDeviceDisplayMode(aDeviceDisplayMode)
	{
	}

/**
 * Destructor.
 */
CImageManipAdapter::~CImageManipAdapter()
	{
	delete iFileToBitmap;
	delete iBitmapToFile;
	delete iRotator;
	delete iScaler;
	delete iImage;
	delete iJpgFormat;
	}

/**
* Routes the commands obtained by the AppUi into the ImageManipAdapter to
* perform the user desired image manipulation
*
* @param aCommand The command Id from the AppUi used to decided which operation to perform
*/
void CImageManipAdapter::HandleCommandL(TInt aCommand)
	{
	switch (iManipulationState)
		{
		case EDecode:
			iFileToBitmap->Cancel();
			break;
		case EEncode:
			iBitmapToFile->Cancel();
			break;
		case ERotating:
			iRotator->CancelRotation();
			break;
		case EScaling:
			iScaler->CancelScaling();
			break;
		default:
			// Do nothing.
			break;
		}

	switch (aCommand)
		{
		case EDecodeImage:
			iManipulationState = EDecode;
			DecodeOpenL();
			break;
		case EEncodeImage:
			iManipulationState = EEncode;
			EncodeOpenL();
			break;
		case ERotate90:
			iManipulationState = ERotating;
			Rotate90L();
			break;
		case ERotate180:
			iManipulationState = ERotating;
			Rotate180L();
			break;
		case ERotate270:
			iManipulationState = ERotating;
			Rotate270L();
			break;
		case EScale:
			iManipulationState = EScaling;
			ScaleImageL();
			break;
		case EResetImage:
			iManipulationState = EDoNothing;
			ResetImageL();
			iMultimediaController.RedrawView();
			break;
		default:
			// Do nothing.
			break;
			}
	}

/**
* From MMdaImageUtilObserver derivation.
* Used to inform client code that a conversion, rotation or scaling operation
* has completed.
* Following this the view is informed to redraw
*
* @param aError An error code value in case manipulation step failed
*/
void CImageManipAdapter::MiuoConvertComplete(TInt aError)
	{
	if (aError == KErrNone)
		{
		switch (iManipulationState)
			{
			case EDecode:
			case EEncode:
			case ERotating:
			case EScaling:
				iManipulationState = EDoNothing;
				iMultimediaController.RedrawView();
				break;
			default:
				break;
			}
		}
	}

/**
* From MMdaImageUtilObserver derivation.
* Used to inform client code that a file creation operation
* has completed.
* Following this the image data will be stored in the file created previously
*
* @param aError An error code value in case manipulation step failed
*/
void CImageManipAdapter::MiuoCreateComplete(TInt aError)
	{
	if (aError == KErrNone)
	{
		switch (iManipulationState)
			{
			case EEncode:
				TRAPD (err, EncodeConvertL());
				break;
			default:
				break;
			}
		}
	}

/**
* From MMdaImageUtilObserver derivation.
* Used to inform client code that an open operation has completed allowing the
* subsequent encoding or decoding of an image file
*
* @param aError An error code value in case manipulation step failed
*/
void CImageManipAdapter::MiuoOpenComplete(TInt aError)
	{
	if (aError == KErrNone)
		{
		switch(iManipulationState)
			{
			case EDecode:
				TRAPD (err, DecodeConvertL());
				break;
			default:
				break;
			}
		}
	}

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

/**
* Opens up a handle to an existing GIF file.
* MuioOpenComplete() will be called when this is finished
*/
void CImageManipAdapter::DecodeOpenL()
	{
	TFileName fileName (KPathOfGifFile);
	CompleteWithAppPath (fileName);
	iFileToBitmap->OpenL(fileName);
	}

/**
* Copies the GIF file into a CFbsBitmap that will be suitable for display.
* MuioConvertComplete() will be called when this operation is finished
*/
void CImageManipAdapter::DecodeConvertL()
	{
	TFrameInfo frmInfo;
	iFileToBitmap->FrameInfo(KGifIndex, frmInfo);
	iImage->Create(frmInfo.iOverallSizeInPixels, iDeviceDisplayMode);
	iFileToBitmap->ConvertL(*iImage, KGifIndex);
	}

/**
* Creates a new JPG file in preparation for data from a CFbsBitmap.
* MuioCreateComplete() will be called when this operation is finished
*/
void CImageManipAdapter::EncodeOpenL()
	{
	// setup the jpg saving information that is required
	iJpgFormat->iSettings.iQualityFactor = KJpgQuality;
	iJpgFormat->iSettings.iSampleScheme = TMdaJpgSettings::TColorSampling(TMdaJpgSettings::EColor420);

	TMdaPackage* codec = NULL;
	TFileName fileName (KPathOfSaveJpgFile);
	CompleteWithAppPath (fileName);
	iBitmapToFile->CreateL(fileName, iJpgFormat, codec, NULL);
	}

/**
* Copies the CFbsBitmap data in a JPG file will be suitable for use in other applications.
* MuioConvertComplete() will be called when this operation is finished
*/
void CImageManipAdapter::EncodeConvertL()
	{
	iBitmapToFile->ConvertL(*iImage, KJpgIndex);
	}

/**
* Rotates the image 90 degrees in a clockwise direction
* MuioConvertComplete wil be called when this operation is finished
*/
void CImageManipAdapter::Rotate90L()
	{
	iRotator->RotateL(*this, *iImage, CMdaBitmapRotator::ERotation90DegreesClockwise);
	}

/**
* Rotates the image 180 degrees in a clockwise direction
* MuioConvertComplete wil be called when this operation is finished
*/
void CImageManipAdapter::Rotate180L()
	{
	iRotator->RotateL(*this, *iImage, CMdaBitmapRotator::ERotation180DegreesClockwise);
	}

/**
* Rotates the image 270 degrees in a clockwise direction
* MuioConvertComplete wil be called when this operation is finished
*/
void CImageManipAdapter::Rotate270L()
	{
	iRotator->RotateL(*this, *iImage, CMdaBitmapRotator::ERotation270DegreesClockwise);
	}

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

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

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

	iImage->Load(fullname, EMbmImagemanipLogo);
	}

// End of File

⌨️ 快捷键说明

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