Fix hackiness in converting a uint32_t to a Color, by providing a function to do so
This commit is contained in:
parent
03db57bbf9
commit
30411b4b78
@ -17,4 +17,6 @@ struct Color
|
||||
static Color Cyan;
|
||||
static Color Magenta;
|
||||
static Color Gray;
|
||||
|
||||
static Color from_integer(uint32_t source);
|
||||
} __attribute__((packed)); // to reinterpret this as a uint32_t AARRGGBB (in reversed order here because endianness)
|
@ -79,7 +79,6 @@ extern "C" void _start()
|
||||
{
|
||||
sleep(2);
|
||||
uint32_t color = (uint32_t)Mersenne::get();
|
||||
uint32_t* colptr = &color;
|
||||
x += xvel;
|
||||
y += yvel;
|
||||
if ((x + 10) >= framebuffer0.width())
|
||||
@ -102,7 +101,7 @@ extern "C" void _start()
|
||||
yvel = -yvel;
|
||||
y = 0;
|
||||
}
|
||||
framebuffer0.paint_rect(x, y, 10, 10, *(Color*)colptr);
|
||||
framebuffer0.paint_rect(x, y, 10, 10, Color::from_integer(color));
|
||||
}
|
||||
});
|
||||
|
||||
@ -111,10 +110,9 @@ extern "C" void _start()
|
||||
{
|
||||
sleep(100);
|
||||
uint32_t color = (uint32_t)Mersenne::get();
|
||||
uint32_t* colptr = &color;
|
||||
framebuffer0.paint_rect(Mersenne::get() % (framebuffer0.width() - 256),
|
||||
Mersenne::get() % (framebuffer0.height() - 256), Mersenne::get() % 255,
|
||||
Mersenne::get() % 255, *(Color*)colptr);
|
||||
Mersenne::get() % 255, Color::from_integer(color));
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -9,3 +9,13 @@ Color Color::Yellow = {0x00, 0xFF, 0xFF, 0xFF};
|
||||
Color Color::Cyan = {0xFF, 0xFF, 0x00, 0xFF};
|
||||
Color Color::Magenta = {0xFF, 0x00, 0xFF, 0xFF};
|
||||
Color Color::Gray = {0x80, 0x80, 0x80, 0xFF};
|
||||
|
||||
#pragma GCC push_options
|
||||
#pragma GCC diagnostic ignored "-Wstrict-aliasing"
|
||||
|
||||
Color Color::from_integer(uint32_t source)
|
||||
{
|
||||
return reinterpret_cast<Color&>(source);
|
||||
}
|
||||
|
||||
#pragma GCC pop_options
|
@ -19,9 +19,8 @@ void sys_paint(Context* context, uint64_t x, uint64_t y, uint64_t w, uint64_t h,
|
||||
}
|
||||
|
||||
uint32_t color = (uint32_t)c;
|
||||
uint32_t* colptr = &color;
|
||||
|
||||
framebuffer0.paint_rect(x, y, w, h, *(Color*)colptr);
|
||||
framebuffer0.paint_rect(x, y, w, h, Color::from_integer(color));
|
||||
|
||||
context->rax = 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user