summaryrefslogtreecommitdiff
path: root/bitmap.c
diff options
context:
space:
mode:
authorandreas <andreas@deltab.de>2009-05-22 11:38:22 +0200
committerandreas <andreas@deltab.de>2009-05-22 11:38:22 +0200
commit54e2650e953c0725e5d14509f79cdd203d7d4db4 (patch)
treeb1d55fe1977e032ad1b3f73a7502745454601463 /bitmap.c
downloadvdr-plugin-imonlcd-54e2650e953c0725e5d14509f79cdd203d7d4db4.tar.gz
vdr-plugin-imonlcd-54e2650e953c0725e5d14509f79cdd203d7d4db4.tar.bz2
initial import
Diffstat (limited to 'bitmap.c')
-rw-r--r--bitmap.c98
1 files changed, 98 insertions, 0 deletions
diff --git a/bitmap.c b/bitmap.c
new file mode 100644
index 0000000..b16ab9a
--- /dev/null
+++ b/bitmap.c
@@ -0,0 +1,98 @@
+/*
+ * iMON LCD plugin to VDR (C++)
+ *
+ * (C) 2009 Andreas Brachold <vdr07 AT deltab de>
+ *
+ * This code is distributed under the terms and conditions of the
+ * GNU GENERAL PUBLIC LICENSE. See the file COPYING for details.
+ *
+ */
+
+#include <vdr/tools.h>
+#include "bitmap.h"
+
+ciMonBitmap::ciMonBitmap(int w, int h) {
+ width = w;
+ height = h;
+
+ // lines are byte aligned
+ bytesPerLine = (width + 7) / 8;
+
+ bitmap = MALLOC(uchar, bytesPerLine * height);
+ clear();
+}
+
+ciMonBitmap::ciMonBitmap() {
+ height = 0;
+ width = 0;
+ bitmap = NULL;
+}
+
+ciMonBitmap::~ciMonBitmap() {
+
+ if(bitmap)
+ free(bitmap);
+ bitmap = NULL;
+}
+
+ciMonBitmap& ciMonBitmap::operator = (const ciMonBitmap& x) {
+
+ if(height != x.height
+ || width != x.width
+ || bitmap == NULL) {
+
+ if(bitmap)
+ free(bitmap);
+ bitmap = NULL;
+
+ height = x.height;
+ width = x.width;
+
+ bytesPerLine = (width + 7) / 8;
+
+ if(height && width)
+ bitmap = MALLOC(uchar, bytesPerLine * height);
+ }
+ if(x.bitmap)
+ memcpy(bitmap, x.bitmap, bytesPerLine * height);
+ return *this;
+}
+
+bool ciMonBitmap::operator == (const ciMonBitmap& x) const {
+
+ if(height != x.height
+ || width != x.width
+ || bitmap == NULL
+ || x.bitmap == NULL)
+ return false;
+ return ((memcmp(x.bitmap, bitmap, bytesPerLine * height)) == 0);
+}
+
+
+void ciMonBitmap::clear() {
+ if (bitmap)
+ memset(bitmap, 0x00, bytesPerLine * height);
+}
+
+bool ciMonBitmap::SetPixel(int x, int y)
+{
+ unsigned char c;
+ unsigned int n;
+
+ if (!bitmap)
+ return false;
+
+ if (x >= width || x < 0)
+ return false;
+ if (y >= height || y < 0)
+ return false;
+
+ n = x + ((y / 8) * width);
+ c = 0x80 >> (y % 8);
+
+ if(n >= (bytesPerLine * height))
+ return false;
+
+ bitmap[n] |= c;
+ return true;
+}