Ogre
2011-03-26 13:57:33
So I'm trying to make a flood fill function with a tolerance that is "progressive" - meaning that it doesn't relate the target color to the first color, but to the last color it was at.
Here is a comparison of normal to progressive.
The only real difference in the code is very small
Anyway, the problem is the speed. It's not nearly fast enough to actually apply it. Nava2 suggested using TMufasaBitmaps to speed it up, and I did, but it didn't seem to help much (am I doing this wrong? :S)
but that's not much faster at all, sometimes it's even slower?
I think a scanline method would have better efficiency but I don't know how you'd make it "progressive"? (maybe I don't understand it right)
Would the only way to speed this up be to make it a plugin? I'm reluctant to do this just because I don't know how :p, the conversion between bitmap types might be hard?, and I don't people to have to download a plugin to use my script.
Edit: how can I get rid of all the extra newlines in the code blocks? I've tried Simba, Scar, and highlight tags..
Here is a comparison of normal to progressive.
The only real difference in the code is very small
procedure FloodFillProg(SPoint: TPoint; Col, Tol: Integer);
var
thisCol: Integer;
begin
try
thisCol := GetColor(SPoint.x, SPoint.y);
if (SimilarColors(thisCol, Col, Tol)) then
begin
FastSetPixel(bmap, SPoint.x, SPoint.y, clYellow);
if (FastGetPixel(bmap, SPoint.x - 1, SPoint.y) = 0) then
FloodFillProg(Point(SPoint.x - 1, SPoint.y), thisCol, Tol); //thisCol instead of Col
if (FastGetPixel(bmap, SPoint.x + 1, SPoint.y) = 0) then
FloodFillProg(Point(SPoint.x + 1, SPoint.y), thisCol, Tol); //thisCol instead of Col
if (FastGetPixel(bmap, SPoint.x, SPoint.y - 1) = 0) then
FloodFillProg(Point(SPoint.x, SPoint.y - 1), thisCol, Tol); //thisCol instead of Col
if (FastGetPixel(bmap, SPoint.x, SPoint.y + 1) = 0) then
FloodFillProg(Point(SPoint.x, SPoint.y + 1), thisCol, Tol); //thisCol instead of Col
end else
FastSetPixel(bmap, 0, 0, 1);
except
FastSetPixel(bmap, 0, 0, 1);
end;
end;
but it seems to make a good difference.Anyway, the problem is the speed. It's not nearly fast enough to actually apply it. Nava2 suggested using TMufasaBitmaps to speed it up, and I did, but it didn't seem to help much (am I doing this wrong? :S)
procedure FloodFillProgMufasa(SPoint: TPoint; Col, Tol: Integer);
var
thisCol: Integer;
begin
try
thisCol := Sbmap.FastGetPixel(SPoint.x, SPoint.y);
if (SimilarColors(thisCol, Col, Tol)) then
begin
Tbmap.FastSetPixel(SPoint.x, SPoint.y, thisCol);
if (Tbmap.FastGetPixel(SPoint.x - 1, SPoint.y) = 0) then
FloodFillProgMufasa(Point(SPoint.x - 1, SPoint.y), thisCol, Tol);
if (Tbmap.FastGetPixel(SPoint.x + 1, SPoint.y) = 0) then
FloodFillProgMufasa(Point(SPoint.x + 1, SPoint.y), thisCol, Tol);
if (Tbmap.FastGetPixel(SPoint.x, SPoint.y - 1) = 0) then
FloodFillProgMufasa(Point(SPoint.x, SPoint.y - 1), thisCol, Tol);
if (Tbmap.FastGetPixel(SPoint.x, SPoint.y + 1) = 0) then
FloodFillProgMufasa(Point(SPoint.x, SPoint.y + 1), thisCol, Tol);
end else
Tbmap.FastSetPixel(SPoint.x, SPoint.y, 1);
except
Tbmap.FastSetPixel(SPoint.x, SPoint.y, 1);
end;
end;where Sbmap and Tbmap are TMufasaBitmap types and Sbmap is a copy of the clientbut that's not much faster at all, sometimes it's even slower?
I think a scanline method would have better efficiency but I don't know how you'd make it "progressive"? (maybe I don't understand it right)
Would the only way to speed this up be to make it a plugin? I'm reluctant to do this just because I don't know how :p, the conversion between bitmap types might be hard?, and I don't people to have to download a plugin to use my script.
Edit: how can I get rid of all the extra newlines in the code blocks? I've tried Simba, Scar, and highlight tags..