Advertisement
Guest User

MasterSystem_halftone_picturefilter_palettebelowpicture_256x

a guest
Jan 13th, 2019
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #! /usr/bin/sdlbrt
  2. finp$="xfs/Xevious_Fardraut_Saga_MSX2_box_front_3.png"
  3. if argc>=3 then:finp$=command$(3):end if
  4.  
  5. quant1=16 '- default is 4, more needed if the result is smaller than 4
  6.  
  7.  
  8. dim dpvl[8]
  9. clstr=0 '- 0..3
  10. xed=256:yed=192:wdwd=1
  11. shell("rm _t*.png")
  12.  
  13. shell("convert "+finp$+" -crop 256x192+0+0 _t1a.png")
  14.  
  15. 'shell("convert "+finp$+" -scale "+str$(xed*4)+"x"+str$(yed*4)+"! _t2.png")
  16. 'shell("convert "+finp$+" +dither -colors "+str$(quant1)+" _t4.png")
  17.  
  18. shell("convert _t1a.png -scale "+str$(xed*4)+"x"+str$(yed*4)+"! _t2.png")
  19. shell("convert _t1a.png +dither -colors "+str$(quant1)+" _t4.png")
  20.  
  21. shell("convert _t4.png +dither -posterize 4 _t5.png")
  22. shell("convert _t5.png +dither -colors 4 _t6.png")
  23.  
  24. shell("convert "+finp$+" -crop 32x8+0+192 _t9a.png")
  25. shell("convert _t9a.png +dither -colors 4 _t9b.png")
  26.  
  27. 'shell("convert _t2.png -quantize CMY -remap _t6.png -dither Riemersma _t3.png")
  28. shell("convert _t2.png -quantize CMY -remap _t9b.png -dither Riemersma _t3.png")
  29. shell("convert _t3.png -unique-colors -scale 400% _t4.png")
  30.  
  31.  
  32. setdisplay(xed*4,yed*4,32,wdwd):paper(8^8-1):ink(0):pen(0):cls
  33. loadimage("_t3.png",1):pasteicon(0,0,1)
  34.  
  35.  
  36. dim p1[16],k1[16]
  37.  
  38. function grayscale(ct):
  39.   cq=ct
  40.   bq=bitwiseand(cq,255):cq=int(cq/256)
  41.   gq=bitwiseand(cq,255):cq=int(cq/256)
  42.   rq=bitwiseand(cq,255):cq=int(cq/256)
  43.   return int(((rq*30)+(gq*59)+(bq*11))/100)
  44.   end function
  45.  
  46. for y2=0 to yed-1
  47.   setcaption(str$(int(100*(y2/yed)))+"%")
  48.   for x2=0 to xed-1
  49.     for y1=0 to 3:for x1=0 to 3
  50.       xq=y1*4+x1
  51.       p1[xq]=point(x2*4+x1,y2*4+y1)
  52.       next:next
  53.     for i=0 to 15
  54.       k1[i]=grayscale(p1[i])
  55.       next
  56.     for j=0 to 14:for i=0 to 14
  57.       if k1[i]>k1[i+1] then:
  58.         tm=k1[i]:k1[i]=k1[i+1]:k1[i+1]=tm
  59.         tm=p1[i]:p1[i]=p1[i+1]:p1[i+1]=tm
  60.         end if
  61.       next:next
  62.  
  63.     if clstr=0 then:
  64.     ink(p1[ 0]):dot(x2*4+0,y2*4+0)
  65.     ink(p1[ 6]):dot(x2*4+1,y2*4+0)
  66.     ink(p1[ 9]):dot(x2*4+2,y2*4+0)
  67.     ink(p1[15]):dot(x2*4+3,y2*4+0)
  68.     ink(p1[ 4]):dot(x2*4+0,y2*4+1)
  69.     ink(p1[10]):dot(x2*4+1,y2*4+1)
  70.     ink(p1[ 3]):dot(x2*4+2,y2*4+1)
  71.     ink(p1[13]):dot(x2*4+3,y2*4+1)
  72.     ink(p1[ 8]):dot(x2*4+0,y2*4+2)
  73.     ink(p1[14]):dot(x2*4+1,y2*4+2)
  74.     ink(p1[ 1]):dot(x2*4+2,y2*4+2)
  75.     ink(p1[ 7]):dot(x2*4+3,y2*4+2)
  76.     ink(p1[ 2]):dot(x2*4+0,y2*4+3)
  77.     ink(p1[12]):dot(x2*4+1,y2*4+3)
  78.     ink(p1[ 5]):dot(x2*4+2,y2*4+3)
  79.     ink(p1[11]):dot(x2*4+3,y2*4+3)
  80.     end if
  81.  
  82.     if clstr=1 then:
  83.     ink(p1[ 0]):dot(x2*4+0,y2*4+0)
  84.     ink(p1[ 4]):dot(x2*4+1,y2*4+0)
  85.     ink(p1[ 8]):dot(x2*4+2,y2*4+0)
  86.     ink(p1[12]):dot(x2*4+3,y2*4+0)
  87.     ink(p1[10]):dot(x2*4+0,y2*4+1)
  88.     ink(p1[14]):dot(x2*4+1,y2*4+1)
  89.     ink(p1[ 2]):dot(x2*4+2,y2*4+1)
  90.     ink(p1[ 6]):dot(x2*4+3,y2*4+1)
  91.     ink(p1[ 1]):dot(x2*4+0,y2*4+2)
  92.     ink(p1[ 5]):dot(x2*4+1,y2*4+2)
  93.     ink(p1[ 9]):dot(x2*4+2,y2*4+2)
  94.     ink(p1[13]):dot(x2*4+3,y2*4+2)
  95.     ink(p1[11]):dot(x2*4+0,y2*4+3)
  96.     ink(p1[15]):dot(x2*4+1,y2*4+3)
  97.     ink(p1[ 3]):dot(x2*4+2,y2*4+3)
  98.     ink(p1[ 7]):dot(x2*4+3,y2*4+3)
  99.     end if
  100.  
  101.     if clstr=2 then:
  102.     ink(p1[ 0]):dot(x2*4+0,y2*4+0)
  103.     ink(p1[10]):dot(x2*4+1,y2*4+0)
  104.     ink(p1[ 1]):dot(x2*4+2,y2*4+0)
  105.     ink(p1[11]):dot(x2*4+3,y2*4+0)
  106.     ink(p1[ 4]):dot(x2*4+0,y2*4+1)
  107.     ink(p1[14]):dot(x2*4+1,y2*4+1)
  108.     ink(p1[ 5]):dot(x2*4+2,y2*4+1)
  109.     ink(p1[15]):dot(x2*4+3,y2*4+1)
  110.     ink(p1[ 8]):dot(x2*4+0,y2*4+2)
  111.     ink(p1[ 2]):dot(x2*4+1,y2*4+2)
  112.     ink(p1[ 9]):dot(x2*4+2,y2*4+2)
  113.     ink(p1[ 3]):dot(x2*4+3,y2*4+2)
  114.     ink(p1[12]):dot(x2*4+0,y2*4+3)
  115.     ink(p1[ 6]):dot(x2*4+1,y2*4+3)
  116.     ink(p1[13]):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=3 then:
  121.     ink(p1[ 0]):dot(x2*4+0,y2*4+0)
  122.     ink(p1[12]):dot(x2*4+1,y2*4+0)
  123.     ink(p1[ 3]):dot(x2*4+2,y2*4+0)
  124.     ink(p1[15]):dot(x2*4+3,y2*4+0)
  125.     ink(p1[ 8]):dot(x2*4+0,y2*4+1)
  126.     ink(p1[ 4]):dot(x2*4+1,y2*4+1)
  127.     ink(p1[11]):dot(x2*4+2,y2*4+1)
  128.     ink(p1[ 7]):dot(x2*4+3,y2*4+1)
  129.     ink(p1[ 2]):dot(x2*4+0,y2*4+2)
  130.     ink(p1[14]):dot(x2*4+1,y2*4+2)
  131.     ink(p1[ 1]):dot(x2*4+2,y2*4+2)
  132.     ink(p1[13]):dot(x2*4+3,y2*4+2)
  133.     ink(p1[10]):dot(x2*4+0,y2*4+3)
  134.     ink(p1[ 6]):dot(x2*4+1,y2*4+3)
  135.     ink(p1[ 9]):dot(x2*4+2,y2*4+3)
  136.     ink(p1[ 5]):dot(x2*4+3,y2*4+3)
  137.     end if
  138.     x1=x2 mod 4:y1=y2 mod 4
  139.     u=point(x2*4+x1,y2*4+y1)
  140.     ink(u):dot(x2,y2)
  141.     next:next
  142.  
  143. loadimage("_t9a.png",1):pasteicon(256,0,1)
  144. for y2=0 to yed-1
  145.   setcaption(str$(int(100*(y2/yed)))+"%")
  146.   for x2=0 to xed-1
  147.     u=point(x2,y2)
  148.     for c2=15 to 0 step -1
  149.       cp=point(xed+c2*8,0)
  150.       if (u=cp) then:
  151.         ink(0xFFFFFF)
  152.         if bitwiseand(c2,1)<>0 then:ink(0):end if
  153.         dot((xed*0)+x2,yed+y2)
  154.         ink(0xFFFFFF)
  155.         if bitwiseand(c2,2)<>0 then:ink(0):end if
  156.         dot((xed*1)+x2,yed+y2)
  157.         end if
  158.       next
  159.     next:next
  160.  
  161. shell("rm _t*.png")
  162.  
  163. '-wrong output, need to correct it
  164. open finp$+".bin" for output as #1
  165. for y9=0 to 191 step 8
  166.  for x1=0 to 255 step 16
  167.   for y8=0 to 7
  168.     y2=y9+y8
  169.     for x7=0 to 15 step 8
  170.     for x0=0 to 1
  171.       setcaption("writebyte:... "+str$(y2)+"/192")
  172.       y=yed+y2
  173.       for x2=0 to 7:dpvl[x2]=0:next
  174.       for x2=0 to 7:xp=(x0*256)+x1+x2+x7
  175.         g=bitwiseand(point(xp,y),0x00FF00)/256
  176.         if g<128 then:dpvl[x2]=1:end if
  177.         next
  178.       dpvb=0
  179.       for x2=0 to 7:dpvb=dpvb+(dpvl[x2]*(2^(7-x2))):next
  180.       writebyte(1,dpvb)
  181.       next:next:next:next:next
  182.  
  183. waitvbl
  184.  
  185. for x0=0 to 3
  186.       setcaption("writebyte:... "+str$(x0)+"/3")
  187.   u=point(xed+(x0*8),0)
  188.   r=(bitwiseand(u,0xC00000)/0x400000)*0x1
  189.   g=(bitwiseand(u,0x00C000)/0x4000)*0x04
  190.   b=(bitwiseand(u,0x0000C0)/0x40)*0x10
  191.   writebyte(1,bitwiseor(r,bitwiseor(g,b)))
  192.   next
  193. close #1
  194.  
  195. waitvbl
  196.  
  197. grab(1,0,0,xed,yed):saveimage("_.bmp",1):shell("convert _.bmp "+finp$+".png && rm _.bmp" )
  198.       setcaption("saved")
  199. 'shell("convert "+finp$+".png  -colors 16 -compress None "+finp$+".ilbm ")
  200. 'shell("convert "+finp$+".png _.ppm && ppmtopi1 _.ppm > "+finp$+".pi1 && rm _.ppm")
  201.  
  202.  
  203. 'waitkey
  204.       setcaption("closing")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement