75 char *outfname = NULL,
83 int *nraw, **save_nraw;
87 long int (*histo)[256];
97 "% t%-threshold!d b%-blacklevel!d w%-whitelevel!d s%- v%- \
98 \to%-outfile!s infile%s",
99 &tflag, &threshold, &bflag, &blacklevel,
101 &sflag, &verbose, &oflag, &outfname, &infname ) == 0 )
120 save_scan = (
rle_op ***)calloc( in_hdr.
ymax + 1,
122 save_nraw = (
int **)calloc( in_hdr.
ymax + 1,
126 nhist = sflag ? in_hdr.
ncolors : 1;
127 histo = (
long int (*)[256]) calloc( 256 * nhist,
sizeof(
long int) );
128 stretch = (
float *)calloc( nhist,
sizeof(
float) );
129 slide = (
int *)calloc( nhist,
sizeof(
int) );
133 while ( (y =
rle_getraw( &in_hdr, scan, nraw )) != 32768 )
136 for ( c = 0; c < in_hdr.
ncolors; c++ )
143 for ( i = 0, scanp = scan[c]; i < nraw[c]; i++, scanp++ )
147 for ( x = 0; x < scanp->
length; x++ )
148 histo[hc][scanp->
u.
pixels[x]]++;
157 copy_raw( &in_hdr, y, scan, nraw, save_scan, save_nraw );
162 thresh = (((double)threshold * (in_hdr.
xmax - in_hdr.
xmin + 1) *
169 for ( hc = 0; hc < nhist; hc++ )
171 for ( i = 0; i < 256 && histo[hc][
i] <= thresh; i++ )
174 for ( i = 255; i >= 0 && histo[hc][
i] <= thresh; i-- )
179 if ( maxval > minval )
180 stretch[hc] = (float)(whitelevel - blacklevel) /
184 slide[hc] = blacklevel - stretch[hc] * minval;
188 fprintf( stderr,
"%s image %d",
189 in_hdr.
rle_file == stdin ?
"Standard input" : infname,
192 fprintf( stderr,
", channel %d", hc );
193 fprintf( stderr,
" min = %d, max = %d\n", minval, maxval );
202 for ( y = in_hdr.
ymin, ynext = -1;
209 for ( c = 0; c < in_hdr.
ncolors; c++ )
216 h_stretch = stretch[c];
221 h_stretch = stretch[0];
225 for ( i = 0, scanp = save_scan[y][c];
231 for ( x = 0; x < scanp->
length; x++ )
233 t = scanp->
u.
pixels[
x] * h_stretch + h_slide;
238 t = scanp->
u.
run_val * h_stretch + h_slide;
253 rle_putraw( save_scan[y], save_nraw[y], &out_hdr );
254 rle_freeraw( &in_hdr, save_scan[y], save_nraw[y] );
void rle_skiprow(rle_hdr *the_hdr, int nrow)
int scanargs(int argc, char **argv, const char *format,...)
void rle_freeraw(rle_hdr *the_hdr, scanraw, nraw)
void rle_addhist(char *argv[], rle_hdr *in_hdr, rle_hdr *out_hdr)
void rle_puteof(rle_hdr *the_hdr)
void rle_names(rle_hdr *the_hdr, const char *pgmname, const char *fname, int img_num)
int rle_get_setup(rle_hdr *the_hdr)
int rle_get_error(int code, const char *pgmname, const char *fname)
rle_hdr * rle_hdr_cp(rle_hdr *from_hdr, rle_hdr *to_hdr)
FILE * rle_open_f(const char *prog_name, const char *f_name, const char *mode)
void rle_put_setup(rle_hdr *the_hdr)
char * cmd_name(char **argv)
unsigned int rle_getraw(rle_hdr *the_hdr, scanraw, nraw)
#define RLE_CHECK_ALLOC(pgm, ptr, name)
rle_hdr * rle_hdr_init(rle_hdr *the_hdr)