Commit f59a16c9 authored by Alejandro Homs Puron's avatar Alejandro Homs Puron
Browse files

Add support for 8-bit stream data

parent 0bec8857
Pipeline #21176 failed with stages
in 1 minute and 14 seconds
...@@ -45,19 +45,28 @@ private: ...@@ -45,19 +45,28 @@ private:
Stream& m_stream; Stream& m_stream;
}; };
void _expand(void *src,Data& dst) template <typename S, typename D>
void _expand(void *src, void *dst, int nbItems)
{ {
int nbItems = dst.size() / dst.depth(); S *src_data = (S *) src;
unsigned short* src_data = (unsigned short*)src; D *dst_data = (D *) dst;
unsigned int* dst_data = (unsigned int*)dst.data(); while(nbItems) {
while(nbItems) *dst_data = unsigned(*src_data);
{ ++dst_data,++src_data,--nbItems;
*dst_data = unsigned(*src_data); }
++dst_data,++src_data,--nbItems;
}
dst.type = Data::UINT32;
} }
typedef unsigned char aligned16_uint8 __attribute__ ((aligned (16)));
typedef unsigned short aligned16_uint16 __attribute__ ((aligned (16)));
typedef unsigned int aligned16_uint32 __attribute__ ((aligned (16)));
inline void _expand_8_to_16(void *src, void *dst, int nbItems)
{ _expand<aligned16_uint8, aligned16_uint16>(src, dst, nbItems); }
inline void _expand_8_to_32(void *src, void *dst, int nbItems)
{ _expand<aligned16_uint8, aligned16_uint32>(src, dst, nbItems); }
inline void _expand_16_to_32(void *src, void *dst, int nbItems)
{ _expand<aligned16_uint16, aligned16_uint32>(src, dst, nbItems); }
Data _DecompressTask::process(Data& out) Data _DecompressTask::process(Data& out)
{ {
void *lima_buffer = out.data(); void *lima_buffer = out.data();
...@@ -67,48 +76,50 @@ Data _DecompressTask::process(Data& out) ...@@ -67,48 +76,50 @@ Data _DecompressTask::process(Data& out)
img_data.getMsgDataNSize(msg_data, msg_size); img_data.getMsgDataNSize(msg_data, msg_size);
const int& depth = img_data.depth; const int& depth = img_data.depth;
const Camera::CompressionType& type = img_data.comp_type; const Camera::CompressionType& type = img_data.comp_type;
bool expand_16_to_32bit = ((out.depth() == 4) && (depth == 2)); bool expand = (out.depth() != depth);
int size = out.size() / (expand_16_to_32bit ? 2 : 1); int nb_pixels = out.size() / out.depth();
int size = nb_pixels * depth;
bool decompress = (type != Camera::NoCompression); bool decompress = (type != Camera::NoCompression);
HeapPtr<void> aux_buffer; HeapPtr<void> aux_buffer;
if(expand_16_to_32bit && decompress) { if(expand && decompress) {
void *ptr; void *ptr;
if(posix_memalign(&ptr,16,size)) if(posix_memalign(&ptr,16,size))
throw ProcessException("Can't allocate temporary memory"); throw ProcessException("Can't allocate temporary memory");
aux_buffer.reset(ptr); aux_buffer.reset(ptr);
} }
void *decompress_out = aux_buffer ? aux_buffer.get() : lima_buffer; void *decompress_out = aux_buffer ? aux_buffer.get() : lima_buffer;
int return_code = 0; int return_code = 0;
if (type == Camera::LZ4) { if(type == Camera::LZ4) {
return_code = LZ4_decompress_fast((const char*)msg_data, return_code = LZ4_decompress_fast((const char*)msg_data,
(char*)decompress_out,size); (char*)decompress_out,size);
} else if (type == Camera::BSLZ4) { } else if(type == Camera::BSLZ4) {
struct bslz4_data { struct bslz4_data {
uint64_t data_size; uint64_t data_size_be;
uint32_t block_size; uint32_t block_size_be;
char data[1]; char data[1];
} *d = (bslz4_data *) msg_data; } *d = (bslz4_data *) msg_data;
size_t data_size = be64toh(d->data_size); if(be64toh(d->data_size_be) != size)
if (data_size != size)
throw ProcessException("Data size mismatch"); throw ProcessException("Data size mismatch");
size_t nb_elements = data_size / depth; size_t block_size = be32toh(d->block_size_be) / depth;
size_t block_size = be32toh(d->block_size) / depth; return_code = bshuf_decompress_lz4(d->data, decompress_out, nb_pixels,
return_code = bshuf_decompress_lz4(d->data, decompress_out, nb_elements,
depth, block_size); depth, block_size);
} }
if(return_code < 0) if(return_code < 0) {
{ char ErrorBuff[1024];
char ErrorBuff[1024]; snprintf(ErrorBuff,sizeof(ErrorBuff),
snprintf(ErrorBuff,sizeof(ErrorBuff), "_DecompressTask: decompression failed, (error code: %d) (data size %d)",
"_DecompressTask: decompression failed, (error code: %d) (data size %d)", return_code,out.size());
return_code,out.size()); throw ProcessException(ErrorBuff);
throw ProcessException(ErrorBuff); }
}
if(expand_16_to_32bit) { if(expand) {
void *expand_src = decompress ? decompress_out : msg_data; void *expand_src = decompress ? decompress_out : msg_data;
_expand(expand_src,out); if(out.depth() == 2)
_expand_8_to_16(expand_src, lima_buffer, nb_pixels);
else if(depth == 1)
_expand_8_to_32(expand_src, lima_buffer, nb_pixels);
else
_expand_16_to_32(expand_src, lima_buffer, nb_pixels);
} else if(!decompress) } else if(!decompress)
memcpy(lima_buffer, msg_data, size); memcpy(lima_buffer, msg_data, size);
......
...@@ -599,6 +599,10 @@ bool Stream::_read_zmq_messages(void *stream_socket) ...@@ -599,6 +599,10 @@ bool Stream::_read_zmq_messages(void *stream_socket)
image_type = Bpp16S; image_type = Bpp16S;
else if(dtype == "uint16") else if(dtype == "uint16")
image_type = Bpp16; image_type = Bpp16;
else if(dtype == "int8")
image_type = Bpp8S;
else if(dtype == "uint8")
image_type = Bpp8;
else else
THROW_HW_ERROR(Error) << "Invalid " << DEB_VAR1(dtype); THROW_HW_ERROR(Error) << "Invalid " << DEB_VAR1(dtype);
anImageDim.setImageType(image_type); anImageDim.setImageType(image_type);
......
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