I think this line:-
index1=(int)(x);
should be:-
index1=(int)(x)*3;
Also, don't assume that the stride is the same as width.sizeof(pixel)
, the first pixel on a line may be aligned to a word/dword/etc boundary, so I'd change the code to:-
void blin(uint8_t* pixelsIn, uint8_t* pixelsOut, int w, int h, float scale, int input_stride, int output_stride)
{
int index1, index2;
int w2, h2;
int i, j, k;
float x, y;
float t;
w2=(int)(scale*w + 0.5);
h2=(int)(scale*h + 0.5);
index2=0;
for(i=0;i<h2;i++) //line
{
int pixelindex2=index2;
for(j=0;j<w2;j++) //column
{
x=((float)(j))/scale;
index1=(int)(x)*3;
x-=(int)(x);
y=((float)(i))/scale;
index1+=(int)(y) * input_stride;
y-=(int)(y);
for(k=0;k<3;k++) //for color in R, G, B
{
t = (float)(pixelsIn[index1]) * (1.0-x)*(1.0-y);
t += (float)(pixelsIn[index1+3]) * (x)*(1.0-y);
t += (float)(pixelsIn[index1+w*3]) * (1.0-x)*(y);
t += (float)(pixelsIn[index1+w*3+3]) * (x)*(y);
pixelsOut[pixelindex2] = (uint8_t)(t);
index1++;
pixelindex2++;
}
} //column
index2+=output_stride;
} //line
}
where input_stride
and output_stride
are the number of bytes between the start of consecutive lines which may not be the same as width * 3
.
You may also want to consider making the '3' constant a variable so that you can deal with different image formats.