+ alpha tool

This commit is contained in:
tth 2022-06-28 22:28:05 +02:00
parent 81611a3491
commit 00c6e55e6a
6 changed files with 272 additions and 3 deletions

View File

@ -14,6 +14,9 @@ all: foo testtga
7seg.o: 7seg.c $(DEPS) 7seg.o: 7seg.c $(DEPS)
alpha.o: alpha.c $(DEPS)
alpha2.o: alpha2.c $(DEPS)
basic_io.o: basic_io.c $(DEPS) basic_io.o: basic_io.c $(DEPS)
bitblt.o: bitblt.c $(DEPS) bitblt.o: bitblt.c $(DEPS)
bmp.o: bmp.c $(DEPS) bmp.h bmp.o: bmp.c $(DEPS) bmp.h
@ -128,6 +131,7 @@ zoom.o: zoom.c $(DEPS)
#----------------------------------------------------------------- #-----------------------------------------------------------------
OBJECTS = 7seg.o \ OBJECTS = 7seg.o \
alpha.o alpha2.o \
basic_io.o bitblt.o bmp.o \ basic_io.o bitblt.o bmp.o \
cadres2.o cadres3.o cadres4.o cadres84.o cadresbox.o \ cadres2.o cadres3.o cadres4.o cadres84.o cadresbox.o \
cadres.o \ cadres.o \

129
Lib/alpha2.c Normal file
View File

@ -0,0 +1,129 @@
/*
alpha2.c
--------
Various transparency operations, aka "alpha channel ops"
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "tthimage.h"
/*::------------------------------------------------------------------::*/
int Image_alpha_setvalue(Image_Desc *dst, int v_alpha)
{
int y;
#if DEBUG_LEVEL
fprintf(stderr, "%s : %d -> %p\n", __func__, v_alpha, dst);
#endif
if (dst->type != IMAGE_RGBA)
{
fprintf(stderr, "%s : picz %p haz no alpha\n", __func__, dst);
#if MUST_ABORT
abort();
#endif
return NO_ALPHA_CHANNEL;
}
for (y=0; y<dst->height; y++)
{
memset(dst->Apix[y], v_alpha, dst->width);
}
dst->modified = 1;
return OLL_KORRECT;
}
/*::------------------------------------------------------------------::*/
/*
* values of r,g,b pixels are scaled by alpha value.
*/
int
Image_alpha_reduce(Image_Desc *src, Image_Desc *dst, int yo)
{
int foo, x, y;
int r, g, b, a;
#if DEBUG_LEVEL
fprintf(stderr, "Image: alpha reduce: %p -> %p (yo=%d)\n", src, dst, yo);
#endif
if (src->type != IMAGE_RGBA)
{
fprintf(stderr, "Image: alpha reduce: %p is not RGBA", src);
return NO_ALPHA_CHANNEL;
}
if ( (foo=Image_compare_desc(src, dst)) )
{
fprintf(stderr, "Image: alpha reduce: images are differents %d\n", foo);
return foo;
}
for (y=0; y<src->height; y++)
{
for (x=0; x<src->width; x++)
{
Image_getRGBA(src, x, y, &r, &g, &b, &a);
r = (r * a) / 256;
g = (g * a) / 256;
b = (b * a) / 256;
Image_plotRGB(dst, x, y, r, g, b);
}
}
dst->modified = 1;
return FUNC_IS_BETA;
}
/*::------------------------------------------------------------------::*/
/*
* this fonction need more explanations :(
*/
int
Image_poke_alpha_from_rgb(Image_Desc *src, Image_Desc *dst,
int fr, int fg, int fb, int flag)
{
int foo, x, y, r, g, b, a0, a1, a;
a = 0; /* warning shutdown */
if ( (foo=Image_compare_desc(src, dst)) )
{
fprintf(stderr, "Poke alpha from rgb: images are differents %d\n", foo);
return foo;
}
if ( dst->Apix == NULL )
{
fprintf(stderr, "poke alpha from rgb: dest image have NO alpha channel\n");
return NO_ALPHA_CHANNEL;
}
a0 = flag ? 0 : 255;
a1 = flag ? 255 : 0;
#if DEBUG_LEVEL
fprintf(stderr, "For rgb = %d,%d,%d alpha wil be %d\n", fr, fg, fb, a);
#endif
for (y=0; y<src->height; y++)
{
for (x=0; x<src->width; x++)
{
Image_getRGB(src, x, y, &r, &g, &b);
if (r==fr && g==fg && b==fb) a = a0;
else a = a1;
Image_plotRGBA(dst, x, y, r, g, b, a);
}
}
dst->modified = 1;
return FUNC_NOT_FINISH;
}
/*::------------------------------------------------------------------::*/

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_combine tga_export tga_alpha \
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
@ -28,6 +28,9 @@ genplot2: genplot2.c $(DEPS) fonctions.o
#----------------------------------------------------------------- #-----------------------------------------------------------------
tga_alpha: tga_alpha.c $(DEPS) fonctions.o
gcc $(CFLAGS) $< ../libtthimage.a fonctions.o -lm -o $@
tga_applymap: tga_applymap.c $(DEPS) fonctions.o tga_applymap: tga_applymap.c $(DEPS) fonctions.o
gcc $(CFLAGS) $< ../libtthimage.a fonctions.o -lm -o $@ gcc $(CFLAGS) $< ../libtthimage.a fonctions.o -lm -o $@

