Add a prebuilt gamma LUT
This commit is contained in:
parent
556bb2ce84
commit
0a5f4c65df
|
@ -78,6 +78,7 @@ static STATIC_SVG_OCTICONS_PATH: &'static str = "../client/node_modules/octicons
|
|||
static STATIC_WOFF2_INTER_UI_PATH: &'static str = "../../resources/fonts/inter-ui";
|
||||
static STATIC_GLSL_PATH: &'static str = "../../shaders";
|
||||
static STATIC_DATA_PATH: &'static str = "../../resources/data";
|
||||
static STATIC_TEXTURES_PATH: &'static str = "../../resources/textures";
|
||||
|
||||
static STATIC_DOC_API_INDEX_URI: &'static str = "/doc/api/pathfinder_font_renderer/index.html";
|
||||
|
||||
|
@ -504,6 +505,10 @@ fn static_svg_demo(svg_name: String) -> Option<NamedFile> {
|
|||
fn static_data(file: PathBuf) -> Option<NamedFile> {
|
||||
NamedFile::open(Path::new(STATIC_DATA_PATH).join(file)).ok()
|
||||
}
|
||||
#[get("/textures/<file..>")]
|
||||
fn static_textures(file: PathBuf) -> Option<NamedFile> {
|
||||
NamedFile::open(Path::new(STATIC_TEXTURES_PATH).join(file)).ok()
|
||||
}
|
||||
|
||||
struct Shader {
|
||||
file: File,
|
||||
|
@ -550,5 +555,6 @@ fn main() {
|
|||
static_otf_demo,
|
||||
static_svg_demo,
|
||||
static_data,
|
||||
static_textures,
|
||||
]).launch();
|
||||
}
|
||||
|
|
Binary file not shown.
After Width: | Height: | Size: 388 B |
|
@ -4,4 +4,6 @@ version = "0.1.0"
|
|||
authors = ["Patrick Walton <pcwalton@mimiga.net>"]
|
||||
|
||||
[dependencies]
|
||||
clap = "2.27"
|
||||
image = "0.17"
|
||||
log = "0.3"
|
||||
|
|
|
@ -165,22 +165,6 @@ impl ColorLut for ColorU {
|
|||
}
|
||||
}
|
||||
|
||||
// This will invert the gamma applied by CoreGraphics,
|
||||
// so we can get linear values.
|
||||
// CoreGraphics obscurely defaults to 2.0 as the smoothing gamma value.
|
||||
// The color space used does not appear to affect this choice.
|
||||
#[cfg(target_os="macos")]
|
||||
fn get_inverse_gamma_table_coregraphics_smoothing() -> [u8; 256] {
|
||||
let mut table = [0u8; 256];
|
||||
|
||||
for (i, v) in table.iter_mut().enumerate() {
|
||||
let x = i as f32 / 255.0;
|
||||
*v = round_to_u8(x * x * 255.0);
|
||||
}
|
||||
|
||||
table
|
||||
}
|
||||
|
||||
// A value of 0.5 for SK_GAMMA_CONTRAST appears to be a good compromise.
|
||||
// With lower values small text appears washed out (though correctly so).
|
||||
// With higher values lcd fringing is worse and the smoothing effect of
|
||||
|
@ -252,8 +236,6 @@ pub fn build_gamma_correcting_lut(table: &mut [u8; 256], src: u8, contrast: f32,
|
|||
|
||||
pub struct GammaLut {
|
||||
pub tables: [[u8; 256]; 1 << LUM_BITS],
|
||||
#[cfg(target_os="macos")]
|
||||
cg_inverse_gamma: [u8; 256],
|
||||
}
|
||||
|
||||
impl GammaLut {
|
||||
|
@ -282,12 +264,6 @@ impl GammaLut {
|
|||
}
|
||||
|
||||
pub fn new(contrast: f32, paint_gamma: f32, device_gamma: f32) -> GammaLut {
|
||||
#[cfg(target_os="macos")]
|
||||
let mut table = GammaLut {
|
||||
tables: [[0; 256]; 1 << LUM_BITS],
|
||||
cg_inverse_gamma: get_inverse_gamma_table_coregraphics_smoothing(),
|
||||
};
|
||||
#[cfg(not(target_os="macos"))]
|
||||
let mut table = GammaLut {
|
||||
tables: [[0; 256]; 1 << LUM_BITS],
|
||||
};
|
||||
|
@ -312,15 +288,6 @@ impl GammaLut {
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(target_os="macos")]
|
||||
pub fn coregraphics_convert_to_linear(&self, pixels: &mut [u8]) {
|
||||
for pixel in pixels.chunks_mut(4) {
|
||||
pixel[0] = self.cg_inverse_gamma[pixel[0] as usize];
|
||||
pixel[1] = self.cg_inverse_gamma[pixel[1] as usize];
|
||||
pixel[2] = self.cg_inverse_gamma[pixel[2] as usize];
|
||||
}
|
||||
}
|
||||
|
||||
// Assumes pixels are in BGRA format. Assumes pixel values are in linear space already.
|
||||
pub fn preblend_grayscale(&self, pixels: &mut [u8], color: ColorU) {
|
||||
let table_g = self.get_table(color.g);
|
||||
|
|
|
@ -1,38 +0,0 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#[macro_use]
|
||||
extern crate log;
|
||||
|
||||
mod gamma_lut;
|
||||
|
||||
use gamma_lut::GammaLut;
|
||||
|
||||
const CONTRAST: f32 = 0.0;
|
||||
const GAMMA: f32 = 0.0;
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq)]
|
||||
pub struct ColorU {
|
||||
pub r: u8,
|
||||
pub g: u8,
|
||||
pub b: u8,
|
||||
pub a: u8,
|
||||
}
|
||||
|
||||
impl ColorU {
|
||||
#[inline]
|
||||
pub fn new(r: u8, g: u8, b: u8, a: u8) -> ColorU {
|
||||
ColorU {
|
||||
r: r,
|
||||
g: g,
|
||||
b: b,
|
||||
a: a,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn main() {
|
||||
let gamma_lut = GammaLut::new(CONTRAST, GAMMA, GAMMA);
|
||||
// TODO(pcwalton)
|
||||
}
|
|
@ -0,0 +1,65 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
extern crate clap;
|
||||
extern crate image;
|
||||
|
||||
#[macro_use]
|
||||
extern crate log;
|
||||
|
||||
mod gamma_lut;
|
||||
|
||||
use clap::{App, Arg};
|
||||
use gamma_lut::GammaLut;
|
||||
use image::{ImageBuffer, ImageLuma8, Luma, PNG};
|
||||
use std::fs::File;
|
||||
use std::path::Path;
|
||||
|
||||
const CONTRAST: f32 = 0.0;
|
||||
const GAMMA: f32 = 0.0;
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq)]
|
||||
pub struct ColorU {
|
||||
pub r: u8,
|
||||
pub g: u8,
|
||||
pub b: u8,
|
||||
pub a: u8,
|
||||
}
|
||||
|
||||
impl ColorU {
|
||||
#[inline]
|
||||
pub fn new(r: u8, g: u8, b: u8, a: u8) -> ColorU {
|
||||
ColorU {
|
||||
r: r,
|
||||
g: g,
|
||||
b: b,
|
||||
a: a,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn main() {
|
||||
let app = App::new("Pathfinder Gamma LUT Generator")
|
||||
.version("0.1")
|
||||
.author("The Pathfinder Project Developers")
|
||||
.about("Generates gamma lookup tables for use with Pathfinder")
|
||||
.arg(Arg::with_name("OUTPUT-PATH").help("The `.png` image to produce")
|
||||
.required(true)
|
||||
.index(1));
|
||||
let matches = app.get_matches();
|
||||
|
||||
let gamma_lut = GammaLut::new(CONTRAST, GAMMA, GAMMA);
|
||||
let mut image = ImageBuffer::new(256, gamma_lut.tables.len() as u32);
|
||||
for (table_index, table) in gamma_lut.tables.iter().enumerate() {
|
||||
for (color_index, &color) in table.iter().enumerate() {
|
||||
image.put_pixel(color_index as u32, table_index as u32, Luma([color]))
|
||||
}
|
||||
}
|
||||
|
||||
let output_path = matches.value_of("OUTPUT-PATH").unwrap();
|
||||
let output_path = Path::new(output_path);
|
||||
|
||||
let mut output = File::create(output_path).unwrap();
|
||||
ImageLuma8(image).save(&mut output, PNG).unwrap();
|
||||
}
|
Loading…
Reference in New Issue