The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

Win32::GUI::DIBitmap add new reading/writing bitmap formats to Win32::GUI and some image manipulation.

SYNOPSIS

use Win32::GUI;
use Win32::GUI::DIBitmap;

$W = new Win32::GUI::Window (
            -title    => "Win32::GUI::DIBitmap test",
            -pos      => [100, 100],
            -size     => [400, 400],
            -name     => "Window",
            );

$dib = newFromFile Win32::GUI::DIBitmap ('image.jpg');
$hbitmap = $dib->ConvertToBitmap();
undef $dib;

$W->AddButton (
  -pos     => [100, 100],
  -size    => [200, 200],
  -bitmap  => $hbitmap,
  -name    => "Button",
  -visible => 1,
  );

$W->Show();
Win32::GUI::Dialog();
sub Window_Terminate { -1 }

DESCRIPTION

Win32::GUI::DIBitmap add new reading/writing bitmap formats to Win32::GUI and some image manipulation.

This package use FreeImage 3.0.4, an open source image library supporting all common bitmap formats (visit : http://freeimage.sourceforge.net/ ).

Supports many formats, such as:

Format  Reading Writing Description
BMP Y   Y   Windows or OS/2 Bitmap [Export = 1 4 8 16 24 32]
ICO Y   Y   Windows Icon [Export = 1 4 8 16 24 32]
JPEG    Y   Y   JPEG - JFIF Compliant [Export = 8 24]
JNG Y   N   JPEG Network Graphics
KOALA   Y   N   C64 Koala Graphics
IFF Y   N   IFF Interleaved Bitmap
MNG Y   N   Multiple Network Graphics
PBM Y   Y   Portable Bitmap (ASCII) [Export = 1 8 24]
PBMRAW  Y   Y   Portable Bitmap (RAW) [Export = 1 8 24]
PCD Y   N   Kodak PhotoCD
PCX Y   N   Zsoft Paintbrush
PGM Y   Y   Portable Greymap (ASCII) [Export = 1 8 24]
PGMRAW  Y   Y   Portable Greymap (RAW) [Export = 1 8 24]
PNG Y   Y   Portable Network Graphics [Export = 1 4 8 24 32]
PPM Y   Y   Portable Pixelmap (ASCII) [Export = 1 8 24]
PPMRAW  Y   Y   Portable Pixelmap (RAW) [Export = 1 8 24]
RAS Y   N   Sun Raster Image
TARGA   Y   Y   Truevision Targa [Export = 1 4 8 16 24 32]
TIFF    Y   Y   Tagged Image File Format [Export = 1 4 8 24 32]
WBMP    Y   Y   Wireless Bitmap [Export = 1]
PSD Y   N   Adobe Photoshop
CUT Y   N   Dr. Halo
XBM Y   N   X11 Bitmap Format
XPM Y   N   X11 Pixmap Format

FreeImage can handle multi-page file (TIFF and ICO support only).

PACKAGE FUNCTIONS

FreeImage Library Info functions

GetVersion ()
Return the FreeImage version string.
GetCopyright ()
Return the FreeImage copyright string.

FIF functions

Constante
FIF = Format Identifier File.

FIF_UNKNOWN = -1
FIF_BMP     FIF_ICO    FIF_JPEG   FIF_JNG
FIF_KOALA   FIF_LBM    FIF_MNG    FIF_PBM
FIF_PBMRAW  FIF_PCD    FIF_PCX    FIF_PGM
FIF_PGMRAW  FIF_PNG    FIF_PPM    FIF_PPMRAW
FIF_RAS     FIF_TARGA  FIF_TIFF   FIF_WBMP
FIF_PSD     FIF_IFF    FIF_LBM    FIF_CUT
FIF_XBM     FIF_XPM
GetFIFCount ()
Return the max FIF value.
GetFormatFromFIF (fif)
Return the string format from FIF value.
GetFIFFromFormat (format)
Return FIF value from the string format.
GetFIFFromMime (mime)
Return FIF value from the Mime string.
GetFIFFromFilename (filename)
Return FIF value from the filename string.
GetFIFFromFile (filename)
Return FIF value from file data.
GetFIFFromData (data)
Return FIF value from memory data.

FIF info functions

FIFExtensionList (fif)
Return a coma separated string of extension filenname.
FIFDescription (fif)
Return a description string of the format.
FIFSupportsReading (fif)
This format can be read ?
FIFSupportsWriting (fif)
This format can be write ?
FIFSupportsExportBPP (fif, bpp)
This format can be write bpp image ?

DIBITMAP OBJECT

DIBitmap New methods

new ([width=100, height=100, bpp=24, redmask=0, bluemask=0, greemask=0])
Allocate a Win32::GUI::DIBitmap object.
newFromFile (filename, [flag])
Create a Win32::GUI::DIBBitmap from a image file.

Some format have special load flag :

Type   | Flag              | Description
-------+-------------------+--------------------------------------------------
JPEG   | JPEG_FAST         | Load file as fast as possible (sacrifing quality)
       | JPEG_ACCURATE     | Load file with the best quality (sacrifing speed)
PCD    | PCD_BASE          | Load picture sized 768 * 512.
PCD    | PCD_BASEDIV4      | Load picture sized 384 * 256.
PCD    | PCD_BASEDIV16     | Load picture sized 192 * 128.
PNG    | PNG_IGNOREGAMMA   | Avoid gamma correction
TARGA  | TARGA_LOAD_RGB888 | Convert RGB555 and ARGB8888 to RGB888
TIFF   | TIFF_CMYK         | Load CMYK bitmap as 32 bit separated CMYK.
newFromData (data, [flag])
Create a Win32::GUI::DIBitmap from memory data.
newFromBitmap (hbitmap)
Create a Win32::GUI::DIBitmap from a Win32::GUI::Bitmap.
newFromDC (hdc, [x, y, w, h] )
Create a Win32::GUI::DIBitmap from a Win32::GUI::DC.

You can capture only a portion of the HDC with x,y,w,h option.
newFromWindow (hwnd, [flag = 0])
Create a Win32::GUI::DIBitmap from a Win32::GUI::Window.

flag = 0 : All the window is capture (with border)
flag = 1 : Only the Client window is capture

DIBitmap Save methods

SaveToFile (filename, [fif, flag])
Save a Win32::GUI::DIBitmap in a file.

Some format have special save format :

Type  | Flag                | Description
------+---------------------+--------------------------------------------------
BMP   | BMP_SAVE_RLE        | Compress bitmap using RLE
JPEG  | JPEG_DEFAULT        | Save with good quality (75:1)
      | JPEG_QUALITYSUPERB  | Save with superb quality (100:1)
      | JPEG_QUALITYGOOD    | Save with good quality (75:1)
      | JPEG_QUALITYNORMAL  | Save with normal quality (50:1)
      | JPEG_QUALITYAVERAGE | Save with average quality (25:1)
      | JPEG_QUALITYBAD     | Save with bad quality (10:1)
PxM   | PNM_DEFAULT         | Save bitmap as a binary file
      | PNM_SAVE_RAW        | Save bitmap as a binary file
      | PNM_SAVE_ASCII      | Save bitmap as a ascii file
TIFF  | TIFF_DEFAULT        | Save using CCITFAX4 compression for 1bit and PACKBITS for other
      | TIFF_CMYK           | Store tags for separated CMYK (conbine with compresion flag)
      | TIFF_PACKBITS       | Save using PACKBITS compression
      | TIFF_DEFLATE        | Save using DEFLATE compression
      | TIFF_ADOBE_DEFLATE  | Save using Adobe DEFLATE compression
      | TIFF_NONE           | Save without compression

A tempory convertion is done for 16-32bit JPEG and 16bit PNG before saving.
SaveToData (fif, [flag])
Save a Win32::GUI::DIBitmap in memory.

DIBitmap information methods

GetWidth () or Width
Return the Width of the image.
GetHeight () or Height
Return the Height of the image.
GetColorsUsed ()
Return the number of color use in the image.
GetBpp ()
Return the bit per pixel use in the image.
GetRedMask ()
Return a bit pattern describing the red color copmponent of a pixel.
GetGreenMask ()
Return a bit pattern describing the green color copmponent of a pixel.
GetBlueMask ()
Return a bit pattern describing the blue color copmponent of a pixel.
GetColorType ()
Return the color type of the image.

Values :
  FIC_MINISWHITE = 0 : Monochrome bitmap, with first palette entry is white
  FIC_MINISBLACK = 1 : Monochrome bitmap, with first palette entry is black
                       Palletised bitmap, with greyscale palette
  FIC_RGB        = 2 : RGB color model
  FIC_PALETTE    = 3 : Color map indexed
  FIC_RGBALPHA   = 4 : RGB color model with alpha channel
  FIC_CMYK       = 5 : CMYK color model
GetPitch ()
Return pitch of data image.
Pitch it's the width of the bitmap in bytes, rounded to the next 32 bit boundary.
GetDotsPerMeterX ()
Return dots per meter on X.
GetDotsPerMeterY ()
Return dots per meter on Y.
GetInfoHeader ()
Return a windows BITMAPINFOHEADER struct.
GetInfo ()
Return a window BITMAPINFO struct.
GetSize ()
Return memory size of data for the image
GetBits ()
Return data of the image
IsTransparent ()
Image is transparent.

DIBitmap and GD

newFromGD (gd, newGD=0)
Create a Win32::GUI::DIBitmap from a GD image
New object have same size and format, gd image copy into.

Flag newGD is for new GD version (> 2.0) with trueColor bitmap.
Default value force 8 bit bitmap.
CopyFromGD (gd, newGD=0)
Copy GD image into Win32::GUI::DIBitmap.
GD and Win32::GUI::DIBitmap must have same size and format.
CopyToGD (gd, newGD=0)
Copy Win32::GUI::DIBitmap into GD image.
GD and Win32::GUI::DIBitmap must have same size and format.

DIBitmap Convertion methods

ConvertToBitmap ()
Convert a Win32::GUI::DIBitmap to a new Win32::GUI::Bitmap.
ConvertTo8Bits ()
Convert a Win32::GUI::DIBitmap to a new 8 bits (grayscale) Win32::GUI::DIBitmap.
See ColorQuantize for convert to 8 bits colors.
ConvertTo16Bits555 ()
Convert a Win32::GUI::DIBitmap to a new 16 bits Win32::GUI::DIBitmap (555 format).
ConvertTo16Bits565 ()
Convert a Win32::GUI::DIBitmap to a new 16 bits Win32::GUI::DIBitmap (565 format).
ConvertTo24Bits ()
Convert a Win32::GUI::DIBitmap to a new 24 bits Win32::GUI::DIBitmap.
ConvertTo32Bits ()
Convert a Win32::GUI::DIBitmap to a new 32 bits Win32::GUI::DIBitmap.
ColorQuantize ([flag = FIQ_WUQUANT])
Convert a Win32::GUI::DIBitmap to a new 8 bits (colorscale) Win32::GUI::DIBitmap.
None 24 bits image are converted to 24bits before.

Flag possible value :
FIQ_WUQUANT = Xiaolin Wu color quantization algorithm
FIQ_NNQUANT = NeuQuant neural-net quantization algorithm by Anthony Dekker
Threshold (T)
Convert a Win32::GUI::DIBitmap to a new 1 bit Win32::GUI::DIBitmap using a Threshold between 0..255.
Dither ([flag = FID_FS])
Convert a Win32::GUI::DIBitmap to a new 1 bit Win32::GUI::DIBitmap.

Flag possible value :
FID_FS            = Floyd and Steinberg error diffusion algorithm.
FID_BAYER4x4      = Bayer ordered dispersed dot dithering (order 2 - 4*4 matrix)
FID_BAYER8x8      = Bayer ordered dispersed dot dithering (order 3 - 8*8 matrix)
FID_CLUSTER6x6    = Ordered clustered dot dithering (order 3 - 6*6 matrix)
FID_CLUSTER8x8    = Ordered clustered dot dithering (order 4 - 8*8 matrix)
FID_CLUSTER16x16  = Ordered clustered dot dithering (order 8 - 16*16 matrix)

DIBitmap Rotating and flipping

Rotate (angle)
Create a new rotated Win32::GUI::DIBitmap (8,24,32 bits only)

This function rotates an 8-bit greyscale, 24- or 32-bit image by means of 3 shears. The angle
of rotation is specified by the angle parameter in degrees. Rotation occurs around the center
of the image area. Rotated image retains size and aspect ratio of source image (destination
image size is usually bigger), so that this function should be used when rotating an image by
90°, 180° or 270°.
RotateEx (angle, x_shift, y_shift, x_origin, y_origin, use_mask)
Create a new rotated/translated Win32::GUI::DIBitmap (8,24,32 bits only)

This function performs a rotation and / or translation of an 8-bit greyscale, 24- or 32-bit
image, using a 3rd order (cubic) B-Spline. The rotated image will have the same width and
height as the source image, so that this function is better suited for computer vision and
robotics.
The angle of rotation is specified by the angle parameter in degrees. Horizontal and vertical
image translations (in pixel units) are specified by the x_shift and y_shift parameters.
Rotation occurs around the center specified by x_origin and y_origin, also given in pixel units.
When use_mask is set to TRUE, the irrelevant part of the image is set to a black color,
otherwise, a mirroring technique is used to fill irrelevant pixels.
FlipHorizontal ()
Flip DIBitmap dib horizontally along the vertical axis.
FlipVertical ()
Flip DIBitmap vertically along the horizontal axis.

DIBitmap UpSampling / DownSampling

Rescale (new_width, new_heigth, filter=FILTER_BOX)
Create a new size Win32::GUI::DIBitmap (32 bits only)

This function performs resampling (or scaling, zooming) of a 32-bit image to the desired destination width and height.
Resampling refers to changing the pixel dimensions (and therefore display size) of an image.
When you downsample (or decrease the number of pixels), information is deleted from the image. When you upsample (or increase the number of pixels), new pixels are added based
on color values of existing pixels. You specify an interpolation filter to determine how pixels are added or deleted.

The following filters can be used as resampling filters:
  FILTER_BOX        = Box, pulse, Fourier window, 1st order (constant) B-Spline
  FILTER_BILINEAR   = Bilinear filter
  FILTER_BSPLINE    = 4th order (cubic) B-Spline
  FILTER_BICUBIC    = Mitchell and Netravali's two-param cubic filter
  FILTER_CATMULLROM = Catmull-Rom spline, Overhauser spline
  FILTER_LANCZOS3   = Lanczos-windowed sinc filter

DIBitmap Color manipulation

AdjustGamma (gamma)
Adjust Gamma of Win32::GUI::DIBitmap (8,24,32 bits only)

The gamma parameter represents the gamma value to use (gamma > 0).
A value of 1.0 leaves the image alone, less than one darkens it, and greater than one lightens it.
AdjustBrightness (percentage)
Adjust Brightness of Win32::GUI::DIBitmap (8,24,32 bits only)

Adjusts the brightness of a 8-, 24- or 32-bit image by a certain amount.
This amount is given by the percentage parameter, where percentage is a value between [-100..100].
A value 0 means no change, less than 0 will make the image darker and greater than 0 will make the image brighter.
AdjustContrast (percentage)
Adjust ContrastCreate of Win32::GUI::DIBitmap (8,24,32 bits only)

Adjusts the contrast of a 8-, 24- or 32-bit image by a certain amount.
This amount is given by the percentage parameter, where percentage is a value between [-100..100].
A value 0 means no change, less than 0 will decrease the contrast and greater than 0 will increase the contrast of the image.
Invert ()
Inverts each pixel data.
GetHistogram (channel)
Return a histogram array[0..255] of a Win32::GUI::DIBitmap (8,24,32 bits only)

Computes the image histogram.
For 24-bit and 32-bit images, histogram can be computed from red, green, blue and black channels.
For 8-bit images, histogram is computed from the black channel.

DIBitmap Channel methods

Channel Constante
FICC_RGB     = 0 : Use red, green and blue channels
FICC_RED     = 1 : Use red channel
FICC_GREEN   = 2 : Use green channel
FICC_BLUE    = 3 : Use blue channel
FICC_ALPHA   = 4 : Use alpha channel
FICC_BLACK   = 5 : Use black channel
GetChannel (channel)
Return a 8bits channel Win32::GUI::DIBitmap.

Retrieves the red, green, blue or alpha channel of a 24 or 32-bit BGR[A] image.
Channel is the color channel to extract.

24,32 only
SetChannel (channel, 8bit_image)
Set the red, green, blue or alpha channel of a 24 or 32-bit BGR[A] image.
Channel is the color channel to extract.

24,32 only

DIBitmap Copy/Paste methods

Clone ()
Clone a Win32::GUI::DIBitmap to a new Win32::GUI::Bitmap.
Copy (left, top, right, botton)
Return a new Win32::GUI::Bitmap with a sub part Win32::GUI::DIBitmap (8, 16, 24 or 32 only).

Left specifies the left position of the cropped rectangle.
Top specifies the top position of the cropped rectangle.
Right specifies the right position of the cropped rectangle.
Bottom specifies the bottom position of the cropped rectangle.
Paste (source_image, left, top, alpha)
Returns TRUE if successful, FALSE otherwise ( 8, 16, 24 or 32 only).

Alpha blend or combine a sub part image with the current dib image.
The bit depth must be greater than or equal to the bit depth of source image.

Alpha is alpha blend factor.
The source and destination images are alpha blended if alpha=0..255.
If alpha > 255, then the source image is combined to the destination image.

DIBitmap Devise Context methods

CopyToDC (hdc, [xd=0, yd=0, w=0, h=0, xs=0, ys=0])
Copy Win32::GUI::DIBitmap to a Win32::GUI::DC.

Specify the destination rectangle with xd,yd,w,h option.
Specify the begining of the image with xs,ys option.
The image copy keep the same size.
AlphaCopyToDC (hdc, [xd=0, yd=0, w=0, h=0, xs=0, ys=0])
Copy Win32::GUI::DIBitmap to a Win32::GUI::DC with transparency / alpha channel support.

Specify the destination rectangle with xd,yd,w,h option.
Specify the begining of the image with xs,ys option.
The image copy keep the same size.
StretchToDC (hdc, [xd=0, yd=0, wd=0, hd=0, xs=0, ys=0, ws=0, hs=0, flag=SRCCOPY])
Copy Win32::GUI::DIBitmap to a Win32::GUI::DC.

Specify the destination rectangle with xd,yd,wd,hd option.
Specify the image source rectangle ith xs,ys,ws,hs option.
The image copy is resize if necessary.

For flag option, see StretchDIBits win32 function.
AlphaStretchToDC (hdc, [xd=0, yd=0, wd=0, hd=0, xs=0, ys=0, ws=0, hs=0)
Copy Win32::GUI::DIBitmap to a Win32::GUI::DC with transparency / alpha channel support.

Specify the destination rectangle with xd,yd,wd,hd option.
Specify the image source rectangle ith xs,ys,ws,hs option.
The image copy is resize if necessary.

MDIBITMAP OBJECT

MDIBitmap New methods

new (filename, fif=-1, keep_cache_in_memory=0)
Create a new Win32::GUI::MDIBBitmap in edit mode.
newFromFile (filename, read_only=1, keep_cache_in_memory=0)
Create a Win32::GUI::MDIBBitmap from a image file.

MDIBitmap Get methods

GetPageCount
Return page count.
GetLockedPageNumbers
Return a list of locked page index.

MDIBitmap Lock methods

LockPage ([index = 0])
Lock and return a page (Win32::GUI::DIBitmap object).
UnlockPage (Win32::GUI::DIBitmap, [update = 0])
Unlock a locked page (Win32::GUI::DIBitmap object).
Update indicate if the page must be updated.

MDIBitmap Edit methods

AppendPage (Win32::GUI::DIBitmap)
Append a Win32::GUI::DIBitmap to a Win32::GUI::MDIBBitmap.
InsertPage (Win32::GUI::DIBitmap, [index = 0])
Insert a Win32::GUI::DIBitmap in a Win32::GUI::MDIBBitmap.
DeletePage ([index = 0])
Delete a page from a Win32::GUI::MDIBBitmap.
MovePage (to_index, [from_index = 0])
Move a page in a Win32::GUI::MDIBBitmap.

AUTHOR

Laurent Rocher (lrocher@cpan.org) HomePage : http://perso.club-internet.fr/rocherl/Win32GUI.html

SEE ALSO

Win32::GUI

37 POD Errors

The following errors were encountered while parsing the POD:

Around line 388:

'=item' outside of any '=over'

Around line 396:

You forgot a '=back' before '=head2'

Around line 398:

'=item' outside of any '=over'

Around line 439:

You forgot a '=back' before '=head2'

Around line 441:

'=item' outside of any '=over'

Around line 461:

You forgot a '=back' before '=head1'

Around line 465:

'=item' outside of any '=over'

Around line 507:

You forgot a '=back' before '=head2'

Around line 509:

'=item' outside of any '=over'

Around line 540:

You forgot a '=back' before '=head2'

Around line 542:

'=item' outside of any '=over'

Around line 616:

You forgot a '=back' before '=head2'

Around line 618:

'=item' outside of any '=over'

Around line 636:

You forgot a '=back' before '=head2'

Around line 638:

'=item' outside of any '=over'

Around line 688:

You forgot a '=back' before '=head2'

Around line 690:

'=item' outside of any '=over'

Around line 698:

Non-ASCII character seen before =encoding in '90°,'. Assuming CP1252

Around line 722:

You forgot a '=back' before '=head2'

Around line 724:

'=item' outside of any '=over'

Around line 741:

You forgot a '=back' before '=head2'

Around line 743:

'=item' outside of any '=over'

Around line 778:

You forgot a '=back' before '=head2'

Around line 780:

'=item' outside of any '=over'

Around line 805:

You forgot a '=back' before '=head2'

Around line 807:

'=item' outside of any '=over'

Around line 831:

You forgot a '=back' before '=head2'

Around line 833:

'=item' outside of any '=over'

Around line 867:

You forgot a '=back' before '=head1'

Around line 871:

'=item' outside of any '=over'

Around line 879:

You forgot a '=back' before '=head2'

Around line 881:

'=item' outside of any '=over'

Around line 889:

You forgot a '=back' before '=head2'

Around line 891:

'=item' outside of any '=over'

Around line 900:

You forgot a '=back' before '=head2'

Around line 902:

'=item' outside of any '=over'

Around line 918:

You forgot a '=back' before '=head1'