getPixel() again & again

Will getPixel be available in Graphics 2.0? This is a feature requested by MANY of us here.

Curious about this as well.  A much loved ActionScript function that I would be thrilled to have again.

+1 get and setPixel would be awesome. open a whole new level.

+1, was thinking of using a feature like this to dynamically be able to set the color of the statusbar

I would use the getPixel() and setPixel() in ActionScript to create custom avatars very easily.  Would love to have that feature again. 

Please use the feedback site to vote this up:

http://feedback.coronalabs.com/forums/188732-corona-sdk-feature-requests-feedback/suggestions/3625203-bitmap-manipulation-read-pixel-e-g-for-selecti

Done.  Thanks Rob.

Curious about this as well.  A much loved ActionScript function that I would be thrilled to have again.

+1 get and setPixel would be awesome. open a whole new level.

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.

For example:

* 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/

* Etc

* Etc

* 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!

Hi Walter,

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.

@develephant, can u give me an idea of the visual effect you want to achieve?

Yes.

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 )   

Thanks for adressing this Walter. In my case I would use the feature similar to Develephant, to get the color of a specific pixel on the screen, ie. ‘getPixelColorAt(x, y)’ and then use the color returned to fill a newRect that is placed behind the statusbar with. This way I could check whether the toolbar in a certain scene contains ‘x’ color, i could fill the statusbar with a matching color dynamically without having to know what the colors will be before hand.

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 :slight_smile:

For creating multiple versions of a single image, is this the kind of thing you are trying to achieve?

http://www.emanueleferonato.com/2009/04/28/understanding-as3-colormatrixfilter-class/

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.

Walter, I am heading out at the moment but your link is close, I will take some screenshots tonight and post them so you can see what I am talking about pretty sure develephant is talking about the exact same thing.

Thanks

Walter,

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 ( B) 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 :slight_smile:

Chris

@cbishop0, isn’t the link I posted exactly what you want then? With a color matrix, you can map initial rgba values to alternate rgba values.