Skip to content

Change crop control background to pattern#77

Merged
meesoft merged 4 commits intomainfrom
features/CropBorderFill
Apr 5, 2026
Merged

Change crop control background to pattern#77
meesoft merged 4 commits intomainfrom
features/CropBorderFill

Conversation

@meesoft
Copy link
Copy Markdown
Owner

@meesoft meesoft commented Apr 2, 2026

Summary by CodeRabbit

  • Style
    • Crop overlay visuals updated: borders, inner grid strips and resize handles now adapt their color for better contrast; ratio label rendered with a clearer foreground and slight offset for improved readability.
    • Preview title text rendering set to ignore mouse input to prevent accidental interaction.
  • New Features
    • Crop overlay color now adapts automatically based on image brightness.

@meesoft meesoft marked this pull request as ready for review April 2, 2026 20:21
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 2, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 260ca2d9-4a89-448b-a0d8-a409ec7e977e

📥 Commits

Reviewing files that changed from the base of the PR and between 896a69f and 4de80c5.

📒 Files selected for processing (2)
  • PhotoLocator/Controls/CropControl.xaml.cs
  • PhotoLocator/MainWindow.xaml.cs
🚧 Files skipped from review as they are similar to previous changes (2)
  • PhotoLocator/MainWindow.xaml.cs
  • PhotoLocator/Controls/CropControl.xaml.cs

Walkthrough

Replaced hardcoded crop overlay fills with a bindable CropBorderColor, added an offset duplicate RatioText label for a shadow, changed CropControl.Reset to accept a BitmapSource? and compute pixel mean via a new FloatBitmap.Mean(), and updated call sites and hit-testing.

Changes

Cohort / File(s) Summary
Crop UI XAML
PhotoLocator/Controls/CropControl.xaml
Replaced multiple #7F000000 rectangle fills with {Binding CropBorderColor}; made original ratio label IsHitTestVisible="False" and added an overlapping translated Label bound to the same RatioText to render a shadowed caption.
Crop control logic
PhotoLocator/Controls/CropControl.xaml.cs
Changed Reset(...) signature to Reset(BitmapSource? image, double imageScale, double cropWidthHeightRatio); derive image dimensions from BitmapSource, compute pixelMean (used to choose CropBorderColor), added public SolidColorBrush? CropBorderColor, and switched several crop properties to SetProperty(...) patterns.
Bitmap operation
PhotoLocator/BitmapOperations/FloatBitmap.cs
Added public double Mean() that sums all float elements via an unsafe fixed pointer and returns the average.
Main window updates
PhotoLocator/MainWindow.xaml, PhotoLocator/MainWindow.xaml.cs
Marked two preview title TextBlocks as IsHitTestVisible="False"; updated ShowCropControl() to pass the BitmapSource to CropGrid.Reset(...) and wrapped cursor override with using var.

Sequence Diagram(s)

mermaid
sequenceDiagram
participant UI as MainWindow
participant Crop as CropControl
participant Img as BitmapSource
participant FB as FloatBitmap

UI->>Crop: ShowCropControl(sourceImage)
Crop->>Img: accept BitmapSource?
Crop->>FB: construct FloatBitmap(image, 1)
FB->>FB: Mean() — unsafe pointer sum / Size
FB-->>Crop: pixelMean
Crop->>Crop: set CropBorderColor (based on pixelMean)
Crop-->>UI: bindings update overlay fills and ratio labels

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • Local contrast histogram #56: Modifies FloatBitmap (adds histogram and pixel conversion utilities); touches the same class and could interact with the new Mean() implementation.
  • Update to .net10 #55: Alters FloatBitmap internals (Elements exposure/backing-field changes and unsafe usage); directly relevant to the new Mean() method.
