James |
I have made various scripts in Lua that do distortions, curve ops and color effects etc but so far I have been confused how to set a single pixel.
What I want is to simply set the r,g,b,a value at an x,y position. Does anyone have a script snippet for this? Thanks |
|||||
Posted: June 25, 2021 11:35 pm | ||||||
Theob |
Have you had a look here. Hope it may help
![]() |
|||||
Posted: June 26, 2021 10:19 am | ||||||
James |
The closest thing I can find in the library is the pixel art generators in the Bearestroika filter. These use an array however, I don't want to have to set a whole array of colours each time but simply set one pixel of an image inputs colour. There should be a simpler way but so far my experiments have failed but I'm guessing there will be a fairly simple solution.
So say for example I want to set 0,0 of images width and height to 255,0,0,1.0 which should make the very first pixel red. |
|||||
Posted: June 26, 2021 2:01 pm | ||||||
emme |
As you probably know, FF works with sample coordinates, not with pixel coordinates - so there isn't really a simple way to set pixel values like you would on a bitmap based system.
You can use the global variables OUTPUT_WIDTH and OUTPUT_HEIGHT to get the image dimensions in pixels and use those calculate the pixel coordinates. For example:
Note that this only works with square images. Some extra code is needed to compensate for different aspect ratios. |
|||||
Posted: June 26, 2021 2:30 pm | ||||||
Rachel Duim
![]() |
Another thing to know, FF is pixel aware. Although this only draws lines and not points, you can use this example to set single pixels if you wish: Pixel Image with Grid
Math meets art meets psychedelia. |
|||||
Posted: June 26, 2021 2:39 pm | ||||||
James |
Thanks emme, that basically does what I want but due to the sample coordinates system you mention your script steps a bit too much each pixel value increased and also when the input value is max it seems to make the pixel vanish.
Another thing I noticed is if you don't use a slider input and just set px,py = 1,1 instead then the pixel vanishes. Also how would you increase the pixel size from 1x1 to say 10x10? My goal was to port some lua scripts that draw various things using a set pixel function but it seems that due to the sample coordinates system there would be problems. Also thanks for the reply Rachel Duim, currently I only have FF version 3 so I can't check the map script that filter uses. The script emme posted is basically what i want but there is the few issues I mention. |
|||||
Posted: June 26, 2021 3:03 pm | ||||||
emme |
Yes, the way the SliderControl UI works doesn't allow for much precision. ValueControl outputs fractional values, but I don't think it's available in FF3. You can also manually ins ert fractional values to the SliderControl for more precision, or set an IntSlider range to match the image dimensions. These are not great solutions, but that's the best you can do. The pixel coordinates can of course be precisely set via code.
For a quick and dirty fix for the rounding problem, just subtract 0.5 from w and h in the if statement.
Yeah, I mean you could make a list / array of all the se t pixel instructions and just loop through them, but that would not be very efficient in FF ![]() |
|||||
Posted: June 26, 2021 3:51 pm | ||||||
James |
Thanks emme, that code makes the pixel disappear if set to 0,0 however but I fixed it using an if statement:
I made a script where I convert the setPixel part into a function but for me it doesn't work in FF3, possibly due to the fractional values thing. Could someone confirm if the following script works in later versions?
If it doesn't work in later versions perhaps my code is broken somehow but it looks as if it should work. Edit - Maybe the developers could a a new node "Pixel Script" in FF11 which can correctly set pixels and maybe also do html5 canvas style things like drawing lines and rectangles etc with simple code. That would allow for all sorts of interesting scripts to be made. |
|||||
Posted: June 26, 2021 4:12 pm | ||||||
emme |
Slight modification, should work now more or less
![]()
|
|||||
Posted: June 26, 2021 4:44 pm | ||||||
James |
Thanks that show me an output.
![]() |
|||||
Posted: June 26, 2021 4:52 pm | ||||||
Rachel Duim
![]() |
If anyone is interested, here is setting a single pixel in FF7 without lua.
Pixel Set.ffxml Math meets art meets psychedelia. |
|||||
Posted: June 27, 2021 1:35 am |
Filter Forge has a thriving, vibrant, knowledgeable user community. Feel free to join us and have fun!
33,712 Registered Users
+19 new in 30 days!
153,533 Posts
+31 new in 30 days!
15,348 Topics
+73 new in year!
35 unregistered users.