summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--scaler.c59
-rw-r--r--scaler.h2
2 files changed, 57 insertions, 4 deletions
diff --git a/scaler.c b/scaler.c
index 04e8d22..5fca036 100644
--- a/scaler.c
+++ b/scaler.c
@@ -27,8 +27,61 @@
#include "scaler.h"
#include <vdr/osd.h>
-cBitmap *cScaler::scaleBitmap(cBitmap *src, uint32_t width, uint32_t height)
+// scaling based on article "Image Scaling With Bresenham" by Thiadmer Riemersma
+// http://www.ddj.com/184405045
+
+static void scaleLine(const tIndex *src, tIndex *dest, int srcWidth, int destWidth)
{
- // TODO
- return NULL;
+ int numPixels = destWidth;
+ int intPart = srcWidth / destWidth;
+ int fractPart = srcWidth % destWidth;
+ int e = 0;
+
+ while (numPixels-- > 0) {
+ *dest++ = *src;
+ src += intPart;
+
+ e += fractPart;
+ if (e >= destWidth) {
+ e -= destWidth;
+ src++;
+ }
+ }
+}
+
+static void scaleRect(const tIndex *src, tIndex *dest, int srcWidth, int srcHeight, int destWidth, int destHeight)
+{
+ int numPixels = destHeight;
+ int intPart = (srcHeight / destHeight) * srcWidth;
+ int fractPart = srcHeight % destHeight;
+ int e = 0;
+
+ while (numPixels-- > 0) {
+
+ scaleLine(src, dest, srcWidth, destWidth);
+
+ dest += destWidth;
+ src += intPart;
+
+ e += fractPart;
+ if (e >= destHeight) {
+ e -= destHeight;
+ src += srcWidth;
+ }
+ }
+}
+
+cBitmap *cScaler::scaleBitmap(cBitmap *source, int width, int height)
+{
+ cBitmap *scaled = new cBitmap(width, height, 4, 0, 0);
+
+ int osdWidth = source->Width();
+ int osdHeight = source->Height();
+
+ const tIndex *src = source->Data(0, 0);
+ tIndex *dest = (tIndex *)scaled->Data(0, 0);
+
+ scaleRect(src, dest, osdWidth, osdHeight, width, height);
+
+ return scaled;
}
diff --git a/scaler.h b/scaler.h
index 0ef336f..cc6a8bb 100644
--- a/scaler.h
+++ b/scaler.h
@@ -32,7 +32,7 @@
class cScaler {
public:
- static cBitmap *scaleBitmap(cBitmap *src, uint32_t width, uint32_t height);
+ static cBitmap *scaleBitmap(cBitmap *source, int width, int height);
};