diff options
Diffstat (limited to 'tools')
-rw-r--r-- | tools/Makefile | 4 | ||||
-rw-r--r-- | tools/convpic/Makefile | 11 | ||||
-rw-r--r-- | tools/convpic/bmp.c | 375 | ||||
-rw-r--r-- | tools/convpic/bmp.h | 45 | ||||
-rw-r--r-- | tools/convpic/convpic.c | 219 | ||||
-rw-r--r-- | tools/convpic/tiff.c | 201 | ||||
-rw-r--r-- | tools/convpic/tiff.h | 42 | ||||
-rw-r--r-- | tools/convpic/tuxbox.c | 280 | ||||
-rw-r--r-- | tools/convpic/tuxbox.h | 44 | ||||
-rw-r--r-- | tools/crtfont/Makefile | 9 | ||||
-rw-r--r-- | tools/crtfont/crtfont.c | 30 | ||||
-rw-r--r-- | tools/genfont/Makefile | 9 | ||||
-rw-r--r-- | tools/genfont/genfont.c | 31 | ||||
-rw-r--r-- | tools/lcdtestpattern/Makefile | 11 | ||||
-rw-r--r-- | tools/showpic/Makefile | 9 | ||||
-rw-r--r-- | tools/showpic/showpic.c | 466 | ||||
-rw-r--r-- | tools/showtext/Makefile | 9 | ||||
-rw-r--r-- | tools/showtext/showtext.c | 9 | ||||
-rw-r--r-- | tools/skintest/DejaVuSans.ttf | bin | 0 -> 720012 bytes | |||
-rw-r--r-- | tools/skintest/Makefile | 42 | ||||
-rw-r--r-- | tools/skintest/skintest.c | 190 | ||||
-rw-r--r-- | tools/skintest/test.skin | 50 |
22 files changed, 693 insertions, 1393 deletions
diff --git a/tools/Makefile b/tools/Makefile index 572067b..d923139 100644 --- a/tools/Makefile +++ b/tools/Makefile @@ -16,6 +16,7 @@ endif @$(MAKE) -C showpic all @$(MAKE) -C showtext all @$(MAKE) -C lcdtestpattern all + @$(MAKE) -C skintest all install: @$(MAKE) -C convpic install @@ -26,6 +27,7 @@ endif @$(MAKE) -C showpic install @$(MAKE) -C showtext install @$(MAKE) -C lcdtestpattern install + @$(MAKE) -C skintest install uninstall: @$(MAKE) -C convpic uninstall @@ -36,6 +38,7 @@ endif @$(MAKE) -C showpic uninstall @$(MAKE) -C showtext uninstall @$(MAKE) -C lcdtestpattern uninstall + @$(MAKE) -C skintest uninstall clean: @$(MAKE) -C convpic clean @@ -44,4 +47,5 @@ clean: @$(MAKE) -C showpic clean @$(MAKE) -C showtext clean @$(MAKE) -C lcdtestpattern clean + @$(MAKE) -C skintest clean diff --git a/tools/convpic/Makefile b/tools/convpic/Makefile index da5494b..3d57aa4 100644 --- a/tools/convpic/Makefile +++ b/tools/convpic/Makefile @@ -6,7 +6,7 @@ PRGNAME = convpic -OBJS = $(PRGNAME).o bmp.o tiff.o tuxbox.o +OBJS = $(PRGNAME).o INCLUDES += -I../../ LIBDIRS += -L../../glcdgraphics/ @@ -18,14 +18,11 @@ all: $(PRGNAME) # Implicit rules: %.o: %.c - $(CXX) $(CXXFLAGS) -c $(DEFINES) $(INCLUDES) $< + $(CXX) $(CXXEXTRA) $(CXXFLAGS) -c $(DEFINES) $(INCLUDES) $< # Dependencies: -MAKEDEP = $(CXX) -MM -MG -DEPFILE = .dependencies -$(DEPFILE): Makefile - @$(MAKEDEP) $(DEFINES) $(INCLUDES) $(OBJS:%.o=%.c) > $@ +DEPFILE = $(OBJS:%.o=%.d) -include $(DEPFILE) @@ -36,7 +33,7 @@ $(PRGNAME): $(OBJS) install: $(PRGNAME) install -d $(BINDIR) - install -m 755 -o root -g root $(STRIP) $(PRGNAME) $(BINDIR) + install -m 755 -o root -g root $(HAVE_STRIP) $(PRGNAME) $(BINDIR) uninstall: rm -f $(BINDIR)/$(PRGNAME) diff --git a/tools/convpic/bmp.c b/tools/convpic/bmp.c deleted file mode 100644 index 0829302..0000000 --- a/tools/convpic/bmp.c +++ /dev/null @@ -1,375 +0,0 @@ -/** - * GraphLCD plugin for the Video Disk Recorder - * - * bmp.c - bmp logo class - * - * (C) 2004 Andreas Brachold <vdr04 AT deltab de> - * (C) 2001-2004 Carsten Siebholz <c.siebholz AT t-online de> - **/ - -/*************************************************************************** - * * - * This program 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. * - * * - * This program 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 this program; * - * if not, write to the Free Software Foundation, Inc., * - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * - * * - ***************************************************************************/ - -#include <stdio.h> -#include <stdint.h> -#include <string.h> -#include <cstring> -#include <cstdlib> - -#include <glcdgraphics/bitmap.h> -#include <glcdgraphics/image.h> - -#include "bmp.h" - - -#pragma pack(1) -typedef struct BMPH { - uint16_t bmpIdentifier; - uint32_t bmpFileSize; - uint32_t bmpReserved; - uint32_t bmpBitmapDataOffset; - uint32_t bmpBitmapHeaderSize; - uint32_t bmpWidth; - uint32_t bmpHeight; - uint16_t bmpPlanes; - uint16_t bmpBitsPerPixel; - uint32_t bmpCompression; - uint32_t bmpBitmapDataSize; - uint32_t bmpHResolution; - uint32_t bmpVResolution; - uint32_t bmpColors; - uint32_t bmpImportantColors; -} BMPHEADER; // 54 bytes - -typedef struct RGBQ { - uint8_t rgbBlue; - uint8_t rgbGreen; - uint8_t rgbRed; - uint8_t rgbReserved; -} RGBQUAD; // 4 bytes -#pragma pack() - - -uint8_t bitmask[8] = {0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01}; -uint8_t bitmaskl[8] = {0x80, 0xc0, 0xe0, 0xf0, 0xf8, 0xfc, 0xfe, 0xff}; -uint8_t bitmaskr[8] = {0xff, 0x7f, 0x3f, 0x1f, 0x0f, 0x07, 0x03, 0x01}; - -cBMPFile::cBMPFile() -{ -} - -cBMPFile::~cBMPFile() -{ -} - -bool cBMPFile::Load(GLCD::cImage & image, const std::string & fileName) -{ - FILE *fIN; - BMPHEADER bmpHeader; - RGBQUAD *pPalette; - char *pByte; - char Dummy; - long iNumColors; - long iSize; - uint32_t x, y; - uint16_t iRead; - uint8_t * bitmap = NULL; - bool bInvert = false; - - if (fileName.length() > 0) - { - fIN = fopen(fileName.c_str(), "rb"); - if (fIN) - { - if (fread(&bmpHeader, sizeof(BMPHEADER), 1, fIN)!=1) - { - fclose(fIN); - return false; - } - - // check for Windows BMP - if (bmpHeader.bmpBitmapHeaderSize != 0x00000028 ) - { - fprintf(stderr, "ERROR: only Windows BMP images are allowed.\n"); - fclose(fIN); - return false; - } - - // check for 2 color - iNumColors = (1 << bmpHeader.bmpBitsPerPixel); - if (iNumColors != 2) - { - fprintf(stderr, "ERROR: the image has %ld colors, but only images with 2 colors are allowed.\n", iNumColors); - fclose(fIN); - return false; - } - - iSize = bmpHeader.bmpHeight * bmpHeader.bmpWidth; - - pPalette = (RGBQUAD *) malloc( iNumColors*sizeof(RGBQUAD)); - if (!pPalette) - { - fprintf(stderr, "ERROR: cannot allocate memory\n"); - fclose(fIN); - return false; - } - - if (fread( pPalette, iNumColors*sizeof(RGBQUAD), 1, fIN)!=1) - { - free(pPalette); - fclose(fIN); - return false; - } - - // check colors - if (pPalette->rgbBlue+pPalette->rgbGreen+pPalette->rgbRed < - (pPalette+1)->rgbBlue+(pPalette+1)->rgbGreen+(pPalette+1)->rgbRed) - { - // index 0 represents 'black', index 1 'white' - bInvert = !bInvert; - } - else - { - // index 0 represents 'white', index 1 'black' - } - - if (fseek(fIN, bmpHeader.bmpBitmapDataOffset, SEEK_SET)==EOF) - { - free(pPalette); - fclose(fIN); - return false; - } - - switch (bmpHeader.bmpCompression) - { - case 0: // BI_RGB no compression - image.Clear(); - image.SetWidth(bmpHeader.bmpWidth); - image.SetHeight(bmpHeader.bmpHeight); - image.SetDelay(100); - bitmap = new unsigned char[bmpHeader.bmpHeight * ((bmpHeader.bmpWidth + 7) / 8)]; - if (!bitmap) - { - fprintf(stderr, "ERROR: cannot allocate memory\n"); - free(pPalette); - fclose(fIN); - image.Clear(); - return false; - } - - for (y = bmpHeader.bmpHeight; y > 0; y--) - { - pByte = (char*)bitmap + (y-1)*((bmpHeader.bmpWidth+7)/8); - iRead = 0; - for (x = 0; x < bmpHeader.bmpWidth / 8; x++) - { - if (fread(pByte, sizeof(char), 1, fIN) != 1) - { - delete[] bitmap; - free(pPalette); - fclose(fIN); - image.Clear(); - return false; - } - iRead++; - if (bInvert) - *pByte = *pByte ^ 0xff; - pByte++; - } - - if (bmpHeader.bmpWidth % 8) - { - if (fread(pByte, sizeof(char), 1, fIN) != 1) - { - delete [] bitmap; - free(pPalette); - fclose(fIN); - image.Clear(); - return false; - } - iRead++; - if (bInvert) - *pByte = *pByte^0xff; - *pByte = *pByte & bitmaskl[bmpHeader.bmpWidth%8]; - pByte++; - } - - // Scan line must be 4-byte-alligned - while (iRead % 4) - { - if (fread(&Dummy, sizeof(char), 1, fIN) != 1) - { - delete [] bitmap; - free(pPalette); - fclose(fIN); - image.Clear(); - return false; - } - iRead++; - } - } - image.AddBitmap(new GLCD::cBitmap(bmpHeader.bmpWidth, bmpHeader.bmpHeight, bitmap)); - break; - case 1: // BI_RLE4 RLE 4bit/pixel - case 2: // BI_RLE8 RLE 8bit/pixel - case 3: // BI_BITFIELDS - default: - fprintf(stderr, "ERROR: only uncompressed RGB images are allowed.\n"); - - free(pPalette); - fclose(fIN); - return false; - } - fclose(fIN); - } - else - { - fprintf(stderr, "ERROR: cannot open picture %s\n", fileName.c_str()); - } - } - else - { - fprintf(stderr, "ERROR: no FileName given!\n"); - } - return true; -} - -bool cBMPFile::Save(const GLCD::cBitmap * bitmap, const std::string & fileName) -{ - FILE *fOut; - BMPHEADER bmpHeader; - RGBQUAD bmpColor1, bmpColor2; - uint32_t dBDO, dBDSx, dBDS; - char *pByte; - char Dummy = 0x00; - uint32_t x, y; - uint16_t iWrote; - const uint8_t * bmpdata = bitmap->Data(); - - if (bitmap - && bitmap->Width() > 0 - && bitmap->Height() > 0) - { - memset(&bmpHeader, 0, sizeof(BMPHEADER)); - - dBDO = sizeof(BMPHEADER)+2*sizeof(RGBQUAD); - dBDSx = ((bitmap->Width() + 7) / 8 + 3) & 0xfffffffc; - dBDS = dBDSx * bitmap->Height(); - - bmpHeader.bmpIdentifier = 0x4d42; // "BM" - bmpHeader.bmpFileSize = dBDO + dBDS; - bmpHeader.bmpBitmapDataOffset = dBDO; - bmpHeader.bmpBitmapHeaderSize = 0x28; - bmpHeader.bmpWidth = bitmap->Width(); - bmpHeader.bmpHeight = bitmap->Height(); - bmpHeader.bmpPlanes = 0x01; - bmpHeader.bmpBitsPerPixel = 0x01; - bmpHeader.bmpCompression = 0x00; - bmpHeader.bmpBitmapDataSize = dBDS; - bmpHeader.bmpHResolution = 0xb13; // 72dpi - bmpHeader.bmpVResolution = 0xb13; // 72dpi - bmpHeader.bmpColors = 0x02; - bmpHeader.bmpImportantColors = 0x02; - - bmpColor1.rgbBlue = 0x00; - bmpColor1.rgbGreen = 0x00; - bmpColor1.rgbRed = 0x00; - bmpColor1.rgbReserved = 0x00; - bmpColor2.rgbBlue = 0xff; - bmpColor2.rgbGreen = 0xff; - bmpColor2.rgbRed = 0xff; - bmpColor2.rgbReserved = 0x00; - - - fOut = fopen(fileName.c_str(), "wb"); - if (!fOut) - { - fprintf(stderr,"Cannot create file: %s\n", fileName.c_str()); - return false; - } - fwrite(&bmpHeader, sizeof(BMPHEADER), 1, fOut); - fwrite(&bmpColor1, sizeof(RGBQUAD), 1, fOut); - fwrite(&bmpColor2, sizeof(RGBQUAD), 1, fOut); - - for (y=bitmap->Height(); y>0; y--) - { - pByte = (char*)bmpdata + (y-1)*((bitmap->Width()+7)/8); - iWrote = 0; - for (x=0; x<(uint32_t) bitmap->Width()/8; x++) - { - *pByte = *pByte^0xff; - if (fwrite(pByte, sizeof(char), 1, fOut)!=1) - { - fclose(fOut); - return false; - } - iWrote++; - pByte++; - } - // Scan line must be 4-byte-alligned - while (iWrote%4) - { - if (fwrite(&Dummy, sizeof(char), 1, fOut)!=1) - { - fclose(fOut); - return 3; - } - iWrote++; - } - } - fclose(fOut); - } - return true; -} - -bool cBMPFile::Save(GLCD::cImage & image, const std::string & fileName) -{ - const GLCD::cBitmap * bitmap; - - if (image.Count() == 1) - { - bitmap = image.GetBitmap(0); - if (bitmap) - { - if (!Save(bitmap, fileName)) - { - return false; - } - } - } - else - { - uint16_t i; - char tmpStr[256]; - - for (i = 0; i < image.Count(); i++) - { - sprintf(tmpStr, "%.248s.%05d", fileName.c_str(), i); - bitmap = image.GetBitmap(i); - if (bitmap) - { - if (!Save(bitmap, tmpStr)) - { - return false; - } - } - } - } - return true; -} diff --git a/tools/convpic/bmp.h b/tools/convpic/bmp.h deleted file mode 100644 index 8419838..0000000 --- a/tools/convpic/bmp.h +++ /dev/null @@ -1,45 +0,0 @@ -/** - * GraphLCD plugin for the Video Disk Recorder - * - * bmp.h - bmp logo class - * - * (C) 2004 Andreas Brachold <vdr04 AT deltab de> - * (C) 2001-2004 Carsten Siebholz <c.siebholz AT t-online de> - **/ - -/*************************************************************************** - * * - * This program 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. * - * * - * This program 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 this program; * - * if not, write to the Free Software Foundation, Inc., * - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * - * * - ***************************************************************************/ - -#ifndef _BMP_H_ -#define _BMP_H_ - -#include <glcdgraphics/imagefile.h> - -class cBMPFile : public GLCD::cImageFile -{ -private: - bool Save(const GLCD::cBitmap * bitmap, const std::string & fileName); -public: - cBMPFile(); - virtual ~cBMPFile(); - virtual bool Load(GLCD::cImage & image, const std::string & fileName); - virtual bool Save(GLCD::cImage & image, const std::string & fileName); -}; - -#endif diff --git a/tools/convpic/convpic.c b/tools/convpic/convpic.c index 732738c..0adba60 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,46 @@ #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 or from a GLCD file.\n\n", prgname); + fprintf(stdout, " Usage: %s [-n] -i file[s...] -o outfile \n\n", prgname); + fprintf(stdout, " -n --invert inverts the output (default: no)\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 (in ms) between multiple images (default: %d)\n",delay); + fprintf(stdout, "\n" ); + fprintf(stdout, " examples:\n"); + fprintf(stdout, " # convert an input image to a single frame GLCD\n"); + fprintf(stdout, " %s -i vdr-logo.bmp -o vdr-logo.glcd\n", prgname ); + fprintf(stdout, " # convert multiple input images to an animated GLCD (delay: 500 ms between two frames)\n"); + fprintf(stdout, " %s -d 500 -i vdr-logo-??.bmp -o vdr-logo.glcd\n", prgname ); + fprintf(stdout, " # convert a GLCD file to PBM file(s)\n"); + fprintf(stdout, " %s -i vdr-logo.glcd -o vdr-logo.pbm\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 +111,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 +222,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 ); -} diff --git a/tools/convpic/tiff.c b/tools/convpic/tiff.c deleted file mode 100644 index 4b8bf0e..0000000 --- a/tools/convpic/tiff.c +++ /dev/null @@ -1,201 +0,0 @@ -/** - * GraphLCD plugin for the Video Disk Recorder - * - * tiff.c - tiff logo class - * - * (c) 2004 Andreas Brachold <vdr04 AT deltab de> - * (c) 2001-2004 Carsten Siebholz <c.siebholz AT t-online de> - **/ - -/*************************************************************************** - * * - * This program 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. * - * * - * This program 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 this program; * - * if not, write to the Free Software Foundation, Inc., * - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * - * * - ***************************************************************************/ - -#include <stdio.h> -#include <string.h> - -#include <string> - -#include <glcdgraphics/bitmap.h> -#include <glcdgraphics/image.h> - -#include "tiff.h" - - -#pragma pack(1) -typedef struct TIFFT{ - unsigned short tag; - unsigned short type; - unsigned long length; - /* 1 = BYTE. 8-bit unsigned integer. */ - /* 2 = ASCII. 8-bit bytes that store ASCII codes; the last byte must be null. */ - /* 3 = SHORT. A 16-bit (2-byte) unsigned integer. */ - /* 4 = LONG. A 32-bit (4-byte) unsigned integer. */ - /* 5 = RATIONAL. Two LONGs: the first represents the numerator of a fraction, the second the denominator. */ - unsigned long off_val; -} TIFFTAG; -#pragma pack() - -#define GETANDCHECK { t=fgetc(fIN);if(t==EOF) {fclose(fIN);return false;};} - -cTIFFFile::cTIFFFile() -{ -} - -cTIFFFile::~cTIFFFile() -{ -} - -bool cTIFFFile::Load(GLCD::cImage & image, const std::string & fileName) -{ - FILE *fIN; - TIFFTAG tifftag; - unsigned int tiff_header, tiff_anztags, tiff_data; - unsigned char cl,ch,y,i; - unsigned char height, width, strip, invert; - unsigned char fLittleEndian=0; - int j; - int t; - unsigned char *bitmap = NULL; - bool bInvert = false; - - if (fileName.length() > 0) - { - fIN = fopen(fileName.c_str(), "rb"); - if (fIN) - { - // isyslog("graphlcd plugin: try to load logo %s.", szFileName); - if (fseek(fIN, 0, SEEK_SET)==EOF) - { - fclose(fIN); - return false; - } - GETANDCHECK; cl=(unsigned char)t; - GETANDCHECK; ch=(unsigned char)t; - if ((cl==0x49) && (ch==0x49)) - { - fLittleEndian=1; - } - - if (fseek(fIN, 4, SEEK_SET)==EOF) - { - fclose(fIN); - return false; - } - GETANDCHECK; cl=(unsigned char)t; - GETANDCHECK; ch=(unsigned char)t; - tiff_header = cl+256*ch; - //printf("tiff_header:%d %x\n", tiff_header, tiff_header); - - if (fseek(fIN, tiff_header, SEEK_SET)==EOF) - { - fclose(fIN); - return false; - } - - GETANDCHECK; cl=(unsigned char)t; - GETANDCHECK; ch=(unsigned char)t; - tiff_anztags = cl+256*ch; - //printf("tiff_anztags:%d %x\n", tiff_anztags, tiff_anztags); - - height=0; - width=0; - strip=0; - invert=0; - for (i=0; (i<tiff_anztags)&&(!height||!width||!strip||!invert); i++) - { - if (fread(&tifftag, sizeof(tifftag), 1, fIN)!=1) - { - fclose(fIN); - return false; - } - if (tifftag.tag==0x0100) width=tifftag.off_val; - if (tifftag.tag==0x0101) height=tifftag.off_val; - if (tifftag.tag==0x0111) strip=tifftag.off_val; - if (tifftag.tag==0x0106) invert=tifftag.off_val+1; - //printf("tag%d: %d %d %ld %ld\n", i,tifftag.tag, tifftag.type, tifftag.length, tifftag.off_val ); - } - - if (fseek(fIN,strip, SEEK_SET)==EOF) - { - fclose(fIN); - return false; - } - GETANDCHECK; cl=(unsigned char)t; - GETANDCHECK; ch=(unsigned char)t; - tiff_data = cl+256*ch; - //printf("tiff_data:%d %x\n", tiff_data, tiff_data); - - if (fseek(fIN, tiff_data, SEEK_SET)==EOF) - { - fclose(fIN); - return false; - } - - - image.Clear(); - image.SetWidth(width); - image.SetHeight(height); - image.SetDelay(100); - bitmap = new unsigned char[height * ((width + 7) / 8)]; - if (bitmap) - { - if (fread(bitmap, height*((width+7)/8), 1, fIN)!=1) - { - delete [] bitmap; - fclose(fIN); - image.Clear(); - return false; - } - - if (invert-1==1) bInvert = !bInvert; // 'Black is zero' - if (bInvert) - { - for (j=0; j < height * ((width+7)/8); j++) - { - (*(bitmap+j)) = (*(bitmap+j))^0xff; - } - } - - // cut the rest of the line - if (width%8) - { - for (y=1; y<=height; y++) { - j=y*((width+7)/8)-1; - (*(bitmap+j)) = ((*(bitmap+j))>>(8-width%8))<<(8-width%8); - } - } - image.AddBitmap(new GLCD::cBitmap(width, height, bitmap)); - } - else - { - fprintf(stderr, "ERROR: cannot allocate memory\n"); - } - fclose(fIN); - } - else - { - fprintf(stderr, "ERROR: cannot open picture %s\n", fileName.c_str()); - } - } - else - { - fprintf(stderr, "ERROR: no szFileName given!\n"); - } - return true; -} diff --git a/tools/convpic/tiff.h b/tools/convpic/tiff.h deleted file mode 100644 index f6e66c1..0000000 --- a/tools/convpic/tiff.h +++ /dev/null @@ -1,42 +0,0 @@ -/** - * GraphLCD plugin for the Video Disk Recorder - * - * tiff.h - tiff logo class - * - * (c) 2004 Andreas Brachold <vdr04 AT deltab de> - * (c) 2001-2004 Carsten Siebholz <c.siebholz AT t-online de> - **/ - -/*************************************************************************** - * * - * This program 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. * - * * - * This program 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 this program; * - * if not, write to the Free Software Foundation, Inc., * - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * - * * - ***************************************************************************/ - -#ifndef _TIFF_H_ -#define _TIFF_H_ - -#include <glcdgraphics/imagefile.h> - -class cTIFFFile : public GLCD::cImageFile -{ -public: - cTIFFFile(); - virtual ~cTIFFFile(); - virtual bool Load(GLCD::cImage & image, const std::string & fileName); -}; - -#endif diff --git a/tools/convpic/tuxbox.c b/tools/convpic/tuxbox.c deleted file mode 100644 index 55d6e1d..0000000 --- a/tools/convpic/tuxbox.c +++ /dev/null @@ -1,280 +0,0 @@ -/** - * GraphLCD plugin for the Video Disk Recorder - * - * tuxbox.c - tuxbox logo class - * - * (c) 2004 Andreas Brachold <vdr04 AT deltab de> - **/ - -/*************************************************************************** - * * - * This program 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. * - * * - * This program 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 this program; * - * if not, write to the Free Software Foundation, Inc., * - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * - * * - ***************************************************************************/ - -#include <stdio.h> -#include <string.h> -#include <netinet/in.h> - -#include <string> - -#include <glcdgraphics/bitmap.h> -#include <glcdgraphics/image.h> - -#include "tuxbox.h" - -#pragma pack(1) -struct ani_header { - unsigned char magic[4]; // = "LCDA" - unsigned short format; // Format - unsigned short width; // Breite - unsigned short height; // Höhe - unsigned short count; // Anzahl Einzelbilder - unsigned long delay; // µs zwischen Einzelbildern -}; -#pragma pack() - -cTuxBoxFile::cTuxBoxFile() -{ -} - -cTuxBoxFile::~cTuxBoxFile() -{ -} - -bool cTuxBoxFile::Load(GLCD::cImage & image, const std::string & fileName) -{ - bool ret = false; - FILE * fIN; - long fileLen; - struct ani_header header; - bool bInvert = false; - - fIN = fopen(fileName.c_str(), "rb"); - if (fIN) - { - // get len of file - if (fseek(fIN, 0, SEEK_END)) - { - fclose(fIN); - return false; - } - fileLen = ftell(fIN); - - // rewind and get Header - if (fseek(fIN, 0, SEEK_SET)) - { - fclose(fIN); - return false; - } - - // Read header - if (fread(&header, sizeof(header), 1, fIN) != 1) - { - fclose(fIN); - return false; - } - - image.Clear(); - image.SetWidth(ntohs(header.width)); - image.SetHeight(ntohs(header.height)); - image.SetDelay(ntohl(header.delay) / 1000); - - // check Header - if (strncmp((const char*)header.magic, "LCDA", sizeof(header.magic)) || - !image.Width() || !image.Height() || ntohs(header.format) != 0) - { - fprintf(stderr, "ERROR: load %s failed, wrong header.\n", fileName.c_str()); - fclose(fIN); - return false; - } - - //fprintf(stderr,"%d %dx%d (%d %d) %d\n",ntohs(header.count),image.Width(),image.Height(),fileLen, ( (ntohs(header.count) * (image.Width() * ((image.Height() + 7) / 8))) + sizeof(header)),lhdr.delay); - - // check file length - if (!ntohs(header.count) - || (fileLen != (long) ( (ntohs(header.count) * (image.Width() * ((image.Height() + 7) / 8))) + sizeof(header)))) - { - fprintf(stderr, "ERROR: load %s failed, wrong size.\n", fileName.c_str()); - fclose(fIN); - return false; - } - // Set minimal limit for next image - if (image.Delay() < 10) - image.SetDelay(10); - for (unsigned int n=0;n<ntohs(header.count);++n) - { - ret = false; - unsigned int nBmpSize = image.Height() * ((image.Width() + 7) / 8); - unsigned char *bitmap = new unsigned char[nBmpSize]; - if (!bitmap) - { - fprintf(stderr, "ERROR: malloc failed."); - break; - } - unsigned int nAniSize = image.Width() * ((image.Height() + 7) / 8); - unsigned char *pAni = new unsigned char[nAniSize]; - if (!pAni) - { - delete[] bitmap; - fprintf(stderr, "ERROR: malloc failed."); - break; - } - - if (1 != fread(pAni, nAniSize, 1, fIN)) - { - fprintf(stderr,"ERROR: Cannot read filedata: %s\n", fileName.c_str()); - delete[] bitmap; - delete[] pAni; - break; - } - - vert2horz(pAni,bitmap, image.Width(), image.Height()); - delete[] pAni; - - if (bInvert) - for (unsigned int i=0;i<nBmpSize;++i) - bitmap[i] ^= 0xFF; - - image.AddBitmap(new GLCD::cBitmap(image.Width(), image.Height(), bitmap)); - ret = true; - } - fclose(fIN); - if (!ret) - image.Clear(); - } - return ret; -} - - -bool cTuxBoxFile::Save(GLCD::cImage & image, const std::string & fileName) -{ - FILE * fOut; - struct ani_header header; - bool bRet = false; - - if (image.Count() > 0 - && image.Width() - && image.Height()) - { - memcpy(header.magic, "LCDA", 4); - header.format = htons(0); - header.width = htons(image.Width()); - header.height = htons(image.Height()); - header.count = htons(image.Count()); - header.delay = htonl(image.Delay() * 1000); - - - if (image.Width() != 120 || image.Height() != 64) - { - fprintf(stderr,"WARNING: Maybe wrong image dimension (for all I know is 120x64 wanted) %s\n", fileName.c_str()); - } - - fOut = fopen(fileName.c_str(), "wb"); - if (!fOut) { - fprintf(stderr,"ERROR: Cannot create file: %s\n", fileName.c_str()); - return false; - } - - if (1 != fwrite(&header, sizeof(header), 1, fOut)) - { - fprintf(stderr,"ERROR: Cannot write fileheader: %s\n", fileName.c_str()); - fclose(fOut); - return false; - } - - for (unsigned int n = 0; n < image.Count(); n++) - { - bRet = false; - unsigned int nAniSize = image.Width() * ((image.Height() + 7) / 8); - unsigned char *pAni = new unsigned char[nAniSize]; - if (!pAni) - { - fprintf(stderr, "ERROR: malloc failed."); - break; - } - horz2vert(image.GetBitmap(n)->Data(), pAni, image.Width(), image.Height()); - - if (1 != fwrite(pAni, nAniSize, 1, fOut)) - { - delete [] pAni; - fprintf(stderr,"ERROR: Cannot write filedata: %s\n", fileName.c_str()); - break; - } - delete [] pAni; - bRet = true; - } - - fclose(fOut); - } - return bRet; -} - -/** Translate memory alignment from vertical to horizontal -rotate from {Byte} to {Byte} -{o}[o][o][o][o][o][o][o] => { oooooooo } -{o}[o][o][o][o][o][o][o] => [ oooooooo ] -{o}[o][o][o][o][o][o][o] => [ oooooooo ] -{o}[o][o][o][o][o][o][o] => [ oooooooo ] -{o}[o][o][o][o][o][o][o] => [ oooooooo ] -{o}[o][o][o][o][o][o][o] => [ oooooooo ] -{o}[o][o][o][o][o][o][o] => [ oooooooo ] -{o}[o][o][o][o][o][o][o] => [ oooooooo ]*/ -void cTuxBoxFile::vert2horz(const unsigned char* source, unsigned char* dest, int width, int height) { - int x, y, off; - memset(dest,0,height*((width+7)/8)); - - for (y=0; y<height; ++y) - { - for (x=0; x<width; ++x) - { - off = x + ((y/8) * width); - if (source[off] & (0x1 << (y % 8))) - { - off = (x / 8) + (y * ((width+7)/8)); - dest[off] |= (unsigned char)(0x80 >> (x % 8)); - } - } - } -} - -/** Translate memory alignment from horizontal to vertical (rotate byte) -rotate from {Byte} to {Byte} -{ oooooooo } => {o}[o][o][o][o][o][o][o] -[ oooooooo ] => {o}[o][o][o][o][o][o][o] -[ oooooooo ] => {o}[o][o][o][o][o][o][o] -[ oooooooo ] => {o}[o][o][o][o][o][o][o] -[ oooooooo ] => {o}[o][o][o][o][o][o][o] -[ oooooooo ] => {o}[o][o][o][o][o][o][o] -[ oooooooo ] => {o}[o][o][o][o][o][o][o] -[ oooooooo ] => {o}[o][o][o][o][o][o][o]*/ -void cTuxBoxFile::horz2vert(const unsigned char* source, unsigned char* dest, int width, int height) { - int x, y, off; - memset(dest,0,width*((height+7)/8)); - - for (y=0; y<height; ++y) - { - for (x=0; x<width; ++x) - { - off = (x / 8) + ((y) * ((width+7)/8)); - if (source[off] & (0x80 >> (x % 8))) - { - off = x + ((y/8) * width); - dest[off] |= (unsigned char)(0x1 << (y % 8)); - } - } - } -} diff --git a/tools/convpic/tuxbox.h b/tools/convpic/tuxbox.h deleted file mode 100644 index 1214fb5..0000000 --- a/tools/convpic/tuxbox.h +++ /dev/null @@ -1,44 +0,0 @@ -/** - * GraphLCD plugin for the Video Disk Recorder - * - * tuxbox.h - tuxbox logo class - * - * (c) 2004 Andreas Brachold <vdr04 AT deltab de> - **/ - -/*************************************************************************** - * * - * This program 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. * - * * - * This program 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 this program; * - * if not, write to the Free Software Foundation, Inc., * - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * - * * - ***************************************************************************/ -#ifndef _TUXBOX_H_ -#define _TUXBOX_H_ - -#include <glcdgraphics/imagefile.h> - -class cTuxBoxFile : public GLCD::cImageFile -{ -private: - void vert2horz(const unsigned char* source, unsigned char* dest, int width, int height); - void horz2vert(const unsigned char* source, unsigned char* dest, int width, int height); -public: - cTuxBoxFile(); - virtual ~cTuxBoxFile(); - virtual bool Load(GLCD::cImage & image, const std::string & fileName); - virtual bool Save(GLCD::cImage & image, const std::string & fileName); -}; - -#endif diff --git a/tools/crtfont/Makefile b/tools/crtfont/Makefile index 592d123..6c6abdf 100644 --- a/tools/crtfont/Makefile +++ b/tools/crtfont/Makefile @@ -17,14 +17,11 @@ all: $(PRGNAME) # Implicit rules: %.o: %.c - $(CXX) $(CXXFLAGS) -c $(DEFINES) $(INCLUDES) $< + $(CXX) $(CXXEXTRA) $(CXXFLAGS) -c $(DEFINES) $(INCLUDES) $< # Dependencies: -MAKEDEP = $(CXX) -MM -MG -DEPFILE = .dependencies -$(DEPFILE): Makefile - @$(MAKEDEP) $(DEFINES) $(INCLUDES) $(OBJS:%.o=%.c) > $@ +DEPFILE = $(OBJS:%.o=%.d) -include $(DEPFILE) @@ -35,7 +32,7 @@ $(PRGNAME): $(OBJS) install: $(PRGNAME) install -d $(BINDIR) - install -m 755 -o root -g root $(STRIP) $(PRGNAME) $(BINDIR) + install -m 755 -o root -g root $(HAVE_STRIP) $(PRGNAME) $(BINDIR) uninstall: rm -f $(BINDIR)/$(PRGNAME) diff --git a/tools/crtfont/crtfont.c b/tools/crtfont/crtfont.c index 97e57fe..fc7beef 100644 --- a/tools/crtfont/crtfont.c +++ b/tools/crtfont/crtfont.c @@ -10,7 +10,9 @@ * This file is released under the GNU General Public License. Refer * to the COPYING file distributed with this package. * - * (c) 2004 Andreas Regel <andreas.regel AT powarman.de> + * (c) 2004 Andreas Regel <andreas.regel AT powarman.de> + * (c) 2010-2011 Wolfgang Astleitner <mrwastl AT users sourceforge net> + * Andreas 'randy' Weinberger */ #include <getopt.h> @@ -20,6 +22,8 @@ #include <string.h> #include <glcdgraphics/bitmap.h> #include <glcdgraphics/font.h> +#include <glcdgraphics/image.h> +#include <glcdgraphics/pbm.h> static const char *prgname = "crtfont"; static const char *version = "0.1.6"; @@ -151,15 +155,25 @@ int main(int argc, char *argv[]) // Load Picture switch (picFormat) { - case PBM: - bitmap = new GLCD::cBitmap(0, 0); - bitmap->LoadPBM(picName); - if (!bitmap) - { + case PBM: { + GLCD::cPBMFile pbm; + GLCD::cImage* image = new GLCD::cImage(); + + if (!image) + return 3; + + if (pbm.Load(*image, picName) == false) { fprintf(stderr, "Cannot open file: %s\n",picName); + delete image; return 2; } - break; + + const GLCD::cBitmap * pbmbm = image->GetBitmap(); + bitmap = new GLCD::cBitmap(*pbmbm); + delete image; + pbmbm = NULL; + } + break; default: return 2; @@ -296,7 +310,7 @@ void usage(void) fprintf(stdout, " graphlcd plugin for VDR.\n\n"); fprintf(stdout, " Usage: %s -f <format> -b bmpfile -d descfile -o outfile\n\n", prgname); fprintf(stdout, " -f --format specifies the format of the bitmap. Possible values are:\n"); - fprintf(stdout, " PBM : file is an binary PBM file\n" ); + fprintf(stdout, " PBM : file is a binary PBM file\n" ); fprintf(stdout, " -b --bmpfile specifies the name of the bitmap file (*.pbm)\n"); fprintf(stdout, " -d --descfile specifies the name of the description file (*.desc)\n"); fprintf(stdout, " -o --outfile specifies the name of the output file (*.fnt)\n"); diff --git a/tools/genfont/Makefile b/tools/genfont/Makefile index e516a21..f97d8e7 100644 --- a/tools/genfont/Makefile +++ b/tools/genfont/Makefile @@ -20,14 +20,11 @@ all: $(PRGNAME) # Implicit rules: %.o: %.c - $(CXX) $(CXXFLAGS) -c $(DEFINES) $(INCLUDES) $< + $(CXX) $(CXXEXTRA) $(CXXFLAGS) -c $(DEFINES) $(INCLUDES) $< # Dependencies: -MAKEDEP = $(CXX) -MM -MG -DEPFILE = .dependencies -$(DEPFILE): Makefile - @$(MAKEDEP) $(DEFINES) $(INCLUDES) $(OBJS:%.o=%.c) > $@ +DEPFILE = $(OBJS:%.o=%.d) -include $(DEPFILE) @@ -38,7 +35,7 @@ $(PRGNAME): $(OBJS) install: $(PRGNAME) install -d $(BINDIR) - install -m 755 -o root -g root $(STRIP) $(PRGNAME) $(BINDIR) + install -m 755 -o root -g root $(HAVE_STRIP) $(PRGNAME) $(BINDIR) uninstall: rm -f $(BINDIR)/$(PRGNAME) diff --git a/tools/genfont/genfont.c b/tools/genfont/genfont.c index 7553e4c..775d142 100644 --- a/tools/genfont/genfont.c +++ b/tools/genfont/genfont.c @@ -7,7 +7,9 @@ * This file is released under the GNU General Public License. Refer * to the COPYING file distributed with this package. * - * (c) 2004 Andreas Regel <andreas.regel AT powarman.de> + * (c) 2004-2010 Andreas Regel <andreas.regel AT powarman.de> + * (c) 2010-2011 Wolfgang Astleitner <mrwastl AT users sourceforge net> + * Andreas 'randy' Weinberger */ #include <getopt.h> @@ -17,6 +19,8 @@ #include <glcdgraphics/bitmap.h> #include <glcdgraphics/font.h> +#include <glcdgraphics/image.h> +#include <glcdgraphics/pbm.h> static const char *prgname = "genfont"; static const char *version = "0.0.2"; @@ -136,13 +140,14 @@ int main(int argc, char *argv[]) fprintf(descFile, "spacebetween:%d\n", 0); fprintf(descFile, "spacewidth:%d\n", 0); - for (unsigned int i = 0; i < 256; i++) + for (uint32_t i = 0; i < 256; i++) { - const GLCD::cBitmap * charBitmap = font.GetCharacter((char) i); + const GLCD::cBitmap * charBitmap = font.GetCharacter(i); + if (charBitmap == NULL) continue; - bitmap->DrawBitmap(posX, posY, *charBitmap, GLCD::clrBlack); + bitmap->DrawBitmap(posX, posY, *charBitmap); fprintf(descFile, "%d %d ", posX, i); posX += charBitmap->Width(); if ((i % 32) == 31) @@ -156,9 +161,23 @@ int main(int argc, char *argv[]) if (posX > 0) // write last end marker fprintf(descFile, "%d\n", posX); fileName = outputName + ".pbm"; - bitmap->SavePBM(fileName); - delete bitmap; + + GLCD::cPBMFile pbm; + GLCD::cImage* image = new GLCD::cImage(); + + if (!image) + return 3; + + image->AddBitmap(bitmap); + + if (pbm.Save(*image, fileName) == false) { + fprintf(stderr, "Cannot save file: %s\n",fileName.c_str()); + delete image; + return 2; + } + fclose(descFile); + delete image; } fprintf(stdout, "Font successfully generated.\n"); diff --git a/tools/lcdtestpattern/Makefile b/tools/lcdtestpattern/Makefile index 51b1123..e29305b 100644 --- a/tools/lcdtestpattern/Makefile +++ b/tools/lcdtestpattern/Makefile @@ -18,25 +18,22 @@ all: $(PRGNAME) # Implicit rules: %.o: %.c - $(CXX) $(CXXFLAGS) -c $(DEFINES) $(INCLUDES) $< + $(CXX) $(CXXEXTRA) $(CXXFLAGS) -c $(DEFINES) $(INCLUDES) $< # Dependencies: -MAKEDEP = $(CXX) -MM -MG -DEPFILE = .dependencies -$(DEPFILE): Makefile - @$(MAKEDEP) $(DEFINES) $(INCLUDES) $(OBJS:%.o=%.c) > $@ +DEPFILE = $(OBJS:%.o=%.d) -include $(DEPFILE) # The main program: $(PRGNAME): $(OBJS) - $(CXX) $(CXXFLAGS) $(LDFLAGS) -rdynamic $(OBJS) $(LIBS) $(LIBDIRS) -lglcdgraphics -lglcddrivers -lstdc++ -o $(PRGNAME) + $(CXX) $(CXXFLAGS) $(LDFLAGS) -rdynamic $(OBJS) $(LIBS) $(LIBDIRS) -lglcddrivers -lglcdgraphics -lstdc++ -o $(PRGNAME) install: $(PRGNAME) install -d $(BINDIR) - install -m 755 -o root -g root $(STRIP) $(PRGNAME) $(BINDIR) + install -m 755 -o root -g root $(HAVE_STRIP) $(PRGNAME) $(BINDIR) uninstall: rm -f $(BINDIR)/$(PRGNAME) diff --git a/tools/showpic/Makefile b/tools/showpic/Makefile index 52c1850..de7560a 100644 --- a/tools/showpic/Makefile +++ b/tools/showpic/Makefile @@ -18,14 +18,11 @@ all: $(PRGNAME) # Implicit rules: %.o: %.c - $(CXX) $(CXXFLAGS) -c $(DEFINES) $(INCLUDES) $< + $(CXX) $(CXXEXTRA) $(CXXFLAGS) -c $(DEFINES) $(INCLUDES) $< # Dependencies: -MAKEDEP = $(CXX) -MM -MG -DEPFILE = .dependencies -$(DEPFILE): Makefile - @$(MAKEDEP) $(DEFINES) $(INCLUDES) $(OBJS:%.o=%.c) > $@ +DEPFILE = $(OBJS:%.o=%.d) -include $(DEPFILE) @@ -36,7 +33,7 @@ $(PRGNAME): $(OBJS) install: $(PRGNAME) install -d $(BINDIR) - install -m 755 -o root -g root $(STRIP) $(PRGNAME) $(BINDIR) + install -m 755 -o root -g root $(HAVE_STRIP) $(PRGNAME) $(BINDIR) uninstall: rm -f $(BINDIR)/$(PRGNAME) diff --git a/tools/showpic/showpic.c b/tools/showpic/showpic.c index ebeb73f..7c05ca3 100644 --- a/tools/showpic/showpic.c +++ b/tools/showpic/showpic.c @@ -9,7 +9,9 @@ * This file is released under the GNU General Public License. Refer * to the COPYING file distributed with this package. * - * (c) 2004 Andreas Regel <andreas.regel AT powarman.de> + * (c) 2004-2010 Andreas Regel <andreas.regel AT powarman.de> + * (c) 2010-2013 Wolfgang Astleitner <mrwastl AT users sourceforge net> + * Andreas 'randy' Weinberger */ #include <stdio.h> @@ -18,240 +20,276 @@ #include <getopt.h> #include <dlfcn.h> #include <unistd.h> -#include <syslog.h> #include <signal.h> #include <string> #include <glcdgraphics/bitmap.h> -#include <glcdgraphics/glcd.h> #include <glcdgraphics/image.h> + #include <glcddrivers/config.h> #include <glcddrivers/driver.h> #include <glcddrivers/drivers.h> static const char *prgname = "showpic"; -static const char *version = "0.1.2"; +static const char *version = "0.1.3"; static const int kDefaultSleepMs = 100; static const char * kDefaultConfigFile = "/etc/graphlcd.conf"; static volatile bool stopProgramm = false; -static void sighandler(int signal) -{ - switch (signal) - { - case SIGINT: - case SIGQUIT: - case SIGTERM: - stopProgramm = true; - } +static void sighandler(int signal) { + switch (signal) { + case SIGINT: + case SIGQUIT: + case SIGTERM: + stopProgramm = true; + } } -void usage() -{ - fprintf(stdout, "\n"); - fprintf(stdout, "%s v%s\n", prgname, version); - fprintf(stdout, "%s is a tool to show an image on a LCD.\n", prgname); - fprintf(stdout, "The image must be in a special format (*.glcd).\n"); - fprintf(stdout, "You can create such images with the convpic tool.\n\n"); - fprintf(stdout, " Usage: %s [-c CONFIGFILE] [-d DISPLAY] [-s SLEEP] [-uie] file [more files]\n\n", prgname); - fprintf(stdout, " -c --config specifies the location of the config file\n"); - fprintf(stdout, " (default: /etc/graphlcd.conf)\n"); - fprintf(stdout, " -d --display specifies the output display (default is the first one)\n"); - fprintf(stdout, " -u --upsidedown rotates the output by 180 degrees (default: no)\n"); - fprintf(stdout, " -i --invert inverts the output (default: no)\n"); - fprintf(stdout, " -e --endless show all images in endless loop (default: no)\n"); - fprintf(stdout, " -s --sleep set sleeptime between two images [ms] (default: %d ms)\n", kDefaultSleepMs); - fprintf(stdout, " -b --brightness set brightness for display if driver support it [%%]\n"); - fprintf(stdout, " (default: config file value)\n"); - fprintf(stdout, "\n" ); - fprintf(stdout, " examples: %s -c /etc/graphlcd.conf vdr-logo.glcd\n", prgname); - fprintf(stdout, " %s -c /etc/graphlcd.conf -d LCD_T6963 -u -i vdr-logo.glcd\n", prgname); - fprintf(stdout, "\n" ); +void usage() { + fprintf(stdout, "\n"); + fprintf(stdout, "%s v%s\n", prgname, version); + fprintf(stdout, "%s is a tool to show an image on an LCD.\n", prgname); + fprintf(stdout, "The image format must be supported by libglcdgraphics.\n\n"); + fprintf(stdout, " Usage: %s [-c CONFIGFILE] [-d DISPLAY] [-s SLEEP] [-uie] file [more files]\n\n", prgname); + fprintf(stdout, " -c --config specifies the location of the config file\n"); + fprintf(stdout, " (default: /etc/graphlcd.conf)\n"); + fprintf(stdout, " -d --display specifies the output display (default is the first one)\n"); + fprintf(stdout, " -u --upsidedown rotates the output by 180 degrees (default: no)\n"); + fprintf(stdout, " -i --invert inverts the output (default: no)\n"); + fprintf(stdout, " -e --endless show all images in endless loop (default: no)\n"); + fprintf(stdout, " -s --sleep set sleeptime between two images [ms] (default: %d ms)\n", kDefaultSleepMs); + fprintf(stdout, " -b --brightness set brightness for display (if supported by the driver) [%%]\n"); + fprintf(stdout, " (default: config file value)\n"); + fprintf(stdout, " -S --scale scale algorithm to be used\n"); + fprintf(stdout, " 0: don't scale (default)\n"); + fprintf(stdout, " 1: fit to display if larger but not if smaller (keeping aspect ratio) \n"); + fprintf(stdout, " 2: fit to display if larger or smaller (keeping aspect ratio)\n"); + fprintf(stdout, " 3: fill display (ignoring aspect ratio)\n"); + fprintf(stdout, " -C --center center image (default: no)\n"); + fprintf(stdout, "\n" ); + fprintf(stdout, " examples: %s -c /etc/graphlcd.conf vdr-logo.glcd\n", prgname); + fprintf(stdout, " %s -c /etc/graphlcd.conf -d somedisplay -u -i vdr-animation.glcd\n", prgname); + fprintf(stdout, "\n" ); } -int main(int argc, char *argv[]) -{ - static struct option long_options[] = - { - {"config", required_argument, NULL, 'c'}, - {"display", required_argument, NULL, 'd'}, - {"sleep", required_argument, NULL, 's'}, - {"endless", no_argument, NULL, 'e'}, - {"upsidedown", no_argument, NULL, 'u'}, - {"invert", no_argument, NULL, 'i'}, - {"brightness", required_argument, NULL, 'b'}, - {NULL} - }; - - std::string configName = ""; - std::string displayName = ""; - bool upsideDown = false; - bool invert = false; - int brightness = -1; - bool delay = false; - int sleepMs = 100; - bool endless = false; - unsigned int displayNumber = 0; - - int c, option_index = 0; - while ((c = getopt_long(argc, argv, "c:d:s:euib:", long_options, &option_index)) != -1) - { - switch(c) - { - case 'c': - configName = optarg; - break; - - case 'd': - displayName = optarg; - break; - - case 'u': - upsideDown = true; - break; - - case 'i': - invert = true; - break; - - case 's': - sleepMs = atoi(optarg); - delay = true; - break; - - case 'e': - endless = true; - break; - - case 'b': - brightness = atoi(optarg); - if (brightness < 0) brightness = 0; - if (brightness > 100) brightness = 100; - break; - - default: - usage(); - return 1; - } - } - - if (configName.length() == 0) - { - configName = kDefaultConfigFile; - syslog(LOG_INFO, "Error: No config file specified, using default (%s).\n", configName.c_str()); - } - - if (GLCD::Config.Load(configName) == false) - { - fprintf(stdout, "Error loading config file!\n"); - return 2; - } - if (GLCD::Config.driverConfigs.size() > 0) - { - if (displayName.length() > 0) - { - for (displayNumber = 0; displayNumber < GLCD::Config.driverConfigs.size(); displayNumber++) - { - if (GLCD::Config.driverConfigs[displayNumber].name == displayName) - break; - } - if (displayNumber == GLCD::Config.driverConfigs.size()) - { - fprintf(stdout, "ERROR: Specified display %s not found in config file!\n", displayName.c_str()); - return 3; - } - } - else - { - fprintf(stdout, "WARNING: No display specified, using first one.\n"); - displayNumber = 0; - } - } - else - { - fprintf(stdout, "ERROR: No displays specified in config file!\n"); - return 4; - } - - if (optind == argc) - { - usage(); - fprintf(stderr, "ERROR: You have to specify the image\n"); - return 5; - } - - GLCD::Config.driverConfigs[displayNumber].upsideDown ^= upsideDown; - GLCD::Config.driverConfigs[displayNumber].invert ^= invert; - if (brightness != -1) - GLCD::Config.driverConfigs[displayNumber].brightness = brightness; - GLCD::cDriver * lcd = GLCD::CreateDriver(GLCD::Config.driverConfigs[displayNumber].id, &GLCD::Config.driverConfigs[displayNumber]); - if (!lcd) - { - fprintf(stderr, "ERROR: Failed creating display object %s\n", displayName.c_str()); - return 6; - } - if (lcd->Init() != 0) - { - fprintf(stderr, "ERROR: Failed initializing display %s\n", displayName.c_str()); - delete lcd; - return 7; - } +int main(int argc, char *argv[]) { + static struct option long_options[] = + { + {"config", required_argument, NULL, 'c'}, + {"display", required_argument, NULL, 'd'}, + {"sleep", required_argument, NULL, 's'}, + {"endless", no_argument, NULL, 'e'}, + {"upsidedown", no_argument, NULL, 'u'}, + {"invert", no_argument, NULL, 'i'}, + {"brightness", required_argument, NULL, 'b'}, + {"scale", required_argument, NULL, 'S'}, + {"center", no_argument, NULL, 'C'}, + {NULL} + }; + + std::string configName = ""; + std::string displayName = ""; + bool upsideDown = false; + bool invert = false; + int brightness = -1; + bool delay = false; + int sleepMs = 100; + bool endless = false; + unsigned int displayNumber = 0; + int scaleAlgo = 0; + bool center = false; + + int c, option_index = 0; + while ((c = getopt_long(argc, argv, "c:d:s:S:euib:C", long_options, &option_index)) != -1) { + switch(c) { + case 'c': + configName = optarg; + break; + + case 'd': + displayName = optarg; + break; + + case 'u': + upsideDown = true; + break; + + case 'i': + invert = true; + break; + + case 's': + sleepMs = atoi(optarg); + delay = true; + break; + + case 'S': + scaleAlgo = atoi(optarg); + if (scaleAlgo < 0 || scaleAlgo > 3) scaleAlgo = 0; + break; + + case 'e': + endless = true; + break; + + case 'b': + brightness = atoi(optarg); + if (brightness < 0) brightness = 0; + if (brightness > 100) brightness = 100; + break; + + case 'C': + center = true; + break; + + default: + usage(); + return 1; + } + } + + if (configName.length() == 0) { + configName = kDefaultConfigFile; + fprintf(stderr, "Error: No config file specified, using default (%s).\n", configName.c_str()); + } + + if (GLCD::Config.Load(configName) == false) { + fprintf(stderr, "Error loading config file!\n"); + return 2; + } + if (GLCD::Config.driverConfigs.size() > 0) { + if (displayName.length() > 0) { + for (displayNumber = 0; displayNumber < GLCD::Config.driverConfigs.size(); displayNumber++) { + if (GLCD::Config.driverConfigs[displayNumber].name == displayName) + break; + } + if (displayNumber == GLCD::Config.driverConfigs.size()) { + fprintf(stderr, "ERROR: Specified display %s not found in config file!\n", displayName.c_str()); + return 3; + } + } else { + fprintf(stderr, "WARNING: No display specified, using first one.\n"); + displayNumber = 0; + } + } else { + fprintf(stderr, "ERROR: No displays specified in config file!\n"); + return 4; + } + + if (optind == argc) { + usage(); + fprintf(stderr, "ERROR: You have to specify the image\n"); + return 5; + } + + GLCD::Config.driverConfigs[displayNumber].upsideDown ^= upsideDown; + GLCD::Config.driverConfigs[displayNumber].invert ^= invert; + if (brightness != -1) + GLCD::Config.driverConfigs[displayNumber].brightness = brightness; + GLCD::cDriver * lcd = GLCD::CreateDriver(GLCD::Config.driverConfigs[displayNumber].id, &GLCD::Config.driverConfigs[displayNumber]); + if (!lcd) { + fprintf(stderr, "ERROR: Failed creating display object %s\n", displayName.c_str()); + return 6; + } + if (lcd->Init() != 0) { + fprintf(stderr, "ERROR: Failed initializing display %s\n", displayName.c_str()); + delete lcd; + return 7; + } lcd->SetBrightness(GLCD::Config.driverConfigs[displayNumber].brightness); - signal(SIGINT, sighandler); - signal(SIGQUIT, sighandler); - signal(SIGTERM, sighandler); - signal(SIGHUP, sighandler); - - const GLCD::cBitmap * bitmap; - GLCD::cImage image; - GLCD::cGLCDFile glcd; - int optFile; - std::string picFile; - - optFile = optind; - while (optFile < argc && !stopProgramm) - { - picFile = argv[optFile++]; - if (glcd.Load(image, picFile) == false) - { - fprintf(stderr, "ERROR: Failed loading file %s\n", picFile.c_str()); - delete lcd; - return 8; - } - - if (delay) - image.SetDelay(sleepMs); - - while ((bitmap = image.GetBitmap()) != NULL && !stopProgramm) - { - lcd->SetScreen(bitmap->Data(), bitmap->Width(), bitmap->Height(), bitmap->LineSize()); - lcd->Refresh(true); - - if (image.Next(0)) // Select next image - { - usleep(image.Delay() * 1000); - } - else if (endless && argc == (optind + 1)) // Endless and one and only image - { - image.First(0); - usleep(image.Delay() * 1000); - } - else - break; - } - - if (optFile < argc || endless) - usleep(sleepMs * 1000); - if (optFile >= argc && endless) - optFile = optind; - } - - lcd->DeInit(); - delete lcd; - - return 0; + signal(SIGINT, sighandler); + signal(SIGQUIT, sighandler); + signal(SIGTERM, sighandler); + signal(SIGHUP, sighandler); + + const GLCD::cBitmap * bitmap; + GLCD::cImage image; + + GLCD::cBitmap * buffer = new GLCD::cBitmap(lcd->Width(), lcd->Height()); + + int optFile; + std::string picFile; + + optFile = optind; + while (optFile < argc && !stopProgramm) { + picFile = argv[optFile++]; + if (GLCD::cImage::LoadImage(image, picFile) == false) { + fprintf(stderr, "ERROR: Failed loading file %s\n", picFile.c_str()); + return 8; + } + + if (scaleAlgo > 0) { + uint16_t scalew = 0; + uint16_t scaleh = 0; + uint16_t imagew = image.Width(); + uint16_t imageh = image.Height(); + + switch (scaleAlgo) { + case 1: + case 2: + if (imagew > lcd->Width() || imageh > lcd->Height()) { + if ((double)imagew / (double)lcd->Width() > (double)imageh / (double)lcd->Height()) + scalew = lcd->Width(); + else + scaleh = lcd->Height(); + } else if (scaleAlgo == 2 && imagew < lcd->Width() && imageh < lcd->Height()) { + if ((double)imagew / (double)lcd->Width() > (double)imageh / (double)lcd->Height()) + scalew = lcd->Width(); + else + scaleh = lcd->Height(); + } + break; + default: /* 3 */ + scalew = lcd->Width(); + scaleh = lcd->Height(); + } + image.Scale(scalew, scaleh, false); + } + + if (delay) + image.SetDelay(sleepMs); + + + uint16_t xstart = 0; + uint16_t ystart = 0; + + if (center) { + if ((unsigned int)(lcd->Width()) > image.Width()) + xstart = (lcd->Width() - image.Width()) >> 1; + if ((unsigned int)(lcd->Height()) > image.Height()) + ystart = (lcd->Height() - image.Height()) >> 1; + } + + lcd->Refresh(true); + while ((bitmap = image.GetBitmap()) != NULL && !stopProgramm) { + buffer->Clear(); + buffer->DrawBitmap(xstart, ystart, *bitmap); + lcd->SetScreen(buffer->Data(), buffer->Width(), buffer->Height()); + lcd->Refresh(false); + + if (image.Next(0)) { // Select next image + usleep(image.Delay() * 1000); + } else if (endless && argc == (optind + 1)) { // Endless and one and only image + image.First(0); + usleep(image.Delay() * 1000); + } else { + break; + } + } + + if (optFile < argc || endless) + usleep(sleepMs * 1000); + if (optFile >= argc && endless) + optFile = optind; + } + + delete buffer; + lcd->DeInit(); + delete lcd; + + return 0; } diff --git a/tools/showtext/Makefile b/tools/showtext/Makefile index d43c986..516f966 100644 --- a/tools/showtext/Makefile +++ b/tools/showtext/Makefile @@ -18,14 +18,11 @@ all: $(PRGNAME) # Implicit rules: %.o: %.c - $(CXX) $(CXXFLAGS) -c $(DEFINES) $(INCLUDES) $< + $(CXX) $(CXXEXTRA) $(CXXFLAGS) -c $(DEFINES) $(INCLUDES) $< # Dependencies: -MAKEDEP = $(CXX) -MM -MG -DEPFILE = .dependencies -$(DEPFILE): Makefile - @$(MAKEDEP) $(DEFINES) $(INCLUDES) $(OBJS:%.o=%.c) > $@ +DEPFILE = $(OBJS:%.o=%.d) -include $(DEPFILE) @@ -36,7 +33,7 @@ $(PRGNAME): $(OBJS) install: $(PRGNAME) install -d $(BINDIR) - install -m 755 -o root -g root $(STRIP) $(PRGNAME) $(BINDIR) + install -m 755 -o root -g root $(HAVE_STRIP) $(PRGNAME) $(BINDIR) uninstall: rm -f $(BINDIR)/$(PRGNAME) diff --git a/tools/showtext/showtext.c b/tools/showtext/showtext.c index 333d9e3..00e6893 100644 --- a/tools/showtext/showtext.c +++ b/tools/showtext/showtext.c @@ -6,7 +6,9 @@ * This file is released under the GNU General Public License. Refer * to the COPYING file distributed with this package. * - * (c) 2004 Andreas Regel <andreas.regel AT powarman.de> + * (c) 2004-2010 Andreas Regel <andreas.regel AT powarman.de> + * (c) 2010-2011 Wolfgang Astleitner <mrwastl AT users sourceforge net> + * Andreas 'randy' Weinberger */ #include <stdio.h> @@ -35,7 +37,7 @@ void usage() { fprintf(stdout, "\n"); fprintf(stdout, "%s v%s\n", prgname, version); - fprintf(stdout, "%s is a tool to show a text on a LCD.\n", prgname); + fprintf(stdout, "%s is a tool to show a text on an LCD.\n", prgname); fprintf(stdout, "\n"); fprintf(stdout, " Usage: %s [-c CONFIGFILE] [-d DISPLAY] [-f FONT] [-x XPOS] [-y YPOS] [-uib] text [more text]\n\n", prgname); fprintf(stdout, " -c --config specifies the location of the config file\n"); @@ -269,7 +271,8 @@ int main(int argc, char *argv[]) bitmap->DrawText(x, y, bitmap->Width() - 1, text, &font); y += font.LineHeight(); } - lcd->SetScreen(bitmap->Data(), bitmap->Width(), bitmap->Height(), bitmap->LineSize()); +// lcd->SetScreen(bitmap->Data(), bitmap->Width(), bitmap->Height(), bitmap->LineSize()); + lcd->SetScreen(bitmap->Data(), bitmap->Width(), bitmap->Height()); lcd->Refresh(true); lcd->DeInit(); diff --git a/tools/skintest/DejaVuSans.ttf b/tools/skintest/DejaVuSans.ttf Binary files differnew file mode 100644 index 0000000..2375915 --- /dev/null +++ b/tools/skintest/DejaVuSans.ttf diff --git a/tools/skintest/Makefile b/tools/skintest/Makefile new file mode 100644 index 0000000..fe73388 --- /dev/null +++ b/tools/skintest/Makefile @@ -0,0 +1,42 @@ +# +# Makefile for the GraphLCD tool showtext +# + +-include ../../Make.config + +PRGNAME = skintest + +OBJS = skintest.o + +INCLUDES += -I../../ +LIBDIRS += -L../../glcdgraphics/ -L../../glcddrivers/ -L../../glcdskin/ + + +all: $(PRGNAME) +.PHONY: all + +# Implicit rules: + +%.o: %.c + $(CXX) $(CXXEXTRA) $(CXXFLAGS) -c $(DEFINES) $(INCLUDES) $< + +# Dependencies: + +DEPFILE = $(OBJS:%.o=%.d) + +-include $(DEPFILE) + +# The main program: + +$(PRGNAME): $(OBJS) + $(CXX) $(CXXFLAGS) $(LDFLAGS) -rdynamic $(OBJS) $(LIBS) $(LIBDIRS) -lglcdgraphics -lglcddrivers -lglcdskin -lstdc++ -o $(PRGNAME) + +install: $(PRGNAME) + install -d $(BINDIR) + install -m 755 -o root -g root $(HAVE_STRIP) $(PRGNAME) $(BINDIR) + +uninstall: + rm -f $(BINDIR)/$(PRGNAME) + +clean: + @-rm -f $(OBJS) $(DEPFILE) $(PRGNAME) *~ diff --git a/tools/skintest/skintest.c b/tools/skintest/skintest.c new file mode 100644 index 0000000..747dd91 --- /dev/null +++ b/tools/skintest/skintest.c @@ -0,0 +1,190 @@ +#include <stdio.h> +#include <string.h> +#include <stdlib.h> +#include <getopt.h> +#include <unistd.h> + +#include <string> + +#include <glcdgraphics/bitmap.h> +#include <glcdgraphics/font.h> +#include <glcddrivers/config.h> +#include <glcddrivers/driver.h> +#include <glcddrivers/drivers.h> +#include <glcdskin/parser.h> +#include <glcdskin/skin.h> +#include <glcdskin/config.h> +#include <glcdskin/string.h> + +class cMySkinConfig : public GLCD::cSkinConfig +{ +private: + GLCD::cDriver * mDriver; +public: + cMySkinConfig(GLCD::cDriver * Driver); + virtual std::string SkinPath(void); + virtual std::string CharSet(void); + virtual std::string Translate(const std::string & Text); + virtual GLCD::cType GetToken(const GLCD::tSkinToken & Token); + virtual GLCD::cDriver * GetDriver(void) const { return mDriver; } +}; + +cMySkinConfig::cMySkinConfig(GLCD::cDriver * Driver) +: mDriver(Driver) +{ +} + +std::string cMySkinConfig::SkinPath(void) +{ + return "."; +} + +std::string cMySkinConfig::CharSet(void) +{ + return "iso8859-15"; +} + +std::string cMySkinConfig::Translate(const std::string & Text) +{ + return Text; +} + +GLCD::cType cMySkinConfig::GetToken(const GLCD::tSkinToken & Token) +{ + return 10; +} + + +static const char * kDefaultConfigFile = "/etc/graphlcd.conf"; + +int main(int argc, char ** argv) +{ + static struct option long_options[] = + { + {"config", required_argument, NULL, 'c'}, + {"display", required_argument, NULL, 'd'}, + {"skin", required_argument, NULL, 's'}, + {"upsidedown", no_argument, NULL, 'u'}, + {"invert", no_argument, NULL, 'i'}, + {"brightness", required_argument, NULL, 'b'}, + {NULL} + }; + + std::string configName = ""; + std::string displayName = ""; + std::string skinFileName = ""; + bool upsideDown = false; + bool invert = false; + int brightness = -1; + unsigned int displayNumber = 0; + + int c, option_index = 0; + while ((c = getopt_long(argc, argv, "c:d:s:uib:", long_options, &option_index)) != -1) + { + switch (c) + { + case 'c': + configName = optarg; + break; + + case 'd': + displayName = optarg; + break; + + case 's': + skinFileName = optarg; + break; + + case 'u': + upsideDown = true; + break; + + case 'i': + invert = true; + break; + + case 'b': + brightness = atoi(optarg); + if (brightness < 0) brightness = 0; + if (brightness > 100) brightness = 100; + break; + + default: + //usage(); + return 1; + } + } + + if (configName.length() == 0) + { + configName = kDefaultConfigFile; + fprintf(stdout, "WARNING: No config file specified, using default (%s).\n", configName.c_str()); + } + + if (GLCD::Config.Load(configName) == false) + { + fprintf(stderr, "Error loading config file!\n"); + return 1; + } + if (GLCD::Config.driverConfigs.size() > 0) + { + if (displayName.length() > 0) + { + for (displayNumber = 0; displayNumber < GLCD::Config.driverConfigs.size(); displayNumber++) + { + if (GLCD::Config.driverConfigs[displayNumber].name == displayName) + break; + } + if (displayNumber == GLCD::Config.driverConfigs.size()) + { + fprintf(stderr, "ERROR: Specified display %s not found in config file!\n", displayName.c_str()); + return 1; + } + } + else + { + fprintf(stdout, "WARNING: No display specified, using first one.\n"); + displayNumber = 0; + } + } + else + { + fprintf(stderr, "ERROR: No displays specified in config file!\n"); + return 1; + } + + GLCD::Config.driverConfigs[displayNumber].upsideDown ^= upsideDown; + GLCD::Config.driverConfigs[displayNumber].invert ^= invert; + if (brightness != -1) + GLCD::Config.driverConfigs[displayNumber].brightness = brightness; + + GLCD::cDriver * lcd = GLCD::CreateDriver(GLCD::Config.driverConfigs[displayNumber].id, &GLCD::Config.driverConfigs[displayNumber]); + if (!lcd) + { + fprintf(stderr, "ERROR: Failed creating display object %s\n", displayName.c_str()); + return 9; + } + if (lcd->Init() != 0) + { + fprintf(stderr, "ERROR: Failed initializing display %s\n", displayName.c_str()); + delete lcd; + return 10; + } + + GLCD::cBitmap * screen = new GLCD::cBitmap(lcd->Width(), lcd->Height()); + screen->Clear(); + + cMySkinConfig skinConfig(lcd); + GLCD::cSkin * skin = GLCD::XmlParse(skinConfig, "test", skinFileName); + skin->SetBaseSize(screen->Width(), screen->Height()); + GLCD::cSkinDisplay * display = skin->GetDisplay("normal"); + + display->Render(screen); + lcd->SetScreen(screen->Data(), screen->Width(), screen->Height()); + lcd->Refresh(true); + + lcd->DeInit(); + delete lcd; + + return 0; +} diff --git a/tools/skintest/test.skin b/tools/skintest/test.skin new file mode 100644 index 0000000..1632b03 --- /dev/null +++ b/tools/skintest/test.skin @@ -0,0 +1,50 @@ +<?xml version="1.0"?> +<skin version="1.0" name="Demo"> + <font id="small" url="ft2:DejaVuSans.ttf:10"/> + <font id="medium" url="ft2:DejaVuSans.ttf:20"/> + <font id="large" url="ft2:DejaVuSans.ttf:20"/> + + <display id="normal"> + <rectangle x1="0" x2="-1" y1="0" y2="-1" color="black" filled="yes"/> +<!-- + <rectangle x1="0" x2="100" y1="5" y2="25" color="white" filled="yes"/> + <rectangle x1="10" x2="20" y1="10" y2="20" color="black"/> + <rectangle x1="30" x2="40" y1="10" y2="20" color="black" filled="yes"/> + <rectangle x1="50" x2="60" y1="10" y2="20" color="black" radius="1"/> + <rectangle x1="70" x2="80" y1="10" y2="20" color="black" filled="yes" radius="1"/> + <rectangle x1="10" x2="20" y1="30" y2="40" color="white"/> + <rectangle x1="30" x2="40" y1="30" y2="40" color="white" filled="yes"/> + <rectangle x1="50" x2="60" y1="30" y2="40" color="white" radius="3"/> + <rectangle x1="70" x2="80" y1="30" y2="40" color="white" filled="yes" radius="1"/> + <line x1="10" x2="40" y1="50" y2="70" color="white" filled="yes" arc="0"/> + <line x1="50" x2="80" y1="50" y2="50" color="white" filled="yes" arc="1"/> + <line x1="90" x2="90" y1="50" y2="70" color="white" filled="yes" arc="2"/> + <slope x1="130" x2="160" y1="50" y2="70" color="white" filled="yes" arc="3"/> + <slope x1="170" x2="200" y1="50" y2="70" color="white" filled="yes" arc="4"/> + <slope x1="50" x2="80" y1="80" y2="100" color="white" filled="yes" arc="5"/> + <slope x1="90" x2="120" y1="80" y2="100" color="white" filled="yes" arc="6"/> + <slope x1="130" x2="160" y1="80" y2="100" color="white" filled="yes" arc="7"/> + + <image x="100" y="60" color="white" path="ARTE_l.glcd"/> + <image x="100" y="50" color="white" path="ARTE_m.glcd"/> + <image x="50" y="50" color="white" condition="or(file('ARTE_m.glcd'),file('ARTE_l.glcd'))" path="ARTE_l.glcd"/> +--> + + <text x1="0" x2="-1" y1="0" y2="-1" color="white" align="left" font="medium"> + This is a left aligned text. + </text> + <text x1="0" x2="-1" y1="20" y2="-1" color="blue" align="right" font="medium"> + This is a right aligned text. + </text> + <text x1="0" x2="-1" y1="40" y2="-1" color="red" align="center" font="medium"> + This is a centered text. + </text> + <text x1="0" x2="-1" y1="60" y2="-1" color="green" align="left" multiline="yes" font="medium"> + This is a longer text that should be wrapped. It really works! + </text> +<!-- +--> + <rectangle x1="10" x2="-10" y1="-30" y2="-10" color="white"/> + <progress x1="12" x2="-12" y1="-28" y2="-12" color="white" direction="0" current="{CurrentProgress}" total="20"/> + </display> +</skin> |