Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/18/84; site uw-beaver Path: utzoo!watmath!clyde!burl!ulysses!mhuxr!mhuxt!houxm!vax135!cornell!uw-beaver!info-mac From: info-mac@uw-beaver Newsgroups: net.sources.mac Subject: Scribepic.shar Message-ID: <1525@uw-beaver> Date: Thu, 29-Aug-85 21:48:56 EDT Article-I.D.: uw-beave.1525 Posted: Thu Aug 29 21:48:56 1985 Date-Received: Sat, 31-Aug-85 07:34:46 EDT Sender: daemon@uw-beaver Organization: U of Washington Computer Science Lines: 1371 From: Richard M. Alderson Here is the source mentioned in the July 14 posting: : to unbundle, "sh" this file -- DO NOT use csh : SHAR archive format. Archive created Sun Jul 14 01:15:41 MDT 1985 echo x - READ_ME sed 's/^X//' >READ_ME <<'+FUNKY+STUFF+' XThese programs are for creating bitmap illustrations into XPostScript/Scribe documents. These support MacPaint files and Apollo GMF Xand BM files. However, any bitmap format using the MacPaint compression Xscheme could be adapted without too much trouble. X XThe MacPaint version (extract_top.c) should run on any Unix system, the Xapollo version must be run on an Apollo. X XFiles in this directory: X X extract_top.c - C program to extract Scribe-able PostScript pictures X from MacPaint files. X X extract_top.hlp - Documentation for the above. X X apollo_scribepic.c - Converts apollo GMF or Bitmap files into X Scribe-able pictures. GMF files are generated X by the DM's "XI" command and the cpscr command. X X gmf_inq.pas - Helper routine for apollo_scribepic.c (Must be X bound to apollo_scribepic. Use: X pas gmf_inq.pas; cc apollo_scribepic.c X bind gmf_inq.bin apollo_scribepic.bin -b apollo_scribepic X to compile and link it. X X scribepic.ps - PostScript preamble used by both programs. X XNOTE: Before using these, you'll want to edit them to change the Xconstant POSTDEF to reflect where the scribepic.ps file lives. X +FUNKY+STUFF+ ls -l READ_ME echo x - extract_top.c sed 's/^X//' >extract_top.c <<'+FUNKY+STUFF+' X/* X Yet another hack with P. Rowley's (U Toronto) macpaint code - this X extracts the top left portion and spits it out in hex, for putting illo's X in Scribe files. X X J.W. Peterson X Computer Science Department X University of Utah. X*/ X X#include X X#define and && X#define or || X X/* Flags & defaults for user */ X X#define FFLAG 'f' /* -f macpaint_file (input macpaint file) */ X#define COLFLAG 'c' /* -c col_width (column width to center on) */ X#define HEIGHTFLAG 'h' /* -h height (height of Scribe picture) */ X#define SIZEFLAG 's' /* -s x y (Size of macpaint picture (in pixels)) */ X#define UPFLAG 'u' /* -u updist (amount to translate up) */ X#define POSTFLAG 'P' /* -P postfile (PostScript file to use) */ X X/* Default values */ X X/* These determine the size of the picture (values here are for exactly the X * size of the window MacPaint displays (416 x 240)) */ X X/* This defines the width of the scanline accepted, IN BYTES (which equals X * the number of pixels / 8) X */ X#define LINE_WIDTH 52 X#define DEF_SCANLINES 240 /* This defines the height (# of scanlines) */ X X#define OUTDEF stdout X#define POSTDEF "/v/misc/mac/lw/scribe_pics/scribepic.ps" X X#define COLUMNDEF 6.5 /* Assume 6.5" text column */ X#define HEIGHTDEF 2 /* Assume 2" height */ X#define UPDEF 0 /* Assume 0" move UP */ X Xint line_width, scanlines; X Xchar in_line[72]; X XFILE *infil, *fopen(); X Xmain(argc,argv) Xint argc; Xchar *argv[]; X{ X int i, j, c; X int size_x, size_y; /* Size of MacPaint picture grabbed*/ X float columnwidth, height, up, atof(); X FILE *fpost; X char postfile[255], filename[255]; X X infil = stdin; /* assume stdin */ X filename[0] = '\0'; X strcpy(postfile, POSTDEF); X X /* Scribe defaults */ X height = HEIGHTDEF; X columnwidth = COLUMNDEF; X up = UPDEF; X X /* Default size clipped from MacPaint page */ X size_x = LINE_WIDTH * 8; X size_y = DEF_SCANLINES; X X /* Command line parsing */ X X for (i=1; i 0) and ((infil = fopen(filename, "r")) == NULL)) { X printf("Can't open input file %s\n", filename); X exit(1); X } X X if ((fpost = fopen(postfile, "r")) == NULL) { X printf("Can't open PostScript header file %s\n", postfile); X exit(1); X } X X /* read and discard 512 byte MacPaint header */ X for (i=0; i<512; i++) X getc(infil); X X /* Copy the postscript header to stdout */ X while ((c = getc(fpost)) != EOF) X putc(c, stdout); X X line_width = (int) size_x / 8; /* Convert to number of bytes */ X scanlines = size_y; X X /* Print a preamble describing size and shape */ X printf( "1 %d %d %f %f %f\n", line_width, scanlines, X columnwidth, height, up ); X X /* read and process each of scanlines scan lines (others get tossed) */ X for (i=0; i < scanlines; i++) X { X do_scan(); X } X} X Xdo_scan() { X int in_pos, count, data_byte, mcount; X unsigned int raw_data; X X in_pos = 0; X while (in_pos < 72) { X count = getc(infil); X X if (count > 127) count -= 256; X X /* Prevent computed count from exceding line_width */ X mcount = count; /* Modified count */ X X /* run too long */ X if ((count >= 0) and ((count + 1 + in_pos) > line_width)) X mcount = line_width - 1 - in_pos; X X /* Data string too long */ X if ((count < 0) and ((-count + 1 + in_pos) > line_width)) X mcount = -( line_width - in_pos -1 ); X X if (in_pos < line_width) X printf ( "%02X", (mcount+256) & 0xFF ); X X if (count >= 0) { /* run of raw bytes */ X count++; /* # of bytes to read */ X while (count--) { X raw_data = getc(infil); X if (in_pos < line_width) X printf ( "%02X", raw_data ); X in_pos++; X } X } X else { /* run of repeated byte */ X count = -count+1; /* repetition factor */ X data_byte = getc(infil); /* byte to repeat */ X if (in_pos < line_width) X printf ( "%02X", data_byte ); X X while (count--) /* Kinda dumb... */ X in_pos++; X } X } X printf ("\n"); X} X +FUNKY+STUFF+ ls -l extract_top.c echo x - extract_top.hlp sed 's/^X//' >extract_top.hlp <<'+FUNKY+STUFF+' XExtract_top is a program for taking a portion of a MacPaint picture and Xconverting it to a PostScript file that can be used with the @Picture command Xin Scribe. X XThe PostScript output generated by extract_top can be included in a Scribe Xfile with a Scribe command like the following: X X @figure[ X @picture(Size=3 inch, ScaleableLaser=[postscript_output.ps]) X @caption(System Overview) X @tag(SysView) X ] X XIn this case, the file "postscript_output.ps" is included into the scribe Xfile, and Scribe will leave 3 inches of column space for it. The "Size" Xspecified in the @Picture command should match the height given to Xextract_top with the "-h" option. (Extract_top's default is 2 inches). X XTo upload a MacPaint file to the vax, you'll need to run MacTerminal on Xthe mac, and use "macget -d filename" to upload the file. (Macget will Xcreate "filename.data" on the vax). See the man page for macget(1) for Xmore information on uploading files. X XExtract_top scales the macpaint picture to match the aspect ratio of the Xarea extracted, and centers it within the Scribe text column (assumed to Xbe 6.5 inches - i.e, 1" margins). You can use the -c option to change Xthe width of the column extract_top centers the picture in. Normally Xthe MacPaint image is placed at the bottom of the area Scribe allocates Xfor it, you can use the -u option to slide it up a specified number of Xinches. X XThe upper left portion of the MacPaint page is extracted by extract_top, the Xrest of the image is ignored. You can use the "Show Page" option in XMacPaint's "Goodies" menu to move your image to the upper left part of the Xpage. By default, extract_top selects an area the size of the window Xdisplayed in MacPaint (416 x 240 pixels). You can use the -s option to Xchange this size. Other useful sizes are 512x480 (a dithered frame buffer Ximage) and 576x720 (a full MacPaint page). X XSummary of extract_top options: X X X Option Description Default X ------ ----------- ------- X X -f file MacPaint file to get picture from Read from stdin X -c XX Set column width to center on (inches) 6.5 (Scribe's default) X -h XX Height of the resulting macpaint image 2.0 inches X -s x y Size (in pixels) of the area extracted 416 240 (M.P. window) X -P postfile PostScript preamble file to use. ~mac/lw/scribe_pics/scribepic.ps X -u XX Amount to slide MacPaint picture up 0.0 inches. X XExamples: X XTo extract a MacPaint-window sized image into a PostScript file for Xgenerating a 2" tall picture in Scribe: X X extract_top -f kloo_pic.data > kloo_pic.ps X XTo extract a full page MacPaint picture into a PostScript file for a 5.5" Xtall picture in Scribe: X X extract-top -f kloo_page.data -h 5.5 -s 576 720 > kloo_page.ps +FUNKY+STUFF+ ls -l extract_top.hlp echo x - apollo_scribepic.c sed 's/^X//' >apollo_scribepic.c <<'+FUNKY+STUFF+' X/*********************************************************************** X* * X* University of Utah - APOLLO Graphics Helper Routine * X* Copyright 1985 University of Utah * X* * X* SCRIBEPIC * X* * X* Module: Main module (scribepic.c) * X* * X* Version Date Person Description * X*----------------------------------------------------------------------* X* 0.1 2-Jun-85 J. Schimpf Make a MACPAINT style file * X* from a screen * X* 0.2 5-Jun-85 J. Schimpf Use level 2 I/O for speed * X* 0.3 5-Jun-85 J. Schimpf Added read GMF format stuff * X* 0.4 14-Jun-85 J. Schimpf Don't invert windows only * X* screens * X* 0.5 26-Jun-85 J. Schimpf Added margin,height & POSTSCRIPT* X* info so SCRIBE picture file * X* can be built * X* * X* Description of code: * X* Copy Apollo Window or Screen to a file suitable for use in a * X* SCRIBE @picture command. (See Below) * X* File produced is a POSTSCRIPT program with the run length * X* encoded version of the bit map following it * X* * X* SCRIBE Picture Command is of the form: * X* * X* @picture(size=2inch, ScalableLaser=[mypic.ps]) * X* * X* And the command used to make the mypic.ps file (assuming you * X* have a window or screen bit map in the file screen) is * X* * X* scribepic -f screen -h 2 -m 6 -o mypic.ps * X* * X* This sets the height at 2 inches, the distance between * X* margins as 6 inches and the output file as mypic.ps * X* the other values are defaulted (see below) * X* * X* SYNTAX: scribepic -f (filename) [-i] [-b] * X* [-o ] * X* [-m ] * X* [-h ] * X* [-P ] * X* [-u ] * X* * X* Parameter Use Default * X*----------------------------------------------------------------------* X* ****** FILE CONTROL ***** * X* * X* -f Input Screen file NONE - ERROR if missing * X* -b Input is APOLLO BM file GMF file assumed * X* (All STD screens & * X* Apollo windows are GMF)* X* -i Invert Input file NOT Inverted * X* -o Output Picture file STDOUT * X* * X* ***** SCRIBE FORMAT CONTROL ***** * X* * X* -m Page margin (inches) 6 inches * X* -h Picture heigh (inches) 2 inches * X* -u Move picture up page 0 inches * X* * X* ***** POSTSCRIPT CONTROL **** * X* * X* -P Postscript code ~/bin/scribepic.ps * X* * X*----------------------------------------------------------------------* X* * X* Output File is of the form: * X* * X* * X* X#include "/sys/ins/base.ins.c" X#include "/sys/ins/gpr.ins.c" X#include "/sys/ins/gmf.ins.c" X X/* Global Constants *******/ X X#define GPR_MODE gpr_$borrow /* Display MODE */ X#define TRUE 1 X#define FALSE 0 X X#define SCREEN_X 1024 /* DN 300 Screen constants */ X#define SCREEN_Y 800 X#define SCREEN_WD 64 X X#define MAX_SCAN_LINE 256 X#define BUF_SZ 50000 X X#define LF 0x0a X X#define SAME 1 X#define NOTSAME 0 X X/* Flags & defaults for user */ X X#define INVFLAG 'i' X#define FFLAG 'f' X#define BITFLAG 'b' X#define OUTFLAG 'o' X#define MARGFLAG 'm' X#define HEIGHTFLAG 'h' X#define UPFLAG 'u' X#define POSTFLAG 'P' X X#define OUTDEF stdout X#define POSTDEF "//a/utah/printers/scribe/scribepic.ps" X X#define MARGINDEF 6 /* Assume 6" margins */ X#define HEIGHTDEF 2 /* Assume 2" height */ X#define UPDEF 0 /* Assume 0" move UP */ X X/* Globals used by all routines */ X X int line_sz; /* # Bytes/scan line */ X int separation; /* Bytes between scan lines */ X int x_size,y_size; /* Raster size */ X char *bitp; /* Pointer to bitmap */ X Xmain(argc,argv) Xint argc; Xchar *argv[]; X{ X X name_$pname_t filename; X gpr_$bitmap_desc_t bitmap,get_bitmap(),get_gmf(); X status_$t status; X int psn = 0; X int outnum; X int n,i,j,size; X int invert,bitfile; X unsigned char scanline[MAX_SCAN_LINE]; X float height,margin,up,atof(); X FILE *fopen(),*fout,*fpost; X char postfile[30],outfile[30]; X X /* Scan command line for input file & other stuff, set other stuff X for defaults X */ X X /* Set default file control stuff */ X X invert = TRUE; X bitfile = FALSE; X filename[0] = '\0'; X X fout = OUTDEF; X strcpy(postfile,POSTDEF); X X /* Set default SCRIBE stuff */ X X height = HEIGHTDEF; X margin = MARGINDEF; X up = UPDEF; X X /* Now scan command line and set all the stuff */ X X for( i=1; i... If < 0x80 i.e. different bytes X* If > 0x80 i.e. repeated bytes X* X*****************************************************************************/ X Xcomprs_line(line,size) Xunsigned char line[]; Xint size; X{ X int i,j,k,cntpsn,count; X int flag; X unsigned char pixel; X unsigned char out[MAX_SCAN_LINE]; X X/*----------------------------------------------------------------------------- X X OPERATION: X X 1) Init counters, Check line - if first two byte == set flag X flag for same else, set for NOTSAME X 2) Reserve a slot in the output list for the count X 3) X X------------------------------------------------------------------------------*/ X X X X i = 0; X j = 2; X if( line[0] == line[1] ) X { X flag = SAME; X cntpsn = 0; X out[1] = line[0]; X } X else X { X flag = NOTSAME; X cntpsn = 0; X out[1] = line[0]; X } X X while( i < size ) X { X switch( flag ) { X X /* Same case see how far the run goes then update stuff */ X X case SAME: count = 0; X for( k=i; k Initialize buffer for run flush channel X* X* channel - fileid to use for output X* X* OUTPUT: If size = -1 Reset buffer pointers for output X* flush channel data ignored X* X* <>-1 Output data to buffer and write each time full X* X*********************************************************************************/ X Xout_buf(data,size,channel) Xchar data[]; Xint size,channel; X{ X int i; X char hexh,hexl,hex_con(); X X /* Ok look for the flush command */ X X if( size == -1 ) X { X write_buf(hexl,1,channel); X return; X } X X /* No flush - output the data as hex bytes to the buffer X if full write X */ X X for( i=0; i> 4; X else X nib = 0x0f & ch; X X /* Convert to hex */ X X if( nib > 9 ) X nib = nib + 'a' - 10; X else X nib = nib + '0'; X X return( nib ); X} +FUNKY+STUFF+ ls -l apollo_scribepic.c echo x - gmf_inq.pas sed 's/^X//' >gmf_inq.pas <<'+FUNKY+STUFF+' X Xmodule gmf_$extend; X XDEFINE gmf_$inquire; X X%include '/sys/ins/base.ins.pas'; X%include '/sys/ins/streams.ins.pas'; X Xprocedure gmf_$inquire( X in id: stream_$id_t; X out x_dim,y_dim, bpi: integer; out status: status_$t ); EXTERN; X Xprocedure gmf_$inquire; X Xconst X gmf_$not_gmf = 16#06040006; X XTYPE header_t = PACKED RECORD X kind : INTEGER; { type of header } X version : INTEGER; { } X x : INTEGER; { x dimension of bitmap in bits } X y : INTEGER; { y dimension of bitmap in bits } X gmf_bpi : INTEGER; { resolution of data in bits per inch, to whatever degree of } X { accuracy is feasible (0 means each bit is one dot } X { regardless of the dot size of the output device) } X END; X X wordsin_t = array [0..1023] of pinteger; { scanline-size array of read words from streams file } X wordsin_ptr_t = ^wordsin_t; X Xvar X t,lines :integer; { counters } X header :header_t; { header identifier } X wordsin :wordsin_t; { input buffer from map file } X bufptr,retptr :wordsin_ptr_t; X retlen :integer32; X seek_key :stream_$sk_t; X Xbegin X stream_$seek( id, stream_$rec, stream_$absolute, 1, status ); X if status.all <> status_$ok then begin X status.fail := true; X return; X end; X X bufptr := addr(wordsin); X X { setup header information from map file } X stream_$get_rec (id,bufptr,SIZEOF(header_t),retptr,retlen,seek_key,status); X X if status.all <> status_$ok then begin X status.fail := true; X return; X end; X for t := 0 to 10 do wordsin[t] := retptr^[t]; X X with header do begin X kind := wordsin[0]; X version := wordsin[1]; X x := wordsin[2]; X x_dim := wordsin[2]; X y := wordsin[3]; X y_dim := wordsin[3]; X gmf_bpi := wordsin[4]; X bpi := wordsin[4]; X end; X X { re-wind the input for future use... } X stream_$seek( id, stream_$rec, stream_$absolute, 1, status ); X if status.all <> status_$ok then begin X status.fail := true; X return; X end; X X { is opened file really a gmf map file? } X if header.kind <> 1 then X begin X status.all := gmf_$not_gmf; X return; X end; X Xend; +FUNKY+STUFF+ ls -l gmf_inq.pas echo x - scribepic.ps sed 's/^X//' >scribepic.ps <<'+FUNKY+STUFF+' X%! X% Postscript pre-amble to parse scribepic output. This is a fairly X% straightforward translation of Peter Rowley's (U Toronto) C code to X% do the same thing. X% X% Originally converted to PostScript by J.W. Peterson X% Arbitrary bitmap sizing added by J. Schimpf X% Margin & format control added by J. Schimpf X% X% SEE SCRIBEPIC info sheet for the use of this file X% YOU SHOULDN'T TRY TO EDIT THIS FILE - IT IS COPIED X% FOR YOU. X% X%--------------------------------------------------------------------- X% X% HEX FILE FORMAT X% X% X% X% X% Where Invert -> 1 For straight through data X% 0 To invert data X% Where YSIZE -> # Of Scan lines X% XBYTES -> # Bytes/scan line X% Margin -> Width of the scribe column (in inches) X% Height -> Height of picture (in inches) X% Move UP -> Distance picture is moved up (in inches) X% X% Hex data is of the form: X% X% -> If < 0x80 then this is count X% of # bytes to read here X% -> If >= 0x80 This is count of # times X% next byte is to be repeated X% X%-------------------------------------------------------------------------- X% Open file routine X/infile (%stdin) (r) file def % This gets around broke "currentfile"? X X%-------------------------------------------------------------------------- X% Get a byte from file routine X/getbyte X { infile (x) readhexstring X pop 0 get } def % Reads 1 byte of data X X%------------------------------------------------------------------------- X% Useful routines & definitions X/inch { 72 mul } def % Conversion inches => points X/inc { 1 add } def % increment TOS X X%-------------------------------------------------------------------------- X% Read file and form 1 scan line X/parseline X{ X /in_pos 0 def % output array pos X { X in_pos xbytes lt % while in_pos < xbytes DO... X { X /cnt getbyte def % get run length X X cnt 127 gt X { /cnt cnt 256 sub def } % if cnt > 128, cnt -= 256; X if X X cnt 0 ge % if cnt >= 0... X { X cnt inc % for count+1 times... X { scanline in_pos getbyte put % scanline[in_pos] = getbyte... X /in_pos in_pos inc def % in_pos++ X } repeat X } X % ELSE X { X /data_byte getbyte def % fetch the run data X cnt neg 1 add % -cnt + 1 X { scanline in_pos data_byte put % scanline[in_pos] = getbyte... X /in_pos in_pos inc def % in_pos++ X } repeat X } X ifelse X } X { exit } % Exit loop if !(in_pos < xbytes) X ifelse X X } X loop X scanline % leave the data on the stack X} def X X X%---------------------------------------------------------------------- X% MAIN ROUTINE X% X% Group all the operations to draw the picture into one procedure, to X% minimize confusion between PostScript commands and hex data... X% X/drawpaint X{ X gsave % Push graphics enviroment X X% Read if this is to be inverted or not put onto the stack, then decide X% If we should invert the data X X infile token pop X 1 eq X { X /invstat true def % Don't Invert the data X } X { X /invstat false def % Invert the data X } X ifelse X X% Get the X & Y size from the file X X /xbytes infile token pop def % Bytes/scanline X /ysize infile token pop def % # Scan lines X X% Get the margin, height & upward movement X X /margin infile token pop def % Default usually 6.5 in X /height infile token pop def % Default usually 2 in X /up infile token pop def % Default usually 0 X X% Generate some constants we will need X X /scanline xbytes string def % Create output scan buffer X /nysize ysize neg def % Used in matrix to define size X /xbits xbytes 8 mul def % Calculate # pixels/scanline X /width height xbits ysize div mul def % Width = height * (x / y) X X% Generate the transformation to place the "unit square" imagemask uses. X X margin width sub 2 div inch % center on page (with scribe margins) X % with x xlate = (margin - width) / 2 X up inch % Y translate by UP translate X translate % Center image on the page. X X width inch % Adjust X size to keep aspect ratio right X height inch % convert Y height to inches X scale X X%------------------------------------------------------------------ X% X% Generate image in unit box X X % The next 5 things are placed on the stack for X % the imagemask function X X xbits % # Pixels/Scanline X ysize % # Scan lines X X invstat % Use invstat to choose pixel black/white X [ xbits 0 0 nysize 0 ysize ] % Bit map description matrix X { parseline } % Routine to read scan lines X imagemask % Move bitmap to page X grestore % Restore graphics enviroment X} def X X% Put the hex data directly after the "drawpaint" command... Xdrawpaint +FUNKY+STUFF+ ls -l scribepic.ps exit 0 -------