annotate lcdemu/ximage.c @ 9:6c35c9f2ecab

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