FloatImg/funcs/rampes.c

114 lines
2.3 KiB
C
Raw Normal View History

2020-01-03 15:39:11 +01:00
/*
* FLOATIMG
* rampes diverses, trucs etranges
*/
#include <stdio.h>
2021-05-17 22:38:56 +02:00
#include <stdint.h>
2022-09-19 11:58:30 +02:00
#include <stdlib.h>
#include <sys/time.h>
2020-01-03 15:39:11 +01:00
#include "../floatimg.h"
/* --------------------------------------------------------------------- */
int fimg_hdeg_a(FloatImg *img, double dcoef)
{
int x, y;
float value;
#if DEBUG_LEVEL
fprintf(stderr, ">>> %s ( %p %f )\n", __func__, img, dcoef);
#endif
if (FIMG_TYPE_RGB != img->type) {
fprintf(stderr, "%s bad type\n", __func__);
return -6;
}
2022-09-19 11:58:30 +02:00
for (x=0; x<img->width; x++) {
2020-01-03 15:39:11 +01:00
value = (float)x / (float)img->width;
value *= dcoef;
for (y=0; y<img->height; y++) {
fimg_plot_rgb(img, x, y, value, value, value);
}
}
return 0;
}
/* --------------------------------------------------------------------- */
2020-11-15 20:57:52 +01:00
/*
2021-03-17 18:32:51 +01:00
* To have the black at the bottom, use a negative dcoef
2020-11-15 20:57:52 +01:00
*/
2020-01-03 15:39:11 +01:00
int fimg_vdeg_a(FloatImg *img, double dcoef)
{
int x, y;
float value;
#if DEBUG_LEVEL
fprintf(stderr, ">>> %s ( %p %f )\n", __func__, img, dcoef);
#endif
if (FIMG_TYPE_RGB != img->type) {
fprintf(stderr, "%s bad type\n", __func__);
return -6;
}
2022-09-19 11:58:30 +02:00
for (x=0; x<img->width; x++) {
value = (float)x / (float)img->width;
value *= dcoef;
for (y=0; y<img->height; y++) {
fimg_plot_rgb(img, x, y, value, value, value);
}
}
return 0;
}
/* --------------------------------------------------------------------- */
/* nouveau 19 septembre 2022
*
* 6 octobre 2023 : rajout du parametre 'fmax'
*/
2022-09-19 11:58:30 +02:00
int fimg_do_stripes(FloatImg *img, float fmax, int mode)
2022-09-19 11:58:30 +02:00
{
int x, y, quad;
float *ligne;
float fr, fg, fb;
fprintf(stderr, ">>> %s ( %p %f %d )\n", __func__, img, fmax, mode);
2022-09-19 11:58:30 +02:00
/*
* allocate and fill a lookup table
*/
if (NULL==(ligne=malloc(img->width*sizeof(float)))) {
fprintf(stderr, "%s: malloc fail\n", __func__);
exit(1);
}
for (x=0; x<img->width; x++) {
2022-09-19 11:58:30 +02:00
ligne[x] = (float)x / (float)img->width;
ligne[x] *= fmax;
}
2022-09-19 11:58:30 +02:00
/*
* build the pixels
*/
2020-01-03 15:39:11 +01:00
for (y=0; y<img->height; y++)
{
2022-09-19 11:58:30 +02:00
quad = (y*4) / img->height ;
2020-01-03 15:39:11 +01:00
for (x=0; x<img->width; x++) {
2022-09-19 11:58:30 +02:00
fr = fg = fb = ligne[x];
switch(quad) {
case 0: fg = fb = 0; break;
case 1: fr = fb = 0; break;
case 2: fr = fg = 0; break;
case 3: break;
default: abort(); break;
}
fimg_plot_rgb(img, x, y, fr, fg, fb);
2020-01-03 15:39:11 +01:00
}
}
2022-09-19 11:58:30 +02:00
free(ligne);
2020-01-03 15:39:11 +01:00
return 0;
}
/* --------------------------------------------------------------------- */