public static PresetWindowLevel buildPresetFromLutData(LookupTableCV voiLUTsData, DicomImageElement image,
TagReadable tagable, boolean pixelPadding, String explanation) {
if (voiLUTsData == null || explanation == null) {
return null;
}
Object inLut;
if (voiLUTsData.getDataType() == DataBuffer.TYPE_BYTE) {
inLut = voiLUTsData.getByteData(0);
} else if (voiLUTsData.getDataType() <= DataBuffer.TYPE_SHORT) {
inLut = voiLUTsData.getShortData(0);
} else {
return null;
}
int minValueLookup = voiLUTsData.getOffset();
int maxValueLookup = voiLUTsData.getOffset() + Array.getLength(inLut) - 1;
minValueLookup = Math.min(minValueLookup, maxValueLookup);
maxValueLookup = Math.max(minValueLookup, maxValueLookup);
int minAllocatedValue = image.getMinAllocatedValue(tagable, pixelPadding);
if (minValueLookup < minAllocatedValue) {
minValueLookup = minAllocatedValue;
}
int maxAllocatedValue = image.getMaxAllocatedValue(tagable, pixelPadding);
if (maxValueLookup > maxAllocatedValue) {
maxValueLookup = maxAllocatedValue;
}
double fullDynamicWidth = (double) maxValueLookup - minValueLookup;
double fullDynamicCenter = minValueLookup + fullDynamicWidth / 2f;
LutShape newLutShape = new LutShape(voiLUTsData, explanation);
return new PresetWindowLevel(newLutShape.toString(), fullDynamicWidth, fullDynamicCenter, newLutShape);
}