Skip to content

Commit

Permalink
Other stuff removed and tested
Browse files Browse the repository at this point in the history
  • Loading branch information
randaz81 committed Oct 16, 2024
1 parent 5da2c83 commit 2ee7d1a
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 129 deletions.
74 changes: 31 additions & 43 deletions src/libYARP_sig/src/yarp/sig/Image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ inline bool readFromConnection(Image &dest, ImageNetworkHeader &header, Connecti

class ImageStorage {
public:
IplImage* pImage;
MiniIplImage* pImage;
char **Data; // this is not IPL. it's char to maintain IPL compatibility
int extern_type_id;
size_t extern_type_quantum;
Expand Down Expand Up @@ -119,11 +119,8 @@ class ImageStorage {
_free_complete();
}

void resize(size_t x, size_t y, int pixel_type,
size_t quantum, bool topIsLow);

void _alloc_complete_extern(const void *buf, size_t x, size_t y, int pixel_type,
size_t quantum, bool topIsLow);
void resize(size_t x, size_t y, int pixel_type, size_t quantum, bool topIsLow);
void _alloc_complete_extern(const void *buf, size_t x, size_t y, int pixel_type, size_t quantum, bool topIsLow);
};


Expand Down Expand Up @@ -164,11 +161,7 @@ void ImageStorage::_alloc_extern (const void *buf)
}
}

//iplAllocateImage (pImage, 0, 0);
pImage->imageData = const_cast<char*>(reinterpret_cast<const char*>(buf));
// probably need to do more for real IPL

//iplSetBorderMode (pImage, IPL_BORDER_CONSTANT, IPL_SIDE_ALL, 0);
}

// allocates the Data pointer.
Expand Down Expand Up @@ -228,7 +221,7 @@ void ImageStorage::_free_complete()

if (pImage != nullptr)
{
iplDeallocate(pImage, IPL_IMAGE_HEADER);
iplDeallocateHeader(pImage);
}
pImage = nullptr;
}
Expand All @@ -247,40 +240,35 @@ struct pixelTypeIplParams
{
int nChannels;
int depth;
const char* colorModel;
const char* channelSeq;
};

const pixelTypeIplParams iplPixelTypeMono{1, IPL_DEPTH_8U, "GRAY", "GRAY"};
const pixelTypeIplParams iplPixelTypeMono16{1, IPL_DEPTH_16U, "GRAY", "GRAY"};

