parent
f9dae37fae
commit
2c12f05517
|
@ -1465,18 +1465,12 @@ void HGImgView::mouseMoveEvent(QMouseEvent* e)
|
||||||
|
|
||||||
if (m_showColorInfo)
|
if (m_showColorInfo)
|
||||||
{
|
{
|
||||||
HGByte *data = nullptr;
|
HGImagePixel pixel;
|
||||||
HGBase_GetImageData(m_image, &data);
|
HGBase_GetImagePixel(m_image, xImg, yImg, &pixel);
|
||||||
HGByte *pixel = data + yImg * info.widthStep + xImg * 3;
|
|
||||||
|
|
||||||
HGByte r = pixel[0];
|
|
||||||
HGByte g = pixel[1];
|
|
||||||
HGByte b = pixel[2];
|
|
||||||
//qDebug("colorInfo, r=%d, g=%d, b=%d", r, g, b);
|
|
||||||
|
|
||||||
char colorInfo[1024];
|
char colorInfo[1024];
|
||||||
sprintf(colorInfo, "X: %d, Y: %d\nRGB(%d, %d, %d)\nHTML(#%02X%02X%02X)",
|
sprintf(colorInfo, "X: %d, Y: %d\nRGB(%d, %d, %d)\nHTML(#%02X%02X%02X)",
|
||||||
xImg, yImg, r, g, b, r, g, b);
|
xImg, yImg, pixel.r, pixel.g, pixel.b, pixel.r, pixel.g, pixel.b);
|
||||||
QToolTip::showText(e->globalPos(), colorInfo, this);
|
QToolTip::showText(e->globalPos(), colorInfo, this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -108,6 +108,7 @@ HGBase_CloneImage
|
||||||
HGBase_DestroyImage
|
HGBase_DestroyImage
|
||||||
HGBase_GetImageData
|
HGBase_GetImageData
|
||||||
HGBase_GetImageInfo
|
HGBase_GetImageInfo
|
||||||
|
HGBase_GetImagePixel
|
||||||
HGBase_GetImageROI
|
HGBase_GetImageROI
|
||||||
HGBase_SetImageROI
|
HGBase_SetImageROI
|
||||||
HGBase_ResetImageROI
|
HGBase_ResetImageROI
|
||||||
|
|
|
@ -798,6 +798,117 @@ HGResult HGAPI HGBase_GetImageInfo(HGImage image, HGImageInfo* info)
|
||||||
return HGBASE_ERR_OK;
|
return HGBASE_ERR_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline HGByte GetBit(const HGByte* data, HGUInt index)
|
||||||
|
{
|
||||||
|
HGUInt byteIndex = index / 8;
|
||||||
|
HGUInt bitIndex = index % 8;
|
||||||
|
return (data[byteIndex] >> (7 - bitIndex)) & 0x01;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void SetBit(HGByte* data, HGUInt index, HGByte value)
|
||||||
|
{
|
||||||
|
assert(0 == value || 1 == value);
|
||||||
|
HGUInt byteIndex = index / 8;
|
||||||
|
HGUInt bitIndex = index % 8;
|
||||||
|
if (1 == value)
|
||||||
|
data[byteIndex] |= (1 << (7 - bitIndex));
|
||||||
|
else
|
||||||
|
data[byteIndex] &= ~(1 << (7 - bitIndex));
|
||||||
|
}
|
||||||
|
|
||||||
|
HGResult HGAPI HGBase_GetImagePixel(HGImage image, HGUInt x, HGUInt y, HGImagePixel *pixel)
|
||||||
|
{
|
||||||
|
if (NULL == image || NULL == pixel)
|
||||||
|
{
|
||||||
|
return HGBASE_ERR_INVALIDARG;
|
||||||
|
}
|
||||||
|
|
||||||
|
HGImageImpl* imageImpl = (HGImageImpl*)image;
|
||||||
|
HGUInt width = imageImpl->m_width;
|
||||||
|
HGUInt height = imageImpl->m_height;
|
||||||
|
HGUInt type = imageImpl->m_type;
|
||||||
|
HGUInt widthStep = imageImpl->m_widthStep;
|
||||||
|
HGUInt origin = imageImpl->m_origin;
|
||||||
|
HGByte* data = imageImpl->m_data;
|
||||||
|
|
||||||
|
if (x >= width || y >= height)
|
||||||
|
{
|
||||||
|
return HGBASE_ERR_INVALIDARG;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (HGBASE_IMGTYPE_BINARY == type)
|
||||||
|
{
|
||||||
|
HGByte *p = data + y * widthStep;
|
||||||
|
if (HGBASE_IMGORIGIN_BOTTOM == origin)
|
||||||
|
p = data + (height - y - 1) * widthStep;
|
||||||
|
|
||||||
|
HGByte v = GetBit(p, x) * 255;
|
||||||
|
pixel->r = v;
|
||||||
|
pixel->g = v;
|
||||||
|
pixel->b = v;
|
||||||
|
pixel->a = 0;
|
||||||
|
}
|
||||||
|
else if (HGBASE_IMGTYPE_GRAY == type)
|
||||||
|
{
|
||||||
|
HGByte *p = data + y * widthStep + x;
|
||||||
|
if (HGBASE_IMGORIGIN_BOTTOM == origin)
|
||||||
|
p = data + (height - y - 1) * widthStep + x;
|
||||||
|
|
||||||
|
pixel->r = p[0];
|
||||||
|
pixel->g = p[0];
|
||||||
|
pixel->b = p[0];
|
||||||
|
pixel->a = 0;
|
||||||
|
}
|
||||||
|
else if (HGBASE_IMGTYPE_BGR == type)
|
||||||
|
{
|
||||||
|
HGByte *p = data + y * widthStep + x * 3;
|
||||||
|
if (HGBASE_IMGORIGIN_BOTTOM == origin)
|
||||||
|
p = data + (height - y - 1) * widthStep + x * 3;
|
||||||
|
|
||||||
|
pixel->r = p[2];
|
||||||
|
pixel->g = p[1];
|
||||||
|
pixel->b = p[0];
|
||||||
|
pixel->a = 0;
|
||||||
|
}
|
||||||
|
else if (HGBASE_IMGTYPE_RGB == type)
|
||||||
|
{
|
||||||
|
HGByte *p = data + y * widthStep + x * 3;
|
||||||
|
if (HGBASE_IMGORIGIN_BOTTOM == origin)
|
||||||
|
p = data + (height - y - 1) * widthStep + x * 3;
|
||||||
|
|
||||||
|
pixel->r = p[0];
|
||||||
|
pixel->g = p[1];
|
||||||
|
pixel->b = p[2];
|
||||||
|
pixel->a = 0;
|
||||||
|
}
|
||||||
|
else if (HGBASE_IMGTYPE_BGRA == type)
|
||||||
|
{
|
||||||
|
HGByte *p = data + y * widthStep + x * 4;
|
||||||
|
if (HGBASE_IMGORIGIN_BOTTOM == origin)
|
||||||
|
p = data + (height - y - 1) * widthStep + x * 4;
|
||||||
|
|
||||||
|
pixel->r = p[2];
|
||||||
|
pixel->g = p[1];
|
||||||
|
pixel->b = p[0];
|
||||||
|
pixel->a = p[3];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
assert(HGBASE_IMGTYPE_RGBA == type);
|
||||||
|
|
||||||
|
HGByte *p = data + y * widthStep + x * 4;
|
||||||
|
if (HGBASE_IMGORIGIN_BOTTOM == origin)
|
||||||
|
p = data + (height - y - 1) * widthStep + x * 4;
|
||||||
|
|
||||||
|
pixel->r = p[0];
|
||||||
|
pixel->g = p[1];
|
||||||
|
pixel->b = p[2];
|
||||||
|
pixel->a = p[3];
|
||||||
|
}
|
||||||
|
|
||||||
|
return HGBASE_ERR_OK;
|
||||||
|
}
|
||||||
|
|
||||||
HGResult HGAPI HGBase_GetImageROI(HGImage image, HGImageRoi* roi)
|
HGResult HGAPI HGBase_GetImageROI(HGImage image, HGImageRoi* roi)
|
||||||
{
|
{
|
||||||
if (NULL == image || NULL == roi)
|
if (NULL == image || NULL == roi)
|
||||||
|
@ -2892,24 +3003,6 @@ HGResult HGAPI HGBase_ReverseImage(HGImage image, HGImage destImage)
|
||||||
return HGBASE_ERR_OK;
|
return HGBASE_ERR_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline HGByte GetBit(const HGByte* data, HGUInt index)
|
|
||||||
{
|
|
||||||
HGUInt byteIndex = index / 8;
|
|
||||||
HGUInt bitIndex = index % 8;
|
|
||||||
return (data[byteIndex] >> (7 - bitIndex)) & 0x01;
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline void SetBit(HGByte* data, HGUInt index, HGByte value)
|
|
||||||
{
|
|
||||||
assert(0 == value || 1 == value);
|
|
||||||
HGUInt byteIndex = index / 8;
|
|
||||||
HGUInt bitIndex = index % 8;
|
|
||||||
if (1 == value)
|
|
||||||
data[byteIndex] |= (1 << (7 - bitIndex));
|
|
||||||
else
|
|
||||||
data[byteIndex] &= ~(1 << (7 - bitIndex));
|
|
||||||
}
|
|
||||||
|
|
||||||
static HGResult CopyImageWithBinary(HGImageImpl *srcImageImpl, HGImageImpl *destImageImpl)
|
static HGResult CopyImageWithBinary(HGImageImpl *srcImageImpl, HGImageImpl *destImageImpl)
|
||||||
{
|
{
|
||||||
assert(HGBASE_IMGTYPE_BINARY == srcImageImpl->m_type
|
assert(HGBASE_IMGTYPE_BINARY == srcImageImpl->m_type
|
||||||
|
|
|
@ -43,6 +43,15 @@ typedef struct
|
||||||
HGUInt origin; /* 数据排列方式,参见HGBASE_IMGORIGIN_* */
|
HGUInt origin; /* 数据排列方式,参见HGBASE_IMGORIGIN_* */
|
||||||
}HGImageInfo;
|
}HGImageInfo;
|
||||||
|
|
||||||
|
/* 图像像素 */
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
HGByte r;
|
||||||
|
HGByte g;
|
||||||
|
HGByte b;
|
||||||
|
HGByte a;
|
||||||
|
}HGImagePixel;
|
||||||
|
|
||||||
/* 图像感兴趣区域 */
|
/* 图像感兴趣区域 */
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
|
@ -205,6 +214,10 @@ HGEXPORT HGResult HGAPI HGBase_GetImageData(HGImage image, HGByte** data);
|
||||||
*/
|
*/
|
||||||
HGEXPORT HGResult HGAPI HGBase_GetImageInfo(HGImage image, HGImageInfo* info);
|
HGEXPORT HGResult HGAPI HGBase_GetImageInfo(HGImage image, HGImageInfo* info);
|
||||||
|
|
||||||
|
/* 获取图像像素值
|
||||||
|
*/
|
||||||
|
HGEXPORT HGResult HGAPI HGBase_GetImagePixel(HGImage image, HGUInt x, HGUInt y, HGImagePixel *pixel);
|
||||||
|
|
||||||
/* 获取图像感兴趣区域
|
/* 获取图像感兴趣区域
|
||||||
* 参数:
|
* 参数:
|
||||||
* 1) image: in, 图像句柄
|
* 1) image: in, 图像句柄
|
||||||
|
|
Loading…
Reference in New Issue