|
1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: Juha Kauppinen, Mika Hokkanen |
|
13 * |
|
14 * Description: Photo Browser |
|
15 * |
|
16 */ |
|
17 |
|
18 // Include files |
|
19 #include "IEImageEncoder.h" |
|
20 |
|
21 // ========================== MEMBER FUNCTIONS ============================= // |
|
22 |
|
23 CIEImageEncoder* CIEImageEncoder::NewL(RFs& aFileServer, MEncodingObserver& aObserver) |
|
24 { |
|
25 CIEImageEncoder* self = new (ELeave) CIEImageEncoder(aFileServer, aObserver); |
|
26 CleanupStack::PushL(self); |
|
27 self->ConstructL(); |
|
28 CleanupStack::Pop(); |
|
29 return self; |
|
30 } |
|
31 |
|
32 CIEImageEncoder::~CIEImageEncoder() |
|
33 { |
|
34 if(iFrameImageData) |
|
35 { |
|
36 delete iFrameImageData; |
|
37 iFrameImageData = NULL; |
|
38 } |
|
39 |
|
40 if(iImageEncoder) |
|
41 { |
|
42 delete iImageEncoder; |
|
43 iImageEncoder = NULL; |
|
44 } |
|
45 |
|
46 if(iExtImageEncoder) |
|
47 { |
|
48 delete iExtImageEncoder; |
|
49 iExtImageEncoder = NULL; |
|
50 } |
|
51 |
|
52 if(iVisualFrame) |
|
53 { |
|
54 delete iVisualFrame; |
|
55 iVisualFrame = NULL; |
|
56 } |
|
57 } |
|
58 |
|
59 |
|
60 CIEImageEncoder::CIEImageEncoder(RFs& aFileServer, MEncodingObserver& aObserver) |
|
61 : CActive(EPriorityStandard), iFileServer(aFileServer), iObserver(aObserver) |
|
62 { |
|
63 } |
|
64 |
|
65 void CIEImageEncoder::ConstructL() |
|
66 { |
|
67 iEncoderBusy = EFalse; |
|
68 |
|
69 CActiveScheduler::Add(this); |
|
70 } |
|
71 |
|
72 void CIEImageEncoder::RunL() |
|
73 { |
|
74 TInt error = iStatus.Int(); |
|
75 |
|
76 //iObserver.JpegImageReadyL(iStatus.Int()); |
|
77 iEncoderBusy = EFalse; |
|
78 } |
|
79 |
|
80 void CIEImageEncoder::DoCancel() |
|
81 { |
|
82 |
|
83 } |
|
84 |
|
85 void CIEImageEncoder::ConvertYuv2JpegL(HBufC8*& aDestBuffer, |
|
86 HBufC8& aSourceBuffer, |
|
87 const TSize aSize, |
|
88 const TImageForamt /*aFormat*/) |
|
89 { |
|
90 TInt blocks = 0; |
|
91 |
|
92 iEncoderBusy = ETrue; |
|
93 |
|
94 if(iExtImageEncoder) |
|
95 { |
|
96 delete iExtImageEncoder; |
|
97 iExtImageEncoder = NULL; |
|
98 |
|
99 } |
|
100 |
|
101 iExtImageEncoder = CExtJpegEncoder::DataNewL(aDestBuffer, _L8("image/jpeg")); |
|
102 |
|
103 TPtr8 ptrSrc = aSourceBuffer.Des(); |
|
104 TInt bufSize = aSourceBuffer.Size(); |
|
105 |
|
106 if(iVisualFrame) |
|
107 { |
|
108 delete iVisualFrame; |
|
109 iVisualFrame = NULL; |
|
110 } |
|
111 |
|
112 iVisualFrame = CVisualFrame::NewL(ptrSrc, aSize, CVisualFrame::EFormatYUV420Planar); |
|
113 |
|
114 SetJpegImageDataL(); |
|
115 iExtImageEncoder->ConvertL(&iStatus, iVisualFrame, blocks, iFrameImageData); |
|
116 |
|
117 if(!IsActive()) |
|
118 SetActive(); |
|
119 } |
|
120 |
|
121 void CIEImageEncoder::ConvertYuv2JpegL(TDesC& aFileName, |
|
122 HBufC8& aSourceBuffer, |
|
123 const TSize aSize, |
|
124 const TImageForamt /*aFormat*/) |
|
125 { |
|
126 TInt blocks = 0; |
|
127 |
|
128 iEncoderBusy = ETrue; |
|
129 |
|
130 if(iExtImageEncoder) |
|
131 { |
|
132 delete iExtImageEncoder; |
|
133 iExtImageEncoder = NULL; |
|
134 |
|
135 } |
|
136 |
|
137 iExtImageEncoder = CExtJpegEncoder::FileNewL(iFileServer, aFileName, _L8("image/jpeg")); |
|
138 |
|
139 TPtr8 ptrSrc = aSourceBuffer.Des(); |
|
140 TInt bufSize = aSourceBuffer.Size(); |
|
141 |
|
142 if(iVisualFrame) |
|
143 { |
|
144 delete iVisualFrame; |
|
145 iVisualFrame = NULL; |
|
146 } |
|
147 |
|
148 iVisualFrame = CVisualFrame::NewL(ptrSrc, aSize, CVisualFrame::EFormatYUV420Planar); |
|
149 |
|
150 SetJpegImageDataL(); |
|
151 iExtImageEncoder->ConvertL(&iStatus, iVisualFrame, blocks, iFrameImageData); |
|
152 |
|
153 if(!IsActive()) |
|
154 SetActive(); |
|
155 } |
|
156 |
|
157 void CIEImageEncoder::SetJpegImageDataL() |
|
158 { |
|
159 TJpegImageData* jpegImageData; |
|
160 jpegImageData = new (ELeave) TJpegImageData; |
|
161 jpegImageData->iSampleScheme = TJpegImageData::EColor420; |
|
162 jpegImageData->iQualityFactor = 90; |
|
163 |
|
164 if(iFrameImageData) |
|
165 { |
|
166 delete iFrameImageData; |
|
167 iFrameImageData = NULL; |
|
168 } |
|
169 |
|
170 iFrameImageData = CFrameImageData::NewL(); |
|
171 // Ownership of jpegImageData lies with CFrameImageData |
|
172 User::LeaveIfError(iFrameImageData->AppendImageData(jpegImageData)); |
|
173 } |
|
174 |
|
175 void CIEImageEncoder::CancelEncoding() |
|
176 { |
|
177 if(iEncoderBusy) |
|
178 { |
|
179 if(iImageEncoder) |
|
180 iImageEncoder->Cancel(); |
|
181 if(iExtImageEncoder) |
|
182 iExtImageEncoder->Cancel(); |
|
183 } |
|
184 |
|
185 if(IsActive()) |
|
186 Cancel(); |
|
187 } |
|
188 |
|
189 // EOF |