epoc32/include/icl/imagecodec.h
branchSymbian2
changeset 2 2fe1408b6811
parent 0 061f57f2323e
child 4 837f303aceeb
equal deleted inserted replaced
1:666f914201fb 2:2fe1408b6811
     1 imagecodec.h
     1 // Copyright (c) 2002-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 the License "Symbian Foundation License v1.0" to Symbian Foundation members and "Symbian Foundation End User License Agreement v1.0" to non-members
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.symbianfoundation.org/legal/licencesv10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 #ifndef __IMAGECODEC_H__
       
    17 #define __IMAGECODEC_H__
       
    18 
       
    19 #include <e32std.h>
       
    20 #include <fbs.h>
       
    21 
       
    22 // Pre-definitions needed to make sure everything always defined in the right order
       
    23 class TFrameInfo;
       
    24 class TImageDataBlock;
       
    25 class CFrameImageData;
       
    26 
       
    27 class CImageDecoder;
       
    28 class CImageEncoder;
       
    29 class CImageProcessor; 
       
    30 class CImageProcessorReadCodecBody;
       
    31 class CImageMaskProcessorReadCodecBody;
       
    32 
       
    33 /**
       
    34 @publishedAll
       
    35 @released
       
    36 
       
    37 Indicates what processing has so far been completed on the frame.
       
    38 */
       
    39 enum TFrameState
       
    40 	{
       
    41 	/** Processing incomplete.
       
    42 	*/
       
    43 	EFrameIncomplete,
       
    44 	/** Processing complete.
       
    45 	*/
       
    46 	EFrameComplete,
       
    47 	/** Unexpected end of frame data.
       
    48 	*/
       
    49 	EUnexpectedEndOfData,
       
    50 	/** Same as EFrameIncomplete but also requests a call to CImageReadCodec::GetNewDataPosition().
       
    51 	*/
       
    52 	EFrameIncompleteRepositionRequest,
       
    53 	/** Processing of streaming block is complete.
       
    54 	*/
       
    55 	EBlockComplete
       
    56 	};
       
    57 
       
    58 /**
       
    59 @internalComponent
       
    60 
       
    61 
       
    62 Class used to shadow the descriptor supplying the image data.
       
    63 
       
    64 It maintains a flag to determine whether the descriptor contains a
       
    65 filename or the image data itself.
       
    66 
       
    67 This class is not intended for public use.
       
    68 */
       
    69 class TImageParameterData
       
    70 	{
       
    71 public:
       
    72 
       
    73 	/**
       
    74 	Flag used to determine what the descriptor contains.
       
    75 	*/
       
    76 	enum TImageParameterDataFlag
       
    77 		{
       
    78 		/** Field not set.
       
    79 		*/
       
    80 		ENull		= 0x00000000,
       
    81 
       
    82 		/** Descriptor is a filename.
       
    83 		*/
       
    84 		EFilename	= 0x00000001,
       
    85 
       
    86 		/** Descriptor contains data.
       
    87 		*/
       
    88 		EData		= 0x00000002
       
    89 		};
       
    90 
       
    91 	TImageParameterData();
       
    92 	void SetFilenamePtr(const TDesC* aSourceFilenamePtr);
       
    93 	void SetDataPtr(const TDesC8* aSourceDataPtr);
       
    94 	IMPORT_C TBool IsFilename() const;
       
    95 	IMPORT_C const TDesC* SourceFilenamePtr() const;
       
    96 	IMPORT_C const TDesC8* SourceDataPtr() const;
       
    97 
       
    98 private:
       
    99 	TImageParameterDataFlag iImageParameterDataFlag;
       
   100 	union
       
   101 		{
       
   102 		const TDesC* iSourceFilenamePtr;
       
   103 		const TDesC8* iSourceDataPtr;
       
   104 		};
       
   105 	};
       
   106 
       
   107 /**
       
   108 @publishedAll
       
   109 @released
       
   110 
       
   111 Utility class to allow forward iteration through the data contained in
       
   112 an 8 bit descriptor.
       
   113 
       
   114 @see TPtr8
       
   115 @see TPtrC8
       
   116 @see TDes8
       
   117 @see TDesC8
       
   118 */
       
   119 class TBufPtr8 : public TPtr8
       
   120 	{
       
   121 public:
       
   122 	/**
       
   123 	Default constructor.
       
   124 	*/
       
   125 	TBufPtr8()
       
   126 		: TPtr8(0, 0, 0) {};
       
   127 	inline void Set(const TDes8& aDes);
       
   128 	inline void SetLengthOnly(const TDes8& aDes);
       
   129 	inline void Set(const TPtrC8& aDes);
       
   130 	inline void Shift(TInt aOffset);
       
   131 	};
       
   132 
       
   133 /**
       
   134 Produces a shallow copy of the argument descriptor.
       
   135 
       
   136 @param  aDes
       
   137         A reference to the descriptor containing the relevant data.
       
   138 */
       
   139 inline void TBufPtr8::Set(const TDes8& aDes)
       
   140 	{
       
   141 	TPtr8::Set(CONST_CAST(TUint8*,aDes.Ptr()), aDes.Length(), aDes.MaxLength());
       
   142 	}
       
   143 
       
   144 /**
       
   145 Produces a shallow copy of the argument descriptor, but also restricts
       
   146 pointer access to the current actual size of the argument descriptor.
       
   147 
       
   148 @param  aDes
       
   149         A reference to the descriptor containing the relevant data.
       
   150 */
       
   151 inline void TBufPtr8::SetLengthOnly(const TDes8& aDes)
       
   152 	{
       
   153 	TPtr8::Set(CONST_CAST(TUint8*,aDes.Ptr()), aDes.Length(), aDes.Length());
       
   154 	}
       
   155 /**
       
   156 Produces a shallow copy of the argument descriptor, but restricts
       
   157 pointer access to the size of the const argument descriptor.
       
   158 
       
   159 @param  aDes
       
   160         A reference to the descriptor containing the relevant data.
       
   161 */
       
   162 inline void TBufPtr8::Set(const TPtrC8& aDes)
       
   163 	{
       
   164 	TPtr8::Set(CONST_CAST(TUint8*,aDes.Ptr()), aDes.Length(), aDes.Length());
       
   165 	}
       
   166 /**
       
   167 Seeks the current data pointer aOffset bytes from the current position.
       
   168 
       
   169 @param  aOffset
       
   170         The number of bytes by which to seek.
       
   171 */
       
   172 inline void TBufPtr8::Shift(TInt aOffset)
       
   173 	{
       
   174 	SetLength(Length() - aOffset); iMaxLength -= aOffset; iPtr += aOffset;
       
   175 	}
       
   176 
       
   177 /**
       
   178 @publishedAll
       
   179 @released
       
   180 
       
   181 Provides read related processing functions for bitmaps.
       
   182 
       
   183 Note: For use by plugin writers only.
       
   184 */
       
   185 class CImageReadCodec : public CBase
       
   186 	{
       
   187 public:
       
   188 	IMPORT_C ~CImageReadCodec();
       
   189 
       
   190 	/**
       
   191 	Performs initial processing of image data and mask bitmaps.
       
   192 
       
   193 	This function processes the image frame using data supplied in
       
   194 	aFrameInfo, aFrameImageData and using the flag aDisableErrorDiffusion. Not all codecs
       
   195 	are expected to make use of all fields.
       
   196 
       
   197 	This is a virtual function that each derived class must implement.
       
   198 
       
   199 	@param	aFrameInfo
       
   200 	        A reference to a TFrameInfo object.
       
   201 	@param	aFrameImageData
       
   202 	        A reference to a CFrameImageData object.
       
   203 	@param	aDisableErrorDiffusion
       
   204 	        A flag indicating whether error diffusion should be disabled.
       
   205 	@param	aDestination
       
   206 	        The destination bitmap.
       
   207 	@param	aDestinationMask
       
   208 	        The destination mask bitmap.
       
   209 	*/
       
   210 	virtual void InitFrameL(TFrameInfo& aFrameInfo, CFrameImageData& aFrameImageData, TBool aDisableErrorDiffusion, CFbsBitmap& aDestination, CFbsBitmap* aDestinationMask) = 0;
       
   211 
       
   212 	IMPORT_C virtual void InitFrameHeader(TFrameInfo& aFrameInfo, CFrameImageData& aFrameData);
       
   213 	IMPORT_C virtual TFrameState ProcessFrameHeaderL(TBufPtr8& aData);
       
   214 	IMPORT_C virtual void Complete(); // Called on frame completion and on underflow
       
   215 	IMPORT_C virtual void GetNewDataPosition(TInt& aPosition, TInt& aLength); // Returns a new position for the data stream, (also length of data required)
       
   216 
       
   217 	/**
       
   218 	Processes the frame data contained in aSrc.
       
   219 
       
   220 	This is a pure virtual function that each derived class must implement.
       
   221 
       
   222 	@param  aSrc
       
   223 	        A reference to the buffer containing the frame data.
       
   224 
       
   225 	@return	The current frame state after processing.
       
   226 	*/
       
   227 	virtual TFrameState ProcessFrameL(TBufPtr8& aSrc) = 0;
       
   228 	void SetCurrentFrame(TInt aFrameNumber);
       
   229 	
       
   230 	IMPORT_C virtual TInt ReductionFactor(const TSize& aOriginalSize, const TSize& aReducedSize) const;
       
   231 	IMPORT_C virtual TInt ReducedSize(const TSize& aOriginalSize,TInt aReductionFactor, TSize& aReducedSize) const;
       
   232 	
       
   233 protected:
       
   234 	IMPORT_C CImageReadCodec();
       
   235 	IMPORT_C void ConstructL();
       
   236 
       
   237 	IMPORT_C void ClearBitmapL(CFbsBitmap& aBitmap, TRgb aColor);
       
   238 	IMPORT_C TInt CurrentFrame() const;
       
   239 
       
   240 private:
       
   241 	// Future proofing
       
   242 	IMPORT_C virtual void ReservedVirtual1();
       
   243 	IMPORT_C virtual void ReservedVirtual2();
       
   244 	IMPORT_C virtual void ReservedVirtual3();
       
   245 	IMPORT_C virtual void ReservedVirtual4();
       
   246 
       
   247 private:
       
   248 	TInt iCurrentFrame; //make handle to body if additional properties are needed
       
   249 	};
       
   250 
       
   251 /**
       
   252 @publishedAll
       
   253 @released 
       
   254 
       
   255 Provides functions to determine or set features of the codec's CImageProcessor.
       
   256 
       
   257 Note: 
       
   258 For use by plugin writers only.
       
   259 */
       
   260 class CImageProcessorReadCodec : public CImageReadCodec
       
   261 	{
       
   262 public:
       
   263 	IMPORT_C ~CImageProcessorReadCodec();
       
   264 protected:
       
   265 	IMPORT_C CImageProcessorReadCodec();
       
   266 	IMPORT_C void ConstructL();
       
   267 
       
   268 	IMPORT_C CImageProcessor* ImageProcessor() const;
       
   269 	IMPORT_C void SetImageProcessor(CImageProcessor* aImageProc);
       
   270 
       
   271 	IMPORT_C const TPoint& Pos() const;
       
   272 	IMPORT_C TPoint& Pos();
       
   273 	IMPORT_C void SetPos(const TPoint& aPos);
       
   274 private:
       
   275 	CImageProcessorReadCodecBody* iBody;
       
   276 	};
       
   277 
       
   278 /**
       
   279 @publishedAll
       
   280 @released
       
   281 
       
   282 Provides functions to determine or set features of the codec's CImageProcessor for a bitmap mask.
       
   283 
       
   284 Note: For use by plugin writers only.
       
   285 */
       
   286 class CImageMaskProcessorReadCodec : public CImageProcessorReadCodec
       
   287 	{
       
   288 public:
       
   289 	IMPORT_C ~CImageMaskProcessorReadCodec();
       
   290 protected:
       
   291 	IMPORT_C CImageMaskProcessorReadCodec();
       
   292 	IMPORT_C void ConstructL();
       
   293 
       
   294 	IMPORT_C CImageProcessor* MaskProcessor() const;
       
   295 	IMPORT_C void SetMaskProcessor(CImageProcessor* aMaskProc);
       
   296 
       
   297 private:
       
   298 	CImageMaskProcessorReadCodecBody* iBody;
       
   299 	};
       
   300 
       
   301 
       
   302 /**
       
   303 @publishedAll
       
   304 @released
       
   305 
       
   306 Interface to be used by read codec implementations in conjunction with framework extension.
       
   307 */
       
   308 class MReadCodecExtension
       
   309 	{
       
   310 public:
       
   311 	/**
       
   312 	Obtains the scaling coefficient 
       
   313 	@param 	aOriginalSize	A reference to the original size of an image.
       
   314 	@param 	aDesiredSize	A reference to the desired size of an image.
       
   315 	@return	The scaling coefficient, for example:
       
   316 			Original size = 1 or -1,
       
   317 			Half original size = -2,
       
   318 			Quarter original size = -3 etc.
       
   319 	*/
       
   320 	virtual TInt ScalingCoefficient(const TSize& aOriginalSize, const TSize& aDesiredSize) const = 0;
       
   321 	
       
   322 	/**
       
   323 	Obtains the reduced size of the decoded bitmap based on the input parameters
       
   324 	and updates aReducedSize with this value.
       
   325 
       
   326 	@param  aOriginalSize		A reference to the original size of an image.
       
   327 	@param  aScalingCoeff		The scaling coefficient to be applied.
       
   328 	@param  aReducedSize		A reference to the new size of an image.
       
   329 	@return KErrNone			If the function call was successful.
       
   330 	@return 					A range of system wide error values.
       
   331 	*/
       
   332 	virtual TInt GetReducedSize(const TSize& aOriginalSize, TInt aScalingCoeff, TSize& aReducedSize) const = 0;	
       
   333 	};
       
   334 
       
   335 /**
       
   336 @publishedAll
       
   337 @released
       
   338 
       
   339 Provides functions to determine or set features of the codec's CImageProcessor plus
       
   340 provide extra functionality for Framework Extensions.
       
   341 
       
   342 Note: 
       
   343 For use by plugin writers only.
       
   344 */
       
   345 class CImageProcessorReadCodecExtension : public CImageProcessorReadCodec,
       
   346 										  public MReadCodecExtension											
       
   347 	{
       
   348 public:
       
   349 	IMPORT_C ~CImageProcessorReadCodecExtension();
       
   350 protected:
       
   351 	IMPORT_C CImageProcessorReadCodecExtension();
       
   352 	IMPORT_C void ConstructL();
       
   353 	
       
   354 	// From MReadCodecExtension
       
   355 	IMPORT_C TInt ScalingCoefficient(const TSize& aOriginalSize, const TSize& aDesiredSize) const;
       
   356 	IMPORT_C TInt GetReducedSize(const TSize& aOriginalSize, TInt aScalingCoeff, TSize& aReducedSize) const;
       
   357 	};
       
   358 
       
   359 /**
       
   360 @publishedAll
       
   361 @released
       
   362 
       
   363 Provides functions to determine or set features of the codec's CImageProcessor plus
       
   364 provide extra functionality for Framework Extensions.
       
   365 
       
   366 Note: 
       
   367 For use by plugin writers only.
       
   368 */
       
   369 class CImageMaskProcessorReadCodecExtension : public CImageMaskProcessorReadCodec,
       
   370 										  	  public MReadCodecExtension											
       
   371 	{
       
   372 public:
       
   373 	IMPORT_C ~CImageMaskProcessorReadCodecExtension();
       
   374 protected:
       
   375 	IMPORT_C CImageMaskProcessorReadCodecExtension();
       
   376 	IMPORT_C void ConstructL();
       
   377 	
       
   378 	// From MReadCodecExtension
       
   379 	IMPORT_C TInt ScalingCoefficient(const TSize& aOriginalSize, const TSize& aDesiredSize) const;
       
   380 	IMPORT_C TInt GetReducedSize(const TSize& aOriginalSize, TInt aScalingCoeff, TSize& aReducedSize) const;
       
   381 
       
   382 	};
       
   383 
       
   384 /**
       
   385 @publishedAll
       
   386 @released
       
   387 
       
   388 Provides read related processing functions for bitmaps.
       
   389 
       
   390 Note:
       
   391 For use by plugin writers only.
       
   392 */
       
   393 class CImageWriteCodec : public CBase
       
   394 	{
       
   395 public:
       
   396 	IMPORT_C ~CImageWriteCodec();
       
   397 	IMPORT_C virtual void InitFrameL(TBufPtr8& aDst, const CFbsBitmap& aSource);
       
   398 
       
   399 	/**
       
   400 	Processes the frame data contained in aDst.
       
   401 
       
   402 	The internally held buffer must have been previously set, either by InitFrameL() or by a 
       
   403 	SetSource().
       
   404 
       
   405 	This is a pure virtual function that each derived class must implement.
       
   406 
       
   407 	@param  aDst
       
   408 	        A reference to the buffer containing the frame data.
       
   409 
       
   410 	@return The current frame state after processing.
       
   411 	*/
       
   412 	virtual TFrameState ProcessFrameL(TBufPtr8& aDst) = 0;
       
   413 
       
   414 	IMPORT_C const CFbsBitmap* Source() const;
       
   415 	IMPORT_C void SetSource(const CFbsBitmap* aSource);
       
   416 protected:
       
   417 	IMPORT_C void ConstructL();
       
   418 	IMPORT_C CImageWriteCodec();
       
   419 private:
       
   420 	// Future proofing
       
   421 	IMPORT_C virtual void ReservedVirtual1();
       
   422 	IMPORT_C virtual void ReservedVirtual2();
       
   423 	IMPORT_C virtual void ReservedVirtual3();
       
   424 	IMPORT_C virtual void ReservedVirtual4();
       
   425 private:
       
   426 	const CFbsBitmap* iSource; // linked object
       
   427 	};
       
   428 
       
   429 /**
       
   430 @internalComponent
       
   431 
       
   432 Max size of strings in extra resource files
       
   433 */
       
   434 const TInt KCodecResourceStringMax=128;
       
   435 
       
   436 #endif // __IMAGECODEC_H__