📄 iplimage.cpp
字号:
FreeAligned<char> (image->imageData); ///delete[] image->imageData;
image->imageData = NULL;
// Not allocated.
image->roi = NULL;
}
/* /////////////////////////////////////////////////////////////////////////
// Name: iplCreateImageHeader
// Purpose: Creates an IPL image header according to the specified
// attributes.
// 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,
// IPL_DEPTH_8S,
// IPL_DEPTH_16U,
// 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,
int origin, int align,
int width, int height, IplROI* roi, IplImage* maskROI,
void* imageId, IplTileInfo* tileInfo))
{
switch (depth)
{
default:
case IPL_DEPTH_1U:
return NULL;
case IPL_DEPTH_8U:
case IPL_DEPTH_8S:
case IPL_DEPTH_32F:
case IPL_DEPTH_16U:
case IPL_DEPTH_16S:
case IPL_DEPTH_32S:
break;
}
IplImage *r = NULL;
r = new IplImage;
assert (r != NULL);
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);
assert (dataOrder == IPL_DATA_ORDER_PIXEL);
r->dataOrder = dataOrder; // IPL_DATA_ORDER_PIXEL, IPL_DATA_ORDER_PLANE
r->origin = origin;
//assert (align == IPL_ALIGN_QWORD); /// don't want to be bothered w/ alignment beside the
/// the 8 bytes stuff.
//assert (align == YARP_IMAGE_ALIGN);
r->align = align;
r->width = width;
r->height = height;
r->roi = NULL;
r->maskROI = NULL;
r->imageId = NULL;
r->tileInfo = NULL;
const int linew = width * (depth & IPL_DEPTH_MASK) / 8 * nChannels;
r->widthStep = linew + PAD_BYTES(linew, align);
r->imageSize = r->widthStep * height;
r->imageData = NULL;
r->tileInfo = NULL;
memset (r->BorderMode, 0, 4);
memset (r->BorderConst, 0, 4);
r->imageDataOrigin = NULL;
return r;
}
IPLAPIIMPL(IplImage*, iplCloneImage, ( const IplImage* img ) )
{
IplImage *ret = iplCreateImageHeader (
img->nChannels, img->alphaChannel, img->depth, (char *)img->colorModel, (char *)img->channelSeq,
img->dataOrder, img->origin, img->align, img->width, img->height, NULL, NULL,
img->imageId, NULL);
if (img->imageData != NULL)
{
switch (img->depth)
{
case IPL_DEPTH_8U:
case IPL_DEPTH_8S:
iplAllocateImage (ret, 0, 0);
break;
case IPL_DEPTH_32F:
iplAllocateImageFP (ret, 0, 0.0);
break;
default:
assert (1 == 0);
break;
}
memcpy (ret->imageData, img->imageData, img->imageSize);
}
return ret;
}
IPLAPIIMPL(void, iplCopy, (IplImage* srcImage, IplImage* dstImage))
{
assert (srcImage->imageData != NULL && dstImage->imageData != NULL);
memcpy (dstImage->imageData, srcImage->imageData, srcImage->imageSize);
}
IPLAPIIMPL(void, iplDeallocateHeader,(IplImage* image))
{
if (image == NULL)
return;
assert (image->nSize == sizeof(IplImage));
if (image->imageData != NULL)
{
FreeAligned<char> (image->imageData);
///delete[] 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;
case IPL_IMAGE_ROI:
case IPL_IMAGE_TILE:
case IPL_IMAGE_MASK:
// NOT IMPLEMENTED.
break;
}
}
IPLAPIIMPL(void,iplSetBorderMode,(IplImage *src,int mode,int border,int constVal))
{
for (int i = 0; i < 4; i++)
if ((border >> i) & 0x1)
{
src->BorderMode[i] = mode;
src->BorderConst[i] = constVal;
}
}
// this is ok only for 8 bits pixel/planes images. RGB and HSV are ok too.
IPLAPIIMPL(void, iplSet, (IplImage* image, int fillValue))
{
assert (image->imageData != NULL);
assert ((image->depth & IPL_DEPTH_MASK) == 8);
memset (image->imageData, fillValue, image->imageSize);
}
IPLAPIIMPL(void, iplSetFP, (IplImage* image, float fillValue))
{
assert (image->imageData != NULL);
assert (image->depth == IPL_DEPTH_32F);
const int size = image->imageSize / sizeof(float);
float *tmp = (float *)image->imageData;
for (int i = 0; i < size; i++)
*tmp++ = fillValue;
}
// only 8 bits supported. Clipping is carried out to be ipl compatible.
IPLAPIIMPL(void, iplAddS,(IplImage* srcImage, IplImage* dstImage, int value))
{
assert (compareHeader (srcImage, dstImage));
assert (srcImage->depth == dstImage->depth);
// assume images have the same size and 8 bits/pixel/planes.
switch (srcImage->depth)
{
case IPL_DEPTH_8U:
{
const int size = srcImage->imageSize;
unsigned char * src = (unsigned char *)srcImage->imageData;
unsigned char * dst = (unsigned char *)dstImage->imageData;
short tmp;
for (int i = 0; i < size; i++)
{
tmp = *src++ + value;
if (tmp < 0)
tmp = 0;
else
if (tmp > 255)
tmp = 255;
*dst++ = char(tmp);
}
}
break;
case IPL_DEPTH_8S:
{
const int size = srcImage->imageSize;
char * src = srcImage->imageData;
char * dst = dstImage->imageData;
short tmp;
for (int i = 0; i < size; i++)
{
tmp = *src++ + value;
if (tmp < -128)
tmp = -128;
else
if (tmp > 127)
tmp = 127;
*dst++ = char(tmp);
}
}
break;
default:
assert (1 == 0);
// NOT IMPLEMENTED.
break;
}
}
IPLAPIIMPL(void, iplAdd,(IplImage* srcImageA, IplImage* srcImageB,
IplImage* dstImage))
{
assert (compareHeader (srcImageA, srcImageB));
assert (compareHeader (srcImageB, dstImage));
assert (srcImageA->depth == srcImageB->depth);
assert (srcImageA->depth == dstImage->depth);
// assume images have the same size and 8 bits/pixel/planes.
switch (srcImageA->depth)
{
case IPL_DEPTH_8U:
{
const int size = srcImageA->imageSize;
unsigned char * src1 = (unsigned char *)srcImageA->imageData;
unsigned char * src2 = (unsigned char *)srcImageB->imageData;
unsigned char * dst = (unsigned char *)dstImage->imageData;
short tmp;
for (int i = 0; i < size; i++)
{
tmp = *src1++ + *src2++;
if (tmp > 255)
tmp = 255;
*dst++ = char(tmp);
}
}
break;
case IPL_DEPTH_8S:
{
const int size = srcImageA->imageSize;
char * src1 = srcImageA->imageData;
char * src2 = srcImageB->imageData;
char * dst = dstImage->imageData;
short tmp;
for (int i = 0; i < size; i++)
{
tmp = *src1++ + *src2++;
if (tmp < -128)
tmp = -128;
else
if (tmp > 127)
tmp = 127;
*dst++ = char(tmp);
}
}
break;
case IPL_DEPTH_32F:
{
const int size = srcImageA->imageSize / sizeof(float);
float * src1 = (float *)srcImageA->imageData;
float * src2 = (float *)srcImageB->imageData;
float * dst = (float *)dstImage->imageData;
for (int i = 0; i < size; i++)
{
*dst++ = *src1++ + *src2++;
}
}
break;
default:
assert (1 == 0);
// NOT IMPLEMENTED.
break;
}
}
IPLAPIIMPL(void, iplSubtract,(IplImage* srcImageA, IplImage* srcImageB,
IplImage* dstImage))
{
assert (compareHeader (srcImageA, srcImageB));
assert (compareHeader (srcImageB, dstImage));
// assume images have the same size and 8 bits/pixel/planes.
switch (srcImageA->depth)
{
case IPL_DEPTH_8U:
{
const int size = srcImageA->imageSize;
unsigned char * src1 = (unsigned char *)srcImageA->imageData;
unsigned char * src2 = (unsigned char *)srcImageB->imageData;
unsigned char * dst = (unsigned char *)dstImage->imageData;
short tmp;
for (int i = 0; i < size; i++)
{
tmp = *src1++ - *src2++;
if (tmp < 0)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -