libtthimage/Lib/combine5.c

179 lines
4.3 KiB
C
Raw Normal View History

2022-06-26 11:06:35 +02:00
/*
combine5.c
----------
d<EFBFBD>grad<EFBFBD>s lin<EFBFBD>aires divers.
avec des erreurs d'arrondi dedans.
*/
#include <stdio.h>
#include <stdlib.h>
2022-06-27 00:48:18 +02:00
#include "../tthimage.h"
2022-06-26 11:06:35 +02:00
/*::------------------------------------------------------------------::*/
int
Image_combine_Vdegrade(Image_Desc *s1, Image_Desc *s2,
Image_Desc *dst, int sens)
{
int x, y, foo;
int r1, g1, b1;
int r2, g2, b2;
int rd, gd, bd;
double k, ka, kb;
2022-07-07 12:52:00 +02:00
if ( (foo=Image_compare_desc(s1, s2)) ) {
fprintf(stderr, "%s: sources err: %s\n", __func__, Image_err2str(foo));
2022-06-26 11:06:35 +02:00
return foo;
}
2022-07-07 12:52:00 +02:00
for (y=0; y<s1->height; y++) {
2022-06-26 11:06:35 +02:00
k = (double)y/(double)s1->height;
if (sens) { ka = k; kb = 1.0 - ka; }
else { kb = k; ka = 1.0 - kb; }
2022-07-07 12:52:00 +02:00
for (x=0; x<s1->width; x++) {
2022-06-26 11:06:35 +02:00
Image_getRGB(s1, x, y, &r1, &g1, &b1);
Image_getRGB(s2, x, y, &r2, &g2, &b2);
rd = (int)((double)r1*ka+(double)r2*(kb));
gd = (int)((double)g1*ka+(double)g2*(kb));
bd = (int)((double)b1*ka+(double)b2*(kb));
Image_plotRGB(dst, x, y, rd, gd, bd);
}
}
return OLL_KORRECT;
}
/*::------------------------------------------------------------------::*/
int
Image_combine_Hdegrade( Image_Desc *s1, Image_Desc *s2,
Image_Desc *dst, int sens)
{
int x, y, foo;
int r1, g1, b1;
int r2, g2, b2;
int rd, gd, bd;
double k, ka, kb;
2022-07-07 12:52:00 +02:00
if ( (foo=Image_compare_desc(s1, s2)) ) {
fprintf(stderr, "%s: sources err: %s\n", __func__, Image_err2str(foo));
2022-06-26 11:06:35 +02:00
return foo;
}
2022-07-07 12:52:00 +02:00
for (x=0; x<s1->width; x++) {
2022-06-26 11:06:35 +02:00
k = (double)x/(double)s1->width;
if (sens) { ka = k; kb = 1.0-ka; }
else { kb = k; ka = 1.0-kb; }
2022-07-07 12:52:00 +02:00
for (y=0; y<s1->height; y++) {
2022-06-26 11:06:35 +02:00
Image_getRGB(s1, x, y, &r1, &g1, &b1);
Image_getRGB(s2, x, y, &r2, &g2, &b2);
rd = (int)((double)r1*ka+(double)r2*(kb));
gd = (int)((double)g1*ka+(double)g2*(kb));
bd = (int)((double)b1*ka+(double)b2*(kb));
Image_plotRGB(dst, x, y, rd, gd, bd);
}
}
return OLL_KORRECT;
}
/*::------------------------------------------------------------------::*/
/*
* bon, l<EFBFBD>, on va essayer de faire <EFBFBD>a en diagonale, mais
* je pense que <EFBFBD>a ne va pas <EFBFBD>tre simple, car il faut traiter
* le cas des images qui ne sont pas carr<EFBFBD>es...
*/
int
Image_combine_Ddegrade( Image_Desc *s1, Image_Desc *s2,
Image_Desc *dst, int sens)
{
int foo;
fprintf(stderr, "%s:%d:%s: no such function or procedure\n",
__FILE__, __LINE__, __func__);
2022-07-07 12:52:00 +02:00
if ( (foo=Image_compare_desc(s1, s2)) ) {
fprintf(stderr, "%s: sources err: %s\n", __func__, Image_err2str(foo));
2022-06-26 11:06:35 +02:00
return foo;
}
2022-07-07 12:52:00 +02:00
if ( (foo=Image_compare_desc(s1, dst)) ) {
fprintf(stderr, "%s: dst err: %s\n", __func__, Image_err2str(foo));
2022-06-26 11:06:35 +02:00
return foo;
}
fprintf(stderr, "%s : sens=%d\n", __func__, sens); /* XXX */
return FUNC_NOT_FINISH;
}
/*::------------------------------------------------------------------::*/
/* nouveau 29 novembre 2013
*/
int Image_combine_Vsplit(Image_Desc *s1, Image_Desc *s2, Image_Desc *d,
int xv, int uh)
{
int foo, x, y;
#if DEBUG_LEVEL
2022-07-07 12:52:00 +02:00
fprintf(stderr, ">>> %s ( %p %p %p %d %d )\n", __func__, s1, s2, d, xv, uh);
2022-06-26 11:06:35 +02:00
#endif
if (0 != uh)
fprintf(stderr, "%s : uh must be 0 and not %d\n", __func__, uh);
2022-07-07 12:52:00 +02:00
if ( (foo=Image_compare_desc(s1, s2)) ) {
2022-06-26 11:06:35 +02:00
fprintf(stderr, "%s : src err: %s\n", __func__, Image_err2str(foo));
return foo;
}
2022-07-07 12:52:00 +02:00
for (y=0; y<s1->height; y++) {
for (x=0; x<s1->width; x++) {
if (x<xv) {
2022-06-26 11:06:35 +02:00
(d->Rpix[y])[x] = (s1->Rpix[y])[x];
(d->Gpix[y])[x] = (s1->Gpix[y])[x];
(d->Bpix[y])[x] = (s1->Bpix[y])[x];
}
2022-07-07 12:52:00 +02:00
else {
2022-06-26 11:06:35 +02:00
(d->Rpix[y])[x] = (s2->Rpix[y])[x];
(d->Gpix[y])[x] = (s2->Gpix[y])[x];
(d->Bpix[y])[x] = (s2->Bpix[y])[x];
}
}
}
2022-07-01 02:36:54 +02:00
return OLL_KORRECT;
2022-06-26 11:06:35 +02:00
}
/*::------------------------------------------------------------------::*/
/* nouveau 29 novembre 2013
*/
int Image_combine_Hsplit(Image_Desc *s1, Image_Desc *s2, Image_Desc *d,
int yv, int uh)
{
int x, y;
#if DEBUG_LEVEL
2022-07-07 12:52:00 +02:00
fprintf(stderr, ">>> %s ( %p %p %p %d %d )\n", __func__, s1, s2, d, yv, uh);
2022-06-26 11:06:35 +02:00
#endif
if (0 != uh)
fprintf(stderr, "*** %s : uh must be 0 and not %d\n", __func__, uh);
for (y=0; y<s1->height; y++) {
for (x=0; x<s1->width; x++) {
if (y<yv)
{
(d->Rpix[y])[x] = (s1->Rpix[y])[x];
(d->Gpix[y])[x] = (s1->Gpix[y])[x];
(d->Bpix[y])[x] = (s1->Bpix[y])[x];
}
else
{
(d->Rpix[y])[x] = (s2->Rpix[y])[x];
(d->Gpix[y])[x] = (s2->Gpix[y])[x];
(d->Bpix[y])[x] = (s2->Bpix[y])[x];
}
}
}
return FUNC_IS_BETA;
}
/*::------------------------------------------------------------------::*/