24 "yarp.carrier.portmonitor.depthimage_compression_zfp",
34 shouldCompress = (options.
find(
"sender_side").
asBool());
36 decompressed =
nullptr;
57 decompressed =
nullptr;
76 yCError(ZFPMONITOR,
"Expected type ImageOf<PixelFloat> in sender side, but got wrong data type!");
83 yCError(ZFPMONITOR,
"Expected type Bottle in receiver side, but got wrong data type!");
102 yCError(ZFPMONITOR,
"Failed to compress, exiting...");
109 Value v(compressed, sizeCompressed);
120 int sizeCompressed=compressedbt->
get(2).
asInt32();
122 decompress((
float*)compressedbt->
get(3).
asBlob(), decompressed, sizeCompressed, width, height,1e-3);
125 yCError(ZFPMONITOR,
"Failed to decompress, exiting...");
128 imageOut.
resize(width,height);
129 memcpy(imageOut.
getRawImage(),decompressed,width*height*4);
138 if(newSize>sizeToAllocate){
139 sizeToAllocate=newSize;
141 array=(
float*) malloc(sizeToAllocate);
147 if(newSize>sizeToAllocateB){
148 sizeToAllocateB=newSize;
150 array=(
void*) malloc(sizeToAllocateB);
164 type = zfp_type_float;
165 field = zfp_field_2d(array, type, nx, ny);
168 zfp = zfp_stream_open(
nullptr);
173 zfp_stream_set_accuracy(zfp, tolerance);
176 bufsize = zfp_stream_maximum_size(zfp, field);
181 stream = stream_open(
buffer, bufsize);
182 zfp_stream_set_bit_stream(zfp, stream);
183 zfp_stream_rewind(zfp);
187 zfpsize = zfp_compress(zfp, field);
189 yCError(ZFPMONITOR,
"compression failed");
194 memcpy(compressed,(
float*) stream_data(zfp->stream),zfpsize);
197 zfp_field_free(field);
198 zfp_stream_close(zfp);
199 stream_close(stream);
212 type = zfp_type_float;
213 resizeF(decompressed,nx*ny*
sizeof(
float));
214 field = zfp_field_2d(decompressed, type, nx, ny);
217 zfp = zfp_stream_open(
nullptr);
222 zfp_stream_set_accuracy(zfp, tolerance);
225 bufsize = zfp_stream_maximum_size(zfp, field);
227 memcpy(
buffer,array,zfpsize);
230 stream = stream_open(
buffer, zfpsize);
231 zfp_stream_set_bit_stream(zfp, stream);
232 zfp_stream_rewind(zfp);
235 if (!zfp_decompress(zfp, field)) {
236 yCError(ZFPMONITOR,
"decompression failed");
241 zfp_field_free(field);
242 zfp_stream_close(zfp);
243 stream_close(stream);
bool setparam(const yarp::os::Property ¶ms) override
This will be called when the portmonitor carrier parameters are set via YARP admin port.
int decompress(float *array, float *&decompressed, int zfpsize, int nx, int ny, float tolerance)
int compress(float *array, float *&compressed, int &zfpsize, int nx, int ny, float tolerance)
bool getparam(yarp::os::Property ¶ms) override
This will be called when the portmonitor carrier parameters are requested via YARP admin port.
void resizeV(void *&array, int newSize)
void resizeF(float *&array, int newSize)
bool accept(yarp::os::Things &thing) override
This will be called when the data reach the portmonitor object.
void destroy() override
This will be called when the portmonitor object destroyes.
yarp::os::Things & update(yarp::os::Things &thing) override
After data get accpeted in the accept() callback, an instance of that is given to the update function...
bool create(const yarp::os::Property &options) override
This will be called when the dll is properly loaded by the portmonitor carrier.
A simple collection of objects that can be described and transmitted in a portable way.
void add(const Value &value)
Add a Value to the bottle, at the end of the list.
Value & get(size_type index) const
Reads a Value v from a certain part of the list.
void clear()
Empties the bottle of any objects it contains.
void addInt32(std::int32_t x)
Places a 32-bit integer in the bottle, at the end of the list.
static LogCallback printCallback()
Get current print callback.
static LogType minimumPrintLevel()
Get current minimum print level.
A class for storing options and configuration information.
Value & find(const std::string &key) const override
Gets a value corresponding to a given keyword.
Base class for generic things.
void setPortWriter(yarp::os::PortWriter *writer)
Set the reference to a PortWriter object.
A single value (typically within a Bottle).
virtual bool asBool() const
Get boolean value.
virtual std::int32_t asInt32() const
Get 32-bit integer value.
virtual const char * asBlob() const
Get binary data value.
size_t width() const
Gets width of image in pixels.
unsigned char * getRawImage() const
Access to the internal image buffer.
void resize(size_t imgWidth, size_t imgHeight)
Reallocate an image to be of a desired size, throwing away its current contents.
size_t height() const
Gets height of image in pixels.
#define yCError(component,...)
#define YARP_LOG_COMPONENT(name,...)
An interface to the operating system, including Port based communication.