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;
{
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)
, __orientation(EXIF_ORIENTATION_TOP_LEFT)
, __pixelFormat(MEDIA_PIXEL_FORMAT_NONE)
, __isLocked(false)
+ , __transparent(false)
+ , __maskColor(0xf81f) // MAGENTA
{
}
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()));
__pBuffer.reset(new (std::nothrow) byte[reqBufferSize]);
SysTryReturn(NID_MEDIA, __pBuffer.get() != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY,
"[E_OUT_OF_MEMORY] Construct instance failed.");
- memset(__pBuffer.get(), 0, reqBufferSize);
+
__bufSize = reqBufferSize;
if (pData != null)
{
memcpy(__pBuffer.get(), pData, reqBufferSize);
}
+ else
+ {
+ memset(__pBuffer.get(), 0, reqBufferSize);
+ }
return r;
}
std::unique_ptr<byte[]> pDstBuf;
Tizen::Graphics::Rectangle transformRegion;
int orientationInfo = 0;
+ Boolean transparency(false);
+ Integer chromaKey;
r = dec.Construct(srcImageBuf);
SysTryReturn(NID_MEDIA, r == E_SUCCESS, r, r, "[%s] Decoder construct failed.", GetErrorMessage(r));
__pBuffer.reset(dec.DecodeN(__bufSize));
SysTryReturn(NID_MEDIA, __pBuffer.get() != null, r, r,
"[%s] DecodeN returned empty buffer.", GetErrorMessage(r));
+ r = dec.GetValue("transparency", transparency);
+ if (r != E_SUCCESS)
+ {
+ __transparent = false;
+ r = E_SUCCESS;
+ }
+ else
+ {
+ __transparent = transparency.ToBool();
+ if (__transparent == true)
+ {
+ r = dec.GetValue(L"chromaKey", chromaKey);
+ if (r != E_SUCCESS)
+ {
+ __transparent = false;
+ r = E_SUCCESS;
+ }
+ else
+ {
+ __maskColor = chromaKey.ToInt();
+ }
+ }
+ }
}
else if (r == E_UNSUPPORTED_OPERATION)
{
__bufSize = _ImageUtil::GetBufferSize(__pixelFormat, pDecodingRegion->width, pDecodingRegion->height);
SysTryReturn(NID_MEDIA, __bufSize > 0, GetLastResult(), GetLastResult(),
"[%s] Could not get output buffer size.", GetErrorMessage(GetLastResult()));
+
+ r = dec.GetValue("transparency", transparency);
+ if (r != E_SUCCESS)
+ {
+ __transparent = false;
+ r = E_SUCCESS;
+ }
+ else
+ {
+ __transparent = transparency.ToBool();
+ if (__transparent == true)
+ {
+ r = dec.GetValue(L"chromaKey", chromaKey);
+ if (r != E_SUCCESS)
+ {
+ __transparent = false;
+ r = E_SUCCESS;
+ }
+ else
+ {
+ __maskColor = chromaKey.ToInt();
+ }
+ }
+ }
}
}
else
SysTryReturn(NID_MEDIA, r == E_SUCCESS, r, r, "[%s] DecodeN failed.", GetErrorMessage(r));
SysTryReturn(NID_MEDIA, __pBuffer.get() != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY,
"[E_OUT_OF_MEMORY] Propagated.");
+
+ r = dec.GetValue("transparency", transparency);
+ if (r != E_SUCCESS)
+ {
+ __transparent = false;
+ r = E_SUCCESS;
+ }
+ else
+ {
+ __transparent = transparency.ToBool();
+ if (__transparent == true)
+ {
+ r = dec.GetValue(L"chromaKey", chromaKey);
+ if (r != E_SUCCESS)
+ {
+ __transparent = false;
+ r = E_SUCCESS;
+ }
+ else
+ {
+ __maskColor = chromaKey.ToInt();
+ }
+ }
+ }
}
if (autoRotate == true)
_ImageDecoder dec;
std::unique_ptr<byte[]> pDstBuf;
Tizen::Graphics::Rectangle transformRegion;
+ Boolean transparency(false);
+ Integer chromaKey;
r = dec.Construct(srcImageBuf);
SysTryReturn(NID_MEDIA, r == E_SUCCESS, r, r, "[%s] Decoder construct failed.", GetErrorMessage(r));
SysTryReturn(NID_MEDIA, __pBuffer.get() != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY,
"[E_OUT_OF_MEMORY] Propagated.");
+ r = dec.GetValue("transparency", transparency);
+ if (r != E_SUCCESS)
+ {
+ __transparent = false;
+ r = E_SUCCESS;
+ }
+ else
+ {
+ __transparent = transparency.ToBool();
+ if (__transparent == true)
+ {
+ r = dec.GetValue(L"chromaKey", chromaKey);
+ if (r != E_SUCCESS)
+ {
+ __transparent = false;
+ r = E_SUCCESS;
+ }
+ else
+ {
+ __maskColor = chromaKey.ToInt();
+ }
+ }
+ }
+
r = dec.GetDimension(__width, __height);
SysTryReturn(NID_MEDIA, r == E_SUCCESS, r, r, "[%s] GetDimension failed.",
GetErrorMessage(r));
r = pOutBitmap->Construct(*pTmpByteBuffer.get(), Dimension(__width, __height), pixelFormat, bufferScaling);
}
+ if ((__transparent == true) && (pixelFormat == BITMAP_PIXEL_FORMAT_RGB565))
+ {
+ byte red = 0;
+ byte green = 0;
+ byte blue = 0;
+ Color *pMaskingColor = null;
+
+ if (__pixelFormat == MEDIA_PIXEL_FORMAT_BGRA8888)
+ {
+ blue = (__maskColor & 0x000000ff);
+ green = (__maskColor & 0x0000ff00) >> 8;
+ red = (__maskColor & 0x00ff0000) >> 16;
+ }
+ else
+ {
+ red = (__maskColor & 0xf800) >> 8;
+ red = red | (red >> 5);
+ green = (__maskColor & 0x07e0) >> 3;
+ green = green | (green >> 6);
+ blue = (__maskColor & 0x001f) << 3;
+ blue = blue | (blue >> 5);
+ }
+
+ pMaskingColor = new Color(red, green, blue);
+ 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));
+ }
+
SysTryReturn(NID_MEDIA, r == E_SUCCESS, null, r, "[%s] Propagated.",
GetErrorMessage(r));
return pOutBitmap.release();
pOutBitmap.reset(_BitmapImpl::GetNonScaledBitmapN(*pOutBuf.get(), convertDim, pixelFormat, destDim));
}
+ if ((__transparent == true) && (pixelFormat == BITMAP_PIXEL_FORMAT_RGB565))
+ {
+ byte red = 0;
+ byte green = 0;
+ byte blue = 0;
+ Color *pMaskingColor = null;
+
+ if (__pixelFormat == MEDIA_PIXEL_FORMAT_BGRA8888)
+ {
+ blue = (__maskColor & 0x000000ff);
+ green = (__maskColor & 0x0000ff00) >> 8;
+ red = (__maskColor & 0x00ff0000) >> 16;
+ }
+ else
+ {
+ red = (__maskColor & 0xf800) >> 8;
+ red = red | (red >> 5);
+ green = (__maskColor & 0x07e0) >> 3;
+ green = green | (green >> 6);
+ blue = (__maskColor & 0x001f) << 3;
+ blue = blue | (blue >> 5);
+ }
+
+ pMaskingColor = new Color(red, green, blue);
+ 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));
+ }
+
SysTryReturn(NID_MEDIA, pOutBitmap.get() != null, null, GetLastResult(), "[%s] Propagated.", GetErrorMessage(GetLastResult()));
return pOutBitmap.release();
}
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.")
byte* pData = null;
int length = 0;
MediaPixelFormat pixFmt = MEDIA_PIXEL_FORMAT_NONE;
+ _ImageBufferImpl* pClonedImpl = null;
r = const_cast<_ImageBufferImpl *>(this)->Lock(pData, length, pixFmt);
SysTryReturn(NID_MEDIA, r == E_SUCCESS, pImgBuffer.get(), r, "[%s] Propagated.", GetErrorMessage(r));
SysTryReturn(NID_MEDIA, r == E_SUCCESS, null, r,
"[%s] Failed to construct the cloned ImageBuffer.", GetErrorMessage(r));
+ pClonedImpl = GetInstance(*pImgBuffer);
+ SysTryReturn(NID_MEDIA, pClonedImpl != null, null, r,
+ "[%s] Failed to GetInstance.", GetErrorMessage(r));
+ pClonedImpl->__maskColor = __maskColor;
+ pClonedImpl->__transparent = __transparent;
+
const_cast<_ImageBufferImpl *>(this)->Unlock();
SetLastResult(r);
int length = 0;
int dstLength = 0;
MediaPixelFormat pixFmt = MEDIA_PIXEL_FORMAT_NONE;
+ _ImageBufferImpl* pConvertedImpl = null;
+
+ SysTryReturn(NID_MEDIA, IsSupportedPixelFormat(pixelFormat) == true , null, E_UNSUPPORTED_FORMAT,
+ "[E_UNSUPPORTED_FORMAT] The specified pixelFormat is not supported.")
- SysTryReturn(NID_MEDIA, ISSUPPORTED(pixelFormat) == true, pImgBuffer.get(), E_INVALID_ARG,
- "[E_INVALID_ARG] Pixel format %d is not supported.", pixelFormat);
+ 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)
{
r = pImgBuffer->Construct(__width, __height, pixelFormat, pDataConvert.get(), dstLength);
SysTryReturn(NID_MEDIA, r == E_SUCCESS, null, r,
"[%s] Failed to construct the converted ImageBuffer.", GetErrorMessage(r));
+
+ pConvertedImpl = GetInstance(*pImgBuffer);
+ SysTryReturn(NID_MEDIA, pConvertedImpl != null, null, r,
+ "[%s] Failed to GetInstance.", GetErrorMessage(r));
+ pConvertedImpl->__maskColor = __maskColor;
+ pConvertedImpl->__transparent = __transparent;
+
}
else
{
int length = 0;
int dstLength = 0;
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);
r = pImgBuffer->Construct(width, height, __pixelFormat, pDataResized.get(), dstLength);
SysTryReturn(NID_MEDIA, r == E_SUCCESS, null, r,
"[%s] Failed to construct the resized ImageBuffer.", GetErrorMessage(r));
+
+ pResizedImpl = GetInstance(*pImgBuffer);
+ SysTryReturn(NID_MEDIA, pResizedImpl != null, null, r,
+ "[%s] Failed to GetInstance.", GetErrorMessage(r));
+ pResizedImpl->__maskColor = __maskColor;
+ pResizedImpl->__transparent = __transparent;
}
else
{
std::unique_ptr<byte[]> pDataFlip;
int length = 0;
MediaPixelFormat pixFmt = MEDIA_PIXEL_FORMAT_NONE;
+ _ImageBufferImpl* pFlippedImpl = null;
SysTryReturn(NID_MEDIA, (flipType >= IMAGE_FLIP_NONE) && (flipType <= IMAGE_FLIP_VERTICAL),
pImgBuffer.get(), E_INVALID_ARG, "[E_INVALID_ARG] Flip type is not valid: %d.", flipType);
r = pImgBuffer->Construct(__width, __height, __pixelFormat, pDataFlip.get(), length);
SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r,
"[%s] Failed to construct the fliped ImageBuffer.", GetErrorMessage(r));
+
+ pFlippedImpl = GetInstance(*pImgBuffer);
+ SysTryReturn(NID_MEDIA, pFlippedImpl != null, null, r,
+ "[%s] Failed to GetInstance.", GetErrorMessage(r));
+ pFlippedImpl->__maskColor = __maskColor;
+ pFlippedImpl->__transparent = __transparent;
}
else
{
int rotatedWidth= 0;
int rotatedHeight = 0;
MediaPixelFormat pixFmt = MEDIA_PIXEL_FORMAT_NONE;
+ _ImageBufferImpl* pRotatedImpl = null;
SysTryReturn(NID_MEDIA, (rotationType >= IMAGE_ROTATION_0) && (rotationType <= IMAGE_ROTATION_270),
pImgBuffer.get(), E_INVALID_ARG, "[E_INVALID_ARG] Rotation type is not valid: %d.", rotationType);
r = pImgBuffer->Construct(rotatedWidth, rotatedHeight, __pixelFormat, pDataRotate.get(), length);
SysTryReturn(NID_MEDIA, r == E_SUCCESS, null, r,
"[%s] Failed to construct the rotated ImageBuffer.", GetErrorMessage(r));
+
+ pRotatedImpl = GetInstance(*pImgBuffer);
+ SysTryReturn(NID_MEDIA, pRotatedImpl != null, null, r,
+ "[%s] Failed to GetInstance.", GetErrorMessage(r));
+ pRotatedImpl->__maskColor = __maskColor;
+ pRotatedImpl->__transparent = __transparent;
}
else
{
int length = 0;
int dstLength = 0;
MediaPixelFormat pixFmt = MEDIA_PIXEL_FORMAT_NONE;
+ _ImageBufferImpl *pCroppedImpl = null;
SysTryReturn(NID_MEDIA, (x >= 0) && (y >= 0) && (x <= __width) && (y <= __height),
pImgBuffer.get(), E_INVALID_ARG,
r = pImgBuffer->Construct(width, height, __pixelFormat, pDataCropped.get(), dstLength);
SysTryReturn(NID_MEDIA, r == E_SUCCESS, null, r,
"[%s] Failed to construct the croped ImageBuffer.", GetErrorMessage(r));
+
+ pCroppedImpl = GetInstance(*pImgBuffer);
+ SysTryReturn(NID_MEDIA, pCroppedImpl != null, null, r,
+ "[%s] Failed to GetInstance.", GetErrorMessage(r));
+ pCroppedImpl->__maskColor = __maskColor;
+ pCroppedImpl->__transparent = __transparent;
}
else
{
bool
_ImageBufferImpl::IsSupportedPixelFormat(MediaPixelFormat pixelFormat)
{
- for (int i = 0; i < sizeof(_IMAGE_BUFFER_PIXEL_FORMATS)/sizeof(_IMAGE_BUFFER_PIXEL_FORMATS[0]) ; i++)
+ for (unsigned int i = 0; i < sizeof(_IMAGE_BUFFER_PIXEL_FORMATS)/sizeof(_IMAGE_BUFFER_PIXEL_FORMATS[0]) ; i++)
{
if(pixelFormat == _IMAGE_BUFFER_PIXEL_FORMATS[i])
{
"[E_OUT_OF_MEMORY] Could not allocate memory for output.");
// TODO update list later for supported color formats in color converter?.
- for (int i=0; i<sizeof(_IMAGE_BUFFER_PIXEL_FORMATS)/sizeof(_IMAGE_BUFFER_PIXEL_FORMATS[0]); i++)
+ for (unsigned int i=0; i<sizeof(_IMAGE_BUFFER_PIXEL_FORMATS)/sizeof(_IMAGE_BUFFER_PIXEL_FORMATS[0]); i++)
{
r = pList->Add(_IMAGE_BUFFER_PIXEL_FORMATS[i]);
SysTryReturn(NID_MEDIA, r == E_SUCCESS, null, r,