mirror of
https://github.com/italicsjenga/rust_minifb.git
synced 2024-12-23 19:31:30 +11:00
Added x16 and x32 scale to X11
This commit is contained in:
parent
8d7eb6b000
commit
3d70a5c7dc
|
@ -170,6 +170,7 @@ void* mfb_open(const char* title, int width, int height, unsigned int flags, int
|
||||||
Window window;
|
Window window;
|
||||||
WindowInfo* window_info;
|
WindowInfo* window_info;
|
||||||
|
|
||||||
|
|
||||||
if (!setup_display()) {
|
if (!setup_display()) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -526,12 +527,65 @@ static void scale_4x(unsigned int* dest, unsigned int* source, int width, int he
|
||||||
dest[(width * offset) + 6] = t; \
|
dest[(width * offset) + 6] = t; \
|
||||||
dest[(width * offset) + 7] = t;
|
dest[(width * offset) + 7] = t;
|
||||||
|
|
||||||
|
#define write_16(offset) \
|
||||||
|
dest[(width * offset) + 0] = t; \
|
||||||
|
dest[(width * offset) + 1] = t; \
|
||||||
|
dest[(width * offset) + 2] = t; \
|
||||||
|
dest[(width * offset) + 3] = t; \
|
||||||
|
dest[(width * offset) + 4] = t; \
|
||||||
|
dest[(width * offset) + 5] = t; \
|
||||||
|
dest[(width * offset) + 6] = t; \
|
||||||
|
dest[(width * offset) + 7] = t; \
|
||||||
|
dest[(width * offset) + 8] = t; \
|
||||||
|
dest[(width * offset) + 9] = t; \
|
||||||
|
dest[(width * offset) + 10] = t; \
|
||||||
|
dest[(width * offset) + 11] = t; \
|
||||||
|
dest[(width * offset) + 12] = t; \
|
||||||
|
dest[(width * offset) + 13] = t; \
|
||||||
|
dest[(width * offset) + 14] = t; \
|
||||||
|
dest[(width * offset) + 15] = t;
|
||||||
|
|
||||||
|
#define write_32(offset) \
|
||||||
|
dest[(width * offset) + 0] = t; \
|
||||||
|
dest[(width * offset) + 1] = t; \
|
||||||
|
dest[(width * offset) + 2] = t; \
|
||||||
|
dest[(width * offset) + 3] = t; \
|
||||||
|
dest[(width * offset) + 4] = t; \
|
||||||
|
dest[(width * offset) + 5] = t; \
|
||||||
|
dest[(width * offset) + 6] = t; \
|
||||||
|
dest[(width * offset) + 7] = t; \
|
||||||
|
dest[(width * offset) + 8] = t; \
|
||||||
|
dest[(width * offset) + 9] = t; \
|
||||||
|
dest[(width * offset) + 10] = t; \
|
||||||
|
dest[(width * offset) + 11] = t; \
|
||||||
|
dest[(width * offset) + 12] = t; \
|
||||||
|
dest[(width * offset) + 13] = t; \
|
||||||
|
dest[(width * offset) + 14] = t; \
|
||||||
|
dest[(width * offset) + 15] = t; \
|
||||||
|
dest[(width * offset) + 16] = t; \
|
||||||
|
dest[(width * offset) + 17] = t; \
|
||||||
|
dest[(width * offset) + 18] = t; \
|
||||||
|
dest[(width * offset) + 19] = t; \
|
||||||
|
dest[(width * offset) + 20] = t; \
|
||||||
|
dest[(width * offset) + 21] = t; \
|
||||||
|
dest[(width * offset) + 22] = t; \
|
||||||
|
dest[(width * offset) + 23] = t; \
|
||||||
|
dest[(width * offset) + 24] = t; \
|
||||||
|
dest[(width * offset) + 25] = t; \
|
||||||
|
dest[(width * offset) + 26] = t; \
|
||||||
|
dest[(width * offset) + 27] = t; \
|
||||||
|
dest[(width * offset) + 28] = t; \
|
||||||
|
dest[(width * offset) + 29] = t; \
|
||||||
|
dest[(width * offset) + 30] = t; \
|
||||||
|
dest[(width * offset) + 31] = t;
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
static void scale_8x(unsigned int* dest, unsigned int* source, int width, int height, int scale) {
|
void scale_8x(unsigned int* dest, unsigned int* source, int width, int height, int scale) {
|
||||||
int x, y;
|
int x, y;
|
||||||
for (y = 0; y < height; y += scale) {
|
scale = 8;
|
||||||
for (x = 0; x < width; x += scale) {
|
for (y = 0; y < height; y += 8) {
|
||||||
|
for (x = 0; x < width; x += 8) {
|
||||||
const unsigned int t = *source++;
|
const unsigned int t = *source++;
|
||||||
|
|
||||||
write_8(0);
|
write_8(0);
|
||||||
|
@ -552,6 +606,89 @@ static void scale_8x(unsigned int* dest, unsigned int* source, int width, int he
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
void scale_16x(unsigned int* dest, unsigned int* source, int width, int height, int scale) {
|
||||||
|
int x, y;
|
||||||
|
scale = 16;
|
||||||
|
for (y = 0; y < height; y += scale) {
|
||||||
|
for (x = 0; x < width; x += scale) {
|
||||||
|
const unsigned int t = *source++;
|
||||||
|
|
||||||
|
write_16(0);
|
||||||
|
write_16(1);
|
||||||
|
write_16(2);
|
||||||
|
write_16(3);
|
||||||
|
write_16(4);
|
||||||
|
write_16(5);
|
||||||
|
write_16(6);
|
||||||
|
write_16(7);
|
||||||
|
write_16(8);
|
||||||
|
write_16(9);
|
||||||
|
write_16(10);
|
||||||
|
write_16(11);
|
||||||
|
write_16(12);
|
||||||
|
write_16(13);
|
||||||
|
write_16(14);
|
||||||
|
write_16(15);
|
||||||
|
|
||||||
|
dest += scale;
|
||||||
|
}
|
||||||
|
|
||||||
|
dest += width * (scale - 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
void scale_32x(unsigned int* dest, unsigned int* source, int width, int height, int scale) {
|
||||||
|
int x, y;
|
||||||
|
|
||||||
|
for (y = 0; y < scale; y += scale) {
|
||||||
|
for (x = 0; x < width; x += scale) {
|
||||||
|
const unsigned int t = *source++;
|
||||||
|
|
||||||
|
write_32(0);
|
||||||
|
write_32(1);
|
||||||
|
write_32(2);
|
||||||
|
write_32(3);
|
||||||
|
write_32(4);
|
||||||
|
write_32(5);
|
||||||
|
write_32(6);
|
||||||
|
write_32(7);
|
||||||
|
write_32(8);
|
||||||
|
write_32(9);
|
||||||
|
write_32(10);
|
||||||
|
write_32(11);
|
||||||
|
write_32(12);
|
||||||
|
write_32(13);
|
||||||
|
write_32(14);
|
||||||
|
write_32(15);
|
||||||
|
|
||||||
|
write_32(16);
|
||||||
|
write_32(17);
|
||||||
|
write_32(18);
|
||||||
|
write_32(19);
|
||||||
|
write_32(20);
|
||||||
|
write_32(21);
|
||||||
|
write_32(22);
|
||||||
|
write_32(23);
|
||||||
|
write_32(24);
|
||||||
|
write_32(25);
|
||||||
|
write_32(26);
|
||||||
|
write_32(27);
|
||||||
|
write_32(28);
|
||||||
|
write_32(29);
|
||||||
|
write_32(30);
|
||||||
|
write_32(31);
|
||||||
|
|
||||||
|
dest += scale;
|
||||||
|
}
|
||||||
|
|
||||||
|
dest += width * (scale - 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
void mfb_update_with_buffer(void* window_info, void* buffer)
|
void mfb_update_with_buffer(void* window_info, void* buffer)
|
||||||
{
|
{
|
||||||
WindowInfo* info = (WindowInfo*)window_info;
|
WindowInfo* info = (WindowInfo*)window_info;
|
||||||
|
@ -579,6 +716,16 @@ void mfb_update_with_buffer(void* window_info, void* buffer)
|
||||||
scale_8x(info->draw_buffer, buffer, width, height, scale);
|
scale_8x(info->draw_buffer, buffer, width, height, scale);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case 16: {
|
||||||
|
scale_16x(info->draw_buffer, buffer, width, height, scale);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case 32: {
|
||||||
|
scale_32x(info->draw_buffer, buffer, width, height, scale);
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
XPutImage(s_display, info->window, s_gc, info->ximage, 0, 0, 0, 0, width, height);
|
XPutImage(s_display, info->window, s_gc, info->ximage, 0, 0, 0, 0, width, height);
|
||||||
|
|
|
@ -375,6 +375,8 @@ impl Window {
|
||||||
Scale::X2 => 2,
|
Scale::X2 => 2,
|
||||||
Scale::X4 => 4,
|
Scale::X4 => 4,
|
||||||
Scale::X8 => 8,
|
Scale::X8 => 8,
|
||||||
|
Scale::X16 => 16,
|
||||||
|
Scale::X32 => 32,
|
||||||
Scale::FitScreen => {
|
Scale::FitScreen => {
|
||||||
let wh: u32 = mfb_get_screen_size();
|
let wh: u32 = mfb_get_screen_size();
|
||||||
let screen_x = (wh >> 16) as i32;
|
let screen_x = (wh >> 16) as i32;
|
||||||
|
@ -395,17 +397,12 @@ impl Window {
|
||||||
scale *= 2;
|
scale *= 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
if scale >= 8 {
|
if scale >= 32 {
|
||||||
8
|
32
|
||||||
} else {
|
} else {
|
||||||
scale
|
scale
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_ => {
|
|
||||||
println!("Scale above 4 not support currently, defaults to 4");
|
|
||||||
4
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
return factor;
|
return factor;
|
||||||
|
|
Loading…
Reference in a new issue