~ubuntu-branches/ubuntu/trusty/netpbm-free/trusty

« back to all changes in this revision

Viewing changes to pnm/pnmnorm.c

  • Committer: Bazaar Package Importer
  • Author(s): Andreas Barth
  • Date: 2004-07-29 20:25:46 UTC
  • Revision ID: james.westby@ubuntu.com-20040729202546-9o69r65403wvtla5
Tags: 2:10.0-5
* build-depends against libtiff4.
* fix typo in ppmtowinicon. Closes: #261999.

Show diffs side-by-side

added added

removed removed

Lines of Context:
296
296
    if (bvalue > 0)
297
297
        for (i = 0; i <= bvalue-1; ++i)
298
298
            newIntensity[i] = 0;
299
 
    {
 
299
 
 
300
    if (wvalue > bvalue) {
300
301
        /* Map the middle intensities to 0..maxval */
301
 
        unsigned int const range = wvalue - bvalue;
302
 
        unsigned int val;
 
302
        /* Size: wvalue, bvalue are xelval, so the diff fits also in xelval */
 
303
        xelval const range = wvalue - bvalue;
 
304
        /* As val is at maximum (wvalue - bvalue - 1) * maxval <
 
305
         * xelval_max * xelval_max this fits into double
 
306
         */
 
307
        double val;
303
308
        /* The following for loop is a hand optimization of this one:
304
309
           for (i = bvalue; i <= wvalue; ++i)
305
310
           newIntensity[i] = (i-bvalue)*maxval/range);
306
311
           (with proper rounding)
 
312
           the rounding is aequivalent to (i-bvalue)*maxval/range + .5
 
313
           <=> ((i-bvalue)*maxval + .5*range)/range, so we set the starting
 
314
           point to range/2
307
315
        */
308
 
        for (i = bvalue, val = maxval/2; 
 
316
        for (i = bvalue, val = range/2; 
309
317
             i <= wvalue; 
310
318
             ++i, val += maxval)
311
319
            newIntensity[i] = val / range;
312
 
        }
 
320
    }
 
321
 
313
322
    /* Map the highest intensities to maxval */
314
323
    for (i = wvalue+1; i <= maxval; ++i)
315
324
        newIntensity[i] = maxval;