dispmap/svimage.cpp

117 lines
1.9 KiB
C++
Raw Normal View History

2014-07-11 20:35:48 +04:00
#include "svimage.h"
int SvImage::getPixel(int x, int y, int channel = -1) {
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);
}
}
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);
return color.hue();
}
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();
}
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-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() {
}