Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 96624731 authored by Nipun Kwatra's avatar Nipun Kwatra
Browse files

Added downsample()

Added a downsample function which downsamples the source image
starting at an offset and skipping every few pixels. Currently
no low pass filtering is done, but it should be added later.

Change-Id: Iec34092c536bfc661a15521e6a1ef2ef3f815c61
parent d1fbdf1a
Loading
Loading
Loading
Loading
+12 −0
Original line number Diff line number Diff line
@@ -55,6 +55,18 @@ public:
            int32_t destStartX, int32_t destStartY,
            const YUVImage &srcImage);

    // Downsamples the srcImage into the canvas' target image (mYUVImage)
    // The downsampling copies pixels from the source image starting at
    // (srcOffsetX, srcOffsetY) to the target image, starting at (0, 0).
    // For each X increment in the target image, skipX pixels are skipped
    // in the source image.
    // Similarly for each Y increment in the target image, skipY pixels
    // are skipped in the source image.
    void downsample(
            int32_t srcOffsetX, int32_t srcOffsetY,
            int32_t skipX, int32_t skipY,
            const YUVImage &srcImage);

private:
    YUVImage& mYUVImage;

+29 −1
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
#define LOG_NDEBUG 0
#define LOG_TAG "YUVCanvas"

#include <media/stagefright/MediaDebug.h>
#include <media/stagefright/YUVCanvas.h>
#include <media/stagefright/YUVImage.h>
#include <ui/Rect.h>
@@ -80,4 +81,31 @@ void YUVCanvas::CopyImageRect(
    }
}

void YUVCanvas::downsample(
        int32_t srcOffsetX, int32_t srcOffsetY,
        int32_t skipX, int32_t skipY,
        const YUVImage &srcImage) {
    // TODO: Add a low pass filter for downsampling.

    // Check that srcImage is big enough to fill mYUVImage.
    CHECK((srcOffsetX + (mYUVImage.width() - 1) * skipX) < srcImage.width());
    CHECK((srcOffsetY + (mYUVImage.height() - 1) * skipY) < srcImage.height());

    uint8_t yValue;
    uint8_t uValue;
    uint8_t vValue;

    int32_t srcY = srcOffsetY;
    for (int32_t y = 0; y < mYUVImage.height(); ++y) {
        int32_t srcX = srcOffsetX;
        for (int32_t x = 0; x < mYUVImage.width(); ++x) {
            srcImage.getPixelValue(srcX, srcY, &yValue, &uValue, &vValue);
            mYUVImage.setPixelValue(x, y, yValue, uValue, vValue);

            srcX += skipX;
        }
        srcY += skipY;
    }
}

}  // namespace android