Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
Add attribution for code sourced from Windows Terminal (#41061)
John Tur59a98bae3a57
diff --git a/crates/gpui/src/platform.rs b/crates/gpui/src/platform.rsindex a5f4a368e37..dd50a08c6b1 100644--- a/crates/gpui/src/platform.rs+++ b/crates/gpui/src/platform.rs@@ -711,6 +711,41 @@ impl PlatformTextSystem for NoopTextSystem {}}+// Adapted from https://github.com/microsoft/terminal/blob/1283c0f5b99a2961673249fa77c6b986efb5086c/src/renderer/atlas/dwrite.cpp+// Copyright (c) Microsoft Corporation.+// Licensed under the MIT license.+#[allow(dead_code)]+pub(crate) fn get_gamma_correction_ratios(gamma: f32) -> [f32; 4] {+ const GAMMA_INCORRECT_TARGET_RATIOS: [[f32; 4]; 13] = [+ [0.0000 / 4.0, 0.0000 / 4.0, 0.0000 / 4.0, 0.0000 / 4.0], // gamma = 1.0+ [0.0166 / 4.0, -0.0807 / 4.0, 0.2227 / 4.0, -0.0751 / 4.0], // gamma = 1.1+ [0.0350 / 4.0, -0.1760 / 4.0, 0.4325 / 4.0, -0.1370 / 4.0], // gamma = 1.2+ [0.0543 / 4.0, -0.2821 / 4.0, 0.6302 / 4.0, -0.1876 / 4.0], // gamma = 1.3+ [0.0739 / 4.0, -0.3963 / 4.0, 0.8167 / 4.0, -0.2287 / 4.0], // gamma = 1.4+ [0.0933 / 4.0, -0.5161 / 4.0, 0.9926 / 4.0, -0.2616 / 4.0], // gamma = 1.5+ [0.1121 / 4.0, -0.6395 / 4.0, 1.1588 / 4.0, -0.2877 / 4.0], // gamma = 1.6+ [0.1300 / 4.0, -0.7649 / 4.0, 1.3159 / 4.0, -0.3080 / 4.0], // gamma = 1.7+ [0.1469 / 4.0, -0.8911 / 4.0, 1.4644 / 4.0, -0.3234 / 4.0], // gamma = 1.8+ [0.1627 / 4.0, -1.0170 / 4.0, 1.6051 / 4.0, -0.3347 / 4.0], // gamma = 1.9+ [0.1773 / 4.0, -1.1420 / 4.0, 1.7385 / 4.0, -0.3426 / 4.0], // gamma = 2.0+ [0.1908 / 4.0, -1.2652 / 4.0, 1.8650 / 4.0, -0.3476 / 4.0], // gamma = 2.1+ [0.2031 / 4.0, -1.3864 / 4.0, 1.9851 / 4.0, -0.3501 / 4.0], // gamma = 2.2+ ];++ const NORM13: f32 = ((0x10000 as f64) / (255.0 * 255.0) * 4.0) as f32;+ const NORM24: f32 = ((0x100 as f64) / (255.0) * 4.0) as f32;++ let index = ((gamma * 10.0).round() as usize).clamp(10, 22) - 10;+ let ratios = GAMMA_INCORRECT_TARGET_RATIOS[index];++ [+ ratios[0] * NORM13,+ ratios[1] * NORM24,+ ratios[2] * NORM13,+ ratios[3] * NORM24,+ ]+}+#[derive(PartialEq, Eq, Hash, Clone)]pub(crate) enum AtlasKey {Glyph(RenderGlyphParams),diff --git a/crates/gpui/src/platform/blade/blade_renderer.rs b/crates/gpui/src/platform/blade/blade_renderer.rsindex d00fbdc7f12..dd0be7db437 100644--- a/crates/gpui/src/platform/blade/blade_renderer.rs+++ b/crates/gpui/src/platform/blade/blade_renderer.rs@@ -5,6 +5,7 @@ use super::{BladeAtlas, BladeContext};use crate::{Background, Bounds, DevicePixels, GpuSpecs, MonochromeSprite, Path, Point, PolychromeSprite,PrimitiveBatch, Quad, ScaledPixels, Scene, Shadow, Size, Underline,+ get_gamma_correction_ratios,};use blade_graphics as gpu;use blade_util::{BufferBelt, BufferBeltDescriptor};@@ -1023,7 +1024,7 @@ impl RenderingParameters {.and_then(|v| v.parse().ok()).unwrap_or(1.8_f32).clamp(1.0, 2.2);- let gamma_ratios = Self::get_gamma_ratios(gamma);+ let gamma_ratios = get_gamma_correction_ratios(gamma);let grayscale_enhanced_contrast = env::var("ZED_FONTS_GRAYSCALE_ENHANCED_CONTRAST").ok().and_then(|v| v.parse().ok())@@ -1036,37 +1037,4 @@ impl RenderingParameters {grayscale_enhanced_contrast,}}-- // Gamma ratios for brightening/darkening edges for better contrast- // https://github.com/microsoft/terminal/blob/1283c0f5b99a2961673249fa77c6b986efb5086c/src/renderer/atlas/dwrite.cpp#L50- fn get_gamma_ratios(gamma: f32) -> [f32; 4] {- const GAMMA_INCORRECT_TARGET_RATIOS: [[f32; 4]; 13] = [- [0.0000 / 4.0, 0.0000 / 4.0, 0.0000 / 4.0, 0.0000 / 4.0], // gamma = 1.0- [0.0166 / 4.0, -0.0807 / 4.0, 0.2227 / 4.0, -0.0751 / 4.0], // gamma = 1.1- [0.0350 / 4.0, -0.1760 / 4.0, 0.4325 / 4.0, -0.1370 / 4.0], // gamma = 1.2- [0.0543 / 4.0, -0.2821 / 4.0, 0.6302 / 4.0, -0.1876 / 4.0], // gamma = 1.3- [0.0739 / 4.0, -0.3963 / 4.0, 0.8167 / 4.0, -0.2287 / 4.0], // gamma = 1.4- [0.0933 / 4.0, -0.5161 / 4.0, 0.9926 / 4.0, -0.2616 / 4.0], // gamma = 1.5- [0.1121 / 4.0, -0.6395 / 4.0, 1.1588 / 4.0, -0.2877 / 4.0], // gamma = 1.6- [0.1300 / 4.0, -0.7649 / 4.0, 1.3159 / 4.0, -0.3080 / 4.0], // gamma = 1.7- [0.1469 / 4.0, -0.8911 / 4.0, 1.4644 / 4.0, -0.3234 / 4.0], // gamma = 1.8- [0.1627 / 4.0, -1.0170 / 4.0, 1.6051 / 4.0, -0.3347 / 4.0], // gamma = 1.9- [0.1773 / 4.0, -1.1420 / 4.0, 1.7385 / 4.0, -0.3426 / 4.0], // gamma = 2.0- [0.1908 / 4.0, -1.2652 / 4.0, 1.8650 / 4.0, -0.3476 / 4.0], // gamma = 2.1- [0.2031 / 4.0, -1.3864 / 4.0, 1.9851 / 4.0, -0.3501 / 4.0], // gamma = 2.2- ];-- const NORM13: f32 = ((0x10000 as f64) / (255.0 * 255.0) * 4.0) as f32;- const NORM24: f32 = ((0x100 as f64) / (255.0) * 4.0) as f32;-- let index = ((gamma * 10.0).round() as usize).clamp(10, 22) - 10;- let ratios = GAMMA_INCORRECT_TARGET_RATIOS[index];-- [- ratios[0] * NORM13,- ratios[1] * NORM24,- ratios[2] * NORM13,- ratios[3] * NORM24,- ]- }}diff --git a/crates/gpui/src/platform/blade/shaders.wgsl b/crates/gpui/src/platform/blade/shaders.wgslindex 1de8ad44201..2981b1446c6 100644--- a/crates/gpui/src/platform/blade/shaders.wgsl+++ b/crates/gpui/src/platform/blade/shaders.wgsl@@ -28,6 +28,9 @@ fn heat_map_color(value: f32, minValue: f32, maxValue: f32, position: vec2<f32>)*/+// Contrast and gamma correction adapted from https://github.com/microsoft/terminal/blob/1283c0f5b99a2961673249fa77c6b986efb5086c/src/renderer/atlas/dwrite.hlsl+// Copyright (c) Microsoft Corporation.+// Licensed under the MIT license.fn color_brightness(color: vec3<f32>) -> f32 {// REC. 601 luminance coefficients for perceived brightnessreturn dot(color, vec3<f32>(0.30, 0.59, 0.11));diff --git a/crates/gpui/src/platform/windows/alpha_correction.hlsl b/crates/gpui/src/platform/windows/alpha_correction.hlslindex dc8d0b5dc52..b0a9ca2e6b6 100644--- a/crates/gpui/src/platform/windows/alpha_correction.hlsl+++ b/crates/gpui/src/platform/windows/alpha_correction.hlsl@@ -1,3 +1,7 @@+// Adapted from https://github.com/microsoft/terminal/blob/1283c0f5b99a2961673249fa77c6b986efb5086c/src/renderer/atlas/dwrite.hlsl+// Copyright (c) Microsoft Corporation.+// Licensed under the MIT license.+float color_brightness(float3 color) {// REC. 601 luminance coefficients for perceived brightnessreturn dot(color, float3(0.30f, 0.59f, 0.11f));diff --git a/crates/gpui/src/platform/windows/directx_renderer.rs b/crates/gpui/src/platform/windows/directx_renderer.rsindex 2baa237cdaa..220876b4a98 100644--- a/crates/gpui/src/platform/windows/directx_renderer.rs+++ b/crates/gpui/src/platform/windows/directx_renderer.rs@@ -612,44 +612,11 @@ impl DirectXRenderer {let render_params: IDWriteRenderingParams1 =factory.CreateRenderingParams().unwrap().cast().unwrap();FontInfo {- gamma_ratios: Self::get_gamma_ratios(render_params.GetGamma()),+ gamma_ratios: get_gamma_correction_ratios(render_params.GetGamma()),grayscale_enhanced_contrast: render_params.GetGrayscaleEnhancedContrast(),}})}-- // Gamma ratios for brightening/darkening edges for better contrast- // https://github.com/microsoft/terminal/blob/1283c0f5b99a2961673249fa77c6b986efb5086c/src/renderer/atlas/dwrite.cpp#L50- fn get_gamma_ratios(gamma: f32) -> [f32; 4] {- const GAMMA_INCORRECT_TARGET_RATIOS: [[f32; 4]; 13] = [- [0.0000 / 4.0, 0.0000 / 4.0, 0.0000 / 4.0, 0.0000 / 4.0], // gamma = 1.0- [0.0166 / 4.0, -0.0807 / 4.0, 0.2227 / 4.0, -0.0751 / 4.0], // gamma = 1.1- [0.0350 / 4.0, -0.1760 / 4.0, 0.4325 / 4.0, -0.1370 / 4.0], // gamma = 1.2- [0.0543 / 4.0, -0.2821 / 4.0, 0.6302 / 4.0, -0.1876 / 4.0], // gamma = 1.3- [0.0739 / 4.0, -0.3963 / 4.0, 0.8167 / 4.0, -0.2287 / 4.0], // gamma = 1.4- [0.0933 / 4.0, -0.5161 / 4.0, 0.9926 / 4.0, -0.2616 / 4.0], // gamma = 1.5- [0.1121 / 4.0, -0.6395 / 4.0, 1.1588 / 4.0, -0.2877 / 4.0], // gamma = 1.6- [0.1300 / 4.0, -0.7649 / 4.0, 1.3159 / 4.0, -0.3080 / 4.0], // gamma = 1.7- [0.1469 / 4.0, -0.8911 / 4.0, 1.4644 / 4.0, -0.3234 / 4.0], // gamma = 1.8- [0.1627 / 4.0, -1.0170 / 4.0, 1.6051 / 4.0, -0.3347 / 4.0], // gamma = 1.9- [0.1773 / 4.0, -1.1420 / 4.0, 1.7385 / 4.0, -0.3426 / 4.0], // gamma = 2.0- [0.1908 / 4.0, -1.2652 / 4.0, 1.8650 / 4.0, -0.3476 / 4.0], // gamma = 2.1- [0.2031 / 4.0, -1.3864 / 4.0, 1.9851 / 4.0, -0.3501 / 4.0], // gamma = 2.2- ];-- const NORM13: f32 = ((0x10000 as f64) / (255.0 * 255.0) * 4.0) as f32;- const NORM24: f32 = ((0x100 as f64) / (255.0) * 4.0) as f32;-- let index = ((gamma * 10.0).round() as usize).clamp(10, 22) - 10;- let ratios = GAMMA_INCORRECT_TARGET_RATIOS[index];-- [- ratios[0] * NORM13,- ratios[1] * NORM24,- ratios[2] * NORM13,- ratios[3] * NORM24,- ]- }}impl DirectXResources {diff --git a/script/licenses/template.md.hbs b/script/licenses/template.md.hbsindex cc986588fb4..f37761f2c56 100644--- a/script/licenses/template.md.hbs+++ b/script/licenses/template.md.hbs@@ -19,3 +19,33 @@--------------------------------------------------------------------------------{{/each}}++#### MIT License++##### Used by:++* [Windows Terminal]( https://github.com/microsoft/terminal )++Copyright (c) Microsoft Corporation. All rights reserved.++MIT License++Permission is hereby granted, free of charge, to any person obtaining a copy+of this software and associated documentation files (the "Software"), to deal+in the Software without restriction, including without limitation the rights+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell+copies of the Software, and to permit persons to whom the Software is+furnished to do so, subject to the following conditions:++The above copyright notice and this permission notice shall be included in all+copies or substantial portions of the Software.++THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE+SOFTWARE.++--------------------------------------------------------------------------------