⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 import-bmp.ulp

📁 老外的PCB设计软件,是免费的.可以上网更新.
💻 ULP
📖 第 1 页 / 共 2 页
字号:
#usage "<b>Import a bitmap</b>\n"
       "<p>"
       "Import a bitmap into an EAGLE drawing."
       "<p>"
       "<author>Author: support@cadsoft.de</author>"

// THIS PROGRAM IS PROVIDED AS IS AND WITHOUT WARRANTY OF ANY KIND, EXPRESSED OR IMPLIED

         // Builtin variables are used to provide information at runtime.
         // int argc (number of arguments given to the RUN command)
         // string argv[] arguments given to the RUN command
         // (argv[0] is the full ULP file name)

         // String ulp_path no longer necessary
string script_path;
string bmpcolor[];
string bmps[];

string run_info = " ";
string Version = "1.0.2";
string fileName;
int nBytes = 0;                 // count bytes of file (fileName)
int ColorBits = 0;              // used bits for color
int AdrStart, AdrEnd = 0;       // Start & End of BITMAP-Data
int length = 0;                 // length of bmp-Data
int Byte4Group = 0;             // bmp-Data organized as 4-byte groups
int Layer = 200;                // 1st used layer
real xScale = 1;                // scale x
real yScale = 0;                // scale y
int X = 0;                      // count pixels x
int Y = 0;                      // count pixels y
string xy = "";
int colorscan = 0;              // flag for color scanning
int cselmax = 32;               // max 32 colors selectable
int Result = 0;

real Offset  = .5;              // offset Wire width

int mBit[];                     // bit line for operating

string grid[] = { "INCH",        // grid units
                  "MIL",
                  "MM",
                  "MIC"
                };
int unit = 1;                   // default unit = mil
int scaled = 1;                 // flag for DPI Scale Ratio
real vmin[] = { 1, 0.001, 0.001, 0.1 };
real vmax[] = { 30.0, 3000.0, 800.0, 800000.0 } ;

string Grid = grid[unit];          // default grid

   // get parameter PDI, Scale, Aspect Ratio, mic, mm, mil INCH ...
   string menuedlg[] = {
           "<b>D</b>ots <b>P</b>er <b>I</b>NCH",
           "<b>Scale</b> factor for a pixel",
           "Aspect-Ratio <b>m</b>"
           } ;
   string menuval0[] = {
           "&Value between 1 and 10000 dots",
           "&Value between 0.01 and 30.0 Inch",
           "&Value between 0.01 and 30.0 Inch"
           };

   string menuval1[] = {
           "&Value between 1 and 10000 dots",
           "&Value between 0.001 and 3000.0 mil",
           "&Value between 0.001 and 3000.0 mil"
           };
   string menuval2[] = {
           "&Value between 1 and 10000 dots",
           "&Value between 0.0001 and 800.0 mm",
           "&Value between 0.0001 and 800.0 mm"
           };
   string menuval3[] = {
           "&Value between 1 and 10000 dots",
           "&Value between 0.1 and 800000.0 micron",
           "&Value between 0.1 and 800000.0 micron"
           };
string menulbl = menuedlg[1];
string menuinfo = menuval1[1];
string ratiologo ;


// table of used colors in Bitmap
int colorUsed[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
                  };

int colorSelect[] ;
char  c[];                      // the file as Byte-Array

// set / clear all colorUsed flags
void setall(int set) {
   for(int n = 0; n < pow(2, ColorBits); n++) {
       colorUsed[n] = set;
   }
   return;
}

