Gamestudio Links
Zorro Links
Newest Posts
AlpacaZorroPlugin v1.3.0 Released
by kzhao. 05/22/24 13:41
Free Live Data for Zorro with Paper Trading?
by AbrahamR. 05/18/24 13:28
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 (AndrewAMD), 1,534 guests, and 3 spiders.
Key: Admin, Global Mod, Mod
Newest Members
LucasJoshua, Baklazhan, Hanky27, firatv, wandaluciaia
19054 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
[req] Help with paint bucket code #254411
03/03/09 06:58
03/03/09 06:58
Joined: Feb 2008
Posts: 337
V
Vadim647 Offline OP
Senior Member
Vadim647  Offline OP
Senior Member
V

Joined: Feb 2008
Posts: 337
Firstly, to note: I never asked anyone for help for that year of being part of this community.
What's about: I'm making my own graphics editor (currently looking like msPaint with number of filters wink ), I have lots of things done, but I'm stuck on making paint bucket tool frown
What I have now: -download link- Inside, simplified version of paint bucket code I tried to do (causes crash or weird results), and several functions for manipulating bmaps.
Please! Help me someone! I really need it...


I switched to other account since marth 2010. Guess which.
Re: [req] Help with paint bucket code [Re: Vadim647] #254571
03/04/09 08:05
03/04/09 08:05
Joined: Feb 2008
Posts: 337
V
Vadim647 Offline OP
Senior Member
Vadim647  Offline OP
Senior Member
V

Joined: Feb 2008
Posts: 337
How predictable... Noone cares.


I switched to other account since marth 2010. Guess which.
Re: [req] Help with paint bucket code [Re: Vadim647] #254600
03/04/09 10:45
03/04/09 10:45
Joined: Feb 2008
Posts: 3,232
Australia
EvilSOB Offline
Expert
EvilSOB  Offline
Expert

Joined: Feb 2008
Posts: 3,232
Australia
Its not that no-one cares. Its just that (for a change) no-one is posting unless they have helpful advice.

And this problem is a bastitch!

Is it OK if I do a complete re-write of (just) the paint_fill function.
It is currently unclear to me if the number of instances of itself is just blowing out,
or if the number of instances is overloading the limited "vector()" function storage space(limit 12).

I am currently thinking its just generating too many instances and falling over its own feet.

PS I will start on the re-write now in case you are in a different time zone to me.

[EDIT] Its definately crashing due to the paint_fill calling itself multiple times per pixel, which
then calls itself, which then calls itself, ad infinitum... Crashes my machine at about 3500 instances.
Still working on it...


Last edited by EvilSOB; 03/04/09 11:55. Reason: UPDATED

"There is no fate but what WE make." - CEO Cyberdyne Systems Corp.
A8.30.5 Commercial
Re: [req] Help with paint bucket code [Re: EvilSOB] #254633
03/04/09 13:13
03/04/09 13:13
Joined: Feb 2008
Posts: 3,232
Australia
EvilSOB Offline
Expert
EvilSOB  Offline
Expert

Joined: Feb 2008
Posts: 3,232
Australia
Still being a challenge, but Ive got a couple of bits sorted.

To stop the paint_fill function replicating insanely, use this barely modified one.
Code:
function paint_fill(VECTOR* pPos)
{
	paint_pixel2 = pixel_for_bmap(paint_bmap,pPos.x,pPos.y);
	pixel_to_vec(pv_a,NULL,paint_txtype,paint_pixel2);
	paint_point(pPos,pv_d);  //Only line changed, moved up from bottom of function.
	if (pPos.x>0)
	{
		paint_pixel = pixel_for_bmap(paint_bmap,pPos.x-1,pPos.y);
		pixel_to_vec(pv_b,NULL,paint_txtype,paint_pixel);
		if (vec_dist(pv_a,pv_b)<=16) paint_fill(vector(pPos.x-1,pPos.y,0));
	}
	if (pPos.y>0)
	{
		paint_pixel = pixel_for_bmap(paint_bmap,pPos.x,pPos.y-1);
		pixel_to_vec(pv_b,NULL,paint_txtype,paint_pixel);
		if (vec_dist(pv_a,pv_b)<=16) paint_fill(vector(pPos.x,pPos.y-1,0));
	}
	if (pPos.x<paint_w)
	{
		paint_pixel = pixel_for_bmap(paint_bmap,pPos.x+1,pPos.y);
		pixel_to_vec(pv_b,NULL,paint_txtype,paint_pixel);
		if (vec_dist(pv_a,pv_b)<=16) paint_fill(vector(pPos.x+1,pPos.y,0));
	}
	if (pPos.y<paint_h)
	{
		paint_pixel = pixel_for_bmap(paint_bmap,pPos.x,pPos.y+1);
		pixel_to_vec(pv_b,NULL,paint_txtype,paint_pixel);
		if (vec_dist(pv_a,pv_b)<=16) paint_fill(vector(pPos.x,pPos.y+1,0));
	}
}
But it still wont work on any bitmaps larger than 32x32. Works with 32x32 pixels but fails with 64x64. Far from good enough.
Still working on this one.


