home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / misc / volume25 / pbmplus / patch30oct91 next >
Text File  |  1991-11-06  |  48KB  |  1,614 lines

  1. Newsgroups: comp.sources.misc
  2. From: jef@well.sf.ca.us (Jef Poskanzer)
  3. Subject:  v25i033:  pbmplus - Extended Portable Bitmap Toolkit, Patch30oct91
  4. Message-ID: <1991Nov6.045135.7889@sparky.imd.sterling.com>
  5. X-Md4-Signature: cc2fa676b351c753487f8f7449cf19aa
  6. Date: Wed, 6 Nov 1991 04:51:35 GMT
  7. Approved: kent@sparky.imd.sterling.com
  8.  
  9. Submitted-by: jef@well.sf.ca.us (Jef Poskanzer)
  10. Posting-number: Volume 25, Issue 33
  11. Archive-name: pbmplus/patch30oct91
  12. Environment: UNIX
  13. Patch-To: pbmplus: Volume 23, Issue 36-59, 60
  14.  
  15. A couple more bugs in the tiff reader, a bug in run-length encoded
  16. color PostScript, and a few enhancements.
  17.  
  18. This new version is dated 30oct91.  If you have the 05oct91 version
  19. you can update with the appended patch file.  Or, you can FTP the new
  20. version complete from:
  21.  
  22.     export.lcs.mit.edu:contrib/pbmplus30oct91.tar.Z  (18.24.0.12)
  23.     ftp.ee.lbl.gov:pbmplus30oct91.tar.Z              (128.3.112.20)
  24.  
  25.            Jef Poskanzer  jef@well.sf.ca.us  apple!well!jef
  26.  
  27. - - - - - - - - - -
  28.  
  29. diff -cr pbmplus05oct91/CHANGES pbmplus30oct91/CHANGES
  30. *** pbmplus05oct91/CHANGES    Sat Oct  5 23:51:13 1991
  31. --- pbmplus30oct91/CHANGES    Wed Oct 30 13:03:49 1991
  32. ***************
  33. *** 1,3 ****
  34. --- 1,18 ----
  35. + Changes since the 05oct91 X11R5 contrib tape version:
  36. +     Fixed minor SysV config error in pbmplus.h.  (Tom Lane)
  37. +     Fixed tifftopnm so that BITSPERSAMPLE and SAMPLESPERPIXEL default
  38. +       correctly.  Fixed possible bug in tgatoppm line-interleaving code.
  39. +       (Arthur David Olson)
  40. +     Fixed tifftopnm so that colormapped files are read correctly.
  41. +       (PauL Drews, Mike Wade)
  42. +     Corrected use of DefaultRGBDatabase / RGB_DB for imake sites.
  43. +       (Randal L. Schwartz)
  44. +     Bugfix to pnmtops color PostScript in -rle mode.  (Angus Duggan)
  45. +     Added auto-turning to pnmtops.
  46. +     Added run-length encoding to ppmtotga.
  47. +     Space optimization to pgmoil.
  48.   Changes since the 27sep91 comp.sources.misc distribution:
  49.   
  50.       Fixed spelling error in giftoppm.  Fixed ppmrelief to not shrink the
  51. diff -cr pbmplus05oct91/Makefile pbmplus30oct91/Makefile
  52. *** pbmplus05oct91/Makefile    Fri Sep 27 17:45:46 1991
  53. --- pbmplus30oct91/Makefile    Wed Oct 30 20:13:49 1991
  54. ***************
  55. *** 35,41 ****
  56.   # path here.  This is used by PPM to parse color names into rgb values.
  57.   # If you don't have such a file, comment this out and use the alternative
  58.   # hex and decimal forms to specify colors (see ppm/pgmtoppm.1 for details).
  59. ! RGBDEF =    -DRGB_DB=\"/usr/lib/X11/rgb.txt\"
  60.   
  61.   # CONFIGURE: PBMPLUS's support for TIFF files depends on the library from
  62.   # Sam Leffler's TIFF Software package - see the OTHER.SYSTEMS file for a
  63. --- 35,41 ----
  64.   # path here.  This is used by PPM to parse color names into rgb values.
  65.   # If you don't have such a file, comment this out and use the alternative
  66.   # hex and decimal forms to specify colors (see ppm/pgmtoppm.1 for details).
  67. ! RGBDEF =    -DRGB_DB=\"/usr/lib/X11/rgb\"
  68.   
  69.   # CONFIGURE: PBMPLUS's support for TIFF files depends on the library from
  70.   # Sam Leffler's TIFF Software package - see the OTHER.SYSTEMS file for a
  71. diff -cr pbmplus05oct91/README pbmplus30oct91/README
  72. *** pbmplus05oct91/README    Sat Oct  5 22:36:16 1991
  73. --- pbmplus30oct91/README    Wed Oct 30 20:11:16 1991
  74. ***************
  75. *** 1,6 ****
  76.                     Extended Portable Bitmap Toolkit
  77. !                       Distribution of 05oct91
  78. !                    Previous distribution 27sep91
  79.   
  80.   
  81.   PBMPLUS is a toolkit for converting various image formats to and from
  82. --- 1,6 ----
  83.                     Extended Portable Bitmap Toolkit
  84. !                       Distribution of 30oct91
  85. !                    Previous distribution 05oct91
  86.   
  87.   
  88.   PBMPLUS is a toolkit for converting various image formats to and from
  89. diff -cr pbmplus05oct91/TODO pbmplus30oct91/TODO
  90. *** pbmplus05oct91/TODO    Fri Sep 27 12:40:08 1991
  91. --- pbmplus30oct91/TODO    Thu Oct 24 13:29:41 1991
  92. ***************
  93. *** 18,24 ****
  94.   Figure out why compiling pnmconvol makes gcc die on some systems.
  95.   
  96.   Convert to line-by-line mode:
  97. ! pbmtext.c pbmtoascii.c pbmtoepson.c pbmtomacp.c pbmtoplot.c
  98.   
  99.   The Converter Generator reorganization: all filters become three library
  100.   routines, one to initialize, one to handle each line, and one to finish off.
  101. --- 18,24 ----
  102.   Figure out why compiling pnmconvol makes gcc die on some systems.
  103.   
  104.   Convert to line-by-line mode:
  105. ! pbmtext.c pbmtoascii.c pbmtoepson.c pbmtomacp.c pbmtoplot.c pgmoil.c
  106.   
  107.   The Converter Generator reorganization: all filters become three library
  108.   routines, one to initialize, one to handle each line, and one to finish off.
  109. diff -cr pbmplus05oct91/pbmplus.h pbmplus30oct91/pbmplus.h
  110. *** pbmplus05oct91/pbmplus.h    Mon Sep 23 15:03:08 1991
  111. --- pbmplus30oct91/pbmplus.h    Sun Oct  6 09:32:33 1991
  112. ***************
  113. *** 95,105 ****
  114. --- 95,107 ----
  115.   #define bzero(dst,len) memset(dst,0,len)
  116.   #define bcopy(src,dst,len) memcpy(dst,src,len)
  117.   #define bcmp memcmp
  118. + extern void srand();
  119.   extern int rand();
  120.   
  121.   #else /*SYSV*/
  122.   
  123.   #include <strings.h>
  124. + extern void srandom();
  125.   extern long random();
  126.   
  127.   #endif /*SYSV*/
  128. ***************
  129. *** 106,112 ****
  130.   
  131.   extern int atoi();
  132.   extern void exit();
  133. - extern void srandom();
  134.   extern long time();
  135.   extern int write();
  136.   
  137. --- 108,113 ----
  138. diff -cr pbmplus05oct91/version.h pbmplus30oct91/version.h
  139. *** pbmplus05oct91/version.h    Sat Oct  5 22:35:33 1991
  140. --- pbmplus30oct91/version.h    Wed Oct 30 20:11:25 1991
  141. ***************
  142. *** 1,4 ****
  143.   /* version.h - define the current version of PBM, PGM, PPM, and PNM
  144.   */
  145.   
  146. ! #define PBMPLUS_VERSION "05oct91"
  147. --- 1,4 ----
  148.   /* version.h - define the current version of PBM, PGM, PPM, and PNM
  149.   */
  150.   
  151. ! #define PBMPLUS_VERSION "30oct91"
  152. diff -cr pbmplus05oct91/pbm/Makefile pbmplus30oct91/pbm/Makefile
  153. *** pbmplus05oct91/pbm/Makefile    Fri Sep 27 12:32:47 1991
  154. --- pbmplus30oct91/pbm/Makefile    Thu Oct 24 13:34:36 1991
  155. ***************
  156. *** 15,21 ****
  157.   #CFLAGS =    -O
  158.   CFLAGS =    -g
  159.   #CFLAGS =    -g -O
  160. ! RGBDEF =        -DRGB_DB=\"/usr/lib/X11/rgb.txt\"
  161.   TIFFDEF =       -DLIBTIFF
  162.   #LDFLAGS =    -s
  163.   LDFLAGS =    
  164. --- 15,21 ----
  165.   #CFLAGS =    -O
  166.   CFLAGS =    -g
  167.   #CFLAGS =    -g -O
  168. ! RGBDEF =        -DRGB_DB=\"/usr/lib/X11/rgb\"
  169.   TIFFDEF =       -DLIBTIFF
  170.   #LDFLAGS =    -s
  171.   LDFLAGS =    
  172. diff -cr pbmplus05oct91/pgm/pgmoil.c pbmplus30oct91/pgm/pgmoil.c
  173. *** pbmplus05oct91/pgm/pgmoil.c    Fri Jun 28 14:29:28 1991
  174. --- pbmplus30oct91/pgm/pgmoil.c    Wed Oct 30 13:04:36 1991
  175. ***************
  176. *** 17,29 ****
  177.   
  178.   void
  179.   main( argc, argv )
  180. ! int argc;
  181. ! char* argv[];
  182.       {
  183.       FILE* ifp;
  184.       gray midval, maxval;
  185. !     gray** gin;
  186. !     gray** gout;
  187.       int argn, rows, n, cols, row;
  188.       register int col, drow, dcol;
  189.       int i;
  190. --- 17,29 ----
  191.   
  192.   void
  193.   main( argc, argv )
  194. !     int argc;
  195. !     char* argv[];
  196.       {
  197.       FILE* ifp;
  198.       gray midval, maxval;
  199. !     gray** grays;
  200. !     gray* grayrow;
  201.       int argn, rows, n, cols, row;
  202.       register int col, drow, dcol;
  203.       int i;
  204. ***************
  205. *** 59,78 ****
  206.       if ( argn != argc )
  207.       pm_usage( usage );
  208.   
  209. !     gin = pgm_readpgm( ifp, &cols, &rows, &maxval );
  210.       pm_close( ifp );
  211. -     gout = pgm_allocarray( cols, rows );
  212.   
  213. !     /* Build histogram. */
  214. !     for ( row = n; row < rows - n; ++row )
  215. !     for ( col = n; col < cols - n; ++col )
  216.           {
  217.           for ( i = 0; i <= maxval; ++i )
  218.           hist[i] = 0;
  219.   
  220.           for ( drow = row - n; drow <= row + n; ++drow )
  221. !         for ( dcol = col - n; dcol <= col + n; ++dcol )
  222. !             ++hist[ (int) (gin[drow][dcol]) ];
  223.   
  224.           for ( drow = dcol = 0; dcol < maxval; ++dcol )
  225.           if ( hist[dcol] > drow )
  226. --- 59,82 ----
  227.       if ( argn != argc )
  228.       pm_usage( usage );
  229.   
  230. !     grays = pgm_readpgm( ifp, &cols, &rows, &maxval );
  231.       pm_close( ifp );
  232.   
  233. !     pgm_writepgminit( stdout, cols, rows, maxval, 0 );
  234. !     grayrow = pgm_allocrow( cols );
  235. !     for ( row = 0; row < rows; ++row )
  236. !     {
  237. !     for ( col = 0; col < cols; ++col )
  238.           {
  239.           for ( i = 0; i <= maxval; ++i )
  240.           hist[i] = 0;
  241.   
  242.           for ( drow = row - n; drow <= row + n; ++drow )
  243. !         if ( drow >= 0 && drow < rows )
  244. !             for ( dcol = col - n; dcol <= col + n; ++dcol )
  245. !             if ( dcol >= 0 && dcol < cols )
  246. !                 ++hist[ (int) (grays[drow][dcol]) ];
  247.   
  248.           for ( drow = dcol = 0; dcol < maxval; ++dcol )
  249.           if ( hist[dcol] > drow )
  250. ***************
  251. *** 80,90 ****
  252.               drow = hist[dcol];
  253.               midval = dcol;
  254.               }
  255. !         gout[row][col] = midval;
  256.           }
  257. !     pgm_writepgm( stdout, gout, cols, rows, maxval, 0 );
  258. !     pgm_freearray( gout, rows );
  259.   
  260.       exit( 0 );
  261.       }
  262. --- 84,93 ----
  263.               drow = hist[dcol];
  264.               midval = dcol;
  265.               }
  266. !         grayrow[col] = midval;
  267.           }
  268. !     pgm_writepgmrow( stdout, grayrow, cols, maxval, 0 );
  269. !     }
  270.   
  271.       exit( 0 );
  272.       }
  273. diff -cr pbmplus05oct91/pnm/pnmmargin.1 pbmplus30oct91/pnm/pnmmargin.1
  274. *** pbmplus05oct91/pnm/pnmmargin.1    Tue Jun  4 14:12:41 1991
  275. --- pbmplus30oct91/pnm/pnmmargin.1    Fri Oct 25 13:23:16 1991
  276. ***************
  277. *** 1,7 ****
  278.   .TH pnmmargin 1 "9 January 1991"
  279.   .IX pnmmargin
  280.   .SH NAME
  281. ! pnmmargin - add a margin to a portable anymap
  282.   .SH SYNOPSIS
  283.   .B pnmmargin
  284.   .RB [ -white | -black | -color
  285. --- 1,7 ----
  286.   .TH pnmmargin 1 "9 January 1991"
  287.   .IX pnmmargin
  288.   .SH NAME
  289. ! pnmmargin - add a border to a portable anymap
  290.   .SH SYNOPSIS
  291.   .B pnmmargin
  292.   .RB [ -white | -black | -color
  293. ***************
  294. *** 10,21 ****
  295.   .RI [ pnmfile ]
  296.   .SH DESCRIPTION
  297.   Reads a portable anymap as input.
  298. ! Adds a margin of the specified number of pixels,
  299.   and produces a portable anymap as output.
  300.   .IX margin
  301.   .SH OPTIONS
  302.   .PP
  303. ! You can specify the margin color with the
  304.   .BR -white ,
  305.   .BR -black ,
  306.   and
  307. --- 10,22 ----
  308.   .RI [ pnmfile ]
  309.   .SH DESCRIPTION
  310.   Reads a portable anymap as input.
  311. ! Adds a border of the specified number of pixels,
  312.   and produces a portable anymap as output.
  313.   .IX margin
  314. + .IX border
  315.   .SH OPTIONS
  316.   .PP
  317. ! You can specify the border color with the
  318.   .BR -white ,
  319.   .BR -black ,
  320.   and
  321. diff -cr pbmplus05oct91/pnm/pnmtops.1 pbmplus30oct91/pnm/pnmtops.1
  322. *** pbmplus05oct91/pnm/pnmtops.1    Fri Sep 27 00:20:28 1991
  323. --- pbmplus30oct91/pnm/pnmtops.1    Sat Oct 26 15:15:16 1991
  324. ***************
  325. *** 1,12 ****
  326. ! .TH pnmtops 1 "26 September 1991"
  327.   .IX pnmtops
  328.   .SH NAME
  329.   pnmtops - convert portable anymap to PostScript
  330.   .SH SYNOPSIS
  331.   .B pnmtops
  332. - .RB [ -rle | -runlength ]
  333.   .RB [ -scale
  334.   .IR s ]
  335.   .RB [ -dpi
  336.   .IR n ]
  337.   .RB [ -width
  338. --- 1,13 ----
  339. ! .TH pnmtops 1 "26 October 1991"
  340.   .IX pnmtops
  341.   .SH NAME
  342.   pnmtops - convert portable anymap to PostScript
  343.   .SH SYNOPSIS
  344.   .B pnmtops
  345.   .RB [ -scale
  346.   .IR s ]
  347. + .RB [ -turn | -noturn ]
  348. + .RB [ -rle | -runlength ]
  349.   .RB [ -dpi
  350.   .IR n ]
  351.   .RB [ -width
  352. ***************
  353. *** 46,51 ****
  354. --- 47,67 ----
  355.   To get one PNM pixel per 300 dpi printer pixel, use "-scale 0.25".
  356.   .PP
  357.   The
  358. + .B -turn
  359. + and
  360. + .B -noturn
  361. + flags control whether the image gets turned 90 degrees.
  362. + Normally, if an image is wider than it is tall, it gets turned
  363. + automatically to better fit the page.
  364. + If the
  365. + .B -turn
  366. + flag is specified, it will be turned no matter what its shape; and if the
  367. + .B -noturn
  368. + flag is specified, it will
  369. + .I not
  370. + be turned no matter what its shape.
  371. + .PP
  372. + The
  373.   .B -rle
  374.   or
  375.   .B -runlength
  376. ***************
  377. *** 74,82 ****
  378.   All flags can be abbreviated to their shortest unique prefix.
  379.   .SH "SEE ALSO"
  380.   pnm(5), psidtopgm(1)
  381. - .SH BUGS
  382. - It ought to automatically rotate to landscape mode if that would fit
  383. - the image better.
  384.   .SH AUTHOR
  385.   Copyright (C) 1989, 1991 by Jef Poskanzer.
  386.   .\" Permission to use, copy, modify, and distribute this software and its
  387. --- 90,95 ----
  388. diff -cr pbmplus05oct91/pnm/pnmtops.c pbmplus30oct91/pnm/pnmtops.c
  389. *** pbmplus05oct91/pnm/pnmtops.c    Fri Sep 27 12:07:53 1991
  390. --- pbmplus30oct91/pnm/pnmtops.c    Sat Oct 26 15:16:56 1991
  391. ***************
  392. *** 14,20 ****
  393.   
  394.   #define MARGIN 0.95
  395.   
  396. ! 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 ));
  397.   static void putitem ARGS(( void ));
  398.   static void putxelval ARGS(( xelval xv ));
  399.   static void putrest ARGS(( void ));
  400. --- 14,20 ----
  401.   
  402.   #define MARGIN 0.95
  403.   
  404. ! 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 ));
  405.   static void putitem ARGS(( void ));
  406.   static void putxelval ARGS(( xelval xv ));
  407.   static void putrest ARGS(( void ));
  408. ***************
  409. *** 32,50 ****
  410.       FILE* ifp;
  411.       xel* xelrow;
  412.       register xel* xP;
  413. !     int argn, rleflag, rows, cols, format, bps, padright, row, col;
  414.       xelval maxval, nmaxval;
  415.       float scale, f;
  416.       int dpi, pagewid, pagehgt;
  417.       char name[100];
  418.       char* cp;
  419. !     char* usage = "[-rle|-runlength] [-scale <x>] [-dpi <n>] [-width <n>] [-height <n>] [pnmfile]";
  420.   
  421.       pnm_init( &argc, argv );
  422.   
  423.       argn = 1;
  424. -     rleflag = 0;
  425.       scale = 1.0;
  426.       /* LaserWriter defaults. */
  427.       dpi = 300;
  428.       pagewid = 612;
  429. --- 32,53 ----
  430.       FILE* ifp;
  431.       xel* xelrow;
  432.       register xel* xP;
  433. !     int argn, turnflag, turnokflag, rleflag;
  434. !     int rows, cols, format, bps, padright, row, col;
  435.       xelval maxval, nmaxval;
  436.       float scale, f;
  437.       int dpi, pagewid, pagehgt;
  438.       char name[100];
  439.       char* cp;
  440. !     char* usage = "[-scale <x>] [-turn|-noturn] [-rle|-runlength] [-dpi <n>] [-width <n>] [-height <n>] [-rle|-runlength] [pnmfile]";
  441.   
  442.       pnm_init( &argc, argv );
  443.   
  444.       argn = 1;
  445.       scale = 1.0;
  446. +     turnflag = 0;
  447. +     turnokflag = 1;
  448. +     rleflag = 0;
  449.       /* LaserWriter defaults. */
  450.       dpi = 300;
  451.       pagewid = 612;
  452. ***************
  453. *** 53,70 ****
  454.       /* Check for flags. */
  455.       while ( argn < argc && argv[argn][0] == '-' && argv[argn][1] != '\0' )
  456.       {
  457. !     if ( pm_keymatch( argv[argn], "-rle", 2 ) ||
  458. !          pm_keymatch( argv[argn], "-runlength", 2 ) )
  459. !         rleflag = 1;
  460. !     else if ( pm_keymatch( argv[argn], "-norle", 2 ) ||
  461. !          pm_keymatch( argv[argn], "-norunlength", 2 ) )
  462. !         rleflag = 0;
  463. !     else if ( pm_keymatch( argv[argn], "-scale", 2 ) )
  464.           {
  465.           ++argn;
  466.           if ( argn == argc || sscanf( argv[argn], "%f", &scale ) != 1 )
  467.           pm_usage( usage );
  468.           }
  469.       else if ( pm_keymatch( argv[argn], "-dpi", 2 ) )
  470.           {
  471.           ++argn;
  472. --- 56,74 ----
  473.       /* Check for flags. */
  474.       while ( argn < argc && argv[argn][0] == '-' && argv[argn][1] != '\0' )
  475.       {
  476. !     if ( pm_keymatch( argv[argn], "-scale", 2 ) )
  477.           {
  478.           ++argn;
  479.           if ( argn == argc || sscanf( argv[argn], "%f", &scale ) != 1 )
  480.           pm_usage( usage );
  481.           }
  482. +     else if ( pm_keymatch( argv[argn], "-turn", 2 ) )
  483. +         turnflag = 1;
  484. +     else if ( pm_keymatch( argv[argn], "-noturn", 2 ) )
  485. +         turnokflag = 0;
  486. +     else if ( pm_keymatch( argv[argn], "-rle", 2 ) ||
  487. +               pm_keymatch( argv[argn], "-runlength", 2 ) )
  488. +         rleflag = 1;
  489.       else if ( pm_keymatch( argv[argn], "-dpi", 2 ) )
  490.           {
  491.           ++argn;
  492. ***************
  493. *** 128,134 ****
  494.   
  495.       putinit(
  496.       name, cols, rows, padright, bps, scale, dpi, pagewid, pagehgt, format,
  497. !     rleflag );
  498.       for ( row = 0; row < rows; ++row )
  499.       {
  500.       pnm_readpnmrow( ifp, xelrow, cols, maxval, format );
  501. --- 132,138 ----
  502.   
  503.       putinit(
  504.       name, cols, rows, padright, bps, scale, dpi, pagewid, pagehgt, format,
  505. !     turnflag, turnokflag, rleflag );
  506.       for ( row = 0; row < rows; ++row )
  507.       {
  508.       pnm_readpnmrow( ifp, xelrow, cols, maxval, format );
  509. ***************
  510. *** 150,155 ****
  511. --- 154,161 ----
  512.               rleputxelval( 0 );
  513.           else
  514.               putxelval( 0 );
  515. +         if ( rleflag )
  516. +         rleflush();
  517.           /* Then green. */
  518.           for ( col = 0, xP = xelrow; col < cols; ++col, ++xP )
  519.           if ( rleflag )
  520. ***************
  521. *** 161,166 ****
  522. --- 167,174 ----
  523.               rleputxelval( 0 );
  524.           else
  525.               putxelval( 0 );
  526. +         if ( rleflag )
  527. +         rleflush();
  528.           /* And blue. */
  529.           for ( col = 0, xP = xelrow; col < cols; ++col, ++xP )
  530.           if ( rleflag )
  531. ***************
  532. *** 213,231 ****
  533.   
  534.   #if __STDC__
  535.   static void
  536. ! putinit( char* name, int cols, int rows, int padright, int bps, float scale, int dpi, int pagewid, int pagehgt, int format, int rleflag )
  537.   #else /*__STDC__*/
  538.   static void
  539. ! putinit( name, cols, rows, padright, bps, scale, dpi, pagewid, pagehgt, format, rleflag )
  540.       char* name;
  541.       int cols, rows, padright, bps;
  542.       float scale;
  543. !     int dpi, pagewid, pagehgt, format, rleflag;
  544.   #endif /*__STDC__*/
  545.       {
  546. !     int devpix;
  547.       float pixfac, scols, srows, llx, lly;
  548.   
  549.       devpix = dpi / 72.0 + 0.5;        /* device pixels per unit, approx. */
  550.       pixfac = 72.0 / dpi * devpix;    /* 1, approx. */
  551.       scols = scale * cols * pixfac;
  552. --- 221,253 ----
  553.   
  554.   #if __STDC__
  555.   static void
  556. ! putinit( char* name, int cols, int rows, int padright, int bps, float scale,
  557. !      int dpi, int pagewid, int pagehgt, int format, int turnflag,
  558. !      int turnokflag, int rleflag )
  559.   #else /*__STDC__*/
  560.   static void
  561. ! putinit( name, cols, rows, padright, bps, scale, dpi, pagewid, pagehgt, format,
  562. !      turnflag, turnokflag, rleflag )
  563.       char* name;
  564.       int cols, rows, padright, bps;
  565.       float scale;
  566. !     int dpi, pagewid, pagehgt, format, turnflag, turnokflag, rleflag;
  567.   #endif /*__STDC__*/
  568.       {
  569. !     int icols, irows, devpix;
  570.       float pixfac, scols, srows, llx, lly;
  571.   
  572. +     /* Turn? */
  573. +     icols = cols;
  574. +     irows = rows;
  575. +     if ( turnflag || ( turnokflag && cols > rows ) )
  576. +     {
  577. +     turnflag = 1;
  578. +     cols = irows;
  579. +     rows = icols;
  580. +     }
  581. +     /* Figure out size. */
  582.       devpix = dpi / 72.0 + 0.5;        /* device pixels per unit, approx. */
  583.       pixfac = 72.0 / dpi * devpix;    /* 1, approx. */
  584.       scols = scale * cols * pixfac;
  585. ***************
  586. *** 302,320 ****
  587.       }
  588.       if ( PNM_FORMAT_TYPE( format ) == PPM_TYPE )
  589.       {
  590. !     printf( "/rpicstr %d string def\n", ( cols + padright ) * bps / 8 );
  591. !     printf( "/gpicstr %d string def\n", ( cols + padright ) * bps / 8 );
  592. !     printf( "/bpicstr %d string def\n", ( cols + padright ) * bps / 8 );
  593.       }
  594.       else
  595. !     printf( "/picstr %d string def\n", ( cols + padright ) * bps / 8 );
  596.       printf( "%%%%EndProlog\n" );
  597.       printf( "%%%%Page: 1 1\n" );
  598.       printf( "gsave\n" );
  599.       printf( "%g %g translate\n", llx, lly );
  600.       printf( "%g %g scale\n", scols, srows );
  601. !     printf( "%d %d %d\n", cols, rows, bps );
  602. !     printf( "[ %d 0 0 -%d 0 %d ]\n", cols, rows, rows );
  603.       if ( PNM_FORMAT_TYPE( format ) == PPM_TYPE )
  604.       {
  605.       printf( "{ rpicstr readstring }\n" );
  606. --- 324,344 ----
  607.       }
  608.       if ( PNM_FORMAT_TYPE( format ) == PPM_TYPE )
  609.       {
  610. !     printf( "/rpicstr %d string def\n", ( icols + padright ) * bps / 8 );
  611. !     printf( "/gpicstr %d string def\n", ( icols + padright ) * bps / 8 );
  612. !     printf( "/bpicstr %d string def\n", ( icols + padright ) * bps / 8 );
  613.       }
  614.       else
  615. !     printf( "/picstr %d string def\n", ( icols + padright ) * bps / 8 );
  616.       printf( "%%%%EndProlog\n" );
  617.       printf( "%%%%Page: 1 1\n" );
  618.       printf( "gsave\n" );
  619.       printf( "%g %g translate\n", llx, lly );
  620.       printf( "%g %g scale\n", scols, srows );
  621. !     if ( turnflag )
  622. !     printf( "0.5 0.5 translate  90 rotate  -0.5 -0.5 translate\n" );
  623. !     printf( "%d %d %d\n", icols, irows, bps );
  624. !     printf( "[ %d 0 0 -%d 0 %d ]\n", icols, irows, irows );
  625.       if ( PNM_FORMAT_TYPE( format ) == PPM_TYPE )
  626.       {
  627.       printf( "{ rpicstr readstring }\n" );
  628. diff -cr pbmplus05oct91/pnm/tifftopnm.c pbmplus30oct91/pnm/tifftopnm.c
  629. *** pbmplus05oct91/pnm/tifftopnm.c    Sun Oct  6 01:11:11 1991
  630. --- pbmplus30oct91/pnm/tifftopnm.c    Thu Oct 24 16:10:55 1991
  631. ***************
  632. *** 46,54 ****
  633.       register u_char sample;
  634.       register int bitsleft;
  635.       unsigned short bps, spp, photomet;
  636. !     unsigned short** redcolormap;
  637. !     unsigned short** greencolormap;
  638. !     unsigned short** bluecolormap;
  639.       char* usage = "[-headerdump] [tifffile]";
  640.   
  641.       pnm_init( &argc, argv );
  642. --- 46,54 ----
  643.       register u_char sample;
  644.       register int bitsleft;
  645.       unsigned short bps, spp, photomet;
  646. !     unsigned short* redcolormap;
  647. !     unsigned short* greencolormap;
  648. !     unsigned short* bluecolormap;
  649.       char* usage = "[-headerdump] [tifffile]";
  650.   
  651.       pnm_init( &argc, argv );
  652. ***************
  653. *** 86,94 ****
  654.       TIFFPrintDirectory( tif, stderr, TIFFPRINT_NONE );
  655.   
  656.       if ( ! TIFFGetField( tif, TIFFTAG_BITSPERSAMPLE, &bps ) )
  657. !     pm_error( "error getting bits per sample" );
  658.       if ( ! TIFFGetField( tif, TIFFTAG_SAMPLESPERPIXEL, &spp ) )
  659. !     pm_error( "error getting samples per pixel" );
  660.       if ( ! TIFFGetField( tif, TIFFTAG_PHOTOMETRIC, &photomet ) )
  661.       pm_error( "error getting photometric" );
  662.   
  663. --- 86,94 ----
  664.       TIFFPrintDirectory( tif, stderr, TIFFPRINT_NONE );
  665.   
  666.       if ( ! TIFFGetField( tif, TIFFTAG_BITSPERSAMPLE, &bps ) )
  667. !     bps = 1;
  668.       if ( ! TIFFGetField( tif, TIFFTAG_SAMPLESPERPIXEL, &spp ) )
  669. !     spp = 1;
  670.       if ( ! TIFFGetField( tif, TIFFTAG_PHOTOMETRIC, &photomet ) )
  671.       pm_error( "error getting photometric" );
  672.   
  673. diff -cr pbmplus05oct91/ppm/Makefile pbmplus30oct91/ppm/Makefile
  674. *** pbmplus05oct91/ppm/Makefile    Fri Sep 27 12:35:05 1991
  675. --- pbmplus30oct91/ppm/Makefile    Thu Oct 24 13:34:40 1991
  676. ***************
  677. *** 15,21 ****
  678.   #CFLAGS =    -O
  679.   CFLAGS =    -g
  680.   #CFLAGS =    -g -O
  681. ! RGBDEF =    -DRGB_DB=\"/usr/lib/X11/rgb.txt\"
  682.   #LDFLAGS =    -s
  683.   LDFLAGS =    
  684.   INSTALLBINARIES =    /usr/new/pbm
  685. --- 15,21 ----
  686.   #CFLAGS =    -O
  687.   CFLAGS =    -g
  688.   #CFLAGS =    -g -O
  689. ! RGBDEF =    -DRGB_DB=\"/usr/lib/X11/rgb\"
  690.   #LDFLAGS =    -s
  691.   LDFLAGS =    
  692.   INSTALLBINARIES =    /usr/new/pbm
  693. diff -cr pbmplus05oct91/ppm/libppm4.c pbmplus30oct91/ppm/libppm4.c
  694. *** pbmplus05oct91/ppm/libppm4.c    Sat Oct  5 23:37:10 1991
  695. --- pbmplus30oct91/ppm/libppm4.c    Sat Oct 26 00:14:45 1991
  696. ***************
  697. *** 202,208 ****
  698.       FILE* f;
  699.       char buf1[200], buf2[200];
  700.   
  701. !     if ( ( f = fopen( RGB_DB, "r" ) ) == NULL )
  702.           pm_error( "can't open color names database - reconfigure with correct RGBDEF" );
  703.       canonstr( colorname );
  704.       while ( fgets( buf1, sizeof(buf1), f ) != NULL )
  705. --- 202,209 ----
  706.       FILE* f;
  707.       char buf1[200], buf2[200];
  708.   
  709. !     (void) sprintf( buf1, "%s.txt", RGB_DB );
  710. !     if ( ( f = fopen( buf1, "r" ) ) == NULL )
  711.           pm_error( "can't open color names database - reconfigure with correct RGBDEF" );
  712.       canonstr( colorname );
  713.       while ( fgets( buf1, sizeof(buf1), f ) != NULL )
  714. ***************
  715. *** 272,278 ****
  716.       }
  717.   
  718.   #ifdef RGB_DB
  719. !     if ( ( f = fopen( RGB_DB, "r" ) ) == NULL )
  720.       pm_error( "can't open color names database - reconfigure with correct RGBDEF" );
  721.       best_diff = 32767;
  722.       while ( fgets( buf, sizeof(buf), f ) != NULL )
  723. --- 273,280 ----
  724.       }
  725.   
  726.   #ifdef RGB_DB
  727. !     (void) sprintf( buf, "%s.txt", RGB_DB );
  728. !     if ( ( f = fopen( buf, "r" ) ) == NULL )
  729.       pm_error( "can't open color names database - reconfigure with correct RGBDEF" );
  730.       best_diff = 32767;
  731.       while ( fgets( buf, sizeof(buf), f ) != NULL )
  732. diff -cr pbmplus05oct91/ppm/ppmtotga.1 pbmplus30oct91/ppm/ppmtotga.1
  733. *** pbmplus05oct91/ppm/ppmtotga.1    Thu Sep 26 17:16:38 1991
  734. --- pbmplus30oct91/ppm/ppmtotga.1    Wed Oct 30 09:37:56 1991
  735. ***************
  736. *** 1,4 ****
  737. ! .TH ppmtotga 1 "26 August 1989"
  738.   .IX ppmtotga
  739.   .SH NAME
  740.   ppmtotga - convert portable pixmap into a TrueVision Targa file
  741. --- 1,4 ----
  742. ! .TH ppmtotga 1 "28 October 1991"
  743.   .IX ppmtotga
  744.   .SH NAME
  745.   ppmtotga - convert portable pixmap into a TrueVision Targa file
  746. ***************
  747. *** 5,10 ****
  748. --- 5,11 ----
  749.   .SH SYNOPSIS
  750.   .B ppmtotga
  751.   .RB [ -mono|-cmap|-rgb ]
  752. + .RB [ -norle ]
  753.   .RI [ ppmfile ]
  754.   .SH DESCRIPTION
  755.   Reads a portable pixmap as input.
  756. ***************
  757. *** 22,27 ****
  758. --- 23,32 ----
  759.   .TP
  760.   .B -rgb
  761.   Forces Targa file to be of type 24 bit unmapped color.
  762. + .TP
  763. + .B -norle
  764. + Disables run-length encoding, in case you have a Targa reader which
  765. + can't read run-length encoded files.
  766.   .PP
  767.   All flags can be abbreviated to their shortest unique prefix.  If no
  768.   file type is specified the most highly constained compatible type is
  769. ***************
  770. *** 33,39 ****
  771.   .SH "SEE ALSO"
  772.   tgatoppm(1), ppm(5)
  773.   .SH AUTHOR
  774. ! Copyright (C) 1991 by Mark Shand.
  775.   .\" Permission to use, copy, modify, and distribute this software and its
  776.   .\" documentation for any purpose and without fee is hereby granted, provided
  777.   .\" that the above copyright notice appear in all copies and that both that
  778. --- 38,44 ----
  779.   .SH "SEE ALSO"
  780.   tgatoppm(1), ppm(5)
  781.   .SH AUTHOR
  782. ! Copyright (C) 1989, 1991 by Mark Shand and Jef Poskanzer.
  783.   .\" Permission to use, copy, modify, and distribute this software and its
  784.   .\" documentation for any purpose and without fee is hereby granted, provided
  785.   .\" that the above copyright notice appear in all copies and that both that
  786. diff -cr pbmplus05oct91/ppm/ppmtotga.c pbmplus30oct91/ppm/ppmtotga.c
  787. *** pbmplus05oct91/ppm/ppmtotga.c    Thu Sep 26 17:16:14 1991
  788. --- pbmplus30oct91/ppm/ppmtotga.c    Wed Oct 30 10:56:22 1991
  789. ***************
  790. *** 1,6 ****
  791.   /* ppmtotga.c - read a portable pixmap and produce a TrueVision Targa file
  792.   **
  793. ! ** Copyright (C) 1991 by Mark Shand
  794.   **
  795.   ** Permission to use, copy, modify, and distribute this software and its
  796.   ** documentation for any purpose and without fee is hereby granted, provided
  797. --- 1,6 ----
  798.   /* ppmtotga.c - read a portable pixmap and produce a TrueVision Targa file
  799.   **
  800. ! ** Copyright (C) 1989, 1991 by Mark Shand and Jef Poskanzer
  801.   **
  802.   ** Permission to use, copy, modify, and distribute this software and its
  803.   ** documentation for any purpose and without fee is hereby granted, provided
  804. ***************
  805. *** 10,23 ****
  806.   ** implied warranty.
  807.   */
  808.   
  809. - #include <ctype.h>
  810.   #include "ppm.h"
  811.   #include "ppmcmap.h"
  812.   #include "tga.h"
  813.   
  814. ! /* Max number of colors allowed in ppm input. */
  815.   #define MAXCOLORS 256
  816.   
  817.   void
  818.   main( argc, argv )
  819.       int argc;
  820. --- 10,33 ----
  821.   ** implied warranty.
  822.   */
  823.   
  824.   #include "ppm.h"
  825.   #include "ppmcmap.h"
  826.   #include "tga.h"
  827.   
  828. ! /* Max number of colors allowed for colormapped output. */
  829.   #define MAXCOLORS 256
  830.   
  831. + /* Forward routines. */
  832. + static void writetga ARGS(( struct ImageHeader* tgaP, char* id ));
  833. + static void put_map_entry ARGS(( pixel* valueP, int size, pixval maxval ));
  834. + static void compute_runlengths ARGS(( int cols, pixel* pixelrow, int* runlength ));
  835. + static void put_pixel ARGS(( pixel* pP, int imgtype, pixval maxval, colorhash_table cht ));
  836. + static void put_mono ARGS(( pixel* pP, pixval maxval ));
  837. + static void put_map ARGS(( pixel* pP, colorhash_table cht ));
  838. + static void put_rgb ARGS(( pixel* pP, pixval maxval ));
  839. + /* Routines. */
  840.   void
  841.   main( argc, argv )
  842.       int argc;
  843. ***************
  844. *** 26,47 ****
  845.       FILE* ifp;
  846.       pixel** pixels;
  847.       register pixel* pP;
  848. !     int argn, rows, cols, ncolors, row, col, i, format, realrow;
  849.       pixval maxval;
  850. -     colorhash_table cht;
  851.       colorhist_vector chv;
  852.       char out_name[100];
  853.       char* cp;
  854. !     char* usage = "[-name <tganame>] [-mono|-cmap|-rgb] [ppmfile]";
  855.       struct ImageHeader tgaHeader;
  856.   
  857.       ppm_init( &argc, argv );
  858.       out_name[0] = '\0';
  859.   
  860.       argn = 1;
  861.       tgaHeader.ImgType = TGA_Null;
  862. !     /* Check for command line options. */
  863.       while ( argn < argc && argv[argn][0] == '-' && argv[argn][1] != '\0' )
  864.           {
  865.           if ( pm_keymatch( argv[argn], "-name", 2 ) )
  866. --- 36,59 ----
  867.       FILE* ifp;
  868.       pixel** pixels;
  869.       register pixel* pP;
  870. !     pixel p;
  871. !     int argn, rle_flag, rows, cols, ncolors, row, col, i, format, realrow;
  872.       pixval maxval;
  873.       colorhist_vector chv;
  874. +     colorhash_table cht;
  875.       char out_name[100];
  876.       char* cp;
  877. !     int* runlength;
  878. !     char* usage = "[-name <tganame>] [-mono|-cmap|-rgb] [-norle] [ppmfile]";
  879.       struct ImageHeader tgaHeader;
  880.   
  881.       ppm_init( &argc, argv );
  882.       out_name[0] = '\0';
  883.   
  884. +     /* Check for command line options. */
  885.       argn = 1;
  886.       tgaHeader.ImgType = TGA_Null;
  887. !     rle_flag = 1;
  888.       while ( argn < argc && argv[argn][0] == '-' && argv[argn][1] != '\0' )
  889.           {
  890.           if ( pm_keymatch( argv[argn], "-name", 2 ) )
  891. ***************
  892. *** 57,62 ****
  893. --- 69,76 ----
  894.               tgaHeader.ImgType = TGA_Mono;
  895.           else if ( pm_keymatch( argv[argn], "-rgb", 2 ) )
  896.               tgaHeader.ImgType = TGA_RGB;
  897. +         else if ( pm_keymatch( argv[argn], "-norle", 2 ) )
  898. +             rle_flag = 0;
  899.           else
  900.               pm_usage( usage );
  901.           ++argn;
  902. ***************
  903. *** 93,287 ****
  904.   
  905.       /* Read in the ppm file. */
  906.       ppm_readppminit( ifp, &cols, &rows, &maxval, &format);
  907. !     pixels = ppm_allocarray(cols, rows);
  908. !     for (row = 0; row < rows; row++)
  909. !     ppm_readppmrow(ifp, pixels[row], cols, maxval, format);
  910.       pm_close( ifp );
  911.   
  912.       /* Figure out the colormap. */
  913. !     switch (PPM_FORMAT_TYPE(format))
  914. !     {
  915.           case PPM_TYPE:
  916. !             if (tgaHeader.ImgType == TGA_Mono)
  917. !                 pm_error("input not a graymap, filter through ppmtopgm first");
  918. !             if (tgaHeader.ImgType == TGA_Null || tgaHeader.ImgType == TGA_Map)
  919. !             {
  920. !                 pm_message( "computing colormap..." );
  921. !                 chv = ppm_computecolorhist( pixels, cols, rows, MAXCOLORS, &ncolors );
  922. !                 if ( chv == (colorhist_vector) 0 )
  923. !                 {
  924. !                     if (tgaHeader.ImgType == TGA_Map)
  925. !                         pm_error(
  926. !                             "too many colors - try doing a 'ppmquant %d'",
  927. !                             MAXCOLORS);
  928. !                     else
  929. !                         tgaHeader.ImgType = TGA_RGB;
  930. !                 }
  931. !                 else
  932. !                 {
  933. !                     pm_message( "%d colors found", ncolors );
  934. !                     if (tgaHeader.ImgType == TGA_Null)
  935. !                         tgaHeader.ImgType = TGA_Map;
  936. !                 }
  937. !             }
  938. !             break;
  939.           case PGM_TYPE:
  940.           case PBM_TYPE:
  941. !             if (tgaHeader.ImgType == TGA_Null)
  942. !                 tgaHeader.ImgType = TGA_Mono;
  943. !             else if (tgaHeader.ImgType == TGA_Map)
  944. !             {
  945. !                 pm_message( "computing colormap..." );
  946. !                 chv = ppm_computecolorhist( pixels, cols, rows, MAXCOLORS, &ncolors );
  947. !                 if ( chv == (colorhist_vector) 0 )
  948. !                     pm_error("can't happen");
  949. !                 pm_message( "%d colors found", ncolors );
  950. !             }
  951. !             break;
  952.   
  953.           default:
  954. !             pm_error( "can't happen");
  955. !     }
  956.   
  957. !     tgaHeader.IDLength = 0;
  958.       
  959. !     if (tgaHeader.ImgType == TGA_Map)
  960. !     {
  961.           /* Make a hash table for fast color lookup. */
  962.           cht = ppm_colorhisttocolorhash( chv, ncolors );
  963.   
  964.           tgaHeader.CoMapType = 1;
  965. !         tgaHeader.Index_lo = 0;
  966. !         tgaHeader.Index_hi = 0;
  967. !         tgaHeader.Length_lo = ncolors%256;
  968. !         tgaHeader.Length_hi = ncolors/256;
  969.           tgaHeader.CoSize = 24;
  970. !         tgaHeader.PixelSize = 8;
  971. !     }
  972.       else
  973. !     {
  974.           tgaHeader.CoMapType = 0;
  975. -         tgaHeader.Index_lo = 0;
  976. -         tgaHeader.Index_hi = 0;
  977.           tgaHeader.Length_lo = 0;
  978.           tgaHeader.Length_hi = 0;
  979.           tgaHeader.CoSize = 0;
  980. !         tgaHeader.PixelSize = (tgaHeader.ImgType == TGA_RGB) ? 24 : 8;
  981. !     }
  982.       tgaHeader.X_org_lo = tgaHeader.X_org_hi = 0;
  983.       tgaHeader.Y_org_lo = tgaHeader.Y_org_hi = 0;
  984. !     tgaHeader.Width_lo = cols%256; tgaHeader.Width_hi = cols/256;
  985. !     tgaHeader.Height_lo = rows%256; tgaHeader.Height_hi = rows/256;
  986.       tgaHeader.AttBits = 0;
  987.       tgaHeader.Rsrvd = 0;
  988.       tgaHeader.IntrLve = 0;
  989.   
  990. !     /* Write out the TGA header. */
  991. !     writetga(&tgaHeader, NULL);
  992.   
  993. !     if (tgaHeader.ImgType == TGA_Map)
  994. !     {
  995. !         /* Write out the TGA colormap. */
  996. !         for (i = 0; i < ncolors; i++)
  997. !             put_map_entry(chv[i].color, tgaHeader.CoSize, maxval);
  998. !     }
  999.   
  1000.       /* Write out the pixels */
  1001.       for ( row = 0; row < rows; ++row )
  1002. !         {
  1003. !             realrow = row;
  1004. !             if ( tgaHeader.OrgBit == 0 )
  1005. !                 realrow = rows - realrow - 1;
  1006. !             if (tgaHeader.ImgType == TGA_Map)
  1007. !                 for ( col = 0; col < cols; col++ )
  1008. !                     putchar(ppm_lookupcolor(cht, pixels[realrow]+col));
  1009. !             else if (tgaHeader.ImgType == TGA_Mono)
  1010. !                 for ( col = 0; col < cols; col++ )
  1011. !                 {
  1012. !                     pixel sP;
  1013. !                     PPM_DEPTH(sP, pixels[realrow][col], maxval, (pixval) 255);
  1014. !                     putchar((int) PPM_LUMIN(sP));
  1015. !                 }
  1016. !             else if (tgaHeader.ImgType == TGA_RGB)
  1017. !                 for ( col = 0; col < cols; col++ )
  1018. !                 {
  1019. !                     pixel sP;
  1020. !                     PPM_DEPTH(sP, pixels[realrow][col], maxval, (pixval) 255);
  1021. !                     putchar(PPM_GETB(sP));
  1022. !                     putchar(PPM_GETG(sP));
  1023. !                     putchar(PPM_GETR(sP));
  1024. !                 }
  1025. !         }
  1026.       exit( 0 );
  1027.       }
  1028.   
  1029. ! writetga( tgaP, id)
  1030. ! struct ImageHeader *tgaP;
  1031. ! char *id;
  1032. ! {
  1033.       unsigned char flags;
  1034.   
  1035. !     putchar(tgaP->IDLength);
  1036. !     putchar(tgaP->CoMapType);
  1037. !     putchar(tgaP->ImgType);
  1038. !     putchar(tgaP->Index_lo);
  1039. !     putchar(tgaP->Index_hi);
  1040. !     putchar(tgaP->Length_lo);
  1041. !     putchar(tgaP->Length_hi);
  1042. !     putchar(tgaP->CoSize);
  1043. !     putchar(tgaP->X_org_lo);
  1044. !     putchar(tgaP->X_org_hi);
  1045. !     putchar(tgaP->Y_org_lo);
  1046. !     putchar(tgaP->Y_org_hi);
  1047. !     putchar(tgaP->Width_lo);
  1048. !     putchar(tgaP->Width_hi);
  1049. !     putchar(tgaP->Height_lo);
  1050. !     putchar(tgaP->Height_hi);
  1051. !     putchar(tgaP->PixelSize);
  1052. !     flags = (tgaP->AttBits & 0xf)
  1053. !             | ((tgaP->Rsrvd & 0x1) << 4)
  1054. !             | ((tgaP->OrgBit & 0x1) << 5)
  1055. !             | ((tgaP->OrgBit & 0x3) << 6);
  1056. !     putchar(flags);
  1057. !     if (tgaP->IDLength)
  1058. !         fwrite( id, 1, (int) tgaP->IDLength, stdout);
  1059. ! }
  1060.       
  1061. ! put_map_entry(Value, Size, maxval) 
  1062. ! pixel Value;
  1063. ! int Size;
  1064. ! pixval maxval;
  1065. ! {
  1066.       int j;
  1067. !     pixel sP;
  1068.       
  1069. !     switch ( Size )
  1070. !     {
  1071.       case 8:                /* Grey scale. */
  1072. !     
  1073. !     PPM_DEPTH(sP, Value, maxval, (pixval) 255);
  1074. !         putchar((int) PPM_LUMIN(sP));
  1075.       break;
  1076.   
  1077.       case 16:            /* 5 bits each of red green and blue. */
  1078.       case 15:            /* Watch for byte order. */
  1079. !     PPM_DEPTH(sP, Value, maxval, 31);
  1080. !     j = (int) PPM_GETB(sP)
  1081. !       | ((int) PPM_GETG(sP) << 5)
  1082. !       | ((int) PPM_GETR(sP) << 10);
  1083. !     putchar(j%256);
  1084. !     putchar(j/256);
  1085.       break;
  1086.   
  1087.       case 32:
  1088.       case 24:            /* 8 bits each of blue green and red. */
  1089. !     PPM_DEPTH(sP, Value, maxval, (pixval) 255);
  1090. !     putchar(PPM_GETB(sP));
  1091. !     putchar(PPM_GETG(sP));
  1092. !     putchar(PPM_GETR(sP));
  1093.       break;
  1094.   
  1095.       default:
  1096. !     pm_error( "unknown colormap pixel size (#2) - %d", Size );
  1097.       }
  1098. ! }
  1099. --- 107,450 ----
  1100.   
  1101.       /* Read in the ppm file. */
  1102.       ppm_readppminit( ifp, &cols, &rows, &maxval, &format);
  1103. !     pixels = ppm_allocarray( cols, rows );
  1104. !     for ( row = 0; row < rows; ++row )
  1105. !     ppm_readppmrow( ifp, pixels[row], cols, maxval, format );
  1106.       pm_close( ifp );
  1107.   
  1108.       /* Figure out the colormap. */
  1109. !     switch ( PPM_FORMAT_TYPE( format ) )
  1110. !     {
  1111.           case PPM_TYPE:
  1112. !     if ( tgaHeader.ImgType == TGA_Mono )
  1113. !         pm_error( "input is not a graymap, filter through ppmtopgm first" );
  1114. !     if ( tgaHeader.ImgType == TGA_Null || tgaHeader.ImgType == TGA_Map )
  1115. !         {
  1116. !         pm_message( "computing colormap..." );
  1117. !         chv = ppm_computecolorhist(
  1118. !         pixels, cols, rows, MAXCOLORS, &ncolors );
  1119. !         if ( chv == (colorhist_vector) 0 )
  1120. !         {
  1121. !         if ( tgaHeader.ImgType == TGA_Map )
  1122. !             pm_error(
  1123. !             "too many colors - try doing a 'ppmquant %d'",
  1124. !             MAXCOLORS );
  1125. !         else
  1126. !             tgaHeader.ImgType = TGA_RGB;
  1127. !         }
  1128. !         else
  1129. !         {
  1130. !         pm_message( "%d colors found", ncolors );
  1131. !         if ( tgaHeader.ImgType == TGA_Null )
  1132. !             tgaHeader.ImgType = TGA_Map;
  1133. !         }
  1134. !         }
  1135. !     break;
  1136.           case PGM_TYPE:
  1137.           case PBM_TYPE:
  1138. !     if ( tgaHeader.ImgType == TGA_Null )
  1139. !         tgaHeader.ImgType = TGA_Mono;
  1140. !     else if ( tgaHeader.ImgType == TGA_Map )
  1141. !         {
  1142. !         pm_message( "computing colormap..." );
  1143. !         chv = ppm_computecolorhist(
  1144. !         pixels, cols, rows, MAXCOLORS, &ncolors );
  1145. !         if ( chv == (colorhist_vector) 0 )
  1146. !         pm_error( "can't happen" );
  1147. !         pm_message( "%d colors found", ncolors );
  1148. !         }
  1149. !     break;
  1150.   
  1151.           default:
  1152. !     pm_error( "can't happen" );
  1153. !     }
  1154.   
  1155. !     if ( rle_flag )
  1156. !     {
  1157. !     switch ( tgaHeader.ImgType )
  1158. !         {
  1159. !         case TGA_Mono:
  1160. !         tgaHeader.ImgType = TGA_RLEMono;
  1161. !         break;
  1162. !         case TGA_Map:
  1163. !         tgaHeader.ImgType = TGA_RLEMap;
  1164. !         break;
  1165. !         case TGA_RGB:
  1166. !         tgaHeader.ImgType = TGA_RLERGB;
  1167. !         break;
  1168. !         default:
  1169. !         pm_error( "can't happen" );
  1170. !         }
  1171. !     runlength = (int*) pm_allocrow( cols, sizeof(int) );
  1172. !     }
  1173.       
  1174. !     tgaHeader.IDLength = 0;
  1175. !     tgaHeader.Index_lo = 0;
  1176. !     tgaHeader.Index_hi = 0;
  1177. !     if ( tgaHeader.ImgType == TGA_Map || tgaHeader.ImgType == TGA_RLEMap )
  1178. !     {
  1179.           /* Make a hash table for fast color lookup. */
  1180.           cht = ppm_colorhisttocolorhash( chv, ncolors );
  1181.   
  1182.           tgaHeader.CoMapType = 1;
  1183. !         tgaHeader.Length_lo = ncolors % 256;
  1184. !         tgaHeader.Length_hi = ncolors / 256;
  1185.           tgaHeader.CoSize = 24;
  1186. !     }
  1187.       else
  1188. !     {
  1189.           tgaHeader.CoMapType = 0;
  1190.           tgaHeader.Length_lo = 0;
  1191.           tgaHeader.Length_hi = 0;
  1192.           tgaHeader.CoSize = 0;
  1193. !     }
  1194. !     if ( tgaHeader.ImgType == TGA_RGB || tgaHeader.ImgType == TGA_RLERGB )
  1195. !     tgaHeader.PixelSize = 24;
  1196. !     else
  1197. !     tgaHeader.PixelSize = 8;
  1198.       tgaHeader.X_org_lo = tgaHeader.X_org_hi = 0;
  1199.       tgaHeader.Y_org_lo = tgaHeader.Y_org_hi = 0;
  1200. !     tgaHeader.Width_lo = cols % 256;
  1201. !     tgaHeader.Width_hi = cols / 256;
  1202. !     tgaHeader.Height_lo = rows % 256;
  1203. !     tgaHeader.Height_hi = rows / 256;
  1204.       tgaHeader.AttBits = 0;
  1205.       tgaHeader.Rsrvd = 0;
  1206.       tgaHeader.IntrLve = 0;
  1207.   
  1208. !     /* Write out the Targa header. */
  1209. !     writetga( &tgaHeader, (char*) 0 );
  1210.   
  1211. !     if ( tgaHeader.ImgType == TGA_Map || tgaHeader.ImgType == TGA_RLEMap )
  1212. !     {
  1213. !         /* Write out the Targa colormap. */
  1214. !         for ( i = 0; i < ncolors; ++i )
  1215. !             put_map_entry( &chv[i].color, tgaHeader.CoSize, maxval );
  1216. !     }
  1217.   
  1218.       /* Write out the pixels */
  1219.       for ( row = 0; row < rows; ++row )
  1220. !     {
  1221. !     realrow = row;
  1222. !     if ( tgaHeader.OrgBit == 0 )
  1223. !         realrow = rows - realrow - 1;
  1224. !     if ( rle_flag )
  1225. !         {
  1226. !         compute_runlengths( cols, pixels[realrow], runlength );
  1227. !         for ( col = 0; col < cols; )
  1228. !         {
  1229. !         if ( runlength[col] > 0 )
  1230. !             {
  1231. !             putchar( 0x80 + runlength[col] - 1 );
  1232. !             put_pixel(
  1233. !             &(pixels[realrow][col]),
  1234. !             tgaHeader.ImgType, maxval, cht );
  1235. !             col += runlength[col];
  1236. !             }
  1237. !         else if ( runlength[col] < 0 )
  1238. !             {
  1239. !             putchar( -runlength[col] - 1 );
  1240. !             for ( i = 0; i < -runlength[col]; ++i )
  1241. !             put_pixel(
  1242. !                 &(pixels[realrow][col + i]),
  1243. !                 tgaHeader.ImgType, maxval, cht );
  1244. !             col += -runlength[col];
  1245. !             }
  1246. !         else
  1247. !             pm_error( "can't happen" );
  1248. !         }
  1249. !         }
  1250. !     else
  1251. !         {
  1252. !         for ( col = 0, pP = pixels[realrow]; col < cols; ++col, ++pP )
  1253. !         put_pixel( pP, tgaHeader.ImgType, maxval, cht );
  1254. !         }
  1255. !     }
  1256.       exit( 0 );
  1257.       }
  1258.   
  1259. ! static void
  1260. ! writetga( tgaP, id )
  1261. !     struct ImageHeader* tgaP;
  1262. !     char* id;
  1263. !     {
  1264.       unsigned char flags;
  1265.   
  1266. !     putchar( tgaP->IDLength );
  1267. !     putchar( tgaP->CoMapType );
  1268. !     putchar( tgaP->ImgType );
  1269. !     putchar( tgaP->Index_lo );
  1270. !     putchar( tgaP->Index_hi );
  1271. !     putchar( tgaP->Length_lo );
  1272. !     putchar( tgaP->Length_hi );
  1273. !     putchar( tgaP->CoSize );
  1274. !     putchar( tgaP->X_org_lo );
  1275. !     putchar( tgaP->X_org_hi );
  1276. !     putchar( tgaP->Y_org_lo );
  1277. !     putchar( tgaP->Y_org_hi );
  1278. !     putchar( tgaP->Width_lo );
  1279. !     putchar( tgaP->Width_hi );
  1280. !     putchar( tgaP->Height_lo );
  1281. !     putchar( tgaP->Height_hi );
  1282. !     putchar( tgaP->PixelSize );
  1283. !     flags = ( tgaP->AttBits & 0xf ) | ( ( tgaP->Rsrvd & 0x1 ) << 4 ) |
  1284. !         ( ( tgaP->OrgBit & 0x1 ) << 5 ) | ( ( tgaP->OrgBit & 0x3 ) << 6 );
  1285. !     putchar( flags );
  1286. !     if ( tgaP->IDLength )
  1287. !         fwrite( id, 1, (int) tgaP->IDLength, stdout );
  1288. !     }
  1289.       
  1290. ! #if __STDC__
  1291. ! static void
  1292. ! put_map_entry( pixel* valueP, int size, pixval maxval )
  1293. ! #else /*__STDC__*/
  1294. ! static void
  1295. ! put_map_entry( valueP, size, maxval )
  1296. !     pixel* valueP;
  1297. !     int size;
  1298. !     pixval maxval;
  1299. ! #endif /*__STDC__*/
  1300. !     {
  1301.       int j;
  1302. !     pixel p;
  1303.       
  1304. !     switch ( size )
  1305. !     {
  1306.       case 8:                /* Grey scale. */
  1307. !     put_mono( valueP, maxval );
  1308.       break;
  1309.   
  1310.       case 16:            /* 5 bits each of red green and blue. */
  1311.       case 15:            /* Watch for byte order. */
  1312. !     PPM_DEPTH( p, *valueP, maxval, 31 );
  1313. !     j = (int) PPM_GETB( p ) | ( (int) PPM_GETG( p ) << 5 ) |
  1314. !         ( (int) PPM_GETR( p ) << 10 );
  1315. !     putchar( j % 256 );
  1316. !     putchar( j / 256 );
  1317.       break;
  1318.   
  1319.       case 32:
  1320.       case 24:            /* 8 bits each of blue green and red. */
  1321. !     put_rgb( valueP, maxval );
  1322.       break;
  1323.   
  1324.       default:
  1325. !     pm_error( "unknown colormap pixel size (#2) - %d", size );
  1326. !     }
  1327.       }
  1328. ! static void
  1329. ! compute_runlengths( cols, pixelrow, runlength )
  1330. !     int cols;
  1331. !     pixel* pixelrow;
  1332. !     int* runlength;
  1333. !     {
  1334. !     int col, start;
  1335. !     /* Initialize all run lengths to 0.  (This is just an error check.) */
  1336. !     for ( col = 0; col < cols; ++col )
  1337. !     runlength[col] = 0;
  1338. !     
  1339. !     /* Find runs of identical pixels. */
  1340. !     for ( col = 0; col < cols; )
  1341. !     {
  1342. !     start = col;
  1343. !     do {
  1344. !         ++col;
  1345. !         }
  1346. !     while ( col < cols &&
  1347. !         col - start < 128 &&
  1348. !         PPM_EQUAL( pixelrow[col], pixelrow[start] ) );
  1349. !     runlength[start] = col - start;
  1350. !     }
  1351. !     
  1352. !     /* Now look for runs of length-1 runs, and turn them into negative runs. */
  1353. !     for ( col = 0; col < cols; )
  1354. !     {
  1355. !     if ( runlength[col] == 1 )
  1356. !         {
  1357. !         start = col;
  1358. !         while ( col < cols &&
  1359. !             col - start < 128 &&
  1360. !             runlength[col] == 1 )
  1361. !         {
  1362. !         runlength[col] = 0;
  1363. !         ++col;
  1364. !         }
  1365. !         runlength[start] = - ( col - start );
  1366. !         }
  1367. !     else
  1368. !         col += runlength[col];
  1369. !     }
  1370. !     }
  1371. ! #if __STDC__
  1372. ! static void
  1373. ! put_pixel( pixel* pP, int imgtype, pixval maxval, colorhash_table cht )
  1374. ! #else /*__STDC__*/
  1375. ! static void
  1376. ! put_pixel( pP, imgtype, maxval, cht )
  1377. !     pixel* pP;
  1378. !     int imgtype;
  1379. !     pixval maxval;
  1380. !     colorhash_table cht;
  1381. ! #endif /*__STDC__*/
  1382. !     {
  1383. !     switch ( imgtype )
  1384. !     {
  1385. !     case TGA_Mono:
  1386. !     case TGA_RLEMono:
  1387. !     put_mono( pP, maxval );
  1388. !     break;
  1389. !     case TGA_Map:
  1390. !     case TGA_RLEMap:
  1391. !     put_map( pP, cht );
  1392. !     break;
  1393. !     case TGA_RGB:
  1394. !     case TGA_RLERGB:
  1395. !     put_rgb( pP, maxval );
  1396. !     break;
  1397. !     default:
  1398. !     pm_error( "can't happen" );
  1399. !     }
  1400. !     }
  1401. ! #if __STDC__
  1402. ! static void
  1403. ! put_mono( pixel* pP, pixval maxval )
  1404. ! #else /*__STDC__*/
  1405. ! static void
  1406. ! put_mono( pP, maxval )
  1407. !     pixel* pP;
  1408. !     pixval maxval;
  1409. ! #endif /*__STDC__*/
  1410. !     {
  1411. !     PPM_DEPTH( *pP, *pP, maxval, (pixval) 255 );
  1412. !     putchar( PPM_GETR( *pP ) );
  1413. !     }
  1414. ! static void
  1415. ! put_map( pP, cht )
  1416. !     pixel* pP;
  1417. !     colorhash_table cht;
  1418. !     {
  1419. !     putchar( ppm_lookupcolor( cht, pP ) );
  1420. !     }
  1421. ! #if __STDC__
  1422. ! static void
  1423. ! put_rgb( pixel* pP, pixval maxval )
  1424. ! #else /*__STDC__*/
  1425. ! static void
  1426. ! put_rgb( pP, maxval )
  1427. !     pixel* pP;
  1428. !     pixval maxval;
  1429. ! #endif /*__STDC__*/
  1430. !     {
  1431. !     PPM_DEPTH( *pP, *pP, maxval, (pixval) 255 );
  1432. !     putchar( PPM_GETB( *pP ) );
  1433. !     putchar( PPM_GETG( *pP ) );
  1434. !     putchar( PPM_GETR( *pP ) );
  1435. !     }
  1436. diff -cr pbmplus05oct91/ppm/tgatoppm.c pbmplus30oct91/ppm/tgatoppm.c
  1437. *** pbmplus05oct91/ppm/tgatoppm.c    Fri Jun 28 15:37:52 1991
  1438. --- pbmplus30oct91/ppm/tgatoppm.c    Wed Oct 30 09:38:05 1991
  1439. ***************
  1440. *** 36,42 ****
  1441.       int i;
  1442.       unsigned int temp1, temp2;
  1443.       FILE* ifp;
  1444. !     int argn, debug, rows, cols, row, col, realrow;
  1445.       int maxval;
  1446.       pixel** pixels;
  1447.       char* usage = " [-debug] [tgafile]";
  1448. --- 36,42 ----
  1449.       int i;
  1450.       unsigned int temp1, temp2;
  1451.       FILE* ifp;
  1452. !     int argn, debug, rows, cols, row, col, realrow, truerow, baserow;
  1453.       int maxval;
  1454.       pixel** pixels;
  1455.       char* usage = " [-debug] [tgafile]";
  1456. ***************
  1457. *** 172,178 ****
  1458.       temp2 = tga_head.Length_lo + tga_head.Length_hi * 256;
  1459.       if ( ( temp1 + temp2 + 1 ) >= MAXCOLORS )
  1460.           pm_error( "too many colors - %d", ( temp1 + temp2 + 1 ) );
  1461. !     for ( i = temp1; i < ( temp1 + temp2 ); i++ )
  1462.           get_map_entry( ifp, &ColorMap[i], (int) tga_head.CoSize );
  1463.       }
  1464.   
  1465. --- 172,178 ----
  1466.       temp2 = tga_head.Length_lo + tga_head.Length_hi * 256;
  1467.       if ( ( temp1 + temp2 + 1 ) >= MAXCOLORS )
  1468.           pm_error( "too many colors - %d", ( temp1 + temp2 + 1 ) );
  1469. !     for ( i = temp1; i < ( temp1 + temp2 ); ++i )
  1470.           get_map_entry( ifp, &ColorMap[i], (int) tga_head.CoSize );
  1471.       }
  1472.   
  1473. ***************
  1474. *** 186,233 ****
  1475.   
  1476.       /* Read the Targa file body and convert to portable format. */
  1477.       pixels = ppm_allocarray( cols, rows );
  1478. !     for ( row = 0; row < rows; row++ )
  1479.       {
  1480. !     if ( tga_head.IntrLve == TGA_IL_Four )
  1481. !         {
  1482. !         if ( 4 * row < rows )
  1483. !         realrow = 4 * row;
  1484. !         else if ( 2 * row < rows )
  1485. !         {
  1486. !         realrow = row - rows / 4;
  1487. !         realrow = 4 * realrow + 1;
  1488. !         }
  1489. !         else if ( 4 * row < 3 * rows )
  1490. !         {
  1491. !         realrow = row - rows / 2;
  1492. !         realrow = 4 * realrow + 2;
  1493. !         }
  1494. !         else
  1495. !         {
  1496. !         realrow = row - rows / 2 - rows / 4;
  1497. !         realrow = 4 * realrow + 3;
  1498. !         }
  1499. !         }
  1500. !     else if ( tga_head.IntrLve == TGA_IL_Two )
  1501. !         {
  1502. !         if ( 2 * row < rows )
  1503. !         realrow = 2 * row;
  1504. !         else
  1505. !         {
  1506. !         realrow = row - rows / 2;
  1507. !         realrow = 2 * realrow + 1;
  1508. !         }
  1509. !         }
  1510. !     else
  1511. !         realrow = row;
  1512.       if ( tga_head.OrgBit == 0 )
  1513.           realrow = rows - realrow - 1;
  1514.   
  1515. !     for ( col = 0; col < cols; col++ )
  1516.           get_pixel( ifp, &(pixels[realrow][col]), (int) tga_head.PixelSize );
  1517.       }
  1518.       pm_close( ifp );
  1519.   
  1520.       ppm_writeppm( stdout, pixels, cols, rows, (pixval) maxval, 0 );
  1521. --- 186,210 ----
  1522.   
  1523.       /* Read the Targa file body and convert to portable format. */
  1524.       pixels = ppm_allocarray( cols, rows );
  1525. !     truerow = 0;
  1526. !     baserow = 0;
  1527. !     for ( row = 0; row < rows; ++row )
  1528.       {
  1529. !     realrow = truerow;
  1530.       if ( tga_head.OrgBit == 0 )
  1531.           realrow = rows - realrow - 1;
  1532.   
  1533. !     for ( col = 0; col < cols; ++col )
  1534.           get_pixel( ifp, &(pixels[realrow][col]), (int) tga_head.PixelSize );
  1535. +     if ( tga_head.IntrLve == TGA_IL_Four )
  1536. +         truerow += 4;
  1537. +     else if ( tga_head.IntrLve == TGA_IL_Two )
  1538. +         truerow += 2;
  1539. +     else
  1540. +         ++truerow;
  1541. +     if ( truerow >= rows )
  1542. +         truerow = ++baserow;
  1543.       }
  1544.       pm_close( ifp );
  1545.   
  1546.       ppm_writeppm( stdout, pixels, cols, rows, (pixval) maxval, 0 );
  1547. ***************
  1548. *** 326,332 ****
  1549.           { /* Have to restart run. */
  1550.           unsigned char i;
  1551.           i = getbyte( ifp );
  1552. !         RLE_flag = ( i & 0x80 ) >> 7;
  1553.           if ( RLE_flag == 0 )
  1554.           /* Stream of unencoded pixels. */
  1555.           RLE_count = i + 1;
  1556. --- 303,309 ----
  1557.           { /* Have to restart run. */
  1558.           unsigned char i;
  1559.           i = getbyte( ifp );
  1560. !         RLE_flag = ( i & 0x80 );
  1561.           if ( RLE_flag == 0 )
  1562.           /* Stream of unencoded pixels. */
  1563.           RLE_count = i + 1;
  1564. ***************
  1565. *** 334,344 ****
  1566.           /* Single pixel replicated. */
  1567.           RLE_count = i - 127;
  1568.           /* Decrement count & get pixel. */
  1569. !         RLE_count--;
  1570.           }
  1571.       else
  1572.           { /* Have already read count & (at least) first pixel. */
  1573. !         RLE_count--;
  1574.           if ( RLE_flag != 0 )
  1575.           /* Replicated pixels. */
  1576.           goto PixEncode;
  1577. --- 311,321 ----
  1578.           /* Single pixel replicated. */
  1579.           RLE_count = i - 127;
  1580.           /* Decrement count & get pixel. */
  1581. !         --RLE_count;
  1582.           }
  1583.       else
  1584.           { /* Have already read count & (at least) first pixel. */
  1585. !         --RLE_count;
  1586.           if ( RLE_flag != 0 )
  1587.           /* Replicated pixels. */
  1588.           goto PixEncode;
  1589.  
  1590. exit 0 # Just in case...
  1591. -- 
  1592. Kent Landfield                   INTERNET: kent@sparky.IMD.Sterling.COM
  1593. Sterling Software, IMD           UUCP:     uunet!sparky!kent
  1594. Phone:    (402) 291-8300         FAX:      (402) 291-4362
  1595. Please send comp.sources.misc-related mail to kent@uunet.uu.net.
  1596.