Skip to content

Commit 4bda224

Browse files
Merge pull request #1463 from Voxel8/me/issue1459
Filter processor should use scaled vectors.
2 parents 58ec498 + a311a16 commit 4bda224

File tree

2 files changed

+33
-4
lines changed

2 files changed

+33
-4
lines changed

src/ImageSharp/Processing/Processors/Filters/FilterProcessor{TPixel}.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,11 @@ public RowOperation(
7272
public void Invoke(int y, Span<Vector4> span)
7373
{
7474
Span<TPixel> rowSpan = this.source.GetPixelRowSpan(y).Slice(this.startX, span.Length);
75-
PixelOperations<TPixel>.Instance.ToVector4(this.configuration, rowSpan, span);
75+
PixelOperations<TPixel>.Instance.ToVector4(this.configuration, rowSpan, span, PixelConversionModifiers.Scale);
7676

7777
ColorNumerics.Transform(span, ref Unsafe.AsRef(this.matrix));
7878

79-
PixelOperations<TPixel>.Instance.FromVector4Destructive(this.configuration, span, rowSpan);
79+
PixelOperations<TPixel>.Instance.FromVector4Destructive(this.configuration, span, rowSpan, PixelConversionModifiers.Scale);
8080
}
8181
}
8282
}

tests/ImageSharp.Tests/Processing/Filters/BrightnessTest.cs

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
// Copyright (c) Six Labors.
1+
// Copyright (c) Six Labors.
22
// Licensed under the Apache License, Version 2.0.
33

4+
using SixLabors.ImageSharp.PixelFormats;
45
using SixLabors.ImageSharp.Processing;
56
using SixLabors.ImageSharp.Processing.Processors.Filters;
67
using Xunit;
@@ -26,5 +27,33 @@ public void Brightness_amount_rect_BrightnessProcessorDefaultsSet()
2627

2728
Assert.Equal(1.5F, processor.Amount);
2829
}
30+
31+
[Fact]
32+
public void Brightness_scaled_vector()
33+
{
34+
var rgbImage = new Image<Rgb24>(Configuration.Default, 100, 100, new Rgb24(0, 0, 0));
35+
36+
rgbImage.Mutate(x => x.ApplyProcessor(new BrightnessProcessor(2)));
37+
38+
Assert.Equal(new Rgb24(0, 0, 0), rgbImage[0, 0]);
39+
40+
rgbImage = new Image<Rgb24>(Configuration.Default, 100, 100, new Rgb24(10, 10, 10));
41+
42+
rgbImage.Mutate(x => x.ApplyProcessor(new BrightnessProcessor(2)));
43+
44+
Assert.Equal(new Rgb24(20, 20, 20), rgbImage[0, 0]);
45+
46+
var halfSingleImage = new Image<HalfSingle>(Configuration.Default, 100, 100, new HalfSingle(-1));
47+
48+
halfSingleImage.Mutate(x => x.ApplyProcessor(new BrightnessProcessor(2)));
49+
50+
Assert.Equal(new HalfSingle(-1), halfSingleImage[0, 0]);
51+
52+
halfSingleImage = new Image<HalfSingle>(Configuration.Default, 100, 100, new HalfSingle(-0.5f));
53+
54+
halfSingleImage.Mutate(x => x.ApplyProcessor(new BrightnessProcessor(2)));
55+
56+
Assert.Equal(new HalfSingle(0), halfSingleImage[0, 0]);
57+
}
2958
}
30-
}
59+
}

0 commit comments

Comments
 (0)