Guest User

pixeltracer02.sdlbas

a guest
Mar 19th, 2011
159
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #! /usr/bin/sdlBrt
  2. finp$="picture.png"
  3. shell("convert "+finp$+" _.png")
  4. xed=0:yed=0:open "_.png" for input as #1:for i=1 to 16:n=readbyte(1):next:for i=1 to 2:n=readbyte(1):next
  5. xed=readbyte(1)*256:xed=xed+readbyte(1):for i=1 to 2:n=readbyte(1):next:yed=readbyte(1)*256:yed=yed+readbyte(1)
  6. close #1:shell("rm _.png")
  7. setdisplay(xed,yed,32,1):paper(8^8-1):ink(0):pen(0):cls
  8. loadimage(finp$,1):pasteicon(0,0,1):fout$=finp$+".svg":pixid=0
  9. open fout$ for output as #1
  10.   print #1,"<?xml version=\"1.0\" standalone=\"no\"?>"
  11.   print #1,"<svg width=\""+str$(xed)+"\" height=\""+str$(yed)+"\" id=\"svg2\" version=\"1.0\">"
  12.   ypos=0:xpos=0:sqflg=0:sqflgs=0:sqsz=0:shpid=0
  13.   while(ypos<yed):
  14.     u=point(xpos,ypos) mod 256
  15.     if u<128 then:
  16.       sqsz=0:sqflg=1
  17.       while sqflgs=0
  18.         sqsz+=1
  19.         for y2=ypos to ypos+sqsz-1
  20.           u=point(xpos+sqsz-1,y2) mod 256
  21.           if u>=128 or (xpos+sqsz-1)>=xed then:sqflgs=1:end if
  22.           next
  23.         for x2=xpos to xpos+sqsz-1
  24.           u=point(x2,ypos+sqsz-1) mod 256
  25.           if u>=128 or (ypos+sqsz-1)>=yed then:sqflgs=1:end if
  26.           next
  27.         wend
  28.       sqsz-=1
  29.       print #1,"<path id=\""+str$(shpid)+"\" style=\"fill:#000000;stroke:none;opacity:1\""
  30.       print #1,"d=\"M "+str$(xpos)+","+str$(ypos)+" l "+str$(sqsz)+",0 l 0,"+str$(sqsz)+" l -"+str$(sqsz)+",0 l 0,-"+str$(sqsz)+" z\"/>"
  31.       ink(0x88FFFF):bar(xpos,ypos,xpos+sqsz-1,ypos+sqsz-1)
  32.       xpos+=sqsz
  33.       shpid+=1
  34.       sqflg=0:sqflgs=0:sqsz=0
  35.     else
  36.       xpos+=1
  37.       end if
  38.     if xpos>=xed then: xpos=0:ypos+=1:end if
  39.     wend
  40.   print #1,"</svg>":close #1
RAW Paste Data