FloatImg/funcs/incrustator.c

109 lines
2.5 KiB
C
Raw Normal View History

2021-03-28 18:52:03 +02:00
/*
2021-04-28 09:16:00 +02:00
* incrustator VERY experimental
2021-04-28 00:21:45 +02:00
* KRKRK
2021-03-28 18:52:03 +02:00
*/
#include <stdio.h>
#include <string.h>
2021-05-20 09:31:28 +02:00
#include <stdint.h>
2021-03-30 21:22:04 +02:00
#include <stdlib.h>
2021-03-28 18:52:03 +02:00
#include "../floatimg.h"
2021-04-28 00:21:45 +02:00
// XXX #include "incrustator.h"
2021-03-28 18:52:03 +02:00
extern int verbosity;
2021-03-30 21:22:04 +02:00
/* ---------------------------------------------------------------- */
static int check_boundaries(FloatImg *from, FloatImg *to, FimgArea51 *a51)
{
#if DEBUG_LEVEL
fprintf(stderr, ">>> %s ( %p %p %p )\n", __func__, from, to, a51);
2022-07-06 10:27:55 +02:00
#endif
2023-01-31 00:14:56 +01:00
if (verbosity > 1) {
fimg_printdims("from", from);
fimg_printdims("to ", to);
}
2021-03-30 21:22:04 +02:00
/* just a small molly-guard */
if ( (a51->w < 0) || (a51->h < 0) ) {
fprintf(stderr, "%s: fubar on %p\n", __func__, a51);
abort(); /* FY Bro ! */
}
2022-07-06 10:27:55 +02:00
return 0;
2021-03-30 21:22:04 +02:00
}
/* ---------------------------------------------------------------- */
2022-07-06 10:27:55 +02:00
/* XXX
2021-03-30 21:22:04 +02:00
static int move_pixels(FloatImg *from, FloatImg *to,
FimgArea51 *a51, int flags)
{
#if DEBUG_LEVEL
fprintf(stderr, ">>> %s ( %p %p %p 0x%04x )\n", __func__,
from, to, a51, flags);
#endif
return -1;
}
2022-07-06 10:27:55 +02:00
*/
2021-03-28 18:52:03 +02:00
/* ---------------------------------------------------------------- */
2023-01-22 15:32:09 +01:00
/*
* See also: fimg_extractor() in geometry.c
*/
2021-04-28 00:21:45 +02:00
int fimg_incrustator_0(FloatImg *psrc, FloatImg *pdst,
2021-03-28 18:52:03 +02:00
int xpos, int ypos, int flags)
{
2021-03-30 21:22:04 +02:00
int y, srcpos, dstpos, szl;
int foo;
FimgArea51 area;
2021-03-28 18:52:03 +02:00
#if DEBUG_LEVEL
fprintf(stderr, ">>> %s ( %p %p %d %d 0x%04X\n", __func__, psrc, pdst,
xpos, ypos, flags);
#endif
2022-07-06 10:27:55 +02:00
if (flags) { fprintf(stderr, "flags: 0x%04x in %s\n", flags, __func__); }
2021-03-28 18:52:03 +02:00
if (verbosity > 1) {
fimg_describe(psrc, "source");
fimg_describe(pdst, "destination");
}
/* check boudaries */
2021-03-30 21:22:04 +02:00
area.x = xpos; area.y = ypos;
area.w = psrc->width; area.h = psrc->height;
foo = check_boundaries(psrc, pdst, &area);
2022-07-06 10:27:55 +02:00
if (foo) {
fprintf(stderr, "Boudary error %d in %s:%d\n", foo, __func__, __LINE__);
return foo;
}
2021-03-30 21:22:04 +02:00
2021-03-28 18:52:03 +02:00
if ( (xpos < 0) || (xpos > pdst->width - psrc->width) ||
(ypos < 0) || (ypos > pdst->height - psrc->height) ) {
2023-01-31 00:14:56 +01:00
fprintf(stderr, "%s: boudary error, x=%d y=%d\n", __func__,
xpos, ypos);
2021-03-28 18:52:03 +02:00
return -2;
}
/* move all the data by looping over lines */
srcpos = 0;
2021-03-29 10:36:59 +02:00
dstpos = (ypos * pdst->width) + xpos;
2021-03-28 18:52:03 +02:00
szl = psrc->width * sizeof(float);
for (y=0; y<psrc->height; y++) {
// fprintf(stderr, " %7d %7d %7d\n", y, srcpos, dstpos);
memcpy(pdst->R + dstpos, psrc->R + srcpos, szl);
memcpy(pdst->G + dstpos, psrc->G + srcpos, szl);
memcpy(pdst->B + dstpos, psrc->B + srcpos, szl);
2021-03-29 10:36:59 +02:00
2021-03-28 19:33:02 +02:00
srcpos += psrc->width;
2021-03-29 10:36:59 +02:00
dstpos += pdst->width;
2021-03-28 18:52:03 +02:00
}
return 0;
}
/* ---------------------------------------------------------------- */