Skip to content

Commit

Permalink
(3.40) For Tiff compression, use AdobeDeflate codec (if available) in…
Browse files Browse the repository at this point in the history
…stead of Deflate (issue #379); another attempt to fix issue #378 (remove unnecessary quotes from ghostscript cmdfile)
  • Loading branch information
altmany committed Jul 5, 2023
1 parent aff397d commit 47ab1f9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
2 changes: 2 additions & 0 deletions append_pdfs.m
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ function append_pdfs(varargin)
% 29/03/20: Accept a cell-array of input files (issue #299); accept both "strings", 'chars'
% 25/01/22: Improved handling of missing input files & folder with non-ASCII chars (issue #349)
% 07/06/23: Fixed (hopefully) unterminated quote run-time error (issues #367, #378); fixed handling of pathnames with non-ASCII chars (issue #349); display ghostscript command upon run-time invocation error
% 06/07/23: Another attempt to fix issue #378 (remove unnecessary quotes from ghostscript cmdfile)
%}

if nargin < 2, return; end % sanity check
Expand Down Expand Up @@ -154,6 +155,7 @@ function prepareCmdFile(cmdfile, output, varargin)
str = ['-q -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -dPDFSETTINGS=/prepress ' ...
'-sOutputFile="' output '" -f ' sprintf('"%s" ',varargin{:})];
str = regexprep(str, ' "?" ',' '); % remove empty strings (issues #367,#378)
str = regexprep(str, '"([^ ]*)"', '$1'); % remove unnecessary quotes
str = strtrim(str); % trim extra spaces

fh = fopen(cmdfile, 'w');
Expand Down
18 changes: 16 additions & 2 deletions export_fig.m
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,7 @@
% 23/04/23: (3.37) Fixed run-time error with old Matlab releases (issue #374); -notify console message about exported image now displays black (STDOUT) not red (STDERR)
% 15/05/23: (3.38) Fixed endless recursion when using export_fig in Live Scripts (issue #375); don't warn about exportgraphics/copygraphics alternatives in deployed mode
% 30/05/23: (3.39) Fixed exported bgcolor of uifigures or figures in Live Scripts (issue #377)
% 06/07/23: (3.40) For Tiff compression, use AdobeDeflate codec (if available) instead of Deflate (issue #379)
%}

if nargout
Expand Down Expand Up @@ -423,7 +424,7 @@
[fig, options] = parse_args(nargout, fig, argNames, varargin{:});

% Check for newer version and exportgraphics/copygraphics compatibility
currentVersion = 3.39;
currentVersion = 3.40;
if options.version % export_fig's version requested - return it and bail out
imageData = currentVersion;
return
Expand Down Expand Up @@ -659,6 +660,8 @@

% Main processing
try
oldWarn = warning;

% Export bitmap formats first
if isbitmap(options)
if abs(options.bb_padding) > 1
Expand Down Expand Up @@ -918,7 +921,13 @@
t.setTag('ImageLength', size(img,1));
t.setTag('ImageWidth', size(img,2));
t.setTag('Photometric', Tiff.Photometric.RGB);
t.setTag('Compression', Tiff.Compression.Deflate);
try %issue #379 use Tiff.Compression.AdobeDeflate by default
compressionMode = Tiff.Compression.AdobeDeflate;
catch
warning off imageio:tiffmexutils:libtiffWarning %issue #379
compressionMode = Tiff.Compression.Deflate;
end
t.setTag('Compression', compressionMode);
t.setTag('PlanarConfiguration', Tiff.PlanarConfiguration.Chunky);
t.setTag('ExtraSamples', Tiff.ExtraSamples.AssociatedAlpha);
t.setTag('ResolutionUnit', Tiff.ResolutionUnit.Inch);
Expand Down Expand Up @@ -1528,7 +1537,12 @@
if ~nargout
clear imageData alpha
end

% Revert warnings state
warning(oldWarn);
catch err
% Revert warnings state
warning(oldWarn);
% Revert figure properties in case they were changed
try set(fig,'Units',oldFigUnits, 'Position',pos, 'Color',tcol_orig); catch, end
% Display possible workarounds before the error message
Expand Down

0 comments on commit 47ab1f9

Please sign in to comment.