From: santhosh.au Date: Fri, 16 Aug 2013 13:34:23 +0000 (+0530) Subject: Support for NV12 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=ef4ce40878a33c3ad055c943231e2412ce3b47bf;p=apps%2Fnative%2Fsample%2FQrCodeRecognizer.git Support for NV12 Change-Id: I23a748e3e54b683d62e8ee091575842974d0e1b0 Signed-off-by: santhosh.au --- diff --git a/project/inc/CameraTools.h b/project/inc/CameraTools.h index 5dcc6b0..7699bbe 100644 --- a/project/inc/CameraTools.h +++ b/project/inc/CameraTools.h @@ -19,6 +19,7 @@ #define CAMERA_TOOLS_H_ #include +#include 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_ diff --git a/project/inc/Tracker.h b/project/inc/Tracker.h index 0f2c7a3..314cd6b 100644 --- a/project/inc/Tracker.h +++ b/project/inc/Tracker.h @@ -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; diff --git a/project/src/CameraTools.cpp b/project/src/CameraTools.cpp index fe2f240..f3d0ecc 100644 --- a/project/src/CameraTools.cpp +++ b/project/src/CameraTools.cpp @@ -20,12 +20,15 @@ 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* 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; +} diff --git a/project/src/Tracker.cpp b/project/src/Tracker.cpp index b16f293..0c14763 100644 --- a/project/src/Tracker.cpp +++ b/project/src/Tracker.cpp @@ -22,6 +22,9 @@ #include #include +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; +}