From: Imre Kaloz Date: Wed, 8 Feb 2012 10:20:13 +0000 (+0000) Subject: fbtest utility X-Git-Tag: reboot~14979 X-Git-Url: http://git.lede-project.org./?a=commitdiff_plain;h=8099f4e0d3af85af483dc8755b5d3f005ba092fb;p=openwrt%2Fopenwrt.git fbtest utility SVN-Revision: 30369 --- diff --git a/package/fbtest/Makefile b/package/fbtest/Makefile new file mode 100644 index 0000000000..05e67cb63a --- /dev/null +++ b/package/fbtest/Makefile @@ -0,0 +1,44 @@ +# +# Copyright (C) 2012 OpenWrt.org +# +# This is free software, licensed under the GNU General Public License v2. +# See /LICENSE for more information. +# + +include $(TOPDIR)/rules.mk + +PKG_NAME:=fbtest +PKG_RELEASE:=1 + +PKG_BUILD_DIR := $(BUILD_DIR)/$(PKG_NAME) + +include $(INCLUDE_DIR)/package.mk + +define Package/fbtest + SECTION:=utils + CATEGORY:=Utilities + TITLE:=Frame buffer device testing tool + DEPENDS:=@DISPLAY_SUPPORT +endef + +define Build/Prepare + mkdir -p $(PKG_BUILD_DIR) + $(CP) ./src/* $(PKG_BUILD_DIR)/ +endef + +define Build/Configure +endef + +define Build/Compile + $(MAKE) -C $(PKG_BUILD_DIR) \ + CC="$(TARGET_CC)" \ + CFLAGS="$(TARGET_CFLAGS) -Wall" \ + LDFLAGS="$(TARGET_LDFLAGS)" +endef + +define Package/fbtest/install + $(INSTALL_DIR) $(1)/usr/sbin + $(INSTALL_BIN) $(PKG_BUILD_DIR)/fbtest $(1)/usr/sbin/ +endef + +$(eval $(call BuildPackage,fbtest)) diff --git a/package/fbtest/src/Makefile b/package/fbtest/src/Makefile new file mode 100644 index 0000000000..075bc0ecbf --- /dev/null +++ b/package/fbtest/src/Makefile @@ -0,0 +1,14 @@ +CC = gcc +CFLAGS = -Wall +OBJS = fbtest.o + +all: fbtest + +%.o: %.c + $(CC) $(CFLAGS) -c -o $@ $< + +fbtest: $(OBJS) + $(CC) -o $@ $(OBJS) + +clean: + rm -f rbcfg *.o diff --git a/package/fbtest/src/fbtest.c b/package/fbtest/src/fbtest.c new file mode 100644 index 0000000000..6e9c2f85fa --- /dev/null +++ b/package/fbtest/src/fbtest.c @@ -0,0 +1,448 @@ +/****************************************************************************** + * fbtest - fbtest.c + * test program for the tuxbox-framebuffer device + * tests all GTX/eNX supported modes + * + * (c) 2003 Carsten Juttner (carjay@gmx.net) + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * The Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + ****************************************************************************** + * $Id: fbtest.c,v 1.5 2005/01/14 23:14:41 carjay Exp $ + ******************************************************************************/ + +// TODO: - should restore the colour map and mode to what it was before +// - is colour map handled correctly? + +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#include + +#include + +#define FBDEV "/dev/fb0" + +struct vidsize{ + int width; + int height; +}; +static +const struct vidsize vidsizetable[]={ // all supported sizes + {720,576},{720,480},{720,288},{720,240}, + {640,576},{640,480},{640,288},{640,240}, + {360,576},{360,480},{360,288},{360,240}, + {320,576},{320,480},{320,288},{320,240} +}; +#define VIDSIZENUM (sizeof(vidsizetable)/sizeof(struct vidsize)) + +enum pixenum{ // keep in sync with pixname ! + CLUT4=0, + CLUT8, + RGB565, + ARGB1555, + ARGB +}; +const char *pixname[] = { + "CLUT4", + "CLUT8", + "RGB565", + "ARGB1555", + "ARGB" +}; + +struct pixelformat{ + char *name; + struct fb_bitfield red; + struct fb_bitfield green; + struct fb_bitfield blue; + struct fb_bitfield transp; + char bpp; + char pixenum; +}; + +static // so far these are all modes supported by the eNX (only partially by GTX) +const struct pixelformat pixelformattable[] = { + { .name = "CLUT4 ARGB8888", // CLUT4 (ARGB8888) + .bpp = 4, .pixenum = CLUT4, + .red = { .offset = 0, .length=8, .msb_right =0 }, + .green = { .offset = 0, .length=8, .msb_right =0 }, + .blue = { .offset = 0, .length=8, .msb_right =0 }, + .transp= { .offset = 0, .length=8, .msb_right =0 } + }, + { .name = "CLUT4 ARGB1555", // CLUT4 (ARGB1555) + .bpp = 4, .pixenum = CLUT4, + .red = { .offset = 0, .length=5, .msb_right =0 }, + .green = { .offset = 0, .length=5, .msb_right =0 }, + .blue = { .offset = 0, .length=5, .msb_right =0 }, + .transp= { .offset = 0, .length=1, .msb_right =0 } + }, + { .name = "CLUT8 ARGB8888", // CLUT8 (ARGB8888) + .bpp = 8, .pixenum = CLUT8, + .red = { .offset = 0, .length=8, .msb_right =0 }, + .green = { .offset = 0, .length=8, .msb_right =0 }, + .blue = { .offset = 0, .length=8, .msb_right =0 }, + .transp= { .offset = 0, .length=8, .msb_right =0 } + }, + { .name = "CLUT8 ARGB1555", // CLUT8 (ARGB1555) + .bpp = 8, .pixenum = CLUT8, + .red = { .offset = 0, .length=5, .msb_right =0 }, + .green = { .offset = 0, .length=5, .msb_right =0 }, + .blue = { .offset = 0, .length=5, .msb_right =0 }, + .transp= { .offset = 0, .length=1, .msb_right =0 } + }, + { .name = "ARGB1555", // ARGB1555 + .bpp = 16, .pixenum = ARGB1555, + .red = { .offset = 10, .length=5, .msb_right =0 }, + .green = { .offset = 5, .length=5, .msb_right =0 }, + .blue = { .offset = 0, .length=5, .msb_right =0 }, + .transp= { .offset = 15, .length=1, .msb_right =0 } + }, + { .name = "RGB565", // RGB565 + .bpp = 16, .pixenum = RGB565, + .red = { .offset = 11, .length=5, .msb_right =0 }, + .green = { .offset = 5, .length=6, .msb_right =0 }, + .blue = { .offset = 0, .length=5, .msb_right =0 }, + .transp= { .offset = 0, .length=0, .msb_right =0 } + }, + { .name = "ARGB", // 32 f*cking bits, the real McCoy :) + .bpp = 32, .pixenum = ARGB, + .red = { .offset = 16, .length=8, .msb_right =0 }, + .green = { .offset = 8, .length=8, .msb_right =0 }, + .blue = { .offset = 0, .length=8, .msb_right =0 }, + .transp= { .offset = 24, .length=8, .msb_right =0 } + } +}; +#define PIXELFORMATNUM (sizeof(pixelformattable)/sizeof(struct pixelformat)) + +struct colour { + __u16 r; + __u16 g; + __u16 b; + __u16 a; +}; +static +struct colour colourtable[] = { + {.r =0xffff, .g = 0xffff, .b=0xffff, .a=0xffff}, // fully transparent white + {.r =0xffff, .g = 0x0000, .b=0x0000, .a=0x0000}, // red + {.r =0x0000, .g = 0xffff, .b=0x0000, .a=0x0000}, // green + {.r =0x0000, .g = 0x0000, .b=0xffff, .a=0x0000}, // blue + {.r =0x0000, .g = 0x0000, .b=0x0000, .a=0x0000} // black +}; +#define COLOURNUM (sizeof(colourtable)/sizeof(struct colour)) + +struct rect{ + int x; + int y; + int width; + int height; + const struct colour *col; +}; +struct pixel{ // up to 32 bits of pixel information + char byte[4]; +}; + +void col2pixel (struct pixel *pix, const struct pixelformat *pixf, const struct colour *col){ + switch (pixf->pixenum){ + case RGB565: + pix->byte[0]=(col->r&0xf8)|(col->g&0xfc)>>5; + pix->byte[1]=(col->g&0xfc)<<3|(col->b&0xf8)>>3; + break; + case ARGB1555: + pix->byte[0]=(col->a&0x80)|(col->r&0xf8)>>1|(col->g&0xf8)>>6; + pix->byte[1]=(col->g&0xf8)<<2|(col->b&0xf8)>>3; + break; + case ARGB: + pix->byte[0]=col->a; + pix->byte[1]=col->r; + pix->byte[2]=col->g; + pix->byte[3]=col->b; + break; + default: + printf ("unknown pixelformat\n"); + exit(1); + } +} + +int setmode(int fbd, const struct pixelformat *pixf,const struct vidsize *vids){ + struct fb_var_screeninfo var; + int stat; + stat = ioctl (fbd, FBIOGET_VSCREENINFO,&var); + if (stat<0) return -2; + + var.xres= vids->width; + var.xres_virtual = vids->width; + var.yres= vids->height; + var.yres_virtual = vids->height; + + var.bits_per_pixel = pixf->bpp; + var.red = pixf->red; + var.green = pixf->green; + var.blue = pixf->blue; + var.transp = pixf->transp; + + stat = ioctl (fbd, FBIOPUT_VSCREENINFO,&var); + if (stat<0) return -1; + return 0; +} + +// unefficient implementation, do NOT use it for your next ego shooter, please :) +// for 4-Bit only rectangles with even width are supported +// CLUT-modes use value of red component as index +void drawrect(void *videoram, struct rect *r, const struct pixelformat *pixf, const struct vidsize *vids){ + int x,y,corwidth, bpp = 0, tocopy = 1; + struct pixel pix; + unsigned char *pmem = videoram; + corwidth = r->width; // actually only "corrected" for 4 Bit + + if (pixf->pixenum!=CLUT4&&pixf->pixenum!=CLUT8){ + switch (pixf->pixenum){ + case ARGB1555: + case RGB565: + bpp = 16; + tocopy = 2; + break; + case ARGB: + bpp = 32; + tocopy = 4; + break; + default: + printf ("drawrect: unknown pixelformat(%d) bpp:%d\n",pixf->pixenum,pixf->bpp); + exit(1); + } + col2pixel(&pix,pixf,r->col); + } else { + switch (pixf->pixenum){ // CLUT = Colour LookUp Table (palette) + case CLUT4: // take red value as index in this case + pix.byte[0]=(r->col->r)<<4|(r->col->r&0xf); // slightly cryptic... "rect->colour->red" + corwidth>>=1; // we copy bytes + bpp=4; + tocopy=1; + break; + case CLUT8: + pix.byte[0]=(r->col->r&0xff); + bpp=8; + tocopy=1; + break; + } + } + pmem=videoram+((((r->y*vids->width)+r->x)*bpp)>>3); + for (y=0;yheight;y++){ + int offset = 0; + for (x=0;xwidth*bpp)>>3); // skip one whole line, actually should be taken from "fix-info" + } +} + +// create quick little test image, 4 colours from table +void draw4field(void *videoram, const struct pixelformat *pixf, const struct vidsize *vids){ + struct rect r; + struct colour c; + int height, width; + c.r = 1; // only used for the indexed modes, r is taken as index + height = vids->height; + width = vids->width; + + r.height = height>>1; + r.width = width>>1; + r.x = 0; r.y = 0; + if (pixf->pixenum==CLUT4||pixf->pixenum==CLUT8) r.col = &c; + else r.col = &colourtable[1]; + drawrect (videoram, &r, pixf, vids); + + r.x = width/2; r.y = 0; + if (pixf->pixenum==CLUT4||pixf->pixenum==CLUT8) c.r = 2; + else r.col = &colourtable[2]; + drawrect (videoram, &r, pixf, vids); + + r.x = 0; r.y = height/2; + if (pixf->pixenum==CLUT4||pixf->pixenum==CLUT8) c.r = 3; + else r.col = &colourtable[3]; + drawrect (videoram, &r, pixf, vids); + + r.x = width/2; r.y = height/2; + if (pixf->pixenum==CLUT4||pixf->pixenum==CLUT8) c.r = 0; + else r.col = &colourtable[0]; + drawrect (videoram, &r, pixf, vids); +} + +void usage(char *name){ + printf ("Usage: %s [options]\n" + "Options: -f\n" + " where format is one of:\n" + " CLUT4,CLUT8,ARGB1555,RGB565,ARGB\n" + " -sx\n" + " where width is either 720,640,360,320\n" + " and height is either 288,240,480,576\n" + " -n\n" + " disables clearing the framebuffer after drawing\n" + " the testimage. This can be useful to keep the last\n" + " drawn image onscreen.\n" + "\nExample: %s -fRGB322\n",name,name); + exit(0); +} + +int main (int argc,char **argv){ + struct fb_fix_screeninfo fix; + struct fb_var_screeninfo var; + struct fb_cmap cmap; + struct rect r; + int fbd; + unsigned char *pfb; + int stat; + int optchar,fmode=-1,smode=-1,clear=1; + int i_cmap,i_size,i_pix; + extern char *optarg; + + if (argc!=0&&argc>4) usage(argv[0]); + while ( (optchar = getopt (argc,argv,"f:s:n"))!= -1){ + int i,height,width; + switch (optchar){ + case 'f': + for (i=0;i<(sizeof(pixname)/sizeof(char*));i++){ + if (!strncmp (optarg,pixname[i],strlen(pixname[i]))){ + fmode=i; + printf ("displaying only %s-modes\n",pixname[i]); + break; + } + } + if (fmode==-1){ + printf ("unknown pixelformat\n"); + exit(0); + } + break; + case 's': + if (sscanf (optarg,"%dx%d",&width,&height)!=2){ + printf ("parsing size failed\n"); + exit(0); + } else { + printf ("requested size %dx%d\n",width,height); + for (i=0;i