Skip to content

Commit

Permalink
Enable NRT for Pinta.Effects.
Browse files Browse the repository at this point in the history
  • Loading branch information
jpobst committed Dec 23, 2020
1 parent 2b9e366 commit 37a9f7a
Show file tree
Hide file tree
Showing 43 changed files with 104 additions and 60 deletions.
2 changes: 1 addition & 1 deletion Pinta.Core/Classes/ObservableObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ protected void SetValue<T> (string propertyName, ref T member, T value)
FirePropertyChanged (propertyName);
}

protected void FirePropertyChanged (string propertyName)
protected void FirePropertyChanged (string? propertyName)
{
if (PropertyChanged != null)
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
Expand Down
2 changes: 1 addition & 1 deletion Pinta.Core/Effects/BaseEffect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ public virtual EffectData Clone ()
/// Fires the PropertyChanged event for this ObservableObject.
/// </summary>
/// <param name="propertyName">The name of the property that changed.</param>
public new void FirePropertyChanged (string propertyName)
public new void FirePropertyChanged (string? propertyName)
{
base.FirePropertyChanged (propertyName);
}
Expand Down
2 changes: 1 addition & 1 deletion Pinta.Effects/Adjustments/AutoLevelEffect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace Pinta.Effects
{
public class AutoLevelEffect : BaseEffect
{
UnaryPixelOps.Level op;
UnaryPixelOps.Level? op;

public override string Icon {
get { return "Menu.Adjustments.AutoLevel.png"; }
Expand Down
10 changes: 5 additions & 5 deletions Pinta.Effects/Adjustments/BrightnessContrastEffect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class BrightnessContrastEffect : BaseEffect
{
private int multiply;
private int divide;
private byte[] rgbTable;
private byte[]? rgbTable;
private bool table_calculated;

public override string Icon {
Expand All @@ -37,7 +37,7 @@ public override string AdjustmentMenuKey {
get { return "B"; }
}

public BrightnessContrastData Data { get { return EffectData as BrightnessContrastData; } }
public BrightnessContrastData Data { get { return (BrightnessContrastData)EffectData!; } } // NRT - Set in constructor

public BrightnessContrastEffect ()
{
Expand All @@ -48,7 +48,7 @@ public BrightnessContrastEffect ()
/// <summary>
/// If any of the effect data was changed, we need to recalculate the rgb table before rendering
/// </summary>
void HandleEffectDataPropertyChanged (object sender, System.ComponentModel.PropertyChangedEventArgs e)
void HandleEffectDataPropertyChanged (object? sender, System.ComponentModel.PropertyChangedEventArgs e)
{
table_calculated = false;
}
Expand All @@ -73,7 +73,7 @@ public unsafe override void Render (ImageSurface src, ImageSurface dest, Gdk.Rec
while (dstRowPtr < dstRowEndPtr) {
ColorBgra col = *srcRowPtr;
int i = col.GetIntensityByte ();
uint c = rgbTable[i];
uint c = rgbTable![i]; // NRT - Set in Calculate
dstRowPtr->Bgra = (col.Bgra & 0xff000000) | c | (c << 8) | (c << 16);

++dstRowPtr;
Expand All @@ -85,7 +85,7 @@ public unsafe override void Render (ImageSurface src, ImageSurface dest, Gdk.Rec
int i = col.GetIntensityByte ();
int shiftIndex = i * 256;

col.R = rgbTable[shiftIndex + col.R];
col.R = rgbTable![shiftIndex + col.R];
col.G = rgbTable[shiftIndex + col.G];
col.B = rgbTable[shiftIndex + col.B];

Expand Down
8 changes: 4 additions & 4 deletions Pinta.Effects/Adjustments/CurvesEffect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace Pinta.Effects
{
public class CurvesEffect : BaseEffect
{
UnaryPixelOp op = null;
UnaryPixelOp? op = null;

public override string Icon {
get { return "Menu.Adjustments.Curves.png"; }
Expand All @@ -35,7 +35,7 @@ public override string AdjustmentMenuKey {
get { return "M"; }
}

public CurvesData Data { get { return EffectData as CurvesData; } }
public CurvesData Data { get { return (CurvesData)EffectData!; } } // NRT - Set in constructor

public CurvesEffect ()
{
Expand Down Expand Up @@ -95,7 +95,7 @@ private UnaryPixelOp MakeUop()
int channels = transferCurves.Length;

for (int channel = 0; channel < channels; channel++) {
SortedList<int, int> channelControlPoints = Data.ControlPoints[channel];
SortedList<int, int> channelControlPoints = Data.ControlPoints![channel]; // NRT - Code expects this to be not-null
IList<int> xa = channelControlPoints.Keys;
IList<int> ya = channelControlPoints.Values;
SplineInterpolator interpolator = new SplineInterpolator();
Expand All @@ -116,7 +116,7 @@ private UnaryPixelOp MakeUop()

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

public ColorTransferMode Mode { get; set; }

Expand Down
4 changes: 2 additions & 2 deletions Pinta.Effects/Adjustments/HueSaturationEffect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace Pinta.Effects
{
public class HueSaturationEffect : BaseEffect
{
UnaryPixelOp op;
UnaryPixelOp? op;

public override string Icon {
get { return "Menu.Adjustments.HueAndSaturation.png"; }
Expand Down Expand Up @@ -60,7 +60,7 @@ public override void Render (ImageSurface src, ImageSurface dest, Gdk.Rectangle[
op.Apply (dest, src, rois);
}

private HueSaturationData Data { get { return EffectData as HueSaturationData; } }
private HueSaturationData Data { get { return (HueSaturationData)EffectData!; } } // NRT - Set in constructor

private class HueSaturationData : EffectData
{
Expand Down
2 changes: 1 addition & 1 deletion Pinta.Effects/Adjustments/LevelsEffect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public override string AdjustmentMenuKeyModifiers {
get { return "<Primary>"; }
}

public LevelsData Data { get { return EffectData as LevelsData; } }
public LevelsData Data { get { return (LevelsData)EffectData!; } } // NRT - Set in constructor

public LevelsEffect ()
{
Expand Down
4 changes: 2 additions & 2 deletions Pinta.Effects/Adjustments/PosterizeEffect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace Pinta.Effects
{
public class PosterizeEffect : BaseEffect
{
UnaryPixelOps.PosterizePixel op = null;
UnaryPixelOps.PosterizePixel? op = null;

public override string Icon {
get { return "Menu.Adjustments.Posterize.png"; }
Expand All @@ -33,7 +33,7 @@ public override string AdjustmentMenuKey {
get { return "P"; }
}

public PosterizeData Data { get { return EffectData as PosterizeData; } }
public PosterizeData Data { get { return (PosterizeData)EffectData!; } } // NRT - Set in constructor

public PosterizeEffect ()
{
Expand Down
14 changes: 8 additions & 6 deletions Pinta.Effects/Dialogs/Effects.CurvesDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
using Cairo;

using Pinta.Core;
using System.Diagnostics.CodeAnalysis;

namespace Pinta.Effects
{
Expand Down Expand Up @@ -61,9 +62,9 @@ private class ControlPointDrawingInfo
private int last_cpx;

//control points for luminosity transfer mode
private SortedList<int, int>[] luminosity_cps;
private SortedList<int, int>[] luminosity_cps = null!; // NRT - Set via code flow
//control points for rg transfer mode
private SortedList<int, int>[] rgb_cps;
private SortedList<int, int>[] rgb_cps = null!;

public SortedList<int, int>[] ControlPoints {
get {
Expand Down Expand Up @@ -119,12 +120,12 @@ private void UpdateLivePreview (string propertyName)
}
}

private void HandleCheckToggled (object o, EventArgs args)
private void HandleCheckToggled (object? o, EventArgs args)
{
InvalidateDrawing ();
}

void HandleButtonResetClicked (object sender, EventArgs e)
void HandleButtonResetClicked (object? sender, EventArgs e)
{
ResetControlPoints ();
InvalidateDrawing ();
Expand All @@ -146,7 +147,7 @@ private void ResetControlPoints()
UpdateLivePreview ("ControlPoints");
}

private void HandleComboMapChanged (object sender, EventArgs e)
private void HandleComboMapChanged (object? sender, EventArgs e)
{
if (ControlPoints == null)
ResetControlPoints ();
Expand All @@ -165,7 +166,7 @@ private void InvalidateDrawing ()
drawing.Window.Invalidate();
}

private void HandleDrawingLeaveNotifyEvent (object o, Gtk.LeaveNotifyEventArgs args)
private void HandleDrawingLeaveNotifyEvent (object? o, Gtk.LeaveNotifyEventArgs args)
{
InvalidateDrawing ();
}
Expand Down Expand Up @@ -414,6 +415,7 @@ private void HandleDrawingDrawnEvent (object o, Gtk.DrawnArgs args)
DrawControlPoints(g);
}

[MemberNotNull (nameof (comboMap), nameof (labelPoint), nameof (labelTip), nameof (checkRed), nameof (checkGreen), nameof (checkBlue), nameof (buttonReset), nameof (drawing))]
private void Build ()
{
WindowPosition = WindowPosition.CenterOnParent;
Expand Down
2 changes: 2 additions & 0 deletions Pinta.Effects/Dialogs/Effects.LevelsDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

#nullable disable

using System;
using Gtk;
using Cairo;
Expand Down
11 changes: 8 additions & 3 deletions Pinta.Effects/Dialogs/Effects.PosterizeDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
// THE SOFTWARE.

using System;
using System.Diagnostics.CodeAnalysis;
using Gtk;
using Pinta.Core;
using Pinta.Gui.Widgets;
Expand All @@ -50,7 +51,7 @@ public int Blue {
get { return blue_spinbox.ValueAsInt; }
}

public PosterizeData EffectData { get; set; }
public PosterizeData? EffectData { get; set; }

public PosterizeDialog () : base (Translations.GetString ("Posterize"),
PintaCore.Chrome.MainWindow, DialogFlags.Modal,
Expand All @@ -65,10 +66,13 @@ public PosterizeDialog () : base (Translations.GetString ("Posterize"),
DefaultResponse = Gtk.ResponseType.Ok;
}

private void HandleValueChanged (object sender, EventArgs e)
private void HandleValueChanged (object? sender, EventArgs e)
{
var widget = sender as HScaleSpinButtonWidget;


if (widget is null)
return;

if (link_button.Active)
green_spinbox.Value = blue_spinbox.Value = red_spinbox.Value = widget.Value;

Expand Down Expand Up @@ -96,6 +100,7 @@ private void InitSpinBox (HScaleSpinButtonWidget spinbox)
ContentArea.Add (spinbox);
}

[MemberNotNull (nameof (red_spinbox), nameof (green_spinbox), nameof (blue_spinbox), nameof (link_button))]
private void Build ()
{
Resizable = false;
Expand Down
4 changes: 3 additions & 1 deletion Pinta.Effects/Effects/AddNoiseEffect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using Cairo;
using Pinta.Gui.Widgets;
using Pinta.Core;
using System.Diagnostics.CodeAnalysis;

namespace Pinta.Effects
{
Expand All @@ -36,7 +37,7 @@ public override string EffectMenuCategory {
get { return Translations.GetString ("Noise"); }
}

public NoiseData Data { get { return EffectData as NoiseData; } }
public NoiseData Data { get { return (NoiseData)EffectData!; } } // NRT - Set in constructor

static AddNoiseEffect ()
{
Expand Down Expand Up @@ -64,6 +65,7 @@ private static double NormalCurve (double x, double scale)
return scale * Math.Exp (-x * x / 2);
}

[MemberNotNull (nameof (lookup))]
private static void InitLookup ()
{
double l = 5;
Expand Down
2 changes: 1 addition & 1 deletion Pinta.Effects/Effects/BulgeEffect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public override string EffectMenuCategory {
}

public BulgeData Data {
get { return EffectData as BulgeData; }
get { return (BulgeData)EffectData!; } // NRT - Set in constructor
}

public BulgeEffect ()
Expand Down
2 changes: 1 addition & 1 deletion Pinta.Effects/Effects/CloudsEffect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public override string EffectMenuCategory {
get { return Translations.GetString ("Render"); }
}

public CloudsData Data { get { return EffectData as CloudsData; } }
public CloudsData Data { get { return (CloudsData)EffectData!; } } // NRT - Set in constructor

public CloudsEffect ()
{
Expand Down
8 changes: 5 additions & 3 deletions Pinta.Effects/Effects/EdgeDetectEffect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@

using Pinta.Gui.Widgets;
using Pinta.Core;
using System.Diagnostics.CodeAnalysis;

namespace Pinta.Effects
{
public class EdgeDetectEffect : ColorDifferenceEffect
{
private double[][] weights;
private double[][]? weights;

public override string Icon {
get { return "Menu.Effects.Stylize.EdgeDetect.png"; }
Expand All @@ -35,7 +36,7 @@ public override string EffectMenuCategory {
get { return Translations.GetString ("Stylize"); }
}

public EdgeDetectData Data { get { return EffectData as EdgeDetectData; } }
public EdgeDetectData Data { get { return (EdgeDetectData)EffectData!; } } // NRT - Set in constructor

public EdgeDetectEffect ()
{
Expand All @@ -52,7 +53,8 @@ public unsafe override void Render (ImageSurface src, ImageSurface dest, Gdk.Rec
SetWeights ();
base.RenderColorDifferenceEffect (weights, src, dest, rois);
}


[MemberNotNull (nameof (weights))]
private void SetWeights ()
{
weights = new double[3][];
Expand Down
2 changes: 1 addition & 1 deletion Pinta.Effects/Effects/EmbossEffect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public override string EffectMenuCategory {
}

public EmbossData Data {
get { return EffectData as EmbossData; }
get { return (EmbossData)EffectData!; } // NRT - Set in constructor
}

public EmbossEffect () {
Expand Down
2 changes: 1 addition & 1 deletion Pinta.Effects/Effects/FragmentEffect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public override string EffectMenuCategory {
get { return Translations.GetString ("Blurs"); }
}

public FragmentData Data { get { return EffectData as FragmentData; } }
public FragmentData Data { get { return (FragmentData)EffectData!; } } // NRT - Set in constructor

public FragmentEffect ()
{
Expand Down
2 changes: 1 addition & 1 deletion Pinta.Effects/Effects/FrostedGlassEffect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public override string EffectMenuCategory {
}

public FrostedGlassData Data {
get { return EffectData as FrostedGlassData; }
get { return (FrostedGlassData)EffectData!; } // NRT - Set in constructor
}

private Random random = new Random ();
Expand Down
2 changes: 1 addition & 1 deletion Pinta.Effects/Effects/GaussianBlurEffect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public override string EffectMenuCategory {
get { return Translations.GetString ("Blurs"); }
}

public GaussianBlurData Data { get { return EffectData as GaussianBlurData; } }
public GaussianBlurData Data { get { return (GaussianBlurData)EffectData!; } } // NRT - Set in constructor

public GaussianBlurEffect ()
{
Expand Down
2 changes: 1 addition & 1 deletion Pinta.Effects/Effects/GlowEffect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public override string EffectMenuCategory {
get { return Translations.GetString ("Photo"); }
}

public GlowData Data { get { return EffectData as GlowData; } }
public GlowData Data { get { return (GlowData)EffectData!; } } // NRT - Set in constructor

public GlowEffect ()
{
Expand Down
2 changes: 1 addition & 1 deletion Pinta.Effects/Effects/InkSketchEffect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public override string EffectMenuCategory {
get { return Translations.GetString ("Artistic"); }
}

public InkSketchData Data { get { return EffectData as InkSketchData; } }
public InkSketchData Data { get { return (InkSketchData)EffectData!; } } // NRT - Set in constructor

public InkSketchEffect ()
{
Expand Down
Loading

0 comments on commit 37a9f7a

Please sign in to comment.