1Prima::ImageViewer(3) User Contributed Perl DocumentationPrima::ImageViewer(3)
2
3
4

NAME

6       Prima::ImageViewer - standard image, icon, and bitmap viewer class.
7
8   SYNOPSIS
9               use Prima qw(ImageViewer StdBitmap Application);
10               Prima::ImageViewer-> new(
11                       image => Prima::StdBitmap::image(0),
12                       zoom  => 2.718,
13               );
14               run Prima;
15

DESCRIPTION

17       The module contains "Prima::ImageViewer" class, which provides image
18       displaying functionality, including different zoom levels.
19
20       "Prima::ImageViewer" is a descendant of "Prima::ScrollWidget" and
21       inherits its document scrolling behavior and programming interface.
22       See Prima::ScrollWidget for details.
23

API

25   Properties
26       alignment INTEGER
27           One of the following "ta::XXX" constants:
28
29                   ta::Left
30                   ta::Center
31                   ta::Right
32
33           Selects the horizontal image alignment.
34
35           Default value: "ta::Left"
36
37       autoZoom BOOLEAN
38           When set, the image is automatically stretched while keeping
39           aspects to the best available fit, given the "zoomPrecision".
40           Scrollbars are turned off if "autoZoom" is set to 1.
41
42       image OBJECT
43           Selects the image object to be displayed. OBJECT can be an instance
44           of "Prima::Image", "Prima::Icon", or "Prima::DeviceBitmap" class.
45
46       imageFile FILE
47           Set the image FILE to be loaded and displayed. Is rarely used since
48           does not return a loading success flag.
49
50       stretch BOOLEAN
51           If set, the image is simply stretched over the visual area, without
52           keeping the aspect. Scroll bars, zooming and keyboard navigation
53           become disabled.
54
55       quality BOOLEAN
56           A boolean flag, selecting if the palette of "image" is to be copied
57           into the widget palette, providing higher visual quality on
58           paletted displays. See also "palette" in Prima::Widget.
59
60           Default value: 1
61
62       valignment INTEGER
63           One of the following "ta::XXX" constants:
64
65                   ta::Top
66                   ta::Middle or ta::Center
67                   ta::Bottom
68
69           Selects the vertical image alignment.
70
71           NB: "ta::Middle" value is not equal to "ta::Center"'s, however the
72           both constants produce equal effect here.
73
74           Default value: "ta::Bottom"
75
76       zoom FLOAT
77           Selects zoom level for image display. The acceptable value range is
78           between 0.01 and 100. The zoom value is rounded to the closest
79           value divisible by 1/"zoomPrecision". For example, is
80           "zoomPrecision" is 100, the zoom values will be rounded to the
81           precision of hundredth - to fiftieth and twentieth fractional
82           values - .02, .04, .05, .06, .08, and 0.1 . When "zoomPrecision" is
83           1000, the precision is one thousandth, and so on.
84
85           Default value: 1
86
87       zoomPrecision INTEGER
88           Zoom precision of "zoom" property. Minimal acceptable value is 10,
89           where zoom will be rounded to 0.2, 0.4, 0.5, 0.6, 0.8 and 1.0 .
90
91           The reason behind this arithmetics is that when an image of an
92           arbitrary zoom factor is requested to be displayed, the image
93           sometimes must be drawn from a fraction image pixel - for example,
94           10x zoomed image shifted 3 pixels left, must be displayed so the
95           first image pixel from the left occupies 7 screen pixels, and the
96           next ones - 10 screen pixels.  That means, that the correct image
97           display routine must ask the system to draw the image at offset -3
98           screen pixels, where the first image pixel column would correspond
99           to that offset.
100
101           When the zoom factor is fractional, the picture is getting more
102           complex. For example, with zoom factor 12.345, and zero screen
103           offset, the first image pixel begins at the 12th screen pixel, the
104           next one - at the 25th ( because of the roundoff ), then the 37th
105           etc etc. If the image is 2000x2000 pixels wide, and is asked to be
106           drawn so that it appears shifted 499 screen image pixels left, it
107           needs to be drawn from the 499/12.345=40.42122th image pixel. Is
108           might seem that indeed it would be enough to ask the system to
109           begin drawing from image pixel 40, and offset int(0.42122*12.345)=5
110           screen pixels to the left, however, that procedure will not account
111           for the correct fixed point roundoff that accumulates as system
112           scales the image. For zoom factor 12.345 this roundoff sequence is,
113           as we seen before, (12,25,37,49,62,74,86,99,111,123) for the first
114           10 pixels displayed, that occupy (12,13,12,12,13,12,12,13,12,12)
115           screen pixels correspondingly.  For the pixels starting at 499, the
116           sequence is (506,519,531,543,556,568,580,593,605,617) offsets or
117           (13,12,12,13,13,12,12,13,12,12) widths -- note the two subsequent
118           13s there.  This sequence begins to repeat itself after 200
119           iterations (12.345*200=2469.000), which means that in order to
120           achieve correct display results, the image must be asked to be
121           displayed from as far as image pixel 0 if image's first pixel on
122           the screen is between 0 and 199 ( or for screen pixels 0-2468),
123           then from image pixel 200 for offsets 200-399, ( screen pixels
124           2469-4937), and so on.
125
126           Since the system internally allocates memory for image scaling,
127           that means that up to
128           2*200*min(window_width,image_width)*bytes_per_pixel unneccessary
129           bytes will be allocated for each image drawing call (2 because the
130           calculations are valid for both the vertical and horizontal
131           strips), and this can lead to slowdown or even request failure when
132           image or window dimensions are large. The proposed solution is to
133           roundoff accepted zoom factors, so these offsets are kept small -
134           for example, N.25 zoom factors require only max 1/.25=4 extra
135           pixels. When "zoomPrecision" value is 100, zoom factors are rounded
136           to 0.X2, 0.X4, 0.X5, 0.X6, 0.X8, 0.X0, thus requiring max 50 extra
137           pixels.
138
139           NB. If, despite the efforts, the property gets in the way, increase
140           it to 1000 or even 10000, but note that this may lead to problems.
141
142           Default value: 100
143
144   Methods
145       on_paint SELF, CANVAS
146           The "Paint" notification handler is mentioned here for the specific
147           case of its return value, that is the return value of internal
148           "put_image" call.  For those who might be interested in "put_image"
149           failures, that mostly occur when trying to draw an image that is
150           too big, the following code might be useful:
151
152               sub on_paint
153               {
154                   my ( $self, $canvas) = @_;
155                   warn "put_image() error:$@" unless $self-> SUPER::on_paint($canvas);
156               }
157
158       screen2point X, Y, [ X, Y, ... ]
159           Performs translation of integer pairs integers as (X,Y)-points from
160           widget coordinates to pixel offset in image coordinates. Takes in
161           account zoom level, image alignments, and offsets. Returns array of
162           same length as the input.
163
164           Useful for determining correspondence, for example, of a mouse
165           event to a image point.
166
167           The reverse function is "point2screen".
168
169       point2screen   X, Y, [ X, Y, ... ]
170           Performs translation of integer pairs as (X,Y)-points from image
171           pixel offset to widget image coordinates. Takes in account zoom
172           level, image alignments, and offsets. Returns array of same length
173           as the input.
174
175           Useful for determining a screen location of an image point.
176
177           The reverse function is "screen2point".
178
179       watch_load_progress IMAGE
180           When called, image viewer watches as IMAGE is being loaded ( see
181           "load" in Prima::Image ) and displays the progress. As soon as
182           IMAGE begins to load, it replaces the existing "image" property.
183           Example:
184
185               $i = Prima::Image-> new;
186               $viewer-> watch_load_progress( $i);
187               $i-> load('huge.jpg');
188               $viewer-> unwatch_load_progress;
189
190           Similar functionality is present in Prima::Dialog::ImageDialog.
191
192       unwatch_load_progress CLEAR_IMAGE=1
193           Stops monitoring of image loading progress. If CLEAR_IMAGE is 0,
194           the leftovers of the incremental loading stay intact in "image"
195           propery. Otherwise, "image" is set to "undef".
196
197       zoom_round ZOOM
198           Rounds the zoom factor to "zoomPrecision" precision, returns the
199           rounded zoom value. The algorithm is the same as used internally in
200           "zoom" property.
201

AUTHOR

203       Dmitry Karasik, <dmitry@karasik.eu.org>.
204

SEE ALSO

206       Prima, Prima::Image, Prima::ScrollWidget, Prima::Dialog::ImageDialog,
207       examples/iv.pl.
208
209
210
211perl v5.36.0                      2022-07-22             Prima::ImageViewer(3)
Impressum