From f991fcbee5bf5f9631779715f6bfcbfa4e7254d7 Mon Sep 17 00:00:00 2001 From: Mateusz Golicz Date: Tue, 10 Nov 2009 17:03:17 +0100 Subject: [PATCH] Import of http://s-tech.elsat.net.pl/fbv/fbv-0.92b.tar.gz released the 2000-Nov-20 22:43:56 --- fb_display.c | 101 ++++++++++++++++++++++++++++++++++------------------------- fb_display.h | 1 + main.c | 2 +- 3 files changed, 60 insertions(+), 44 deletions(-) diff --git a/fb_display.c b/fb_display.c index 368ff9f..5b89fb7 100644 --- a/fb_display.c +++ b/fb_display.c @@ -6,7 +6,7 @@ /* Public Use Functions: * - * extern void fb_display(char *rgbbuff, + * extern void fb_display(unsigned char *rgbbuff, * int x_size, int y_size, * int x_pan, int y_pan, * int x_offs, int y_offs); @@ -19,6 +19,8 @@ unsigned short red[256], green[256], blue[256]; struct fb_cmap map332 = {0, 256, red, green, blue, NULL}; +unsigned short red_b[256], green_b[256], blue_b[256]; +struct fb_cmap map_back = {0, 256, red_b, green_b, blue_b, NULL}; int openFB(const char *name); @@ -27,7 +29,7 @@ void getVarScreenInfo(int fh, struct fb_var_screeninfo *var); void setVarScreenInfo(int fh, struct fb_var_screeninfo *var); void getFixScreenInfo(int fh, struct fb_fix_screeninfo *fix); void set332map(int fh); -void* convertRGB2FB(int fh, char *rgbbuff, unsigned long count, int bpp, int *cpp); +void* convertRGB2FB(int fh, unsigned char *rgbbuff, unsigned long count, int bpp, int *cpp); void blit2FB(int fh, void *fbbuff, unsigned int pic_xs, unsigned int pic_ys, unsigned int scr_xs, unsigned int scr_ys, @@ -35,7 +37,7 @@ void blit2FB(int fh, void *fbbuff, unsigned int xoffs, unsigned int yoffs, int cpp); -void fb_display(char *rgbbuff, int x_size, int y_size, int x_pan, int y_pan, int x_offs, int y_offs) +void fb_display(unsigned char *rgbbuff, int x_size, int y_size, int x_pan, int y_pan, int x_offs, int y_offs) { struct fb_var_screeninfo var; unsigned short *fbbuff = NULL; @@ -121,6 +123,48 @@ void getFixScreenInfo(int fh, struct fb_fix_screeninfo *fix) } } +void make332map(struct fb_cmap *map) +{ + int rs, gs, bs, i; + int r = 8, g = 8, b = 4; + + map->red = red; + map->green = green; + map->blue = blue; + + rs = 256 / (r - 1); + gs = 256 / (g - 1); + bs = 256 / (b - 1); + + for (i = 0; i < 256; i++) { + map->red[i] = (rs * ((i / (g * b)) % r)) * 255; + map->green[i] = (gs * ((i / b) % g)) * 255; + map->blue[i] = (bs * ((i) % b)) * 255; + } +} + +void set8map(int fh, struct fb_cmap *map) +{ + if (ioctl(fh, FBIOPUTCMAP, map) < 0) { + fprintf(stderr, "Error putting colormap"); + exit(1); + } +} + +void get8map(int fh, struct fb_cmap *map) +{ + if (ioctl(fh, FBIOGETCMAP, map) < 0) { + fprintf(stderr, "Error getting colormap"); + exit(1); + } +} + +void set332map(int fh) +{ + make332map(&map332); + set8map(fh, &map332); +} + void blit2FB(int fh, void *fbbuff, unsigned int pic_xs, unsigned int pic_ys, unsigned int scr_xs, unsigned int scr_ys, @@ -129,18 +173,21 @@ void blit2FB(int fh, void *fbbuff, int cpp) { int i, xc, yc; - char *cp; unsigned short *sp; unsigned int *ip; - cp = (char *) sp = (unsigned short *) ip = (unsigned int *) fbbuff; + unsigned char *cp; unsigned short *sp; unsigned int *ip; + cp = (unsigned char *) sp = (unsigned short *) ip = (unsigned int *) fbbuff; xc = (pic_xs > scr_xs) ? scr_xs : pic_xs; yc = (pic_ys > scr_ys) ? scr_ys : pic_ys; switch(cpp){ case 1: + get8map(fh, &map_back); + set332map(fh); for(i = 0; i < yc; i++){ lseek(fh, ((i+yoffs)*scr_xs+xoffs)*cpp, SEEK_SET); write(fh, cp + (i+yp)*pic_xs+xp, xc*cpp); } + set8map(fh, &map_back); break; case 2: for(i = 0; i < yc; i++){ @@ -157,7 +204,7 @@ void blit2FB(int fh, void *fbbuff, } } -inline char make8color(char r, char g, char b) +inline unsigned char make8color(unsigned char r, unsigned char g, unsigned char b) { return ( (((r >> 5) & 7) << 5) | @@ -165,7 +212,7 @@ inline char make8color(char r, char g, char b) ((b >> 6) & 3) ); } -inline unsigned short make15color(char r, char g, char b) +inline unsigned short make15color(unsigned char r, unsigned char g, unsigned char b) { return ( (((r >> 3) & 31) << 10) | @@ -173,7 +220,7 @@ inline unsigned short make15color(char r, char g, char b) ((b >> 3) & 31) ); } -inline unsigned short make16color(char r, char g, char b) +inline unsigned short make16color(unsigned char r, unsigned char g, unsigned char b) { return ( (((r >> 3) & 31) << 11) | @@ -181,51 +228,19 @@ inline unsigned short make16color(char r, char g, char b) ((b >> 3) & 31) ); } -void make332map(struct fb_cmap *map) -{ - int rs, gs, bs, i; - int r = 8, g = 8, b = 4; - - map->red = red; - map->green = green; - map->blue = blue; - - rs = 256 / (r - 1); - gs = 256 / (g - 1); - bs = 256 / (b - 1); - - for (i = 0; i < 256; i++) { - map->red[i] = (rs * ((i / (g * b)) % r)) * 255; - map->green[i] = (gs * ((i / b) % g)) * 255; - map->blue[i] = (bs * ((i) % b)) * 255; - } -} - -void set332map(int fh) -{ - make332map(&map332); - - if (ioctl(fh, FBIOPUTCMAP, &map332) < 0) { - fprintf(stderr, "Error putting pseudo-truecolor colormap"); - exit(1); - } -} - -void* convertRGB2FB(int fh, char *rgbbuff, unsigned long count, int bpp, int *cpp) +void* convertRGB2FB(int fh, unsigned char *rgbbuff, unsigned long count, int bpp, int *cpp) { unsigned long i; void *fbbuff = NULL; - char *c_fbbuff; + unsigned char *c_fbbuff; unsigned short *s_fbbuff; unsigned int *i_fbbuff; -// printf("%d bpp\n",bpp); switch(bpp) { case 8: - set332map(fh); *cpp = 1; - c_fbbuff = (char *) malloc(count * sizeof(char)); + c_fbbuff = (unsigned char *) malloc(count * sizeof(unsigned char)); for(i = 0; i < count; i++) c_fbbuff[i] = make8color(rgbbuff[i*3], rgbbuff[i*3+1], rgbbuff[i*3+2]); fbbuff = (void *) c_fbbuff; diff --git a/fb_display.h b/fb_display.h index 788c5e8..046c170 100644 --- a/fb_display.h +++ b/fb_display.h @@ -11,3 +11,4 @@ #include #include #include "config.h" + diff --git a/main.c b/main.c index d794ec6..cd09185 100644 --- a/main.c +++ b/main.c @@ -8,7 +8,7 @@ #define min(a,b) ((a) < (b) ? (a) : (b)) #define max(a,b) ((a) > (b) ? (a) : (b)) #define SHOWDELAY 100000 -#define IDSTRING "fbv 0.9b, s-tech" +#define IDSTRING "fbv 0.92b, s-tech" extern unsigned char * simple_resize(unsigned char * orgin,int ox,int oy,int dx,int dy); extern unsigned char * color_average_resize(unsigned char * orgin,int ox,int oy,int dx,int dy); -- 2.11.4.GIT