SRL Archive - SRL Archives

CAB - Bitmap operations!


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:


//-----------------------------------------------------------------//
//-- 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:

ian.

2009-06-23 01:27:45

Could this be used for RS? :o

Wizzup?

2009-06-23 02:12:20

Nice, I wrote something similar, but it only had Saturation, Brightness, Grayscale and a few more… :)

Da 0wner

2009-06-23 02:38:33

In your procedures in the include, put the freebitmap in a finally and not an except.

senrath

2009-06-23 03:19:57

From: Da 0wner
In your procedures in the include, put the freebitmap in a finally and not an except.


Um, why? That would make the function do nothing at all, even when it would have worked.

Da 0wner

2009-06-23 03:25:42

To free it at all times, but I didn't know it resulted in a bitmap. Yeah, it would never work because it is freeing at end of procedure and cannot be used for other things :p.

ian.

2009-06-23 03:52:47

Again, could this be used for RS? :o

Wizzup?

2009-06-23 04:13:02

From: 99_
Again, could this be used for RS? :o


Yes. It can be particularly useful when trying to get rid of background noise, or certain colors. (Contrast, Grayscale, Brightness.)

ian.

2009-06-23 04:19:47

Oh okay. :] Thanks, Wizzup? ^^

Quickmarch

2009-06-23 10:58:25

Thanks for the feedback guys :), I use this mainly for generating bitmaps on-the-fly for forms so i don't have to have a massive string. It also would be cool to add effects to an RS screenshot. :)