Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions ij/gui/Roi.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public class Roi extends Object implements Cloneable, java.io.Serializable, Iter
public static final int FERET_ARRAYSIZE = 16; // Size of array with Feret values
public static final int FERET_ARRAY_POINTOFFSET = 8; // Where point coordinates start in Feret array
private static final String NAMES_KEY = "group.names";
private static final int MAX_ROI_GROUP = 65535; // limit to uint16 max value

static final int NO_MODS=0, ADD_TO_ROI=1, SUBTRACT_FROM_ROI=2; // modification states

Expand Down Expand Up @@ -1807,7 +1808,7 @@ public static int getDefaultGroup() {
* @see #getGroupColor
*/
public static void setDefaultGroup(int group) {
if (group<0 || group>255)
if (group<0 || group>MAX_ROI_GROUP)
throw new IllegalArgumentException("Invalid group: "+group);
defaultGroup = group;
groupColor = getGroupColor(group);
Expand All @@ -1820,7 +1821,7 @@ public int getGroup() {

/** Returns the group name associtated with the specified group. */
public static String getGroupName(int groupNumber) {
if (groupNumber<1 || groupNumber>255)
if (groupNumber<1 || groupNumber>MAX_ROI_GROUP)
return null;
if (groupNames==null && groupNamesString==null)
return null;
Expand All @@ -1835,7 +1836,7 @@ public static String getGroupName(int groupNumber) {
}

public static synchronized void setGroupName(int groupNumber, String name) {
if (groupNumber<1 || groupNumber>255)
if (groupNumber<1 || groupNumber>MAX_ROI_GROUP)
return;
if (groupNamesString==null && groupNames==null)
groupNames = new String[groupNumber];
Expand Down Expand Up @@ -1884,7 +1885,7 @@ public static void setGroupNames(String names) {

/** Sets the group of this Roi, and updates stroke color accordingly. */
public void setGroup(int group) {
if (group<0 || group>255)
if (group<0 || group>MAX_ROI_GROUP)
throw new IllegalArgumentException("Invalid group: "+group);
if (group>0)
setStrokeColor(getGroupColor(group));
Expand Down
7 changes: 6 additions & 1 deletion ij/io/RoiDecoder.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ public class RoiDecoder {
public static final int ROI_PROPS_OFFSET = 40;
public static final int ROI_PROPS_LENGTH = 44;
public static final int COUNTERS_OFFSET = 48;
public static final int GROUP_EXTENDED = 52; //short (uint16) for groups > 255

// subtypes
public static final int TEXT = 1;
Expand Down Expand Up @@ -207,7 +208,11 @@ public Roi getRoi() throws IOException {
overlayFontSize = getShort(hdr2Offset+OVERLAY_FONT_SIZE);
imageOpacity = getByte(hdr2Offset+IMAGE_OPACITY);
imageSize = getInt(hdr2Offset+IMAGE_SIZE);
group = getByte(hdr2Offset+GROUP);
int groupByte = getByte(hdr2Offset+GROUP);
if (version>=229 && groupByte==0 && hdr2Offset+GROUP_EXTENDED+2<=size)
group = getUnsignedShort(hdr2Offset+GROUP_EXTENDED);
else
group = groupByte;
}

if (name!=null && name.endsWith(".roi"))
Expand Down
10 changes: 8 additions & 2 deletions ij/io/RoiEncoder.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
public class RoiEncoder {
static final int HEADER_SIZE = 64;
static final int HEADER2_SIZE = 64;
static final int VERSION = 228; // v1.52t (roi groups, scale stroke width)
static final int VERSION = 229; // v1.52u (extended roi groups via uint16)
private String path;
private OutputStream f;
private final int polygon=0, rect=1, oval=2, line=3, freeline=4, polyline=5, noRoi=6, freehand=7,
Expand Down Expand Up @@ -423,7 +423,13 @@ void putHeader2(Roi roi, int hdr2Offset) {
putProps(roi, hdr2Offset);
if (countersSize>0)
putPointCounters(roi, hdr2Offset);
putByte(hdr2Offset+RoiDecoder.GROUP, roi.getGroup());
int group = roi.getGroup();
if (group > 255) {
putByte(hdr2Offset+RoiDecoder.GROUP, 0); // marker for extended group
putShort(hdr2Offset+RoiDecoder.GROUP_EXTENDED, group);
} else {
putByte(hdr2Offset+RoiDecoder.GROUP, group);
}
}

void putName(Roi roi, int hdr2Offset) {
Expand Down