template<typename _Tpvec>
inline _Tpvec v256_combine_diagonal(const _Tpvec& a, const _Tpvec& b)
-{ return _Tpvec(_mm256_blend_epi32(a.val, b.val, 0b11110000)); }
+{ return _Tpvec(_mm256_blend_epi32(a.val, b.val, 0xf0)); }
inline v_float32x8 v256_combine_diagonal(const v_float32x8& a, const v_float32x8& b)
-{ return v256_blend<0b11110000>(a, b); }
+{ return v256_blend<0xf0>(a, b); }
inline v_float64x4 v256_combine_diagonal(const v_float64x4& a, const v_float64x4& b)
-{ return v256_blend<0b1100>(a, b); }
+{ return v256_blend<0xc>(a, b); }
template<typename _Tpvec>
inline _Tpvec v256_alignr_128(const _Tpvec& a, const _Tpvec& b)
{
_Tpvec ab0 = v256_unpacklo(a, b);
_Tpvec bc1 = v256_unpackhi(b, c);
- _Tpvec ca10 = v256_swap_halves(v256_blend<0b1010>(c, a));
+ _Tpvec ca10 = v256_swap_halves(v256_blend<0xa>(c, a));
v_store(ptr, v256_combine_diagonal(ab0, ca10));
v_store(ptr + _Tpvec::nlanes, v256_combine_diagonal(bc1, ab0));
v256_zip(a, b, ab0, ab1);
v256_zip(b, c, bc0, bc1);
- _Tpvec cazg = v256_blend<0b10101010>(c, a);
+ _Tpvec cazg = v256_blend<0xaa>(c, a);
_Tpvec abc0abc1(_mm256_unpacklo_epi64(ab0.val, cazg.val));
_Tpvec abc1abc2(_mm256_unpackhi_epi64(cazg.val, bc1.val));
- _Tpvec abc2abc0 = v256_reverse_64(v256_blend<0b11001100>(ab1, bc0));
+ _Tpvec abc2abc0 = v256_reverse_64(v256_blend<0xcc>(ab1, bc0));
_Tpvec abc0 = v256_combine_diagonal(abc0abc1, abc2abc0);
_Tpvec abc1 = v256_combine_diagonal(abc1abc2, abc0abc1);
v256_zip(a, b, ab0, ab1);
v256_zip(b, c, bc0, bc1);
- v_float32x8 cazg = v256_blend<0b10101010>(c, a);
+ v_float32x8 cazg = v256_blend<0xaa>(c, a);
v_float32x8 abc0abc1(_mm256_shuffle_ps(ab0.val, cazg.val, _MM_SHUFFLE(1, 0, 1, 0)));
v_float32x8 abc1abc2(_mm256_shuffle_ps(cazg.val, bc1.val, _MM_SHUFFLE(3, 2, 3, 2)));
_Tpvec abc2 = v256_alignr_128(abc02, abc20);
_Tpvec abc0 = v256_combine_diagonal(abc02, abc20);
- a = v256_blend<0b10010010>(abc0, abc1);
- a = v256_blend<0b01000100>(a, abc2);
+ a = v256_blend<0x92>(abc0, abc1);
+ a = v256_blend<0x44>(a, abc2);
- b = v256_blend<0b00100100>(abc0, abc1);
- b = v256_blend<0b10011001>(b, abc2);
+ b = v256_blend<0x24>(abc0, abc1);
+ b = v256_blend<0x99>(b, abc2);
- c = v256_blend<0b01001001>(abc0, abc1);
- c = v256_blend<0b00100010>(c, abc2);
+ c = v256_blend<0x49>(abc0, abc1);
+ c = v256_blend<0x22>(c, abc2);
a = v256_shuffle<_MM_SHUFFLE(1, 2, 3, 0)>(a);
b = v256_shuffle<_MM_SHUFFLE(2, 3, 0, 1)>(b);
v_uint32x8 bc0 = v_reinterpret_as_u32(v256_unpacklo(b, c));
v_uint32x8 bc1 = v_reinterpret_as_u32(v256_unpackhi(b, c));
- v_uint32x8 cazg = v_reinterpret_as_u32(v256_blend<0b10101010>(c, a));
+ v_uint32x8 cazg = v_reinterpret_as_u32(v256_blend<0xaa>(c, a));
cazg = v256_shuffle<_MM_SHUFFLE(2, 1, 0, 3)>(cazg);
- v_uint32x8 ac1ab1 = v256_blend<0b10101010>(ab1, bc1);
+ v_uint32x8 ac1ab1 = v256_blend<0xaa>(ab1, bc1);
ac1ab1 = v256_shuffle<_MM_SHUFFLE(2, 1, 0, 3)>(ac1ab1);
- v_uint32x8 abc001 = v256_blend<0b10101010>(ab0, cazg);
- v_uint32x8 cabc0 = v256_blend<0b10101010>(cazg, bc0);
+ v_uint32x8 abc001 = v256_blend<0xaa>(ab0, cazg);
+ v_uint32x8 cabc0 = v256_blend<0xaa>(cazg, bc0);
v_uint32x8 cabc1 = v256_unpacklo(cabc0, ac1ab1);
v_uint32x8 bcab0 = v256_unpackhi(cabc1, abc001);
// Utility function for safe integer conversions
template <typename D, typename S>
-inline D safe_int_cast(S val)
+inline D safe_int_cast(S val, const char * msg = 0)
{
typedef std::numeric_limits<S> st;
typedef std::numeric_limits<D> dt;
const bool in_range_l = (double)val >= (double)dt::min();
if (!in_range_r || !in_range_l)
{
- CV_Error_(cv::Error::StsOutOfRange, ("Can not convert integer values (%s -> %s), value 0x%llx is out of range", typeid(S).name(), typeid(D).name(), val));
+ if (!msg)
+ CV_Error_(Error::StsOutOfRange, ("Can not convert integer values (%s -> %s), value 0x%llx is out of range", typeid(S).name(), typeid(D).name(), val));
+ else
+ CV_Error(Error::StsOutOfRange, msg);
}
return static_cast<D>(val);
}
VideoInputStream();
VideoInputStream(const String& filename);
~VideoInputStream();
- VideoInputStream& read(char*, uint64_t);
+ VideoInputStream& read(char*, uint32_t);
VideoInputStream& seekg(uint64_t);
uint64_t tellg();
bool isOpened() const;
}
}
-VideoInputStream& VideoInputStream::read(char* buf, uint64_t count)
+VideoInputStream& VideoInputStream::read(char* buf, uint32_t count)
{
if(isOpened())
{
- input.read(buf, safe_int_cast<std::streamsize>(count));
+ input.read(buf, safe_int_cast<std::streamsize>(count, "Failed to read AVI file: requested chunk size is too large"));
m_is_valid = (input.gcount() == (std::streamsize)count);
}
VideoInputStream& VideoInputStream::seekg(uint64_t pos)
{
input.clear();
- input.seekg(safe_int_cast<std::streamoff>(pos));
+ input.seekg(safe_int_cast<std::streamoff>(pos, "Failed to seek in AVI file: position is out of range"));
m_is_valid = !input.eof();
return *this;
}
}
size_t BitStream::getPos() const {
- return safe_int_cast<size_t>(m_current - m_start) + m_pos;
+ return safe_int_cast<size_t>(m_current - m_start, "Failed to determine AVI bufer position: value is out of range") + m_pos;
}
void BitStream::putByte(int val)
{
if( pos >= m_pos )
{
- ptrdiff_t delta = safe_int_cast<ptrdiff_t>(pos - m_pos);
+ ptrdiff_t delta = safe_int_cast<ptrdiff_t>(pos - m_pos, "Failed to seek in AVI buffer: value is out of range");
CV_Assert( delta < m_current - m_start );
m_start[delta] = (uchar)val;
m_start[delta+1] = (uchar)(val >> 8);
else
{
std::streamoff fpos = output.tellp();
- output.seekp(safe_int_cast<std::streamoff>(pos));
+ output.seekp(safe_int_cast<std::streamoff>(pos, "Failed to seek in AVI file: value is out of range"));
uchar buf[] = { (uchar)val, (uchar)(val >> 8), (uchar)(val >> 16), (uchar)(val >> 24) };
output.write((char *)buf, 4);
output.seekp(fpos);
size_t pospos = AVIChunkSizeIndex.back();
AVIChunkSizeIndex.pop_back();
CV_Assert(currpos >= pospos);
- uint32_t chunksz = safe_int_cast<uint32_t>(currpos - pospos);
+ uint32_t chunksz = safe_int_cast<uint32_t>(currpos - pospos, "Failed to write AVI file: chunk size is out of bounds");
strm->patchInt(chunksz, pospos);
}
}
void AVIWriteContainer::finishWriteAVI()
{
- uint32_t nframes = safe_int_cast<uint32_t>(frameOffset.size());
+ uint32_t nframes = safe_int_cast<uint32_t>(frameOffset.size(), "Failed to write AVI file: number of frames is too large");
// Record frames numbers to AVI Header
while (!frameNumIndexes.empty())
{