133
Tools/tga_alpha.c Normal file
View File

@ -0,0 +1,133 @@
/*
=I =I
=I=I=I =I =I=I=I =I=I=I =I=I=I =I=I =I=I=I =I=I=I
=I =I =I =I =I =I =I =I =I =I =I =I =I =I=I
=I =I =I =I =I =I =I =I =I =I =I =I =I =I=I
=I=I=I =I =I=I=I =I =I =I=I=I =I=I =I=I=I =I=I=I
=I =I
=I =I
*/
#include <stdio.h>
#include <stdlib.h>
#include "tga_outils.h"
/*::------------------------------------------------------------------::*/
#define ALPHA_ADD 1
#define ALPHA_REDUCE 2
#define ALPHA_KILL 3
#define ALPHA_SETV 4
mot_clef mots_clef[] =
{
{ "add", ALPHA_ADD, "i", "value of alpha channel" },
{ "reduce", ALPHA_REDUCE, "i", "param = ?, put zero..." },
{ "kill", ALPHA_KILL, "", "kill the alpha channel" },
{ "setv", ALPHA_SETV, "i", "set alpha channel to param" },
{ NULL, 0, NULL, NULL }
};
/*::------------------------------------------------------------------::*/
void usage(int flag)
{
fprintf(stderr, "* tga_alpha v 0.0.10 [%s] %s\n",
TGA_OUTILS_VERSION, TGA_OUTILS_COPYLEFT);
Image_print_version(0);
fprintf(stderr, "Usage:\n tga_alpha src op dst\n");
if (flag)
{
liste_mots_clefs(mots_clef, 0);
}
exit(5);
}
/*::------------------------------------------------------------------::*/
/*
* argv[1] = source image
* argv[2] = operation
* argv[3] = destination image
*/
#define FIRST_PARAM 4
int main(int argc, char *argv[])
{
Image_Desc *src, *dst;
int foo;
RGB_map map;
int idx, commande, nbargs;
dump_command_line(argc, argv, 0);
if (argc<3) usage(1);
/* search operation keyword in table */
idx = cherche_mot_clef(argv[2], mots_clef, &commande, &nbargs);
if (idx < 0)
{
fprintf(stderr, "tga_filtres: mot-clef %s inconnu...\n", argv[2]);
exit (5);
}
foo = parse_parametres(argc, argv, mots_clef[idx].ptypes, FIRST_PARAM);
#if DEBUG_LEVEL
fprintf(stderr, "tga_alpha: parse params : %d\n", foo);
#endif
if ( (src=Image_TGA_alloc_load(argv[1])) == NULL )
{
fprintf(stderr, "tga_alpha: can't load '%s'\n", argv[1]);
exit(1);
}
if ( (dst=Image_clone(src, 0)) == NULL )
{
fprintf(stderr, "tga_alpha: can't clone %p\n", src);
exit(1);
}
switch (commande)
{
case ALPHA_ADD:
Image_copy(src, dst);
foo = GIP(0);
fprintf(stderr, "valeur canal alpha %d\n", foo);
Image_add_alpha_channel(dst, foo);
break;
case ALPHA_REDUCE:
fprintf(stderr, "'%s' not implemented.\n", argv[2]);
exit(1);
break;
case ALPHA_KILL:
Image_copy(src, dst);
fprintf(stderr, "jette le canal alpha\n");
Image_kill_alpha_channel(dst);
break;
case ALPHA_SETV:
Image_copy(src, dst);
foo = Image_alpha_setvalue(dst, GIP(0));
break;
default:
fprintf(stderr, "FUNCTION NOT IMPLEMENTED\n");
break;
}
if (foo)
{
fprintf(stderr, "alpha op -> %d\n", foo);
}
foo = Image_TGA_save(argv[3], dst, 0);
return 1;
}
/*::------------------------------------------------------------------::*/

View File

@ -10,7 +10,7 @@ install -m 0644 tthimage.h $DESTDIR/include/tthimage.h
liste="genplot2 tga_cadre tga_effects tga_filtres tga_remap tga_tools \ liste="genplot2 tga_cadre tga_effects tga_filtres tga_remap tga_tools \
tga_combine tga_television tga_dither tga_applymap tga_makehf15 \ tga_combine tga_television tga_dither tga_applymap tga_makehf15 \
tga_mires tga_incrust tga_pattern tga_equalize" tga_mires tga_incrust tga_pattern tga_equalize tga_alpha"
for binaire in $liste for binaire in $liste
do do

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.50" #define IMAGE_VERSION_STRING "0.4.51"
/*::------------------------------------------------------------------::*/ /*::------------------------------------------------------------------::*/
/* /*