Compare commits

..

4 Commits

Author SHA1 Message Date
tTh
907f538cff add a gradient generator 2023-09-18 08:46:13 +02:00
tTh
42fafdc570 cosmetic 2023-09-18 08:27:49 +02:00
tTh
395b262c92 add "cos01" contrast adjustement 2023-09-17 22:36:08 +02:00
tTh
bef1c6c5e3 add tga_extract 2023-09-12 18:19:12 +02:00
11 changed files with 292 additions and 11 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)
@ -125,7 +126,6 @@ text1.o: text1.c $(DEPS)
text16x24.o: text16x24.c $(DEPS) text16x24.o: text16x24.c $(DEPS)
tga.o: tga.c $(DEPS) tga.o: tga.c $(DEPS)
tools.o: tools.c $(DEPS) tools.o: tools.c $(DEPS)
trigo.o: trigo.c $(DEPS)
turtle.o: turtle.c $(DEPS) turtle.o: turtle.c $(DEPS)
vignetize.o: vignetize.c $(DEPS) vignetize.o: vignetize.c $(DEPS)
@ -154,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 \
@ -174,7 +174,7 @@ OBJECTS = 7seg.o \
scale.o sobel4.o stereo.o \ scale.o sobel4.o stereo.o \
tamppool.o tele_2.o television.o \ tamppool.o tele_2.o television.o \
text0.o text1.o text16x24.o \ text0.o text1.o text16x24.o \
tga.o tools.o trigo.o turtle.o \ tga.o tools.o turtle.o \
vignetize.o \ vignetize.o \
warp0.o warp1.o warp2.o warp3.o \ warp0.o warp1.o warp2.o warp3.o \
zoom.o zoom.o
@ -186,7 +186,7 @@ OBJECTS = 7seg.o \
#----------------------------------------------------------------- #-----------------------------------------------------------------
foo: foo.c $(DEPS) ../libtthimage.a foo: foo.c $(DEPS) ../libtthimage.a
gcc $(CFLAGS) $< ../libtthimage.a -o $@ gcc $(CFLAGS) $< ../libtthimage.a -lm -o $@
t_png: t_png.c $(DEPS) ../libtthimage.a t_png: t_png.c $(DEPS) ../libtthimage.a
gcc $(CFLAGS) $< ../libtthimage.a -lpng -lz -o $@ gcc $(CFLAGS) $< ../libtthimage.a -lpng -lz -o $@

View File

