I'll explain what I want.
Say that I have an image, PNG / JPEG / BMP, it doesn't really matter as I can manually convert the image to the format I want (i.e. PNG -> JPEG using painter).
I'd like to convert this image to an array, each organ contains RGB565 of each pixel of the image.
I'll send this array to the GLCD and it will show it on its display.
RB
I looked for RGB565 over google, but still haven't found any code implying to how to do it.
So do you need help understanding how jpeg compression works and how to read image files? Or do you need help how your GLCD works and how to display images on it? Or do you need help with C arrays and bit manipulation? What is this organ you talk about?
If you know VB it would be quite easy to load a picture in a picture box and use the point function to get the RGB values. A little shifting (dividing) would give you 565 and you can then write it out in any format you like. I assume source code would be best.
misterT
I read the link you posted, which is great.
I think you missed my point.
I need help with taking an image (JPEG / BMP / PNG, doesn't matter to me), and extracting from it an array which looks like that:
array[0] = RGB of pixel row 1, column 1
array [1] = RGB of pixel row 1, column 2
etc..
What I didn't manage to find yet it a function that does that.
you will never find it, this is simple data manipulation. those functions you write yourself.
i guess by "organ" you mean pixel.
you may make a structure for one pixel then make an array of that type...
don't know, maybe something like
Code:
// create custom data type for image, smallest image element is one RGB pixel
typedef struct image {
byte r;
byte g;
byte b;
} image;
// specify image size so we can adjust it in only one place when needed
#define img_row 32
#define img_col 32
#define img_size img_row*img_col
// now create an array to hold the image
image pixel[img_size];
// somewhere in program manipulate content of the image pixel by pixel
for (int i=0; i<img_size;i++){
pixel[i].r= 160;
pixel[i].g= 50;
pixel[i].b= 71 + i % 16;
}
Unfortunately, I guess I did not explain myself well again.
I'm looking for a function as follows:
- Input: Image file (any format you like - JPEG / PNG / GIF / BMP)
- Output: RGB Array (I'll handle any type of array structure).
In your function, I did not see where you transform the image file to an array i.e. I see you already assumed an array which represents the image file, and that is exactly that Part i'm missing.
just use any uncompressed format and you already have RGB values in order you ask. for example BMP format is very simple to use. header is tiny, you only need few values from it, after header you get data byte by byte:
R0,G0,B0,R1,G1,B1,R2,G2,B2...
where 0,1,2 etc represent pixel number.
if you need to compact this into RGB565 for example, you just shift values around to strip least significant bits.
You read the BMP file as a binary format. The header is at the beginning of the data and has a well defined structure. Google for bmp file structure. How you read the BMP file as binary depends on your hardware.. are you using SD card or something else to store the image?
Here is an image of that structure:
**broken link removed**
I read the format the guy showed there, however, the problem is that when I read the BMP image (using the code I attached above), I get for example several F's (i.e. FFFF) between the File type. Set to "BM" and the Size in BYTES of the file.
I don't get what is the problem.
That is the reading I get:
The file size is (642,806 bytes), meaning 0x09CEF6.
But what I read was: 424dfffffff6ffffffce900000...
I read the format the guy showed there, however, the problem is that when I read the BMP image (using the code I attached above), I get for example several F's (i.e. FFFF) between the File type. Set to "BM" and the Size in BYTES of the file.
I don't get what is the problem.
The file size is (642,806 bytes), meaning 0x09CEF6.
But what I read was: 424dfffffff6ffffffce900000...
File size is not the same as image size. File size is image size + header.
EDIT: I tried to track those hex values and could not come to a sane conclusion (I got image width of 4294967173 pixels [0xffffff85]). Maybe there is padding so that all the values are 32 bits wide, but that is only a guess. According to the link Ian posted, the third field should be a "reserved word set to zero".. and in your output I can't see eight zeros at that place..