From 49079c35625db23eb3bad60401a9721f7caabc6a Mon Sep 17 00:00:00 2001 From: David Miguel Susano Pinto Date: Wed, 13 Dec 2023 13:04:28 +0000 Subject: [PATCH] matlab/bfGetPlane.m: avoid use of makeDataArray2D when Octave (ome/bio-formats-octave-docker#29) Octave does not autobox multi-dimensional arrays (Matlab does) so we can't use makeDataArray2D. Instead, use makeDataArray to get a 1D array and reshape it. This commit partially reverts 3aa468e9 (see ome/bioformats#3301) for Octave only, so the data copy is back but for Octave only. --- components/formats-bsd/matlab/bfGetPlane.m | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/components/formats-bsd/matlab/bfGetPlane.m b/components/formats-bsd/matlab/bfGetPlane.m index 7903b298900..ced40280423 100644 --- a/components/formats-bsd/matlab/bfGetPlane.m +++ b/components/formats-bsd/matlab/bfGetPlane.m @@ -82,9 +82,20 @@ ip.Results.iPlane - 1, ip.Results.x - 1, ip.Results.y - 1, ... ip.Results.width, ip.Results.height); -% Convert byte array to MATLAB image -I = javaMethod('makeDataArray2D', 'loci.common.DataTools', plane, ... - bpp, fp, little, ip.Results.height); +% Convert byte array into the appropriate primitive type array which +% Octave and Matlab then autobox into their own array type. +if is_octave() + % Octave will not autobox multi-dimensional arrays, so use + % makeDataArray (returns 1D vector) instead of makeDataArray2D + % See https://github.com/ome/bio-formats-octave-docker/issues/29 + I = javaMethod('makeDataArray', 'loci.common.DataTools', plane, ... + bpp, fp, little); + I = reshape(I, [ip.Results.width ip.Results.height]).'; +else + I = javaMethod('makeDataArray2D', 'loci.common.DataTools', plane, ... + bpp, fp, little, ip.Results.height); +end + if ~sgn % Java does not have explicitly unsigned data types; % hence, we must inform MATLAB when the data is unsigned