summaryrefslogtreecommitdiff
path: root/bitmap.c
diff options
context:
space:
mode:
Diffstat (limited to 'bitmap.c')
-rw-r--r--bitmap.c100
1 files changed, 95 insertions, 5 deletions
diff --git a/bitmap.c b/bitmap.c
index 44ebdbd..deff15e 100644
--- a/bitmap.c
+++ b/bitmap.c
@@ -14,23 +14,35 @@
#include <vdr/tools.h>
#include "bitmap.h"
+/**
+ * Ctor - Create framebuffer
+ *
+ * \param w count of horizontal columns.
+ * \param h count of vertical rows.
+ */
cVFDBitmap::cVFDBitmap(int w, int h) {
width = w;
height = h;
// lines are byte aligned
bytesPerLine = (width + 7) / 8;
-
- bitmap = MALLOC(uchar, bytesPerLine * height);
+ if(0<height && 0<bytesPerLine)
+ bitmap = MALLOC(uchar, bytesPerLine * height);
clear();
}
+/**
+ * Ctor - Create empty framebuffer
+ */
cVFDBitmap::cVFDBitmap() {
height = 0;
width = 0;
bitmap = NULL;
}
+/**
+ * Dtor - Destroy framebuffer
+ */
cVFDBitmap::~cVFDBitmap() {
if(bitmap)
@@ -38,6 +50,9 @@ cVFDBitmap::~cVFDBitmap() {
bitmap = NULL;
}
+/**
+ * Compare current framebuffer.
+ */
cVFDBitmap& cVFDBitmap::operator = (const cVFDBitmap& x) {
if(height != x.height
@@ -53,14 +68,17 @@ cVFDBitmap& cVFDBitmap::operator = (const cVFDBitmap& x) {
bytesPerLine = (width + 7) / 8;
- if(height && width)
+ if(0<height && 0<bytesPerLine)
bitmap = MALLOC(uchar, bytesPerLine * height);
}
- if(x.bitmap)
+ if(bitmap && x.bitmap)
memcpy(bitmap, x.bitmap, bytesPerLine * height);
return *this;
}
+/**
+ * Copy current framebuffer.
+ */
bool cVFDBitmap::operator == (const cVFDBitmap& x) const {
if(height != x.height
@@ -71,12 +89,20 @@ bool cVFDBitmap::operator == (const cVFDBitmap& x) const {
return ((memcmp(x.bitmap, bitmap, bytesPerLine * height)) == 0);
}
-
+/**
+ * Cleanup current framebuffer.
+ */
void cVFDBitmap::clear() {
if (bitmap)
memset(bitmap, 0x00, bytesPerLine * height);
}
+/**
+ * Draw a single pixel framebuffer.
+ *
+ * \param x horizontal column.
+ * \param y vertical row.
+ */
bool cVFDBitmap::SetPixel(int x, int y)
{
unsigned char c;
@@ -100,3 +126,67 @@ bool cVFDBitmap::SetPixel(int x, int y)
return true;
}
+
+/**
+ * Draw a horizontal line on framebuffer.
+ *
+ * \param x1 First horizontal column.
+ * \param y vertical row.
+ * \param x2 Second horizontal column.
+ */
+bool cVFDBitmap::HLine(int x1, int y, int x2) {
+
+ sort(x1,x2);
+
+ for (int x = x1; x <= x2; x++) {
+ if(!SetPixel(x, y))
+ return false;
+ }
+ return true;
+}
+
+/**
+ * Draw a vertical line on framebuffer.
+ *
+ * \param x horizontal column.
+ * \param y1 First vertical row.
+ * \param y2 Second vertical row.
+ */
+bool cVFDBitmap::VLine(int x, int y1, int y2) {
+
+ sort(y1,y2);
+
+ for (int y = y1; y <= y2; y++) {
+ if(!SetPixel(x, y))
+ return false;
+ }
+ return true;
+}
+
+/**
+ * Draw a rectangle on framebuffer.
+ *
+ * \param x1 First horizontal corner (column).
+ * \param y1 First vertical corner (row).
+ * \param x2 Second horizontal corner (column).
+ * \param y2 Second vertical corner (row).
+ * \param filled drawing of rectangle should be filled.
+ */
+bool cVFDBitmap::Rectangle(int x1, int y1, int x2, int y2, bool filled) {
+
+ if (!filled) {
+ return HLine(x1, y1, x2)
+ && VLine(x1, y1, y2)
+ && HLine(x1, y2, x2)
+ && VLine(x2, y1, y2);
+ } else {
+ sort(y1,y2);
+
+ for (int y = y1; y <= y2; y++) {
+ if(!HLine(x1, y, x2))
+ return false;
+ }
+ return true;
+ }
+}
+