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

Method PresentImage90

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

* PresentImage90() * Converting YUV to RGB * Rotation image anti-clockwise 90 degree -- (x, y) --> (-y, x) */

Source from the content-addressed store, hash-verified

287 * Rotation image anti-clockwise 90 degree -- (x, y) --> (-y, x)
288 */
289void ImageReader::PresentImage90(ANativeWindow_Buffer* buf, AImage* image) {
290 AImageCropRect srcRect;
291 AImage_getCropRect(image, &srcRect);
292
293 int32_t yStride, uvStride;
294 uint8_t *yPixel, *uPixel, *vPixel;
295 int32_t yLen, uLen, vLen;
296 AImage_getPlaneRowStride(image, 0, &yStride);
297 AImage_getPlaneRowStride(image, 1, &uvStride);
298 AImage_getPlaneData(image, 0, &yPixel, &yLen);
299 AImage_getPlaneData(image, 1, &uPixel, &uLen);
300 AImage_getPlaneData(image, 2, &vPixel, &vLen);
301 int32_t uvPixelStride;
302 AImage_getPlanePixelStride(image, 1, &uvPixelStride);
303
304 int32_t height = MIN(buf->width, (srcRect.bottom - srcRect.top));
305 int32_t width = MIN(buf->height, (srcRect.right - srcRect.left));
306
307 uint32_t* out = static_cast<uint32_t*>(buf->bits);
308 out += height - 1;
309 for (int32_t y = 0; y < height; y++) {
310 const uint8_t* pY = yPixel + yStride * (y + srcRect.top) + srcRect.left;
311
312 int32_t uv_row_start = uvStride * ((y + srcRect.top) >> 1);
313 const uint8_t* pU = uPixel + uv_row_start + (srcRect.left >> 1);
314 const uint8_t* pV = vPixel + uv_row_start + (srcRect.left >> 1);
315
316 for (int32_t x = 0; x < width; x++) {
317 const int32_t uv_offset = (x >> 1) * uvPixelStride;
318 // [x, y]--> [-y, x]
319 out[x * buf->stride] = YUV2RGB(pY[x], pU[uv_offset], pV[uv_offset]);
320 }
321 out -= 1; // move to the next column
322 }
323}
324
325/*
326 * PresentImage180()

Callers

nothing calls this directly

Calls 1

YUV2RGBFunction · 0.85

Tested by

no test coverage detected