pixel_to_vec returns wrong color

Posted By: Scorpion

pixel_to_vec returns wrong color - 03/16/08 15:26

hello,
I played around with pixel_to_vec a bit and I found out, that I alwas returns 0 at the blue chanel, red and green behave normally.

This lines(in a loop) for example give me a yellow picture:

Code:
vec_set(pixelColor,vector(255,255,255));
pixel = pixel_for_vec(pixelColor,100,format);
pixel_to_bmap(outputBMP,x,y,pixel);



Cheers
Scorpion
Posted By: jcl

Re: pixel_to_vec returns wrong color - 03/16/08 17:39

Yellow is blue plus green. Getting a yellow image with 0 in the blue channel is physically impossible.

The most frequent mistake of people trying to write into a bitmap is using a wrong format.
Posted By: Scorpion

Re: pixel_to_vec returns wrong color - 03/16/08 19:40

yellow is red + green..sorry to disappoint you there lol^^



edit: i checked the format it's 8888....the target and the destination bmap
Posted By: tindust

Re: pixel_to_vec returns wrong color - 03/16/08 23:53

It's been a while since I worked with this, but it has to do with the order in which the colors are listed in the vector. For bitmap it is red-green-blue so using vec_set then you need to begin the vector with red, for example vec_set(colorvector.x,your.red). But when accessing or setting the color vector of a pixel, the color order is blue-green-red. The vector is then set through colorvector.blue. A conversion step from bmap vector to pixelvector is needed otherwise you "loose" a color which you seem to have done since the vector used begins with the second color. The last color value, the lost one, is set to zero. It took a while before I realized what was going on when working with this.

Hope this makes sense.

cheers,
Posted By: Scorpion

Re: pixel_to_vec returns wrong color - 03/17/08 00:01

as you can see i set the vector to 255,255,255 so the order isn't important
Posted By: jcl

Re: pixel_to_vec returns wrong color - 03/17/08 09:55

You're right with the red plus green. But I can still not confirm your problem.

pixel_to_vec is a frequently used function, but we haven't heard that any other user had problems with it so far. Check the the format with bmap_lock. Make sure that it's really 8888 and not 888, which would explain your problem.

If you can't find the problem this way, please send a test project to the support. We'll check.
Posted By: jcl

Re: pixel_to_vec returns wrong color - 03/18/08 13:28

The reason for your problem is a wrong type of your pixel parameter. You used int but the function expects var. Converting var to int loses the fractional part of the number, which in turn leads to wrong colors.

You can find a description of the difference of int and var in the manual under "Variables".
Posted By: Scorpion

Re: pixel_to_vec returns wrong color - 03/19/08 14:20

hm ok, thank you. I didn'T noticed that I defined it as int.
Controled everything, but the type of the variable X/
© 2024 lite-C Forums