problem with pixel_for_bmap

Posted By: Caermundh

problem with pixel_for_bmap - 06/17/12 23:13

I am trying to copy one panel bmap to another using pixel for bmap and pixel to bmap. I am using the following code:

PANEL* panel_one =
{ pos_x = 10;
pos_y = 10;
layer = 10;
flags = SHOW;
}

PANEL* panel_two =
{ pos_x = 30;
pos_y = 10;
layer = 10;
flags = SHOW;
}


function main()
{ var count;
var count2;
var pixel;
panel_one.bmap = bmap_create("my_bmap.tga");
panel_two.bmap = bmap_createblack(bmap_width(panel_one.bmap),bmap_height(panel_one.bmap),32);
bmap_lock(panel_one.bmap);
bmap_lock(panel_two.bmap);
count = 0;
while(count<bmap_height(panel_one.bmap))
{ count2 = 0;
while(count2<bmap_width(panel_one.bmap))
{ pixel = pixel_for_bmap(panel_one.bmap,count,count2);
pixel_to_bmap(panel_two.bmap,count,count2,pixel);
count2 += 1;
}
count += 1;
}
bmap_unlock(panel_one.bmap);
bmap_unlock(panel_two.bmap);
}

When I run this code i get a crash. upon testing im finding that the pixel read from pixel_for_bmap is zero. Why is this? and would feeding a zero value for the pixel to pixel to bmap cause a crash?

(P.S. please do not tell me to just use panel_two.bmap = panel_one.bmap - this will not work for my purposes.)
Posted By: txesmi

Re: problem with pixel_for_bmap - 06/18/12 06:44

hello,
may be those bmap_lock calls need their second parameter.
Does 'my_bmap.tga' have 32bit format? I'm not sure but both bmaps should have same.

Salud!
Posted By: sivan

Re: problem with pixel_for_bmap - 06/18/12 07:29

the main error: count should be bmap_width() and count2 should be bmap_height() in the while statement !!!

and some tips:

put a wait(1); after panel_one.bmap = bmap_create("my_bmap.tga");
and
put a wait(1); after panel_two.bmap = bmap_createblack(bmap_width(panel_one.bmap),bmap_height(panel_one.bmap),32);
because I'm not sure they can be locked in the same frame as creation.

and yes, my_bmap.tga must be 32b, or use bmap_to_format();
Posted By: Caermundh

Re: problem with pixel_for_bmap - 06/18/12 16:16

ok! thanks! that fixed it - part of my problem was that "my_bmap.tga" was 24 bit and the createblack bmap was 32 - changed the create black to 24, flipped count and count2, and put in the wait(1); - all of that fixed that problem.

It never even occured to me to check the bit depth of the maps - when i bmap locked them it returned 8888 for both so i figured they were the same.

(the bmap lock is a typo. i did have bmap_lock(panel_one.bmap,0) - my bad)

heres the code that works:

panel_one.bmap = bmap_create("cb_iconbox_md.tga");
wait(1);
panel_two.bmap = bmap_createblack(bmap_width(panel_one.bmap),bmap_height(panel_one.bmap),24);
wait(1);
bmap_lock(panel_one.bmap,0);
bmap_lock(panel_two.bmap,0);
count = 0;
while(count<bmap_height(panel_one.bmap))
{ count2 = 0;
while(count2<bmap_width(panel_one.bmap))
{ pixel = pixel_for_bmap(panel_one.bmap,count2,count);
pixel_to_bmap(panel_two.bmap,count2,count,pixel);
count2 += 1;
}
count += 1;
}
bmap_unlock(panel_one.bmap);
bmap_unlock(panel_two.bmap);
© 2024 lite-C Forums