leJOS EV3 image format

This is where you talk about the EV3 software itself, installation issues, and programming talk.

Moderators: roger, gloomyandy, skoehler

leJOS EV3 image format

Postby onamali » Wed Aug 28, 2013 11:23 pm

Thanks for your help in the other thread with SSH, I'll recreate my sd card tomorrow.

I'm working with the Image library now, I used it on the NXT some time ago (> 2 years). I wrote a script to convert a PNG to bytes for that and it worked just fine. But when I dropped them bytes into the EV3 program, it came out garbled. Did the algorithm change? I didn't find a tool to convert images, do you have one?

Thanks
Mark
onamali
New User
 
Posts: 8
Joined: Wed Aug 28, 2013 9:10 pm

Re: Writing programs for the EV3

Postby gloomyandy » Thu Aug 29, 2013 1:00 am

The format of images on the EV3 is different to those on the NXT. The I did update the leJOS image tool to handle this but I've not checked that code into git yet. I'm in the middle of some major changes and can't really push the changes at the moment. Did your script use the old NXT image conversion tool?

On the NXT each image byte represented 8 pixels running down the screen. So if the image was say 10 pixels wide and 6 pixels high then it would use 10 bytes with byte 0 containing the first pixel for each of the six rows. On the EV3 things are more conventional. The first byte contains the first 8 pixels of the first row, the second the next 8 pixels etc. The left most pixel is bit 0 (I think not 100% sure).

Andy
User avatar
gloomyandy
leJOS Team Member
 
Posts: 4240
Joined: Fri Sep 28, 2007 2:06 pm
Location: UK

Re: Writing programs for the EV3

Postby onamali » Thu Aug 29, 2013 10:04 pm

Thanks for the info, after quite some hackery I got it working.

The image spec is now:
It starts on the uppermost row at the left side
It reads in 8 pixels at a time, with the least significant bit being the first pixel.
When it reaches the end of the row it 'continues' beyond that image row with hidden pixels until it reaches an even byte. (01010101, never 01010)
It then starts on the 2nd row in the same way.

I have big plans for the EV3, have been testing it out a lot and am finding it really nice to work with.
onamali
New User
 
Posts: 8
Joined: Wed Aug 28, 2013 9:10 pm

Re: Writing programs for the EV3

Postby gloomyandy » Fri Aug 30, 2013 10:14 am

Hi,
Glad you got it working. However I'm not sure about the need to nave an even number of pixels. As far as I am aware that is not the case. Can you provide details of why you think it is? What test case have you been using?

Andy
User avatar
gloomyandy
leJOS Team Member
 
Posts: 4240
Joined: Fri Sep 28, 2007 2:06 pm
Location: UK

Re: leJOS EV3 image format

Postby onamali » Fri Aug 30, 2013 11:35 pm

Sorry, I think I picked the wrong word...I mean until it reaches a 'full byte'. Though you can kind of ignore it. It's hard to explain really.

If we have an image that is 11pixels wide, and it has this pattern on the first row
10101010100
then the image format would take the first 8 pixels (10101010) and reverse it (because pixel 0 is the least sig. bit) and convert it to hex (01010101 -> 0x55)
then it would take the last 3 pixels (100) and reverse it (001) and convert to hex (0x01)

So you can kind of ignore the hidden pixels description. Just remember that you start a new line with a new byte. << a better description?

___________________________________________________
A link to the image I created, more hackery to come soon (currently building EV3RSTORM)

https://www.facebook.com/photo.php?fbid ... 095&type=1
onamali
New User
 
Posts: 8
Joined: Wed Aug 28, 2013 9:10 pm

Re: leJOS EV3 image format

Postby gloomyandy » Fri Aug 30, 2013 11:58 pm

Yep that makes sense. Glad it is all working!
User avatar
gloomyandy
leJOS Team Member
 
Posts: 4240
Joined: Fri Sep 28, 2007 2:06 pm
Location: UK

Re: leJOS EV3 image format

Postby skoehler » Sun Sep 01, 2013 9:40 am

