|
Author |
Topic: AIExport corruption (Read 267 times) |
|
st33d
|
AIExport corruption
« on: Nov 28th, 2004, 11:06pm » |
|
I wrote a program that would hunt down lines that could exist in a black and white bitmap image and then report it as an illustrator file. The problem is that any image above 49x49 pixels gets corrupted. I thought that it might be the continuous export function that might be causing the corruption by being accessed a billion times so I wrote a memory object with dynamic arrays in it to store the output and then run it through the exportOneFrame function. But all that does is export a blank file. The corruption takes form in a mass of erroneous lines on the left hand side of the image. I know there's nothing wrong with my code because I wrote a web demo to prove to myself I hadn't written it wrong and to explain it to my tutors. See here: http://www.st33d.net/processing/vector.html Can anyone get this code to export a clean file? Is it just my computer that's doing it? It also seems to report exporting a file of some thousand lines for what the memory object tells me is only 420 lines. I greatly appreciate any enlightenment. Here's the code for the memory object vectoriser. Unreminder the ai.toggleContinuousRecording(); and reminder exportOneFrame to get it to work as it does normally. Code: int w=50; //width of display int h=50; //height of display AIExport ai; dstore[] pix = new dstore[w*h]; memory mem = new memory (1,1,2,2); int i; void setup(){ for (int ip=0;ip<w*h;ip++){ pix[ip] = new dstore(); } i=0; size (w,h); background (255); BImage scan = loadImage ("self.gif"); //image to be scanned (place in data folder, must be a .gif) image (scan,0,0); ai = new AIExport( this, 1 ); //ai.toggleContinuousRecording(); //ai.turnTransparencyOff(); //ai.setLineWeight( 0.25 ); ai.ai_stroke( 0,0,255 ); // fill(0); // rect(0,0,10,10); // testing square for bugs } void loop(){ ai.run(); if (i<pixels.length){ if (pixels[i]!=#FFFFFF){escan(i);} println(pixels.length-i); i++; } if (i==pixels.length){ for (int j = 0; j < mem.x1.length; j++){ ai.ai_line (mem.x1[j],mem.y1[j],mem.x2[j],mem.y2[j]); }//for; //ai.toggleContinuousRecording(); ai.exportOneFrame(); i++; println("done with "+mem.x1.length+" lines"); } }//loop; void escan(int pt){ int x1=(pt)%width; int y1=pt/width; for (int d=0; d<4; d++){ int x2=x1; int y2=y1; pix[x2+y2*width].d[d]=true; while ((d==0) && (x2<width-1) && (pixels[(x2+1)+y2*width]!=#FFFFFF) && !(pix[(x2+1)+y2*width].d[d])){x2++;pix[x2+y2*width].d[d]=true;} while ((d==1) && (x2<width-1) && (y2<height-1) && (pixels[(x2+1)+(y2+1)*width]!=#FFFFFF) && !(pix[(x2+1)+(y2+1)*width].d[d])){x2++; y2++;pix[x2+y2*width].d[d]=true;} while ((d==2) && (y2<height-1) && (pixels[x2+(y2+1)*width]!=#FFFFFF) && !(pix[x2+(y2+1)*width].d[d])){y2++;pix[x2+y2*width].d[d]=true;} while ((d==3) && (x2>0) && (y2<height-1) && (pixels[(x2-1)+(y2+1)*width]!=#FFFFFF) && !(pix[(x2-1)+(y2+1)*width].d[d])){x2--; y2++;pix[x2+y2*width].d[d]=true;} if (x2 != x1 || y2 != y1) { mem.stack(x1,y1,x2,y2); } }//for; }//escan; class dstore{ boolean [] d=new boolean [4]; dstore (){ for (int id=0;id<4;id++){ d[id]=false; } }//dstore; }//class; class memory{ int [] x1=new int[1]; int [] y1=new int[1]; int [] x2=new int[1]; int [] y2=new int[1]; memory (int x1t,int y1t,int x2t,int y2t){ x1[0]=x1t; y1[0]=x1t; x2[0]=x2t; y2[0]=x2t; } void stack (int xa, int ya, int xb, int yb){ int[] tempx1 = new int[x1.length + 1]; System.arraycopy(x1, 0, tempx1, 0, x1.length); tempx1[x1.length] = x1[x1.length-1]; x1 = tempx1; int[] tempy1 = new int[y1.length + 1]; System.arraycopy(y1, 0, tempy1, 0, y1.length); tempy1[y1.length] = y1[y1.length-1]; y1 = tempy1; int[] tempx2 = new int[x2.length + 1]; System.arraycopy(x2, 0, tempx2, 0, x2.length); tempx2[x2.length] = x2[x2.length-1]; x2 = tempx2; int[] tempy2 = new int[y2.length + 1]; System.arraycopy(y2, 0, tempy2, 0, y2.length); tempy2[y2.length] = y2[y2.length-1]; y2 = tempy2; x1[x1.length-1]=xa; y1[y1.length-1]=ya; x2[x2.length-1]=xb; y2[y2.length-1]=yb; }//stack; }//class memory; |
|
|
I could murder a pint.
|
|
|
|