Gamestudio Links
Zorro Links
Newest Posts
Change chart colours
by 7th_zorro. 05/11/24 09:25
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
1 registered members (M_D), 1,501 guests, and 4 spiders.
Key: Admin, Global Mod, Mod
Newest Members
firatv, wandaluciaia, Mega_Rod, EternallyCurious, howardR
19050 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 2 1 2
[SOLVED] now I have problem with pixel_to_bmap() #348751
11/30/10 06:17
11/30/10 06:17
Joined: Aug 2005
Posts: 238
Caermundh Offline OP
Member
Caermundh  Offline OP
Member

Joined: Aug 2005
Posts: 238
Now i am attempting to read the pixel color from one bmap and write a blue pixel to another bmap if the pixel color read from the first bmap is the right color.

I have the following function:

function color_bmap(COLOR pixel_color)
{ var count_x;
var count_y;
var pixel;
COLOR temp_color;
BMAP* temp_bmap = bmap_createblack(744,600,32);
bmap_lock(temp_bmap,0);
bmap_lock(my_bmap,0);
count_y = 0;
while(count_y<600)
{ count_x = 0;
while(count_x<744)
{ pixel = pixel_for_bmap(my_bmap,count_x,count_y);
pixel_to_vec(temp_color,NULL,8888,pixel);
if(temp_color.blue==pixel_color.blue||temp_color.red==pixel_color.red||temp_color.green==pixel_color.green)
{ temp_color.red = 0;
temp_color.green = 0;
temp_color.blue = 250;
pixel = pixel_for_vec(temp_color,100,8888);
pixel_to_bmap(temp_bmap,count_x,count_y,pixel);
}
count_x += 1;
}
count_y += 1;
}
bmap_unlock(temp_bmap);
bmap_unlock(my_bmap);
my_panel.bmap = temp_bmap;
set(my_panel,VISIBLE);
}

This whole routine is working as it should, except that when i write a pixel to temp_bmap - no pixel is written. The instruction, pixel_to_bmap() is being executed - it just fails to actually write a pixel to temp_bmap. Why is this happening?

Last edited by Caermundh; 12/01/10 17:37.
Re: now I have problem with pixel_to_bmap() [Re: Caermundh] #348752
11/30/10 06:57
11/30/10 06:57
Joined: Feb 2010
Posts: 320
TANA/Madagascar
3dgs_snake Offline
Senior Member
3dgs_snake  Offline
Senior Member

Joined: Feb 2010
Posts: 320
TANA/Madagascar
Hi,

I don't really know what you want to achieve blush. Anyway, bellow is your code with a test program

In the manual, it is said that "Structs can not be used for parameters, but struct pointers can."

Code:
#include <acknex.h>
#include <default.c>

BMAP *bmp_nature = "NATURE.JPG";

PANEL *pan_bmp = 
{
	bmap = bmp_nature ;	
	flags = SHOW ;
	
	scale_x = 0.5 ;
	scale_y = 0.5 ;
}

PANEL *my_panel = 
{	
	scale_x = 0.5 ;
	scale_y = 0.5 ;
	
	pos_x = 400;
}

BMAP *my_bmap;

// Color bmap
function color_bmap(COLOR *pixel_color)
{
	var count_x;
	var count_y;
	var pixel;
	
	COLOR temp_color;
	var bmp_width = bmap_width(my_bmap);
	var bmp_height = bmap_height(my_bmap);
	
	BMAP* temp_bmap = bmap_createblack(bmp_width, bmp_height, 32);
	
	bmap_lock(temp_bmap,0);
	bmap_lock(my_bmap,0);
	
	count_y = 0;
	while(count_y<bmp_height)
	{ 
		count_x = 0;
		while(count_x<bmp_width)
		{
			pixel = pixel_for_bmap(my_bmap,count_x,count_y);
			pixel_to_vec(&temp_color,NULL,8888,pixel);
			if(temp_color.blue==pixel_color->blue||temp_color.red==pixel_color->red||temp_color.green==pixel_color->green)
			{
				temp_color.red = 0;
				temp_color.green = 0;
				temp_color.blue = 250;
				pixel = pixel_for_vec(&temp_color,100,8888);
				pixel_to_bmap(temp_bmap,count_x,count_y,pixel);
			}
			count_x += 1;
		}
		count_y += 1;
	}
	bmap_unlock(temp_bmap);
	bmap_unlock(my_bmap);
	my_panel.bmap = temp_bmap;
	set(my_panel,VISIBLE);
}

