Advertisement
Guest User

Untitled

a guest
May 30th, 2017
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. xed=640:yed=400:wdwd=1:ratio$="pal":delaysec=2
  2. setdisplay(xed,yed,32,wdwd):paper(0xFFFFFF):ink(0):cls
  3.  
  4. '- c64 hires picture converter (webcam capture) - sdlBasic version - Paulo Silva - june'10 - (converter started august'02) - GPL licence
  5. '- only tested on Ubuntu Linux - terminal command line below install needed packages (Ubuntu and Debian):
  6. '-   sudo apt-get install sdlbrt imagemagick fswebcam sdlbasic
  7.  
  8. dim cr[40,25,16],mt[40,25],cmu[16],ag[40,25,4],iklv[16],colourid[16],colourid2[16],pke[16384]
  9. ' cr[,,] - ammount of pixels from each colour in each attribute
  10. ' mt[,]  - ammount of colours in each attribute
  11. ' cmu[]  - ammount of attributes with 4 colours or more which each colour belongs
  12. ' cnt    - most used colour in attributes with 4 colours or more
  13. ' ag[,,] - attributes
  14.  
  15. colourid[0]=0x000:colourid[1]=0xFFF:colourid[2]=0x931:colourid[3]=0x5BD
  16. colourid[4]=0x93C:colourid[5]=0x4A1:colourid[6]=0x32C:colourid[7]=0xBD3
  17. colourid[8]=0x950:colourid[9]=0x440:colourid[10]=0xC64:colourid[11]=0x444
  18. colourid[12]=0x777:colourid[13]=0x8E5:colourid[14]=0x75F:colourid[15]=0x999
  19.  
  20. for i=0 to 15
  21.   u=colourid[i]
  22.   rlv=(int(u/256))
  23.   glv=bitwiseand((int(u/16)),15)
  24.   blv=bitwiseand(u,15)
  25.   iklv[i]=((blv*11)+(glv*59)+(rlv*30))/15
  26.   next
  27. for i=0 to 15
  28.   u=colourid[i]
  29.   rlv=(int(u/256))
  30.   glv=bitwiseand((int(u/16)),15)
  31.   blv=bitwiseand(u,15)
  32.   colourid2[i]=(int((rlv/15)*255))*65536+(int((glv/15)*255))*256+(int((blv/15)*255))
  33.   next
  34.  
  35. while 0=0
  36.  
  37. setcaption("webcam - ratio: "+ratio$)
  38. finp$="_tmpr2.jpg"
  39. shell("fswebcam -d /dev/video0 _tmpr1.jpg")
  40.  
  41. if ratio$="normal" then:
  42.   shell("convert _tmpr1.jpg -resize 320x200\\! "+finp$)
  43.   loadimage(finp$,1):pasteicon(0,0,1)
  44.   end if
  45. if ratio$="pal" then:
  46.   shell("convert _tmpr1.jpg -resize 320x256\\! "+finp$)
  47.   loadimage(finp$,1):pasteicon(0,-28,1)
  48.   end if
  49. if ratio$="ntsc" then:
  50.   shell("convert _tmpr1.jpg -resize 320x214\\! _tmpr2.jpg")
  51.   loadimage(finp$,1):pasteicon(0,-7,1)
  52.   end if
  53.  
  54. ' ----- step 1
  55. ' ----- counts ammount of pixels from each colour from each attribute
  56. for y1=0 to 24
  57.   setcaption("step 1: "+str$(y1)+"/24     ")
  58.   for x1=0 to 39
  59.     for y2=0 to 7:for x2=0 to 7
  60.       x=x2+(x1*8)
  61.       y=y2+(y1*8)
  62.  
  63.       u2=point(x,y)
  64.       u=0:dis=1000
  65.       for i=0 to 15
  66.         qq=colourid[i]
  67.         blv=qq mod 16:qq=int(qq/16)
  68.         glv=qq mod 16:qq=int(qq/16)
  69.         rlv=qq mod 16
  70.         qq=u2
  71.         blv2=int(qq/16) mod 16:qq=int(qq/256)
  72.         glv2=int(qq/16) mod 16:qq=int(qq/256)
  73.         rlv2=int(qq/16) mod 16
  74.         bdist=abs(blv-blv2)
  75.         gdist=abs(glv-glv2)
  76.         rdist=abs(rlv-rlv2)
  77.         rgbdist=sqr((rdist^2)+(gdist^2)+(bdist^2))
  78.         if rgbdist<dis then:dis=rgbdist:u=i:end if
  79.         next
  80.  
  81.       cr[x1,y1,u]=cr[x1,y1,u]+1
  82.       next:next:next:next
  83.  
  84. ' ----- step 2
  85. ' ----- counts ammount of colours in each attribute
  86. for y1=0 to 24
  87.   setcaption("step 2: "+str$(y1)+"/24     ")
  88.   for x1=0 to 39
  89.     es=0
  90.     for e=0 to 15
  91.       if cr[x1,y1,e]<>0 then:es=es+1:end if
  92.       next
  93.     mt[x1,y1]=es
  94.     next:next
  95.  
  96. ' ----- step 3
  97. ' ----- counts the most used colours in attributes with 2 colours or more
  98. for y1=0 to 24
  99.   setcaption("step 3: "+str$(y1)+"/24     ")
  100.   for x1=0 to 39
  101.     if mt[x1,y1]>=2 then
  102.       for e=0 to 15
  103.         if cr[x1,y1,e]>0 then:cmu[e]=cmu[e]+1:end if
  104.         next
  105.       end if
  106.     next:next
  107.  
  108. ' ----- step 4
  109. ' ----- sets index from 1 to 2 from each attribute with remaining colours
  110. for y1=0 to 24
  111.   setcaption("step 4: "+str$(y1)+"/24")
  112.   for x1=0 to 39
  113.     for g=1 to 2
  114.       mx=0:ct=0
  115.       for e=0 to 15
  116.         if cr[x1,y1,e]>mx then:ct=e : mx=cr[x1,y1,e]: end if
  117.         next
  118.       cr[x1,y1,ct]=0:ag[x1,y1,g]=ct
  119.       next:next:next
  120.  
  121. ' ----- step 5
  122. ' ----- clears the value 16 created from the step above (becomes background0)  
  123. for y1=0 to 24
  124.   setcaption("step 5: "+str$(y1)+"/24")
  125.   for x1=0 to 39
  126.     for g=1 to 2
  127.       if ag[x1,y1,g]>15 then:ag[x1,y1,g]=ag[0,0,0]:end if
  128.    next:next:next
  129.  
  130. ' ----- step 6
  131. ' ----- i can't remember...
  132. ink (colourid2[ag[0,0,0]]):bar(320,0,639,199)
  133. for y1=0 to 24
  134.   setcaption("step 6: "+str$(y1)+"/24")
  135.   for x1=0 to 39
  136.     for e=1 to 2
  137.       ink (colourid2[ag[x1,y1,e]])
  138.       px=320+(x1*8)+1
  139.       py=(y1*8)+((e-1)*2)+1
  140.       bar(px,py,px+5,py+1)
  141.       next:next:next
  142.  
  143. ' ----- step 7
  144. ' ----- i can't remember... (binaries?)
  145. ink (colourid2[ag[0,0,0]]):bar(0,200,319,399)
  146. for y1=0 to 24
  147.   setcaption("step 7: "+str$(y1)+"/24")
  148.   for x1=0 to 39
  149.     kv1=iklv[ag[x1,y1,1]]:kv2=iklv[ag[x1,y1,2]]
  150.     ink (colourid2[ag[x1,y1,1]])
  151.     for y2=0 to 7
  152.       vac=0
  153.       for x2=0 to 7
  154.         x=(x1*8)+x2
  155.         y=(y1*8)+y2
  156.  
  157.         u2=point(x,y)
  158.         u=0:dis=1000
  159.         for i=0 to 15
  160.           qq=colourid[i]
  161.           blv=qq mod 16:qq=int(qq/16)
  162.           glv=qq mod 16:qq=int(qq/16)
  163.           rlv=qq mod 16
  164.           qq=u2
  165.           blv2=int(qq/16) mod 16:qq=int(qq/256)
  166.           glv2=int(qq/16) mod 16:qq=int(qq/256)
  167.           rlv2=int(qq/16) mod 16
  168.           bdist=abs(blv-blv2)
  169.           gdist=abs(glv-glv2)
  170.           rdist=abs(rlv-rlv2)
  171.           rgbdist=sqr((rdist^2)+(gdist^2)+(bdist^2))
  172.           if rgbdist<dis then:dis=rgbdist:u=i:end if
  173.           next
  174.  
  175.         kvv=iklv[u]
  176.         ink (colourid2[ag[x1,y1,1]]):dot(x,y+200)
  177.         ink (colourid2[0]):dot(x+320,y+200)
  178.         if abs(kv2-kvv)<abs(kv1-kvv) then:
  179.           ink(colourid2[ag[x1,y1,2]]):dot(x,y+200)
  180.           ink(colourid2[1]):dot(x+320,y+200)
  181.           vac=vac+(2^(7-x2))
  182.           end if
  183.       next
  184.       adrp=0+2+y2+(x1*8)+(y1*320): pke[adrp]=vac
  185. next:next:next
  186.  
  187. ' ----- step 8
  188. ' ----- i can't remember... (binaries?)
  189. for y1=0 to 24
  190.   setcaption("step 8: "+str$(y1)+"/24")
  191.   for x1=0 to 39
  192.     adrp=0+x1+(y1*40)
  193.     pke[adrp+8002]=((ag[x1,y1,2])*16)+ag[x1,y1,1]
  194.     next:next
  195.   pke[0+9002]=0:pke[0+9003]=ag[0,0,0]
  196.   pke[0+0]=0:pke[0+1]=32
  197.  
  198. ' ----- step 9
  199. ' ----- saving
  200.   setcaption("step 9: saving...")
  201. open finp$+".hpic" for output as #1
  202.   for i=0 to 9009
  203.     writebyte(1,pke[i])
  204.     next
  205.   close #1
  206.  
  207. grab (1,0,200,320,200):saveimage(finp$+"_.bmp",1)
  208. shell("convert "+finp$+"_.bmp"+" "+finp$+"_.png"):shell("rm "+finp$+"_.bmp")
  209.  
  210. setcaption("wait 2 secs...")
  211. wait(2000)
  212.  
  213. wend
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement