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) gadgrect.o: gadgrect.c $(DEPS)
glitch.o: glitch.c $(DEPS) glitch.o: glitch.c $(DEPS)
gradient.o: gradient.c $(DEPS)
halfsize.o: halfsize.c $(DEPS) halfsize.o: halfsize.c $(DEPS)
@ -153,7 +154,7 @@ OBJECTS = 7seg.o \
doublesz.o drawalpha.o drawing.o drawpatt.o \ doublesz.o drawalpha.o drawing.o drawpatt.o \
effects.o effects2.o effects3.o extractbits.o \ effects.o effects2.o effects3.o extractbits.o \
filtadapt.o filtres.o \ filtadapt.o filtres.o \
gadgrect.o glitch.o \ gadgrect.o glitch.o gradient.o \
halfsize.o \ halfsize.o \
image.o imprime.o \ image.o imprime.o \
luts15bits.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++) { void essai_gradients(void)
fidx = (float)idx / 255.0; {
uc = (unsigned char)(255.0*(0.5 - 0.5 * cos(3.141592654*fidx))); int foo;
lut[idx] = uc;
printf("%7d %7d\n", idx, uc); 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) int essai_draw_paint_rect(char *outga)
@ -77,9 +75,8 @@ return OLL_KORRECT;
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
int foo; int foo;
unsigned char Lut[256];
mk_lut(Lut); essai_gradients();
#if 0 #if 0
Image_print_version(2); 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;
}
/*::------------------------------------------------------------------::*/

View File

@ -25,6 +25,8 @@
#define HEADER 33 #define HEADER 33
#define TIMESTAMP 34 #define TIMESTAMP 34
#define PRHISTO 35 #define PRHISTO 35
#define H_GRAD 36
#define V_GRAD 37
#define TAG7SEG0 40 #define TAG7SEG0 40
#define BIZARRE 41 #define BIZARRE 41
#define ENVIRON 50 #define ENVIRON 50
@ -49,6 +51,7 @@ mot_clef commandes[] =
{ "environ", ENVIRON, "", "" }, { "environ", ENVIRON, "", "" },
{ "bizarre", BIZARRE, "", "portnawak..." }, { "bizarre", BIZARRE, "", "portnawak..." },
{ "mk_rgb", MK_RGB, "siiiii", "fname w h r g b" }, { "mk_rgb", MK_RGB, "siiiii", "fname w h r g b" },
{ "mk_hgrad", H_GRAD, "sii", "fname w h" },
{ NULL, 0, NULL, NULL } { NULL, 0, NULL, NULL }
}; };
@ -109,6 +112,24 @@ fprintf(stderr, "%s got %d\n", __func__, foo);
return foo; return foo;
} }
/*::------------------------------------------------------------------::*/ /*::------------------------------------------------------------------::*/
/* new: Mon Sep 18 06:28:51 UTC 2023
this is just a dummy wraper */
int make_a_H_gradient(char *fname, int w, int h)
{
int foo;
#if DEBUG_LEVEL
fprintf(stderr, ">>> %s ( %s %d %d )\n", __func__, fname, w, h);
#endif
foo = Image_plot_H_gradient(fname, w, h);
#if DEBUG_LEVEL
fprintf(stderr, " got a %d\n", foo);
#endif
return foo;
}
/*::------------------------------------------------------------------::*/ /*::------------------------------------------------------------------::*/
int make_a_rgb_tga(char *fname, int w, int h, int r, int g, int b) int make_a_rgb_tga(char *fname, int w, int h, int r, int g, int b)
{ {
@ -304,13 +325,13 @@ dump_command_line(argc, argv, 0);
/* new 4 feb 2014 */ /* new 4 feb 2014 */
foo = set_new_seed(42); foo = set_new_seed(42);
#if DEBUG_LEVEL #if DEBUG_LEVEL > 1
fprintf(stderr, "set new seed -> %d\n", foo); fprintf(stderr, "!!! set new seed -> %d\n", foo);
#endif #endif
if (1 == argc) if (1 == argc)
{ {
fprintf(stderr, "* tga_tools v 0.1.32 (%s) *\n", __DATE__); fprintf(stderr, "* tga_tools v 0.1.33 (%s) *\n", __DATE__);
fprintf(stderr, "usage:\n\t%s action f.tga [params]\n", argv[0]); fprintf(stderr, "usage:\n\t%s action f.tga [params]\n", argv[0]);
liste_mots_clefs(commandes, 42); liste_mots_clefs(commandes, 42);
exit(0); exit(0);
@ -380,6 +401,11 @@ switch(mode)
foo = make_a_rgb_tga(cptr, GIP(1), GIP(2), foo = make_a_rgb_tga(cptr, GIP(1), GIP(2),
GIP(3), GIP(4), GIP(5)); GIP(3), GIP(4), GIP(5));
break; break;
case H_GRAD:
cptr = GSP(0);
fprintf(stderr, "MK_HGRAD -> %s\n", cptr);
foo = make_a_H_gradient(cptr, GIP(1), GIP(2));
break;
case MK_NOISE: case MK_NOISE:
cptr = GSP(0); cptr = GSP(0);
fprintf(stderr, "MK_NOISE -> %s\n", cptr); fprintf(stderr, "MK_NOISE -> %s\n", cptr);

View File

@ -4,7 +4,7 @@
http://la.buvette.org/devel/libimage/ http://la.buvette.org/devel/libimage/
*/ */
#ifndef IMAGE_VERSION_STRING #ifndef IMAGE_VERSION_STRING
#define IMAGE_VERSION_STRING "0.4.51 pl 49" #define IMAGE_VERSION_STRING "0.4.51 pl 50"
/*::------------------------------------------------------------------::*/ /*::------------------------------------------------------------------::*/
/* /*
@ -932,6 +932,13 @@ int Image_texture_1(Image_Desc *dst, int bas, int haut);
int Image_texture_2(Image_Desc *dst, int bas, int haut, int modulo); int Image_texture_2(Image_Desc *dst, int bas, int haut, int modulo);
int Image_texture_3(Image_Desc *dst, int b, int h, char *ctrl, int qux); int Image_texture_3(Image_Desc *dst, int b, int h, char *ctrl, int qux);
/*::------------------------------------------------------------------::*/
/*
* module gradient.c
*/
int Image_plot_H_gradient(char *fname, int w, int h);
int Image_plot_V_gradient(char *fname, int w, int h);
/*::------------------------------------------------------------------::*/ /*::------------------------------------------------------------------::*/
/* /*
module patterns.c module patterns.c