"There is no fate but what WE make." - CEO Cyberdyne Systems Corp.
A8.30.5 Commercial
Re: [req] Help with paint bucket code [Re: EvilSOB] #254681
03/04/09 18:58
03/04/09 18:58
Joined: Feb 2008
Posts: 337
V
Vadim647 Offline OP
Senior Member
Vadim647  Offline OP
Senior Member
V

Joined: Feb 2008
Posts: 337
Already thanks! smile


I switched to other account since marth 2010. Guess which.
Re: [req] Help with paint bucket code [Re: Vadim647] #254774
03/05/09 13:10
03/05/09 13:10
Joined: Feb 2008
Posts: 3,232
Australia
EvilSOB Offline
Expert
EvilSOB  Offline
Expert

Joined: Feb 2008
Posts: 3,232
Australia
Heres the best I can manage, slight display twitch as there is a noticable delay (not major I think) when filling large areas.
The delay is about 0.25 seconds for a 64 X 64 bit block filled on my P4 3.0g 512Mb machine.
Maybe you can fine tune it better. If you can I would be interested to see the resulting code.

This change to be made in paint_1.c
Click to reveal..
Code:
function mouseleft()
{
	if (tool == 1)
	{
		while (mouse_left)
		{
			if (mouse_in)
			{
				paint_begin();
				paint_blend(mousepos,vector(0,192,255),100);
				paint_end();
			}
			wait(1);
		}
	}
	if (tool == 2)
	{
		if (mouse_in)
		{
			paint_fill(mousepos, vector(0,255,192));
			wait_for(paint_fill);
		}
	}
}
And both these functions to replace "paint_fill" in paint_functions.c
Click to reveal..
Code:
function paint_fill(VECTOR* pPos, COLOR* pCol)
{
	paint_begin();
	COLOR pOldCol;
	var start_pixel = pixel_for_bmap(paint_bmap, pPos.x, pPos.y);	//start pixel
	pixel_to_vec(pOldCol, NULL, paint_txtype, start_pixel);		//start pixel color
	paint_fill_spread(pPos, pCol, pOldCol);					//replace pixels
	wait_for(paint_fill_spread);				//wait till all pixels done
	paint_end();	//   maybe the "draw_quad(paint_bmap, ..." is causing the bmap to unlock.
	paint_begin();	//paint_begin required to re-fresh BMAP.  I DONT KNOW why this is needed,
	paint_end();	//   maybe the "draw_quad(paint_bmap, ..." is causing the bmap to unlock.
}

function paint_fill_spread(VECTOR* ppPos, COLOR* ppCol, COLOR* ppOldCol)
{	VECTOR	pPos;	COLOR this_color, pCol, pOldCol;
	vec_set(pPos, ppPos);	vec_set(pCol, ppCol);	vec_set(pOldCol, ppOldCol);
	//
	paint_point(pPos, pCol);
	wait(1);				//*** CRITICAL PLACEMENT ***
	if (pPos.x<paint_w-1)
	{
		var this_pixel = pixel_for_bmap(paint_bmap,pPos.x+1,pPos.y);
		pixel_to_vec(this_color, NULL, paint_txtype, this_pixel);
		if(abs(vec_dist(pOldCol,this_color))<=16)
			if(vec_dist(this_color, pCol)!=0)    		
				paint_fill_spread(vector(pPos.x+1,pPos.y,0), pCol, pOldCol);
	}
	if (pPos.y<paint_h-1)
	{
		var this_pixel = pixel_for_bmap(paint_bmap,pPos.x,pPos.y+1);
		pixel_to_vec(this_color, NULL, paint_txtype, this_pixel);
		if(abs(vec_dist(pOldCol,this_color))<=16)
			if(vec_dist(this_color, pCol)!=0)    		
				paint_fill_spread(vector(pPos.x,pPos.y+1,0), pCol, pOldCol);
	}
	if (pPos.x>0)
	{
		var this_pixel = pixel_for_bmap(paint_bmap, pPos.x-1, pPos.y);
		pixel_to_vec(this_color, NULL, paint_txtype, this_pixel);
		if(abs(vec_dist(pOldCol,this_color))<=16)
			if(vec_dist(this_color, pCol)!=0)    		
				paint_fill_spread(vector(pPos.x-1,pPos.y,0), pCol, pOldCol);
	}
	if (pPos.y>0)
	{
		var this_pixel = pixel_for_bmap(paint_bmap,pPos.x,pPos.y-1);
		pixel_to_vec(this_color, NULL, paint_txtype, this_pixel);
		if(abs(vec_dist(pOldCol,this_color))<=16)
			if(vec_dist(this_color, pCol)!=0)    		
				paint_fill_spread(vector(pPos.x,pPos.y-1,0), pCol, pOldCol);
	}
}


Last edited by EvilSOB; 03/05/09 19:50. Reason: Code optimised slightly

"There is no fate but what WE make." - CEO Cyberdyne Systems Corp.
A8.30.5 Commercial

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