add a gradient generator

This commit is contained in:
tTh
2023-09-18 08:46:13 +02:00
parent 42fafdc570
commit 907f538cff
5 changed files with 108 additions and 17 deletions

View File

@@ -67,6 +67,7 @@ filtres.o: filtres.c $(DEPS)
gadgrect.o: gadgrect.c $(DEPS)
glitch.o: glitch.c $(DEPS)
gradient.o: gradient.c $(DEPS)
halfsize.o: halfsize.c $(DEPS)
@@ -153,7 +154,7 @@ OBJECTS = 7seg.o \
doublesz.o drawalpha.o drawing.o drawpatt.o \
effects.o effects2.o effects3.o extractbits.o \
filtadapt.o filtres.o \
gadgrect.o glitch.o \
gadgrect.o glitch.o gradient.o \
halfsize.o \
image.o imprime.o \
luts15bits.o \

View File

@@ -17,17 +17,15 @@ return 0;
}
/* ============================== */
void mk_lut(unsigned char lut[])
{
int idx, uc;
float fidx;
for (idx=0; idx<256; idx++) {
fidx = (float)idx / 255.0;
uc = (unsigned char)(255.0*(0.5 - 0.5 * cos(3.141592654*fidx)));
lut[idx] = uc;
printf("%7d %7d\n", idx, uc);
}
void essai_gradients(void)
{
int foo;
foo = Image_plot_H_gradient("foo.tga", 640, 200);
fprintf(stderr, "plot h gradient -> %d\n", foo);
foo = Image_plot_V_gradient("foo.tga", 900, 200);
fprintf(stderr, "plot v gradient -> %d\n", foo);
}
/* ============================== */
int essai_draw_paint_rect(char *outga)
@@ -77,9 +75,8 @@ return OLL_KORRECT;
int main(int argc, char *argv[])
{
int foo;
unsigned char Lut[256];
mk_lut(Lut);
essai_gradients();
#if 0
Image_print_version(2);

60
Lib/gradient.c Normal file
View File

@@ -0,0 +1,60 @@
/*
gradient.c
----------
new: Sun Sep 17 20:47:57 UTC 2023
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include "../tthimage.h"
/*::------------------------------------------------------------------::*/
int Image_plot_H_gradient(char *fname, int w, int h)
{
Image_Desc *img;
int x, y, pix, foo;
float fval;
if ( (img = Image_alloc(w, h, IMAGE_RGB)) == NULL ) {
#if DEBUG_LEVEL
fprintf(stderr, "%s: alloc of img failed, file=%s\n", __func__, fname);
#endif
return IMAGE_NO_MEM;
}
for (x=0; x<w; x++) {
fval = (float)x / (float)(w-1);
pix = (int)(fval * 255.0);
#if DEBUG_LEVEL > 1
printf("%5d %6.3f %5d\n", x, fval, pix);
#endif
for (y=0; y<h; y++) {
(img->Rpix[y])[x] = pix;
(img->Gpix[y])[x] = pix;
(img->Bpix[y])[x] = pix;
}
}
foo = Image_TGA_save(fname, img, 0);
if (foo) {
fprintf(stderr, "%s: err write to '%s'\n", __func__, fname);
return FULL_NUCKED;
}
Image_DeAllocate(img); free(img);
return FUNC_IS_BETA;
}
/*::------------------------------------------------------------------::*/
int Image_plot_V_gradient(char *fname, int w, int h)
{
return FUNC_IS_ALPHA;
}
/*::------------------------------------------------------------------::*/