[PR #1746] [MERGED] fix: ocr luminance calculation fix #2471

Closed
opened 2026-01-29 17:22:20 +00:00 by claunia · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/CCExtractor/ccextractor/pull/1746
Author: @hrideshmg
Created: 9/8/2025
Status: Merged
Merged: 9/13/2025
Merged by: @prateekmedia

Base: masterHead: ocr_fixes


📝 Commits (1)

  • 208c70d fix: ocr luminance calculation fix

📊 Changes

1 file changed (+3 additions, -3 deletions)

View changed files

📝 src/rust/src/hardsubx/imgops.rs (+3 -3)

📄 Description

In raising this pull request, I confirm the following (please check boxes):

  • I have read and understood the contributors guide.
  • I have checked that another pull request for this purpose does not exist.
  • I have considered, and confirmed that this submission will be valuable to others.
  • I accept that this submission may not be used, and the pull request closed at the will of the maintainer.
  • I give this submission freely, and claim no ownership to its content.
  • I have mentioned this change in the changelog.

My familiarity with the project is as follows (check one):

  • I have never used CCExtractor.
  • I have used CCExtractor just a couple of times.
  • I absolutely love CCExtractor, but have not contributed previously.
  • I am an active contributor to CCExtractor.

Hardsubx in rust currently does not give identical output as the C implementation, often providing inferior results. After debugging for a bit I noticed that there were very slight differences in the luminance masks between both versions.

In the old C code, the RGB to LAB conversion was done manually, in rust we now use the palette crate for this purpose.
The Srgb implementation from palette we were using till now assumes that the input image is gamma corrected, and thus performs gamma decoding to make the RGB values linear.

This is unnecessary though, because our input is already linear RGB and was thus causing a faulty conversion. I've modified the code to use LinSrgb instead. The Rust implementation now provides identical output to the C code.

Tested on this sample.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/CCExtractor/ccextractor/pull/1746 **Author:** [@hrideshmg](https://github.com/hrideshmg) **Created:** 9/8/2025 **Status:** ✅ Merged **Merged:** 9/13/2025 **Merged by:** [@prateekmedia](https://github.com/prateekmedia) **Base:** `master` ← **Head:** `ocr_fixes` --- ### 📝 Commits (1) - [`208c70d`](https://github.com/CCExtractor/ccextractor/commit/208c70de1ecce88df2ce6da704a49cc93f874245) fix: ocr luminance calculation fix ### 📊 Changes **1 file changed** (+3 additions, -3 deletions) <details> <summary>View changed files</summary> 📝 `src/rust/src/hardsubx/imgops.rs` (+3 -3) </details> ### 📄 Description <!-- Please prefix your pull request with one of the following: **[FEATURE]** **[FIX]** **[IMPROVEMENT]**. --> **In raising this pull request, I confirm the following (please check boxes):** - [ ] I have read and understood the [contributors guide](https://github.com/CCExtractor/ccextractor/blob/master/.github/CONTRIBUTING.md). - [ ] I have checked that another pull request for this purpose does not exist. - [ ] I have considered, and confirmed that this submission will be valuable to others. - [ ] I accept that this submission may not be used, and the pull request closed at the will of the maintainer. - [ ] I give this submission freely, and claim no ownership to its content. - [ ] **I have mentioned this change in the [changelog](https://github.com/CCExtractor/ccextractor/blob/master/docs/CHANGES.TXT).** **My familiarity with the project is as follows (check one):** - [ ] I have never used CCExtractor. - [ ] I have used CCExtractor just a couple of times. - [ ] I absolutely love CCExtractor, but have not contributed previously. - [x] I am an active contributor to CCExtractor. --- Hardsubx in rust currently does not give identical output as the C implementation, often providing inferior results. After debugging for a bit I noticed that there were very slight differences in the luminance masks between both versions. In the old C code, the RGB to LAB conversion was done [manually](https://github.com/hrideshmg/ccextractor/blob/ocr_fixes/src/lib_ccx/hardsubx_imgops.c#L69), in rust we [now](https://github.com/hrideshmg/ccextractor/blob/master/src/rust/src/hardsubx/imgops.rs#L15) use the `palette` crate for this purpose. The `Srgb` implementation from `palette` we were using till now assumes that the input image is [gamma corrected](https://en.wikipedia.org/wiki/Gamma_correction), and thus performs gamma decoding to make the RGB values linear. This is unnecessary though, because our input is already linear RGB and was thus causing a faulty conversion. I've modified the code to use [`LinSrgb`](https://docs.rs/palette/latest/palette/type.LinSrgb.html) instead. The Rust implementation now provides identical output to the C code. Tested on this [sample](https://drive.google.com/file/d/0B_61ywKPmI0TdlRWcVdnajVJUWs/view?resourcekey=0-oCZT9NnDCE9h0jMzcma9wg). --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
claunia added the pull-request label 2026-01-29 17:22:20 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/ccextractor#2471