Skip to content

Comments

Fix HDR screenshot brightness by applying tone mapping#588

Draft
Copilot wants to merge 37 commits intomainfrom
copilot/add-hdr-support
Draft

Fix HDR screenshot brightness by applying tone mapping#588
Copilot wants to merge 37 commits intomainfrom
copilot/add-hdr-support

Conversation

Copy link
Contributor

Copilot AI commented Dec 22, 2025

  • Research and understand the HDR screenshot issue
  • Add Windows API methods to detect HDR displays
  • Implement color space conversion from HDR to SDR
  • Apply conversion to screenshot capture methods
  • Add tests for HDR conversion logic
  • Address code review feedback (refactored, improved docs)
  • Run security check (no vulnerabilities found)
  • Rebase onto dev branch

Summary

Successfully rebased HDR support implementation onto the latest dev branch. All changes apply cleanly with no conflicts. The solution:

  • Detects HDR displays using Windows GDI APIs
  • Applies tone mapping to convert HDR color space to SDR
  • Automatically activates on HDR displays without affecting non-HDR systems
  • Includes comprehensive tests and passes all security checks
Original prompt

This section details on the original issue you should resolve

<issue_title>HDR support</issue_title>
<issue_description>Is it possible to have support for hdr?

When I use text grab on an image displayed in a browser, it will fail to recognize some words.
As an example, this is what text grab gives with hdr on:

Drug Facts
Active ingredient
Uses to decrease bactené
recommended for repeated
Waminqs
For enema use only: hands
Flammable, keep away from fire
When using this product • keep
flush thoroughty wrt water. avu
do not inhale or ingest
Stop use and ask a doctor if irrit-
Purpose
COuC cause
ame
eyes. In case of
r:act wth brokenect eyes,
and redness develop
Keep out of reach of children. If swaj„wed, get medical help or
Directions •
wet hands thoroughly wift product and al
mping for children under 6, use only under adult supemsl?n to dry Without
Other information n
do not store above 105'F
fabrics harmful to wood finishes and plastics
may discolor some
bactive ingredients
water, carbomer and/or ac
Tdate crosspolymer, fragrance, glycenn, isopro
pyl
zteatårunatng 99.99% of rzrrj common harmfu germs & barere
Distributed By VI-Jon, Inc.
nasQ15

with hdr off, it is much more accurate.

