Page 1 of 2

paint image reading(for painter version 2.2 and up)

PostPosted: Wed Jun 13, 2007 2:29 am
by Sgt. Sparky
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.)

PostPosted: Fri Jun 15, 2007 2:59 pm
by KingCupons
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?

PostPosted: Sat Jun 16, 2007 3:44 pm
by morcior
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.

PostPosted: Tue Jun 19, 2007 5:08 am
by Sgt. Sparky
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.)

PostPosted: Tue Jun 19, 2007 5:10 am
by Sgt. Sparky
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

PostPosted: Tue Jun 19, 2007 1:19 pm
by morcior
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.

PostPosted: Tue Jun 19, 2007 6:35 pm
by Sgt. Sparky
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. :(

PostPosted: Tue Jun 19, 2007 9:42 pm
by morcior
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);

PostPosted: Wed Jun 20, 2007 11:37 pm
by Sgt. Sparky
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

PostPosted: Fri Jun 22, 2007 4:30 pm
by morcior
what?

i was demonstrating that a char is numeric, like an int. you're not supposed to use that code lol!

PostPosted: Mon Jun 25, 2007 4:21 pm
by Sgt. Sparky
I am completely confused now, I have not even tried my code with replacing int with char.....
what are you talking about?...

PostPosted: Sun Jul 15, 2007 2:22 am
by kyensoftware
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??

PostPosted: Sun Jul 15, 2007 5:59 am
by Fuzzy
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.

PostPosted: Mon Jul 16, 2007 3:23 am
by Sgt. Sparky
char can also store negative numbers from I think -255, I only tested it with -174. :D

Most code

PostPosted: Tue Jul 17, 2007 9:32 am
by kyensoftware
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.)