-
Notifications
You must be signed in to change notification settings - Fork 3
/
test-resizer.cpp
48 lines (36 loc) · 1.08 KB
/
test-resizer.cpp
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
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include "imgdb.h"
#include "resizer.h"
int debug_level = -1;
int main(int argc, char** argv) {
if (argc < 3) exit(1);
const char* thumb = argv[1];
const char* outname = argv[2];
int thudim = strtol(argv[3], NULL, 0);
int fd = -1;
unsigned char* map = NULL;
size_t len = 0;
try {
struct stat st;
if ((fd = open(thumb, O_RDONLY)) == -1 || fstat(fd, &st) ||
(map = (unsigned char*)mmap(NULL, len = st.st_size, PROT_READ, MAP_SHARED, fd, 0)) == MAP_FAILED)
throw imgdb::io_errno(errno);
fprintf(stderr, "Mapped %s at %p:%zd.\n", thumb, map, len);
AutoGDImage thu(resize_image_data(map, len, thudim, 0, 12*thudim));
FILE *out = fopen(outname, "wb");
if (!out) throw imgdb::io_errno(errno);
gdImageJpeg(thu, out, 95);
fclose(out);
fprintf(stderr, "OK:%d %d\n", thu->sx, thu->sy);
} catch (std::exception& e) {
fprintf(stderr, "Resizer caught exception, what=%s.\n", e.what());
}
if (map) munmap(map, len);
if (fd != -1) close(fd);
return 0;
}