Skip to content

Commit

Permalink
bfsave: use the metadata endianness to create the byte array
Browse files Browse the repository at this point in the history
The existing code assumes the data are ordered using big-endian
as in the default minimal OME-XML metadata.
This adjusts the code to handle OME metadata specifying little-endian
ordering
  • Loading branch information
sbesson committed Dec 18, 2024
1 parent b8d3ae1 commit 5b8b31d
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions components/formats-bsd/matlab/bfsave.m
Original file line number Diff line number Diff line change
Expand Up @@ -109,17 +109,18 @@ function bfsave(varargin)
writer.setId(ip.Results.outputPath);

% Load conversion tools for saving planes
isLittleEndian = ~metadata.getPixelsBigEndian(0).booleanValue;
switch class(ip.Results.I)
case {'int8', 'uint8'}
getBytes = @(x) x(:);
case {'uint16','int16'}
getBytes = @(x) javaMethod('shortsToBytes', 'loci.common.DataTools', x(:), 0);
getBytes = @(x) javaMethod('shortsToBytes', 'loci.common.DataTools', x(:), isLittleEndian);
case {'uint32','int32'}
getBytes = @(x) javaMethod('intsToBytes', 'loci.common.DataTools', x(:), 0);
getBytes = @(x) javaMethod('intsToBytes', 'loci.common.DataTools', x(:), isLittleEndian);
case {'single'}
getBytes = @(x) javaMethod('floatsToBytes', 'loci.common.DataTools', x(:), 0);
getBytes = @(x) javaMethod('floatsToBytes', 'loci.common.DataTools', x(:), isLittleEndian);
case 'double'
getBytes = @(x) javaMethod('doublesToBytes', 'loci.common.DataTools', x(:), 0);
getBytes = @(x) javaMethod('doublesToBytes', 'loci.common.DataTools', x(:), isLittleEndian);
end

% Save planes to the writer
Expand Down

0 comments on commit 5b8b31d

Please sign in to comment.