pwnaz0r
2007-09-28 15:28:20
Well here they are. GetAreaCols gets all the colors in an box (l and w are modifiers)). Find Best Color finds the best color to use in those boxes. Have fun.
An Average, takes 300 ms.
An Average, takes 300 ms.
procedure GetAreaColors(var Colors: array of integer; L, W: integer; MH, MS: extended);
var
xCount, yCount, xMouse, yMouse, cColor, rBitmap, bHeight, bWidth, aCount, wCount, zCount: integer;
hCount, sCount, lCount, cH, cS, cL: extended;
rBox: TBox;
begin
SetArrayLength(Colors, 1);
GetMousePos(xMouse,yMouse);
cColor:= GetColor(xMouse, yMouse);
ColorToHSL(cColor, cH, cS, cL);
rBox.x1:= xMouse - W;
rBox.y1:= yMouse - L;
rBox.x2:= xMouse + W;
rBox.y2:= yMouse + L;
CopyClientToBitmap(rBitmap, rBox.x1, rBox.y1, rBox.x2, rBox.y2);
GetBitmapSize(rBitmap, bWidth, bHeight);
DisplayDebugImgWindow(bWidth, bHeight);
SafeCopyCanvas(GetBitmapCanvas(rBitmap), GetDebugCanvas, 0, 0, bWidth, bHeight, 0, 0, bWidth, bHeight);
for xCount:= 1 to bWidth do
for yCount:= 1 to bHeight do
begin
ColorToHSL(FastGetPixel(rBitmap, xCount, yCount), hCount, sCount, lCount);
if MaxE(hCount, cH) - MinE(hCount, cH) <= MH then
if MaxE(sCount, cS) - MinE(sCount, cS) <= MS then
if MaxE(lCount, cL) - MinE(lCount, cL) <= 30.0 then
begin
SetArrayLength(Colors, Length(Colors) + 1);
aCount:= Length(Colors) - 1;
Colors[aCount]:= FastGetPixel(rBitmap, xCount, yCount);
end;
end;
BubbleSort(Colors);
if InIntArrayEx(Colors, zCount, 0) then Colors[zCount]:= Colors[(zCount + 1)];
ClearSameIntegers(Colors);
for wCount:= 0 to Length(Colors) - 1 do
Writeln(IntToStr(Colors[wCount]));
end;
function FindBestCol(var Colors: array of integer; L, W: integer; MH, MS: extended): integer;
var
aCount, mCoun, xMouse, yMouse : integer;
rCount: array of integer;
rBox: TBox;
begin
GetAreaColors(Colors, l, w, mh, ms);
SetArrayLength(rCount, Length(Colors));
GetMousePos(xMouse, yMouse);
rBox.x1:= xMouse - W;
rBox.y1:= yMouse - L;
rBox.x2:= xMouse + W;
rBox.y2:= yMouse + L;
for aCount:= 0 to Length(Colors) - 1do
rCount[aCount]:= CountColor(Colors[aCount], rBox.x1, rBox.y1, rBox.x2, rBox.y2);
mCoun:= AMin(rCount);
result:= Colors[mCoun];
Writeln('Best Color = '+IntToStr(result)+';');
end;