jef@helios.ee.lbl.gov (Jef Poskanzer) (11/09/88)
Posting-number: Volume 5, Issue 41 Submitted-by: "Jef Poskanzer" <jef@helios.ee.lbl.gov> Archive-name: pbm3/Part1 #! /bin/sh # This is a shell archive, meaning: # 1. Remove everything above the #! /bin/sh line. # 2. Save the resulting text in a file. # 3. Execute the file with /bin/sh (not csh) to create the files: # README # FORMATS # Makefile # cbmtopbm.c # cbmtopbm.1 # icontopbm.c # icontopbm.1 # macptopbm.c # macptopbm.1 # rasttopbm.c # rasttopbm.1 # xbmtopbm.c # xbmtopbm.1 # xwdtopbm.c # This archive created: Mon Oct 31 18:33:27 1988 # By: Jef Poskanzer (Paratheo-Anametamystikhood Of Eris Esoteric, Ada Lovelace Cabal) export PATH; PATH=/bin:$PATH echo shar: extracting "'README'" '(4090 characters)' if test -f 'README' then echo shar: will not over-write existing file "'README'" else sed 's/^X//' << \SHAR_EOF > 'README' X Portable Bitmap Toolkit X Version of 31oct88 X Previous distribution 31aug88 X X XIncluded are a number of programs for converting various bitmap formats Xto and from a portable format; plus some tools for manipulating the Xportable bitmaps. X XChanges since the X.V11R3 distribution of 31aug88: X X The cbm format has been revised to support run-length encoding. X Pbmtops now does run-length encoding. X XMajor changes since the X.V11R2 distribution of 28mar88: X X The pbm format now has a "magic number". X New conversion filters: brushtopbm, giftopbm, pbmtolj, pbmtomacp, X pbmtoxwd, and pbmtox10wd. X Icontopbm converter has a better parser -- it knows to skip over X any extraneous comments at the beginning of the icon file. X Pbmtops generates a different PostScript wrapper program -- it should X handle huge bitmaps better. X Xwdtopbm now handles byte-swapping correctly. X Pbmmake takes a flag to specify the color of the new bitmap. X Pbmpaste now implements 'or', 'and', and 'xor' operations as well X as the default 'replace'. X X XFiles in this distribution: X X README this X FORMATS descriptions of the various bitmap formats X Makefile guess X X brushtopbm.c convert from Xerox doodle brushes to portable bitmap X cbmtopbm.c convert from compact bitmap to portable bitmap X giftopbm.c convert from GIF to portable bitmap X icontopbm.c convert from Sun icon to portable bitmap X macptopbm.c convert from MacPaint to portable bitmap X rasttopbm.c convert from Sun raster to portable bitmap X xbmtopbm.c convert from X10 or X11 bitmap to portable bitmap X xwdtopbm.c convert from X10 or X11 window dump to portable bitmap X xxxtopbm.c convert from UNKNOWN BITMAP to portable bitmap X X pbmtoascii.c convert from portable bitmap to ASCII graphic form X pbmtocbm.c convert from portable bitmap to compact bitmap X pbmtoicon.c convert from portable bitmap to Sun icon X pbmtolj.c convert from portable bitmap to HP LaserJet X pbmtomacp.c convert from portable bitmap to MacPaint X pbmtops.c convert from portable bitmap to PostScript X pbmtoptx.c convert from portable bitmap to Printronix X pbmtorast.c convert from portable bitmap to Sun raster X pbmtoxbm.c convert from portable bitmap to X11 bitmap X pbmtox10bm.c convert from portable bitmap to X10 bitmap X pbmtoxwd.c convert from portable bitmap to X11 window dump X pbmtox10wd.c convert from portable bitmap to X10 window dump X X pbmcatlr.c concatenate portable bitmaps left to right X pbmcattb.c concatenate portable bitmaps top to bottom X pbmcrop.c crop a portable bitmap X pbmcut.c cut a rectangle out of a portable bitmap X pbmenlarge.c enlarge a portable bitmap N times X pbmfliplr.c flip a portable bitmap left for right X pbmfliptb.c flip a portable bitmap top for bottom X pbminvert.c invert a portable bitmap X pbmmake.c create a blank bitmap of a specified size X pbmpaste.c paste a rectangle into a portable bitmap X pbmtrnspos.c transpose a portable bitmap x for y X X libpbm[1-5].c a few utility routines X pbm.h header file for libpbm X libpbm.h internal header file for libpbm X macp.h definitions for MacPaint files X x10wd.h definitions for X10 window dumps X x11wd.h definitions for X11 window dumps X bmaliases csh script to make aliases for converting formats X *.1 manual entries for all of the tools X pbm.5 manual entry for the pbm format X bitreverse.h useful include file X X XUnpack the files, edit Makefile and change the options to suit, Xmake, and enjoy! Note that if you're not on a Sun, you won't be Xable to compile rasttopbm and pbmtorast. X XI've tested this stuff under 4.2 BSD, 4.3 BSD, and System V rel 2, Xand on both Suns and Vaxen. Nevertheless, I'm sure bugs remain. XFeedback is welcome - send bug reports, enhancements, checks, money Xorders, etc. to the addresses below. X X X Jef Poskanzer X jef@rtsg.ee.lbl.gov X {ucbvax, lll-crg, sun!pacbell, apple, hplabs}!well!pokey SHAR_EOF if test 4090 -ne "`wc -c < 'README'`" then echo shar: error transmitting "'README'" '(should have been 4090 characters)' fi fi # end of overwriting check echo shar: extracting "'FORMATS'" '(3320 characters)' if test -f 'FORMATS' then echo shar: will not over-write existing file "'FORMATS'" else sed 's/^X//' << \SHAR_EOF > 'FORMATS' XThe portable bitmap format is a lowest common denominator. X XFormats currently supported are: X X X11 and X10 bitmaps X X11 window dump files X Sun icons X Sun raster files X MacPaint X GIF X PostScript X Printronix printer graphics X HP LaserJet X "portable bitmap format" X "compact bitmap format" X X XThe portable bitmap format is something I came up with while I was Xat Xerox. It is a lowest common denominator. It was originally Xdesigned to make it reasonable to mail bitmaps between different Xtypes of machines using the typical stupid network mailers we have Xtoday. Now it serves as the common language for this family of Xbitmap conversion filters. The definition is as follows: X X - A "magic number" for identifying the file type. A pbm file's X magic number is the two characters "P1". X X - Whitespace (blanks, TABs, CRs, LFs). X X - A width, formatted as ASCII characters in decimal. X X - Whitespace. X X - A height, again in ASCII decimal. X X - Whitespace. X X - Width * height bits, each either '1' or '0', starting at the top-left X corner of the bitmap, proceding in normal English reading order. X X - The character '1' means black, '0' means white. X X - Whitespace in the bits section is ignored. X X - Characters from a "#" to the next end-of-line are ignored (comments). X X - No line may be longer than 70 characters. X XHere is an example of a small bitmap in this format: X X P1 X # feep.pbm X 24 7 X 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 X 0 1 1 1 1 0 0 1 1 1 1 0 0 1 1 1 1 0 0 1 1 1 1 0 X 0 1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 1 0 X 0 1 1 1 0 0 0 1 1 1 0 0 0 1 1 1 0 0 0 1 1 1 1 0 X 0 1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 X 0 1 0 0 0 0 0 1 1 1 1 0 0 1 1 1 1 0 0 1 0 0 0 0 X 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 X XPrograms that read this format should be as lenient as possible, Xaccepting anything that looks remotely like a bitmap. For instance, Xthe above example does not actually conform to the standard, since Xit has whitespace before the width; neverthless, it should be accepted. X X XThe compact bitmap format is the same basic idea as the portable Xformat, but it assumes the underlying filesystem can reliably store X8-bit bytes. If you have the compress and zcat programs, you should Xnot bother with compact bitmaps -- all formats are about the same size Xafter being compressed. Otherwise, compact bitmaps are probably the Xmost space-efficient format. The definition: X X - Two bytes of "magic number", which are always 0x2A 0x17. X X - Two bytes representing the width. The bytes are in "big-endian" X order, i.e. the formula for the width is firstbyte * 256 + secondbyte. X X - Two bytes representing the height, same order as above. X X - The bits, in the same order as in the portable format: starting X at the top-left, proceeding in normal English reading order. X Within each byte, the most significant bit is used first, and so X on down to the least significant bit. X X - Nothing special happens at the end of a row -- no padding, not even X to the end of the current byte. X X - A 1 bit means black, a 0 bit means white; X X - All eight bits of each byte are used, except of course for the X last byte, where there may be some extra bits. These are ignored. SHAR_EOF if test 3320 -ne "`wc -c < 'FORMATS'`" then echo shar: error transmitting "'FORMATS'" '(should have been 3320 characters)' fi fi # end of overwriting check echo shar: extracting "'Makefile'" '(5820 characters)' if test -f 'Makefile' then echo shar: will not over-write existing file "'Makefile'" else sed 's/^X//' << \SHAR_EOF > 'Makefile' X# Makefile for pbm tools. X# X# Copyright (C) 1988 by Jef Poskanzer. X# X# Permission to use, copy, modify, and distribute this software and its X# documentation for any purpose and without fee is hereby granted, provided X# that the above copyright notice appear in all copies and that both that X# copyright notice and this permission notice appear in supporting X# documentation. This software is provided "as is" without express or X# implied warranty. X X X# Valid options: X# OS_BSD Set this if your system is BSD 4.2 or later. X# OS_SYSV Set this if your system is System V. XOPTIONS = -DOS_BSD X X XCC = cc XCFLAGS = -O $(OPTIONS) XLDFLAGS = -s XLDLIBS = libpbm.a X X.SUFFIXES: .1 .5 .cat X.1.cat: X nroff -h -man $< > $@ X.5.cat: X nroff -h -man $< > $@ X Xall: brushtopbm brushtopbm.cat cbmtopbm cbmtopbm.cat \ X giftopbm giftopbm.cat icontopbm icontopbm.cat \ X macptopbm macptopbm.cat pbm.cat pbmcatlr pbmcatlr.cat \ X pbmcattb pbmcattb.cat pbmcrop pbmcrop.cat \ X pbmcut pbmcut.cat pbmenlarge pbmenlarge.cat \ X pbmfliplr pbmfliplr.cat pbmfliptb pbmfliptb.cat \ X pbminvert pbminvert.cat pbmmake pbmmake.cat \ X pbmpaste pbmpaste.cat pbmtoascii pbmtoascii.cat \ X pbmtocbm pbmtocbm.cat pbmtoicon pbmtoicon.cat \ X pbmtolj pbmtolj.cat pbmtomacp pbmtomacp.cat \ X pbmtops pbmtops.cat pbmtoptx pbmtoptx.cat \ X pbmtorast pbmtorast.cat pbmtox10bm pbmtox10bm.cat \ X pbmtox10wd pbmtox10wd.cat pbmtoxbm pbmtoxbm.cat \ X pbmtoxwd pbmtoxwd.cat pbmtrnspos pbmtrnspos.cat \ X rasttopbm rasttopbm.cat xbmtopbm xbmtopbm.cat \ X xwdtopbm xwdtopbm.cat xxxtopbm xxxtopbm.cat X X# Rule for plain programs. Xbrushtopbm cbmtopbm giftopbm icontopbm macptopbm pbmcatlr pbmcattb \ Xpbmcrop pbmcut pbmenlarge pbmfliplr pbmfliptb pbminvert pbmmake \ Xpbmpaste pbmtoascii pbmtocbm pbmtoicon pbmtolj pbmtomacp pbmtops \ Xpbmtoptx pbmtox10bm pbmtox10wd pbmtoxbm pbmtoxwd pbmtrnspos \ Xxbmtopbm xwdtopbm xxxtopbm: pbm.h libpbm.a X $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $@.c $(LDLIBS) X X# Rule for pixrect-dependent programs. Xpbmtorast rasttopbm: pbm.h libpbm.a X $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $@.c $(LDLIBS) -lpixrect X X# And library. Xlibpbm.a: libpbm1.o libpbm2.o libpbm3.o libpbm4.o libpbm5.o X -rm libpbm.a X ar rc libpbm.a libpbm1.o libpbm2.o libpbm3.o libpbm4.o libpbm5.o X -ranlib libpbm.a X Xlibpbm1.o: pbm.h libpbm.h libpbm1.c X $(CC) $(CFLAGS) -c libpbm1.c Xlibpbm2.o: pbm.h libpbm.h libpbm2.c X $(CC) $(CFLAGS) -c libpbm2.c Xlibpbm3.o: pbm.h libpbm.h libpbm3.c X $(CC) $(CFLAGS) -c libpbm3.c Xlibpbm4.o: pbm.h libpbm.h libpbm4.c X $(CC) $(CFLAGS) -c libpbm4.c Xlibpbm5.o: pbm.h libpbm.h libpbm5.c X $(CC) $(CFLAGS) -c libpbm5.c X X# Other dependencies. Xbrushtopbm: brushtopbm.c Xcbmtopbm: cbmtopbm.c Xgiftopbm: giftopbm.c Xicontopbm: icontopbm.c Xmacptopbm: macptopbm.c macp.h Xpbmcatlr: pbmcatlr.c Xpbmcattb: pbmcattb.c Xpbmcrop: pbmcrop.c Xpbmcut: pbmcut.c Xpbmenlarge: pbmenlarge.c Xpbmfliplr: pbmfliplr.c Xpbmfliptb: pbmfliptb.c Xpbminvert: pbminvert.c Xpbmmake: pbmmake.c Xpbmpaste: pbmpaste.c Xpbmtoascii: pbmtoascii.c Xpbmtocbm: pbmtocbm.c Xpbmtoicon: pbmtoicon.c Xpbmtolj: pbmtolj.c Xpbmtomacp: pbmtomacp.c macp.h Xpbmtops: pbmtops.c Xpbmtoptx: pbmtoptx.c Xpbmtorast: pbmtorast.c Xpbmtox10bm: pbmtox10bm.c Xpbmtoxbm: pbmtoxbm.c Xpbmtox10wd: pbmtox10wd.c x10wd.h Xpbmtoxwd: pbmtoxwd.c x11wd.h Xpbmtrnspos: pbmtrnspos.c Xrasttopbm: rasttopbm.c Xxbmtopbm: xbmtopbm.c Xxwdtopbm: xwdtopbm.c x11wd.h x10wd.h Xxxxtopbm: xxxtopbm.c X Xclean: X -rm -f *.o *.cat libpbm.a pbm.shar* core X -rm -f brushtopbm cbmtopbm giftopbm icontopbm macptopbm X -rm -f pbmcatlr pbmcattb pbmcrop pbmcut pbmenlarge X -rm -f pbmfliplr pbmfliptb pbminvert pbmmake pbmpaste X -rm -f pbmtoascii pbmtocbm pbmtoicon pbmtolj pbmtomacp X -rm -f pbmtops pbmtoptx pbmtorast pbmtox10bm pbmtoxbm X -rm -f pbmtox10wd pbmtoxwd pbmtrnspos rasttopbm X -rm -f xbmtopbm xwdtopbm xxxtopbm X Xshar: pbm.shar Xpbm.shar: pbm.shar1 pbm.shar2 pbm.shar3 pbm.shar4 pbm.shar5 X Xpbm.shar1: README FORMATS Makefile cbmtopbm.c cbmtopbm.1 icontopbm.c \ X icontopbm.1 macptopbm.c macptopbm.1 rasttopbm.c \ X rasttopbm.1 xbmtopbm.c xbmtopbm.1 xwdtopbm.c X shar -v -c -p X README FORMATS Makefile cbmtopbm.c cbmtopbm.1 icontopbm.c icontopbm.1 macptopbm.c macptopbm.1 rasttopbm.c rasttopbm.1 xbmtopbm.c xbmtopbm.1 xwdtopbm.c > $@ X Xpbm.shar2: xwdtopbm.1 pbmtocbm.c pbmtocbm.1 pbmtoicon.c pbmtoicon.1 \ X pbmtops.c pbmtops.1 pbmtoptx.c pbmtoptx.1 pbmtorast.c \ X pbmtorast.1 pbmtoxbm.c pbmtoxbm.1 pbmtox10bm.c pbmtox10bm.1 \ X pbmtoascii.c pbmtoascii.1 pbmcatlr.c pbmcatlr.1 pbmcattb.c \ X pbmcattb.1 pbmfliplr.c pbmfliplr.1 X shar -v -c -p X xwdtopbm.1 pbmtocbm.c pbmtocbm.1 pbmtoicon.c pbmtoicon.1 pbmtops.c pbmtops.1 pbmtoptx.c pbmtoptx.1 pbmtorast.c pbmtorast.1 pbmtoxbm.c pbmtoxbm.1 pbmtox10bm.c pbmtox10bm.1 pbmtoascii.c pbmtoascii.1 pbmcatlr.c pbmcatlr.1 pbmcattb.c pbmcattb.1 pbmfliplr.c pbmfliplr.1 > $@ X Xpbm.shar3: pbmfliptb.c pbmfliptb.1 pbminvert.c pbminvert.1 pbmcrop.c \ X pbmcrop.1 pbmtrnspos.c pbmtrnspos.1 pbmcut.c pbmcut.1 \ X pbmpaste.c pbmpaste.1 xxxtopbm.c xxxtopbm.1 pbmenlarge.c \ X pbmenlarge.1 pbmmake.c pbmmake.1 pbmtolj.c pbmtolj.1 \ X pbmtomacp.c X shar -v -c -p X pbmfliptb.c pbmfliptb.1 pbminvert.c pbminvert.1 pbmcrop.c pbmcrop.1 pbmtrnspos.c pbmtrnspos.1 pbmcut.c pbmcut.1 pbmpaste.c pbmpaste.1 xxxtopbm.c xxxtopbm.1 pbmenlarge.c pbmenlarge.1 pbmmake.c pbmmake.1 pbmtolj.c pbmtolj.1 pbmtomacp.c > $@ X Xpbm.shar4: pbmtomacp.1 pbmtox10wd.c pbmtox10wd.1 pbmtoxwd.c pbmtoxwd.1 \ X brushtopbm.c brushtopbm.1 libpbm1.c libpbm2.c libpbm3.c \ X libpbm4.c libpbm5.c giftopbm.c giftopbm.1 X shar -v -c -p X pbmtomacp.1 pbmtox10wd.c pbmtox10wd.1 pbmtoxwd.c pbmtoxwd.1 brushtopbm.c brushtopbm.1 libpbm1.c libpbm2.c libpbm3.c libpbm4.c libpbm5.c giftopbm.c giftopbm.1 > $@ X Xpbm.shar5: pbm.h libpbm.h macp.h x10wd.h x11wd.h pbm.5 bmaliases \ X bitreverse.h X shar -v -c -p X pbm.h libpbm.h macp.h x10wd.h x11wd.h pbm.5 bmaliases bitreverse.h > $@ SHAR_EOF if test 5820 -ne "`wc -c < 'Makefile'`" then echo shar: error transmitting "'Makefile'" '(should have been 5820 characters)' fi fi # end of overwriting check echo shar: extracting "'cbmtopbm.c'" '(1112 characters)' if test -f 'cbmtopbm.c' then echo shar: will not over-write existing file "'cbmtopbm.c'" else sed 's/^X//' << \SHAR_EOF > 'cbmtopbm.c' X/* cbmtopbm.c - read a compact bitmap and write a portable bitmap X** X** Copyright (C) 1988 by Jef Poskanzer. X** X** Permission to use, copy, modify, and distribute this software and its X** documentation for any purpose and without fee is hereby granted, provided X** that the above copyright notice appear in all copies and that both that X** copyright notice and this permission notice appear in supporting X** documentation. This software is provided "as is" without express or X** implied warranty. X*/ X X#include <stdio.h> X#include "pbm.h" X Xmain( argc, argv ) Xint argc; Xchar *argv[]; X { X FILE *ifd; X bit **bits, getbit(); X int rows, cols, row, col; X X if ( argc > 2 ) X { X fprintf( stderr, "usage: %s [cbmfile]\n", argv[0] ); X exit( 1 ); X } X X if ( argc == 2 ) X { X ifd = fopen( argv[1], "r" ); X if ( ifd == NULL ) X { X fprintf( stderr, "%s: can't open.\n", argv[1] ); X exit( 1 ); X } X } X else X ifd = stdin; X X bits = pbm_readcbm( ifd, &cols, &rows ); X X if ( ifd != stdin ) X fclose( ifd ); X X pbm_writepbm( stdout, bits, cols, rows ); X X exit( 0 ); X } SHAR_EOF if test 1112 -ne "`wc -c < 'cbmtopbm.c'`" then echo shar: error transmitting "'cbmtopbm.c'" '(should have been 1112 characters)' fi fi # end of overwriting check echo shar: extracting "'cbmtopbm.1'" '(669 characters)' if test -f 'cbmtopbm.1' then echo shar: will not over-write existing file "'cbmtopbm.1'" else sed 's/^X//' << \SHAR_EOF > 'cbmtopbm.1' X.TH cbmtopbm 1 "31 August 1988" X.SH NAME Xcbmtopbm - convert compact bitmaps into portable bitmaps X.SH SYNOPSIS Xcbmtopbm [cbmfile] X.SH DESCRIPTION XReads a compact bitmap as input. XProduces a portable bitmap as output. X.SH "SEE ALSO" Xpbmtocbm(1), pbm(5) X.SH AUTHOR XCopyright (C) 1988 by Jef Poskanzer. X XPermission to use, copy, modify, and distribute this software and its Xdocumentation for any purpose and without fee is hereby granted, provided Xthat the above copyright notice appear in all copies and that both that Xcopyright notice and this permission notice appear in supporting Xdocumentation. This software is provided "as is" without express or Ximplied warranty. SHAR_EOF if test 669 -ne "`wc -c < 'cbmtopbm.1'`" then echo shar: error transmitting "'cbmtopbm.1'" '(should have been 669 characters)' fi fi # end of overwriting check echo shar: extracting "'icontopbm.c'" '(3806 characters)' if test -f 'icontopbm.c' then echo shar: will not over-write existing file "'icontopbm.c'" else sed 's/^X//' << \SHAR_EOF > 'icontopbm.c' X/* icontopbm.c - read a Sun icon file and produce a portable bitmap X** X** Copyright (C) 1988 by Jef Poskanzer. X** X** Permission to use, copy, modify, and distribute this software and its X** documentation for any purpose and without fee is hereby granted, provided X** that the above copyright notice appear in all copies and that both that X** copyright notice and this permission notice appear in supporting X** documentation. This software is provided "as is" without express or X** implied warranty. X*/ X X#include <stdio.h> X#include <sys/types.h> X#include "pbm.h" X Xmain( argc, argv ) Xint argc; Xchar *argv[]; X { X FILE *ifd; X bit **bits; X int rows, cols, row, col, shortcount, mask; X short *data; X X if ( argc > 2 ) X { X fprintf( stderr, "usage: %s [iconfile]\n", argv[0] ); X exit( 1 ); X } X X if ( argc == 2 ) X { X ifd = fopen( argv[1], "r" ); X if ( ifd == NULL ) X { X fprintf( stderr, "%s: can't open.\n", argv[1] ); X exit( 1 ); X } X } X else X ifd = stdin; X X if ( ReadIconFile( ifd, &cols, &rows, &data ) < 0 ) X { X fprintf( stderr, "%s: can't load.\n", argv[1] ); X exit( 1 ); X } X X if ( ifd != stdin ) X fclose( ifd ); X X bits = pbm_allocarray( cols, rows ); X X for ( row = 0; row < rows; row++ ) X { X shortcount = 0; X mask = 0x8000; X for ( col = 0; col < cols; col++ ) X { X if ( shortcount >= 16 ) X { X data++; X shortcount = 0; X mask = 0x8000; X } X bits[row][col] = ( ( *data & mask ) ? 1 : 0 ); X shortcount++; X mask = mask >> 1; X } X data++; X } X X pbm_writepbm( stdout, bits, cols, rows ); X X exit( 0 ); X } X X X/* size in bytes of a bitmap */ X#define BitmapSize(width, height) (((((width) + 15) >> 3) &~ 1) * (height)) X Xint XReadIconFile( file, width, height, data ) XFILE *file; Xint *width, *height; Xshort **data; X { X char variable[81], ch; X int status, value, i, data_length, gotsome; X X if ( file == NULL ) X return -1; X X gotsome = 0; X *width = *height = -1; X for ( ; ; ) X { X while ( ( ch = getc( file ) ) == ',' | ch == '\n' | ch == '\t' | X ch == ' ' ) X ; X for ( i = 0; X ch != '=' & ch != ',' & ch != '\n' & ch != '\t' & ch != ' '; X i++ ) X { X variable[i] = ch; X ch = getc( file ); X } X variable[i] = '\0'; X X if ( strcmp( variable, "*/" ) == 0 & gotsome ) X break; X X if ( fscanf( file, "%d", &value ) != 1 ) X continue; X X if ( strcmp( variable, "Width" ) == 0 ) X { X *width = value; X gotsome = 1; X } X else if ( strcmp( variable, "Height" ) == 0 ) X { X *height = value; X gotsome = 1; X } X else if ( strcmp( variable, "Depth" ) == 0 ) X { X if ( value != 1 ) X { X fprintf( stderr, "Invalid depth.\n" ); X return -1; X } X gotsome = 1; X } X else if ( strcmp( variable, "Format_version" ) == 0 ) X { X if ( value != 1 ) X { X fprintf( stderr, "Invalid Format_version.\n" ); X return -1; X } X gotsome = 1; X } X else if ( strcmp( variable, "Valid_bits_per_item" ) == 0 ) X { X if ( value != 16 ) X { X fprintf( stderr, "Invalid Valid_bits_per_item.\n" ); X return -1; X } X gotsome = 1; X } X } X X if ( *width <= 0 ) X { X fprintf( stderr, "Invalid width: %d.\n", *width ); X return -1; X } X X if ( *height <= 0 ) X { X fprintf( stderr, "Invalid height: %d.\n", *height ); X return -1; X } X X data_length = BitmapSize( *width, *height ); X *data = (short *) malloc( data_length ); X data_length /= sizeof( short ); X if ( *data == NULL ) X { X return -1; X } X X for ( i = 0 ; i < data_length; i++ ) X { X if ( i == 0 ) X status = fscanf( file, " 0x%4hx", *data ); X else X status = fscanf( file, ", 0x%4hx", *data + i ); X if ( status != 1 ) X { X free( *data ); X fprintf( stderr, "Error 4 scanning bits item.\n" ); X return -1; X } X } X X return 0; X } SHAR_EOF if test 3806 -ne "`wc -c < 'icontopbm.c'`" then echo shar: error transmitting "'icontopbm.c'" '(should have been 3806 characters)' fi fi # end of overwriting check echo shar: extracting "'icontopbm.1'" '(662 characters)' if test -f 'icontopbm.1' then echo shar: will not over-write existing file "'icontopbm.1'" else sed 's/^X//' << \SHAR_EOF > 'icontopbm.1' X.TH icontopbm 1 "31 August 1988" X.SH NAME Xicontopbm - convert Sun icons into portable bitmaps X.SH SYNOPSIS Xicontopbm [iconfile] X.SH DESCRIPTION XReads a Sun icon as input. XProduces a portable bitmap as output. X.SH "SEE ALSO" Xpbmtoicon(1), pbm(5) X.SH AUTHOR XCopyright (C) 1988 by Jef Poskanzer. X XPermission to use, copy, modify, and distribute this software and its Xdocumentation for any purpose and without fee is hereby granted, provided Xthat the above copyright notice appear in all copies and that both that Xcopyright notice and this permission notice appear in supporting Xdocumentation. This software is provided "as is" without express or Ximplied warranty. SHAR_EOF if test 662 -ne "`wc -c < 'icontopbm.1'`" then echo shar: error transmitting "'icontopbm.1'" '(should have been 662 characters)' fi fi # end of overwriting check echo shar: extracting "'macptopbm.c'" '(2965 characters)' if test -f 'macptopbm.c' then echo shar: will not over-write existing file "'macptopbm.c'" else sed 's/^X//' << \SHAR_EOF > 'macptopbm.c' X/* macptopbm.c - read a MacPaint file and produce a portable bitmap X** X** Copyright (C) 1988 by Jef Poskanzer. X** X** Permission to use, copy, modify, and distribute this software and its X** documentation for any purpose and without fee is hereby granted, provided X** that the above copyright notice appear in all copies and that both that X** copyright notice and this permission notice appear in supporting X** documentation. This software is provided "as is" without express or X** implied warranty. X*/ X X#include <stdio.h> X#include <sys/types.h> X#include "pbm.h" X#include "macp.h" X Xmain( argc, argv ) Xint argc; Xchar *argv[]; X { X FILE *ifd; X unsigned char Pic[MAX_LINES][BYTES_WIDE]; X bit **bits; X int scanLine, rows, cols, row, bcol, i; X X if ( argc > 2 ) X { X fprintf( stderr, "usage: %s [macpfile]\n", argv[0] ); X exit( 1 ); X } X X if ( argc == 2 ) X { X ifd = fopen( argv[1], "r" ); X if ( ifd == NULL ) X { X fprintf( stderr, "%s: can't open.\n", argv[1] ); X exit( 1 ); X } X } X else X ifd = stdin; X X if ( ReadMacPaintFile( ifd, &scanLine, Pic ) < 0 ) X { X fprintf( stderr, "%s: can't load.\n", argv[1] ); X exit( 1 ); X } X X if ( ifd != stdin ) X fclose( ifd ); X X cols = BYTES_WIDE * 8; X rows = scanLine; X bits = pbm_allocarray( cols, rows ); X X for ( row = 0; row < rows; row++ ) X for ( bcol = 0; bcol < BYTES_WIDE; bcol++ ) X for ( i = 0; i < 8; i++ ) X bits[row][bcol * 8 + i] = ( (Pic[row][bcol] >> (7 - i)) & 1); X X pbm_writepbm( stdout, bits, cols, rows ); X X exit( 0 ); X } X X/* X** Some of the following routine is: X** X** Copyright 1987 by Patrick J. Naughton X** All Rights Reserved X** Permission to use, copy, modify, and distribute this software and its X** documentation for any purpose and without fee is hereby granted, X** provided that the above copyright notice appear in all copies and that X** both that copyright notice and this permission notice appear in X** supporting documentation. X*/ X Xint XReadMacPaintFile( file, scanLineP, Pic ) XFILE *file; Xint *scanLineP; Xunsigned char Pic[MAX_LINES][BYTES_WIDE]; X { X unsigned int i, j, k; X unsigned char ch; X X /* Skip over the header. */ X for ( i = 0; i < HEADER_LENGTH; i++ ) X getc( file ); X X *scanLineP = 0; X k = 0; X X while ( *scanLineP < MAX_LINES ) X { X ch = (unsigned char) getc( file ); /* Count byte */ X i = (unsigned int) ch; X if ( ch < 0x80 ) X { /* Unpack next (I+1) chars as is */ X for ( j = 0; j <= i; j++ ) X if ( *scanLineP < MAX_LINES ) X { X Pic[*scanLineP][k++] = (unsigned char) getc( file ); X if ( ! (k %= BYTES_WIDE) ) X *scanLineP += 1; X } X } X else X { /* Repeat next char (2's comp I) times */ X ch = getc( file ); X for ( j = 0; j <= 256 - i; j++ ) X if ( *scanLineP < MAX_LINES ) X { X Pic[*scanLineP][k++] = (unsigned char) ch; X if ( ! (k %= BYTES_WIDE) ) X *scanLineP += 1; X } X } X } X X return(0); X } SHAR_EOF if test 2965 -ne "`wc -c < 'macptopbm.c'`" then echo shar: error transmitting "'macptopbm.c'" '(should have been 2965 characters)' fi fi # end of overwriting check echo shar: extracting "'macptopbm.1'" '(1066 characters)' if test -f 'macptopbm.1' then echo shar: will not over-write existing file "'macptopbm.1'" else sed 's/^X//' << \SHAR_EOF > 'macptopbm.1' X.TH macptopbm 1 "31 August 1988" X.SH NAME Xmacptopbm - convert MacPaint files into portable bitmaps X.SH SYNOPSIS Xmacptopbm [macpfile] X.SH DESCRIPTION XReads a MacPaint file as input. XProduces a portable bitmap as output. X.SH "SEE ALSO" Xpbmtomacp(1), pbm(5) X.SH AUTHOR XCopyright (C) 1988 by Jef Poskanzer. X XPermission to use, copy, modify, and distribute this software and its Xdocumentation for any purpose and without fee is hereby granted, provided Xthat the above copyright notice appear in all copies and that both that Xcopyright notice and this permission notice appear in supporting Xdocumentation. This software is provided "as is" without express or Ximplied warranty. X XThe MacPaint-reading code is XCopyright (c) 1987 by Patrick J. Naughton X(naughton@wind.sun.com) X XPermission to use, copy, modify, and distribute this software and its Xdocumentation for any purpose and without fee is hereby granted, Xprovided that the above copyright notice appear in all copies and that Xboth that copyright notice and this permission notice appear in Xsupporting documentation. SHAR_EOF if test 1066 -ne "`wc -c < 'macptopbm.1'`" then echo shar: error transmitting "'macptopbm.1'" '(should have been 1066 characters)' fi fi # end of overwriting check echo shar: extracting "'rasttopbm.c'" '(3223 characters)' if test -f 'rasttopbm.c' then echo shar: will not over-write existing file "'rasttopbm.c'" else sed 's/^X//' << \SHAR_EOF > 'rasttopbm.c' X/* rasttopbm.c - read a Sun raster file and produce a portable bitmap X** X** Copyright (C) 1988 by Jef Poskanzer. X** X** Permission to use, copy, modify, and distribute this software and its X** documentation for any purpose and without fee is hereby granted, provided X** that the above copyright notice appear in all copies and that both that X** copyright notice and this permission notice appear in supporting X** documentation. This software is provided "as is" without express or X** implied warranty. X*/ X X#include <stdio.h> X#include "pbm.h" X X/* Because of the following include, this program compiles only on Suns. */ X#include <pixrect/pixrect_hs.h> X Xmain( argc, argv ) Xint argc; Xchar *argv[]; X { X FILE *ifd; X bit **bits; X int rows, cols, row, col, shortcount, mask; X int linesize; X short *data; X X if ( argc > 2 ) X { X fprintf( stderr, "usage: %s [rastfile]\n", argv[0] ); X exit( 1 ); X } X X if ( argc == 2 ) X { X ifd = fopen( argv[1], "r" ); X if ( ifd == NULL ) X { X fprintf( stderr, "%s: can't open.\n", argv[1] ); X exit( 1 ); X } X } X else X ifd = stdin; X X if ( ReadRasterFile( ifd, &cols, &rows, &linesize, &data ) < 0 ) X { X fprintf( stderr, "%s: can't load.\n", argv[1] ); X exit( 1 ); X } X X if ( ifd != stdin ) X fclose( ifd ); X X bits = pbm_allocarray( cols, rows ); X X for ( row = 0; row < rows; row++ ) X { X shortcount = 0; X mask = 0x8000; X for ( col = 0; col < cols; col++ ) X { X if ( mask == 0 ) X { X shortcount++; X mask = 0x8000; X } X bits[row][col] = ( *(data + shortcount) & mask ) ? 1 : 0; X mask = mask >> 1; X } X data += linesize / sizeof(short); X } X X pbm_writepbm( stdout, bits, cols, rows ); X X exit( 0 ); X } X X Xint XReadRasterFile( file, width, height, linebytes, data ) XFILE *file; Xint *width, *height; Xint *linebytes; Xshort **data; X { X struct rasterfile header; X struct pixrect *pr, *pr_load_image(); X int status, firsttime, value, i, data_length; X X if ( file == NULL ) X return -1; X X *width = *height = -1; X X X /* Get the raster file's header. */ X if ( pr_load_header( file, &header ) != 0 ) X { X fprintf( stderr, "Unable to read in raster file header.\n"); X return -1; X } X X /* PBM can only handle monochrome bitmaps. */ X if ( header.ras_depth != 1 ) X { X fprintf( stderr, "Invalid depth.\n" ); X return -1; X } X X *width = header.ras_width; X *height = header.ras_height; X if ( *width <= 0 ) X { X fprintf( stderr, "Invalid width: %d.\n", *width ); X return -1; X } X X if ( *height <= 0 ) X { X fprintf( stderr, "Invalid height: %d.\n", *height ); X return -1; X } X X /* If there is a color map, skip over it. */ X if ( header.ras_maptype != RMT_NONE && header.ras_maplength != 0 ) X { X if (pr_load_colormap(file, &header, NULL) != 0) X { X fprintf( stderr, "Unable to skip colormap data.\n"); X return -1; X } X } X X /* Now load the data. The pixrect returned is a memory pixrect. */ X if ( (pr = pr_load_image(file, &header, NULL)) == NULL ) X { X fprintf( X stderr, "Unable to read in the image from the raster file.\n"); X return -1; X } X X *linebytes = ((struct mpr_data *)pr->pr_data)->md_linebytes; X *data = ((struct mpr_data *)pr->pr_data)->md_image; X X return 0; X } SHAR_EOF if test 3223 -ne "`wc -c < 'rasttopbm.c'`" then echo shar: error transmitting "'rasttopbm.c'" '(should have been 3223 characters)' fi fi # end of overwriting check echo shar: extracting "'rasttopbm.1'" '(1052 characters)' if test -f 'rasttopbm.1' then echo shar: will not over-write existing file "'rasttopbm.1'" else sed 's/^X//' << \SHAR_EOF > 'rasttopbm.1' X.TH rasttopbm 1 "31 August 1988" X.SH NAME Xrasttopbm - convert Sun rasters into portable bitmaps X.SH SYNOPSIS Xrasttopbm [rastfile] X.SH DESCRIPTION XReads a Sun raster as input. XProduces a portable bitmap as output. XNOTE: since it uses Sun-specific include files, pbmtorast will compile Xonly on Suns. X.LP XUsing this program you can convert anything you can see on a Sun screen Xinto a pbm bitmap. XJust display whatever you're interested in, do a screendump, run it through Xrasfilter8to1 if you're on a color Sun, run it through rasttopbm, and then Xuse pbmcut to select the part you want. X.SH "SEE ALSO" Xpbmtorast(1), pbm(5) X.SH AUTHOR XBarry Klawans X XCopyright (C) 1988 by Jef Poskanzer. X XPermission to use, copy, modify, and distribute this software and its Xdocumentation for any purpose and without fee is hereby granted, provided Xthat the above copyright notice appear in all copies and that both that Xcopyright notice and this permission notice appear in supporting Xdocumentation. This software is provided "as is" without express or Ximplied warranty. SHAR_EOF if test 1052 -ne "`wc -c < 'rasttopbm.1'`" then echo shar: error transmitting "'rasttopbm.1'" '(should have been 1052 characters)' fi fi # end of overwriting check echo shar: extracting "'xbmtopbm.c'" '(4098 characters)' if test -f 'xbmtopbm.c' then echo shar: will not over-write existing file "'xbmtopbm.c'" else sed 's/^X//' << \SHAR_EOF > 'xbmtopbm.c' X/* xbmtopbm.c - read an X bitmap file and produce a portable bitmap X** X** Copyright (C) 1988 by Jef Poskanzer. X** X** Permission to use, copy, modify, and distribute this software and its X** documentation for any purpose and without fee is hereby granted, provided X** that the above copyright notice appear in all copies and that both that X** copyright notice and this permission notice appear in supporting X** documentation. This software is provided "as is" without express or X** implied warranty. X*/ X X#include <stdio.h> X#include <sys/types.h> X#include "pbm.h" X Xmain( argc, argv ) Xint argc; Xchar *argv[]; X { X FILE *ifd; X bit **bits; X int rows, cols, row, col, charcount; X char *data, mask; X X if ( argc > 2 ) X { X fprintf( stderr, "usage: %s [bitmapfile]\n", argv[0] ); X exit( 1 ); X } X X if ( argc == 2 ) X { X ifd = fopen( argv[1], "r" ); X if ( ifd == NULL ) X { X fprintf( stderr, "%s: can't open.\n", argv[1] ); X exit( 1 ); X } X } X else X ifd = stdin; X X if ( ReadBitmapFile( ifd, &cols, &rows, &data ) < 0 ) X { X fprintf( stderr, "%s: can't load.\n", argv[1] ); X exit( 1 ); X } X X if ( ifd != stdin ) X fclose( ifd ); X X bits = pbm_allocarray( cols, rows ); X X for ( row = 0; row < rows; row++ ) X { X charcount = 0; X mask = 1; X for ( col = 0; col < cols; col++ ) X { X if ( charcount >= 8 ) X { X data++; X charcount = 0; X mask = 1; X } X bits[row][col] = ( *data & mask ) ? 1 : 0; X charcount++; X mask = mask << 1; X } X data++; X } X X pbm_writepbm( stdout, bits, cols, rows ); X X exit( 0 ); X } X X X#ifdef OS_SYSV X#include <string.h> X#else OS_SYSV X#include <strings.h> X#endif OS_SYSV X X#define MAX_LINE 200 X Xint XReadBitmapFile( stream, widthP, heightP, dataP ) XFILE *stream; Xint *widthP, *heightP; Xchar **dataP; X { X char line[MAX_LINE], name_and_type[MAX_LINE]; X char *ptr, *t; X int bytes, bytes_per_line, value, version10p, raster_length, padding; X X *widthP = *heightP = -1; X X for ( ; ; ) X { X if ( ! fgets( line, MAX_LINE, stream ) ) X break; X if ( strlen( line ) == MAX_LINE - 1 ) X { X fprintf( stderr, "Line too long.\n" ); X return -1; X } X X if (sscanf(line, "#define %s %d", name_and_type, &value) == 2) X { X#ifdef OS_SYSV X if ( ! (t = strrchr( name_and_type, '_' )) ) X#else OS_SYSV X if ( ! (t = rindex( name_and_type, '_' )) ) X#endif OS_SYSV X t = name_and_type; X else X t++; X if ( ! strcmp( "width", t ) ) X *widthP = value; X if ( ! strcmp( "height", t ) ) X *heightP = value; X continue; X } X X if ( sscanf( line, "static short %s = {", name_and_type ) == 1 ) X { X version10p = 1; X break; X } X else if ( sscanf( line, "static char %s = {", name_and_type ) == 1 ) X { X version10p = 0; X break; X } X else X continue; X } X X#ifdef OS_SYSV X if ( ! (t = strrchr( name_and_type, '_' )) ) X#else OS_SYSV X if ( ! (t = rindex( name_and_type, '_' )) ) X#endif OS_SYSV X t = name_and_type; X else X t++; X X if ( *widthP == -1 ) X { X fprintf( stderr, "Invalid width.\n" ); X return -1; X } X if ( *heightP == -1 ) X { X fprintf( stderr, "Invalid height.\n" ); X return -1; X } X X padding = 0; X if ( ((*widthP % 16) >= 1) && ((*widthP % 16) <= 8) && version10p ) X padding = 1; X X bytes_per_line = (*widthP+7)/8 + padding; X X raster_length = bytes_per_line * *heightP; X *dataP = (char *) malloc( raster_length ); X if ( ! *dataP ) X { X fprintf( stderr, "Not enough memory.\n" ); X return -1; X } X X if ( version10p ) X for ( bytes = 0, ptr = *dataP; bytes < raster_length; bytes += 2 ) X { X if ( fscanf( stream, " 0x%x%*[,}]%*[ \n]", &value ) != 1 ) X { X fprintf( stderr, "Error scanning bits item.\n" ); X return -1; X } X *(ptr++) = value & 0xff; X if ( (! padding) || ((bytes+2) % bytes_per_line) ) X *(ptr++) = value >> 8; X } X else X for ( bytes = 0, ptr = *dataP; bytes < raster_length; bytes++ ) X { X if ( fscanf( stream, " 0x%x%*[,}]%*[ \n]", &value ) != 1 ) X { X fprintf( stderr, "Error scanning bits item.\n" ); X return -1; X } X *(ptr++) = value; X } X X return 0; X } SHAR_EOF if test 4098 -ne "`wc -c < 'xbmtopbm.c'`" then echo shar: error transmitting "'xbmtopbm.c'" '(should have been 4098 characters)' fi fi # end of overwriting check echo shar: extracting "'xbmtopbm.1'" '(695 characters)' if test -f 'xbmtopbm.1' then echo shar: will not over-write existing file "'xbmtopbm.1'" else sed 's/^X//' << \SHAR_EOF > 'xbmtopbm.1' X.TH xbmtopbm 1 "31 August 1988" X.SH NAME Xxbmtopbm - convert X11 and X10 bitmaps into portable bitmaps X.SH SYNOPSIS Xxbmtopbm [bitmapfile] X.SH DESCRIPTION XReads an X11 or X10 bitmap as input. XProduces a portable bitmap as output. X.SH "SEE ALSO" Xpbmtoxbm(1), pbmtox10bm(1), pbm(5) X.SH AUTHOR XCopyright (C) 1988 by Jef Poskanzer. X XPermission to use, copy, modify, and distribute this software and its Xdocumentation for any purpose and without fee is hereby granted, provided Xthat the above copyright notice appear in all copies and that both that Xcopyright notice and this permission notice appear in supporting Xdocumentation. This software is provided "as is" without express or Ximplied warranty. SHAR_EOF if test 695 -ne "`wc -c < 'xbmtopbm.1'`" then echo shar: error transmitting "'xbmtopbm.1'" '(should have been 695 characters)' fi fi # end of overwriting check echo shar: extracting "'xwdtopbm.c'" '(8899 characters)' if test -f 'xwdtopbm.c' then echo shar: will not over-write existing file "'xwdtopbm.c'" else sed 's/^X//' << \SHAR_EOF > 'xwdtopbm.c' X/* xwdtopbm.c - read an X11 or X10 window dump file and write a portable bitmap X** X** Copyright (C) 1988 by Jef Poskanzer. X** X** Permission to use, copy, modify, and distribute this software and its X** documentation for any purpose and without fee is hereby granted, provided X** that the above copyright notice appear in all copies and that both that X** copyright notice and this permission notice appear in supporting X** documentation. This software is provided "as is" without express or X** implied warranty. X*/ X X#include <stdio.h> X#include "pbm.h" X#include "x10wd.h" X#include "x11wd.h" X Xmain( argc, argv ) Xint argc; Xchar *argv[]; X { X FILE *ifd; X bit **bits, getbit(); X int rows, cols, padright, row, col; X X if ( argc > 2 ) X { X fprintf( stderr, "usage: %s [xwdfile]\n", argv[0] ); X exit( 1 ); X } X X if ( argc == 2 ) X { X ifd = fopen( argv[1], "r" ); X if ( ifd == NULL ) X { X fprintf( stderr, "%s: can't open.\n", argv[1] ); X exit( 1 ); X } X } X else X ifd = stdin; X X getinit( ifd, &cols, &rows, &padright ); X X bits = pbm_allocarray( cols, rows ); X X for ( row = 0; row < rows; row++ ) X { X for ( col = 0; col < cols; col++ ) X bits[row][col] = getbit( ifd ); X for ( col = 0; col < padright; col++ ) X (void) getbit( ifd ); X } X X if ( ifd != stdin ) X fclose( ifd ); X X pbm_writepbm( stdout, bits, cols, rows ); X X exit( 0 ); X } X X Xchar buf[4]; Xchar *byteP; Xshort *shortP; Xlong *longP; Xint bits_per_item, bits_used, bit_shift, bit_order, bit_invert, byte_swap; X Xshort bs_short(); Xint bs_int(); Xlong bs_long(); X X Xgetinit( file, colP, rowP, padrightP ) XFILE *file; Xint *colP, *rowP, *padrightP; X { X /* Assume X11 headers are larger than X10 ones. */ X unsigned char header[sizeof(X11WDFileHeader)]; X X10WDFileHeader *h10P; X X11WDFileHeader *h11P; X char junk[10000]; X int i; X X h10P = (X10WDFileHeader *) header; X h11P = (X11WDFileHeader *) header; X X if ( sizeof(*h10P) > sizeof(*h11P) ) X { X fprintf( stderr, "ARGH! On this machine, X10 headers are larger than X11 headers!\n" ); X fprintf( stderr, "You will have to re-write xwdtopbm.\n" ); X exit( 1 ); X } X X /* Read an X10 header. */ X if ( fread( &header[0], sizeof(*h10P), 1, file ) != 1 ) X { X fprintf( stderr, "Couldn't read XWD file header.\n" ); X exit( 1 ); X } X X if ( h10P->file_version == X10WD_FILE_VERSION || X bs_int( h10P->file_version ) == X10WD_FILE_VERSION ) X { X if ( h10P->file_version != X10WD_FILE_VERSION ) X { X byte_swap = 1; X h10P->header_size = bs_int( h10P->header_size ); X h10P->file_version = bs_int( h10P->file_version ); X h10P->display_type = bs_int( h10P->display_type ); X h10P->display_planes = bs_int( h10P->display_planes ); X h10P->pixmap_format = bs_int( h10P->pixmap_format ); X h10P->pixmap_width = bs_int( h10P->pixmap_width ); X h10P->pixmap_height = bs_int( h10P->pixmap_height ); X h10P->window_width = bs_short( h10P->window_width ); X h10P->window_height = bs_short( h10P->window_height ); X h10P->window_x = bs_short( h10P->window_x ); X h10P->window_y = bs_short( h10P->window_y ); X h10P->window_bdrwidth = bs_short( h10P->window_bdrwidth ); X h10P->window_ncolors = bs_short( h10P->window_ncolors ); X } X if ( fread( junk, h10P->header_size - sizeof(*h10P), 1, file ) != 1 ) X { X fprintf( stderr, "Couldn't read rest of X10 XWD file header.\n" ); X exit( 1 ); X } X if ( fread( junk, sizeof(X10Color), h10P->window_ncolors, file ) != X h10P->window_ncolors ) X { X fprintf( stderr, "Couldn't read X10 XWD colormap.\n" ); X exit( 1 ); X } X X /* Check whether we can handle this dump. */ X if ( h10P->window_ncolors != 0 ) X { X fprintf( stderr, "Can't handle X10 window_ncolors != 0.\n" ); X exit( 1 ); X } X if ( h10P->pixmap_format != XYFormat ) X { X fprintf( stderr, "Can't handle X10 pixmap_format %d.\n", X h10P->pixmap_format ); X exit( 1 ); X } X X *colP = h10P->pixmap_width; X *rowP = h10P->pixmap_height; X *padrightP = X ( ( h10P->pixmap_width + 15 ) / 16 ) * 16 - h10P->pixmap_width; X bits_per_item = 16; X bits_used = bits_per_item; X bit_order = LSBFirst; X bit_invert = 1; X } X else X { X if ( h11P->file_version == X11WD_FILE_VERSION || X bs_long( h11P->file_version ) == X11WD_FILE_VERSION ) X { X if ( fread( &header[sizeof(*h10P)], sizeof(*h11P) - sizeof(*h10P), 1, file ) != 1 ) X { X fprintf( stderr, "Couldn't read X11 XWD file header.\n" ); X exit( 1 ); X } X if ( h11P->file_version != X11WD_FILE_VERSION ) X { X byte_swap = 1; X h11P->header_size = bs_long( h11P->header_size ); X h11P->file_version = bs_long( h11P->file_version ); X h11P->pixmap_format = bs_long( h11P->pixmap_format ); X h11P->pixmap_depth = bs_long( h11P->pixmap_depth ); X h11P->pixmap_width = bs_long( h11P->pixmap_width ); X h11P->pixmap_height = bs_long( h11P->pixmap_height ); X h11P->xoffset = bs_long( h11P->xoffset ); X h11P->byte_order = bs_long( h11P->byte_order ); X h11P->bitmap_unit = bs_long( h11P->bitmap_unit ); X h11P->bitmap_bit_order = bs_long( h11P->bitmap_bit_order ); X h11P->bitmap_pad = bs_long( h11P->bitmap_pad ); X h11P->bits_per_pixel = bs_long( h11P->bits_per_pixel ); X h11P->bytes_per_line = bs_long( h11P->bytes_per_line ); X h11P->visual_class = bs_long( h11P->visual_class ); X h11P->red_mask = bs_long( h11P->red_mask ); X h11P->green_mask = bs_long( h11P->green_mask ); X h11P->blue_mask = bs_long( h11P->blue_mask ); X h11P->bits_per_rgb = bs_long( h11P->bits_per_rgb ); X h11P->colormap_entries = bs_long( h11P->colormap_entries ); X h11P->ncolors = bs_long( h11P->ncolors ); X h11P->window_width = bs_long( h11P->window_width ); X h11P->window_height = bs_long( h11P->window_height ); X h11P->window_x = bs_long( h11P->window_x ); X h11P->window_y = bs_long( h11P->window_y ); X h11P->window_bdrwidth = bs_long( h11P->window_bdrwidth ); X } X if ( fread( junk, h11P->header_size - sizeof(*h11P), 1, file ) != 1 ) X { X fprintf( stderr, "Couldn't read rest of X11 XWD file header.\n" ); X exit( 1 ); X } X if ( fread( junk, sizeof(X11XColor), h11P->ncolors, file ) != X h11P->ncolors ) X { X fprintf( stderr, "Couldn't read X11 XWD colormap.\n" ); X exit( 1 ); X } X X /* Check whether we can handle this dump. */ X if ( h11P->pixmap_depth != 1 ) X { X fprintf( stderr, "Can't handle X11 pixmap_depth != 1.\n" ); X exit( 1 ); X } X if ( h11P->pixmap_format != XYBitmap && X h11P->pixmap_format != ZPixmap ) X { X fprintf( stderr, "Can't handle X11 pixmap_format %d.\n", X h11P->pixmap_format ); X exit( 1 ); X } X if ( h11P->bitmap_unit != h11P->bitmap_pad ) X { X fprintf( X stderr, X "X11 bitmap_unit (%d) != bitmap_pad (%d) - can't handle.\n", X h11P->bitmap_unit, h11P->bitmap_pad ); X exit( 1 ); X } X if ( h11P->bitmap_unit != 8 && h11P->bitmap_unit != 16 && X h11P->bitmap_unit != 32 ) X { X fprintf( X stderr, X "X11 bitmap_unit (%d) is non-standard - can't handle.\n", X h11P->bitmap_unit ); X exit( 1 ); X } X X *colP = h11P->pixmap_width; X *rowP = h11P->pixmap_height; X *padrightP = h11P->bytes_per_line * 8 - h11P->pixmap_width; X bits_per_item = h11P->bitmap_unit; X bits_used = bits_per_item; X bit_order = h11P->bitmap_bit_order; X bit_invert = 0; X } X else X { X fprintf( stderr, "Unknown XWD file version: %d.\n", X h11P->file_version ); X exit( 1 ); X } X } X X byteP = (char *) buf; X shortP = (short *) buf; X longP = (long *) buf; X } X Xbit Xgetbit( file ) XFILE *file; X { X bit b; X X if ( bits_used == bits_per_item ) X { X if ( fread( buf, bits_per_item / 8, 1, file ) != 1 ) X { X fprintf( stderr, "Couldn't read bits.\n" ); X exit( 1 ); X } X switch ( bits_per_item ) X { X case 8: X break; X X case 16: X if ( byte_swap ) X *shortP = bs_short( *shortP ); X break; X X case 32: X if ( byte_swap ) X *longP = bs_long( *longP ); X break; X } X bits_used = 0; X X if ( bit_order == MSBFirst ) X bit_shift = bits_per_item - 1; X else X bit_shift = 0; X } X X switch ( bits_per_item ) X { X case 8: X b = ( *byteP >> bit_shift) & 1; X break; X X case 16: X b = ( *shortP >> bit_shift) & 1; X break; X X case 32: X b = ( *longP >> bit_shift) & 1; X break; X } X X if ( bit_invert ) X b = 1 - b; X X if ( bit_order == MSBFirst ) X bit_shift--; X else X bit_shift++; X bits_used++; X X return b; X } X Xshort Xbs_short( s ) Xshort s; X { X short ss; X unsigned char *bp, t; X X ss = s; X bp = (unsigned char *) &ss; X t = bp[0]; X bp[0] = bp[1]; X bp[1] = t; X return ss; X } X Xint Xbs_int( i ) Xint i; X { X int ii; X unsigned char *bp, t; X X ii = i; X bp = (unsigned char *) ⅈ X t = bp[0]; X bp[0] = bp[3]; X bp[3] = t; X t = bp[1]; X bp[1] = bp[2]; X bp[2] = t; X return ii; X } X Xlong bs_long( l ) Xlong l; X { X return bs_int( l ); X } SHAR_EOF if test 8899 -ne "`wc -c < 'xwdtopbm.c'`" then echo shar: error transmitting "'xwdtopbm.c'" '(should have been 8899 characters)' fi fi # end of overwriting check # End of shell archive exit 0