mmplugins/imagingplugins/codecs/OTACodec/OTAConvert.cpp
changeset 0 40261b775718
equal deleted inserted replaced
-1:000000000000 0:40261b775718
       
     1 // Copyright (c) 1999-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 //
       
    15 
       
    16 #include <barsc.h>
       
    17 #include <barsread.h>
       
    18 #include <bautils.h>
       
    19 #include <imageconversion.h>
       
    20 #include "ImageClientMain.h"
       
    21 #include "icl/ICL_UIDS.hrh"
       
    22 #ifdef SYMBIAN_ENABLE_SPLIT_HEADERS
       
    23 #include <icl/icl_uids_const.hrh>
       
    24 #include <icl/icl_uids_def.hrh>
       
    25 #include <icl/imagecodecdef.h>
       
    26 #endif
       
    27 #include <101F45D0_extra.rsg>
       
    28 #include "OTACodec.h"
       
    29 
       
    30 _LIT(KOTAPanicCategory, "OTAConvertPlugin");
       
    31 
       
    32 
       
    33 // Global panic function
       
    34 GLDEF_C void Panic(TIclPanic aError)
       
    35 	{
       
    36 	User::Panic(KOTAPanicCategory, aError);
       
    37 	}
       
    38 
       
    39 
       
    40 // Ota decoder.
       
    41 COtaDecoder* COtaDecoder::NewL()
       
    42 	{
       
    43 	return new(ELeave) COtaDecoder;
       
    44 	}
       
    45 
       
    46 COtaDecoder::COtaDecoder()
       
    47 	{}
       
    48 
       
    49 COtaDecoder::~COtaDecoder()
       
    50 	{
       
    51 	Cleanup();
       
    52 	}
       
    53 
       
    54 void COtaDecoder::ImageType(TInt aFrameNumber, TUid& aImageType, TUid& aImageSubType) const
       
    55 	{
       
    56 	__ASSERT_ALWAYS(aFrameNumber == 0, Panic(EFrameNumberOutOfRange));
       
    57 	aImageType = KImageTypeOTAUid;
       
    58 	aImageSubType = KNullUid;
       
    59 	}
       
    60 
       
    61 // Scan header.
       
    62 // Validate that format is correct.
       
    63 // Create codec.
       
    64 // Fill in image info. (All frames)
       
    65 void COtaDecoder::ScanDataL()
       
    66 	{
       
    67 	ReadFormatL();
       
    68 	
       
    69 	ASSERT(ImageReadCodec() == NULL);
       
    70 
       
    71 	COtaReadCodec* imageReadCodec = COtaReadCodec::NewL(iSize);
       
    72 
       
    73 	SetImageReadCodec(imageReadCodec);
       
    74 	
       
    75 	ReadFrameHeadersL();
       
    76 	}
       
    77 
       
    78 const TInt KOtaFileHeaderSize = 22; // InfoField + 16 extFields + width + height + depth.
       
    79 const TInt KOtaUnsupportedFormats = 0x6F;
       
    80 const TInt KOtaConcatenationFlag = 0x80;
       
    81 const TInt KOtaSixteenBitSizeFlag = 0x10;
       
    82 void COtaDecoder::ReadFormatL()
       
    83 	{
       
    84 	TPtrC8 bufferDes;
       
    85 
       
    86 	ReadDataL(0, bufferDes, KOtaFileHeaderSize);
       
    87 
       
    88 	// Validate the header.
       
    89 	if (bufferDes.Length() < KOtaFileHeaderSize)
       
    90 		User::Leave(KErrUnderflow);
       
    91 
       
    92 	const TUint8* ptr = &bufferDes[0];
       
    93 	const TUint8* startPtr = ptr;
       
    94 
       
    95 	TUint8 infoField = *ptr++;
       
    96 	if (infoField & KOtaUnsupportedFormats)
       
    97 		User::Leave(KErrNotSupported); // Compression, palette and animations not supported
       
    98 
       
    99 	TUint8 extField = infoField;
       
   100 	while ((extField & KOtaConcatenationFlag) && ((ptr-startPtr) < 17)) // Skip extField concatenations
       
   101 		extField = *ptr++;
       
   102 
       
   103 	if (extField & KOtaConcatenationFlag)
       
   104 		User::Leave(KErrCorrupt); // There should be an infoField and no more than 16 extFields.
       
   105 
       
   106 	if (infoField & KOtaSixteenBitSizeFlag) // Size values are 16 bit
       
   107 		{
       
   108 		iSize.iWidth = (ptr[1] << 8) | ptr[0];
       
   109 		iSize.iHeight = (ptr[3] << 8) | ptr[2];
       
   110 		ptr += 4;
       
   111 		}
       
   112 	else // Size values are 8 bit
       
   113 		{
       
   114 		iSize.iWidth = *ptr++;
       
   115 		iSize.iHeight = *ptr++;
       
   116 		}
       
   117 
       
   118 	TUint8 depth = *ptr++;
       
   119 	if (depth != 1)
       
   120 		User::Leave(KErrNotSupported);
       
   121 
       
   122 	TInt startPosition = ptr - startPtr;
       
   123 	SetStartPosition(startPosition);
       
   124 	SetDataLength(startPosition + (((iSize.iWidth * iSize.iHeight) + 7) / 8));
       
   125 	
       
   126 	TFrameInfo imageInfo;
       
   127 	imageInfo = ImageInfo();
       
   128 	imageInfo.iFrameCoordsInPixels.SetRect(TPoint(0, 0), iSize);
       
   129 	imageInfo.iOverallSizeInPixels = iSize;
       
   130 	imageInfo.iFrameSizeInTwips = TSize(0, 0);
       
   131 	imageInfo.iBitsPerPixel = 1;
       
   132 	imageInfo.iDelay = 0;
       
   133 	imageInfo.iFlags = 0;
       
   134 	imageInfo.iFrameDisplayMode = EGray2;
       
   135 	SetImageInfo(imageInfo);
       
   136 	}
       
   137 
       
   138 CFrameInfoStrings* COtaDecoder::FrameInfoStringsL(RFs& aFs, TInt aFrameNumber)
       
   139 	{
       
   140 
       
   141 	const TUid KOtaCodecDllUid = {KOTACodecDllUidValue};
       
   142 
       
   143 	RResourceFile resourceFile;
       
   144 	OpenExtraResourceFileLC(aFs,KOtaCodecDllUid,resourceFile);
       
   145 
       
   146 	HBufC8* resourceInfo = resourceFile.AllocReadLC(THEDECODERINFO);
       
   147 	TResourceReader resourceReader;
       
   148 	resourceReader.SetBuffer(resourceInfo);
       
   149 
       
   150 	TBuf<KCodecResourceStringMax> info;
       
   151 	TBuf<KCodecResourceStringMax> templte;
       
   152 
       
   153 	const TFrameInfo& frameInfo = FrameInfo(aFrameNumber);
       
   154 	CFrameInfoStrings* frameInfoStrings = CFrameInfoStrings::NewLC();
       
   155 
       
   156 	info = resourceReader.ReadTPtrC();
       
   157 	frameInfoStrings->SetDecoderL(info);
       
   158 
       
   159 	info = resourceReader.ReadTPtrC();
       
   160 	frameInfoStrings->SetFormatL(info);
       
   161 
       
   162 	TInt width = frameInfo.iOverallSizeInPixels.iWidth;
       
   163 	TInt height = frameInfo.iOverallSizeInPixels.iHeight;
       
   164 
       
   165 	templte = resourceReader.ReadTPtrC();
       
   166 	info.Format(templte, width, height);
       
   167 	frameInfoStrings->SetDimensionsL(info);
       
   168 
       
   169 	info = resourceReader.ReadTPtrC(); // note depth is fixed
       
   170 	frameInfoStrings->SetDepthL(info);
       
   171 
       
   172 	// leave details blank
       
   173 
       
   174 	CleanupStack::Pop(frameInfoStrings); 
       
   175 	CleanupStack::PopAndDestroy(2); // resourceInfo + resourceFile
       
   176 	return frameInfoStrings;
       
   177 	}
       
   178 
       
   179