From 5b8b31d3a5f59b866c634e7a4ad6e3b43a80e471 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Besson?= Date: Wed, 18 Dec 2024 09:13:19 +0000 Subject: [PATCH] bfsave: use the metadata endianness to create the byte array 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 --- components/formats-bsd/matlab/bfsave.m | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/components/formats-bsd/matlab/bfsave.m b/components/formats-bsd/matlab/bfsave.m index 7a9fd18344a..f7ce958bc2a 100644 --- a/components/formats-bsd/matlab/bfsave.m +++ b/components/formats-bsd/matlab/bfsave.m @@ -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