FreeCalypso > hg > freecalypso-sw
annotate lcdemu/ximage.c @ 992:a7b0b426f9ca
target-utils: boot ROM UART autodetection revamped
The new implementation should work with both the familiar Calypso C035
boot ROM version found in our regular targets as well as the older
Calypso F741979B version found on the vintage D-Sample board.
author | Mychaela Falconia <falcon@ivan.Harhan.ORG> |
---|---|
date | Wed, 30 Dec 2015 21:28:41 +0000 |
parents | 7a189b7bbd67 |
children |
rev | line source |
---|---|
906
69623c4cbf6c
lcdemu: image conversion implemented for X11 depth 24
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
1 /* |
69623c4cbf6c
lcdemu: image conversion implemented for X11 depth 24
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
2 * LCDemu based on HECterm by the same author |
69623c4cbf6c
lcdemu: image conversion implemented for X11 depth 24
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
3 * XImage conversion muck |
69623c4cbf6c
lcdemu: image conversion implemented for X11 depth 24
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
4 */ |
69623c4cbf6c
lcdemu: image conversion implemented for X11 depth 24
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
5 |
69623c4cbf6c
lcdemu: image conversion implemented for X11 depth 24
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
6 #include <stdio.h> |
69623c4cbf6c
lcdemu: image conversion implemented for X11 depth 24
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
7 #include <stdint.h> |
69623c4cbf6c
lcdemu: image conversion implemented for X11 depth 24
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
8 #include <stdlib.h> |
69623c4cbf6c
lcdemu: image conversion implemented for X11 depth 24
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
9 #include <string.h> |
69623c4cbf6c
lcdemu: image conversion implemented for X11 depth 24
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
10 #include <strings.h> |
69623c4cbf6c
lcdemu: image conversion implemented for X11 depth 24
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
11 #include <X11/Xlib.h> |
69623c4cbf6c
lcdemu: image conversion implemented for X11 depth 24
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
12 #include <X11/Xresource.h> |
69623c4cbf6c
lcdemu: image conversion implemented for X11 depth 24
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
13 #include <X11/Xutil.h> |
69623c4cbf6c
lcdemu: image conversion implemented for X11 depth 24
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
14 #include "globals.h" |
69623c4cbf6c
lcdemu: image conversion implemented for X11 depth 24
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
15 |
69623c4cbf6c
lcdemu: image conversion implemented for X11 depth 24
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
16 XImage * |
69623c4cbf6c
lcdemu: image conversion implemented for X11 depth 24
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
17 convert_image_depth24(input, npix) |
69623c4cbf6c
lcdemu: image conversion implemented for X11 depth 24
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
18 uint16_t *input; |
69623c4cbf6c
lcdemu: image conversion implemented for X11 depth 24
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
19 int npix; |
69623c4cbf6c
lcdemu: image conversion implemented for X11 depth 24
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
20 { |
69623c4cbf6c
lcdemu: image conversion implemented for X11 depth 24
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
21 uint32_t *imgbuf; |
69623c4cbf6c
lcdemu: image conversion implemented for X11 depth 24
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
22 int i, in, r, g, b; |
69623c4cbf6c
lcdemu: image conversion implemented for X11 depth 24
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
23 XImage *img; |
69623c4cbf6c
lcdemu: image conversion implemented for X11 depth 24
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
24 |
69623c4cbf6c
lcdemu: image conversion implemented for X11 depth 24
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
25 imgbuf = malloc(npix * 4); |
69623c4cbf6c
lcdemu: image conversion implemented for X11 depth 24
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
26 if (!imgbuf) { |
69623c4cbf6c
lcdemu: image conversion implemented for X11 depth 24
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
27 perror("malloc"); |
69623c4cbf6c
lcdemu: image conversion implemented for X11 depth 24
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
28 exit(1); |
69623c4cbf6c
lcdemu: image conversion implemented for X11 depth 24
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
29 } |
69623c4cbf6c
lcdemu: image conversion implemented for X11 depth 24
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
30 for (i = 0; i < npix; i++) { |
69623c4cbf6c
lcdemu: image conversion implemented for X11 depth 24
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
31 in = input[i]; |
69623c4cbf6c
lcdemu: image conversion implemented for X11 depth 24
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
32 r = (in & 0xF800) << 8; |
69623c4cbf6c
lcdemu: image conversion implemented for X11 depth 24
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
33 g = (in & 0x07E0) << 5; |
69623c4cbf6c
lcdemu: image conversion implemented for X11 depth 24
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
34 b = (in & 0x001F) << 3; |
69623c4cbf6c
lcdemu: image conversion implemented for X11 depth 24
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
35 imgbuf[i] = r | g | b; |
69623c4cbf6c
lcdemu: image conversion implemented for X11 depth 24
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
36 } |
69623c4cbf6c
lcdemu: image conversion implemented for X11 depth 24
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
37 img = XCreateImage(mydisplay, CopyFromParent, display_depth, ZPixmap, |
69623c4cbf6c
lcdemu: image conversion implemented for X11 depth 24
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
38 0, (char *) imgbuf, npix, 1, 32, 0); |
69623c4cbf6c
lcdemu: image conversion implemented for X11 depth 24
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
39 if (!img) { |
69623c4cbf6c
lcdemu: image conversion implemented for X11 depth 24
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
40 perror("XCreateImage"); |
69623c4cbf6c
lcdemu: image conversion implemented for X11 depth 24
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
41 exit(1); |
69623c4cbf6c
lcdemu: image conversion implemented for X11 depth 24
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
42 } |
69623c4cbf6c
lcdemu: image conversion implemented for X11 depth 24
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
43 return(img); |
69623c4cbf6c
lcdemu: image conversion implemented for X11 depth 24
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
44 } |
69623c4cbf6c
lcdemu: image conversion implemented for X11 depth 24
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
45 |
69623c4cbf6c
lcdemu: image conversion implemented for X11 depth 24
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
46 init_image_conversion() |
69623c4cbf6c
lcdemu: image conversion implemented for X11 depth 24
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
47 { |
69623c4cbf6c
lcdemu: image conversion implemented for X11 depth 24
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
48 display_depth = DefaultDepth(mydisplay, DefaultScreen(mydisplay)); |
69623c4cbf6c
lcdemu: image conversion implemented for X11 depth 24
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
49 switch (display_depth) { |
69623c4cbf6c
lcdemu: image conversion implemented for X11 depth 24
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
50 case 24: |
69623c4cbf6c
lcdemu: image conversion implemented for X11 depth 24
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
51 convert_function = convert_image_depth24; |
69623c4cbf6c
lcdemu: image conversion implemented for X11 depth 24
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
52 break; |
69623c4cbf6c
lcdemu: image conversion implemented for X11 depth 24
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
53 default: |
69623c4cbf6c
lcdemu: image conversion implemented for X11 depth 24
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
54 fprintf(stderr, |
907
7a189b7bbd67
lcdemu: input processing implemented, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
906
diff
changeset
|
55 "error: fc-lcdemu has not been adapted for X11 depth != 24, yours is %d\n", |
906
69623c4cbf6c
lcdemu: image conversion implemented for X11 depth 24
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
56 display_depth); |
69623c4cbf6c
lcdemu: image conversion implemented for X11 depth 24
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
57 exit(1); |
69623c4cbf6c
lcdemu: image conversion implemented for X11 depth 24
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
58 } |
69623c4cbf6c
lcdemu: image conversion implemented for X11 depth 24
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
59 } |