Mercurial > hg > minimon
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 |
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 | 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 | 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 | 10 #include "common.h" |
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 | 14 if (argc != 2) { |
15 fprintf(stderr, "usage: fbt /dev/fbX\n"); | |
16 exit(EXIT_FAILURE); | |
17 } | |
18 | |
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 | 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 | 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 | 47 size_t fb_mem_size = siv.xres * siv.yres * siv.bits_per_pixel / 8; |
48 void *fb_mem = mmap(NULL, fb_mem_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); | |
49 if (fb_mem == MAP_FAILED) { | |
50 perror(""); | |
51 exit(EXIT_FAILURE); | |
52 } | |
53 | |
3 | 54 printf("-------------\n"); |
55 fflush(stdout); | |
56 | |
8 | 57 jpg_buf_t jpg_buf = build_jpg_from_fb((unsigned char *)fb_mem, siv.xres, siv.yres, siv.bits_per_pixel); |
3 | 58 |
8 | 59 munmap(fb_mem, fb_mem_size); |
3 | 60 close(fd); |
61 | |
62 printf("jpg %ld\n", jpg_buf.size); | |
63 | |
64 FILE *f = fopen("test.jpg", "wb"); | |
65 if (!f) { | |
66 fprintf(stderr, "fopen failed\n"); | |
67 exit(EXIT_FAILURE); | |
68 } | |
69 | |
70 fwrite(jpg_buf.ptr, 1, jpg_buf.size, f); | |
71 | |
72 fclose(f); | |
73 | |
74 free(jpg_buf.ptr); | |
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 } |