Skip to content

Conversation

@changm
Copy link
Contributor

@changm changm commented Jan 24, 2017

I finished Jeff's port of Skia's gamma mask code here - https://github.com/changm/gamma-lut-rs, which is the packaged added in this patch.

The original source is here - http://searchfox.org/mozilla-central/source/gfx/skia/skia/src/core/SkMaskGamma.cpp


This change is Reviewable

}

// Assumes the pixels here are linear values from CG
fn gamma_correct_pixels(&self, pixels: &mut Vec<u8>, width: usize,
Copy link
Member

Choose a reason for hiding this comment

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

nit: As far as I understand it, pixels's length cannot change, right? If so, you could probably make it a &mut [u8] so you save an indirection.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ahh good point. Thanks! Since I already have the dwrite gamma correction also using vector, can I fix this + dwrite + the gamma-lut library in a follow up patch? Too many patches in mid flight right now.

Copy link
Member

Choose a reason for hiding this comment

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

Sounds fine to me :)

@glennw
Copy link
Member

glennw commented Jan 24, 2017

@bors-servo r+

@bors-servo
Copy link
Contributor

📌 Commit 130bc43 has been approved by glennw

Copy link
Member

@kvark kvark left a comment

Choose a reason for hiding this comment

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

Got a few places where the code could look nicer (in addition to @emilio 's note, plus a question.

use std::collections::HashMap;
use std::collections::hash_map::Entry;
use webrender_traits::{ColorU, FontKey, FontRenderMode, GlyphDimensions};
use gamma_lut;
Copy link
Member

Choose a reason for hiding this comment

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

would be cleaner to use gamma_lut::{GammaLut, Color as ColorLut};

match render_mode {
FontRenderMode::Alpha => {
self.gamma_lut.preblend_grayscale_bgra(pixels, width, height,
gamma_lut::Color::new(color.r,
Copy link
Member

Choose a reason for hiding this comment

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

could move the ColorLut initialization out of the match

FontContext {
cg_fonts: HashMap::new(),
ct_fonts: HashMap::new(),
gamma_lut: gamma_lut::GammaLut::new(contrast, gamma, gamma),
Copy link
Member

Choose a reason for hiding this comment

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

given that you pass the same gamma as both paint gamma and device gamma, the whole LUT'ing thing becomes just a contrast application, according to the source:

if (src - dst).abs() < (1.0 / 256.0) {
        let mut ii : f32 = 0.0;
        for i in 0..256 {
            let raw_srca = ii / 255.0;
            let srca = apply_contrast(raw_srca, adjusted_contrast);

            table[i] = round_to_u8(255.0 * srca);
            ii += 1.0;
        }
}

Is this by design? Are we going to use different gamma parameters here in the long term?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is by design at the moment, it's just a port from Skia - http://searchfox.org/mozilla-central/source/gfx/skia/skia/src/core/SkPaint.cpp#1498

Also, that bit of code isn't the src/dst gamma. That's after the luminance conversion - http://searchfox.org/mozilla-central/source/gfx/skia/skia/src/core/SkMaskGamma.cpp#79. We don't actually hit that if block.

bors-servo pushed a commit that referenced this pull request Jan 25, 2017
Gamma correction for dwrite fonts

Same as #774 (review) but for dwrite fonts!

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/webrender/775)
<!-- Reviewable:end -->
@changm
Copy link
Contributor Author

changm commented Jan 25, 2017

@kvark Did I answer your question? If so, please merge. Thanks!

@kvark
Copy link
Member

kvark commented Jan 25, 2017 via email

@bors-servo
Copy link
Contributor

📌 Commit cffd17d has been approved by kvark

@bors-servo
Copy link
Contributor

🔒 Merge conflict

@bors-servo
Copy link
Contributor

☔ The latest upstream changes (presumably #770) made this pull request unmergeable. Please resolve the merge conflicts.

bors-servo pushed a commit that referenced this pull request Jan 26, 2017
Gamma correction for dwrite fonts

Same as #774 (review) but for dwrite fonts!

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/webrender/775)
<!-- Reviewable:end -->
@glennw
Copy link
Member

glennw commented Jan 26, 2017

@bors-servo r=kvark

@bors-servo
Copy link
Contributor

📌 Commit 259bab0 has been approved by kvark

@bors-servo
Copy link
Contributor

⌛ Testing commit 259bab0 with merge 5f0fc29...

bors-servo pushed a commit that referenced this pull request Jan 26, 2017
Apply gamma correction for coregraphics fonts

I finished Jeff's port of Skia's gamma mask code here - https://github.com/changm/gamma-lut-rs, which is the packaged added in this patch.

The original source is here - http://searchfox.org/mozilla-central/source/gfx/skia/skia/src/core/SkMaskGamma.cpp

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/webrender/774)
<!-- Reviewable:end -->
@bors-servo
Copy link
Contributor

☀️ Test successful - status-travis

@bors-servo bors-servo merged commit 259bab0 into servo:master Jan 27, 2017
@changm changm deleted the cg-gamma branch January 27, 2017 01:08
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.

5 participants