@ -6,6 +6,48 @@
#include <math.h> #include <math.h>
#include "../tthimage.h" #include "../tthimage.h"
/*::------------------------------------------------------------------::*/
/*
* new: Fri Sep 15 20:18:35 UTC 2023
* inspired by the sam func in FloatImg
*/
int Image_egalise_cos01(Image_Desc *source, Image_Desc *but, int k)
{
unsigned char lut[256], uc;
int idx, x, y, pix, foo;
float fidx;
fprintf(stderr, ">>> %s ( %p %p %d )\n", __func__,
source, but, k);
if ( (foo=Image_compare_desc(source, but)) ) {
fprintf(stderr, "%s: images not compatible, %d\n", __func__, foo);
return foo;
}
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); */
}
for (y=0; y<source->height; y++) {
for (x=0; x<source->width; x++) {
pix = source->Rpix[y][x];
but->Rpix[y][x] = lut[pix];
pix = source->Gpix[y][x];
but->Gpix[y][x] = lut[pix];
pix = source->Bpix[y][x];
but->Bpix[y][x] = lut[pix];
}
}
return FULL_NUCKED;
}
/*::------------------------------------------------------------------::*/ /*::------------------------------------------------------------------::*/
/* /*
* cette fonction peut etre utilisee avec la meme image * cette fonction peut etre utilisee avec la meme image
@ -20,6 +62,10 @@ float fr, fg, fb;
fprintf(stderr, "%s : %p -> %p\n", __func__, source, but); fprintf(stderr, "%s : %p -> %p\n", __func__, source, but);
#endif #endif
if (k) {
fprintf(stderr, "In %s, k must be 0, was %d\n", __func__, k);
}
if ( (foo=Image_compare_desc(source, but)) ) { if ( (foo=Image_compare_desc(source, but)) ) {
fprintf(stderr, "%s : images are differents %d\n", __func__, foo); fprintf(stderr, "%s : images are differents %d\n", __func__, foo);
return foo; return foo;
@ -55,6 +101,10 @@ float fr, fg, fb;
fprintf(stderr, "%s : %p -> %p\n", __func__, source, but); fprintf(stderr, "%s : %p -> %p\n", __func__, source, but);
#endif #endif
if (k) {
fprintf(stderr, "In %s, k must be 0, was %d\n", __func__, k);
}
if ( (foo=Image_compare_desc(source, but)) ) { if ( (foo=Image_compare_desc(source, but)) ) {
fprintf(stderr, "%s : images are differents %d\n", __func__, foo); fprintf(stderr, "%s : images are differents %d\n", __func__, foo);
return foo; return foo;

View File

@ -2,6 +2,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <unistd.h> #include <unistd.h>
#include <stdint.h> #include <stdint.h>
#include <math.h>
#include "../tthimage.h" #include "../tthimage.h"
@ -14,6 +15,18 @@ else
Image_t16x24_essai("16x24gruik", "0123456789abcdef", "16x24.tga"); Image_t16x24_essai("16x24gruik", "0123456789abcdef", "16x24.tga");
return 0; return 0;
} }
/* ============================== */
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) int essai_draw_paint_rect(char *outga)
{ {
@ -63,6 +76,9 @@ int main(int argc, char *argv[])
{ {
int foo; int foo;
essai_gradients();
#if 0
Image_print_version(2); Image_print_version(2);
Image_print_sizeof_structs("foo"); Image_print_sizeof_structs("foo");
@ -72,5 +88,8 @@ fprintf(stderr, "essai show t16x24 --> %d\n", foo);
foo = essai_draw_paint_rect("foo.tga"); foo = essai_draw_paint_rect("foo.tga");
fprintf(stderr, "essai draw rect --> %d\n", foo); fprintf(stderr, "essai draw rect --> %d\n", foo);
Image_egalise_cos01(NULL, NULL, 0);
#endif
return 0; return 0;
} }

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;
}
/*::------------------------------------------------------------------::*/

2
Tools/.gitignore vendored
View File

@ -2,3 +2,5 @@
*.tga *.tga
*.scratch *.scratch
tga_extract

View File

@ -10,7 +10,7 @@ DEPS = ../tthimage.h Makefile tga_outils.h ../libtthimage.a
all: genplot2 \ all: genplot2 \
tga_cadre tga_effects tga_filtres tga_remap tga_tools \ tga_cadre tga_effects tga_filtres tga_remap tga_tools \
tga_combine tga_export tga_alpha \ tga_combine tga_export tga_alpha tga_extract \
tga_television tga_dither tga_applymap tga_makehf15 \ tga_television tga_dither tga_applymap tga_makehf15 \
tga_mires tga_incrust tga_pattern tga_equalize tga_mires tga_incrust tga_pattern tga_equalize
@ -73,6 +73,10 @@ tga_tools: tga_tools.c $(DEPS) fonctions.o
tga_incrust: tga_incrust.c $(DEPS) fonctions.o tga_incrust: tga_incrust.c $(DEPS) fonctions.o
gcc $(CFLAGS) $< ../libtthimage.a fonctions.o -lm -o $@ gcc $(CFLAGS) $< ../libtthimage.a fonctions.o -lm -o $@
tga_extract: tga_extract.c $(DEPS) fonctions.o
gcc $(CFLAGS) $< ../libtthimage.a fonctions.o -lm -o $@
# tga_info: tga_info.c $(DEPS) fonctions.o # tga_info: tga_info.c $(DEPS) fonctions.o
# gcc $(CFLAGS) $< ../libimage.a fonctions.o -lm -o $@ # gcc $(CFLAGS) $< ../libimage.a fonctions.o -lm -o $@

View File

@ -446,7 +446,9 @@ int set_new_seed(int k)
char *ptr; char *ptr;
long seed; long seed;
#if DEBUG_MESSAGE
if (k) fprintf(stderr, "%s: k %d\n", __func__, k); if (k) fprintf(stderr, "%s: k %d\n", __func__, k);
#endif
if (NULL==(ptr=getenv("FIXED_SEED"))) { if (NULL==(ptr=getenv("FIXED_SEED"))) {
/* no fixed seed in context, doing semi-random */ /* no fixed seed in context, doing semi-random */

View File

@ -14,6 +14,7 @@
/*::------------------------------------------------------------------::*/ /*::------------------------------------------------------------------::*/
#define EQ_STD 4 #define EQ_STD 4
#define EQ_GRAY 8 #define EQ_GRAY 8
#define EQ_COS01 9
#define EQ_2X2 12 #define EQ_2X2 12
#define EQ_LUMIN 14 #define EQ_LUMIN 14
#define EQ_SQUARE 16 #define EQ_SQUARE 16
@ -26,6 +27,7 @@ mot_clef mots_clef[] =
{ "std", EQ_STD, "", "standard method" }, { "std", EQ_STD, "", "standard method" },
{ "rgb", EQ_STD, "", "same as 'std'" }, { "rgb", EQ_STD, "", "same as 'std'" },
{ "gray", EQ_GRAY, "", "gray based" }, { "gray", EQ_GRAY, "", "gray based" },
{ "cos01", EQ_COS01, "", "cosinus 0->1" },
{ "2x2", EQ_2X2, "", "2x2 matrix" }, { "2x2", EQ_2X2, "", "2x2 matrix" },
{ "lumin", EQ_LUMIN, "i", "param: ident is 256" }, { "lumin", EQ_LUMIN, "i", "param: ident is 256" },
/* { "gamma", EQ_GAMMA, "d", "not implemented" },*/ /* { "gamma", EQ_GAMMA, "d", "not implemented" },*/
@ -38,7 +40,7 @@ mot_clef mots_clef[] =
/*::------------------------------------------------------------------::*/ /*::------------------------------------------------------------------::*/
void usage() void usage()
{ {
fprintf(stderr, "* tga_equalize v 0.0.21 [%s] (dwtfywl) tonton Th\n", fprintf(stderr, "* tga_equalize v 0.0.23 [%s] (dwtfywl) tonton Th\n",
TGA_OUTILS_VERSION); TGA_OUTILS_VERSION);
fprintf(stderr, " compiled %s at %s\n", __DATE__, __TIME__); fprintf(stderr, " compiled %s at %s\n", __DATE__, __TIME__);
fprintf(stderr, "usage:\n\ttga_equalize avant.tga mode apres.tga [params]\n"); fprintf(stderr, "usage:\n\ttga_equalize avant.tga mode apres.tga [params]\n");
@ -106,6 +108,10 @@ switch (commande)
foo = Image_pix_sqroot(src, dst, 0); foo = Image_pix_sqroot(src, dst, 0);
break; break;
case EQ_COS01:
foo = Image_egalise_cos01(src, dst, 0);
break;
case EQ_GAMMA: case EQ_GAMMA:
fprintf(stderr, "no gamma func in %d\n", getpid()); fprintf(stderr, "no gamma func in %d\n", getpid());
foo = FULL_NUCKED; foo = FULL_NUCKED;

103
Tools/tga_extract.c Normal file
View File

@ -0,0 +1,103 @@
/*
TGA EXTRACTOR
-------------
http://www.chez.com/oulala/libimage/
*/
#include <stdio.h>
#include <stdlib.h>
#include "tga_outils.h"
/*::------------------------------------------------------------------::*/
void usage(void)
{
fprintf(stderr, "* TGA extractor v 0.0.12 [%s] %s \n",
TGA_OUTILS_VERSION, TGA_OUTILS_COPYLEFT);
fprintf(stderr, "usage:\n");
fprintf(stderr, " $ tga_extract source.tga resultat.tga X Y W H\n\n");
Image_print_version(0);
fprintf(stderr, "\n");
exit(1);
}
/*::------------------------------------------------------------------::*/
#define X 0
#define Y 1
#define W 2
#define H 3
int main(int argc, char *argv[])
{
Image_Desc *image, *resultat;
int foo, coords[4];
Image_Rect rect;
dump_command_line(argc, argv, 0);
if ( argc != 7 ) {
fprintf(stderr, "argc=%d\n", argc);
usage();
}
/* decode and check parameters */
for (foo=0; foo<4; foo++) {
if ( sscanf(argv[foo+3], "%d", &coords[foo]) != 1 ) {
fprintf(stderr, " '%s' oikk?!\n", argv[foo+3]);
usage();
}
}
if ( (coords[X]<0) || (coords[Y]<0) || (coords[W]<0) || (coords[H]<0) )
{
fprintf(stderr, "%s: no negative parameter, please.\n", argv[0]);
exit(1);
}
if (coords[X]>16000 || coords[Y]>16000 || coords[W]>16000 || coords[H]>16000)
{
fprintf(stderr, "%s: no overburned parameter, please.\n", argv[0]);
exit(1);
}
/* load the source image ... */
if ( (image=Image_TGA_alloc_load(argv[1])) == NULL ) {
fprintf(stderr, "%s: no mem for input image '%s'\n", argv[0], argv[1]);
exit(1);
}
if (must_be_verbose()) {
/* ... so we know source dimensions */
fprintf(stderr, "tga_extract: src '%s': %d x %d\n",
argv[1], image->width, image->height);
}
if ( (resultat=Image_alloc(coords[W], coords[H], 3)) == NULL ) {
fprintf(stderr, "%s: no mem for ouput image\n", argv[0]);
exit(1);
}
rect.x = coords[X]; rect.y = coords[Y];
rect.w = coords[W]; rect.h = coords[H];
foo = Image_get_rect(image, &rect, resultat, 0, 0); if (foo)
{
fprintf(stderr, "tga_extract: get_rect: err %d %s\n",
foo, Image_err2str(foo));
exit(2);
}
if (must_be_verbose()) {
fprintf(stderr, "tga_extract: dst '%s': %dx%d @%d,%d\n",
argv[2], resultat->width, resultat->height,
rect.x, rect.y);
}
foo = Image_TGA_save(argv[2], resultat, 0);
if (foo) {
fprintf(stderr, "tga_extract: %s save err %d %s\n",
argv[2], foo, Image_err2str(foo));
exit(2);
}
return 0;
}
/*::------------------------------------------------------------------::*/

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

@ -1,10 +1,10 @@
/* /*
tthimage.h tthimage.h
---------- ----------
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 43" #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
@ -1192,6 +1199,8 @@ int Image_insert_with_alpha(Image_Desc *img, Image_Desc *ins, int foo);
int Image_pix_square(Image_Desc *source, Image_Desc *but, int k); int Image_pix_square(Image_Desc *source, Image_Desc *but, int k);
int Image_pix_sqroot(Image_Desc *source, Image_Desc *but, int k); int Image_pix_sqroot(Image_Desc *source, Image_Desc *but, int k);
int Image_egalise_cos01(Image_Desc *source, Image_Desc *but, int k);
/*::------------------------------------------------------------------::*/ /*::------------------------------------------------------------------::*/
/* /*
module levels.c new: Jan 2001 module levels.c new: Jan 2001