NAME
Win32::GUI::DIBitmap - add new reading/writing image 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 adds new reading/writing image formats to Win32::GUI and some image manipulation.
This package use FreeImage 3.8.0, an open source image library supporting all common image formats 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 = 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 Y X11 Pixmap Format [Export = 8 24]
DDS Y N DirectX Surface
GIF Y Y Graphics Interchange Format [Export = 8]
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
Constant
-
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 FIF_DDS FIF_GIF
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.
FIFRegExpr
(fif)-
Return a regexp string for identify format.
FIFMimeType
(fif)-
Return a mime-type 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 ?
FIFSupportsExportType
(fif, type)-
This format can export as image format type ?
FIFSupportsICCProfiles
(fif)-
This format support ICC profile ?
Colors functions
LookupX11Color
(string_color)-
Return Color of string color or undef if error. This color value can be an integer value or a [B,G,R,A] array.
LookupSVGColor
(string_color)-
Return Color of string color or undef if error. This color value can be an integer value or a [B,G,R,A] array.
DIBITMAP OBJECT
DIBitmap New methods
new
([width=100, height=100, bpp=24, redmask=0, bluemask=0, greemask=0, type=FIT_BITMAP])-
Allocate a Win32::GUI::DIBitmap object.
Image storage types availlable.
FIT_UNKNOWN = 0 : unknown type FIT_BITMAP = 1 : standard image : 1-, 4-, 8-, 16-, 24-, 32-bit FIT_UINT16 = 2 : array of unsigned short : unsigned 16-bit FIT_INT16 = 3 : array of short : signed 16-bit FIT_UINT32 = 4 : array of unsigned long : unsigned 32-bit FIT_INT32 = 5 : array of long : signed 32-bit FIT_FLOAT = 6 : array of float : 32-bit IEEE floating point FIT_DOUBLE = 7 : array of double : 64-bit IEEE floating point FIT_COMPLEX = 8 : array of FICOMPLEX : 2 x 64-bit IEEE floating point
newFromFile
(filename, [flag])-
Create a Win32::GUI::DIBBitmap from a image file.
Some format have special load flag :
Type | Flag | Description -------+-------------------+---------------------------------------- ICO | ICO_MAKEALPHA | Convert to 32bpp and create an alpha | | channel from the AND-mask when loading JPEG | JPEG_FAST | Load file fast (sacrifing quality) | JPEG_ACCURATE | Load file with 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 | | (combine 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 | TIFF_CCITTFAX3 | Save using CCITT Group 3 fax encoding | TIFF_CCITTFAX4 | Save using CCITT Group 4 fax encoding | TIFF_LZW | Save using LZW 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
() orWidth
-
Return the Width of the image.
GetHeight
() orHeight
-
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
GetLine
()-
Return width of data image in bytes.
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.
GetImageType
()-
Return image type.
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 Pixels and Background methods
GetPixel
(x, y)-
Return pixel value color at x, y or undef if error. For image with BPP <= 8 return palette index color. For image with BPP > 8 return color value. This color value can be an integer value or a [B,G,R,A] array.
SetPixel
(x, y, color | Blue, Green, Red, [Alpha])-
Set pixel value color at x, y. Return boolean value. For image with BPP <= 8, it's palette color index. For image with BPP > 8, arguments can an integer color value or B,G,R,[A] values.
HasBackgroundColor
()-
Indicate if image have Background Color.
GetBackgroundColor
()-
Return Background Color or undef if error. This color value can be an integer value or a [B,G,R,A] array.
SetBackgroundColor
(color | Blue, Green, Red, [Alpha])-
Set Background Color. Return boolean value.
DIBitmap Convertion methods
ConvertToBitmap
()-
Convert a Win32::GUI::DIBitmap to a new Win32::GUI::Bitmap.
ConvertTo4Bits
()-
Convert a Win32::GUI::DIBitmap to a new 4 bits Win32::GUI::DIBitmap.
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)
ConvertToStandardType
([scale_linear=TRUE])-
TBD
ConvertToType
(type, [scale_linear=TRUE])-
For type see new method.
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 Constant
-
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 FICC_REAL = 6 : Complex images: use real part FICC_IMAG = 7 : Complex images: use imaginary part FICC_MAG = 8 : Complex images: use magnitude FICC_PHASE = 9 : Complex images: use phase
GetChannel
(channel)-
Return an 8-bit 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.
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 set.
GetComplexChannel
(channel)-
Return a complex 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.
SetComplexChannel
(channel, 8bit_image)-
Set the red, green, blue or alpha channel of a 24 or 32-bit BGR[A] image. Channel is the complex channel to set.
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.
Composite
([useFileBkg=FALSE, imageBkg=undef appBkColor=undef)-
TBD
DIBitmap Device 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::MDIBitmap in edit mode.
newFromFile
(filename, read_only=1, keep_cache_in_memory=0)-
Create a Win32::GUI::MDIBitmap 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.
SEE ALSO
AUTHOR
Laurent Rocher (lrocher@cpan.org)
COPYRIGHT AND LICENCE
Copyright 2003 by Laurent Rocher (lrocher@cpan.org).
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See http://www.perl.com/perl/misc/Artistic.html
Unmodified code from the FreeImage project (http://freeimage.sourceforge.net) is statically linked into this module. The FreeImage code is released under the GNU General Public Licence (http://www.opensource.org/licenses/gpl-license.php) and the FreeImage Public Licence (http://freeimage.sourceforge.net/freeimage-license.txt)