cosmetic
This commit is contained in:
parent
e596e11425
commit
e5ecb0eb13
178
Lib/colors.c
178
Lib/colors.c
@ -20,8 +20,7 @@
|
||||
echange de deux composantes d'une image RGB
|
||||
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;
|
||||
int y, code;
|
||||
@ -30,15 +29,13 @@ int y, code;
|
||||
fprintf(stderr, "Echange de couleurs: [%s] %p\n", cols, im);
|
||||
#endif
|
||||
|
||||
if (strlen(cols) != 2)
|
||||
{
|
||||
fprintf(stderr, "SwapColors: bad control string: '%s'\n", cols);
|
||||
if (strlen(cols) != 2) {
|
||||
fprintf(stderr, "%s: bad control string: '%s'\n", __func__, cols);
|
||||
return INVALID_PARAM;
|
||||
}
|
||||
|
||||
code = 0;
|
||||
switch (cols[0])
|
||||
{
|
||||
switch (cols[0]) {
|
||||
case 'r': case 'R': code |= 0x10; break;
|
||||
case 'g': case 'G': code |= 0x20; break;
|
||||
case 'b': case 'B': code |= 0x30; break;
|
||||
@ -46,8 +43,7 @@ switch (cols[0])
|
||||
fprintf(stderr, "SwapColors: bad first color '%c'\n", cols[0]);
|
||||
return INVALID_PARAM;
|
||||
}
|
||||
switch (cols[1])
|
||||
{
|
||||
switch (cols[1]) {
|
||||
case 'r': case 'R': code |= 0x1; break;
|
||||
case 'g': case 'G': code |= 0x2; break;
|
||||
case 'b': case 'B': code |= 0x3; break;
|
||||
@ -56,20 +52,17 @@ switch (cols[1])
|
||||
return INVALID_PARAM;
|
||||
}
|
||||
|
||||
if ( (buffer=(uint8_t *)alloca(im->width)) == NULL )
|
||||
{
|
||||
fprintf(stderr, "SwapColors: no mem for buffer\n");
|
||||
if ( (buffer=(uint8_t *)alloca(im->width)) == NULL ) {
|
||||
fprintf(stderr, "%s: no mem for buffer\n", __func__);
|
||||
return BUFFER_NO_MEM;
|
||||
}
|
||||
|
||||
#if DEBUG_LEVEL
|
||||
fprintf(stderr, "SwapColors: code is %02x, buffer at %p\n", code, buffer);
|
||||
fprintf(stderr, "%s: code is %02x, buffer at %p\n", __func__, code, buffer);
|
||||
#endif
|
||||
|
||||
for (y=0; y<im->height; y++)
|
||||
{
|
||||
switch (code)
|
||||
{
|
||||
for (y=0; y<im->height; y++) {
|
||||
switch (code) {
|
||||
case 0x12: case 0x21:
|
||||
memcpy(buffer, im->Rpix[y], im->width);
|
||||
memcpy(im->Rpix[y], im->Gpix[y], im->width);
|
||||
@ -86,7 +79,7 @@ for (y=0; y<im->height; y++)
|
||||
memcpy(im->Gpix[y], buffer, im->width);
|
||||
break;
|
||||
default:
|
||||
fprintf(stderr, "SwapColors: code=%02x, Aie.\n", code);
|
||||
fprintf(stderr, "%s: code=%02x, Aie.\n", __func__, code);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
@ -101,8 +94,7 @@ return OLL_KORRECT;
|
||||
fonction de deux parametre [0..1], mais c,a marche
|
||||
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;
|
||||
|
||||
@ -122,8 +114,7 @@ return OLL_KORRECT;
|
||||
* Il doit exister quelque part la meme fonction pour ce
|
||||
* 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;
|
||||
long sr, sg, sb, surface;
|
||||
@ -153,21 +144,19 @@ return OLL_KORRECT;
|
||||
/*
|
||||
* 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 foo;
|
||||
int minmax[6];
|
||||
|
||||
#if DEBUG_LEVEL
|
||||
fprintf(stderr, "%s : %p -> %p\n", __func__, src, dst);
|
||||
fprintf(stderr, " r=%d g=%d b=%d\n", sr, sb, sg);
|
||||
fprintf(stderr, ">>> %s ( %p %p %d %d %d )", __func__, src, dst,
|
||||
sr, sg, sb);
|
||||
#endif
|
||||
|
||||
if ( (foo=Image_compare_desc(src, dst)) )
|
||||
{
|
||||
fprintf(stderr, "Image saturate: images are differents %d\n", foo);
|
||||
if ( (foo=Image_compare_desc(src, dst)) ) {
|
||||
fprintf(stderr, "%s: images are differents %d\n", __func__, foo);
|
||||
return foo;
|
||||
}
|
||||
|
||||
@ -176,15 +165,13 @@ foo = Image_minmax_RGB(src, minmax); /* pourquoi faire ce truc ici ? */
|
||||
fprintf(stderr, " calcul minmax -> %d\n", foo);
|
||||
#endif
|
||||
|
||||
for (y=0; y<src->height; y++)
|
||||
{
|
||||
for (y=0; y<src->height; y++) {
|
||||
for (x=0; x<src->width; x++)
|
||||
{
|
||||
/* et il faut faire quoi, exactement ? */
|
||||
r = src->Rpix[y][x];
|
||||
g = src->Rpix[y][x];
|
||||
b = src->Rpix[y][x];
|
||||
|
||||
/* je n'en ai pas la moindre ideee LOL */
|
||||
}
|
||||
}
|
||||
@ -195,27 +182,23 @@ return FUNC_IS_ALPHA;
|
||||
/*
|
||||
* 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 foo;
|
||||
|
||||
#if DEBUG_LEVEL
|
||||
fprintf(stderr, "%s : %p -> %p : ", __func__, src, dst);
|
||||
fprintf(stderr, " %d %d %d\n", sr, sg, sb);
|
||||
fprintf(stderr, ">>> %s ( %p %p %d %d %d )", __func__, src, dst,
|
||||
sr, sg, sb);
|
||||
#endif
|
||||
|
||||
if ( (foo=Image_compare_desc(src, dst)) )
|
||||
{
|
||||
fprintf(stderr, "Image desaturate: images are differents %d\n", foo);
|
||||
if ( (foo=Image_compare_desc(src, dst)) ) {
|
||||
fprintf(stderr, "%s: images are differents %d\n", __func__, foo);
|
||||
return foo;
|
||||
}
|
||||
|
||||
for (y=0; y<src->height; y++)
|
||||
{
|
||||
for (x=0; x<src->width; x++)
|
||||
{
|
||||
for (y=0; y<src->height; y++) {
|
||||
for (x=0; x<src->width; x++) {
|
||||
r = src->Rpix[y][x];
|
||||
g = src->Gpix[y][x];
|
||||
b = src->Bpix[y][x];
|
||||
@ -267,9 +250,8 @@ int Image_color_shift_rgb(Image_Desc *s, Image_Desc *d, int rs, int gs, int bs)
|
||||
int x, y, r, g, b;
|
||||
int foo;
|
||||
|
||||
if ( (foo=Image_compare_desc(s, d)) )
|
||||
{
|
||||
fprintf(stderr, "Shift RGB: src & dst are differents (%d)\n", foo);
|
||||
if ( (foo=Image_compare_desc(s, d)) ) {
|
||||
fprintf(stderr, "%s: src & dst are differents (%d)\n", __func__, foo);
|
||||
return foo;
|
||||
}
|
||||
|
||||
@ -277,10 +259,8 @@ if ( (foo=Image_compare_desc(s, d)) )
|
||||
fprintf(stderr, "Shift RGB: %d %d %d\n", rs, gs, bs);
|
||||
#endif
|
||||
|
||||
for (y=0; y<s->height; y++)
|
||||
{
|
||||
for (x=0; x<s->width; x++)
|
||||
{
|
||||
for (y=0; y<s->height; y++) {
|
||||
for (x=0; x<s->width; x++) {
|
||||
r = (s->Rpix[y][x] + rs) % 256;
|
||||
g = (s->Gpix[y][x] + gs) % 256;
|
||||
b = (s->Bpix[y][x] + bs) % 256;
|
||||
@ -303,8 +283,7 @@ return FUNC_IS_ALPHA;
|
||||
* 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 or, og, ob;
|
||||
@ -313,10 +292,8 @@ double cr, cg, cb, surface;
|
||||
fprintf(stderr, "Image_colors_recenter_0 is a work in progress... ymmv.\n");
|
||||
|
||||
cr = cg = cb = 0.0;
|
||||
for (y=0; y<s->height; y++)
|
||||
{
|
||||
for (x=0; x<s->width; x++)
|
||||
{
|
||||
for (y=0; y<s->height; y++) {
|
||||
for (x=0; x<s->width; x++) {
|
||||
Image_getRGB(s, x, y, &r, &g, &b);
|
||||
cr += (double)r;
|
||||
cg += (double)g;
|
||||
@ -335,10 +312,8 @@ og -= 127;
|
||||
ob -= 127;
|
||||
fprintf(stderr, "colors recenter 0: %d %d %d\n", or, og, ob);
|
||||
|
||||
for (y=0; y<s->height; y++)
|
||||
{
|
||||
for (x=0; x<s->width; x++)
|
||||
{
|
||||
for (y=0; y<s->height; y++) {
|
||||
for (x=0; x<s->width; x++) {
|
||||
Image_getRGB(s, x, y, &r, &g, &b);
|
||||
r = Image_clamp_pixel(r + or);
|
||||
g = Image_clamp_pixel(g + og);
|
||||
@ -365,8 +340,7 @@ long mindist, pos, dist;
|
||||
|
||||
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);
|
||||
/*
|
||||
* WTF ? we have an empty map ?!? *
|
||||
@ -380,19 +354,15 @@ fprintf(stderr, "Colors 2 Map: %d couleurs dans la map\n", map->nbre);
|
||||
|
||||
pos = 0; /* XXX verifier a quoi c,a sert ?! */
|
||||
|
||||
for (y=0; y<s->height; y++)
|
||||
{
|
||||
for (x=0; x<s->width; x++)
|
||||
{
|
||||
for (y=0; y<s->height; y++) {
|
||||
for (x=0; x<s->width; x++) {
|
||||
mindist = 99999999;
|
||||
sr = s->Rpix[y][x];
|
||||
sg = s->Gpix[y][x];
|
||||
sb = s->Bpix[y][x];
|
||||
|
||||
for (m=0; m<map->nbre; m++)
|
||||
{
|
||||
switch (mode)
|
||||
{
|
||||
for (m=0; m<map->nbre; m++) {
|
||||
switch (mode) {
|
||||
case 0:
|
||||
dist = CUB(sr-map->red[m]) +
|
||||
CUB(sg-map->green[m]) +
|
||||
@ -433,8 +403,7 @@ for (y=0; y<s->height; y++)
|
||||
return INVALID_PARAM;
|
||||
}
|
||||
|
||||
if (dist < mindist)
|
||||
{
|
||||
if (dist < mindist) {
|
||||
pos = m; mindist = dist;
|
||||
}
|
||||
}
|
||||
@ -461,8 +430,7 @@ return OLL_KORRECT;
|
||||
#define B_COEF 114
|
||||
#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 grey, diviseur;
|
||||
@ -472,8 +440,7 @@ int vmax;
|
||||
fprintf(stderr, "converting image %p to gray in %p, flag %d\n", s, d, flag);
|
||||
#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);
|
||||
return foo;
|
||||
}
|
||||
@ -496,14 +463,11 @@ if (diviseur==0) {
|
||||
}
|
||||
|
||||
vmax = 0;
|
||||
for (y=0; y<s->height; y++)
|
||||
{
|
||||
for (x=0; x<s->width; x++)
|
||||
{
|
||||
for (y=0; y<s->height; y++) {
|
||||
for (x=0; x<s->width; x++) {
|
||||
r = s->Rpix[y][x];
|
||||
g = s->Gpix[y][x];
|
||||
b = s->Bpix[y][x];
|
||||
|
||||
grey = (r * kr) + (g * kg) + (b * kb);
|
||||
v = grey / diviseur;
|
||||
|
||||
@ -525,8 +489,7 @@ d->modified = 1;
|
||||
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;
|
||||
|
||||
@ -547,30 +510,25 @@ return foo;
|
||||
* et on fait quoi si il y a pas assez de couleurs dans la MAP ?
|
||||
* 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;
|
||||
|
||||
#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
|
||||
|
||||
if (map->nbre == 0)
|
||||
{
|
||||
fprintf(stderr, "%s : no colors in palette ?\n", __func__);
|
||||
if (map->nbre == 0) {
|
||||
fprintf(stderr, "%s: no colors in palette ?\n", __func__);
|
||||
return EMPTY_COL_MAP;
|
||||
}
|
||||
|
||||
if (map->nbre < 255)
|
||||
{
|
||||
fprintf(stderr, "%s : only %d cols in palette\n", __func__, map->nbre);
|
||||
if (map->nbre < 255) {
|
||||
fprintf(stderr, "%s: only %d cols in palette\n", __func__, map->nbre);
|
||||
}
|
||||
|
||||
for (y=0; y<src->height; y++)
|
||||
{
|
||||
for (x=0; x<src->width; x++)
|
||||
{
|
||||
for (y=0; y<src->height; y++) {
|
||||
for (x=0; x<src->width; x++) {
|
||||
r = (src->Rpix[y])[x];
|
||||
g = (src->Gpix[y])[x];
|
||||
b = (src->Bpix[y])[x];
|
||||
@ -591,32 +549,26 @@ return OLL_KORRECT;
|
||||
/*::------------------------------------------------------------------::*/
|
||||
/* 8 May 2001
|
||||
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;
|
||||
|
||||
if (map->nbre == 0)
|
||||
{
|
||||
fprintf(stderr, "%s : no colors in palette ?\n", __func__);
|
||||
if (map->nbre == 0) {
|
||||
fprintf(stderr, "%s: no colors in palette ?\n", __func__);
|
||||
return VERY_STRANGE;
|
||||
}
|
||||
|
||||
if (map->nbre < 255)
|
||||
{
|
||||
fprintf(stderr, "%s : only %d cols in palette\n", __func__, map->nbre);
|
||||
if (map->nbre < 255) {
|
||||
fprintf(stderr, "%s: only %d cols in palette\n", __func__, map->nbre);
|
||||
}
|
||||
|
||||
for (y=0; y<src->height; y++)
|
||||
{
|
||||
for (x=0; x<src->width; x++)
|
||||
{
|
||||
for (y=0; y<src->height; y++) {
|
||||
for (x=0; x<src->width; x++) {
|
||||
r = (src->Rpix[y])[x];
|
||||
g = (src->Gpix[y])[x];
|
||||
b = (src->Bpix[y])[x];
|
||||
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);
|
||||
exit(5);
|
||||
}
|
||||
@ -641,7 +593,7 @@ char *cptr, sep[] = " \t,";
|
||||
int idx;
|
||||
|
||||
#if DEBUG_LEVEL
|
||||
fprintf(stderr, "%s ( %p %p )\n", __func__, str, ints);
|
||||
fprintf(stderr, ">>> %s ( %p %p )\n", __func__, str, ints);
|
||||
#endif
|
||||
|
||||
idx = 0;
|
||||
@ -666,7 +618,7 @@ int foo;
|
||||
int values[4];
|
||||
|
||||
#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
|
||||
|
||||
if ( NULL != (envptr=getenv(ENV_DEFAULT_RGBA)) ) {
|
||||
@ -678,7 +630,7 @@ if ( NULL != (envptr=getenv(ENV_DEFAULT_RGBA)) ) {
|
||||
ptr->r = values[0];
|
||||
ptr->g = values[1];
|
||||
ptr->b = values[2];
|
||||
ptr->a = values[3];
|
||||
ptr->a = values[3]; /* wtf ? */
|
||||
}
|
||||
else {
|
||||
fprintf(stderr, "no '%s' env var defined\n", ENV_DEFAULT_RGBA);
|
||||
|
Loading…
Reference in New Issue
Block a user