FloatImg/experiment/muxplanes.c

102 lines
2.2 KiB
C
Raw Normal View History

2021-05-26 20:31:52 +11:00
/*
* another ugly experiment
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <stdint.h>
2021-06-11 15:50:13 +11:00
#include <string.h>
2021-05-26 20:31:52 +11:00
#include "../floatimg.h"
int verbosity;
/* ---------------------------------------------- ~~~~~~~~~~~~~~~~ */
int triplane_muxer(FloatImg *sr, FloatImg *sg, FloatImg *sb,
FloatImg *dst, int flages)
{
int foo;
int sz;
if (FIMG_TYPE_RGB != dst->type) {
fprintf(stderr, "%s: dst picz must be RGB, was %d\n",
__func__, dst->type);
return -99;
}
if ( fimg_images_not_compatible(sr, sg) ||
fimg_images_not_compatible(sr, sb) ||
fimg_images_not_compatible(sr, dst) ) {
fprintf(stderr, "%s: compatibility error\n", __func__);
return -2;
}
sz = sr->width * sr->height * sizeof(float);
memcpy(dst->R, sr->R, sz);
memcpy(dst->G, sg->G, sz);
memcpy(dst->B, sb->B, sz);
return 0;
}
/* ---------------------------------------------- ~~~~~~~~~~~~~~~~ */
int try_this_muxplane(char *fr, char *fg, char *fb, char *dst, int flags)
{
int foo;
FloatImg imr, img, imb, dest;
2021-10-16 08:21:02 +11:00
fprintf(stderr, "muxing: %s %s %s -> %s\n", fr, fg, fb, dst);
2021-05-26 20:31:52 +11:00
foo = fimg_create_from_dump(fr, &imr);
if (foo) {
fprintf(stderr, "%s: err %d loading %s\n", __func__, foo, fr);
return -1;
}
foo = fimg_create_from_dump(fg, &img);
if (foo) {
fprintf(stderr, "%s: err %d loading %s\n", __func__, foo, fr);
return -1;
}
foo = fimg_create_from_dump(fb, &imb);
if (foo) {
fprintf(stderr, "%s: err %d loading %s\n", __func__, foo, fr);
return -1;
}
fimg_clone(&imr, &dest, 0);
foo = triplane_muxer(&imr, &img, &imb, &dest, 0);
if (foo) {
fprintf(stderr, "%s: err %d\n", __func__, foo);
return foo;
}
fimg_export_picture(&dest, dst, 0);
2022-01-22 00:48:45 +11:00
fimg_destroy(&imr); fimg_destroy(&img);
fimg_destroy(&imr); fimg_destroy(&dest);
2021-05-26 20:31:52 +11:00
return 0;
}
/* ---------------------------------------------- ~~~~~~~~~~~~~~~~ */
int main(int argc, char *argv[])
{
int foo;
if (5 != argc) {
2021-10-16 08:21:02 +11:00
fprintf(stderr, "ERROR: %s need four fimg files arguments\n",
argv[0]);
2021-05-26 20:31:52 +11:00
return 1;
}
foo = try_this_muxplane(argv[1], argv[2], argv[3], argv[4], 0);
if (foo) {
fprintf(stderr, "oups %d\n", foo);
exit(1);
}
return 0;
}
/* ---------------------------------------------- ~~~~~~~~~~~~~~~~ */