Merge "Added downsample()"
This commit is contained in:
@@ -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;
|
||||
|
||||
|
||||
@@ -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>
|
||||
@@ -74,10 +75,37 @@ void YUVCanvas::CopyImageRect(
|
||||
uint8_t uValue;
|
||||
uint8_t vValue;
|
||||
|
||||
srcImage.getPixelValue(srcX, srcY, &yValue, &uValue, & vValue);
|
||||
srcImage.getPixelValue(srcX, srcY, &yValue, &uValue, &vValue);
|
||||
mYUVImage.setPixelValue(destX, destY, yValue, uValue, vValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user