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

Method PresentImage

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

* PresentImage() * Converting yuv to RGB * No rotation: (x,y) --> (x, y) * Refer to: * https://mathbits.com/MathBits/TISection/Geometry/Transformations2.htm */

Source from the content-addressed store, hash-verified

248 * https://mathbits.com/MathBits/TISection/Geometry/Transformations2.htm
249 */
250void ImageReader::PresentImage(ANativeWindow_Buffer* buf, AImage* image) {
251 AImageCropRect srcRect;
252 AImage_getCropRect(image, &srcRect);
253
254 int32_t yStride, uvStride;
255 uint8_t *yPixel, *uPixel, *vPixel;
256 int32_t yLen, uLen, vLen;
257 AImage_getPlaneRowStride(image, 0, &yStride);
258 AImage_getPlaneRowStride(image, 1, &uvStride);
259 AImage_getPlaneData(image, 0, &yPixel, &yLen);
260 AImage_getPlaneData(image, 1, &uPixel, &uLen);
261 AImage_getPlaneData(image, 2, &vPixel, &vLen);
262 int32_t uvPixelStride;
263 AImage_getPlanePixelStride(image, 1, &uvPixelStride);
264
265 int32_t height = MIN(buf->height, (srcRect.bottom - srcRect.top));
266 int32_t width = MIN(buf->width, (srcRect.right - srcRect.left));
267
268 uint32_t* out = static_cast<uint32_t*>(buf->bits);
269 for (int32_t y = 0; y < height; y++) {
270 const uint8_t* pY = yPixel + yStride * (y + srcRect.top) + srcRect.left;
271
272 int32_t uv_row_start = uvStride * ((y + srcRect.top) >> 1);
273 const uint8_t* pU = uPixel + uv_row_start + (srcRect.left >> 1);
274 const uint8_t* pV = vPixel + uv_row_start + (srcRect.left >> 1);
275
276 for (int32_t x = 0; x < width; x++) {
277 const int32_t uv_offset = (x >> 1) * uvPixelStride;
278 out[x] = YUV2RGB(pY[x], pU[uv_offset], pV[uv_offset]);
279 }
280 out += buf->stride;
281 }
282}
283
284/*
285 * PresentImage90()

Callers

nothing calls this directly

Calls 1

YUV2RGBFunction · 0.85

Tested by

no test coverage detected