-
Notifications
You must be signed in to change notification settings - Fork 3
/
scale_image_linear.c
67 lines (52 loc) · 1.16 KB
/
scale_image_linear.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include "header.h"
void scale_image_linear(
int *image_arr1,
int width1,
int height1,
int *image_arr2,
int width2,
int height2
)
{
int i2;
double y1;
int j2;
double x1;
int pixel2;
double intensity_dbl;
int intensity_int;
for ( i2= 0 ; i2< height2; i2++ ) {
/*
Get corresponding y1 in image1_arr
*/
y1= ( (double)i2/(double)height2 ) * (double)height1;
for ( j2= 0 ; j2< width2; j2++ ) {
/*
Get corresponding x1 in image1_arr
*/
x1= ( (double)j2/(double)width2 ) * (double)width1;
if ( !(x1 >= 0.0) )
x1= 0.0;
if ( !(x1 < (double)width1) )
x1= (double)(width1-1);
if ( !(y1 >= 0.0) )
y1= 0.0;
if ( !(y1 < (double)height1) )
y1= (double)(height1-1);
intensity_dbl= bilinear_interpolation_on_image_int(
image_arr1,
x1,
y1,
width1,
height1
);
intensity_int= (int)round(intensity_dbl);
if ( !(intensity_int >= 0) )
intensity_int= 0;
if ( !(intensity_int <= 255) )
intensity_int= 255;
pixel2= i2*width2+j2;
image_arr2[pixel2]= intensity_int;
}
}
}