2af4a7db0e8c5b7835ad2a6e7be3579a27a52c4e
4 #include "libvidstab.h"
5 #include "transformtype_operations.h"
7 void paintRectangle(unsigned char* buffer
, const VSFrameInfo
* fi
, int x
, int y
, int sizex
, int sizey
, unsigned char color
){
8 if(x
>=0 && x
+sizex
< fi
->width
&& y
>=0 && y
+sizey
< fi
->height
){
10 for(j
=y
; j
< y
+sizey
; j
++){
11 for(i
=x
; i
<x
+sizex
; i
++){
12 buffer
[j
*fi
->width
+ i
] = color
;
19 /// corr: correlation length of noise
20 void fillArrayWithNoise(unsigned char* buffer
, int length
, float corr
){
21 unsigned char avg
=randPixel();
24 float alpha
= 1.0/corr
;
25 for(i
=0; i
< length
; i
++){
27 avg
= avg
* (1.0-alpha
) + randPixel()*alpha
;
31 VSTransform
getTestFrameTransform(int i
){
32 VSTransform t
= null_transform();
33 t
.x
= ( (i
%2)==0 ? -1 : 1) *i
*5;
34 t
.y
= ( (i
%3)==0 ? 1 : -1) *i
*5;
35 t
.alpha
= (i
<3 ? 0 : 1) * (i
)*1*M_PI
/(180.0);
40 static int readNumber (const char* filename
, FILE *f
)
46 vs_log_error("TEST", "unexpected end of file in '%s'", filename
);
47 if (c
>= '0' && c
<= '9') n
= n
*10 + (c
- '0');
56 static void skipWhiteSpace (const char* filename
, FILE *f
)
62 vs_log_error("TEST", "unexpected end of file in '%s'", filename
);
69 vs_log_error("TEST", "unexpected end of file in '%s'", filename
);
81 int loadPGMImage(const char* filename
, VSFrame
* frame
, VSFrameInfo
* fi
)
83 FILE *f
= fopen (filename
,"rb");
85 vs_log_error("TEST", "Can't open image file '%s'", filename
);
90 if (fgetc(f
) != 'P' || fgetc(f
) != '2')
91 vs_log_error("TEST","image file ist not binary PGM (no P5 header) '%s'", filename
);
92 skipWhiteSpace (filename
,f
);
94 // read in image parameters
95 fi
->width
= readNumber (filename
,f
);
96 skipWhiteSpace (filename
,f
);
97 fi
->height
= readNumber (filename
,f
);
98 skipWhiteSpace (filename
,f
);
99 int max_value
= readNumber (filename
,f
);
102 if (fi
->width
< 1 || fi
->height
< 1)
103 vs_log_error("TEST", "bad image file '%s'", filename
);
104 if (max_value
!= 255)
105 vs_log_error("TEST", "image file '%s' must have color range 255", filename
);
107 // read either nothing, LF (10), or CR,LF (13,10)
115 if (c
!= 10) ungetc (c
,f
);
120 // read in rest of data
121 vsFrameAllocate(frame
,fi
);
122 if (fread( frame
->data
[0], fi
->width
*fi
->height
, 1, f
) != 1){
123 vs_log_error("TEST", "Can't read data from image file '%s'", filename
);
131 int storePGMImage(const char* filename
, const uint8_t* data
, VSFrameInfo fi
) {
132 FILE *f
= fopen (filename
,"wb");
134 vs_log_error("TEST", "Can't open image file '%s'", filename
);
140 fprintf(f
,"# CREATOR test suite of vid.stab\n");
141 fprintf(f
,"%i %i\n", fi
.width
, fi
.height
);
145 if (fwrite( data
, fi
.width
*fi
.height
, 1, f
) != 1){
146 vs_log_error("TEST", "Can't write to image file '%s'", filename
);