2
* imagesource_bilinear.cpp - Interpolated scaling filter
3
* Implements bilinear scaling
5
* Supports Greyscale, RGB and CMYK data
6
* Doesn't (yet) support random access
8
* Copyright (c) 2004 by Alastair M. Robinson
9
* Distributed under the terms of the GNU General Public License -
10
* see the file named "COPYING" for more details.
19
#include "imagesource_bilinear.h"
24
ImageSource_Bilinear::~ImageSource_Bilinear()
34
ISDataType *ImageSource_Bilinear::GetRow(int row)
41
int srow1=(row*source->height)/height;
43
if(srow2>=source->height)
46
ISDataType *src1,*src2;
54
src1=source->GetRow(srow1);
55
for(int i=0;i<source->width*source->samplesperpixel;++i)
61
src2=source->GetRow(srow2);
63
double yfactor=row*source->height;
69
int x1=(i*source->width)/width;
71
if(x2 >= source->width)
73
float xfactor=(i*source->width);
80
for(int s=0;s<samplesperpixel;++s)
87
double a1=(1.0-xfactor)*s1+xfactor*s2;
88
double a2=(1.0-xfactor)*s3+xfactor*s4;
89
double a3=(1.0-yfactor)*a1+yfactor*a2;
91
rowbuffer[i*samplesperpixel+s]=int(a3);
101
ImageSource_Bilinear::ImageSource_Bilinear(struct ImageSource *source,int width,int height)
102
: ImageSource(source), source(source), lastrow(NULL), cachedrow(-1)
104
this->width=width; this->height=height;
105
xres=(source->xres*width); xres/=source->width;
106
yres=(source->yres*height); yres/=source->height;
108
lastrow=(ISDataType *)malloc(source->width*source->samplesperpixel*sizeof(ISDataType));