added get pixel methods

This commit is contained in:
Damian Kowalski 2024-04-07 13:22:45 +02:00
parent 96129bc8ab
commit d5dad0ee19

View File

@ -103,8 +103,8 @@ QRgb Transformation::getPixel(int x, int y, Mode mode)
*/ */
QRgb Transformation::getPixelCyclic(int x, int y) QRgb Transformation::getPixelCyclic(int x, int y)
{ {
qDebug() << Q_FUNC_INFO << "Not implemented yet!"; x = x % image->width();
y = y % image->height();
return image->pixel(x,y); return image->pixel(x,y);
} }
@ -114,7 +114,9 @@ QRgb Transformation::getPixelCyclic(int x, int y)
*/ */
QRgb Transformation::getPixelNull(int x, int y) QRgb Transformation::getPixelNull(int x, int y)
{ {
qDebug() << Q_FUNC_INFO << "Not implemented yet!"; bool isX = x < 0 || x > image->width();
bool isY = y < 0 || y > image->height();
if (isX || isY) return Qt::black;
return image->pixel(x,y); return image->pixel(x,y);
} }
@ -126,7 +128,27 @@ QRgb Transformation::getPixelNull(int x, int y)
*/ */
QRgb Transformation::getPixelRepeat(int x, int y) QRgb Transformation::getPixelRepeat(int x, int y)
{ {
qDebug() << Q_FUNC_INFO << "Not implemented yet!"; int width = image->width();
int height = image->height();
if (x < 0 && y < 0)
return image->pixel(0, 0);
else if (x >= width && y < 0)
return image->pixel(width - 1, 0);
else if (x >= width && y >= height)
return image->pixel(width - 1, height - 1);
else if (x < 0 && y >= height)
return image->pixel(0, height - 1);
else if (x < 0)
return image->pixel(0, y);
else if (y < 0)
return image->pixel(x, 0);
else if (x >= width)
return image->pixel(width - 1, y);
else if (y >= height)
return image->pixel(x, height - 1);
else
return image->pixel(x, y);
return image->pixel(x,y); return image->pixel(x,y);
} }