FloatImg/experiment/muxplanes.c

111 lines
2.3 KiB
C
Raw Normal View History

2021-05-26 11:31:52 +02:00
/*
* another ugly experiment
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <stdint.h>
2021-06-11 06:50:13 +02:00
#include <string.h>
2021-05-26 11:31:52 +02:00
#include "../floatimg.h"
int verbosity;
2022-01-22 14:47:46 +01:00
/* --------------------------------------------------------------- */
2021-05-26 11:31:52 +02:00
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;
}
2022-01-22 14:47:46 +01:00
/* --------------------------------------------------------------- */
2021-05-26 11:31:52 +02:00
int try_this_muxplane(char *fr, char *fg, char *fb, char *dst, int flags)
{
int foo;
FloatImg imr, img, imb, dest;
2021-10-15 23:21:02 +02:00
fprintf(stderr, "muxing: %s %s %s -> %s\n", fr, fg, fb, dst);
2021-05-26 11:31:52 +02: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;
}
2022-01-22 14:47:46 +01:00
foo = fimg_export_picture(&dest, dst, 0);
if (foo) {
fprintf(stderr, "%s: err %d exporting to %s\n", __func__, foo, dst);
return foo;
}
2021-05-26 11:31:52 +02:00
2022-01-21 14:48:45 +01:00
fimg_destroy(&imr); fimg_destroy(&img);
2022-01-22 14:47:46 +01:00
fimg_destroy(&imb); fimg_destroy(&dest);
2022-01-21 14:48:45 +01:00
2021-05-26 11:31:52 +02:00
return 0;
}
2022-01-22 14:47:46 +01:00
/* --------------------------------------------------------------- */
2021-05-26 11:31:52 +02:00
int main(int argc, char *argv[])
{
int foo;
if (5 != argc) {
2021-10-15 23:21:02 +02:00
fprintf(stderr, "ERROR: %s need four fimg files arguments\n",
argv[0]);
2021-05-26 11:31:52 +02:00
return 1;
}
2022-01-22 14:47:46 +01:00
/*
* and now, we have to decipher options on the
* command line.
*/
2021-05-26 11:31:52 +02:00
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;
}
2022-01-22 14:47:46 +01:00
/* --------------------------------------------------------------- */