Roku Developer Program

Developers and content creators—a complete solution for growing an audience directly.
cancel
Showing results for 
Search instead for 
Did you mean: 
squirreltown
Level 9

BuhByteArray

I am trying to send the contents of a bitmap as as byte array to a server to be re-constituted as a jpeg. The php file creates a jpg from known good data and it's also receiving my bad data fine. so the problem seems to be the data format i'm outputting from the roku.

so we start here:
thispainting= screen.GetByteArray(0, 0, 5, 5)
strx=thispainting.ToBase64String()
? strx
SendPaintingPost(strx)
The code the Roku outputs looks like this:
$data ='q6ur/6urq/+rq6v/q6ur/6urq/+rq6v/q6ur/6urq/+rq6v/q6ur/6urq/+rq6v/q6ur/6urq/+rq6v/q6ur/6urq/+rq6v/q6ur/6urq/+rq6v/q6ur/6urq/+rq6v/q6ur/w==';
and the good sample code i have looks like this:
$data = 'iVBORw0KGgoAAAANSUhEUgAAABwAAAASCAMAAAB/2U7WAAAABl'  //works
. 'BMVEUAAAD///+l2Z/dAAAASUlEQVR4XqWQUQoAIAxC2/0vXZDr'
. 'EX4IJTRkb7lobNUStXsB0jIXIAMSsQnWlsV+wULF4Avk9fLq2r'
. '8a5HSE35Q3eO2XP1A1wQkZSgETvDtKdQAAAABJRU5ErkJggg==';
See how one of these things is not like the other?
This is the PHP thats making the jpeg.
$data = base64_decode($data);
$im = imagecreatefromstring($data);
Any ideas would be appreciated. Thanks
Kinetics Screensavers
0 Kudos
25 Replies
Roku Employee
Roku Employee

Re: BuhByteArray

GetByteArray returns pixels (color values), not JPEG data, so if your server is expecting to be passed a JPEG encoded data blob it isn't going to work.

http://sdkdocs.roku.com/display/sdkdoc/ ... erasObject :

ifDraw2D GetByteArray(x as Integer, y as Integer, width as Integer, height as Integer) as Object

Returns an roByteArray representing the 32 bit RGBA pixel values for the rectangle described by the parameters.
0 Kudos
RokuMarkn
Level 7

Re: BuhByteArray

Also, even if the server accepted an RGBA bitmap, the server is doing a base64 decode so you would need to do a base64 encode on the Roku before sending it. That's why your data doesn't look like the sample data.

--Mark
0 Kudos
squirreltown
Level 9

Re: BuhByteArray

"RokuMarkn" wrote:
Also, even if the server accepted an RGBA bitmap, the server is doing a base64 decode so you would need to do a base64 encode on the Roku before sending it. That's why your data doesn't look like the sample data.

--Mark


OK, so what is this
strx=thispainting.ToBase64String()
doing then? Is it not an encode?

KC - So is this php
$im = imagecreatefromstring($data);
expecting jpeg encoded data? Because you can do either imagejpeg(' ') or imagepng(' ') after this to make a file.

Either one of you care to make a suggestion on how I might make it work?

Thanks.
Kinetics Screensavers
0 Kudos
RokuMarkn
Level 7

Re: BuhByteArray

Sorry, I didn't notice the encode. But the $data= line you quoted doesn't look like it was printed on the Roku. That looks like piece of PHP code. However if the string in quotes is what the Roku is printing, then it's fine. It's a valid base64 string representing 25 words of &hABABABFF.

I've never used it but according to the PHP doc, imagecreatefromstring accepts JPEG, PNG, GIF, WBMP, and GD2. There may be some tools on your server that would help convert a raw bitmap to one of those file types.

--Mark
0 Kudos
Roku Employee
Roku Employee

Re: BuhByteArray

"squirreltown" wrote:

KC - So is this php
$im = imagecreatefromstring($data);
expecting jpeg encoded data? Because you can do either imagejpeg(' ') or imagepng(' ') after this to make a file.


I can only guess about the PHP code. FWIW your example good $data appears to be PNG file data.

You might look into whether the server can accept raw pixel data, in which case I imagine you would also need to pass the dimensions.
Or BMP format, which is also fairly easy to generate a header for it followed by the pixel data.

Is your intent to send a full screen image, at 1280 x 720? Or just a small part of it?
If you are sending a full screen image, without compression it would be pretty big (3.5 MB?).

It seems what you really want is a Roku 2D API that gives you PNG or JPEG output, but that is not available.
0 Kudos
squirreltown
Level 9

Re: BuhByteArray

"RokuMarkn" wrote:
Sorry, I didn't notice the encode. But the $data= line you quoted doesn't look like it was printed on the Roku. That looks like piece of PHP code.Mark

Well i just copied what the roku printed from the console and enclosed it with data=' and '; . At this point i'm just pasting the data into the php file its easier then sending it each time until it works.

"RokuKC" wrote:
It seems what you really want is a Roku 2D API that gives you PNG or JPEG output, but that is not available.

You sure hit that nail on the head.

"RokuKC" wrote:
Is your intent to send a full screen image, at 1280 x 720? Or just a small part of it?
If you are sending a full screen image, without compression it would be pretty big (3.5 MB?).


Yea, thats the end game. It wouldn't happen often. I have a function that makes a decent "painting" out of a photgraph. It would have a lot more promise if i could get the silly image out of the Roku.
Kinetics Screensavers
0 Kudos
Roku Employee
Roku Employee

Re: BuhByteArray

"squirreltown" wrote:

Either one of you care to make a suggestion on how I might make it work?


I'm not a PHP developer, but spurred by Mark's comment looked at PHP docs briefly...

Looks like if you had to, on the server you could do $img = imagecreatetruecolor( $w, $h ) to allocate an image buffer,
then walk over all the pixels and set them from the input pixel data using imagesetpixel.

I imagine there may be more efficient approaches though, browsing PHP docs or internet search may provide options.
0 Kudos
squirreltown
Level 9

Re: BuhByteArray

"RokuKC" wrote:
Looks like if you had to, on the server you could do $img = imagecreatetruecolor( $w, $h ) to allocate an image buffer,
then walk over all the pixels and set them from the input pixel data using imagesetpixel.

I imagine there may be more efficient approaches though, browsing PHP docs or internet search may provide options.


OK thanks I'll have a look.
Kinetics Screensavers
0 Kudos
squirreltown
Level 9

Re: BuhByteArray

Well I got this working to some degree. I used KC's suggestion about imagesetpixel. The size limit seems to about 350 x 350 at this point, not sure if my servers POST data limit is affecting that but i'm checking, also switching to base64 from the hex string I'm using now would save 40% on the number of characters sent.
The server builds the .jpg at that size pretty fast, as fast as i can refresh my ftp app once the Roku says its sent.
I will say it feels pretty ridiculous to be doing it this way, with pony-express era technology, almost as ridiculous as having to record my own Roku sounds when they are already in the box.
Please Roku implement this feature, just because you all can't see a good reason for some feature, doesn't mean someone else can't. Everyone wins if you just make things available.
Kinetics Screensavers
0 Kudos