27 "yarp.carrier.portmonitor.zfp",
37 shouldCompress = (options.
find(
"sender_side").
asBool());
39 decompressed =
nullptr;
60 decompressed =
nullptr;
79 yCError(ZFPMONITOR,
"Expected type ImageOf<PixelFloat> in sender side, but got wrong data type!");
86 yCError(ZFPMONITOR,
"Expected type Bottle in receiver side, but got wrong data type!");
105 yCError(ZFPMONITOR,
"Failed to compress, exiting...");
109 data.addInt32(img->
width());
110 data.addInt32(img->
height());
111 data.addInt32(sizeCompressed);
112 Value v(compressed, sizeCompressed);
114 th.setPortWriter(&data);
123 int sizeCompressed=compressedbt->
get(2).
asInt32();
125 decompress((
float*)compressedbt->
get(3).
asBlob(), decompressed, sizeCompressed, width, height,1e-3);
128 yCError(ZFPMONITOR,
"Failed to decompress, exiting...");
131 imageOut.resize(width,height);
132 memcpy(imageOut.getRawImage(),decompressed,width*height*4);
133 th.setPortWriter(&imageOut);
141 if(newSize>sizeToAllocate){
142 sizeToAllocate=newSize;
144 array=(
float*) malloc(sizeToAllocate);
150 if(newSize>sizeToAllocateB){
151 sizeToAllocateB=newSize;
153 array=(
void*) malloc(sizeToAllocateB);
167 type = zfp_type_float;
168 field = zfp_field_2d(array, type, nx, ny);
171 zfp = zfp_stream_open(
nullptr);
176 zfp_stream_set_accuracy(zfp, tolerance);
179 bufsize = zfp_stream_maximum_size(zfp, field);
184 stream = stream_open(
buffer, bufsize);
185 zfp_stream_set_bit_stream(zfp, stream);
186 zfp_stream_rewind(zfp);
190 zfpsize = zfp_compress(zfp, field);
192 yCError(ZFPMONITOR,
"compression failed");
196 resizeF(compressed,zfpsize);
197 memcpy(compressed,(
float*) stream_data(zfp->stream),zfpsize);
200 zfp_field_free(field);
201 zfp_stream_close(zfp);
202 stream_close(stream);
215 type = zfp_type_float;
216 resizeF(decompressed,nx*ny*
sizeof(
float));
217 field = zfp_field_2d(decompressed, type, nx, ny);
220 zfp = zfp_stream_open(
nullptr);
225 zfp_stream_set_accuracy(zfp, tolerance);
228 bufsize = zfp_stream_maximum_size(zfp, field);
230 memcpy(
buffer,array,zfpsize);
233 stream = stream_open(
buffer, zfpsize);
234 zfp_stream_set_bit_stream(zfp, stream);
235 zfp_stream_rewind(zfp);
238 if (!zfp_decompress(zfp, field)) {
239 yCError(ZFPMONITOR,
"decompression failed");
244 zfp_field_free(field);
245 zfp_stream_close(zfp);
246 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.
Value & get(size_type index) const
Reads a Value v from a certain part 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.
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.
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.