Example #1
0
int main (int argc, char *argv[])
{
    char
	inputfile[DEF_FILELEN],
	outputfile[DEF_FILELEN],
	varname[DEF_FILELEN];

    image_t 		rgb_logo, yuyv_logo ;

    switch (argc){
    case 2:
    case 3:
    case 4:
	strcpy (inputfile, 	argv[1]);

	if (argc > 2)
	    strcpy (varname, 	argv[2]);
	else
	{
	    int pos = strchr(inputfile, '.');

	    if (pos >= 0)
	    {
		strncpy (varname, inputfile, pos);
		varname[pos] = 0 ;
	    }
	}

	if (argc > 3)
	    strcpy (outputfile, argv[3]);
	else
	{
	    int pos = strchr (varname, '.');

	    if (pos > 0)
	    {
		char app[DEF_FILELEN] ;

		strncpy(app, varname, pos);
		sprintf(outputfile, "%s.h", app);
	    }
	}
	break;

    default:
	printf("EasyLogo 1.0 (C) 2000 by Paolo Scaffardi\n\n");

	printf("Syntax:	easylogo inputfile [outputvar {outputfile}] \n");
	printf("\n");
	printf("Where:	'inputfile' 	is the TGA image to load\n");
	printf("      	'outputvar' 	is the variable name to create\n");
	printf("       	'outputfile' 	is the output header file (default is 'inputfile.h')\n");

	return -1 ;
    }

    printf("Doing '%s' (%s) from '%s'...",
	outputfile, varname, inputfile);

/* Import TGA logo */

    printf("L");
    if (image_load_tga (&rgb_logo, inputfile)<0)
    {
	printf("input file not found!\n");
	exit(1);
    }

/* Convert it to YUYV format */

    printf("C");
    image_rgb_to_yuyv (&rgb_logo, &yuyv_logo) ;

/* Save it into a header format */

    printf("S");
    image_save_header (&yuyv_logo, outputfile, varname) ;

/* Free original image and copy */

    image_free (&rgb_logo);
    image_free (&yuyv_logo);

    printf("\n");

    return 0 ;
}
int main (int argc, char *argv[])
{
	int c;
	bool use_rgb = false;
	char inputfile[DEF_FILELEN],
		outputfile[DEF_FILELEN], varname[DEF_FILELEN];

	image_t rgb_logo, yuyv_logo;

	while ((c = getopt(argc, argv, "hrgb")) > 0) {
		switch (c) {
		case 'h':
			usage (0);
			break;
		case 'r':
			use_rgb = true;
			puts ("Using 24-bit RGB Output Fromat");
			break;
		case 'g':
			use_gzip |= 0x1;
			puts ("Compressing with gzip");
			break;
		case 'b':
			use_gzip |= 0x2;
			puts ("Preallocating bss space for decompressing image");
			break;
		default:
			usage (1);
			break;
		}
	}

	c = argc - optind;
	if (c > 4 || c < 1)
		usage (1);

	strcpy (inputfile, argv[optind]);

	if (c > 1)
		strcpy (varname, argv[optind + 1]);
	else {
		/* transform "input.tga" to just "input" */
		char *dot;
		strcpy (varname, inputfile);
		dot = strchr (varname, '.');
		if (dot)
			*dot = '\0';
	}

	if (c > 2)
		strcpy (outputfile, argv[optind + 2]);
	else {
		/* just append ".h" to input file name */
		strcpy (outputfile, inputfile);
		strcat (outputfile, ".h");
	}

	/* Make sure the output is sent as soon as we printf() */
	setbuf(stdout, NULL);

	printf ("Doing '%s' (%s) from '%s'...",
		outputfile, varname, inputfile);

	/* Import TGA logo */

	printf ("L");
	if (image_load_tga (&rgb_logo, inputfile) < 0) {
		printf ("input file not found!\n");
		exit (1);
	}

	/* Convert it to YUYV format if wanted */

	if (!use_rgb) {
		printf ("C");
		image_rgb_to_yuyv (&rgb_logo, &yuyv_logo);
	}

	/* Save it into a header format */

	printf ("S");
	image_save_header (use_rgb ? &rgb_logo : &yuyv_logo, outputfile, varname);

	/* Free original image and copy */

	image_free (&rgb_logo);
	if (!use_rgb)
		image_free (&yuyv_logo);

	printf ("\n");

	return 0;
}