imagingandcamerafws/imagingfws/src/Recognizer/RecIcl.cpp
changeset 0 40261b775718
equal deleted inserted replaced
-1:000000000000 0:40261b775718
       
     1 // Copyright (c) 2003-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 <f32file.h>
       
    17 #include <barsread.h>
       
    18 
       
    19 #include "ImageDisplayRecognizer.h"
       
    20 #include "RecIcl.h"
       
    21 #include "ImageResolverAPI.h"	// for KImageHeaderSize
       
    22 
       
    23 const TInt KMimeIclRecognizerValue = 0x101F7C0B;
       
    24 const TUid KUidMimeIclRecognizer = {KMimeIclRecognizerValue};
       
    25 const TInt KIclRecognizerPriority = 10; // The recognizer priority is set to 10(a value between ENormal and EHigh)
       
    26 
       
    27 // CApaIclRecognizer
       
    28 
       
    29 /**
       
    30  * @internalAll
       
    31  *
       
    32  * call base constructor with the recognizer's UID and confidence level
       
    33  * The recognizer priority is set to 10(a value between ENormal and EHigh) to allow 
       
    34  * third-party recognizers to specify high priority.
       
    35  */
       
    36 CApaIclRecognizer::CApaIclRecognizer()
       
    37 	:CApaDataRecognizerType(KUidMimeIclRecognizer,KIclRecognizerPriority)
       
    38 	{
       
    39 	}
       
    40 
       
    41 CApaIclRecognizer::~CApaIclRecognizer()
       
    42 	{
       
    43 	delete iIclRecognizer;
       
    44 	}
       
    45 
       
    46 /**
       
    47  * @internalAll
       
    48  *
       
    49  * return the supposed minimum buffer size we need to 
       
    50  * successfully recognize the data
       
    51  */
       
    52 TUint CApaIclRecognizer::PreferredBufSize()
       
    53 	{
       
    54 	return KImageHeaderSize;	
       
    55 	}
       
    56 
       
    57 /**
       
    58  * @internalAll
       
    59  *
       
    60  * Gets one of the data (MIME) types that the recognizer can recognize.
       
    61  */
       
    62 TDataType CApaIclRecognizer::SupportedDataTypeL(TInt aIndex) const
       
    63 	{
       
    64 	TDataType temp(iIclRecognizer->SupportedDataTypeL(aIndex));
       
    65 	return temp;
       
    66 	}
       
    67 
       
    68 
       
    69 /**
       
    70  * @internalAll
       
    71  *
       
    72  * attempt to recognize the data
       
    73  * this recognizer only attempts to match the data - not the file name
       
    74  *
       
    75  * NB if the file is not recognized, this function should NOT leave :
       
    76  * it should instead set iConfidence = ENotRecognized and return
       
    77  * the function should only leave if there is an out-of-memory condition
       
    78  */
       
    79 void CApaIclRecognizer::DoRecognizeL(const TDesC& aName , const TDesC8& aBuffer)
       
    80 	{
       
    81 	CIclRecognizer::TMatchMethod matchMethod = iIclRecognizer->MatchL(aBuffer, aName);
       
    82 	
       
    83 	// return whether the data was matched by setting iConfidence
       
    84 	// if matched the MIME type is returned in iDataType
       
    85 	if (matchMethod == CIclRecognizer::ENotMatched)
       
    86 		{	
       
    87 		iConfidence = CApaDataRecognizerType::ENotRecognized;
       
    88 		}
       
    89 	else
       
    90 		{
       
    91 		iDataType = iIclRecognizer->MimeString();
       
    92 
       
    93 		if (matchMethod == CIclRecognizer::EBySignature)
       
    94 			iConfidence = CApaDataRecognizerType::EProbable;
       
    95 		else
       
    96 			{
       
    97 			ASSERT(matchMethod==CIclRecognizer::EByName);
       
    98 			iConfidence = CApaDataRecognizerType::EPossible;
       
    99 			}
       
   100 		}
       
   101 	}
       
   102 
       
   103 void CApaIclRecognizer::ConstructL()
       
   104 	{
       
   105 	iIclRecognizer = CIclRecognizer::NewL();
       
   106 	iCountDataTypes = iIclRecognizer->NumMimeTypes();
       
   107 	}
       
   108 
       
   109 CApaIclRecognizer* CApaIclRecognizer::NewL()
       
   110 	{
       
   111 	CApaIclRecognizer* self = new (ELeave) CApaIclRecognizer();   
       
   112 	CleanupStack::PushL(self);
       
   113 	self->ConstructL();
       
   114 	CleanupStack::Pop(self);
       
   115 	return self;
       
   116 	}
       
   117 
       
   118 // CIclRecognizer - the main utility class owner by CApaIclRecognizer
       
   119 
       
   120 CIclRecognizer::CIclRecognizer()
       
   121 	{
       
   122 	}
       
   123 
       
   124 CIclRecognizer::~CIclRecognizer()
       
   125 	{
       
   126 	delete iIclRecognizerUtil;
       
   127 	delete iImgDisplayRecognizer;
       
   128 	iFileExtensionMIMETypeArray.ResetAndDestroy();
       
   129 	}
       
   130 
       
   131 void CIclRecognizer::ConstructL()
       
   132 	{
       
   133 	iImgDisplayRecognizer= CImgDisplayMimeTypeRecognizer::NewL();
       
   134 	iIclRecognizerUtil = CIclRecognizerUtil::NewL();
       
   135 	BuildListL();
       
   136 	}
       
   137 
       
   138 CIclRecognizer* CIclRecognizer::NewL()
       
   139 	{
       
   140 	CIclRecognizer* self = new (ELeave) CIclRecognizer();   
       
   141 	CleanupStack::PushL(self);
       
   142 	self->ConstructL();
       
   143 	CleanupStack::Pop(self);
       
   144 	return self;
       
   145 	}
       
   146 
       
   147 /**
       
   148  * @internalComponent
       
   149  *
       
   150  * return the number of MIME types supported 
       
   151  */
       
   152 TInt CIclRecognizer::NumMimeTypes() const
       
   153 	{
       
   154 	return(iFileExtensionMIMETypeArray.Count());
       
   155 	}
       
   156 
       
   157 /**
       
   158  * @internalComponent
       
   159  *
       
   160  * call into the ImageConversion DLL to get
       
   161  * a list of supported MIME types
       
   162  */
       
   163 void CIclRecognizer::BuildListL()
       
   164 	{
       
   165 	iFileExtensionMIMETypeArray.ResetAndDestroy();
       
   166 	CImageDecoder::GetFileTypesL(iFileExtensionMIMETypeArray);
       
   167 	iImgDisplayRecognizer->GetFileTypesL(iFileExtensionMIMETypeArray);
       
   168 	}
       
   169 
       
   170 /**
       
   171  * @internalComponent
       
   172  *
       
   173  * Get one of the data (MIME) types that ICL can recognize.
       
   174  */
       
   175 const TDesC8& CIclRecognizer::SupportedDataTypeL(TInt aIndex) const
       
   176 	{
       
   177 	if ((aIndex < 0) || (aIndex >= iFileExtensionMIMETypeArray.Count()))
       
   178 		{
       
   179 		User::Leave(KErrArgument);
       
   180 		}
       
   181 	
       
   182 	return(iFileExtensionMIMETypeArray[aIndex]->MIMEType());
       
   183 	}
       
   184 
       
   185 /**
       
   186  * @internalComponent
       
   187  *
       
   188  * get a reference to the last MIME type string successfully matched
       
   189  */
       
   190 const TDesC8& CIclRecognizer::MimeString() const
       
   191 	{
       
   192 	return iMimeString;
       
   193 	}
       
   194 
       
   195 /**
       
   196  * @internalComponent
       
   197  *
       
   198  * attempt to recognize the data
       
   199  */
       
   200 CIclRecognizer::TMatchMethod CIclRecognizer::MatchL(const TDesC8& aBuffer, const TDesC& aFileName)
       
   201 	{
       
   202 	TMatchMethod bestMatchMethod = ENotMatched;
       
   203 
       
   204 	//Try to recognize image data
       
   205 	TBool matchFound = EFalse;
       
   206 	matchFound = iIclRecognizerUtil->GetMimeTypeL(aBuffer, KNullDesC, iMimeString);
       
   207 	if (!matchFound)
       
   208 		{
       
   209 		matchFound = iImgDisplayRecognizer->GetMimeTypeL(aBuffer, KNullDesC, iMimeString);
       
   210 		}
       
   211 
       
   212 	if(matchFound)
       
   213 		{
       
   214 		bestMatchMethod = EBySignature;
       
   215 		}
       
   216 
       
   217 	if (aFileName != KNullDesC && !matchFound)
       
   218 		{//Try to recognize file extension
       
   219 		matchFound = iIclRecognizerUtil->GetMimeTypeL(KNullDesC8, aFileName, iMimeString);
       
   220 		if (!matchFound)
       
   221 			{
       
   222 			matchFound = iImgDisplayRecognizer->GetMimeTypeL(KNullDesC8, aFileName, iMimeString);
       
   223 			}		
       
   224 		if(matchFound)
       
   225 			{
       
   226 			bestMatchMethod = EByName;
       
   227 			}
       
   228 		}
       
   229 
       
   230 	return bestMatchMethod;
       
   231 	}
       
   232 
       
   233 
       
   234 #include <ecom/ecom.h>
       
   235 #include <ecom/implementationproxy.h>
       
   236 
       
   237 const TImplementationProxy ImplementationTable[] = 
       
   238 	{
       
   239 	IMPLEMENTATION_PROXY_ENTRY(0x101F7C40, CApaIclRecognizer::NewL)
       
   240 	};
       
   241 
       
   242 
       
   243 EXPORT_C const TImplementationProxy* ImplementationGroupProxy(TInt& aTableCount)
       
   244     {
       
   245     aTableCount = sizeof(ImplementationTable) / sizeof(TImplementationProxy);
       
   246     return ImplementationTable;
       
   247     }
       
   248 
       
   249 
       
   250