gitignore ignorable gtksparrow executable
[sparrow.git] / test-jpeg.c
blobab52e2b8457c8469b99b96525e67ef2f02758ecd
1 #include "gstsparrow.h"
2 #include "sparrow.h"
3 #include <string.h>
4 #include <math.h>
5 #include <sys/time.h>
7 #include <stdio.h>
9 //#include "jpeg_src.c"
11 static const int INSIZE = 100000;
12 static const int OUTSIZE = 800 * 600 * 4;
13 static const char *FN_IN = "test.jpg";
14 static const char *FN_OUT = "test.ppm";
15 static const int cycles = 100;
17 int main(int argc, char **argv)
19 guint8* inbuffer = malloc_aligned_or_die(INSIZE);
20 guint8* outbuffer = malloc_aligned_or_die(OUTSIZE);
22 FILE *in = fopen(FN_IN, "r");
23 int size = fread(inbuffer, INSIZE, 1, in);
25 struct timeval tv1, tv2;
26 guint32 t;
27 int width, height;
29 GstSparrow sparrow;
30 init_jpeg_src(&sparrow);
32 gettimeofday(&tv1, NULL);
34 for (int i = 0; i < cycles; i++){
35 decompress_buffer(sparrow.cinfo, inbuffer, size, outbuffer,
36 &width, &height);
39 gettimeofday(&tv2, NULL);
40 t = ((tv2.tv_sec - tv1.tv_sec) * 1000000 +
41 tv2.tv_usec - tv1.tv_usec);
42 printf("average of %d took %u microseconds (%0.5f of a frame)\n",
43 cycles, t / cycles, (double)t * (25.0 / 1000000.0 / cycles));
46 sparrow_format rgb;
47 rgb.rshift = 24;
48 rgb.gshift = 16;
49 rgb.bshift = 8;
51 ppm_dump(&rgb, outbuffer, width, height, FN_OUT);
53 finalise_jpeg_src(&sparrow);