const correctness, validPixel test.
- made width(), height() const member functions.
- added validPixel() which returns true if pixel is in the allowed range.
- now testing validPixel in get/setPixelValue
Change-Id: I1dee5060bd4f8dcbdcd542ec4647ea328f0185c3
diff --git a/include/media/stagefright/YUVImage.h b/include/media/stagefright/YUVImage.h
index afeac3f..4e98618 100644
--- a/include/media/stagefright/YUVImage.h
+++ b/include/media/stagefright/YUVImage.h
@@ -67,18 +67,22 @@
// memory.
static size_t bufferSize(YUVFormat yuvFormat, int32_t width, int32_t height);
- int32_t width() {return mWidth;}
- int32_t height() {return mHeight;}
+ int32_t width() const {return mWidth;}
+ int32_t height() const {return mHeight;}
+
+ // Returns true if pixel is the range [0, width-1] x [0, height-1]
+ // and false otherwise.
+ bool validPixel(int32_t x, int32_t y) const;
// Get the pixel YUV value at pixel (x,y).
// Note that the range of x is [0, width-1] and the range of y is [0, height-1].
- // Returns true if get was succesful and false otherwise.
+ // Returns true if get was successful and false otherwise.
bool getPixelValue(int32_t x, int32_t y,
uint8_t *yPtr, uint8_t *uPtr, uint8_t *vPtr) const;
// Set the pixel YUV value at pixel (x,y).
// Note that the range of x is [0, width-1] and the range of y is [0, height-1].
- // Returns true if set was succesful and false otherwise.
+ // Returns true if set was successful and false otherwise.
bool setPixelValue(int32_t x, int32_t y,
uint8_t yValue, uint8_t uValue, uint8_t vValue);
diff --git a/media/libstagefright/yuv/YUVImage.cpp b/media/libstagefright/yuv/YUVImage.cpp
index 73e3297..b712062 100644
--- a/media/libstagefright/yuv/YUVImage.cpp
+++ b/media/libstagefright/yuv/YUVImage.cpp
@@ -155,8 +155,15 @@
return true;
}
+bool YUVImage::validPixel(int32_t x, int32_t y) const {
+ return (x >= 0 && x < mWidth &&
+ y >= 0 && y < mHeight);
+}
+
bool YUVImage::getPixelValue(int32_t x, int32_t y,
uint8_t *yPtr, uint8_t *uPtr, uint8_t *vPtr) const {
+ CHECK(validPixel(x, y));
+
uint8_t *yAddr;
uint8_t *uAddr;
uint8_t *vAddr;
@@ -171,6 +178,8 @@
bool YUVImage::setPixelValue(int32_t x, int32_t y,
uint8_t yValue, uint8_t uValue, uint8_t vValue) {
+ CHECK(validPixel(x, y));
+
uint8_t *yAddr;
uint8_t *uAddr;
uint8_t *vAddr;