File indexing completed on 2024-04-14 04:47:43

0001 /*
0002     SPDX-FileCopyrightText: 2022 Eric Jiang
0003     SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0004 */
0005 #include "test_utils.hpp"
0006 // test specific headers
0007 #include "scopes/colorscopes/colorconstants.h"
0008 #include "scopes/colorscopes/vectorscopegenerator.h"
0009 #include "scopes/colorscopes/waveformgenerator.h"
0010 #include "scopes/colorscopes/rgbparadegenerator.h"
0011 #include "scopes/colorscopes/histogramgenerator.h"
0012 
0013 // test for a bug where pixels were assumed to be RGB which was not true on
0014 // Windows, resulting in red and blue switched. BUG: 453149
0015 // Multiple scopes are affected, including vectorscope and waveform
0016 TEST_CASE("Colorscope RGB/BGR handling")
0017 {
0018     // create a fully red image
0019     QImage inputImage(480, 320, QImage::Format_RGB32);
0020     inputImage.fill(Qt::red);
0021     QImage bgrInputImage = inputImage.convertToFormat(QImage::Format_BGR30);
0022 
0023     QSize scopeSize{256, 256};
0024 
0025     SECTION("Vectorscope handles both RGB and BGR")
0026     {
0027         VectorscopeGenerator vectorscope{};
0028         QImage rgbScope = vectorscope.calculateVectorscope(scopeSize, inputImage, 1,
0029             VectorscopeGenerator::PaintMode::PaintMode_Green2,
0030             VectorscopeGenerator::ColorSpace::ColorSpace_YUV,
0031             false, 7);
0032         QImage bgrScope = vectorscope.calculateVectorscope(scopeSize, bgrInputImage, 1,
0033             VectorscopeGenerator::PaintMode::PaintMode_Green2,
0034             VectorscopeGenerator::ColorSpace::ColorSpace_YUV,
0035             false, 7);
0036 
0037         // both of these should be equivalent, since the vectorscope should
0038         // handle different pixel formats
0039         CHECK(rgbScope == bgrScope);
0040     }
0041 
0042     SECTION("Waveform handles both RGB and BGR")
0043     {
0044         WaveformGenerator waveform{};
0045         QImage rgbScope = waveform.calculateWaveform(scopeSize, inputImage,
0046             WaveformGenerator::PaintMode::PaintMode_Yellow,
0047             false, ITURec::Rec_709, 3);
0048         QImage bgrScope = waveform.calculateWaveform(scopeSize, bgrInputImage,
0049             WaveformGenerator::PaintMode::PaintMode_Yellow,
0050             false, ITURec::Rec_709, 3);
0051 
0052         CHECK(rgbScope == bgrScope);
0053     }
0054 
0055     SECTION("RGB Parade handles both RGB and BGR")
0056     {
0057         RGBParadeGenerator rgb{};
0058         QImage rgbScope = rgb.calculateRGBParade(scopeSize, inputImage,
0059             RGBParadeGenerator::PaintMode::PaintMode_RGB,
0060             false, false, 3);
0061         QImage bgrScope = rgb.calculateRGBParade(scopeSize, bgrInputImage,
0062             RGBParadeGenerator::PaintMode::PaintMode_RGB,
0063             false, false, 3);
0064 
0065         CHECK(rgbScope == bgrScope);
0066     }
0067 
0068     SECTION("Histogram handles both RGB and BGR")
0069     {
0070         const auto ALL_COMPONENTS = HistogramGenerator::Components::ComponentR |
0071             HistogramGenerator::Components::ComponentG |
0072             HistogramGenerator::Components::ComponentB;
0073 
0074         HistogramGenerator hist{};
0075         QImage rgbScope = hist.calculateHistogram(scopeSize, inputImage,
0076             ALL_COMPONENTS, ITURec::Rec_709, false, false, 3);
0077         QImage bgrScope = hist.calculateHistogram(scopeSize, bgrInputImage,
0078             ALL_COMPONENTS, ITURec::Rec_709, false, false, 3);
0079 
0080         CHECK(rgbScope == bgrScope);
0081     }
0082 }