Fix video format

Apparently, video pixel format expected by the camera framework is YU12, and not YV12
as it was implemented.

Change-Id: Id33d8aa7f62f6e68276774ca2a7d25c04acd71cc
This commit is contained in:
Vladimir Chtchetkine
2011-09-21 14:55:29 -07:00
parent 1f37cd45f6
commit 68ec4ac828
5 changed files with 29 additions and 27 deletions

View File

@@ -98,6 +98,15 @@ void YV12ToRGB32(const void* yv12, void* rgb, int width, int height)
{ {
const int pix_total = width * height; const int pix_total = width * height;
const uint8_t* Y = reinterpret_cast<const uint8_t*>(yv12); const uint8_t* Y = reinterpret_cast<const uint8_t*>(yv12);
const uint8_t* V = Y + pix_total;
const uint8_t* U = V + pix_total / 4;
_YUV420SToRGB32(Y, U, V, 1, reinterpret_cast<uint32_t*>(rgb), width, height);
}
void YU12ToRGB32(const void* yu12, void* rgb, int width, int height)
{
const int pix_total = width * height;
const uint8_t* Y = reinterpret_cast<const uint8_t*>(yu12);
const uint8_t* U = Y + pix_total; const uint8_t* U = Y + pix_total;
const uint8_t* V = U + pix_total / 4; const uint8_t* V = U + pix_total / 4;
_YUV420SToRGB32(Y, U, V, 1, reinterpret_cast<uint32_t*>(rgb), width, height); _YUV420SToRGB32(Y, U, V, 1, reinterpret_cast<uint32_t*>(rgb), width, height);
@@ -113,20 +122,7 @@ static void _NVXXToRGB565(const uint8_t* Y,
int width, int width,
int height) int height)
{ {
#if 1
_YUV420SToRGB565(Y, U, V, 2, rgb, width, height); _YUV420SToRGB565(Y, U, V, 2, rgb, width, height);
#else
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x += 2, U += 2, V += 2) {
const uint8_t nU = *U;
const uint8_t nV = *V;
*rgb = YUVToRGB565(*Y, nU, nV);
Y++; rgb++;
*rgb = YUVToRGB565(*Y, nU, nV);
Y++; rgb++;
}
}
#endif
} }
/* Common converter for YUV 4:2:0 interleaved to RGB32. /* Common converter for YUV 4:2:0 interleaved to RGB32.
@@ -139,20 +135,7 @@ static void _NVXXToRGB32(const uint8_t* Y,
int width, int width,
int height) int height)
{ {
#if 1
_YUV420SToRGB32(Y, U, V, 2, rgb, width, height); _YUV420SToRGB32(Y, U, V, 2, rgb, width, height);
#else
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x += 2, U += 2, V += 2) {
const uint8_t nU = *U;
const uint8_t nV = *V;
*rgb = YUVToRGB32(*Y, nU, nV);
Y++; rgb++;
*rgb = YUVToRGB32(*Y, nU, nV);
Y++; rgb++;
}
}
#endif
} }
void NV12ToRGB565(const void* nv12, void* rgb, int width, int height) void NV12ToRGB565(const void* nv12, void* rgb, int width, int height)

View File

@@ -269,6 +269,14 @@ void YV12ToRGB565(const void* yv12, void* rgb, int width, int height);
*/ */
void YV12ToRGB32(const void* yv12, void* rgb, int width, int height); void YV12ToRGB32(const void* yv12, void* rgb, int width, int height);
/* Converts an YU12 framebuffer to RGB32 framebuffer.
* Param:
* yu12 - YU12 framebuffer.
* rgb - RGB32 framebuffer.
* width, height - Dimensions for both framebuffers.
*/
void YU12ToRGB32(const void* yu12, void* rgb, int width, int height);
/* Converts an NV12 framebuffer to RGB565 framebuffer. /* Converts an NV12 framebuffer to RGB565 framebuffer.
* Param: * Param:
* nv12 - NV12 framebuffer. * nv12 - NV12 framebuffer.

View File

@@ -543,7 +543,7 @@ status_t EmulatedCamera::doStartPreview()
} }
uint32_t org_fmt; uint32_t org_fmt;
if (strcmp(pix_fmt, CameraParameters::PIXEL_FORMAT_YUV420P) == 0) { if (strcmp(pix_fmt, CameraParameters::PIXEL_FORMAT_YUV420P) == 0) {
org_fmt = V4L2_PIX_FMT_YVU420; org_fmt = V4L2_PIX_FMT_YUV420;
} else if (strcmp(pix_fmt, CameraParameters::PIXEL_FORMAT_RGBA8888) == 0) { } else if (strcmp(pix_fmt, CameraParameters::PIXEL_FORMAT_RGBA8888) == 0) {
org_fmt = V4L2_PIX_FMT_RGB32; org_fmt = V4L2_PIX_FMT_RGB32;
} else if (strcmp(pix_fmt, CameraParameters::PIXEL_FORMAT_YUV420SP) == 0) { } else if (strcmp(pix_fmt, CameraParameters::PIXEL_FORMAT_YUV420SP) == 0) {

View File

@@ -117,6 +117,9 @@ status_t EmulatedCameraDevice::getCurrentPreviewFrame(void* buffer)
case V4L2_PIX_FMT_YVU420: case V4L2_PIX_FMT_YVU420:
YV12ToRGB32(mCurrentFrame, buffer, mFrameWidth, mFrameHeight); YV12ToRGB32(mCurrentFrame, buffer, mFrameWidth, mFrameHeight);
return NO_ERROR; return NO_ERROR;
case V4L2_PIX_FMT_YUV420:
YU12ToRGB32(mCurrentFrame, buffer, mFrameWidth, mFrameHeight);
return NO_ERROR;
case V4L2_PIX_FMT_NV21: case V4L2_PIX_FMT_NV21:
NV21ToRGB32(mCurrentFrame, buffer, mFrameWidth, mFrameHeight); NV21ToRGB32(mCurrentFrame, buffer, mFrameWidth, mFrameHeight);
return NO_ERROR; return NO_ERROR;
@@ -142,6 +145,7 @@ status_t EmulatedCameraDevice::commonStartDevice(int width,
/* Validate pixel format, and calculate framebuffer size at the same time. */ /* Validate pixel format, and calculate framebuffer size at the same time. */
switch (pix_fmt) { switch (pix_fmt) {
case V4L2_PIX_FMT_YVU420: case V4L2_PIX_FMT_YVU420:
case V4L2_PIX_FMT_YUV420:
case V4L2_PIX_FMT_NV21: case V4L2_PIX_FMT_NV21:
case V4L2_PIX_FMT_NV12: case V4L2_PIX_FMT_NV12:
mFrameBufferSize = (width * height * 12) / 8; mFrameBufferSize = (width * height * 12) / 8;

View File

@@ -117,6 +117,13 @@ status_t EmulatedFakeCameraDevice::startDevice(int width,
/* Calculate U/V panes inside the framebuffer. */ /* Calculate U/V panes inside the framebuffer. */
switch (mPixelFormat) { switch (mPixelFormat) {
case V4L2_PIX_FMT_YVU420: case V4L2_PIX_FMT_YVU420:
mFrameV = mCurrentFrame + mTotalPixels;
mFrameU = mFrameU + mTotalPixels / 4;
mUVStep = 1;
mUVTotalNum = mTotalPixels / 4;
break;
case V4L2_PIX_FMT_YUV420:
mFrameU = mCurrentFrame + mTotalPixels; mFrameU = mCurrentFrame + mTotalPixels;
mFrameV = mFrameU + mTotalPixels / 4; mFrameV = mFrameU + mTotalPixels / 4;
mUVStep = 1; mUVStep = 1;