((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_YUV444P) || (x == MEDIA_PIXEL_FORMAT_YUYV422) \
- || (x == MEDIA_PIXEL_FORMAT_YUV420P) || (x == MEDIA_PIXEL_FORMAT_NV12) || (x == MEDIA_PIXEL_FORMAT_NV21))
+ || ( x == MEDIA_PIXEL_FORMAT_YUV444P) \
+ || (x == MEDIA_PIXEL_FORMAT_YUYV422) || (x == MEDIA_PIXEL_FORMAT_UYVY422) \
+ || (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())
}
/*
-* Input is assumed to be YUYV422
-* pDataIn => Input YUYV422 Buffer
+* Input is assumed to be either YUYV422 or UYVY422
+* pDataIn => Input YUYV422 or UYVY422 Buffer
* pDataOut => Output buffer, allocated by caller
* inWidth => Input Width
* inHeight => Input Height
_ImageUtil::ResizeYUYV422(const byte* pDataIn, byte* pDataOut, int inWidth, int inHeight, int outWidth, int outHeight)
{
- return ResizeRGB565(pDataIn, pDataOut, inWidth, inHeight, outWidth, outHeight);
+ return Resize8888(pDataIn, pDataOut, inWidth/2, inHeight, outWidth/2, outHeight);
}
/*
{
case MEDIA_PIXEL_FORMAT_RGBA8888:
+ // fall through
case MEDIA_PIXEL_FORMAT_BGRA8888:
{
r = Resize8888(pInBuf, pOutBuf, srcWidth, srcHeight, dstWidth, dstHeight);
break;
case MEDIA_PIXEL_FORMAT_YUYV422:
+ // fall through
+ case MEDIA_PIXEL_FORMAT_UYVY422:
{
r = ResizeYUYV422(pInBuf, pOutBuf, srcWidth, srcHeight, dstWidth, dstHeight);
}
break;
case MEDIA_PIXEL_FORMAT_NV12:
+ // fall through
case MEDIA_PIXEL_FORMAT_NV21:
{
r = ResizeNV12(pInBuf, pOutBuf, srcWidth, srcHeight, dstWidth, dstHeight);
outHeight = height;
}
- if (pixelFormat == MEDIA_PIXEL_FORMAT_GRAY)
+ switch(pixelFormat)
+ {
+ case MEDIA_PIXEL_FORMAT_GRAY:
{
int rowCount = 0;
int colCount = 0;
break;
}
}
- else if (pixelFormat == MEDIA_PIXEL_FORMAT_RGB888)
+ break;
+ case MEDIA_PIXEL_FORMAT_RGB888:
{
int rowCount = 0;
int colCount = 0;
for (colCount = 0; colCount < width / 2; colCount++)
{
- pTmpOutCol -= 2; // move to R bye of pixel
+ pTmpOutCol -= 2; // move to R byte of pixel
*pTmpOutCol++ = *pSrcBuf++; // copied R
*pTmpOutCol++ = *pSrcBuf++; // copied G
*pTmpOutCol = *pSrcBuf++; // copied B
pTmpOutCol -= 3; // move to next pixel to get copied
- pTmpOutCol -= 2; // move to R bye of pixel
+ pTmpOutCol -= 2; // move to R byte of pixel
*pTmpOutCol++ = *pSrcBuf++; // copied R
*pTmpOutCol++ = *pSrcBuf++; // copied G
*pTmpOutCol = *pSrcBuf++; // copied B
break;
}
}
- else if (pixelFormat == MEDIA_PIXEL_FORMAT_RGB565LE)
+ break;
+ case MEDIA_PIXEL_FORMAT_RGB565LE:
{
switch (rotate)
{
break;
}
}
- else if (pixelFormat == MEDIA_PIXEL_FORMAT_RGBA8888 || pixelFormat == MEDIA_PIXEL_FORMAT_BGRA8888)
+ break;
+ case MEDIA_PIXEL_FORMAT_RGBA8888:
+ // fall through
+ case MEDIA_PIXEL_FORMAT_BGRA8888:
{
switch (rotate)
{
break;
}
}
- else if (pixelFormat == MEDIA_PIXEL_FORMAT_YUV420P)
+ break;
+ case MEDIA_PIXEL_FORMAT_YUV420P:
{
int rowCount = 0;
int colCount = 0;
break;
}
}
- else if (pixelFormat == MEDIA_PIXEL_FORMAT_NV12
- || pixelFormat == MEDIA_PIXEL_FORMAT_NV21)
+ break;
+ case MEDIA_PIXEL_FORMAT_NV12:
+ // fall through
+ case MEDIA_PIXEL_FORMAT_NV21:
{
int rowCount = 0;
int colCount = 0;
break;
}
}
- else if (pixelFormat == MEDIA_PIXEL_FORMAT_YUV444P)
+ break;
+ case MEDIA_PIXEL_FORMAT_YUV444P:
{
int rowCount = 0;
int colCount = 0;
break;
}
}
- else if (pixelFormat == MEDIA_PIXEL_FORMAT_YUYV422)
+ break;
+ case MEDIA_PIXEL_FORMAT_YUYV422:
{
int rowCount = 0;
int colCount = 0;
- short* pSrcBuf = (short*)srcBuf;
- short* pDstBuf = (short*)dstBuf;
- short* pTmpOutCol = null;
+ byte* pSrcBuf = const_cast<byte*>(srcBuf);
+ byte* pDstBuf = dstBuf;
+ byte* pTmpOutCol = null;
+ byte* pTmpOut = null;
switch (rotate)
{
case IMAGE_ROTATION_90:
{
+ pTmpOutCol = pDstBuf + (outWidth * 2);
// Copying from all source rows to destination columns.
- for (rowCount = 0; rowCount < height; rowCount++)
+ for (rowCount = 0; rowCount < height; rowCount += 2)
{
// pTmpOutCol points to the top of the output column being filled.
- pTmpOutCol = pDstBuf + outWidth - 1 - rowCount;
+ pTmpOutCol -= 4;
+ pTmpOut = pTmpOutCol;
+ pSrcBuf = const_cast<byte*>(srcBuf) + (width * 2 * rowCount);
for (colCount = 0; colCount < width / 2 ; colCount++)
{
- *pTmpOutCol = *pSrcBuf++; // copied Y0 U0
- pTmpOutCol += outWidth;
-
- *pTmpOutCol = *pSrcBuf++; // copied Y1 V0
- pTmpOutCol += outWidth;
+ /*
+ y0 u0 y1 v1 y2 u2 y0 v1
+ ==>
+ y2 u2 y3 v3 y3 u2 y1 v1
+ */
+ pTmpOut[0] = pSrcBuf[(width * 2)]; // copied y2
+ pTmpOut[1] = pSrcBuf[(width * 2) + 1]; // copied u2
+ pTmpOut[2] = pSrcBuf[0]; // copied y0
+ pTmpOut[3] = pSrcBuf[3]; // copied v1
+ pTmpOut += outWidth * 2;
+
+ pTmpOut[0] = pSrcBuf[(width * 2) + 2]; // copied y3
+ pTmpOut[1] = pSrcBuf[(width * 2) + 1]; // copied u2
+ pTmpOut[2] = pSrcBuf[2]; // copied y1
+ pTmpOut[3] = pSrcBuf[3]; // copied v1
+ pTmpOut += outWidth * 2;
+
+ pSrcBuf += 4;
}
}
}
break;
case IMAGE_ROTATION_180:
{
- // Copying all source rows to destination columns.
+ // Copying all source rows to destination rows in reverse.
+ // pTmpOut points to the end of last row: u0y1 v1y0
+ pTmpOut = pDstBuf + (outWidth * outHeight * 2) - 4;
for (rowCount = 0; rowCount < height; rowCount++)
{
+ for (colCount = 0; colCount < width / 2; colCount++)
+ {
+ /*
+ y0 u0 y1 v1 => y1 u1 y0 v0
+ */
+ pTmpOut[0] = pSrcBuf[2]; // copied y1
+ pTmpOut[1] = pSrcBuf[1]; // copied u0
+ pTmpOut[2] = pSrcBuf[0]; // copied y0
+ pTmpOut[3] = pSrcBuf[3]; // copied v1
+ pSrcBuf += 4;
+ pTmpOut -= 4;
+ }
+ }
+ }
+ break;
+ case IMAGE_ROTATION_270:
+ {
+ // Copying all source rows to destination columns.
+ pTmpOutCol = pDstBuf + (outWidth * (outHeight - 1) * 2);
+ for (rowCount = 0; rowCount < height; rowCount += 2)
+ {
+ pTmpOut = pTmpOutCol;
+ pSrcBuf = const_cast<byte*>(srcBuf) + (width * 2 * rowCount);
// pTmpOutCol points to the bottom of the column being filled.
- pTmpOutCol = pDstBuf + ((outWidth * outHeight ) - 1) - (rowCount * outWidth);
+ for (colCount = 0; colCount < width / 2; colCount++)
+ {
+ /*
+ y0 u0 y1 v1 y1 u0 y3 v3
+ ==>
+ y2 u2 y3 v3 y0 u0 y2 v3
+ */
+ pTmpOut[0] = pSrcBuf[0]; // copied y0
+ pTmpOut[1] = pSrcBuf[1]; // copied u0
+ pTmpOut[2] = pSrcBuf[(width * 2) + 2]; // copied y3
+ pTmpOut[3] = pSrcBuf[(width * 2) + 3]; // copied v3
+ pTmpOut -= outWidth * 2;
+
+ pTmpOut[0] = pSrcBuf[2]; // copied y1
+ pTmpOut[1] = pSrcBuf[1]; // copied u0
+ pTmpOut[2] = pSrcBuf[(width * 2)]; // copied y2
+ pTmpOut[3] = pSrcBuf[(width * 2) + 3]; // copied v3
+ pTmpOut -= outWidth * 2;
+
+ pSrcBuf += 4;
+
+ }
+ pTmpOutCol += 4;
+ }
+ }
+ break;
+ default:
+ break;
+ }
+ }
+ break;
+
+ case MEDIA_PIXEL_FORMAT_UYVY422:
+ {
+ int rowCount = 0;
+ int colCount = 0;
+ byte* pSrcBuf = const_cast<byte*>(srcBuf);
+ byte* pDstBuf = dstBuf;
+ byte* pTmpOutCol = null;
+ byte* pTmpOut = null;
+ switch (rotate)
+ {
+ case IMAGE_ROTATION_90:
+ {
+ pTmpOutCol = pDstBuf + (outWidth * 2);
+ // Copying from all source rows to destination columns.
+ for (rowCount = 0; rowCount < height; rowCount += 2)
+ {
+ // pTmpOutCol points to the top of the output column being filled.
+ pTmpOutCol -= 4;
+ pTmpOut = pTmpOutCol;
+ pSrcBuf = const_cast<byte*>(srcBuf) + (width * 2 * rowCount);
+ for (colCount = 0; colCount < width / 2 ; colCount++)
+ {
+ /*
+ u0 y0 v1 y1 u2 y2 v1 y0
+ ==>
+ u2 y2 v3 y3 u2 y3 v1 y1
+ */
+
+ pTmpOut[0] = pSrcBuf[(width * 2)]; // copied u2
+ pTmpOut[1] = pSrcBuf[(width * 2) + 1]; // copied y2
+ pTmpOut[2] = pSrcBuf[2]; // copied v1
+ pTmpOut[3] = pSrcBuf[1]; // copied y0
+ pTmpOut += outWidth * 2;
+
+ pTmpOut[0] = pSrcBuf[(width * 2)]; // copied u2
+ pTmpOut[1] = pSrcBuf[(width * 2) + 3]; // copied y3
+ pTmpOut[2] = pSrcBuf[2]; // copied v1
+ pTmpOut[3] = pSrcBuf[3]; // copied y1
+ pTmpOut += outWidth * 2;
+
+ pSrcBuf += 4;
+ }
+ }
+ }
+ break;
+ case IMAGE_ROTATION_180:
+ {
+ // Copying all source rows to destination rows in reverse.
+ // pTmpOut points to the end of last row: u0y1 v1y0
+ pTmpOut = pDstBuf + (outWidth * outHeight * 2) - 4;
+ for (rowCount = 0; rowCount < height; rowCount++)
+ {
for (colCount = 0; colCount < width / 2; colCount++)
{
- *pTmpOutCol-- = *pSrcBuf++; // copied Y0 U0
- *pTmpOutCol-- = *pSrcBuf++; // copied Y1 V0
+ /*
+ u0 y0 v1 y1 => u0 y1 v1 y0
+ */
+ pTmpOut[0] = pSrcBuf[0]; // copied u0
+ pTmpOut[1] = pSrcBuf[3]; // copied y1
+ pTmpOut[2] = pSrcBuf[2]; // copied v1
+ pTmpOut[3] = pSrcBuf[1]; // copied y0
+ pSrcBuf += 4;
+ pTmpOut -= 4;
}
}
}
case IMAGE_ROTATION_270:
{
// Copying all source rows to destination columns.
- for (rowCount = 0; rowCount < height; rowCount++)
+ pTmpOutCol = pDstBuf + (outWidth * (outHeight - 1) * 2);
+ for (rowCount = 0; rowCount < height; rowCount += 2)
{
+ pTmpOut = pTmpOutCol;
+ pSrcBuf = const_cast<byte*>(srcBuf) + (width * 2 * rowCount);
// pTmpOutCol points to the bottom of the column being filled.
- pTmpOutCol = pDstBuf + (outWidth * (outHeight - 1)) + rowCount;
for (colCount = 0; colCount < width / 2; colCount++)
{
- *pTmpOutCol = *pSrcBuf++; // copied B
- pTmpOutCol -= outWidth;
+ /*
+ u0 y0 v1 y1 u0 y1 v3 y3
+ ==>
+ u2 y2 v3 y3 u0 y0 v3 y2
+ */
+
+ pTmpOut[0] = pSrcBuf[0]; // copied u0
+ pTmpOut[1] = pSrcBuf[1]; // copied y0
+ pTmpOut[2] = pSrcBuf[(width * 2) + 2]; // copied v3
+ pTmpOut[3] = pSrcBuf[(width * 2) + 1]; // copied y2
+ pTmpOut -= outWidth * 2;
+
+ pTmpOut[0] = pSrcBuf[0]; // copied u0
+ pTmpOut[1] = pSrcBuf[3]; // copied y1
+ pTmpOut[2] = pSrcBuf[(width * 2) + 2]; // copied v3
+ pTmpOut[3] = pSrcBuf[(width * 2) + 3]; // copied y3
+ pTmpOut -= outWidth * 2;
+
+ pSrcBuf += 4;
- *pTmpOutCol = *pSrcBuf++; // copied B
- pTmpOutCol -= outWidth;
}
+ pTmpOutCol += 4;
}
}
break;
break;
}
}
- else
+ break;
+ default:
{
#ifdef USE_MM_UTIL
"[E_SYSTEM] util_transform failed: %0x", ret);
#endif
}
+ break;
+ }
return r;
outWidth = width;
outHeight = height;
- if (pixelFormat == MEDIA_PIXEL_FORMAT_GRAY)
- {
- if (flip == IMAGE_FLIP_HORIZONTAL)
- {
+ switch (pixelFormat)
+ {
+ case MEDIA_PIXEL_FORMAT_GRAY:
+ {
+ if (flip == IMAGE_FLIP_HORIZONTAL)
+ {
int rowCount = 0;
int colCount = 0;
- byte* pSrcBuf = (byte *)srcBuf;
- byte* pDstBuf = (byte *)dstBuf;
- // pTmpOutRow points to last column of first row of destination.
- byte* pTmpOutRow = pDstBuf + width - 1;
-
- for (rowCount = 0; rowCount < height; rowCount++)
- {
- for (colCount = 0; colCount < width; colCount++)
- {
- *pTmpOutRow-- = *pSrcBuf++; // copy source row in reverse to destination.
- }
- pTmpOutRow += (2 * outWidth);
- }
+ byte* pSrcBuf = (byte *)srcBuf;
+ byte* pDstBuf = (byte *)dstBuf;
+ // pTmpOutRow points to last column of first row of destination.
+ byte* pTmpOutRow = pDstBuf + width - 1;
+
+ for (rowCount = 0; rowCount < height; rowCount++)
+ {
+ for (colCount = 0; colCount < width; colCount++)
+ {
+ *pTmpOutRow-- = *pSrcBuf++; // copy source row in reverse to destination.
+ }
+ pTmpOutRow += (2 * outWidth);
+ }
}
else
{
int rowCount = 0;
- byte* pSrcBuf = (byte *)srcBuf;
- byte* pDstBuf = (byte *)dstBuf;
- // pTmpOutRow points to the start of last row in destination buffer.
- byte* pTmpOutRow = pDstBuf + (width * (height - 1));
-
- for (rowCount = 0; rowCount < height; rowCount++)
- {
- // copy one row worth of data.
- memcpy(pTmpOutRow, pSrcBuf, sizeof(byte) * width);
- pTmpOutRow -= width; // go to one higher row.
- pSrcBuf += width; // go to next row.
- }
+ byte* pSrcBuf = (byte *)srcBuf;
+ byte* pDstBuf = (byte *)dstBuf;
+ // pTmpOutRow points to the start of last row in destination buffer.
+ byte* pTmpOutRow = pDstBuf + (width * (height - 1));
+ for (rowCount = 0; rowCount < height; rowCount++)
+ {
+ // copy one row worth of data.
+ memcpy(pTmpOutRow, pSrcBuf, sizeof(byte) * width);
+ pTmpOutRow -= width; // go to one higher row.
+ pSrcBuf += width; // go to next row.
+ }
}
}
- else if (pixelFormat == MEDIA_PIXEL_FORMAT_RGB565LE)
+ break;
+ case MEDIA_PIXEL_FORMAT_RGB565LE:
{
if (flip == IMAGE_FLIP_HORIZONTAL)
{
}
}
}
- else if (pixelFormat == MEDIA_PIXEL_FORMAT_RGB888)
- {
- if (flip == IMAGE_FLIP_HORIZONTAL)
- {
+ break;
+ case MEDIA_PIXEL_FORMAT_RGB888:
+ {
+ if (flip == IMAGE_FLIP_HORIZONTAL)
+ {
int rowCount = 0;
- int colCount = 0;
- byte* pSrcBuf = (byte *)srcBuf;
- byte* pDstBuf = (byte *)dstBuf;
- // pTmpOutRow points to last column of first row of destination.
- byte* pTmpOutRow = NULL;// pDstBuf + width * 3;
-
- for (rowCount = 0; rowCount < height; rowCount++)
- {
+ int colCount = 0;
+ byte* pSrcBuf = (byte *)srcBuf;
+ byte* pDstBuf = (byte *)dstBuf;
+ // pTmpOutRow points to last column of first row of destination.
+ byte* pTmpOutRow = NULL;// pDstBuf + width * 3;
+
+ for (rowCount = 0; rowCount < height; rowCount++)
+ {
pTmpOutRow = pDstBuf + (rowCount + 1) * width * 3 - 3;
- for (colCount = 0; colCount < width; colCount++)
- {
- *pTmpOutRow++ = *pSrcBuf++; // copy source row in reverse to destination.
- *pTmpOutRow++ = *pSrcBuf++; // copy source row in reverse to destination.
- *pTmpOutRow = *pSrcBuf++; // copy source row in reverse to destination.
+ for (colCount = 0; colCount < width; colCount++)
+ {
+ *pTmpOutRow++ = *pSrcBuf++; // copy source row in reverse to destination.
+ *pTmpOutRow++ = *pSrcBuf++; // copy source row in reverse to destination.
+ *pTmpOutRow = *pSrcBuf++; // copy source row in reverse to destination.
pTmpOutRow -= 5;
- }
- }
- }
- else
- {
- int rowCount = 0;
- byte* pSrcBuf = (byte *)srcBuf;
- byte* pDstBuf = (byte *)dstBuf;
- // pTmpOutRow points to the start of last row in destination buffer.
- byte* pTmpOutRow = pDstBuf + (width * 3 * (height - 1));
-
- for (rowCount = 0; rowCount < height; rowCount++)
- {
- // copy one row worth of data.
- memcpy(pTmpOutRow, pSrcBuf, sizeof(byte) * 3 * width);
- pTmpOutRow -= width*3; // go to one higher row.
- pSrcBuf += width*3; // go to next row.
- }
- }
- }
- else if (pixelFormat == MEDIA_PIXEL_FORMAT_RGBA8888 || pixelFormat == MEDIA_PIXEL_FORMAT_BGRA8888)
+ }
+ }
+ }
+ else
+ {
+ int rowCount = 0;
+ byte* pSrcBuf = (byte *)srcBuf;
+ byte* pDstBuf = (byte *)dstBuf;
+ // pTmpOutRow points to the start of last row in destination buffer.
+ byte* pTmpOutRow = pDstBuf + (width * 3 * (height - 1));
+
+ for (rowCount = 0; rowCount < height; rowCount++)
+ {
+ // copy one row worth of data.
+ memcpy(pTmpOutRow, pSrcBuf, sizeof(byte) * 3 * width);
+ pTmpOutRow -= width*3; // go to one higher row.
+ pSrcBuf += width*3; // go to next row.
+ }
+ }
+ }
+ break;
+ case MEDIA_PIXEL_FORMAT_RGBA8888:
+ // fall through
+ case MEDIA_PIXEL_FORMAT_BGRA8888:
{
if (flip == IMAGE_FLIP_HORIZONTAL)
- {
- int rowCount = 0;
- int colCount = 0;
- unsigned int* pSrcBuf = (unsigned int *)srcBuf;
- unsigned int* pDstBuf = (unsigned int *)dstBuf;
- // pTmpOutRow points to last column of first row of destination.
- unsigned int* pTmpOutRow = pDstBuf + width - 1;
-
- for (rowCount = 0; rowCount < height; rowCount++)
- {
- for (colCount = 0; colCount < width; colCount++)
- {
- *pTmpOutRow-- = *pSrcBuf++; // copy source row in reverse to destination.
- }
- pTmpOutRow += (2 * outWidth);
- }
- }
- else
- {
- int rowCount = 0;
- unsigned int* pSrcBuf = (unsigned int *)srcBuf;
- unsigned int* pDstBuf = (unsigned int *)dstBuf;
- // pTmpOutRow points to the start of last row in destination buffer.
- unsigned int* pTmpOutRow = pDstBuf + (width * (height - 1));
-
- for (rowCount = 0; rowCount < height; rowCount++)
- {
- // copy one row worth of data.
- memcpy(pTmpOutRow, pSrcBuf, sizeof(unsigned int) * width);
- pTmpOutRow -= width; // go to one higher row.
- pSrcBuf += width; // go to next row.
- }
- }
- }
- else if (pixelFormat == MEDIA_PIXEL_FORMAT_YUV420P)
- {
- byte* pDstY = (byte *)dstBuf;
- byte* pDstU = pDstY + width * height;
- byte* pDstV = pDstU + (width / 2) * (height / 2);
-
- byte* pSrcY = (byte *) srcBuf;
- byte* pSrcU = pSrcY + width * height;
- byte* pSrcV = pSrcU + (width /2) * ( height / 2);
- byte* pTmpOutY = null;
- byte* pTmpOutU = null;
- byte* pTmpOutV = null;
+ {
+ int rowCount = 0;
+ int colCount = 0;
+ unsigned int* pSrcBuf = (unsigned int *)srcBuf;
+ unsigned int* pDstBuf = (unsigned int *)dstBuf;
+ // pTmpOutRow points to last column of first row of destination.
+ unsigned int* pTmpOutRow = pDstBuf + width - 1;
+
+ for (rowCount = 0; rowCount < height; rowCount++)
+ {
+ for (colCount = 0; colCount < width; colCount++)
+ {
+ *pTmpOutRow-- = *pSrcBuf++; // copy source row in reverse to destination.
+ }
+ pTmpOutRow += (2 * outWidth);
+ }
+ }
+ else
+ {
+ int rowCount = 0;
+ unsigned int* pSrcBuf = (unsigned int *)srcBuf;
+ unsigned int* pDstBuf = (unsigned int *)dstBuf;
+ // pTmpOutRow points to the start of last row in destination buffer.
+ unsigned int* pTmpOutRow = pDstBuf + (width * (height - 1));
+
+ for (rowCount = 0; rowCount < height; rowCount++)
+ {
+ // copy one row worth of data.
+ memcpy(pTmpOutRow, pSrcBuf, sizeof(unsigned int) * width);
+ pTmpOutRow -= width; // go to one higher row.
+ pSrcBuf += width; // go to next row.
+ }
+ }
+ }
+ break;
+ case MEDIA_PIXEL_FORMAT_YUV420P:
+ {
+ byte* pDstY = (byte *)dstBuf;
+ byte* pDstU = pDstY + width * height;
+ byte* pDstV = pDstU + (width / 2) * (height / 2);
+
+ byte* pSrcY = (byte *) srcBuf;
+ byte* pSrcU = pSrcY + width * height;
+ byte* pSrcV = pSrcU + (width / 2) * ( height / 2);
+ byte* pTmpOutY = null;
+ byte* pTmpOutU = null;
+ byte* pTmpOutV = null;
if (flip == IMAGE_FLIP_HORIZONTAL)
- {
- SysLog(NID_MEDIA,"$$$ MEDIA_PIXEL_FORMAT_YUV420 Flip: horizontal");
- int rowCount = 0;
- int colCount = 0;
- // pTmpOutRow points to last column of first row of destination.
- pTmpOutY = pDstY + width - 1;
- pTmpOutU = pDstU + width / 2 - 1;
- pTmpOutV = pDstV + width / 2 - 1;
-
- for (rowCount = 0; rowCount < height ; rowCount++)
- {
- for (colCount = 0; colCount < width; colCount++)
- {
- *pTmpOutY-- = *pSrcY++; // copy source row in reverse to destination.
- }
- pTmpOutY += (2 * width);
- }
- for (rowCount = 0; rowCount < height/2 ; rowCount++)
- {
- for (colCount = 0; colCount < width/2; colCount++)
- {
- *pTmpOutU-- = *pSrcU++; // copy source row in reverse to destination.
- *pTmpOutV-- = *pSrcV++; // copy source row in reverse to destination.
- }
- pTmpOutU += (width);
- pTmpOutV += (width);
- }
- }
- else
- {
+ {
int rowCount = 0;
- // pTmpOutRow points to last column of first row of destination.
- pTmpOutY = pDstY + (height - 1) * width;
- pTmpOutU = pDstU + (height / 2 - 1) * width / 2;
- pTmpOutV = pDstV + (height / 2 - 1) * width / 2;
+ int colCount = 0;
+ // pTmpOut* points to last column of first row of destination.
+ pTmpOutY = pDstY + width - 1;
+ pTmpOutU = pDstU + width / 2 - 1;
+ pTmpOutV = pDstV + width / 2 - 1;
- for (rowCount = 0; rowCount < height / 2; rowCount++)
- {
+ for (rowCount = 0; rowCount < height ; rowCount++)
+ {
+ for (colCount = 0; colCount < width; colCount++)
+ {
+ *pTmpOutY-- = *pSrcY++; // copy source row in reverse to destination.
+ }
+ pTmpOutY += (2 * width);
+ }
+ for (rowCount = 0; rowCount < height/2 ; rowCount++)
+ {
+ for (colCount = 0; colCount < width/2; colCount++)
+ {
+ *pTmpOutU-- = *pSrcU++; // copy source row in reverse to destination.
+ *pTmpOutV-- = *pSrcV++; // copy source row in reverse to destination.
+ }
+ pTmpOutU += (width);
+ pTmpOutV += (width);
+ }
+ }
+ else
+ {
+ int rowCount = 0;
+ // pTmpOut* points to last column of first row of destination.
+ pTmpOutY = pDstY + (height - 1) * width;
+ pTmpOutU = pDstU + (height / 2 - 1) * width / 2;
+ pTmpOutV = pDstV + (height / 2 - 1) * width / 2;
+
+ for (rowCount = 0; rowCount < height / 2; rowCount++)
+ {
memcpy(pTmpOutY, pSrcY, sizeof(byte) * width);
memcpy(pTmpOutU, pSrcU, sizeof(byte) * width / 2 );
memcpy(pTmpOutV, pSrcV, sizeof(byte) * width / 2 );
- pTmpOutY -= width;
+ pTmpOutY -= width;
pSrcY += width;
- pTmpOutU -= (width / 2);
+ pTmpOutU -= (width / 2);
pSrcU += (width / 2);
- pTmpOutV -= (width / 2);
+ pTmpOutV -= (width / 2);
pSrcV += (width / 2);
- }
- for (rowCount = height / 2; rowCount < height; rowCount++)
- {
+ }
+ for (rowCount = height / 2; rowCount < height; rowCount++)
+ {
memcpy(pTmpOutY, pSrcY, sizeof(byte) * width);
- pTmpOutY -= width;
+ pTmpOutY -= width;
pSrcY += width;
- }
- }
- }
- else if (pixelFormat == MEDIA_PIXEL_FORMAT_NV12
- || pixelFormat == MEDIA_PIXEL_FORMAT_NV21)
- {
- byte* pDstY = (byte *)dstBuf;
- short* pDstUV = (short* )(pDstY + width * height);
-
- byte* pSrcY = (byte* ) srcBuf;
- short* pSrcUV = (short* )(pSrcY + width * height);
- byte* pTmpOutY = null;
- short* pTmpOutUV = null;
+ }
+ }
+ }
+ break;
+ case MEDIA_PIXEL_FORMAT_NV12:
+ // fall through
+ case MEDIA_PIXEL_FORMAT_NV21:
+ {
+ byte* pDstY = (byte *)dstBuf;
+ short* pDstUV = (short* )(pDstY + width * height);
+
+ byte* pSrcY = (byte* ) srcBuf;
+ short* pSrcUV = (short* )(pSrcY + width * height);
+
+ byte* pTmpOutY = null;
+ short* pTmpOutUV = null;
+
if (flip == IMAGE_FLIP_HORIZONTAL)
- {
- int rowCount = 0;
- int colCount = 0;
- // pTmpOutRow points to last column of first row of destination.
- pTmpOutY = pDstY + width - 1;
- pTmpOutUV = pDstUV + width / 2 - 1;
-
- for (rowCount = 0; rowCount < height / 2; rowCount++)
- {
- for (colCount = 0; colCount < width / 2; colCount++)
- {
- *pTmpOutY-- = *pSrcY++; // copy source row in reverse to destination.
- *pTmpOutUV-- = *pSrcUV++; // copy source row in reverse to destination.
- }
- for (colCount = width / 2; colCount < width; colCount++)
- {
- *pTmpOutY-- = *pSrcY++;
- }
- pTmpOutY += (2 * width);
- pTmpOutUV += (width);
- }
- for (rowCount = height / 2; rowCount < height; rowCount++)
- {
- for (colCount = 0; colCount < width; colCount++)
- {
- *pTmpOutY-- = *pSrcY++;
- }
- pTmpOutY += (2 * width);
- }
- }
+ {
+ int rowCount = 0;
+ int colCount = 0;
+ // pTmpOut* points to last column of first row of destination.
+ pTmpOutY = pDstY + width - 1;
+ pTmpOutUV = pDstUV + width / 2 - 1;
+
+ for (rowCount = 0; rowCount < height / 2; rowCount++)
+ {
+ for (colCount = 0; colCount < width / 2; colCount++)
+ {
+ *pTmpOutY-- = *pSrcY++; // copy source row in reverse to destination.
+ *pTmpOutUV-- = *pSrcUV++; // copy source row in reverse to destination.
+ }
+ for (colCount = width / 2; colCount < width; colCount++)
+ {
+ *pTmpOutY-- = *pSrcY++;
+ }
+ pTmpOutY += (2 * width);
+ pTmpOutUV += (width);
+ }
+ for (rowCount = height / 2; rowCount < height; rowCount++)
+ {
+ for (colCount = 0; colCount < width; colCount++)
+ {
+ *pTmpOutY-- = *pSrcY++;
+ }
+ pTmpOutY += (2 * width);
+ }
+ }
else
- {
- int rowCount = 0;
- // pTmpOutRow points to last column of first row of destination.
- pTmpOutY = pDstY + (height - 1) * width;
- pTmpOutUV = pDstUV + (height / 2 - 1) * width / 2;
-
- for (rowCount = 0; rowCount < height / 2; rowCount++)
- {
- memcpy(pTmpOutY, pSrcY, sizeof(byte) * width);
- memcpy(pTmpOutUV, pSrcUV, sizeof(short) * width / 2 );
-
- pTmpOutY -= width;
- pSrcY += width;
+ {
+ int rowCount = 0;
+ // pTmpOut* points to last column of first row of destination.
+ pTmpOutY = pDstY + (height - 1) * width;
+ pTmpOutUV = pDstUV + (height / 2 - 1) * width / 2;
+
+ for (rowCount = 0; rowCount < height / 2; rowCount++)
+ {
+ memcpy(pTmpOutY, pSrcY, sizeof(byte) * width);
+ memcpy(pTmpOutUV, pSrcUV, sizeof(short) * width / 2 );
+
+ pTmpOutY -= width;
+ pSrcY += width;
pTmpOutUV -= width / 2;
pSrcUV += width / 2;
- }
- for (rowCount = height / 2; rowCount < height; rowCount++)
- {
- memcpy(pTmpOutY, pSrcY, sizeof(byte) * width);
- pTmpOutY -= width;
+ }
+ for (rowCount = height / 2; rowCount < height; rowCount++)
+ {
+ memcpy(pTmpOutY, pSrcY, sizeof(byte) * width);
+ pTmpOutY -= width;
pSrcY += width;
- }
- }
- }
- else if (pixelFormat == MEDIA_PIXEL_FORMAT_YUV444P)
- {
- byte* pDstY = (byte *)dstBuf;
- byte* pDstU = pDstY + width * height;
- byte* pDstV = pDstU + width * height;
-
- byte* pSrcY = (byte *) srcBuf;
- byte* pSrcU = pSrcY + width * height;
- byte* pSrcV = pSrcU + width * height;
- byte* pTmpOutY = null;
- byte* pTmpOutU = null;
- byte* pTmpOutV = null;
+ }
+ }
+ }
+ break;
+ case MEDIA_PIXEL_FORMAT_YUV444P:
+ {
+ byte* pDstY = (byte *)dstBuf;
+ byte* pDstU = pDstY + width * height;
+ byte* pDstV = pDstU + width * height;
+
+ byte* pSrcY = (byte *) srcBuf;
+ byte* pSrcU = pSrcY + width * height;
+ byte* pSrcV = pSrcU + width * height;
+ byte* pTmpOutY = null;
+ byte* pTmpOutU = null;
+ byte* pTmpOutV = null;
if (flip == IMAGE_FLIP_HORIZONTAL)
- {
- int rowCount = 0;
- int colCount = 0;
- // pTmpOutRow points to last column of first row of destination.
- pTmpOutY = pDstY + width - 1;
- pTmpOutU = pDstU + width - 1;
- pTmpOutV = pDstV + width - 1;
-
- for (rowCount = 0; rowCount < height; rowCount++)
- {
- for (colCount = 0; colCount < width ; colCount++)
- {
- *pTmpOutY-- = *pSrcY++; // copy source row in reverse to destination.
- *pTmpOutU-- = *pSrcU++; // copy source row in reverse to destination.
- *pTmpOutV-- = *pSrcV++; // copy source row in reverse to destination.
- }
- pTmpOutY += (2 * width);
- pTmpOutU += (2 * width);
- pTmpOutV += (2 * width);
- }
- }
+ {
+ int rowCount = 0;
+ int colCount = 0;
+ // pTmpOut* points to last column of first row of destination.
+ pTmpOutY = pDstY + width - 1;
+ pTmpOutU = pDstU + width - 1;
+ pTmpOutV = pDstV + width - 1;
+
+ for (rowCount = 0; rowCount < height; rowCount++)
+ {
+ for (colCount = 0; colCount < width ; colCount++)
+ {
+ *pTmpOutY-- = *pSrcY++; // copy source row in reverse to destination.
+ *pTmpOutU-- = *pSrcU++; // copy source row in reverse to destination.
+ *pTmpOutV-- = *pSrcV++; // copy source row in reverse to destination.
+ }
+ pTmpOutY += (2 * width);
+ pTmpOutU += (2 * width);
+ pTmpOutV += (2 * width);
+ }
+ }
else
- {
- int rowCount = 0;
- // pTmpOutRow points to last column of first row of destination.
- pTmpOutY = pDstY + (height - 1) * width;
- pTmpOutU = pDstU + (height - 1) * width;
- pTmpOutV = pDstV + (height - 1) * width;
-
- for (rowCount = 0; rowCount < height; rowCount++)
- {
- memcpy(pTmpOutY, pSrcY, sizeof(byte) * width);
- memcpy(pTmpOutU, pSrcU, sizeof(byte) * width);
- memcpy(pTmpOutV, pSrcV, sizeof(byte) * width);
-
- pTmpOutY -= width;
+ {
+ int rowCount = 0;
+ // pTmpOut* points to last column of first row of destination.
+ pTmpOutY = pDstY + (height - 1) * width;
+ pTmpOutU = pDstU + (height - 1) * width;
+ pTmpOutV = pDstV + (height - 1) * width;
+
+ for (rowCount = 0; rowCount < height; rowCount++)
+ {
+ memcpy(pTmpOutY, pSrcY, sizeof(byte) * width);
+ memcpy(pTmpOutU, pSrcU, sizeof(byte) * width);
+ memcpy(pTmpOutV, pSrcV, sizeof(byte) * width);
+
+ pTmpOutY -= width;
pSrcY += width;
- pTmpOutU -= width;
+ pTmpOutU -= width;
pSrcU += width;
- pTmpOutV -= width;
+ pTmpOutV -= width;
pSrcV += width;
- }
- }
+ }
+ }
}
- else if (pixelFormat == MEDIA_PIXEL_FORMAT_YUYV422)
- {
- short* pSrcBuf = (short*)srcBuf;
- short* pDstBuf = (short*)dstBuf;
- short* pTmpOut = null;
+ break;
+ case MEDIA_PIXEL_FORMAT_YUYV422:
+ // fall through
+ case MEDIA_PIXEL_FORMAT_UYVY422:
+ {
+ byte* pSrcBuf = const_cast<byte*>(srcBuf);
+ byte* pDstBuf = dstBuf;
+ byte* pTmpOut = null;
if (flip == IMAGE_FLIP_HORIZONTAL)
- {
- int rowCount = 0;
- int colCount = 0;
- // pTmpOutRow points to last column of first row of destination.
- pTmpOut = pDstBuf + width - 1;
-
- for (rowCount = 0; rowCount < height; rowCount++)
- {
- for (colCount = 0; colCount < width / 2; colCount++)
- {
- *pTmpOut-- = *pSrcBuf++; // copied YO U0.
- *pTmpOut-- = *pSrcBuf++; // copied Y1 U1
- }
- pTmpOut += 2 * width;
- }
- }
+ {
+ int rowCount = 0;
+ int colCount = 0;
+ // pTmpOut points to last column of first row of destination.
+ pTmpOut = pDstBuf + (width * 2) - 4;
+
+ for (rowCount = 0; rowCount < height; rowCount++)
+ {
+ for (colCount = 0; colCount < width / 2; colCount++)
+ {
+ pTmpOut[0] = pSrcBuf[0]; // u0
+ pTmpOut[1] = pSrcBuf[3]; // y1
+ pTmpOut[2] = pSrcBuf[2]; // v1
+ pTmpOut[3] = pSrcBuf[1]; // y0
+
+ pTmpOut -= 4;
+ pSrcBuf += 4;
+ }
+ pTmpOut += 4 * width;
+ }
+ }
else
- {
- int rowCount = 0;
- // pTmpOutRow points to last column of first row of destination.
- pTmpOut = pDstBuf + (height - 1) * (width);
-
- for (rowCount = 0; rowCount < height; rowCount++)
- {
- memcpy(pTmpOut, pSrcBuf, sizeof(short) * width);
- pTmpOut -= width;
- pSrcBuf += width;
- }
- }
+ {
+ int rowCount = 0;
+ // pTmpOut points to last column of first row of destination.
+ pTmpOut = pDstBuf + ((height - 1) * width * 2);
+
+ for (rowCount = 0; rowCount < height; rowCount++)
+ {
+ memcpy(pTmpOut, pSrcBuf, 2 * width);
+ pTmpOut -= width * 2;
+ pSrcBuf += width * 2;
+ }
+ }
}
- else
+ break;
+ default:
{
#ifdef USE_MM_UTIL
"util_transform failed with error code: %0x", ret);
#endif
}
+ }
CATCH:
return r;
outHeight = height;
}
- return RotateBuffer((byte *)srcBuf.GetPointer(), pixelFormat, width, height,
+ return RotateBuffer((byte *)srcBuf.GetPointer(), pixelFormat, width, height,
(byte *)dstBuf.GetPointer(), outWidth, outHeight, rotate);
CATCH:
return r;
break;
}
}
- if ((fmt == IMG_FORMAT_WBMP) && (pBuf[2] == 1 || pBuf[2] == 2) && pBuf[3] == 0 )
+ if ((fmt == IMG_FORMAT_WBMP) && (pBuf[2] == 0 || pBuf[2] == 1 || pBuf[2] == 2) && pBuf[3] == 0 )
{
fmt = IMG_FORMAT_NONE;
}
{
result r = E_SUCCESS;
- r = CropBuffer(srcBuf.GetPointer(), pixelFormat, srcWidth, srcHeight,
+ 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 = E_INVALID_ARG, E_INVALID_ARG,
"[E_INVALID_ARG] Dimensions should be even (%d x %d).", dstWidth, dstHeight);
+ SysTryCatch(NID_MEDIA, IsValidCoordinate(pixelFormat, dstX, dstY),
+ r = E_INVALID_ARG, E_INVALID_ARG,
+ "[E_INVALID_ARG] Source location must be even (%d, %d).", dstX, dstY);
+
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);
}
break;
case MEDIA_PIXEL_FORMAT_RGB888:
+ // fall through
case MEDIA_PIXEL_FORMAT_BGR888:
{
bpp = 3;
}
break;
case MEDIA_PIXEL_FORMAT_RGBA8888:
+ // fall through
case MEDIA_PIXEL_FORMAT_BGRA8888:
{
bpp = 4;
}
break;
case MEDIA_PIXEL_FORMAT_YUYV422:
+ // fall through
+ case MEDIA_PIXEL_FORMAT_UYVY422:
{
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++)
+ if ((dstX % 2) == 0)
{
- memcpy(pOutBuffer, pInBuffer, copyRowWidth);
- pOutBuffer += copyRowWidth;
- pInBuffer += srcRowWidth;
+ for (int i = dstY; i < dstY + dstHeight; i++)
+ {
+ memcpy(pOutBuffer, pInBuffer, copyRowWidth);
+ pOutBuffer += copyRowWidth;
+ pInBuffer += srcRowWidth;
+ }
}
}
break;
}
break;
case MEDIA_PIXEL_FORMAT_NV12:
+ // fall through
case MEDIA_PIXEL_FORMAT_NV21:
{
bpp = 1;
{ MEDIA_PIXEL_FORMAT_NV21, {3, 2}},
{ MEDIA_PIXEL_FORMAT_YUV444P, {3, 1}},
{ MEDIA_PIXEL_FORMAT_YUYV422, {2, 1}},
+ { MEDIA_PIXEL_FORMAT_UYVY422, {2, 1}},
{ MEDIA_PIXEL_FORMAT_BGR888, {3,1}},
{ MEDIA_PIXEL_FORMAT_RGB888, {3,1}},
};
MEDIA_PIXEL_FORMAT_NV12,
MEDIA_PIXEL_FORMAT_NV21,
MEDIA_PIXEL_FORMAT_YUYV422,
+ MEDIA_PIXEL_FORMAT_UYVY422,
};
for (unsigned int i = 0; i < sizeof(fmt)/sizeof(fmt[0]); i++)
return true;
}
+bool
+_ImageUtil::IsValidCoordinate(MediaPixelFormat pixelFormat, int XLoc, int YLoc)
+{
+ if ((MEDIA_PIXEL_FORMAT_YUV420P == pixelFormat) ||
+ (MEDIA_PIXEL_FORMAT_NV12 == pixelFormat) ||
+ (MEDIA_PIXEL_FORMAT_NV21 == pixelFormat))
+ {
+ if ((XLoc & 0x01) || (YLoc & 0x01))
+ {
+ return false;
+ }
+ return true;
+ }
+
+ if ((MEDIA_PIXEL_FORMAT_YUYV422 == pixelFormat) ||
+ (MEDIA_PIXEL_FORMAT_UYVY422 == pixelFormat))
+ {
+ if ((XLoc & 0x01))
+ {
+ return false;
+ }
+ return true;
+ }
+ // return true for other pixel formats
+ return true;
+}
+
int
_ImageUtil::ToFfmpegPixelFormat(MediaPixelFormat pixelFmt)
{