/* BITMAPIN (STD) -- Import Bitmap Data */ /* BITMAPIN (STD) -- Import Bitmapdaten */ /* // Copyright (c) 2005-2012 Oliver Bartels F+E, Muenchen // Author: Roman Ludwig // Changes History: // rl (120427) RELEASED FOR BAE V7.8. // rl (101019) RELEASED FOR BAE V7.6. // rl (100225) BUGFIX: // Fixed problem with antialiasing start conditions. // rl (091021) RELEASED FOR BAE V7.4. // rl (081014) RELEASED FOR BAE V7.2. // jw/rl (071126) ENHANCEMENT: // Added signal/power layer support. // rl (071029) RELEASED FOR BAE V7.0. // rl (060829) RELEASED FOR BAE V6.8. // rl (050906) RELEASED FOR BAE V6.6. // rl (050408) ORIGINAL CODING. // // DESCRIPTION // // The bitmapin User Language program imports bitmap files in various formats // and converts the therein defined graphic to documentary areas. */ // Includes #include "pop.ulh" // User Language popup utilities #include "lay.ulh" // User Language layout utilities // Enforce editor caller type #pragma ULCALLEREDT // Disable undo state request #pragma ULCALLERNOUNDO // Messages string UPRABORT = M_UPRABORT(); string UPRPEXIT = M_UPRPEXIT(); string UPRFMT = M("Format selektieren!", "Select Format!"); string UPRFMT1 = M("&PCX 24 Bit komprimiert","PCX 24 Bit compressed"); string UPRFMT2 = M("BMP &monochrom unkomprimiert", "BMP &monochrom uncompressed"); string UPRFMT3 = M("&BMP 24 Bit unkomprimiert", "&BMP 24 Bit uncompressed"); string UPRPCXFILE = M("PCX-Dateiname ? ","PCX File Name ? "); string UPRBMPFILE = M("BMP-Dateiname ? ","BMP File Name ? "); string UPRDOCLAY = M("Lage fuer Bitmapdaten selektieren!", "Select Bitmap Data Layer!"); string UPRBMPPARAM = M("Bitmap Parameter","Bitmap Settings"); string UPRRESDPI = M("Aufloesung [dpi]","Resolution [dpi]"); string UPRXDPI = M("X-Aufloesung [dpi] ? ","X Resolution [dpi] ?"); string UPRYDPI = M("Y-Aufloesung [dpi] ? ","Y Resolution [dpi] ?"); string UPRDXDPI = M("X :","X :"); string UPRDYDPI = M("Y :","Y :"); string UPRALIAS = M("Antialias ? ","Antialiasing ? "); string UPRDALIAS = M("Antialias :","Antialiasing :"); string UPRISLAND = M("Inselmindestgroesse ? ","Island min. size ? "); string UPRDISLAND = M("Inselmindestgroesse :","Island min. size :"); string UPRSIZE0 = M("&aus","&off"); string UPRSIZE1 = M("&1","&1"); string UPRSIZE2 = M("&2","&2"); string UPRSIZE3 = M("&3","&3"); string UPRSIZE4 = M("&4","&4"); string UPRBW = M("Uebernahmemodus selektieren!", "Select import mode!"); string UPRDBW = M("Uebernahme :","Import :"); string UPRBLACK = M("&dunkel","&dark"); string UPRWHITE = M("&hell","&light"); string UPRZERO = M("&null","&zero"); string UPRONE = M("&eins","&one"); string UPRDTHRES = M("Schwellwert [0.0,1.0] :","Threshold [0.0,1.0] :"); string UPRTHRES = M("Schwellwert [0.0,1.0] ? ", "Threshold [0.0,1.0] ? "); string REPLINE = M("Zeile %d/%d","Line %d/%d"); string REPBMPSIZE = M("Bitmap %d Pixel x %d Pixel", "Bitmap %s Pixels x %d Pixels"); string ERRFMIS = M("Datei '%s' nicht gefunden!", "File '%s' not found!"); string ERRINVENC = M("Nicht unterstuetzte Kodierung!", "Unsupported coding!"); // INI file parameter name definitions #define PAR_BMPALIAS "BMPANTIALIAS_STD" // Antialiasing #define PAR_BMPISLAND "BMPISLAND_STD" // Island size #define PAR_BMPBWMODE "BMPBWMODE_STD" // B/W process mode #define PAR_BMPTHRES "BMPTHRESHOLD_STD" // Grey value THRESHOLD #define PCXEXT ".pcx" // PCX bitmap file name extension #define BMPEXT ".bmp" // Windows bitmap file name extension #define DEFDPI 72.0 // Default DPI value #define COLFIN 2 // Fade in color value #define GV_BMPALIAS "bmp_antialias" // Antialiasing #define GV_BMPISLAND "bmp_island" // Island size #define GV_BMPBWMODE "bmp_bwmode" // B/W process mode #define GV_BMPTHRES "bmp_threshold" // Grey value THRESHOLD #define CORNCMASK 0x0F // Corner class mask #define EDGEFIX 0x10 // Edge fix bit #define EDGESKIP 0x20 // Skip edge for antialiasing bit int scmflag = (uliptype()==ULIPSCM ? 1 : 0) /* SCM environment flag */; int fh /* File handle */; int format /* File format */; int linebytes /* Bytes per line */; int w, h /* Bitmap dimension */; double xres, yres /* Bitmap floating resolution */; int redline[] /* Red scan line */; int greenline[] /* Green scan line */; int curline[] /* Current scan line */; int encbuf /* Encoding buffer */; int enccnt = 0 /* Encoding count */; int BWFLAG = bae_iniintval(PAR_BMPBWMODE,0) /* Black/white flag */; int ANTIALIAS = bae_iniintval(PAR_BMPALIAS,1) /* Antialias distance */; int ISLAND = bae_iniintval(PAR_BMPISLAND,0) /* Min. island size */; double THRESHOLD = bae_inidblval(PAR_BMPTHRES,0.25) /* Grey value THRESHOLD */; int curlayer /* Current layer */; int curptyp /* Current polygon type */; int row /* Current row */; int pidx /* Current polygon index */; double xfac, yfac /* Conversion factors */; double wsnx = bae_planwsnx() /* Workspace X origin */; double wsny = bae_planwsny() /* Workspace Y origin */; double wsux, wsuy /* Workspace upper coordinates */; double basex, basey /* Workspace upper coordinates */; struct polydes { // Polygon descriptor int lxl[],lyl[] /* Left boundary coordinate list */; int lcl[] /* Left boundary class list */; int l /* Current left boundary */; int ln /* Left boundary coordinate count */; int rxl[],ryl[] /* Right boundary coordinate list */; int rcl[] /* Right boundary class list */; int r /* Current right boundary */; int rn /* Right boundary coordinate count */; int next /* Next free polygon index */; } polyl[] /* Polygon list */; int polyn = 0 /* Polygon count */; int pfree = (-1) /* Polygon free chain header */; int pl[] /* Polygon index list */; int pn = 0 /* Polygon index count */; // Main program void main() { string fname /* File name */; string fext /* File extension */; string msg /* Message buffer */; double pcol = 23.0 /* Parameter column */; double cy /* Dialog box current y coordinate */; int repflag /* Dialog box repeat flag */; int res /* Dialog box selection result */; int varidx /* INI variable index */; int xdpidx /* X dpi parameter index */; int ydpidx /* Y dpi parameter index */; int alsidx /* Alias parameter index */; int islidx /* Island size parameter index */; int bwidx /* Black/white parameter index */; int thridx = (-1) /* Threshold parameter index */; int fp /* Flush polygon index */; int intval /* Integer value buffer */; double dblval /* Double value buffer */; int i /* Loop control variable */; // Abort if invalid plan class if (bae_planddbclass()==DDBCLUNDEF) error_class(); if (varget(GV_BMPBWMODE,intval)==0) BWFLAG=intval; if (varget(GV_BMPALIAS,intval)==0) ANTIALIAS=intval; if (varget(GV_BMPISLAND,intval)==0) ISLAND=intval; if (varget(GV_BMPTHRES,dblval)==0) THRESHOLD=dblval; // Get the file format bae_promptdialog(UPRFMT); switch (format=bae_askmenu(4,UPRFMT1,UPRFMT2,UPRFMT3,UPRABORT)) { // PCX 24 Bit case 0 : msg=UPRPCXFILE; fext=PCXEXT; break; // BMP monochrome case 1 : msg=UPRBMPFILE; fext=BMPEXT; break; // BMP 24 Bit case 2 : msg=UPRBMPFILE; fext=BMPEXT; break; default : error_abort(); } // Select file if (bae_askfilename(fname,fext,msg) || fname=="") // Abort error_abort(); // Test if file exists if (filetype(fname)<=0) // File not found errormsg(ERRFMIS,fname); if (scmflag) { curptyp=C_POLYDOCAREA; } else { if (bae_promptdialog(UPRDOCLAY),ged_asklayer(curlayer,7)) error_abort(); if (curlayer>=0 && curlayer=POWLAYBASE && curlayer1) error_abort(); } else { bae_promptdialog(UPRBW); if ((BWFLAG=bae_askmenu(3, UPRBLACK,UPRWHITE,UPRABORT))<0 || BWFLAG>1) error_abort(); bae_promptdialog(UPRTHRES); if (askdbl(THRESHOLD,UPRXDPI,5) || THRESHOLD<0.0 || THRESHOLD>1.0) error_abort(); } } else { // Init. the y coordinate cy=DIAL_TOPMARG; // Store size label sprintf(msg,REPBMPSIZE,w,h); dial_label(0.0,cy,msg); cy+=DIAL_CTRVSTEP; // Store dpi controls dial_label(0.0,cy,UPRRESDPI); dial_label(pcol,cy,UPRDXDPI); xdpidx=bae_dialaddcontrol(PA_DBL|PA_CHKLL,0,1,0,0.0, 0.0,xres,"",0,DIAL_LEFTMARG+pcol+2.0,cy,5.0,""); dial_label(pcol+9.0,cy,UPRDYDPI); ydpidx=dial_double(1,yres,pcol+11.0,cy); // Store antialiasing mode controls dial_label(0.0,cy,UPRDALIAS); alsidx=dial_selbox(ANTIALIAS,pcol,cy); dial_sbentry(0,0,UPRSIZE0); dial_sbentry(0,1,UPRSIZE1); dial_sbentry(0,2,UPRSIZE2); dial_sbentry(0,3,UPRSIZE3); dial_sbentry(0,4,UPRSIZE4); // Store island mode controls dial_label(0.0,cy,UPRDISLAND); islidx=dial_selbox(ISLAND,pcol,cy); dial_sbentry(0,0,UPRSIZE0); dial_sbentry(0,1,UPRSIZE1); dial_sbentry(0,2,UPRSIZE2); dial_sbentry(0,3,UPRSIZE3); dial_sbentry(0,4,UPRSIZE4); // Store B/W controls dial_label(0.0,cy,UPRDBW); bwidx=bae_dialaddcontrol(PA_RBF,0,0,BWFLAG,0.0,0.0,0.0,"",0, DIAL_LEFTMARG+pcol,cy,0.0,format==1 ? UPRZERO : UPRBLACK); bae_dialaddcontrol(PA_RBN,1,0,0,0.0,0.0,0.0,"",0, DIAL_LEFTMARG+pcol+9.0,cy,0.0,format==1 ? UPRONE : UPRWHITE); cy+=DIAL_CTRVSTEP; // Store THRESHOLD controls if (format!=1) { dial_label(0.0,cy,UPRDTHRES); thridx=dial_double(5,THRESHOLD,pcol,cy); } dial_hsep(cy); dial_okabortini(cy,pcol+18.7,1); // Perform the dialog input loop repflag=1; do { // Call the dialog function bae_setintpar(16,5001); switch (res=bae_dialaskparams( UPRBMPPARAM,0,DIAL_LEFTMARG+pcol+18.7,cy)) { // Done case 0 : repflag=0; case 1 : // Get parameters bae_dialgetdata(xdpidx,0,xres,""); bae_dialgetdata(ydpidx,0,yres,""); bae_dialgetdata(alsidx,ANTIALIAS,0.0,""); bae_dialgetdata(islidx,ISLAND,0.0,""); bae_dialgetdata(bwidx,BWFLAG,0.0,""); if (thridx!=(-1)) bae_dialgetdata(thridx,0,THRESHOLD,""); if (res==0) break; varidx=0; if (thridx!=(-1)) bae_inidblset( varidx,PAR_BMPTHRES,THRESHOLD); bae_iniintset(varidx,PAR_BMPALIAS,ANTIALIAS); bae_iniintset(varidx,PAR_BMPISLAND,ISLAND); bae_iniintset(varidx,PAR_BMPBWMODE,BWFLAG); bae_iniwrite(varidx); break; // Fail/abort case (-1) : default : error_abort(); } // Stop if no further repeat requests } while (repflag); } // Store settings for next call varset(GV_BMPBWMODE,BWFLAG); varset(GV_BMPALIAS,ANTIALIAS); varset(GV_BMPISLAND,ISLAND); varset(GV_BMPTHRES,THRESHOLD); // Calc. conversion factors xfac=cvtlength(1.0/xres,1,0); yfac=cvtlength(1.0/yres,1,0); if (!scmflag) layerfadein(curlayer,COLFIN,0); // Zoom to target area wsux=wsnx+w*xfac; wsuy=wsny+h*xfac; bae_clriactqueue(); bae_storemouseiact(1,wsny,wsny,0,LMB); bae_storemouseiact(1,wsux,wsuy,0,LMB); bae_callmenu(MNU_BAEZOOMWND); basex=wsny; if (format==0) { yfac*=(-1.0); basey=wsuy; } else { basey=wsny; } // Save current state for undo bae_callmenu(MNU_BAESAVESTATE); // Read lines for (row=0;row=0;i--) { fp=pl[i]; storepoly(fp); } // Close the file fclose(fh); bae_prtdialog(""); } void readheader() // Read file header { int lx, ly /* Bitmap lower corner */; int ux, uy /* Bitmap upper corner */; int hres, vres /* Bitmap resolution */; int skipsize /* Bitmap header skip offset */; int i /* Loop control variable */; switch (format) { // PCX 24 Bit case 0 : fgetc(fh); fgetc(fh); if (fgetc(fh)!=1) error(ERRINVENC); fgetc(fh); lx=readint(); ly=readint(); ux=readint(); uy=readint(); w=ux-lx+1; h=uy-ly+1; hres=readint(); vres=readint(); for (i=0;i<48;i++) fgetc(fh); if (fgetc(fh)!=0) error(ERRINVENC); if (fgetc(fh)!=3) error(ERRINVENC); linebytes=readint(); readint(); for (i=0;i<58;i++) fgetc(fh); xres=hres; yres=vres; break; // Windows BMP monochrome case 1 : if (fgetc(fh)!='B' || fgetc(fh)!='M') error(ERRINVENC); for (i=0;i<8;i++) fgetc(fh); skipsize=readquadint()-54; readquadint(); w=readquadint(); h=readquadint(); if (readint()!=1) error(ERRINVENC); if (readint()!=1) error(ERRINVENC); // Get compression if (readquadint()!=0) error(ERRINVENC); readquadint(); hres=readquadint(); vres=readquadint(); readquadint(); readquadint(); // Skip color table for (i=0;iTHRESHOLD ? 1 : 0; else curline[col]= greyval>=1; bcnt--; } // Read pad bytes while ((bytecnt&0x03)!=0) { fgetc(fh); bytecnt++; } break; // Windows BMP 24 Bit case 2 : bytecnt=0; for (col=0;colTHRESHOLD ? 1 : 0; else curline[col]= greyval0) { p=pl[pidx-1]; if (polyl[p].rn>1 && polyl[p].rxl[polyl[p].rn-2]>=lcol) { polyl[p].rcl[polyl[p].rn-2]=EDGEFIX; polyl[p].rcl[polyl[p].rn-1]=EDGEFIX; touch=EDGEFIX; } } // Create new polygon if (pfree>=0) { p=pfree; pfree=polyl[p].next; } else { p=polyn; polyn++; } // Store polygon data polyl[p].l=lcol; polyl[p].lxl[0]=lcol; polyl[p].lyl[0]=row; polyl[p].lcl[0]=touch; polyl[p].ln=1; polyl[p].r=col; polyl[p].rxl[0]=col; polyl[p].ryl[0]=row; polyl[p].rcl[0]=touch; polyl[p].rn=1; for (i=pn;i>pidx;i--) pl[i]=pl[i-1]; pl[pidx]=p; pn++; pidx++; } } // Flush polygons while (pidxrmax) rmax=polyl[p].rxl[i]; if ((row-polyl[p].lyl[0])<=ISLAND && (rmax-lmin)<=ISLAND) { // Free polygon polyl[p].next=pfree; pfree=p; // Update the polygon index list for (i=pidx;i<(pn-1);i++) pl[i]=pl[i+1]; pn--; return; } } bae_clearpoints(); // Store left polygon side start point pcnt=polyl[p].ln; storegridpoint(polyl[p].lxl[0],polyl[p].lyl[0]); if (ANTIALIAS!=0) { // Store extension point for corner classification access polyl[p].lxl[pcnt]=polyl[p].l; polyl[p].lyl[pcnt]=row; // Mark first corner if (pcnt>2) { ls=abs(polyl[p].lyl[1]-polyl[p].lyl[0])<=ANTIALIAS ? 4 : 0; if (polyl[p].lcl[0]&EDGEFIX) polyl[p].lcl[1]=EDGEFIX; else polyl[p].lcl[0]=EDGEFIX; if (polyl[p].lxl[2]>polyl[p].lxl[0]) polyl[p].lcl[1]=EDGEFIX; if (polyl[p].lxl[pcnt-2]>polyl[p].l) polyl[p].lcl[pcnt-1]=EDGEFIX; } // Classify left side corners for (i=1;i0 ? 2 : 0)|ls|cs; curclass=(polyl[p].lcl[i]); // Check corner combination switch (polyl[p].lcl[i-1]&CORNCMASK) { case 0 : switch (curclass&CORNCMASK) { case 1 : case 3 : case 11 : polyl[p].lcl[i-1]|=EDGEFIX; polyl[p].lcl[i]|=EDGEFIX; break; case 9 : if (!(curclass&EDGEFIX)) { polyl[p].lcl[i]|=EDGESKIP; polyl[p].lcl[i+1]|=EDGEFIX; } break; default : ; } break; case 1 : switch (curclass&CORNCMASK) { case 0 : polyl[p].lcl[i-1]|=EDGEFIX; polyl[p].lcl[i]|=EDGEFIX; break; case 8 : polyl[p].lcl[i-1]|=EDGEFIX; if (!(curclass&EDGEFIX)) { polyl[p].lcl[i]|=EDGESKIP; polyl[p].lcl[i+1]|=EDGEFIX; } break; default : ; } break; case 2 : switch (curclass&CORNCMASK) { case 1 : case 3 : case 9 : polyl[p].lcl[i-1]|=EDGEFIX; polyl[p].lcl[i]|=EDGEFIX; break; case 11 : polyl[p].lcl[i-1]|=EDGEFIX; if (!(curclass&EDGEFIX)) { polyl[p].lcl[i]|=EDGESKIP; polyl[p].lcl[i+1]|=EDGEFIX; } break; default : ; } break; case 3 : switch (curclass&CORNCMASK) { case 2 : polyl[p].lcl[i-1]|=EDGEFIX; polyl[p].lcl[i]|=EDGEFIX; break; case 10 : polyl[p].lcl[i-1]|=EDGEFIX; if (!(curclass&EDGEFIX)) { polyl[p].lcl[i]|=EDGESKIP; polyl[p].lcl[i+1]|=EDGEFIX; } break; default : ; } break; case 4 : switch (curclass&CORNCMASK) { case 1 : if (!(polyl[p].lcl[i-1]&EDGEFIX)) { polyl[p].lcl[i-1]|=EDGESKIP; polyl[p].lcl[i]|=EDGEFIX; } break; case 3 : case 11 : polyl[p].lcl[i-1]|=EDGEFIX; polyl[p].lcl[i]|=EDGEFIX; break; case 9 : if (!(curclass&EDGEFIX)) { if (!(polyl[p].lcl[i-1]&EDGEFIX)) { if (i>1) polyl[p].lcl[i-2]|= EDGEFIX; polyl[p].lcl[i-1]|=EDGESKIP; polyl[p].lcl[i]|=EDGESKIP; polyl[p].lcl[i+1]|=EDGEFIX; } else { polyl[p].lcl[i]|=EDGESKIP; polyl[p].lcl[i+1]|=EDGEFIX; } } break; default : ; } break; case 5 : switch (curclass&CORNCMASK) { case 0 : polyl[p].lcl[i-1]|=EDGESKIP; polyl[p].lcl[i]|=EDGEFIX; break; case 8 : if (!(curclass&EDGEFIX)) { if (!(polyl[p].lcl[i-1]&EDGEFIX)) { if (i>1) polyl[p].lcl[i-2]|= EDGEFIX; polyl[p].lcl[i-1]|=EDGESKIP; polyl[p].lcl[i]|=EDGESKIP; polyl[p].lcl[i+1]|=EDGEFIX; } else { polyl[p].lcl[i]|=EDGESKIP; polyl[p].lcl[i+1]|=EDGEFIX; } } break; default : ; } break; case 6 : switch (curclass&CORNCMASK) { case 1 : case 9 : polyl[p].lcl[i-1]|=EDGEFIX; polyl[p].lcl[i]|=EDGEFIX; break; case 3 : if (!(polyl[p].lcl[i-1]&EDGEFIX)) { polyl[p].lcl[i-1]|=EDGESKIP; polyl[p].lcl[i]|=EDGEFIX; } break; case 11 : if (!(curclass&EDGEFIX)) { if (!(polyl[p].lcl[i-1]&EDGEFIX)) { if (i>1) polyl[p].lcl[i-2]|= EDGEFIX; polyl[p].lcl[i-1]|=EDGESKIP; polyl[p].lcl[i]|=EDGESKIP; polyl[p].lcl[i+1]|=EDGEFIX; } else { polyl[p].lcl[i]|=EDGESKIP; polyl[p].lcl[i+1]|=EDGEFIX; } } break; default : ; } break; case 7 : switch (curclass&CORNCMASK) { case 2 : if (!(polyl[p].lcl[i-1]&EDGEFIX) && !(curclass&EDGEFIX)) { if (i>1) polyl[p].lcl[i-2]|=EDGEFIX; polyl[p].lcl[i-1]|=EDGESKIP; } polyl[p].lcl[i]|=EDGEFIX; break; case 10 : if (!(curclass&EDGEFIX)) { if (!(polyl[p].lcl[i-1]&EDGEFIX)) { if (i>1) polyl[p].lcl[i-2]|= EDGEFIX; polyl[p].lcl[i-1]|=EDGESKIP; polyl[p].lcl[i]|=EDGESKIP; polyl[p].lcl[i+1]|=EDGEFIX; } else { polyl[p].lcl[i]|=EDGESKIP; polyl[p].lcl[i+1]|=EDGEFIX; } } break; default : ; } break; case 8 : case 12 : switch (curclass&CORNCMASK) { case 5 : case 13 : if (!(curclass&EDGEFIX)) { if (!(polyl[p].lcl[i-1]&EDGEFIX)) { if (i>1) polyl[p].lcl[i-2]|= EDGEFIX; polyl[p].lcl[i-1]|=EDGESKIP; polyl[p].lcl[i]|=EDGESKIP; polyl[p].lcl[i+1]|=EDGEFIX; } else { polyl[p].lcl[i]|=EDGESKIP; polyl[p].lcl[i+1]|=EDGEFIX; } } break; case 7 : case 15 : polyl[p].lcl[i-1]|=EDGEFIX; polyl[p].lcl[i]|=EDGEFIX; break; default : ; } break; case 9 : case 13 : switch (curclass&CORNCMASK) { case 4 : case 12 : if (!(curclass&EDGEFIX)) { if (!(polyl[p].lcl[i-1]&EDGEFIX)) { if (i>1) polyl[p].lcl[i-2]|= EDGEFIX; polyl[p].lcl[i-1]|=EDGESKIP; polyl[p].lcl[i]|=EDGESKIP; polyl[p].lcl[i+1]|=EDGEFIX; } else { polyl[p].lcl[i]|=EDGESKIP; polyl[p].lcl[i+1]|=EDGEFIX; } } break; default : ; } break; case 10 : case 14 : switch (curclass&CORNCMASK) { case 5 : case 13 : polyl[p].lcl[i-1]|=EDGEFIX; polyl[p].lcl[i]|=EDGEFIX; break; case 7 : case 15 : if (!(curclass&EDGEFIX)) { if (!(polyl[p].lcl[i-1]&EDGEFIX)) { if (i>1) polyl[p].lcl[i-2]|= EDGEFIX; polyl[p].lcl[i-1]|=EDGESKIP; polyl[p].lcl[i]|=EDGESKIP; polyl[p].lcl[i+1]|=EDGEFIX; } else { polyl[p].lcl[i]|=EDGESKIP; polyl[p].lcl[i+1]|=EDGEFIX; } } break; default : ; } break; case 11 : case 15 : switch (curclass&CORNCMASK) { case 6 : case 14 : if (!(curclass&EDGEFIX)) { if (!(polyl[p].lcl[i-1]&EDGEFIX)) { if (i>1) polyl[p].lcl[i-2]|= EDGEFIX; polyl[p].lcl[i-1]|=EDGESKIP; polyl[p].lcl[i]|=EDGESKIP; polyl[p].lcl[i+1]|=EDGEFIX; } else { polyl[p].lcl[i]|=EDGESKIP; polyl[p].lcl[i+1]|=EDGEFIX; } } break; default : ; } break; default : ; } ls=cs>>1; } } // Store left polygon side for (i=1;i2) { ls=abs(polyl[p].ryl[1]-polyl[p].ryl[0])<=ANTIALIAS ? 4 : 0; if (polyl[p].rcl[0]&EDGEFIX) polyl[p].rcl[1]=EDGEFIX; else polyl[p].rcl[0]=EDGEFIX; if (polyl[p].rxl[2]0 ? 2 : 0)|ls|cs; curclass=(polyl[p].rcl[i]); // Check corner combination switch (polyl[p].rcl[i-1]&CORNCMASK) { case 0 : switch (curclass&CORNCMASK) { case 1 : case 3 : case 11 : polyl[p].rcl[i-1]|=EDGEFIX; polyl[p].rcl[i]|=EDGEFIX; break; case 9 : if (!(curclass&EDGEFIX)) { polyl[p].rcl[i]|=EDGESKIP; polyl[p].rcl[i+1]|=EDGEFIX; } break; default : ; } break; case 1 : switch (curclass&CORNCMASK) { case 0 : polyl[p].rcl[i-1]|=EDGEFIX; polyl[p].rcl[i]|=EDGEFIX; break; case 8 : polyl[p].rcl[i-1]|=EDGEFIX; if (!(curclass&EDGEFIX)) { polyl[p].rcl[i]|=EDGESKIP; polyl[p].rcl[i+1]|=EDGEFIX; } break; default : ; } break; case 2 : switch (curclass&CORNCMASK) { case 1 : case 3 : case 9 : polyl[p].rcl[i-1]|=EDGEFIX; polyl[p].rcl[i]|=EDGEFIX; break; case 11 : polyl[p].rcl[i-1]|=EDGEFIX; if (!(curclass&EDGEFIX)) { polyl[p].rcl[i]|=EDGESKIP; polyl[p].rcl[i+1]|=EDGEFIX; } break; default : ; } break; case 3 : switch (curclass&CORNCMASK) { case 2 : polyl[p].rcl[i-1]|=EDGEFIX; polyl[p].rcl[i]|=EDGEFIX; break; case 10 : polyl[p].rcl[i-1]|=EDGEFIX; if (!(curclass&EDGEFIX)) { polyl[p].rcl[i]|=EDGESKIP; polyl[p].rcl[i+1]|=EDGEFIX; } break; default : ; } break; case 4 : switch (curclass&CORNCMASK) { case 1 : if (!(polyl[p].rcl[i-1]&EDGEFIX)) { polyl[p].rcl[i-1]|=EDGESKIP; polyl[p].rcl[i]|=EDGEFIX; } break; case 3 : case 11 : polyl[p].rcl[i-1]|=EDGEFIX; polyl[p].rcl[i]|=EDGEFIX; break; case 9 : if (!(curclass&EDGEFIX)) { if (!(polyl[p].rcl[i-1]&EDGEFIX)) { if (i>1) polyl[p].rcl[i-2]|= EDGEFIX; polyl[p].rcl[i-1]|=EDGESKIP; polyl[p].rcl[i]|=EDGESKIP; polyl[p].rcl[i+1]|=EDGEFIX; } else { polyl[p].rcl[i]|=EDGESKIP; polyl[p].rcl[i+1]|=EDGEFIX; } } break; default : ; } break; case 5 : switch (curclass&CORNCMASK) { case 0 : polyl[p].rcl[i-1]|=EDGESKIP; polyl[p].rcl[i]|=EDGEFIX; break; case 8 : if (!(curclass&EDGEFIX)) { if (!(polyl[p].rcl[i-1]&EDGEFIX)) { if (i>1) polyl[p].rcl[i-2]|= EDGEFIX; polyl[p].rcl[i-1]|=EDGESKIP; polyl[p].rcl[i]|=EDGESKIP; polyl[p].rcl[i+1]|=EDGEFIX; } else { polyl[p].rcl[i]|=EDGESKIP; polyl[p].rcl[i+1]|=EDGEFIX; } } break; default : ; } break; case 6 : switch (curclass&CORNCMASK) { case 1 : case 9 : polyl[p].rcl[i-1]|=EDGEFIX; polyl[p].rcl[i]|=EDGEFIX; break; case 3 : if (!(polyl[p].rcl[i-1]&EDGEFIX)) { polyl[p].rcl[i-1]|=EDGESKIP; polyl[p].rcl[i]|=EDGEFIX; } break; case 11 : if (!(curclass&EDGEFIX)) { if (!(polyl[p].rcl[i-1]&EDGEFIX)) { if (i>1) polyl[p].rcl[i-2]|= EDGEFIX; polyl[p].rcl[i-1]|=EDGESKIP; polyl[p].rcl[i]|=EDGESKIP; polyl[p].rcl[i+1]|=EDGEFIX; } else { polyl[p].rcl[i]|=EDGESKIP; polyl[p].rcl[i+1]|=EDGEFIX; } } break; default : ; } break; case 7 : switch (curclass&CORNCMASK) { case 2 : if (!(polyl[p].rcl[i-1]&EDGEFIX) && !(curclass&EDGEFIX)) { if (i>1) polyl[p].rcl[i-2]|=EDGEFIX; polyl[p].rcl[i-1]|=EDGESKIP; } polyl[p].rcl[i]|=EDGEFIX; break; case 10 : if (!(curclass&EDGEFIX)) { if (!(polyl[p].rcl[i-1]&EDGEFIX)) { if (i>1) polyl[p].rcl[i-2]|= EDGEFIX; polyl[p].rcl[i-1]|=EDGESKIP; polyl[p].rcl[i]|=EDGESKIP; polyl[p].rcl[i+1]|=EDGEFIX; } else { polyl[p].rcl[i]|=EDGESKIP; polyl[p].rcl[i+1]|=EDGEFIX; } } break; default : ; } break; case 8 : case 12 : switch (curclass&CORNCMASK) { case 5 : case 13 : if (!(curclass&EDGEFIX)) { if (!(polyl[p].rcl[i-1]&EDGEFIX)) { if (i>1) polyl[p].rcl[i-2]|= EDGEFIX; polyl[p].rcl[i-1]|=EDGESKIP; polyl[p].rcl[i]|=EDGESKIP; polyl[p].rcl[i+1]|=EDGEFIX; } else { polyl[p].rcl[i]|=EDGESKIP; polyl[p].rcl[i+1]|=EDGEFIX; } } break; case 7 : case 15 : polyl[p].rcl[i-1]|=EDGEFIX; polyl[p].rcl[i]|=EDGEFIX; break; default : ; } break; case 9 : case 13 : switch (curclass&CORNCMASK) { case 4 : case 12 : if (!(curclass&EDGEFIX)) { if (!(polyl[p].rcl[i-1]&EDGEFIX)) { if (i>1) polyl[p].rcl[i-2]|= EDGEFIX; polyl[p].rcl[i-1]|=EDGESKIP; polyl[p].rcl[i]|=EDGESKIP; polyl[p].rcl[i+1]|=EDGEFIX; } else { polyl[p].rcl[i]|=EDGESKIP; polyl[p].rcl[i+1]|=EDGEFIX; } } break; default : ; } break; case 10 : case 14 : switch (curclass&CORNCMASK) { case 5 : case 13 : polyl[p].rcl[i-1]|=EDGEFIX; polyl[p].rcl[i]|=EDGEFIX; break; case 7 : case 15 : if (!(curclass&EDGEFIX)) { if (!(polyl[p].rcl[i-1]&EDGEFIX)) { if (i>1) polyl[p].rcl[i-2]|= EDGEFIX; polyl[p].rcl[i-1]|=EDGESKIP; polyl[p].rcl[i]|=EDGESKIP; polyl[p].rcl[i+1]|=EDGEFIX; } else { polyl[p].rcl[i]|=EDGESKIP; polyl[p].rcl[i+1]|=EDGEFIX; } } break; default : ; } break; case 11 : case 15 : switch (curclass&CORNCMASK) { case 6 : case 14 : if (!(curclass&EDGEFIX)) { if (!(polyl[p].rcl[i-1]&EDGEFIX)) { if (i>1) polyl[p].rcl[i-2]|= EDGEFIX; polyl[p].rcl[i-1]|=EDGESKIP; polyl[p].rcl[i]|=EDGESKIP; polyl[p].rcl[i+1]|=EDGEFIX; } else { polyl[p].rcl[i]|=EDGESKIP; polyl[p].rcl[i+1]|=EDGEFIX; } } break; default : ; } break; default : ; } ls=cs>>1; } } // Store right polygon side for (i=pcnt-1;i>0;i--) { if (polyl[p].rcl[i]&EDGESKIP && !(polyl[p].rcl[i]&EDGEFIX)) continue; storegridpoint(polyl[p].rxl[i],polyl[p].ryl[i]); } storegridpoint(polyl[p].rxl[0],polyl[p].ryl[0]); // Create polygon if (scmflag) { scm_storepoly(curptyp); if (cap_lastfigelem(cfig)==0) scm_elemgrpchg(cfig,1); } else { ged_storepoly(curlayer,curptyp,"",0); if (lay_lastfigelem(lfig)==0) ged_elemgrpchg(lfig,1); } // Free polygon polyl[p].next=pfree; pfree=p; // Update the polygon index list for (i=pidx;i<(pn-1);i++) pl[i]=pl[i+1]; pn--; } void storegridpoint(int x,int y) /* // Store transformed polygon point // Parameters : // int x : Point bitmap x coordinate // int y : Point bitmap y coordinate */ { bae_storepoint(basex+x*xfac,basey+y*yfac,0); } int encget() // Read next byte from compressed PCX stream { int res /* Read result */; // Check if buffered repeat character if (enccnt>0) { // Decrement buffer count enccnt--; // Use buffer character return(encbuf); } // Get next character res=fgetc(fh); // Check if repeat request if ((res&0xC0)==0xC0) { // Store repeat count enccnt=res&0x3F; // Get character res=encbuf=fgetc(fh); // Decrement buffer count enccnt--; } return(res); } int readint() // Read 2 byte integer value { return(fgetc(fh)|(fgetc(fh)<<8)); } int readquadint() // Read 4 byte integer value { return(fgetc(fh)|(fgetc(fh)<<8)|(fgetc(fh)<<16)|(fgetc(fh)<<24)); } // User Language program end