2019-12-08 16:16:33 +01:00
|
|
|
#include "image.hpp"
|
|
|
|
|
|
|
|
|
|
|
|
bool Image::check_bounds(int x, int y) {
|
|
|
|
if ((x < 0) || (y < 0)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2023-04-24 21:52:33 +02:00
|
|
|
if ((x >= IMAGE_WIDTH) || (y >= IMAGE_HEIGHT)) {
|
2019-12-08 16:16:33 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
byte Image::get_pixel(int x, int y) {
|
|
|
|
if (check_bounds(x, y) == false) {
|
2023-04-24 21:52:33 +02:00
|
|
|
Serial.print(F("get_pixel outOfBound\n"));
|
|
|
|
return 1;
|
2019-12-08 16:16:33 +01:00
|
|
|
}
|
2023-04-24 21:52:33 +02:00
|
|
|
return data[y * IMAGE_WIDTH + x];
|
2019-12-08 16:16:33 +01:00
|
|
|
}
|
|
|
|
|
2023-04-25 21:42:31 +02:00
|
|
|
void Image::set_pixel_offset(int offset, byte value) {
|
|
|
|
int x = offset % IMAGE_WIDTH;
|
|
|
|
int y = floor(offset / IMAGE_WIDTH);
|
|
|
|
if (check_bounds(x, y) == false) {
|
|
|
|
Serial.print(F("set_pixel outOfBound\n"));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
data[y * IMAGE_WIDTH + x] = value;
|
|
|
|
}
|
|
|
|
|
2019-12-08 16:16:33 +01:00
|
|
|
void Image::set_pixel(int x, int y, byte value) {
|
|
|
|
if (check_bounds(x, y) == false) {
|
2023-04-24 21:52:33 +02:00
|
|
|
Serial.print(F("set_pixel outOfBound\n"));
|
2019-12-08 16:16:33 +01:00
|
|
|
return;
|
|
|
|
}
|
2023-04-24 21:52:33 +02:00
|
|
|
data[y * IMAGE_WIDTH + x] = value;
|
2019-12-08 16:16:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void Image::clear_pixels() {
|
|
|
|
memset(data, 0, sizeof(data));
|
|
|
|
}
|