Win32::GUI::DIBitmap - add new reading/writing image formats to Win32::GUI and some image manipulation. |
Win32::GUI::DIBitmap - add new reading/writing image formats to Win32::GUI and some image manipulation.
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 }
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).
GetVersion
()GetCopyright
()
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
()GetFormatFromFIF
(fif)GetFIFFromFormat
(format)GetFIFFromMime
(mime)GetFIFFromFilename
(filename)GetFIFFromFile
(filename)GetFIFFromData
(data)
FIFExtensionList
(fif)FIFDescription
(fif)FIFRegExpr
(fif)FIFMimeType
(fif)FIFSupportsReading
(fif)FIFSupportsWriting
(fif)FIFSupportsExportBPP
(fif, bpp)FIFSupportsExportType
(fif, type)FIFSupportsICCProfiles
(fif)
LookupX11Color
(string_color)LookupSVGColor
(string_color)
new
([width=100, height=100, bpp=24, redmask=0, bluemask=0, greemask=0, type=FIT_BITMAP])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])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])newFromBitmap
(hbitmap)newFromDC
(hdc, [x, y, w, h] )You can capture only a portion of the HDC with x,y,w,h option.
newFromWindow
(hwnd, [flag = 0])flag = 0 : All the window is capture (with border) flag = 1 : Only the Client window is capture
SaveToFile
(filename, [fif, flag])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.
GetWidth
() or Width
GetHeight
() or Height
GetColorsUsed
()GetBPP
()GetRedMask
()GetGreenMask
()GetBlueMask
()GetColorType
()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
()GetPitch
()GetDotsPerMeterX
()GetDotsPerMeterY
()GetInfoHeader
()GetInfo
()GetSize
()GetBits
()IsTransparent
()GetImageType
()
newFromGD
(gd, newGD=0)Flag newGD is for new GD version (> 2.0) with trueColor bitmap. Default value force 8 bit bitmap.
CopyFromGD
(gd, newGD=0)CopyToGD
(gd, newGD=0)
GetPixel
(x, y)SetPixel
(x, y, color | Blue, Green, Red, [Alpha])HasBackgroundColor
()GetBackgroundColor
()SetBackgroundColor
(color | Blue, Green, Red, [Alpha])
ConvertToBitmap
()ConvertTo4Bits
()ConvertTo8Bits
()ConvertTo16Bits555
()ConvertTo16Bits565
()ConvertTo24Bits
()ConvertTo32Bits
()ColorQuantize
([flag = FIQ_WUQUANT])Flag possible value : FIQ_WUQUANT = Xiaolin Wu color quantization algorithm FIQ_NNQUANT = NeuQuant neural-net quantization algorithm by Anthony Dekker
Threshold
(T)Dither
([flag = FID_FS])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])ConvertToType
(type, [scale_linear=TRUE])
Rotate
(angle)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)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
()FlipVertical
()
Rescale
(new_width, new_heigth, filter=FILTER_BOX)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
AdjustGamma
(gamma)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)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)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
()GetHistogram
(channel)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.
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)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)GetComplexChannel
(channel)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)
Clone
()Copy
(left, top, right, botton)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)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)
CopyToDC
(hdc, [xd=0, yd=0, w=0, h=0, xs=0, ys=0])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])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])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)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.
new
(filename, fif=-1, keep_cache_in_memory=0)newFromFile
(filename, read_only=1, keep_cache_in_memory=0)
GetPageCount
GetLockedPageNumbers
LockPage
([index = 0])UnlockPage
(Win32::GUI::DIBitmap, [update = 0])
AppendPage
(Win32::GUI::DIBitmap)InsertPage
(Win32::GUI::DIBitmap, [index = 0])DeletePage
([index = 0])MovePage
(to_index, [from_index = 0])
Laurent Rocher (lrocher@cpan.org)
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)
Win32::GUI::DIBitmap - add new reading/writing image formats to Win32::GUI and some image manipulation. |