libtthimage/Lib/rgbmask.c

164 lines
3.7 KiB
C
Raw Normal View History

2022-06-26 20:06:35 +11:00
/*
rgbmask.c
----------------
WORK IN PROGRESS
- manque de documentation, toussa -
*/
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
2022-06-27 09:48:18 +11:00
#include "../tthimage.h"
2022-06-26 20:06:35 +11:00
/*::------------------------------------------------------------------::*/
/*
* horizontal lines
*/
2024-08-12 21:32:58 +11:00
int Image_rgbmask_H(Image_Desc *src, Image_Desc *dst, int gris)
2022-06-26 20:06:35 +11:00
{
int foo, x, y;
2024-08-12 21:32:58 +11:00
if ( (foo=Image_compare_desc(src, dst)) ) {
2022-06-26 20:06:35 +11:00
fprintf(stderr, "%s : images are differents %d\n", __func__, foo);
return foo;
}
Image_copy(src, dst); /* XXX pourquoi cette copie ? */
2024-08-12 21:32:58 +11:00
for (y=0; y<src->height; y++) {
for (x=0; x<src->width; x++) {
switch (y%3) {
2022-06-26 20:06:35 +11:00
case 0:
Image_plot_channel(dst, 'r', x, y, gris);
Image_plot_channel(dst, 'g', x, y, gris);
break;
case 1:
Image_plot_channel(dst, 'r', x, y, gris);
Image_plot_channel(dst, 'b', x, y, gris);
break;
case 2:
Image_plot_channel(dst, 'b', x, y, gris);
Image_plot_channel(dst, 'g', x, y, gris);
break;
}
}
}
return FUNC_IS_BETA;
}
/*::------------------------------------------------------------------::*/
/*
* vertical lines
*/
2024-08-12 21:32:58 +11:00
int Image_rgbmask_V(Image_Desc *src, Image_Desc *dst, int gris)
2022-06-26 20:06:35 +11:00
{
int foo, x, y;
2024-08-12 21:32:58 +11:00
if ( (foo=Image_compare_desc(src, dst)) ) {
2022-06-26 20:06:35 +11:00
fprintf(stderr, "Image rgbmask V: images are differents %d\n", foo);
return foo;
}
Image_copy(src, dst);
2024-08-12 21:32:58 +11:00
for (y=0; y<src->height; y++) {
for (x=0; x<src->width; x++) {
switch (x%3) {
2022-06-26 20:06:35 +11:00
case 0:
Image_plot_channel(dst, 'r', x, y, gris);
Image_plot_channel(dst, 'g', x, y, gris);
break;
case 1:
Image_plot_channel(dst, 'r', x, y, gris);
Image_plot_channel(dst, 'b', x, y, gris);
break;
case 2:
Image_plot_channel(dst, 'b', x, y, gris);
Image_plot_channel(dst, 'g', x, y, gris);
break;
}
}
}
return FUNC_IS_BETA;
}
/*::------------------------------------------------------------------::*/
/*
* sequential dots - _very_ dependant on image dimensions.
*/
2024-08-12 21:32:58 +11:00
int Image_rgbmask_2(Image_Desc *src, Image_Desc *dst, int gris)
2022-06-26 20:06:35 +11:00
{
int foo, x, y;
2024-08-12 21:32:58 +11:00
if ( (foo=Image_compare_desc(src, dst)) ) {
2022-06-26 20:06:35 +11:00
fprintf(stderr, "Image rgbmask 2: images are differents %d\n", foo);
return foo;
}
Image_copy(src, dst);
foo = 0;
2024-08-12 21:32:58 +11:00
for (y=0; y<src->height; y++) {
for (x=0; x<src->width; x++) {
2022-06-26 20:06:35 +11:00
foo++;
2024-08-12 21:32:58 +11:00
switch (foo%3) {
2022-06-26 20:06:35 +11:00
case 0:
Image_plot_channel(dst, 'r', x, y, gris);
Image_plot_channel(dst, 'g', x, y, gris);
break;
case 1:
Image_plot_channel(dst, 'r', x, y, gris);
Image_plot_channel(dst, 'b', x, y, gris);
break;
case 2:
Image_plot_channel(dst, 'b', x, y, gris);
Image_plot_channel(dst, 'g', x, y, gris);
break;
}
}
}
return FUNC_IS_BETA;
}
/*::------------------------------------------------------------------::*/
/*
* random dots - VERY BAD RESULTS :(
*/
2024-08-12 21:32:58 +11:00
int Image_rgbmask_R(Image_Desc *src, Image_Desc *dst, int gris)
2022-06-26 20:06:35 +11:00
{
int foo, x, y;
#if DEBUG_LEVEL
fprintf(stderr, "this function, %s(%d), is very buggy...\n", __func__, gris);
#endif
2024-08-12 21:32:58 +11:00
if ( (foo=Image_compare_desc(src, dst)) ) {
2022-06-26 20:06:35 +11:00
fprintf(stderr, "Image rgbmask R: images are differents %d\n", foo);
return foo;
}
Image_copy(src, dst);
2024-08-12 21:32:58 +11:00
for (y=0; y<src->height; y++) {
for (x=0; x<src->width; x++) {
2022-06-26 20:06:35 +11:00
foo = rand() % 3; /* mmmm pas tres bon :( */
2024-08-12 21:32:58 +11:00
switch (foo) {
2022-06-26 20:06:35 +11:00
case 0:
Image_plot_channel(dst, 'r', x, y, gris);
Image_plot_channel(dst, 'g', x, y, gris);
break;
case 1:
Image_plot_channel(dst, 'r', x, y, gris);
Image_plot_channel(dst, 'b', x, y, gris);
break;
case 2:
Image_plot_channel(dst, 'b', x, y, gris);
Image_plot_channel(dst, 'g', x, y, gris);
break;
}
}
}
return FUNC_IS_BETA;
}
/*::------------------------------------------------------------------::*/