diff lcdemu/ximage.c @ 0:e7502631a0f9

initial import from freecalypso-sw rev 1033:5ab737ac3ad7
author Mychaela Falconia <falcon@freecalypso.org>
date Sat, 11 Jun 2016 00:13:35 +0000
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/lcdemu/ximage.c	Sat Jun 11 00:13:35 2016 +0000
@@ -0,0 +1,59 @@
+/*
+ * LCDemu based on HECterm by the same author
+ * XImage conversion muck
+ */
+
+#include <stdio.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <string.h>
+#include <strings.h>
+#include <X11/Xlib.h>
+#include <X11/Xresource.h>
+#include <X11/Xutil.h>
+#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-lcdemu has not been adapted for X11 depth != 24, yours is %d\n",
+			display_depth);
+		exit(1);
+	}
+}