void ScriptLine(int Line) {
   // for(int cs = 0; cs < cselmax; cs++) {          // extract max 32 colors
   for(int cs = 0; cs < ColorBits; cs++) {          // extract max 32 colors
      sprintf(run_info, "%d Line %d Color #%d ", Y, Line, cs);
      dlgRedisplay();
      if(colorSelect[cs] > -1) {                  // -1 color not used
         int lineColor = colorSelect[cs];         // extraction color
         int line = 0;
         printf("change layer %d;\n", Layer + cs);

         for(int z = 0; z < X; z++) {
            if(mBit[z] == lineColor) {           // if color used
               if(line == 0) {                   // start of line in script (rectangle)
                  printf("RECT (%.5f ", (z - Offset) * xScale);
                  printf("%.5f)", (Line - Offset) * yScale);
                  line = 1;
               }
            }
            else {
               if(line == 1) {
                  printf( "(%.5f ", (z - Offset) * xScale);
                  // end of line in script (rectangle)
                  printf( "%.5f);\n", (Line + Offset) * yScale);
                  line = 0;
               }
            }
         }
         if(line == 1) {
            printf( "(%.5f ", (z - Offset) * xScale);
            // end of line in script(rectangle)
            printf( "%.5f);\n", (Line + Offset) * yScale);
            line = 0;
         }
      }
   }
   return;
}

// Generate Script from BitMaP
void GenScript(void) {
   int xByte = 4 * Byte4Group;                      // organised by groups of 4 bytes
   int bmpBits;

   for(int yRead = 0; yRead < Y; yRead++) {         // counter for  lines / Y
      for(int xRead = 0; xRead < xByte; xRead ++) {
         bmpBits = c[AdrStart + yRead * xByte + xRead];

         switch (ColorBits) {
            case  1 :  for(int bitcnt = 7; bitcnt > -1; bitcnt--) {
                          mBit[(xRead * 8) + (7 - bitcnt)] = bmpBits;
                          mBit[(xRead * 8) + (7 - bitcnt)] >>= bitcnt;
                          mBit[(xRead * 8) + (7 - bitcnt)] &= 0X1;
                       }
                       break;

            case  4 :  mBit[xRead * 2 ] = bmpBits;
                       mBit[xRead * 2 + 1] = bmpBits;
                       mBit[xRead * 2 ] >>= 4;
                       mBit[xRead * 2 + 1] &= 0x0f;
                       break;

            case  8 :  mBit[xRead] = bmpBits;
                       break;
         }
      }

      if(colorscan) {
         for(int z = 0; z < X; z++) {
            colorUsed[mBit[z]]++;          // set flag for used color
         }
      }
      else {
         ScriptLine(yRead);                // generate Eagle Script line
      }
   }
   return;
}

// bmp file info
string bmpDaten(void) {                    // diagnostics
   string st = "";
   string cmd = "";
   printf( "Bitmap Start \t = %d\n", AdrStart);
   cmd = st;
   printf( "Bitmap End \t = %d\n", AdrEnd);
   cmd += st;
   printf( "Bitmap length \t = %d\n", length);
   cmd += st;
   printf( "high / pixel - Y \t = %d\n", Y);
   cmd += st;
   printf( "wide / pixel - X \t = %d\n", X);
   cmd += st;
   printf( "4-Byte Group(s) \t = %d\n", Byte4Group);
   cmd += st;
   printf( "Bits / Color \t = %d  (Colors %.0f)\n", ColorBits, pow(2, ColorBits));
   cmd += st;
   printf( "File length \t = %d\n", nBytes);
   cmd += st;
   return cmd;
}

// Select menu for 2 color BITmap
void Cselect2(void) {
   Result = dlgDialog("Select used colors in " + fileName) {
      dlgStretch(0);
      dlgHBoxLayout {
         dlgStretch(0);
         dlgSpacing(3);
         for(int colum = 0 ; colum < 2; colum++) {
            dlgCheckBox("", colorUsed[colum]);
         }
         dlgSpacing(6);
         dlgStretch(1);
      }
      dlgHBoxLayout {
         dlgSpacing(3);
         dlgStretch(0);
         dlgLabel("<img src=import-bmp-c2.bmp>");
         dlgStretch(1);   // stretch bottom
      }
      dlgStretch(0);
      dlgSpacing(20);
      dlgLabel("<b> Select up to 2 colors </b>");
      dlgStretch(0);
      dlgHBoxLayout {
         dlgStretch(0);
         dlgPushButton("+OK") dlgAccept();
         dlgStretch(0);
         dlgPushButton("-ESC") dlgReject();
         dlgStretch(1);
         dlgPushButton("&Set all") setall(1);
         dlgStretch(0);
         dlgPushButton("&Clear all") setall(0);
         dlgStretch(0);
      }
      dlgStretch(1);
   };
   if (Result == 0) exit (0);
   return;
}

