summaryrefslogtreecommitdiffstats
path: root/core/jni
diff options
context:
space:
mode:
authorRuben Brunk <rubenbrunk@google.com>2014-12-10 19:12:41 -0800
committerRuben Brunk <rubenbrunk@google.com>2014-12-11 11:35:46 -0800
commit433e715cc0040ce22a31964c71bff71b1fe1a14f (patch)
treeffdde7f8e30d0044178380d2ff6a0eac1711e8fa /core/jni
parentb897f013b558596964e33b39c0e9678998c281dc (diff)
downloadframeworks_base-433e715cc0040ce22a31964c71bff71b1fe1a14f.zip
frameworks_base-433e715cc0040ce22a31964c71bff71b1fe1a14f.tar.gz
frameworks_base-433e715cc0040ce22a31964c71bff71b1fe1a14f.tar.bz2
camera2: Fix LEGACY YUV production and orientation.
Bug: 18486140 Change-Id: I119e57315b67d1f485bea7f1682bfc261ae0f934
Diffstat (limited to 'core/jni')
-rw-r--r--core/jni/android_hardware_camera2_legacy_LegacyCameraDevice.cpp35
1 files changed, 19 insertions, 16 deletions
diff --git a/core/jni/android_hardware_camera2_legacy_LegacyCameraDevice.cpp b/core/jni/android_hardware_camera2_legacy_LegacyCameraDevice.cpp
index b44c829..b27add8 100644
--- a/core/jni/android_hardware_camera2_legacy_LegacyCameraDevice.cpp
+++ b/core/jni/android_hardware_camera2_legacy_LegacyCameraDevice.cpp
@@ -49,36 +49,35 @@ using namespace android;
#define ALIGN(x, mask) ( ((x) + (mask) - 1) & ~((mask) - 1) )
/**
- * Convert from RGB 888 to Y'CbCr using the conversion specified in ITU-R BT.601 for
- * digital RGB with K_b = 0.114, and K_r = 0.299.
+ * Convert from RGB 888 to Y'CbCr using the conversion specified in JFIF v1.02
*/
static void rgbToYuv420(uint8_t* rgbBuf, size_t width, size_t height, uint8_t* yPlane,
uint8_t* uPlane, uint8_t* vPlane, size_t chromaStep, size_t yStride, size_t chromaStride) {
uint8_t R, G, B;
size_t index = 0;
-
- size_t cStrideDiff = chromaStride - width;
-
for (size_t j = 0; j < height; j++) {
+ uint8_t* u = uPlane;
+ uint8_t* v = vPlane;
+ uint8_t* y = yPlane;
+ bool jEven = (j & 1) == 0;
for (size_t i = 0; i < width; i++) {
R = rgbBuf[index++];
G = rgbBuf[index++];
B = rgbBuf[index++];
- *(yPlane + i) = ((66 * R + 129 * G + 25 * B + 128) >> 8) + 16;
-
- if (j % 2 == 0 && i % 2 == 0){
- *uPlane = (( -38 * R - 74 * G + 112 * B + 128) >> 8) + 128;
- *vPlane = (( 112 * R - 94 * G - 18 * B + 128) >> 8) + 128;
- uPlane += chromaStep;
- vPlane += chromaStep;
+ *y++ = (77 * R + 150 * G + 29 * B) >> 8;
+ if (jEven && (i & 1) == 0) {
+ *v = (( -43 * R - 85 * G + 128 * B) >> 8) + 128;
+ *u = (( 128 * R - 107 * G - 21 * B) >> 8) + 128;
+ u += chromaStep;
+ v += chromaStep;
}
// Skip alpha
index++;
}
yPlane += yStride;
- if (j % 2 == 0) {
- uPlane += cStrideDiff;
- vPlane += cStrideDiff;
+ if (jEven) {
+ uPlane += chromaStride;
+ vPlane += chromaStride;
}
}
}
@@ -87,8 +86,10 @@ static void rgbToYuv420(uint8_t* rgbBuf, size_t width, size_t height, android_yc
size_t cStep = ycbcr->chroma_step;
size_t cStride = ycbcr->cstride;
size_t yStride = ycbcr->ystride;
+ ALOGV("%s: yStride is: %zu, cStride is: %zu, cStep is: %zu", __FUNCTION__, yStride, cStride,
+ cStep);
rgbToYuv420(rgbBuf, width, height, reinterpret_cast<uint8_t*>(ycbcr->y),
- reinterpret_cast<uint8_t*>(ycbcr->cb), reinterpret_cast<uint8_t*>(ycbcr->cr),
+ reinterpret_cast<uint8_t*>(ycbcr->cr), reinterpret_cast<uint8_t*>(ycbcr->cb),
cStep, yStride, cStride);
}
@@ -231,6 +232,7 @@ static status_t produceFrame(const sp<ANativeWindow>& anw,
size_t totalSizeBytes = tmpSize;
+ ALOGV("%s: Pixel format chosen: %x", __FUNCTION__, pixelFmt);
switch(pixelFmt) {
case HAL_PIXEL_FORMAT_YCrCb_420_SP: {
if (bufferLength < totalSizeBytes) {
@@ -276,6 +278,7 @@ static status_t produceFrame(const sp<ANativeWindow>& anw,
}
uint32_t stride = buf->getStride();
+ ALOGV("%s: stride is: %" PRIu32, __FUNCTION__, stride);
LOG_ALWAYS_FATAL_IF(stride % 16, "Stride is not 16 pixel aligned %d", stride);
uint32_t cStride = ALIGN(stride / 2, 16);