home *** CD-ROM | disk | FTP | other *** search
Wrap
Text File | 1991-11-06 | 46.8 KB | 1,614 lines
Newsgroups: comp.sources.misc From: jef@well.sf.ca.us (Jef Poskanzer) Subject: v25i033: pbmplus - Extended Portable Bitmap Toolkit, Patch30oct91 Message-ID: <1991Nov6.045135.7889@sparky.imd.sterling.com> X-Md4-Signature: cc2fa676b351c753487f8f7449cf19aa Date: Wed, 6 Nov 1991 04:51:35 GMT Approved: kent@sparky.imd.sterling.com Submitted-by: jef@well.sf.ca.us (Jef Poskanzer) Posting-number: Volume 25, Issue 33 Archive-name: pbmplus/patch30oct91 Environment: UNIX Patch-To: pbmplus: Volume 23, Issue 36-59, 60 A couple more bugs in the tiff reader, a bug in run-length encoded color PostScript, and a few enhancements. This new version is dated 30oct91. If you have the 05oct91 version you can update with the appended patch file. Or, you can FTP the new version complete from: export.lcs.mit.edu:contrib/pbmplus30oct91.tar.Z (18.24.0.12) ftp.ee.lbl.gov:pbmplus30oct91.tar.Z (128.3.112.20) Jef Poskanzer jef@well.sf.ca.us apple!well!jef - - - - - - - - - - diff -cr pbmplus05oct91/CHANGES pbmplus30oct91/CHANGES *** pbmplus05oct91/CHANGES Sat Oct 5 23:51:13 1991 --- pbmplus30oct91/CHANGES Wed Oct 30 13:03:49 1991 *************** *** 1,3 **** --- 1,18 ---- + Changes since the 05oct91 X11R5 contrib tape version: + + Fixed minor SysV config error in pbmplus.h. (Tom Lane) + Fixed tifftopnm so that BITSPERSAMPLE and SAMPLESPERPIXEL default + correctly. Fixed possible bug in tgatoppm line-interleaving code. + (Arthur David Olson) + Fixed tifftopnm so that colormapped files are read correctly. + (PauL Drews, Mike Wade) + Corrected use of DefaultRGBDatabase / RGB_DB for imake sites. + (Randal L. Schwartz) + Bugfix to pnmtops color PostScript in -rle mode. (Angus Duggan) + Added auto-turning to pnmtops. + Added run-length encoding to ppmtotga. + Space optimization to pgmoil. + Changes since the 27sep91 comp.sources.misc distribution: Fixed spelling error in giftoppm. Fixed ppmrelief to not shrink the diff -cr pbmplus05oct91/Makefile pbmplus30oct91/Makefile *** pbmplus05oct91/Makefile Fri Sep 27 17:45:46 1991 --- pbmplus30oct91/Makefile Wed Oct 30 20:13:49 1991 *************** *** 35,41 **** # path here. This is used by PPM to parse color names into rgb values. # If you don't have such a file, comment this out and use the alternative # hex and decimal forms to specify colors (see ppm/pgmtoppm.1 for details). ! RGBDEF = -DRGB_DB=\"/usr/lib/X11/rgb.txt\" # CONFIGURE: PBMPLUS's support for TIFF files depends on the library from # Sam Leffler's TIFF Software package - see the OTHER.SYSTEMS file for a --- 35,41 ---- # path here. This is used by PPM to parse color names into rgb values. # If you don't have such a file, comment this out and use the alternative # hex and decimal forms to specify colors (see ppm/pgmtoppm.1 for details). ! RGBDEF = -DRGB_DB=\"/usr/lib/X11/rgb\" # CONFIGURE: PBMPLUS's support for TIFF files depends on the library from # Sam Leffler's TIFF Software package - see the OTHER.SYSTEMS file for a diff -cr pbmplus05oct91/README pbmplus30oct91/README *** pbmplus05oct91/README Sat Oct 5 22:36:16 1991 --- pbmplus30oct91/README Wed Oct 30 20:11:16 1991 *************** *** 1,6 **** Extended Portable Bitmap Toolkit ! Distribution of 05oct91 ! Previous distribution 27sep91 PBMPLUS is a toolkit for converting various image formats to and from --- 1,6 ---- Extended Portable Bitmap Toolkit ! Distribution of 30oct91 ! Previous distribution 05oct91 PBMPLUS is a toolkit for converting various image formats to and from diff -cr pbmplus05oct91/TODO pbmplus30oct91/TODO *** pbmplus05oct91/TODO Fri Sep 27 12:40:08 1991 --- pbmplus30oct91/TODO Thu Oct 24 13:29:41 1991 *************** *** 18,24 **** Figure out why compiling pnmconvol makes gcc die on some systems. Convert to line-by-line mode: ! pbmtext.c pbmtoascii.c pbmtoepson.c pbmtomacp.c pbmtoplot.c The Converter Generator reorganization: all filters become three library routines, one to initialize, one to handle each line, and one to finish off. --- 18,24 ---- Figure out why compiling pnmconvol makes gcc die on some systems. Convert to line-by-line mode: ! pbmtext.c pbmtoascii.c pbmtoepson.c pbmtomacp.c pbmtoplot.c pgmoil.c The Converter Generator reorganization: all filters become three library routines, one to initialize, one to handle each line, and one to finish off. diff -cr pbmplus05oct91/pbmplus.h pbmplus30oct91/pbmplus.h *** pbmplus05oct91/pbmplus.h Mon Sep 23 15:03:08 1991 --- pbmplus30oct91/pbmplus.h Sun Oct 6 09:32:33 1991 *************** *** 95,105 **** --- 95,107 ---- #define bzero(dst,len) memset(dst,0,len) #define bcopy(src,dst,len) memcpy(dst,src,len) #define bcmp memcmp + extern void srand(); extern int rand(); #else /*SYSV*/ #include <strings.h> + extern void srandom(); extern long random(); #endif /*SYSV*/ *************** *** 106,112 **** extern int atoi(); extern void exit(); - extern void srandom(); extern long time(); extern int write(); --- 108,113 ---- diff -cr pbmplus05oct91/version.h pbmplus30oct91/version.h *** pbmplus05oct91/version.h Sat Oct 5 22:35:33 1991 --- pbmplus30oct91/version.h Wed Oct 30 20:11:25 1991 *************** *** 1,4 **** /* version.h - define the current version of PBM, PGM, PPM, and PNM */ ! #define PBMPLUS_VERSION "05oct91" --- 1,4 ---- /* version.h - define the current version of PBM, PGM, PPM, and PNM */ ! #define PBMPLUS_VERSION "30oct91" diff -cr pbmplus05oct91/pbm/Makefile pbmplus30oct91/pbm/Makefile *** pbmplus05oct91/pbm/Makefile Fri Sep 27 12:32:47 1991 --- pbmplus30oct91/pbm/Makefile Thu Oct 24 13:34:36 1991 *************** *** 15,21 **** #CFLAGS = -O CFLAGS = -g #CFLAGS = -g -O ! RGBDEF = -DRGB_DB=\"/usr/lib/X11/rgb.txt\" TIFFDEF = -DLIBTIFF #LDFLAGS = -s LDFLAGS = --- 15,21 ---- #CFLAGS = -O CFLAGS = -g #CFLAGS = -g -O ! RGBDEF = -DRGB_DB=\"/usr/lib/X11/rgb\" TIFFDEF = -DLIBTIFF #LDFLAGS = -s LDFLAGS = diff -cr pbmplus05oct91/pgm/pgmoil.c pbmplus30oct91/pgm/pgmoil.c *** pbmplus05oct91/pgm/pgmoil.c Fri Jun 28 14:29:28 1991 --- pbmplus30oct91/pgm/pgmoil.c Wed Oct 30 13:04:36 1991 *************** *** 17,29 **** void main( argc, argv ) ! int argc; ! char* argv[]; { FILE* ifp; gray midval, maxval; ! gray** gin; ! gray** gout; int argn, rows, n, cols, row; register int col, drow, dcol; int i; --- 17,29 ---- void main( argc, argv ) ! int argc; ! char* argv[]; { FILE* ifp; gray midval, maxval; ! gray** grays; ! gray* grayrow; int argn, rows, n, cols, row; register int col, drow, dcol; int i; *************** *** 59,78 **** if ( argn != argc ) pm_usage( usage ); ! gin = pgm_readpgm( ifp, &cols, &rows, &maxval ); pm_close( ifp ); - gout = pgm_allocarray( cols, rows ); ! /* Build histogram. */ ! for ( row = n; row < rows - n; ++row ) ! for ( col = n; col < cols - n; ++col ) { for ( i = 0; i <= maxval; ++i ) hist[i] = 0; for ( drow = row - n; drow <= row + n; ++drow ) ! for ( dcol = col - n; dcol <= col + n; ++dcol ) ! ++hist[ (int) (gin[drow][dcol]) ]; for ( drow = dcol = 0; dcol < maxval; ++dcol ) if ( hist[dcol] > drow ) --- 59,82 ---- if ( argn != argc ) pm_usage( usage ); ! grays = pgm_readpgm( ifp, &cols, &rows, &maxval ); pm_close( ifp ); ! pgm_writepgminit( stdout, cols, rows, maxval, 0 ); ! grayrow = pgm_allocrow( cols ); ! ! for ( row = 0; row < rows; ++row ) ! { ! for ( col = 0; col < cols; ++col ) { for ( i = 0; i <= maxval; ++i ) hist[i] = 0; for ( drow = row - n; drow <= row + n; ++drow ) ! if ( drow >= 0 && drow < rows ) ! for ( dcol = col - n; dcol <= col + n; ++dcol ) ! if ( dcol >= 0 && dcol < cols ) ! ++hist[ (int) (grays[drow][dcol]) ]; for ( drow = dcol = 0; dcol < maxval; ++dcol ) if ( hist[dcol] > drow ) *************** *** 80,90 **** drow = hist[dcol]; midval = dcol; } ! gout[row][col] = midval; } ! ! pgm_writepgm( stdout, gout, cols, rows, maxval, 0 ); ! pgm_freearray( gout, rows ); exit( 0 ); } --- 84,93 ---- drow = hist[dcol]; midval = dcol; } ! grayrow[col] = midval; } ! pgm_writepgmrow( stdout, grayrow, cols, maxval, 0 ); ! } exit( 0 ); } diff -cr pbmplus05oct91/pnm/pnmmargin.1 pbmplus30oct91/pnm/pnmmargin.1 *** pbmplus05oct91/pnm/pnmmargin.1 Tue Jun 4 14:12:41 1991 --- pbmplus30oct91/pnm/pnmmargin.1 Fri Oct 25 13:23:16 1991 *************** *** 1,7 **** .TH pnmmargin 1 "9 January 1991" .IX pnmmargin .SH NAME ! pnmmargin - add a margin to a portable anymap .SH SYNOPSIS .B pnmmargin .RB [ -white | -black | -color --- 1,7 ---- .TH pnmmargin 1 "9 January 1991" .IX pnmmargin .SH NAME ! pnmmargin - add a border to a portable anymap .SH SYNOPSIS .B pnmmargin .RB [ -white | -black | -color *************** *** 10,21 **** .RI [ pnmfile ] .SH DESCRIPTION Reads a portable anymap as input. ! Adds a margin of the specified number of pixels, and produces a portable anymap as output. .IX margin .SH OPTIONS .PP ! You can specify the margin color with the .BR -white , .BR -black , and --- 10,22 ---- .RI [ pnmfile ] .SH DESCRIPTION Reads a portable anymap as input. ! Adds a border of the specified number of pixels, and produces a portable anymap as output. .IX margin + .IX border .SH OPTIONS .PP ! You can specify the border color with the .BR -white , .BR -black , and diff -cr pbmplus05oct91/pnm/pnmtops.1 pbmplus30oct91/pnm/pnmtops.1 *** pbmplus05oct91/pnm/pnmtops.1 Fri Sep 27 00:20:28 1991 --- pbmplus30oct91/pnm/pnmtops.1 Sat Oct 26 15:15:16 1991 *************** *** 1,12 **** ! .TH pnmtops 1 "26 September 1991" .IX pnmtops .SH NAME pnmtops - convert portable anymap to PostScript .SH SYNOPSIS .B pnmtops - .RB [ -rle | -runlength ] .RB [ -scale .IR s ] .RB [ -dpi .IR n ] .RB [ -width --- 1,13 ---- ! .TH pnmtops 1 "26 October 1991" .IX pnmtops .SH NAME pnmtops - convert portable anymap to PostScript .SH SYNOPSIS .B pnmtops .RB [ -scale .IR s ] + .RB [ -turn | -noturn ] + .RB [ -rle | -runlength ] .RB [ -dpi .IR n ] .RB [ -width *************** *** 46,51 **** --- 47,67 ---- To get one PNM pixel per 300 dpi printer pixel, use "-scale 0.25". .PP The + .B -turn + and + .B -noturn + flags control whether the image gets turned 90 degrees. + Normally, if an image is wider than it is tall, it gets turned + automatically to better fit the page. + If the + .B -turn + flag is specified, it will be turned no matter what its shape; and if the + .B -noturn + flag is specified, it will + .I not + be turned no matter what its shape. + .PP + The .B -rle or .B -runlength *************** *** 74,82 **** All flags can be abbreviated to their shortest unique prefix. .SH "SEE ALSO" pnm(5), psidtopgm(1) - .SH BUGS - It ought to automatically rotate to landscape mode if that would fit - the image better. .SH AUTHOR Copyright (C) 1989, 1991 by Jef Poskanzer. .\" Permission to use, copy, modify, and distribute this software and its --- 90,95 ---- diff -cr pbmplus05oct91/pnm/pnmtops.c pbmplus30oct91/pnm/pnmtops.c *** pbmplus05oct91/pnm/pnmtops.c Fri Sep 27 12:07:53 1991 --- pbmplus30oct91/pnm/pnmtops.c Sat Oct 26 15:16:56 1991 *************** *** 14,20 **** #define MARGIN 0.95 ! static void putinit ARGS(( char* name, int cols, int rows, int padright, int bps, float scale, int dpi, int pagewid, int pagehgt, int format, int rleflag )); static void putitem ARGS(( void )); static void putxelval ARGS(( xelval xv )); static void putrest ARGS(( void )); --- 14,20 ---- #define MARGIN 0.95 ! static void putinit ARGS(( char* name, int cols, int rows, int padright, int bps, float scale, int dpi, int pagewid, int pagehgt, int format, int turnflag, int turnokflag, int rleflag )); static void putitem ARGS(( void )); static void putxelval ARGS(( xelval xv )); static void putrest ARGS(( void )); *************** *** 32,50 **** FILE* ifp; xel* xelrow; register xel* xP; ! int argn, rleflag, rows, cols, format, bps, padright, row, col; xelval maxval, nmaxval; float scale, f; int dpi, pagewid, pagehgt; char name[100]; char* cp; ! char* usage = "[-rle|-runlength] [-scale <x>] [-dpi <n>] [-width <n>] [-height <n>] [pnmfile]"; pnm_init( &argc, argv ); argn = 1; - rleflag = 0; scale = 1.0; /* LaserWriter defaults. */ dpi = 300; pagewid = 612; --- 32,53 ---- FILE* ifp; xel* xelrow; register xel* xP; ! int argn, turnflag, turnokflag, rleflag; ! int rows, cols, format, bps, padright, row, col; xelval maxval, nmaxval; float scale, f; int dpi, pagewid, pagehgt; char name[100]; char* cp; ! char* usage = "[-scale <x>] [-turn|-noturn] [-rle|-runlength] [-dpi <n>] [-width <n>] [-height <n>] [-rle|-runlength] [pnmfile]"; pnm_init( &argc, argv ); argn = 1; scale = 1.0; + turnflag = 0; + turnokflag = 1; + rleflag = 0; /* LaserWriter defaults. */ dpi = 300; pagewid = 612; *************** *** 53,70 **** /* Check for flags. */ while ( argn < argc && argv[argn][0] == '-' && argv[argn][1] != '\0' ) { ! if ( pm_keymatch( argv[argn], "-rle", 2 ) || ! pm_keymatch( argv[argn], "-runlength", 2 ) ) ! rleflag = 1; ! else if ( pm_keymatch( argv[argn], "-norle", 2 ) || ! pm_keymatch( argv[argn], "-norunlength", 2 ) ) ! rleflag = 0; ! else if ( pm_keymatch( argv[argn], "-scale", 2 ) ) { ++argn; if ( argn == argc || sscanf( argv[argn], "%f", &scale ) != 1 ) pm_usage( usage ); } else if ( pm_keymatch( argv[argn], "-dpi", 2 ) ) { ++argn; --- 56,74 ---- /* Check for flags. */ while ( argn < argc && argv[argn][0] == '-' && argv[argn][1] != '\0' ) { ! if ( pm_keymatch( argv[argn], "-scale", 2 ) ) { ++argn; if ( argn == argc || sscanf( argv[argn], "%f", &scale ) != 1 ) pm_usage( usage ); } + else if ( pm_keymatch( argv[argn], "-turn", 2 ) ) + turnflag = 1; + else if ( pm_keymatch( argv[argn], "-noturn", 2 ) ) + turnokflag = 0; + else if ( pm_keymatch( argv[argn], "-rle", 2 ) || + pm_keymatch( argv[argn], "-runlength", 2 ) ) + rleflag = 1; else if ( pm_keymatch( argv[argn], "-dpi", 2 ) ) { ++argn; *************** *** 128,134 **** putinit( name, cols, rows, padright, bps, scale, dpi, pagewid, pagehgt, format, ! rleflag ); for ( row = 0; row < rows; ++row ) { pnm_readpnmrow( ifp, xelrow, cols, maxval, format ); --- 132,138 ---- putinit( name, cols, rows, padright, bps, scale, dpi, pagewid, pagehgt, format, ! turnflag, turnokflag, rleflag ); for ( row = 0; row < rows; ++row ) { pnm_readpnmrow( ifp, xelrow, cols, maxval, format ); *************** *** 150,155 **** --- 154,161 ---- rleputxelval( 0 ); else putxelval( 0 ); + if ( rleflag ) + rleflush(); /* Then green. */ for ( col = 0, xP = xelrow; col < cols; ++col, ++xP ) if ( rleflag ) *************** *** 161,166 **** --- 167,174 ---- rleputxelval( 0 ); else putxelval( 0 ); + if ( rleflag ) + rleflush(); /* And blue. */ for ( col = 0, xP = xelrow; col < cols; ++col, ++xP ) if ( rleflag ) *************** *** 213,231 **** #if __STDC__ static void ! putinit( char* name, int cols, int rows, int padright, int bps, float scale, int dpi, int pagewid, int pagehgt, int format, int rleflag ) #else /*__STDC__*/ static void ! putinit( name, cols, rows, padright, bps, scale, dpi, pagewid, pagehgt, format, rleflag ) char* name; int cols, rows, padright, bps; float scale; ! int dpi, pagewid, pagehgt, format, rleflag; #endif /*__STDC__*/ { ! int devpix; float pixfac, scols, srows, llx, lly; devpix = dpi / 72.0 + 0.5; /* device pixels per unit, approx. */ pixfac = 72.0 / dpi * devpix; /* 1, approx. */ scols = scale * cols * pixfac; --- 221,253 ---- #if __STDC__ static void ! putinit( char* name, int cols, int rows, int padright, int bps, float scale, ! int dpi, int pagewid, int pagehgt, int format, int turnflag, ! int turnokflag, int rleflag ) #else /*__STDC__*/ static void ! putinit( name, cols, rows, padright, bps, scale, dpi, pagewid, pagehgt, format, ! turnflag, turnokflag, rleflag ) char* name; int cols, rows, padright, bps; float scale; ! int dpi, pagewid, pagehgt, format, turnflag, turnokflag, rleflag; #endif /*__STDC__*/ { ! int icols, irows, devpix; float pixfac, scols, srows, llx, lly; + /* Turn? */ + icols = cols; + irows = rows; + if ( turnflag || ( turnokflag && cols > rows ) ) + { + turnflag = 1; + cols = irows; + rows = icols; + } + + /* Figure out size. */ devpix = dpi / 72.0 + 0.5; /* device pixels per unit, approx. */ pixfac = 72.0 / dpi * devpix; /* 1, approx. */ scols = scale * cols * pixfac; *************** *** 302,320 **** } if ( PNM_FORMAT_TYPE( format ) == PPM_TYPE ) { ! printf( "/rpicstr %d string def\n", ( cols + padright ) * bps / 8 ); ! printf( "/gpicstr %d string def\n", ( cols + padright ) * bps / 8 ); ! printf( "/bpicstr %d string def\n", ( cols + padright ) * bps / 8 ); } else ! printf( "/picstr %d string def\n", ( cols + padright ) * bps / 8 ); printf( "%%%%EndProlog\n" ); printf( "%%%%Page: 1 1\n" ); printf( "gsave\n" ); printf( "%g %g translate\n", llx, lly ); printf( "%g %g scale\n", scols, srows ); ! printf( "%d %d %d\n", cols, rows, bps ); ! printf( "[ %d 0 0 -%d 0 %d ]\n", cols, rows, rows ); if ( PNM_FORMAT_TYPE( format ) == PPM_TYPE ) { printf( "{ rpicstr readstring }\n" ); --- 324,344 ---- } if ( PNM_FORMAT_TYPE( format ) == PPM_TYPE ) { ! printf( "/rpicstr %d string def\n", ( icols + padright ) * bps / 8 ); ! printf( "/gpicstr %d string def\n", ( icols + padright ) * bps / 8 ); ! printf( "/bpicstr %d string def\n", ( icols + padright ) * bps / 8 ); } else ! printf( "/picstr %d string def\n", ( icols + padright ) * bps / 8 ); printf( "%%%%EndProlog\n" ); printf( "%%%%Page: 1 1\n" ); printf( "gsave\n" ); printf( "%g %g translate\n", llx, lly ); printf( "%g %g scale\n", scols, srows ); ! if ( turnflag ) ! printf( "0.5 0.5 translate 90 rotate -0.5 -0.5 translate\n" ); ! printf( "%d %d %d\n", icols, irows, bps ); ! printf( "[ %d 0 0 -%d 0 %d ]\n", icols, irows, irows ); if ( PNM_FORMAT_TYPE( format ) == PPM_TYPE ) { printf( "{ rpicstr readstring }\n" ); diff -cr pbmplus05oct91/pnm/tifftopnm.c pbmplus30oct91/pnm/tifftopnm.c *** pbmplus05oct91/pnm/tifftopnm.c Sun Oct 6 01:11:11 1991 --- pbmplus30oct91/pnm/tifftopnm.c Thu Oct 24 16:10:55 1991 *************** *** 46,54 **** register u_char sample; register int bitsleft; unsigned short bps, spp, photomet; ! unsigned short** redcolormap; ! unsigned short** greencolormap; ! unsigned short** bluecolormap; char* usage = "[-headerdump] [tifffile]"; pnm_init( &argc, argv ); --- 46,54 ---- register u_char sample; register int bitsleft; unsigned short bps, spp, photomet; ! unsigned short* redcolormap; ! unsigned short* greencolormap; ! unsigned short* bluecolormap; char* usage = "[-headerdump] [tifffile]"; pnm_init( &argc, argv ); *************** *** 86,94 **** TIFFPrintDirectory( tif, stderr, TIFFPRINT_NONE ); if ( ! TIFFGetField( tif, TIFFTAG_BITSPERSAMPLE, &bps ) ) ! pm_error( "error getting bits per sample" ); if ( ! TIFFGetField( tif, TIFFTAG_SAMPLESPERPIXEL, &spp ) ) ! pm_error( "error getting samples per pixel" ); if ( ! TIFFGetField( tif, TIFFTAG_PHOTOMETRIC, &photomet ) ) pm_error( "error getting photometric" ); --- 86,94 ---- TIFFPrintDirectory( tif, stderr, TIFFPRINT_NONE ); if ( ! TIFFGetField( tif, TIFFTAG_BITSPERSAMPLE, &bps ) ) ! bps = 1; if ( ! TIFFGetField( tif, TIFFTAG_SAMPLESPERPIXEL, &spp ) ) ! spp = 1; if ( ! TIFFGetField( tif, TIFFTAG_PHOTOMETRIC, &photomet ) ) pm_error( "error getting photometric" ); diff -cr pbmplus05oct91/ppm/Makefile pbmplus30oct91/ppm/Makefile *** pbmplus05oct91/ppm/Makefile Fri Sep 27 12:35:05 1991 --- pbmplus30oct91/ppm/Makefile Thu Oct 24 13:34:40 1991 *************** *** 15,21 **** #CFLAGS = -O CFLAGS = -g #CFLAGS = -g -O ! RGBDEF = -DRGB_DB=\"/usr/lib/X11/rgb.txt\" #LDFLAGS = -s LDFLAGS = INSTALLBINARIES = /usr/new/pbm --- 15,21 ---- #CFLAGS = -O CFLAGS = -g #CFLAGS = -g -O ! RGBDEF = -DRGB_DB=\"/usr/lib/X11/rgb\" #LDFLAGS = -s LDFLAGS = INSTALLBINARIES = /usr/new/pbm diff -cr pbmplus05oct91/ppm/libppm4.c pbmplus30oct91/ppm/libppm4.c *** pbmplus05oct91/ppm/libppm4.c Sat Oct 5 23:37:10 1991 --- pbmplus30oct91/ppm/libppm4.c Sat Oct 26 00:14:45 1991 *************** *** 202,208 **** FILE* f; char buf1[200], buf2[200]; ! if ( ( f = fopen( RGB_DB, "r" ) ) == NULL ) pm_error( "can't open color names database - reconfigure with correct RGBDEF" ); canonstr( colorname ); while ( fgets( buf1, sizeof(buf1), f ) != NULL ) --- 202,209 ---- FILE* f; char buf1[200], buf2[200]; ! (void) sprintf( buf1, "%s.txt", RGB_DB ); ! if ( ( f = fopen( buf1, "r" ) ) == NULL ) pm_error( "can't open color names database - reconfigure with correct RGBDEF" ); canonstr( colorname ); while ( fgets( buf1, sizeof(buf1), f ) != NULL ) *************** *** 272,278 **** } #ifdef RGB_DB ! if ( ( f = fopen( RGB_DB, "r" ) ) == NULL ) pm_error( "can't open color names database - reconfigure with correct RGBDEF" ); best_diff = 32767; while ( fgets( buf, sizeof(buf), f ) != NULL ) --- 273,280 ---- } #ifdef RGB_DB ! (void) sprintf( buf, "%s.txt", RGB_DB ); ! if ( ( f = fopen( buf, "r" ) ) == NULL ) pm_error( "can't open color names database - reconfigure with correct RGBDEF" ); best_diff = 32767; while ( fgets( buf, sizeof(buf), f ) != NULL ) diff -cr pbmplus05oct91/ppm/ppmtotga.1 pbmplus30oct91/ppm/ppmtotga.1 *** pbmplus05oct91/ppm/ppmtotga.1 Thu Sep 26 17:16:38 1991 --- pbmplus30oct91/ppm/ppmtotga.1 Wed Oct 30 09:37:56 1991 *************** *** 1,4 **** ! .TH ppmtotga 1 "26 August 1989" .IX ppmtotga .SH NAME ppmtotga - convert portable pixmap into a TrueVision Targa file --- 1,4 ---- ! .TH ppmtotga 1 "28 October 1991" .IX ppmtotga .SH NAME ppmtotga - convert portable pixmap into a TrueVision Targa file *************** *** 5,10 **** --- 5,11 ---- .SH SYNOPSIS .B ppmtotga .RB [ -mono|-cmap|-rgb ] + .RB [ -norle ] .RI [ ppmfile ] .SH DESCRIPTION Reads a portable pixmap as input. *************** *** 22,27 **** --- 23,32 ---- .TP .B -rgb Forces Targa file to be of type 24 bit unmapped color. + .TP + .B -norle + Disables run-length encoding, in case you have a Targa reader which + can't read run-length encoded files. .PP All flags can be abbreviated to their shortest unique prefix. If no file type is specified the most highly constained compatible type is *************** *** 33,39 **** .SH "SEE ALSO" tgatoppm(1), ppm(5) .SH AUTHOR ! Copyright (C) 1991 by Mark Shand. .\" Permission to use, copy, modify, and distribute this software and its .\" documentation for any purpose and without fee is hereby granted, provided .\" that the above copyright notice appear in all copies and that both that --- 38,44 ---- .SH "SEE ALSO" tgatoppm(1), ppm(5) .SH AUTHOR ! Copyright (C) 1989, 1991 by Mark Shand and Jef Poskanzer. .\" Permission to use, copy, modify, and distribute this software and its .\" documentation for any purpose and without fee is hereby granted, provided .\" that the above copyright notice appear in all copies and that both that diff -cr pbmplus05oct91/ppm/ppmtotga.c pbmplus30oct91/ppm/ppmtotga.c *** pbmplus05oct91/ppm/ppmtotga.c Thu Sep 26 17:16:14 1991 --- pbmplus30oct91/ppm/ppmtotga.c Wed Oct 30 10:56:22 1991 *************** *** 1,6 **** /* ppmtotga.c - read a portable pixmap and produce a TrueVision Targa file ** ! ** Copyright (C) 1991 by Mark Shand ** ** Permission to use, copy, modify, and distribute this software and its ** documentation for any purpose and without fee is hereby granted, provided --- 1,6 ---- /* ppmtotga.c - read a portable pixmap and produce a TrueVision Targa file ** ! ** Copyright (C) 1989, 1991 by Mark Shand and Jef Poskanzer ** ** Permission to use, copy, modify, and distribute this software and its ** documentation for any purpose and without fee is hereby granted, provided *************** *** 10,23 **** ** implied warranty. */ - #include <ctype.h> #include "ppm.h" #include "ppmcmap.h" #include "tga.h" ! /* Max number of colors allowed in ppm input. */ #define MAXCOLORS 256 void main( argc, argv ) int argc; --- 10,33 ---- ** implied warranty. */ #include "ppm.h" #include "ppmcmap.h" #include "tga.h" ! /* Max number of colors allowed for colormapped output. */ #define MAXCOLORS 256 + /* Forward routines. */ + static void writetga ARGS(( struct ImageHeader* tgaP, char* id )); + static void put_map_entry ARGS(( pixel* valueP, int size, pixval maxval )); + static void compute_runlengths ARGS(( int cols, pixel* pixelrow, int* runlength )); + static void put_pixel ARGS(( pixel* pP, int imgtype, pixval maxval, colorhash_table cht )); + static void put_mono ARGS(( pixel* pP, pixval maxval )); + static void put_map ARGS(( pixel* pP, colorhash_table cht )); + static void put_rgb ARGS(( pixel* pP, pixval maxval )); + + /* Routines. */ + void main( argc, argv ) int argc; *************** *** 26,47 **** FILE* ifp; pixel** pixels; register pixel* pP; ! int argn, rows, cols, ncolors, row, col, i, format, realrow; pixval maxval; - colorhash_table cht; colorhist_vector chv; char out_name[100]; char* cp; ! char* usage = "[-name <tganame>] [-mono|-cmap|-rgb] [ppmfile]"; struct ImageHeader tgaHeader; ppm_init( &argc, argv ); out_name[0] = '\0'; argn = 1; - tgaHeader.ImgType = TGA_Null; ! /* Check for command line options. */ while ( argn < argc && argv[argn][0] == '-' && argv[argn][1] != '\0' ) { if ( pm_keymatch( argv[argn], "-name", 2 ) ) --- 36,59 ---- FILE* ifp; pixel** pixels; register pixel* pP; ! pixel p; ! int argn, rle_flag, rows, cols, ncolors, row, col, i, format, realrow; pixval maxval; colorhist_vector chv; + colorhash_table cht; char out_name[100]; char* cp; ! int* runlength; ! char* usage = "[-name <tganame>] [-mono|-cmap|-rgb] [-norle] [ppmfile]"; struct ImageHeader tgaHeader; ppm_init( &argc, argv ); out_name[0] = '\0'; + /* Check for command line options. */ argn = 1; tgaHeader.ImgType = TGA_Null; ! rle_flag = 1; while ( argn < argc && argv[argn][0] == '-' && argv[argn][1] != '\0' ) { if ( pm_keymatch( argv[argn], "-name", 2 ) ) *************** *** 57,62 **** --- 69,76 ---- tgaHeader.ImgType = TGA_Mono; else if ( pm_keymatch( argv[argn], "-rgb", 2 ) ) tgaHeader.ImgType = TGA_RGB; + else if ( pm_keymatch( argv[argn], "-norle", 2 ) ) + rle_flag = 0; else pm_usage( usage ); ++argn; *************** *** 93,287 **** /* Read in the ppm file. */ ppm_readppminit( ifp, &cols, &rows, &maxval, &format); ! pixels = ppm_allocarray(cols, rows); ! for (row = 0; row < rows; row++) ! ppm_readppmrow(ifp, pixels[row], cols, maxval, format); pm_close( ifp ); /* Figure out the colormap. */ ! switch (PPM_FORMAT_TYPE(format)) ! { case PPM_TYPE: ! if (tgaHeader.ImgType == TGA_Mono) ! pm_error("input not a graymap, filter through ppmtopgm first"); ! if (tgaHeader.ImgType == TGA_Null || tgaHeader.ImgType == TGA_Map) ! { ! pm_message( "computing colormap..." ); ! chv = ppm_computecolorhist( pixels, cols, rows, MAXCOLORS, &ncolors ); ! if ( chv == (colorhist_vector) 0 ) ! { ! if (tgaHeader.ImgType == TGA_Map) ! pm_error( ! "too many colors - try doing a 'ppmquant %d'", ! MAXCOLORS); ! else ! tgaHeader.ImgType = TGA_RGB; ! } ! else ! { ! pm_message( "%d colors found", ncolors ); ! if (tgaHeader.ImgType == TGA_Null) ! tgaHeader.ImgType = TGA_Map; ! } ! } ! break; case PGM_TYPE: case PBM_TYPE: ! if (tgaHeader.ImgType == TGA_Null) ! tgaHeader.ImgType = TGA_Mono; ! else if (tgaHeader.ImgType == TGA_Map) ! { ! pm_message( "computing colormap..." ); ! chv = ppm_computecolorhist( pixels, cols, rows, MAXCOLORS, &ncolors ); ! if ( chv == (colorhist_vector) 0 ) ! pm_error("can't happen"); ! pm_message( "%d colors found", ncolors ); ! } ! break; default: ! pm_error( "can't happen"); ! } ! tgaHeader.IDLength = 0; ! if (tgaHeader.ImgType == TGA_Map) ! { /* Make a hash table for fast color lookup. */ cht = ppm_colorhisttocolorhash( chv, ncolors ); tgaHeader.CoMapType = 1; ! tgaHeader.Index_lo = 0; ! tgaHeader.Index_hi = 0; ! tgaHeader.Length_lo = ncolors%256; ! tgaHeader.Length_hi = ncolors/256; tgaHeader.CoSize = 24; ! tgaHeader.PixelSize = 8; ! } else ! { tgaHeader.CoMapType = 0; - tgaHeader.Index_lo = 0; - tgaHeader.Index_hi = 0; tgaHeader.Length_lo = 0; tgaHeader.Length_hi = 0; tgaHeader.CoSize = 0; ! tgaHeader.PixelSize = (tgaHeader.ImgType == TGA_RGB) ? 24 : 8; ! } tgaHeader.X_org_lo = tgaHeader.X_org_hi = 0; tgaHeader.Y_org_lo = tgaHeader.Y_org_hi = 0; ! tgaHeader.Width_lo = cols%256; tgaHeader.Width_hi = cols/256; ! tgaHeader.Height_lo = rows%256; tgaHeader.Height_hi = rows/256; tgaHeader.AttBits = 0; tgaHeader.Rsrvd = 0; tgaHeader.IntrLve = 0; ! /* Write out the TGA header. */ ! writetga(&tgaHeader, NULL); ! if (tgaHeader.ImgType == TGA_Map) ! { ! /* Write out the TGA colormap. */ ! for (i = 0; i < ncolors; i++) ! put_map_entry(chv[i].color, tgaHeader.CoSize, maxval); ! } /* Write out the pixels */ for ( row = 0; row < rows; ++row ) ! { ! realrow = row; ! if ( tgaHeader.OrgBit == 0 ) ! realrow = rows - realrow - 1; ! if (tgaHeader.ImgType == TGA_Map) ! for ( col = 0; col < cols; col++ ) ! putchar(ppm_lookupcolor(cht, pixels[realrow]+col)); ! else if (tgaHeader.ImgType == TGA_Mono) ! for ( col = 0; col < cols; col++ ) ! { ! pixel sP; ! PPM_DEPTH(sP, pixels[realrow][col], maxval, (pixval) 255); ! putchar((int) PPM_LUMIN(sP)); ! } ! else if (tgaHeader.ImgType == TGA_RGB) ! for ( col = 0; col < cols; col++ ) ! { ! pixel sP; ! PPM_DEPTH(sP, pixels[realrow][col], maxval, (pixval) 255); ! putchar(PPM_GETB(sP)); ! putchar(PPM_GETG(sP)); ! putchar(PPM_GETR(sP)); ! } ! } exit( 0 ); } ! writetga( tgaP, id) ! struct ImageHeader *tgaP; ! char *id; ! { unsigned char flags; ! putchar(tgaP->IDLength); ! putchar(tgaP->CoMapType); ! putchar(tgaP->ImgType); ! putchar(tgaP->Index_lo); ! putchar(tgaP->Index_hi); ! putchar(tgaP->Length_lo); ! putchar(tgaP->Length_hi); ! putchar(tgaP->CoSize); ! putchar(tgaP->X_org_lo); ! putchar(tgaP->X_org_hi); ! putchar(tgaP->Y_org_lo); ! putchar(tgaP->Y_org_hi); ! putchar(tgaP->Width_lo); ! putchar(tgaP->Width_hi); ! putchar(tgaP->Height_lo); ! putchar(tgaP->Height_hi); ! putchar(tgaP->PixelSize); ! flags = (tgaP->AttBits & 0xf) ! | ((tgaP->Rsrvd & 0x1) << 4) ! | ((tgaP->OrgBit & 0x1) << 5) ! | ((tgaP->OrgBit & 0x3) << 6); ! putchar(flags); ! if (tgaP->IDLength) ! fwrite( id, 1, (int) tgaP->IDLength, stdout); ! } ! put_map_entry(Value, Size, maxval) ! pixel Value; ! int Size; ! pixval maxval; ! { int j; ! pixel sP; ! switch ( Size ) ! { case 8: /* Grey scale. */ ! ! PPM_DEPTH(sP, Value, maxval, (pixval) 255); ! putchar((int) PPM_LUMIN(sP)); break; case 16: /* 5 bits each of red green and blue. */ case 15: /* Watch for byte order. */ ! PPM_DEPTH(sP, Value, maxval, 31); ! j = (int) PPM_GETB(sP) ! | ((int) PPM_GETG(sP) << 5) ! | ((int) PPM_GETR(sP) << 10); ! putchar(j%256); ! putchar(j/256); break; case 32: case 24: /* 8 bits each of blue green and red. */ ! PPM_DEPTH(sP, Value, maxval, (pixval) 255); ! putchar(PPM_GETB(sP)); ! putchar(PPM_GETG(sP)); ! putchar(PPM_GETR(sP)); break; default: ! pm_error( "unknown colormap pixel size (#2) - %d", Size ); } ! } --- 107,450 ---- /* Read in the ppm file. */ ppm_readppminit( ifp, &cols, &rows, &maxval, &format); ! pixels = ppm_allocarray( cols, rows ); ! for ( row = 0; row < rows; ++row ) ! ppm_readppmrow( ifp, pixels[row], cols, maxval, format ); pm_close( ifp ); /* Figure out the colormap. */ ! switch ( PPM_FORMAT_TYPE( format ) ) ! { case PPM_TYPE: ! if ( tgaHeader.ImgType == TGA_Mono ) ! pm_error( "input is not a graymap, filter through ppmtopgm first" ); ! if ( tgaHeader.ImgType == TGA_Null || tgaHeader.ImgType == TGA_Map ) ! { ! pm_message( "computing colormap..." ); ! chv = ppm_computecolorhist( ! pixels, cols, rows, MAXCOLORS, &ncolors ); ! if ( chv == (colorhist_vector) 0 ) ! { ! if ( tgaHeader.ImgType == TGA_Map ) ! pm_error( ! "too many colors - try doing a 'ppmquant %d'", ! MAXCOLORS ); ! else ! tgaHeader.ImgType = TGA_RGB; ! } ! else ! { ! pm_message( "%d colors found", ncolors ); ! if ( tgaHeader.ImgType == TGA_Null ) ! tgaHeader.ImgType = TGA_Map; ! } ! } ! break; ! case PGM_TYPE: case PBM_TYPE: ! if ( tgaHeader.ImgType == TGA_Null ) ! tgaHeader.ImgType = TGA_Mono; ! else if ( tgaHeader.ImgType == TGA_Map ) ! { ! pm_message( "computing colormap..." ); ! chv = ppm_computecolorhist( ! pixels, cols, rows, MAXCOLORS, &ncolors ); ! if ( chv == (colorhist_vector) 0 ) ! pm_error( "can't happen" ); ! pm_message( "%d colors found", ncolors ); ! } ! break; default: ! pm_error( "can't happen" ); ! } ! if ( rle_flag ) ! { ! switch ( tgaHeader.ImgType ) ! { ! case TGA_Mono: ! tgaHeader.ImgType = TGA_RLEMono; ! break; ! case TGA_Map: ! tgaHeader.ImgType = TGA_RLEMap; ! break; ! case TGA_RGB: ! tgaHeader.ImgType = TGA_RLERGB; ! break; ! default: ! pm_error( "can't happen" ); ! } ! runlength = (int*) pm_allocrow( cols, sizeof(int) ); ! } ! tgaHeader.IDLength = 0; ! tgaHeader.Index_lo = 0; ! tgaHeader.Index_hi = 0; ! if ( tgaHeader.ImgType == TGA_Map || tgaHeader.ImgType == TGA_RLEMap ) ! { /* Make a hash table for fast color lookup. */ cht = ppm_colorhisttocolorhash( chv, ncolors ); tgaHeader.CoMapType = 1; ! tgaHeader.Length_lo = ncolors % 256; ! tgaHeader.Length_hi = ncolors / 256; tgaHeader.CoSize = 24; ! } else ! { tgaHeader.CoMapType = 0; tgaHeader.Length_lo = 0; tgaHeader.Length_hi = 0; tgaHeader.CoSize = 0; ! } ! if ( tgaHeader.ImgType == TGA_RGB || tgaHeader.ImgType == TGA_RLERGB ) ! tgaHeader.PixelSize = 24; ! else ! tgaHeader.PixelSize = 8; tgaHeader.X_org_lo = tgaHeader.X_org_hi = 0; tgaHeader.Y_org_lo = tgaHeader.Y_org_hi = 0; ! tgaHeader.Width_lo = cols % 256; ! tgaHeader.Width_hi = cols / 256; ! tgaHeader.Height_lo = rows % 256; ! tgaHeader.Height_hi = rows / 256; tgaHeader.AttBits = 0; tgaHeader.Rsrvd = 0; tgaHeader.IntrLve = 0; ! /* Write out the Targa header. */ ! writetga( &tgaHeader, (char*) 0 ); ! if ( tgaHeader.ImgType == TGA_Map || tgaHeader.ImgType == TGA_RLEMap ) ! { ! /* Write out the Targa colormap. */ ! for ( i = 0; i < ncolors; ++i ) ! put_map_entry( &chv[i].color, tgaHeader.CoSize, maxval ); ! } /* Write out the pixels */ for ( row = 0; row < rows; ++row ) ! { ! realrow = row; ! if ( tgaHeader.OrgBit == 0 ) ! realrow = rows - realrow - 1; ! if ( rle_flag ) ! { ! compute_runlengths( cols, pixels[realrow], runlength ); ! for ( col = 0; col < cols; ) ! { ! if ( runlength[col] > 0 ) ! { ! putchar( 0x80 + runlength[col] - 1 ); ! put_pixel( ! &(pixels[realrow][col]), ! tgaHeader.ImgType, maxval, cht ); ! col += runlength[col]; ! } ! else if ( runlength[col] < 0 ) ! { ! putchar( -runlength[col] - 1 ); ! for ( i = 0; i < -runlength[col]; ++i ) ! put_pixel( ! &(pixels[realrow][col + i]), ! tgaHeader.ImgType, maxval, cht ); ! col += -runlength[col]; ! } ! else ! pm_error( "can't happen" ); ! } ! } ! else ! { ! for ( col = 0, pP = pixels[realrow]; col < cols; ++col, ++pP ) ! put_pixel( pP, tgaHeader.ImgType, maxval, cht ); ! } ! } ! exit( 0 ); } ! static void ! writetga( tgaP, id ) ! struct ImageHeader* tgaP; ! char* id; ! { unsigned char flags; ! putchar( tgaP->IDLength ); ! putchar( tgaP->CoMapType ); ! putchar( tgaP->ImgType ); ! putchar( tgaP->Index_lo ); ! putchar( tgaP->Index_hi ); ! putchar( tgaP->Length_lo ); ! putchar( tgaP->Length_hi ); ! putchar( tgaP->CoSize ); ! putchar( tgaP->X_org_lo ); ! putchar( tgaP->X_org_hi ); ! putchar( tgaP->Y_org_lo ); ! putchar( tgaP->Y_org_hi ); ! putchar( tgaP->Width_lo ); ! putchar( tgaP->Width_hi ); ! putchar( tgaP->Height_lo ); ! putchar( tgaP->Height_hi ); ! putchar( tgaP->PixelSize ); ! flags = ( tgaP->AttBits & 0xf ) | ( ( tgaP->Rsrvd & 0x1 ) << 4 ) | ! ( ( tgaP->OrgBit & 0x1 ) << 5 ) | ( ( tgaP->OrgBit & 0x3 ) << 6 ); ! putchar( flags ); ! if ( tgaP->IDLength ) ! fwrite( id, 1, (int) tgaP->IDLength, stdout ); ! } ! #if __STDC__ ! static void ! put_map_entry( pixel* valueP, int size, pixval maxval ) ! #else /*__STDC__*/ ! static void ! put_map_entry( valueP, size, maxval ) ! pixel* valueP; ! int size; ! pixval maxval; ! #endif /*__STDC__*/ ! { int j; ! pixel p; ! switch ( size ) ! { case 8: /* Grey scale. */ ! put_mono( valueP, maxval ); break; case 16: /* 5 bits each of red green and blue. */ case 15: /* Watch for byte order. */ ! PPM_DEPTH( p, *valueP, maxval, 31 ); ! j = (int) PPM_GETB( p ) | ( (int) PPM_GETG( p ) << 5 ) | ! ( (int) PPM_GETR( p ) << 10 ); ! putchar( j % 256 ); ! putchar( j / 256 ); break; case 32: case 24: /* 8 bits each of blue green and red. */ ! put_rgb( valueP, maxval ); break; default: ! pm_error( "unknown colormap pixel size (#2) - %d", size ); ! } } ! ! static void ! compute_runlengths( cols, pixelrow, runlength ) ! int cols; ! pixel* pixelrow; ! int* runlength; ! { ! int col, start; ! ! /* Initialize all run lengths to 0. (This is just an error check.) */ ! for ( col = 0; col < cols; ++col ) ! runlength[col] = 0; ! ! /* Find runs of identical pixels. */ ! for ( col = 0; col < cols; ) ! { ! start = col; ! do { ! ++col; ! } ! while ( col < cols && ! col - start < 128 && ! PPM_EQUAL( pixelrow[col], pixelrow[start] ) ); ! runlength[start] = col - start; ! } ! ! /* Now look for runs of length-1 runs, and turn them into negative runs. */ ! for ( col = 0; col < cols; ) ! { ! if ( runlength[col] == 1 ) ! { ! start = col; ! while ( col < cols && ! col - start < 128 && ! runlength[col] == 1 ) ! { ! runlength[col] = 0; ! ++col; ! } ! runlength[start] = - ( col - start ); ! } ! else ! col += runlength[col]; ! } ! } ! ! #if __STDC__ ! static void ! put_pixel( pixel* pP, int imgtype, pixval maxval, colorhash_table cht ) ! #else /*__STDC__*/ ! static void ! put_pixel( pP, imgtype, maxval, cht ) ! pixel* pP; ! int imgtype; ! pixval maxval; ! colorhash_table cht; ! #endif /*__STDC__*/ ! { ! switch ( imgtype ) ! { ! case TGA_Mono: ! case TGA_RLEMono: ! put_mono( pP, maxval ); ! break; ! case TGA_Map: ! case TGA_RLEMap: ! put_map( pP, cht ); ! break; ! case TGA_RGB: ! case TGA_RLERGB: ! put_rgb( pP, maxval ); ! break; ! default: ! pm_error( "can't happen" ); ! } ! } ! ! #if __STDC__ ! static void ! put_mono( pixel* pP, pixval maxval ) ! #else /*__STDC__*/ ! static void ! put_mono( pP, maxval ) ! pixel* pP; ! pixval maxval; ! #endif /*__STDC__*/ ! { ! PPM_DEPTH( *pP, *pP, maxval, (pixval) 255 ); ! putchar( PPM_GETR( *pP ) ); ! } ! ! static void ! put_map( pP, cht ) ! pixel* pP; ! colorhash_table cht; ! { ! putchar( ppm_lookupcolor( cht, pP ) ); ! } ! ! #if __STDC__ ! static void ! put_rgb( pixel* pP, pixval maxval ) ! #else /*__STDC__*/ ! static void ! put_rgb( pP, maxval ) ! pixel* pP; ! pixval maxval; ! #endif /*__STDC__*/ ! { ! PPM_DEPTH( *pP, *pP, maxval, (pixval) 255 ); ! putchar( PPM_GETB( *pP ) ); ! putchar( PPM_GETG( *pP ) ); ! putchar( PPM_GETR( *pP ) ); ! } diff -cr pbmplus05oct91/ppm/tgatoppm.c pbmplus30oct91/ppm/tgatoppm.c *** pbmplus05oct91/ppm/tgatoppm.c Fri Jun 28 15:37:52 1991 --- pbmplus30oct91/ppm/tgatoppm.c Wed Oct 30 09:38:05 1991 *************** *** 36,42 **** int i; unsigned int temp1, temp2; FILE* ifp; ! int argn, debug, rows, cols, row, col, realrow; int maxval; pixel** pixels; char* usage = " [-debug] [tgafile]"; --- 36,42 ---- int i; unsigned int temp1, temp2; FILE* ifp; ! int argn, debug, rows, cols, row, col, realrow, truerow, baserow; int maxval; pixel** pixels; char* usage = " [-debug] [tgafile]"; *************** *** 172,178 **** temp2 = tga_head.Length_lo + tga_head.Length_hi * 256; if ( ( temp1 + temp2 + 1 ) >= MAXCOLORS ) pm_error( "too many colors - %d", ( temp1 + temp2 + 1 ) ); ! for ( i = temp1; i < ( temp1 + temp2 ); i++ ) get_map_entry( ifp, &ColorMap[i], (int) tga_head.CoSize ); } --- 172,178 ---- temp2 = tga_head.Length_lo + tga_head.Length_hi * 256; if ( ( temp1 + temp2 + 1 ) >= MAXCOLORS ) pm_error( "too many colors - %d", ( temp1 + temp2 + 1 ) ); ! for ( i = temp1; i < ( temp1 + temp2 ); ++i ) get_map_entry( ifp, &ColorMap[i], (int) tga_head.CoSize ); } *************** *** 186,233 **** /* Read the Targa file body and convert to portable format. */ pixels = ppm_allocarray( cols, rows ); ! for ( row = 0; row < rows; row++ ) { ! if ( tga_head.IntrLve == TGA_IL_Four ) ! { ! if ( 4 * row < rows ) ! realrow = 4 * row; ! else if ( 2 * row < rows ) ! { ! realrow = row - rows / 4; ! realrow = 4 * realrow + 1; ! } ! else if ( 4 * row < 3 * rows ) ! { ! realrow = row - rows / 2; ! realrow = 4 * realrow + 2; ! } ! else ! { ! realrow = row - rows / 2 - rows / 4; ! realrow = 4 * realrow + 3; ! } ! } ! else if ( tga_head.IntrLve == TGA_IL_Two ) ! { ! if ( 2 * row < rows ) ! realrow = 2 * row; ! else ! { ! realrow = row - rows / 2; ! realrow = 2 * realrow + 1; ! } ! } ! else ! realrow = row; ! if ( tga_head.OrgBit == 0 ) realrow = rows - realrow - 1; ! for ( col = 0; col < cols; col++ ) get_pixel( ifp, &(pixels[realrow][col]), (int) tga_head.PixelSize ); } - pm_close( ifp ); ppm_writeppm( stdout, pixels, cols, rows, (pixval) maxval, 0 ); --- 186,210 ---- /* Read the Targa file body and convert to portable format. */ pixels = ppm_allocarray( cols, rows ); ! truerow = 0; ! baserow = 0; ! for ( row = 0; row < rows; ++row ) { ! realrow = truerow; if ( tga_head.OrgBit == 0 ) realrow = rows - realrow - 1; ! for ( col = 0; col < cols; ++col ) get_pixel( ifp, &(pixels[realrow][col]), (int) tga_head.PixelSize ); + if ( tga_head.IntrLve == TGA_IL_Four ) + truerow += 4; + else if ( tga_head.IntrLve == TGA_IL_Two ) + truerow += 2; + else + ++truerow; + if ( truerow >= rows ) + truerow = ++baserow; } pm_close( ifp ); ppm_writeppm( stdout, pixels, cols, rows, (pixval) maxval, 0 ); *************** *** 326,332 **** { /* Have to restart run. */ unsigned char i; i = getbyte( ifp ); ! RLE_flag = ( i & 0x80 ) >> 7; if ( RLE_flag == 0 ) /* Stream of unencoded pixels. */ RLE_count = i + 1; --- 303,309 ---- { /* Have to restart run. */ unsigned char i; i = getbyte( ifp ); ! RLE_flag = ( i & 0x80 ); if ( RLE_flag == 0 ) /* Stream of unencoded pixels. */ RLE_count = i + 1; *************** *** 334,344 **** /* Single pixel replicated. */ RLE_count = i - 127; /* Decrement count & get pixel. */ ! RLE_count--; } else { /* Have already read count & (at least) first pixel. */ ! RLE_count--; if ( RLE_flag != 0 ) /* Replicated pixels. */ goto PixEncode; --- 311,321 ---- /* Single pixel replicated. */ RLE_count = i - 127; /* Decrement count & get pixel. */ ! --RLE_count; } else { /* Have already read count & (at least) first pixel. */ ! --RLE_count; if ( RLE_flag != 0 ) /* Replicated pixels. */ goto PixEncode; exit 0 # Just in case... -- Kent Landfield INTERNET: kent@sparky.IMD.Sterling.COM Sterling Software, IMD UUCP: uunet!sparky!kent Phone: (402) 291-8300 FAX: (402) 291-4362 Please send comp.sources.misc-related mail to kent@uunet.uu.net.