2022-06-26 11:06:35 +02:00
|
|
|
/*
|
|
|
|
tele_2.c
|
|
|
|
--------
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <math.h>
|
|
|
|
|
2022-06-27 09:00:44 +02:00
|
|
|
#include "../tthimage.h"
|
2022-06-26 11:06:35 +02:00
|
|
|
|
|
|
|
/*::------------------------------------------------------------------::*/
|
|
|
|
/*
|
|
|
|
* comme au bon vieux temps...
|
|
|
|
*/
|
2022-09-23 13:28:02 +02:00
|
|
|
int Image_TV_old(Image_Desc *src, Image_Desc *dst, int p1, int p2, int p3)
|
2022-06-26 11:06:35 +02:00
|
|
|
{
|
|
|
|
int foo;
|
|
|
|
int x, y, v1, v2;
|
|
|
|
int resteY;
|
|
|
|
int sigma;
|
|
|
|
|
2022-09-23 13:28:02 +02:00
|
|
|
#if DEBUG_LEVEL
|
|
|
|
fprintf(stderr, ">>> %s ( %p %p %d %d %d )\n", __func__,
|
|
|
|
src, dst, p1, p2, p3);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if ( (foo=Image_compare_desc(src, dst)) ) {
|
2022-06-26 11:06:35 +02:00
|
|
|
fprintf(stderr, "%s: images are differents %d\n", __func__, foo);
|
|
|
|
return foo;
|
|
|
|
}
|
|
|
|
|
|
|
|
sigma = p1 + p2 + p3;
|
|
|
|
if (!sigma) sigma++;
|
|
|
|
|
|
|
|
resteY = src->height % 3;
|
|
|
|
resteY /= 2; /* half for the top, half for the bottom */
|
|
|
|
|
|
|
|
#if DEBUG_LEVEL
|
|
|
|
fprintf(stderr, "%s : height %d reste Y %d\n", __func__, src->height, resteY);
|
2022-09-23 13:28:02 +02:00
|
|
|
fprintf(stderr, "%s : %d %d %d -> %d\n", __func__, p1, p2, p3, sigma);
|
2022-06-26 11:06:35 +02:00
|
|
|
#endif
|
|
|
|
|
2022-09-23 13:28:02 +02:00
|
|
|
for (y=resteY; y<src->height-resteY-1; y+=3) {
|
|
|
|
for (x=0; x<src->width; x++) {
|
2022-06-26 11:06:35 +02:00
|
|
|
v1 = ( Image_R_pixel(src, x, y) +
|
|
|
|
Image_R_pixel(src, x, y+1) +
|
|
|
|
Image_R_pixel(src, x, y+2) +
|
|
|
|
Image_G_pixel(src, x, y) +
|
|
|
|
Image_G_pixel(src, x, y+1) +
|
|
|
|
Image_G_pixel(src, x, y+2) +
|
|
|
|
Image_B_pixel(src, x, y) +
|
|
|
|
Image_B_pixel(src, x, y+1) +
|
|
|
|
Image_B_pixel(src, x, y+2) ) / 9 ;
|
|
|
|
|
|
|
|
v2 = (v1 * p1) / sigma;
|
|
|
|
Image_plotRGB(dst, x, y, v2, v2, v2);
|
|
|
|
v2 = (v1 * p2) / sigma;
|
|
|
|
Image_plotRGB(dst, x, y+1, v2, v2, v2);
|
|
|
|
v2 = (v1 * p3) / sigma;
|
|
|
|
Image_plotRGB(dst, x, y+2, v2, v2, v2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return FUNC_IS_BETA;
|
|
|
|
}
|
|
|
|
/*::------------------------------------------------------------------::*/
|
|
|
|
/*
|
|
|
|
* this is juste a wrapper function - need more work...
|
|
|
|
*/
|
2022-09-23 13:28:02 +02:00
|
|
|
int Image_TV_veryold(Image_Desc *src, Image_Desc *dst, int p1, int p2, int p3)
|
2022-06-26 11:06:35 +02:00
|
|
|
{
|
|
|
|
int foo;
|
|
|
|
|
|
|
|
/* 15 janvier 2007: chasse au coredump... */
|
2022-09-23 13:28:02 +02:00
|
|
|
if ( (src->magic!=MAGIC_OF_IMAGE) || (dst->magic!=MAGIC_OF_IMAGE) ) {
|
2022-06-26 11:06:35 +02:00
|
|
|
fprintf(stderr, "Image TV veryold: bad image descriptor\n");
|
|
|
|
abort();
|
|
|
|
}
|
|
|
|
|
2022-09-23 13:28:02 +02:00
|
|
|
if ( (foo=Image_compare_desc(src, dst)) ) {
|
2022-06-26 11:06:35 +02:00
|
|
|
fprintf(stderr, "Image TV veryold: images are differents %d\n", foo);
|
|
|
|
return foo;
|
|
|
|
}
|
|
|
|
|
|
|
|
foo = Image_TV_old(src, dst, p1, p2, p3);
|
|
|
|
fprintf(stderr, "%s : ret %d\n", __func__, foo);
|
|
|
|
|
|
|
|
return FUNC_IS_ALPHA;
|
|
|
|
}
|
|
|
|
/*::------------------------------------------------------------------::*/
|
|
|
|
/*
|
|
|
|
* new 10 novembre 2013, in mixart-myrys
|
|
|
|
*/
|
2022-09-23 13:28:02 +02:00
|
|
|
int Image_TV_pix_0(Image_Desc *src, Image_Desc *dst, int w, int h, int grey)
|
2022-06-26 11:06:35 +02:00
|
|
|
{
|
|
|
|
int foo, ox, oy;
|
|
|
|
int x, y, r, g, b;
|
|
|
|
int xmax, ymax;
|
|
|
|
Image_Rect zone;
|
|
|
|
|
2022-09-23 13:28:02 +02:00
|
|
|
#if DEBUG_LEVEL
|
|
|
|
fprintf(stderr, ">>> %s ( %p %p %d %d %d )\n", __func__,
|
|
|
|
src, dst, w, h, grey);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if ( (foo=Image_compare_desc(src, dst)) ) {
|
2022-06-26 11:06:35 +02:00
|
|
|
fprintf(stderr, "%s: images are differents %d\n", __func__, foo);
|
|
|
|
return foo;
|
|
|
|
}
|
|
|
|
|
|
|
|
#if DEBUG_LEVEL
|
|
|
|
fprintf(stderr, "%s : w %d h %d grey %d\n", __func__, w, h, grey);
|
|
|
|
#endif
|
|
|
|
|
2022-09-23 13:28:02 +02:00
|
|
|
if (0==h || 0==w) {
|
2022-06-26 11:06:35 +02:00
|
|
|
return BAD_PARAMETER;
|
|
|
|
}
|
|
|
|
|
|
|
|
zone.w = w-1; zone.h = h-1;
|
|
|
|
xmax = src->width - w; ymax = src->height - h;
|
|
|
|
ox = (src->width % w) / 2;
|
|
|
|
oy = (src->height % h) / 2;
|
|
|
|
#if DEBUG_LEVEL
|
2024-08-10 17:48:08 +02:00
|
|
|
fprintf(stderr, "%s : offsets = %d & %d\n", __func__, ox, oy);
|
2022-06-26 11:06:35 +02:00
|
|
|
#endif
|
|
|
|
Image_clear(dst, grey, grey, grey);
|
|
|
|
|
2024-08-11 11:20:04 +02:00
|
|
|
for (x=ox; x<(xmax-ox); x+=w) {
|
2022-06-26 11:06:35 +02:00
|
|
|
zone.x = x + (w/2);
|
2024-08-11 11:20:04 +02:00
|
|
|
for (y=oy; y<(ymax-oy); y+=h) {
|
2022-06-26 11:06:35 +02:00
|
|
|
zone.y = y + (h/2);
|
|
|
|
r = src->Rpix[y][x] & 0xfe;
|
|
|
|
g = src->Gpix[y][x] & 0xfe;
|
|
|
|
b = src->Bpix[y][x] & 0xfe;
|
|
|
|
|
|
|
|
Image_paint_rect(dst, &zone, r, g, b);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return FUNC_IS_BETA;
|
|
|
|
}
|
|
|
|
/*::------------------------------------------------------------------::*/
|
|
|
|
/*
|
|
|
|
* new 10 novembre 2013, in mixart-myrys
|
|
|
|
*/
|
|
|
|
int Image_TV_pix_1(Image_Desc *src, Image_Desc *dst, int w, int h, int p3)
|
|
|
|
{
|
|
|
|
int foo;
|
|
|
|
int x, y, v1, v2, r, g, b;
|
|
|
|
int xmax, ymax;
|
|
|
|
Image_Rect zone;
|
|
|
|
|
2022-09-23 13:28:02 +02:00
|
|
|
#if DEBUG_LEVEL
|
|
|
|
fprintf(stderr, ">>> %s ( %p %p %d %d %d )\n", __func__,
|
|
|
|
src, dst, w, h, p3);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if ( (foo=Image_compare_desc(src, dst)) ) {
|
2022-06-26 11:06:35 +02:00
|
|
|
fprintf(stderr, "%s: images are differents %d\n", __func__, foo);
|
|
|
|
return foo;
|
|
|
|
}
|
|
|
|
|
|
|
|
#if DEBUG_LEVEL
|
|
|
|
fprintf(stderr, "%s : w %d h %d g%d\n", __func__, w, h, p3);
|
|
|
|
#endif
|
|
|
|
|
2022-09-23 13:28:02 +02:00
|
|
|
if ((0==h) || (0==w)) {
|
2022-06-26 11:06:35 +02:00
|
|
|
return BAD_PARAMETER;
|
|
|
|
}
|
|
|
|
|
|
|
|
zone.w = w-1;
|
|
|
|
zone.h = h-1;
|
|
|
|
xmax = src->width - w;
|
|
|
|
ymax = src->height - h;
|
|
|
|
v1 = v2 = 0;
|
|
|
|
|
2022-09-23 13:28:02 +02:00
|
|
|
for (x=0; x<xmax; x+=w) {
|
2022-06-26 11:06:35 +02:00
|
|
|
zone.x = x;
|
2022-09-23 13:28:02 +02:00
|
|
|
for (y=0; y<ymax; y+=h) {
|
2022-06-26 11:06:35 +02:00
|
|
|
zone.y = y;
|
|
|
|
r = src->Rpix[y][x];
|
|
|
|
g = src->Gpix[y][x];
|
|
|
|
b = src->Bpix[y][x];
|
|
|
|
|
|
|
|
Image_paint_rect(dst, &zone, r, g, b);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return FULL_NUCKED;
|
|
|
|
}
|
|
|
|
/*::------------------------------------------------------------------::*/
|
|
|
|
/*
|
2024-04-01 18:26:46 +02:00
|
|
|
* new 3 jan 2013 - at Mixart-Myrys
|
2022-06-26 11:06:35 +02:00
|
|
|
*/
|
|
|
|
int Image_TV_cplus_v1(Image_Desc *src, Image_Desc *dst, int p)
|
|
|
|
{
|
|
|
|
int foo;
|
|
|
|
int y, taille;
|
|
|
|
|
|
|
|
#if DEBUG_LEVEL
|
2024-04-01 18:26:46 +02:00
|
|
|
fprintf(stderr, ">>> %s ( %p %p %d )\n", __func__, src, dst, p);
|
2022-06-26 11:06:35 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
if (p <= 1) {
|
|
|
|
fprintf(stderr, "%s: p must be > 1, but was %d\n", __func__, p);
|
|
|
|
return BAD_PARAMETER;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( (foo=Image_compare_desc(src, dst)) ) {
|
|
|
|
fprintf(stderr, "%s : images are differents %d\n", __func__, foo);
|
|
|
|
return foo;
|
|
|
|
}
|
|
|
|
|
|
|
|
taille = src->width - (abs(p*2));
|
|
|
|
#if DEBUG_LEVEL
|
|
|
|
fprintf(stderr, "%s: largeur %d, taille %d\n", __func__, src->width, taille);
|
|
|
|
#endif
|
|
|
|
|
2024-04-01 18:26:46 +02:00
|
|
|
/* make a background for left and right border's pixels */
|
|
|
|
Image_gray_noise_0(dst, 20, 90);
|
2022-06-26 11:06:35 +02:00
|
|
|
|
2022-09-23 13:28:02 +02:00
|
|
|
for (y=0; y<src->height; y++) {
|
2022-06-26 11:06:35 +02:00
|
|
|
switch (rand()%3) {
|
|
|
|
case 0 :
|
|
|
|
memcpy((dst->Rpix[y]), src->Rpix[y], taille);
|
|
|
|
memcpy((dst->Gpix[y]), src->Gpix[y], taille);
|
|
|
|
memcpy((dst->Bpix[y]), src->Bpix[y], taille);
|
|
|
|
break;
|
|
|
|
case 1 :
|
|
|
|
memcpy((dst->Rpix[y])+p, src->Rpix[y], taille);
|
|
|
|
memcpy((dst->Gpix[y])+p, src->Gpix[y], taille);
|
|
|
|
memcpy((dst->Bpix[y])+p, src->Bpix[y], taille);
|
|
|
|
break;
|
|
|
|
case 2 :
|
|
|
|
memcpy((dst->Rpix[y])+p+p, src->Rpix[y], taille);
|
|
|
|
memcpy((dst->Gpix[y])+p+p, src->Gpix[y], taille);
|
|
|
|
memcpy((dst->Bpix[y])+p+p, src->Bpix[y], taille);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return FUNC_IS_BETA;
|
|
|
|
}
|
|
|
|
/*::------------------------------------------------------------------::*/
|
|
|
|
/* new 28 janvier 2015 - MixartMyrys */
|
|
|
|
/* le parametre 'mode' est un flag */
|
|
|
|
|
|
|
|
int Image_TV_triligne(Image_Desc *src, Image_Desc *dst, int mode)
|
|
|
|
{
|
|
|
|
int x, y, tri, v, idx;
|
|
|
|
|
|
|
|
#if DEBUG_LEVEL
|
|
|
|
fprintf(stderr, "%s ( %p %p %d ) -> ", __func__, src, dst, mode);
|
|
|
|
if (mode) fprintf(stderr, " rand\n");
|
|
|
|
else fprintf(stderr, " modulo\n");
|
|
|
|
#endif
|
|
|
|
|
|
|
|
Image_clear(dst, 60, 60, 60); /* XXX necessaire ? */
|
|
|
|
|
|
|
|
idx = rand() % 42;
|
|
|
|
|
2022-09-23 13:28:02 +02:00
|
|
|
for (y=0; y<src->height; y++) {
|
2022-06-26 11:06:35 +02:00
|
|
|
if (0==mode) {
|
|
|
|
tri = (idx + y) % 3;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
tri = rand() % 3;
|
|
|
|
}
|
|
|
|
#if DEBUG_LEVEL > 1
|
|
|
|
fprintf(stderr, " %5d -> %d\n", y, tri);
|
|
|
|
#endif
|
2022-09-23 13:28:02 +02:00
|
|
|
switch (tri) {
|
2022-06-26 11:06:35 +02:00
|
|
|
case 0:
|
|
|
|
for (x=0; x<(src->width)-1; x++) {
|
|
|
|
v = (src->Rpix[y][x] + src->Rpix[y][x+1]);
|
|
|
|
dst->Rpix[y][x] = v / 2;
|
|
|
|
v = (src->Gpix[y][x] + src->Gpix[y][x+1]);
|
|
|
|
dst->Gpix[y][x] = v / 2;
|
|
|
|
v = (src->Bpix[y][x] + src->Bpix[y][x+1]);
|
|
|
|
dst->Bpix[y][x] = v / 2;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
for (x=1; x<(src->width)-1; x++) {
|
|
|
|
v = src->Rpix[y][x-1] + src->Rpix[y][x+1];
|
|
|
|
dst->Rpix[y][x] = v / 2;
|
|
|
|
v = src->Gpix[y][x-1] + src->Gpix[y][x+1];
|
|
|
|
dst->Gpix[y][x] = v / 2;
|
|
|
|
v = src->Bpix[y][x-1] + src->Bpix[y][x+1];
|
|
|
|
dst->Bpix[y][x] = v / 2;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
for (x=1; x<src->width; x++) {
|
|
|
|
v = src->Rpix[y][x] + src->Rpix[y][x-1];
|
|
|
|
dst->Rpix[y][x] = v / 2;
|
|
|
|
v = src->Gpix[y][x] + src->Gpix[y][x-1];
|
|
|
|
dst->Gpix[y][x] = v / 2;
|
|
|
|
v = src->Bpix[y][x] + src->Bpix[y][x-1];
|
|
|
|
dst->Bpix[y][x] = v / 2;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
/* blam< */
|
|
|
|
abort();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return FULL_NUCKED;
|
|
|
|
}
|
|
|
|
/*::------------------------------------------------------------------::*/
|