🚥 Pre-merge checks | ✅ 1 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Title check ⚠️ Warning The title describes changing the crop control background to a pattern, but the changeset actually implements dynamic crop border color selection based on image pixel mean values and adds a shadow effect for ratio text—not a pattern background. Update the title to accurately reflect the main changes, such as 'Implement adaptive crop border color and ratio text shadow' or 'Add dynamic crop border styling based on image content'.
✅ Passed checks (1 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch features/CropBorderFill

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
PhotoLocator/Controls/CropControl.xaml (1)

65-72: Make the ratio overlay labels non-interactive.

These two overlay labels can intercept pointer input over the text area. Setting IsHitTestVisible="False" avoids accidental interaction conflicts with crop gestures.

Proposed change
-        <Label Content="{Binding RatioText}" Grid.ColumnSpan="3" Grid.RowSpan="3" HorizontalAlignment="Left" VerticalAlignment="Top" Foreground="Black">
+        <Label Content="{Binding RatioText}" Grid.ColumnSpan="3" Grid.RowSpan="3" HorizontalAlignment="Left" VerticalAlignment="Top" Foreground="Black" IsHitTestVisible="False">
             <Label.RenderTransform>
                 <TransformGroup>
                     <TranslateTransform X="1" Y="1"/>
                 </TransformGroup>
             </Label.RenderTransform>
         </Label>
-        <Label Content="{Binding RatioText}" Grid.ColumnSpan="3" Grid.RowSpan="3" HorizontalAlignment="Left" VerticalAlignment="Top" Foreground="White"/>
+        <Label Content="{Binding RatioText}" Grid.ColumnSpan="3" Grid.RowSpan="3" HorizontalAlignment="Left" VerticalAlignment="Top" Foreground="White" IsHitTestVisible="False"/>
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@PhotoLocator/Controls/CropControl.xaml` around lines 65 - 72, The two overlay
Label elements that bind to RatioText are intercepting pointer input and should
be made non-interactive by adding IsHitTestVisible="False" to each Label; locate
the Label elements in CropControl.xaml (the ones with Content="{Binding
RatioText}" and the RenderTransform/TranslateTransform) and add
IsHitTestVisible="False" to both so they no longer block crop gestures.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@PhotoLocator/Controls/CropControl.xaml`:
- Around line 65-72: The two overlay Label elements that bind to RatioText are
intercepting pointer input and should be made non-interactive by adding
IsHitTestVisible="False" to each Label; locate the Label elements in
CropControl.xaml (the ones with Content="{Binding RatioText}" and the
RenderTransform/TranslateTransform) and add IsHitTestVisible="False" to both so
they no longer block crop gestures.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: d508254c-127e-424a-a9ac-9dadb4288afb

📥 Commits

Reviewing files that changed from the base of the PR and between a7b2f5e and 346808c.

📒 Files selected for processing (1)
  • PhotoLocator/Controls/CropControl.xaml

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@PhotoLocator/BitmapOperations/FloatBitmap.cs`:
- Around line 389-402: The Mean() method in FloatBitmap.cs can divide by zero
when Size == 0; add a fast guard at the start of FloatBitmap.Mean() that checks
if Size == 0 and returns a deterministic value (e.g., 0.0) to avoid the invalid
0/0 result, then proceed with the existing unsafe block that sums Elements and
returns sum/Size.

In `@PhotoLocator/Controls/CropControl.xaml.cs`:
- Around line 34-49: Add a resilient, cheap pixel-mean helper and call it from
Reset instead of creating a full FloatBitmap on the UI path: implement a private
static double EstimatePixelMean(BitmapSource image) that normalizes alpha
formats (convert Bgra32/Pbgra32 to Bgr32 via FormatConvertedBitmap), downsamples
large images using TransformedBitmap + ScaleTransform when max dimension > 256,
computes mean via new FloatBitmap(src, 1).Mean(), and returns 0 on
UserMessageException; then replace the direct FloatBitmap call in Reset with
pixelMean = EstimatePixelMean(image) and keep existing logic using
CropBorderColor and Width.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: e9f6c613-68e1-45a3-bf34-bf3ad763f73c

📥 Commits

Reviewing files that changed from the base of the PR and between 346808c and 896a69f.

📒 Files selected for processing (5)
  • PhotoLocator/BitmapOperations/FloatBitmap.cs
  • PhotoLocator/Controls/CropControl.xaml
  • PhotoLocator/Controls/CropControl.xaml.cs
  • PhotoLocator/MainWindow.xaml
  • PhotoLocator/MainWindow.xaml.cs
🚧 Files skipped from review as they are similar to previous changes (1)
  • PhotoLocator/Controls/CropControl.xaml

Comment thread PhotoLocator/BitmapOperations/FloatBitmap.cs
Comment thread PhotoLocator/Controls/CropControl.xaml.cs
@meesoft meesoft merged commit ad8641a into main Apr 5, 2026
5 checks passed
@meesoft meesoft deleted the features/CropBorderFill branch April 5, 2026 06:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant