This patch does two things: 1. Fixes a bug in ppmchange that causes it not to work properly for images whose maxval is not 65535 (or 255 if PGM_BIGGRAYS is not defined).. To see this bug, try ppmmake white 10 10 | pnmdepth 127 | ppmchange white blue | ppmhist the correct output is this: r g b lum count --- --- --- --- ----- 0 0 127 14 100 but instead you get this: r g b lum count --- --- --- --- ----- 127 127 127 127 100 2. Makes all depth conversions (from one maxval to another) use the same method: the PGM_DEPTH macro. Before applying this patch, these two sequences will give different results, since pnmdepth and pgmtoppm use different depth-conversion formulas: ppmmake white 10 10 | ppmtopgm | pnmdepth 255 | pgmtoppm rgb:fffe/fffe/fffe | ppmhist ppmmake white 10 10 | ppmtopgm | pgmtoppm rgb:fffe/fffe/fffe | pnmdepth 255 | ppmhist This fix affects several conversion programs. *** pgm/pgm.h.orig Mon Oct 4 05:11:13 1993 --- pgm/pgm.h Sun May 19 17:59:08 1996 *************** *** 29,34 **** --- 29,45 ---- #define PGM_FORMAT_TYPE(f) ((f) == PGM_FORMAT || (f) == RPGM_FORMAT ? PGM_TYPE : PBM_FORMAT_TYPE(f)) + /* Macro for scaling to a new maxval. + * This formula has a few important properties for all positive + * integers m,n,r, and integers x with 0 <= x <= m: + * (1) PGM_DEPTH(0,m,n) = 0 (black pixels remain black) + * (2) PGM_DEPTH(m,m,n) = n (white pixels remain white) + * (3) PGM_DEPTH(PGM_DEPTH(x,m,n),n,m) = x, if m <= n + * (Property 3 ensures that if we convert to a larger maxval and + * back to the original maxval, we recover the original value.) + */ + #define PGM_DEPTH(p,oldmaxval,newmaxval) \ + ( ( (int) (p) * (newmaxval) + (oldmaxval) / 2 ) / (oldmaxval) ) /* Declarations of routines. */ *** ppm/ppm.h.orig Tue Feb 1 09:04:21 1994 --- ppm/ppm.h Sun May 19 00:26:04 1996 *************** *** 93,102 **** #define PPM_DEPTH(newp,p,oldmaxval,newmaxval) \ PPM_ASSIGN( (newp), \ ! ( (int) PPM_GETR(p) * (newmaxval) + (oldmaxval) / 2 ) / (oldmaxval), \ ! ( (int) PPM_GETG(p) * (newmaxval) + (oldmaxval) / 2 ) / (oldmaxval), \ ! ( (int) PPM_GETB(p) * (newmaxval) + (oldmaxval) / 2 ) / (oldmaxval) ) ! /* Luminance macro. */ --- 93,101 ---- #define PPM_DEPTH(newp,p,oldmaxval,newmaxval) \ PPM_ASSIGN( (newp), \ ! PGM_DEPTH(PPM_GETR(p),oldmaxval,newmaxval), \ ! PGM_DEPTH(PPM_GETG(p),oldmaxval,newmaxval), \ ! PGM_DEPTH(PPM_GETB(p),oldmaxval,newmaxval) ) /* Luminance macro. */ *** pgm/pgmtofs.c.orig Mon Oct 4 05:11:22 1993 --- pgm/pgmtofs.c Sat May 18 20:48:50 1996 *************** *** 70,76 **** for ( col = 0, gP = grays[row]; col < cols; ++col, ++gP ) { if ( maxval != nmaxval ) ! *gP = (int) *gP * nmaxval / maxval; putgray( *gP ); } for ( col = 0; col < padright; ++col ) --- 70,76 ---- for ( col = 0, gP = grays[row]; col < cols; ++col, ++gP ) { if ( maxval != nmaxval ) ! *gP = (int) PGM_DEPTH( *gP, maxval, nmaxval ); putgray( *gP ); } for ( col = 0; col < padright; ++col ) *** pgm/pgmtopbm.c.orig Fri Feb 18 05:03:01 1994 --- pgm/pgmtopbm.c Sat May 18 16:25:30 1996 *************** *** 140,167 **** /* Scale dither matrix. */ for ( row = 0; row < 16; ++row ) for ( col = 0; col < 16; ++col ) ! dither8[row][col] = dither8[row][col] * ( maxval + 1 ) / 256; break; case QT_CLUSTER3: /* Scale order-3 clustered dither matrix. */ for ( row = 0; row < 6; ++row ) for ( col = 0; col < 6; ++col ) ! cluster3[row][col] = cluster3[row][col] * ( maxval + 1 ) / 18; break; case QT_CLUSTER4: /* Scale order-4 clustered dither matrix. */ for ( row = 0; row < 8; ++row ) for ( col = 0; col < 8; ++col ) ! cluster4[row][col] = cluster4[row][col] * ( maxval + 1 ) / 32; break; case QT_CLUSTER8: /* Scale order-8 clustered dither matrix. */ for ( row = 0; row < 16; ++row ) for ( col = 0; col < 16; ++col ) ! cluster8[row][col] = cluster8[row][col] * ( maxval + 1 ) / 128; break; default: --- 140,171 ---- /* Scale dither matrix. */ for ( row = 0; row < 16; ++row ) for ( col = 0; col < 16; ++col ) ! dither8[row][col] = PGM_DEPTH( dither8[row][col], ! 255, maxval ); break; case QT_CLUSTER3: /* Scale order-3 clustered dither matrix. */ for ( row = 0; row < 6; ++row ) for ( col = 0; col < 6; ++col ) ! cluster3[row][col] = PGM_DEPTH( cluster3[row][col], ! maxval, 17 ); break; case QT_CLUSTER4: /* Scale order-4 clustered dither matrix. */ for ( row = 0; row < 8; ++row ) for ( col = 0; col < 8; ++col ) ! cluster4[row][col] = PGM_DEPTH( cluster4[row][col], ! maxval, 31 ); break; case QT_CLUSTER8: /* Scale order-8 clustered dither matrix. */ for ( row = 0; row < 16; ++row ) for ( col = 0; col < 16; ++col ) ! cluster8[row][col] = PGM_DEPTH( cluster8[row][col], ! maxval, 127 ); break; default: *** ppm/ilbmtoppm.c.orig Thu Dec 2 04:18:07 1993 --- ppm/ilbmtoppm.c Sat May 18 17:16:00 1996 *************** *** 614,622 **** if( scale ) { for( col = 0; col < cols; col++ ) { PPM_ASSIGN(pixelrow[col], ! Rrow[col] * maxval / redmaxval, ! Grow[col] * maxval / greenmaxval, ! Brow[col] * maxval / bluemaxval); } } else { --- 614,622 ---- if( scale ) { for( col = 0; col < cols; col++ ) { PPM_ASSIGN(pixelrow[col], ! PGM_DEPTH( Rrow[col], redmaxval, maxval ), ! PGM_DEPTH( Grow[col], greenmaxval, maxval ), ! PGM_DEPTH( Brow[col], bluemaxval, maxval ) ); } } else { *************** *** 1237,1245 **** #endif for( i = 0; i < PCHG->TotalChanges; i++ ) { ! Palette[i].Red = Palette[i].Red * newmaxval / oldmaxval; ! Palette[i].Green= Palette[i].Green * newmaxval / oldmaxval; ! Palette[i].Blue = Palette[i].Blue * newmaxval / oldmaxval; } pchginfo->maxval = newmaxval; } --- 1237,1248 ---- #endif for( i = 0; i < PCHG->TotalChanges; i++ ) { ! Palette[i].Red = PGM_DEPTH( Palette[i].Red, ! oldmaxval, newmaxval ); ! Palette[i].Green = PGM_DEPTH( Palette[i].Green, ! oldmaxval, newmaxval ); ! Palette[i].Blue = PGM_DEPTH( Palette[i].Blue, ! oldmaxval, newmaxval ); } pchginfo->maxval = newmaxval; } *************** *** 1299,1308 **** int i, r, g, b; for( i = 0; i < colors; i++ ) { ! r = PPM_GETR(colormap[i]) * newmaxval / oldmaxval; ! g = PPM_GETG(colormap[i]) * newmaxval / oldmaxval; ! b = PPM_GETB(colormap[i]) * newmaxval / oldmaxval; ! PPM_ASSIGN(colormap[i], r, g, b); } } --- 1302,1308 ---- int i, r, g, b; for( i = 0; i < colors; i++ ) { ! PPM_DEPTH( colormap[i], colormap[i], oldmaxval, newmaxval ); } } *** ppm/libppm4.c.orig Mon Oct 4 05:12:13 1993 --- ppm/libppm4.c Sat May 18 14:54:18 1996 *************** *** 41,59 **** { case 1: if ( lmaxval != 15 ) ! rgb = rgb * lmaxval / 15; break; case 2: if ( lmaxval != 255 ) ! rgb = rgb * lmaxval / 255; break; case 3: if ( lmaxval != 4095 ) ! rgb = rgb * lmaxval / 4095; break; case 4: if ( lmaxval != 65535L ) ! rgb = rgb * lmaxval / 65535L; break; default: pm_error( "invalid color specifier - \"%s\"", colorname ); --- 41,59 ---- { case 1: if ( lmaxval != 15 ) ! rgb = PGM_DEPTH( rgb, 15, lmaxval ); break; case 2: if ( lmaxval != 255 ) ! rgb = PGM_DEPTH( rgb, 255, lmaxval ); break; case 3: if ( lmaxval != 4095 ) ! rgb = PGM_DEPTH( rgb, 4095, lmaxval ); break; case 4: if ( lmaxval != 65535L ) ! rgb = PGM_DEPTH( rgb, 65535L, lmaxval ); break; default: pm_error( "invalid color specifier - \"%s\"", colorname ); *************** *** 236,244 **** /* Rescale from [0..255] if necessary. */ if ( lmaxval != 255 ) { ! r = r * lmaxval / 255; ! g = g * lmaxval / 255; ! b = b * lmaxval / 255; } #endif /*RGB_DB*/ } --- 236,244 ---- /* Rescale from [0..255] if necessary. */ if ( lmaxval != 255 ) { ! r = PGM_DEPTH(r, 255, lmaxval); ! g = PGM_DEPTH(g, 255, lmaxval); ! b = PGM_DEPTH(b, 255, lmaxval); } #endif /*RGB_DB*/ } *************** *** 272,288 **** #endif /* A_RGBENV */ #endif /*RGB_DB*/ ! if ( maxval == 255 ) ! { ! r = PPM_GETR( *colorP ); ! g = PPM_GETG( *colorP ); ! b = PPM_GETB( *colorP ); ! } ! else ! { ! r = (int) PPM_GETR( *colorP ) * 255 / (int) maxval; ! g = (int) PPM_GETG( *colorP ) * 255 / (int) maxval; ! b = (int) PPM_GETB( *colorP ) * 255 / (int) maxval; } #ifdef RGB_DB --- 272,286 ---- #endif /* A_RGBENV */ #endif /*RGB_DB*/ ! r = PPM_GETR( *colorP ); ! g = PPM_GETG( *colorP ); ! b = PPM_GETB( *colorP ); ! ! if ( maxval != 255 ) ! { ! r = PGM_DEPTH( r, 255, maxval ); ! g = PGM_DEPTH( g, 255, maxval ); ! b = PGM_DEPTH( b, 255, maxval ); } #ifdef RGB_DB *** ppm/pgmtoppm.c.orig Mon Oct 4 05:12:16 1993 --- ppm/pgmtoppm.c Sat May 18 17:23:23 1996 *************** *** 135,141 **** if ( maxval == mapmaxcolor ) c = *gP; else ! c = *gP * mapmaxcolor / maxval; *pP = mappixels[c / mapcols][c % mapcols]; } } --- 135,141 ---- if ( maxval == mapmaxcolor ) c = *gP; else ! c = PGM_DEPTH( *gP, maxval, mapmaxcolor ); *pP = mappixels[c / mapcols][c % mapcols]; } } *** ppm/picttoppm.c.orig Fri Jan 28 04:19:18 1994 --- ppm/picttoppm.c Sat May 18 17:31:25 1996 *************** *** 1556,1564 **** while (rows-- > 0) { ppm_readppmrow(scaled, row, cols, maxval, format); for (i = 0, rowp = row; i < cols; ++i, ++rowp) { ! *reddst++ = PPM_GETR(*rowp) * 65536L / (maxval + 1); ! *greendst++ = PPM_GETG(*rowp) * 65536L / (maxval + 1); ! *bluedst++ = PPM_GETB(*rowp) * 65536L / (maxval + 1); } reddst += dstadd; greendst += dstadd; --- 1556,1567 ---- while (rows-- > 0) { ppm_readppmrow(scaled, row, cols, maxval, format); for (i = 0, rowp = row; i < cols; ++i, ++rowp) { ! *reddst++ = PGM_DEPTH(PPM_GETR(*rowp), ! maxval, 65535L); ! *greendst++ =PGM_DEPTH(PPM_GETG(*rowp), ! maxval, 65535L); ! *bluedst++ = PGM_DEPTH(PPM_GETB(*rowp), ! maxval, 65535L); } reddst += dstadd; greendst += dstadd; *************** *** 1572,1580 **** dst_c.red = *reddst; dst_c.green = *greendst; dst_c.blue = *bluedst; ! src_c.red = PPM_GETR(*rowp) * 65536L / (maxval + 1); ! src_c.green = PPM_GETG(*rowp) * 65536L / (maxval + 1); ! src_c.blue = PPM_GETB(*rowp) * 65536L / (maxval + 1); (*trf)(&src_c, &dst_c); *reddst++ = dst_c.red; *greendst++ = dst_c.green; --- 1575,1586 ---- dst_c.red = *reddst; dst_c.green = *greendst; dst_c.blue = *bluedst; ! src_c.red = PGM_DEPTH(PPM_GETR(*rowp), ! maxval, 65535L); ! src_c.green= PGM_DEPTH(PPM_GETG(*rowp), ! maxval, 65535L); ! src_c.blue = PGM_DEPTH(PPM_GETB(*rowp), ! maxval, 65535L); (*trf)(&src_c, &dst_c); *reddst++ = dst_c.red; *greendst++ = dst_c.green; *** ppm/ppmbrighten.c.orig Wed Oct 27 10:00:31 1993 --- ppm/ppmbrighten.c Sat May 18 17:38:51 1996 *************** *** 200,208 **** g = PPM_GETG( pixelP[i] ); b = PPM_GETB( pixelP[i] ); ! R = (MULTI * r + maxval - 1) / maxval; ! G = (MULTI * g + maxval - 1) / maxval; ! B = (MULTI * b + maxval - 1) / maxval; GetHSV( R, G, B, &H, &S, &V ); if ( V > max_value) max_value = V; --- 200,208 ---- g = PPM_GETG( pixelP[i] ); b = PPM_GETB( pixelP[i] ); ! R = PGM_DEPTH( r, maxval, MULTI ); ! G = PGM_DEPTH( g, maxval, MULTI ); ! B = PGM_DEPTH( b, maxval, MULTI ); GetHSV( R, G, B, &H, &S, &V ); if ( V > max_value) max_value = V; *************** *** 236,244 **** g = PPM_GETG( pixelP[i] ); b = PPM_GETB( pixelP[i] ); ! R = (MULTI * r + maxval - 1) / maxval; ! G = (MULTI * g + maxval - 1) / maxval; ! B = (MULTI * b + maxval - 1) / maxval; GetHSV( R, G, B, &H, &S, &V ); --- 236,244 ---- g = PPM_GETG( pixelP[i] ); b = PPM_GETB( pixelP[i] ); ! R = PGM_DEPTH( r, maxval, MULTI ); ! G = PGM_DEPTH( g, maxval, MULTI ); ! B = PGM_DEPTH( b, maxval, MULTI ); GetHSV( R, G, B, &H, &S, &V ); *************** *** 259,264 **** --- 259,267 ---- GetRGB( H, S, V, &R, &G, &B ); + r = PGM_DEPTH( R, MULTI, maxval ); + g = PGM_DEPTH( G, MULTI, maxval ); + b = PGM_DEPTH( B, MULTI, maxval ); r = (R * maxval) / MULTI; g = (G * maxval) / MULTI; b = (B * maxval) / MULTI; *** ppm/ppmchange.c.orig Fri Jan 28 12:11:41 1994 --- ppm/ppmchange.c Sat May 18 05:00:51 1996 *************** *** 28,33 **** --- 28,34 ---- int rows, cols, ncolors; pixel* prow; pixel color0[TCOLS], color1[TCOLS]; + char *colorname0[TCOLS], *colorname1[TCOLS]; pixval maxval; char* usage = " [...] [ppmfile]"; *************** *** 39,49 **** pm_usage( usage ); for ( i = 0; argn < argc - 1 && i < TCOLS; i++ ) { ! color0[i] = ppm_parsecolor( argv[argn], PPM_MAXMAXVAL ); ++argn; if ( argn == argc ) pm_usage( usage ); ! color1[i] = ppm_parsecolor( argv[argn], PPM_MAXMAXVAL ); ++argn; } ncolors = i; --- 40,50 ---- pm_usage( usage ); for ( i = 0; argn < argc - 1 && i < TCOLS; i++ ) { ! colorname0[i] = argv[argn]; ++argn; if ( argn == argc ) pm_usage( usage ); ! colorname1[i] = argv[argn]; ++argn; } ncolors = i; *************** *** 54,59 **** --- 55,66 ---- ifp = stdin; ppm_readppminit( ifp, &cols, &rows, &maxval, &format ); + + for ( i = 0; i < ncolors; i++ ) { + color0[i] = ppm_parsecolor( colorname0[i], maxval ); + color1[i] = ppm_parsecolor( colorname1[i], maxval ); + } + ppm_writeppminit( stdout, cols, rows, maxval, 0 ); prow = ppm_allocrow( cols ); *** ppm/ppmtoilbm.c.orig Fri Jan 21 08:05:38 1994 --- ppm/ppmtoilbm.c Sat May 18 14:55:15 1996 *************** *** 1785,1791 **** table = MALLOC(oldmaxval + 1, pixval); for(i = 0; i <= oldmaxval; i++ ) ! table[i] = (i * newmaxval + oldmaxval/2) / oldmaxval; return table; } --- 1785,1791 ---- table = MALLOC(oldmaxval + 1, pixval); for(i = 0; i <= oldmaxval; i++ ) ! table[i] = PGM_DEPTH( i, oldmaxval, newmaxval ); return table; } *** pnm/libpnm3.c.orig Mon Oct 4 05:11:32 1993 --- pnm/libpnm3.c Sat May 18 16:41:01 1996 *************** *** 311,317 **** case PGM_TYPE: for ( col = 0, xP = xelrow; col < cols; ++col, ++xP ) PNM_ASSIGN1( ! *xP, (int) PNM_GET1(*xP) * newmaxval / maxval ); break; case PPM_TYPE: --- 311,317 ---- case PGM_TYPE: for ( col = 0, xP = xelrow; col < cols; ++col, ++xP ) PNM_ASSIGN1( ! *xP, PGM_DEPTH( PNM_GET1(*xP), maxval, newmaxval ) ); break; case PPM_TYPE: *************** *** 369,377 **** { /* Increase maxval. */ for ( col = 0, xP = xelrow; col < cols; ++col, ++xP ) PPM_ASSIGN( ! *xP, (int) PNM_GET1(*xP) * newmaxval / maxval, ! (int) PNM_GET1(*xP) * newmaxval / maxval, ! (int) PNM_GET1(*xP) * newmaxval / maxval ); } break; --- 369,377 ---- { /* Increase maxval. */ for ( col = 0, xP = xelrow; col < cols; ++col, ++xP ) PPM_ASSIGN( ! *xP, PGM_DEPTH( PNM_GET1(*xP), maxval, newmaxval ), ! PGM_DEPTH( PNM_GET1(*xP), maxval, newmaxval ), ! PGM_DEPTH( PNM_GET1(*xP), maxval, newmaxval ) ); } break; *** pnm/pnmdepth.c.orig Mon Oct 4 05:11:38 1993 --- pnm/pnmdepth.c Sat May 18 16:44:26 1996 *************** *** 68,74 **** newformat = format; for ( i = 0; i <= maxval; ++i ) ! newvals[i] = ( i * newmaxval + maxval / 2 ) / maxval; pnm_writepnminit( stdout, cols, rows, newmaxval, newformat, 0 ); --- 68,74 ---- newformat = format; for ( i = 0; i <= maxval; ++i ) ! newvals[i] = PGM_DEPTH( i, maxval, newmaxval ); pnm_writepnminit( stdout, cols, rows, newmaxval, newformat, 0 ); *** pnm/pnmtorast.c.orig Mon Oct 4 05:11:58 1993 --- pnm/pnmtorast.c Sat May 18 16:46:35 1996 *************** *** 211,217 **** case PGM_TYPE: color = PNM_GET1( *xP ); if ( maxval != 255 ) ! color = color * 255 / maxval; break; default: --- 211,217 ---- case PGM_TYPE: color = PNM_GET1( *xP ); if ( maxval != 255 ) ! color = PGM_DEPTH( color, 255, maxval ); break; default: *** pnm/pnmtosir.c.orig Thu Dec 9 06:32:47 1993 --- pnm/pnmtosir.c Sat May 18 16:51:10 1996 *************** *** 115,133 **** for ( row = 0; row < rows; ++row ) for ( col = 0, xP = xels[row]; col < cols; ++col, ++xP ) { ! ub = (char) ( PPM_GETR( *xP ) * ( 255 / maxval ) ); fputc( ub, stdout ); } for ( row = 0; row < rows; ++row ) for ( col = 0, xP = xels[row]; col < cols; ++col, ++xP ) { ! ub = (char) ( PPM_GETG( *xP ) * ( 255 / maxval ) ); fputc( ub, stdout ); } for ( row = 0; row < rows; ++row ) for ( col = 0, xP = xels[row]; col < cols; ++col, ++xP ) { ! ub = (char) ( PPM_GETB( *xP ) * ( 255 / maxval ) ); fputc( ub, stdout ); } break; --- 115,133 ---- for ( row = 0; row < rows; ++row ) for ( col = 0, xP = xels[row]; col < cols; ++col, ++xP ) { ! ub = (char) PGM_DEPTH( PPM_GETR( *xP ), maxval, 255 ); fputc( ub, stdout ); } for ( row = 0; row < rows; ++row ) for ( col = 0, xP = xels[row]; col < cols; ++col, ++xP ) { ! ub = (char) PGM_DEPTH( PPM_GETG( *xP ), maxval, 255 ); fputc( ub, stdout ); } for ( row = 0; row < rows; ++row ) for ( col = 0, xP = xels[row]; col < cols; ++col, ++xP ) { ! ub = (char) PGM_DEPTH( PPM_GETB( *xP ), maxval, 255 ); fputc( ub, stdout ); } break; *************** *** 139,145 **** register unsigned long val; val = PNM_GET1( *xP ); ! ub = (char) ( val * ( 255 / maxval ) ); fputc( ub, stdout ); } break; --- 139,145 ---- register unsigned long val; val = PNM_GET1( *xP ); ! ub = (char) PGM_DEPTH ( val, maxval, 255 ); fputc( ub, stdout ); } break; *** pnm/pnmtotiff.c.orig Thu Jan 27 11:59:25 1994 --- pnm/pnmtotiff.c Sat May 18 16:55:11 1996 *************** *** 255,263 **** /* Make TIFF colormap. */ for ( i = 0; i < colors; ++i ) { ! red[i] = (long) PPM_GETR( chv[i].color ) * 65535L / maxval; ! grn[i] = (long) PPM_GETG( chv[i].color ) * 65535L / maxval; ! blu[i] = (long) PPM_GETB( chv[i].color ) * 65535L / maxval; } TIFFSetField( tif, TIFFTAG_COLORMAP, red, grn, blu ); --- 255,266 ---- /* Make TIFF colormap. */ for ( i = 0; i < colors; ++i ) { ! red[i] = (long) PGM_DEPTH( PPM_GETR( chv[i].color ), ! maxval, 65535L ); ! grn[i] = (long) PGM_DEPTH( PPM_GETG( chv[i].color ), ! maxval, 65535L ); ! blu[i] = (long) PGM_DEPTH( PPM_GETB( chv[i].color ), ! maxval, 65535L ); } TIFFSetField( tif, TIFFTAG_COLORMAP, red, grn, blu ); *************** *** 280,294 **** s = PPM_GETR( *xP ); if ( maxval != 255 ) ! s = (long) s * 255 / maxval; *tP++ = s; s = PPM_GETG( *xP ); if ( maxval != 255 ) ! s = (long) s * 255 / maxval; *tP++ = s; s = PPM_GETB( *xP ); if ( maxval != 255 ) ! s = (long) s * 255 / maxval; *tP++ = s; } } --- 283,297 ---- s = PPM_GETR( *xP ); if ( maxval != 255 ) ! s = (long) PGM_DEPTH( s, maxval, 255 ); *tP++ = s; s = PPM_GETG( *xP ); if ( maxval != 255 ) ! s = (long) PGM_DEPTH( s, maxval, 255 ); *tP++ = s; s = PPM_GETB( *xP ); if ( maxval != 255 ) ! s = (long) PGM_DEPTH( s, maxval, 255 ); *tP++ = s; } } *************** *** 323,329 **** { s = PNM_GET1( *xP ); if ( maxval != bigger_maxval ) ! s = (long) s * bigger_maxval / maxval; byte |= s << bitshift; bitshift -= bitspersample; if ( bitshift < 0 ) --- 326,332 ---- { s = PNM_GET1( *xP ); if ( maxval != bigger_maxval ) ! s = (long) PGM_DEPTH( s, maxval, bigger_maxval ); byte |= s << bitshift; bitshift -= bitspersample; if ( bitshift < 0 ) *** pnm/pnmtoxwd.c.orig Mon Oct 4 05:12:00 1993 --- pnm/pnmtoxwd.c Sat May 18 17:05:16 1996 *************** *** 232,240 **** /* Stupid hack because xloadimage and xwud disagree on ** how to interpret bitmaps. */ if ( PNM_FORMAT_TYPE(format) == PBM_TYPE ) ! color.red = (long) ( colors-1-i ) * 65535L / ( colors - 1 ); else ! color.red = (long) i * 65535L / ( colors - 1 ); color.green = color.red; color.blue = color.red; --- 232,241 ---- /* Stupid hack because xloadimage and xwud disagree on ** how to interpret bitmaps. */ if ( PNM_FORMAT_TYPE(format) == PBM_TYPE ) ! color.red = (long) PGM_DEPTH( colors - 1 - i, ! colors - 1, 65535L ); else ! color.red = (long) PGM_DEPTH( i, colors - 1, 65535L ); color.green = color.red; color.blue = color.red; *************** *** 246,254 **** color.blue = PPM_GETB( chv[i].color ); if ( lmaxval != 65535L ) { ! color.red = (long) color.red * 65535L / lmaxval; ! color.green = (long) color.green * 65535L / lmaxval; ! color.blue = (long) color.blue * 65535L / lmaxval; } } pm_writebiglong( stdout, color.num ); --- 247,258 ---- color.blue = PPM_GETB( chv[i].color ); if ( lmaxval != 65535L ) { ! color.red = (long) PGM_DEPTH( color.red, ! lmaxval, 65535L ); ! color.green = (long) PGM_DEPTH( color.green, ! lmaxval, 65535L ); ! color.blue = (long) PGM_DEPTH( color.blue, ! lmaxval, 65535L ); } } pm_writebiglong( stdout, color.num ); *************** *** 271,279 **** { unsigned long ul; ! ul = ( ( PPM_GETR( *xP ) * xmaxval / lmaxval ) << 16 ) | ! ( ( PPM_GETG( *xP ) * xmaxval / lmaxval ) << 8 ) | ! ( PPM_GETB( *xP ) * xmaxval / lmaxval ); fwrite( &ul, sizeof(ul), 1, stdout ); } break; --- 275,283 ---- { unsigned long ul; ! ul = (PGM_DEPTH( PPM_GETR( *xP ), lmaxval, xmaxval ) << 16) ! | (PGM_DEPTH( PPM_GETG( *xP ), lmaxval, xmaxval ) << 8) ! | (PGM_DEPTH( PPM_GETB( *xP ), lmaxval, xmaxval ) ); fwrite( &ul, sizeof(ul), 1, stdout ); } break; *************** *** 285,293 **** register unsigned long val; val = PNM_GET1( *xP ); ! ul = ( ( val * xmaxval / lmaxval ) << 16 ) | ! ( ( val * xmaxval / lmaxval ) << 8 ) | ! ( val * xmaxval / lmaxval ); fwrite( &ul, sizeof(ul), 1, stdout ); } break; --- 289,298 ---- register unsigned long val; val = PNM_GET1( *xP ); ! ! ul = (PGM_DEPTH( PPM_GETR( *xP ), lmaxval, xmaxval ) << 16) ! | (PGM_DEPTH( PPM_GETG( *xP ), lmaxval, xmaxval ) << 8) ! | (PGM_DEPTH( PPM_GETB( *xP ), lmaxval, xmaxval ) ); fwrite( &ul, sizeof(ul), 1, stdout ); } break; *************** *** 312,318 **** s = 1 - s; if ( maxval != bigger_maxval ) ! s = (long) s * bigger_maxval / maxval; byte |= s << bitshift; bitshift -= h11.bits_per_pixel; if ( bitshift < 0 ) --- 317,323 ---- s = 1 - s; if ( maxval != bigger_maxval ) ! s = (long) PGM_DEPTH( s, maxval, bigger_maxval ); byte |= s << bitshift; bitshift -= h11.bits_per_pixel; if ( bitshift < 0 ) *** pnm/xwdtopnm.c.orig Mon Oct 4 05:12:03 1993 --- pnm/xwdtopnm.c Sun May 19 01:09:28 1996 *************** *** 216,226 **** if ( *maxvalP != 65535L ) { x10colors[i].red = ! (long) x10colors[i].red * (long) *maxvalP / 65535L; x10colors[i].green = ! (long) x10colors[i].green * (long) *maxvalP / 65535L; x10colors[i].blue = ! (long) x10colors[i].blue * (long) *maxvalP / 65535L; } if ( x10colors[i].red != x10colors[i].green || x10colors[i].green != x10colors[i].blue ) --- 216,229 ---- if ( *maxvalP != 65535L ) { x10colors[i].red = ! (long) PGM_DEPTH( x10colors[i].red, ! 65535L, (long) *maxvalP ); x10colors[i].green = ! (long) PGM_DEPTH( x10colors[i].green, ! 65535L, (long) *maxvalP ); x10colors[i].blue = ! (long) PGM_DEPTH( x10colors[i].blue, ! 65535L, (long) *maxvalP ); } if ( x10colors[i].red != x10colors[i].green || x10colors[i].green != x10colors[i].blue ) *************** *** 365,375 **** if ( *maxvalP != 65535L ) { x11colors[i].red = ! (long) x11colors[i].red * (long) *maxvalP / 65535L; x11colors[i].green = ! (long) x11colors[i].green * (long) *maxvalP / 65535L; x11colors[i].blue = ! (long) x11colors[i].blue * (long) *maxvalP / 65535L; } if ( x11colors[i].red != x11colors[i].green || x11colors[i].green != x11colors[i].blue ) --- 368,381 ---- if ( *maxvalP != 65535L ) { x11colors[i].red = ! (long) PGM_DEPTH( x11colors[i].red, ! 65535L, (long) *maxvalP ); x11colors[i].green = ! (long) PGM_DEPTH( x11colors[i].green, ! 65535L, (long) *maxvalP ); x11colors[i].blue = ! (long) PGM_DEPTH( x11colors[i].blue, ! 65535L, (long) *maxvalP ); } if ( x11colors[i].red != x11colors[i].green || x11colors[i].green != x11colors[i].blue )