Add missing bin/merge.c
This commit is contained in:
parent
631a41856e
commit
31a712224d
1 changed files with 90 additions and 0 deletions
90
bin/merge.c
Normal file
90
bin/merge.c
Normal file
|
@ -0,0 +1,90 @@
|
||||||
|
#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 <cammy/photo.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 merge input.png output-r.png output-g.png output-b.png\n", argv[0]);
|
||||||
|
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
int cammy_merge(int argc, char **argv) {
|
||||||
|
cammy_image *image_in_r,
|
||||||
|
*image_in_g,
|
||||||
|
*image_in_b,
|
||||||
|
*image_out;
|
||||||
|
|
||||||
|
if (argc < 3) {
|
||||||
|
usage(argc, argv, "No red input file provided");
|
||||||
|
} else if (argc < 4) {
|
||||||
|
usage(argc, argv, "No green input file provided");
|
||||||
|
} else if (argc < 5) {
|
||||||
|
usage(argc, argv, "No blue input file provided");
|
||||||
|
} else if (argc < 6) {
|
||||||
|
usage(argc, argv, "No output PNG filename provided");
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((image_in_r = cammy_image_open(argv[2])) == NULL) {
|
||||||
|
goto error_image_open_r;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((image_in_g = cammy_image_open(argv[3])) == NULL) {
|
||||||
|
goto error_image_open_g;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((image_in_b = cammy_image_open(argv[4])) == NULL) {
|
||||||
|
goto error_image_open_b;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((image_out = cammy_image_merge(image_in_r,
|
||||||
|
image_in_g,
|
||||||
|
image_in_b)) == NULL) {
|
||||||
|
goto error_image_merge;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (cammy_image_save(image_out, argv[5]) < 0) {
|
||||||
|
goto error_image_save;
|
||||||
|
}
|
||||||
|
|
||||||
|
cammy_image_destroy(image_out);
|
||||||
|
cammy_image_destroy(image_in_b);
|
||||||
|
cammy_image_destroy(image_in_g);
|
||||||
|
cammy_image_destroy(image_in_r);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
error_image_save:
|
||||||
|
cammy_image_destroy(image_out);
|
||||||
|
|
||||||
|
error_image_merge:
|
||||||
|
cammy_image_destroy(image_in_b);
|
||||||
|
|
||||||
|
error_image_open_b:
|
||||||
|
cammy_image_destroy(image_in_g);
|
||||||
|
|
||||||
|
error_image_open_g:
|
||||||
|
cammy_image_destroy(image_in_r);
|
||||||
|
|
||||||
|
error_image_open_r:
|
||||||
|
return 1;
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue