-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
59 changed files
with
4,889 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
api/src/main/java/org/jmisb/api/klv/st0602/ActiveLinesPerFrame.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package org.jmisb.api.klv.st0602; | ||
|
||
import org.jmisb.api.common.KlvParseException; | ||
import org.jmisb.core.klv.PrimitiveConverter; | ||
|
||
/** | ||
* Active Lines per Frame. | ||
* | ||
* <p>Total number of active lines (rows) in a frame of an image matrix. | ||
*/ | ||
public class ActiveLinesPerFrame implements IAnnotationMetadataValue { | ||
private int number; | ||
|
||
/** | ||
* Create from value. | ||
* | ||
* @param lines the number of lines per frame (in the range [0, 65535]). | ||
* @throws KlvParseException if {@code lines} is not in the valid range | ||
*/ | ||
public ActiveLinesPerFrame(int lines) throws KlvParseException { | ||
if ((lines < 0) || (lines > 65535)) { | ||
throw new KlvParseException("Active Lines Per Frame must be in the range [0, 65535]"); | ||
} | ||
number = lines; | ||
} | ||
|
||
/** | ||
* Create from encoded bytes. | ||
* | ||
* @param bytes Byte array of length 2 | ||
* @throws KlvParseException if the length is not valid | ||
*/ | ||
public ActiveLinesPerFrame(byte[] bytes) throws KlvParseException { | ||
if (bytes.length != 2) { | ||
throw new KlvParseException( | ||
"Active Lines Per Frame encoding is a two-byte unsigned int"); | ||
} | ||
number = PrimitiveConverter.toUint16(bytes); | ||
} | ||
|
||
/** | ||
* Get the number of lines per frame. | ||
* | ||
* @return The number of lines (rows) as an unsigned integer | ||
*/ | ||
public int getNumber() { | ||
return number; | ||
} | ||
|
||
@Override | ||
public byte[] getBytes() { | ||
return PrimitiveConverter.uint16ToBytes(number); | ||
} | ||
|
||
@Override | ||
public String getDisplayableValue() { | ||
return String.format("%d", number); | ||
} | ||
|
||
@Override | ||
public String getDisplayName() { | ||
return "Active Lines Per Frame"; | ||
} | ||
} |
124 changes: 124 additions & 0 deletions
124
api/src/main/java/org/jmisb/api/klv/st0602/ActiveLinesPerFrameMessage.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
package org.jmisb.api.klv.st0602; | ||
|
||
import java.util.Arrays; | ||
import java.util.Collections; | ||
import java.util.Set; | ||
import org.jmisb.api.common.KlvParseException; | ||
import org.jmisb.api.klv.ArrayBuilder; | ||
import org.jmisb.api.klv.IKlvKey; | ||
import org.jmisb.api.klv.IKlvValue; | ||
import org.jmisb.api.klv.IMisbMessage; | ||
import org.jmisb.api.klv.KlvConstants; | ||
import org.jmisb.api.klv.UniversalLabel; | ||
|
||
/** | ||
* Active Lines Per Frame prefix message. | ||
* | ||
* <p>This message conceptually wraps an {@code ActiveLinesPerFrame} instance so it can appear as a | ||
* top level entity in a KLV stream. | ||
*/ | ||
public class ActiveLinesPerFrameMessage implements IMisbMessage { | ||
|
||
private final ActiveLinesPerFrame activeLinesPerFrame; | ||
private static final int UNIVERSAL_LABEL_BYTE_OFFSET = 0; | ||
private static final int UNIVERSAL_LABEL_LEN = | ||
KlvConstants.AnnotationActiveLinesPerFrameUl.getBytes().length; | ||
private static final int LEN_BYTE_OFFSET = UNIVERSAL_LABEL_BYTE_OFFSET + UNIVERSAL_LABEL_LEN; | ||
private static final int LEN_REQUIRED_LEN = 1; | ||
private static final int VALUE_BYTE_OFFSET = LEN_BYTE_OFFSET + LEN_REQUIRED_LEN; | ||
private static final int VALUE_REQUIRED_LEN = 2; | ||
private static final int TOTAL_REQUIRED_LEN = | ||
UNIVERSAL_LABEL_LEN + LEN_REQUIRED_LEN + VALUE_REQUIRED_LEN; | ||
|
||
/** | ||
* Construct an {@code ActiveLinesPerFrameMessage} by wrapping an {@link ActiveLinesPerFrame} | ||
* instance. | ||
* | ||
* @param linesPerFrame the wrapped object | ||
*/ | ||
public ActiveLinesPerFrameMessage(ActiveLinesPerFrame linesPerFrame) { | ||
this.activeLinesPerFrame = linesPerFrame; | ||
} | ||
|
||
/** | ||
* Construct an {@code ActiveLinesPerFrameMessage} from a serialised representation. | ||
* | ||
* <p>The serialised representation is the universal label, the length, and the two byte value. | ||
* | ||
* @param bytes byte array containing the serialised representation. | ||
* @throws KlvParseException if the label or length are not as expected. | ||
*/ | ||
public ActiveLinesPerFrameMessage(byte[] bytes) throws KlvParseException { | ||
verifyLength(bytes); | ||
verifyUniversalLabel(bytes); | ||
activeLinesPerFrame = | ||
new ActiveLinesPerFrame( | ||
Arrays.copyOfRange( | ||
bytes, VALUE_BYTE_OFFSET, VALUE_BYTE_OFFSET + VALUE_REQUIRED_LEN)); | ||
} | ||
|
||
private void verifyUniversalLabel(byte[] bytes) throws KlvParseException { | ||
if (!Arrays.equals( | ||
bytes, | ||
0, | ||
UNIVERSAL_LABEL_LEN, | ||
KlvConstants.AnnotationActiveLinesPerFrameUl.getBytes(), | ||
0, | ||
UNIVERSAL_LABEL_LEN)) { | ||
throw new KlvParseException( | ||
"Unexpected Annotation Active Lines per Frame Universal Label passed in"); | ||
} | ||
} | ||
|
||
private void verifyLength(byte[] bytes) throws KlvParseException { | ||
if (bytes.length != TOTAL_REQUIRED_LEN) { | ||
throw new KlvParseException( | ||
"Annotation Active Lines per Frame Universal Label must have length 19"); | ||
} | ||
if (bytes[LEN_BYTE_OFFSET] != VALUE_REQUIRED_LEN) { | ||
throw new KlvParseException( | ||
"Annotation Active Lines per Frame Universal Label must be specified as length 2"); | ||
} | ||
} | ||
|
||
@Override | ||
public UniversalLabel getUniversalLabel() { | ||
return KlvConstants.AnnotationActiveLinesPerFrameUl; | ||
} | ||
|
||
@Override | ||
public byte[] frameMessage(boolean isNested) { | ||
if (isNested) { | ||
throw new IllegalArgumentException("ST 0602 active lines per frame cannot be nested"); | ||
} | ||
byte[] linesBytes = activeLinesPerFrame.getBytes(); | ||
ArrayBuilder arrayBuilder = new ArrayBuilder(); | ||
arrayBuilder.append(KlvConstants.AnnotationActiveLinesPerFrameUl); | ||
arrayBuilder.appendAsBerLength(linesBytes.length); | ||
arrayBuilder.append(linesBytes); | ||
return arrayBuilder.toBytes(); | ||
} | ||
|
||
@Override | ||
public String displayHeader() { | ||
return "ST 0602, Active Lines per Frame"; | ||
} | ||
|
||
@Override | ||
public IKlvValue getField(IKlvKey tag) { | ||
if (tag.equals(AnnotationMetadataKey.ActiveLinesPerFrame)) { | ||
return this.activeLinesPerFrame; | ||
} else { | ||
return null; | ||
} | ||
} | ||
|
||
@Override | ||
public Set<? extends IKlvKey> getIdentifiers() { | ||
if (activeLinesPerFrame != null) { | ||
return Collections.singleton(AnnotationMetadataKey.ActiveLinesPerFrame); | ||
} else { | ||
return Collections.emptySet(); | ||
} | ||
} | ||
} |
64 changes: 64 additions & 0 deletions
64
api/src/main/java/org/jmisb/api/klv/st0602/ActiveSamplesPerLine.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package org.jmisb.api.klv.st0602; | ||
|
||
import org.jmisb.api.common.KlvParseException; | ||
import org.jmisb.core.klv.PrimitiveConverter; | ||
|
||
/** | ||
* Active Samples per Line. | ||
* | ||
* <p>Total number of active samples (columns) in a line of an image matrix. | ||
*/ | ||
public class ActiveSamplesPerLine implements IAnnotationMetadataValue { | ||
private int number; | ||
|
||
/** | ||
* Create from value. | ||
* | ||
* @param samples the number of samples per line (in the range [0, 65535]). | ||
* @throws KlvParseException if {@code samples} is not in the valid range | ||
*/ | ||
public ActiveSamplesPerLine(int samples) throws KlvParseException { | ||
if ((samples < 0) || (samples > 65535)) { | ||
throw new KlvParseException("Active Samples Per Line must be in the range [0, 65535]"); | ||
} | ||
number = samples; | ||
} | ||
|
||
/** | ||
* Create from encoded bytes. | ||
* | ||
* @param bytes Byte array of length 2 | ||
* @throws KlvParseException if the length is not valid | ||
*/ | ||
public ActiveSamplesPerLine(byte[] bytes) throws KlvParseException { | ||
if (bytes.length != 2) { | ||
throw new KlvParseException( | ||
"Active Samples Per Line encoding is a two-byte unsigned int"); | ||
} | ||
number = PrimitiveConverter.toUint16(bytes); | ||
} | ||
|
||
/** | ||
* Get the number of samples per line. | ||
* | ||
* @return The number of samples (columns) as an unsigned integer | ||
*/ | ||
public int getNumber() { | ||
return number; | ||
} | ||
|
||
@Override | ||
public byte[] getBytes() { | ||
return PrimitiveConverter.uint16ToBytes(number); | ||
} | ||
|
||
@Override | ||
public String getDisplayableValue() { | ||
return String.format("%d", number); | ||
} | ||
|
||
@Override | ||
public String getDisplayName() { | ||
return "Active Samples Per Line"; | ||
} | ||
} |
Oops, something went wrong.