mirror of
https://github.com/eried/portapack-mayhem.git
synced 2025-11-27 23:20:33 -05:00
parent
c01597baf2
commit
6b02ba6e5d
7 changed files with 128 additions and 15 deletions
|
|
@ -173,7 +173,7 @@ bool BMPFile::read_next_px(ui::Color& px, bool seek = true) {
|
|||
//*a = (val >> 15) & 0x01; // 1-bit alpha
|
||||
uint8_t r = (val >> 10) & 0x1F; // 5-bit red
|
||||
uint8_t g = (val >> 5) & 0x1F; // 5-bit green
|
||||
uint8_t b = (val)&0x1F; // 5-bit blue
|
||||
uint8_t b = (val) & 0x1F; // 5-bit blue
|
||||
// expand
|
||||
r = (r << 3) | (r >> 2);
|
||||
g = (g << 3) | (g >> 2);
|
||||
|
|
@ -200,6 +200,53 @@ bool BMPFile::read_next_px(ui::Color& px, bool seek = true) {
|
|||
return true;
|
||||
}
|
||||
|
||||
bool BMPFile::read_next_px_cnt(ui::Color* px, uint32_t count, bool seek) {
|
||||
if (!is_opened) return false;
|
||||
size_t bytesneeded = byte_per_px * count;
|
||||
while (bytesneeded > 0) { // read in batches
|
||||
size_t currusedbytes = bytesneeded > 256 ? 85 * byte_per_px : bytesneeded; // don't mind this magic number.
|
||||
uint8_t buffer[currusedbytes];
|
||||
auto res = bmpimage.read(buffer, currusedbytes);
|
||||
if (res.is_error()) return false;
|
||||
for (uint32_t i = 0; i < currusedbytes; i += byte_per_px, px++) {
|
||||
switch (type) {
|
||||
case 5: {
|
||||
// ARGB1555
|
||||
uint16_t val = buffer[i] | (buffer[i + 1] << 8);
|
||||
// Extract components
|
||||
//*a = (val >> 15) & 0x01; // 1-bit alpha
|
||||
uint8_t r = (val >> 10) & 0x1F; // 5-bit red
|
||||
uint8_t g = (val >> 5) & 0x1F; // 5-bit green
|
||||
uint8_t b = (val) & 0x1F; // 5-bit blue
|
||||
// expand
|
||||
r = (r << 3) | (r >> 2);
|
||||
g = (g << 3) | (g >> 2);
|
||||
b = (b << 3) | (b >> 2);
|
||||
*px = ui::Color(r, g, b);
|
||||
break;
|
||||
}
|
||||
case 2: // 32
|
||||
*px = ui::Color(buffer[i + 2], buffer[i + 1], buffer[i]);
|
||||
break;
|
||||
|
||||
case 4: { // 8-bit
|
||||
// uint8_t index = buffer[0];
|
||||
// px = ui::Color(color_palette[index][2], color_palette[index][1], color_palette[index][0]); // Palette is BGR
|
||||
// px = ui::Color(buffer[0]); // niy, since needs a lot of ram for the palette
|
||||
break;
|
||||
}
|
||||
case 1: // 24
|
||||
default:
|
||||
*px = ui::Color(buffer[i + 2], buffer[i + 1], buffer[i]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
bytesneeded -= currusedbytes;
|
||||
}
|
||||
if (seek) advance_curr_px(count);
|
||||
return true;
|
||||
}
|
||||
|
||||
// if you set this, then the expanded part (or the newly created) will be filled with this color. but the expansion or the creation will be slower.
|
||||
void BMPFile::set_bg_color(ui::Color background) {
|
||||
bg = background;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue