Browse Source

ColorMatrix4x4 should allow alpha component transform

pull/22/head
James Jackson-South 9 years ago
parent
commit
160302ae4b
  1. 27
      src/ImageSharp/Filters/Processors/ColorMatrix/BlackWhiteProcessor.cs
  2. 19
      src/ImageSharp/Filters/Processors/ColorMatrix/ColorBlindness/AchromatomalyProcessor.cs
  3. 19
      src/ImageSharp/Filters/Processors/ColorMatrix/ColorBlindness/AchromatopsiaProcessor.cs
  4. 15
      src/ImageSharp/Filters/Processors/ColorMatrix/ColorBlindness/DeuteranomalyProcessor.cs
  5. 15
      src/ImageSharp/Filters/Processors/ColorMatrix/ColorBlindness/DeuteranopiaProcessor.cs
  6. 15
      src/ImageSharp/Filters/Processors/ColorMatrix/ColorBlindness/ProtanomalyProcessor.cs
  7. 15
      src/ImageSharp/Filters/Processors/ColorMatrix/ColorBlindness/ProtanopiaProcessor.cs
  8. 15
      src/ImageSharp/Filters/Processors/ColorMatrix/ColorBlindness/TritanomalyProcessor.cs
  9. 15
      src/ImageSharp/Filters/Processors/ColorMatrix/ColorBlindness/TritanopiaProcessor.cs
  10. 3
      src/ImageSharp/Filters/Processors/ColorMatrix/ColorMatrixFilter.cs
  11. 21
      src/ImageSharp/Filters/Processors/ColorMatrix/GrayscaleBt601Processor.cs
  12. 21
      src/ImageSharp/Filters/Processors/ColorMatrix/GrayscaleBt709Processor.cs
  13. 3
      src/ImageSharp/Filters/Processors/ColorMatrix/HueProcessor.cs
  14. 15
      src/ImageSharp/Filters/Processors/ColorMatrix/KodachromeProcessor.cs
  15. 15
      src/ImageSharp/Filters/Processors/ColorMatrix/LomographProcessor.cs
  16. 25
      src/ImageSharp/Filters/Processors/ColorMatrix/PolaroidProcessor.cs
  17. 5
      src/ImageSharp/Filters/Processors/ColorMatrix/SaturationProcessor.cs
  18. 21
      src/ImageSharp/Filters/Processors/ColorMatrix/SepiaProcessor.cs

27
src/ImageSharp/Filters/Processors/ColorMatrix/BlackWhiteProcessor.cs

@ -19,18 +19,19 @@ namespace ImageSharp.Processors
/// <inheritdoc/>
public override Matrix4x4 Matrix => new Matrix4x4()
{
M11 = 1.5f,
M12 = 1.5f,
M13 = 1.5f,
M21 = 1.5f,
M22 = 1.5f,
M23 = 1.5f,
M31 = 1.5f,
M32 = 1.5f,
M33 = 1.5f,
M41 = -1f,
M42 = -1f,
M43 = -1f,
M11 = 1.5F,
M12 = 1.5F,
M13 = 1.5F,
M21 = 1.5F,
M22 = 1.5F,
M23 = 1.5F,
M31 = 1.5F,
M32 = 1.5F,
M33 = 1.5F,
M41 = -1F,
M42 = -1F,
M43 = -1F,
M44 = 1
};
}
}
}

19
src/ImageSharp/Filters/Processors/ColorMatrix/ColorBlindness/AchromatomalyProcessor.cs

@ -19,15 +19,16 @@ namespace ImageSharp.Processors
/// <inheritdoc/>
public override Matrix4x4 Matrix => new Matrix4x4()
{
M11 = .618f,
M12 = .163f,
M13 = .163f,
M21 = .320f,
M22 = .775f,
M23 = .320f,
M31 = .062f,
M32 = .062f,
M33 = .516f
M11 = .618F,
M12 = .163F,
M13 = .163F,
M21 = .320F,
M22 = .775F,
M23 = .320F,
M31 = .062F,
M32 = .062F,
M33 = .516F,
M44 = 1
};
/// <inheritdoc/>

