[TASK] Implement basic yuv handling.
This commit is contained in:
parent
6514501d1a
commit
b762a3a076
|
@ -235,11 +235,16 @@ void ImageViewer::adjustBrightness(int b) {
|
|||
for(int x=0; x<working_copy->getImage()->width(); x++) {
|
||||
for(int y=0; y<working_copy->getImage()->height(); y++) {
|
||||
QColor color = QColor::fromRgb(original->getImage()->pixel(x, y));
|
||||
color.getHsl(&h, &s, &old_l);
|
||||
new_l = old_l + delta;
|
||||
if(new_l > 255) new_l = 255;
|
||||
if(new_l < 0) new_l = 0;
|
||||
color.setHsl(h, s, new_l);
|
||||
// color.getHsl(&h, &s, &old_l);
|
||||
// new_l = old_l + delta;
|
||||
// if(new_l > 255) new_l = 255;
|
||||
// if(new_l < 0) new_l = 0;
|
||||
// color.setHsl(h, s, new_l);
|
||||
struct yuv yuv = LazyImage::RGBToYUV(color.rgb());
|
||||
yuv.y = yuv.y + (delta / 255.0);
|
||||
if(yuv.y > 1) yuv.y = 1;
|
||||
if(yuv.y < 0) yuv.y = 0;
|
||||
color = LazyImage::YUVToRGB(yuv);
|
||||
working_copy->getImage()->setPixel(x, y, color.rgb());
|
||||
}
|
||||
}
|
||||
|
@ -564,7 +569,7 @@ void ImageViewer::applyBasicFilter() {
|
|||
*/
|
||||
void ImageViewer::applyBasicFilterWithOverflowHandling() {
|
||||
QString chosen_mode = filter_mode_combobox->currentText();
|
||||
LazyImage::overflowMode overflow_mode;
|
||||
LazyImage::overflowMode overflow_mode = LazyImage::CONSTANT; // default for compiler
|
||||
if(chosen_mode == "Zero padding") overflow_mode = LazyImage::ZERO_PADDING;
|
||||
else if(chosen_mode == "Constant") overflow_mode = LazyImage::CONSTANT;
|
||||
else if(chosen_mode == "Continuous") overflow_mode = LazyImage::CONTINUOUS;
|
||||
|
|
|
@ -9,6 +9,13 @@
|
|||
|
||||
#include <math.h>
|
||||
|
||||
struct yuv {
|
||||
// values in [0,1]
|
||||
double y; // brightness
|
||||
double u; // red/green part
|
||||
double v; // green/blue part
|
||||
};
|
||||
|
||||
class LazyImage {
|
||||
|
||||
private:
|
||||
|
@ -256,6 +263,48 @@ class LazyImage {
|
|||
}
|
||||
};
|
||||
|
||||
static struct yuv RGBToYUV(QColor input) {
|
||||
struct yuv result;
|
||||
int input_r, input_g, input_b;
|
||||
input.getRgb(&input_r, &input_g, &input_b);
|
||||
//std::cout << input_r << "," << input_g << "," << input_b << " (rgb) -> (yuv) ";
|
||||
// normalize input rgb to values in [0,1]
|
||||
double r, g, b;
|
||||
r = input_r / 255.0;
|
||||
g = input_g / 255.0;
|
||||
b = input_b / 255.0;
|
||||
// calculate yuv
|
||||
result.y = 0.299 * r + 0.587 * g + 0.114 * b;
|
||||
result.u = (b - result.y) * 0.493;
|
||||
result.v = (r - result.y) * 0.877;
|
||||
//std::cout << result.y << "," << result.u << "," << result.v << std::endl;
|
||||
return result;
|
||||
};
|
||||
|
||||
static QColor YUVToRGB(struct yuv input) {
|
||||
double r, g, b;
|
||||
// calculate rgb
|
||||
//std::cout << input.y << "," << input.u << "," << input.v << " (yuv) -> (rgb) ";
|
||||
b = (input.u / 0.493) + input.y;
|
||||
r = (input.v / 0.877) + input.y;
|
||||
// möp g = (input.y - 0.299*r - 0.144*b) / 0.587;
|
||||
g = (1.0/0.587)*input.y - (0.299/0.587)*r - (0.114/0.585)*b;
|
||||
// normalize into [0,255]
|
||||
int output_r, output_g, output_b;
|
||||
output_r = qRound(r * 255.0);
|
||||
output_g = qRound(g * 255.0);
|
||||
output_b = qRound(b * 255.0);
|
||||
if(output_r < 0) output_r = 0;
|
||||
if(output_g < 0) output_g = 0;
|
||||
if(output_b < 0) output_b = 0;
|
||||
if(output_r > 255) output_r = 255;
|
||||
if(output_g > 255) output_g = 255;
|
||||
if(output_b > 255) output_b = 255;
|
||||
//std::cout << output_r << "," << output_g << "," << output_b << std::endl << std::endl;
|
||||
QColor result = QColor(output_r, output_g, output_b);
|
||||
return result;
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue