sm.getDataType() == raster.getSampleModel().getDataType()
? raster
: Raster.createWritableRaster(sm, null);
Attributes imgAttrs = metadata.getAttributes();
StoredValue sv = StoredValue.valueOf(imgAttrs);
LookupTableFactory lutParam = new LookupTableFactory(sv);
DicomImageReadParam dParam = param instanceof DicomImageReadParam
? (DicomImageReadParam) param
: new DicomImageReadParam();
Attributes psAttrs = dParam.getPresentationState();
if (psAttrs != null) {
lutParam.setModalityLUT(psAttrs);
lutParam.setVOI(
selectVOILUT(psAttrs,
imgAttrs.getString(Tag.SOPInstanceUID),
frameIndex+1),
0, 0, false);
lutParam.setPresentationLUT(psAttrs);
} else {
Attributes sharedFctGroups = imgAttrs.getNestedDataset(
Tag.SharedFunctionalGroupsSequence);
Attributes frameFctGroups = imgAttrs.getNestedDataset(
Tag.PerFrameFunctionalGroupsSequence, frameIndex);
lutParam.setModalityLUT(
selectFctGroup(imgAttrs, sharedFctGroups, frameFctGroups,
Tag.PixelValueTransformationSequence));
if (dParam.getWindowWidth() != 0) {
lutParam.setWindowCenter(dParam.getWindowCenter());
lutParam.setWindowWidth(dParam.getWindowWidth());
} else
lutParam.setVOI(
selectFctGroup(imgAttrs, sharedFctGroups, frameFctGroups,
Tag.FrameVOILUTSequence),
dParam.getWindowIndex(),
dParam.getVOILUTIndex(),
dParam.isPreferWindow());
if (dParam.isAutoWindowing())
lutParam.autoWindowing(imgAttrs, raster);
lutParam.setPresentationLUT(imgAttrs);
}
LookupTable lut = lutParam.createLUT(outBits);
lut.lookup(raster, destRaster);
return destRaster;
}