Page 1 of 1

Read an image file

PostPosted: Mon Feb 04, 2008 1:57 pm
by asmodeus
Can anybody tell me how to read an image file, so that I can draw it with a canvas?

Re: Read an image file

PostPosted: Mon Feb 04, 2008 4:48 pm
by Thanx
Maybe you could use draw_from You'ld need another actor that has the animation, but you could put the actor out of view, or make it transparent. No better idea, unless there's a C function for loading images, which I'm sure there is, but I don't know what it is, or how to use it.

Re: Read an image file

PostPosted: Mon Feb 04, 2008 10:49 pm
by DilloDude
I made a function to load a BMP file (at least it works with one). Fuzzy made a TGA loader.
I'll test mine out a bit and then post it, if you want.

Re: Read an image file

PostPosted: Tue Feb 05, 2008 3:34 pm
by asmodeus
Thanx wrote:Maybe you could use draw_from You'ld need another actor that has the animation, but you could put the actor out of view, or make it transparent. No better idea, unless there's a C function for loading images, which I'm sure there is, but I don't know what it is, or how to use it.


Sorry, but I need to put the values of red, green, blue and maybe transpanrent in a variable.
The variable is called TEXTURE[10][5][4][100][100].
The first array (10) is for the texture number. For example for a floor of a wall. The second (5) is for the animation position. I want read different files to get the animation. The third (4) is for red (0), green (1), blue (2) and transparent (3).
The last to arrays (100) is for the pixel in the image.
So, this: TEXTURE[3][1][0][50][10] reads the red-value from the pixel x=50, y=10 of the texture number 3, first animation postition.

Re: Read an image file

PostPosted: Tue Feb 05, 2008 3:37 pm
by asmodeus
DilloDude wrote:I made a function to load a BMP file (at least it works with one). Fuzzy made a TGA loader.
I'll test mine out a bit and then post it, if you want.

If anybody has got an example, that should help me, please post an ged example, not only a script.

Re: Read an image file

PostPosted: Wed Feb 06, 2008 12:37 pm
by asmodeus
Maybe anybody can make a script to read XPMs. It is an image file which is written as a text.
This:
Code: Select all
/* XPM */
static char * example_xpm[] = {
"24 20 3 1",
"  c None",
". c #0000FF",
"+ c #FF0000",
"                        ",
"    ..                  ",
"   ....                 ",
"  ......++++++++        ",
" .........+++++++       ",
" ..........+++++++      ",
" ............++++++     ",
" .............++++++    ",
"  ..............++++    ",
"   +.............+++    ",
"   ++.............++    ",
"   +++.............+    ",
"   +++++.............   ",
"   ++++++.............. ",
"   ++++++++............ ",
"   +++++++++........... ",
"    +++++++++.........  ",
"     ++++++++++.......  ",
"      ++++++++++.....   ",
"       +++++++++ ...    "};

I can't upload XPMs here, so if you want to view it, copy the text in notepad or something like that and save it as *.xpm.

Re: Read an image file

PostPosted: Thu Feb 07, 2008 4:14 pm
by Fuzzy
xpm sounds a loot like PAM format or PPM. I'll look it up and maybe write something.

[edit]It looks like it gets complicated and messy with more than 16 colors. Is it possible to convert it? Maybe to PAM format? Do you need a text based format for GE or just simple?

Re: Read an image file

PostPosted: Thu Feb 07, 2008 4:37 pm
by asmodeus
I need any image file, that I can read and put the values in variables to draw it with a canvas.

Re: Read an image file

PostPosted: Thu Feb 07, 2008 7:06 pm
by Fuzzy
What size of images will you be working with? Oh, I see. 100x100.

I think your array is too complicated. You should just store the pixels as RGB instead of a palette and a look up value.

instead of TEXTURE[10][5][4][100][100].

try TEXTURE[10][5][400][100].

now you read 4 byte values from the TEXTURE and take the modulus of the position to get the [100][100]

TEXTURE[TexNum][Anim][Xval % 100][Yval] for example. Take this to an extreme and you can reduce some other dimensions of the array, which will require less loops and the program will run faster. Getting the R G B from that 400 is easy too. The same technique.. Xval % 4 will get you the red, Xval % 4 + 1 is green and Xval % 4 +2 is blue. Xval % 4 + 3 is the Alpha!

Re: Read an image file

PostPosted: Fri Feb 08, 2008 4:26 pm
by asmodeus
That sounds well. :D