paint image reading(for painter version 2.2 and up)

You must understand the Game Editor concepts, before post here.

paint image reading(for painter version 2.2 and up)

Postby Sgt. Sparky » Wed Jun 13, 2007 2:29 am

here is an image reading function I made so you can use my painter images in a game,
link: http://game-editor.com/forum/tp-3662-Pa ... aker-.html
to start off:
put this code in the global code area,
Code: Select all
void readpaint(char filename[255], int size, int clr1, int clr2, int clr3, int clr4)
{
FILE*bmp;
int image01[36][36];
int image101[36][36];
int image201[36][36];
int i, i2;
erase(clr1, clr2, clr3, clr4);
i = 0;
for(i = 0; i < 36; i++)
{
    i2 = 0;
 
    for(i2 = 0; i2 < 36; i2++)
    {
        image01[i][i2] = -1;
        image101[i][i2] = -1;
        image201[i][i2] = -1;
    }
}
bmp = fopen(filename, "r+b");
fread(image01, sizeof(image01), 1, bmp);
fread(image101, sizeof(image101), 1, bmp);
fread(image201, sizeof(image201), 1, bmp);
fclose(bmp);
i = 0;
for(i = 0; i < 36; i++)
{
    i2 = 0;
    for(i2 = 0; i2 < 36; i2++)
    {
        if(image01[i][i2] > -1)
        {
        if(image01[i][i2] < 255 && image101[i][i2] < 255 && image201[i][i2] < 255)
        {
        setpen(image01[i][i2], image101[i][i2], image201[i][i2], 0, size);
        putpixel(i * size, i2 * size);
        }
        }
    }
}
}
//(c) Sgt Games 2007 by Sgt. Sparky

for use on any event you must place the image in the same folder or a folder near by,
its just like loading a variable.
here is the function in use taken apart:
Code: Select all
readpaint("your file name.paint", image size 5 is default, colourtoreplacewhiteR, colourtoreplacewhiteG, colourtoreplacewhiteB, colourtoreplacewhitetransparency);

another examle with using a transparent background(will replace white.) and the default size of 5(the image as you draw it.) and the image name of player_left_01,
Code: Select all
readpaint("player_left_01.paint", 5, 0, 0, 0, 1);

:D
I will make a game of all painter images soon, and I will post the source. :D
and I will make a painter animator as well. :D
(All I must do is modify the image writing and reading which is alot more complex than the plain image reading function because of the way I read pixels and with the undo everything.)
Image
Random Links:
viewtopic.php?p=19474#19474
Right now (10/14/2009) I'm working on some C++ projects, but I might be able to help if you have some Game Editor questions. :)
User avatar
Sgt. Sparky
 
Posts: 1850
Joined: Sat Oct 07, 2006 5:28 pm
Location: Somewhere out there, beneath the pale blue sky...
Score: 236 Give a positive score

Postby KingCupons » Fri Jun 15, 2007 2:59 pm

Okay. I don't know if it's just me, but I was just ready to accept my inability to use the Painter program for the Game Editor. Then when I saw this, I got excited. Now that I've worked with this, I have absolutely no idea what to do. I feel as if a few steps were left out of the instructions. Help some people who don't know a whole lot of code, please.

Somebody?
KingCupons
 
Posts: 2
Joined: Fri Jun 15, 2007 10:20 am
Score: 0 Give a positive score

Postby morcior » Sat Jun 16, 2007 3:44 pm

Sorry to have to always point out the obvious sparky, but WHY OH WHY are you using ints to store individual color components?

The Red, Green, Blue and Alpha components of each pixel are values from 0-255 so a char is a much more suitable data type and will instantly reduce the size of the image files your 'paint' program produces by 50%

You should also think of adding a simple 2 integer header (width/height) to the file so that images of different sizes can be loaded/saved seamlessly.
morcior
 
Posts: 83
Joined: Fri Jan 12, 2007 12:16 am
Location: UK
Score: 9 Give a positive score

Postby Sgt. Sparky » Tue Jun 19, 2007 5:08 am

