1pod::Prima::Image(3)  User Contributed Perl Documentation pod::Prima::Image(3)
2
3
4

NAME

6       Prima::Image - Bitmap routines
7

SYNOPSIS

9          use Prima qw(Application);
10
11          # create a new image from scratch
12          my $i = Prima::Image-> new(
13             width => 32,
14             height => 32,
15             type   => im::BW, # same as im::bpp1 | im::GrayScale
16          );
17
18          # draw something
19          $i-> begin_paint;
20          $i-> color( cl::White);
21          $i-> ellipse( 5, 5, 10, 10);
22          $i-> end_paint;
23
24          # mangle
25          $i-> size( 64, 64);
26
27          # file operations
28          $i-> save('a.gif') or die "Error saving:$@\n";
29          $i-> load('a.gif') or die "Error loading:$@\n";
30
31          # draw on screen
32          $::application-> begin_paint;
33
34          # an image is drawn as specified by its palette
35          $::application-> put_image( 100, 100, $i);
36
37          # a bitmap is drawn as specified by destination device colors
38          $::application-> set( color => cl::Red, backColor => cl::Green);
39          $::application-> put_image( 200, 100, $i-> bitmap);
40

DESCRIPTION

42       Prima::Image, Prima::Icon and Prima::DeviceBitmap are classes for
43       bitmap handling, including file and graphic input and output.
44       Prima::Image and Prima::DeviceBitmap are descendants of Prima::Drawable
45       and represent bitmaps, stored in memory.  Prima::Icon is a descendant
46       of Prima::Image and contains a transparency mask along with the regular
47       data.
48

USAGE