void main()
{
	wait(1);
	my_bmap = pan_bmp->bmap;
	
	color_bmap(vector(0, 150, 0));
}




This is a sample code to transform a bmap to a gray scale
Code:
#include <acknex.h>
#include <default.c>

BMAP *bmp_nature = "NATURE.JPG";
BMAP *FIREFOX_3_bmap = "FIREFOX_3.JPG";
BMAP *bmp_box = "box.png" ;

PANEL *pan_bmp = 
{
	bmap = bmp_nature ;	
	flags = SHOW ;
	
	//scale_x = 0.2 ;
	//scale_y = 0.2 ;
}

void main()
{
	// Wait for video functions to be ready
	wait (1) ;
	
	BMAP *bmp_to = pan_bmp->bmap ;
	
	pan_bmp->pos_x = ( screen_size.x - bmap_width ( bmp_to ) ) * 0.5 ;	
	pan_bmp->pos_y = ( screen_size.y - bmap_height ( bmp_to ) ) * 0.5 ;
	
	var format = bmap_lock ( bmp_to, 0 ) ;
	if ( format > 565 )
	{
		int width = bmap_width ( bmp_to ) ;
		int height = bmap_height ( bmp_to ) ;
		
		int i = 0 ;
		int j = 0 ;
		
		COLOR vec_color ;
		var pixel ;
		var pixel_transparency;
		
		for ( i = 0; i<width ; i++ )
		{
			for ( j = 0; j < height ; j++ ) 
			{
				pixel = pixel_for_bmap ( bmp_to, i, j ) ;
				pixel_to_vec ( &vec_color, &pixel_transparency, format, pixel ) ;
				
				vec_mul( &vec_color, vector ( 0.0721, 0.7154, 0.2125 ) ) ; 
				//vec_mul( &vec_color, vector ( 0.5, 0.587, 0.299 ) ) ; 
				//vec_mul( &vec_color, vector ( 0.3, 0.59, 0.11 ) ) ; 
				
				int gray = vec_color.red + vec_color.blue + vec_color.green ;
				
				int red = (vec_color.red * .393) + (vec_color.green *.769) + (vec_color.blue * .189) ;

				int green = (vec_color.red * .349) + (vec_color.green *.686) + (vec_color.blue * .168) ;
				
				int blue = (vec_color.red * .272) + (vec_color.green *.534) + (vec_color.blue * .131) ;
				
				pixel = pixel_for_vec ( vector( gray, gray, gray ), pixel_transparency, format ) ;
				pixel_to_bmap ( bmp_to, i, j, pixel ) ;
				
			}
		}
	}
	
	bmap_unlock ( bmp_to ) ;
}



Re: now I have problem with pixel_to_bmap() [Re: 3dgs_snake] #348789
11/30/10 18:32
11/30/10 18:32
Joined: Aug 2005
Posts: 238
Caermundh Offline OP
Member
Caermundh  Offline OP
Member

Joined: Aug 2005
Posts: 238
What I am trying to accomplish is to "color in" sections of a blank bmap based on the color values in another bmap. For example, for every red pixel (R=250, G=0, B=0) in the primary bitmap, write a blue pixel (R=0, G=0, B=250) to the second bmap at the same location in the bmap. (Both bmaps are the same resolution, so im drawing a blue pixel in the second bmap everywhere there is a red pixel in the first bmap, essentially.)

Good catch on passing the parameter. I had forgotten about passing a pointer instead of the struct itself. I corrected that, but the code still does not write a pixel to temp_bmap. As I said, I know that the pixel_to_bmap() instruction is being reached and that it is being executed, but it does not write a pixel to the second bmap. At runtime, the second bmap is completely blank.

