microbit-dal: Corrected bad validation in MicroBitImage.printImage

width was validated, height was not. Documentation also modified to have a better example that works.
This commit is contained in:
James Devine 2017-04-23 00:53:16 +01:00
parent 58f8f0f22e
commit d5ee7d99b6
2 changed files with 11 additions and 11 deletions

View file

@ -266,9 +266,9 @@ class MicroBitImage
* Replaces the content of this image with that of a given 2D array representing
* the image.
*
* @param x the width of the image. Must be within the dimensions of the image.
* @param width the width of the image. Must be within the dimensions of the image.
*
* @param y the width of the image. Must be within the dimensions of the image.
* @param height the height of the image. Must be within the dimensions of the image.
*
* @param bitmap a 2D array representing the image.
*
@ -276,13 +276,13 @@ class MicroBitImage
*
* @code
* const uint8_t heart[] = { 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 0, 1, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, }; // a cute heart
* MicroBitImage i();
* i.printImage(0,0,heart);
* MicroBitImage i(10, 5);
* i.printImage(10,5,heart);
* @endcode
*
* @note all coordinates originate from the top left of an image.
*/
int printImage(int16_t x, int16_t y, const uint8_t *bitmap);
int printImage(int16_t width, int16_t height, const uint8_t *bitmap);
/**
* Pastes a given bitmap at the given co-ordinates.

View file

@ -428,9 +428,9 @@ int MicroBitImage::getPixelValue(int16_t x , int16_t y)
* Replaces the content of this image with that of a given 2D array representing
* the image.
*
* @param x the width of the image. Must be within the dimensions of the image.
* @param width the width of the image. Must be within the dimensions of the image.
*
* @param y the width of the image. Must be within the dimensions of the image.
* @param height the height of the image. Must be within the dimensions of the image.
*
* @param bitmap a 2D array representing the image.
*
@ -438,8 +438,8 @@ int MicroBitImage::getPixelValue(int16_t x , int16_t y)
*
* @code
* const uint8_t heart[] = { 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 0, 1, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, }; // a cute heart
* MicroBitImage i();
* i.printImage(0,0,heart);
* MicroBitImage i(10, 5);
* i.printImage(10,5,heart);
* @endcode
*
* @note all coordinates originate from the top left of an image.
@ -451,10 +451,10 @@ int MicroBitImage::printImage(int16_t width, int16_t height, const uint8_t *bitm
int pixelsToCopyX, pixelsToCopyY;
// Sanity check.
if (width <= 0 || width <= 0 || bitmap == NULL)
if (width <= 0 || height <= 0 || bitmap == NULL)
return MICROBIT_INVALID_PARAMETER;
// Calcualte sane start pointer.
// Calculate sane start pointer.
pixelsToCopyX = min(width,this->getWidth());
pixelsToCopyY = min(height,this->getHeight());