diff options
author | Christian Gmeiner <christian.gmeiner@gmail.com> | 2009-10-13 11:27:17 +0200 |
---|---|---|
committer | Christian Gmeiner <christian.gmeiner@gmail.com> | 2009-10-13 11:27:17 +0200 |
commit | 524c3aeb6f60e3bab7f09936a75da5fa758fc830 (patch) | |
tree | 77a831e6e0ea0589cc9f050efbe22a269e5c68f5 /scaler.c | |
parent | aacb17750c711065a3bcf5307f40b7c25e1e49f6 (diff) | |
download | vdr-plugin-dxr3-524c3aeb6f60e3bab7f09936a75da5fa758fc830.tar.gz vdr-plugin-dxr3-524c3aeb6f60e3bab7f09936a75da5fa758fc830.tar.bz2 |
implement scaler basd on 'Image Scaling With Bresenham'
Diffstat (limited to 'scaler.c')
-rw-r--r-- | scaler.c | 59 |
1 files changed, 56 insertions, 3 deletions
@@ -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; } |