#include #include /*................................................................*/ FILE *tek_file; FILE *bm_file; int x1, y1, x0, y0, bm_counter; int xoff[4], yoff[4], inext=0; char delimiter, reduce, nplotsfrm; char first_instruction, frame_flag, c1; char infile[80], outfile[80]; char ESC=27, FF=12, US=31, GS=29; unsigned char bitmap[1024*780/8]; int lineoffset; /* Global Variables: tek_file - Tektronix input file bm_file - Post Script output file frame_flag - whether or not frame has anything in it bm_counter - holds counter of Post Script points plotted first_instruction - whether or not first instruction of the frame. inext - controls position of plot on the frame */ /*...................................................................*/ main ( argc, argv ) int argc; char *argv[]; { void Setup(),Initialization(),Scan_Tektronix_File(),Close_Files(); Setup ( argc, argv ); Initialization(); Scan_Tektronix_File(); Close_Files(); } void Usage_Note() { fprintf ( stderr, "Usage: tekxbm [-options] [infile [outfile]\n"); fprintf ( stderr, "Options:\n" ); fprintf ( stderr, " -h displays this message\n" ); fprintf ( stderr, " -d n specifies character n as delimiter"); fprintf ( stderr," (default=%d)\n", delimiter ); fprintf ( stderr, " -f n specifies n plots per frame; n can only\n"); fprintf ( stderr, " be 1, 2 or 4" ); fprintf ( stderr," (default=%d)\n", nplotsfrm ); fprintf ( stderr, " -r n specifies reduction 1,2,4"); fprintf ( stderr," (default=%d)\n", reduce ); } void Setup ( argc, argv ) int argc; char *argv[]; { int i; char *fin=NULL; char *fout=NULL; /*---- defaults for internal parameters ---*/ delimiter = '%'; nplotsfrm = 1; reduce = 2; i=1; while (i= 32 ) && ( OneByte <= 63 ) ) { if ( after_low_y ) hx = OneByte - 32; else hy = OneByte - 32; after_low_y = 0; } /* Set low x */ else if ( ( OneByte >= 64 ) && ( OneByte <= 95 ) ) { lx = OneByte - 64; x0 = hx * 128 + lx * 4 + ( lxy & 3 ); y0 = hy * 128 + ly * 4 + ( lxy >> 2 ); if ( pen_down ) Plot ( x0, y0, 'L' ); else { Plot ( x0, y0, 'M' ); pen_down = 1; } after_low_y = 0; } /* Set low y / extra byte */ else if ( ( OneByte >= 96 ) && ( OneByte <= 127 ) ) { if ( after_low_y ) lxy = ( ly & 15 ); ly = OneByte - 96; after_low_y = 1; } } } if ( inext != 0 ) { inext = 999; /* to force end of page */ frame_flag = 1; } End_Page(); } void Initialization() { int i; for(i=0;i<1024*780/8;i++)bitmap[i]=0; lineoffset=1024/reduce/8; } void New_Page() { int i; for(i=0;i<1024*780/8;i++)bitmap[i]=0; } void Plot ( XA, YA, com ) int XA, YA; char com; /* This procedure plots or move the pen depending on the value of com: xa, ya -- Tektronix coordinates - range: [0,4095] com -- command: "M" - move to position xa, xb "L" - draw line from previous position to xa, ya NOTE: The bm_counter is related to the size of the printer buffer. The value used (500) is ok for many printers (like Apple, NEC, TI, etc...) */ { int xa, ya; void line(); switch ( nplotsfrm ) /* transform coordinates according to the number of plots per frame */ { case 2: xa = xoff[inext] + 0.64 * XA ; ya = yoff[inext] + 0.64 * YA ; break; case 4: xa = xoff[inext] + 0.5 * ( YA ); ya = yoff[inext] + 0.5 * ( 4096 - XA ); break; case 7: xa = xoff[inext] + 1.024 * ( YA - 1600) + 800.; ya = yoff[inext] + 0.8 * ( 2048 - XA) + 1024.; break; case 8: xa = xoff[inext] + 1.28 * ( YA - 1600) + 800.; ya = yoff[inext] + 1. * ( 2048 - XA) + 1024.; break; case 9: xa = xoff[inext] + 1.6 * ( YA - 1600) + 800.; ya = yoff[inext] + 1.25 * ( 2048 - XA) + 1024.; break; default: xa = XA; ya = 3120 - YA; break; } if ( ! frame_flag ) { if ( first_instruction ) /* consider only frames with more than 1 instruction */ { x1 = xa; y1 = ya; c1 = com; first_instruction = 0; } else { New_Page(); if ( com == 'L' ) line ( x1, y1, xa, ya ); x1 = xa; y1 = ya; frame_flag = 1; } } else /* third or later instruction */ { if ( com == 'L' ) line ( x1, y1, xa, ya ); x1 = xa; y1 = ya; } } /* end of Plot */ void End_Page() { int i,j; if ( frame_flag ) { inext++; if ( inext >= nplotsfrm ) inext=putbitmap(bm_file,bitmap,1024/reduce,780/reduce); } } void line ( x1, y1, x2, y2 ) int x1, y1, x2, y2; /* Draw line using Bresenham's algorithm */ { register int t, dist; int xerr=0, yerr=0, dx, dy; int incx, incy; static int bits[]={128,64,32,16,8,4,2,1}; /* compute distance in both directions */ x1=x1/4/reduce; x2=x2/4/reduce; y1=y1/4/reduce; y2=y2/4/reduce; dx = x2 - x1; dy = y2 - y1; /* compute direction of the increment, an increment of 0 means either a vertical or horizontal line. */ if ( dx>0 ) incx = 1; else if ( dx==0 ) incx = 0; else incx = -1; if ( dy>0 ) incy = 1; else if ( dy==0 ) incy = 0; else incy = -1; /* determine which distance is greater */ dx = abs ( dx ); dy = abs ( dy ); if ( dx > dy ) dist = dx; else dist = dy; /* draw the line */ for ( t = 0; t<=dist+1; t++ ) { bitmap[x1/8+lineoffset*(y1)] = bitmap[x1/8+lineoffset*(y1)] | bits[x1%8]; xerr += dx; yerr += dy; if ( xerr > dist ) { xerr -= dist; x1 += incx; } if ( yerr > dist ) { yerr -= dist; y1 += incy; } } } /* ---------------------------------------------------------------------- */