* PresentImage270() * Converting image from YUV to RGB * Rotate Image counter-clockwise 270 degree: (x, y) --> (y, x) */
| 370 | * Rotate Image counter-clockwise 270 degree: (x, y) --> (y, x) |
| 371 | */ |
| 372 | void ImageReader::PresentImage270(ANativeWindow_Buffer* buf, AImage* image) { |
| 373 | AImageCropRect srcRect; |
| 374 | AImage_getCropRect(image, &srcRect); |
| 375 | |
| 376 | int32_t yStride, uvStride; |
| 377 | uint8_t *yPixel, *uPixel, *vPixel; |
| 378 | int32_t yLen, uLen, vLen; |
| 379 | AImage_getPlaneRowStride(image, 0, &yStride); |
| 380 | AImage_getPlaneRowStride(image, 1, &uvStride); |
| 381 | AImage_getPlaneData(image, 0, &yPixel, &yLen); |
| 382 | AImage_getPlaneData(image, 1, &uPixel, &uLen); |
| 383 | AImage_getPlaneData(image, 2, &vPixel, &vLen); |
| 384 | int32_t uvPixelStride; |
| 385 | AImage_getPlanePixelStride(image, 1, &uvPixelStride); |
| 386 | |
| 387 | int32_t height = MIN(buf->width, (srcRect.bottom - srcRect.top)); |
| 388 | int32_t width = MIN(buf->height, (srcRect.right - srcRect.left)); |
| 389 | |
| 390 | uint32_t* out = static_cast<uint32_t*>(buf->bits); |
| 391 | for (int32_t y = 0; y < height; y++) { |
| 392 | const uint8_t* pY = yPixel + yStride * (y + srcRect.top) + srcRect.left; |
| 393 | |
| 394 | int32_t uv_row_start = uvStride * ((y + srcRect.top) >> 1); |
| 395 | const uint8_t* pU = uPixel + uv_row_start + (srcRect.left >> 1); |
| 396 | const uint8_t* pV = vPixel + uv_row_start + (srcRect.left >> 1); |
| 397 | |
| 398 | for (int32_t x = 0; x < width; x++) { |
| 399 | const int32_t uv_offset = (x >> 1) * uvPixelStride; |
| 400 | out[(width - 1 - x) * buf->stride] = |
| 401 | YUV2RGB(pY[x], pU[uv_offset], pV[uv_offset]); |
| 402 | } |
| 403 | out += 1; // move to the next column |
| 404 | } |
| 405 | } |
| 406 | void ImageReader::SetPresentRotation(int32_t angle) { |
| 407 | presentRotation_ = angle; |
| 408 | } |