fbui | Framebuffer-based graphical environment |
| download: https://git.y1.nz/archives/fbui.tar.gz | |
| README | Files | Log | Refs |
libfbui/Dump/main.c
1
2 /*=========================================================================
3 *
4 * fbdump, a screen dumper for FBUI (in-kernel framebuffer UI)
5 * Copyright (C) 2004 Zachary T Smith, fbui@comcast.net
6 *
7 * This module is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This module is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this module; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 *
21 * (See the file COPYING in the main directory of this archive for
22 * more details.)
23 *
24 *=======================================================================*/
25
26
27 /* Copyright (C) 2004 by Zack T Smith */
28
29 #include <stdio.h>
30 #include <sys/types.h>
31 #include <sys/stat.h>
32 #include <fcntl.h>
33 #include <sys/ioctl.h>
34 #include <linux/fb.h>
35 #include <sys/mman.h>
36
37 #include <linux/fb.h>
38 #include <jpeglib.h>
39
40
41 JSAMPLE * image_buffer;
42 int image_height;
43 int image_width;
44
45 static struct fb_fix_screeninfo fi;
46 static struct fb_var_screeninfo vi;
47
48
49 extern int read_JPEG_file (char*);
50
51 int
52 main(int argc, char** argv)
53 {
54 int i,j;
55 char *path="dump.jpg";
56 int fd;
57 unsigned char *buf = NULL;
58 unsigned long buflen = 0;
59 int bpp;
60 int bytes_per_pixel;
61
62 image_buffer=NULL;
63 image_height=0;
64 image_width=0;
65
66 i=1;
67 while(i<argc) {
68 if ('-' != *argv[i]) {
69 path=argv[i];
70 break;
71 }
72 i++;
73 }
74
75 fd = open ("/dev/fb0", O_RDWR );
76 if (fd == -1)
77 fd = open ("/dev/fb/0", O_RDWR );
78 if (fd == -1)
79 {
80 perror("open");
81 exit(1);
82 }
83 else
84 {
85 if (ioctl (fd, FBIOGET_FSCREENINFO, &fi))
86 {
87 perror("ioctl");
88 exit(1);
89 }
90 else
91 if (ioctl (fd, FBIOGET_VSCREENINFO, &vi))
92 {
93 perror("ioctl");
94 exit(1);
95 }
96 else
97 {
98 if (fi.visual != FB_VISUAL_TRUECOLOR &&
99 fi.visual != FB_VISUAL_DIRECTCOLOR )
100 {
101 fprintf (stderr, "error: need direct/truecolor display\n");
102 exit(1);
103 }
104 else
105 {
106 buf = (unsigned char*) fi.smem_start;
107 buflen = fi.smem_len;
108 buf = mmap (buf, buflen,
109 PROT_WRITE | PROT_READ,
110 MAP_SHARED, fd, 0);
111 if (buf == MAP_FAILED)
112 {
113 perror ("mmap");
114 exit(1);
115 }
116 }
117 }
118 }
119
120 printf ("Framebuffer resolution: %dx%d, %dbpp\n",
121 vi.xres, vi.yres, vi.bits_per_pixel);
122
123 image_width = vi.xres;
124 image_height = vi.yres;
125 bpp = vi.bits_per_pixel;
126 bytes_per_pixel = (bpp+7)>>3;
127
128 image_buffer = (JSAMPLE*) malloc (image_width * image_height * 3);
129 if (!image_buffer) {
130 fprintf (stderr,"error: cannot allocate pixel buffer\n");
131 exit(1);
132 }
133
134 unsigned char ro = vi.red.offset;
135 unsigned char go = vi.green.offset;
136 unsigned char bo = vi.blue.offset;
137 unsigned char rl = vi.red.length;
138 unsigned char gl = vi.green.length;
139 unsigned char bl = vi.blue.length;
140
141 unsigned long ix = 0;
142
143 for (j=0; j<image_height; j++) {
144 unsigned char *ptr = buf + fi.line_length * j;
145 unsigned long value=0;
146 int x=0;
147
148 while (x < image_width) {
149 unsigned long value=0;
150 unsigned long a0,a1=0,a2=0,a3=0;
151 switch (bytes_per_pixel) {
152 case 4:
153 a0 = *ptr++;
154 a1 = *ptr++;
155 a2 = *ptr++;
156 a3 = *ptr++;
157 break;
158 case 3:
159 a0 = *ptr++;
160 a1 = *ptr++;
161 a2 = *ptr++;
162 break;
163 case 2:
164 a0 = *ptr++;
165 a1 = *ptr++;
166 break;
167 case 1:
168 a0 = *ptr++;
169 break;
170 }
171 a1 <<= 8;
172 a2 <<= 16;
173 a3 <<= 24;
174 value = a0|a1|a2|a3;
175
176 unsigned long r,g,b;
177 r = value >> ro;
178 g = value >> go;
179 b = value >> bo;
180 r <<= (8 - rl);
181 g <<= (8 - gl);
182 b <<= (8 - bl);
183
184 image_buffer[ix++] = r;
185 image_buffer[ix++] = g;
186 image_buffer[ix++] = b;
187 x++;
188 }
189 }
190
191 write_JPEG_file (path,999);
192 close(fd);
193
194 return 0;
195 }
This webpage is intended to be an accessible preview of this repository. To get a fuller picture, clone it and use the git CLI.