KingCupons wrote:Okay. I don't know if it's just me, but I was just ready to accept my inability to use the Painter program for the Game Editor. Then when I saw this, I got excited. Now that I've worked with this, I have absolutely no idea what to do. I feel as if a few steps were left out of the instructions. Help some people who don't know a whole lot of code, please.

Somebody?

press the script button,
then click on global code,
then you can add this code to it and put somthing like readpaint(); for the name of the code(in the smaller grey box.). :D
(my post describes how to use this as well.)
Last edited by Sgt. Sparky on Tue Jun 19, 2007 6:39 pm, edited 1 time in total.
Image
Random Links:
viewtopic.php?p=19474#19474
Right now (10/14/2009) I'm working on some C++ projects, but I might be able to help if you have some Game Editor questions. :)
User avatar
Sgt. Sparky
 
Posts: 1850
Joined: Sat Oct 07, 2006 5:28 pm
Location: Somewhere out there, beneath the pale blue sky...
Score: 236 Give a positive score

Postby Sgt. Sparky » Tue Jun 19, 2007 5:10 am

morcior wrote:Sorry to have to always point out the obvious sparky, but WHY OH WHY are you using ints to store individual color components?

The Red, Green, Blue and Alpha components of each pixel are values from 0-255 so a char is a much more suitable data type and will instantly reduce the size of the image files your 'paint' program produces by 50%

You should also think of adding a simple 2 integer header (width/height) to the file so that images of different sizes can be loaded/saved seamlessly.

I was just trying to make a simple to understand version,
but why are you always flaming me?? :|
EDIT: the file is about 16 kb which is still small for an image. :D
Image
Random Links:
viewtopic.php?p=19474#19474
Right now (10/14/2009) I'm working on some C++ projects, but I might be able to help if you have some Game Editor questions. :)
User avatar
Sgt. Sparky
 
Posts: 1850
Joined: Sat Oct 07, 2006 5:28 pm
Location: Somewhere out there, beneath the pale blue sky...
Score: 236 Give a positive score

Postby morcior » Tue Jun 19, 2007 1:19 pm

Sparky, I'm just trying to help you learn.

I was just trying to make a simple to understand version,

Using the word "char" instead of "int", I doubt makes your code any harder to understand.

EDIT: the file is about 16 kb which is still small for an image.

Proper bmp format --the largest uncompressed format you could possibly save in-- would make a 36x36 image in 3.8kb, proving that your format is wasting a lot of disk space. It makes files more than 4 times larger than they need to be! A single 2048x1152 photo in this format would be close to 40 megabytes!!!!

I told you an extremely simple way to reduce the size of your images by 75%, to speed up loading by 75% and to reduce the memory usage of your code by 75% by changing 3 words from "int" to "char" - its not a 'flame', its advice.
morcior
 
Posts: 83
Joined: Fri Jan 12, 2007 12:16 am
Location: UK
Score: 9 Give a positive score

Postby Sgt. Sparky » Tue Jun 19, 2007 6:35 pm

oh,
I though you were suggesting changing the reading from one solid string that would be read a different way ect.

