dispmap/svimage.cpp

149 lines
2.5 KiB
C++
Raw Normal View History

2014-07-11 20:35:48 +04:00
#include "svimage.h"
2014-07-22 20:37:29 +04:00
int SvImage::getPixel(int x, int y, int channel) {
2014-07-11 20:35:48 +04:00
if (y >= m_image->height() ||
y < 0 ||
x >= m_image->width()
|| x < 0) {
return 0;
}
QRgb rgb = m_image->pixel(x, y);
switch (channel) {
case 0:
return qRed(rgb);
case 1:
return qGreen(rgb);
case 2:
return qBlue(rgb);
default:
return qGray(rgb);
}
}
2014-07-22 20:37:29 +04:00
int SvImage::getPixelNormalizedHue(int x, int y) {
if (y >= m_image->height() ||
y < 0 ||
x >= m_image->width()
|| x < 0) {
return 0;
}
QRgb rgb = m_image->pixel(x, y);
QColor color(rgb);
return (color.hsvHue() * getPixelSaturation(x, y)) / 255;
}
2014-07-11 20:35:48 +04:00
int SvImage::getPixelHue(int x, int y) {
if (y >= m_image->height() ||
y < 0 ||
x >= m_image->width()
|| x < 0) {
return 0;
}
QRgb rgb = m_image->pixel(x, y);
QColor color(rgb);
2014-07-22 20:37:29 +04:00
return color.hsvHue();
2014-07-11 20:35:48 +04:00
}
int SvImage::getPixelValue(int x, int y) {
if (y >= m_image->height() ||
y < 0 ||
x >= m_image->width()
|| x < 0) {
return 0;
}
QRgb rgb = m_image->pixel(x, y);
QColor color(rgb);
return color.value();
}
2014-07-18 20:48:42 +04:00
int SvImage::getPixelSaturation(int x, int y)
{
if (y >= m_image->height() ||
y < 0 ||
x >= m_image->width()
|| x < 0) {
return 0;
}
QRgb rgb = m_image->pixel(x, y);
QColor color(rgb);
return color.saturation();
}
2014-07-22 20:37:29 +04:00
QRgb SvImage::getPixelRGB(int x, int y)
{
if (y >= m_image->height() ||
y < 0 ||
x >= m_image->width()
|| x < 0) {
return 0;
}
return m_image->pixel(x, y);
}
2014-07-18 20:48:42 +04:00
void SvImage::putGrayPixel(int x, int y, int value)
2014-07-11 20:35:48 +04:00
{
if (y >= m_image->height() ||
y < 0 ||
x >= m_image->width()
|| x < 0) {
return;
}
2014-07-22 20:37:29 +04:00
if (value > 255) {
value = 255;
}
2014-07-14 10:55:56 +04:00
m_image->setPixel(x, y, qRgb(value, value, value));
2014-07-11 20:35:48 +04:00
}
2014-07-18 20:48:42 +04:00
void SvImage::putPixel(int x, int y, int red, int green, int blue)
{
if (y >= m_image->height() ||
y < 0 ||
x >= m_image->width()
|| x < 0) {
return;
}
m_image->setPixel(x, y, qRgb(red, green, blue));
}
2014-07-11 20:35:48 +04:00
unsigned int SvImage::getHeight() {
return m_image->height();
}
unsigned int SvImage::getWidth() {
return m_image->width();
}
QImage& SvImage::getImage() {
return *m_image;
}
SvImage::SvImage(QImage& image) {
m_image = &image;
}
SvImage::~SvImage() {
}