Skip to content

Commit

Permalink
Merge pull request #4261 from sbesson/bfsave_endianness
Browse files Browse the repository at this point in the history
bfsave: use the metadata endianness to create the byte array
  • Loading branch information
melissalinkert authored Dec 20, 2024
2 parents 342b084 + 5b8b31d commit 2ffe82c
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 2ffe82c

Please sign in to comment.