From f3f07e0c82cfc06f026bc7b95af562b3d6978506 Mon Sep 17 00:00:00 2001 From: Murat Seker Date: Sat, 8 Aug 2020 12:57:15 +0200 Subject: [PATCH] Get rid of unnecessary computation in ImageResampler (#947) --- libsrc/utils/ImageResampler.cpp | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/libsrc/utils/ImageResampler.cpp b/libsrc/utils/ImageResampler.cpp index 204e4fd7..83aa137d 100644 --- a/libsrc/utils/ImageResampler.cpp +++ b/libsrc/utils/ImageResampler.cpp @@ -1,4 +1,5 @@ #include "utils/ImageResampler.h" + #include ImageResampler::ImageResampler() @@ -65,6 +66,8 @@ void ImageResampler::processImage(const uint8_t * data, int width, int height, i for (int yDest = 0, ySource = _cropTop + (_verticalDecimation >> 1); yDest < outputHeight; ySource += _verticalDecimation, ++yDest) { + int yOffset = lineLength * ySource; + for (int xDest = 0, xSource = _cropLeft + (_horizontalDecimation >> 1); xDest < outputWidth; xSource += _horizontalDecimation, ++xDest) { ColorRgb & rgb = outputImage(xDest, yDest); @@ -73,7 +76,7 @@ void ImageResampler::processImage(const uint8_t * data, int width, int height, i { case PixelFormat::UYVY: { - int index = lineLength * ySource + (xSource << 1); + int index = yOffset + (xSource << 1); uint8_t y = data[index+1]; uint8_t u = ((xSource&1) == 0) ? data[index ] : data[index-2]; uint8_t v = ((xSource&1) == 0) ? data[index+2] : data[index ]; @@ -82,7 +85,7 @@ void ImageResampler::processImage(const uint8_t * data, int width, int height, i break; case PixelFormat::YUYV: { - int index = lineLength * ySource + (xSource << 1); + int index = yOffset + (xSource << 1); uint8_t y = data[index]; uint8_t u = ((xSource&1) == 0) ? data[index+1] : data[index-1]; uint8_t v = ((xSource&1) == 0) ? data[index+3] : data[index+1]; @@ -91,7 +94,7 @@ void ImageResampler::processImage(const uint8_t * data, int width, int height, i break; case PixelFormat::BGR16: { - int index = lineLength * ySource + (xSource << 1); + int index = yOffset + (xSource << 1); rgb.blue = (data[index] & 0x1f) << 3; rgb.green = (((data[index+1] & 0x7) << 3) | (data[index] & 0xE0) >> 5) << 2; rgb.red = (data[index+1] & 0xF8); @@ -99,7 +102,7 @@ void ImageResampler::processImage(const uint8_t * data, int width, int height, i break; case PixelFormat::BGR24: { - int index = lineLength * ySource + (xSource << 1) + xSource; + int index = yOffset + (xSource << 1) + xSource; rgb.blue = data[index ]; rgb.green = data[index+1]; rgb.red = data[index+2]; @@ -107,7 +110,7 @@ void ImageResampler::processImage(const uint8_t * data, int width, int height, i break; case PixelFormat::RGB32: { - int index = lineLength * ySource + (xSource << 2); + int index = yOffset + (xSource << 2); rgb.red = data[index ]; rgb.green = data[index+1]; rgb.blue = data[index+2]; @@ -115,7 +118,7 @@ void ImageResampler::processImage(const uint8_t * data, int width, int height, i break; case PixelFormat::BGR32: { - int index = lineLength * ySource + (xSource << 2); + int index = yOffset + (xSource << 2); rgb.blue = data[index ]; rgb.green = data[index+1]; rgb.red = data[index+2];