52 printf(
"There is a problem reading an image\n");
53 printf(
"incoming: width %d, height %d, code %d, quantum %d, size %d\n",
57 printf(
"my space: width %d, height %d, code %d, quantum %d, size %d\n",
61 bool ok = connection.
expectBlock((
char *)mem, allocatedBytes);
62 return (!connection.
isError() && ok);
90 void _alloc_extern (
const void *buf);
95 void _make_independent();
96 bool _set_ipl_header(
int x,
int y,
int pixel_type,
int quantum,
98 void _free_ipl_header();
99 void _alloc_complete(
int x,
int y,
int pixel_type,
int quantum,
101 void _free_complete();
105 int _pad_bytes (
int linesize,
int align)
const;
121 extern_type_quantum = -1;
128 void resize(
int x,
int y,
int pixel_type,
129 int quantum,
bool topIsLow);
131 void _alloc_complete_extern(
const void *buf,
int x,
int y,
int pixel_type,
132 int quantum,
bool topIsLow);
138 int quantum,
bool topIsLow) {
139 int need_recreation = 1;
145 if (need_recreation) {
147 DBGPF1 printf(
"HIT recreation for %ld %ld: %d %d %d\n", (
long int)
this, (
long int) pImage, x, y, pixel_type);
148 _alloc_complete (x, y, pixel_type, quantum, topIsLow);
150 extern_type_id = pixel_type;
151 extern_type_quantum = quantum;
166 iplAllocateImageFP(pImage, 0, 0);
168 iplAllocateImage (pImage, 0, 0);
179 if (pImage !=
nullptr)
180 if (pImage->imageData !=
nullptr)
181 iplDeallocateImage (pImage);
184 pImage->imageData = (
char*)buf;
193 DBGPF1 printf(
"alloc_data1\n"), fflush(stdout);
198 char **ptr =
new char *[pImage->height];
204 yAssert(pImage->imageData !=
nullptr);
206 int height = pImage->height;
208 char * DataArea = pImage->imageData;
210 for (
int r = 0; r < height; r++)
215 Data[height-r-1] = DataArea;
217 DataArea += pImage->widthStep;
219 DBGPF1 printf(
"alloc_data4\n");
224 if (pImage !=
nullptr)
225 if (pImage->imageData !=
nullptr)
229 iplDeallocateImage (pImage);
245 pImage->imageData =
nullptr;
278 _set_ipl_header(x, y, pixel_type, quantum, topIsLow);
326 {-2, iplPixelTypeMono16},
333 if (pImage !=
nullptr) {
334 iplDeallocateImage(pImage);
340 printf (
"*** Trying to allocate an invalid pixel type image\n");
343 if (pixelCode2iplParams.find(pixel_type) == pixelCode2iplParams.end()) {
355 pImage = iplCreateImageHeader(param.
nChannels, 0, param.
depth, const_cast<char*>(param.
colorModel), const_cast<char*>(param.
channelSeq),
IPL_DATA_ORDER_PIXEL, origin, quantum, x, y,
nullptr,
nullptr,
nullptr,
nullptr);
357 type_id = pixel_type;
358 this->quantum = quantum;
359 this->topIsLow = topIsLow;
368 this->quantum = quantum;
369 this->topIsLow = topIsLow;
373 _set_ipl_header(x, y, pixel_type, quantum, topIsLow);
424 imgWidth = imgHeight = 0;
425 imgPixelSize = imgRowSize = 0;
453 if (getRawImage()!=
nullptr) {
454 memset(getRawImage(),0,getRawImageSize());
460 yAssert(imgWidth>=0 && imgHeight>=0);
462 int code = getPixelCode();
464 if (code!=imgPixelCode) {
471 if (imgQuantum!=((
ImageStorage*)implementation)->extern_type_quantum) {
475 if (imgWidth!=width()||imgHeight!=height()) {
480 ((
ImageStorage*)implementation)->resize(imgWidth,imgHeight,
493 setPixelCode(-imgPixelSize);
498 this->imgPixelCode = imgPixelCode;
502 imgPixelSize = -imgPixelCode;
510 this->imgQuantum = imgQuantum;
517 if (impl->
pImage!=
nullptr) {
525 imgWidth = imgHeight = 0;
533 if (impl->
pImage!=
nullptr) {
542 if (impl->
pImage!=
nullptr) {
562 if (str==
"rgb"||str==
"RGB"||
563 str==
"bgr"||str==
"BGR"||
564 str==
"gray"||str==
"GRAY"||
565 str==
"graygray"||str==
"GRAYGRAY") {
567 if (str==
"rgb"||str==
"RGB") {
569 }
else if (str==
"bgr"||str==
"BGR") {
571 }
else if (str==
"gray"||str==
"GRAY"||
572 str==
"graygray"||str==
"GRAYGRAY") {
575 printf(
"specific IPL RGB order (%s) is not yet supported\n",
577 printf(
"Try RGB, BGR, or \n");
578 printf(
"Or fix code at %s line %d\n",__FILE__,__LINE__);
588 switch (color_code) {
600 switch (color_code) {
606 fprintf(stderr,
"No translation currently available for this pixel type\n");
611 switch (color_code) {
621 switch (color_code) {
633 fprintf(stderr,
"IPL pixel type / depth combination is not yet supported\n");
634 fprintf(stderr,
"Please email a YARP developer to complain, quoting this:\n");
635 fprintf(stderr,
" %s:%d\n", __FILE__, __LINE__);
638 if (getPixelCode()!=code && getPixelCode()!=-1) {
639 printf(
"your specific IPL format (%s depth %d -> %s) does not match your YARP format (%s)\n",
642 Vocab::decode(code).c_str(),
643 Vocab::decode(getPixelCode()).c_str());
644 printf(
"Making a copy instead of just wrapping...\n");
651 setQuantum(p->
align);
666 bool ok = connection.
expectBlock((
char*)&header,
sizeof(header));
667 if (!ok)
return false;
670 if (header.width == 0 || header.height == 0)
676 setPixelCode(header.id);
678 int q = getQuantum();
681 setQuantum(header.quantum);
684 if (q!=header.quantum) {
685 if ((header.depth*header.width)%header.quantum==0 &&
686 (header.depth*header.width)%q==0) {
692 if (getPixelCode() == header.id && q == header.quantum && imgPixelSize == header.depth)
781 connection.
appendBlock((
char*)&header,
sizeof(header));
782 unsigned char *mem = getRawImage();
783 if (header.width!=0&&header.height!=0) {
867 return copy(img,w,h);
875 return copy(img,w,h);
886 float di = ((float)h)/nh;
887 float dj = ((float)w)/nw;
889 for (
int i=0; i<nh; i++)
891 int i0 = (int)(di*i);
892 for (
int j=0; j<nw; j++)
894 int j0 = (int)(dj*j);
Floating point RGB pixel type.
int height
image height in pixels
char channelSeq[4]
ignored by OpenCV
virtual void appendExternalBlock(const char *data, size_t len)=0
Send a block of data to the network connection, without making a copy.
unsigned char * getRawImage() const
Access to the internal image buffer.
int align
Alignment of image rows (4 or 8).
bool copy(const Image &alt)
Copy operator.
Packed HSV (hue/saturation/value pixel type.
void zero()
Set all pixels to 0.
const pixelTypeIplParams iplPixelTypeMono
Floating point HSV pixel type.
ImageStorage(Image &owner)
#define YARP_FIXME_NOTIMPLEMENTED(what)
virtual ~Image()
Destructor.
virtual void appendBlock(const char *data, size_t len)=0
Send a block of data to the network connection.
This is a base class for objects that can be both read from and be written to the YARP network...
bool topIsLowIndex() const
int width() const
Gets width of image in pixels.
void wrapIplImage(void *iplImage)
Act as a wrapper around an IPL/OpenCV image.
virtual bool read(yarp::os::ConnectionReader &connection) override
Read image from a connection.
YARP_END_PACK typedef float PixelFloat
Floating point pixel type.
const pixelTypeIplParams iplPixelTypeMono16
char * imageData
pointer to aligned image data
A string with almost the same api as std::string.
unsigned char PixelMono
Monochrome pixel type.
virtual bool convertTextMode()=0
Reads in a standard description in text mode, and converts it to a standard description in binary...
Image()
Default constructor.
void setPixelSize(int imgPixelSize)
void resize(int imgWidth, int imgHeight)
Reallocate an image to be of a desired size, throwing away its current contents.
Signed, packed RGB pixel type.
void setPixelCode(int imgPixelCode)
Image class with user control of representation details.
void exit(int exit_code)
Portable wrapper for the exit() function.
Base class for storing images.
void copyPixels(const unsigned char *src, int id1, unsigned char *dest, int id2, int w, int h, int imageSize, int quantum1, int quantum2, bool topIsLow1, bool topIsLow2)
An interface for writing to a network connection.
bool readFromConnection(Image &dest, ImageNetworkHeader &header, ConnectionReader &connection)
This helper function groups code to avoid duplication.
yarp::os::NetUint16 PixelMono16
16-bit monochrome pixel type.
const std::map< int, pixelTypeIplParams > pixelCode2iplParams
unsigned char * getPixelAddress(int x, int y) const
Get address of a pixel in memory.
int getRawImageSize() const
Access to the internal buffer size information (this is how much memory has been allocated for the im...
Packed RGB pixel type, with pixels stored in reverse order.
int nChannels
Most of OpenCV functions support 1,2,3 or 4 channels.
int width
image width in pixels
bool isBayer8(int v)
Basic implementations of debayering functions.
void setExternal(const void *data, int imgWidth, int imgHeight)
Use this to wrap an external image.
virtual bool write(yarp::os::ConnectionWriter &connection) override
Write image to a connection.
void * getIplImage()
Returns IPL/OpenCV view of image, if possible.
An interface for reading from a network connection.
int getQuantum() const
The size of a row is constrained to be a multiple of the "quantum".
int depth
pixel depth in bits: IPL_DEPTH_8U, IPL_DEPTH_8S, IPL_DEPTH_16S, IPL_DEPTH_32S, IPL_DEPTH_32F and IPL_...
void _alloc_extern(const void *buf)
char colorModel[4]
ignored by OpenCV
int imageSize
image data size in bytes (==image->height*image->widthStep in case of interleaved data) ...
#define IPL_DATA_ORDER_PIXEL
YARP_END_PACK typedef char PixelMonoSigned
Signed byte pixel type.
#define IPL_BORDER_CONSTANT
int widthStep
size of aligned image row in bytes
yarp::os::NetInt32 PixelInt
32-bit integer pixel type.
const char * c_str() const
Accesses the character sequence stored in this object.
void setQuantum(int imgQuantum)
bool _set_ipl_header(int x, int y, int pixel_type, int quantum, bool topIsLow)
RandScalar * implementation(void *t)
bool deBayer_GRBG8_TO_BGR(yarp::sig::Image &source, yarp::sig::Image &dest, int pixelSize)
virtual bool convertTextMode()=0
Converts a standard description in binary into a textual description, if the connection is in text-mo...
virtual int getPixelSize() const
Gets pixel size in memory in bytes.
void _alloc_complete_extern(const void *buf, int x, int y, int pixel_type, int quantum, bool topIsLow)
An interface to the operating system, including Port based communication.
int PAD_BYTES(int len, int pad)
computes the padding of YARP images.
void setPixelCode(int imgPixelCode)
bool deBayer_GRBG8_TO_RGB(yarp::sig::Image &source, yarp::sig::Image &dest, int pixelSize)
static const std::map< YarpVocabPixelTypesEnum, unsigned int > pixelCode2Size
const Image & operator=(const Image &alt)
Assignment operator.
int _pad_bytes(int linesize, int align) const
virtual bool expectBlock(const char *data, size_t len)=0
Read a block of data from the network connection.
int height() const
Gets height of image in pixels.
void setQuantum(int imgQuantum)
void _alloc_complete(int x, int y, int pixel_type, int quantum, bool topIsLow)
memcpy(dstImage->imageData, srcImage->imageData, srcImage->imageSize)
virtual int getPixelCode() const
Gets pixel type identifier.
void resize(int x, int y, int pixel_type, int quantum, bool topIsLow)