Commit 26c8a6e3 authored by Alejandro Homs Puron's avatar Alejandro Homs Puron
Browse files

[IO] Use H5 type deduction machinery in writer

parent 819c629a
......@@ -23,6 +23,7 @@ namespace io
{
// clang-format off
template <typename T> struct deduct;
template <> struct deduct<bool> { static const hid_t type() { return H5T_NATIVE_HBOOL; } };
template <> struct deduct<unsigned char> { static const hid_t type() { return H5T_NATIVE_UINT8; } };
template <> struct deduct<signed char> { static const hid_t type() { return H5T_NATIVE_INT8; } };
template <> struct deduct<char> { static const hid_t type() { return H5T_NATIVE_INT8; } };
......
......@@ -63,47 +63,10 @@ namespace io
static const bool is_supported = false;
};
template <>
struct write_support_private<std::uint8_t, boost::gil::gray_t>
template <typename Channel>
struct write_support_private<Channel, boost::gil::gray_t> : deduct<Channel>
{
static const bool is_supported = true;
static const hid_t type() { return H5T_NATIVE_UINT8; }
};
template <>
struct write_support_private<std::int8_t, boost::gil::gray_t>
: write_support_private<std::uint8_t, boost::gil::gray_t>
{
};
template <>
struct write_support_private<std::uint16_t, boost::gil::gray_t>
{
static const bool is_supported = true;
static const hid_t type() { return H5T_NATIVE_UINT16; }
};
template <>
struct write_support_private<std::int16_t, boost::gil::gray_t>
: write_support_private<std::uint16_t, boost::gil::gray_t>
{
};
template <>
struct write_support_private<std::uint32_t, boost::gil::gray_t>
{
static const bool is_supported = true;
static const hid_t type() { return H5T_NATIVE_UINT32; }
};
template <>
struct write_support_private<std::int32_t, boost::gil::gray_t>
: write_support_private<std::uint32_t, boost::gil::gray_t>
{
};
template <>
struct write_support_private<float, boost::gil::gray_t>
{
static const bool is_supported = true;
static const hid_t type() { return H5T_NATIVE_FLOAT; }
};
template <typename View>
......@@ -154,34 +117,8 @@ namespace io
inline predef_datatype datatype(pixel_enum px)
{
hid_t res;
switch (px) {
case pixel_enum::gray8:
res = H5T_NATIVE_UINT8;
break;
case pixel_enum::gray8s:
res = H5T_NATIVE_INT8;
break;
case pixel_enum::gray16:
res = H5T_NATIVE_UINT16;
break;
case pixel_enum::gray16s:
res = H5T_NATIVE_INT16;
break;
case pixel_enum::gray32:
res = H5T_NATIVE_UINT32;
break;
case pixel_enum::gray32s:
res = H5T_NATIVE_INT32;
break;
case pixel_enum::gray32f:
res = H5T_NATIVE_FLOAT;
break;
default:
LIMA_THROW_EXCEPTION(lima::hdf5_error("Unsupported pixel type"));
}
return predef_datatype(res);
return std::visit([](auto p) { return predef_datatype::create<typename decltype(p)::type>(); },
typeof_pixel(px));
}
class writer
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment