1 registered members (Ayumi),
1,170
guests, and 2
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
[SOLVED]Pixel_to_vec() is crashing engine?
#348697
11/29/10 17:44
11/29/10 17:44
|
Joined: Aug 2005
Posts: 238
Caermundh
OP
Member
|
OP
Member
Joined: Aug 2005
Posts: 238
|
Hi!
I am attempting to write an sub-routine that will read a pixel from a bitmap based on the position of the mouse and give me a return value based on the color of that pixel. here is what I have so far:
function get_pixel_color() {var x_coord = integer(mouse_pos.x*(bmap_width(my_bmap)/screen_size.x)); var y_coord = integer(mouse_pos.y*(bmap_height(my_bmap)/screen_size.y)); var pixel; COLOR* pixel_color; if(x_coord>bmap_width(my_bmap)||x_coord<0) { return(-1); } if(y_coord>bmap_height(my_bmap)||y_coord<0) { return(-1); } bmap_lock(my_bmap,0); pixel = pixel_for_bmap(my_bmap,x_coord,y_coord); bmap_unlock(my_bmap); pixel_to_vec(pixel_color,NULL,8888,pixel); if(pixel_color.red) { if(pixel_color.red>245&&pixel_color.red<255) { return(0); } } return(-1) }
The routine works fine - x_coord and y_coord are always co-ordinates within the bmap and pixel_for_bmap() is returning the pixel it is supposed to. However, when I execute the pixel_to_vec() command, the game crashes.
I tested the return value from bmap_lock and it is 8888, indicating that it is locking a 32-bit tga file with an alpha channel - which is curious becuse the bmap im reading from was created in photshop and saved as a 24-bit tga file with no alpha channel.
Am I feeding pixel_to_vec a bad pixel value? or maybe im feeding some bad value for one of the other parameters? Is bmap_lock misreading the bmap and thats whats causing problems? why would pixel_to_vec() crash the engine like this?
Last edited by Caermundh; 11/30/10 05:39.
|
|
|
Re: Pixel_to_vec() is crashing engine?
[Re: Caermundh]
#348738
11/30/10 00:00
11/30/10 00:00
|
Joined: Jul 2008
Posts: 1,178 England
MrGuest
Serious User
|
Serious User
Joined: Jul 2008
Posts: 1,178
England
|
sorry only read half the thread. Should var x_coord = integer(mouse_pos.x*(bmap_width(my_bmap)/screen_size.x)); be var x_coord = integer(mouse_pos.x+[(bmap_width(my_bmap)/screen_size.x)); I'm using a function (hopefully) similar to what you're trying to achieve
void av_colorChange(var id, PANEL* pnl){
var min_x, min_y, max_x, max_y;
BMAP* bmp;
switch(id){
case 1: //color pallette
min_x = pnl.pos_x + 6;
min_y = pnl.pos_y + 42;
max_x = pnl.pos_x + 6 + bmap_width(bmp_avColorPallette);
max_y = pnl.pos_y + 42 + bmap_height(bmp_avColorPallette);
bmp = bmp_avColorPallette;
break;
case 2: //skin pallette
min_x = pnl.pos_x + 6;
min_y = pnl.pos_y + 130;
max_x = pnl.pos_x + 6 + bmap_width(bmp_avSkinPallette);
max_y = pnl.pos_y + 130 + bmap_height(bmp_avSkinPallette);
bmp = bmp_avSkinPallette;
break;
case 3: //pattern color pallette
min_x = pnl.pos_x + 6;
min_y = pnl.pos_y + 322;
max_x = pnl.pos_x + 6 + bmap_width(bmp_avColorPallette);
max_y = pnl.pos_y + 322 + bmap_height(bmp_avColorPallette);
bmp = bmp_avColorPallette;
break;
}
var format = bmap_lock(bmp, 0), pixel;
VECTOR vec_temp;
while(mouse_left){
if((mouse_pos.x >= min_x) && (mouse_pos.x < max_x)){
if((mouse_pos.y >= min_y) && (mouse_pos.y < max_y)){
pixel = pixel_for_bmap(bmp, mouse_pos.x - min_x, mouse_pos.y - min_y);
}
}
pixel_to_vec(vec_temp, NULL, format, pixel);
vec_temp.x /= 256;
vec_temp.y /= 256;
vec_temp.z /= 256;
switch(id){
case 1: case 2:
vec_set(var_avArea[0], vector(vec_temp.z, vec_temp.y, vec_temp.x));
break;
case 3:
vec_set(var_avPattern[0], vector(vec_temp.z, vec_temp.y, vec_temp.x));
break;
}
wait(1);
}
bmap_unlock(bmp);
}
1, 2 and 3 chooses the panel clicked and the limits of the bmap while holding mouse_left
|
|
|
|