libtthimage/Lib/combine3.c

143 lines
3.3 KiB
C
Raw Normal View History

2022-06-26 11:06:35 +02:00
/*
combine3.c
----------
*/
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
2022-06-27 00:48:18 +02:00
#include "../tthimage.h"
2022-06-26 11:06:35 +02:00
/*::------------------------------------------------------------------::*/
/*
* un kludge en chantier. programmation <EFBFBD> la 'Gruiik' en vue.
*/
2024-08-10 14:56:50 +02:00
int Image_combine_waou(Image_Desc *s1, Image_Desc *s2, Image_Desc *dst,
2022-06-26 11:06:35 +02:00
int a, int b, int c, int d)
{
int x, y, foo;
#if DEBUG_LEVEL
2024-08-10 14:56:50 +02:00
fprintf(stderr, ">>> %s ( %p %p %p %d : %d %d (%d) )\n",
2022-06-26 11:06:35 +02:00
__func__, s1, s2, dst, a, b, c, d);
#endif
2024-08-10 14:56:50 +02:00
if ( (foo=Image_compare_desc(s1, s2)) ) {
2022-06-26 11:06:35 +02:00
fprintf(stderr, "%s : sources are differents %d\n", __func__, foo);
return foo;
}
2024-08-10 14:56:50 +02:00
if ( (foo=Image_compare_desc(s1, dst)) ) {
2022-06-26 11:06:35 +02:00
fprintf(stderr, "%s : destination bad dims %d\n", __func__, foo);
return foo;
}
2024-08-10 14:56:50 +02:00
for (y=0; y<dst->height; y++) {
for (x=0; x<dst->width; x++) {
if (d) {
2022-06-26 11:06:35 +02:00
/* canonical function */
(dst->Rpix[y])[x] = (x & (s1->Rpix[y])[x]) | a;
(dst->Gpix[y])[x] = x | b;
(dst->Bpix[y])[x] = (y & (s2->Rpix[y])[x]) | c;
}
2024-08-10 14:56:50 +02:00
else {
2022-06-26 11:06:35 +02:00
/* new 9 mars 2010 - ave St Ex */
(dst->Rpix[y])[x] = (x & (s1->Rpix[y])[x]) ^ a;
(dst->Gpix[y])[x] = x ^ b;
(dst->Bpix[y])[x] = (y & (s2->Gpix[y])[x]) ^ c;
}
}
}
return FUNC_IS_BETA;
}
/*::------------------------------------------------------------------::*/
/*
* un kludge en chantier. programmation <EFBFBD> la 'Gruiik' en vue.
2024-08-10 14:56:50 +02:00
*/
int Image_combine_wauo(Image_Desc *s1, Image_Desc *s2, Image_Desc *dst,
2022-06-26 11:06:35 +02:00
int flag)
{
int x, y, foo;
if ( flag )
fprintf(stderr, "Combine Wauo: flag = %d ?\n", flag);
2024-08-10 14:56:50 +02:00
if ( (foo=Image_compare_desc(s1, s2)) ) {
2022-06-26 11:06:35 +02:00
fprintf(stderr, "Combine Wauo: sources are differents %d\n", foo);
return foo;
}
2024-08-10 14:56:50 +02:00
if ( (foo=Image_compare_desc(s1, dst)) {
2022-06-26 11:06:35 +02:00
fprintf(stderr, "Combine Wauo: destination bad dims %d\n", foo);
return foo;
}
2024-08-10 14:56:50 +02:00
for (y=1; y<dst->height-1; y++) {
for (x=1; x<dst->width-1; x++) {
2022-06-26 11:06:35 +02:00
(dst->Rpix[y])[x] = (s1->Rpix[y][x] + s2->Rpix[y][x])/2;
2024-08-10 14:56:50 +02:00
if (s1->Rpix[y][x] > s2->Rpix[y][x]) {
2022-06-26 11:06:35 +02:00
(dst->Gpix[y])[x] = (s1->Gpix[y])[x];
(dst->Bpix[y])[x] = (s2->Bpix[y])[x];
}
2024-08-10 14:56:50 +02:00
else {
2022-06-26 11:06:35 +02:00
(dst->Gpix[y])[x] = (s2->Gpix[y])[x];
(dst->Bpix[y])[x] = (s1->Bpix[y])[x];
}
}
}
return OLL_KORRECT;
}
/*::------------------------------------------------------------------::*/
/*
* threshold values (sr, sg, sb) are in the pix range [0..255]
*/
2024-08-10 14:56:50 +02:00
int Image_combine_seuils(Image_Desc *s1, Image_Desc *s2, Image_Desc *dst,
2022-06-26 11:06:35 +02:00
int sr, int sb, int sg)
{
int x, y, foo;
int r, g, b;
2024-08-10 14:56:50 +02:00
if ( (foo=Image_compare_desc(s1, s2)) ) {
2022-06-26 11:06:35 +02:00
fprintf(stderr, "Combine Seuils: sources are differents %d\n", foo);
return foo;
}
2024-08-10 14:56:50 +02:00
if ( (foo=Image_compare_desc(s1, dst)) ) {
2022-06-26 11:06:35 +02:00
fprintf(stderr, "Combine Seuils: destination bad dims %d\n", foo);
return foo;
}
sr*=2; sg*=2; sb*=2;
2024-08-10 14:56:50 +02:00
for (y=0; y<dst->height; y++) {
for (x=0; x<dst->width; x++) {
2022-06-26 11:06:35 +02:00
if ( (s1->Rpix[y][x] + s2->Rpix[y][x]) > sr )
r = s1->Rpix[y][x];
else
r = s2->Rpix[y][x];
if ( (s1->Gpix[y][x] + s2->Gpix[y][x]) > sg )
g = s1->Gpix[y][x];
else
g = s2->Gpix[y][x];
if ( (s1->Bpix[y][x] + s2->Bpix[y][x]) > sb )
b = s1->Bpix[y][x];
else
b = s2->Bpix[y][x];
(dst->Rpix[y])[x] = r;
(dst->Gpix[y])[x] = g;
(dst->Bpix[y])[x] = b;
}
}
dst->modified = 1;
return FUNC_IS_BETA;
}
/*::------------------------------------------------------------------::*/