67 lines
1.3 KiB
C
67 lines
1.3 KiB
C
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <stdarg.h>
|
|
#include <string.h>
|
|
#include <sys/types.h>
|
|
#include <sys/stat.h>
|
|
#include <unistd.h>
|
|
#include <fcntl.h>
|
|
#include <errno.h>
|
|
|
|
#include <cammy/image.h>
|
|
|
|
#include "png.h"
|
|
#include "commands.h"
|
|
|
|
static void usage(int argc, char **argv, const char *message, ...) {
|
|
if (message) {
|
|
va_list args;
|
|
|
|
va_start(args, message);
|
|
vfprintf(stderr, message, args);
|
|
va_end(args);
|
|
fprintf(stderr, "\n");
|
|
}
|
|
|
|
fprintf(stderr, "usage: %1$s slice x-pad y-pad input.png\n", argv[0]);
|
|
|
|
exit(1);
|
|
}
|
|
|
|
int cammy_slice(int argc, char **argv) {
|
|
uint8_t *buf;
|
|
|
|
size_t width, height,
|
|
x_pad, y_pad;
|
|
|
|
int depth;
|
|
|
|
if (argc < 3) {
|
|
usage(argc, argv, "No X padding provided");
|
|
} else if (argc < 4) {
|
|
usage(argc, argv, "No Y padding provided");
|
|
} else if (argc < 5) {
|
|
usage(argc, argv, "No input PNG image provided");
|
|
}
|
|
|
|
x_pad = atoi(argv[2]);
|
|
y_pad = atoi(argv[3]);
|
|
|
|
if ((buf = cammy_png_load(argv[4], &width, &height, &depth)) == NULL) {
|
|
goto error_read_png_file;
|
|
}
|
|
|
|
if (cammy_image_slice(buf, width, height, x_pad, y_pad, depth) < 0) {
|
|
goto error_image_slice;
|
|
}
|
|
|
|
free(buf);
|
|
|
|
return 0;
|
|
|
|
error_image_slice:
|
|
free(buf);
|
|
|
|
error_read_png_file:
|
|
return 1;
|
|
}
|