19
src/ImageSharp/Filters/Processors/ColorMatrix/ColorBlindness/AchromatopsiaProcessor.cs

@ -19,15 +19,16 @@ namespace ImageSharp.Processors
/// <inheritdoc/>
public override Matrix4x4 Matrix => new Matrix4x4()
{
M11 = .299f,
M12 = .299f,
M13 = .299f,
M21 = .587f,
M22 = .587f,
M23 = .587f,
M31 = .114f,
M32 = .114f,
M33 = .114f
M11 = .299F,
M12 = .299F,
M13 = .299F,
M21 = .587F,
M22 = .587F,
M23 = .587F,
M31 = .114F,
M32 = .114F,
M33 = .114F,
M44 = 1
};
/// <inheritdoc/>

15
src/ImageSharp/Filters/Processors/ColorMatrix/ColorBlindness/DeuteranomalyProcessor.cs

@ -19,15 +19,16 @@ namespace ImageSharp.Processors
/// <inheritdoc/>
public override Matrix4x4 Matrix => new Matrix4x4()
{
M11 = 0.8f,
M12 = 0.258f,
M21 = 0.2f,
M22 = 0.742f,
M23 = 0.142f,
M33 = 0.858f
M11 = 0.8F,
M12 = 0.258F,
M21 = 0.2F,
M22 = 0.742F,
M23 = 0.142F,
M33 = 0.858F,
M44 = 1
};
/// <inheritdoc/>
public override bool Compand => false;
}
}
}

15
src/ImageSharp/Filters/Processors/ColorMatrix/ColorBlindness/DeuteranopiaProcessor.cs

@ -19,15 +19,16 @@ namespace ImageSharp.Processors
/// <inheritdoc/>
public override Matrix4x4 Matrix => new Matrix4x4()
{
M11 = 0.625f,
M12 = 0.7f,
M21 = 0.375f,
M22 = 0.3f,
M23 = 0.3f,
M33 = 0.7f
M11 = 0.625F,
M12 = 0.7F,
M21 = 0.375F,
M22 = 0.3F,
M23 = 0.3F,
M33 = 0.7F,
M44 = 1
};
/// <inheritdoc/>
public override bool Compand => false;
}
}
}

15
src/ImageSharp/Filters/Processors/ColorMatrix/ColorBlindness/ProtanomalyProcessor.cs

@ -19,15 +19,16 @@ namespace ImageSharp.Processors
/// <inheritdoc/>
public override Matrix4x4 Matrix => new Matrix4x4()
{
M11 = 0.817f,
M12 = 0.333f,
M21 = 0.183f,
M22 = 0.667f,
M23 = 0.125f,
M33 = 0.875f
M11 = 0.817F,
M12 = 0.333F,
M21 = 0.183F,
M22 = 0.667F,
M23 = 0.125F,
M33 = 0.875F,
M44 = 1
};
/// <inheritdoc/>
public override bool Compand => false;
}
}
}

15
src/ImageSharp/Filters/Processors/ColorMatrix/ColorBlindness/ProtanopiaProcessor.cs

@ -19,15 +19,16 @@ namespace ImageSharp.Processors
/// <inheritdoc/>
public override Matrix4x4 Matrix => new Matrix4x4()
{
M11 = 0.567f,
M12 = 0.558f,
M21 = 0.433f,
M22 = 0.442f,
M23 = 0.242f,
M33 = 0.758f
M11 = 0.567F,
M12 = 0.558F,
M21 = 0.433F,
M22 = 0.442F,
M23 = 0.242F,
M33 = 0.758F,
M44 = 1
};
/// <inheritdoc/>
public override bool Compand => false;
}
}
}

15
src/ImageSharp/Filters/Processors/ColorMatrix/ColorBlindness/TritanomalyProcessor.cs

@ -19,15 +19,16 @@ namespace ImageSharp.Processors
/// <inheritdoc/>
public override Matrix4x4 Matrix => new Matrix4x4()
{
M11 = 0.967f,
M21 = 0.33f,
M22 = 0.733f,
M23 = 0.183f,
M32 = 0.267f,
M33 = 0.817f
M11 = 0.967F,
M21 = 0.33F,
M22 = 0.733F,
M23 = 0.183F,
M32 = 0.267F,
M33 = 0.817F,
M44 = 1
};
/// <inheritdoc/>
public override bool Compand => false;
}
}
}

15
src/ImageSharp/Filters/Processors/ColorMatrix/ColorBlindness/TritanopiaProcessor.cs

@ -19,15 +19,16 @@ namespace ImageSharp.Processors
/// <inheritdoc/>
public override Matrix4x4 Matrix => new Matrix4x4()
{
M11 = 0.95f,
M21 = 0.05f,
M22 = 0.433f,
M23 = 0.475f,
M32 = 0.567f,
M33 = 0.525f
M11 = 0.95F,
M21 = 0.05F,
M22 = 0.433F,
M23 = 0.475F,
M32 = 0.567F,
M33 = 0.525F,
M44 = 1
};
/// <inheritdoc/>
public override bool Compand => false;
}
}
}

3
src/ImageSharp/Filters/Processors/ColorMatrix/ColorMatrixFilter.cs

@ -86,8 +86,7 @@ namespace ImageSharp.Processors
vector = vector.Expand();
}
Vector3 transformed = Vector3.Transform(new Vector3(vector.X, vector.Y, vector.Z), matrix);
vector = new Vector4(transformed, vector.W);
vector = Vector4.Transform(vector, matrix);
TColor packed = default(TColor);
packed.PackFromVector4(compand ? vector.Compress() : vector);
return packed;

21
src/ImageSharp/Filters/Processors/ColorMatrix/GrayscaleBt601Processor.cs

@ -20,15 +20,16 @@ namespace ImageSharp.Processors
/// <inheritdoc/>
public override Matrix4x4 Matrix => new Matrix4x4()
{
M11 = .299f,
M12 = .299f,
M13 = .299f,
M21 = .587f,
M22 = .587f,
M23 = .587f,
M31 = .114f,
M32 = .114f,
M33 = .114f
M11 = .299F,
M12 = .299F,
M13 = .299F,
M21 = .587F,
M22 = .587F,
M23 = .587F,
M31 = .114F,
M32 = .114F,
M33 = .114F,
M44 = 1
};
}
}
}

21
src/ImageSharp/Filters/Processors/ColorMatrix/GrayscaleBt709Processor.cs

@ -20,15 +20,16 @@ namespace ImageSharp.Processors
/// <inheritdoc/>
public override Matrix4x4 Matrix => new Matrix4x4()
{
M11 = .2126f,
M12 = .2126f,
M13 = .2126f,
M21 = .7152f,
M22 = .7152f,
M23 = .7152f,
M31 = .0722f,
M32 = .0722f,
M33 = .0722f
M11 = .2126F,
M12 = .2126F,
M13 = .2126F,
M21 = .7152F,
M22 = .7152F,
M23 = .7152F,
M31 = .0722F,
M32 = .0722F,
M33 = .0722F,
M44 = 1
};
}
}
}

3
src/ImageSharp/Filters/Processors/ColorMatrix/HueProcessor.cs

@ -59,7 +59,8 @@ namespace ImageSharp.Processors
M23 = (float)(lumG - (cosradians * lumG) + (sinradians * lumG)),
M31 = (float)(lumB - (cosradians * lumB) + (sinradians * oneMinusLumB)),
M32 = (float)(lumB - (cosradians * lumB) - (sinradians * 0.283)),
M33 = (float)(lumB + (cosradians * oneMinusLumB) + (sinradians * lumB))
M33 = (float)(lumB + (cosradians * oneMinusLumB) + (sinradians * lumB)),
M44 = 1
};
this.Matrix = matrix4X4;

15
src/ImageSharp/Filters/Processors/ColorMatrix/KodachromeProcessor.cs

