# HG changeset patch # User Space Falcon # Date 1441621119 0 # Node ID 69623c4cbf6cf1c42e8a2e1df97c5dfbf461081f # Parent 841982f31be344e00e7a44e4364dae3e4c693896 lcdemu: image conversion implemented for X11 depth 24 diff -r 841982f31be3 -r 69623c4cbf6c lcdemu/Makefile --- a/lcdemu/Makefile Mon Sep 07 08:51:02 2015 +0000 +++ b/lcdemu/Makefile Mon Sep 07 10:18:39 2015 +0000 @@ -1,7 +1,7 @@ CC= gcc CFLAGS= -O2 PROG= fc-lcdemu -OBJS= globals.o main.o process.o window.o xrm.o +OBJS= globals.o main.o process.o window.o ximage.o xrm.o INSTBIN=/usr/local/bin all: ${PROG} diff -r 841982f31be3 -r 69623c4cbf6c lcdemu/globals.c --- a/lcdemu/globals.c Mon Sep 07 08:51:02 2015 +0000 +++ b/lcdemu/globals.c Mon Sep 07 10:18:39 2015 +0000 @@ -12,6 +12,9 @@ Display *mydisplay; Window mainwindow; GC mainwingc; +int display_depth; XrmDatabase xrmdb_defaults, xrmdb_displayres, xrmdb_cmdline; XrmQuark xrmquark_topclass, xrmquark_topinstance; + +XImage *(*convert_function)(); diff -r 841982f31be3 -r 69623c4cbf6c lcdemu/globals.h --- a/lcdemu/globals.h Mon Sep 07 08:51:02 2015 +0000 +++ b/lcdemu/globals.h Mon Sep 07 10:18:39 2015 +0000 @@ -8,6 +8,9 @@ extern Display *mydisplay; extern Window mainwindow; extern GC mainwingc; +extern int display_depth; extern XrmDatabase xrmdb_defaults, xrmdb_displayres, xrmdb_cmdline; extern XrmQuark xrmquark_topclass, xrmquark_topinstance; + +extern XImage *(*convert_function)(); diff -r 841982f31be3 -r 69623c4cbf6c lcdemu/main.c --- a/lcdemu/main.c Mon Sep 07 08:51:02 2015 +0000 +++ b/lcdemu/main.c Mon Sep 07 10:18:39 2015 +0000 @@ -19,6 +19,7 @@ XrmInitialize(); process_cmdline(argc, argv); open_display(); + init_image_conversion(); load_resources(); create_our_window(); set_initial_window_title(); diff -r 841982f31be3 -r 69623c4cbf6c lcdemu/ximage.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lcdemu/ximage.c Mon Sep 07 10:18:39 2015 +0000 @@ -0,0 +1,59 @@ +/* + * LCDemu based on HECterm by the same author + * XImage conversion muck + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include "globals.h" + +XImage * +convert_image_depth24(input, npix) + uint16_t *input; + int npix; +{ + uint32_t *imgbuf; + int i, in, r, g, b; + XImage *img; + + imgbuf = malloc(npix * 4); + if (!imgbuf) { + perror("malloc"); + exit(1); + } + for (i = 0; i < npix; i++) { + in = input[i]; + r = (in & 0xF800) << 8; + g = (in & 0x07E0) << 5; + b = (in & 0x001F) << 3; + imgbuf[i] = r | g | b; + } + img = XCreateImage(mydisplay, CopyFromParent, display_depth, ZPixmap, + 0, (char *) imgbuf, npix, 1, 32, 0); + if (!img) { + perror("XCreateImage"); + exit(1); + } + return(img); +} + +init_image_conversion() +{ + display_depth = DefaultDepth(mydisplay, DefaultScreen(mydisplay)); + switch (display_depth) { + case 24: + convert_function = convert_image_depth24; + break; + default: + fprintf(stderr, +"error: fc-ledemu has not been adapted for X11 depth != 24, yours is %d\n", + display_depth); + exit(1); + } +}