Skip to content

Commit 00379db

Browse files
authored
Merge pull request #1810 from tannewt/black_line_ondisk
Fix off by one error in OnDiskBitmap
2 parents fcfafe6 + c372567 commit 00379db

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

shared-module/displayio/OnDiskBitmap.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ void common_hal_displayio_ondiskbitmap_construct(displayio_ondiskbitmap_t *self,
6868
self->r_bitmask = read_word(bmp_header, 27);
6969
self->g_bitmask = read_word(bmp_header, 29);
7070
self->b_bitmask = read_word(bmp_header, 31);
71-
71+
7272
} else { // no compression or short header means 5:5:5
7373
self->r_bitmask = 0x7c00;
7474
self->g_bitmask = 0x3e0;
@@ -114,7 +114,7 @@ void common_hal_displayio_ondiskbitmap_construct(displayio_ondiskbitmap_t *self,
114114
}
115115
self->stride = (bit_stride / 8);
116116
}
117-
117+
118118
}
119119

120120

@@ -123,12 +123,13 @@ uint32_t common_hal_displayio_ondiskbitmap_get_pixel(displayio_ondiskbitmap_t *s
123123
if (x < 0 || x >= self->width || y < 0 || y >= self->height) {
124124
return 0;
125125
}
126+
126127
uint32_t location;
127128
uint8_t bytes_per_pixel = (self->bits_per_pixel / 8) ? (self->bits_per_pixel /8) : 1;
128129
if (self->bits_per_pixel >= 8){
129-
location = self->data_offset + (self->height - y) * self->stride + x * bytes_per_pixel;
130+
location = self->data_offset + (self->height - y - 1) * self->stride + x * bytes_per_pixel;
130131
} else {
131-
location = self->data_offset + (self->height - y) * self->stride + x / 8;
132+
location = self->data_offset + (self->height - y - 1) * self->stride + x / 8;
132133
}
133134
// We don't cache here because the underlying FS caches sectors.
134135
f_lseek(&self->file->fp, location);
@@ -140,15 +141,15 @@ uint32_t common_hal_displayio_ondiskbitmap_get_pixel(displayio_ondiskbitmap_t *s
140141
uint8_t red;
141142
uint8_t green;
142143
uint8_t blue;
143-
if (self->bits_per_pixel == 1){
144+
if (self->bits_per_pixel == 1) {
144145
uint8_t bit_offset = x%8;
145146
tmp = ( pixel_data & (0x80 >> (bit_offset))) >> (7 - bit_offset);
146147
if (tmp == 1) {
147148
return 0x00FFFFFF;
148149
} else {
149150
return 0x00000000;
150151
}
151-
} else if (bytes_per_pixel == 1){
152+
} else if (bytes_per_pixel == 1) {
152153
blue = ((self->palette_data[pixel_data] & 0xFF) >> 0);
153154
red = ((self->palette_data[pixel_data] & 0xFF0000) >> 16);
154155
green = ((self->palette_data[pixel_data] & 0xFF00) >> 8);

0 commit comments

Comments
 (0)