50       Images usually are represented as a memory area, where pixel data are
51       stored row-wise. The Prima toolkit is no exception, however, it does
52       not assume that the GUI system uses the same memory format.  The
53       implicit conversion routines are called when Prima::Image is about to
54       be drawn onto the screen, for example. The conversions are not always
55       efficient, therefore the Prima::DeviceBitmap class is introduced to
56       represent a bitmap, stored in the system memory in the system pixel
57       format. These two basic classes serve the different needs, but can be
58       easily converted to each other, with "image" and "bitmap" methods.
59       Prima::Image is a more general bitmap representation, capable of file
60       and graphic input and output, plus it is supplied with number of
61       conversion and scaling functions. The Prima::DeviceBitmap class has
62       almost none of additional functionality, and is targeted to efficient
63       graphic input and output.
64
65       Note: If you're looking for information how to display an image, this
66       is not the manual page. Look either at Prima::ImageViewer, or use
67       "put_image" / "stretch_image" ( Prima::Drawable ) inside your widget's
68       onPaint.
69
70   Graphic input and output
71       As descendants of Prima::Drawable, all Prima::Image, Prima::Icon and
72       Prima::DeviceBitmap objects are subject to three-state painting mode -
73       normal ( disabled ), painting ( enabled ) and informational.
74       Prima::DeviceBitmap is, however, exists only in the enabled state, and
75       can not be switched to the other two.
76
77       When an object enters the enabled state, it serves as a canvas, and all
78       Prima::Drawable operations can be performed on it. When the object is
79       back to the disabled state, the graphic information is stored into the
80       object associated memory, in the pixel format, supported by the
81       toolkit.  This information can be visualized by using one of
82       "Prima::Drawable::put_image" group methods. If the object enters the
83       enabled state again, the graphic information is presented as an initial
84       state of a bitmap.
85
86       It must be noted, that if an implicit conversion takes place after an
87       object enters and before it leaves the enabled state, as it is with
88       Prima::Image and Prima::Icon, the bitmap is converted to the system
89       pixel format. During such conversion some information can be lost, due
90       to down-sampling, and there is no way to preserve the information. This
91       does not happen with Prima::DeviceBitmap.
92
93       Image objects can be drawn upon images, as well as on the screen and
94       Prima::Widget objects. This operation is performed via one of
95       Prima::Drawable::put_image group methods ( see Prima::Drawable), and
96       can be called with the image object disregarding the paint state. The
97       following code illustrates the dualism of an image object, where it can
98       serve both as a drawing surface and as a drawing tool:
99
100           my $a = Prima::Image-> create( width => 100, height => 100, type => im::RGB);
101           $a-> begin_paint;
102           $a-> clear;
103           $a-> color( cl::Green);
104           $a-> fill_ellipse( 50, 50, 30, 30);
105           $a-> end_paint;
106           $a-> rop( rop::XorPut);
107           $a-> put_image( 10, 10, $a);
108           $::application-> begin_paint;
109           $::application-> put_image( 0, 0, $a);
110           $::application-> end_paint;
111
112       It must be noted, that "put_image", "stretch_image" and
113       "put_image_indirect" only allow "Prima::Image" descendants to be passed
114       as a source image object.  This functionality does not imply that the
115       image is internally switched to the paint-enabled state and back; on
116       the contrary, the painting is performed without switching and using
117       only Prima's own code, without using the system's graphical layer.
118
119       Another special case is a 1-bit ( monochrome ) DeviceBitmap. When it is
120       drawn upon a drawable with bit depth greater than 1, the drawable's
121       color and backColor properties are used to reflect 1 and 0 bits,
122       respectively. On a 1-bit drawable this does not happen, and the color
123       properties are not used.
124
125   File input and output
126       Depending on the toolkit configuration, images can be read and written
127       in different formats. This functionality in accessible via "load()" and
128       "save()" methods. Prima::image-load is dedicated to the description of
129       loading and saving parameters, that can be passed to the methods, so
130       they can handle different aspects of file format-specific options, such
131       as multi-frame operations, auto conversion when a format does not
132       support a particular pixel format etc. In this document, "load()" and
133       "save()" methods are illustrated only in their basic, single-frame
134       functionality. When called with no extra parameters, these methods fail
135       only if a disk I/O error occurred or an unknown image format was used.
136
137       When an image is loaded, the old bitmap memory content is discarded,
138       and the image attributes are changed accordingly to the loaded image.
139       Along with these, an image palette is loaded, if available, and a pixel
140       format is assigned, closest or identical to the pixel format in the
141       image file.
142
143   Pixel formats
144       Prima::Image supports a number of pixel formats, governed by the
145       "::type" property. It is reflected by an integer value, a combination
146       of "im::XXX" constants. The whole set of pixel formats is represented
147       by colored formats, like, 16-color, 256-color and 16M-color, and by
148       gray-scale formats, mapped to C data types - unsigned char, unsigned
149       short, unsigned long, float and double.  The gray-scale formats are
150       further subdivided to real-number formats and complex-number format;
151       the last ones are represented by two real values per pixel, containing
152       the real and the imaginary values.
153
154       Prima::Image can also be initialized from other formats, that it does
155       not support, but can convert data from. Currently these are represented
156       by a set of permutations of 32-bit RGBA format, and 24-bit BGR format.
157       These formats can only be used in conjunction with "::data" property.
158
159       The conversions can be performed between any of the supported formats (
160       to do so, "::type" property is to be set-called ). An image of any of
161       these formats can be drawn on the screen, but if the system can not
162       accept the pixel format ( as it is with non-integer or complex formats
163       ), the bitmap data are implicitly converted. The conversion does not
164       change the data if the image is about to be drawn; the conversion is
165       performed only when the image is about to be served as a drawing
166       surface. If, by any reason, it is desired that the pixel format is not
167       to be changed, the "::preserveType" property must be set to 1. It does
168       not prevent the conversion, but it detects if the image was implicitly
169       converted inside "end_paint()" call, and reverts it to its previous
170       pixel format.
171
172       There are situations, when pixel format must be changed together while
173       down-sampling the image. One of four down-sampling methods can be
174       selected - no halftoning, 8x8 ordered halftoning, error diffusion, and
175       error diffusion combined with optimized palette. These can be set to
176       the "::conversion" property with one of "ict::XXX" constants.  When
177       there is no information loss, "::conversion" property is not used.
178
179       Another special case of conversion is a conversion with a palette. The
180       following calls,
181
182         $image-> type( im::bpp4);
183         $image-> palette( $palette);
184
185       and
186
187         $image-> palette( $palette);
188         $image-> type( im::bpp4);
189
190       produce different results, but none of these takes into account
191       eventual palette remapping, because "::palette" property does not
192       change bitmap pixel data, but overwrites palette information. A proper
193       call syntax here would be
194
195         $image-> set(
196            palette => $palette,
197            type    => im::bpp4,
198         );
199
200       This call produces also palette pixel mapping.  This syntax is most
201       powerful when conversion is set to those algorithms that can take in
202       the account the existing image pixels, to produce an optimized palette.
203       These are "ict::Optimized" ( by default ) and "ict::Posterization".
204       This syntax not only allows remapping or downsampling to a predefined
205       colors set, but also can be used to limit palette size to a particular
206       number, without knowing the actual values of the final color palette.
207       For example, for an 24-bit image,
208
209         $image-> set( type => im::bpp8, palette => 32);
210
211       call would calculate colors in the image, compress them to an optimized
212       palette of 32 cells and finally converts to a 8-bit format.
213
214       Instead of "palette" property, "colormap" can also be used.
215
216   Data access
217       The pixel values can be accessed in Prima::Drawable style, via
218       "::pixel" property. However, Prima::Image introduces several helper
219       functions on its own.
220
221       The "::data" property is used to set or retrieve a scalar
222       representation of bitmap data. The data are expected to be lined up to
223       a 'line size' margin ( 4-byte boundary ), which is calculated as
224
225         $lineSize = int(( $image->width * ( $image-> type & im::BPP) + 31) / 32) * 4;
226
227       or returned from the read-only property "::lineSize".
228
229       This is the line size for the data as lined up internally in memory,
230       however "::data" should not necessarily should be aligned like this,
231       and can be accompanied with a write-only flag 'lineSize' if pixels are
232       aligned differently:
233
234         $image-> set( width => 1, height=> 2);
235         $image-> type( im::RGB);
236         $image-> set(
237            data => 'RGB----RGB----',
238            lineSize => 7,
239         );
240         print $image-> data, "\n";
241
242         output: RGB-RGB-
243
244       Internally, Prima contains images in memory so that the first scanline
245       is the farthest away from the memory start; this is consistent with
246       general Y-axis orientation in Prima drawable terminology, but might be
247       inconvenient when importing data organized otherwise. Another write-
248       only boolean flag "reverse" can be set to 1 so data then are treated as
249       if the first scanline of the image is the closest to the start of data:
250
251         $image-> set( width => 1, height=> 2, type => im::RGB);
252         $image-> set(
253            data => 'RGB-123-',
254            reverse => 1,
255         );
256         print $image-> data, "\n";
257
258         output: RGB-123-
259
260       Although it is possible to perform all kinds of calculations and
261       modification with the pixels, returned by "::data", it is not advisable
262       unless the speed does not matter. Standalone PDL package with help of
263       PDL::PrimaImage package, and Prima-derived IPA package provide routines
264       for data and image analysis.  Also, Prima::Image::Magick connects
265       ImageMagick with Prima.  Prima::Image itself provides only the simplest
266       statistic information, namely: lowest and highest pixel values, pixel
267       sum, sum of square pixels, mean, variance, and standard deviation.
268
269   Standalone usage
270       Some of image functionality can be used standalone, with all other
271       parts of the toolkit being uninitialized. The functionality is limited
272       to loading and saving files, and reading and writing pixels (outside
273       begin_paint only).  All other calls are ignored. Example:
274
275          my $i = Prima::Image->new( size => [5,5]);
276          $i->color(cl::Red);
277          $i->bar(0,0,$i->size);
278          $i->save('1.bmp');
279
280       This feature is useful in non-interactive programs, running in
281       environments with no GUI access, a cgi-script with no access to X11
282       display, for example.  Normally, Prima fails to start in such
283       situations, but can be told not to initialize its GUI part by
284       explicitly operating system-dependent options. To do so, invoke
285
286         use Prima::noX11;
287
288       in the beginning of your program. See Prima::noX11 for more.
289
290       Generally the standalone methods support all the OS-specific functions
291       (i.e. color, region, etc), plus they support alpha blending using "rop"
292       property and "rop::alpha($rop, $src_alpha[, $dst_alpha]))" value.
293
294       See individual methods and properties in API that support standalone
295       usage, and how they differ from system-dependent implementation.
296
297   Prima::Icon
298       Prima::Icon inherits all properties of Prima::Image, and it also
299       provides a transparency mask of either 1 or 8 bits.  This mask can also
300       be loaded and saved into image files, if the format supports
301       transparency information.
302
303       Similar to Prima::Image::data property, Prima::Icon::mask property
304       provides access to the binary mask data.  The mask can be updated
305       automatically, after an icon object was subject to painting, resizing,
306       or other destructive change.  The auxiliary properties "::autoMasking"
307       and "::maskColor"/"::maskIndex" regulate  mask update procedure. For
308       example, if an icon was loaded with the color ( vs. bitmap )
309       transparency information, the binary mask will be generated anyway, but
310       it will be also recorded that a particular color serves as a
311       transparent indicator, so eventual conversions can rely on the color
312       value, instead of the mask bitmap.
313
314       If an icon is drawn upon a graphic canvas, the image output is
315       constrained to the mask. On raster displays it is typically simulated
316       by a combination of and- and xor- operation modes, therefore attempts
317       to put an icon with "::rop", different from "rop::CopyPut", usually
318       fail.
319
320   Layering
321       The term layered window is borrowed from Windows world, and means a
322       window with transparency. In Prima, the property layered is used to
323       select this functionality. The call to
324       "$::application->get_system_value(sv::LayeredWidgets)" can check
325       whether this functionality is available; if not, the property is
326       ignored.  By default, widgets can not use layering.
327
328       A layered drawable uses an extra alpha channel to designate the
329       transparency.  Drawing on widgets will also look different - for
330       example, drawing with black color will make the black pixels fully
331       transparent, while other colors will blend with the underlying
332       background, but never in full. Prima provides no functions to draw with
333       alpha effects, and scarce image functions to address the alpha
334       surfaces. Drawing lines, text, etc with blending is delegated to
335       Prima::Cairo which is a separate module. Prima only provides alpha
336       surfaces and bitmaps with an additional alpha channel to draw upon.
337       However, "put_image" / "stretch_image" functions can operate on
338       surfaces with alpha as source and destination drawables. To address the
339       alpha channel on a drawable with Prima, one has to send either an
340       "Prima::Icon" with "maskType(im::bpp8)", or a layered "DeviceBitmap" to
341       these functions.
342
343       The corresponding "Prima::DeviceBitmap" type is "dbt::Layered", and is
344       fully compatible with layered widgets in the same fashion as
345       "DeviceBitmap" with type "dbt::Pixmap" is fully compatible with normal
346       widgets. One of ways to put a constant alpha value over a rectangle is
347       this, for example:
348
349          my $a = Prima::Icon->new(
350              width    => 1,
351              height   => 1,
352              type     => im::RGB,
353              maskType => im::bpp8,
354              data     => "\0\0\0",
355              mask     => chr( $constant_alpha ),
356          );
357          $drawable-> stretch_image( 0, 0, 100, 100, $a, rop::SrcOver );
358
359       If displaying a picture with pre-existing alpha channel, you'll need to
360       call premultiply_alpha, because picture renderer assumes that pixel
361       values are premultiplied.
362
363       Even though addressing alpha values of pixels when drawing on layered
364       surfaces is not straighforward, the conversion between images and
365       device bitmaps fully supports alpha pixels. This means that:
366
367       * When drawing on an icon with 8-bit alpha channel (argb icon), any
368       changes to alpha values of pixels will be transferred back to the mask
369       property after "end_paint"
370
371       * Calls to "icon" function on DeviceBitmap with type "dbt::Layered"
372       produce identical argb icons. Calls to "bitmap" on argb icos produce
373       identical layered device bitmaps.
374
375       * Putting argb icons and layered device bitmap on other drawables
376       yields identical results.
377
378       Putting of argb source surfaces can be only used with two rops,
379       "rop::SrcOver" (default) and "rop::SrcCopy". The former produces
380       blending effect, while the latter copies alpha bits over to the
381       destination surface. Prima internal implementation of "put_image" and
382       "stretch_image" functions extends the allowed set of rops when
383       operating on images outside the begin_paint/end_paint brackets. These
384       rops support 12 Porter-Duff operators, some more "photoshop" operators,
385       and special flags to specify constant alpha values to override the
386       existing alpha channel, if any.  See more in "Raster operations" in
387       Prima::Drawable.
388
389       Caveats: In Windows, mouse events will not be delivered to the layered
390       widget if the pixel under the mouse pointer is fully transparent.
391
392       See also: examples/layered.pl.
393

