Skip to content

Commit

Permalink
Added IsTileable property to effects (PintaProject#556)
Browse files Browse the repository at this point in the history
* Added `IsTileable` property to effects

* Improved documentation comment

---------

Co-authored-by: Lehonti Ramos <lehonti@ramos>
  • Loading branch information
Lehonti and Lehonti Ramos committed Oct 11, 2023
1 parent 21aacdd commit 9c24acf
Show file tree
Hide file tree
Showing 39 changed files with 143 additions and 59 deletions.
10 changes: 9 additions & 1 deletion Pinta.Core/Effects/BaseEffect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 25,7 @@
// THE SOFTWARE.

using System;
using System.Diagnostics;
using Cairo;
using Mono.Addins;
using Mono.Addins.Localization;
Expand All @@ -37,6 38,13 @@ namespace Pinta.Core;
[Mono.Addins.TypeExtensionPoint]
public abstract class BaseEffect
{
/// <summary>
/// Specifies whether Render() can be called separately (and possibly in parallel) for different sub-regions of the image.
/// If false, Render () will be called once with the entire region the effect is applied to.
/// This is required for effects which cannot be applied independently to each pixel, e.g. if the effect accumulates information from previously processed pixels.
/// </summary>
public abstract bool IsTileable { get; }

/// <summary>
/// Returns the name of the effect, displayed to the user in the Adjustments/Effects menu and history pad.
/// </summary>
Expand Down Expand Up @@ -223,7 231,7 @@ public virtual EffectData Clone ()
/// <summary>
/// Wrapper around the AddinLocalizer of an add-in.
/// </summary>
internal class AddinLocalizerWrapper : IAddinLocalizer
internal sealed class AddinLocalizerWrapper : IAddinLocalizer
{
private readonly AddinLocalizer localizer;

Expand Down
2 changes: 2 additions & 0 deletions Pinta.Effects/Adjustments/AutoLevelEffect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 17,8 @@ public sealed class AutoLevelEffect : BaseEffect
{
UnaryPixelOps.Level? op;

public sealed override bool IsTileable => true;

public override string Icon => Pinta.Resources.Icons.AdjustmentsAutoLevel;

public override string Name => Translations.GetString ("Auto Level");
Expand Down
2 changes: 2 additions & 0 deletions Pinta.Effects/Adjustments/BlackAndWhiteEffect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 17,8 @@ public sealed class BlackAndWhiteEffect : BaseEffect
{
readonly UnaryPixelOp op = new UnaryPixelOps.Desaturate ();

public sealed override bool IsTileable => true;

public override string Icon => Pinta.Resources.Icons.AdjustmentsBlackAndWhite;

public override string Name => Translations.GetString ("Black and White");
Expand Down
8 changes: 5 additions & 3 deletions Pinta.Effects/Adjustments/BrightnessContrastEffect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 21,8 @@ public sealed class BrightnessContrastEffect : BaseEffect
private byte[]? rgb_table;
private bool table_calculated;

public sealed override bool IsTileable => true;

public override string Icon => Pinta.Resources.Icons.AdjustmentsBrightnessContrast;

public override string Name => Translations.GetString ("Brightness / Contrast");
Expand Down Expand Up @@ -132,7 134,7 @@ private void Calculate ()
table_calculated = true;
}

public class BrightnessContrastData : EffectData
public sealed class BrightnessContrastData : EffectData
{
private int brightness = 0;
private int contrast = 0;
Expand All @@ -143,7 145,7 @@ public int Brightness {
set {
if (value != brightness) {
brightness = value;
FirePropertyChanged ("Brightness");
FirePropertyChanged (nameof (Brightness));
}
}
}
Expand All @@ -154,7 156,7 @@ public int Contrast {
set {
if (value != contrast) {
contrast = value;
FirePropertyChanged ("Contrast");
FirePropertyChanged (nameof (Contrast));
}
}
}
Expand Down
4 changes: 3 additions & 1 deletion Pinta.Effects/Adjustments/CurvesEffect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 19,8 @@ public sealed class CurvesEffect : BaseEffect
{
UnaryPixelOp? op = null;

public sealed override bool IsTileable => true;

public override string Icon => Pinta.Resources.Icons.AdjustmentsCurves;

public override string Name => Translations.GetString ("Curves");
Expand Down Expand Up @@ -107,7 109,7 @@ private UnaryPixelOp MakeUop ()
}
}

public class CurvesData : EffectData
public sealed class CurvesData : EffectData
{
public SortedList<int, int>[]? ControlPoints { get; set; }

Expand Down
2 changes: 2 additions & 0 deletions Pinta.Effects/Adjustments/HueSaturationEffect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 16,8 @@ namespace Pinta.Effects;

public sealed class HueSaturationEffect : BaseEffect
{
public sealed override bool IsTileable => true;

public override string Icon => Pinta.Resources.Icons.AdjustmentsHueSaturation;

public override string Name => Translations.GetString ("Hue / Saturation");
Expand Down
2 changes: 2 additions & 0 deletions Pinta.Effects/Adjustments/InvertColorsEffect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 17,8 @@ public sealed class InvertColorsEffect : BaseEffect
{
readonly UnaryPixelOp op = new UnaryPixelOps.Invert ();

public sealed override bool IsTileable => true;

public override string Icon => Pinta.Resources.Icons.AdjustmentsInvertColors;

public override string Name => Translations.GetString ("Invert Colors");
Expand Down
6 changes: 4 additions & 2 deletions Pinta.Effects/Adjustments/LevelsEffect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 15,8 @@ namespace Pinta.Effects;

public sealed class LevelsEffect : BaseEffect
{
public sealed override bool IsTileable => true;

public override string Icon => Pinta.Resources.Icons.AdjustmentsLevels;

public override string Name => Translations.GetString ("Levels");
Expand Down Expand Up @@ -55,7 57,7 @@ public override void Render (ImageSurface src, ImageSurface dest, ReadOnlySpan<R
}
}

public class LevelsData : EffectData
public sealed class LevelsData : EffectData
{
public UnaryPixelOps.Level Levels { get; set; }

Expand All @@ -66,6 68,6 @@ public LevelsData ()

public override EffectData Clone ()
{
return new LevelsData () { Levels = (UnaryPixelOps.Level) Levels.Clone () };
return new LevelsData { Levels = (UnaryPixelOps.Level) Levels.Clone () };
}
}
8 changes: 5 additions & 3 deletions Pinta.Effects/Adjustments/PosterizeEffect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 17,8 @@ public sealed class PosterizeEffect : BaseEffect
{
UnaryPixelOps.PosterizePixel? op = null;

public sealed override bool IsTileable => true;

public override string Icon => Pinta.Resources.Icons.AdjustmentsPosterize;

public override string Name => Translations.GetString ("Posterize");
Expand Down Expand Up @@ -58,7 60,7 @@ public override void Render (ImageSurface src, ImageSurface dest, ReadOnlySpan<R

public sealed class PosterizeData : EffectData
{
public int Red = 16;
public int Green = 16;
public int Blue = 16;
public int Red { get; set; } = 16;
public int Green { get; set; } = 16;
public int Blue { get; set; } = 16;
}
2 changes: 2 additions & 0 deletions Pinta.Effects/Adjustments/SepiaEffect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 18,8 @@ public sealed class SepiaEffect : BaseEffect
readonly UnaryPixelOp desat = new UnaryPixelOps.Desaturate ();
readonly UnaryPixelOp level = new UnaryPixelOps.Desaturate ();

public sealed override bool IsTileable => true;

public override string Icon => Pinta.Resources.Icons.AdjustmentsSepia;

public override string Name => Translations.GetString ("Sepia");
Expand Down
8 changes: 5 additions & 3 deletions Pinta.Effects/Effects/AddNoiseEffect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 21,8 @@ public sealed class AddNoiseEffect : BaseEffect
private int color_saturation;
private double coverage;

public sealed override bool IsTileable => true;

public override string Icon => Pinta.Resources.Icons.EffectsNoiseAddNoise;

public override string Name => Translations.GetString ("Add Noise");
Expand Down Expand Up @@ -166,12 168,12 @@ public override void Render (ImageSurface src, ImageSurface dst, ReadOnlySpan<Re
public sealed class NoiseData : EffectData
{
[Caption ("Intensity"), MinimumValue (0), MaximumValue (100)]
public int Intensity = 64;
public int Intensity { get; set; } = 64;

[Caption ("Color Saturation"), MinimumValue (0), MaximumValue (400)]
public int ColorSaturation = 100;
public int ColorSaturation { get; set; } = 100;

[Caption ("Coverage"), MinimumValue (0), DigitsValue (2), MaximumValue (100)]
public double Coverage = 100.0;
public double Coverage { get; set; } = 100.0;
}
}
6 changes: 4 additions & 2 deletions Pinta.Effects/Effects/BulgeEffect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 16,8 @@ namespace Pinta.Effects;

public sealed class BulgeEffect : BaseEffect
{
public sealed override bool IsTileable => true;

public override string Icon => Pinta.Resources.Icons.EffectsDistortBulge;

public override string Name => Translations.GetString ("Bulge");
Expand Down Expand Up @@ -85,10 87,10 @@ public override void Render (ImageSurface src, ImageSurface dst, ReadOnlySpan<Re
public sealed class BulgeData : EffectData
{
[Caption ("Amount"), MinimumValue (-200), MaximumValue (100)]
public int Amount = 45;
public int Amount { get; set; } = 45;

[Caption ("Offset")]
public Core.PointD Offset = new (0.0, 0.0);
public Core.PointD Offset { get; set; } = new (0.0, 0.0);

[Skip]
public override bool IsDefault => Amount == 0;
Expand Down
16 changes: 9 additions & 7 deletions Pinta.Effects/Effects/CloudsEffect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 22,8 @@ public sealed class CloudsEffect : BaseEffect
private readonly byte instance_seed = unchecked((byte) DateTime.Now.Ticks);
private static readonly object render_lock = new ();

public sealed override bool IsTileable => true;

public override string Icon => Pinta.Resources.Icons.EffectsRenderClouds;

public override string Name => Translations.GetString ("Clouds");
Expand Down Expand Up @@ -193,16 195,16 @@ public sealed class CloudsData : EffectData
public override bool IsDefault => Power == 0;

[Caption ("Scale"), MinimumValue (2), MaximumValue (1000)]
public int Scale = 250;
public int Scale { get; set; } = 250;

[Caption ("Power"), MinimumValue (0), MaximumValue (100)]
public int Power = 50;
public int Power { get; set; } = 50;

[Skip]
public static Dictionary<string, object> BlendOps;
public static Dictionary<string, object> BlendOps { get; }

[Skip]
private static readonly string defaultBlendOp;
private static readonly string default_blend_op;

static CloudsData ()
{
Expand All @@ -211,14 213,14 @@ static CloudsData ()
foreach (string name in UserBlendOps.GetAllBlendModeNames ()) {
BlendOps.Add (name, UserBlendOps.GetBlendModeByName (name));
}
defaultBlendOp = UserBlendOps.GetBlendModeName (Pinta.Core.BlendMode.Normal);
default_blend_op = UserBlendOps.GetBlendModeName (Pinta.Core.BlendMode.Normal);
}

[StaticList ("BlendOps")]
public string BlendMode = defaultBlendOp;
public string BlendMode { get; set; } = default_blend_op;

[Caption ("Seed"), MinimumValue (0), MaximumValue (255)]
public int Seed = 0;
public int Seed { get; set; } = 0;

}
}
4 changes: 3 additions & 1 deletion Pinta.Effects/Effects/EdgeDetectEffect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 18,8 @@ public sealed class EdgeDetectEffect : ColorDifferenceEffect
{
public override string Icon => Pinta.Resources.Icons.EffectsStylizeEdgeDetect;

public sealed override bool IsTileable => true;

public override string Name => Translations.GetString ("Edge Detect");

public override bool IsConfigurable => true;
Expand Down Expand Up @@ -76,5 78,5 @@ private double[][] ComputeWeights ()
public sealed class EdgeDetectData : EffectData
{
[Caption ("Angle")]
public double Angle = 45;
public double Angle { get; set; } = 45;
}
4 changes: 3 additions & 1 deletion Pinta.Effects/Effects/EmbossEffect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 18,8 @@ public sealed class EmbossEffect : BaseEffect
{
public override string Icon => Pinta.Resources.Icons.EffectsStylizeEmboss;

public sealed override bool IsTileable => true;

public override string Name => Translations.GetString ("Emboss");

public override bool IsConfigurable => true;
Expand Down Expand Up @@ -131,6 133,6 @@ public override void Render (ImageSurface src, ImageSurface dst, ReadOnlySpan<Re
public sealed class EmbossData : EffectData
{
[Caption ("Angle")]
public double Angle = 0;
public double Angle { get; set; } = 0;
}
}
8 changes: 5 additions & 3 deletions Pinta.Effects/Effects/FragmentEffect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 19,8 @@ public sealed class FragmentEffect : BaseEffect
{
public override string Icon => Pinta.Resources.Icons.EffectsBlursFragment;

public sealed override bool IsTileable => true;

public override string Name => Translations.GetString ("Fragment");

public override bool IsConfigurable => true;
Expand Down Expand Up @@ -103,12 105,12 @@ public override void Render (ImageSurface src, ImageSurface dst, ReadOnlySpan<Re
public sealed class FragmentData : EffectData
{
[Caption ("Fragments"), MinimumValue (2), MaximumValue (50)]
public int Fragments = 4;
public int Fragments { get; set; } = 4;

[Caption ("Distance"), MinimumValue (0), MaximumValue (100)]
public int Distance = 8;
public int Distance { get; set; } = 8;

[Caption ("Rotation")]
public double Rotation = 0;
public double Rotation { get; set; } = 0;
}
}
2 changes: 2 additions & 0 deletions Pinta.Effects/Effects/FrostedGlassEffect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 18,8 @@ public sealed class FrostedGlassEffect : BaseEffect
{
public override string Icon => Pinta.Resources.Icons.EffectsDistortFrostedGlass;

public sealed override bool IsTileable => true;

public override string Name => Translations.GetString ("Frosted Glass");

public override bool IsConfigurable => true;
Expand Down
4 changes: 3 additions & 1 deletion Pinta.Effects/Effects/GaussianBlurEffect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 19,8 @@ public sealed class GaussianBlurEffect : BaseEffect
{
public override string Icon => Pinta.Resources.Icons.EffectsBlursGaussianBlur;

public sealed override bool IsTileable => true;

public override string Name => Translations.GetString ("Gaussian Blur");

public override bool IsConfigurable => true;
Expand Down Expand Up @@ -241,7 243,7 @@ public override void Render (ImageSurface src, ImageSurface dest, ReadOnlySpan<R
public sealed class GaussianBlurData : EffectData
{
[Caption ("Radius"), MinimumValue (0), MaximumValue (200)]
public int Radius = 2;
public int Radius { get; set; } = 2;

[Skip]
public override bool IsDefault => Radius == 0;
Expand Down
8 changes: 5 additions & 3 deletions Pinta.Effects/Effects/GlowEffect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 22,8 @@ public sealed class GlowEffect : BaseEffect

public override string Icon => Pinta.Resources.Icons.EffectsPhotoGlow;

public sealed override bool IsTileable => true;

public override string Name => Translations.GetString ("Glow");

public override bool IsConfigurable => true;
Expand Down Expand Up @@ -72,10 74,10 @@ public override void Render (ImageSurface src, ImageSurface dest, ReadOnlySpan<R
public sealed class GlowData : EffectData
{
[Caption ("Radius"), MinimumValue (1), MaximumValue (20)]
public int Radius = 6;
public int Radius { get; set; } = 6;
[Caption ("Brightness"), MinimumValue (-100), MaximumValue (100)]
public int Brightness = 10;
public int Brightness { get; set; } = 10;
[Caption ("Contrast"), MinimumValue (-100), MaximumValue (100)]
public int Contrast = 10;
public int Contrast { get; set; } = 10;
}
}
6 changes: 4 additions & 2 deletions Pinta.Effects/Effects/InkSketchEffect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 26,8 @@ public sealed class InkSketchEffect : BaseEffect

public override string Icon => Pinta.Resources.Icons.EffectsArtisticInkSketch;

public sealed override bool IsTileable => true;

public override string Name => Translations.GetString ("Ink Sketch");

public override bool IsConfigurable => true;
Expand Down Expand Up @@ -151,9 153,9 @@ public override void Render (ImageSurface src, ImageSurface dest, ReadOnlySpan<R
public sealed class InkSketchData : EffectData
{
[Caption ("Ink Outline"), MinimumValue (0), MaximumValue (99)]
public int InkOutline = 50;
public int InkOutline { get; set; } = 50;

[Caption ("Coloring"), MinimumValue (0), MaximumValue (100)]
public int Coloring = 50;
public int Coloring { get; set; } = 50;
}
}
Loading

0 comments on commit 9c24acf

Please sign in to comment.