Update contrib.
1 // Copyright (c) 2006-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 the License "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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // e32test\multimedia\t_camera_display.cpp
21 #include <videodriver.h>
22 #include "t_camera_display.h"
24 _LIT(KFrameSizeConfTitle,"Current frame size :");
25 _LIT(KFrameSize, " %d x %d");
27 #define CLIP(a) if (a < 0) a = 0; else if (a > 255) a = 255;
32 TCamDisplayHandler::TCamDisplayHandler()
36 Initialise the display handler.
37 @return KErrNone if write was successful, otherwise one of the other system wide error codes.
39 TInt TCamDisplayHandler::Init()
41 TScreenInfoV01 screenInfo;
42 TPckg<TScreenInfoV01> screenInfoBuf(screenInfo);
43 UserSvr::ScreenInfo(screenInfoBuf);
44 iVideoAddress = (TUint8*) screenInfo.iScreenAddress;
45 iScreenWidth = screenInfo.iScreenSize.iWidth;
46 iScreenHeight = screenInfo.iScreenSize.iHeight;
48 TPckgBuf<TVideoInfoV01> videoInfoBuf;
49 UserSvr::HalFunction(EHalGroupDisplay, EDisplayHalCurrentModeInfo, &videoInfoBuf, NULL);
50 iBitsPerPixel = videoInfoBuf().iBitsPerPixel;
55 TInt TCamDisplayHandler::Min(TInt aA, TInt aB)
57 return (aA < aB) ? aA : aB;
60 TInt TCamDisplayHandler::SetConfig(const SDevCamFrameSize& aSize,const SDevCamPixelFormat& aPixelFormat)
62 if (aPixelFormat.iPixelFormat==EUidPixelFormatYUV_422Interleaved || aPixelFormat.iPixelFormat==EUidPixelFormatRGB_565)
63 iPixelFormat=aPixelFormat;
67 iWidth = aSize.iWidth;
68 iHeight = aSize.iHeight;
74 Post process a received image.
75 @return KErrNone if write was successful, otherwise one of the other system wide error codes.
77 TInt TCamDisplayHandler::Process(TUint8* aImageBaseAddress)
79 switch (iPixelFormat.iPixelFormat)
81 case EUidPixelFormatYUV_422Interleaved:
82 return(ProcessYUV422(aImageBaseAddress));
83 case EUidPixelFormatRGB_565:
84 return(ProcessRGB565(aImageBaseAddress));
86 return(KErrNotSupported);
91 Post process a received RGB565 image.
92 @return KErrNone if write was successful, otherwise one of the other system wide error codes.
94 TInt TCamDisplayHandler::ProcessRGB565(TUint8* aImageBaseAddress)
96 TUint16* source = (TUint16*) aImageBaseAddress;
98 TInt sourceModulo, destModulo, width, height;
101 // Determine whether the screen or the picture to display is the widest, and calculate modulos
102 // and clipping sizes appropriately
103 if (iWidth < iScreenWidth)
107 destModulo = (iScreenWidth - iWidth);
111 width = iScreenWidth;
112 sourceModulo = (iWidth - iScreenWidth);
116 // Determine whether the screen or the picture to display is the highest
117 height = (iHeight < iScreenHeight) ? iHeight : iScreenHeight;
119 if (iBitsPerPixel == 16)
121 TUint16* dest = (TUint16*) iVideoAddress;
123 // Loop around and copy the data directly onto the screen
124 for (TInt line = 0; line < height; ++line)
126 for (TInt x = 0; x < width; ++x)
131 source += sourceModulo;
135 else if (iBitsPerPixel == 32)
137 TUint8* dest = iVideoAddress;
141 // Loop around and convert whatever part of the picture will fit onto the screen into BGRA,
142 // writing it directly onto the screen
143 for (TInt line = 0; line < height; ++line)
145 for (TInt x = 0; x < width; ++x)
148 *dest++= (TUint8) ((pixel & 0x001f) << 3);
149 *dest++= (TUint8) ((pixel & 0x07e0) >> 3);
150 *dest++= (TUint8) ((pixel & 0xf800) >> 8);
154 source += sourceModulo;
160 r = KErrNotSupported;
167 Post process a received YUV422 image.
168 @return KErrNone if write was successful, otherwise one of the other system wide error codes.
170 TInt TCamDisplayHandler::ProcessYUV422(TUint8* aImageBaseAddress)
172 TUint16* dest16 = (TUint16*) iVideoAddress;
173 TUint32* dest32 = (TUint32*) iVideoAddress;
174 TUint8* source = aImageBaseAddress;
175 TInt y, u, v, r, g, b, sourceModulo, destModulo, width, height;
176 TInt retVal = KErrNone;
178 // Determine whether the screen or the picture to display is the widest, and calculate modulos
179 // and clipping sizes appropriately
180 if (iWidth < iScreenWidth)
182 width = (iWidth / 2);
184 destModulo = (iScreenWidth - iWidth);
188 width = (iScreenWidth / 2);
189 sourceModulo = ((iWidth - iScreenWidth) * 2);
193 // Determine whether the screen or the picture to display is the highest
194 height = (iHeight < iScreenHeight) ? iHeight : iScreenHeight;
196 // Only 16 and 32 bits per pixel are supported. It is also assumed that 16 bit will be RGB565 and
197 // 32 bit will be BGRA. You will need to add support for new formats if required
198 if ((iBitsPerPixel == 16) || (iBitsPerPixel == 32))
200 // Loop around and convert whatever part of the picture will fit onto the screen into RGB565 or BGRA,
201 // writing it directly onto the screen
202 for (TInt line = 0; line < height; ++line)
204 for (TInt x = 0; x < width; ++x)
206 u = (source[0] - 128);
207 v = (source[2] - 128);
208 y = (source[3] - 16);
210 r = ((298 * y + 409 * u) / 256);
211 g = ((298 * y - 100 * v - 208 * u) / 256);
212 b = ((298 * y + 516 * v) / 256);
218 if (iBitsPerPixel == 16)
220 *dest16++ = (TUint16) (((b & 0xf8) << 8) | ((g & 0xfc) << 3) | ((r & 0xf8) >> 3));
224 *dest32++ = (0xff000000 | (r << 16) | (g << 8) | b);
227 y = (source[1] - 16);
229 r = ((298 * y + 409 * u) / 256);
230 g = ((298 * y - 100 * v - 208 * u) / 256);
231 b = ((298 * y + 516 * v) / 256);
237 if (iBitsPerPixel == 16)
239 *dest16++ = (TUint16) (((b & 0xf8) << 8) | ((g & 0xfc) << 3) | ((r & 0xf8) >> 3));
243 *dest32++ = (0xff000000 | (r << 16) | (g << 8) | b);
249 source += sourceModulo;
250 dest16 += destModulo;
251 dest32 += destModulo;
256 retVal = KErrNotSupported;
263 Appends a string representing a pixel format UID onto a descriptor.
264 @param aBuffer Reference to the descriptor into which to append the string. It is up to the
265 caller to ensure that this is large enough.
266 @param aPixelFormat UID of the pixel format to be converted into a string.
268 void AppendPixelFormat(TDes& aBuffer, TUidPixelFormat aPixelFormat)
270 if (aPixelFormat == EUidPixelFormatRGB_565)
271 aBuffer.Append(KPixelFormatRGB_565);
272 else if (aPixelFormat == EUidPixelFormatYUV_422Interleaved)
273 aBuffer.Append(KPixelFormatYUV_422Interleaved);
274 else if (aPixelFormat == EUidPixelFormatSpeedTaggedJPEG)
275 aBuffer.Append(KPixelFormatSpeedTaggedJPEG);
276 else if (aPixelFormat == EUidPixelFormatJPEG)
277 aBuffer.Append(KPixelFormatJPEG);
279 aBuffer.Append(KPixelFormatUnknown);
282 void PrintCamModes(TCameraCapsV02* aCaps,RTest& aTest)
286 // Display the supported capture modes
288 buf.Append(KCaptureModeCapsTitle);
289 if (aCaps->iNumImagePixelFormats)
290 buf.Append(KCaptureModeImage);
291 if (aCaps->iNumVideoPixelFormats)
292 buf.Append(KCaptureModeVideo);
293 if (aCaps->iNumViewFinderPixelFormats)
294 buf.Append(KCaptureModeViewFinder);
295 buf.Append(_L("\r\n"));
298 // Display the supported video pixel formats
300 SDevCamPixelFormat* pixelFormat;
301 if (aCaps->iNumImagePixelFormats)
304 buf.Append(KPixelFormatCapsTitle);
305 buf.Append(KCaptureModeImage);
306 pixelFormat = (SDevCamPixelFormat*) (aCaps + 1);
307 for (i = 0; i < aCaps->iNumImagePixelFormats; i++)
309 AppendPixelFormat(buf, pixelFormat->iPixelFormat);
312 buf.Append(_L("\r\n"));
316 if (aCaps->iNumVideoPixelFormats)
319 buf.Append(KPixelFormatCapsTitle);
320 buf.Append(KCaptureModeVideo);
321 pixelFormat = (SDevCamPixelFormat*) (aCaps + 1);
322 for (i = aCaps->iNumImagePixelFormats; i < (aCaps->iNumImagePixelFormats + aCaps->iNumVideoPixelFormats); i++)
324 AppendPixelFormat(buf, pixelFormat->iPixelFormat);
327 buf.Append(_L("\r\n"));
331 if (aCaps->iNumViewFinderPixelFormats)
334 buf.Append(KPixelFormatCapsTitle);
335 buf.Append(KCaptureModeViewFinder);
336 pixelFormat = (SDevCamPixelFormat*) (aCaps + 1);
337 i = aCaps->iNumImagePixelFormats + aCaps->iNumImagePixelFormats + 1;
338 for (i = aCaps->iNumImagePixelFormats + aCaps->iNumVideoPixelFormats; i < (aCaps->iNumImagePixelFormats + aCaps->iNumVideoPixelFormats + aCaps->iNumViewFinderPixelFormats); i++)
340 AppendPixelFormat(buf, pixelFormat->iPixelFormat);
343 buf.Append(_L("\r\n"));
348 void PrintCamConf(TCameraConfigV02& aConf,RTest& aTest)
352 // Display the current frame size
354 buf.Append(KFrameSizeConfTitle);
355 buf.AppendFormat(KFrameSize, aConf.iFrameSize.iWidth, aConf.iFrameSize.iHeight);
356 buf.Append(_L("\r\n"));
359 // Display the current pixel format
361 buf.Append(KPixelFormatConfTitle);
362 AppendPixelFormat(buf, aConf.iPixelFormat.iPixelFormat);
363 buf.Append(_L("\r\n"));
366 // Display the current frame rate
368 buf.Format(_L("Current frame rate : %d fps\r\n"),aConf.iFrameRate);
372 void PrintBufferConf(TMmSharedChunkBufConfig& aBufConf,RTest& aTest)
376 SBufSpecList* tempSpec = aBufConf.iSpec;
378 // Display the buffer configuration
379 buf.Format(_L("Buffer Config : NumBufs:%d Size:%xH\r\n"),aBufConf.iNumBuffers,aBufConf.iBufferSizeInBytes);
381 if (aBufConf.iFlags & KScFlagBufOffsetListInUse)
383 buf.Format(_L(" Offsets[%08xH,%08xH,%08xH,%08xH]\r\n"),tempSpec[0].iBufferOffset,tempSpec[1].iBufferOffset,tempSpec[2].iBufferOffset,tempSpec[3].iBufferOffset);
385 buf.Format(_L(" Offsets[%08xH,%08xH,%08xH,%08xH]\r\n"),tempSpec[4].iBufferOffset,tempSpec[5].iBufferOffset,tempSpec[6].iBufferOffset,tempSpec[7].iBufferOffset);