You state that when calling pixel_to_vec() you have to pass the address of the color variable instead of the variable itself. (IE "pixel_to_vec(&vec_color, &pixel_transparency, format, pixel);" instead of "pixel_to_vec(vec_color, ppixel_transparency, format, pixel);". I know for a fact that I can pass vec_color and not &vec_color - I have another routine that is working just fine using the variable instead of the address.

In your code, when you call pixel_to_bmap(), you are passing the bmap pointer, the x & y co-ordinates, and a pixel value converted by pixel_for_vec(). Im essentially doing the exact same thing in my code, yet yours works and mine doesnt? The only thing you are doing differently is passing a vector() to pixel_for_vec() instead of a COLOR value. a COLOR value is still a vector, im pretty sure thats not the problem.

I'm sorry, I think im just missing your point. What is it that the greyscale code you showed me does differently from the way im doing things?

Re: now I have problem with pixel_to_bmap() [Re: Caermundh] #348795
11/30/10 19:29
11/30/10 19:29
Joined: Apr 2010
Posts: 172
W
wdlmaster Offline
Member
wdlmaster  Offline
Member
W

Joined: Apr 2010
Posts: 172
Code:
function compare() {

	int p;	
	bmap_lock (bmp1,0);
	bmap_lock (bmp2,0);
	char* b1 = bmp1.finalbits;
	char* b2 = bmp2.finalbits;

	for (p=0;p<bmp1.finalwidth * bmp1.finalheight;p++)
		if (	b1[p*4  ] == find_color.blue &&
			b1[p*4+1] == find_color.green &&
			b1[p*4+2] == find_color.red) {

			b2[p*4  ] = new_color.blue;
			b2[p*4+1] = new_color.green;
			b2[p*4+2] = new_color.red;
			b2[p*4+3] = 255;}

	bmap_unlock(bmp1);
	bmap_unlock(bmp2);}


both bitmaps must have the same dimensions! If not, the result is either messed up or the engine crashes!

Re: now I have problem with pixel_to_bmap() [Re: wdlmaster] #348796
11/30/10 19:39
11/30/10 19:39
Joined: Aug 2005
Posts: 238
Caermundh Offline OP
Member
Caermundh  Offline OP
Member

Joined: Aug 2005
Posts: 238
@wdlmaster:

Both of my bitmaps do indeed have the same dimensions - 744x600. That is not the problem. Additionally, the engine is not crashing when I run the function - the function simply fails to write pixels to the second bmap.

Re: now I have problem with pixel_to_bmap() [Re: Caermundh] #348809
11/30/10 21:08
11/30/10 21:08
Joined: Aug 2005
Posts: 238
Caermundh Offline OP
Member
Caermundh  Offline OP
Member

Joined: Aug 2005
Posts: 238
OK, tried this:

function color_bmap(COLOR* find_color)
{ BMAP* temp_bmap = bmap_createblack(744,600,32);
char* b1 = my_bmap.finalbits;
char* b2 = temp_bmap.finalbits;
int p;
bmap_lock(my_bmap,0);
bmap_lock(temp_bmap,0);
for(p=0;p<my_bmap.finalwidth*my_bmap.finalheight;p++)
if(b1[p*4]==find_color.blue&&b1[p*4+1]==find_color.green&&b1[p*4+2]==find_color.red)
{ b2[p*4] = 0;
b2[p*4+1] = 0;
b2[p*4+2] = 250;
b2[p*4+3] = 255;
}
bmap_unlock(temp_bmap);
bmap_unlock(campaignmap_lands_bmap);
}

The result is an engine crash. (The bmaps are the same size - both are 744x600)

Re: now I have problem with pixel_to_bmap() [Re: Caermundh] #348811
11/30/10 21:13
11/30/10 21:13
Joined: Jul 2008
Posts: 1,178
England
M
MrGuest Offline
Serious User
MrGuest  Offline
Serious User
M

Joined: Jul 2008
Posts: 1,178
England
have a look at this, hopefully will get you working along the right tracks
Code:
#include <acknex.h>
#include <default.c>


PANEL* pnlFrom;
PANEL* pnlTo;

void main(){
	
	wait(1);
	
	//create panel to read from
	pnlFrom = pan_create("", 1);
	pnlFrom.bmap = bmap_createblack(200, 100, 32);
	bmap_fill(pnlFrom.bmap, vector(0, 0, 250), 100);
	set(pnlFrom, SHOW);
	
	var alpha, formatFrom, formatTo, pixel;
	COLOR col;
	
	int x, y, x_max = bmap_width(pnlFrom.bmap), y_max = bmap_height(pnlFrom.bmap);
	
	//create random noise to find
	formatFrom = bmap_lock(pnlFrom.bmap, 0);
	for(x = 0; x < x_max; x++){
		
		for(y = 0; y < y_max; y++){
			
			vec_set(col, vector(integer(random(255)), integer(random(255)), integer(random(255)))); 
			pixel = pixel_for_vec(col, 100, formatFrom);
			pixel_to_bmap(pnlFrom.bmap, x, y, pixel);
		}
	}
	bmap_unlock(pnlFrom.bmap);
	
	//create panel to write to
	pnlTo = pan_create("", 1);
	pnlTo.bmap = bmap_createblack(200, 100, 32);
	bmap_fill(pnlTo.bmap, vector(0, 0, 250), 100);
	set(pnlTo, SHOW);
	pnlTo.pos_x = 400;
	
	//read all pixel and write only blue to new panel
	formatTo = bmap_lock(pnlTo.bmap, 0);
	formatFrom = bmap_lock(pnlFrom.bmap, 0);
	for(x = 0; x < x_max; x++){
		
		for(y = 0; y < y_max; y++){
			
			pixel = pixel_for_bmap(pnlFrom.bmap, x, y);
			pixel_to_vec(col, alpha, formatFrom, pixel);
			
			if(col.blue > 127){
				
				
				//only draw blue... comment out next 4 lines if not needed
				col.blue = 255;
				col.green = 0;
				col.red = 0;
				pixel = pixel_for_vec(col, 100, formatTo);
				pixel_to_bmap(pnlTo.bmap, x, y, pixel);
			}
		}
	}
	bmap_unlock(pnlTo.bmap);
	bmap_unlock(pnlFrom.bmap);
	
	wait(1);
	while(!key_enter){ wait(1); }
//	while(key_enter){ wait(1); }
	
	pan_remove(pnlFrom);
	pan_remove(pnlTo);
	main();
}


hold enter to see the impact it has on performance

Re: now I have problem with pixel_to_bmap() [Re: Caermundh] #348821
11/30/10 21:45
11/30/10 21:45
Joined: Apr 2010
Posts: 172
W
wdlmaster Offline
Member
wdlmaster  Offline
Member
W

Joined: Apr 2010
Posts: 172
Quote:

OK, tried this:
...
The result is an engine crash. (The bmaps are the same size - both are 744x600)

you must replace the p*4 with p*3 if you use 24 bit bitmaps. The code is tested and works fine. see here

Re: now I have problem with pixel_to_bmap() [Re: wdlmaster] #348905
12/01/10 17:36
12/01/10 17:36
Joined: Aug 2005
Posts: 238
Caermundh Offline OP
Member
Caermundh  Offline OP
Member

Joined: Aug 2005
Posts: 238
Found the problem....

It wasnt the code at all. pretty much every routine posted here works fine - theres no problems with them.

The problem was the .tga file. It was saved as 24 bit. Once I saved it as 32 bit, all the pixel_to_bmap() calls wrote pixels to the bmap just fine.

I guess the pixel manipulation commands just dont work on 24 bit maps?

(@wdlmaster & @MrGuest: Both of your routines worked perfectly - *until* I tried using them on a 24 bit bmap. once i converted to 24 bit, both routines displayed the same problem - not writing pixels to the bitmap.)

Re: now I have problem with pixel_to_bmap() [Re: Caermundh] #348957
12/02/10 07:15
12/02/10 07:15
Joined: Oct 2002
Posts: 2,256
Oz
L
Locoweed Offline
Expert
Locoweed  Offline
Expert
L

Joined: Oct 2002
Posts: 2,256
Oz
Glad you figured it out Caermundh, and happy you described what happened to get it to work. Everyone should do that.


Professional A8.30
Spoils of War - East Coast Games
Page 1 of 2 1 2

Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1