From 3e13254858c69e76c86ba19aa9cb6e24454b7555 Mon Sep 17 00:00:00 2001 From: pancake Date: Mon, 30 Apr 2007 06:26:27 +0200 Subject: * Initial import of the logotool utility --- logotool/compress.c | 72 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 logotool/compress.c (limited to 'logotool/compress.c') diff --git a/logotool/compress.c b/logotool/compress.c new file mode 100644 index 0000000..327d50e --- /dev/null +++ b/logotool/compress.c @@ -0,0 +1,72 @@ +/* + * Copyright (C) 2007 + * pancake + * esteve + * + * logotool 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. + * + * logotool 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 logotool; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +int compress_image(char *srcf, char *dstf, int w, int h) +{ + char buf[256]; + char tmp[256]; + int fd, fdout; + int i,ret; + + fd = open(srcf, O_RDONLY); + if (fd == -1) { + printf("Cannot open file '%s' \n", srcf); + return 1; + } + + fdout = open( dstf, 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); + + 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