summaryrefslogtreecommitdiffstats
path: root/logotool/logotool.c
blob: b81e40726e084777479bcb4f65d1a6100e2f05a4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
/*
 * Copyright (C) 2007
 *       pancake <pancake@youterm.com>
 *       esteve <esteve@eslack.org>
 *
 * 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 <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <getopt.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>

#define VERSION "0.1"

int uncompress_image(char *srcf, char *dstf);
int compress_image(char *srcf, char *dstf, int w, int h);

static int show_usage()
{
	printf("Usage: logotool [-flags]\n");
	printf("  -u [img]   uncompress image to img.rgb\n");
	printf("  -c [img]   compres a 24 bit rgb raw image to a 16(565) one\n");
	printf("  -m [img]   show image using mplayer (dumps to <img>.yuv)\n");
	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("  -h         specify height (required for -v and -c)\n");
	printf("  -V         version number\n");
	printf("\n");
	printf("Example:\n");
	printf(" $ `logotool -u logo-file`   # uncompress and display a logo\n");
	return 1;
}

int main ( int argc , char** argv )
{	
	int c;
	int w=0,h=0;
	char *mimg = NULL;
	char *cimg = NULL;
	char *uimg = NULL;
	char *view = NULL;

	while((c = getopt(argc, argv, "w:h:Vv:u:c:m:")) != -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 'w': w = atoi(optarg); break;
		case 'h': h = atoi(optarg); break;
		case 'v': view = optarg; break;
		}
	}

	if (mimg) {
		char *buf;
		if (w==0||h==0) {
			printf("You must specify width and height with '-w' and '-h'.\n");
			return 1;
		}

		buf = (char *)malloc(strlen(mimg)+128);
		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);
			system(buf);
		} else {
			printf("Oops\n");
		}
		free(buf);
	} else
	if (view) {
		char *buf;
		
		if (w==0||h==0) {
			printf("You must specify width and height with '-w' and '-h'.\n");
			return 1;
		}
		buf = (char *)malloc(strlen(view)+128);
		sprintf(buf, "display -size %dx%d -depth 16 %s", w,h,view);
		printf("%s\n", buf);
		system(buf);
		free(buf);
	} else
	if (uimg) {
		char *dst = (char*)malloc(strlen(uimg)+5);
		strcpy(dst, uimg);
		strcat(dst, ".gray");
		uncompress_image(uimg, dst);
		free(dst);
	} else
	if (cimg) {
		char *dst;
		if (w==0||h==0) {
			printf("You must specify width and height with '-w' and '-h'.\n");
			return 1;
		}
		dst = (char*)malloc(strlen(cimg)+5);
		strcpy(dst, cimg);
		strcat(dst, ".logo");
		compress_image(cimg, dst, w, h);
		free(dst);
	} else
		show_usage();

	return 0;
}