One Star Review : GetPixel() needed and soon!

It was inevitable.
My app can’t do anything useful with images because I don’t have GetPixel() or anything similar.
So today I got my first 1 star review because my app doesn’t import and process images.

To be fair, I never said it did.
(I never said it makes toast or mows the lawn either…)
But people aren’t fair, which is why I dislike the ratings system: why buy a cat and complain it isn’t a pony?
+++++++++++++ 1 for GetPixel()

Please!
I’m desperate!

[import]uid: 108660 topic_id: 24518 reply_id: 324518[/import]

OpenGl is great for displaying graphics but was not indented for reading back pixels displayed. We have looked at this issue and unforturenly that is no easy way to do this at this time. As we look to optimize our graphics engine, we will look for a way to make this happen in the future. [import]uid: 7559 topic_id: 24518 reply_id: 99248[/import]

OK.
If OpenGL isn’t an option, there are at least 6 different GFX libraries that link to Lua (but they all seem to need DLLs or the like.)

Does iOS provide a library call that Corona could tap into? (Can we even declare an external call of this kind in a Corona app?)

Does anyone know of a native LUA language library that can open a PNG file as binary and create a bitmapped array from it?

I could just about do it for the Windows BMP format, but PNG and JPG are a bit beyond me.
[import]uid: 108660 topic_id: 24518 reply_id: 99262[/import]

This may help as a starting point…

http://lua-users.org/wiki/PortableNetworkGraphicsParser
cheers

evs [import]uid: 8366 topic_id: 24518 reply_id: 99281[/import]

Thanks EVS
That heading promised so much. And then… :wink:
It basically gets the headers so you know ‘whats coming’. But no more.

Ive found a python implementation of JPG files, but I have no experience of Python yet, so it could be a steep learning curve if I go for it!

https://github.com/enmasse/jpeg_read/blob/master/jpeg_read.py
[import]uid: 108660 topic_id: 24518 reply_id: 99307[/import]

By the way: to avoid any confusion with Open GL:
I am not looking for something which gets me a pixel from the screen at some point.
Im looking for something that can take a picture and return an array of {R,G,B} triplets

And incidentally, the methods behind capturing the screen to save as a PNG file MUST have access to the screen as a set of pixels, mustn’t it???
[import]uid: 108660 topic_id: 24518 reply_id: 99578[/import]

Tom:
Couldn’t you implement glReadPixels?

void glReadPixels( GLint x,
GLint y,
GLsizei width,
GLsizei height,
GLenum format,
GLenum type,
GLvoid * data);
Parameters

x, y
Specify the window coordinates of the first pixel that is read from the frame buffer. This location is the lower left corner of a rectangular block of pixels.

width, height
Specify the dimensions of the pixel rectangle. width and height of one correspond to a single pixel.

format
Specifies the format of the pixel data. The following symbolic values are accepted: GL_COLOR_INDEX, GL_STENCIL_INDEX, GL_DEPTH_COMPONENT, GL_RED, GL_GREEN, GL_BLUE, GL_ALPHA, GL_RGB, GL_BGR, GL_RGBA, GL_BGRA, GL_LUMINANCE, and GL_LUMINANCE_ALPHA.

type
Specifies the data type of the pixel data. Must be one of GL_UNSIGNED_BYTE, GL_BYTE, GL_BITMAP, GL_UNSIGNED_SHORT, GL_SHORT, GL_UNSIGNED_INT, GL_INT, GL_FLOAT, GL_UNSIGNED_BYTE_3_3_2, GL_UNSIGNED_BYTE_2_3_3_REV, GL_UNSIGNED_SHORT_5_6_5, GL_UNSIGNED_SHORT_5_6_5_REV, GL_UNSIGNED_SHORT_4_4_4_4, GL_UNSIGNED_SHORT_4_4_4_4_REV, GL_UNSIGNED_SHORT_5_5_5_1, GL_UNSIGNED_SHORT_1_5_5_5_REV, GL_UNSIGNED_INT_8_8_8_8, GL_UNSIGNED_INT_8_8_8_8_REV, GL_UNSIGNED_INT_10_10_10_2, or GL_UNSIGNED_INT_2_10_10_10_REV.

data
Returns the pixel data.

[import]uid: 108660 topic_id: 24518 reply_id: 99580[/import]

I had assumed this too. The storyboard seems to render the previous scene to a bitmap so there must be bitmap data access lurking in there somewhere. [import]uid: 42417 topic_id: 24518 reply_id: 99581[/import]

The openGL pixel code is what is used internally but there are major performance problems if exposed via the Lua interface. Lua also lacks true arrays, which would add to the performance issue when working with a range of pixels.

