Commit 0dd38668 authored by Stefan Westerfeld's avatar Stefan Westerfeld

Support 32 bit conversions in RawConverter.

Signed-off-by: Stefan Westerfeld's avatarStefan Westerfeld <stefan@space.twc.de>
parent 0afd30ad
...@@ -69,28 +69,36 @@ RawConverter::create (const RawFormat& raw_format, Error& error) ...@@ -69,28 +69,36 @@ RawConverter::create (const RawFormat& raw_format, Error& error)
{ {
case 16: return create_with_bits<16> (raw_format, error); case 16: return create_with_bits<16> (raw_format, error);
case 24: return create_with_bits<24> (raw_format, error); case 24: return create_with_bits<24> (raw_format, error);
case 32: return create_with_bits<32> (raw_format, error);
default: error = Error ("unsupported bit depth"); default: error = Error ("unsupported bit depth");
return nullptr; return nullptr;
} }
} }
template<int BIT_DEPTH, RawFormat::Endian ENDIAN> template<int BIT_DEPTH, RawFormat::Endian ENDIAN>
constexpr std::array<int, 3> constexpr std::array<int, 4>
make_endian_shift () make_endian_shift ()
{ {
if (BIT_DEPTH == 16) if (BIT_DEPTH == 16)
{ {
if (ENDIAN == RawFormat::Endian::LITTLE) if (ENDIAN == RawFormat::Endian::LITTLE)
return { 16, 24, -1 }; return { 16, 24, -1, -1 };
else else
return { 24, 16, -1 }; return { 24, 16, -1, -1 };
} }
if (BIT_DEPTH == 24) if (BIT_DEPTH == 24)
{ {
if (ENDIAN == RawFormat::Endian::LITTLE) if (ENDIAN == RawFormat::Endian::LITTLE)
return { 8, 16, 24 }; return { 8, 16, 24, -1 };
else else
return { 24, 16, 8 }; return { 24, 16, 8, -1 };
}
if (BIT_DEPTH == 32)
{
if (ENDIAN == RawFormat::Endian::LITTLE)
return { 0, 8, 16, 24 };
else
return { 24, 16, 8, 0 };
} }
} }
...@@ -120,6 +128,8 @@ RawConverterImpl<BIT_DEPTH, ENDIAN, ENCODING>::to_raw (const vector<float>& samp ...@@ -120,6 +128,8 @@ RawConverterImpl<BIT_DEPTH, ENDIAN, ENCODING>::to_raw (const vector<float>& samp
ptr[1] = sample >> eshift[1]; ptr[1] = sample >> eshift[1];
if (eshift[2] >= 0) if (eshift[2] >= 0)
ptr[2] = sample >> eshift[2]; ptr[2] = sample >> eshift[2];
if (eshift[3] >= 0)
ptr[3] = sample >> eshift[3];
ptr += sample_width; ptr += sample_width;
} }
...@@ -146,6 +156,8 @@ RawConverterImpl<BIT_DEPTH, ENDIAN, ENCODING>::from_raw (const vector<unsigned c ...@@ -146,6 +156,8 @@ RawConverterImpl<BIT_DEPTH, ENDIAN, ENCODING>::from_raw (const vector<unsigned c
s32 += ptr[1] << eshift[1]; s32 += ptr[1] << eshift[1];
if (eshift[2] >= 0) if (eshift[2] >= 0)
s32 += ptr[2] << eshift[2]; s32 += ptr[2] << eshift[2];
if (eshift[3] >= 0)
s32 += ptr[3] << eshift[3];
samples[i] = s32 * norm; samples[i] = s32 * norm;
ptr += sample_width; ptr += sample_width;
......
Markdown is supported
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