53 lines
1 KiB
C
53 lines
1 KiB
C
|
#include <stdio.h>
|
||
|
#include <stdlib.h>
|
||
|
#include <string.h>
|
||
|
#include <stdarg.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"
|
||
|
|
||
|
int cammy_command_slice(int argc, char **argv) {
|
||
|
uint8_t *buf;
|
||
|
|
||
|
size_t width, height,
|
||
|
x_pad, y_pad;
|
||
|
|
||
|
int depth;
|
||
|
|
||
|
if (argc < 3) {
|
||
|
cammy_command_usage(argc, argv, "No X padding provided");
|
||
|
} else if (argc < 4) {
|
||
|
cammy_command_usage(argc, argv, "No Y padding provided");
|
||
|
} else if (argc < 5) {
|
||
|
cammy_command_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;
|
||
|
}
|