FreeCalypso > hg > freecalypso-ui-dev
comparison lcdemu/ximage.c @ 0:e7f1035f10d4
lcdemu: initial import from freecalypso-tools
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Wed, 14 Mar 2018 18:16:45 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:e7f1035f10d4 |
---|---|
1 /* | |
2 * LCDemu based on HECterm by the same author | |
3 * XImage conversion muck | |
4 */ | |
5 | |
6 #include <stdio.h> | |
7 #include <stdint.h> | |
8 #include <stdlib.h> | |
9 #include <string.h> | |
10 #include <strings.h> | |
11 #include <X11/Xlib.h> | |
12 #include <X11/Xresource.h> | |
13 #include <X11/Xutil.h> | |
14 #include "globals.h" | |
15 | |
16 XImage * | |
17 convert_image_depth24(input, npix) | |
18 uint16_t *input; | |
19 int npix; | |
20 { | |
21 uint32_t *imgbuf; | |
22 int i, in, r, g, b; | |
23 XImage *img; | |
24 | |
25 imgbuf = malloc(npix * 4); | |
26 if (!imgbuf) { | |
27 perror("malloc"); | |
28 exit(1); | |
29 } | |
30 for (i = 0; i < npix; i++) { | |
31 in = input[i]; | |
32 r = (in & 0xF800) << 8; | |
33 g = (in & 0x07E0) << 5; | |
34 b = (in & 0x001F) << 3; | |
35 imgbuf[i] = r | g | b; | |
36 } | |
37 img = XCreateImage(mydisplay, CopyFromParent, display_depth, ZPixmap, | |
38 0, (char *) imgbuf, npix, 1, 32, 0); | |
39 if (!img) { | |
40 perror("XCreateImage"); | |
41 exit(1); | |
42 } | |
43 return(img); | |
44 } | |
45 | |
46 init_image_conversion() | |
47 { | |
48 display_depth = DefaultDepth(mydisplay, DefaultScreen(mydisplay)); | |
49 switch (display_depth) { | |
50 case 24: | |
51 convert_function = convert_image_depth24; | |
52 break; | |
53 default: | |
54 fprintf(stderr, | |
55 "error: fc-lcdemu has not been adapted for X11 depth != 24, yours is %d\n", | |
56 display_depth); | |
57 exit(1); | |
58 } | |
59 } |