Adding gray8, nv12 and nv21 support in ImageBuffer.
authormamata pattanaik <mamata.p@samsung.com>
Tue, 2 Apr 2013 05:52:15 +0000 (11:22 +0530)
committermamata pattanaik <mamata.p@samsung.com>
Tue, 2 Apr 2013 05:52:15 +0000 (11:22 +0530)
Change-Id: I3e077d710c74af810fca41527b990c8b49e533b0
Signed-off-by: mamata pattanaik <mamata.p@samsung.com>
src/FMedia_ImageBufferImpl.cpp

index 6746310..a3db7e5 100644 (file)
@@ -48,10 +48,6 @@ using namespace Tizen::Ui;
 namespace Tizen { namespace Media
 {
 
-#define ISSUPPORTED(x)                                                                                                                 \
-       ((x == MEDIA_PIXEL_FORMAT_YUV420P) || (x == MEDIA_PIXEL_FORMAT_BGRA8888) ||     \
-       (x == MEDIA_PIXEL_FORMAT_RGB565LE) || (x == MEDIA_PIXEL_FORMAT_GRAY))
-
 typedef struct {
        ImageRotationType rotateType;
        ImageFlipType flipType;
@@ -86,7 +82,10 @@ static const MediaPixelFormat _IMAGE_BUFFER_PIXEL_FORMATS[] =
 {
        MEDIA_PIXEL_FORMAT_RGB565LE,
        MEDIA_PIXEL_FORMAT_BGRA8888,
-       MEDIA_PIXEL_FORMAT_YUV420P
+       MEDIA_PIXEL_FORMAT_YUV420P,
+       MEDIA_PIXEL_FORMAT_NV12,
+       MEDIA_PIXEL_FORMAT_NV21,
+       MEDIA_PIXEL_FORMAT_GRAY
 };
 
 _ImageBufferImpl::_ImageBufferImpl(void)
@@ -145,9 +144,6 @@ _ImageBufferImpl::Construct(int width, int height, MediaPixelFormat pixelFormat,
        SysTryReturn(NID_MEDIA, (width > 0) && (height > 0), E_INVALID_ARG, E_INVALID_ARG,
                "[E_INVALID_ARG] Dimensions should be greater than zero : (%d x %d).", width, height);
 
-       SysTryReturn(NID_MEDIA, ISSUPPORTED(pixelFormat) == true, E_INVALID_ARG, E_INVALID_ARG,
-               "[E_INVALID_ARG] Pixelformat is not supported : %d.", pixelFormat);
-
        reqBufferSize = _ImageUtil::GetBufferSize(pixelFormat, width, height);
        SysTryReturn(NID_MEDIA, reqBufferSize > 0, GetLastResult(), GetLastResult(),
                        "[%s] Could not get output buffer size.", GetErrorMessage(GetLastResult()));
@@ -837,9 +833,9 @@ _ImageBufferImpl::GetBitmapN(BitmapPixelFormat pixelFormat, BufferScaling buffer
                SysTryReturn(NID_MEDIA, pMaskingColor != null, pOutBitmap.release(), E_SUCCESS,
                        "[%s] Could not apply masking color.", GetErrorMessage(r));
                r = pOutBitmap->SetMaskingColor(pMaskingColor);
+               delete pMaskingColor;
                SysTryReturn(NID_MEDIA, r == E_SUCCESS, pOutBitmap.release(), E_SUCCESS,
                        "[%s] Could not set masking color.", GetErrorMessage(r));
-               delete pMaskingColor;
        }
 
        SysTryReturn(NID_MEDIA, r == E_SUCCESS, null, r, "[%s] Propagated.",
@@ -921,9 +917,9 @@ _ImageBufferImpl::GetBitmapN(BitmapPixelFormat pixelFormat, const FloatDimension
                SysTryReturn(NID_MEDIA, pMaskingColor != null, pOutBitmap.release(), E_SUCCESS,
                        "[%s] Could not apply masking color.", GetErrorMessage(r));
                r = pOutBitmap->SetMaskingColor(pMaskingColor);
+               delete pMaskingColor;
                SysTryReturn(NID_MEDIA, r == E_SUCCESS, pOutBitmap.release(), E_SUCCESS,
                        "[%s] Could not set masking color.", GetErrorMessage(r));
-               delete pMaskingColor;
        }
 
        SysTryReturn(NID_MEDIA, pOutBitmap.get() != null, null, GetLastResult(), "[%s] Propagated.", GetErrorMessage(GetLastResult()));
@@ -939,9 +935,6 @@ _ImageBufferImpl::GetByteBufferN(MediaPixelFormat inPixelFormat) const
        SysTryReturn(NID_MEDIA, !__isLocked, null, E_INVALID_STATE,
                "[E_INVALID_STATE] Instance is locked. Unlock to use.");
 
-       SysTryReturn(NID_MEDIA, (inPixelFormat > MEDIA_PIXEL_FORMAT_NONE) && (inPixelFormat <= MEDIA_PIXEL_FORMAT_YUYV422),
-               null, E_INVALID_ARG, "[E_INVALID_ARG] Pixel format is invalid.", inPixelFormat);
-
        SysTryReturn(NID_MEDIA, IsSupportedPixelFormat(inPixelFormat) == true , null, E_UNSUPPORTED_FORMAT,
                "[E_UNSUPPORTED_FORMAT] The specified pixelFormat is not supported.")
 
@@ -1023,8 +1016,11 @@ _ImageBufferImpl::ConvertPixelFormatN(MediaPixelFormat pixelFormat) const
        MediaPixelFormat pixFmt = MEDIA_PIXEL_FORMAT_NONE;
        _ImageBufferImpl* pConvertedImpl = null;
 
-       SysTryReturn(NID_MEDIA, ISSUPPORTED(pixelFormat) == true, pImgBuffer.get(), E_INVALID_ARG,
-               "[E_INVALID_ARG] Pixel format %d is not supported.", pixelFormat);
+       SysTryReturn(NID_MEDIA, IsSupportedPixelFormat(pixelFormat) == true , null, E_UNSUPPORTED_FORMAT,
+               "[E_UNSUPPORTED_FORMAT] The specified pixelFormat is not supported.")
+
+       SysTryReturn(NID_MEDIA, _ImageUtil::IsValidDimension(pixelFormat, __width, __height) == true, null, E_INVALID_ARG,
+               "[E_INVALID_ARG] Dimensions should be even for this pixel format: (%d x %d)", __width, __height);
 
        if (pixelFormat != __pixelFormat)
        {
@@ -1058,6 +1054,7 @@ _ImageBufferImpl::ConvertPixelFormatN(MediaPixelFormat pixelFormat) const
                        "[%s] Failed to GetInstance.", GetErrorMessage(r));
                pConvertedImpl->__maskColor = __maskColor;
                pConvertedImpl->__transparent = __transparent;
+
        }
        else
        {
@@ -1085,9 +1082,12 @@ _ImageBufferImpl::ResizeN(int width, int height) const
        MediaPixelFormat pixFmt = MEDIA_PIXEL_FORMAT_NONE;
        _ImageBufferImpl* pResizedImpl = null;
 
-       SysTryReturn(NID_MEDIA, (width > 0) && (height > 0), pImgBuffer.get(), E_INVALID_ARG,
+       SysTryReturn(NID_MEDIA, (width > 0) && (height > 0), null, E_INVALID_ARG,
                "[E_INVALID_ARG] Dimensions should be greater than zero: (%d x %d)", width, height);
 
+       SysTryReturn(NID_MEDIA, _ImageUtil::IsValidDimension(__pixelFormat, width, height) == true, null, E_INVALID_ARG,
+               "[E_INVALID_ARG] Dimensions should be even for this pixel format: (%d x %d)", width, height);
+
        if ((width != __width) && (height != __height))
        {
                dstLength = _ImageUtil::GetBufferSize(__pixelFormat, width, height);
@@ -1114,7 +1114,7 @@ _ImageBufferImpl::ResizeN(int width, int height) const
                SysTryCatch(NID_MEDIA, pImgBuffer.get() != null, , E_OUT_OF_MEMORY,
                        "[E_OUT_OF_MEMORY] Could not create new instance.")
 
-               r = pImgBuffer->Construct(width, height, __pixelFormat, pDataResized.get(), dstLength);
+               r = pImgBuffer->Construct(width, height, __pixelFormat, pDataResized.release(), dstLength);
                SysTryReturn(NID_MEDIA, r == E_SUCCESS, null, r,
                        "[%s] Failed to construct the resized ImageBuffer.", GetErrorMessage(r));