namespace Tizen { namespace Media
{
-#define IS_VALID_PIXEL(x) \
- ((x == MEDIA_PIXEL_FORMAT_YUV420P) || (x == MEDIA_PIXEL_FORMAT_NV12) \
- || (x == MEDIA_PIXEL_FORMAT_YUYV422) || (x == MEDIA_PIXEL_FORMAT_RGB565LE) \
+#define IS_VALID_PIXEL(x) \
+ ((x == MEDIA_PIXEL_FORMAT_RGB565LE) || ( x == MEDIA_PIXEL_FORMAT_GRAY) \
|| (x == MEDIA_PIXEL_FORMAT_BGRA8888) || (x == MEDIA_PIXEL_FORMAT_RGBA8888) \
|| (x == MEDIA_PIXEL_FORMAT_BGR888) || (x == MEDIA_PIXEL_FORMAT_RGB888) \
- || (x == MEDIA_PIXEL_FORMAT_NV21) || ( x == MEDIA_PIXEL_FORMAT_YUV444P))
+ || ( x == MEDIA_PIXEL_FORMAT_YUV444P) || (x == MEDIA_PIXEL_FORMAT_YUYV422) \
+ || (x == MEDIA_PIXEL_FORMAT_YUV420P) || (x == MEDIA_PIXEL_FORMAT_NV12) || (x == MEDIA_PIXEL_FORMAT_NV21))
#define IS_VALID_BUF(buf, format, w, h) \
(_ImageUtil::GetBufferSize(format, w, h) <= buf.GetCapacity())
{ MEDIA_PIXEL_FORMAT_UYVY422, PIX_FMT_UYVY422, 2 },
{ MEDIA_PIXEL_FORMAT_NV12, PIX_FMT_NV12, 1.5 },
{ MEDIA_PIXEL_FORMAT_NV12_TILE, PIX_FMT_NV12, 1.5 },
- { MEDIA_PIXEL_FORMAT_NV21, PIX_FMT_NV21, 1.5 }
+ { MEDIA_PIXEL_FORMAT_NV21, PIX_FMT_NV21, 1.5 },
+ { MEDIA_PIXEL_FORMAT_GRAY, PIX_FMT_GRAY8, 1 }
};
static const int _BPP_RGB565 = 2;
}
/*
+* Input is assumed to be GRAY8
+* pDataIn => Input GRAY8 Buffer
+* pDataOut => Output GRAY8 Buffer (memory is assumed to be already allocated)
+* inWidth => Input Width
+* inHeight => Input Height
+* outWidth => Output Width
+* outHeight => Output Height
+*/
+result
+_ImageUtil::ResizeGray(const byte* pDataIn, byte* pDataOut, int inWidth, int inHeight, int outWidth, int outHeight)
+{
+ int scaleX = 0;
+ int scaleY = 0;
+ int i = 0;
+ int j = 0;
+
+ int iRow = 0;
+ int iIndex = 0;
+
+ byte* pOutput = pDataOut;
+ byte* pOut = pDataOut;
+ const byte* pIn = null;
+
+ std::unique_ptr<int []> pColLUT (new (std::nothrow) int[sizeof(int) * outWidth]);
+ SysTryReturn(NID_MEDIA, pColLUT.get() != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY,
+ "[E_OUT_OF_MEMORY] Could not allocate memory.");
+
+ /* Calculate X Scale factor */
+ scaleX = inWidth * 256 / outWidth;
+
+ /* Calculate Y Scale factor, aspect ratio is not maintained */
+ scaleY = inHeight * 256 / outHeight;
+
+ for (j = 0; j < outWidth; j++)
+ {
+ /* Get input index based on column scale factor */
+
+ /* To get more optimization, this is calculated once and
+ * is placed in a LUT and used for indexing
+ */
+ pColLUT [j] = ((j * scaleX) >> 8);
+ }
+
+ pOut = pOutput;
+
+ for (i = 0; i < outHeight; i++)
+ {
+ /* Get input row index based on row scale factor */
+ iRow = (i * scaleY >> 8) * inWidth;
+
+ /* Loop could be unrolled for more optimization */
+ for (j = 0; j < (outWidth); j++)
+ {
+ /* Get input index based on column scale factor */
+ iIndex = iRow + pColLUT [j];
+
+ pIn = pDataIn + iIndex;
+ *pOut++ = *pIn++;
+ }
+ }
+
+ return E_SUCCESS;
+}
+
+/*
* Input is assumed to be YUV444
* pDataIn => Input YUV444 Buffer
* pDataOut => Output buffer, allocated by caller
}
break;
+ case MEDIA_PIXEL_FORMAT_GRAY:
+ {
+ r = ResizeGray(pInBuf, pOutBuf, srcWidth, srcHeight, dstWidth, dstHeight);
+ }
+ break;
+
case MEDIA_PIXEL_FORMAT_YUV444P:
{
r = ResizeYUV444(pInBuf, pOutBuf, srcWidth, srcHeight, dstWidth, dstHeight);
break;
case MEDIA_PIXEL_FORMAT_NV12:
+ case MEDIA_PIXEL_FORMAT_NV21:
{
r = ResizeNV12(pInBuf, pOutBuf, srcWidth, srcHeight, dstWidth, dstHeight);
}
outHeight = height;
}
- if (pixelFormat == MEDIA_PIXEL_FORMAT_RGB888)
- {
+ if (pixelFormat == MEDIA_PIXEL_FORMAT_GRAY)
+ {
+ int rowCount = 0;
+ int colCount = 0;
+ byte* pSrcBuf = (byte *)srcBuf;
+ byte* pDstBuf = (byte *)dstBuf;
+ byte* pTmpOutCol = null;
+
+ switch (rotate)
+ {
+ case IMAGE_ROTATION_90:
+ {
+ // Copying from all source rows to destination columns.
+ for (rowCount = 0; rowCount < height; rowCount++)
+ {
+ // pTmpOutCol points to the top of the output column being filled.
+ pTmpOutCol = pDstBuf + (outWidth - 1) - rowCount;
+
+ for (colCount = 0; colCount < width; colCount++)
+ {
+ *pTmpOutCol = *pSrcBuf++;
+ pTmpOutCol += outWidth;
+ }
+ }
+ }
+ break;
+ case IMAGE_ROTATION_180:
+ {
+ // Copying all source rows to destination columns.
+ for (rowCount = 0; rowCount < height; rowCount++)
+ {
+ // pTmpOutCol points to the bottom of the column being filled.
+ pTmpOutCol = pDstBuf + ((outWidth * outHeight) - 1) - (rowCount * outWidth);
+
+ for (colCount = 0; colCount < width; colCount++)
+ {
+ *pTmpOutCol-- = *pSrcBuf++;
+ }
+ }
+ }
+ break;
+ case IMAGE_ROTATION_270:
+ {
+ // Copying all source rows to destination columns.
+ for (rowCount = 0; rowCount < height; rowCount++)
+ {
+ // pTmpOutCol points to the bottom of the column being filled.
+ pTmpOutCol = pDstBuf + (outWidth * (outHeight - 1)) + rowCount;
+
+ for (colCount = 0; colCount < width; colCount++)
+ {
+ *pTmpOutCol = *pSrcBuf++;
+ pTmpOutCol -= outWidth;
+ }
+ }
+ }
+ break;
+ default:
+ break;
+ }
+ }
+ else if (pixelFormat == MEDIA_PIXEL_FORMAT_RGB888)
+ {
int rowCount = 0;
int colCount = 0;
byte* pSrcBuf = (byte *)srcBuf;
break;
}
}
-
else if (pixelFormat == MEDIA_PIXEL_FORMAT_RGB565LE)
{
switch (rotate)
// Copying from all source rows to destination columns of Y plane.
for (rowCount = 0; rowCount < height / 2; rowCount++)
{
- // pTmpOutCol points to the top of the output column being filled.
+ // pTmpOutCol points to the top of the output column being filled.
pTmpOutColU = pDstU + (outWidth / 2) - 1 - rowCount;
pTmpOutColV = pDstV + (outWidth / 2) - 1 - rowCount;
pTmpOutColY = pDstY + outWidth - 1 - rowCount;
*pTmpOutColY = *pSrcY++;
pTmpOutColY += outWidth;
}
- }
+ }
for (rowCount = height / 2; rowCount < height; rowCount++)
{
pTmpOutColY = pDstY + outWidth - 1 - rowCount;
// Copying from all source rows to destination columns of Y plane.
for (rowCount = 0; rowCount < height / 2; rowCount++)
- {
+ {
// pTmpOutCol points to the top of the output column being filled.
pTmpOutColY = pDstY + (outWidth * (outHeight - 1)) + rowCount;
pTmpOutColU = pDstU + (outWidth / 2) * (outHeight / 2 - 1) + rowCount;
pTmpOutColU -= outWidth / 2;
*pTmpOutColV = *pSrcV++;
pTmpOutColV -= outWidth / 2;
- }
+ }
for (colCount = width / 2; colCount < width; colCount++)
{
*pTmpOutColY = *pSrcY++;
pTmpOutColY -= outWidth;
}
- }
+ }
for (rowCount = height / 2; rowCount < height; rowCount++)
- {
+ {
pTmpOutColY = pDstY + (outWidth * (outHeight - 1)) + rowCount;
// pTmpOutCol points to the top of the output column being filled.
for (colCount = 0; colCount < width; colCount++)
pTmpOutColY -= outWidth;
}
}
- }
+ }
break;
default:
break;
*pTmpOutColY-- = *pSrcY++;
}
}
- break;
+ break;
case IMAGE_ROTATION_270:
{
// Copying from all source rows to destination columns of Y plane.
for (colCount = 0; colCount < width / 2; colCount++)
{
*pTmpOutColU = *pSrcU++;
- pTmpOutColU += outWidth;
+ pTmpOutColU += outWidth;
*pTmpOutColV = *pSrcV++;
pTmpOutColV += outWidth;
*pTmpOutColY = *pSrcY++;
pTmpOutColY += outWidth;
*pTmpOutColU = *pSrcU++;
- pTmpOutColU += outWidth;
+ pTmpOutColU += outWidth;
*pTmpOutColV = *pSrcV++;
pTmpOutColV += outWidth;
*pTmpOutColY = *pSrcY++;
{
case IMAGE_ROTATION_90:
{
- // Copying from all source rows to destination columns.
- for (rowCount = 0; rowCount < height; rowCount++)
- {
- // pTmpOutCol points to the top of the output column being filled.
- pTmpOutCol = pDstBuf + outWidth - 1 - rowCount;
- for (colCount = 0; colCount < width / 2 ; colCount++)
- {
+ // Copying from all source rows to destination columns.
+ for (rowCount = 0; rowCount < height; rowCount++)
+ {
+ // pTmpOutCol points to the top of the output column being filled.
+ pTmpOutCol = pDstBuf + outWidth - 1 - rowCount;
+ for (colCount = 0; colCount < width / 2 ; colCount++)
+ {
*pTmpOutCol = *pSrcBuf++; // copied Y0 U0
pTmpOutCol += outWidth;
*pTmpOutCol = *pSrcBuf++; // copied Y1 V0
pTmpOutCol += outWidth;
- }
- }
- }
- break;
+ }
+ }
+ }
+ break;
case IMAGE_ROTATION_180:
- {
+ {
// Copying all source rows to destination columns.
for (rowCount = 0; rowCount < height; rowCount++)
{
ImageRotationType rotate)
{
result r = E_SUCCESS;
- int ret = 0;
-#ifdef USE_MM_UTIL
- mm_util_img_format colorFormat = MM_UTIL_IMG_FMT_NUM;
- mm_util_img_rotate_type rotation = MM_UTIL_ROTATE_NUM;
-
- unsigned int outWidth = 0;
- unsigned int outHeight = 0;
-#else
- image_util_colorspace_e colorFormat = IMAGE_UTIL_COLORSPACE_RGB565;
- image_util_rotation_e rotation = IMAGE_UTIL_ROTATION_NONE;
int outWidth = 0;
int outHeight = 0;
-#endif
-
SysTryCatch(NID_MEDIA, IS_VALID_BUF(srcBuf, pixelFormat, width, height),
r = E_INVALID_ARG, E_INVALID_ARG,
outHeight = height;
}
- return RotateBuffer( (byte *)srcBuf.GetPointer(), pixelFormat, width, height, (byte *)dstBuf.GetPointer(), (int &)outWidth, (int &)outHeight, rotate);
+ return RotateBuffer((byte *)srcBuf.GetPointer(), pixelFormat, width, height,
+ (byte *)dstBuf.GetPointer(), outWidth, outHeight, rotate);
CATCH:
return r;
}
int dstX, int dstY, int dstWidth, int dstHeight)
{
result r = E_SUCCESS;
- byte* pInBuffer = null;
- byte* pOutBuffer = null;
- int copyRowWidth = 0;
- int srcRowWidth = 0;
- int bpp = 0;
-
- SysTryCatch(NID_MEDIA, srcWidth > 0 && srcHeight > 0, r = E_INVALID_ARG, E_INVALID_ARG,
- "[E_INVALID_ARG] Invalid src dimension: Should be greater than zero (%d x %d)", srcWidth, srcHeight);
- SysTryCatch(NID_MEDIA, dstWidth > 0 && dstHeight > 0, r = E_INVALID_ARG, E_INVALID_ARG,
- "[E_INVALID_ARG] Invalid dst dimension: Should be greater than zero (%d x %d)", dstWidth, dstHeight);
- SysTryCatch(NID_MEDIA, dstX >= 0 && dstY >= 0, r = E_INVALID_ARG, E_INVALID_ARG,
- "[E_INVALID_ARG] Invalid offset dimension: Should be greater than zero (%d x %d)", dstX, dstY);
-
- SysTryCatch(NID_MEDIA, (pixelFormat == MEDIA_PIXEL_FORMAT_RGB565LE) ||
- (pixelFormat == MEDIA_PIXEL_FORMAT_RGBA8888) ||
- (pixelFormat == MEDIA_PIXEL_FORMAT_BGRA8888),
- r = E_UNSUPPORTED_FORMAT, E_UNSUPPORTED_FORMAT,
- "Unsupported pixelFormat: %d", pixelFormat);
-
- SysTryCatch(NID_MEDIA, IsValidDimension(pixelFormat, srcWidth, srcHeight),
- r = E_INVALID_ARG, E_INVALID_ARG,
- "[E_INVALID_ARG] Dimensions should be even (%d x %d).", srcWidth, srcHeight);
-
- SysTryCatch(NID_MEDIA, IS_VALID_BUF(srcBuf, pixelFormat, srcWidth, srcHeight),
- r = E_INVALID_ARG, E_INVALID_ARG,
- "Invalid buffer size (%d) for format (%d), width (%d), height (%d)",
- srcBuf.GetLimit(), pixelFormat, srcWidth, srcHeight);
-
- SysTryCatch(NID_MEDIA, IsValidDimension(pixelFormat, dstWidth, dstHeight),
- r = E_INVALID_ARG, E_INVALID_ARG,
- "[E_INVALID_ARG] Dimensions should be even (%d x %d).", dstWidth, dstHeight);
-
- SysTryCatch(NID_MEDIA, IS_VALID_BUF(dstBuf, pixelFormat, dstWidth, dstHeight),
- r = E_INVALID_ARG, E_INVALID_ARG,
- "Invalid buffer size (%d) for format (%d), width (%d), height (%d)",
- dstBuf.GetLimit(), pixelFormat, dstWidth, dstHeight);
-
- SysTryCatch(NID_MEDIA, dstWidth + dstX <= srcWidth , r = E_INVALID_ARG, E_INVALID_ARG,
- "Invalid Clip Area : destination \"x\" (%d) exceeds image width (%d).",
- dstWidth + dstX, srcWidth);
-
- SysTryCatch(NID_MEDIA, dstHeight + dstY <= srcHeight , r = E_INVALID_ARG, E_INVALID_ARG,
- "Invalid Clip Area : destination \"y\" (%d) exceeds image height (%d).",
- dstHeight + dstY, srcHeight);
-
- pOutBuffer = (byte *)dstBuf.GetPointer();
-
- if (pixelFormat == MEDIA_PIXEL_FORMAT_RGB565LE)
- {
- bpp = 2;
- // pInBuffer points to the start of the region to be copied to destination.
- pInBuffer = (byte *)srcBuf.GetPointer() + (dstY * srcWidth * bpp) + (dstX * bpp);
- copyRowWidth = dstWidth * bpp;
- srcRowWidth = srcWidth * bpp;
- }
- else
- {
- bpp = 4;
- // pInBuffer points to the start of the region to be copied to destination.
- pInBuffer = (byte *)srcBuf.GetPointer() + (dstY * srcWidth * bpp) + (dstX * bpp);
- copyRowWidth = dstWidth * bpp; // BGRA and RGBA are 4 bytes each.
- srcRowWidth = srcWidth * bpp;
- }
- for (int i = dstY; i < dstY + dstHeight; i++)
- {
- memcpy(pOutBuffer, pInBuffer, copyRowWidth);
- pOutBuffer += copyRowWidth;
- pInBuffer += srcRowWidth;
- }
+ r = CropBuffer(srcBuf.GetPointer(), pixelFormat, srcWidth, srcHeight,
+ const_cast<byte*>(dstBuf.GetPointer()), dstX, dstY, dstWidth, dstHeight);
+ SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] _ImageUtil::CropBuffer failed.",
+ GetErrorMessage(r));
r = dstBuf.SetLimit(_ImageUtil::GetBufferSize(pixelFormat, dstWidth, dstHeight));
SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] ByteBuffer.SetLimit to %d failed.",
GetErrorMessage(r), _ImageUtil::GetBufferSize(pixelFormat, dstWidth, dstHeight));
- return r;
CATCH:
return r;
SysTryCatch(NID_MEDIA, dstX >= 0 && dstY >= 0, r = E_INVALID_ARG, E_INVALID_ARG,
"[E_INVALID_ARG] Invalid offset dimension: Should be greater than zero (%d x %d)", dstX, dstY);
- SysTryCatch(NID_MEDIA, (pixelFormat == MEDIA_PIXEL_FORMAT_RGB565LE) ||
- (pixelFormat == MEDIA_PIXEL_FORMAT_RGBA8888) ||
- (pixelFormat == MEDIA_PIXEL_FORMAT_BGRA8888),
- r = E_UNSUPPORTED_FORMAT, E_UNSUPPORTED_FORMAT,
- "Unsupported pixelFormat: %d", pixelFormat);
+ SysTryCatch(NID_MEDIA, IS_VALID_PIXEL(pixelFormat), r = E_UNSUPPORTED_FORMAT, E_UNSUPPORTED_FORMAT,
+ "[E_UNSUPPORTED_FORMAT] Unsupported pixelFormat: %d", pixelFormat);
SysTryCatch(NID_MEDIA, IsValidDimension(pixelFormat, srcWidth, srcHeight),
r = E_INVALID_ARG, E_INVALID_ARG,
pOutBuffer = dstBuf;
- if (pixelFormat == MEDIA_PIXEL_FORMAT_RGB565LE)
+ switch(pixelFormat)
{
- bpp = 2;
- // pInBuffer points to the start of the region to be copied to destination.
- pInBuffer = const_cast<byte*>(srcBuf) + (dstY * srcWidth * bpp) + (dstX * bpp);
- copyRowWidth = dstWidth * bpp;
- srcRowWidth = srcWidth * bpp;
- }
- else
- {
- bpp = 4;
- // pInBuffer points to the start of the region to be copied to destination.
- pInBuffer = const_cast<byte*>(srcBuf) + (dstY * srcWidth * bpp) + (dstX * bpp);
- copyRowWidth = dstWidth * bpp; // BGRA and RGBA are 4 bytes each.
- srcRowWidth = srcWidth * bpp;
- }
+ case MEDIA_PIXEL_FORMAT_GRAY:
+ {
+ bpp = 1;
+ // pInBuffer points to the start of the region to be copied to destination.
+ pInBuffer = const_cast<byte*>(srcBuf) + (dstY * srcWidth * bpp) + (dstX * bpp);
+ copyRowWidth = dstWidth * bpp;
+ srcRowWidth = srcWidth * bpp;
+ for (int i = dstY; i < dstY + dstHeight; i++)
+ {
+ memcpy(pOutBuffer, pInBuffer, copyRowWidth);
+ pOutBuffer += copyRowWidth;
+ pInBuffer += srcRowWidth;
+ }
+ }
+ break;
+ case MEDIA_PIXEL_FORMAT_RGB565LE:
+ {
+ bpp = 2;
+ // pInBuffer points to the start of the region to be copied to destination.
+ pInBuffer = const_cast<byte*>(srcBuf) + (dstY * srcWidth * bpp) + (dstX * bpp);
+ copyRowWidth = dstWidth * bpp;
+ srcRowWidth = srcWidth * bpp;
+ for (int i = dstY; i < dstY + dstHeight; i++)
+ {
+ memcpy(pOutBuffer, pInBuffer, copyRowWidth);
+ pOutBuffer += copyRowWidth;
+ pInBuffer += srcRowWidth;
+ }
+ }
+ break;
+ case MEDIA_PIXEL_FORMAT_RGB888:
+ case MEDIA_PIXEL_FORMAT_BGR888:
+ {
+ bpp = 3;
+ // pInBuffer points to the start of the region to be copied to destination.
+ pInBuffer = const_cast<byte*>(srcBuf) + (dstY * srcWidth * bpp) + (dstX * bpp);
+ copyRowWidth = dstWidth * bpp;
+ srcRowWidth = srcWidth * bpp;
+ for (int i = dstY; i < dstY + dstHeight; i++)
+ {
+ memcpy(pOutBuffer, pInBuffer, copyRowWidth);
+ pOutBuffer += copyRowWidth;
+ pInBuffer += srcRowWidth;
+ }
+ }
+ break;
+ case MEDIA_PIXEL_FORMAT_RGBA8888:
+ case MEDIA_PIXEL_FORMAT_BGRA8888:
+ {
+ bpp = 4;
+ // pInBuffer points to the start of the region to be copied to destination.
+ pInBuffer = const_cast<byte*>(srcBuf) + (dstY * srcWidth * bpp) + (dstX * bpp);
+ copyRowWidth = dstWidth * bpp; // BGRA and RGBA are 4 bytes each.
+ srcRowWidth = srcWidth * bpp;
+ for (int i = dstY; i < dstY + dstHeight; i++)
+ {
+ memcpy(pOutBuffer, pInBuffer, copyRowWidth);
+ pOutBuffer += copyRowWidth;
+ pInBuffer += srcRowWidth;
+ }
+ }
+ break;
+ case MEDIA_PIXEL_FORMAT_YUV444P:
+ {
+ bpp = 1;
+ // pInBuffer points to the start of the region to be copied to destination.
+ pInBuffer = const_cast<byte*>(srcBuf) + (dstY * srcWidth * bpp) + (dstX * bpp);
+ copyRowWidth = dstWidth * bpp;
+ srcRowWidth = srcWidth * bpp;
+ for (int i = dstY; i < dstY + dstHeight; i++)
+ {
+ memcpy(pOutBuffer, pInBuffer, copyRowWidth);
+ memcpy(pOutBuffer + (dstWidth * dstHeight), pInBuffer + (srcWidth * srcHeight), copyRowWidth);
+ memcpy(pOutBuffer + (2 * dstWidth * dstHeight), pInBuffer + (2 * srcWidth * srcHeight), copyRowWidth);
+ pOutBuffer += copyRowWidth;
+ pInBuffer += srcRowWidth;
+ }
+ }
+ break;
+ case MEDIA_PIXEL_FORMAT_YUYV422:
+ {
+ bpp = 2;
+ // pInBuffer points to the start of the region to be copied to destination.
+ pInBuffer = const_cast<byte*>(srcBuf) + (dstY * srcWidth * bpp) + (dstX * bpp);
+ copyRowWidth = dstWidth * bpp;
+ srcRowWidth = srcWidth * bpp;
+ for (int i = dstY; i < dstY + dstHeight; i++)
+ {
+ memcpy(pOutBuffer, pInBuffer, copyRowWidth);
+ pOutBuffer += copyRowWidth;
+ pInBuffer += srcRowWidth;
+ }
+ }
+ break;
+ case MEDIA_PIXEL_FORMAT_YUV420P:
+ {
+ bpp = 1;
+ // pInBuffer points to the start of the region to be copied to destination.
+ pInBuffer = const_cast<byte*>(srcBuf) + (dstY * srcWidth * bpp) + (dstX * bpp);
+ copyRowWidth = dstWidth * bpp;
+ srcRowWidth = srcWidth * bpp;
+ for (int i = dstY; i < dstY + dstHeight; i++)
+ {
+ memcpy(pOutBuffer, pInBuffer, copyRowWidth);
+ pOutBuffer += copyRowWidth;
+ pInBuffer += srcRowWidth;
+ }
- for (int i = dstY; i < dstY + dstHeight; i++)
- {
- memcpy(pOutBuffer, pInBuffer, copyRowWidth);
- pOutBuffer += copyRowWidth;
- pInBuffer += srcRowWidth;
+ pOutBuffer = dstBuf + (dstWidth * dstHeight);
+ pInBuffer = const_cast<byte*>(srcBuf) + (srcWidth * srcHeight) + (dstY/2 * srcWidth/2) + (dstX/2);
+ copyRowWidth /= 2;
+ srcRowWidth /= 2;
+ for (int i = 0; i < dstHeight/2; i++)
+ {
+ memcpy(pOutBuffer, pInBuffer, copyRowWidth);
+ memcpy(pOutBuffer + (dstWidth * dstHeight)/4, pInBuffer + (srcWidth * srcHeight)/4, copyRowWidth);
+ pOutBuffer += copyRowWidth;
+ pInBuffer += srcRowWidth;
+ }
+ }
+ break;
+ case MEDIA_PIXEL_FORMAT_NV12:
+ case MEDIA_PIXEL_FORMAT_NV21:
+ {
+ bpp = 1;
+ // pInBuffer points to the start of the region to be copied to destination.
+ pInBuffer = const_cast<byte*>(srcBuf) + (dstY * srcWidth * bpp) + (dstX * bpp);
+ copyRowWidth = dstWidth * bpp;
+ srcRowWidth = srcWidth * bpp;
+ for (int i = dstY; i < dstY + (dstHeight)/2; i++)
+ {
+ memcpy(pOutBuffer, pInBuffer, copyRowWidth);
+ memcpy(pOutBuffer + (dstWidth * dstHeight), pInBuffer + (srcWidth * srcHeight), copyRowWidth);
+ pOutBuffer += copyRowWidth;
+ pInBuffer += srcRowWidth;
+ }
+ for (int i = dstY + (dstHeight + 1)/2; i < dstY + dstHeight; i++)
+ {
+ memcpy(pOutBuffer, pInBuffer, copyRowWidth);
+ pOutBuffer += copyRowWidth;
+ pInBuffer += srcRowWidth;
+ }
+ }
+ break;
+ default:
+ r = E_UNSUPPORTED_FORMAT;
}
CATCH:
{ MEDIA_PIXEL_FORMAT_RGBA8888, {4, 1}},
{ MEDIA_PIXEL_FORMAT_BGRA8888, {4, 1}},
{ MEDIA_PIXEL_FORMAT_YUV420P, {3, 2}},
+ { MEDIA_PIXEL_FORMAT_GRAY, {1, 1}},
{ MEDIA_PIXEL_FORMAT_NV12, {3, 2}},
{ MEDIA_PIXEL_FORMAT_NV21, {3, 2}},
{ MEDIA_PIXEL_FORMAT_YUV444P, {3, 1}},
"Could not find details for pixelformat %d.", pixelFormat);
SetLastResult(E_SUCCESS);
+
return width * height * ret.num / ret.den;
CATCH:
MediaPixelFormat fmt[] = {
MEDIA_PIXEL_FORMAT_YUV420P,
MEDIA_PIXEL_FORMAT_NV12,
+ MEDIA_PIXEL_FORMAT_NV21,
MEDIA_PIXEL_FORMAT_YUYV422,
};