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
|
#include <stdio.h>
#include "libplum.h"
int main(int const argc, char *const *const argv) {
if (argc < 3) {
fprintf(stderr, "usage: %s <OUT.png> <IN.png>...\n", argv[0]);
return 1;
}
unsigned error;
struct plum_image *outimage = plum_new_image();
outimage->type = PLUM_IMAGE_PNG;
outimage->color_format = PLUM_COLOR_32;
outimage->frames = 1;
outimage->width = 128;
if (argc == 3) {
struct plum_image *inimage = plum_load_image(argv[2], PLUM_MODE_FILENAME, PLUM_COLOR_32, &error);
if (inimage == NULL) {
printf("%s: read error (%s)\n", argv[2], plum_get_error_text(error));
return 1;
}
outimage->height = inimage->height / 4;
outimage->data = plum_malloc(outimage, plum_pixel_buffer_size(outimage));
for (int i = 0; i < inimage->height / 32; i++) {
int const toy = i * outimage->width * 8;
for (int j = 0; j < 16; j++) {
int const tox = j * 8;
int const tiy = ((int [16]) {0, 0, 1, 3, 3, 3, 0, 2, 0, 2, 1, 1, 1, 3, 2, 2}[j]) * 8 + inimage->width * 32 * i;
int const tix = ((int [16]) {0, 3, 0, 3, 0, 1, 2, 3, 1, 0, 3, 2, 1, 2, 1, 2}[j]) * 8 * inimage->width;
for (int py = 0; py < 8; py++) {
int const poy = py * outimage->width;
int const piy = py * inimage->width;
for (int px = 0; px < 8; px++) {
outimage->data32[toy + tox + poy + px] = inimage->data32[tiy + tix + piy + px];
}
}
}
}
plum_destroy_image(inimage);
} else {
outimage->height = (argc - 2) * 8;
outimage->data = plum_malloc(outimage, plum_pixel_buffer_size(outimage));
for (int i = 2; i < argc; i++) {
struct plum_image *inimage = plum_load_image(argv[i], PLUM_MODE_FILENAME, PLUM_COLOR_32, &error);
if (inimage == NULL) {
printf("%s: read error (%s)\n", argv[i], plum_get_error_text(error));
return 1;
}
int const toy = (i - 2) * outimage->width * 8;
for (int j = 0; j < 16; j++) {
int const tox = j * 8;
int const tiy = ((int [16]) {0, 0, 1, 3, 3, 3, 0, 2, 0, 2, 1, 1, 1, 3, 2, 2}[j]) * 8;
int const tix = ((int [16]) {0, 3, 0, 3, 0, 1, 2, 3, 1, 0, 3, 2, 1, 2, 1, 2}[j]) * 8 * inimage->width;
for (int py = 0; py < 8; py++) {
int const poy = py * outimage->width;
int const piy = py * inimage->width;
for (int px = 0; px < 8; px++) {
outimage->data32[toy + tox + poy + px] = inimage->data32[tiy + tix + piy + px];
}
}
}
plum_destroy_image(inimage);
}
}
plum_store_image(outimage, argv[1], PLUM_MODE_FILENAME, &error);
if (error) {
printf("%s: write error (%s)\n", argv[1], plum_get_error_text(error));
return 1;
}
plum_destroy_image(outimage);
return 0;
}
|