mmplugins/imagingplugins/imagedisplay/plugins/mng/PngProcessor.cpp
changeset 0 40261b775718
equal deleted inserted replaced
-1:000000000000 0:40261b775718
       
     1 // Copyright (c) 2004-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 /** 	@file
       
    17 	@internalTechnology */
       
    18 #include <e32base.h>
       
    19 
       
    20 #include "InputStream.h"
       
    21 #include "MngChunks.h"
       
    22 #include "MngPanic.h"
       
    23 #include "PngLayer.h"
       
    24 #include "MngPlayer.h"
       
    25 #include "logger.h"
       
    26 
       
    27 #include "PngProcessor.h"
       
    28 
       
    29 /*static*/
       
    30 CPngProcessor* CPngProcessor::NewL(CMngPlayer& aPlayer)
       
    31 	{
       
    32 	CPngProcessor* self=new (ELeave) CPngProcessor(aPlayer);
       
    33 	return self;
       
    34 	}
       
    35 
       
    36 inline
       
    37 CPngProcessor::CPngProcessor(CMngPlayer& aPlayer):
       
    38 								CChunkProcessor(aPlayer)
       
    39 	{
       
    40 	}
       
    41 
       
    42 CPngProcessor::~CPngProcessor()
       
    43 	{
       
    44 	delete iCurrentLayer;
       
    45 	Stop();
       
    46 	}
       
    47 
       
    48 void CPngProcessor::DoRunL()
       
    49 	{
       
    50 	switch (iState)
       
    51 		{
       
    52 		case ECreateLayer:
       
    53 			if (NULL != iCurrentLayer)
       
    54 				{
       
    55 				MngPanic(EPanicAlreadyCreated);
       
    56 				}
       
    57 			iCurrentLayer = CPngLayer::NewL();
       
    58 			iState=TState(iState+1);
       
    59 			// and go further
       
    60 		case EReadHeader:
       
    61 			if (iInputStream->DataAvailable() < TMNGChunkHeader::RequiredData() )
       
    62 				{
       
    63 				iInputStream->WaitForData(TMNGChunkHeader::RequiredData(), iStatus);
       
    64 				SetActive();
       
    65 				break;
       
    66 				}
       
    67 			else 
       
    68 				{
       
    69 				iCurrentChunkHeader.ReadL(*iInputStream);
       
    70 				LOG3("Chunk %4s, len=%d", iCurrentChunkHeader.iChunkId.iChunkIdChr, iCurrentChunkHeader.iLength);
       
    71 				// PNG decoder needs chunk headers, so we go back to the chunk header
       
    72 				iInputStream->SeekL( iInputStream->Tell() - TMNGChunkHeader::RequiredData() );
       
    73 				iState=TState(iState+1);
       
    74 				}
       
    75 			// go further for reading the chunk body
       
    76 		case EReadChunk:
       
    77 			{
       
    78 			const TInt overallChunkSize=TMNGChunkHeader::RequiredData()+iCurrentChunkHeader.iLength + sizeof(TChunkCrc);
       
    79 			if (iInputStream->DataAvailable() < overallChunkSize )
       
    80 				{
       
    81 				iInputStream->WaitForData(overallChunkSize, iStatus);
       
    82 				SetActive();
       
    83 				break;
       
    84 				}
       
    85 			else
       
    86 				{
       
    87 				switch (iCurrentChunkHeader.iChunkId.iChunkIdInt)
       
    88 				{
       
    89 				case KIhdrChunkId:
       
    90 				case KIendChunkId:
       
    91 				case KIdatChunkId:
       
    92 				case KPlteChunkId:
       
    93 				case KTrnsChunkId:
       
    94 				case KBkgdChunkId:
       
    95 				case KPhysChunkId:
       
    96 					iCurrentLayer->AppendChunkL(iCurrentChunkHeader, *iInputStream);
       
    97 					break;
       
    98 				default:
       
    99 					iInputStream->SeekL( iInputStream->Tell() + overallChunkSize );
       
   100 				}
       
   101 
       
   102 				if (iCurrentChunkHeader.iChunkId != KIendChunkId)
       
   103 					{
       
   104 					iState = EReadHeader;
       
   105 					RunAgain();
       
   106 					}
       
   107 				else
       
   108 					{
       
   109 					iState = ECreateLayer;
       
   110 					iMngPlayer.AppendObjectL(reinterpret_cast<CMngObject*&>(iCurrentLayer));
       
   111 					NotifyCaller(KErrNone);
       
   112 					}
       
   113 				}
       
   114 			}
       
   115 			break;
       
   116 
       
   117 		default:
       
   118 			ASSERT(EFalse);
       
   119 		}
       
   120 	}
       
   121 
       
   122 void CPngProcessor::Start(MInputStream& aInputStream, TRequestStatus& aRequest)
       
   123 	{
       
   124 	if (NULL != iCallerRequest)
       
   125 		{
       
   126 		MngPanic(EPanicAlreadyStarted);
       
   127 		}
       
   128 	iCallerRequest	= &aRequest;
       
   129 	*iCallerRequest	= KRequestPending;
       
   130 	iInputStream	= &aInputStream;
       
   131 	iInputStream->AddRef();
       
   132 	iState = ECreateLayer;
       
   133 	RunAgain();
       
   134 	}
       
   135 
       
   136 TInt CPngProcessor::AddSubProcessor(MChunkProcessor& /*aSubProcessor*/)
       
   137 	{
       
   138 	ASSERT(EFalse);
       
   139 	return KErrNotSupported;
       
   140 	}
       
   141 
       
   142 TBool CPngProcessor::OfferChunkType(const TChunkId& aChunkId)
       
   143 	{
       
   144 	return (aChunkId == KIhdrChunkId);
       
   145 	}
       
   146 
       
   147 
       
   148