Advertisement
Guest User

MsxScr04c8x1pictFilter0709211600.sdlbas

a guest
Jul 28th, 2013
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. finp$="source.png"
  2.  
  3. '- 0108091823
  4. '---- teste1_0105052418_fileopening_msx1_8x1_conv.txt
  5. '---- 010808 - primeira tentativa no firstbasic-dos
  6.  
  7. '- reads palette after imagemagick conversion
  8. tmfl$="_tmpr01.gif"
  9.  
  10. '- shell("convert "+finp$+" -colors 16 "+tmfl$+".xpm")
  11. shell("convert "+finp$+" -colors 16 "+tmfl$)
  12.  
  13. dim npaletr[16],npaletg[16],npaletb[16]
  14. dim clust[8,8],grpltlev[16]
  15. dim rfromat[16],gfromat[16],bfromat[16],r0[8,8],g0[8,8],b0[8,8],plte[16]
  16.  
  17. open tmfl$ for input as #1
  18.    for i=1 to 13:n=readbyte(1):next
  19.    for i=0 to 15
  20.       n=readbyte(1):npaletr[i]=int((int(n/32))*(255/7))
  21.       n=readbyte(1):npaletg[i]=int((int(n/32))*(255/7))
  22.       n=readbyte(1):npaletb[i]=int((int(n/32))*(255/7))
  23.    next
  24.  close #1
  25.  
  26. shell ("rm "+tmfl$)
  27.  
  28.  
  29.  
  30.  
  31. '- reads png file
  32. xed=0:yed=0:open finp$ for input as #1:for i=1 to 16:n=readbyte(1):next:for i=1 to 2:n=readbyte(1):next
  33. 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)
  34. close #1:setdisplay(xed,yed,32,1):paper(8^8-1):ink(0):pen(0):cls
  35.  
  36.  
  37. 'for i=0 to 15
  38. '  prints(str$(npaletr[i])+","+str$(npaletg[i])+","+str$(npaletb[i]))
  39. ' next
  40. 'for i=0 to 15
  41. '  ink(rgb(npaletr[i],npaletg[i],npaletb[i])):bar(0,4*i,xed,64):next
  42. 'waitkey
  43.  
  44.  
  45. loadimage(finp$,1):pasteicon(0,0,1)
  46.  
  47. '- defines the cluster for halftone
  48. dmst$="00,06,08,14,02,12,04,10,08,14,00,06,04,10,02,12."
  49. for y2=0 to 3:for x2=0 to 3:clust[x2,y2]=val(mid$(dmst$,((y2*4+x2)*3)+1,2)):next:next
  50.  
  51.  
  52. fout$=finp$+"_.bmp"
  53. fout2$=finp$+"_.png"
  54.  
  55. '- colour palette
  56. 'dmst$="0,1,5,1,7,2,6,1,7,2,5,6,6,6,7,":for i=0 to 14:rr=val(mid$(dmst$,(i*2)+1,1)):npaletr[i]=(rr*255)/7:next
  57. 'dmst$="0,1,1,4,1,3,2,6,3,6,5,7,6,6,7,":for i=0 to 14:rg=val(mid$(dmst$,(i*2)+1,1)):npaletg[i]=(rg*255)/7:next
  58. 'dmst$="0,7,1,1,1,7,5,1,3,7,5,6,2,8,7,":for i=0 to 14:rb=val(mid$(dmst$,(i*2)+1,1)):npaletb[i]=(rb*255)/7:next
  59.  
  60.  
  61.  
  62.  
  63. '- defines grayscale from the palette
  64. 'dmst$="0000,0237,0314,0395,0400,0448,0504,0564,0600,0701,0714,0765,0778,0825,1000."
  65. 'for i=0 to 14:grd=val(mid$(dmst$,(i*5)+1,4)):grpltlev[i]=((grd*255)/1000):next
  66.  
  67. for i=0 to 15:grpltlev[i]=int(((npaletr[i]*30)+(npaletg[i]*59)+(npaletb[i]*11))/100): next
  68.  
  69.  
  70. '- sorts the palette
  71.  
  72. for i=0 to 14
  73. for j=i+1 to 15
  74. if grpltlev[i]>grpltlev[j] then
  75.   tmprq=grpltlev[i]:grpltlev[i]=grpltlev[j]:grpltlev[j]=tmprq
  76.   tmprq=npaletr[i]:npaletr[i]=npaletr[j]:npaletr[j]=tmprq
  77.   tmprq=npaletg[i]:npaletg[i]=npaletg[j]:npaletg[j]=tmprq
  78.   tmprq=npaletb[i]:npaletb[i]=npaletb[j]:npaletb[j]=tmprq
  79. end if
  80. next:next
  81.  
  82.  
  83.  
  84.  
  85. 'for i=0 to 15
  86. '  ink(rgb(npaletr[i],npaletg[i],npaletb[i])):bar(0,4*i,xed,64):next'
  87. 'waitkey
  88.  
  89.  
  90.  
  91.  
  92.  
  93. for i=0 to 15:plte[i]=rgb(npaletr[i],npaletg[i],npaletb[i]):next
  94. xmax=xed
  95. ymax=yed
  96. xmaxo=int(xmax/8):ymaxo=int(ymax/8)
  97. xmaxoo=xmaxo*8:ymaxoo=ymaxo*8
  98. xsm0=(xmaxoo and 255):ysm0=(ymaxoo and 255)
  99.  
  100. for i=0 to 15:rfromat[i]=npaletr[i]:gfromat[i]=npaletg[i]:bfromat[i]=npaletb[i]:next
  101. for y1=0 to ymaxo-1
  102.   setcaption(str$(int((y1*100)/ymaxo))+"%")
  103.   for x1=0 to xmaxo-1
  104.     for y2=0 to 7:for x2=0 to 7
  105.       y=y1*8+y2:x=x1*8+x2:iy=(ymax-1)-y:ympos=(((iy*xmax)+x)*3)+55
  106.       zzz=point(x,y)
  107.       b0[x2,y2]=bitwiseand(zzz,255):zzz=int(zzz/256)
  108.       g0[x2,y2]=bitwiseand(zzz,255):zzz=int(zzz/256)
  109.       r0[x2,y2]=bitwiseand(zzz,255)
  110.       next:next
  111.     for y2=0 to 7
  112.       y=y1*8+y2
  113.       '- atribute reading and mounting
  114.       bi=0:ri=0:gi=0
  115.       for x2=0 to 7:x=(x1*8)+x2:iy=(ymax-1)-y:bi=bi+b0[x2,y2]:gi=gi+g0[x2,y2]:ri=ri+r0[x2,y2]:next
  116.       b=bi/8:g=gi/8:r=ri/8:dbuf=1000:paattr=0:ikattr=15:pa=0:ik=15
  117.       lumik=15:lumpa=0
  118.  
  119.       for pa=0 to 14
  120.         for ik=pa+1 to 15
  121.           graypa=grpltlev[pa]: grayik=grpltlev[ik]
  122.           '- lumik=grayik:lumpa=graypa
  123.           grayrgb=(((b*11)+(r*30)+(g*59))/100)
  124.           if grayrgb>graypa and grayrgb<grayik then
  125.             ikincid=((grayrgb-graypa)*255)/(grayik-graypa)
  126.             rfikinc=((rfromat[ik]*ikincid)+(rfromat[pa]*(255-ikincid)))/255
  127.             gfikinc=((gfromat[ik]*ikincid)+(gfromat[pa]*(255-ikincid)))/255
  128.             bfikinc=((bfromat[ik]*ikincid)+(bfromat[pa]*(255-ikincid)))/255
  129.             rdist=abs(rfikinc-r):gdist=abs(gfikinc-g):bdist=abs(bfikinc-b)
  130.             rgbdist=sqr((rdist^2)+(gdist^2)+(bdist^2))
  131.             if rgbdist<=dbuf then:dbuf=rgbdist:paattr=pa:ikattr=ik:lumik=grayik:lumpa=graypa:end if
  132.             end if
  133.           next:next
  134.  
  135.         '- memory block 4 reading as grayscale for screen 2
  136.         dflum=lumik-lumpa:pkvar=0
  137.         for x2=0 to 7
  138.           x=x1*8+x2:yi=(ymaxoo-1)-y:b=b0[x2,y2]:g=g0[x2,y2]:r=r0[x2,y2]
  139.           vlue=(((b*11)+(r*30)+(g*59))/100)
  140.           patgf1=x2 mod 4:patgf2=y mod 4:patgf=(((clust[patgf1,patgf2]+1)*255)/16)
  141.           varnd=((patgf*dflum)/255)+lumpa
  142.           ik=ikattr
  143.           if varnd>vlue then:ik=paattr:end if
  144.  
  145.           ink(plte[ik]):dot(x,y)
  146.  
  147.           next:next:next:next
  148.  
  149. grab (1,0,0,xed,yed):saveimage(fout$,1)
  150. shell("convert "+fout$+" "+fout2$)
  151. shell("rm "+fout$)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement