diff options
Diffstat (limited to 'tools/convpic/convpic.c')
-rw-r--r-- | tools/convpic/convpic.c | 214 |
1 files changed, 77 insertions, 137 deletions
diff --git a/tools/convpic/convpic.c b/tools/convpic/convpic.c index 732738c..252b6c8 100644 --- a/tools/convpic/convpic.c +++ b/tools/convpic/convpic.c @@ -5,6 +5,7 @@ * * (C) 2004 Andreas Brachold <vdr04 AT deltab de> * (C) 2001-2003 by Carsten Siebholz <c.siebholz AT t-online.de> + * (C) 2013 Wolfgang Astleitner <mrwastl AT users sourceforge net> **/ /*************************************************************************** @@ -40,98 +41,41 @@ #include <glcdgraphics/glcd.h> #include <glcdgraphics/pbm.h> -#include "bmp.h" -#include "tiff.h" -#include "tuxbox.h" - static const char *prgname = "convpic"; -static const char *VERSION = "0.1.1"; +static const char *VERSION = "0.1.3"; unsigned int delay = 250; -enum ePicFormat -{ - pfUndefined, - pfTIFF, - pfBMP, - pfGLCD, - pfPBM, - pfTUXBOX -}; - -void usage(void); - -ePicFormat getFormat(const char* szFile) -{ - static const struct tagformats {const char* szExt; ePicFormat picformat;} formats[] = - { - {".tiff", pfTIFF }, - {".tif", pfTIFF }, - {".bmp", pfBMP }, - {".glcd", pfGLCD }, - {".pbm", pfPBM }, - {".ani", pfTUXBOX} - }; - ePicFormat pf = pfUndefined; - - if (szFile) - { - for (int i = strlen(szFile) - 1; i >= 0; i--) - { - if (*(szFile+i) == '.' && strlen(szFile + i + 1)) - { - for (unsigned int n = 0; n < sizeof(formats)/sizeof(*formats); n++) - { - if (!strcasecmp((szFile+i), formats[n].szExt)) - { - return formats[n].picformat; - } - } - } - } - } - return pf; +void usage(void) { + fprintf(stdout, "\n"); + fprintf(stdout, "%s v%s\n", prgname, VERSION); + fprintf(stdout, "%s is a tool to convert images to a simple format (*.glcd)\n", prgname); + fprintf(stdout, " that is used by the graphlcd plugin for VDR.\n\n"); + fprintf(stdout, " Usage: %s [-n] -i file[s...] -o outfile \n\n", prgname); + fprintf(stdout, " -n --invert inverts the output (default: none)\n"); + fprintf(stdout, " -i --infile specifies the name of the input file[s]\n"); + fprintf(stdout, " -o --outfile specifies the name of the output file\n"); + fprintf(stdout, " -d --delay specifies the delay between multiple images [Default: %d ms] \n",delay); + fprintf(stdout, "\n" ); + fprintf(stdout, " example: %s -i vdr-logo.bmp -o vdr-logo.glcd \n", prgname ); } -GLCD::cImageFile * GetFileTranslator(ePicFormat Format) -{ - switch (Format) - { - case pfGLCD: - return new GLCD::cGLCDFile(); - - case pfPBM: - return new GLCD::cPBMFile(); - - case pfBMP: - return new cBMPFile(); - - case pfTIFF: - return new cTIFFFile(); - - case pfTUXBOX: - return new cTuxBoxFile(); - - default: - return NULL; - } - -} int main(int argc, char *argv[]) { - ePicFormat inFormat = pfUndefined; - ePicFormat outFormat = pfUndefined; std::string inFile = ""; std::string outFile = ""; + std::string inExtension = ""; + std::string outExtension = ""; GLCD::cImage image; GLCD::cImage nextImage; - GLCD::cImageFile * pInBitmap = NULL; - GLCD::cImageFile * pOutBitmap = NULL; bool bError = false; bool bInvert = false; bool bDelay = false; + unsigned int image_w = 0; + unsigned int image_h = 0; + static struct option long_options[] = { @@ -162,97 +106,108 @@ int main(int argc, char *argv[]) { bDelay = true; if (delay < 10) { - fprintf(stderr, "Warning: You have specify a to short delay, minimum are 10 ms\n"); + fprintf(stderr, "WARNING: Delay is too short, minimum delay is 10 ms\n"); delay = 10; } break; default: + usage(); return 1; } } - if (inFile.length() == 0) - { + if (inFile.length() == 0) { fprintf(stderr, "ERROR: You have to specify the infile (-i filename)\n"); bError = true; } - if (pfUndefined == (inFormat = getFormat(inFile.c_str()))) - { - fprintf(stderr, "ERROR: You have to specify a correct extension for the %s\n", inFile.c_str()); + inExtension = GLCD::cImage::GetFilenameExtension(inFile); + + if (outFile.length() == 0) { + outFile = inFile.substr(0, inFile.length() - inExtension.length() - 1); + if (inExtension == "GLCD") { + outFile += ".pbm"; + outExtension = "PBM"; + } else { + outFile += ".glcd"; + outExtension = "GLCD"; + } + fprintf(stderr, "WARNING: No output filename given, will use '%s'\n", outFile.c_str()); + } + + if (outExtension.length() == 0) { + outExtension = GLCD::cImage::GetFilenameExtension(outFile); + } + + if ( !(outExtension == "GLCD" || outExtension == "PBM") ) { + fprintf(stderr, "ERROR: Unsupported format for outfile ('%s')\n", outExtension.c_str()); bError = true; } - if (outFile.length() == 0) - { - fprintf(stderr, "ERROR: You have to specify the outfile (-o filename)\n"); + if ( inExtension != "GLCD" && outExtension != "GLCD" ) { + fprintf(stderr, "ERROR: Either infile or outfile needs to be a GLCD file\n"); bError = true; } - if (pfUndefined == (outFormat = getFormat(outFile.c_str()))) - { - fprintf(stderr, "ERROR: You have to specify a correct extension for the %s \n", outFile.c_str()); + if ( outExtension != "GLCD" && outExtension != "PBM" ) { + fprintf(stderr, "ERROR: outfile needs to be either GLCD or PBM\n"); bError = true; } - if (bError) - { + if (bError) { usage(); return 1; } - - pInBitmap = GetFileTranslator(inFormat); - if (!pInBitmap) - return 2; - - pOutBitmap = GetFileTranslator(outFormat); - if (!pOutBitmap) - return 3; - // Load Picture fprintf(stdout, "loading %s\n", inFile.c_str()); - bError = !pInBitmap->Load(image, inFile); - if (!bError) - { + if (GLCD::cImage::LoadImage(image, inFile) == false) { + fprintf(stderr, "ERROR: Failed loading file %s\n", inFile.c_str()); + bError = true; + } + + /* if more than one input image: following images must match width and height of first image */ + image_w = image.GetBitmap(0)->Width(); + image_h = image.GetBitmap(0)->Height(); + + if (!bError) { + GLCD::cImageFile * outImage = NULL; // Load more in files - while (optind < argc && !bError) - { + while (optind < argc && !bError) { inFile = argv[optind++]; - inFormat = getFormat(inFile.c_str()); - if (inFormat == pfUndefined) - { - fprintf(stderr, "ERROR: You have to specify a correct extension for the %s\n", inFile.c_str()); - bError = true; - break; - } - pInBitmap = GetFileTranslator(inFormat); - if (!pInBitmap) - break; fprintf(stdout, "loading %s\n", inFile.c_str()); - if (pInBitmap->Load(nextImage, inFile)) - { + if (GLCD::cImage::LoadImage(nextImage, inFile) == false) { + fprintf(stderr, "ERROR: Failed loading file '%s', ignoring it ...\n", inFile.c_str()); + } else { + unsigned int nim_w = nextImage.GetBitmap(0)->Width(); + unsigned int nim_h = nextImage.GetBitmap(0)->Height(); + if ( nim_w != image_w || nim_h != image_h) { + fprintf(stderr, "ERROR: Image '%s' is not matching dimensions of first image, ignoring it ...\n", inFile.c_str()); + } else { uint16_t i; - for (i = 0; i < nextImage.Count(); i++) - { + for (i = 0; i < nextImage.Count(); i++) { image.AddBitmap(new GLCD::cBitmap(*nextImage.GetBitmap(i))); } + } } } if (bDelay) image.SetDelay(delay); - if (bInvert) - { + if (bInvert) { uint16_t i; - for (i = 0; i < image.Count(); i++) - { + for (i = 0; i < image.Count(); i++) { image.GetBitmap(i)->Invert(); } } + if (outExtension == "PBM") { + outImage = new GLCD::cPBMFile(); + } else { + outImage = new GLCD::cGLCDFile(); + } fprintf(stdout, "saving %s\n", outFile.c_str()); - bError = !pOutBitmap->Save(image, outFile); + bError = !outImage->Save(image, outFile); } if (bError) { return 4; @@ -262,18 +217,3 @@ int main(int argc, char *argv[]) { return 0; } - -void usage(void) -{ - fprintf(stdout, "\n"); - fprintf(stdout, "%s v%s\n", prgname, VERSION); - fprintf(stdout, "%s is a tool to convert images to a simple format (*.glcd)\n", prgname); - fprintf(stdout, " that is used by the graphlcd plugin for VDR.\n\n"); - fprintf(stdout, " Usage: %s [-n] -i file[s...] -o outfile \n\n", prgname); - fprintf(stdout, " -n --invert inverts the output (default: none)\n"); - fprintf(stdout, " -i --infile specifies the name of the input file[s]\n"); - fprintf(stdout, " -o --outfile specifies the name of the output file\n"); - fprintf(stdout, " -d --delay specifies the delay between multiple images [Default: %d ms] \n",delay); - fprintf(stdout, "\n" ); - fprintf(stdout, " example: %s -i vdr-logo.bmp -o vdr-logo.glcd \n", prgname ); -} |