MCPcopy Create free account
hub / github.com/android/ndk-samples / PresentImage180

Method PresentImage180

camera/basic/src/main/cpp/image_reader.cpp:330–365  ·  view source on GitHub ↗

* PresentImage180() * Converting yuv to RGB * Rotate image 180 degree: (x, y) --> (-x, -y) */

Source from the content-addressed store, hash-verified

328 * Rotate image 180 degree: (x, y) --> (-x, -y)
329 */
330void ImageReader::PresentImage180(ANativeWindow_Buffer* buf, AImage* image) {
331 AImageCropRect srcRect;
332 AImage_getCropRect(image, &srcRect);
333
334 int32_t yStride, uvStride;
335 uint8_t *yPixel, *uPixel, *vPixel;
336 int32_t yLen, uLen, vLen;
337 AImage_getPlaneRowStride(image, 0, &yStride);
338 AImage_getPlaneRowStride(image, 1, &uvStride);
339 AImage_getPlaneData(image, 0, &yPixel, &yLen);
340 AImage_getPlaneData(image, 1, &uPixel, &uLen);
341 AImage_getPlaneData(image, 2, &vPixel, &vLen);
342 int32_t uvPixelStride;
343 AImage_getPlanePixelStride(image, 1, &uvPixelStride);
344
345 int32_t height = MIN(buf->height, (srcRect.bottom - srcRect.top));
346 int32_t width = MIN(buf->width, (srcRect.right - srcRect.left));
347
348 uint32_t* out = static_cast<uint32_t*>(buf->bits);
349 out += (height - 1) * buf->stride;
350 for (int32_t y = 0; y < height; y++) {
351 const uint8_t* pY = yPixel + yStride * (y + srcRect.top) + srcRect.left;
352
353 int32_t uv_row_start = uvStride * ((y + srcRect.top) >> 1);
354 const uint8_t* pU = uPixel + uv_row_start + (srcRect.left >> 1);
355 const uint8_t* pV = vPixel + uv_row_start + (srcRect.left >> 1);
356
357 for (int32_t x = 0; x < width; x++) {
358 const int32_t uv_offset = (x >> 1) * uvPixelStride;
359 // mirror image since we are using front camera
360 out[width - 1 - x] = YUV2RGB(pY[x], pU[uv_offset], pV[uv_offset]);
361 // out[x] = YUV2RGB(pY[x], pU[uv_offset], pV[uv_offset]);
362 }
363 out -= buf->stride;
364 }
365}
366
367/*
368 * PresentImage270()

Callers

nothing calls this directly

Calls 1

YUV2RGBFunction · 0.85

Tested by

no test coverage detected