diff --git a/AGENTS.md b/AGENTS.md index 29a4041..d5ec633 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -187,7 +187,7 @@ Platform adaptations, each forced by a missing Qt analog: - Rotate Canvas 90° (14.4, Swift 1.4.6: `754f188`): `Document/CanvasRotation.cpp` twins Swift's file, `CanvasRotation+Session.h` its session half; `LayerTransform::quarterTurned` and `CanvasGuide::quarterTurned` are declared in their own headers and defined there, as `mirrored` is. `rotateCanvas` commits a transform edit and drops a crop frame first, asks `canEditLayers`, then turns every layer and placed mask about the canvas (the middle carried, the angle by ±90 through `fmod`, which keeps Swift's sign), swaps the sides in place, turns the guides and the selection's path (its feather and antialiasing kept), fits the view, one `Rotate Canvas 90° Clockwise` or `Counterclockwise` step; Swift's `finishOpacityEdit` is dead (`commitTransform` runs it, as `flipCanvas` notes) and left out. `restore` fits the view when the canvas changes size too. The Image menu lists both entries before the flips, enabled by `canEditLayers`. A fix the item's exact test found: QPainter turned a layer through `rotateRadians`, whose cos(π/2) is 6e-17, so a turned edge missed its pixel boundary and antialiasing shaved it, and its fixed-point bilinear fetch strayed a level or two (40 read 39) where CoreGraphics' low quality copies a pixel-aligned turn exactly. Every layer placement now turns through `LayerTransform::degrees()` and `QTransform::rotate`, which Qt builds exactly at ±90, ±270 and 180 and as `rotateRadians` elsewhere, and `LayerRenderer::upright` keeps Swift's upright (no turn) and adds a draw that takes image pixels onto device pixels one to one: the whole map from the image's pixels through its target rect, the placement and the painter's device transform is a signed permutation (no stretch on either axis, no shear, no perspective, the painter's own turn counted), within a thousandth of a pixel across the image, with the image's corner on a whole device pixel. Such a draw takes no filter; a turn half a pixel off, a stretched side or a turned painter still filters, as CoreGraphics' low quality blends them. Equivalent mutants: `degrees()` in `BrushStroke`'s grid map, `Distort` and `LayerMask` (the two matrices differ by 1e-16 there; the change keeps every placement one turn). Tests: `CanvasRotationTests` (Swift's four, a turned layer and a placed mask, the crop frame, the refit, refusals and steps), `SharpCanvasTests::aQuarterTurnOnWholePixelsCopiesAcross` (the rule's edges: every quarter, a nudge on either axis, a stretched side, a 30,000-pixel side leaning 0.0001°, painters turned, sheared and in perspective; plain and painted layers exact on whole pixels and filtered half off or stretched), `everyLayerAndEveryPlacedMaskTurns`, `anOpenEditClosesBeforeTheTurn` (an opacity drag and a pending transform each their own step), the menu in `ImageMenuTests`. - The command palette (14.6, Swift 1.4.6–1.4.9: `cb139a1`, `384632d`, `07b8b1e`, `94b57f7`, `bba92dc`, `088a5c1`, `720c121`): `UI/CommandPalette.h/.cpp` twin Swift's `CommandPalette.swift`: `CommandPaletteEntry` (an aggregate, `title` given beside `id`), `CommandPaletteSearch` (`score` and `rank`, a stable sort), `CommandPaletteMenu` (`entries` of a `QMenuBar`, `plain` for a title without its mnemonic, `&&` read as one ampersand), `CommandPaletteCommands` (`layerCommands`, `tools`, Swift's statics on the entry) and `CommandPaletteModel`. Scores work on graphemes (`QTextBoundaryFinder`) of the NFC text, Swift's Characters, which compare canonically (a decomposed accent in a recent project's name matches a composed one); `isLetter` and `isNumber` read the first code point's general category (`QChar`), where Swift reads its Alphabetic and numeric-type properties (known difference: marks and numeric ideographs). `CommandPaletteTests::scoresAreSwiftsOwn` pins scores Swift 6.0.3 computed with v1.4.9's own code. An entry holds a `QPointer` to its `QAction` and triggers it, where Swift finds the item again by its path (SwiftUI rebuilds menus; the twin's actions live with the window, and Open Recent's rebuilt entries become a warning on `omaphoto.app`, Swift's beep); Swift's app-menu skip has no twin (no app menu on Linux), and the menus are current already, synchronized on every `changed()`. Shortcuts print as `QKeySequence` native text. `UI/CommandPaletteView.h/.cpp` twin the view and controller: View › Search Commands… (Ctrl+F, first in View, `Search Commands` in `ShortcutDefinition::all` after Fit Canvas) toggles a `Qt::Popup` of 460 by 290 centred on the window's frame, so a click elsewhere puts it away (Swift's `resignKey`) and Wayland places it relative to its window; the menu's action is added to the popup, so its key, remapped too, closes it from inside. The field (17 pixels, 16 and 13 of margin) takes Up and Down (wrapping, the row scrolled into view), Return and Enter; Escape is the popup's own. The rows (`CommandPaletteRows`, painted: 13 pixels, the chosen row in the accent at 35% rounded 6, a drawn checkmark twelve points with six after for a toggle that is on, the key in a 12-pixel fixed font in `PlaceholderText`, a disabled entry in the disabled `WindowText`) run on a left release; "No commands match" shows over an empty list. Running closes the popup, activates the window and posts the entry to the event loop; a disabled entry warns and keeps it open. A hidden popup clears the focus it held: Qt returns focus only to a window's own focus widget, so the menus would otherwise keep the hidden field as the one whose undo Undo drives. Equivalent mutants: `score`'s `words.size() > 1` (one word is the phrase, which the tier before tried) and `rank`'s `!query.isEmpty()` (an empty query scores every entry 0). Tests: `CommandPaletteTests` (Swift's four model tests and Swift's scores, the model, a hand-built bar's paths, mnemonics, sections, hidden entries, numbering and a gone action, the real bar's entries and a toggle run through them, the mask commands, every tool and each named mode reached from its sibling, a refused tool), `CommandPaletteWindowTests` (Ctrl+F in the window, place, focus, Ctrl+F inside, ranking and wrapping with scrolling, Return and Enter running the chosen row once the loop is free, a disabled row, Escape, clicks in and out, the checkmark's room, a key drawn at the row's end with an elided title six points before it, the empty words). - Canvas Only (14.7, Swift 1.4.6–1.4.7: `ad4bddf`, `088a5c1`, `720c121`): the session keeps `canvasOnly` (a getter and a setter that notifies), `escapeHasNothingToCancel` and `canToggleCanvasOnly` (Swift's terms). `ProjectWorkspaceView::toggleCanvasOnly` is Swift's delegate's: it keeps the window's state, hides the menu bar (Swift hides macOS's menu bar and Dock; the twin's menu bar is in the window) and the toolbar, and makes the window fullscreen, which on Linux also covers the desktop's own bars; again, it shows both and puts the state back. A window already fullscreen keeps the screen and hides only its toolbar, as Swift's. Swift's black frame over the window's rounded corners and rim has no twin: a fullscreen Linux window has neither. View › Toggle Fullscreen (after Search Commands, checkable, a plain F, Swift's unconfigured key; its definition joins the canvas group first, as Swift's) rests while `canToggleCanvasOnly` does not hold; a `QLineEdit` takes a plain letter through `ShortcutOverride`, so a field types its F, Swift's monitor that hands an F to an `NSText` first, and open text holds the entry resting. A hidden `QMenuBar` disables its actions' keys (Qt's shortcut context reads the bar's visibility), so every menu action is also added to the window, which keeps them live. Escape leaves (an application event filter, Swift's local monitor) when it carries no Ctrl, Alt, Meta or Shift, the window is active, nothing is left to cancel and the focus is neither a `QLineEdit` nor inside a `QDialog`, so a docked panel keeps its Escape (Swift's docked panel is a window of its own). `ContentView` hides the tool bar, the rail, the rulers, the layers panel and its edge, the status bar and their dividers (`m_panels`); `showHeader` clears `m_header` after deleting it, since a new bar's constructor signals and `synchronize` then finds no bar. The canvas's surround is black, and `DisplayState` carries the flag so it repaints. Tests: `CanvasOnlySessionTests` (the flag's signal, each gate term and each Escape term), the definitions' place in `KeyboardShortcutsTests`, `CanvasOnlyWindowTests` (F in and out with every bar and the layers edge, the canvas filling the window, keys through the hidden menus, black, Escape after a cancel and with held keys, a field's F, a docked panel's and another window's Escape, an already fullscreen or maximised window, the entry resting under text, a picker and no document). -- Camera Raw's colour noise reduction (14.8, Swift 1.4.6: `a2718d9`, `42a559b`): `kernels/AdjustPixels.c` is 42a559b's, unchanged: Color smooths each pixel's red and blue differences from its Rec. 709 brightness toward the area's (each weighted by coverage, so clear pixels add no colour and pull none toward gray), green following from the brightness kept, over a reach that grows with the amount and Color Smoothness; Color Detail keeps edges where the smoothed colour itself changes across the blur's width. Tests: `CameraRawColorNoiseTests` (Swift's two: colour grain under a quarter with brightness within a level, and a run that reads nothing clear pixels left behind, made sharp by `mallopt`: the planes on the heap, `M_PERTURB` filling what is handed out, so a plane left unwritten differs from run to run; then half the amount, a red beside clear pixels kept, an edge kept by Color Detail down and across, a speck taking its surround's colour at its own brightness, translucent colour kept, and exact pixels of the upstream kernel for a faint neighbour's coverage and for Color Smoothness at 0 and 100). +- Camera Raw's colour noise reduction (14.8, Swift 1.4.6: `a2718d9`, `42a559b`): `kernels/AdjustPixels.c` is 42a559b's, unchanged: Color smooths each pixel's red and blue differences from its Rec. 709 brightness toward the area's (each weighted by coverage, so clear pixels add no colour and pull none toward gray), green following from the brightness kept, over a reach that grows with the amount and Color Smoothness; Color Detail keeps edges where the smoothed colour itself changes across the blur's width. Tests: `CameraRawColorNoiseTests` (Swift's two: colour grain under a quarter with brightness within a level, and a run that reads nothing clear pixels left behind, made sharp by `mallopt`: the planes on the heap, `M_PERTURB` filling what is handed out, so a plane left unwritten differs from run to run; then half the amount, a red beside clear pixels kept, an edge kept by Color Detail down and across, a speck taking its surround's colour at its own brightness, translucent colour kept, and exact pixels of the upstream kernel for a faint neighbour's coverage, Color Smoothness at 0 and 100, a partial amount, a reduced preview, a lone pixel among clear ones, and edges in the red or the blue difference alone, down and across). - 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 "), 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. diff --git a/tests/CameraRawColorNoiseTests.cpp b/tests/CameraRawColorNoiseTests.cpp index 429e60e..d77804d 100644 --- a/tests/CameraRawColorNoiseTests.cpp +++ b/tests/CameraRawColorNoiseTests.cpp @@ -59,6 +59,7 @@ private slots: void aSpeckTakesTheColorAroundItAndKeepsItsBrightness(); void translucentPixelsKeepTheirColor(); void coverageWeighsNeighboursAndSmoothnessReaches(); + void blueAloneMakesAnEdgeAndTheReachFollowsAmountAndScale(); }; void CameraRawColorNoiseTests::colorNoiseReductionRemovesColorGrainNotBrightness() @@ -123,6 +124,10 @@ void CameraRawColorNoiseTests::clearPixelsPullNoColorTowardGray() QVERIFY2(std::abs(beside[0] - 230) <= 1 && std::abs(beside[1] - 51) <= 1 && std::abs(beside[2] - 51) <= 1, qPrintable(QStringLiteral("%1 %2 %3").arg(beside[0]).arg(beside[1]).arg(beside[2]))); QCOMPARE(smoothed[size_t(10 * 40 + 5)][3], 0); + // A lone pixel among clear ones keeps its colour too. + QImage lone = BrushRaster::context(31, 31, false); + lone.setPixelColor(15, 15, QColor(230, 51, 51)); + QCOMPARE(pixels(colorNoise(100).apply(lone))[size_t(15 * 31 + 15)], (std::array<int, 4>{230, 51, 51, 255})); } void CameraRawColorNoiseTests::colorDetailKeepsARealColorEdge() @@ -173,5 +178,33 @@ void CameraRawColorNoiseTests::coverageWeighsNeighboursAndSmoothnessReaches() QCOMPARE(pixels(colorNoise(100, 0, 100).apply(split(255)))[size_t(10 * 31 + 9)], (Pixel{203, 55, 87, 255})); } +void CameraRawColorNoiseTests::blueAloneMakesAnEdgeAndTheReachFollowsAmountAndScale() +{ + using Pixel = std::array<int, 4>; + // Two opaque halves, 60 by 20, meeting at x 30. + const auto halves = [](QColor left, QColor right) { + QImage picture = BrushRaster::context(60, 20, false); + QPainter painter(&picture); + painter.fillRect(QRect(0, 0, 30, 20), left); + painter.fillRect(QRect(30, 0, 30, 20), right); + return picture; + }; + // An edge mostly in the blue difference: Detail keeps it. + const QImage blue = halves(QColor(102, 115, 26), QColor(102, 100, 179)); + QCOMPARE(pixels(colorNoise(100, 100).apply(blue))[size_t(10 * 60 + 29)], (Pixel{102, 115, 26, 255})); + const QImage blueAcross = blue.transformed(QTransform().rotate(90)); + QCOMPARE(pixels(colorNoise(100, 100).apply(blueAcross))[size_t(29 * 20 + 10)], (Pixel{102, 115, 26, 255})); + // One in the red difference alone, blue kept equal. + const QImage red = halves(QColor(26, 115, 100), QColor(179, 100, 124)); + QCOMPARE(pixels(colorNoise(100, 100).apply(red))[size_t(10 * 60 + 29)], (Pixel{26, 115, 100, 255})); + QVERIFY(pixels(colorNoise(100, 0).apply(red))[size_t(10 * 60 + 29)] != (Pixel{26, 115, 100, 255})); + const QImage redAcross = red.transformed(QTransform().rotate(90)); + QCOMPARE(pixels(colorNoise(100, 100).apply(redAcross))[size_t(29 * 20 + 10)], (Pixel{26, 115, 100, 255})); + // The reach shrinks with the amount and the scale. + const QImage redBlue = halves(QColor(230, 51, 51), QColor(51, 51, 230)); + QCOMPARE(pixels(colorNoise(50, 0).apply(redBlue))[size_t(10 * 60 + 24)], (Pixel{230, 51, 51, 255})); + QCOMPARE(pixels(colorNoise(100, 0).apply(redBlue, std::nullopt, 0.25))[size_t(10 * 60 + 27)], (Pixel{230, 51, 51, 255})); +} + QTEST_MAIN(CameraRawColorNoiseTests) #include "CameraRawColorNoiseTests.moc"