|
1 // Copyright (c) 2008-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 "TImageTran.h" |
|
17 #include <iclexifimageframe.h> |
|
18 |
|
19 |
|
20 /* |
|
21 * Case-insensitive matching of possibly-abbreviated keyword switches. |
|
22 * keyword is the constant keyword (must be lower case already), |
|
23 * minchars is length of minimum legal abbreviation. |
|
24 */ |
|
25 TBool CITArgsandFuncts::KeywordMatch (TPtrC aKeyMatch, const TDesC16& aKeyWord, TInt aMinCharsMatch) |
|
26 { |
|
27 |
|
28 if(aKeyMatch.MatchF(aKeyWord) != KErrNotFound) |
|
29 { |
|
30 return ETrue; |
|
31 } |
|
32 |
|
33 if((aKeyWord.Length() < aMinCharsMatch)) |
|
34 { |
|
35 return EFalse; //no matching keyword found |
|
36 } |
|
37 return EFalse; |
|
38 } |
|
39 |
|
40 /* Read next argument from commandline */ |
|
41 void CITArgsandFuncts::ReadNextArg(TInt aArgNum) |
|
42 { |
|
43 if (aArgNum >= iCmdArgs->Count()) /* advance to next argument */ |
|
44 { |
|
45 iEndOfCmd = ETrue; |
|
46 //ExitImageTranTool(); |
|
47 } |
|
48 else |
|
49 { |
|
50 iArgumentPtr.Set(iCmdArgs->Arg(aArgNum)); |
|
51 } |
|
52 } |
|
53 |
|
54 /* |
|
55 * Get the input image size to check that MaxImagesize and MinImagesize are |
|
56 * within the input image size range |
|
57 * |
|
58 */ |
|
59 void CITArgsandFuncts::Fetch_ImageSize() |
|
60 { |
|
61 CJPEGImageFrameDecoder *decoder = NULL; |
|
62 TRAPD(error, decoder= static_cast<CJPEGImageFrameDecoder*> (CImageDecoder::FileNewL(iFs, iInputfile, CImageDecoder::EOptionNone, KNullUid, KNullUid, KImageFramePluginUid))); |
|
63 if(error != KErrNone) |
|
64 { |
|
65 iConsole->Printf(_L("JpegCodec does not support this image format.InputImageSize caluculation for autosqueeze transformation failed with %d\n"), error); |
|
66 ExitImageTranTool(); |
|
67 } |
|
68 |
|
69 const TFrameInfo* frameInfo = NULL; |
|
70 frameInfo = &decoder->FrameInfo(); |
|
71 iInputImageSize = frameInfo->iOverallSizeInPixels; |
|
72 |
|
73 if(iSqueezeAutoResizeParams.iMaxImageSize.iWidth > iInputImageSize.iWidth ) |
|
74 { |
|
75 iConsole->Printf(_L("MaxImage width is greater than the input image width\n")); |
|
76 ExitImageTranTool(); |
|
77 } |
|
78 |
|
79 if(iSqueezeAutoResizeParams.iMaxImageSize.iHeight > iInputImageSize.iHeight ) |
|
80 { |
|
81 iConsole->Printf(_L("MaxImage height is greater than the input image height\n")); |
|
82 ExitImageTranTool(); |
|
83 } |
|
84 |
|
85 if(iSqueezeAutoResizeParams.iMinImageSize.iWidth > iInputImageSize.iWidth && iSqueezeAutoResizeParams.iMinImageSize.iWidth > iSqueezeAutoResizeParams.iMaxImageSize.iWidth) |
|
86 { |
|
87 iConsole->Printf(_L("MinImage width is greater than the input image width/Maximage height\n")); |
|
88 ExitImageTranTool(); |
|
89 } |
|
90 if(iSqueezeAutoResizeParams.iMinImageSize.iHeight > iInputImageSize.iHeight && iSqueezeAutoResizeParams.iMinImageSize.iHeight > iSqueezeAutoResizeParams.iMaxImageSize.iHeight) |
|
91 { |
|
92 iConsole->Printf(_L("MinImage height is greater than the input image height/Maximage height\n")); |
|
93 ExitImageTranTool(); |
|
94 } |
|
95 delete decoder; |
|
96 } |
|
97 |
|
98 /* |
|
99 * Validate whether its a valid numeric number or not |
|
100 * validation is done based on the ascii value of the character |
|
101 * for digits 0 to 9 it starts from 48 to 57 |
|
102 */ |
|
103 TUint CITArgsandFuncts::ValidateImageSize() |
|
104 { |
|
105 TUint tmpVal; |
|
106 TLex lLex(iArgumentPtr); |
|
107 TLex lLextmp(iArgumentPtr); |
|
108 TChar charArg = lLex.Get(); |
|
109 do |
|
110 { |
|
111 if(charArg > 47 && charArg < 58 ) |
|
112 { |
|
113 charArg = lLex.Get(); |
|
114 } |
|
115 else |
|
116 { |
|
117 if(charArg < 47 || charArg > 58) |
|
118 { |
|
119 iConsole->Printf(_L("SizeinBytes or ImageSize is incorrect alphabetic or alphanumeric or special characters\n")); |
|
120 ExitImageTranTool(); |
|
121 } |
|
122 } |
|
123 }while(!lLex.Eos()); |
|
124 |
|
125 lLextmp.Val(tmpVal); |
|
126 return tmpVal; |
|
127 } |
|
128 |
|
129 /* |
|
130 * Set source and destination file, squeeze option |
|
131 */ |
|
132 void CITArgsandFuncts::SetupTransformation (ITRAN_CODES aTransCode) |
|
133 { |
|
134 TInt error = KErrNone; |
|
135 |
|
136 TRAP(error, iImageTransform->SetSourceFilenameL(iInputfile)); |
|
137 if(error != KErrNone) |
|
138 { |
|
139 iConsole->Printf(_L("Input file is having a problem failed with error : %d\n"), error); |
|
140 ExitImageTranTool(); |
|
141 } |
|
142 |
|
143 TRAP(error, iImageTransform->SetDestFilenameL(iOutputfile)); |
|
144 if(error != KErrNone) |
|
145 { |
|
146 iConsole->Printf(_L("Output file is having a problem failed with error: %d\n"), error); |
|
147 ExitImageTranTool(); |
|
148 } |
|
149 if(aTransCode == ITRAN_SQU || aTransCode == ITRAN_AUTOSQU) |
|
150 { |
|
151 TRAP(error, iImageTransform->SetTransformationsL(CImageTransform::ESqueeze)); |
|
152 } |
|
153 else if (aTransCode == ITRAN_ROTATE || aTransCode == ITRAN_FLIP || |
|
154 aTransCode == ITRAN_TRANSPOSE || aTransCode == ITRAN_TRANSVERSE) |
|
155 { |
|
156 TRAP(error, iImageTransform->SetTransformationsL(CImageTransform::EOrientation)); |
|
157 } |
|
158 if(error != KErrNone) |
|
159 { |
|
160 iConsole->Printf(_L("Not a valid option : %d\n"), error); |
|
161 ExitImageTranTool(); |
|
162 } |
|
163 |
|
164 TRAP(error, iImageTransform->SetupL()); |
|
165 if(error != KErrNone) |
|
166 { |
|
167 iConsole->Printf(_L("Not a valid input or outputfile : %d\n"), error); |
|
168 ExitImageTranTool(); |
|
169 } |
|
170 |
|
171 if(aTransCode == ITRAN_SQU || aTransCode == ITRAN_AUTOSQU) |
|
172 { |
|
173 TUid lSqUid = {KUidSqueezeTransformExtension}; |
|
174 iTransExtn = static_cast<CSqueezeTransformExtension*>(iImageTransform->Extension(lSqUid, error)); |
|
175 if(!iTransExtn) |
|
176 { |
|
177 iConsole->Printf(_L("Extension Returned unexpected error: %d"), error); |
|
178 ExitImageTranTool(); |
|
179 } |
|
180 } |
|
181 else if(aTransCode == ITRAN_ROTATE || aTransCode == ITRAN_FLIP || |
|
182 aTransCode == ITRAN_TRANSPOSE || aTransCode == ITRAN_TRANSVERSE) |
|
183 { |
|
184 TUid lTransOrUid = {KUidOrientationTransformExtension}; |
|
185 iTransOrientation = static_cast<COrientationTransformExtension*>(iImageTransform->Extension(lTransOrUid, error)); |
|
186 if(!iTransOrientation) |
|
187 { |
|
188 iConsole->Printf(_L("Extension Returned unexpected error: %d"), error); |
|
189 ExitImageTranTool(); |
|
190 } |
|
191 } |
|
192 } |
|
193 |
|
194 /* Set extension, overlayfile and overlay position for overlay comamnd */ |
|
195 void CITArgsandFuncts::SetupOverlayTrans() |
|
196 { |
|
197 TInt error = KErrNone; |
|
198 TUid lTransOlUid = {KUidOverlayTransformExtension}; |
|
199 |
|
200 TRAP(error, iImageTransform->SetSourceFilenameL(iInputfile)); |
|
201 if(error != KErrNone) |
|
202 { |
|
203 iConsole->Printf(_L("Input file is having a problem failed with error : %d\n"), error); |
|
204 ExitImageTranTool(); |
|
205 } |
|
206 |
|
207 TRAP(error, iImageTransform->SetDestFilenameL(iOutputfile)); |
|
208 if(error != KErrNone) |
|
209 { |
|
210 iConsole->Printf(_L("Output file is having a problem failed with error: %d\n"), error); |
|
211 ExitImageTranTool(); |
|
212 } |
|
213 |
|
214 TRAP(error, iImageTransform->SetTransformationsL(CImageTransform::EOverlay)); |
|
215 if(error != KErrNone) |
|
216 { |
|
217 iConsole->Printf(_L("Not a valid option : %d\n"), error); |
|
218 ExitImageTranTool(); |
|
219 } |
|
220 |
|
221 TRAP(error, iImageTransform->SetupL()); |
|
222 if(error != KErrNone) |
|
223 { |
|
224 iConsole->Printf(_L("Not a valid input or outputfile : %d\n"), error); |
|
225 ExitImageTranTool(); |
|
226 } |
|
227 |
|
228 iOverlayExtn = static_cast<COverlayTransformExtension*>(iImageTransform->Extension(lTransOlUid, error)); |
|
229 if(!iOverlayExtn) |
|
230 { |
|
231 iConsole->Printf(_L("Extension Returned unexpected error: %d"), error); |
|
232 ExitImageTranTool(); |
|
233 } |
|
234 |
|
235 iOverlayExtn->SetPosition(iPoint); |
|
236 |
|
237 TParse fileExtn; |
|
238 fileExtn.Set(iOverlayfile,NULL,NULL); |
|
239 |
|
240 if(error != KErrNotFound) |
|
241 { |
|
242 if(KeywordMatch(fileExtn.Ext(),_L(".mbm"),3)) |
|
243 { |
|
244 CFbsBitmap bitmap; |
|
245 error = bitmap.Load(iOverlayfile); |
|
246 if (error != KErrNone) |
|
247 { |
|
248 iConsole->Printf(_L("Cannot load overlayfile into a bitmap, failed with error: %d\n"), error); |
|
249 ExitImageTranTool(); |
|
250 } |
|
251 TRAP(error, iOverlayExtn->SetOverlayImageL(bitmap)); |
|
252 } |
|
253 else if(KeywordMatch(fileExtn.Ext(),_L(".jpg"),3)) |
|
254 { |
|
255 TUid uUid = KImageTypeJPGUid; |
|
256 TRAP(error, iOverlayExtn->SetOverlayFileL(iOverlayfile, uUid)); |
|
257 } |
|
258 else if(KeywordMatch(fileExtn.Ext(),_L(".png"),3)) |
|
259 { |
|
260 TUid uUid = KImageTypePNGUid; |
|
261 TRAP(error, iOverlayExtn->SetOverlayFileL(iOverlayfile, uUid)); |
|
262 } |
|
263 } |
|
264 if(error != KErrNone) |
|
265 { |
|
266 iConsole->Printf(_L("Not a valid option : %d\n"), error); |
|
267 ExitImageTranTool(); |
|
268 } |
|
269 |
|
270 } |