@ -19,12 +19,13 @@ namespace ImageSharp.Processors
/// <inheritdoc/>
public override Matrix4x4 Matrix => new Matrix4x4()
{
M11 = 0.6997023f,
M22 = 0.4609577f,
M33 = 0.397218f,
M41 = 0.005f,
M42 = -0.005f,
M43 = 0.005f
M11 = 0.6997023F,
M22 = 0.4609577F,
M33 = 0.397218F,
M41 = 0.005F,
M42 = -0.005F,
M43 = 0.005F,
M44 = 1
};
}
}
}

15
src/ImageSharp/Filters/Processors/ColorMatrix/LomographProcessor.cs

@ -19,12 +19,13 @@ namespace ImageSharp.Processors
/// <inheritdoc/>
public override Matrix4x4 Matrix => new Matrix4x4()
{
M11 = 1.5f,
M22 = 1.45f,
M33 = 1.11f,
M41 = -.1f,
M42 = .0f,
M43 = -.08f
M11 = 1.5F,
M22 = 1.45F,
M33 = 1.11F,
M41 = -.1F,
M42 = .0F,
M43 = -.08F,
M44 = 1
};
/// <inheritdoc/>
@ -35,4 +36,4 @@ namespace ImageSharp.Processors
new VignetteProcessor<TColor, TPacked> { VignetteColor = packed }.Apply(source, sourceRectangle);
}
}
}
}

25
src/ImageSharp/Filters/Processors/ColorMatrix/PolaroidProcessor.cs

@ -19,18 +19,19 @@ namespace ImageSharp.Processors
/// <inheritdoc/>
public override Matrix4x4 Matrix => new Matrix4x4()
{
M11 = 1.538f,
M12 = -0.062f,
M13 = -0.262f,
M21 = -0.022f,
M22 = 1.578f,
M23 = -0.022f,
M31 = .216f,
M32 = -.16f,
M33 = 1.5831f,
M41 = 0.02f,
M42 = -0.05f,
M43 = -0.05f
M11 = 1.538F,
M12 = -0.062F,
M13 = -0.262F,
M21 = -0.022F,
M22 = 1.578F,
M23 = -0.022F,
M31 = .216F,
M32 = -.16F,
M33 = 1.5831F,
M41 = 0.02F,
M42 = -0.05F,
M43 = -0.05F,
M44 = 1
};
/// <inheritdoc/>

5
src/ImageSharp/Filters/Processors/ColorMatrix/SaturationProcessor.cs

@ -26,7 +26,7 @@ namespace ImageSharp.Processors
public SaturationProcessor(int saturation)
{
Guard.MustBeBetweenOrEqualTo(saturation, -100, 100, nameof(saturation));
float saturationFactor = saturation / 100f;
float saturationFactor = saturation / 100F;
// Stop at -1 to prevent inversion.
saturationFactor++;
@ -40,7 +40,7 @@ namespace ImageSharp.Processors
float saturationComplementG = 0.6094f * saturationComplement;
float saturationComplementB = 0.0820f * saturationComplement;
Matrix4x4 matrix4X4 = new Matrix4x4()
Matrix4x4 matrix4X4 = new Matrix4x4
{
M11 = saturationComplementR + saturationFactor,
M12 = saturationComplementR,
@ -51,6 +51,7 @@ namespace ImageSharp.Processors
M31 = saturationComplementB,
M32 = saturationComplementB,
M33 = saturationComplementB + saturationFactor,
M44 = 1
};
this.Matrix = matrix4X4;

21
src/ImageSharp/Filters/Processors/ColorMatrix/SepiaProcessor.cs

@ -18,17 +18,18 @@ namespace ImageSharp.Processors
where TPacked : struct
{
/// <inheritdoc/>
public override Matrix4x4 Matrix => new Matrix4x4()
public override Matrix4x4 Matrix => new Matrix4x4
{
M11 = .393f,
M12 = .349f,
M13 = .272f,
M21 = .769f,
M22 = .686f,
M23 = .534f,
M31 = .189f,
M32 = .168f,
M33 = .131f
M11 = .393F,
M12 = .349F,
M13 = .272F,
M21 = .769F,
M22 = .686F,
M23 = .534F,
M31 = .189F,
M32 = .168F,
M33 = .131F,
M44 = 1
};
/// <inheritdoc/>

Loading…
Cancel
Save