onamali wrote:If we have an image that is 11pixels wide, and it has this pattern on the first row
10101010100
then the image format would take the first 8 pixels (10101010) and reverse it (because pixel 0 is the least sig. bit) and convert it to hex (01010101 -> 0x55)
then it would take the last 3 pixels (100) and reverse it (001) and convert to hex (0x01)


Or in other words, the i-th pixel (i=0 being the first) is represented by the (i%8)-th bit (the 0-th bit being the least significant) of the (i/8)-th byte, right?
skoehler
leJOS Team Member
 
Posts: 1458
Joined: Thu Oct 30, 2008 4:54 pm

Re: leJOS EV3 image format

Postby epascual » Sun Nov 03, 2013 10:14 pm

Hello,

I don't know if this can help somebody, but in case of, I've written a small utility which takes a black and white graphic file and produces the Java source code corresponding to the image in EV3 format. In the current version, the output is packaged in an independent file implementing a class containing the image bytes as static data. It looks like this :
Code: Select all
import javax.microedition.lcdui.Image;

// Generated on 2013-11-03 22:42:17 from file pobot-logo-small-bw.png

public class LogoImage {
    static public final Image image = new Image(128, 118, new byte[]{
        (byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x80,
        (byte)0x07,(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00,
[...]
    });
}


You just have to add this source file to your project and use its content like this :
Code: Select all
final Image logo = LogoImage.image;


Here is its embedded help:
Code: Select all
usage: make_ev3_image.py [-h] [--class-name CLASS_NAME]
                         [--package PACKAGE_NAME]
                         [--output-format {java,resource}]
                         infile

Converts a graphic file into an EV3 image.

positional arguments:
  infile                input graphic file

optional arguments:
  -h, --help            show this help message and exit
  --class-name CLASS_NAME
                        the name of the generated class (default: EV3Image)
  --package PACKAGE_NAME
                        name of the parent package (default: None)
  --output-format {java,resource}
                        output format selector (default: java)


The tool is written in Python and weights only 130 lines, including blank and wrapped ones, and there is no black magic inside. I'm planning to add the implementation of a generator of a binary resource file which can be loaded from the application jar afterwards, and also some options to make it possible to process grey level images too.

If you want to know more about it and maybe download the code, have a look at our website.

Sorry, the article is written in French but Google is able to translate it (more or less)... I'll put an English version online as soon as I'll find some spare time to write it.

Best regards

Eric
Eric PASCUAL - POBOT association VP & co-founder - http://www.pobot.org
epascual
Active User
 
Posts: 123
Joined: Sun Jan 17, 2010 12:15 am
Location: Sophia-Antipolis (France)

Re: leJOS EV3 image format

Postby epascual » Mon Nov 04, 2013 11:59 pm

I've updated the tool described above, and it is now able to generate a binary file containing the image data too.

The related article and its companion showing an example of usage have been updated too.
Eric PASCUAL - POBOT association VP & co-founder - http://www.pobot.org
epascual
Active User
 
Posts: 123
Joined: Sun Jan 17, 2010 12:15 am
Location: Sophia-Antipolis (France)

leJOS EV3 image format

Postby Goreva » Sat Dec 07, 2013 2:20 pm

Ok I am tryign to use UnDelphiX from Turbo and Im having a slight problem using PNG and GIF images.

I have TPNGOnject and TGIFObject instaleld and they work fine for the normal TImage component.. But is there a way of doing this for UnDelphiX? Because It wont let me use a png it just shows up all black with high FPS because its displayign no tiles on the map.
современная-урология.рф болезни почек лечение
Goreva
New User
 
Posts: 2
Joined: Wed Nov 27, 2013 11:11 am
Location: Россия

Re: leJOS EV3 image format

Postby epascual » Sat Dec 07, 2013 2:58 pm

Hi Goreva,

I'm not sure to understand how your question relates to the topic. What are you trying to with Delphi and the EV3 ?
Eric PASCUAL - POBOT association VP & co-founder - http://www.pobot.org
epascual
Active User
 
Posts: 123
Joined: Sun Jan 17, 2010 12:15 am
Location: Sophia-Antipolis (France)


Return to EV3 Software

Who is online

Users browsing this forum: No registered users and 2 guests

more stuff