Skip to content
Snippets Groups Projects
Commit edfed1d9 authored by Mike Frysinger's avatar Mike Frysinger Committed by Wolfgang Denk
Browse files

easylogo: clean up some more and add -r (rgb) support


Michael Hennerich added support for outputting an image in RGB format rather
than forcing YUYV all the time.  This makes obvious sense if the display you
have takes RGB input rather than YUYV.

Rather than hack in support for options, I've converted it to use getopt and
cleaned up the argument parsing in the process.

Signed-off-by: default avatarMichael Hennerich <michael.hennerich@analog.com>
Signed-off-by: default avatarMike Frysinger <vapier@gentoo.org>
parent f65c9812
No related branches found
No related tags found
No related merge requests found
...@@ -7,6 +7,8 @@ ...@@ -7,6 +7,8 @@
** This is still under construction! ** This is still under construction!
*/ */
#include <getopt.h>
#include <stdbool.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
...@@ -216,15 +218,10 @@ int image_load_tga (image_t * image, char *filename) ...@@ -216,15 +218,10 @@ int image_load_tga (image_t * image, char *filename)
return 0; return 0;
} }
int image_free (image_t * image) void image_free (image_t * image)
{ {
if (image->data != NULL) free (image->data);
free (image->data); free (image->palette);
if (image->palette != NULL)
free (image->palette);
return 0;
} }
int image_rgb_to_yuyv (image_t * rgb_image, image_t * yuyv_image) int image_rgb_to_yuyv (image_t * rgb_image, image_t * yuyv_image)
...@@ -353,59 +350,76 @@ int image_save_header (image_t * image, char *filename, char *varname) ...@@ -353,59 +350,76 @@ int image_save_header (image_t * image, char *filename, char *varname)
#define DEF_FILELEN 256 #define DEF_FILELEN 256
static void usage (int exit_status)
{
puts (
"EasyLogo 1.0 (C) 2000 by Paolo Scaffardi\n"
"\n"
"Syntax: easylogo [options] inputfile [outputvar [outputfile]]\n"
"\n"
"Options:\n"
" -r Output RGB instead of YUYV\n"
" -h Help output\n"
"\n"
"Where: 'inputfile' is the TGA image to load\n"
" 'outputvar' is the variable name to create\n"
" 'outputfile' is the output header file (default is 'inputfile.h')"
);
exit (exit_status);
}
int main (int argc, char *argv[]) int main (int argc, char *argv[])
{ {
int c;
bool use_rgb = false;
char inputfile[DEF_FILELEN], char inputfile[DEF_FILELEN],
outputfile[DEF_FILELEN], varname[DEF_FILELEN]; outputfile[DEF_FILELEN], varname[DEF_FILELEN];
image_t rgb_logo, yuyv_logo; image_t rgb_logo, yuyv_logo;
switch (argc) { while ((c = getopt(argc, argv, "hr")) > 0) {
case 2: switch (c) {
case 3: case 'h':
case 4: usage (0);
strcpy (inputfile, argv[1]); break;
case 'r':
if (argc > 2) use_rgb = true;
strcpy (varname, argv[2]); puts ("Using 24-bit RGB Output Fromat");
else { break;
char *dot = strchr (inputfile, '.'); default:
int pos = dot - inputfile; usage (1);
break;
if (dot) {
strncpy (varname, inputfile, pos);
varname[pos] = 0;
}
}
if (argc > 3)
strcpy (outputfile, argv[3]);
else {
char *dot = strchr (varname, '.');
int pos = dot - varname;
if (dot) {
char app[DEF_FILELEN];
strncpy (app, varname, pos);
app[pos] = 0;
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"); c = argc - optind;
printf("\n"); if (c > 4 || c < 1)
printf("Where: 'inputfile' is the TGA image to load\n"); usage (1);
printf(" 'outputvar' is the variable name to create\n");
printf(" 'outputfile' is the output header file (default is 'inputfile.h')\n"); 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';
}
return -1; 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'...", printf ("Doing '%s' (%s) from '%s'...",
outputfile, varname, inputfile); outputfile, varname, inputfile);
...@@ -417,20 +431,23 @@ int main (int argc, char *argv[]) ...@@ -417,20 +431,23 @@ int main (int argc, char *argv[])
exit (1); exit (1);
} }
/* Convert it to YUYV format */ /* Convert it to YUYV format if wanted */
printf ("C"); if (!use_rgb) {
image_rgb_to_yuyv (&rgb_logo, &yuyv_logo); printf ("C");
image_rgb_to_yuyv (&rgb_logo, &yuyv_logo);
}
/* Save it into a header format */ /* Save it into a header format */
printf ("S"); printf ("S");
image_save_header (&yuyv_logo, outputfile, varname); image_save_header (use_rgb ? &rgb_logo : &yuyv_logo, outputfile, varname);
/* Free original image and copy */ /* Free original image and copy */
image_free (&rgb_logo); image_free (&rgb_logo);
image_free (&yuyv_logo); if (!use_rgb)
image_free (&yuyv_logo);
printf ("\n"); printf ("\n");
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment