From ed37b5ee621a8c90ff08cb63038c6799642748fd Mon Sep 17 00:00:00 2001 From: pancake Date: Sat, 5 May 2007 03:04:52 +0200 Subject: * Enhacements and fixups for logotool * Add support for RGBA raw images (New flag -a) * Autodetect RGBA images * Fix endianness stuff when writting the logo header --- logotool/compress.c | 114 +++++++++++++++++++++++++++++++++++++++++++--------- logotool/logotool.c | 9 +++-- 2 files changed, 100 insertions(+), 23 deletions(-) diff --git a/logotool/compress.c b/logotool/compress.c index 327d50e..e2a6975 100644 --- a/logotool/compress.c +++ b/logotool/compress.c @@ -28,45 +28,119 @@ #include #include +extern int rgba; + +int isbe() +{ + int a=1; char *b=(char *)&a; + return (int)b[0]; +} + +void ememcpy(char *dst, char *src) +{ + char buffer[4]; + memcpy(buffer, src, 4); + dst[0] = buffer[3]; dst[1] = buffer[2]; + dst[2] = buffer[1]; dst[3] = buffer[0]; +} + int compress_image(char *srcf, char *dstf, int w, int h) { char buf[256]; char tmp[256]; - int fd, fdout; + int fdout; + FILE *fd; int i,ret; - fd = open(srcf, O_RDONLY); - if (fd == -1) { + fd = fopen(srcf, "rb"); + if (fd == NULL) { printf("Cannot open file '%s' \n", srcf); return 1; } - fdout = open( dstf, O_CREAT | O_WRONLY , 0660 ); + fdout = open( dstf, O_TRUNC | O_CREAT | O_WRONLY , 0660 ); if (fdout == -1) { printf("Cannot open file '%s' for writing\n", dstf); return 1; } - // TODO: force little endian!! (not safe for big endian) - write(fdout, &w, 4); - write(fdout, &h, 4); + if (isbe()) { + char oop[4]; + ememcpy((char *)&oop, (char *)&w); + write(fdout, &oop, 4); + ememcpy((char *)&oop, (char *)&h); + write(fdout, &oop, 4); + } else { + write(fdout, &w, 4); + write(fdout, &h, 4); + } - for(;;) { - unsigned char c; - ret = read(fd, buf, 3*80); - c = (int)((2*ret/3)>>1); - write(fdout,&c, 1); - if (ret <= 0) break; - for(i=0;i %d (ret %d)\n",i,ret-i, ret); +for(i=0;i5) { +// if (i==MAX) { + if (0x80>ret) printf("PRON\n"); + c = 0x80 | ret; //(int)((2*ret/3)>>1); + write(fdout,&c, 1); + tmp[0] = buf[i+0]&0xf8; + tmp[0] |= buf[i+1]&0x07; + tmp[1] = buf[i+1]&0xe0; + tmp[1] |= buf[i+1]&0x1f; + write(fdout, tmp, 2); + // restore state + memcpy(buf,buf+i,ret-i); + ret -= i; + } + +#endif diff --git a/logotool/logotool.c b/logotool/logotool.c index 72e33d8..32e3454 100644 --- a/logotool/logotool.c +++ b/logotool/logotool.c @@ -33,6 +33,7 @@ int uncompress_image(char *srcf, char *dstf); int compress_image(char *srcf, char *dstf, int w, int h); int rgb2yuv(char *from, char *to, int width, int height); +int rgba = 0; static int show_usage() { @@ -43,6 +44,7 @@ static int show_usage() printf(" -v [img] view uncompressed image using the 'display'\n"); printf(" command from ImageMagick (in monochrome)\n"); printf(" -w specify width (required for -v and -c)\n"); + printf(" -a force RGBA instead of RGB when compressing (use with -c)\n"); printf(" -h specify height (required for -v and -c)\n"); printf(" -V version number\n"); printf("\n"); @@ -60,12 +62,13 @@ int main ( int argc , char** argv ) char *uimg = NULL; char *view = NULL; - while((c = getopt(argc, argv, "w:h:Vv:u:c:m:")) != -1) { + while((c = getopt(argc, argv, "w:h:Vv:u:c:m:a")) != -1) { switch(c) { case 'V': printf("%s\n", VERSION); return 0; case 'u': uimg = optarg; break; case 'c': cimg = optarg; break; case 'm': mimg = optarg; break; + case 'a': rgba = 1; break; case 'w': w = atoi(optarg); break; case 'h': h = atoi(optarg); break; case 'v': view = optarg; break; @@ -83,7 +86,7 @@ int main ( int argc , char** argv ) sprintf(buf, "%s.rgb", mimg); if ( rgb2yuv(mimg, buf, w,h ) ) { - sprintf(buf, "echo pause | mplayer %s.rgb -slave -demuxer rawvideo -rawvideo fps=1:w=416:h=70", mimg); + sprintf(buf, "echo pause | mplayer %s.rgb -slave -demuxer rawvideo -rawvideo fps=1:w=%d:h=%d", mimg, w,h); system(buf); } else { printf("Oops\n"); @@ -116,7 +119,7 @@ int main ( int argc , char** argv ) printf("You must specify width and height with '-w' and '-h'.\n"); return 1; } - dst = (char*)malloc(strlen(cimg)+5); + dst = (char*)malloc(strlen(cimg)+6); strcpy(dst, cimg); strcat(dst, ".logo"); compress_image(cimg, dst, w, h); -- cgit v1.2.3