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

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

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
parent 7d73206a
Loading
Loading
Loading
Loading
+8 −4
Original line number Diff line number Diff line
@@ -67,18 +67,22 @@ public:
    // 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);

+9 −0
Original line number Diff line number Diff line
@@ -155,8 +155,15 @@ bool YUVImage::getYUVAddresses(int32_t x, int32_t y,
    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::getPixelValue(int32_t x, int32_t y,

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;