lib/LaTeXML/Util/Image.pm untested

filter: Statementstmt 0.0% 0 / 335 Branchbran 0.0% 0 / 198 Conditioncond 0.0% 0 / 138 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 29 Podpod 0.0% 0 / 18 totaltotal 0.0% 0 / 718 CC 100 SCAR 61.6
CC
100
Cov
0%
image_graphicx_complex
992.0
image_graphicx_parse
930.0
image_graphicx_size
110.0
CRAP 474.5
1 # /=====================================================================\ #
2 # | LaTeXML::Util::Image | #
3 # | Image support for LaTeXML | #
4 # |=====================================================================| #
5 # | Part of LaTeXML: | #
6 # | Public domain software, produced as part of work done by the | #
7 # | United States Government & not subject to copyright in the US. | #
8 # |---------------------------------------------------------------------| #
9 # | Bruce Miller <bruce.miller@nist.gov> #_# | #
10 # | http://dlmf.nist.gov/LaTeXML/ (o o) | #
11 # \=========================================================ooo==U==ooo=/ #
12 package LaTeXML::Util::Image;
13 use strict;
14 use warnings;
15 use LaTeXML::Global;
16 use LaTeXML::Common::Error;
17 use LaTeXML::Common::Dimension;
18 use LaTeXML::Util::Pathname;
19 use List::Util qw(min max);
20 use Image::Size;
21 use POSIX;
22 use base qw(Exporter);
23 our @EXPORT = (
24 qw( &image_type &image_size ),
25 qw( &image_classes &image_can_image &image_object ),
26 qw( &image_write ),
27 qw( &image_graphicx_parse &image_graphicx_is_trivial &image_graphicx_trivialize
28 &image_graphicx_size &image_graphicx_trivial &image_graphicx_complex),
29 qw( &image_graphicx_sizer),
30 );
31 # The initial idea here is to form a minimal interface to image operations
32 # and to shield LaTeXML from the 'unreliable' Image::Magick;
33 # Namely, it is hard to rely on as a dependency, since it is often
34 # difficult to port, or has mismatched versions or whatever.
35 # We do, at least, need to be able to get image size.....
36  
37 our $DPI = 90; # [CONSTANT]
38 our $DOTS_PER_POINT = ($DPI / 72.0); # [CONSTANT] Dots per point.
39 our $BACKGROUND = "#FFFFFF"; # [CONSTANT]
40  
41 # These environment variables can be used to limit the amount
42 # of time & space used by ImageMagick. They are particularly useful
43 # when ghostscript becomes involved in converting postscript or pdf.
44 # HOWEVER, there are indications that the time limit (at least)
45 # is being measured against the whole latexml process, not just image processing.
46 # Thus they aren't really that useful here.
47 # They probably are useful in a server context, however, so I'll leave the comments.
48 # $ENV{MAGICK_DISK_LIMIT} = "2GiB" unless defined $ENV{MAGICK_DISK_LIMIT};
49 # $ENV{MAGICK_MEMORY_LIMIT} = "512MiB" unless defined $ENV{MAGICK_MEMORY_LIMIT};
50 # $ENV{MAGICK_MAP_LIMIT} = "1GiB" unless defined $ENV{MAGICK_MAP_LIMIT};
51 # $ENV{MAGICK_TIME_LIMIT} = "300" unless defined $ENV{MAGICK_TIME_LIMIT};
52  
53 # Note that Image::Size may, itself, use Image::Magick, if available,
54 # as a fallback for getting image size & type!!!
55 # However, it seems not to recognize file types with extension .EPS (uppercase), eg!
56 sub image_type {
57 my ($pathname) = @_;
58 my ($w, $h, $t) = imgsize($pathname);
59 # even though Image::Size CLAIMS to use Image::Magick as fallback... needs tickling?
60 if (!(defined $w) && !(defined $h) && image_can_image()) { # try harder!
61 my $image = image_read($pathname) or return;
62 ($t) = image_getvalue($image, 'format'); }
63 # Note that Image::Magick (sometimes) returns "descriptive" types
64 # (but I can't find a list anywhere!)
65 $t = 'eps' if $t && $t =~ /postscript/i;
66 return (defined $t ? lc($t) : undef); }
67  
68 sub image_size {
69 my ($pathname) = @_;
70 my ($w, $h, $t) = imgsize($pathname);
71 return ($w, $h) if $w && $h;
72 if (image_can_image()) { # try harder!
73 my $image = image_read($pathname) or return;
74 return image_getvalue($image, 'width', 'height'); } }
75  
76 # This will be set once we've found an Image processing library to use [Daemon safe]
77 our $IMAGECLASS; # cached class if we found one that works. [CONFIGURABLE?]
78 my @MagickClasses = (qw(Graphics::Magick Image::Magick)); # CONSTANT
79  
80 sub image_classes {
81 return @MagickClasses; }
82  
83 sub image_can_image {
84 my ($pathname) = @_;
85 if (!$IMAGECLASS) {
86 foreach my $class (@MagickClasses) {
87 my $module = $class . ".pm";
88 $module =~ s/::/\//g;
89 my $object = eval {
90 local $LaTeXML::IGNORE_ERRORS = 1;
91 require $module; $class->new(); };
92 if ($object) {
93 $IMAGECLASS = $class;
94 last; } } }
95 return $IMAGECLASS; }
96  
97 # return an image object (into which you can read), if possible.
98 sub image_object {
99 my (%properties) = @_;
100 return unless image_can_image();
101 my $image = $IMAGECLASS->new(%properties);
102 return $image; }
103  
104 #%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
105 # Working with Image transformation options from the graphic(s|x) packages
106 #%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
107 # Note that viewport is supposed to be relative to bounding box,
108 # and EITHER ONE can cause clipping, if clip=true.
109 # However, apparently the INTENT of bounding box is simply to
110 # supply one, if one can't be found, in order to determine the image size.
111 # In our case, we may end up getting a gif, jpeg, etc, whose origin is always 0,0,
112 # and whose size is clear; also postscript figures sizes will be determined
113 # by ghostview(?). Another use of setting a bounding box, when clip=false,
114 # is to make the image lay ontop of neighboring text. This isn't quite
115 # possible in HTML, other than possibly through some tricky CSS.
116 # Besides, I'd like to avoid reading the bb file, if I can.
117 # --- So, for all these reasons, we simply ignore bounding box here.
118  
119 sub image_graphicx_parse {
120 my ($transformstring, %options) = @_;
121 return [] unless $transformstring;
122 local $_ = $_;
123 my ($v, $clip, $trim, $width, $height, $xscale, $yscale,
124 $aspect, $angle, $rotfirst, $mag, @bb, @vp,) = ('', '', '', 0, 0, 0, 0, '', 0, '', 1, 0);
125 my @unknown = ();
126 my @ignore = @{ $options{ignore_options} || [] };
127 foreach (split(',', $transformstring || '')) {
128 if (/^\s*(\w+)(?:=\s*(.*))?\s*$/) {
129 $_ = $1; $v = $2 || '';
130 my $op = $_;
131 if (grep { $op eq $_ } @ignore) { } # Ignore this option
132 elsif (/^bb$/) { @bb = map { to_bp($_) } split(' ', $v); }
133 elsif (/^bb(?:ll|ur)(?:x|y)$/) { $bb[2 * /ur/ + /y/] = to_bp($v); }
134 elsif (/^nat(?:width|height)$/) { $bb[2 + /width/] = to_bp($v); }
135 elsif (/^viewport$/) { @vp = map { to_bp($_) } split(' ', $v); $trim = 0; }
136 elsif (/^trim$/) { @vp = map { to_bp($_) } split(' ', $v); $trim = 1; }
137 elsif (/^clip$/) { $clip = !($v eq 'false'); }
138 elsif (/^keepaspectratio$/) { $aspect = !($v eq 'false'); }
139 elsif (/^width$/) { $width = to_bp($v); }
140 elsif (/^(?:total)?height$/) { $height = to_bp($v); }
141 elsif (/^scale$/) { $xscale = $yscale = $v; }
142 elsif (/^xscale$/) { $xscale = $v; }
143 elsif (/^yscale$/) { $yscale = $v; }
144 elsif (/^angle$/) { $angle = $v; $rotfirst = !($width || $height || $xscale || $yscale); }
145 elsif (/^origin$/) { } # ??
146 # Non-standard option
147 elsif (/^magnification$/) { $mag = $v; }
148 else { push(@unknown, [$op, $v]); } }
149 else { } } # ?
150 # --------------------------------------------------
151 # Now, compile the options into a sequence of `transformations'.
152 # Note: the order of rotation & scaling is significant,
153 # but the order of various clipping options w.r.t rotation or scaling is not.
154 my @transform = ();
155 # We ignore viewport & trim if clip isn't set, since in that case we shouldn't
156 # actually remove anything from the image (and there's no way to have the image
157 # overlap neighboring text, etc, in current HTML).
158 push(@transform, [($trim ? 'trim' : 'clip'), @vp]) if (@vp && $clip);
159 push(@transform, ['rotate', $angle]) if ($rotfirst && $angle); # Rotate before scaling?
160 if ($width && $height) { push(@transform, ['scale-to', $mag * $width, $mag * $height, $aspect]); }
161 elsif ($width) { push(@transform, ['scale-to', $mag * $width, 999999, 1]); }
162 elsif ($height) { push(@transform, ['scale-to', 999999, $mag * $height, 1]); }
163 elsif ($xscale && $yscale) { push(@transform, ['scale', $mag * $xscale, $mag * $yscale]); }
164 elsif ($xscale) { push(@transform, ['scale', $mag * $xscale, $mag]); }
165 elsif ($yscale) { push(@transform, ['scale', $mag, $mag * $yscale]); }
166 elsif ($mag != 1) { push(@transform, ['scale', $mag, $mag]); }
167 push(@transform, ['rotate', $angle]) if (!$rotfirst && $angle); # Rotate after scaling?
168 # ----------------------
169 return [@transform, @unknown]; }
170  
171 my %BP_conversions = ( # CONSTANT
172 pt => 72 / 72.27, pc => 12 / 72.27, in => 72, bp => 1,
173 cm => 72 / 2.54, mm => 72 / 25.4, dd => (72 / 72.27) * (1238 / 1157),
174 cc => 12 * (72 / 72.27) * (1238 / 1157), sp => 72 / 72.27 / 65536);
175  
176 sub to_bp {
177 my ($x) = @_;
178 if ($x =~ /^\s*([+-]?[\d\.]+)(\w*)\s*$/) {
179 my ($v, $u) = ($1, $2);
180 $u =~ s/^true//;
181 return $v * ($u ? $BP_conversions{$u} : 1); }
182 else {
183 return 1; } }
184  
185 #======================================================================
186 # Compute the effective size of a graphic transformed in graphicx style.
187 # [this is a simplification of image_graphicx_complex]
188 sub image_graphicx_size {
189 my ($source, $transform, %properties) = @_;
190 my $dppt = $properties{dppt} || $DOTS_PER_POINT;
191 my ($w, $h) = image_size($source);
192 return unless $w && $h;
193 foreach my $trans (@$transform) {
194 my ($op, $a1, $a2, $a3, $a4) = @$trans;
195 if ($op eq 'scale') { # $a1 => scale
196 ($w, $h) = (ceil($w * $a1), ceil($h * ($a2 || $a1))); }
197 elsif ($op eq 'scale-to') {
198 # $a1 => width (pts), $a2 => height (pts), $a3 => preserve aspect ratio.
199 if ($a3) { # If keeping aspect ratio, ignore the most extreme request
200 if ($a1 / $w < $a2 / $h) { $a2 = $h * $a1 / $w; }
201 else { $a1 = $w * $a2 / $h; } }
202 ($w, $h) = (ceil($a1 * $dppt), ceil($a2 * $dppt)); }
203 elsif ($op eq 'rotate') {
204 my $rad = -$a1 * 3.1415926 / 180; # close enough
205 my $s = sin($rad);
206 my $c = cos($rad);
207 ($w, $h) = (abs($w * $c) + abs($h * $s), abs($w * $s) + abs($h * $c)); }
208 elsif ($op eq 'reflect') { }
209 # In the following two, note that TeX's coordinates are relative to lower left corner,
210 # but ImageMagick's coordinates are relative to upper left.
211 elsif (($op eq 'trim') || ($op eq 'clip')) {
212 my ($x0, $y0, $ww, $hh);
213 if ($op eq 'trim') { # Amount to trim: a1=left, a2=bottom, a3=right, a4=top
214 ($x0, $y0, $ww, $hh) = (floor($a1 * $dppt), floor($a4 * $dppt),
215 ceil($w - ($a1 + $a3) * $dppt), ceil($h - ($a4 + $a2) * $dppt)); }
216 else { # BBox: a1=left, a2=bottom, a3=right, a4=top
217 ($x0, $y0, $ww, $hh) = (floor($a1 * $dppt), floor($h - $a4 * $dppt),
218 ceil(($a3 - $a1) * $dppt), ceil(($a4 - $a2) * $dppt)); }
219 ($w, $h) = ($ww, $hh);
220 } }
221 return ($w, $h); }
222  
223 # Totally doesn't belong here, but want to share...
224 sub image_graphicx_sizer {
225 my ($whatsit) = @_;
226 if (my $candidates = $whatsit->getProperty('candidates')) {
227 my ($source) = split(/,/, $candidates);
228 if (!pathname_is_absolute($source)) {
229 if (my $base = $STATE->lookupValue('SOURCEDIRECTORY')) {
230 $source = pathname_concat($base, $source); } }
231 my $options = $whatsit->getProperty('options');
232 my ($w, $h) = image_graphicx_size($source, image_graphicx_parse($options));
233 return (Dimension($w / $DOTS_PER_POINT . 'pt'), Dimension($h / $DOTS_PER_POINT . 'pt'), Dimension(0)) if $w; }
234 return (Dimension(0), Dimension(0), Dimension(0)); }
235  
236 #======================================================================
237 # Trivial scaling.
238 # When an image can be dealt with by simple scaling without "editting" the image.
239 # Compute the desired image size (width,height)
240 # No need to necessarily read the image!
241  
242 # Check if the transform (parsed from above) is trivial
243 sub image_graphicx_is_trivial {
244 my ($transform) = @_;
245 return !grep { !($_->[0] =~ /^scale/) } @$transform; }
246  
247 # Make the transform (parsed from above) trivial
248 # by removing any non-scaling operations!
249 sub image_graphicx_trivialize {
250 my ($transform) = @_;
251 return [grep { ($_->[0] =~ /^scale/) } @$transform]; }
252  
253 # sub trivial_scaling {
254 sub image_graphicx_trivial {
255 my ($source, $transform, %properties) = @_;
256 my ($w, $h) = image_size($source);
257 return unless $w && $h;
258 my $dppt = $properties{dppt} || $DOTS_PER_POINT;
259 foreach my $trans (@$transform) {
260 my ($op, $a1, $a2, $a3, $a4) = @$trans;
261 if ($op eq 'scale') { # $a1 => scale
262 ($w, $h) = (ceil($w * $a1), ceil($h * ($a2 || $a1))); }
263 elsif ($op eq 'scale-to') { # $a1 => width, $a2 => height, $a3 => preserve aspect ratio.
264 if ($a3) { # If keeping aspect ratio, ignore the most extreme request
265 if ($a1 / $w < $a2 / $h) { $a2 = $h * $a1 / $w; }
266 else { $a1 = $w * $a2 / $h; } }
267 ($w, $h) = (ceil($a1 * $dppt), ceil($a2 * $dppt)); } }
268 return ($w, $h); }
269  
270 #======================================================================
271 # Transform the image, returning (image,width,height);
272 # sub complex_transform {
273 sub image_graphicx_complex {
274 my ($source, $transform, %properties) = @_;
275 my $dppt = $properties{dppt} || $DOTS_PER_POINT;
276 my $background = $properties{background} || $BACKGROUND;
277 my $image = image_read($source, antialias => 1) or return;
278 # Get some defaults from the read-in image.
279 my ($imagedpi) = image_getvalue($image, 'x-resolution');
280 # image_setvalue($image,debug=>'exception');
281 my ($bg) = image_getvalue($image, 'transparent-color');
282 $background = "rgba($bg)" if $bg; # Use background from image, if any.
283 my ($hasalpha) = image_getvalue($image, 'matte');
284  
285 image_internalop($image, 'Trim') or return if $properties{autocrop};
286 my $orig_ncolors = image_getvalue($image, 'colors');
287 return unless $orig_ncolors;
288 my ($w, $h) = image_getvalue($image, 'width', 'height');
289 return unless $w && $h;
290 my @transform = @$transform;
291 # If native unit is points, we at least need to scale by dots/point.
292 # [tho' other scalings may override this]
293 if (($properties{unit} || 'pixel') eq 'point') {
294 push(@transform, ['scale', $dppt, $dppt]); }
295  
296 # For prescaling, compute the desired size and re-read the image into that size,
297 # with an appropriate density set. This will give much better anti-aliasing.
298 # Actually, we'll set the density & size up a further factor of $F, and then downscale.
299 if ($properties{prescale}) {
300 my ($w0, $h0) = ($w, $h);
301 while (@transform && ($transform[0]->[0] =~ /^scale/)) {
302 my ($op, $a1, $a2, $a3, $a4) = @{ shift(@transform) };
303 if ($op eq 'scale') { # $a1 => scale
304 ($w, $h) = (ceil($w * $a1), ceil($h * ($a2 || $a1))); }
305 elsif ($op eq 'scale-to') {
306 # $a1 => width (pts), $a2 => height (pts), $a3 => preserve aspect ratio.
307 if ($a3) { # If keeping aspect ratio, ignore the most extreme request
308 if ($a1 / $w < $a2 / $h) { $a2 = $h * $a1 / $w; }
309 else { $a1 = $w * $a2 / $h; } }
310 ($w, $h) = (ceil($a1 * $dppt), ceil($a2 * $dppt)); } }
311 my $X = 4; # Expansion factor
312 my ($dx, $dy) = (int($X * 72 * $w / $w0), int($X * 72 * $h / $h0));
313 NoteProgressDetailed(" [reloading to desired size $w x $h (density = $dx x $dy)]");
314 $image = image_read($source, antialias => 1, density => $dx . 'x' . $dy) or return;
315 image_internalop($image, 'Trim') or return if $properties{autocrop};
316 # image_setvalue($image, colorspace => 'RGB') or return;
317 image_internalop($image, 'Scale', geometry => int(100 / $X) . "%") or return; # Now downscale.
318 ($w, $h) = image_getvalue($image, 'width', 'height');
319 return unless $w && $h; }
320  
321 my $notes = '';
322 foreach my $trans (@transform) {
323 my ($op, $a1, $a2, $a3, $a4) = @$trans;
324 if ($op eq 'scale') { # $a1 => scale
325 ($w, $h) = (ceil($w * $a1), ceil($h * ($a2 || $a1)));
326 $notes .= " scale to $w x $h";
327 image_internalop($image, 'Scale', width => $w, height => $h) or return; }
328 elsif ($op eq 'scale-to') {
329 # $a1 => width (pts), $a2 => height (pts), $a3 => preserve aspect ratio.
330 if ($a3) { # If keeping aspect ratio, ignore the most extreme request
331 if ($a1 / $w < $a2 / $h) { $a2 = $h * $a1 / $w; }
332 else { $a1 = $w * $a2 / $h; } }
333 ($w, $h) = (ceil($a1 * $dppt), ceil($a2 * $dppt));
334 $notes .= " scale-to $w x $h";
335 image_internalop($image, 'Scale', width => $w, height => $h) or return; }
336 elsif ($op eq 'rotate') {
337 image_internalop($image, 'Rotate', degrees => -$a1, background => $background) or return;
338 ($w, $h) = image_getvalue($image, 'width', 'height');
339 return unless $w && $h;
340 $notes .= " rotate $a1 to $w x $h"; }
341 elsif ($op eq 'reflect') {
342 image_internalop($image, 'Flop') or return;
343 $notes .= " reflected"; }
344 # In the following two, note that TeX's coordinates are relative to lower left corner,
345 # but ImageMagick's coordinates are relative to upper left.
346 elsif (($op eq 'trim') || ($op eq 'clip')) {
347 my ($x0, $y0, $ww, $hh);
348 # Use the image's dpi for trim & clip!
349 my $idppt = (defined $imagedpi ? ($imagedpi / 72.0) : $dppt);
350 if ($op eq 'trim') { # Amount to trim: a1=left, a2=bottom, a3=right, a4=top
351 ($x0, $y0, $ww, $hh) = (floor($a1 * $idppt), floor($a4 * $idppt),
352 ceil($w - ($a1 + $a3) * $idppt), ceil($h - ($a4 + $a2) * $idppt));
353 $notes .= " trim to $ww x $hh @ $x0,$y0"; }
354 else { # BBox: a1=left, a2=bottom, a3=right, a4=top
355 ($x0, $y0, $ww, $hh) = (floor($a1 * $idppt), floor($h - $a4 * $idppt),
356 ceil(($a3 - $a1) * $idppt), ceil(($a4 - $a2) * $idppt));
357 $notes .= " clip to $ww x $hh @ $x0,$y0"; }
358  
359 if (($x0 > 0) || ($y0 > 0) || ($x0 + $ww < $w) || ($y0 + $hh < $h)) {
360 my $x0p = max($x0, 0); $x0 = min($x0, 0);
361 my $y0p = max($y0, 0); $y0 = min($y0, 0);
362 image_internalop($image, 'Crop', x => $x0p, width => min($ww, $w - $x0p),
363 y => $y0p, height => min($hh, $h - $y0p)) or return;
364 $w = min($ww + $x0, $w - $x0p);
365 $h = min($hh + $y0, $h - $y0p);
366 $notes .= " crop $w x $h @ $x0p,$y0p"; }
367 # No direct `padding' operation in ImageMagick
368 # BUT, trim & clip really shouldn't need to pad???
369 # And besides, this composition seems to mangle the colormap (depending on background)
370 # my $nimage = image_read("xc:$background", size => "$ww x $hh") or return;
371 # image_internalop($nimage, 'Composite', image => $image, compose => 'over',
372 # x => -$x0, y => -$y0) or return;
373 # $notes .= " compose to $ww x $hh at $x0,$y0";
374 # $image = $nimage;
375 # ($w, $h) = ($ww, $hh);
376 } }
377  
378 if ($properties{transparent} && !$hasalpha) {
379 $notes .= " transparent=$background";
380 image_internalop($image, 'Transparent', $background) or return; }
381  
382 if (my $curr_ncolors = image_getvalue($image, 'colors')) {
383 if (my $req_ncolors = $properties{ncolors}) {
384 $req_ncolors = int($orig_ncolors * $1 / 100) if $req_ncolors =~ /^([\d]*)\%$/;
385 if ($req_ncolors < $curr_ncolors) {
386 $notes .= " quantize $orig_ncolors => $req_ncolors";
387 image_internalop($image, 'Quantize', colors => $req_ncolors) or return; } } }
388  
389 if (my $quality = $properties{quality}) {
390 $notes .= " quality=$quality";
391 image_setvalue($image, quality => $properties{quality}) or return; }
392  
393 NoteProgressDetailed(" [Transformed : $notes]") if $notes;
394 return ($image, $w, $h); }
395  
396 # Wrap up ImageMagick's methods to give more useful & consistent error handling.
397 # These all return non-zero on success!
398 # so, you generally want to do image_internalop(...) or return;
399  
400 # This reads a new image, setting the given properties BEFORE ingesting the image data.
401 sub image_read {
402 my ($source, @args) = @_;
403 if (!$source) {
404 Error('imageprocessing', 'read', undef, "No image source given"); return; }
405 return unless $source;
406 my $image = image_object();
407 image_internalop($image, 'Set', @args) or return;
408 image_internalop($image, 'Read', $source) or return;
409 return $image; }
410  
411 sub image_write {
412 my ($image, $destination) = @_;
413 if (!$image) {
414 Error('imageprocessing', 'write', undef, "No image object!"); return; }
415 if (!$destination) {
416 Error('imageprocessing', 'write', undef, "No image destination!"); return; }
417 # In the perverse case that we've ended up with a sequence of images; flatten them.
418 if (@$image > 1) {
419 my $fimage = $image->Flatten(); # Just in case we ended up with pieces!?!?!?
420 $image = $fimage if $fimage; }
421 return image_internalop($image, 'Write', filename => $destination); }
422  
423 sub image_getvalue {
424 my ($image, @args) = @_;
425 if (!$image) {
426 Error('imageprocessing', 'getvalue', undef, "No image object!"); return; }
427 my @values = $image->Get(@args);
428 return @values; }
429  
430 sub image_setvalue {
431 my ($image, @args) = @_;
432 if (!$image) {
433 Error('imageprocessing', 'setvalue', undef, "No image object!"); return; }
434 return image_internalop($image, 'Set', @args); }
435  
436 sub image_internalop {
437 my ($image, $operation, @args) = @_;
438 if (!$image) {
439 Error('imageprocessing', 'internal', undef, "No image object!"); return; }
440 my $retval = $image->$operation(@args);
441 return 1 unless $retval;
442 my $retcode = 999;
443 if ($retval =~ /(\d+)/) {
444 $retcode = $1; }
445 if ($retcode < 400) { # Warning
446 Warn('imageprocessing', $operation, undef,
447 "Image processing operation $operation (" . join(', ', @args) . ") returned $retval");
448 return 1; }
449 else { # Error
450 Error('imageprocessing', $operation, undef,
451 "Image processing operation $operation (" . join(', ', @args) . ") returned $retval");
452 return 0; } }
453  
454 #======================================================================
455 1;