Read an image file

Game Editor comments and discussion.

Read an image file

Postby asmodeus » Mon Feb 04, 2008 1:57 pm

Can anybody tell me how to read an image file, so that I can draw it with a canvas?
User avatar
asmodeus
 
Posts: 483
Joined: Thu Oct 11, 2007 5:04 pm
Location: Germany
Score: 43 Give a positive score

Re: Read an image file

Postby Thanx » Mon Feb 04, 2008 4:48 pm

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.
http://www.youtube.com/watch?v=XyXexDJBv58
http://www.youtube.com/watch?v=Be4__gww1xQ
These are me and playing the piano (second one with a friend/fellow student)
Hope you watch and enjoy!
User avatar
Thanx
 
Posts: 314
Joined: Sat Jan 26, 2008 10:07 pm
Location: Home sweet home! :)
Score: 24 Give a positive score

Re: Read an image file

Postby DilloDude » Mon Feb 04, 2008 10:49 pm

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.
Image
User avatar
DilloDude
 
Posts: 866
Joined: Tue Jan 24, 2006 9:51 am
Location: Nyerellion
Score: 58 Give a positive score

Re: Read an image file

Postby asmodeus » Tue Feb 05, 2008 3:34 pm

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.
Attachments
graphic.png
User avatar
asmodeus
 
Posts: 483
Joined: Thu Oct 11, 2007 5:04 pm
Location: Germany
Score: 43 Give a positive score

Re: Read an image file

Postby asmodeus » Tue Feb 05, 2008 3:37 pm

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.
User avatar
asmodeus
 
Posts: 483
Joined: Thu Oct 11, 2007 5:04 pm
Location: Germany
Score: 43 Give a positive score

Re: Read an image file

Postby asmodeus » Wed Feb 06, 2008 12:37 pm

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.
Attachments
test.png
This is the image as PNG.
test.png (255 Bytes) Viewed 1587 times
User avatar
asmodeus
 
Posts: 483
Joined: Thu Oct 11, 2007 5:04 pm
Location: Germany
Score: 43 Give a positive score

Re: Read an image file

Postby Fuzzy » Thu Feb 07, 2008 4:14 pm

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?
Mortal Enemy of IF....THEN(and Inspector Gadget)

Still ThreeFingerPete to tekdino
User avatar
Fuzzy
 
Posts: 1068
Joined: Thu Mar 03, 2005 9:32 am
Location: Plymostic Programmer
Score: 95 Give a positive score

Re: Read an image file

Postby asmodeus » Thu Feb 07, 2008 4:37 pm

I need any image file, that I can read and put the values in variables to draw it with a canvas.
User avatar
asmodeus
 
Posts: 483
Joined: Thu Oct 11, 2007 5:04 pm
Location: Germany
Score: 43 Give a positive score

Re: Read an image file

Postby Fuzzy » Thu Feb 07, 2008 7:06 pm

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!
Mortal Enemy of IF....THEN(and Inspector Gadget)

Still ThreeFingerPete to tekdino
User avatar
Fuzzy
 
Posts: 1068
Joined: Thu Mar 03, 2005 9:32 am
Location: Plymostic Programmer
Score: 95 Give a positive score

Re: Read an image file

Postby asmodeus » Fri Feb 08, 2008 4:26 pm

That sounds well. :D
User avatar
asmodeus
 
Posts: 483
Joined: Thu Oct 11, 2007 5:04 pm
Location: Germany
Score: 43 Give a positive score


Return to GE - General

Who is online

Users browsing this forum: No registered users and 1 guest

cron