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 *jpegfile, 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
**********************************************
2 #include <stdio.h>
3
4 #include "main.h"
5
6
8 {
9 FILE *fp = fopen(filename ,"r");
10 if(fp == NULL)
11 {
12
13
14 }
15 u32_t color = 0xFFFFFF;
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 }
~
当然还需要用JPEG 解码库,需要下载解码库文件,我用的是别人已经分装好的函数
Makefile
***********************************************88888
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
~
~
~
~