imaging/imagingfws/src/ImageConversionPriv.h
changeset 0 5752a19fdefe
equal deleted inserted replaced
-1:000000000000 0:5752a19fdefe
       
     1 // Copyright (c) 2001-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // Not for public use
       
    15 // These are structures for the Image Conversion Library
       
    16 // to maintain future binary compatibility
       
    17 // 
       
    18 //
       
    19 
       
    20 #ifndef IMAGECONVERSIONPRIV_H
       
    21 #define IMAGECONVERSIONPRIV_H
       
    22 
       
    23 #include "icl/ImageCodec.h"
       
    24 #include "icl/ImageData.h"
       
    25 #include "ImageConversion.h"
       
    26 #include "ImagePrivSupport.h"
       
    27 #include "icl/imageconversionextension.h"
       
    28 #ifdef SYMBIAN_ENABLE_SPLIT_HEADERS
       
    29 #include <icl/imagecodecdef.h>
       
    30 #endif
       
    31 
       
    32 #if defined(SYMBIAN_ENABLE_ENCODER_ASYNC_WRITES)
       
    33 #include "asyncfilewriter.h"
       
    34 #endif
       
    35 
       
    36 #include <caf/caf.h>
       
    37 #include <caf/content.h>
       
    38 #include <caf/data.h>
       
    39 
       
    40 using namespace ContentAccess;
       
    41 
       
    42 // incomplete forward declarations
       
    43 class CImageDecoderPlugin;
       
    44 class CImageEncoderPlugin;
       
    45 
       
    46 class RCImageDecoderPrivContinueProcessingHeaderLTest; 
       
    47 
       
    48 class CImageDataArray; // declared here
       
    49 NONSHARABLE_CLASS( CImageDataArray ): public CBase
       
    50 	{
       
    51 public:
       
    52 	~CImageDataArray();
       
    53 
       
    54 	// Access fns.
       
    55 	// Append/insert/delete
       
    56 	TInt InsertImageData(const TImageDataBlock* aEntry, TInt aPos);
       
    57 	TInt AppendImageData(const TImageDataBlock* aEntry);
       
    58 	void RemoveImageData(TInt aIndex);
       
    59 
       
    60 	// Get image data/local image data.
       
    61 	const TImageDataBlock* GetImageData(TInt aIndex) const;
       
    62 	TImageDataBlock* GetImageData(TInt aIndex);
       
    63 
       
    64 	// Get num entries.
       
    65 	TInt ImageDataCount() const;
       
    66 
       
    67 	// Append image buffers.
       
    68 	TInt AppendImageBuffer(const HBufC8* aImageBuffer);
       
    69 
       
    70 private:
       
    71 	// Image data for the frame. (Single frame formats)
       
    72 	// Image data that is the same for all frames. (Multi frame formats)
       
    73 	RPointerArray<TImageDataBlock> iImageData;
       
    74 
       
    75 	// List of HBufC8 (Comments) owned by us.
       
    76 	// Deleted when we are.
       
    77 	RPointerArray<HBufC8> iImageBuffers;
       
    78 
       
    79 friend class CFrameImageData;
       
    80 	};
       
    81 
       
    82 /*
       
    83 Interface to allow proxy (from straight), or stub (from threaded) to set the
       
    84 framework's TRequestStatus.
       
    85 */	
       
    86 class MFrameworkExtAsyncInterface
       
    87 	{
       
    88 public:
       
    89 	/*
       
    90 	Used only in conjunction with asynchronous framework extension methods.
       
    91 	It registers the calling thread's TRequestStatus with the framework, which is
       
    92 	signalled when RequestComplete() is called, indicating an error code (including
       
    93 	KErrNone) to the client.
       
    94 	@param 	aRequestThread 	The calling thread.
       
    95 	@param 	aRequestStatus	The calling thread's TRequestStatus.
       
    96 	*/
       
    97 	virtual void RegisterClientRequestStatus(RThread& aRequestThread, TRequestStatus* aRequestStatus) = 0;
       
    98 	
       
    99 	/*
       
   100 	Used only in conjunction with asynchronous framework extension methods.
       
   101 	Starts the framework AO, and thus the processing loop.
       
   102 	*/
       
   103 	virtual void StartActivity() = 0;
       
   104 	};
       
   105 
       
   106 // Properties for CImageDecoder
       
   107 class CImageDecoderPriv; // declared here
       
   108 NONSHARABLE_CLASS( CImageDecoderPriv ): public CActive,
       
   109 										public MFrameworkExtAsyncInterface
       
   110 	{
       
   111 public:
       
   112 	static CImageDecoderPriv* NewL(CImageDecodeConstruct *aConstruct, MImageDecoderPrivSupport* aSupport);
       
   113 	virtual ~CImageDecoderPriv();
       
   114 
       
   115 	void SetFileL(RFs& aFs, const TDesC& aSourceFilename, const CImageDecoder::TOptions aOptions = CImageDecoder::EOptionNone);
       
   116 	void SetFileL(RFile& aFile, const CImageDecoder::TOptions aOptions = CImageDecoder::EOptionNone);
       
   117 	void SetDataL(RFs& aFs, const TDesC8& aSourceData, const CImageDecoder::TOptions aOptions = CImageDecoder::EOptionNone);
       
   118 
       
   119 	void CreatePluginL();
       
   120 	CImageDecoderPlugin* Plugin() const;
       
   121 
       
   122 	void HandleNewlyOpenedImageL();
       
   123 
       
   124 	void InitConvertL();
       
   125 	void RequestInitL(TInt aFrameNumber);
       
   126 	void Convert(RThread& aRequestThread, TRequestStatus* aRequestStatus, CFbsBitmap& aDestination, TInt aFrameNumber);
       
   127 	void Convert(RThread& aRequestThread, TRequestStatus* aRequestStatus, CFbsBitmap& aDestination, CFbsBitmap& aDestinationMask, TInt aFrameNumber = 0);
       
   128 	void ContinueConvert(RThread& aRequestThread, TRequestStatus* aRequestStatus);
       
   129 
       
   130 	void DoConvert();
       
   131 	void PrepareForProcessFrameL();
       
   132 	void HandleProcessFrameResult(TInt aErrCode, TFrameState aCodecState);
       
   133 	TBufPtr8& SourceData();
       
   134 
       
   135 	void ContinueProcessingHeaderL();
       
   136 
       
   137 	void ReadDataL(TInt aPosition, TPtrC8& aReadBuffer, TInt aLength);
       
   138 
       
   139 	void CreateFrameInfoL();
       
   140 	void DeleteFrameInfoL();
       
   141 	void ReadFrameHeadersL();
       
   142 
       
   143 	const TFrameInfo& FrameInfo(TInt aFrameNumber) const;
       
   144 	CFrameInfoStrings* FrameInfoStringsLC(TInt aFrameNumber);
       
   145 
       
   146 	void Cleanup();
       
   147 	void RequestComplete(TInt aReason);
       
   148 	void SelfComplete(TInt aReason);
       
   149 	void SetSelfPending();
       
   150 
       
   151 	TUid ImplementationUid() const;
       
   152 
       
   153 	void SetImageTypeL(TInt aImageType);
       
   154 	
       
   155 	// custom command support
       
   156 	void CustomSyncL(TInt aParam);
       
   157 	void BodyHandleCustomSyncL(TInt aParam);
       
   158 	void CustomAsync(RThread& aRequestThread, TRequestStatus* aRequestStatus, TInt aParam);
       
   159 	void BodyInitCustomAsyncL(TInt aParam);
       
   160 	void BodyNotifyComplete();
       
   161 
       
   162 	// thread support to plugin
       
   163 	TBool AmInThread() const;
       
   164 	TBool ShouldAbort() const;
       
   165 
       
   166 	// straight access functions decoder
       
   167 	TInt FrameCount() const;
       
   168 	TBool IsImageHeaderProcessingComplete() const;
       
   169 	const CFrameImageData& FrameData(TInt aFrameNumber) const;
       
   170 
       
   171 	// straight access functions from plugin
       
   172 	CImageReadCodec* ImageReadCodec() const;
       
   173 	void SetImageReadCodec(CImageReadCodec* aImageReadCodec);
       
   174 	TInt DataLength() const;
       
   175 	void SetDataLength(TInt aDataLength);
       
   176 	TInt StartPosition() const;
       
   177 	void SetStartPosition(TInt aStartPosition);
       
   178 	const TImageDataBlock* ImageData(TInt aIndex) const;
       
   179 	TInt InsertImageData(const TImageDataBlock* aEntry, TInt aPos);
       
   180 	void RemoveImageData(TInt aPos);
       
   181 	TInt AppendImageData(const TImageDataBlock* aEntry);
       
   182 	TInt ImageDataCount() const;
       
   183 	TInt AppendImageDataBuffer(const HBufC8* aImageBuffer);
       
   184 	TInt NumberOfFrames() const;
       
   185 	TInt Position() const;
       
   186 	void SetPosition(const TInt aPosition);
       
   187 	const TFrameInfo& ImageInfo() const;
       
   188 	void SetImageInfo(const TFrameInfo& aImageInfo);
       
   189 	const CFbsBitmap& Destination() const;
       
   190 	TBool ValidDestination() const;
       
   191 	const CFbsBitmap& DestinationMask() const;
       
   192 	TBool ValidDestinationMask() const;
       
   193 	TInt SourceLength() const;
       
   194 
       
   195 	void SetIntent(TIntent aIntent);
       
   196 
       
   197 	void SetUniqueIdL(const TDesC& aUniqueId);
       
   198 	TInt SetAgentProperty(TAgentProperty aProperty, TInt aValue);
       
   199 
       
   200 	void SetThumbnailData(HBufC8* aThumbnailData);
       
   201 	
       
   202 	TInt ReductionFactor(const TSize& aOriginalSize, const TSize& aReducedSize) const;
       
   203 	TInt ReducedSize(const TSize& aOriginalSize, TInt aReductionFactor, TSize& aReducedSize) const;
       
   204 	
       
   205 	inline CImageDecoder::TOptions DecoderOptions() const;
       
   206 	
       
   207 	// Framework extension
       
   208 	void GetExtensionL(TUid aExtUid, MImageConvExtension*& aExtPtr);
       
   209 	void SetClippingRectL(const TRect* aClipRect);
       
   210 	TInt GetDestinationSize(TSize& aSize, TInt aFrameNumber = 0);
       
   211 	
       
   212 	// From MFrameworkExtAsyncInterface
       
   213 	void RegisterClientRequestStatus(RThread& aRequestThread, TRequestStatus* aRequestStatus);
       
   214 	void StartActivity();
       
   215 	
       
   216 protected:
       
   217 	TBool MustUseBufferWithDescriptor() const;
       
   218 	void CopyBufferToDescriptor(TDes8& aBuffer, const TDesC8& aSource, TInt aPosition, TInt aSize);
       
   219 
       
   220 private:
       
   221 
       
   222 	CImageDecoderPriv(CImageDecodeConstruct* aConstruct, MImageDecoderPrivSupport* aSupport);
       
   223 
       
   224 	void RunL(); // From CActive
       
   225 	void DoCancel();
       
   226 
       
   227 	void OpenExtraResourceFileLC(RFs& aFs, const TUid aUid, RResourceFile& aResourceFile) const;
       
   228 	TInt DataSizeL();
       
   229 	void SeekReadL(TInt aPosition, TDes8& aDest, TInt aSize);
       
   230 
       
   231 
       
   232 private:
       
   233 	// Frame info and frame data arrays. (Local frame settings)
       
   234 	RPointerArray<TFrameInfo> iFrameInfo;
       
   235 	RPointerArray<CFrameImageData> iFrameData;
       
   236 
       
   237 	TFrameInfo iImageInfo;
       
   238 	CImageDataArray iImageData;
       
   239 
       
   240 	// Global frame settings 
       
   241 	CFbsBitmap* iDestination;     // not owned
       
   242 	CFbsBitmap* iDestinationMask; // not owned
       
   243 
       
   244 	TInt iDataLength;
       
   245 	TInt iStartPosition;
       
   246 	TInt iPosition;
       
   247 	TInt iSrcLength;
       
   248 	TBufPtr8 iSrcDes;
       
   249 
       
   250 	CImageReadCodec* iImageReadCodec;
       
   251 	TBool iHaveCompleteImageHeaders;
       
   252 	
       
   253 	TInt iImageType;
       
   254 	HBufC8* iThumbnailData;
       
   255 	
       
   256 private:
       
   257 	RFs* iFs;
       
   258 	CContent* iContent;
       
   259 	CData* iData;
       
   260 	TIntent iIntent;
       
   261 	HBufC* iUniqueId;
       
   262 	TImageParameterData iImageParameterData;
       
   263 	TFileName iFileName;
       
   264 	TInt iDestinationHandle;
       
   265 	TInt iDestinationMaskHandle;
       
   266 
       
   267 	HBufC8* iReadBuffer;
       
   268 
       
   269 	TInt iNextFrameOffset;
       
   270 	TBool iProcessingFrameInfo;
       
   271 
       
   272 	TInt iBlockLength;
       
   273 	TInt iCurrentBlockLength;
       
   274 	TSize iDestinationSize; // used to check we don't continue with different bitmap
       
   275 	TInt iOldSrcDesLength;
       
   276 
       
   277 	CImageDecoder::TOptions iOptions;
       
   278 
       
   279 	RThread* iRequestThread; // not owned
       
   280 	TRequestStatus* iConvStatus; // not owned
       
   281 	TInt iCurrentFrame;
       
   282 	TBool iCurrentlyProcessingData;
       
   283 
       
   284 	CImageDecodeConstruct* iConstruct; // not owned
       
   285 	MImageDecoderPrivSupport* iSupport; // not owned
       
   286 	CImageDecoderPlugin* iPlugin;
       
   287 	TBool iIntentHasBeenExecuted;
       
   288 	/** Size of data source in bytes.  Only valid if data source is read-only. */
       
   289 	 TInt iCachedDataSize;
       
   290 	 /** Start byte of last read from data file. */
       
   291 	TInt iLastPos;
       
   292 	/** Byte after last data block which was read from data source. */
       
   293 	 TInt iLastExtent;
       
   294 	 /** Flag to indicate if file input is read only or will grow  **/
       
   295 	 TBool iReadOnly;
       
   296 	 /** Flag to Check whether to Use Image buffer read optimization **/
       
   297 	 TBool iUseBufferReadOptimization;
       
   298 
       
   299 // allow direct access to unit tests.
       
   300 friend class RCImageDecoderPrivTestBase;
       
   301 friend class RCImageDecoderPrivContinueProcessingHeaderLTest;
       
   302 	};
       
   303 
       
   304 // forward declaration - gives access to internal destination buffer
       
   305 class CImageEncoderPrivTestAccess;
       
   306 
       
   307 // Properties for CImageEncoder
       
   308 class CImageEncoderPriv; // declared here
       
   309 NONSHARABLE_CLASS( CImageEncoderPriv ): public CActive,
       
   310 										public MFrameworkExtAsyncInterface
       
   311 #if defined(SYMBIAN_ENABLE_ENCODER_ASYNC_WRITES)
       
   312  ,protected MBufferWrittenObserver
       
   313 #endif
       
   314 	{
       
   315 public:
       
   316 	static CImageEncoderPriv* NewL(CImageEncodeConstruct* aConstruct, MImageEncoderPrivSupport* aSupport);
       
   317 	virtual ~CImageEncoderPriv();
       
   318 
       
   319 	void SetFileL(RFs& aFs, const TDesC& aDestinationFilename, const CImageEncoder::TOptions aOptions = CImageEncoder::EOptionNone);
       
   320 	void SetFileL(RFile& aFile, const CImageEncoder::TOptions aOptions = CImageEncoder::EOptionNone);
       
   321 	void SetDataL(HBufC8*& aDestinationData, const CImageEncoder::TOptions aOptions = CImageEncoder::EOptionNone);
       
   322 
       
   323 	void CreatePluginL();
       
   324 	CImageEncoderPlugin* Plugin() const;
       
   325 
       
   326 	TInt CurrentImageSizeL() const;
       
   327 	void Cleanup();
       
   328 	void InitConvertL();
       
   329 	void RequestInitL();
       
   330 	void Convert(RThread& aRequestThread, TRequestStatus* aRequestStatus, const CFbsBitmap& aSource, const CFrameImageData* aFrameImageData);
       
   331 	void WriteDataL(TInt aPosition,const TDesC8& aDes);
       
   332 	void WriteDataPositionIncL(TInt aPosition,const TDesC8& aDes);
       
   333 	void DoConvert();
       
   334 	void HandleProcessFrameResult(TInt aErrCode, TFrameState aCodecState);
       
   335 	TBufPtr8& DestinationData();
       
   336 	void DoCancel();
       
   337 	void FinishConvertL();
       
   338 
       
   339 	TUid ImplementationUid() const;
       
   340 
       
   341 	// custom command support
       
   342 	void CustomSyncL(TInt aParam);
       
   343 	void BodyHandleCustomSyncL(TInt aParam);
       
   344 	void CustomAsync(RThread& aRequestThread, TRequestStatus* aRequestStatus, TInt aParam);
       
   345 	void BodyInitCustomAsyncL(TInt aParam);
       
   346 	void BodyNotifyComplete();
       
   347 
       
   348 	void RequestComplete(TInt aReason);
       
   349 	void SelfComplete(TInt aReason);
       
   350 	void SetSelfPending();
       
   351 
       
   352 	// thread support to plugin
       
   353 	TBool AmInThread() const;
       
   354 	TBool ShouldAbort() const;
       
   355 
       
   356 	// Data access from CImageEncoderPlugin
       
   357 	CImageWriteCodec* ImageWriteCodec() const;
       
   358 	void SetImageWriteCodec(CImageWriteCodec* aImageWriteCodec);
       
   359 	const CFbsBitmap& Source() const;
       
   360 	TBool ValidSource() const;
       
   361 	TInt& StartPosition();
       
   362 	TInt& Position();
       
   363 	const TSize& FrameInfoOverallSizeInPixels() const;
       
   364 
       
   365 	void SetThumbnail(TBool aDoGenerateThumbnail);
       
   366 	
       
   367 	inline CImageEncoder::TOptions EncoderOptions() const;
       
   368 	
       
   369 	// Framework extension
       
   370 	void GetExtensionL(TUid aExtUid, MImageConvExtension*& aExtPtr);
       
   371 	
       
   372 	// From MFrameworkExtAsyncInterface
       
   373 	void RegisterClientRequestStatus(RThread& aRequestThread, TRequestStatus* aRequestStatus);
       
   374 	void StartActivity();
       
   375 	
       
   376 #if defined(SYMBIAN_ENABLE_ENCODER_ASYNC_WRITES)		
       
   377 protected:
       
   378     void DoHandleProcessFrameResultL(TFrameState aCodecState);
       
   379     
       
   380     // from the MBufferWrittenObserver
       
   381     virtual void BufferWritten(const TPtrC8& aWritten, TInt aErrorCode);
       
   382 #endif // defined(SYMBIAN_ENABLE_ENCODER_ASYNC_WRITES)
       
   383 
       
   384 private:
       
   385 	CImageEncoderPriv(CImageEncodeConstruct* aConstruct, MImageEncoderPrivSupport* aSupport);
       
   386 
       
   387 	void RunL();
       
   388 
       
   389 private:
       
   390 	RThread* iRequestThread; // not owned
       
   391 	TRequestStatus* iConvStatus; // not owned
       
   392 	TFrameInfo iFrameInfo;
       
   393 	CImageWriteCodec* iImageWriteCodec;
       
   394 	TBufPtr8 iDstDes;
       
   395 	HBufC8* iDstBuffer;
       
   396 	HBufC8* iFinalDstBuffer;
       
   397 	HBufC8** iDestination;
       
   398 	TInt iStartPosition;
       
   399 	TInt iPosition;
       
   400 	
       
   401 	TBool iHeaderWritten;	// describes if the header has been written or not
       
   402 
       
   403 	CImageEncoder::TOptions iOptions;
       
   404 
       
   405 	RFs* iFs;
       
   406 	RFile iFile;
       
   407 	TFileName iFileName;
       
   408 
       
   409 	const CFbsBitmap* iSource;
       
   410 	TImageParameterData iImageParameterData;
       
   411 	TBool iConvertStarted;
       
   412 
       
   413 private:
       
   414 	CImageEncodeConstruct* iConstruct; // not owned
       
   415 	MImageEncoderPrivSupport* iSupport;
       
   416 	CImageEncoderPlugin* iPlugin;
       
   417 	
       
   418 #if defined(SYMBIAN_ENABLE_ENCODER_ASYNC_WRITES)	
       
   419 	CAsyncFileWriter* iAsyncFileWriter;
       
   420 	TInt iWriterError;
       
   421 	
       
   422 #else
       
   423 	TBool iLastBuffer;
       
   424 #endif // defined(SYMBIAN_ENABLE_ENCODER_ASYNC_WRITES)
       
   425 
       
   426 // allow this class access to internal buffers
       
   427 friend class CImageEncoderPrivTestAccess;
       
   428 	};
       
   429 
       
   430 #include "ImageConversionPriv.inl"
       
   431 
       
   432 
       
   433 #endif // IMAGECONVERSIONPRIV_H
       
   434