2022-06-27 09:48:18 +11:00
|
|
|
/*
|
|
|
|
plotteur.c
|
|
|
|
----------
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
#ifdef NEED_ALLOCA_H
|
|
|
|
#include <alloca.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "../tthimage.h"
|
|
|
|
|
2022-10-28 14:07:32 +11:00
|
|
|
#define SOMBRE 26 /* pourquoi ces valeurs sont codees en */
|
2022-06-27 09:48:18 +11:00
|
|
|
#define CLAIR 242 /* dur ? et ~/.tth/libimagerc alors ? */
|
|
|
|
|
|
|
|
/*::------------------------------------------------------------------::*/
|
|
|
|
static void vline(Image_Desc *i, int x, int y1, int y2, char c, int v)
|
|
|
|
{
|
|
|
|
int haut, bas, foo;
|
|
|
|
|
|
|
|
if (y1 > y2) { bas = y2; haut = y1; }
|
|
|
|
else { bas = y1; haut = y2; }
|
|
|
|
|
|
|
|
for (foo=bas; foo<=haut; foo++)
|
|
|
|
Image_plot_channel(i, c, x, foo, v);
|
|
|
|
}
|
|
|
|
/*::------------------------------------------------------------------::*/
|
|
|
|
/* new 20 mars 2002
|
|
|
|
*/
|
2022-10-28 14:07:32 +11:00
|
|
|
int Image_plot_luts(char *nomtga, int *lr, int *lg, int *lb, char *texte)
|
2022-06-27 09:48:18 +11:00
|
|
|
{
|
|
|
|
Image_Desc *img;
|
|
|
|
int foo;
|
|
|
|
RGBA paper, ink;
|
|
|
|
int vr, vg, vb, ovr, ovg, ovb;
|
|
|
|
|
2022-10-28 14:07:32 +11:00
|
|
|
if ( (img = Image_alloc(400, 300, 3)) == NULL ) {
|
2022-06-27 09:48:18 +11:00
|
|
|
#if DEBUG_LEVEL
|
2022-10-28 14:07:32 +11:00
|
|
|
fprintf(stderr, "%s: alloc of img failed, file=%s\n", __func__, nomtga);
|
2022-06-27 09:48:18 +11:00
|
|
|
#endif
|
|
|
|
return IMAGE_NO_MEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
Image_clear(img, SOMBRE, SOMBRE, SOMBRE);
|
|
|
|
|
|
|
|
ovr = ovg = ovb = 0; /* warning suppressor */
|
|
|
|
for (foo=0; foo<256; foo++)
|
|
|
|
{
|
|
|
|
vr = lr[foo];
|
|
|
|
vg = lg[foo];
|
|
|
|
vb = lb[foo];
|
|
|
|
if (foo)
|
|
|
|
{
|
|
|
|
vline(img, foo+60, 290-vr, 290-ovr, 'r', CLAIR);
|
|
|
|
vline(img, foo+60, 290-vg, 290-ovg, 'g', CLAIR);
|
|
|
|
vline(img, foo+60, 290-vb, 290-ovb, 'b', CLAIR);
|
|
|
|
}
|
|
|
|
|
|
|
|
ovr = vr; ovg = vg; ovb = vb;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (texte != NULL)
|
|
|
|
{
|
|
|
|
paper.r = paper.b = paper.g = SOMBRE; paper.a = 0;
|
|
|
|
ink.r = ink.b = ink.g = CLAIR; ink.a = 255;
|
|
|
|
Image_trace_chaine_1(img, texte, 5, 5, "libimage.fonte", &paper, &ink);
|
|
|
|
}
|
|
|
|
|
|
|
|
Image_cadre_A(img);
|
|
|
|
foo=Image_TGA_save(nomtga, img, 0);
|
|
|
|
Image_DeAllocate(img); free(img);
|
|
|
|
return foo;
|
|
|
|
}
|
|
|
|
/*::------------------------------------------------------------------::*/
|
|
|
|
/*
|
|
|
|
* fevrier 2009 : je constate avec amertume que cette fonction ne
|
|
|
|
* remplit plus vraiment son role face aux exigences
|
|
|
|
* de buzzwording du monde moderne. un revamping me
|
|
|
|
* semble vraiment necessaire.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
Image_plot_histo(char *nomtga, long *hr, long *hg, long *hb, char *txt)
|
|
|
|
{
|
|
|
|
Image_Desc *img;
|
|
|
|
int foo, vr, vg, vb, ovr, ovg, ovb;
|
|
|
|
long maxhisto;
|
|
|
|
RGBA paper, ink;
|
|
|
|
char chaine[120];
|
|
|
|
|
|
|
|
if ( (img = Image_alloc(400, 300, 3)) == NULL )
|
|
|
|
{
|
|
|
|
#if DEBUG_LEVEL
|
|
|
|
fprintf(stderr, "Plot Histo: alloc of img failed, file=%s\n", nomtga);
|
|
|
|
#endif
|
|
|
|
return IMAGE_NO_MEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
maxhisto = 0;
|
|
|
|
for (foo=0; foo<256; foo++)
|
|
|
|
{
|
|
|
|
if (hr[foo] > maxhisto) maxhisto = hr[foo];
|
|
|
|
if (hg[foo] > maxhisto) maxhisto = hg[foo];
|
|
|
|
if (hb[foo] > maxhisto) maxhisto = hb[foo];
|
|
|
|
}
|
|
|
|
|
|
|
|
#if DEBUG_LEVEL > 1
|
|
|
|
fprintf(stderr, "plot histo: max rgb = %ld\n", maxhisto);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
Image_clear(img, SOMBRE, SOMBRE, SOMBRE); /* ou est SOMBRE ? */
|
|
|
|
|
|
|
|
ovr = ovg = ovb = 0; /* warning suppressor */
|
|
|
|
for (foo=0; foo<256; foo++)
|
|
|
|
{
|
|
|
|
vr = (hr[foo]*256)/maxhisto;
|
|
|
|
vg = (hg[foo]*256)/maxhisto;
|
|
|
|
vb = (hb[foo]*256)/maxhisto;
|
|
|
|
if (foo)
|
|
|
|
{
|
|
|
|
vline(img, foo+60, 290-vr, 290-ovr, 'r', CLAIR);
|
|
|
|
vline(img, foo+60, 290-vg, 290-ovg, 'g', CLAIR);
|
|
|
|
vline(img, foo+60, 290-vb, 290-ovb, 'b', CLAIR);
|
|
|
|
}
|
|
|
|
ovr = vr; ovg = vg; ovb = vb;
|
|
|
|
}
|
|
|
|
|
|
|
|
paper.r = paper.b = paper.g = SOMBRE; paper.a = 0;
|
|
|
|
ink.r = ink.b = ink.g = CLAIR; ink.a = 255;
|
|
|
|
|
|
|
|
#if DEBUG_LEVEL > 1
|
|
|
|
fprintf(stderr, "taille txt %d\n", strlen(txt));
|
|
|
|
#endif
|
|
|
|
|
|
|
|
Image_trace_chaine_1(img, txt, 5, 5, "libimage.fonte", &paper, &ink);
|
|
|
|
#if DEBUG_LEVEL > 1
|
2022-10-28 14:07:32 +11:00
|
|
|
fprintf(stderr, "[%s] drawed...\n", txt);
|
2022-06-27 09:48:18 +11:00
|
|
|
#endif
|
|
|
|
|
|
|
|
sprintf(chaine, "max rgb = %ld", maxhisto);
|
|
|
|
Image_trace_chaine_1(img, chaine, 5, 15, NULL, &paper, &ink);
|
|
|
|
#if DEBUG_LEVEL > 1
|
2022-10-28 14:07:32 +11:00
|
|
|
fprintf(stderr, "[%s] drawed...\n", chaine);
|
2022-06-27 09:48:18 +11:00
|
|
|
#endif
|
|
|
|
|
|
|
|
Image_cadre_A(img);
|
|
|
|
foo=Image_TGA_save(nomtga, img, 0);
|
|
|
|
Image_DeAllocate(img); free(img);
|
|
|
|
return foo;
|
|
|
|
}
|
|
|
|
/*::------------------------------------------------------------------::*/
|
|
|
|
/* mmmmm, pas tres sexy, ce truc-la...
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
Image_calc_plot_histo(Image_Desc *img, char *tganame)
|
|
|
|
{
|
|
|
|
long hr[256], hg[256], hb[256];
|
|
|
|
int foo;
|
|
|
|
|
|
|
|
#if DEBUG_LEVEL
|
|
|
|
fprintf(stderr, "%s : %p --> '%s'\n", __func__, img, tganame);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
foo = Image_histo_RGB(img, hr, hg, hb);
|
|
|
|
Image_print_error("calc plot histo: calc", foo);
|
|
|
|
foo = Image_plot_histo(tganame, hr, hg, hb, tganame);
|
|
|
|
Image_print_error("calc plot histo: plot", foo);
|
|
|
|
|
|
|
|
return FUNC_IS_BETA;
|
|
|
|
}
|
|
|
|
/*::------------------------------------------------------------------::*/
|
|
|
|
/*
|
|
|
|
* fabrique dans une image une petite bande a partir d'une palette
|
|
|
|
* cette bande est horizontale.
|
|
|
|
*/
|
2022-10-28 14:07:32 +11:00
|
|
|
int Image_plot_h_Map(Image_Desc *img, RGB_map *map, int xpos, int ypos, int h)
|
2022-06-27 09:48:18 +11:00
|
|
|
{
|
|
|
|
int x, y, v;
|
|
|
|
|
|
|
|
for (x=0; x<256; x++)
|
|
|
|
{
|
|
|
|
for (y=0; y<h; y++)
|
|
|
|
{
|
|
|
|
if ( ((y>>2)+(x>>2)) & 1) v = SOMBRE;
|
|
|
|
else v = CLAIR;
|
|
|
|
Image_plotRGB(img, x+xpos, y+ypos, v, v, v);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#if DEBUG_LEVEL
|
|
|
|
fprintf(stderr, "Image plot h Map: %d colors\n", map->nbre);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
for (x=0; x<map->nbre; x++)
|
|
|
|
{
|
|
|
|
for (y=0; y<h; y++)
|
|
|
|
{
|
|
|
|
Image_plotRGB(img, x+xpos, y+ypos,
|
|
|
|
map->red[x], map->green[x], map->blue[x]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return FUNC_IS_BETA;
|
|
|
|
}
|
|
|
|
/*::------------------------------------------------------------------::*/
|
|
|
|
/*
|
|
|
|
* fabrique dans une image une petite bande a partir d'une palette
|
|
|
|
* cette bande est verticale.
|
|
|
|
*/
|
2022-10-28 14:07:32 +11:00
|
|
|
int Image_plot_v_Map(Image_Desc *img, RGB_map *map, int xpos, int ypos, int l)
|
2022-06-27 09:48:18 +11:00
|
|
|
{
|
|
|
|
int x, y, v;
|
|
|
|
|
2022-10-28 14:07:32 +11:00
|
|
|
for (y=0; y<256; y++) {
|
|
|
|
for (x=0; x<l; x++) {
|
2022-06-27 09:48:18 +11:00
|
|
|
if ( ((y>>2)+(x>>2)) & 1) v = SOMBRE;
|
|
|
|
else v = CLAIR;
|
|
|
|
Image_plotRGB(img, x+xpos, y+ypos, v, v, v);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#if DEBUG_LEVEL
|
|
|
|
fprintf(stderr, "Image plot v Map: %d colors\n", map->nbre);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
for (y=0; y<map->nbre; y++)
|
|
|
|
{
|
|
|
|
for (x=0; x<l; x++)
|
|
|
|
{
|
|
|
|
Image_plotRGB(img, x+xpos, y+ypos,
|
|
|
|
map->red[y], map->green[y], map->blue[y]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return FUNC_IS_BETA;
|
|
|
|
}
|
|
|
|
/*::------------------------------------------------------------------::*/
|
|
|
|
/*
|
|
|
|
* fabrique une petite TGA horizontale avec une palette dedans
|
|
|
|
*/
|
|
|
|
#define LITTLE_DIM 42
|
2022-10-28 14:07:32 +11:00
|
|
|
int Image_plot_little_h_Map(char *nom, RGB_map *map, char *texte)
|
2022-06-27 09:48:18 +11:00
|
|
|
{
|
|
|
|
Image_Desc *img;
|
|
|
|
int foo;
|
|
|
|
|
|
|
|
if ( (img=Image_alloc(260, LITTLE_DIM+4, 3)) == NULL)
|
|
|
|
{
|
|
|
|
return IMAGE_NO_MEM;
|
|
|
|
}
|
|
|
|
foo = Image_plot_h_Map(img, map, 2, 2, LITTLE_DIM);
|
|
|
|
#if DEBUG_LEVEL
|
|
|
|
fprintf(stderr, "Plot little H map: ret plot = %d, %s\n",
|
|
|
|
foo, Image_err2str(foo));
|
|
|
|
#endif
|
|
|
|
|
|
|
|
(void)Image_cadre_A(img);
|
|
|
|
|
|
|
|
if (texte != NULL) Image_set_comment(img, texte);
|
|
|
|
|
|
|
|
foo = Image_TGA_save(nom, img, 0);
|
|
|
|
fprintf(stderr, "plot little H map: save %s: %d\n", nom, foo);
|
|
|
|
|
|
|
|
Image_DeAllocate(img); free(img);
|
|
|
|
|
|
|
|
return FUNC_IS_BETA;
|
|
|
|
}
|
|
|
|
/*::------------------------------------------------------------------::*/
|
|
|
|
/*
|
2022-10-28 14:07:32 +11:00
|
|
|
* 20 Fevrier 2002.
|
2022-06-27 09:48:18 +11:00
|
|
|
* fabrique une petite TGA verticale avec une palette dedans
|
|
|
|
*/
|
2022-10-28 14:07:32 +11:00
|
|
|
int Image_plot_little_v_Map(char *nom, RGB_map *map, char *texte)
|
2022-06-27 09:48:18 +11:00
|
|
|
{
|
|
|
|
Image_Desc *img;
|
|
|
|
int foo;
|
|
|
|
|
|
|
|
if ( (img=Image_alloc(LITTLE_DIM+4, 260, 3)) == NULL)
|
|
|
|
{
|
|
|
|
return IMAGE_NO_MEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
foo = Image_plot_v_Map(img, map, 2, 2, LITTLE_DIM);
|
|
|
|
|
|
|
|
(void)Image_cadre_A(img);
|
|
|
|
|
|
|
|
if (texte != NULL) Image_set_comment(img, texte);
|
|
|
|
|
|
|
|
foo = Image_TGA_save(nom, img, 0);
|
|
|
|
fprintf(stderr, "plot little V map: save '%s': %d\n", nom, foo);
|
|
|
|
|
|
|
|
Image_DeAllocate(img); free(img);
|
|
|
|
|
|
|
|
return FUNC_IS_BETA;
|
|
|
|
}
|
|
|
|
/*::------------------------------------------------------------------::*/
|
|
|
|
/* new 2 decembre 2009 - ave St Exupery
|
|
|
|
*/
|
2022-10-28 14:07:32 +11:00
|
|
|
int Image_plot_square_Map(char *fname, RGB_map *map, char *texte, int k)
|
2022-06-27 09:48:18 +11:00
|
|
|
{
|
|
|
|
int x, y, foo;
|
|
|
|
int r, g, b;
|
|
|
|
Image_Desc *img;
|
|
|
|
Image_Rect rect;
|
|
|
|
|
|
|
|
|
|
|
|
#if DEBUG_LEVEL
|
|
|
|
fprintf(stderr, "%s ( '%s' %p '%s' %d )\n", __func__,
|
|
|
|
fname, map, texte, k);
|
|
|
|
#endif
|
|
|
|
|
2022-10-28 14:07:32 +11:00
|
|
|
if ( (img = Image_alloc(512, 512, 3)) == NULL ) {
|
2022-06-27 09:48:18 +11:00
|
|
|
#if DEBUG_LEVEL
|
2022-10-28 14:07:32 +11:00
|
|
|
fprintf(stderr, "%s: alloc of img failed, file=%s\n", __func__, fname);
|
2022-06-27 09:48:18 +11:00
|
|
|
#endif
|
|
|
|
return IMAGE_NO_MEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
Image_clear(img, 0, 0, 0);
|
|
|
|
|
|
|
|
rect.h = rect.w = 31;
|
|
|
|
|
2022-10-28 14:07:32 +11:00
|
|
|
for (foo=0; foo<256; foo++) {
|
2022-06-27 09:48:18 +11:00
|
|
|
x = ( foo & 0x0f ) * 32;
|
|
|
|
y = ( foo & 0xf0 ) * 2;
|
|
|
|
#if DEBUG_LEVEL > 1
|
|
|
|
printf("%4d : %3d %3d ", foo, x, y);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
rect.x = x;
|
|
|
|
rect.y = y;
|
|
|
|
|
2022-10-28 14:07:32 +11:00
|
|
|
if (foo < map->nbre) {
|
2022-06-27 09:48:18 +11:00
|
|
|
r = map->red[foo];
|
|
|
|
g = map->green[foo];
|
|
|
|
b = map->blue[foo];
|
|
|
|
#if DEBUG_LEVEL > 1
|
|
|
|
printf(" %3d %3d %3d\n", r, g, b);
|
|
|
|
#endif
|
|
|
|
Image_paint_rect(img, &rect, r, g, b);
|
|
|
|
}
|
2022-10-28 14:07:32 +11:00
|
|
|
else { /* on est au dela de la fin de la palette */
|
2022-06-27 09:48:18 +11:00
|
|
|
/* Image_gadrct_Hsweep_0(img, &rect, 0); */
|
|
|
|
Image_gadrct_cross(img, &rect, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
foo=Image_TGA_save(fname, img, 0);
|
|
|
|
|
|
|
|
Image_DeAllocate(img); free(img);
|
|
|
|
|
|
|
|
return FULL_NUCKED;
|
|
|
|
}
|
|
|
|
/*::------------------------------------------------------------------::*/
|
|
|
|
/*
|
|
|
|
* plotte une palette 'a la fractint'
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
Image_plot_Map(char *nomtga, RGB_map *map , char *txt)
|
|
|
|
{
|
|
|
|
Image_Desc *img;
|
|
|
|
int foo, x;
|
|
|
|
RGBA paper, ink;
|
|
|
|
Image_Rect rect;
|
|
|
|
|
|
|
|
if ( (img = Image_alloc(400, 300, 3)) == NULL )
|
|
|
|
{
|
|
|
|
#if DEBUG_LEVEL
|
2022-10-28 14:07:32 +11:00
|
|
|
fprintf(stderr, "%s: alloc of img failed, file=%s\n", __func__, nomtga);
|
2022-06-27 09:48:18 +11:00
|
|
|
#endif
|
|
|
|
return IMAGE_NO_MEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
Image_clear(img, SOMBRE, SOMBRE, SOMBRE);
|
|
|
|
|
2022-10-28 14:07:32 +11:00
|
|
|
for (foo=0; foo<map->nbre; foo++) {
|
2022-06-27 09:48:18 +11:00
|
|
|
Image_plotRGB(img, foo+90, 120, 255, 255, 255);
|
|
|
|
Image_plotRGB(img, foo+90, 200, 255, 255, 255);
|
|
|
|
Image_plotRGB(img, foo+90, 280, 255, 255, 255);
|
|
|
|
|
|
|
|
Image_plotRGB(img, foo+90, 120-(map->red[foo]/5), 255, 0, 0);
|
|
|
|
Image_plotRGB(img, foo+90, 200-(map->green[foo]/5), 0, 255, 0);
|
|
|
|
Image_plotRGB(img, foo+90, 280-(map->blue[foo]/5), 0, 0, 255);
|
|
|
|
}
|
|
|
|
|
|
|
|
rect.x = 20; rect.y = 30;
|
|
|
|
rect.h = 258; rect.w = 31;
|
|
|
|
Image_draw_rect(img, &rect, CLAIR/2, CLAIR/2, CLAIR/2);
|
|
|
|
|
|
|
|
#if DEBUG_LEVEL > 1
|
|
|
|
fprintf(stderr, "Plot MAP: the text is '%s'\n", txt);
|
|
|
|
#endif
|
|
|
|
|
2022-10-28 14:07:32 +11:00
|
|
|
for (foo=0; foo<map->nbre; foo++) {
|
|
|
|
for (x=21; x<50; x++) {
|
2022-06-27 09:48:18 +11:00
|
|
|
Image_plotRGB(img, x, foo+31,
|
|
|
|
map->red[foo], map->green[foo], map->blue[foo]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
paper.r = paper.b = paper.g = SOMBRE; paper.a = 0;
|
|
|
|
ink.r = ink.b = ink.g = CLAIR; ink.a = 255;
|
|
|
|
foo = Image_trace_chaine_1(img, txt, 15, 7, "8x8thin", &paper, &ink);
|
|
|
|
#if DEBUG_LEVEL > 1
|
2022-10-28 14:07:32 +11:00
|
|
|
fprintf(stderr, "%s: retour trace chaine = %d\n", __func__, foo);
|
2022-06-27 09:48:18 +11:00
|
|
|
#endif
|
|
|
|
Image_cadre_A(img);
|
|
|
|
|
|
|
|
if ( (foo=Image_TGA_save(nomtga, img, 0)) )
|
|
|
|
{
|
|
|
|
Image_DeAllocate(img); free(img);
|
|
|
|
return foo;
|
|
|
|
}
|
|
|
|
|
|
|
|
Image_DeAllocate(img); free(img);
|
|
|
|
|
|
|
|
return OLL_KORRECT;
|
|
|
|
}
|
|
|
|
/*::------------------------------------------------------------------::*/
|
|
|
|
/*
|
|
|
|
* new 23 oct 2001
|
|
|
|
* parameters 'p1' and 'p2' are not used, and must be 0 !
|
|
|
|
*/
|
2022-10-28 14:07:32 +11:00
|
|
|
int Image_plot_histo_hf15(Image_Desc *img, char *nom, char *txt, int p1, int p2)
|
2022-06-27 09:48:18 +11:00
|
|
|
{
|
|
|
|
Image_Desc *plot;
|
|
|
|
long *histo, maximum;
|
|
|
|
double diviseur;
|
|
|
|
int x, y, foo, h, h2, epic_fail;
|
|
|
|
RGBA paper, ink;
|
|
|
|
char chaine[200];
|
|
|
|
|
|
|
|
#if DEBUG_LEVEL
|
|
|
|
fprintf(stderr, "%s: img %p ! work in progress !\n", __func__, img);
|
|
|
|
#endif
|
|
|
|
|
2022-10-28 14:07:32 +11:00
|
|
|
if ( (histo=alloca(sizeof(long)*32768)) == NULL) {
|
|
|
|
fprintf(stderr, "%s: no mem for buffer\n", __func__);
|
2022-06-27 09:48:18 +11:00
|
|
|
#if FORCE_ABORT
|
|
|
|
abort();
|
|
|
|
#endif
|
|
|
|
return BUFFER_NO_MEM;
|
|
|
|
}
|
|
|
|
|
2022-10-28 14:07:32 +11:00
|
|
|
if ( (plot = Image_alloc(800, 600, 3)) == NULL ) {
|
2022-06-27 09:48:18 +11:00
|
|
|
#if DEBUG_LEVEL
|
|
|
|
fprintf(stderr, "Plot histo hf15: alloc img failed\n");
|
|
|
|
#endif
|
2022-10-28 14:07:32 +11:00
|
|
|
free(histo);
|
2022-06-27 09:48:18 +11:00
|
|
|
return IMAGE_NO_MEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
Image_clear(plot, SOMBRE, SOMBRE, SOMBRE);
|
|
|
|
for (foo=0; foo<32768; foo++) histo[foo] = 0L;
|
|
|
|
|
|
|
|
epic_fail = 0;
|
2022-10-28 14:07:32 +11:00
|
|
|
for (y=0; y<img->height; y++) {
|
|
|
|
for (x=0; x<img->width; x++) {
|
2022-06-27 09:48:18 +11:00
|
|
|
h = Image_hf15_height(img, x, y);
|
2022-10-28 14:07:32 +11:00
|
|
|
if (h<0 || h>32767) epic_fail++;
|
|
|
|
else histo[h]++;
|
2022-06-27 09:48:18 +11:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-28 14:07:32 +11:00
|
|
|
if (epic_fail) {
|
|
|
|
fprintf(stderr, "%s: %d epic fail(s) is epic\n", __func__, epic_fail);
|
2022-06-27 09:48:18 +11:00
|
|
|
#if FORCE_ABORT
|
|
|
|
abort();
|
|
|
|
#endif
|
2022-10-28 14:07:32 +11:00
|
|
|
free(histo);
|
|
|
|
|
2022-06-27 09:48:18 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
/* recherche du maximum de l'histogramme, pour faire la mise a l'echelle */
|
|
|
|
maximum = 0L;
|
|
|
|
for (foo=0; foo<32768; foo++)
|
|
|
|
if (histo[foo] > maximum)
|
|
|
|
maximum = histo[foo];
|
|
|
|
|
|
|
|
diviseur = (double)maximum/400.0;
|
|
|
|
if (diviseur==0) diviseur=1.0; /* XXX workaround */
|
|
|
|
|
|
|
|
fprintf(stderr, "%s: maximum = %ld, diviseur = %g\n", __func__,
|
|
|
|
maximum, diviseur);
|
|
|
|
|
|
|
|
h2 = 0;
|
2022-10-28 14:07:32 +11:00
|
|
|
for (foo=0; foo<32768; foo+=4) {
|
2022-06-27 09:48:18 +11:00
|
|
|
h = (int)((double)histo[foo] / diviseur);
|
|
|
|
x = (foo/64)+60;
|
2022-10-28 14:07:32 +11:00
|
|
|
if (foo) { /* pourquoi ? */
|
2022-06-27 09:48:18 +11:00
|
|
|
vline(plot, x, 590-h, 290-h2, 'g', CLAIR);
|
|
|
|
h2 = h;
|
|
|
|
}
|
|
|
|
Image_plotRGB(plot, x, 590-h, CLAIR, SOMBRE, SOMBRE);
|
|
|
|
Image_plotRGB(plot, x, 590, SOMBRE, CLAIR, SOMBRE);
|
|
|
|
}
|
|
|
|
|
|
|
|
paper.r = paper.b = paper.g = SOMBRE; paper.a = 0;
|
|
|
|
ink.r = ink.b = ink.g = CLAIR; ink.a = 255;
|
|
|
|
/* Image_trace_chaine_0(plot, txt, 5, 5, &paper, &ink, 0); */
|
|
|
|
Image_trace_chaine_1(plot, chaine, 5, 5, NULL, &paper, &ink);
|
|
|
|
sprintf(chaine, "max %ld", maximum);
|
|
|
|
/* Image_trace_chaine_0(plot, chaine, 5, 15, &paper, &ink, 0); */
|
|
|
|
Image_trace_chaine_1(plot, chaine, 5, 15, NULL, &paper, &ink);
|
|
|
|
sprintf(chaine, "div %g", diviseur);
|
|
|
|
/* Image_trace_chaine_0(plot, chaine, 5, 25, &paper, &ink, 0); */
|
|
|
|
Image_trace_chaine_1(plot, chaine, 5, 25, NULL, &paper, &ink);
|
|
|
|
|
|
|
|
Image_cadre_A(plot);
|
|
|
|
foo=Image_TGA_save(nom, plot, 0);
|
|
|
|
|
|
|
|
Image_DeAllocate(plot); free(plot);
|
|
|
|
|
|
|
|
return FUNC_IS_BETA;
|
|
|
|
}
|
|
|
|
/*::------------------------------------------------------------------::*/
|