annotate fbt.c @ 10:078dc69945ad

working: libjpeg-turbo support, handle fb and monitor with different size
author Peter Meerwald <pmeerw@pmeerw.net>
date Sun, 15 May 2011 17:48:57 +0200
parents c7af696b6221
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2
bac8ed8d6eb9 add jpeg coding and test stuff
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
1 #include <stdlib.h>
bac8ed8d6eb9 add jpeg coding and test stuff
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
2 #include <stdio.h>
bac8ed8d6eb9 add jpeg coding and test stuff
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
3 #include <fcntl.h>
3
e8957085fe8a working
Peter Meerwald <pmeerw@pmeerw.net>
parents: 2
diff changeset
4 #include <unistd.h>
2
bac8ed8d6eb9 add jpeg coding and test stuff
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
5 #include <sys/ioctl.h>
8
66c77f9ba9b9 convert rgba -> rgb
Peter Meerwald <pmeerw@pmeerw.net>
parents: 3
diff changeset
6 #include <sys/mman.h>
2
bac8ed8d6eb9 add jpeg coding and test stuff
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
7
bac8ed8d6eb9 add jpeg coding and test stuff
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
8 #include "linux/fb.h"
bac8ed8d6eb9 add jpeg coding and test stuff
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
9
3
e8957085fe8a working
Peter Meerwald <pmeerw@pmeerw.net>
parents: 2
diff changeset
10 #include "common.h"
e8957085fe8a working
Peter Meerwald <pmeerw@pmeerw.net>
parents: 2
diff changeset
11
2
bac8ed8d6eb9 add jpeg coding and test stuff
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
12 int main(int argc, char *argv[]) {
bac8ed8d6eb9 add jpeg coding and test stuff
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
13
3
e8957085fe8a working
Peter Meerwald <pmeerw@pmeerw.net>
parents: 2
diff changeset
14 if (argc != 2) {
e8957085fe8a working
Peter Meerwald <pmeerw@pmeerw.net>
parents: 2
diff changeset
15 fprintf(stderr, "usage: fbt /dev/fbX\n");
e8957085fe8a working
Peter Meerwald <pmeerw@pmeerw.net>
parents: 2
diff changeset
16 exit(EXIT_FAILURE);
e8957085fe8a working
Peter Meerwald <pmeerw@pmeerw.net>
parents: 2
diff changeset
17 }
e8957085fe8a working
Peter Meerwald <pmeerw@pmeerw.net>
parents: 2
diff changeset
18
e8957085fe8a working
Peter Meerwald <pmeerw@pmeerw.net>
parents: 2
diff changeset
19 int fd = open(argv[1], O_RDWR);
2
bac8ed8d6eb9 add jpeg coding and test stuff
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
20 if (fd < 0) {
bac8ed8d6eb9 add jpeg coding and test stuff
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
21 perror("");
bac8ed8d6eb9 add jpeg coding and test stuff
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
22 exit(EXIT_FAILURE);
bac8ed8d6eb9 add jpeg coding and test stuff
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
23 }
bac8ed8d6eb9 add jpeg coding and test stuff
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
24
bac8ed8d6eb9 add jpeg coding and test stuff
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
25 struct fb_fix_screeninfo sif;
9
Peter Meerwald <pmeerw@pmeerw.net>
parents: 8
diff changeset
26 if (ioctl(fd, FBIOGET_FSCREENINFO, &sif) < 0) {
2
bac8ed8d6eb9 add jpeg coding and test stuff
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
27 perror("");
bac8ed8d6eb9 add jpeg coding and test stuff
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
28 exit(EXIT_FAILURE);
bac8ed8d6eb9 add jpeg coding and test stuff
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
29 }
bac8ed8d6eb9 add jpeg coding and test stuff
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
30
bac8ed8d6eb9 add jpeg coding and test stuff
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
31 printf("id %s\n", sif.id);
bac8ed8d6eb9 add jpeg coding and test stuff
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
32 printf("type %d, aux %d\n", sif.type, sif.type_aux);
bac8ed8d6eb9 add jpeg coding and test stuff
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
33 printf("visual %d\n", sif.visual);
bac8ed8d6eb9 add jpeg coding and test stuff
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
34 printf("accel %d\n", sif.accel);
bac8ed8d6eb9 add jpeg coding and test stuff
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
35 printf("line length %d\n", sif.line_length);
8
66c77f9ba9b9 convert rgba -> rgb
Peter Meerwald <pmeerw@pmeerw.net>
parents: 3
diff changeset
36 printf("mem %d\n", sif.smem_len);
2
bac8ed8d6eb9 add jpeg coding and test stuff
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
37
bac8ed8d6eb9 add jpeg coding and test stuff
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
38 struct fb_var_screeninfo siv;
bac8ed8d6eb9 add jpeg coding and test stuff
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
39 if (ioctl(fd, FBIOGET_VSCREENINFO, &siv) < 0) {
bac8ed8d6eb9 add jpeg coding and test stuff
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
40 perror("");
bac8ed8d6eb9 add jpeg coding and test stuff
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
41 exit(EXIT_FAILURE);
bac8ed8d6eb9 add jpeg coding and test stuff
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
42 }
bac8ed8d6eb9 add jpeg coding and test stuff
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
43
bac8ed8d6eb9 add jpeg coding and test stuff
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
44 printf("res x %d y %d\n", siv.xres, siv.yres);
bac8ed8d6eb9 add jpeg coding and test stuff
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
45 printf("bpp %d\n", siv.bits_per_pixel);
bac8ed8d6eb9 add jpeg coding and test stuff
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
46
8
66c77f9ba9b9 convert rgba -> rgb
Peter Meerwald <pmeerw@pmeerw.net>
parents: 3
diff changeset
47 size_t fb_mem_size = siv.xres * siv.yres * siv.bits_per_pixel / 8;
66c77f9ba9b9 convert rgba -> rgb
Peter Meerwald <pmeerw@pmeerw.net>
parents: 3
diff changeset
48 void *fb_mem = mmap(NULL, fb_mem_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
66c77f9ba9b9 convert rgba -> rgb
Peter Meerwald <pmeerw@pmeerw.net>
parents: 3
diff changeset
49 if (fb_mem == MAP_FAILED) {
66c77f9ba9b9 convert rgba -> rgb
Peter Meerwald <pmeerw@pmeerw.net>
parents: 3
diff changeset
50 perror("");
66c77f9ba9b9 convert rgba -> rgb
Peter Meerwald <pmeerw@pmeerw.net>
parents: 3
diff changeset
51 exit(EXIT_FAILURE);
66c77f9ba9b9 convert rgba -> rgb
Peter Meerwald <pmeerw@pmeerw.net>
parents: 3
diff changeset
52 }
66c77f9ba9b9 convert rgba -> rgb
Peter Meerwald <pmeerw@pmeerw.net>
parents: 3
diff changeset
53
3
e8957085fe8a working
Peter Meerwald <pmeerw@pmeerw.net>
parents: 2
diff changeset
54 printf("-------------\n");
e8957085fe8a working
Peter Meerwald <pmeerw@pmeerw.net>
parents: 2
diff changeset
55 fflush(stdout);
e8957085fe8a working
Peter Meerwald <pmeerw@pmeerw.net>
parents: 2
diff changeset
56
8
66c77f9ba9b9 convert rgba -> rgb
Peter Meerwald <pmeerw@pmeerw.net>
parents: 3
diff changeset
57 jpg_buf_t jpg_buf = build_jpg_from_fb((unsigned char *)fb_mem, siv.xres, siv.yres, siv.bits_per_pixel);
3
e8957085fe8a working
Peter Meerwald <pmeerw@pmeerw.net>
parents: 2
diff changeset
58
8
66c77f9ba9b9 convert rgba -> rgb
Peter Meerwald <pmeerw@pmeerw.net>
parents: 3
diff changeset
59 munmap(fb_mem, fb_mem_size);
3
e8957085fe8a working
Peter Meerwald <pmeerw@pmeerw.net>
parents: 2
diff changeset
60 close(fd);
e8957085fe8a working
Peter Meerwald <pmeerw@pmeerw.net>
parents: 2
diff changeset
61
e8957085fe8a working
Peter Meerwald <pmeerw@pmeerw.net>
parents: 2
diff changeset
62 printf("jpg %ld\n", jpg_buf.size);
e8957085fe8a working
Peter Meerwald <pmeerw@pmeerw.net>
parents: 2
diff changeset
63
e8957085fe8a working
Peter Meerwald <pmeerw@pmeerw.net>
parents: 2
diff changeset
64 FILE *f = fopen("test.jpg", "wb");
e8957085fe8a working
Peter Meerwald <pmeerw@pmeerw.net>
parents: 2
diff changeset
65 if (!f) {
e8957085fe8a working
Peter Meerwald <pmeerw@pmeerw.net>
parents: 2
diff changeset
66 fprintf(stderr, "fopen failed\n");
e8957085fe8a working
Peter Meerwald <pmeerw@pmeerw.net>
parents: 2
diff changeset
67 exit(EXIT_FAILURE);
e8957085fe8a working
Peter Meerwald <pmeerw@pmeerw.net>
parents: 2
diff changeset
68 }
e8957085fe8a working
Peter Meerwald <pmeerw@pmeerw.net>
parents: 2
diff changeset
69
e8957085fe8a working
Peter Meerwald <pmeerw@pmeerw.net>
parents: 2
diff changeset
70 fwrite(jpg_buf.ptr, 1, jpg_buf.size, f);
e8957085fe8a working
Peter Meerwald <pmeerw@pmeerw.net>
parents: 2
diff changeset
71
e8957085fe8a working
Peter Meerwald <pmeerw@pmeerw.net>
parents: 2
diff changeset
72 fclose(f);
e8957085fe8a working
Peter Meerwald <pmeerw@pmeerw.net>
parents: 2
diff changeset
73
e8957085fe8a working
Peter Meerwald <pmeerw@pmeerw.net>
parents: 2
diff changeset
74 free(jpg_buf.ptr);
e8957085fe8a working
Peter Meerwald <pmeerw@pmeerw.net>
parents: 2
diff changeset
75
2
bac8ed8d6eb9 add jpeg coding and test stuff
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
76 exit(EXIT_SUCCESS);
bac8ed8d6eb9 add jpeg coding and test stuff
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
77 }

Repositories maintained by Peter Meerwald, pmeerw@pmeerw.net.