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

AUTHOR

211       Dmitry Karasik, <dmitry@karasik.eu.org>.
212

SEE ALSO

214       Prima, Prima::Image, Prima::Widget::ScrollWidget,
215       Prima::Dialog::ImageDialog, examples/iv.pl.
216
217
218
219perl v5.38.0                      2023-07-21             Prima::ImageViewer(3)
Impressum