// Select menu for 16 color BITmap
void Cselect16(void) {
   Result = dlgDialog("Select used colors" + fileName) {
      dlgStretch(0);
      dlgHBoxLayout {
         dlgStretch(0);
         dlgSpacing(3);
         for(int colum = 0 ; colum < 16; colum++) {
            dlgCheckBox("", colorUsed[colum]);
         }
         dlgSpacing(6);
         dlgStretch(1);
      }
      dlgHBoxLayout {
         dlgSpacing(3);
         dlgStretch(0);
         dlgLabel("<img src=import-bmp-c16.bmp>");
         dlgStretch(1);          // stretch bottom
      }
      dlgStretch(0);
      dlgSpacing(20);
      dlgLabel("<b> Select up to 16 colors </b>");
      dlgStretch(0);
      dlgHBoxLayout {
         dlgStretch(0);
         dlgPushButton("+OK") dlgAccept();
         dlgStretch(0);
         dlgPushButton("-ESC") dlgReject();
         dlgStretch(1);
         dlgPushButton("&set all") { setall(1); dlgRedisplay();}
         dlgStretch(0);
         dlgPushButton("&clear all") { setall(0); dlgRedisplay();}
         dlgStretch(0);
      }
      dlgStretch(1);
   };
   if (Result == 0) exit (0);
   return;
}

// Select menu for 256 color BITmap
void Cselect256(void) {
//   dlgMessageBox("please be patient\nif you have a slow computer!", "OK");

   Result = dlgDialog("Select used colors " + fileName) {
      dlgVBoxLayout {
         dlgStretch(0);
         // ********* 550 DO NOT CHANGE THIS VALUE *********
         dlgHBoxLayout dlgSpacing(550);
         // ********* 550 DO NOT CHANGE THIS VALUE *********
         dlgStretch(0);
         for(int row = 0 ; row < 8; row++) {
            dlgHBoxLayout {
               dlgVBoxLayout {
                  dlgStretch(0);
                  dlgHBoxLayout {
                     dlgStretch(0);
                     dlgSpacing(3);
                     for(int colum = 0 ; colum < 32; colum++) {
                        dlgCheckBox("", colorUsed[row * 32 + colum]);
                     }
                     dlgSpacing(6);
                     dlgStretch(1);
                  }
                  dlgHBoxLayout {
                     dlgSpacing(3);
                     dlgStretch(0);
                     dlgLabel(bmps[row]);
                     dlgStretch(1);
                  }
               }
               dlgStretch(1);   // stretch right
            }
            dlgStretch(1);   // stretch bottom
         }
         dlgStretch(1);
      }
      dlgStretch(0);
      dlgVBoxLayout {
         dlgStretch(0);
         dlgSpacing(20);
         string hc;
         sprintf( hc, "<b> Select up to %d colors </b>", cselmax);
         dlgLabel(hc);
         dlgStretch(0);
         dlgHBoxLayout {
            dlgStretch(0);
            dlgPushButton("+OK") dlgAccept();
            dlgStretch(0);
            dlgPushButton("-ESC") dlgReject();
            dlgStretch(1);
            dlgPushButton("&set all") setall(1);
            dlgStretch(0);
            dlgPushButton("&clear all") setall(0);
            dlgStretch(0);
         }
         dlgStretch(1);
      }
      dlgStretch(1);
   };
   if (Result == 0) exit (0);
   return;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -