v1.0.0-rc.40
This commit is contained in:
@@ -12,62 +12,42 @@ JFJochReaderImage::JFJochReaderImage(const DataMessage &in_message,
|
||||
image(in_dataset->experiment.GetPixelsNum(), 0){
|
||||
ProcessInputImage(in_message.image);
|
||||
|
||||
message.image = CompressedImage{
|
||||
.data = reinterpret_cast<const uint8_t *>(image.data()),
|
||||
.size = image.size() * sizeof(int32_t),
|
||||
.xpixel = (size_t) in_dataset->experiment.GetXPixelsNum(),
|
||||
.ypixel = (size_t) in_dataset->experiment.GetYPixelsNum(),
|
||||
.pixel_depth_bytes = 4,
|
||||
.pixel_is_signed = true,
|
||||
.pixel_is_float = false,
|
||||
.algorithm = CompressionAlgorithm::NO_COMPRESSION,
|
||||
.channel = "default"
|
||||
};
|
||||
message.image = CompressedImage(image, in_dataset->experiment.GetXPixelsNum(),
|
||||
in_dataset->experiment.GetYPixelsNum());
|
||||
}
|
||||
|
||||
void JFJochReaderImage::ProcessInputImage(const CompressedImage &in_image) {
|
||||
size_t npixel = in_image.xpixel * in_image.ypixel;
|
||||
size_t npixel = in_image.GetWidth() * in_image.GetHeight();
|
||||
if (npixel == 0)
|
||||
throw JFJochException(JFJochExceptionCategory::InputParameterInvalid,
|
||||
"Image size cannot be zero");
|
||||
|
||||
std::vector<uint8_t> tmp;
|
||||
|
||||
const uint8_t *image_ptr;
|
||||
if (in_image.algorithm == CompressionAlgorithm::NO_COMPRESSION)
|
||||
image_ptr = in_image.data;
|
||||
else {
|
||||
tmp.resize(in_image.xpixel * in_image.ypixel * in_image.pixel_depth_bytes);
|
||||
const uint8_t *image_ptr = in_image.GetUncompressedPtr(tmp);
|
||||
|
||||
JFJochDecompressPtr(tmp.data(),
|
||||
in_image.algorithm,
|
||||
in_image.data,
|
||||
in_image.size,
|
||||
in_image.xpixel * in_image.ypixel,
|
||||
in_image.pixel_depth_bytes);
|
||||
image_ptr = tmp.data();
|
||||
}
|
||||
switch (in_image.GetMode()) {
|
||||
case CompressedImageMode::Int8:
|
||||
ProcessInputImage<int8_t>(image_ptr, npixel, INT8_MAX, INT8_MIN);
|
||||
break;
|
||||
case CompressedImageMode::Int16:
|
||||
ProcessInputImage<int16_t>(image_ptr, npixel, INT16_MAX, INT16_MIN);
|
||||
break;
|
||||
case CompressedImageMode::Int32:
|
||||
ProcessInputImage<int32_t>(image_ptr, npixel, INT32_MAX, INT32_MIN);
|
||||
break;
|
||||
case CompressedImageMode::Uint8:
|
||||
ProcessInputImage<uint8_t>(image_ptr, npixel, UINT8_MAX, INT64_MAX);
|
||||
break;
|
||||
case CompressedImageMode::Uint16:
|
||||
ProcessInputImage<uint16_t>(image_ptr, npixel, UINT16_MAX, INT64_MAX);
|
||||
|
||||
// For signed types there is no special value, only mask
|
||||
switch (in_image.pixel_depth_bytes) {
|
||||
case 1:
|
||||
if (in_image.pixel_is_signed)
|
||||
ProcessInputImage<int8_t>(image_ptr, npixel, INT8_MAX, INT8_MIN);
|
||||
else
|
||||
ProcessInputImage<uint8_t>(image_ptr, npixel, UINT8_MAX, INT64_MAX);
|
||||
break;
|
||||
case 2:
|
||||
if (in_image.pixel_is_signed)
|
||||
ProcessInputImage<int16_t>(image_ptr, npixel, INT16_MAX, INT16_MIN);
|
||||
else
|
||||
ProcessInputImage<uint16_t>(image_ptr, npixel, UINT16_MAX, INT64_MAX);
|
||||
break;
|
||||
case 4:
|
||||
if (in_image.pixel_is_signed)
|
||||
ProcessInputImage<int32_t>(image_ptr, npixel, INT32_MAX, INT32_MIN);
|
||||
else
|
||||
ProcessInputImage<uint32_t>(image_ptr, npixel, INT32_MAX, INT64_MAX);
|
||||
case CompressedImageMode::Uint32:
|
||||
ProcessInputImage<uint32_t>(image_ptr, npixel, INT32_MAX, INT64_MAX);
|
||||
break;
|
||||
default:
|
||||
throw JFJochException(JFJochExceptionCategory::InputParameterInvalid, "Floating point images not supported");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user