API

395   Prima::Image properties
396       colormap @PALETTE
397           A color palette, used for representing 1, 4, and 8-bit bitmaps,
398           when an image object is to be visualized. @PALETTE contains
399           individual colors component triplets, in RGB format. For example,
400           black-and-white monochrome image may contain colormap as
401           "0,0xffffff".
402
403           See also "palette".
404
405       conversion TYPE
406           Selects the type of dithering algorithm to be used for pixel down-
407           sampling.  TYPE is one of "ict::XXX" constants:
408
409              ict::None            - no dithering, with static palette or palette optimized by source palette
410              ict::Posterization   - no dithering, with optimized palette by source pixels
411              ict::Ordered         - fast 8x8 ordered halftone dithering with static palette
412              ict::ErrorDiffusion  - error diffusion dithering with static palette
413              ict::Optimized       - error diffusion dithering with optimized palette
414
415           As an example, if a 4x4 color image with every pixel set to
416           RGB(32,32,32), converted to a 1-bit image, the following results
417           occur:
418
419              ict::None, ict::Posterization:
420                [ 0 0 0 0 ]
421                [ 0 0 0 0 ]
422                [ 0 0 0 0 ]
423                [ 0 0 0 0 ]
424
425              ict::Ordered:
426                [ 0 0 0 0 ]
427                [ 0 0 1 0 ]
428                [ 0 0 0 0 ]
429                [ 1 0 0 0 ]
430
431              ict::ErrorDiffusion, ict::Ordered:
432                [ 0 0 1 0 ]
433                [ 0 0 0 1 ]
434                [ 0 0 0 0 ]
435                [ 0 0 0 0 ]
436
437           Values of these constants are made from "ictp::" in Prima::Const
438           and "ictd::" in Prima::Const constansts.
439
440       data SCALAR
441           Provides access to the bitmap data. On get-call, returns all bitmap
442           pixels, aligned to 4-byte boundary. On set-call, stores the
443           provided data with same alignment. The alignment can be altered by
444           submitting 'lineSize' write-only flag to set call; the ordering of
445           scan lines can be altered by setting 'reverse' write-only flag (
446           see "Data access" ).
447
448       height INTEGER
449           Manages the vertical dimension of the image data.  On set-call, the
450           image data are changed accordingly to the new height, and depending
451           on "::vScaling" property, the pixel values are either scaled or
452           truncated.
453
454       lineSize INTEGER
455           A read-only property, returning the length of an image row in
456           bytes, as represented internally in memory. Data returned by
457           "::data" property are aligned with "::lineSize" bytes per row, and
458           setting "::data" expects data aligned with this value, unless
459           "lineSize" is set together with "data" to indicate another
460           alignment. See "Data access" for more.
461
462       mean
463           Returns mean value of pixels.  Mean value is "::sum" of pixel
464           values, divided by number of pixels.
465
466       palette [ @PALETTE ]
467           A color palette, used for representing 1, 4, and 8-bit bitmaps,
468           when an image object is to be visualized. @PALETTE contains
469           individual color component triplets, in BGR format. For example,
470           black-and-white monochrome image may contain palette as
471           "[0,0,0,255,255,255]".
472
473           See also "colormap".
474
475       pixel ( X_OFFSET, Y_OFFSET ) PIXEL
476           Provides per-pixel access to the image data when image object is in
477           disabled paint state.
478
479           Pixel values for grayscale 1- and 4- bit images are treated
480           specifically, such that like 8-bit function, values cover range
481           between 0 and 255. F.ex. pixel values for grayscale 1 bit images
482           are 0 and 255, not 0 and 1.
483
484           In paint state same as "Prima::Drawable::pixel".
485
486       preserveType BOOLEAN
487           If 1, reverts the image type to its old value if an implicit
488           conversion was called during "end_paint()".
489
490       rangeHi
491           Returns maximum pixel value in the image data.
492
493       rangeLo
494           Returns minimum pixel value in the image data.
495
496       scaling INT
497           Declares the scaling strategy when image is resized.  Strategies
498           "ist::None" through "ist::Box" are very fast scalers, others not
499           so.
500
501           Can be one of "ist:::XXX" constants:
502
503             ist::None      - image will be either stripped (when downsizing)
504                              or padded (when upsizing) with zeros
505             ist::Box       - image will be scaled using simple box transform
506             ist::BoxX      - columns will behave same as in ist::None,
507                              rows will behave same as in ist::Box
508             ist::BoxY      - rows will behave same as in ist::None,
509                              columns will behave same as in ist::Box
510             ist::AND       - when row or columns is to be shrunk, leftover pixels
511                              will be AND-end together (for black on white)
512                              ( does not work for floating poing pixels )
513             ist::OR        - when row or columns is to be shrunk, leftover pixels
514                              will be OR-end together (for white on black)
515                              ( does not work for floating poing pixels )
516             ist::Triangle  - bilinear interpolation
517             ist::Quadratic - 2rd order (quadratic) B-Spline approximation of Gaussian
518             ist::Sinc      - sine function
519             ist::Hermite   - B-Spline interpolation
520             ist::Cubic     - 3rd order (cubic) B-Spline approximation of Gaussian
521             ist::Gaussian  - Gaussian transform with gamma=0.5
522
523           Note: Resampling scaling algorithms (those greater than
524           "ist::Box"), when applied to Icons with 1-bit icon mask, will
525           silently convert the mask in 8-bit and apply the same scaling
526           algorithm to it. This will have great smoothing effect on mask
527           edges if the system supports ARGB layering (see "Layering" ).
528
529       size WIDTH, HEIGHT
530           Manages dimensions of the image. On set-call, the image data are
531           changed accordingly to the new dimensions, and depending on
532           "::scaling" property, the pixel values are either scaled or
533           truncated.
534
535       stats ( INDEX ) VALUE
536           Returns one of calculated values, that correspond to INDEX, which
537           is one of the following "is::XXX" constants:
538
539              is::RangeLo  - minimum pixel value
540              is::RangeHi  - maximum pixel value
541              is::Mean     - mean value
542              is::Variance - variance
543              is::StdDev   - standard deviation
544              is::Sum      - sum of pixel values
545              is::Sum2     - sum of squares of pixel values
546
547           The values are re-calculated on request and cached.  On set-call
548           VALUE is stored in the cache, and is returned on next get-call.
549           The cached values are discarded every time the image data changes.
550
551           These values are also accessible via set of alias properties:
552           "::rangeLo", "::rangeHi", "::mean", "::variance", "::stdDev",
553           "::sum", "::sum2".
554
555       stdDev
556           Returns standard deviation of the image data.  Standard deviation
557           is the square root of "::variance".
558
559       sum Returns sum of pixel values of the image data
560
561       sum2
562           Returns sum of squares of pixel values of the image data
563
564       type TYPE
565           Governs the image pixel format type. TYPE is a combination of
566           "im::XXX" constants. The constants are collected in groups:
567
568           Bit-depth constants provide size of pixel is bits. Their actual
569           value is same as number of bits, so "im::bpp1" value is 1,
570           "im::bpp4" - 4, etc. The valid constants represent bit depths from
571           1 to 128:
572
573              im::bpp1
574              im::bpp4
575              im::bpp8
576              im::bpp16
577              im::bpp24
578              im::bpp32
579              im::bpp64
580              im::bpp128
581
582           The following values designate the pixel format category:
583
584              im::Color
585              im::GrayScale
586              im::RealNumber
587              im::ComplexNumber
588              im::TrigComplexNumber
589              im::SignedInt
590
591           Value of "im::Color" is 0, whereas other category constants
592           represented by unique bit value, so combination of "im::RealNumber"
593           and "im::ComplexNumber" is possible.
594
595           There also several mnemonic constants defined:
596
597              im::Mono          - im::bpp1
598              im::BW            - im::bpp1 | im::GrayScale
599              im::16            - im::bpp4
600              im::Nibble        - im::bpp4
601              im::256           - im::bpp8
602              im::RGB           - im::bpp24
603              im::Triple        - im::bpp24
604              im::Byte          - gray 8-bit unsigned integer
605              im::Short         - gray 16-bit unsigned integer
606              im::Long          - gray 32-bit unsigned integer
607              im::Float         - float
608              im::Double        - double
609              im::Complex       - dual float
610              im::DComplex      - dual double
611              im::TrigComplex   - dual float
612              im::TrigDComplex  - dual double
613
614           Bit depths of float- and double- derived pixel formats depend on a
615           platform.
616
617           The groups can be masked out with the mask values:
618
619              im::BPP      - bit depth constants
620              im::Category - category constants
621              im::FMT      - extra format constants
622
623           The extra formats are the pixel formats, not supported by "::type",
624           but recognized within the combined set-call, like
625
626              $image-> set(
627                 type => im::fmtBGRI,
628                 data => 'BGR-BGR-',
629              );
630
631           The data, supplied with the extra image format specification will
632           be converted to the closest supported format. Currently, the
633           following extra pixel formats are recognized:
634
635              im::fmtBGR
636              im::fmtRGBI
637              im::fmtIRGB
638              im::fmtBGRI
639              im::fmtIBGR
640
641       variance
642           Returns variance of pixel values of the image data.  Variance is
643           "::sum2", divided by number of pixels minus square of "::sum" of
644           pixel values.
645
646       width INTEGER
647           Manages the horizontal dimension of the image data.  On set-call,
648           the image data are changed accordingly to the new width, and
649           depending on "::scaling" property, the pixel values are either
650           scaled or truncated.
651
652   Prima::Icon properties
653       autoMasking TYPE
654           Selects whether the mask information should be updated
655           automatically with "::data" change or not. Every "::data" change is
656           mirrored in "::mask", using TYPE, one of "am::XXX" constants:
657
658              am::None           - no mask update performed
659              am::MaskColor      - mask update based on ::maskColor property
660              am::MaskIndex      - mask update based on ::maskIndex property
661              am::Auto           - mask update based on corner pixel values
662
663           The "::maskColor" color value is used as a transparent color if
664           TYPE is "am::MaskColor". The transparency mask generation
665           algorithm, turned on by "am::Auto" checks corner pixel values,
666           assuming that majority of the corner pixels represents a
667           transparent color. Once such color is found, the mask is generated
668           as in "am::MaskColor" case.
669
670           "::maskIndex" is the same as "::maskColor", except that it points
671           to a specific color index in the palette.
672
673           When image "::data" is stretched, "::mask" is stretched
674           accordingly, disregarding the "::autoMasking" value.
675
676       mask SCALAR
677           Provides access to the transparency bitmap. On get-call, returns
678           all bitmap pixels, aligned to 4-byte boundary in 1-bit format. On
679           set-call, stores the provided transparency data with same
680           alignment.
681
682       maskColor COLOR
683           When "::autoMasking" set to "am::MaskColor", COLOR is used as a
684           transparency value.
685
686       maskIndex INDEX
687           When "::autoMasking" set to "am::MaskIndex", INDEXth color in teh
688           current palette is used as a transparency value.
689
690       maskType INTEGER
691           Is either "im::bpp1" (1) or "im::bpp8" (8). The latter can be used
692           as a layered (argb) source surface to draw with blending effect.
693
694   Prima::DeviceBitmap properties
695       type INTEGER
696           A read-only property, that can only be set during creation,
697           reflects whether the system bitmap is black-and-white 1-bit
698           ("dbt::Bitmap"), is colored and compatible with widgets
699           ("dbt::Pixmap"), or is colored with alpha channel and compatible
700           with layered widgets ("dbt::Layered").
701
702           The color depth of a bitmap can be read via "get_bpp()" method;
703           monochrome bitmaps always have bit depth of 1, layered bitmaps have
704           bit depth of 32.
705
706   Prima::Image methods
707       bar X1, Y1, X2, Y2
708           Outside the paint state uses owen implementation for drawing a
709           rectangular shape.  The following properties are respected:
710           "color", "backColor", "rop", "rop2", "fillPattern",
711           "fillPatternOffset", "region". "rop2" accepts either "rop::CopyPut"
712           or "rop::NoOper" values, to produce either opaque or transparent
713           fill pattern application.
714
715           Inside the paint state is identical to "Drawable::bar".
716
717       bitmap
718           Returns newly created Prima::DeviceBitmap instance, with the image
719           dimensions and with the bitmap pixel values copied to.
720
721       clear [X1, Y1, X2, Y2]
722           Same as "Drawable::clear" but can be used also outside of the paint
723           state.
724
725       clone %properties
726           Creates a copy of the image and applies %properties. An easy way to
727           create a down-sampled copy, for example.
728
729       codecs
730           Returns array of hashes, each describing the supported image
731           format. If the array is empty, the toolkit was set up so it can not
732           load and save images.
733
734           See Prima::image-load for details.
735
736           This method can be called without object instance.
737
738       dup Returns a duplicate of the object, a newly created Prima::Image,
739           with all information copied to it. Does not preserve graphical
740           properties (color etc).
741
742       extract X_OFFSET, Y_OFFSET, WIDTH, HEIGHT
743           Returns a newly created image object with WIDTH and HEIGHT
744           dimensions, initialized with pixel data from X_OFFSET and Y_OFFSET
745           in the bitmap.
746
747       fill_chord, fill_ellipse, fill_sector, flood_fill
748           Same as "Drawable::" functions but can be used also outside of the
749           paint state.
750
751       get_bpp
752           Returns the bit depth of the pixel format. Same as "::type &
753           im::BPP".
754
755       get_handle
756           Returns a system handle for an image object.
757
758       load (FILENAME or FILEGLOB) [ %PARAMETERS ]
759           Loads image from file FILENAME or stream FILEGLOB into an object,
760           and returns the success flag.  The semantics of "load()" is
761           extensive, and can be influenced by PARAMETERS hash. "load()" can
762           be called either in a context of an existing object, then a boolean
763           success flag is returned, or in a class context, then a newly
764           created object ( or "undef" ) is returned. If an error occurs, $@
765           variable contains the error description string. These two
766           invocation semantics are equivalent:
767
768              my $x = Prima::Image-> create();
769              die "$@" unless $x-> load( ... );
770
771           and
772
773              my $x = Prima::Image-> load( ... );
774              die "$@" unless $x;
775
776           See Prima::image-load for details.
777
778           NB! When loading from streams on win32, mind "binmode".
779
780       map COLOR
781           Performs iterative mapping of bitmap pixels, setting every pixel to
782           "::color" property with respect to "::rop" type if a pixel equals
783           to COLOR, and to "::backColor" property with respect to "::rop2"
784           type otherwise.
785
786           "rop::NoOper" type can be used for color masking.
787
788           Examples:
789
790              width => 4, height => 1, data => [ 1, 2, 3, 4]
791              color => 10, backColor => 20, rop => rop::CopyPut
792
793              rop2 => rop::CopyPut
794              input: map(2) output: [ 20, 10, 20, 20 ]
795
796              rop2 => rop::NoOper
797              input: map(2) output: [ 1, 10, 3, 4 ]
798
799       mirror VERTICAL
800           Mirrors the image depending on boolean flag VERTICAL
801
802       premultiply_alpha CONSTANT_OR_IMAGE
803           Applies premultiplication formula to each pixel
804
805              pixel = pixel * alpha / 256
806
807           where alpha either is a constant, or a pixel value in an image
808
809       put_image, put_image_indirect, stretch_image
810           Same as "Drawable::" functions but can be used also outside of the
811           paint state.
812
813           Extends raster functionality to access alpha channel either using
814           constant alpha values or "Prima::Icon" as sources. See explanation
815           of "rop::" constants in "Raster operations" in Prima::Drawable.
816
817       resample SRC_LOW, SRC_HIGH, DEST_LOW, DEST_HIGH
818           Performs linear scaling of gray pixel values from range (SRC_LOW -
819           SRC_HIGH) to range (DEST_LOW - DEST_HIGH). Can be used to visualize
820           gray non-8 bit pixel values, by the code:
821
822              $image-> resample( $image-> rangeLo, $image-> rangeHi, 0, 255);
823
824       rotate DEGREES
825           Rotates the image. Where the angle is 90, 180, or 270 degrees, fast
826           pixel flipping is used, otherwise fast Paeth rotation is used.
827           Eventual resampling can be controlled by "scaling" property (
828           probably not worth it for functions with support of more than 1
829           pixel).
830
831           Resulting images can be 1 pixel too wide due to horizontal shearing
832           applied twice, where in worst cases 1 pixel from the original image
833           can take 3 horizontal pixels on the result.
834
835       save (FILENAME or FILEGLOB), [ %PARAMETERS ]
836           Stores image data into image file FILENAME or stream FILEGLOB, and
837           returns the success flag.  The semantics of "save()" is extensive,
838           and can be influenced by PARAMETERS hash. If error occurs, $@
839           variable contains error description string.
840
841           Note that when saving to a stream, "codecID" must be explicitly
842           given in %PARAMETERS.
843
844           See Prima::image-load for details.
845
846           NB! When saving to streams on win32, mind "binmode".
847
848       shear X, Y
849           Applies shearing to the image. If the shearing is needed only for
850           one axis, set shear factor for the other one to zero.
851
852       to_region
853           Creates a new Prima::Region object with the image as the data
854           source.
855
856       transform @MATRIX
857           Applies generic 2D transform matrix to the image, where matrix is 4
858           numbers.
859
860           Tries first to split matrix into series of shear and scale
861           transforms using LDU decomposition; if an interim image needs to be
862           too large, fails and returns "false".
863
864           Rotation matrices can be applied too, however, when angles are
865           close to 90 and 270, either interim images become too big, or
866           defects introduced by shearing become too visible. Therefore the
867           method specifically detects for rotation cases, and uses Paeth
868           rotation algorithm instead, which yields better results.  Also, if
869           the angle is detected to be 90, 180, or 270 degrees, fast pixel
870           flipping is used.
871
872           Eventual resampling can be controlled by "scaling" property.
873
874       ui_scale %OPTIONS
875           Resizes the image with smooth scaling. Understands "zoom" and
876           "scaling" options. The "zoom" default value is the one in
877           "$::application->uiScaling", the "scaling" default value is
878           "ist::Quadratic" .
879
880           See also: "uiScaling" in Application
881
882   Prima::Image events
883       "Prima::Image"-specific events occur only from inside load call, to
884       report image loading progress. Not all codecs (currently JPEG,PNG,TIFF
885       only) are able to report the progress to the caller. See "Loading with
886       progress indicator" in Prima::image-load for details,
887       "watch_load_progress" in Prima::ImageViewer and "load" in
888       Prima::Dialog::ImageDialog for suggested use.
889
890       HeaderReady EXTRAS
891           Called whenever image header is read, and image dimensions and
892           pixel type is changed accordingly to accomodate image data.
893
894           "EXTRAS" is the hash to be stored later in "{extras}" key on the
895           object.
896
897       DataReady X, Y, WIDTH, HEIGHT
898           Called whenever image data that cover area designated by
899           X,Y,WIDTH,HEIGHT is acquired. Use "load" option "eventDelay" to
900           limit the rate of "DataReady" event.
901
902   Prima::Icon methods
903       alpha ALPHA <X1, Y1, X2, Y2>
904           Same as "Drawable::alpha" but can be used also outside of the paint
905           state.
906
907       combine DATA, MASK
908           Copies information from DATA and MASK images into "::data" and
909           "::mask" property. DATA and MASK are expected to be images of same
910           dimension.
911
912       create_combined DATA, MASK
913           Same as "combine", but to be called as constructor.
914
915       image %opt
916           Renders icon graphics on a newly created Prima::Image object
917           instance upon black background.  If $opt{background} is given, it
918           is used instead.
919
920       premultiply_alpha CONSTANT_OR_IMAGE = undef
921           Applies premultiplication formula to each pixel
922
923              pixel = pixel * alpha / 256
924
925           where alpha is the corresponding alpha value for each coordinate.
926           Only applicable when "maskType" is <im::bpp8>.
927
928       split
929           Returns two new Prima::Image objects of same dimension.  Pixels in
930           the first is are duplicated from "::data" storage, in the second -
931           from "::mask" storage.
932
933       ui_scale %OPTIONS
934           Same as "ui_scale" from "Prima::Image", but with few exceptions: It
935           tries to use "ist::Quadratic" only when the system supports ARGB
936           layering. Otherwise, falls back on "ist::Box" scaling algorithm,
937           and also limits the zoom factor to integers (2x, 3x etc) only,
938           because when displayed, the smooth-scaled color plane will not
939           match mask plane downgraded to 0/1 mask, and because box-scaling
940           with non-integer zooms looks ugly.
941
942   Prima::DeviceBitmap methods
943       dup Returns a duplicate of the object, a newly created
944           Prima::DeviceBitmap, with all information copied to it. Does not
945           preserve graphical properties (color etc).
946
947       icon
948           Returns a newly created Prima::Icon object instance, with the pixel
949           information copied from the object. If the bitmap is layered,
950           returns icons with maskType set to "im::bpp8".
951
952       image
953           Returns a newly created Prima::Image object instance, with the
954           pixel information copied from the object.
955
956       get_handle
957           Returns a system handle for a system bitmap object.
958

AUTHOR

960       Dmitry Karasik, <dmitry@karasik.eu.org>.
961

SEE ALSO

963       Prima, Prima::Drawable, Prima::image-load, Prima::codecs.
964
965       PDL, PDL::PrimaImage, IPA
966
967       ImageMagick, Prima::Image::Magick
968
969
970
971perl v5.34.0                      2021-07-22              pod::Prima::Image(3)
Impressum