sorry, I did not know that is what you ment. :oops: :De
EDIT: but GE would not exept reading a char value to set the pen colour ect. :(
Image
Random Links:
viewtopic.php?p=19474#19474
Right now (10/14/2009) I'm working on some C++ projects, but I might be able to help if you have some Game Editor questions. :)
User avatar
Sgt. Sparky
 
Posts: 1850
Joined: Sat Oct 07, 2006 5:28 pm
Location: Somewhere out there, beneath the pale blue sky...
Score: 236 Give a positive score

Postby morcior » Tue Jun 19, 2007 9:42 pm

a char is a numeric value with range 0-255. GE will have no problems

Code: Select all
char i = 10;

setpen(255,255,255, i);
morcior
 
Posts: 83
Joined: Fri Jan 12, 2007 12:16 am
Location: UK
Score: 9 Give a positive score

Postby Sgt. Sparky » Wed Jun 20, 2007 11:37 pm

morcior wrote:a char is a numeric value with range 0-255. GE will have no problems

Code: Select all
char i = 10;

setpen(255,255,255, i);

the size changes depending on what you want it to be. :P
and the there are four values when setting a pen size, but oh well.
sorry if I sound rude, I am just trying to type fast! :D
Image
Random Links:
viewtopic.php?p=19474#19474
Right now (10/14/2009) I'm working on some C++ projects, but I might be able to help if you have some Game Editor questions. :)
User avatar
Sgt. Sparky
 
Posts: 1850
Joined: Sat Oct 07, 2006 5:28 pm
Location: Somewhere out there, beneath the pale blue sky...
Score: 236 Give a positive score

Postby morcior » Fri Jun 22, 2007 4:30 pm

what?

i was demonstrating that a char is numeric, like an int. you're not supposed to use that code lol!
morcior
 
Posts: 83
Joined: Fri Jan 12, 2007 12:16 am
Location: UK
Score: 9 Give a positive score

Postby Sgt. Sparky » Mon Jun 25, 2007 4:21 pm

I am completely confused now, I have not even tried my code with replacing int with char.....
what are you talking about?...
Image
Random Links:
viewtopic.php?p=19474#19474
Right now (10/14/2009) I'm working on some C++ projects, but I might be able to help if you have some Game Editor questions. :)
User avatar
Sgt. Sparky
 
Posts: 1850
Joined: Sat Oct 07, 2006 5:28 pm
Location: Somewhere out there, beneath the pale blue sky...
Score: 236 Give a positive score

Postby kyensoftware » Sun Jul 15, 2007 2:22 am

Im sorry, but how does int work then??
A range of 0-255 in 6502, ARM and heaps of other processors is a BYTE.
I thought char was like string??
Games for Windows, Linux, and PPC
Bin dosnt stand for "Binary";
it stands for Bin.
You know, where the junk goes...
User avatar
kyensoftware
 
Posts: 198
Joined: Thu Oct 26, 2006 7:49 am
Score: 5 Give a positive score

Postby Fuzzy » Sun Jul 15, 2007 5:59 am

a char is a signed 8 bit number. it ranges from 0-127 and from -1 to -128. The first 128(0-127) numbers are used to represent the basic ascii character set, and the other 128 are for the extended characters.

For example, char(64) == 'd'
also char('d') = 64;

an array of chars is a string.

char ThreeD[3] = {'d','d','d'};
which is the same as

string ThreeD = "ddd";

Note that a string appends '/0', an extra character, to the end, which tells the compiler(GE in this case) that the string is done. You just dont ever see it.

Hope that clears it up.
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

Postby Sgt. Sparky » Mon Jul 16, 2007 3:23 am

char can also store negative numbers from I think -255, I only tested it with -174. :D
Image
Random Links:
viewtopic.php?p=19474#19474
Right now (10/14/2009) I'm working on some C++ projects, but I might be able to help if you have some Game Editor questions. :)
User avatar
Sgt. Sparky
 
Posts: 1850
Joined: Sat Oct 07, 2006 5:28 pm
Location: Somewhere out there, beneath the pale blue sky...
Score: 236 Give a positive score

Most code

Postby kyensoftware » Tue Jul 17, 2007 9:32 am

Most bytes is UNsigned...
I asked how INTEGERS work.
also, i dont understand double.
I thought the C64 was a good place to start learning...should I have bought the Apple ][?? I hate apple. mouldy.
I will only play games on C64 then...
I just use strings...
and char goes to 255.
mine went to 256 using a Draw actor>charcoal += 2.
GE's chars are emulated.
Besides, it is 32-bit windows here! 16-bit GP2X! (due to DS being same type chip.)
Games for Windows, Linux, and PPC
Bin dosnt stand for "Binary";
it stands for Bin.
You know, where the junk goes...
User avatar
kyensoftware
 
Posts: 198
Joined: Thu Oct 26, 2006 7:49 am
Score: 5 Give a positive score

Next

Return to Advanced Topics

Who is online

Users browsing this forum: No registered users and 1 guest