20 #define CLAMP(x) ((x)<0
? 0
: ((x)>255
? 255
: (x)))
75 char *outfname = NULL,
77 FILE *outfile = stdout;
81 rle_op **scan, ***save_scan;
82 register rle_op *scanp;
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,
121 sizeof( rle_op ** ) );
122 save_nraw = (
int **)calloc( in_hdr
.ymax + 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) );
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]]++;
151 histo[hc][scanp->u.run_val] += scanp
->length;
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;
234 scanp->u.pixels[x] =
CLAMP( t );
238 t = scanp->u.run_val * h_stretch + h_slide;
239 scanp->u.run_val =
CLAMP( t );
309 if ( save_nraw[y] == NULL )
315 totlen += save_nraw[y][c] = nraw[c];
320 if ( save_scan[y] == NULL )
328 save_scan[y][0] = (rle_op *)malloc( 1 + totlen *
sizeof(rle_op) );
329 if ( save_scan[y][0] == NULL )
338 save_scan[y][c] = save_scan[y][c-1] + nraw[c-1];
339 bcopy( scan[c], save_scan[y][c], nraw[c] *
sizeof(rle_op) );
FILE * rle_open_f(char *prog_name, char *file_name, char *mode)
rle_hdr * rle_hdr_cp(rle_hdr *from_hdr, rle_hdr *to_hdr)
void rle_freeraw(rle_hdr *the_hdr, scanraw, nraw)
void rle_names(rle_hdr *the_hdr, const char *pgmname, const char *fname, int img_num)
int rle_raw_alloc(rle_hdr *the_hdr, rle_op ***scanp, int **nrawp)
char * cmd_name(char **argv)
void main(int argc, char **argv)
int rle_get_setup(rle_hdr *the_hdr)
void rle_putraw(rle_op **scanraw, int *nraw, rle_hdr *the_hdr)
void copy_raw(rle_hdr *the_hdr, int y, rle_op **scan, int *nraw, rle_op ***save_scan, int **save_nraw)
int rle_get_error(int code, const char *pgmname, const char *fname)
int scanargs(int argc, char **argv, const char *format,...)
void rle_puteof(rle_hdr *the_hdr)
void rle_addhist(argv, rle_hdr *in_hdr, rle_hdr *out_hdr)
void rle_skiprow(rle_hdr *the_hdr, int nrow)
void rle_put_setup(rle_hdr *the_hdr)
void rle_raw_free(rle_hdr *the_hdr, rle_op **scanp, nrawp)
rle_hdr * rle_hdr_init(rle_hdr *the_hdr)
unsigned int rle_getraw(rle_hdr *the_hdr, scanraw, nraw)
#define RLE_CHECK_ALLOC(pgm, ptr, name)