aboutsummaryrefslogtreecommitdiffstats
path: root/com32/lib/sys/vesa/background.c
diff options
context:
space:
mode:
Diffstat (limited to 'com32/lib/sys/vesa/background.c')
-rw-r--r--com32/lib/sys/vesa/background.c59
1 files changed, 35 insertions, 24 deletions
diff --git a/com32/lib/sys/vesa/background.c b/com32/lib/sys/vesa/background.c
index 815f984c..60ff1f2b 100644
--- a/com32/lib/sys/vesa/background.c
+++ b/com32/lib/sys/vesa/background.c
@@ -44,9 +44,9 @@
aligned dwords. */
static void draw_background_line(int line, int start, int npixels)
{
- uint32_t *bgptr = &__vesacon_background[line][start];
+ uint32_t *bgptr = &__vesacon_background[line*__vesa_info.mi.h_res+start];
unsigned int bytes_per_pixel = __vesacon_bytes_per_pixel;
- size_t fbptr = line * __vesa_info.mi.logical_scan + start * bytes_per_pixel;
+ size_t fbptr = line * __vesa_info.mi.logical_scan + start*bytes_per_pixel;
__vesacon_copy_to_screen(fbptr, bgptr, npixels);
}
@@ -60,15 +60,17 @@ static void draw_background(void)
const int right_border = VIDEO_BORDER + (TEXT_PIXEL_COLS % FONT_WIDTH);
for (i = 0; i < VIDEO_BORDER; i++)
- draw_background_line(i, 0, VIDEO_X_SIZE);
+ draw_background_line(i, 0, __vesa_info.mi.h_res);
- for (i = VIDEO_BORDER; i < VIDEO_Y_SIZE - bottom_border; i++) {
+ for (i = VIDEO_BORDER; i < __vesa_info.mi.v_res - bottom_border; i++) {
draw_background_line(i, 0, VIDEO_BORDER);
- draw_background_line(i, VIDEO_X_SIZE - right_border, right_border);
+ draw_background_line(i, __vesa_info.mi.h_res - right_border,
+ right_border);
}
- for (i = VIDEO_Y_SIZE - bottom_border; i < VIDEO_Y_SIZE; i++)
- draw_background_line(i, 0, VIDEO_X_SIZE);
+ for (i = __vesa_info.mi.v_res - bottom_border;
+ i < __vesa_info.mi.v_res; i++)
+ draw_background_line(i, 0, __vesa_info.mi.h_res);
__vesacon_redraw_text();
}
@@ -82,7 +84,7 @@ static int read_png_file(FILE * fp)
png_color_16p image_background;
static const png_color_16 my_background = { 0, 0, 0, 0, 0 };
#endif
- png_bytep row_pointers[VIDEO_Y_SIZE];
+ png_bytep row_pointers[__vesa_info.mi.v_res], rp;
int passes;
int i;
int rv = -1;
@@ -98,7 +100,7 @@ static int read_png_file(FILE * fp)
png_init_io(png_ptr, fp);
png_set_sig_bytes(png_ptr, 8);
- png_set_user_limits(png_ptr, VIDEO_X_SIZE, VIDEO_Y_SIZE);
+ png_set_user_limits(png_ptr, __vesa_info.mi.h_res, __vesa_info.mi.v_res);
png_read_info(png_ptr, info_ptr);
@@ -138,8 +140,11 @@ static int read_png_file(FILE * fp)
#endif
/* Whew! Now we should get the stuff we want... */
- for (i = 0; i < (int)info_ptr->height; i++)
- row_pointers[i] = (void *)__vesacon_background[i];
+ rp = (png_bytep)__vesacon_background;
+ for (i = 0; i < (int)info_ptr->height; i++) {
+ row_pointers[i] = rp;
+ rp += __vesa_info.mi.h_res << 2;
+ }
passes = png_set_interlace_handling(png_ptr);
@@ -157,7 +162,9 @@ err:
static int jpeg_sig_cmp(uint8_t * bytes, int len)
{
(void)len;
- return (bytes[0] == 0xff && bytes[1] == 0xd8) ? 0 : -1;
+
+ /* FF D8 = start of image, FF E0 = JFIF header */
+ return memcmp(bytes, "\xff\xd8\xff\xe0", 4) ? -1 : 0;
}
static int read_jpeg_file(FILE * fp, uint8_t * header, int len)
@@ -183,12 +190,12 @@ static int read_jpeg_file(FILE * fp, uint8_t * header, int len)
goto err;
tinyjpeg_get_size(jdec, &width, &height);
- if (width > VIDEO_X_SIZE || height > VIDEO_Y_SIZE)
+ if (width > __vesa_info.mi.h_res || height > __vesa_info.mi.v_res)
goto err;
- components[0] = (void *)&__vesacon_background[0];
+ components[0] = (void *)__vesacon_background;
tinyjpeg_set_components(jdec, components, 1);
- bytes_per_row[0] = VIDEO_X_SIZE << 2;
+ bytes_per_row[0] = __vesa_info.mi.h_res << 2;
tinyjpeg_set_bytes_per_row(jdec, bytes_per_row, 1);
tinyjpeg_decode(jdec, TINYJPEG_FMT_BGRA32);
@@ -217,9 +224,11 @@ int vesacon_default_background(void)
if (__vesacon_pixel_format == PXF_NONE)
return 0; /* Not in graphics mode */
- for (y = 0, dy = -VIDEO_Y_SIZE / 2; y < VIDEO_Y_SIZE; y++, dy++) {
+ for (y = 0, dy = -__vesa_info.mi.v_res / 2;
+ y < __vesa_info.mi.v_res; y++, dy++) {
dy2 = dy * dy;
- for (x = 0, dx = -VIDEO_X_SIZE / 2; x < VIDEO_X_SIZE; x++, dx++) {
+ for (x = 0, dx = -__vesa_info.mi.h_res / 2;
+ x < __vesa_info.mi.h_res; x++, dx++) {
k = __vesacon_linear_to_srgb[500 + ((dx * dx + dy2) >> 6)];
bgptr[0] = k; /* Blue */
bgptr[1] = k; /* Green */
@@ -236,7 +245,7 @@ int vesacon_default_background(void)
int vesacon_set_background(unsigned int rgb)
{
void *bgptr = __vesacon_background;
- unsigned int count = VIDEO_X_SIZE * VIDEO_Y_SIZE;
+ unsigned int count = __vesa_info.mi.h_res * __vesa_info.mi.v_res;
if (__vesacon_pixel_format == PXF_NONE)
return 0; /* Not in graphics mode */
@@ -265,7 +274,8 @@ static inline int lss16_sig_cmp(const void *header, int len)
return 1;
return !(h->magic == LSS16_MAGIC &&
- h->xsize <= VIDEO_X_SIZE && h->ysize <= VIDEO_Y_SIZE);
+ h->xsize <= __vesa_info.mi.h_res &&
+ h->ysize <= __vesa_info.mi.v_res);
}
static int read_lss16_file(FILE * fp, const void *header, int header_len)
@@ -283,7 +293,7 @@ static int read_lss16_file(FILE * fp, const void *header, int header_len)
st_c2,
} state;
int i, x, y;
- uint32_t *bgptr = (void *)__vesacon_background;
+ uint32_t *bgptr = __vesacon_background;
/* Assume the header, 8 bytes, has already been loaded. */
if (header_len != 8)
@@ -295,7 +305,8 @@ static int read_lss16_file(FILE * fp, const void *header, int header_len)
return -1;
colors[i] = (((rgb[0] & 63) * 255 / 63) << 16) +
- (((rgb[1] & 63) * 255 / 63) << 8) + ((rgb[2] & 63) * 255 / 63);
+ (((rgb[1] & 63) * 255 / 63) << 8) +
+ ((rgb[2] & 63) * 255 / 63);
}
/* By spec, the state machine is per row */
@@ -356,12 +367,12 @@ do_run:
}
/* Zero-fill rest of row */
- i = VIDEO_X_SIZE - x;
+ i = __vesa_info.mi.h_res - x;
asm volatile ("rep; stosl":"+D" (bgptr), "+c"(i):"a"(0):"memory");
}
/* Zero-fill rest of screen */
- i = (VIDEO_Y_SIZE - y) * VIDEO_X_SIZE;
+ i = (__vesa_info.mi.v_res - y) * __vesa_info.mi.h_res;
asm volatile ("rep; stosl":"+D" (bgptr), "+c"(i):"a"(0):"memory");
return 0;
@@ -404,7 +415,7 @@ err:
int __vesacon_init_background(void)
{
- /* The BSS clearing has already cleared __vesacon_background */
+ /* __vesacon_background was cleared by calloc() */
/* The VESA BIOS has already cleared the screen */
return 0;