Will getPixel be available in Graphics 2.0? This is a feature requested by MANY of us here.
Jump to content
Please use the feedback site to vote this up:
Can you guys give me more context into your use case?
The reason I ask is b/c with a GPU pipeline, you have to do things differently than you might in a pure CPU pipeline (e.g. Flash). So in a modern GPU pipeline, you do almost all pixel manipulation in a shader.
Classically, i.e. CPU-based renderers, you could just manipulate bitmaps, read or write, and then just flush those changes to the framebuffer. Or you could just read the framebuffer directly. With GPUs, those operations are very costly, but that loss of control was outweighed by the benefits.
So depending on what you want to do, there's probably a GPU-way of doing it, but I need to understand what you want to do.
* a color picker use case (i.e. sample an individual color from the screen) could probably be done via some async mechanism. It's not going to be in real-time, so just be aware of that. We'd have to implement that, but it's not clear who wants this.
* another use case would be that you relax the real-time constraint. In particular, you are okay with manipulating the image *offscreen* and then when you're done, handing the image to Corona. In this case, you would want to do this in native C code for performance reasons, as Lua would probably be too slow to manipulate images on a per-pixel basis.
* yet another would be that you want to draw into your own texture and use that to fill other objects. This is on the roadmap, and what you would ultimately use here are snapshot objects.
* or maybe you want to do a canvas style effect where you can "draw" onto a texture. Snapshot objects have the ability to let you do this: https://blog.coronalabs.com/blog/2013/11/01/snapshot-canvas-paint-brushes-trailing-object-effects-etc/
My point is there are a lot of use cases and they may require new techniques, ones that are appropriate to Corona's GPU pipeline.
For example, there were some Mode7-like techniques, and on a SNES you'd do it one way to achieve the effect, but in Corona, you'd use snapshot objects: http://forums.coronalabs.com/topic/40443-mode-7-demo-full-source/
So if you can give me use cases, we can make sure we're targeting them as we continue to push G2.0 forward!
In my case, it would not need to be real-time. In AS3 you can get the color under the mouse pointer, as well as replace a color in a bitmap.
So, it seems like it's 2 different needs. One would be the ability to find and replace a color on a bitmap. The other would be the ability to get the color value from a finger tap. But, the more I think about it, it's probably going to be difficult to do something like that since the precision of a mouse pointer is lost on a touch device. Of course if it was a large enough area of color, it could still be useful.
Hope that helps.
Let's say I have a simple 2D avatar, mostly solid colors for skin, shirt, pants, etc. and I want the user to be able to adjust some of the colors to add some variation, especially in a multi-player setting.
Instead of having to create the multitude of avatar options, I could present a panel with some color options. Once a color was tapped on the color panel ( getPixel() ) then I could apply that to the chosen piece for the avatar -- pants for example -- which would require a color "find and replace" ( setPixel() ) and let's assume the starting pants color is a value I know in advance. I could then replace that color with the user selected color, save that out, and have the users avatar.
It could also be used in a variety of other cases, but that's a simple one.
So I suppose it would look something like:
local colorTbl = getColorAt( x, y ) replaceColor( colorToFind, colorToReplace )
I could use the same as develephant's suggestion for the most part fillColor works good with the exception of when you want "white" lol, for example:
A candy can is white with red stripes if you want to change just red you have to either create another image that you can overlay and change that fill color or you use fill color and get blue + red, or orange + red instead of white + blue, white + orange etc. and so forth.
at the moment i handle this with "layers" which works just fine and is still less than having multiple different colored pants etc.
so for example on pants i might have 1 layer for the pants background, one for the belt, etc. then allow color change on both layers... it isn't ideal but works just fine when you slam everything into an image sheet
For creating multiple versions of a single image, is this the kind of thing you are trying to achieve?
I'm personally interested in the ability to perform different custom interventions on individual pixels and generate different photo effects that way. I already have a photo editing/sharing app in App Store developed in Corona but lacking any kind of original filters/effects because I can not access pixels.
See attached... and just focus on the t-shirt (as one of many t-shirts)...
So currently because of the way fillColor works with white the only way to achieve the shirt in the picture is to either (a) make 20 different variations of it and show those or ( create 2 different "white" images one is the shirt and the other is the skull on the front of the shirt and the combine them into a group and that becomes your t-shirt then from there you can easily say tshirt->fillcolor->rgb(0,0,0) and skull->fillcolor->(1,1,1) etc. and so forth...
What this does is allow you to customize a character or avatar or really anything else.
But... if I was able to just have 1 image with say black tshirt and white skull and say something to the effect of fillcolor(getPixel(0,0,0), setPixel(1,0,0)) and it knows to change the color of black to red that would make life a whole lot easier.
I realize the back end openGL side of this is ummm well brutal as you are not dealing with a model and simply swapping out a texture on geometry but hey if we are all asking for something lol...
The way I currently do it actually gives me a lot of lead way and even with over 500 parts I am still only pushing about 5mb in texture memory so not a big deal but a nice to have
One thing of note - changing the pixel colour is not the same as tinting an image.
In the example image posted above you aren't going to have much success converting all black of the t-shirt to another colour as it isn't going to handle anti-aliasing at all (except where it is only a result of alpha channel, but that itself implies overlaying various images).
Laying the images one over the other would be the best way for this, or possibly even using polygon shapes.
If you need to use the 'final' image a lot, you might be able combine it all into a snapshot and work with that, depending on the specifics of the case.
Community Forum Software by IP.Board