14.19 round 1: Scanlines normalized with the filter, Two Colors rounded, sheet tests apart
This commit is contained in:
4 files changed
+214
-166
No files matched your search
@@ -198,7 +198,7 @@ Platform adaptations, each forced by a missing Qt analog:
|
||||
- Camera Raw's Shadows and Highlights (14.16, Swift 1.4.8: `0b4c56c`): `kernels/AdjustPixels.c` is 0b4c56c's, unchanged: each follows a bump, u(1 − 2u)², over its half of the tones (Shadows from black, Highlights from white), two and a half times the bump to lift Shadows or pull Highlights down and once the other way, so tones never swap, and black, middle gray and white stay. Tests: `CameraRawToneOrderTests` (Swift's ramp kept in order at ±100 and the dark tones lifted; every level of a gray ramp against the curve written apart, each way at full and partial amounts and both together, Highlights first).
|
||||
- The Layers panel's gray (14.17, Swift 1.4.8: `06313a9`): `layersLookEditable` is Swift's: `canEditLayers` without what lasts only while the mouse is down (a stroke, a warp, a drag's transform edit, a pixel move) or a moment (`isProjectBusy`, read as `showsBusy`, which shows after 250 ms). The list's rows and their eyes (an effect's eye keeps `canEditLayers`, as Swift makes each effect row anew with it), the footer's buttons (new layer, folder, adjustments, delete with an active layer), the effects menu (with a layer that has pixels) and the mask button (one layer selected, without a mask) follow it, so nothing flashes gray for a click; every action still asks the session's own gate, which refuses meanwhile. The effects menu's folder term is left out as dead: a folder never holds pixels, so the pixel term refuses it. Tests: `LayersLookEditableTests` (each moment looks editable while the gate stays shut, each lasting state grays, the footer and list mid-stroke and under a pending transform, the effects menu's and mask button's own terms); the busy cases in `BlendModePickerTests`, `LayersPanelTests`, `NativeLayerListTests` and `LayerEffectRowTests` now wait for the indicator, and a click before it changes nothing.
|
||||
- Export As (14.18, Swift 1.4.8: `9287cf1`, `450af5f`, `b1db93d`): `ProjectController::exportAs(start, done)` replaces `exportJPEG`; `ExportFormat` (png, jpeg, pdf, Swift's raw values through `rawValue`, `allExportFormats`) starts the sheet, else the last format exported this run (`m_lastExportFormat`, PNG at first), and the File menu's Export JPEG… opens it on JPEG; Export As… (Ctrl+Alt+Shift+W, a new shortcut definition) on the last. The flow is the JPEG one: the render in a worker, the sheet, then the format's panel (Export PNG, Export JPEG or Export PDF, suggesting `.png`, `.jpeg` or `.pdf`), the write in a worker, one alert titled "Couldn’t export" for a failure past the render. `UI/ExportAsSheet` (Swift's sheet, renamed from the JPEG one): titled Export As; the format as three checkable buttons; the size as two `PickerField`s keeping the proportions (a number applies on Return or leaving, else both fields show the size again; a scrub or menu replaces their typing) and a scale menu of 25, 50, 75, 100 and 200%, every scale held between a hundredth and the side and surface limits; Quality for JPEG alone (saved only from a JPEG export), the page size in inches at the document's DPI for PDF alone, the background swatch ("Export Background") for JPEG and PDF; "Transparency kept · sRGB" for PNG, else "sRGB"; a change of format or size asks again only when the settings change, as Swift's `task(id:)`. The encoding resizes first (`ImageExporter::resized`: smooth, the same raster at the same size, `tooLarge` past the limits) and encodes by format (`pngData`; `jpeg`; `pdfData` over `flattened` for the preview). `JPEGPreview` takes the export's size beside its image (`setImage(image, pixels, updating)`), so Fit and 100% follow the chosen size, and draws Swift 1.4.8's checkerboard (20-point tiles of grays 0.30 and 0.35, anchored at the image) behind what it shows. Swift's PDF comes from `CGContext`'s PDF writer; `QPdfWriter` rounds a page to whole points, so `ImageExporter::pdfData` writes PDF 1.4 by hand: one page whose MediaBox is the print size in points (72 / resolution a pixel, 72 when none), the background as a filled rectangle when given, the pixels as a Flate RGB image with a gray soft mask, straight colour (adaptation; checked against poppler's `pdfinfo` and `pdftoppm`). A Flate stream that `qCompress` cannot make (it returns nothing when memory runs out) is `ExportError(render)`, never an empty stream. A zoom set before the first image (Ctrl+1 while the sheet still encodes) centres that image when it lands, as Swift's preview, made with its first result, centres on appearing. The page's inches round as Swift's formatter: its shortest digits, halves to even (45 pixels at 72 DPI are 0.62 in). A size field reads Swift's `Int` field (`typedInteger`, checked against Swift 6.0.3): a sign, decimal digits of any script read by code point, a fraction and an exponent (its leading zeros dropped), the number truncated toward zero and exact within Int64 (`1e3` is 1000, `12.7` is 12, `-9.223372036854775808e18` is Int64's least, `1e-400` is 0, `128e` is 128), grouping refused; known difference: ICU's lenient parse also reads a leading number before other text (`7abc` is 7, `1,000` is 1, `--5` is −5), where the twin puts the size back; and ICU rounds some long fractions before Swift truncates them (`199.99999999999999` is 200, `0.99999999999999999` is 1, while `9007199254740993.5` stays …993 and `12.99999999999999` stays 12), a rule the measured cases do not pin down, so the twin truncates the digits as typed. Encoding finds no memory as `ExportError(render)` at `encode`'s door, so Export As's PNG worker never meets a `bad_alloc`. Equivalent mutant: the parser's `point <= 0` as `< 0` (a point at zero leaves no digits, which read as 0). Tests: `ExportPDFTests` (the page, its size, the straight pixels and alpha, rows and channels, the background, a refusal, resizing, flattening), `ExportPDFFailureTests` (a binary of its own: a 360-pixel PDF, small enough that Qt converts it on the calling thread (a pool thread that cannot start hangs Qt 6.4's conversion), under limits from 64 KB to 4 MB throws or inflates whole, both reached, and a PNG likewise throws or matches the unstarved file), `ExportAsSheetTests` (formats and their rows and bytes, the size and its limits, the checkerboard, the page against Swift 6.0.3's formatter), `JPEGPreviewTests::aZoomBeforeTheFirstImageCentresIt`, `ProjectExportTests` (each format through the controller, the menu's Export As on the last format), the entry in `CompositorMenusTests` and `KeyboardShortcutsTests` (its chord, group and place). Equivalent mutants: none found.
|
||||
- Filter › Scanlines (14.19, Swift 1.4.9: `06c3a22`, `1187736`, `cdde327`): Scanlines leaves Dither for a filter of its own. `kernels/DitherPixels.c/.h` are `cdde327`'s, with 13.17's adaptation carried on: Swift's GCD blocks become static band functions with context structs (`scanlines_tone_band`, `line_scan_band`, `blur_band`, `spread_band`, `column_band`, `split_band`), each failure flag an `atomic_int`, every band through `dither_bands`; the arithmetic is Swift's word for word, and `dither_glow`'s new easing near white came with it. `ScanlinesTests::theKernelDrawsSwiftsOwnBytes` holds that: Swift's own file, built unchanged with clang's blocks and libdispatch in the `swift:6.0.3` image, drew five scenes (37 by 53 and 70 by 300, every setting, both directions of Displace, 32 bands of columns, lines and rows) and a glow, and the twin's bytes hash the same (FNV-1a). `Document/Scanlines.h/.cpp` twin Swift's file: `ScanlinesSettings` with Swift's fields, defaults (glow 0 now, thickness 70, smoothness 50) and clamps, Line Spacing and Color Split rounded, `apply` handing the kernel the normalized settings and Two Colors' bytes (black on white otherwise), then 13.17's `glowing` moved here unchanged. `DitherStyle` loses `scanlines` (`usesPixelSize` is ASCII alone, `drawsMarks` every style without tones) and `DitherSettings` its four fields. `FilterKind::scanlines` ("Scanlines") sits after Dither in Swift's order, so the Filter menu lists it there; it previews whole, as Dither does. Its two colours reuse Dither's picker (`openDitherColorPicker`, `setDitherColor`, Swift's), choosing the edit's own settings, and the titles drop "Dither" (`Color Picker (Light Color)`, `(Dark Color)`). The sheet's `scanlines` (`UI/FilterSheet+Scanlines.cpp`) is Swift's `scanlinesControls`: twelve rows with Swift's ranges, units and help, then the Colors menu and swatches, which `colorChoices` builds for Dither too (the screen's and the lines' colour help for Scanlines). Equivalent mutant: `glowing` run at glow 0 (it adds nothing). Tests: `ScanlinesTests` (Swift's eight, Swift's own bytes, each setting reaching its field, every clamp, clear pixels, the eased glow against a full-size blur, the menu place and a commit, the sheet's rows, ranges and fields, both pickers), the order in `FilterModelTests`, `FinishingFilterTests`, `DitherSheetTests` and `CompositorMenusTests`, the acceptance run's Scanlines row through the menu.
|
||||
- Filter › Scanlines (14.19, Swift 1.4.9: `06c3a22`, `1187736`, `cdde327`): Scanlines leaves Dither for a filter of its own. `kernels/DitherPixels.c/.h` are `cdde327`'s, with 13.17's adaptation carried on: Swift's GCD blocks become static band functions with context structs (`scanlines_tone_band`, `line_scan_band`, `blur_band`, `spread_band`, `column_band`, `split_band`), each failure flag an `atomic_int`, every band through `dither_bands`; the arithmetic is Swift's word for word, and `dither_glow`'s new easing near white came with it. `ScanlinesTests::theKernelDrawsSwiftsOwnBytes` holds that: Swift's own file, built unchanged with clang's blocks and libdispatch in the `swift:6.0.3` image, drew five scenes (37 by 53 and 70 by 300, every setting, both directions of Displace, 32 bands of columns, lines and rows) and a glow, and the twin's bytes hash the same (FNV-1a). `Document/Scanlines.h/.cpp` twin Swift's file: `ScanlinesSettings` with Swift's fields, defaults (glow 0 now, thickness 70, smoothness 50) and clamps, Line Spacing and Color Split rounded, `apply` handing the kernel the normalized settings and Two Colors' bytes (black on white otherwise), then 13.17's `glowing` moved here unchanged. `DitherStyle` loses `scanlines` (`usesPixelSize` is ASCII alone, `drawsMarks` every style without tones) and `DitherSettings` its four fields. `FilterKind::scanlines` ("Scanlines") sits after Dither in Swift's order, so the Filter menu lists it there; it previews whole, as Dither does. Its two colours reuse Dither's picker (`openDitherColorPicker`, `setDitherColor`, Swift's), choosing the edit's own settings, and the titles drop "Dither" (`Color Picker (Light Color)`, `(Dark Color)`). The sheet's `scanlines` (`UI/FilterSheet+Scanlines.cpp`) is Swift's `scanlinesControls`: twelve rows with Swift's ranges, units and help, then the Colors menu and swatches, which `colorChoices` builds for Dither too (the screen's and the lines' colour help for Scanlines). Equivalent mutant: `glowing` run at glow 0 (it adds nothing). Tests: `ScanlinesTests` (Swift's eight, Swift's own bytes, each setting reaching its field, Two Colors rounded, every clamp through `FilterSettings` too, clear pixels, the eased glow against a full-size blur), `ScanlinesSheetTests` (the menu place and a commit, the sheet's rows, ranges and fields, both pickers), the order in `FilterModelTests`, `FinishingFilterTests`, `DitherSheetTests` and `CompositorMenusTests`, the acceptance run's Scanlines row through the menu.
|
||||
- Drops between projects: `ProjectWorkspace::draggedLayerSource` finds the tab whose document holds the dragged id (Swift reads the drag pasteboard; the twin reads the drag's `QMimeData`, which every drop target has), `canReceiveDrag(data, destination)` refuses only a layer's own tab, and `receiveProviders` copies several ids one after another, as Swift awaits each provider, so a two-row drop on the New button opens two tabs as Swift's does. `ContentView` takes such a drop over its whole area (`setWorkspace` hands it the workspace; `acceptsDrop` keeps Swift's guards: busy, the sheet, the importer, a rename; `levels` arrives with 9.x), shows the 3-point accent ring inside the canvas while targeted and hands the drop's document point on when it fell on the canvas. `ProjectTabButton` takes drops for its tab (accent fill and rim, "Add to <title>"), and `NewCanvasButton`, the toolbar's New canvas button with the action as its default, for a fresh tab ("Open in a new project tab"), both refusing an Alt drag, which duplicates in the panel; Swift's transient `NewTabDropSlot` in the strip has no twin, the New canvas button is `NewProjectDropTarget` already. Files and pictures arrived with 10.4.
|
||||
- `CanvasThumbnail` draws a layer or a mask inside the canvas's box at `backingScale` 2 (the panel's pixmaps carry that ratio); a mask's ground is `LayerMask::background`, white or black by its edge's majority, as the canvas treats it (Swift's `edgeTone` mean went with 12.12b). `LayerIcons` draws the panel's SF Symbols as paths, in one palette colour, like `ToolIcons`. `BlendModePicker` is a `QComboBox` whose popup previews the highlighted mode through `previewBlendMode` for the layer it opened on (Qt calls `hidePopup` before `activated`, so the preview, the target and the highlight are cleared from the event loop, after a choice had its chance) and refuses a choice once another layer is active. `LayerAppearanceControls` is Swift's blend and opacity row: the slider's press and release are one opacity drag (the release is watched application-wide while the slider is down, so a popup opened mid-drag cannot keep the step open), the percent field applies once through its `FocusOut`, which Return and Escape cause (Swift's `releasesFocusOnCommit`), and steps with Up and Down (Swift's `isFinite` test and the steps' clamp are left out: `setLayerOpacity` refuses a value that is no finite number and clamps the rest), and another active layer makes the controls anew, as Swift's `.id` does.
|
||||
- `ProjectWorkspaceView` is the `QMainWindow`: the front tab's `ContentView` as its central widget, made anew when another tab comes to the front, as SwiftUI's `.id` rebuilds it, and disabled while the workspace manages; the window holds the shown tab (`std::shared_ptr`) until the old editor is deleted, as Swift's views hold their session, so a replaced or closed tab's session never ends under its editor (`ProjectWorkspace::tab` is public for this); a `QToolBar` with the New canvas action, the `ProjectTabStrip` (which takes the toolbar's free width) and the four zoom actions, since SwiftUI's `.toolbar` modifier lives in `ContentView` but the toolbar belongs to the window. Its actions follow the front session's `changed()`, and on that signal the window syncs every tab's button as well, because a busy front tab dims the other tabs' buttons, which their own sessions' signals do not reach; the strip syncs its buttons on the workspace's signal, each button on its own session's. The window's title is the front tab's, with Qt's `[*]` placeholder, so `setWindowModified` can show the mark that `isDocumentEdited` shows; `setWindowFilePath` carries `representedURL`. The editor's own minimum size is cleared inside the window, which owns the 800 × 520 minimum for the whole, toolbar included. Closing the window ignores the event and asks the workspace (`closeWindow`), which confirms tab by tab and then closes the window again with the property `closeConfirmed` set, since the workspace may not include `UI/` headers; a confirmed close is accepted and the mark cleared, so a window shown again asks again. `ProjectTabStrip` is a plain `QWidget` whose buttons are kept for the tabs that stay, made for new tabs and deleted for tabs that went, and placed by hand from `projectTabOverflow` (13.14): every button at its own size hint, so no title is squeezed below Swift's 35 points, laid out again when the strip is resized, the workspace changes or any tab's session changes; it fills no background, so the toolbar shows through (a stylesheet would do the same but freezes the widgets' palette, so a theme switch would pass them by); the unsaved dot is a character before the title. Files named on the command line go to `ProjectWorkspace::receive`, as Finder's Open With reaches the delegate. Layer drops on tabs and the New canvas button are 4.7's; file and picture drops arrived with 10.4.
|
||||
|
||||
@@ -0,0 +1,196 @@
|
||||
#include "Document/BrushStroke.h"
|
||||
#include "Document/EditorSession.h"
|
||||
#include "Document/Scanlines.h"
|
||||
#include "UI/ColorPaletteControls.h"
|
||||
#include "UI/FilterSheet.h"
|
||||
#include <QComboBox>
|
||||
#include <QLabel>
|
||||
#include <QLayout>
|
||||
#include <QLineEdit>
|
||||
#include <QSlider>
|
||||
#include <QtTest>
|
||||
|
||||
// Swift 1.4.9's Scanlines in the Filter menu and its sheet.
|
||||
namespace {
|
||||
QImage filled(int width, int height, QColor colour)
|
||||
{
|
||||
QImage image = BrushRaster::context(width, height, false);
|
||||
image.fill(colour);
|
||||
return image;
|
||||
}
|
||||
|
||||
std::vector<int> column(const QImage &image, int x)
|
||||
{
|
||||
std::vector<int> values;
|
||||
for (int y = 0; y < image.height(); ++y)
|
||||
values.push_back(image.constScanLine(y)[x * 4]);
|
||||
return values;
|
||||
}
|
||||
|
||||
struct Shown {
|
||||
EditorSession session;
|
||||
std::unique_ptr<FilterSheet> sheet;
|
||||
Shown()
|
||||
{
|
||||
session.createDocument(40, 30);
|
||||
const QImage image = filled(40, 30, QColor(200, 120, 40));
|
||||
session.insert(ImportedImage(image, image, QStringLiteral("Colour")));
|
||||
session.beginFilter(FilterKind::scanlines);
|
||||
sheet = std::make_unique<FilterSheet>(session);
|
||||
sheet->show();
|
||||
}
|
||||
const ScanlinesSettings &lines() const { return session.filterEdit().value().settings.scanlines; }
|
||||
QStringList rows() const
|
||||
{
|
||||
QStringList titles;
|
||||
QLayout *column = sheet->layout();
|
||||
for (int index = 0; index < column->count(); ++index) {
|
||||
QWidget *each = column->itemAt(index)->widget();
|
||||
if (!each || each->isHidden())
|
||||
continue;
|
||||
for (QLabel *label : each->findChildren<QLabel *>(QString(), Qt::FindDirectChildrenOnly)) {
|
||||
if (label->buddy())
|
||||
titles << label->text() + u'|' + each->toolTip();
|
||||
}
|
||||
}
|
||||
return titles;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
class ScanlinesSheetTests : public QObject {
|
||||
Q_OBJECT
|
||||
private slots:
|
||||
void theFilterIsListedAndPreviewsWhole();
|
||||
void theSheetShowsSwiftsRows();
|
||||
void theRowsWriteTheirSettings();
|
||||
void twoColorsPickTheScreenAndTheLines();
|
||||
};
|
||||
|
||||
void ScanlinesSheetTests::theFilterIsListedAndPreviewsWhole()
|
||||
{
|
||||
QCOMPARE(rawValue(FilterKind::scanlines), QString("Scanlines"));
|
||||
const auto at = std::find(allFilterKinds.begin(), allFilterKinds.end(), FilterKind::scanlines);
|
||||
QVERIFY(at != allFilterKinds.end() && *(at - 1) == FilterKind::dither && *(at + 1) == FilterKind::tonalContrast);
|
||||
QVERIFY(!isImageAdjustment(FilterKind::scanlines) && !isAutomatic(FilterKind::scanlines) && repeatsAsLastFilter(FilterKind::scanlines));
|
||||
EditorSession session;
|
||||
session.createDocument(3000, 20);
|
||||
const QImage wide = filled(3000, 20, Qt::white);
|
||||
session.insert(ImportedImage(wide, wide, QStringLiteral("Wide")));
|
||||
session.beginFilter(FilterKind::scanlines);
|
||||
QCOMPARE(session.filterEdit().value().previewScale, 1.0);
|
||||
// Its commit is one step that draws the lines.
|
||||
QVERIFY(session.filterEdit().value().settings.scanlines == ScanlinesSettings());
|
||||
bool done = false;
|
||||
session.commitFilter([&done] { done = true; });
|
||||
QTRY_VERIFY(done);
|
||||
QCOMPARE(session.history.undoName(), QString("Scanlines"));
|
||||
const QImage drawn = session.document().value().layers.front().asset.value().image();
|
||||
// Beam 1.4 round the middle 2: row 0 covers 0.4.
|
||||
QCOMPARE(column(drawn, 5)[0], int(std::lround(255 * 1.35f * 0.4f)));
|
||||
QCOMPARE(column(drawn, 5)[2], 255);
|
||||
}
|
||||
|
||||
void ScanlinesSheetTests::theSheetShowsSwiftsRows()
|
||||
{
|
||||
Shown shown;
|
||||
QCOMPARE(shown.rows(),
|
||||
(QStringList{"Line Spacing|How far apart the screen's lines are", "Thickness|How much of the gap a bright line fills; dimmer parts draw it thinner",
|
||||
"Glow|Light blooming around the lines, like a CRT's phosphors",
|
||||
"Dots|Break the lines into beads where the picture is darker than this, blending into solid lines where it's brighter",
|
||||
"Displace|Lift the lines where the picture is bright, or lower them when negative, so they swell into its shapes",
|
||||
"Smoothness|How far the brightness is smoothed before it displaces the lines, from sharp ridges to rounded hills",
|
||||
"Threshold|Draw no line where the picture is darker than this, leaving the screen dark",
|
||||
"Wobble|Make the lines waver sideways down the screen, like a CRT losing sync",
|
||||
"Color Split|Move the red and blue apart, for colored fringes on the lines", "Density|Darker or lighter before the lines are drawn",
|
||||
"Contrast|", "Black Level|How bright the lines are where the picture is black, so they show even over black", "Colors|"}));
|
||||
using Field = double ScanlinesSettings::*;
|
||||
const std::tuple<const char *, Field, double, double, QString> sliders[] = {
|
||||
{"lineSpacing", &ScanlinesSettings::lineSpacing, 2, 32, "px"}, {"thickness", &ScanlinesSettings::thickness, 5, 100, "%"},
|
||||
{"glow", &ScanlinesSettings::glow, 0, 100, "%"}, {"dots", &ScanlinesSettings::dots, 0, 100, "%"},
|
||||
{"displace", &ScanlinesSettings::displace, -100, 100, "px"}, {"smoothness", &ScanlinesSettings::smoothness, 0, 100, "%"},
|
||||
{"threshold", &ScanlinesSettings::threshold, 0, 100, "%"}, {"wobble", &ScanlinesSettings::wobble, 0, 64, "px"},
|
||||
{"colorSplit", &ScanlinesSettings::split, 0, 16, "px"}, {"density", &ScanlinesSettings::density, -100, 100, ""},
|
||||
{"contrast", &ScanlinesSettings::contrast, -100, 100, ""}, {"blackLevel", &ScanlinesSettings::blackLevel, 0, 100, "%"}};
|
||||
for (const auto &[name, field, low, high, unit] : sliders) {
|
||||
QSlider *slider = shown.sheet->findChild<QSlider *>(QString::fromLatin1(name) + "Slider");
|
||||
QLineEdit *edit = shown.sheet->findChild<QLineEdit *>(QString::fromLatin1(name) + "Field");
|
||||
QVERIFY2(slider && edit, name);
|
||||
slider->setValue(slider->maximum());
|
||||
QCOMPARE(shown.lines().*field, high);
|
||||
slider->setValue(slider->minimum());
|
||||
QCOMPARE(shown.lines().*field, low);
|
||||
QCOMPARE(edit->parentWidget()->findChildren<QLabel *>(QString(), Qt::FindDirectChildrenOnly).last()->text(), unit);
|
||||
}
|
||||
}
|
||||
|
||||
void ScanlinesSheetTests::theRowsWriteTheirSettings()
|
||||
{
|
||||
Shown shown;
|
||||
const std::tuple<const char *, double ScanlinesSettings::*, const char *, double> rows[] = {
|
||||
{"lineSpacingField", &ScanlinesSettings::lineSpacing, "12", 12}, {"displaceField", &ScanlinesSettings::displace, "-30", -30},
|
||||
{"colorSplitField", &ScanlinesSettings::split, "5", 5}, {"blackLevelField", &ScanlinesSettings::blackLevel, "40", 40},
|
||||
{"smoothnessField", &ScanlinesSettings::smoothness, "10", 10}, {"thicknessField", &ScanlinesSettings::thickness, "55", 55}};
|
||||
for (const auto &[name, field, typed, expected] : rows) {
|
||||
ScanlinesSettings wanted = shown.lines();
|
||||
QLineEdit *edit = shown.sheet->findChild<QLineEdit *>(QString::fromLatin1(name));
|
||||
QVERIFY2(edit, name);
|
||||
edit->setFocus();
|
||||
edit->selectAll();
|
||||
QTest::keyClicks(edit, QString::fromLatin1(typed));
|
||||
QTest::keyClick(edit, Qt::Key_Return);
|
||||
wanted.*field = expected;
|
||||
QVERIFY2(shown.lines() == wanted, name);
|
||||
}
|
||||
}
|
||||
|
||||
void ScanlinesSheetTests::twoColorsPickTheScreenAndTheLines()
|
||||
{
|
||||
Shown shown;
|
||||
auto *colors = shown.sheet->findChild<QComboBox *>(QStringLiteral("scanlinesColors"));
|
||||
auto *dark = shown.sheet->findChild<SwatchButton *>(QStringLiteral("scanlinesDark"));
|
||||
auto *light = shown.sheet->findChild<SwatchButton *>(QStringLiteral("scanlinesLight"));
|
||||
QVERIFY(colors && dark && light && !dark->isVisible());
|
||||
QVERIFY(dark->toolTip() == QString("Choose the screen's color") && light->toolTip() == QString("Choose the lines' color"));
|
||||
colors->activated(int(DitherColors::twoColors));
|
||||
QVERIFY(shown.lines().colors == DitherColors::twoColors && dark->isVisible() && light->isVisible());
|
||||
// The menu follows the settings, however they change.
|
||||
FilterSettings original = shown.session.filterEdit().value().settings;
|
||||
original.scanlines.colors = DitherColors::original;
|
||||
shown.session.updateFilter(original, true);
|
||||
QVERIFY(colors->currentIndex() == int(DitherColors::original) && !dark->isVisible());
|
||||
original.scanlines.colors = DitherColors::twoColors;
|
||||
shown.session.updateFilter(original, true);
|
||||
QCOMPARE(colors->currentIndex(), int(DitherColors::twoColors));
|
||||
// The picker starts from the lines' own colour.
|
||||
FilterSettings settings = shown.session.filterEdit().value().settings;
|
||||
settings.scanlines.light = AdjustmentColor(0, 1, 0), settings.scanlines.dark = AdjustmentColor(0.2, 0, 0);
|
||||
shown.session.updateFilter(settings, true);
|
||||
light->click();
|
||||
QCOMPARE(shown.session.colorPicker().value().target.title(), QString("Color Picker (Light Color)"));
|
||||
QVERIFY(shown.session.colorPicker().value().original == (PaletteColor{0, 1, 0}));
|
||||
struct Paints : QObject {
|
||||
int count = 0;
|
||||
bool eventFilter(QObject *, QEvent *event) override { return count += event->type() == QEvent::Paint, false; }
|
||||
} paints;
|
||||
QCoreApplication::processEvents();
|
||||
light->installEventFilter(&paints);
|
||||
shown.session.setColorPickerHSB(PickerHSB(PaletteColor{1, 0, 0}));
|
||||
shown.session.previewDitherColor();
|
||||
// A new colour repaints the swatch.
|
||||
QTRY_VERIFY(paints.count > 0);
|
||||
QVERIFY(shown.lines().light == AdjustmentColor(1, 0, 0));
|
||||
QVERIFY(shown.session.filterEdit().value().settings.dither.light == AdjustmentColor(1, 1, 1));
|
||||
QCOMPARE(light->grab().toImage().pixelColor(12, 12), QColor(255, 0, 0));
|
||||
shown.session.closeColorPicker(false);
|
||||
QVERIFY(shown.lines().light == AdjustmentColor(0, 1, 0));
|
||||
dark->click();
|
||||
QCOMPARE(shown.session.colorPicker().value().target.title(), QString("Color Picker (Dark Color)"));
|
||||
QVERIFY(shown.session.colorPicker().value().original == (PaletteColor{0.2, 0, 0}));
|
||||
shown.session.setColorPickerHSB(PickerHSB(PaletteColor{0, 0, 1}));
|
||||
shown.session.closeColorPicker(true);
|
||||
QVERIFY(shown.lines().dark == AdjustmentColor(0, 0, 1));
|
||||
}
|
||||
|
||||
QTEST_MAIN(ScanlinesSheetTests)
|
||||
#include "ScanlinesSheetTests.moc"
|
||||
+16
-165
@@ -2,14 +2,7 @@
|
||||
#include "Document/EditorSession.h"
|
||||
#include "Document/PixelAdjust.h"
|
||||
#include "Document/Scanlines.h"
|
||||
#include "UI/ColorPaletteControls.h"
|
||||
#include "UI/FilterSheet.h"
|
||||
#include <QComboBox>
|
||||
#include <QLabel>
|
||||
#include <QLayout>
|
||||
#include <QLineEdit>
|
||||
#include <QPainter>
|
||||
#include <QSlider>
|
||||
#include <QtTest>
|
||||
#include <numeric>
|
||||
extern "C" {
|
||||
@@ -102,35 +95,6 @@ QImage kernel(int width, int height, const ScanlinesParams ¶ms)
|
||||
return image;
|
||||
}
|
||||
|
||||
struct Shown {
|
||||
EditorSession session;
|
||||
std::unique_ptr<FilterSheet> sheet;
|
||||
Shown()
|
||||
{
|
||||
session.createDocument(40, 30);
|
||||
const QImage image = filled(40, 30, QColor(200, 120, 40));
|
||||
session.insert(ImportedImage(image, image, QStringLiteral("Colour")));
|
||||
session.beginFilter(FilterKind::scanlines);
|
||||
sheet = std::make_unique<FilterSheet>(session);
|
||||
sheet->show();
|
||||
}
|
||||
const ScanlinesSettings &lines() const { return session.filterEdit().value().settings.scanlines; }
|
||||
QStringList rows() const
|
||||
{
|
||||
QStringList titles;
|
||||
QLayout *column = sheet->layout();
|
||||
for (int index = 0; index < column->count(); ++index) {
|
||||
QWidget *each = column->itemAt(index)->widget();
|
||||
if (!each || each->isHidden())
|
||||
continue;
|
||||
for (QLabel *label : each->findChildren<QLabel *>(QString(), Qt::FindDirectChildrenOnly)) {
|
||||
if (label->buddy())
|
||||
titles << label->text() + u'|' + each->toolTip();
|
||||
}
|
||||
}
|
||||
return titles;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
class ScanlinesTests : public QObject {
|
||||
@@ -149,10 +113,6 @@ private slots:
|
||||
void normalizingClampsEverySetting();
|
||||
void clearPixelsStayClear();
|
||||
void theGlowIsTheBlurredLightEasedNearWhite();
|
||||
void theFilterIsListedAndPreviewsWhole();
|
||||
void theSheetShowsSwiftsRows();
|
||||
void theRowsWriteTheirSettings();
|
||||
void twoColorsPickTheScreenAndTheLines();
|
||||
};
|
||||
|
||||
void ScanlinesTests::scanlinesAreLinesOfLightThatBloomWithBrightness()
|
||||
@@ -279,6 +239,17 @@ void ScanlinesTests::theSettingsReachTheKernel()
|
||||
settings.lineSpacing = 5, settings.thickness = 40, settings.contrast = 60, settings.colors = DitherColors::twoColors;
|
||||
settings.dark = AdjustmentColor(10 / 255.0, 20 / 255.0, 200 / 255.0), settings.light = AdjustmentColor(250 / 255.0, 200 / 255.0, 10 / 255.0);
|
||||
QCOMPARE(settings.apply(pattern(37, 53)), kernel(37, 53, made([](ScanlinesParams &p) { p.spacing = 5; p.thickness = 0.4f; p.contrast = 0.6f; p.smoothness = 0.5f; rgb(p.dark, 10, 20, 200); rgb(p.light, 250, 200, 10); })));
|
||||
// Half a channel rounds to 128, lit at 1.35 times.
|
||||
ScanlinesSettings halves;
|
||||
halves.colors = DitherColors::twoColors, halves.dark = AdjustmentColor(0.5, 0.5, 0.5), halves.light = AdjustmentColor(0.5, 0.5, 0.5);
|
||||
const QImage greyLines = halves.apply(filled(8, 8, Qt::white));
|
||||
const int lit = int(std::lround(128 / 255.0f * 1.35f * 255));
|
||||
const auto pixel = [&greyLines](int y) {
|
||||
const uchar *at = greyLines.constScanLine(y);
|
||||
return std::array<int, 4>{at[0], at[1], at[2], at[3]};
|
||||
};
|
||||
QCOMPARE(pixel(1), (std::array<int, 4>{lit, lit, lit, 255}));
|
||||
QCOMPARE(pixel(0)[0], int(std::lround(128 + (lit - 128) * 0.4f)));
|
||||
// Picked colours count only for Two Colors.
|
||||
settings.colors = DitherColors::blackWhite;
|
||||
QCOMPARE(settings.apply(pattern(37, 53)), kernel(37, 53, made([](ScanlinesParams &p) { p.spacing = 5; p.thickness = 0.4f; p.contrast = 0.6f; p.smoothness = 0.5f; })));
|
||||
@@ -317,6 +288,11 @@ void ScanlinesTests::normalizingClampsEverySetting()
|
||||
wild.lineSpacing = 5.6, wild.thickness = 500, wild.split = 2.4, wild.displace = 300;
|
||||
QCOMPARE(wild.apply(pattern(37, 53)), wild.normalized().apply(pattern(37, 53)));
|
||||
QCOMPARE(fnv(wild.apply(pattern(37, 53))), fnv(kernel(37, 53, made([](ScanlinesParams &p) { p.spacing = 6; p.thickness = 1; p.split = 2; p.displace = 100; p.smoothness = 0.5f; }))));
|
||||
// The filter's settings normalize Scanlines with the rest.
|
||||
FilterSettings filter;
|
||||
filter.scanlines = wild;
|
||||
QVERIFY(filter.normalized().scanlines == wild.normalized());
|
||||
QVERIFY(filter.normalized().scanlines.lineSpacing == 6 && filter.normalized().scanlines.thickness == 100 && filter.normalized().scanlines.split == 2);
|
||||
ScanlinesSettings colours;
|
||||
colours.dark = AdjustmentColor(-1, 2, 0.5), colours.light = AdjustmentColor(3, -2, 0.25);
|
||||
QVERIFY(colours.normalized().dark == AdjustmentColor(0, 1, 0.5) && colours.normalized().light == AdjustmentColor(1, 0, 0.25));
|
||||
@@ -358,130 +334,5 @@ void ScanlinesTests::theGlowIsTheBlurredLightEasedNearWhite()
|
||||
}
|
||||
}
|
||||
|
||||
void ScanlinesTests::theFilterIsListedAndPreviewsWhole()
|
||||
{
|
||||
QCOMPARE(rawValue(FilterKind::scanlines), QString("Scanlines"));
|
||||
const auto at = std::find(allFilterKinds.begin(), allFilterKinds.end(), FilterKind::scanlines);
|
||||
QVERIFY(at != allFilterKinds.end() && *(at - 1) == FilterKind::dither && *(at + 1) == FilterKind::tonalContrast);
|
||||
QVERIFY(!isImageAdjustment(FilterKind::scanlines) && !isAutomatic(FilterKind::scanlines) && repeatsAsLastFilter(FilterKind::scanlines));
|
||||
EditorSession session;
|
||||
session.createDocument(3000, 20);
|
||||
const QImage wide = filled(3000, 20, Qt::white);
|
||||
session.insert(ImportedImage(wide, wide, QStringLiteral("Wide")));
|
||||
session.beginFilter(FilterKind::scanlines);
|
||||
QCOMPARE(session.filterEdit().value().previewScale, 1.0);
|
||||
// Its commit is one step that draws the lines.
|
||||
QVERIFY(session.filterEdit().value().settings.scanlines == ScanlinesSettings());
|
||||
bool done = false;
|
||||
session.commitFilter([&done] { done = true; });
|
||||
QTRY_VERIFY(done);
|
||||
QCOMPARE(session.history.undoName(), QString("Scanlines"));
|
||||
const QImage drawn = session.document().value().layers.front().asset.value().image();
|
||||
// Beam 1.4 round the middle 2: row 0 covers 0.4.
|
||||
QCOMPARE(column(drawn, 5)[0], int(std::lround(255 * 1.35f * 0.4f)));
|
||||
QCOMPARE(column(drawn, 5)[2], 255);
|
||||
}
|
||||
|
||||
void ScanlinesTests::theSheetShowsSwiftsRows()
|
||||
{
|
||||
Shown shown;
|
||||
QCOMPARE(shown.rows(),
|
||||
(QStringList{"Line Spacing|How far apart the screen's lines are", "Thickness|How much of the gap a bright line fills; dimmer parts draw it thinner",
|
||||
"Glow|Light blooming around the lines, like a CRT's phosphors",
|
||||
"Dots|Break the lines into beads where the picture is darker than this, blending into solid lines where it's brighter",
|
||||
"Displace|Lift the lines where the picture is bright, or lower them when negative, so they swell into its shapes",
|
||||
"Smoothness|How far the brightness is smoothed before it displaces the lines, from sharp ridges to rounded hills",
|
||||
"Threshold|Draw no line where the picture is darker than this, leaving the screen dark",
|
||||
"Wobble|Make the lines waver sideways down the screen, like a CRT losing sync",
|
||||
"Color Split|Move the red and blue apart, for colored fringes on the lines", "Density|Darker or lighter before the lines are drawn",
|
||||
"Contrast|", "Black Level|How bright the lines are where the picture is black, so they show even over black", "Colors|"}));
|
||||
using Field = double ScanlinesSettings::*;
|
||||
const std::tuple<const char *, Field, double, double, QString> sliders[] = {
|
||||
{"lineSpacing", &ScanlinesSettings::lineSpacing, 2, 32, "px"}, {"thickness", &ScanlinesSettings::thickness, 5, 100, "%"},
|
||||
{"glow", &ScanlinesSettings::glow, 0, 100, "%"}, {"dots", &ScanlinesSettings::dots, 0, 100, "%"},
|
||||
{"displace", &ScanlinesSettings::displace, -100, 100, "px"}, {"smoothness", &ScanlinesSettings::smoothness, 0, 100, "%"},
|
||||
{"threshold", &ScanlinesSettings::threshold, 0, 100, "%"}, {"wobble", &ScanlinesSettings::wobble, 0, 64, "px"},
|
||||
{"colorSplit", &ScanlinesSettings::split, 0, 16, "px"}, {"density", &ScanlinesSettings::density, -100, 100, ""},
|
||||
{"contrast", &ScanlinesSettings::contrast, -100, 100, ""}, {"blackLevel", &ScanlinesSettings::blackLevel, 0, 100, "%"}};
|
||||
for (const auto &[name, field, low, high, unit] : sliders) {
|
||||
QSlider *slider = shown.sheet->findChild<QSlider *>(QString::fromLatin1(name) + "Slider");
|
||||
QLineEdit *edit = shown.sheet->findChild<QLineEdit *>(QString::fromLatin1(name) + "Field");
|
||||
QVERIFY2(slider && edit, name);
|
||||
slider->setValue(slider->maximum());
|
||||
QCOMPARE(shown.lines().*field, high);
|
||||
slider->setValue(slider->minimum());
|
||||
QCOMPARE(shown.lines().*field, low);
|
||||
QCOMPARE(edit->parentWidget()->findChildren<QLabel *>(QString(), Qt::FindDirectChildrenOnly).last()->text(), unit);
|
||||
}
|
||||
}
|
||||
|
||||
void ScanlinesTests::theRowsWriteTheirSettings()
|
||||
{
|
||||
Shown shown;
|
||||
const std::tuple<const char *, double ScanlinesSettings::*, const char *, double> rows[] = {
|
||||
{"lineSpacingField", &ScanlinesSettings::lineSpacing, "12", 12}, {"displaceField", &ScanlinesSettings::displace, "-30", -30},
|
||||
{"colorSplitField", &ScanlinesSettings::split, "5", 5}, {"blackLevelField", &ScanlinesSettings::blackLevel, "40", 40},
|
||||
{"smoothnessField", &ScanlinesSettings::smoothness, "10", 10}, {"thicknessField", &ScanlinesSettings::thickness, "55", 55}};
|
||||
for (const auto &[name, field, typed, expected] : rows) {
|
||||
ScanlinesSettings wanted = shown.lines();
|
||||
QLineEdit *edit = shown.sheet->findChild<QLineEdit *>(QString::fromLatin1(name));
|
||||
QVERIFY2(edit, name);
|
||||
edit->setFocus();
|
||||
edit->selectAll();
|
||||
QTest::keyClicks(edit, QString::fromLatin1(typed));
|
||||
QTest::keyClick(edit, Qt::Key_Return);
|
||||
wanted.*field = expected;
|
||||
QVERIFY2(shown.lines() == wanted, name);
|
||||
}
|
||||
}
|
||||
|
||||
void ScanlinesTests::twoColorsPickTheScreenAndTheLines()
|
||||
{
|
||||
Shown shown;
|
||||
auto *colors = shown.sheet->findChild<QComboBox *>(QStringLiteral("scanlinesColors"));
|
||||
auto *dark = shown.sheet->findChild<SwatchButton *>(QStringLiteral("scanlinesDark"));
|
||||
auto *light = shown.sheet->findChild<SwatchButton *>(QStringLiteral("scanlinesLight"));
|
||||
QVERIFY(colors && dark && light && !dark->isVisible());
|
||||
QVERIFY(dark->toolTip() == QString("Choose the screen's color") && light->toolTip() == QString("Choose the lines' color"));
|
||||
colors->activated(int(DitherColors::twoColors));
|
||||
QVERIFY(shown.lines().colors == DitherColors::twoColors && dark->isVisible() && light->isVisible());
|
||||
// The menu follows the settings, however they change.
|
||||
FilterSettings original = shown.session.filterEdit().value().settings;
|
||||
original.scanlines.colors = DitherColors::original;
|
||||
shown.session.updateFilter(original, true);
|
||||
QVERIFY(colors->currentIndex() == int(DitherColors::original) && !dark->isVisible());
|
||||
original.scanlines.colors = DitherColors::twoColors;
|
||||
shown.session.updateFilter(original, true);
|
||||
QCOMPARE(colors->currentIndex(), int(DitherColors::twoColors));
|
||||
// The picker starts from the lines' own colour.
|
||||
FilterSettings settings = shown.session.filterEdit().value().settings;
|
||||
settings.scanlines.light = AdjustmentColor(0, 1, 0), settings.scanlines.dark = AdjustmentColor(0.2, 0, 0);
|
||||
shown.session.updateFilter(settings, true);
|
||||
light->click();
|
||||
QCOMPARE(shown.session.colorPicker().value().target.title(), QString("Color Picker (Light Color)"));
|
||||
QVERIFY(shown.session.colorPicker().value().original == (PaletteColor{0, 1, 0}));
|
||||
struct Paints : QObject {
|
||||
int count = 0;
|
||||
bool eventFilter(QObject *, QEvent *event) override { return count += event->type() == QEvent::Paint, false; }
|
||||
} paints;
|
||||
QCoreApplication::processEvents();
|
||||
light->installEventFilter(&paints);
|
||||
shown.session.setColorPickerHSB(PickerHSB(PaletteColor{1, 0, 0}));
|
||||
shown.session.previewDitherColor();
|
||||
// A new colour repaints the swatch.
|
||||
QTRY_VERIFY(paints.count > 0);
|
||||
QVERIFY(shown.lines().light == AdjustmentColor(1, 0, 0));
|
||||
QVERIFY(shown.session.filterEdit().value().settings.dither.light == AdjustmentColor(1, 1, 1));
|
||||
QCOMPARE(light->grab().toImage().pixelColor(12, 12), QColor(255, 0, 0));
|
||||
shown.session.closeColorPicker(false);
|
||||
QVERIFY(shown.lines().light == AdjustmentColor(0, 1, 0));
|
||||
dark->click();
|
||||
QCOMPARE(shown.session.colorPicker().value().target.title(), QString("Color Picker (Dark Color)"));
|
||||
QVERIFY(shown.session.colorPicker().value().original == (PaletteColor{0.2, 0, 0}));
|
||||
shown.session.setColorPickerHSB(PickerHSB(PaletteColor{0, 0, 1}));
|
||||
shown.session.closeColorPicker(true);
|
||||
QVERIFY(shown.lines().dark == AdjustmentColor(0, 0, 1));
|
||||
}
|
||||
|
||||
QTEST_MAIN(ScanlinesTests)
|
||||
#include "ScanlinesTests.moc"
|
||||
@@ -185,6 +185,7 @@ compositor_test(QuitPendingEditsTests)
|
||||
compositor_test(ScanlinesTests)
|
||||
# It checks the kernel against Swift's own bytes.
|
||||
target_include_directories(ScanlinesTests PRIVATE ${OMAPHOTO_KERNELS})
|
||||
compositor_test(ScanlinesSheetTests)
|
||||
compositor_test(CameraRawCurveTests)
|
||||
compositor_test(CameraRawCurveGraphTests)
|
||||
compositor_test(OpenRecentTests)
|
||||
|
||||
Reference in new issue
Block a user