Compare commits

..

No commits in common. "e5ecb0eb139bfa108c9bc14fbed00061d6ebe162" and "2e0809b69184cee98a50c5af2b0d5620203a36c1" have entirely different histories.

4 changed files with 119 additions and 73 deletions

View File

@ -487,9 +487,7 @@ for (y=0; y<im->height; y++)
} }
for (x=0; x<nv; x++) for (x=0; x<nv; x++)
{ {
(im->Rpix[y])[im->width-x] = r; Image_plotRGB(im, x+im->width - nv, y, r, g, b);
(im->Gpix[y])[im->width-x] = g;
(im->Bpix[y])[im->width-x] = b;
} }
} }

View File

@ -20,7 +20,8 @@
echange de deux composantes d'une image RGB echange de deux composantes d'une image RGB
what about swapping with the alpha channel ? what about swapping with the alpha channel ?
*/ */
int Image_swap_colors(Image_Desc *im, char *cols) int
Image_swap_colors(Image_Desc *im, char *cols)
{ {
uint8_t *buffer; uint8_t *buffer;
int y, code; int y, code;
@ -29,13 +30,15 @@ int y, code;
fprintf(stderr, "Echange de couleurs: [%s] %p\n", cols, im); fprintf(stderr, "Echange de couleurs: [%s] %p\n", cols, im);
#endif #endif
if (strlen(cols) != 2) { if (strlen(cols) != 2)
fprintf(stderr, "%s: bad control string: '%s'\n", __func__, cols); {
fprintf(stderr, "SwapColors: bad control string: '%s'\n", cols);
return INVALID_PARAM; return INVALID_PARAM;
} }
code = 0; code = 0;
switch (cols[0]) { switch (cols[0])
{
case 'r': case 'R': code |= 0x10; break; case 'r': case 'R': code |= 0x10; break;
case 'g': case 'G': code |= 0x20; break; case 'g': case 'G': code |= 0x20; break;
case 'b': case 'B': code |= 0x30; break; case 'b': case 'B': code |= 0x30; break;
@ -43,7 +46,8 @@ switch (cols[0]) {
fprintf(stderr, "SwapColors: bad first color '%c'\n", cols[0]); fprintf(stderr, "SwapColors: bad first color '%c'\n", cols[0]);
return INVALID_PARAM; return INVALID_PARAM;
} }
switch (cols[1]) { switch (cols[1])
{
case 'r': case 'R': code |= 0x1; break; case 'r': case 'R': code |= 0x1; break;
case 'g': case 'G': code |= 0x2; break; case 'g': case 'G': code |= 0x2; break;
case 'b': case 'B': code |= 0x3; break; case 'b': case 'B': code |= 0x3; break;
@ -52,17 +56,20 @@ switch (cols[1]) {
return INVALID_PARAM; return INVALID_PARAM;
} }
if ( (buffer=(uint8_t *)alloca(im->width)) == NULL ) { if ( (buffer=(uint8_t *)alloca(im->width)) == NULL )
fprintf(stderr, "%s: no mem for buffer\n", __func__); {
fprintf(stderr, "SwapColors: no mem for buffer\n");
return BUFFER_NO_MEM; return BUFFER_NO_MEM;
} }
#if DEBUG_LEVEL #if DEBUG_LEVEL
fprintf(stderr, "%s: code is %02x, buffer at %p\n", __func__, code, buffer); fprintf(stderr, "SwapColors: code is %02x, buffer at %p\n", code, buffer);
#endif #endif
for (y=0; y<im->height; y++) { for (y=0; y<im->height; y++)
switch (code) { {
switch (code)
{
case 0x12: case 0x21: case 0x12: case 0x21:
memcpy(buffer, im->Rpix[y], im->width); memcpy(buffer, im->Rpix[y], im->width);
memcpy(im->Rpix[y], im->Gpix[y], im->width); memcpy(im->Rpix[y], im->Gpix[y], im->width);
@ -79,7 +86,7 @@ for (y=0; y<im->height; y++) {
memcpy(im->Gpix[y], buffer, im->width); memcpy(im->Gpix[y], buffer, im->width);
break; break;
default: default:
fprintf(stderr, "%s: code=%02x, Aie.\n", __func__, code); fprintf(stderr, "SwapColors: code=%02x, Aie.\n", code);
exit(1); exit(1);
} }
} }
@ -94,7 +101,8 @@ return OLL_KORRECT;
fonction de deux parametre [0..1], mais c,a marche fonction de deux parametre [0..1], mais c,a marche
pas terrible, alors je vais faire encore des essais pas terrible, alors je vais faire encore des essais
*/ */
int Image_color_x(double v1, double v2, int *pr, int *pg, int *pb) int
Image_color_x(double v1, double v2, int *pr, int *pg, int *pb)
{ {
double s, c; double s, c;
@ -114,7 +122,8 @@ return OLL_KORRECT;
* Il doit exister quelque part la meme fonction pour ce * Il doit exister quelque part la meme fonction pour ce
* calcul sur une zone rectangulaire d'une image. * calcul sur une zone rectangulaire d'une image.
*/ */
int Image_couleur_moyenne(Image_Desc *im, int *pr, int *pg, int *pb) int
Image_couleur_moyenne(Image_Desc *im, int *pr, int *pg, int *pb)
{ {
int x, y; int x, y;
long sr, sg, sb, surface; long sr, sg, sb, surface;
@ -144,19 +153,21 @@ return OLL_KORRECT;
/* /*
* nouveau 28 juillet 2008 - avenue St Exupery * nouveau 28 juillet 2008 - avenue St Exupery
*/ */
int Image_saturate(Image_Desc *src, Image_Desc *dst, int sr, int sg, int sb) int
Image_saturate(Image_Desc *src, Image_Desc *dst, int sr, int sg, int sb)
{ {
int x, y, r, g, b; int x, y, r, g, b;
int foo; int foo;
int minmax[6]; int minmax[6];
#if DEBUG_LEVEL #if DEBUG_LEVEL
fprintf(stderr, ">>> %s ( %p %p %d %d %d )", __func__, src, dst, fprintf(stderr, "%s : %p -> %p\n", __func__, src, dst);
sr, sg, sb); fprintf(stderr, " r=%d g=%d b=%d\n", sr, sb, sg);
#endif #endif
if ( (foo=Image_compare_desc(src, dst)) ) { if ( (foo=Image_compare_desc(src, dst)) )
fprintf(stderr, "%s: images are differents %d\n", __func__, foo); {
fprintf(stderr, "Image saturate: images are differents %d\n", foo);
return foo; return foo;
} }
@ -165,13 +176,15 @@ foo = Image_minmax_RGB(src, minmax); /* pourquoi faire ce truc ici ? */
fprintf(stderr, " calcul minmax -> %d\n", foo); fprintf(stderr, " calcul minmax -> %d\n", foo);
#endif #endif
for (y=0; y<src->height; y++) { for (y=0; y<src->height; y++)
{
for (x=0; x<src->width; x++) for (x=0; x<src->width; x++)
{ {
/* et il faut faire quoi, exactement ? */ /* et il faut faire quoi, exactement ? */
r = src->Rpix[y][x]; r = src->Rpix[y][x];
g = src->Rpix[y][x]; g = src->Rpix[y][x];
b = src->Rpix[y][x]; b = src->Rpix[y][x];
/* je n'en ai pas la moindre ideee LOL */ /* je n'en ai pas la moindre ideee LOL */
} }
} }
@ -182,23 +195,27 @@ return FUNC_IS_ALPHA;
/* /*
* nouveau 12 mars 2009 - avenue St Exupery, avec du "Gros plant nantais" * nouveau 12 mars 2009 - avenue St Exupery, avec du "Gros plant nantais"
*/ */
int Image_desaturate(Image_Desc *src, Image_Desc *dst, int sr, int sg, int sb) int
Image_desaturate(Image_Desc *src, Image_Desc *dst, int sr, int sg, int sb)
{ {
int x, y, r, g, b; int x, y, r, g, b;
int foo; int foo;
#if DEBUG_LEVEL #if DEBUG_LEVEL
fprintf(stderr, ">>> %s ( %p %p %d %d %d )", __func__, src, dst, fprintf(stderr, "%s : %p -> %p : ", __func__, src, dst);
sr, sg, sb); fprintf(stderr, " %d %d %d\n", sr, sg, sb);
#endif #endif
if ( (foo=Image_compare_desc(src, dst)) ) { if ( (foo=Image_compare_desc(src, dst)) )
fprintf(stderr, "%s: images are differents %d\n", __func__, foo); {
fprintf(stderr, "Image desaturate: images are differents %d\n", foo);
return foo; return foo;
} }
for (y=0; y<src->height; y++) { for (y=0; y<src->height; y++)
for (x=0; x<src->width; x++) { {
for (x=0; x<src->width; x++)
{
r = src->Rpix[y][x]; r = src->Rpix[y][x];
g = src->Gpix[y][x]; g = src->Gpix[y][x];
b = src->Bpix[y][x]; b = src->Bpix[y][x];
@ -250,8 +267,9 @@ int Image_color_shift_rgb(Image_Desc *s, Image_Desc *d, int rs, int gs, int bs)
int x, y, r, g, b; int x, y, r, g, b;
int foo; int foo;
if ( (foo=Image_compare_desc(s, d)) ) { if ( (foo=Image_compare_desc(s, d)) )
fprintf(stderr, "%s: src & dst are differents (%d)\n", __func__, foo); {
fprintf(stderr, "Shift RGB: src & dst are differents (%d)\n", foo);
return foo; return foo;
} }
@ -259,8 +277,10 @@ if ( (foo=Image_compare_desc(s, d)) ) {
fprintf(stderr, "Shift RGB: %d %d %d\n", rs, gs, bs); fprintf(stderr, "Shift RGB: %d %d %d\n", rs, gs, bs);
#endif #endif
for (y=0; y<s->height; y++) { for (y=0; y<s->height; y++)
for (x=0; x<s->width; x++) { {
for (x=0; x<s->width; x++)
{
r = (s->Rpix[y][x] + rs) % 256; r = (s->Rpix[y][x] + rs) % 256;
g = (s->Gpix[y][x] + gs) % 256; g = (s->Gpix[y][x] + gs) % 256;
b = (s->Bpix[y][x] + bs) % 256; b = (s->Bpix[y][x] + bs) % 256;
@ -283,7 +303,8 @@ return FUNC_IS_ALPHA;
* 16 Dec 2001: not fully tested, may be bogus :-( * 16 Dec 2001: not fully tested, may be bogus :-(
*/ */
int Image_colors_recenter_0(Image_Desc *s, Image_Desc *d) int
Image_colors_recenter_0(Image_Desc *s, Image_Desc *d)
{ {
int x, y, r, g, b; int x, y, r, g, b;
int or, og, ob; int or, og, ob;
@ -292,8 +313,10 @@ double cr, cg, cb, surface;
fprintf(stderr, "Image_colors_recenter_0 is a work in progress... ymmv.\n"); fprintf(stderr, "Image_colors_recenter_0 is a work in progress... ymmv.\n");
cr = cg = cb = 0.0; cr = cg = cb = 0.0;
for (y=0; y<s->height; y++) { for (y=0; y<s->height; y++)
for (x=0; x<s->width; x++) { {
for (x=0; x<s->width; x++)
{
Image_getRGB(s, x, y, &r, &g, &b); Image_getRGB(s, x, y, &r, &g, &b);
cr += (double)r; cr += (double)r;
cg += (double)g; cg += (double)g;
@ -312,8 +335,10 @@ og -= 127;
ob -= 127; ob -= 127;
fprintf(stderr, "colors recenter 0: %d %d %d\n", or, og, ob); fprintf(stderr, "colors recenter 0: %d %d %d\n", or, og, ob);
for (y=0; y<s->height; y++) { for (y=0; y<s->height; y++)
for (x=0; x<s->width; x++) { {
for (x=0; x<s->width; x++)
{
Image_getRGB(s, x, y, &r, &g, &b); Image_getRGB(s, x, y, &r, &g, &b);
r = Image_clamp_pixel(r + or); r = Image_clamp_pixel(r + or);
g = Image_clamp_pixel(g + og); g = Image_clamp_pixel(g + og);
@ -340,7 +365,8 @@ long mindist, pos, dist;
if ( (foo=Image_compare_desc(s, d)) ) return foo; if ( (foo=Image_compare_desc(s, d)) ) return foo;
if ( map->nbre == 0 ) { if ( map->nbre == 0 )
{
fprintf(stderr, "%s: empty map at %p\n", __func__, map); fprintf(stderr, "%s: empty map at %p\n", __func__, map);
/* /*
* WTF ? we have an empty map ?!? * * WTF ? we have an empty map ?!? *
@ -354,15 +380,19 @@ fprintf(stderr, "Colors 2 Map: %d couleurs dans la map\n", map->nbre);
pos = 0; /* XXX verifier a quoi c,a sert ?! */ pos = 0; /* XXX verifier a quoi c,a sert ?! */
for (y=0; y<s->height; y++) { for (y=0; y<s->height; y++)
for (x=0; x<s->width; x++) { {
for (x=0; x<s->width; x++)
{
mindist = 99999999; mindist = 99999999;
sr = s->Rpix[y][x]; sr = s->Rpix[y][x];
sg = s->Gpix[y][x]; sg = s->Gpix[y][x];
sb = s->Bpix[y][x]; sb = s->Bpix[y][x];
for (m=0; m<map->nbre; m++) { for (m=0; m<map->nbre; m++)
switch (mode) { {
switch (mode)
{
case 0: case 0:
dist = CUB(sr-map->red[m]) + dist = CUB(sr-map->red[m]) +
CUB(sg-map->green[m]) + CUB(sg-map->green[m]) +
@ -403,7 +433,8 @@ for (y=0; y<s->height; y++) {
return INVALID_PARAM; return INVALID_PARAM;
} }
if (dist < mindist) { if (dist < mindist)
{
pos = m; mindist = dist; pos = m; mindist = dist;
} }
} }
@ -430,7 +461,8 @@ return OLL_KORRECT;
#define B_COEF 114 #define B_COEF 114
#define RGB_DIV (R_COEF+G_COEF+B_COEF) #define RGB_DIV (R_COEF+G_COEF+B_COEF)
int Image_to_gray_k(Image_Desc *s, Image_Desc *d, int kr, int kg, int kb, int flag) int
Image_to_gray_k(Image_Desc *s, Image_Desc *d, int kr, int kg, int kb, int flag)
{ {
int x, y, r, g, b, v, foo; int x, y, r, g, b, v, foo;
int grey, diviseur; int grey, diviseur;
@ -440,7 +472,8 @@ int vmax;
fprintf(stderr, "converting image %p to gray in %p, flag %d\n", s, d, flag); fprintf(stderr, "converting image %p to gray in %p, flag %d\n", s, d, flag);
#endif #endif
if ( (foo=Image_compare_desc(s, d)) ) { if ( (foo=Image_compare_desc(s, d)) )
{
fprintf(stderr, "To Gray: src & dst are differents (%d)\n", foo); fprintf(stderr, "To Gray: src & dst are differents (%d)\n", foo);
return foo; return foo;
} }
@ -463,11 +496,14 @@ if (diviseur==0) {
} }
vmax = 0; vmax = 0;
for (y=0; y<s->height; y++) { for (y=0; y<s->height; y++)
for (x=0; x<s->width; x++) { {
for (x=0; x<s->width; x++)
{
r = s->Rpix[y][x]; r = s->Rpix[y][x];
g = s->Gpix[y][x]; g = s->Gpix[y][x];
b = s->Bpix[y][x]; b = s->Bpix[y][x];
grey = (r * kr) + (g * kg) + (b * kb); grey = (r * kr) + (g * kg) + (b * kb);
v = grey / diviseur; v = grey / diviseur;
@ -489,7 +525,8 @@ d->modified = 1;
return OLL_KORRECT; return OLL_KORRECT;
} }
/*::------------------------------------------------------------------::*/ /*::------------------------------------------------------------------::*/
int Image_to_gray(Image_Desc *s, Image_Desc *d, int flag) int
Image_to_gray(Image_Desc *s, Image_Desc *d, int flag)
{ {
int foo; int foo;
@ -510,25 +547,30 @@ return foo;
* et on fait quoi si il y a pas assez de couleurs dans la MAP ? * et on fait quoi si il y a pas assez de couleurs dans la MAP ?
* ben, on patche ? * ben, on patche ?
*/ */
int Image_apply_Map(Image_Desc *src, Image_Desc *dst, RGB_map *map) int
Image_apply_Map(Image_Desc *src, Image_Desc *dst, RGB_map *map)
{ {
int x, y, r, g, b; int x, y, r, g, b;
#if DEBUG_LEVEL #if DEBUG_LEVEL
fprintf(stderr, ">>> %s ( %p %p %p )\n", __func__, src, dst, map); fprintf(stderr, "%s ( %p %p %p )\n", __func__, src, dst, map);
#endif #endif
if (map->nbre == 0) { if (map->nbre == 0)
fprintf(stderr, "%s: no colors in palette ?\n", __func__); {
fprintf(stderr, "%s : no colors in palette ?\n", __func__);
return EMPTY_COL_MAP; return EMPTY_COL_MAP;
} }
if (map->nbre < 255) { if (map->nbre < 255)
fprintf(stderr, "%s: only %d cols in palette\n", __func__, map->nbre); {
fprintf(stderr, "%s : only %d cols in palette\n", __func__, map->nbre);
} }
for (y=0; y<src->height; y++) { for (y=0; y<src->height; y++)
for (x=0; x<src->width; x++) { {
for (x=0; x<src->width; x++)
{
r = (src->Rpix[y])[x]; r = (src->Rpix[y])[x];
g = (src->Gpix[y])[x]; g = (src->Gpix[y])[x];
b = (src->Bpix[y])[x]; b = (src->Bpix[y])[x];
@ -549,26 +591,32 @@ return OLL_KORRECT;
/*::------------------------------------------------------------------::*/ /*::------------------------------------------------------------------::*/
/* 8 May 2001 /* 8 May 2001
et on fait quoi si il y a pas assez de couleurs dans la MAP ? */ et on fait quoi si il y a pas assez de couleurs dans la MAP ? */
int Image_gray_Map(Image_Desc *src, Image_Desc *dst, RGB_map *map) int
Image_gray_Map(Image_Desc *src, Image_Desc *dst, RGB_map *map)
{ {
int x, y, r, g, b, gray; int x, y, r, g, b, gray;
if (map->nbre == 0) { if (map->nbre == 0)
fprintf(stderr, "%s: no colors in palette ?\n", __func__); {
fprintf(stderr, "%s : no colors in palette ?\n", __func__);
return VERY_STRANGE; return VERY_STRANGE;
} }
if (map->nbre < 255) { if (map->nbre < 255)
fprintf(stderr, "%s: only %d cols in palette\n", __func__, map->nbre); {
fprintf(stderr, "%s : only %d cols in palette\n", __func__, map->nbre);
} }
for (y=0; y<src->height; y++) { for (y=0; y<src->height; y++)
for (x=0; x<src->width; x++) { {
for (x=0; x<src->width; x++)
{
r = (src->Rpix[y])[x]; r = (src->Rpix[y])[x];
g = (src->Gpix[y])[x]; g = (src->Gpix[y])[x];
b = (src->Bpix[y])[x]; b = (src->Bpix[y])[x];
gray = ((r * R_COEF) + (g * G_COEF) + (b * B_COEF)) / RGB_DIV; gray = ((r * R_COEF) + (g * G_COEF) + (b * B_COEF)) / RGB_DIV;
if (gray<0 || gray>255) { if (gray<0 || gray>255)
{
fprintf(stderr, "%s: GRAY---- %d\n", __func__, gray); fprintf(stderr, "%s: GRAY---- %d\n", __func__, gray);
exit(5); exit(5);
} }
@ -593,7 +641,7 @@ char *cptr, sep[] = " \t,";
int idx; int idx;
#if DEBUG_LEVEL #if DEBUG_LEVEL
fprintf(stderr, ">>> %s ( %p %p )\n", __func__, str, ints); fprintf(stderr, "%s ( %p %p )\n", __func__, str, ints);
#endif #endif
idx = 0; idx = 0;
@ -618,7 +666,7 @@ int foo;
int values[4]; int values[4];
#if DEBUG_LEVEL #if DEBUG_LEVEL
fprintf(stderr, ">>> %s ( %p '%s' 0x%x )\n", __func__, ptr, texte, flags); fprintf(stderr, "%s ( %p '%s' 0x%x )\n", __func__, ptr, texte, flags);
#endif #endif
if ( NULL != (envptr=getenv(ENV_DEFAULT_RGBA)) ) { if ( NULL != (envptr=getenv(ENV_DEFAULT_RGBA)) ) {
@ -630,7 +678,7 @@ if ( NULL != (envptr=getenv(ENV_DEFAULT_RGBA)) ) {
ptr->r = values[0]; ptr->r = values[0];
ptr->g = values[1]; ptr->g = values[1];
ptr->b = values[2]; ptr->b = values[2];
ptr->a = values[3]; /* wtf ? */ ptr->a = values[3];
} }
else { else {
fprintf(stderr, "no '%s' env var defined\n", ENV_DEFAULT_RGBA); fprintf(stderr, "no '%s' env var defined\n", ENV_DEFAULT_RGBA);

View File

@ -9,9 +9,9 @@ HTML_DIR=$(DESTDIR)/html
#----------------------------------------------------------------- #-----------------------------------------------------------------
# #
# pour le debuging: option -g # pour le debuging: option -g
# pour le profiling: option -pg # pour le profiling: option -pg
# pour tracer plein de trucs: -DDEBUG_LEVEL=1 # pour tracer plein de trucs: -DDEBUG_LEVEL=1
# if IMGCOMMENT, the image comment is written to the TGA file, # if IMGCOMMENT, the image comment is written to the TGA file,
# but this files can't be loaded by Xv... # but this files can't be loaded by Xv...
# pour coredumper dans les situations graves: -DABORT=1 # pour coredumper dans les situations graves: -DABORT=1
@ -22,7 +22,7 @@ HTML_DIR=$(DESTDIR)/html
# use -Wmissing-prototypes ? # use -Wmissing-prototypes ?
LIBIMG_OPT=-DFORCE_ABORT=1 -DDEBUG_LEVEL=0 -DIMGCOMMENT=0 LIBIMG_OPT=-DFORCE_ABORT=1 -DDEBUG_LEVEL=0 -DIMGCOMMENT=0
CC_OPTS=-Wall -W -g -ansi -O3 -fPIC -no-pie CC_OPTS=-Wall -W -g -ansi -O3 -fPIC -no-pie
CC_HACKS=-DNEED_ALLOCA_H CC_HACKS=-DNEED_ALLOCA_H
CFLAGS= $(CC_OPTS) \ CFLAGS= $(CC_OPTS) \
$(LIBIMG_OPT) \ $(LIBIMG_OPT) \

View File

@ -1,6 +1,6 @@
#!/bin/bash #!/bin/bash
set -e # abort on error set -e # obort on error
cd Lib cd Lib
echo "========== in $PWD" echo "========== in $PWD"