From 68ec4ac828762745155be9662285d2174a7eff1e Mon Sep 17 00:00:00 2001 From: Vladimir Chtchetkine Date: Wed, 21 Sep 2011 14:55:29 -0700 Subject: [PATCH] Fix video format Apparently, video pixel format expected by the camera framework is YU12, and not YV12 as it was implemented. Change-Id: Id33d8aa7f62f6e68276774ca2a7d25c04acd71cc --- tools/emulator/system/camera/Converters.cpp | 35 +++++-------------- tools/emulator/system/camera/Converters.h | 8 +++++ .../emulator/system/camera/EmulatedCamera.cpp | 2 +- .../system/camera/EmulatedCameraDevice.cpp | 4 +++ .../camera/EmulatedFakeCameraDevice.cpp | 7 ++++ 5 files changed, 29 insertions(+), 27 deletions(-) diff --git a/tools/emulator/system/camera/Converters.cpp b/tools/emulator/system/camera/Converters.cpp index 22c4bd3cd..f63f67f11 100755 --- a/tools/emulator/system/camera/Converters.cpp +++ b/tools/emulator/system/camera/Converters.cpp @@ -98,6 +98,15 @@ void YV12ToRGB32(const void* yv12, void* rgb, int width, int height) { const int pix_total = width * height; const uint8_t* Y = reinterpret_cast(yv12); + const uint8_t* V = Y + pix_total; + const uint8_t* U = V + pix_total / 4; + _YUV420SToRGB32(Y, U, V, 1, reinterpret_cast(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(yu12); const uint8_t* U = Y + pix_total; const uint8_t* V = U + pix_total / 4; _YUV420SToRGB32(Y, U, V, 1, reinterpret_cast(rgb), width, height); @@ -113,20 +122,7 @@ static void _NVXXToRGB565(const uint8_t* Y, int width, int height) { -#if 1 _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. @@ -139,20 +135,7 @@ static void _NVXXToRGB32(const uint8_t* Y, int width, int height) { -#if 1 _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) diff --git a/tools/emulator/system/camera/Converters.h b/tools/emulator/system/camera/Converters.h index 5001948b4..ab00711fc 100755 --- a/tools/emulator/system/camera/Converters.h +++ b/tools/emulator/system/camera/Converters.h @@ -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); +/* 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. * Param: * nv12 - NV12 framebuffer. diff --git a/tools/emulator/system/camera/EmulatedCamera.cpp b/tools/emulator/system/camera/EmulatedCamera.cpp index 8f50eb8f1..d050413bb 100755 --- a/tools/emulator/system/camera/EmulatedCamera.cpp +++ b/tools/emulator/system/camera/EmulatedCamera.cpp @@ -543,7 +543,7 @@ status_t EmulatedCamera::doStartPreview() } uint32_t org_fmt; 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) { org_fmt = V4L2_PIX_FMT_RGB32; } else if (strcmp(pix_fmt, CameraParameters::PIXEL_FORMAT_YUV420SP) == 0) { diff --git a/tools/emulator/system/camera/EmulatedCameraDevice.cpp b/tools/emulator/system/camera/EmulatedCameraDevice.cpp index bfb2c342f..e09bead0c 100755 --- a/tools/emulator/system/camera/EmulatedCameraDevice.cpp +++ b/tools/emulator/system/camera/EmulatedCameraDevice.cpp @@ -117,6 +117,9 @@ status_t EmulatedCameraDevice::getCurrentPreviewFrame(void* buffer) case V4L2_PIX_FMT_YVU420: YV12ToRGB32(mCurrentFrame, buffer, mFrameWidth, mFrameHeight); return NO_ERROR; + case V4L2_PIX_FMT_YUV420: + YU12ToRGB32(mCurrentFrame, buffer, mFrameWidth, mFrameHeight); + return NO_ERROR; case V4L2_PIX_FMT_NV21: NV21ToRGB32(mCurrentFrame, buffer, mFrameWidth, mFrameHeight); return NO_ERROR; @@ -142,6 +145,7 @@ status_t EmulatedCameraDevice::commonStartDevice(int width, /* Validate pixel format, and calculate framebuffer size at the same time. */ switch (pix_fmt) { case V4L2_PIX_FMT_YVU420: + case V4L2_PIX_FMT_YUV420: case V4L2_PIX_FMT_NV21: case V4L2_PIX_FMT_NV12: mFrameBufferSize = (width * height * 12) / 8; diff --git a/tools/emulator/system/camera/EmulatedFakeCameraDevice.cpp b/tools/emulator/system/camera/EmulatedFakeCameraDevice.cpp index 1aac44248..53a5b1bfb 100755 --- a/tools/emulator/system/camera/EmulatedFakeCameraDevice.cpp +++ b/tools/emulator/system/camera/EmulatedFakeCameraDevice.cpp @@ -117,6 +117,13 @@ status_t EmulatedFakeCameraDevice::startDevice(int width, /* Calculate U/V panes inside the framebuffer. */ switch (mPixelFormat) { 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; mFrameV = mFrameU + mTotalPixels / 4; mUVStep = 1;