-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Initial cut of primitives from piet-scene #1
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
aca2934
Initial cut of primitives from piet-scene
dfrg 725df89
impl PartialEq for Brush to make it usable in parley
dfrg d3c10e3
address review feedback
dfrg 42d826e
depend on kurbo 0.9.0 from crates.io
dfrg 7d0e358
BrushRef type to improve ergonomics in method calls
dfrg File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/target |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
[package] | ||
name = "peniko" | ||
version = "0.1.0" | ||
authors = ["Chad Brokaw <cbrokaw@gmail.com>"] | ||
license = "MIT/Apache-2.0" | ||
edition = "2021" | ||
description = "Primitive types for styling vector graphics" | ||
keywords = ["graphics", "vector", "style"] | ||
categories = ["graphics"] | ||
repository = "https://github.com/linebender/peniko" | ||
homepage = "https://github.com/linebender/peniko" | ||
readme = "README.md" | ||
|
||
[dependencies] | ||
kurbo = "0.9.0" | ||
smallvec = "1.8.0" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,148 @@ | ||
// Copyright 2022 The peniko authors. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// https://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
// Also licensed under MIT license, at your choice. | ||
|
||
/// Defines the color mixing function for a blend operation. | ||
#[derive(Copy, Clone, PartialEq, Eq, Debug)] | ||
#[repr(C)] | ||
pub enum Mix { | ||
/// Default attribute which specifies no blending. The blending formula simply selects the source color. | ||
Normal = 0, | ||
/// Source color is multiplied by the destination color and replaces the destination. | ||
Multiply = 1, | ||
/// Multiplies the complements of the backdrop and source color values, then complements the result. | ||
Screen = 2, | ||
/// Multiplies or screens the colors, depending on the backdrop color value. | ||
Overlay = 3, | ||
/// Selects the darker of the backdrop and source colors. | ||
Darken = 4, | ||
/// Selects the lighter of the backdrop and source colors. | ||
Lighten = 5, | ||
/// Brightens the backdrop color to reflect the source color. Painting with black produces no | ||
/// change. | ||
ColorDodge = 6, | ||
/// Darkens the backdrop color to reflect the source color. Painting with white produces no | ||
/// change. | ||
ColorBurn = 7, | ||
/// Multiplies or screens the colors, depending on the source color value. The effect is | ||
/// similar to shining a harsh spotlight on the backdrop. | ||
HardLight = 8, | ||
/// Darkens or lightens the colors, depending on the source color value. The effect is similar | ||
/// to shining a diffused spotlight on the backdrop. | ||
SoftLight = 9, | ||
/// Subtracts the darker of the two constituent colors from the lighter color. | ||
Difference = 10, | ||
/// Produces an effect similar to that of the Difference mode but lower in contrast. Painting | ||
/// with white inverts the backdrop color; painting with black produces no change. | ||
Exclusion = 11, | ||
/// Creates a color with the hue of the source color and the saturation and luminosity of the | ||
/// backdrop color. | ||
Hue = 12, | ||
/// Creates a color with the saturation of the source color and the hue and luminosity of the | ||
/// backdrop color. Painting with this mode in an area of the backdrop that is a pure gray | ||
/// (no saturation) produces no change. | ||
Saturation = 13, | ||
/// Creates a color with the hue and saturation of the source color and the luminosity of the | ||
/// backdrop color. This preserves the gray levels of the backdrop and is useful for coloring | ||
/// monochrome images or tinting color images. | ||
Color = 14, | ||
/// Creates a color with the luminosity of the source color and the hue and saturation of the | ||
/// backdrop color. This produces an inverse effect to that of the Color mode. | ||
Luminosity = 15, | ||
/// Clip is the same as normal, but the latter always creates an isolated blend group and the | ||
/// former can optimize that out. | ||
Clip = 128, | ||
} | ||
|
||
/// Defines the layer composition function for a blend operation. | ||
#[derive(Copy, Clone, PartialEq, Eq, Debug)] | ||
#[repr(C)] | ||
pub enum Compose { | ||
/// No regions are enabled. | ||
Clear = 0, | ||
/// Only the source will be present. | ||
Copy = 1, | ||
/// Only the destination will be present. | ||
Dest = 2, | ||
/// The source is placed over the destination. | ||
SrcOver = 3, | ||
/// The destination is placed over the source. | ||
DestOver = 4, | ||
/// The parts of the source that overlap with the destination are placed. | ||
SrcIn = 5, | ||
/// The parts of the destination that overlap with the source are placed. | ||
DestIn = 6, | ||
/// The parts of the source that fall outside of the destination are placed. | ||
SrcOut = 7, | ||
/// The parts of the destination that fall outside of the source are placed. | ||
DestOut = 8, | ||
/// The parts of the source which overlap the destination replace the destination. The | ||
/// destination is placed everywhere else. | ||
SrcAtop = 9, | ||
/// The parts of the destination which overlaps the source replace the source. The source is | ||
/// placed everywhere else. | ||
DestAtop = 10, | ||
/// The non-overlapping regions of source and destination are combined. | ||
Xor = 11, | ||
/// The sum of the source image and destination image is displayed. | ||
Plus = 12, | ||
/// Allows two elements to cross fade by changing their opacities from 0 to 1 on one | ||
/// element and 1 to 0 on the other element. | ||
PlusLighter = 13, | ||
} | ||
|
||
/// Blend mode consisting of color mixing and composition functions. | ||
#[derive(Copy, Clone, PartialEq, Eq, Debug)] | ||
pub struct BlendMode { | ||
/// The color mixing function. | ||
pub mix: Mix, | ||
/// The layer composition function. | ||
pub compose: Compose, | ||
} | ||
|
||
impl BlendMode { | ||
/// Creates a new blend mode from color mixing and layer composition | ||
/// functions. | ||
pub fn new(mix: Mix, compose: Compose) -> Self { | ||
Self { mix, compose } | ||
} | ||
} | ||
|
||
impl Default for BlendMode { | ||
fn default() -> Self { | ||
Self { | ||
mix: Mix::Clip, | ||
compose: Compose::SrcOver, | ||
} | ||
} | ||
} | ||
|
||
impl From<Mix> for BlendMode { | ||
fn from(mix: Mix) -> Self { | ||
Self { | ||
mix, | ||
compose: Compose::SrcOver, | ||
} | ||
} | ||
} | ||
|
||
impl From<Compose> for BlendMode { | ||
fn from(compose: Compose) -> Self { | ||
Self { | ||
mix: Mix::Normal, | ||
compose, | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
// Copyright 2022 The peniko authors. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// https://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
// Also licensed under MIT license, at your choice. | ||
|
||
mod color; | ||
mod gradient; | ||
mod image; | ||
|
||
pub use color::Color; | ||
pub use gradient::{ | ||
ColorStop, ColorStops, ColorStopsSource, LinearGradient, RadialGradient, SweepGradient, | ||
}; | ||
pub use image::Format; | ||
|
||
/// Describes the color content of a filled or stroked shape. | ||
#[derive(Clone, PartialEq, Debug)] | ||
pub enum Brush { | ||
/// Solid color brush. | ||
Solid(Color), | ||
/// Linear gradient brush. | ||
LinearGradient(LinearGradient), | ||
/// Radial gradient brush. | ||
RadialGradient(RadialGradient), | ||
/// Sweep gradient brush. | ||
SweepGradient(SweepGradient), | ||
} | ||
|
||
impl From<Color> for Brush { | ||
fn from(c: Color) -> Self { | ||
Self::Solid(c) | ||
} | ||
} | ||
|
||
impl From<LinearGradient> for Brush { | ||
fn from(g: LinearGradient) -> Self { | ||
Self::LinearGradient(g) | ||
} | ||
} | ||
|
||
impl From<RadialGradient> for Brush { | ||
fn from(g: RadialGradient) -> Self { | ||
Self::RadialGradient(g) | ||
} | ||
} | ||
|
||
impl From<SweepGradient> for Brush { | ||
fn from(g: SweepGradient) -> Self { | ||
Self::SweepGradient(g) | ||
} | ||
} | ||
|
||
/// Reference to a brush. | ||
/// | ||
/// This is useful for methods that would like to accept brushes by reference. Defining | ||
/// the type as `impl<Into<BrushRef>>` allows accepting types like `&LinearGradient` | ||
/// directly without cloning or allocating. | ||
#[derive(Clone, PartialEq, Debug)] | ||
pub enum BrushRef<'a> { | ||
/// Solid color brush. | ||
Solid(Color), | ||
/// Linear gradient brush. | ||
LinearGradient(&'a LinearGradient), | ||
/// Radial gradient brush. | ||
RadialGradient(&'a RadialGradient), | ||
/// Sweep gradient brush. | ||
SweepGradient(&'a SweepGradient), | ||
} | ||
|
||
impl From<Color> for BrushRef<'_> { | ||
fn from(color: Color) -> Self { | ||
Self::Solid(color) | ||
} | ||
} | ||
|
||
impl<'a> From<&'a Color> for BrushRef<'_> { | ||
fn from(color: &'a Color) -> Self { | ||
Self::Solid(*color) | ||
} | ||
} | ||
|
||
impl<'a> From<&'a LinearGradient> for BrushRef<'a> { | ||
fn from(gradient: &'a LinearGradient) -> Self { | ||
Self::LinearGradient(gradient) | ||
} | ||
} | ||
|
||
impl<'a> From<&'a RadialGradient> for BrushRef<'a> { | ||
fn from(gradient: &'a RadialGradient) -> Self { | ||
Self::RadialGradient(gradient) | ||
} | ||
} | ||
|
||
impl<'a> From<&'a SweepGradient> for BrushRef<'a> { | ||
fn from(gradient: &'a SweepGradient) -> Self { | ||
Self::SweepGradient(gradient) | ||
} | ||
} | ||
|
||
impl<'a> From<&'a Brush> for BrushRef<'a> { | ||
fn from(brush: &'a Brush) -> Self { | ||
match brush { | ||
Brush::Solid(color) => Self::Solid(*color), | ||
Brush::LinearGradient(gradient) => Self::LinearGradient(gradient), | ||
Brush::RadialGradient(gradient) => Self::RadialGradient(gradient), | ||
Brush::SweepGradient(gradient) => Self::SweepGradient(gradient), | ||
} | ||
} | ||
} | ||
|
||
/// Defines how a brush is extended when the content does not | ||
/// fill a shape. | ||
#[derive(Copy, Clone, PartialEq, Eq, Default, Debug)] | ||
pub enum Extend { | ||
/// Extends the image by repeating the edge color of the brush. | ||
#[default] | ||
Pad, | ||
/// Extends the image by repeating the brush. | ||
Repeat, | ||
/// Extends the image by reflecting the brush. | ||
Reflect, | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be nice to have this a little more filled out - author, description, readme link, keywords.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Definitely will do.