You are here

How can i code a filter with Python-Gimp?

Some time ago i coded this picture converter below on sdlBasic. Is there some way to recode this using Python-Gimp and use this as picture filter? afaik, the Python syntax can be somehow similar of the used on sdlBasic, and maybe i'd need to use get_pixel and set_pixel, but i have no idea about how to do this - if someone do, please recode this as Python-Gimp plugin for allowing me and all of us how to do similar picture filters in a similar way - thanks in advance

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
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)
close #1
dim clust[8,8] '-,o4b[2]
for y2=0 to 3:for x2=0 to 3:lc=(y2*4)+x2
dim cor[16]
for y=0 to yed-1:for x=0 to xed-1
b=ind mod 256:ind=int(ind/256):g=ind mod 256:ind=int(ind/256):r=ind mod 256
patgf=(((clust[x mod 4,y mod 4]+1)*255)/16)
rpat=0:if r>patgf then:rpat=1:end if
gpat=0:if g>patgf then:gpat=1:end if
bpat=0:if b>patgf then:bpat=1:end if
o4b=(bpat+(rpat*2)+(gpat*4)) mod 8
fout$=finp$+".bmp":grab (1,0,0,xed,yed):saveimage(fout$,1)

... this should translate into the following formulas that can be fed into the UserFilter plug-in ( R=put(0,0),put(6,1),put(8,2),put(14,3), put(2,4),put(12,5),put(4,6),put(10,7), put(8,8),put(14,9),put(0,10),put(6,11), put(4,12),put(10,13),put(12,14),put(12,15), r>put(((1+get(x%4+4*(y%4)))*255)/16,16)?rmax:rmin G=g>get(16)?gmax:gmin B=b>get(16)?bmax:bmin A=a You could even add some more fun by making the filter depending upon controler values: R=put(0,0),put(6,1),put(8,2),put(14,3), put(2,4),put(12,5),put(4,6),put(10,7), put(8,8),put(14,9),put(0,10),put(6,11), put(4,12),put(10,13),put(12,14),put(12,15), r>put(((1+get(x%val(0,1,4)+val(0,1,4)*(y%val(0,1,4))))*ctl(1))/16,16)?rmax:rmin Where control 0 will change the size of the dither matrix and conrol 1 would change the intensity.

@cholfatyarh - thanks, i think i know this 'custom filter' you tell about, i think it came from a PaintShopPro version from 10 years ago, isn't it? Thanks again, but it's too limited for what i really want to do, which would be a 'true' picture processing, using Gimp-Python for it... btw, i posted some filters coded in Python can be interesting for people curious about! - thanks! :-)

If you know of any gentle introduction to python-fu or more general GIMP Python, let me know. The official documentation barely touches the ground and is beginner unfriendly.

this would my main concern - try to help on contributing with simple and useful python-gimp scripts would encourage and help newbies on a fast learning and immediate usage/feedback/productivity.
Subscribe to Comments for "How can i code a filter with Python-Gimp?"