Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

getPixel() again & again
Started by glyphed Oct 09 2013 09:53 AM

35 replies to this topic
[TOPIC CONTROLS]
Page 1 of 2 1 2
This topic has been archived. This means that you cannot reply to this topic.
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

glyphed

[GLOBAL: userInfoPane.html]
glyphed
  • Observer

  • 3 posts
  • Corona SDK

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



[TOPIC: post.html]
#2

Develephant

[GLOBAL: userInfoPane.html]
Develephant
  • Corona Geek

  • 1,450 posts
  • Corona SDK

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



[TOPIC: post.html]
#3

searchm

[GLOBAL: userInfoPane.html]
searchm
  • Contributor

  • 187 posts
  • Corona SDK

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



[TOPIC: post.html]
#4

Skatan

[GLOBAL: userInfoPane.html]
Skatan
  • Contributor

  • 547 posts
  • Corona SDK

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



[TOPIC: post.html]
#5

Develephant

[GLOBAL: userInfoPane.html]
Develephant
  • Corona Geek

  • 1,450 posts
  • Corona SDK

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



[TOPIC: post.html]
#6

Rob Miracle

[GLOBAL: userInfoPane.html]
Rob Miracle
  • Moderator

  • 25,801 posts
  • Enterprise

[TOPIC: post.html]
#7

Develephant

[GLOBAL: userInfoPane.html]
Develephant
  • Corona Geek

  • 1,450 posts
  • Corona SDK

Done.  Thanks Rob.



[TOPIC: post.html]
#8

walter

[GLOBAL: userInfoPane.html]
walter
  • Moderator

  • 726 posts
  • Alumni

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!



[TOPIC: post.html]
#9

Develephant

[GLOBAL: userInfoPane.html]
Develephant
  • Corona Geek

  • 1,450 posts
  • Corona SDK

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.



[TOPIC: post.html]
#10

walter

[GLOBAL: userInfoPane.html]
walter
  • Moderator

  • 726 posts
  • Alumni

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



[TOPIC: post.html]
#11

Develephant

[GLOBAL: userInfoPane.html]
Develephant
  • Corona Geek

  • 1,450 posts
  • Corona SDK

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 ) 
 


[TOPIC: post.html]
#12

Skatan

[GLOBAL: userInfoPane.html]
Skatan
  • Contributor

  • 547 posts
  • Corona SDK

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.

[TOPIC: post.html]
#13

Christopher Bishop

[GLOBAL: userInfoPane.html]
Christopher Bishop
  • Contributor

  • 416 posts
  • Corona SDK

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



[TOPIC: post.html]
#14

walter

[GLOBAL: userInfoPane.html]
walter
  • Moderator

  • 726 posts
  • Alumni

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/



[TOPIC: post.html]
#15

glyphed

[GLOBAL: userInfoPane.html]
glyphed
  • Observer

  • 3 posts
  • Corona SDK

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.



[TOPIC: post.html]
#16

Christopher Bishop

[GLOBAL: userInfoPane.html]
Christopher Bishop
  • Contributor

  • 416 posts
  • Corona SDK

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



[TOPIC: post.html]
#17

Christopher Bishop

[GLOBAL: userInfoPane.html]
Christopher Bishop
  • Contributor

  • 416 posts
  • Corona SDK

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

 

Chris

 

Attached Files



[TOPIC: post.html]
#18

walter

[GLOBAL: userInfoPane.html]
walter
  • Moderator

  • 726 posts
  • Alumni

@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.



[TOPIC: post.html]
#19

Christopher Bishop

[GLOBAL: userInfoPane.html]
Christopher Bishop
  • Contributor

  • 416 posts
  • Corona SDK

In theory yes, if implemented better :)

 

Adobes ColorMatrixFilter is a pig and that is being nice lol...

 

But same logic applies yes.



[TOPIC: post.html]
#20

Christopher Bishop

[GLOBAL: userInfoPane.html]
Christopher Bishop
  • Contributor

  • 416 posts
  • Corona SDK

like i said a nice to have, but at the moment i am just happy being able to apply fillcolors on masks :) 



[TOPIC: post.html]
#21

walter

[GLOBAL: userInfoPane.html]
walter
  • Moderator

  • 726 posts
  • Alumni

a pig? in terms of performance? or in terms of usage? what would make it better?



[TOPIC: post.html]
#22

Christopher Bishop

[GLOBAL: userInfoPane.html]
Christopher Bishop
  • Contributor

  • 416 posts
  • Corona SDK

Performance mostly but that could have been just flash as I am not a big fan :)

personally I think something as simple as the fill color option would be nice just add find color replace color and it would be super simple to use so long as it didn't hammer the texture memory.

But man would it be nice for sprites lol

[TOPIC: post.html]
#23

rakoonic2

[GLOBAL: userInfoPane.html]
rakoonic2
  • Contributor

  • 503 posts
  • Corona SDK

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.



[TOPIC: post.html]
#24

Christopher Bishop

[GLOBAL: userInfoPane.html]
Christopher Bishop
  • Contributor

  • 416 posts
  • Corona SDK

The way I do it is pretty simple and provides the best output at the moment and since everything is in an image sheet I just really keep and index like shirt=1 etc and color index = 3 and what not.

It would just be nice to have white on something and have it not effected by fill color etc. lol

[TOPIC: post.html]
#25

Christopher Bishop

[GLOBAL: userInfoPane.html]
Christopher Bishop
  • Contributor

  • 416 posts
  • Corona SDK

Actually come to think about it, if there was an option to exclude solid white on set fill color I would be ecstatic :)


[topic_controls]
Page 1 of 2 1 2
 
[/topic_controls]