const std::map<int, pixelTypeIplParams> pixelCode2iplParams = {
{VOCAB_PIXEL_MONO, iplPixelTypeMono},
{VOCAB_PIXEL_ENCODING_BAYER_GRBG8, iplPixelTypeMono},
{VOCAB_PIXEL_ENCODING_BAYER_BGGR8, iplPixelTypeMono},
{VOCAB_PIXEL_ENCODING_BAYER_GBRG8, iplPixelTypeMono},
{VOCAB_PIXEL_ENCODING_BAYER_RGGB8, iplPixelTypeMono},
{VOCAB_PIXEL_YUV_420, iplPixelTypeMono}, // {1, 12, "GRAY", "GRAY"}},
{VOCAB_PIXEL_YUV_444, iplPixelTypeMono}, // {1, 24, "GRAY", "GRAY"}},
{VOCAB_PIXEL_YUV_422, iplPixelTypeMono16},
{VOCAB_PIXEL_YUV_411, iplPixelTypeMono}, // {1, 12, "GRAY", "GRAY"}},
{VOCAB_PIXEL_MONO16, iplPixelTypeMono16},
{VOCAB_PIXEL_ENCODING_BAYER_GRBG16, iplPixelTypeMono16},
{VOCAB_PIXEL_ENCODING_BAYER_BGGR16, iplPixelTypeMono16},
{VOCAB_PIXEL_ENCODING_BAYER_GBRG16, iplPixelTypeMono16},
{VOCAB_PIXEL_ENCODING_BAYER_RGGB16, iplPixelTypeMono16},
{VOCAB_PIXEL_RGB, {3, IPL_DEPTH_8U, "RGB", "RGB" }},
{VOCAB_PIXEL_RGBA, {4, IPL_DEPTH_8U, "RGBA", "RGBA"}},
{VOCAB_PIXEL_BGRA, {4, IPL_DEPTH_8U, "BGRA", "BGRA"}},
{VOCAB_PIXEL_INT, {1, IPL_DEPTH_32S, "GRAY", "GRAY"}},
{VOCAB_PIXEL_HSV, {3, IPL_DEPTH_8U, "HSV", "HSV" }},
{VOCAB_PIXEL_BGR, {3, IPL_DEPTH_8U, "RGB", "BGR" }},
{VOCAB_PIXEL_MONO_SIGNED, {1, IPL_DEPTH_8S, "GRAY", "GRAY"}},
{VOCAB_PIXEL_RGB_INT, {3, IPL_DEPTH_32S, "RGB", "RGB" }},
{VOCAB_PIXEL_MONO_FLOAT, {1, IPL_DEPTH_32F, "GRAY", "GRAY"}},
{VOCAB_PIXEL_RGB_FLOAT, {3, IPL_DEPTH_32F, "RGB", "RGB" }},
{-2, iplPixelTypeMono16},
{-4, {1, IPL_DEPTH_32S, "GRAY", "GRAY"}}
{VOCAB_PIXEL_MONO, {1, IPL_DEPTH_8U}},
{VOCAB_PIXEL_ENCODING_BAYER_GRBG8, {1, IPL_DEPTH_8U}},
{VOCAB_PIXEL_ENCODING_BAYER_BGGR8, {1, IPL_DEPTH_8U}},
{VOCAB_PIXEL_ENCODING_BAYER_GBRG8, {1, IPL_DEPTH_8U}},
{VOCAB_PIXEL_ENCODING_BAYER_RGGB8, {1, IPL_DEPTH_8U}},
{VOCAB_PIXEL_YUV_420, {1, IPL_DEPTH_8U}},
{VOCAB_PIXEL_YUV_444, {1, IPL_DEPTH_8U}},
{VOCAB_PIXEL_YUV_422, {1, IPL_DEPTH_16U}},
{VOCAB_PIXEL_YUV_411, {1, IPL_DEPTH_8U}},
{VOCAB_PIXEL_MONO16, {1, IPL_DEPTH_16U}},
{VOCAB_PIXEL_ENCODING_BAYER_GRBG16, {1, IPL_DEPTH_16U}},
{VOCAB_PIXEL_ENCODING_BAYER_BGGR16, {1, IPL_DEPTH_16U}},
{VOCAB_PIXEL_ENCODING_BAYER_GBRG16, {1, IPL_DEPTH_16U}},
{VOCAB_PIXEL_ENCODING_BAYER_RGGB16, {1, IPL_DEPTH_16U}},
{VOCAB_PIXEL_RGB, {3, IPL_DEPTH_8U,}},
{VOCAB_PIXEL_RGBA, {4, IPL_DEPTH_8U,}},
{VOCAB_PIXEL_BGRA, {4, IPL_DEPTH_8U,}},
{VOCAB_PIXEL_INT, {1, IPL_DEPTH_32S}},
{VOCAB_PIXEL_HSV, {3, IPL_DEPTH_8U,}},
{VOCAB_PIXEL_BGR, {3, IPL_DEPTH_8U,}},
{VOCAB_PIXEL_MONO_SIGNED, {1, IPL_DEPTH_8S,}},
{VOCAB_PIXEL_RGB_INT, {3, IPL_DEPTH_32S}},
{VOCAB_PIXEL_MONO_FLOAT, {1, IPL_DEPTH_32F}},
{VOCAB_PIXEL_RGB_FLOAT, {3, IPL_DEPTH_32F}},
{-2, {1, IPL_DEPTH_16U}},
{-4, {1, IPL_DEPTH_32S}}
};

bool ImageStorage::_set_ipl_header(size_t x, size_t y, int pixel_type, size_t quantum,
Expand Down Expand Up @@ -308,7 +296,7 @@ bool ImageStorage::_set_ipl_header(size_t x, size_t y, int pixel_type, size_t qu
}
int origin = topIsLow ? IPL_ORIGIN_TL : IPL_ORIGIN_BL;

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);
pImage = iplCreateImageHeader(param.nChannels, param.depth, origin, quantum, x, y);

type_id = pixel_type;
this->quantum = quantum;
Expand Down
94 changes: 25 additions & 69 deletions src/libYARP_sig/src/yarp/sig/impl/IplImage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,38 +18,38 @@ inline int PAD_BYTES (int len, int pad)
return (rem != 0) ? (pad - rem) : 0;
}