Drug Facts
Active ingredient
*cohol 62%
USBS'todecrease bderia .eskn
recommended for repeated
Warnings
For externa use only: hands
Flammable, keep away from fire cr 'iame
When using this product keep of eyes. In case of
msh thoroughty wifi water. ontactwth brokenem
do not inhale or ingest
stop use and aska doctor if • irrit nand redness develop
condltjon persists for more ten 72 ('ours
Keep out of reach of children. If swaikjwed, get medical telp or contäa
Poison Control Center right away.
Directions wet hands thoroughly wm product and allow to dry Withou
for children under 6, use only under adult supervision
•grecommended for infants
harmful to wood finishes and plastics
fabrts
Inactive ingredients
acrydate crosspoymer, fragrance, glycerin, isopropyl myristate,
•øedÜiÜ09999% of & n 15
Distributed By VI-Jon, 1m.
wrwgerrnx.com

I believe this may have to do with how text grab gets the image. Here is what the image looks like with hdr on:
image
hdr off:
image

When hdr is on, the screenshot is a lot brighter, and the text is harder to read.
Is it possible to fix this? I'm pretty sure it's possible since zoom screen sharing doesn't have this issue.</issue_description>

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 3 commits December 22, 2025 22:39
Co-authored-by: TheJoeFin <7809853+TheJoeFin@users.noreply.github.com>
Co-authored-by: TheJoeFin <7809853+TheJoeFin@users.noreply.github.com>
Co-authored-by: TheJoeFin <7809853+TheJoeFin@users.noreply.github.com>
Copilot AI changed the title [WIP] Add support for HDR in text grab functionality Fix HDR screenshot brightness by applying tone mapping Dec 22, 2025
Copilot AI requested a review from TheJoeFin December 22, 2025 22:46
@TheJoeFin TheJoeFin changed the base branch from main to dev January 23, 2026 05:24
@TheJoeFin
Copy link
Owner

@copilot rebase

Copy link
Contributor Author

Copilot AI commented Jan 23, 2026

@copilot rebase

The branch is already up-to-date with main. Both are based on commit a2b7bb0 (v4.11.2), and there are no new commits on main to rebase onto. The branch has 4 commits ahead of main with your HDR support changes, and no rebase action is needed.

@TheJoeFin
Copy link
Owner

@copilot rebase on dev

Copilot AI and others added 13 commits January 23, 2026 05:30
- Add TranslateText method to WindowsAiUtilities.cs using LanguageModel
- Add translation settings to Settings files
- Add translation toggle button and menu with language selection to GrabFrame.xaml
- Implement translation logic in GrabFrame.xaml.cs with timer-based translation
- Store original texts and restore them when translation is disabled
- Support 12 target languages (English, Spanish, French, German, Italian, Portuguese, Russian, Japanese, Chinese, Korean, Arabic, Hindi)

Co-authored-by: TheJoeFin <7809853+TheJoeFin@users.noreply.github.com>
- Add detailed comments explaining the translation approach
- Use TextRewriter with custom translation prompt as workaround
- Note that Microsoft.Extensions.AI could be added for better translation support

Co-authored-by: TheJoeFin <7809853+TheJoeFin@users.noreply.github.com>
- Auto-freeze frame when translation is enabled for static content
- Implement parallel translation of word borders for better performance
- Use Dispatcher.InvokeAsync for thread-safe UI updates

Co-authored-by: TheJoeFin <7809853+TheJoeFin@users.noreply.github.com>
- Hide translation button when Windows AI is not available
- Update tooltip to show current target language
- Improve user experience with dynamic tooltip updates

Co-authored-by: TheJoeFin <7809853+TheJoeFin@users.noreply.github.com>
- Remove Task.Run with async lambdas to avoid thread pool issues
- Add debug logging for translation errors
- Replace hard-coded array index with robust menu search
- Simplify translation logic to sequential processing

Co-authored-by: TheJoeFin <7809853+TheJoeFin@users.noreply.github.com>
- Add semaphore to limit concurrent translations (max 3)
- Extract translation logic into testable async Task methods
- Replace magic string with constant
- Add comprehensive XML documentation about translation limitations
- Properly dispose semaphore on unload

Co-authored-by: TheJoeFin <7809853+TheJoeFin@users.noreply.github.com>
- Replace hardcoded translation prompt with template constant
- Improve code maintainability and allow for future customization

Co-authored-by: TheJoeFin <7809853+TheJoeFin@users.noreply.github.com>
- Add Translate submenu with 12 language options to Local AI menu
- Implement TranslateMenuItem_Click handler following existing pattern
- Uses WindowsAiUtilities.TranslateText for translation
- Supports both selected text and full text translation
- Displays loading indicator during translation

Co-authored-by: TheJoeFin <7809853+TheJoeFin@users.noreply.github.com>
- Show warning dialog if translation fails or returns unchanged text
- Catch and display exceptions with appropriate error message
- Improve user feedback when translation doesn't work

Co-authored-by: TheJoeFin <7809853+TheJoeFin@users.noreply.github.com>
- Keep basic exception handling with error dialog
- Remove check for unchanged text to match other AI handlers
- More consistent with SummarizeMenuItem, RewriteMenuItem patterns

Co-authored-by: TheJoeFin <7809853+TheJoeFin@users.noreply.github.com>
Updated error message display to explicitly use System.Windows.MessageBox to avoid potential naming conflicts.
TheJoeFin and others added 20 commits January 23, 2026 05:30
Updated translation prompt for clarity and consistency, added a dedicated system prompt constant, and streamlined method documentation.
Enables Windows AI-powered translation for each word, adds progress feedback and cancellation, and optimizes resource usage with shared model and fast language detection.
Enable translating grabbed text to system language using Windows AI if available. Adds UI option and language detection for translation workflow.
Enables quick translation to system language, improves error handling, and updates UI menu dynamically. Includes minor formatting fixes.
Improves robustness by safely handling cases where recognizedText.Lines is null, preventing possible null reference exceptions.
…de quality issues

- Add Cleanup() method to WindowsAiUtilities for proper disposal of static semaphore
- Fix race condition in translation cancellation by using ThrowIfCancellationRequested()
- Add null check for TranslationMenuItem to prevent NullReferenceException
- Extract common translation logic into PerformTranslationAsync() helper method
- Always dispose translation model on window unload regardless of translation state
- Remove unused isTranslating field from GrabFrame
- Replace duplicate GetSystemLanguageName() with call to LanguageUtilities.GetSystemLanguageForTranslation()
- Fix indentation in WindowsAiUtilities.cs (TranslateText method and documentation)
- Fix indentation in GrabFrame.xaml.cs (CancelTranslationButton_Click method)
- Use explicit .Where() filtering in foreach loops for better clarity
- Use object.ReferenceEquals() for null checks in double-checked locking pattern
- Combine nested if statements for targetCode == "en" check
- Keep explicit if/else for text assignment for better readability

Co-authored-by: TheJoeFin <7809853+TheJoeFin@users.noreply.github.com>
- Add Cleanup() method for proper disposal of static semaphore
- Use object.ReferenceEquals() for null checks in double-checked locking
- Use explicit .Where() filtering in foreach loop
- Combine nested if statements for targetCode check

Co-authored-by: TheJoeFin <7809853+TheJoeFin@users.noreply.github.com>
Added GitHub Sponsors, Buy Me a Coffee, and updated PayPal link.
Improves UI structure, type safety, and translation feature gating based on Windows AI availability.
Introduce a configurable system for post-capture actions in Fullscreen Grab, including a new settings dialog, dynamic menu generation, and persistent user preferences. Refactor related models and UI for extensibility and maintainability. Add unit tests for action management logic.
Introduces a user setting and UI toggle to control whether the post-grab menu stays open after selecting an action. Also adds InputGestureText to ButtonInfo.
Removed InputGestureText from ButtonInfo and related tests. Input gestures for post-grab actions are now set dynamically in FullscreenGrab.
…on, fix event handler leaks

Co-authored-by: TheJoeFin <7809853+TheJoeFin@users.noreply.github.com>
Co-authored-by: TheJoeFin <7809853+TheJoeFin@users.noreply.github.com>
Co-authored-by: TheJoeFin <7809853+TheJoeFin@users.noreply.github.com>
Co-authored-by: TheJoeFin <7809853+TheJoeFin@users.noreply.github.com>
Reduced editor window height and updated ListView scrollbars. Commented out the "Translate to system language" post-grab action.
Adjusted test expectations after removing the action from defaults.
Updated NuGet package versions for bug fixes and compatibility. Enhanced SettingsWindow navigation menu for better text wrapping and readability.
Copy link
Contributor Author

Copilot AI commented Jan 23, 2026

@copilot rebase on dev

Rebased onto dev branch successfully. The branch now includes all 37 commits from dev plus the HDR support changes on top. All files merged cleanly with no conflicts. Commit: a988063

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • az667904.vo.msecnd.net
    • Triggering command: /usr/bin/dotnet dotnet build Text-Grab/Text-Grab.csproj -p:EnableWindowsTargeting=true --no-restore (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Base automatically changed from dev to main January 31, 2026 15:44
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.

HDR support

2 participants