Support for NV12
authorsanthosh.au <santhosh.au@samsung.com>
Fri, 16 Aug 2013 13:34:23 +0000 (19:04 +0530)
committersanthosh.au <santhosh.au@samsung.com>
Fri, 16 Aug 2013 13:34:23 +0000 (19:04 +0530)
Change-Id: I23a748e3e54b683d62e8ee091575842974d0e1b0
Signed-off-by: santhosh.au <santhosh.au@samsung.com>
project/inc/CameraTools.h
project/inc/Tracker.h
project/src/CameraTools.cpp
project/src/Tracker.cpp

index 5dcc6b0..7699bbe 100644 (file)
@@ -19,6 +19,7 @@
 #define CAMERA_TOOLS_H_
 
 #include <FMedia.h>
+#include <FGraphics.h>
 
 class CameraTools
 {
@@ -43,6 +44,7 @@ public:
 
     static int GetWidth(void);
     static int GetHeight(void);
+    static Tizen::Graphics::PixelFormat GetFormat(void);
 
 private:
 
@@ -51,6 +53,7 @@ private:
     static Tizen::Media::ICameraEventListener* __pListener;
     static int __width;
     static int __height;
+    static Tizen::Graphics::PixelFormat __format;
 };
 
 #endif //CAMERA_TOOLS_H_
index 0f2c7a3..314cd6b 100644 (file)
@@ -49,6 +49,8 @@ public:
     // Called when camera  error occurred
     void OnCameraErrorOccurred(Tizen::Media::CameraErrorReason r);
 
+    void ConvertNV12ToYCbCr(byte *src, byte *dst, int width, int height);
+
     static const int DESIRED_CAMERA_WIDTH  = 640;
     static const int DESIRED_CAMERA_HEIGHT = 480;
 
index fe2f240..f3d0ecc 100644 (file)
 
 using namespace Tizen::Base;
 using namespace Tizen::Media;
+using namespace Tizen::Graphics;
+
 
 Camera*  CameraTools::__pCamera(null);
 Tizen::Graphics::Dimension CameraTools::__choosenResolution;
 int CameraTools::__width;
 int CameraTools::__height;
 Tizen::Media::ICameraEventListener*  CameraTools::__pListener(null);
+Tizen::Graphics::PixelFormat CameraTools::__format;
 
 const char* pTag = "CameraTools";
 
@@ -65,7 +68,27 @@ CameraTools::InitCamera(ICameraEventListener &listener,
         return false;
     }
 
-    if (IsFailed(__pCamera->SetPreviewFormat(Tizen::Graphics::PIXEL_FORMAT_YCbCr420_PLANAR)))
+       __format = PIXEL_FORMAT_MIN;
+
+   Tizen::Base::Collection::IListT<Tizen::Graphics::PixelFormat>* PreviewList = __pCamera->GetSupportedPreviewFormatListN();
+
+       for (int i = 0; i < PreviewList->GetCount(); i++)
+       {
+               Tizen::Graphics::PixelFormat format;
+
+               PreviewList->GetAt(i,format);
+               if(format == PIXEL_FORMAT_YCbCr420_PLANAR)
+               {
+                       __format = PIXEL_FORMAT_YCbCr420_PLANAR;
+                       break;
+               }else if (format == PIXEL_FORMAT_NV12)
+               {
+                       __format = PIXEL_FORMAT_NV12;
+               }
+       }
+    
+       
+    if (IsFailed(__pCamera->SetPreviewFormat(__format)))
     {
        AppSecureLogExceptionTag(pTag, "SetPreviewFormat failed with %s", GetErrorMessage(GetLastResult()));
         return false;
@@ -236,3 +259,9 @@ CameraTools::GetHeight(void)
 {
     return __height;
 }
+
+Tizen::Graphics::PixelFormat
+CameraTools::GetFormat(void)
+{
+    return __format;
+}
index b16f293..0c14763 100644 (file)
@@ -22,6 +22,9 @@
 #include <FApp.h>
 #include <FIo.h>
 
+using namespace Tizen::Graphics;
+using namespace Tizen::Base;
+
 Tracker::Tracker()
     : __pQrRecognizer(0)
     , __pRenderer(0)
@@ -84,11 +87,32 @@ Tracker::OnCameraPreviewed(Tizen::Base::ByteBuffer& previewedData, result r)
     if (__doRender && !__terminating)
     {
         bool was_object = false;
-        __pQrRecognizer->ProcessImage(previewedData);
+
+        Tizen::Base::ByteBuffer* pBuffer = new (std::nothrow) ByteBuffer();
+               TryReturn(pBuffer != null, , "Failed to create ByteBuffer");
+               /* check the preview format*/
+               if (CameraTools::GetFormat() == PIXEL_FORMAT_NV12)
+               {
+                       byte *pSrcArray = null;
+                       byte *pDstArray = null;
+                       pBuffer->Construct((CameraTools::GetHeight()*CameraTools::GetWidth())*1.5);
+
+                       pSrcArray = previewedData.GetPointer();
+                       pDstArray = pBuffer->GetPointer();
+
+                       ConvertNV12ToYCbCr(pSrcArray,pDstArray,CameraTools::GetHeight(),CameraTools::GetWidth());
+               }/*check the preview format*/
+               else
+               {
+                       pBuffer->Construct(previewedData);
+               }
+
+        __pQrRecognizer->ProcessImage(*pBuffer);
+
 
         if (GLtools::startDrawing())
         {
-            __pRenderer->SetTextureData(CameraTools::GetWidth(), CameraTools::GetHeight(), (unsigned char*) previewedData.GetPointer());
+            __pRenderer->SetTextureData(CameraTools::GetWidth(), CameraTools::GetHeight(), (unsigned char*) pBuffer->GetPointer());
             static float zeroBuffer[4][4] = {{ 0, 0, 0, 0}};
             static Tizen::Graphics::FloatMatrix4 zeroMatrix(zeroBuffer);
             __pRenderer->SetModelViewMatrix(0, &zeroMatrix);
@@ -118,6 +142,9 @@ Tracker::OnCameraPreviewed(Tizen::Base::ByteBuffer& previewedData, result r)
         }
 
         __pForm->Draw();
+
+        if(pBuffer)
+               delete pBuffer;
     }
     else if (__terminating)
     {
@@ -200,3 +227,25 @@ Tracker::Focus(bool objectVisible)
         frames = 0;
     }
 }
+
+void
+Tracker::ConvertNV12ToYCbCr(byte *src, byte *dst, int width, int height)
+{
+       byte *pSrcStart = src;
+       byte *pDstStart = dst;
+       byte *pDstUStart = dst + width*height;
+       byte *pDstVStart = pDstUStart + width*height/4;
+
+       //Copy Y Components
+       memcpy(pDstStart, pSrcStart, (width*height));
+       pSrcStart += width*height;
+
+       //Copy UV Components
+       for (int i = 0; i < (width*height)/4; i++)
+       {
+               *pDstUStart++ = *pSrcStart++;
+               *pDstVStart++ = *pSrcStart++;
+       }
+
+       return;
+}