| 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 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 1 | ▶ | use LaTeXML::Global; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 1 | ▶ | use LaTeXML::Common::Error; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 1 | ▶ | use LaTeXML::Common::Dimension; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 1 | ▶ | use LaTeXML::Util::Pathname; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 1 | ▶ | use List::Util qw(min max); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 1 | ▶ | use Image::Size; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 1 | ▶ | use POSIX; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 1 | ▶ | use base qw(Exporter); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 1 | our @EXPORT = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | qw( &image_candidates &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 | 1 | our $DPI = 100; # [CONSTANT] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 1 | our $BACKGROUND = "#FFFFFF"; # [CONSTANT] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | # Return cleaned-up path and list of candidate image files | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | # {We could, but dont, filter out non-image types, since extensions are so inconsistent. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | # although we could query image_type which is more thorough) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 0 | ▶ | sub image_candidates { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
image_candidates: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 0 | my ($path) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 0 | $path =~ s/^\s+//; $path =~ s/\s+$//; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 0 | $path =~ s/^("+)(.+)\g1$/$2/; # unwrap if in quotes | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 0 | my $searchpaths = $STATE->lookupValue('GRAPHICSPATHS'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 0 | my @candidates = pathname_findall($path, types => ['*'], paths => $searchpaths); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 0 | ▶ | if (!@candidates) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | # if we have no candidates, also consult kpsewhich, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | # e.g. for "example-image-a" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 0 | ▶ | if (my $kpse_found = pathname_kpsewhich("$path.png", "$path.pdf")) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 0 | @candidates = ($kpse_found); } } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 0 | ▶ | if (my $base = $STATE->lookupValue('SOURCEDIRECTORY')) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 0 | @candidates = map { pathname_relative($_, $base) } @candidates; } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 0 | return ($path, @candidates); } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | # These environment variables can be used to limit the amount | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | # of time & space used by ImageMagick. They are particularly useful | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | # when ghostscript becomes involved in converting postscript or pdf. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | # HOWEVER, there are indications that the time limit (at least) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | # is being measured against the whole latexml process, not just image processing. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | # Thus they aren't really that useful here. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | # They probably are useful in a server context, however, so I'll leave the comments. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | # $ENV{MAGICK_DISK_LIMIT} = "2GiB" unless defined $ENV{MAGICK_DISK_LIMIT}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | # $ENV{MAGICK_MEMORY_LIMIT} = "512MiB" unless defined $ENV{MAGICK_MEMORY_LIMIT}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | # $ENV{MAGICK_MAP_LIMIT} = "1GiB" unless defined $ENV{MAGICK_MAP_LIMIT}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | # $ENV{MAGICK_TIME_LIMIT} = "300" unless defined $ENV{MAGICK_TIME_LIMIT}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | # Note that Image::Size may, itself, use Image::Magick, if available, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | # as a fallback for getting image size & type!!! | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | # However, it seems not to recognize file types with extension .EPS (uppercase), eg! | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 0 | ▶ | sub image_type { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
image_type: not called CC=8 SCAR=42.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 0 | my ($pathname) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 0 | my ($w, $h, $t) = imgsize($pathname); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | # even though Image::Size CLAIMS to use Image::Magick as fallback... needs tickling? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 0 | ▶ | if (!(defined $w) && !(defined $h) && image_can_image()) { # try harder! | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
not defined $w || defined $h and image_can_image()
defined $w || defined $h
MC/DC0%0/3
not defined $w || defined $h and image_can_image()
defined $w
defined $h
image_can_image()
Truth table0%0/4
not(A || B) and C
A= defined $wB= defined $hC= image_can_image()
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 0 | ▶ | my $image = image_read($pathname) or return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 0 | ($t) = image_getvalue($image, 'format'); } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | # Note that Image::Magick (sometimes) returns "descriptive" types | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | # (but I can't find a list anywhere!) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 0 | ▶ | $t = 'eps' if $t && $t =~ /postscript/i; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$t and $t =~ /postscript/i
MC/DC0%0/2
$t and $t =~ /postscript/i
$t
$t =~ /postscript/i
Truth table0%0/3
A and B
A= $tB= $t =~ /postscript/i
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 0 | ▶ | return (defined $t ? lc($t) : undef); } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 0 | ▶ | sub image_size { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
image_size: not called CC=8 SCAR=42.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 0 | my ($pathname) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | # Annoyingly, ImageMagick uses the MediaBox instead of CropBox (as does graphics.sty) for pdfs. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | # Worse, imgsize delegates to ImageMagick, w/o ability to add options | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 0 | ▶ | if (($pathname =~ /\.pdf$/i) && image_can_image()) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$pathname =~ /\.pdf$/i and image_can_image()
MC/DC0%0/2
$pathname =~ /\.pdf$/i and image_can_image()
$pathname =~ /\.pdf$/i
image_can_image()
Truth table0%0/3
A and B
A= $pathname =~ /\.pdf$/iB= image_can_image()
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 0 | ▶ | my $image = image_read($pathname) or return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 0 | return image_getvalue($image, 'width', 'height'); } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 0 | my ($w, $h, $t) = imgsize($pathname); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 0 | ▶ | return ($w, $h) if $w && $h; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$w and $h
MC/DC0%0/2
$w and $h
$w
$h
Truth table0%0/3
A and B
A= $wB= $h
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 0 | ▶ | if (image_can_image()) { # try harder! | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 0 | ▶ | my $image = image_read($pathname) or return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 0 | return image_getvalue($image, 'width', 'height'); } } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | # This will be set once we've found an Image processing library to use [Daemon safe] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 1 | our $IMAGECLASS; # cached class if we found one that works. [CONFIGURABLE?] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 1 | my @MagickClasses = (qw(Graphics::Magick Image::Magick)); # CONSTANT | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 0 | ▶ | sub image_classes { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
image_classes: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 0 | return @MagickClasses; } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 1 | ▶ | sub image_can_image { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
image_can_image: called CC=4 SCAR=14.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 1 | my ($pathname) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 1 | ▶ | if (!$IMAGECLASS) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 1 | foreach my $class (@MagickClasses) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 2 | my $module = $class . ".pm"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 2 | $module =~ s/::/\//g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 2 | my $object = eval { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 2 | local $LaTeXML::IGNORE_ERRORS = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 0 | require $module; $class->new(); }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 2 | ▶ | if ($object) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 0 | $IMAGECLASS = $class; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 0 | last; } } } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 1 | return $IMAGECLASS; } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | # return an image object (into which you can read), if possible. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 1 | ▶ | sub image_object { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
image_object: called CC=2 SCAR=9.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 1 | my (%properties) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 1 | ▶ | return unless image_can_image(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 0 | my $image = $IMAGECLASS->new(%properties); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 0 | return $image; } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | #%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | # Working with Image transformation options from the graphic(s|x) packages | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | #%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | # Note that viewport is supposed to be relative to bounding box, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | # and EITHER ONE can cause clipping, if clip=true. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | # However, apparently the INTENT of bounding box is simply to | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | # supply one, if one can't be found, in order to determine the image size. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | # In our case, we may end up getting a gif, jpeg, etc, whose origin is always 0,0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | # and whose size is clear; also postscript figures sizes will be determined | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | # by ghostview(?). Another use of setting a bounding box, when clip=false, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | # is to make the image lay ontop of neighboring text. This isn't quite | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | # possible in HTML, other than possibly through some tricky CSS. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | # Besides, I'd like to avoid reading the bb file, if I can. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | # --- So, for all these reasons, we simply ignore bounding box here. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | 0 | ▶ | sub image_graphicx_parse { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
image_graphicx_parse: not called CC=41 SCAR=74.5
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 0 | my ($transformstring, %options) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 0 | ▶ | return [] unless $transformstring; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 0 | local $_ = $_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 0 | my ($v, $clip, $trim, $width, $height, $xscale, $yscale, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | $aspect, $angle, $rotfirst, $mag, @bb, @vp,) = ('', '', '', 0, 0, 0, 0, '', 0, '', 1, 0); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | 0 | my @unknown = (); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 0 | ▶ | my @ignore = @{ $options{ignore_options} || [] }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$options{'ignore_options'} || []
MC/DC0%0/1
$options{'ignore_options'} || []
$options{'ignore_options'}
Truth table0%0/2
A
A= $options{'ignore_options'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | 0 | ▶ | foreach (split(/(?<!\\),/, $transformstring || '')) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$transformstring || ''
MC/DC0%0/1
$transformstring || ''
$transformstring
Truth table0%0/2
A
A= $transformstring
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | 0 | ▶ | if (/^\s*(\w+)(?:=\s*(.*))?\s*$/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | 0 | ▶ | $_ = $1; $v = $2 || ''; $v =~ s/\\,/,/g; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$2 || ''
MC/DC0%0/1
$2 || ''
$2
Truth table0%0/2
A
A= $2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | 0 | my $op = $_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | 0 | ▶ | if (grep { $op eq $_ } @ignore) { } # Ignore this option | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 16 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | 0 | elsif (/^bb$/) { @bb = map { to_bp($_) } split(' ', $v); } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | 0 | elsif (/^bb(?:ll|ur)(?:x|y)$/) { $bb[2 * /ur/ + /y/] = to_bp($v); } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | 0 | elsif (/^nat(?:width|height)$/) { $bb[2 + /width/] = to_bp($v); } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | 0 | elsif (/^viewport$/) { @vp = map { to_bp($_) } split(' ', $v); $trim = 0; } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | 0 | elsif (/^trim$/) { @vp = map { to_bp($_) } split(' ', $v); $trim = 1; } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | 0 | elsif (/^clip$/) { $clip = !($v eq 'false'); } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | 0 | elsif (/^keepaspectratio$/) { $aspect = !($v eq 'false'); } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | 0 | elsif (/^width$/) { $width = to_bp($v); } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | 0 | elsif (/^(?:total)?height$/) { $height = to_bp($v); } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | 0 | elsif (/^scale$/) { $xscale = $yscale = $v; } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | 0 | elsif (/^xscale$/) { $xscale = $v; } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | 0 | elsif (/^yscale$/) { $yscale = $v; } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | 0 | ▶ | elsif (/^angle$/) { $angle = $v; $rotfirst = !($width || $height || $xscale || $yscale); } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/9
$width || $height || $xscale || $yscale
$width or $height or $xscale
$width or $height
MC/DC0%0/4
$width || $height || $xscale || $yscale
$width
$height
$xscale
$yscale
Truth table0%0/5
A or B or C || D
A= $widthB= $heightC= $xscaleD= $yscale
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | elsif (/^origin$/) { } # ?? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | # Non-standard option | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | 0 | elsif (/^magnification$/) { $mag = $v; } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | 0 | else { push(@unknown, [$op, $v]); } } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | else { } } # ? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | # -------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | # Now, compile the options into a sequence of `transformations'. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | # Note: the order of rotation & scaling is significant, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | # but the order of various clipping options w.r.t rotation or scaling is not. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | 0 | my @transform = (); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | # If clip is set, viewport and trim will clip the image to that box, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | # but if not, they should ONLY affect the apparent size of the image. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | # Anything outside the box will *overlap* any adjacent material. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | # That's tricky to do in html, but possible with some fancy, brittle, CSS .... | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | # For now, I guess we'll just clip in all cases. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | 0 | ▶ | push(@transform, [($trim ? 'trim' : 'clip'), @vp]) if @vp; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | 0 | ▶ | push(@transform, ['rotate', $angle]) if ($rotfirst && $angle); # Rotate before scaling? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$rotfirst and $angle
MC/DC0%0/2
$rotfirst and $angle
$rotfirst
$angle
Truth table0%0/3
A and B
A= $rotfirstB= $angle
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | 0 | ▶ | if ($width && $height) { push(@transform, ['scale-to', $mag * $width, $mag * $height, $aspect]); } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 7 branches
Condition0%0/3
$width and $height
MC/DC0%0/2
$width and $height
$width
$height
Truth table0%0/3
A and B
A= $widthB= $height
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | 0 | elsif ($width) { push(@transform, ['scale-to', $mag * $width, 999999, 1]); } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | 0 | elsif ($height) { push(@transform, ['scale-to', 999999, $mag * $height, 1]); } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | 0 | ▶ | elsif ($xscale && $yscale) { push(@transform, ['scale', $mag * $xscale, $mag * $yscale]); } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$xscale and $yscale
MC/DC0%0/2
$xscale and $yscale
$xscale
$yscale
Truth table0%0/3
A and B
A= $xscaleB= $yscale
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | 0 | elsif ($xscale) { push(@transform, ['scale', $mag * $xscale, $mag]); } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | 0 | elsif ($yscale) { push(@transform, ['scale', $mag, $mag * $yscale]); } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | 0 | elsif ($mag != 1) { push(@transform, ['scale', $mag, $mag]); } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | 0 | ▶ | push(@transform, ['rotate', $angle]) if (!$rotfirst && $angle); # Rotate after scaling? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not $rotfirst and $angle
MC/DC0%0/2
not $rotfirst and $angle
not $rotfirst
$angle
Truth table0%0/3
not(A) and B
A= not $rotfirstB= $angle
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | # ---------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | 0 | return [@transform, @unknown]; } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | 1 | my %BP_conversions = ( # CONSTANT | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | pt => 72 / 72.27, pc => 12 / 72.27, in => 72, bp => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | cm => 72 / 2.54, mm => 72 / 25.4, dd => (72 / 72.27) * (1238 / 1157), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | cc => 12 * (72 / 72.27) * (1238 / 1157), sp => 72 / 72.27 / 65536); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | 0 | ▶ | sub to_bp { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
to_bp: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | 0 | my ($x) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | 0 | ▶ | if ($x =~ /^\s*([+-]?[\d\.]+)(\w*)\s*$/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | 0 | my ($v, $u) = ($1, $2); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | 0 | $u =~ s/^true//; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | 0 | ▶ | return $v * (($u && $BP_conversions{$u}) || 1); } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/5
$u && $BP_conversions{$u} || 1
$u and $BP_conversions{$u}
MC/DC0%0/2
$u && $BP_conversions{$u} || 1
$u
$BP_conversions{$u}
Truth table0%0/3
A and B
A= $uB= $BP_conversions{$u}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | 0 | return 1; } } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | #====================================================================== | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | # Compute the effective size of a graphic transformed in graphicx style. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | # [this is a simplification of image_graphicx_complex] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | # Note: This is not (yet) using any of the magnify/upscale parameters; Should it? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | 0 | ▶ | sub image_graphicx_size { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
image_graphicx_size: not called CC=15 SCAR=54.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | 0 | my ($source, $transform, %properties) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | 0 | ▶ | my $dppt = ($properties{DPI} || $DPI) / 72.27; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$properties{'DPI'} || $LaTeXML::Util::Image::DPI
MC/DC0%0/2
$properties{'DPI'} || $LaTeXML::Util::Image::DPI
$properties{'DPI'}
$LaTeXML::Util::Image::DPI
Truth table0%0/3
A || B
A= $properties{'DPI'}B= $LaTeXML::Util::Image::DPI
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | 0 | my ($w, $h) = image_size($source); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | 0 | ▶ | return unless $w && $h; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$w and $h
MC/DC0%0/2
$w and $h
$w
$h
Truth table0%0/3
A and B
A= $wB= $h
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | 0 | foreach my $trans (@$transform) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | 0 | my ($op, $a1, $a2, $a3, $a4) = @$trans; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | 0 | ▶ | if ($op eq 'scale') { # $a1 => scale | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 5 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | 0 | ▶ | ($w, $h) = (ceil($w * $a1), ceil($h * ($a2 || $a1))); } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$a2 || $a1
MC/DC0%0/2
$a2 || $a1
$a2
$a1
Truth table0%0/3
A || B
A= $a2B= $a1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | elsif ($op eq 'scale-to') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | # $a1 => width (pts), $a2 => height (pts), $a3 => preserve aspect ratio. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | 0 | ▶ | if ($a3) { # If keeping aspect ratio, ignore the most extreme request | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | 0 | ▶ | if ($a1 / $w < $a2 / $h) { $a2 = $h * $a1 / $w; } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | 0 | else { $a1 = $w * $a2 / $h; } } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | 0 | ($w, $h) = (ceil($a1 * $dppt), ceil($a2 * $dppt)); } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | elsif ($op eq 'rotate') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | 0 | my $rad = -$a1 * 3.1415926 / 180; # close enough | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | 0 | my $s = sin($rad); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | 0 | my $c = cos($rad); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | 0 | ($w, $h) = (abs($w * $c) + abs($h * $s), abs($w * $s) + abs($h * $c)); } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | elsif ($op eq 'reflect') { } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | # In the following two, note that TeX's coordinates are relative to lower left corner, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | # but ImageMagick's coordinates are relative to upper left. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | ▶ | elsif (($op eq 'trim') || ($op eq 'clip')) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$op eq "trim" or $op eq "clip"
MC/DC0%0/2
$op eq "trim" or $op eq "clip"
$op eq "trim"
$op eq "clip"
Truth table0%0/3
A or B
A= $op eq "trim"B= $op eq "clip"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | 0 | my ($x0, $y0, $ww, $hh); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | 0 | ▶ | if ($op eq 'trim') { # Amount to trim: a1=left, a2=bottom, a3=right, a4=top | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | 0 | ($x0, $y0, $ww, $hh) = (floor($a1 * $dppt), floor($a4 * $dppt), | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | ceil($w - ($a1 + $a3) * $dppt), ceil($h - ($a4 + $a2) * $dppt)); } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | else { # BBox: a1=left, a2=bottom, a3=right, a4=top | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | 0 | ($x0, $y0, $ww, $hh) = (floor($a1 * $dppt), floor($h - $a4 * $dppt), | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | ceil(($a3 - $a1) * $dppt), ceil(($a4 - $a2) * $dppt)); } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | 0 | ($w, $h) = ($ww, $hh); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | } } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | 0 | return ($w, $h); } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | # Totally doesn't belong here, but want to share... | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | 0 | ▶ | sub image_graphicx_sizer { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
image_graphicx_sizer: not called CC=8 SCAR=42.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | 0 | my ($whatsit) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | 0 | ▶ | if (my $candidates = $whatsit->getProperty('candidates')) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | 0 | ▶ | my $dpi = ($STATE && $STATE->lookupValue('DPI')) || $DPI; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/6
$LaTeXML::Util::Image::STATE && $LaTeXML::Util::Image::STATE->lookupValue('DPI') || $LaTeXML::Util::Image::DPI
$LaTeXML::Util::Image::STATE and $LaTeXML::Util::Image::STATE->lookupValue("DPI")
MC/DC0%0/3
$LaTeXML::Util::Image::STATE && $LaTeXML::Util::Image::STATE->lookupValue('DPI') || $LaTeXML::Util::Image::DPI
$LaTeXML::Util::Image::STATE
$LaTeXML::Util::Image::STATE->lookupValue("DPI")
$LaTeXML::Util::Image::DPI
Truth table0%0/5
A and B || C
A= $LaTeXML::Util::Image::STATEB= $LaTeXML::Util::Image::STATE->lookupValue("DPI")C= $LaTeXML::Util::Image::DPI
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | 0 | foreach my $source (split(/,/, $candidates)) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | 0 | ▶ | if (!pathname_is_absolute($source)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | 0 | ▶ | if (my $base = $STATE->lookupValue('SOURCEDIRECTORY')) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | 0 | $source = pathname_concat($base, $source); } } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | # Skip anything that a lower level imgsize can't understand | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | 0 | my $options = $whatsit->getProperty('options'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | 0 | local $LaTeXML::IGNORE_ERRORS = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | 0 | my ($w, $h) = image_graphicx_size($source, image_graphicx_parse($options), DPI => $dpi); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | 0 | ▶ | return (Dimension($w * 72.27 / $dpi . 'pt'), Dimension($h * 72.27 / $dpi . 'pt'), Dimension(0)) if $w; } } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | 0 | return (Dimension(0), Dimension(0), Dimension(0)); } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | #====================================================================== | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | # Trivial scaling. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | # When an image can be dealt with by simple scaling without "editting" the image. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | # Compute the desired image size (width,height) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | # No need to necessarily read the image! | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | # Check if the transform (parsed from above) is trivial | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | # at most scaling; no rotations, reflectiosn or clipping. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | 0 | ▶ | sub image_graphicx_is_trivial { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
image_graphicx_is_trivial: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | 0 | my ($transform) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | 0 | return !grep { ($_->[0] =~ /^(?:rotate|reflect|trim|clip)$/) } @$transform; } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | # Make the transform (parsed from above) trivial | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | # by removing any non-scaling operations! | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | 0 | ▶ | sub image_graphicx_trivialize { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
image_graphicx_trivialize: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | 0 | my ($transform) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | 0 | return [grep { ($_->[0] =~ /^scale/) } @$transform]; } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | # trivial_scaling: for transforms containing ONLY scale, scale-to | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | 0 | ▶ | sub image_graphicx_trivial { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
image_graphicx_trivial: not called CC=10 SCAR=47.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | 0 | my ($source, $transform, %properties) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | 0 | my ($w, $h) = image_size($source); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | 0 | ▶ | return unless $w && $h; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$w and $h
MC/DC0%0/2
$w and $h
$w
$h
Truth table0%0/3
A and B
A= $wB= $h
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | 0 | ▶ | my $dppt = ($properties{DPI} || $DPI) / 72.27; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$properties{'DPI'} || $LaTeXML::Util::Image::DPI
MC/DC0%0/2
$properties{'DPI'} || $LaTeXML::Util::Image::DPI
$properties{'DPI'}
$LaTeXML::Util::Image::DPI
Truth table0%0/3
A || B
A= $properties{'DPI'}B= $LaTeXML::Util::Image::DPI
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | 0 | foreach my $trans (@$transform) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | 0 | my ($op, $a1, $a2, $a3, $a4) = @$trans; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | 0 | ▶ | if ($op eq 'scale') { # $a1 => scale | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | 0 | ▶ | ($w, $h) = (ceil($w * $a1), ceil($h * ($a2 || $a1))); } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$a2 || $a1
MC/DC0%0/2
$a2 || $a1
$a2
$a1
Truth table0%0/3
A || B
A= $a2B= $a1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | elsif ($op eq 'scale-to') { # $a1 => width, $a2 => height, $a3 => preserve aspect ratio. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | 0 | ▶ | if ($a3) { # If keeping aspect ratio, ignore the most extreme request | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | 0 | ▶ | if ($a1 / $w < $a2 / $h) { $a2 = $h * $a1 / $w; } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | 0 | else { $a1 = $w * $a2 / $h; } } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | 0 | ($w, $h) = (ceil($a1 * $dppt), ceil($a2 * $dppt)); } } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | 0 | return ($w, $h); } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | #====================================================================== | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | # Transform the image, returning (image,width,height); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | # complex transform for transforms containing ONLY | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | # scale, scale-to, rotate, reflect, trim, clip. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | 0 | ▶ | sub image_graphicx_complex { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
image_graphicx_complex: not called CC=76 SCAR=86.7
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | 0 | my ($source, $transform, %properties) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | 0 | ▶ | my $dpi = ($properties{DPI} || $DPI); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$properties{'DPI'} || $LaTeXML::Util::Image::DPI
MC/DC0%0/2
$properties{'DPI'} || $LaTeXML::Util::Image::DPI
$properties{'DPI'}
$LaTeXML::Util::Image::DPI
Truth table0%0/3
A || B
A= $properties{'DPI'}B= $LaTeXML::Util::Image::DPI
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | 0 | ▶ | my $magnify = $properties{magnify} || 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$properties{'magnify'} || 1
MC/DC0%0/1
$properties{'magnify'} || 1
$properties{'magnify'}
Truth table0%0/2
A
A= $properties{'magnify'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | 0 | ▶ | my $upsample = $properties{upsample} || 2; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$properties{'upsample'} || 2
MC/DC0%0/1
$properties{'upsample'} || 2
$properties{'upsample'}
Truth table0%0/2
A
A= $properties{'upsample'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | 0 | ▶ | my $zoomout = $properties{zoomout} || 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$properties{'zoomout'} || 1
MC/DC0%0/1
$properties{'zoomout'} || 1
$properties{'zoomout'}
Truth table0%0/2
A
A= $properties{'zoomout'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | 0 | my ($xprescale, $yprescale) = (1, 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | # # Wastefully preread the image to get it's initial size | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | 0 | my ($w0, $h0) = image_size($source); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | 0 | ▶ | return unless $w0 && $h0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$w0 and $h0
MC/DC0%0/2
$w0 and $h0
$w0
$h0
Truth table0%0/3
A and B
A= $w0B= $h0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | Debug("Processing $source initially $w0 x $h0," | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | 0 | ▶ | . "w/ DPI=$dpi, magnify=$magnify, upsample=$upsample, zoomout=$zoomout") if $LaTeXML::DEBUG{images}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | 0 | my @transform = @$transform; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | # Establish the scaling necessary to carry out the transformation w/o loosing resolution | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | # This is particularly for vector formats before rasterizing. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | # If image is vector & transform starts with scaling, rasterize at at least desired size | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | # We REALLY should go through the ENTIRE transformation detecting the scaling, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | # but it's tricky to account for the prescale when carrying out the actual transformation! | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | 0 | ▶ | if ($properties{prescale}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | 0 | ▶ | while (@transform && ($transform[0]->[0] =~ /^scale/)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
@transform and $transform[0][0] =~ /^scale/
MC/DC0%0/2
@transform and $transform[0][0] =~ /^scale/
@transform
$transform[0][0] =~ /^scale/
Truth table0%0/3
A and B
A= @transformB= $transform[0][0] =~ /^scale/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | 0 | my ($op, $a1, $a2, $a3, $a4) = @{ shift(@transform) }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | 0 | ▶ | if ($op eq 'scale') { # $a1 => scale | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | 0 | ▶ | $xprescale *= $a1; $yprescale *= ($a2 || $a1); } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$a2 || $a1
MC/DC0%0/2
$a2 || $a1
$a2
$a1
Truth table0%0/3
A || B
A= $a2B= $a1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | elsif ($op eq 'scale-to') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | # $a1 => width (pts), $a2 => height (pts), $a3 => preserve aspect ratio. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | 0 | ▶ | if ($a3) { # If keeping aspect ratio, ignore the most extreme request | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | 0 | ▶ | if ($a1 / $w0 < $a2 / $h0) { $a2 = $h0 * $a1 / $w0; } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | 0 | else { $a1 = $w0 * $a2 / $h0; } } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | 0 | $xprescale *= $a1 * $dpi / $w0 / 72.27; $yprescale *= $a2 * $dpi / $h0 / 72.27; } } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | 0 | ▶ | Debug("Prescaling factors $xprescale x $yprescale") if $LaTeXML::DEBUG{images}; } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | # At this point, we conceivably could clamp the resolution to limit | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | # to a maximum (or minimum) size, either for display or to reduce needed resources. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | # We'd presumably want to adjust (one of) the scaling factors. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | 0 | $dpi *= $magnify * $upsample; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | 0 | ▶ | my $background = $properties{background} || $BACKGROUND; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$properties{'background'} || $LaTeXML::Util::Image::BACKGROUND
MC/DC0%0/2
$properties{'background'} || $LaTeXML::Util::Image::BACKGROUND
$properties{'background'}
$LaTeXML::Util::Image::BACKGROUND
Truth table0%0/3
A || B
A= $properties{'background'}B= $LaTeXML::Util::Image::BACKGROUND
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | 0 | ▶ | my $image = image_read($source, antialias => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | density => $dpi * $xprescale . 'x' . $dpi * $yprescale, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | ) or return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | 0 | my ($w, $h) = image_getvalue($image, 'width', 'height'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | # Get some defaults from the read-in image. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | 0 | my ($imagedpi) = image_getvalue($image, 'x-resolution'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | # image_setvalue($image,debug=>'exception'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | 0 | my ($bg) = image_getvalue($image, 'mattecolor'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | 0 | ▶ | $background = "rgba($bg)" if $bg; # Use background from image, if any. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | 0 | my ($hasalpha) = image_getvalue($image, 'matte'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | 0 | ▶ | Debug("Read $source to $w x $h") if $LaTeXML::DEBUG{images}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | 0 | ▶ | if ($properties{autocrop}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | 0 | ▶ | image_internalop($image, 'Trim') or return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | 0 | ($w, $h) = image_getvalue($image, 'width', 'height'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | 0 | ▶ | Debug(" Autocrop to $w x $h") if $LaTeXML::DEBUG{images}; } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | 0 | my $orig_ncolors = image_getvalue($image, 'colors'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | 0 | ▶ | if (!$orig_ncolors || !($w && $h)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$orig_ncolors and ($w and $h)
$w and $h
MC/DC0%0/3
$orig_ncolors and ($w and $h)
$orig_ncolors
$w
$h
Truth table0%0/4
A and B and C
A= $orig_ncolorsB= $wC= $h
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 359 | 0 | ▶ | Debug(" Image is now empty; skipping") if $LaTeXML::DEBUG{images}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | 0 | return; } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | 0 | foreach my $trans (@transform) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 363 | 0 | my ($op, $a1, $a2, $a3, $a4) = @$trans; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 364 | 0 | ▶ | return unless $w && $h; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$w and $h
MC/DC0%0/2
$w and $h
$w
$h
Truth table0%0/3
A and B
A= $wB= $h
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 365 | 0 | ▶ | if ($op eq 'scale') { # $a1 => scale | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 5 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 366 | 0 | ▶ | ($w, $h) = (ceil($w * $a1), ceil($h * ($a2 || $a1))); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$a2 || $a1
MC/DC0%0/2
$a2 || $a1
$a2
$a1
Truth table0%0/3
A || B
A= $a2B= $a1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 367 | 0 | ▶ | return unless $w && $h; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$w and $h
MC/DC0%0/2
$w and $h
$w
$h
Truth table0%0/3
A and B
A= $wB= $h
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 368 | 0 | ▶ | image_internalop($image, 'Scale', width => $w, height => $h) or return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 369 | 0 | ▶ | Debug(" Scale by $a1 " . ($a2 ? " x $a2" : '') . " => $w x $h") if $LaTeXML::DEBUG{images}; } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 370 | elsif ($op eq 'scale-to') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 371 | # $a1 => width (pts), $a2 => height (pts), $a3 => preserve aspect ratio. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 372 | 0 | ▶ | if ($a3) { # If keeping aspect ratio, ignore the most extreme request | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 373 | 0 | ▶ | if ($a1 / $w < $a2 / $h) { $a2 = $h * $a1 / $w; } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 374 | 0 | else { $a1 = $w * $a2 / $h; } } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 375 | 0 | ($w, $h) = (ceil($a1 * $dpi / 72.27), ceil($a2 * $dpi / 72.27)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 376 | 0 | ▶ | image_internalop($image, 'Scale', width => $w, height => $h) or return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 377 | 0 | ▶ | Debug(" Scale to $w x $h") if $LaTeXML::DEBUG{images}; } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 378 | elsif ($op eq 'rotate') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 379 | 0 | ▶ | image_internalop($image, 'Rotate', degrees => -$a1, background => $background) or return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 380 | 0 | ($w, $h) = image_getvalue($image, 'width', 'height'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 381 | 0 | ▶ | return unless $w && $h; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$w and $h
MC/DC0%0/2
$w and $h
$w
$h
Truth table0%0/3
A and B
A= $wB= $h
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 382 | 0 | ▶ | Debug(" Rotate by $a1 => $w x $h") if $LaTeXML::DEBUG{images}; } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 383 | elsif ($op eq 'reflect') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 384 | 0 | ▶ | image_internalop($image, 'Flop') or return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 385 | 0 | ▶ | Debug(" Reflext image => $w x $h") if $LaTeXML::DEBUG{images}; } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 386 | # In the following two, note that TeX's coordinates are relative to lower left corner, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 387 | # but ImageMagick's coordinates are relative to upper left. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 388 | ▶ | elsif (($op eq 'trim') || ($op eq 'clip')) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$op eq "trim" or $op eq "clip"
MC/DC0%0/2
$op eq "trim" or $op eq "clip"
$op eq "trim"
$op eq "clip"
Truth table0%0/3
A or B
A= $op eq "trim"B= $op eq "clip"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 389 | 0 | my ($x0, $y0, $ww, $hh); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 390 | # Use the image's dpi for trim & clip! | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 391 | 0 | ▶ | my $idppt = (defined $imagedpi ? $imagedpi : $dpi) / 72.27; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 392 | 0 | ▶ | if ($op eq 'trim') { # Amount to trim: a1=left, a2=bottom, a3=right, a4=top | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 393 | 0 | ($x0, $y0, $ww, $hh) = (floor($a1 * $idppt), floor($a4 * $idppt), | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 394 | ceil($w - ($a1 + $a3) * $idppt), ceil($h - ($a4 + $a2) * $idppt)); } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 395 | else { # BBox: a1=left, a2=bottom, a3=right, a4=top | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 396 | 0 | ($x0, $y0, $ww, $hh) = (floor($a1 * $idppt), floor($h - $a4 * $idppt), | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 397 | ceil(($a3 - $a1) * $idppt), ceil(($a4 - $a2) * $idppt)); } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 398 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 399 | 0 | ▶ | if (($x0 > 0) || ($y0 > 0) || ($x0 + $ww < $w) || ($y0 + $hh < $h)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/9
$x0 > 0 or $y0 > 0 or $x0 + $ww < $w or $y0 + $hh < $h
$x0 > 0 or $y0 > 0 or $x0 + $ww < $w
$x0 > 0 or $y0 > 0
MC/DC0%0/4
$x0 > 0 or $y0 > 0 or $x0 + $ww < $w or $y0 + $hh < $h
$x0 > 0
$y0 > 0
$x0 + $ww < $w
$y0 + $hh < $h
Truth table0%0/5
A or B or C or D
A= $x0 > 0B= $y0 > 0C= $x0 + $ww < $wD= $y0 + $hh < $h
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 400 | 0 | my $x0p = max($x0, 0); $x0 = min($x0, 0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 401 | 0 | my $y0p = max($y0, 0); $y0 = min($y0, 0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 402 | 0 | ▶ | image_internalop($image, 'Crop', x => $x0p, width => min($ww, $w - $x0p), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 403 | y => $y0p, height => min($hh, $h - $y0p)) or return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 404 | 0 | $w = min($ww + $x0, $w - $x0p); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 405 | 0 | $h = min($hh + $y0, $h - $y0p); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 406 | 0 | ▶ | Debug(" Trim/Clip to $w x $h @ $x0p, $y0p") if $LaTeXML::DEBUG{images}; } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 407 | # No direct `padding' operation in ImageMagick | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 408 | # BUT, trim & clip really shouldn't need to pad??? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 409 | # And besides, this composition seems to mangle the colormap (depending on background) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 410 | # my $nimage = image_read("xc:$background", size => "$ww x $hh") or return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 411 | # image_internalop($nimage, 'Composite', image => $image, compose => 'over', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 412 | # x => -$x0, y => -$y0) or return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 413 | # $notes .= " compose to $ww x $hh at $x0,$y0"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 414 | # $image = $nimage; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 415 | # ($w, $h) = ($ww, $hh); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 416 | } } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 417 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 418 | 0 | ▶ | if ($properties{transparent} && !$hasalpha) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$properties{"transparent"} and not $hasalpha
MC/DC0%0/2
$properties{"transparent"} and not $hasalpha
$properties{"transparent"}
not $hasalpha
Truth table0%0/3
A and not(B)
A= $properties{"transparent"}B= not $hasalpha
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 419 | 0 | ▶ | image_internalop($image, 'Transparent', $background) or return; } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 420 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 421 | 0 | ▶ | if (my $curr_ncolors = image_getvalue($image, 'colors')) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 422 | 0 | ▶ | if (my $req_ncolors = $properties{ncolors}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 423 | 0 | ▶ | $req_ncolors = int($orig_ncolors * $1 / 100) if $req_ncolors =~ /^([\d]*)\%$/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 424 | 0 | ▶ | if ($req_ncolors < $curr_ncolors) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 425 | 0 | ▶ | image_internalop($image, 'Quantize', colors => $req_ncolors) or return; } } } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 426 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 427 | 0 | ▶ | if (my $quality = $properties{quality}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 428 | 0 | ▶ | image_setvalue($image, quality => $properties{quality}) or return; } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 429 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 430 | 0 | ▶ | if ($properties{prescale} && ($upsample != 1)) { # Now downsample IF actually upsampled! | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$properties{"prescale"} and $upsample != 1
MC/DC0%0/2
$properties{"prescale"} and $upsample != 1
$properties{"prescale"}
$upsample != 1
Truth table0%0/3
A and B
A= $properties{"prescale"}B= $upsample != 1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 431 | 0 | ▶ | image_internalop($image, 'Scale', geometry => $w / $upsample . 'x' . $h / $upsample) or return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 432 | 0 | ($w, $h) = image_getvalue($image, 'width', 'height'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 433 | 0 | ▶ | Debug(" Downsampled to $w x $h") if $LaTeXML::DEBUG{images}; } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 434 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 435 | 0 | my ($watt, $hatt) = ($w / $zoomout, $h = $h / $zoomout); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 436 | 0 | ▶ | Debug("Transformed $source final size $w x $h, displayed as $watt x $hatt") if $LaTeXML::DEBUG{images}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 437 | 0 | return ($image, $watt, $hatt); } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 438 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 439 | # Wrap up ImageMagick's methods to give more useful & consistent error handling. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 440 | # These all return non-zero on success! | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 441 | # so, you generally want to do image_internalop(...) or return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 442 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 443 | # This reads a new image, setting the given properties BEFORE ingesting the image data. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 444 | 0 | ▶ | sub image_read { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
image_read: not called CC=6 SCAR=37.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 445 | 0 | my ($source, @args) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 446 | 0 | ▶ | if (!$source) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 447 | 0 | Error('imageprocessing', 'read', undef, "No image source given"); return; } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 448 | 0 | ▶ | return unless $source; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 449 | 0 | my $image = image_object(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 450 | # Just in case this is pdf, set this option; ImageMagick defaults to MediaBox (Wrong!!!) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 451 | 0 | ▶ | image_internalop($image, 'Set', option => 'pdf:use-cropbox=true') or return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 452 | 0 | ▶ | image_internalop($image, 'Set', @args) or return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 453 | 0 | ▶ | image_internalop($image, 'Read', $source) or return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 454 | 0 | return $image; } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 455 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 456 | 0 | ▶ | sub image_write { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
image_write: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 457 | 0 | my ($image, $destination) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 458 | 0 | ▶ | if (!$image) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 459 | 0 | Error('imageprocessing', 'write', undef, "No image object!"); return; } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 460 | 0 | ▶ | if (!$destination) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 461 | 0 | Error('imageprocessing', 'write', undef, "No image destination!"); return; } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 462 | # In the perverse case that we've ended up with a sequence of images; flatten them. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 463 | 0 | ▶ | if (@$image > 1) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 464 | 0 | my $fimage = $image->Flatten(); # Just in case we ended up with pieces!?!?!? | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 465 | 0 | ▶ | $image = $fimage if $fimage; } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 466 | 0 | return image_internalop($image, 'Write', filename => $destination); } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 467 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 468 | 0 | ▶ | sub image_getvalue { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
image_getvalue: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 469 | 0 | my ($image, @args) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 470 | 0 | ▶ | if (!$image) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 471 | 0 | Error('imageprocessing', 'getvalue', undef, "No image object!"); return; } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 472 | 0 | my @values = $image->Get(@args); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 473 | 0 | return @values; } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 474 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 475 | 0 | ▶ | sub image_setvalue { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
image_setvalue: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 476 | 0 | my ($image, @args) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 477 | 0 | ▶ | if (!$image) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 478 | 0 | Error('imageprocessing', 'setvalue', undef, "No image object!"); return; } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 479 | 0 | return image_internalop($image, 'Set', @args); } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 480 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 481 | # Apparently ignorable warnings from Image::Magick | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 482 | 1 | our %ignorable = map { $_ => 1; } ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 483 | 350, # profile 'icc' not permitted on grayscale PNG | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 484 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 485 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 486 | 0 | ▶ | sub image_internalop { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
image_internalop: not called CC=6 SCAR=37.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 487 | 0 | my ($image, $operation, @args) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 488 | 0 | ▶ | if (!$image) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 489 | 0 | Error('imageprocessing', 'internal', undef, "No image object!"); return; } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 490 | 0 | my $retval = $image->$operation(@args); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 491 | 0 | ▶ | return 1 unless $retval; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 492 | 0 | my $retcode = 999; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 493 | 0 | ▶ | if ($retval =~ /(\d+)/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 494 | 0 | $retcode = $1; } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 495 | 0 | ▶ | if ($retcode < 400) { # Warning | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 496 | Warn('imageprocessing', $operation, undef, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 497 | "Image processing operation $operation (" . join(', ', @args) . ") returned $retval") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 498 | 0 | ▶ | unless $ignorable{$retcode}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 499 | 0 | return 1; } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 500 | else { # Error | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 501 | 0 | Error('imageprocessing', $operation, undef, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 502 | "Image processing operation $operation (" . join(', ', @args) . ") returned $retval"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 503 | 0 | return 0; } } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 504 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 505 | #====================================================================== | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 506 | 1 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||