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 the primitives and "put_image" methods
292       support drawing using Porter-Duff operators from "rop" property (i e
293       rop::SrcOver and above).
294
295       See individual methods and properties in API that support standalone
296       usage, and how they differ from system-dependent implementation.
297
298   Prima::Icon
299       Prima::Icon inherits all properties of Prima::Image, and it also
300       provides a transparency mask of either 1 or 8 bits.  This mask can also
301       be loaded and saved into image files, if the format supports
302       transparency information.
303
304       Similar to Prima::Image::data property, Prima::Icon::mask property
305       provides access to the binary mask data.  The mask can be updated
306       automatically, after an icon object was subject to painting, resizing,
307       or other destructive change.  The auxiliary properties "::autoMasking"
308       and "::maskColor"/"::maskIndex" regulate  mask update procedure. For
309       example, if an icon was loaded with the color ( vs. bitmap )
310       transparency information, the binary mask will be generated anyway, but
311       it will be also recorded that a particular color serves as a
312       transparent indicator, so eventual conversions can rely on the color
313       value, instead of the mask bitmap.
314
315       If an icon is drawn upon a graphic canvas, the image output is
316       constrained to the mask. On raster displays it is typically simulated
317       by a combination of and- and xor- operation modes, therefore attempts
318       to put an icon with "::rop", different from "rop::CopyPut", usually
319       fail.
320
321   Layering
322       The term layered window is borrowed from Windows world, and means a
323       window with transparency. In Prima, the property layered is used to
324       select this functionality. The call to
325       "$::application->get_system_value(sv::LayeredWidgets)" can check
326       whether this functionality is available; if not, the property is
327       ignored.  By default, widgets can not use layering.
328
329       A layered drawable uses an extra alpha channel to designate the
330       transparency.  Drawing on widgets will also look different - for
331       example, drawing with black color will make the black pixels fully
332       transparent, while other colors will blend with the underlying
333       background, but never in full. Prima provides graphics primitives to
334       draw using alpha effects, and some image functions to address the alpha
335       surfaces.
336
337       "put_image" / "stretch_image" functions can operate on surfaces with
338       alpha as source and destination drawables. To address the alpha channel
339       on a drawable with Prima, one has to send either an "Prima::Icon" with
340       "maskType(im::bpp8)", or a layered "DeviceBitmap" to these functions.
341
342       The corresponding "Prima::DeviceBitmap" type is "dbt::Layered", and is
343       fully compatible with layered widgets in the same fashion as
344       "DeviceBitmap" with type "dbt::Pixmap" is fully compatible with normal
345       widgets. One of ways to put a constant alpha value over a rectangle is
346       this, for example:
347
348          my $a = Prima::Icon->new(
349              width    => 1,
350              height   => 1,
351              type     => im::RGB,
352              maskType => im::bpp8,
353              data     => "\0\0\0",
354              mask     => chr( $constant_alpha ),
355          );
356          $drawable-> stretch_image( 0, 0, 100, 100, $a, rop::SrcOver );
357
358       If displaying a picture with pre-existing alpha channel, you'll need to
359       call premultiply_alpha, because picture renderer assumes that pixel
360       values are premultiplied.
361
362       Even though addressing alpha values of pixels when drawing on layered
363       surfaces is not straighforward, the conversion between images and
364       device bitmaps fully supports alpha pixels. This means that:
365
366       * When drawing on an icon with 8-bit alpha channel (argb icon), any
367       changes to alpha values of pixels will be transferred back to the mask
368       property after "end_paint"
369
370       * Calls to "icon" function on DeviceBitmap with type "dbt::Layered"
371       produce identical argb icons. Calls to "bitmap" on argb icos produce
372       identical layered device bitmaps.
373
374       * Putting argb icons and layered device bitmap on other drawables
375       yields identical results.
376
377       Putting of argb source surfaces can be only used with two rops,
378       "rop::SrcOver" (default) and "rop::SrcCopy". The former produces
379       blending effect, while the latter copies alpha bits over to the
380       destination surface. Prima internal implementation of "put_image" and
381       "stretch_image" functions extends the allowed set of rops when
382       operating on images outside the begin_paint/end_paint brackets. These
383       rops support 12 Porter-Duff operators, some more "photoshop" operators,
384       and special flags to specify constant alpha values to override the
385       existing alpha channel, if any.  See more in "Raster operations" in
386       Prima::Drawable.
387
388       Caveats: In Windows, mouse events will not be delivered to the layered
389       widget if the pixel under the mouse pointer is fully transparent.
390
391       See also: examples/layered.pl.
392

API

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

AUTHOR

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

SEE ALSO

962       Prima, Prima::Drawable, Prima::image-load, Prima::codecs.
963
964       PDL, PDL::PrimaImage, IPA
965
966       ImageMagick, Prima::Image::Magick
967
968
969
970perl v5.34.1                      2022-04-20              pod::Prima::Image(3)
Impressum