Storyboard uses this API internally to capture a screen bitmap, which is one reason why it runs slow on larger displays.
[import]uid: 7559 topic_id: 24518 reply_id: 99612[/import]

Thanks Tom. Any updates on Storyboard in general? [import]uid: 42417 topic_id: 24518 reply_id: 99616[/import]

>>The openGL pixel code is what is used internally but there are major performance problems if exposed via the Lua interface. <<

It can’t slow down an app if it is not used in an app.
If it was available, even if it was slow, people could choose whether to use it, surely?

>>Lua also lacks true arrays, which would add to the performance issue when working with a range of pixels.<<

OK, But if the parameters were asking for a single pixel, you wouldn’t need an array.
Yes, I know, open a door and people would start asking for the rest, but if I was hungry, I’d rather have a peanut than nothing at all. [import]uid: 108660 topic_id: 24518 reply_id: 99682[/import]

GetPixel
Just one pixel… just the rgb of one pixel
I don’t even care how slow it is.

I’m literally going to have to abandon Corona and rewrite my whole app in something else…

“Storyboard uses this API internally to capture a screen bitmap”
So why would one pixel be hard? [import]uid: 108660 topic_id: 24518 reply_id: 108867[/import]

Danny’s png reader might be a place to start:
http://developer.anscamobile.com/forum/2012/05/16/pnglib-extract-data-png-files-width-height-color-depth-etc [import]uid: 7563 topic_id: 24518 reply_id: 108881[/import]

@ewing:
Thank you for responding, but Danny’s PNG header reader has nothing to offer here.
He would tell you so himself.

Its a smaller alternative to David Manura’s 2008 code
http://lua-users.org/wiki/PortableNetworkGraphicsParser

Both code sets literally only open a PNG file and let you know how big the picture is.
Anything other than that requires an implementation of zlib compression, which Corona also doesn’t have.
Thats presumably why Danny hasn’t gone any further with it.

Sadly, its a bit like needing a sandwich but finding a shopping list.
And even though I said:
“I am not looking for something which gets me a pixel from the screen at some point.”

That should be easier to implement, given that OpenGL is being used to do screen grabs.
So if I have to display the image first, and grab a rgb triplet from screen, that would be OK.
Any solution at all that provides an RGB triplet from any kind of source would do.

eg:
GetPixel() from visible screen
getPixel() from a display.Image
getPixel() from a file in a known location

(Ive even debated running a small ‘command line’ app from a Corona app, and asking it to do the work, but it doesn’t seem possible to bundle such an app with a Corona one and launch it from Corona code)
[import]uid: 108660 topic_id: 24518 reply_id: 108888[/import]

What about internal HTML5/JS lib? Canvas elementh give you what you need:
https://developer.mozilla.org/En/HTML/Canvas/Pixel_manipulation_with_canvas [import]uid: 12704 topic_id: 24518 reply_id: 108916[/import]

Is that usable from inside Corona?

I just read through those pages and I can see how to create a new image context from scratch, but not how to open an existing image.
Getting back a pixel from an image I have drawn myself isn’t that useful: (if I put a pixel there, I don’t need to ask what colour it is)
[import]uid: 108660 topic_id: 24518 reply_id: 108917[/import]

This could be completely irrelevant and not helping at all, but here are my rather random thoughts of this.

What if you make a screen capture, save it to as a file, open a html5 page which uses that image and checks the pixel from the image?
You can then pass that information back to the application.

This is a big hassle, I know. But if it’s not possible otherwise this could make it done.

(Also, the first thing I thought was uploading the screenshot to a server where the pixel is checked and the value is returned to the app, it’s slow, uses bandwidth and needs user to have a internet connection… so it’s really not a smooth way) [import]uid: 10416 topic_id: 24518 reply_id: 108922[/import]

You are right, it sounds like an immense hassle. And to be honest, Im not 100% sure it would work, but thank you for the suggestion and I will research it.
[import]uid: 108660 topic_id: 24518 reply_id: 108924[/import]

http://stackoverflow.com/questions/667045/getpixel-from-html-canvas [import]uid: 12704 topic_id: 24518 reply_id: 108956[/import]

Thanks, gtatarkin, I think

var imgd = context.getImageData(x, y, width, height);  
var pix = imgd.data;  

I don’t see the significance in the context of Lua or Corona.
Where does this run?
Where does the image come from?
This example code looks like it creates a big white image and turns it black.
Somewhere.

I’m guessing this needs to be in an web page and that theres a few dozen more lines of code at least that is implied.
But send an image to a web page from a Corona app?
Does that mean I need to find a server and allow for FTP?
Does that code make sense to you? (anyone?)

[import]uid: 108660 topic_id: 24518 reply_id: 108958[/import]