Advertisement
Guest User

CgaArtifact160x200_halftone_picturefilter_03.sdlbas

a guest
May 7th, 2019
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #! /usr/bin/sdlbrt
  2. finp$="q2_49474899_1769271099846253_8522749926122192896_n.jpg"
  3. if argc>=3 then:finp$=command$(3):end if
  4.  
  5. dim dpvl[8]
  6. function hexvl(a$)
  7.    e=asc(ucase$(a$))
  8.    hexvl=abs(((e>=48 and e<=57)*(e-48))+((e>=65 and e<=70)*(e-55)))
  9.  end function
  10. sub hexvpr(a$)
  11.      lngta=len(a$):i=1
  12.   while i<=lngta
  13.      m1$=mid$(a$,i,1):m2$=mid$(a$,i+1,1)
  14.      b=(hexvl(m1$)*16)+hexvl(m2$):WriteByte(1,b):i+=2
  15.    end while
  16.  end sub
  17. function bthx$(a)
  18.   b$="00"+hex$(a):bthx$=right$(b$,2)
  19.  end function
  20.  
  21. shell("rm _t9.gif _tmp_.png")
  22. shell("convert -size 64x4 xc:#020002 _tmp_.png")
  23. shell("convert _tmp_.png -stroke none -fill '#00680C' -draw 'rectangle 4,0 64,64' _tmp_.png")
  24. shell("convert _tmp_.png -stroke none -fill '#212BBD' -draw 'rectangle 8,0 64,64' _tmp_.png")
  25. shell("convert _tmp_.png -stroke none -fill '#0D9ED5' -draw 'rectangle 12,0 64,64' _tmp_.png")
  26. shell("convert _tmp_.png -stroke none -fill '#85096C' -draw 'rectangle 16,0 64,64' _tmp_.png")
  27. shell("convert _tmp_.png -stroke none -fill '#757376' -draw 'rectangle 20,0 64,64' _tmp_.png")
  28. shell("convert _tmp_.png -stroke none -fill '#AF36FF' -draw 'rectangle 24,0 64,64' _tmp_.png")
  29. shell("convert _tmp_.png -stroke none -fill '#9BA9FF' -draw 'rectangle 28,0 64,64' _tmp_.png")
  30. shell("convert _tmp_.png -stroke none -fill '#514700' -draw 'rectangle 32,0 64,64' _tmp_.png")
  31. shell("convert _tmp_.png -stroke none -fill '#42BD00' -draw 'rectangle 36,0 64,64' _tmp_.png")
  32. shell("convert _tmp_.png -stroke none -fill '#707470' -draw 'rectangle 40,0 64,64' _tmp_.png")
  33. shell("convert _tmp_.png -stroke none -fill '#5DF47A' -draw 'rectangle 44,0 64,64' _tmp_.png")
  34. shell("convert _tmp_.png -stroke none -fill '#E5541D' -draw 'rectangle 48,0 64,64' _tmp_.png")
  35. shell("convert _tmp_.png -stroke none -fill '#D7CB19' -draw 'rectangle 52,0 64,64' _tmp_.png")
  36. shell("convert _tmp_.png -stroke none -fill '#FF81F2' -draw 'rectangle 56,0 64,64' _tmp_.png")
  37. shell("convert _tmp_.png -stroke none -fill '#FDFFFC' -draw 'rectangle 60,0 64,64' _tmp_.png")
  38. shell("convert _tmp_.png _t9.gif")
  39. shell("rm _tmp_.png")
  40.  
  41. clstr=0 '- 0..3
  42. xed=160:yed=200:wdwd=1
  43. shell("rm _t*.png")
  44. shell("convert "+finp$+" -scale "+str$(xed*4)+"x"+str$(yed*4)+"! _t2.png")
  45. shell("convert "+finp$+" +dither -colors 16 _t4.png")
  46. shell("convert _t4.png +dither -posterize 8 _t5.png")
  47. shell("convert _t5.png +dither -colors 16 _t6.png")
  48. 'shell("convert _t2.png -quantize CMY -remap _t6.png -dither Riemersma _t3.png")
  49. shell("convert _t2.png -quantize CMY -remap _t9.gif -dither Riemersma _t3.png")
  50. shell("convert _t3.png -unique-colors -scale 400% _t4.png")
  51.  
  52. setdisplay(xed*4,yed*4,32,wdwd):paper(8^8-1):ink(0):pen(0):cls
  53. loadimage("_t3.png",1):pasteicon(0,0,1)
  54.  
  55. dim p1[16],k1[16]
  56.  
  57. function grayscale(ct):
  58.   cq=ct
  59.   bq=bitwiseand(cq,255):cq=int(cq/256)
  60.   gq=bitwiseand(cq,255):cq=int(cq/256)
  61.   rq=bitwiseand(cq,255):cq=int(cq/256)
  62.   return int(((rq*30)+(gq*59)+(bq*11))/100)
  63.   end function
  64.  
  65. for y2=0 to yed-1
  66.   setcaption(str$(int(100*(y2/yed)))+"%")
  67.   for x2=0 to xed-1
  68.     for y1=0 to 3:for x1=0 to 3
  69.       xq=y1*4+x1
  70.       p1[xq]=point(x2*4+x1,y2*4+y1)
  71.       next:next
  72.     for i=0 to 15
  73.       k1[i]=grayscale(p1[i])
  74.       next
  75.     for j=0 to 14:for i=0 to 14
  76.       if k1[i]>k1[i+1] then:
  77.         tm=k1[i]:k1[i]=k1[i+1]:k1[i+1]=tm
  78.         tm=p1[i]:p1[i]=p1[i+1]:p1[i+1]=tm
  79.         end if
  80.       next:next
  81.  
  82.     if clstr=0 then:
  83.     ink(p1[ 0]):dot(x2*4+0,y2*4+0)
  84.     ink(p1[ 6]):dot(x2*4+1,y2*4+0)
  85.     ink(p1[ 9]):dot(x2*4+2,y2*4+0)
  86.     ink(p1[15]):dot(x2*4+3,y2*4+0)
  87.     ink(p1[ 4]):dot(x2*4+0,y2*4+1)
  88.     ink(p1[10]):dot(x2*4+1,y2*4+1)
  89.     ink(p1[ 3]):dot(x2*4+2,y2*4+1)
  90.     ink(p1[13]):dot(x2*4+3,y2*4+1)
  91.     ink(p1[ 8]):dot(x2*4+0,y2*4+2)
  92.     ink(p1[14]):dot(x2*4+1,y2*4+2)
  93.     ink(p1[ 1]):dot(x2*4+2,y2*4+2)
  94.     ink(p1[ 7]):dot(x2*4+3,y2*4+2)
  95.     ink(p1[ 2]):dot(x2*4+0,y2*4+3)
  96.     ink(p1[12]):dot(x2*4+1,y2*4+3)
  97.     ink(p1[ 5]):dot(x2*4+2,y2*4+3)
  98.     ink(p1[11]):dot(x2*4+3,y2*4+3)
  99.     end if
  100.  
  101.     if clstr=1 then:
  102.     ink(p1[ 0]):dot(x2*4+0,y2*4+0)
  103.     ink(p1[ 4]):dot(x2*4+1,y2*4+0)
  104.     ink(p1[ 8]):dot(x2*4+2,y2*4+0)
  105.     ink(p1[12]):dot(x2*4+3,y2*4+0)
  106.     ink(p1[10]):dot(x2*4+0,y2*4+1)
  107.     ink(p1[14]):dot(x2*4+1,y2*4+1)
  108.     ink(p1[ 2]):dot(x2*4+2,y2*4+1)
  109.     ink(p1[ 6]):dot(x2*4+3,y2*4+1)
  110.     ink(p1[ 1]):dot(x2*4+0,y2*4+2)
  111.     ink(p1[ 5]):dot(x2*4+1,y2*4+2)
  112.     ink(p1[ 9]):dot(x2*4+2,y2*4+2)
  113.     ink(p1[13]):dot(x2*4+3,y2*4+2)
  114.     ink(p1[11]):dot(x2*4+0,y2*4+3)
  115.     ink(p1[15]):dot(x2*4+1,y2*4+3)
  116.     ink(p1[ 3]):dot(x2*4+2,y2*4+3)
  117.     ink(p1[ 7]):dot(x2*4+3,y2*4+3)
  118.     end if
  119.  
  120.     if clstr=2 then:
  121.     ink(p1[ 0]):dot(x2*4+0,y2*4+0)
  122.     ink(p1[10]):dot(x2*4+1,y2*4+0)
  123.     ink(p1[ 1]):dot(x2*4+2,y2*4+0)
  124.     ink(p1[11]):dot(x2*4+3,y2*4+0)
  125.     ink(p1[ 4]):dot(x2*4+0,y2*4+1)
  126.     ink(p1[14]):dot(x2*4+1,y2*4+1)
  127.     ink(p1[ 5]):dot(x2*4+2,y2*4+1)
  128.     ink(p1[15]):dot(x2*4+3,y2*4+1)
  129.     ink(p1[ 8]):dot(x2*4+0,y2*4+2)
  130.     ink(p1[ 2]):dot(x2*4+1,y2*4+2)
  131.     ink(p1[ 9]):dot(x2*4+2,y2*4+2)
  132.     ink(p1[ 3]):dot(x2*4+3,y2*4+2)
  133.     ink(p1[12]):dot(x2*4+0,y2*4+3)
  134.     ink(p1[ 6]):dot(x2*4+1,y2*4+3)
  135.     ink(p1[13]):dot(x2*4+2,y2*4+3)
  136.     ink(p1[ 7]):dot(x2*4+3,y2*4+3)
  137.     end if
  138.  
  139.     if clstr=3 then:
  140.     ink(p1[ 0]):dot(x2*4+0,y2*4+0)
  141.     ink(p1[12]):dot(x2*4+1,y2*4+0)
  142.     ink(p1[ 3]):dot(x2*4+2,y2*4+0)
  143.     ink(p1[15]):dot(x2*4+3,y2*4+0)
  144.     ink(p1[ 8]):dot(x2*4+0,y2*4+1)
  145.     ink(p1[ 4]):dot(x2*4+1,y2*4+1)
  146.     ink(p1[11]):dot(x2*4+2,y2*4+1)
  147.     ink(p1[ 7]):dot(x2*4+3,y2*4+1)
  148.     ink(p1[ 2]):dot(x2*4+0,y2*4+2)
  149.     ink(p1[14]):dot(x2*4+1,y2*4+2)
  150.     ink(p1[ 1]):dot(x2*4+2,y2*4+2)
  151.     ink(p1[13]):dot(x2*4+3,y2*4+2)
  152.     ink(p1[10]):dot(x2*4+0,y2*4+3)
  153.     ink(p1[ 6]):dot(x2*4+1,y2*4+3)
  154.     ink(p1[ 9]):dot(x2*4+2,y2*4+3)
  155.     ink(p1[ 5]):dot(x2*4+3,y2*4+3)
  156.     end if
  157.  
  158.     x1=x2 mod 4:y1=y2 mod 4
  159.     u=point(x2*4+x1,y2*4+y1)
  160.     ink(u):dot(x2,y2)
  161.     next:next
  162.  
  163. loadimage("_t9.gif",1):pasteicon(xed,0,1)
  164. shell("rm _t*.png _t*.gif")
  165.  
  166. '-------------------------------------------------------------------------------
  167.  
  168. for y2=0 to yed-1
  169.   setcaption(str$(int(100*(y2/yed)))+"%")
  170.   for x2=0 to xed-1
  171.     u=point(x2,y2)
  172.     for c2=15 to 0 step -1
  173.       cp=point(xed+c2*4,0)
  174.       if (u=cp) then:
  175.  
  176.         ink(0x000000)
  177.         if bitwiseand(c2,1)<>0 then:ink(0xFFFFFF):end if
  178.         dot(0+(x2*4),yed+y2)
  179.  
  180.         ink(0x000000)
  181.         if bitwiseand(c2,2)<>0 then:ink(0xFFFFFF):end if
  182.         dot(1+(x2*4),yed+y2)
  183.  
  184.         ink(0x000000)
  185.         if bitwiseand(c2,4)<>0 then:ink(0xFFFFFF):end if
  186.         dot(2+(x2*4),yed+y2)
  187.  
  188.         ink(0x000000)
  189.         if bitwiseand(c2,8)<>0 then:ink(0xFFFFFF):end if
  190.         dot(3+(x2*4),yed+y2)
  191.  
  192.         end if
  193.       next
  194.     next:next
  195.  
  196. '-------------------------------------------------------------------------------
  197.  
  198. grab(1,0,0,xed,yed):saveimage("_.bmp",1):shell("convert _.bmp "+finp$+".png && rm _.bmp" )
  199.  
  200. grab(1,0,yed,xed*4,yed)
  201. saveimage("_.bmp",1)
  202. shell("convert _.bmp "+finp$+"_cga_artifact.png")
  203. shell("convert _.bmp -colors 2 -compress None "+finp$+"_cga_artifact.ilbm")
  204. shell("rm _.bmp" )
  205.  
  206. waitkey
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement