|
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.JpegImageReady(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 { |
|
89 TInt blocks = 0; |
|
90 |
|
91 iEncoderBusy = ETrue; |
|
92 |
|
93 if(iExtImageEncoder) |
|
94 { |
|
95 delete iExtImageEncoder; |
|
96 iExtImageEncoder = NULL; |
|
97 |
|
98 } |
|
99 |
|
100 iExtImageEncoder = CExtJpegEncoder::DataNewL(aDestBuffer, _L8("image/jpeg")); |
|
101 |
|
102 TPtr8 ptrSrc = aSourceBuffer.Des(); |
|
103 TInt bufSize = aSourceBuffer.Size(); |
|
104 |
|
105 if(iVisualFrame) |
|
106 { |
|
107 delete iVisualFrame; |
|
108 iVisualFrame = NULL; |
|
109 } |
|
110 |
|
111 iVisualFrame = CVisualFrame::NewL(ptrSrc, aSize, CVisualFrame::EFormatYUV420Planar); |
|
112 |
|
113 SetJpegImageDataL(); |
|
114 iExtImageEncoder->ConvertL(&iStatus, iVisualFrame, blocks, iFrameImageData); |
|
115 |
|
116 if(!IsActive()) |
|
117 SetActive(); |
|
118 } |
|
119 |
|
120 void CIEImageEncoder::ConvertYuv2JpegL(TDesC& aFileName, |
|
121 HBufC8& aSourceBuffer, |
|
122 const TSize aSize) |
|
123 { |
|
124 TInt blocks = 0; |
|
125 |
|
126 iEncoderBusy = ETrue; |
|
127 |
|
128 if(iExtImageEncoder) |
|
129 { |
|
130 delete iExtImageEncoder; |
|
131 iExtImageEncoder = NULL; |
|
132 |
|
133 } |
|
134 |
|
135 iExtImageEncoder = CExtJpegEncoder::FileNewL(iFileServer, aFileName, _L8("image/jpeg")); |
|
136 |
|
137 TPtr8 ptrSrc = aSourceBuffer.Des(); |
|
138 TInt bufSize = aSourceBuffer.Size(); |
|
139 |
|
140 if(iVisualFrame) |
|
141 { |
|
142 delete iVisualFrame; |
|
143 iVisualFrame = NULL; |
|
144 } |
|
145 |
|
146 iVisualFrame = CVisualFrame::NewL(ptrSrc, aSize, CVisualFrame::EFormatYUV420Planar); |
|
147 |
|
148 SetJpegImageDataL(); |
|
149 iExtImageEncoder->ConvertL(&iStatus, iVisualFrame, blocks, iFrameImageData); |
|
150 |
|
151 if(!IsActive()) |
|
152 SetActive(); |
|
153 } |
|
154 |
|
155 void CIEImageEncoder::SetJpegImageDataL() |
|
156 { |
|
157 TJpegImageData* jpegImageData; |
|
158 jpegImageData = new (ELeave) TJpegImageData; |
|
159 jpegImageData->iSampleScheme = TJpegImageData::EColor420; |
|
160 jpegImageData->iQualityFactor = 90; |
|
161 |
|
162 if(iFrameImageData) |
|
163 { |
|
164 delete iFrameImageData; |
|
165 iFrameImageData = NULL; |
|
166 } |
|
167 |
|
168 iFrameImageData = CFrameImageData::NewL(); |
|
169 // Ownership of jpegImageData lies with CFrameImageData |
|
170 User::LeaveIfError(iFrameImageData->AppendImageData(jpegImageData)); |
|
171 } |
|
172 |
|
173 void CIEImageEncoder::CancelEncoding() |
|
174 { |
|
175 if(iEncoderBusy) |
|
176 { |
|
177 if(iImageEncoder) |
|
178 iImageEncoder->Cancel(); |
|
179 if(iExtImageEncoder) |
|
180 iExtImageEncoder->Cancel(); |
|
181 } |
|
182 |
|
183 if(IsActive()) |
|
184 Cancel(); |
|
185 } |
|
186 |
|
187 // EOF |