summaryrefslogtreecommitdiff
path: root/gfxtools.cpp
diff options
context:
space:
mode:
authorJochen Dolze <vdr@dolze.de>2010-08-01 08:42:12 +0200
committerJochen Dolze <vdr@dolze.de>2010-07-31 22:32:15 +0200
commit415f957ea35045b32b96831def310465b35035e1 (patch)
tree571819cd67f6d0da19e8d290d65db240473da1fb /gfxtools.cpp
parent5785295a438e1ddd874f27b0f89b391d7c976fd7 (diff)
downloadvdr-plugin-tvonscreen-415f957ea35045b32b96831def310465b35035e1.tar.gz
vdr-plugin-tvonscreen-415f957ea35045b32b96831def310465b35035e1.tar.bz2
Added gettext support
Diffstat (limited to 'gfxtools.cpp')
-rw-r--r--gfxtools.cpp174
1 files changed, 174 insertions, 0 deletions
diff --git a/gfxtools.cpp b/gfxtools.cpp
new file mode 100644
index 0000000..a7f4dca
--- /dev/null
+++ b/gfxtools.cpp
@@ -0,0 +1,174 @@
+/*
+ * gfxtools.c
+ *
+ * See the README file for copyright information and how to reach the author.
+ *
+ * $Id: gfxtools.c,v 1.8 2006/06/18 13:59:36 schmitzj Exp $
+ *
+ */
+
+#include <vdr/plugin.h>
+#include "gfxtools.h"
+#include <string.h>
+
+bool DrawXpm(const char *FileName,areaT *drawable,int x,int y,winhandleT winhand,bool blackwhite)
+{ // Bases on vdr cBitmap::LoadXpm but made more readable
+ // and added x/y support
+ bool Result = false;
+ cReadLine ReadLine;
+ FILE *f = fopen(FileName, "r");
+ if (f)
+ {
+ char **Xpm = NULL;
+ bool isXpm = false;
+ int lines = 0;
+ int index = 0;
+ char *s;
+
+ while ((s = ReadLine.Read(f)) != NULL)
+ {
+ s = skipspace(s);
+ if (!isXpm)
+ {
+ if (strcmp(s, "/* XPM */") != 0)
+ {
+ esyslog("ERROR: invalid header in XPM file '%s'", FileName);
+ break;
+ }
+ isXpm = true;
+ }
+ else if (*s++ == '"')
+ {
+ if (!lines)
+ {
+ int w, h, n, c;
+ if (4 != sscanf(s, "%d %d %d %d", &w, &h, &n, &c))
+ {
+ esyslog("ERROR: faulty 'values' line in XPM file '%s'", FileName);
+ break;
+ }
+ lines = h + n + 1;
+ Xpm = MALLOC(char *, lines);
+ }
+ char *q = strchr(s, '"');
+ if (!q)
+ {
+ esyslog("ERROR: missing quotes in XPM file '%s'", FileName);
+ break;
+ }
+ *q = 0;
+ if (index < lines)
+ Xpm[index++] = strdup(s);
+ else
+ {
+ esyslog("ERROR: too many lines in XPM file '%s'", FileName);
+ break;
+ }
+ }
+ }
+ if (index == lines)
+ Result = DrawXpm(Xpm,drawable,x,y,winhand,blackwhite);
+ else
+ esyslog("ERROR: too few lines in XPM file '%s'", FileName);
+ for (int i = 0; i < index; i++)
+ free(Xpm[i]);
+ free(Xpm);
+ fclose(f);
+ }
+ else
+ esyslog("ERROR: can't open XPM file '%s'", FileName);
+ return Result;
+}
+
+bool DrawXpm(char *Xpm[], areaT *drawable,int x0,int y0,winhandleT winhand,bool blackwhite)
+{ // Bases on vdr cBitmap::LoadXpm but made more readable
+ // and added x/y support and "none" is now no longer drawn
+ char **p = Xpm;
+ int w, h, n, c;
+ if (4 != sscanf(*p, "%d %d %d %d", &w, &h, &n, &c))
+ {
+ esyslog("ERROR: faulty 'values' line in XPM: '%s'", *p);
+ return false;
+ }
+ if (n > MAXNUMCOLORS)
+ {
+ esyslog("ERROR: too many colors in XPM: %d", n);
+ return false;
+ }
+
+ int NoneColorIndex = MAXNUMCOLORS;
+#if VDRVERSNUM >= 10307
+ tColor cols[n];
+#else
+ eDvbColor cols[n];
+#endif
+ for (int i = 0; i < n; i++)
+ {
+ const char *s = *++p;
+ if (int(strlen(s)) < c)
+ {
+ esyslog("ERROR: faulty 'colors' line in XPM: '%s'", s);
+ return false;
+ }
+ s = skipspace(s + c);
+ if (*s != 'c')
+ {
+ esyslog("ERROR: unknown color key in XPM: '%c'", *s);
+ return false;
+ }
+ s = skipspace(s + 1);
+ if (strcasecmp(s, "none") == 0)
+ {
+ s = "#00000000";
+ NoneColorIndex = i;
+ }
+ if (*s != '#')
+ {
+ esyslog("ERROR: unknown color code in XPM: '%c'", *s);
+ return false;
+ }
+ unsigned int col=strtoul(++s, NULL, 16);
+ if (blackwhite)
+ {
+ int bwcol=(int)(0.299*(double)((col & 0xff0000) >> 16) + 0.587*(double)((col & 0xff00) >> 8) + 0.114*(double)(col & 0xff));
+ if (bwcol>0xff) bwcol=0xff;
+ bwcol&=(0xff-31);
+ col=(bwcol<<16) | (bwcol<<8)| (bwcol);
+ }
+#if VDRVERSNUM >= 10307
+ cols[i] = col | 0xFF000000;
+#else
+ cols[i] = (eDvbColor)(((col & 0xff) << 16) | (col & 0xff00) | ((col & 0xff0000) >> 16) | 0xFF000000);
+#endif
+ }
+ for (int y = 0; y < h; y++)
+ {
+ const char *s = *++p;
+ if (int(strlen(s)) != w * c)
+ {
+ esyslog("ERROR: faulty pixel line in XPM: %d '%s'", y, s);
+ return false;
+ }
+ for (int x = 0; x < w; x++)
+ {
+ for (int i = 0; i < n; i++)
+ {
+ if (strncmp(Xpm[i + 1], s, c) == 0)
+ {
+ if (i != NoneColorIndex)
+ {
+#if VDRVERSNUM >= 10307
+ drawable->DrawPixel(x0+x,y0+y, cols[i]);
+#else
+// drawable->AddColor(cols[i],winhand);
+ drawable->Fill(x0+x,y0+y,x0+x,y0+y,cols[i],winhand);
+#endif
+ }
+ break;
+ }
+ }
+ s += c;
+ }
+ }
+ return true;
+}