template <class T>
T* AllocAligned (int size)
char* AllocAligned (int size)
{
T *ptr = new T[size + YARP_IMAGE_ALIGN];
char* ptr = new char[size + YARP_IMAGE_ALIGN];
const int rem = (((size_t)ptr) % YARP_IMAGE_ALIGN);
const char addbytes = YARP_IMAGE_ALIGN - rem;

char *p = ((char *)ptr) + addbytes;
*(p - 1) = addbytes;
return reinterpret_cast<T*>(p);
return p;
}

template <class T>
void FreeAligned (T* ptr)
void FreeAligned (char* ptr)
{
if (ptr == nullptr) {
if (ptr == nullptr)
{
return;
}

const char addbytes = *(((char *)ptr) - 1);
delete[] reinterpret_cast<T*>(((char *)ptr) - addbytes);
const char addbytes = *(ptr - 1);
delete[] (ptr - addbytes);
}

IPLAPIIMPL(void, iplAllocateImage,(IplImage* image))
IPLAPIIMPL(void, iplAllocateImage, (MiniIplImage* image))
{
image->imageData = AllocAligned<char> (image->imageSize);
image->imageData = AllocAligned (image->imageSize);
}

IPLAPIIMPL(void, iplDeallocateImage,(IplImage* image))
IPLAPIIMPL(void, iplDeallocateImage, (MiniIplImage* image))
{
if (image->imageData != nullptr) {
FreeAligned<char>(image->imageData); ///delete[] image->imageData;
if (image->imageData != nullptr)
{
FreeAligned (image->imageData); ///delete[] image->imageData;
}
image->imageData = nullptr;
}
Expand All @@ -62,7 +62,6 @@ IPLAPIIMPL(void, iplDeallocateImage,(IplImage* image))
// Returns: The newly constructed IPL image header.
// Parameters:
// nChannels - Number of channels in the image.
// alphaChannel - Alpha channel number (0 if no alpha channel in image).
// depth - Bit depth of pixels. Can be one of
// IPL_DEPTH_1U,
// IPL_DEPTH_8U,
Expand All @@ -71,37 +70,21 @@ IPLAPIIMPL(void, iplDeallocateImage,(IplImage* image))
// IPL_DEPTH_16S,
// IPL_DEPTH_32S.
// IPL_DEPTH_32F.
// colorModel - A four character array describing the color model,
// e.g. "RGB", "GRAY", "MSI" etc.
// channelSeq - The sequence of channels in the image,
// e.g. "BGR" for an RGB image.
// dataOrder - IPL_DATA_ORDER_PIXEL or IPL_DATA_ORDER_PLANE.
// origin - The origin of the image.
// Can be IPL_ORIGIN_TL or IPL_ORIGIN_BL.
// align - Alignment of image data.
// Can be IPL_ALIGN_4BYTES (IPL_ALIGN_DWORD) or
// IPL_ALIGN_8BYTES (IPL_ALIGN_QWORD) or
// IPL_ALIGN_16BYTES IPL_ALIGN_32BYTES.
// width - Width of the image in pixels.
// height - Height of the image in pixels.
// roi - Pointer to an ROI (region of interest) structure.
// This can be NULL (implying a region of interest comprising
// all channels and the entire image area).
// maskROI - Pointer on mask image
// imageId - use of the application
// tileInfo - contains information on tiling
//
// Notes:
*/

IPLAPIIMPL(IplImage*, iplCreateImageHeader,
(int nChannels, int alphaChannel, int depth,
char* colorModel, char* channelSeq, int dataOrder,
IPLAPIIMPL(MiniIplImage*, iplCreateImageHeader,
(int nChannels, int depth,
int origin, int align,
int width, int height))
{
switch (depth)
{
{
default:
case IPL_DEPTH_1U:
return nullptr;
Expand All @@ -113,25 +96,14 @@ IPLAPIIMPL(IplImage*, iplCreateImageHeader,
case IPL_DEPTH_16S:
case IPL_DEPTH_32S:
break;
}
}

IplImage *r = nullptr;
r = new IplImage;
MiniIplImage* r = new MiniIplImage;
yAssert(r != nullptr);

r->nSize = sizeof(IplImage);
r->ID = 0xf0f0f0f0; // pasa's ID for IPL under QNX.

r->nChannels = nChannels;
r->alphaChannel = alphaChannel;
r->depth = depth;

memcpy (r->colorModel, colorModel, 4);
memcpy (r->channelSeq, channelSeq, 4);

yAssert(dataOrder == IPL_DATA_ORDER_PIXEL);

r->dataOrder = dataOrder;
r->origin = origin;

r->align = align;
Expand All @@ -147,36 +119,20 @@ IPLAPIIMPL(IplImage*, iplCreateImageHeader,
return r;
}

IPLAPIIMPL(void, iplDeallocateHeader,(IplImage* image))
IPLAPIIMPL(void, iplDeallocateHeader, (MiniIplImage * image))
{
if (image == nullptr) {
if (image == nullptr)
{
return;
}

yAssert(image->nSize == sizeof(IplImage));
if (image->imageData != nullptr)
{
FreeAligned<char> (image->imageData);
}
{
FreeAligned (image->imageData);
}

delete image;
}

IPLAPIIMPL(void, iplDeallocate,(IplImage* image, int flag))
{
switch (flag)
{
case IPL_IMAGE_ALL_WITHOUT_MASK:
case IPL_IMAGE_ALL:
case IPL_IMAGE_HEADER:
iplDeallocateHeader (image);
break;

case IPL_IMAGE_DATA:
iplDeallocateImage (image);
break;
}
}

// not used outside this file.
#undef IPLAPIIMPL
24 changes: 7 additions & 17 deletions src/libYARP_sig/src/yarp/sig/impl/IplImage.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ typedef unsigned char uchar;


/****************************************************************************************\
* Image type (IplImage) *
* Image type (MiniIplImage) *
\****************************************************************************************/

/*
Expand Down Expand Up @@ -79,16 +79,9 @@ typedef unsigned char uchar;
#define IPL_ALIGN_QWORD IPL_ALIGN_8BYTES

typedef struct _IplImage {
int nSize; /**< sizeof(IplImage) */
int ID; /**< version (=0)*/
int nChannels; /**< Most of OpenCV functions support 1,2,3 or 4 channels */
int alphaChannel; /**< ignored by OpenCV */
int depth; /**< pixel depth in bits: IPL_DEPTH_8U, IPL_DEPTH_8S, IPL_DEPTH_16S,
IPL_DEPTH_32S, IPL_DEPTH_32F and IPL_DEPTH_64F are supported */
char colorModel[4]; /**< ignored by OpenCV */
char channelSeq[4]; /**< ignored by OpenCV */
int dataOrder; /**< 0 - interleaved color channels, 1 - separate color channels.
cvCreateImage can only create interleaved images */
int origin; /**< 0 - top-left origin,
1 - bottom-left origin (Windows bitmaps style) */
int align; /**< Alignment of image rows (4 or 8).
Expand All @@ -101,7 +94,7 @@ typedef struct _IplImage {
char *imageData; /**< pointer to aligned image data */
int widthStep; /**< size of aligned image row in bytes */
}
IplImage;
MiniIplImage;

typedef struct _IplTileInfo IplTileInfo;

Expand All @@ -115,19 +108,16 @@ typedef struct _IplTileInfo IplTileInfo;
*/
#define IPLAPIIMPL(type,name,arg) extern type name arg

IPLAPIIMPL(void, iplAllocateImage,(IplImage* image));
IPLAPIIMPL(void, iplAllocateImage, (MiniIplImage * image));

IPLAPIIMPL(void, iplDeallocateImage,(IplImage* image));
IPLAPIIMPL(void, iplDeallocateImage, (MiniIplImage * image));

IPLAPIIMPL(IplImage*, iplCreateImageHeader,
(int nChannels, int alphaChannel, int depth,
char* colorModel, char* channelSeq, int dataOrder,
IPLAPIIMPL(MiniIplImage*, iplCreateImageHeader,
(int nChannels, int depth,
int origin, int align,
int width, int height));

IPLAPIIMPL(void, iplDeallocateHeader,(IplImage* image));

IPLAPIIMPL(void, iplDeallocate,(IplImage* image, int flag));
IPLAPIIMPL(void, iplDeallocateHeader, (MiniIplImage * image));

#define IPL_BORDER_CONSTANT 0

Expand Down

0 comments on commit 2ee7d1a

Please sign in to comment.