Quickmarch
2009-06-23 00:48:16
CAB (Colour and bitmap) is a plugin I made that does a few bitmap and colour operations, i also made an include for it:
CAB Plugin and source:
//-----------------------------------------------------------------//
//-- Scar Standard Resource Library --//
//-- ยป Bitmap Routines --//
//-----------------------------------------------------------------//
// * function GradientBitmap(Width, Height, Colour: Integer; Saturation: Extended): Integer; // * Quickmarch
// * function ColourBitmap(Width, Height, Colour: Integer): Integer; // * Quickmarch
// * function LightenBitmap(BMP, Percent: Integer): Integer; // * Quickmarch
// * function DarkenBitmap(BMP, Percent: Integer): Integer; // * Quickmarch
// * function NegativeBitmap(BMP: Integer): Integer; // * Quickmarch
// * function GreystyleBitmap(BMP: Integer): Integer; // * Quickmarch
{*******************************************************************************
function GradientBitmap(Width, Height, Colour: Integer; Saturation: Extended): Integer;
By: Quickmarch
Description: Creates a bitmap with a gradient defined by Colour. Saturation = 0.0 - 1.0,
Makes it darker or lighter.
*******************************************************************************}
function GradientBitmap(Width, Height, Colour: Integer; Saturation: Extended): Integer;
var
BMP: TBitmap;
begin
try
Result := BitmapFromString(Width, Height, '');
BMP := CAB_GradientBitmap(Width, Height, Colour, Saturation);
SafeCopyCanvas(BMP.Canvas, GetBitmapCanvas(Result), 0, 0, Width, Height, 0, 0, Width, Height);
except
FreeBitmap(Result);
WriteLn('Error generating bitmap');
end;
end;
{*******************************************************************************
function ColourBitmap(Width, Height, Colour: Integer): Integer;
By: Quickmarch
Description: Creates a bitmap with one colour only.
*******************************************************************************}
function ColourBitmap(Width, Height, Colour: Integer): Integer;
var
BMP: TBitmap;
begin
try
Result := BitmapFromString(Width, Height, '');
BMP := CAB_ColourBitmap(Colour, Width, Height);
SafeCopyCanvas(BMP.Canvas, GetBitmapCanvas(Result), 0, 0, Width, Height, 0, 0, Width, Height);
except
FreeBitmap(Result);
WriteLn('Error generating bitmap');
end;
end;
{*******************************************************************************
function LightenBitmap(BMP, Percent: Integer): Integer;
By: Quickmarch
Description: Lightens a bitmap by Percent.
*******************************************************************************}
function LightenBitmap(BMP, Percent: Integer): Integer;
var
BMP2: TBitmap;
w, h: Integer;
begin
try
GetBitmapSize(BMP, w, h);
BMP2 := CAB_LightenBitmap(GetBitmapDC(BMP), w, h, Percent);
SafeCopyCanvas(BMP2.Canvas, GetBitmapCanvas(Result), 0, 0, w, h, 0, 0, w, h);
except
FreeBitmap(Result);
WriteLn('Error in LightenBitmap');
end;
end;
{*******************************************************************************
function DarkenBitmap(BMP, Percent: Integer): Integer;
By: Quickmarch
Description: Darkens a bitmap by Percent.
*******************************************************************************}
function DarkenBitmap(BMP, Percent: Integer): Integer;
var
BMP2: TBitmap;
w, h: Integer;
begin
try
GetBitmapSize(BMP, w, h);
BMP2 := CAB_DarkenBitmap(GetBitmapDC(BMP), w, h, Percent);
SafeCopyCanvas(BMP2.Canvas, GetBitmapCanvas(Result), 0, 0, w, h, 0, 0, w, h);
except
FreeBitmap(Result);
WriteLn('Error in DarkenBitmap');
end;
end;
{*******************************************************************************
function NegativeBitmap(BMP: Integer): Integer;
By: Quickmarch
Description: Inverts all the colours in the bitmap.
*******************************************************************************}
function NegativeBitmap(BMP: Integer): Integer;
var
BMP2: TBitmap;
w, h: Integer;
begin
try
GetBitmapSize(BMP, w, h);
BMP2 := CAB_NegativeBitmap(GetBitmapDC(BMP), w, h);
SafeCopyCanvas(BMP2.Canvas, GetBitmapCanvas(Result), 0, 0, w, h, 0, 0, w, h);
except
FreeBitmap(Result);
WriteLn('Error in NegativeBitmap');
end;
end;
{*******************************************************************************
function GreystyleBitmap(BMP: Integer): Integer;
By: Quickmarch
Description: Makes the bitmap greystyle.
*******************************************************************************}
function GreystyleBitmap(BMP: Integer): Integer;
var
BMP2: TBitmap;
w, h: Integer;
begin
try
GetBitmapSize(BMP, w, h);
BMP2 := CAB_GreystyleBitmap(GetBitmapDC(BMP), w, h);
SafeCopyCanvas(BMP2.Canvas, GetBitmapCanvas(Result), 0, 0, w, h, 0, 0, w, h);
except
FreeBitmap(Result);
WriteLn('Error in GreystyleBitmap');
end;
end;
CAB Plugin and source: