[73d389]: tests / test_image.cpp  Maximize  Restore  History

Download this file

126 lines (102 with data), 2.8 kB

  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
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#include <libjp4/image.h>
#include <libjp4/clock.h>
extern "C" {
#include <stdio.h>
}
void PGM(const char* output, const ImageL8i* img) {
FILE* pgm = fopen(output, "w");
fprintf(pgm, "P2\n%hu %hu\n%hhu\n", img->xsize(), img->ysize(), 0xff);
for (uint16_t i = 0; i < img->ysize(); i++) {
for (uint16_t j = 0; j < img->xsize(); j++) {
fprintf(pgm, "%hhu ", img->operator()(i,j));
}
fprintf(pgm, "\n");
}
fclose(pgm);
}
ImageL8i* PGM(const char* input) {
FILE* f = fopen(input, "r");
uint16_t w = 0;
uint16_t h = 0;
uint8_t max = 0;
fscanf(f, "P2");
fscanf(f, "%hu %hu", &w, &h);
fscanf(f, "%hhu", &max);
ImageL8i* img = new ImageL8i(w,h);
for (uint16_t i=0; i < h; i++) {
for (uint16_t j=0; j < w; j++) {
fscanf(f, "%hhu", &img->operator()(i,j));
}
}
return img;
}
void flipX() {
ImageL8i* img = PGM("test_image.pgm.template");
uint64_t t0 = currentTimeMillis();
img->flipX();
uint64_t t1 = currentTimeMillis();
PGM("__autogen__flipX.pgm", img);
printf("flipX %llu\n", t1-t0);
delete img;
}
void flipY() {
ImageL8i* img = PGM("test_image.pgm.template");
uint64_t t0 = currentTimeMillis();
img->flipY();
uint64_t t1 = currentTimeMillis();
PGM("__autogen__flipY.pgm", img);
printf("flipY: %llu\n", t1-t0);
delete img;
}
void flipXY() {
ImageL8i* img = PGM("test_image.pgm.template");
uint64_t t0 = currentTimeMillis();
img->flipXY();
uint64_t t1 = currentTimeMillis();
PGM("__autogen__flipXY.pgm", img);
printf("flipXY: %llu\n", t1-t0);
delete img;
}
void rotate90() {
ImageL8i* img = PGM("test_image.pgm.template");
uint64_t t0 = currentTimeMillis();
img->rotate(ROTATE_90);
uint64_t t1 = currentTimeMillis();
PGM("__autogen__rotate90.pgm", img);
printf("rotate90: %llu\n", t1-t0);
delete img;
}
void rotate180() {
ImageL8i* img = PGM("test_image.pgm.template");
uint64_t t0 = currentTimeMillis();
img->rotate(ROTATE_180);
uint64_t t1 = currentTimeMillis();
PGM("__autogen__rotate180.pgm", img);
printf("rotate180: %llu\n", t1-t0);
delete img;
}
void rotate270() {
ImageL8i* img = PGM("test_image.pgm.template");
uint64_t t0 = currentTimeMillis();
img->rotate(ROTATE_270);
uint64_t t1 = currentTimeMillis();
PGM("__autogen__rotate270.pgm", img);
printf("rotate270: %llu\n", t1-t0);
delete img;
}
void crop() {
ImageL8i* img = PGM("test_image.pgm.template");
uint64_t t0 = currentTimeMillis();
ImageL8i* crop = img->crop(256, 256, 1024, 1024);
uint64_t t1 = currentTimeMillis();
PGM("__autogen__crop-1024x1024+256+256.pgm", crop);
printf("crop: %llu\n", t1-t0);
delete img;
delete crop;
}
int main() {
flipX(); flipY(); flipXY();
rotate90(); rotate180(); rotate270();
crop();
return 0;
};