Skip to content

Commit a0e3746

Browse files
authored
Merge pull request #3224 from ControlSystemStudio/pva_pvxs_image
PVA Image: Decode image from PVXS 'group' demo
2 parents 33e8410 + cd42c6d commit a0e3746

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

core/pv-pva/src/main/java/org/phoebus/pv/pva/ImageDecoder.java

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2019-2022 Oak Ridge National Laboratory.
2+
* Copyright (c) 2019-2025 Oak Ridge National Laboratory.
33
* All rights reserved. This program and the accompanying materials
44
* are made available under the terms of the Eclipse Public License v1.0
55
* which accompanies this distribution, and is available at
@@ -19,13 +19,13 @@
1919
import org.epics.pva.data.PVAInt;
2020
import org.epics.pva.data.PVAIntArray;
2121
import org.epics.pva.data.PVALongArray;
22+
import org.epics.pva.data.PVANumber;
2223
import org.epics.pva.data.PVAShortArray;
2324
import org.epics.pva.data.PVAString;
2425
import org.epics.pva.data.PVAStructure;
2526
import org.epics.pva.data.PVAStructureArray;
2627
import org.epics.pva.data.PVAUnion;
2728
import org.epics.pva.data.PVAny;
28-
import org.epics.pvdata.pv.PVInt;
2929
import org.epics.util.array.ArrayByte;
3030
import org.epics.util.array.ArrayDouble;
3131
import org.epics.util.array.ArrayFloat;
@@ -104,14 +104,14 @@ public static VType decode(final PVAStructure struct) throws Exception
104104
offsets = new int[n_dims];
105105
reversed = new boolean[n_dims];
106106
for (int i = 0; i < n_dims; ++i)
107-
{
107+
{ // 'size' is mandatory, 'offset' and 'reverse' are optional
108108
final PVAStructure d = dim.get()[i];
109109
PVAInt el = d.get("size");
110110
dimensions[i] = el.get();
111111
el = d.get("offset");
112-
offsets[i] = el.get();
112+
offsets[i] = el == null ? 0 : el.get();
113113
final PVABool b = d.get("reverse");
114-
reversed[i] = b.get();
114+
reversed[i] = b == null ? false : b.get();
115115
}
116116
}
117117

@@ -127,9 +127,9 @@ public static VType decode(final PVAStructure struct) throws Exception
127127
{
128128
final PVAny color_mode_field = attribute.get("value");
129129
final PVAData cm = color_mode_field.get();
130-
if (cm instanceof PVInt)
130+
if (cm instanceof PVANumber n)
131131
{
132-
colorMode = ((PVInt) cm).get();
132+
colorMode = n.getNumber().intValue();
133133
break;
134134
}
135135
// else: log warning, or throw exception?
@@ -192,8 +192,16 @@ else if (colorMode <= 4 && colorMode >= 2 && dimensions.length != 3)
192192
}
193193

194194
// Fetch pixel data
195-
final PVAUnion value_field = struct.get("value");
196-
PVAData value = value_field.get();
195+
// NTNDArray is defined with 'union value',
196+
// but PVXS 'group' demo generates 'any value'
197+
final PVAData value_field = struct.get("value");
198+
PVAData value;
199+
if (value_field instanceof PVAUnion vf)
200+
value = vf.get();
201+
else if (value_field instanceof PVAny vf)
202+
value = vf.get();
203+
else
204+
throw new Exception("NDArray expected with value of type 'union' or 'any', got '" + value_field.getType() + "'");
197205

198206
// Value might be compressed, which means that a PVAByteArray
199207
// needs to be de-compressed and then converted into the

0 commit comments

Comments
 (0)