Mian. h
*********************************
1 # ifndef _ main_h __
2 # DEFINE _ main_h __
3
4 # define screen_bpp 32
5 # define debug 1
6
7 typedef unsigned char u8_t;
8 typedef unsigned short u16_t;
9 typedef unsigned int u32_t;
10
11 typedef struct
12 {
13 int W;
14 int h;
15 int BPP;
16 void * fb_mem;
17} info_t;
18
19/********************** FB. c *********************/
20 extern int init_fb (const char * device, info_t * FB );
21 extern int fb_pixel (const info_t * FB, int X, int y, u32_t color );
22 extern int disp_basic (const info_t * FB, const char * filename );
23 extern int display (const info_t * FB, int X, int y, const info_t * size, const char * filename );
24/* disp_basic.c ******************/
25 u32_t * rgb24to32 (const u8_t * buf24, const info_t * JPEG );
26 u8_t * decode_jpeg (const char * encoding file, info_t * JPEG );
27 u8_t * scale24 (const u8_t * buf24, const info_t * New, const info_t * JPEG );
28 u16_t * rgb24to16 (const u8_t * buf24, const info_t * JPEG );
29
30
31
32
33
34 # endif
~
~
Main. c
**************************************
1 # include <stdio. h>
2 # include <string. h>
3 # include <errno. h>
4 # include <stdlib. h>
5
6 # include "Main. H"
7
8 int main (INT argc, char * argv [])
9 {
10 info_t FB;
11
12 if (init_fb (null, & FB) <0 ){
13 fprintf (stderr, "error for init framebuffer \ n ");
14 exit (1 );
15}
16
17 // fb_pixel (& FB, 640,400, 0xff0000 );
18 // disp_basic (& FB, "1024-768-32.jpg ");
19 info_t size;
20 size. W = FB. W;
21 size. H = FB. h;
22 display (& FB, 0, 0, & size, "test.jpg ");
23 return 0;
24}
~
FB. c
**************************************** ****************************
1 # include <stdio. h>
2 # include <string. h>
3 # include <errno. h>
4 # include <stdlib. h>
5
6 # include <fcntl. h>
7 # include <unistd. h>
8 # include <sys/IOCTL. h>
9 # include <sys/Mman. h>
10 # include <Linux/FB. h>
11
12 # include "Main. H"
13 int init_fb (const char * device, info_t * FB)
14 {
15 int r = 0;/* return value */
16
17 if (device = NULL)
18 device = "/dev/fb0 ";
19
20 int FD = open (device, o_rdwr );
21 if (FD <0 ){
22 fprintf (stderr, "error for open % s: % s \ n ",
23 device, strerror (errno ));
24 return-1;
25}
26/* IOCTL */
27 struct fb_var_screeninfo fb_var;
28 If (IOCTL (FD, fbioget_vscreeninfo, & fb_var) <0 ){
29 fprintf (stderr, "error for IOCTL: % s \ n ",
30 strerror (errno ));
31 r =-1;
32 goto ret;
33}
34
35 FB-> W = fb_var.xres;
36 FB-> H = fb_var.yres;
37 FB-> bpp = fb_var.bits_per_pixel;
38
39 # If debug
40 printf ("width: % d \ thigh: % d \ t BPP: % d \ n ",
41 FB-> W, FB-> H, FB-> bpp );
42 # endif
43/* MMAP */
44 If (FB-> fb_mem = MMAP (null, FB-> W * FB-> H * FB-> BPP/8,
45 prot_read | prot_write,
46 map_shared,
47 FD, 0) = map_failed ){
48 fprintf (stderr, "error for MMAP: % s \ n ",
49 strerror (errno ));
50 R =-1;
51 goto ret;
52}
53
54 RET:
55
56 close (FD );
57 Return R;
58}
59
60
61 int fb_pixel (const info_t * FB, int X, int y, u32_t color)
62 {
63 # If 0
64 char * P = FB-> fb_mem;
65 p = P + (x + y * FB-> W) * FB-> BPP/8;
66 switch (FB-> bpp ){
67 case 32:
68 * (p + 3) = color> 24;
69 case 24:
70 * (p + 2) = color> 16;
71 case 16:
72 * (p + 1) = color> 8;
73 default:
74 * P = color;
75}
76 # endif
77 # If (screen_bpp = 32)
78 u32_t * P = FB-> fb_mem;
79 p = P + x + y * FB-> W;
80 * P = color;
81 # else
82 u16_t * P = FB-> fb_mem;
83 p = P + x + y * FB-> W;
84 * P = color;
85
86 # endif
87
88 return 0;
89}
Display. c
**************************************** ******
1 # include <unistd. h>
2 # include <stdio. h>
3
4 # include "Main. H"
5
6
7 int disp_basic (const info_t * FB, const char * filename)
8 {
9 file * fp = fopen (filename, "R ");
10 if (FP = NULL)
11 {
12
13
14}
15 u32_t color = 0 xffffff;
16 int I, J;
17 For (j = 0; j <FB-> H; ++ J)
18 {
19 For (I = 0; I <FB-> W; ++ I)
20 {
21 fread (& color, 4, 1, FP );
22 fb_pixel (FB, I, j, color );
23}
24 usleep (1000 );
25}
26 fclose (FP );
27 return 0;
28}
~
Of course, you also need to use the JPEG decoding library. You need to download the decoded library file. I use functions that have been split by others.
Makefile
**************************************** * ****** 88888
2 src = $ (wildcard *. c)
3 OBJ = $ (patsubst %. C, %. O, $ (SRC ))
4 target = Main
5 # compiler_prefix = arm-Linux-
6 cc = $ (compiler_prefix) GCC
7 cflags =-wall-g-c-I ../jpeg-8c
8 ldflags =-wall-g-l ../jpeg-8c/. libs-ljpeg
9 All: $ (target)
10 $ (target): $ (OBJ)
11 $ (CC)-o $ ^ $ (ldflags)
12%. O: %. c
13 $ (CC) $ (cflags)-o $ @ $ <
14 clean:
15-rm-F $ (OBJ)
16-rm-F $ (target)
17. Phony: clean all
~
~
~
~