Skip to content

Commit

Permalink
getting ready for new pixel formats, fix planar 4:2:2 bug
Browse files Browse the repository at this point in the history
  • Loading branch information
saucecontrol committed Jan 21, 2017
1 parent 543255d commit 4bdfd8f
Show file tree
Hide file tree
Showing 9 changed files with 95 additions and 79 deletions.
4 changes: 2 additions & 2 deletions doc/main.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ Default Value: 0

Indicates whether an [unsharp mask](https://en.wikipedia.org/wiki/Unsharp_masking) operation should be performed on the image following the resize. The sharpening settings are controlled by the [UnsharpMask](#unsharpmask-unsharpmasksettings) property.

Default value: false
Default value: true

###ResizeMode: CropScaleMode

Expand Down Expand Up @@ -288,7 +288,7 @@ A reference to an object implementing IInterpolator, which specifies the samplin

###Blur: double

A value used to stretch (or compress) the sampling range for the filter. The default and recommnded value is 1. You may use a value greater than 1 to blur or smooth the sampling function. Values less than 1 can cause unpleasant artifacts.
A value used to stretch (or compress) the sampling range for the filter. The default and recommended value is 1. You may use a value greater than 1 to blur or smooth the sampling function. Values less than 1 can cause unpleasant artifacts.

##IInterpolator

Expand Down
3 changes: 3 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ See the [documentation page](doc/main.md) for more details.
Release History
---------------

####0.6.1.0
* Fixed argument out of range error when using planar scaling with 4:2:2 subsampled JPEG source images.

####0.6.0.0
* Fixed invalid color profile error when using hybrid scaling with non-JPEG CMYK images.
* Enabled sharpening by default. This can be disabled with the Sharpen property on ProcessImageSettings.
Expand Down
137 changes: 75 additions & 62 deletions src/Interop/WinCodec.cs

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions src/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
[assembly: AssemblyCopyright("Copyright © Clinton Ingram 2015-2017")]
[assembly: AssemblyCulture("")]

[assembly: AssemblyVersion("0.6.0.0")]
[assembly: AssemblyFileVersion("0.6.0.0")]
[assembly: AssemblyVersion("0.6.1.0")]
[assembly: AssemblyFileVersion("0.6.1.0")]

[assembly: ComVisible(false)]

Expand Down
16 changes: 8 additions & 8 deletions src/WIC/Generated/WicConvolution.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public WicConvolution8bpc(IWICBitmapSource source, KernelMap mapx, KernelMap map
else
throw new NotSupportedException("Unsupported pixel format");

Stride /= 1;
Stride /= sizeof(byte);
IntStride = (int)(mapy.SampleCount * Channels);

LineBuff = new byte[(bufferSource ? mapy.SampleCount : 1) * Stride];
Expand Down Expand Up @@ -122,9 +122,9 @@ unsafe protected void LoadBuffer(byte* bstart, int* tstart, int* mapxstart, int*
if (tk > 0)
{
if (BufferSource)
Buffer.MemoryCopy(bstart + tc * Stride, bstart, LineBuff.LongLength * 1, tk * Stride * 1);
Buffer.MemoryCopy(bstart + tc * Stride, bstart, LineBuff.LongLength * sizeof(byte), tk * Stride * sizeof(byte));

Buffer.MemoryCopy(tstart + tc * Channels, tstart, IntBuff.LongLength * 4, (IntBuff.LongLength - tc * Channels) * 4);
Buffer.MemoryCopy(tstart + tc * Channels, tstart, IntBuff.LongLength * sizeof(int), (IntBuff.LongLength - tc * Channels) * sizeof(int));
}

for (int ty = tk; ty < smapy; ty++)
Expand All @@ -133,7 +133,7 @@ unsafe protected void LoadBuffer(byte* bstart, int* tstart, int* mapxstart, int*
int* tline = tstart + ty * Channels;

SourceRect.Y = iy + ty;
Source.CopyPixels(SourceRect, Stride * 1, Stride * 1, (IntPtr)bline);
Source.CopyPixels(SourceRect, Stride * sizeof(byte), Stride * sizeof(byte), (IntPtr)bline);

Processor.ConvolveSourceLine(bline, tline, IntStride, IntBuff.Length, mapxstart, mapxastart, XMap.SampleCount);
}
Expand Down Expand Up @@ -206,7 +206,7 @@ public WicConvolution16bpc(IWICBitmapSource source, KernelMap mapx, KernelMap ma
else
throw new NotSupportedException("Unsupported pixel format");

Stride /= 2;
Stride /= sizeof(ushort);
IntStride = (int)(mapy.SampleCount * Channels);

LineBuff = new ushort[(bufferSource ? mapy.SampleCount : 1) * Stride];
Expand Down Expand Up @@ -263,9 +263,9 @@ unsafe protected void LoadBuffer(ushort* bstart, int* tstart, int* mapxstart, in
if (tk > 0)
{
if (BufferSource)
Buffer.MemoryCopy(bstart + tc * Stride, bstart, LineBuff.LongLength * 2, tk * Stride * 2);
Buffer.MemoryCopy(bstart + tc * Stride, bstart, LineBuff.LongLength * sizeof(ushort), tk * Stride * sizeof(ushort));

Buffer.MemoryCopy(tstart + tc * Channels, tstart, IntBuff.LongLength * 4, (IntBuff.LongLength - tc * Channels) * 4);
Buffer.MemoryCopy(tstart + tc * Channels, tstart, IntBuff.LongLength * sizeof(int), (IntBuff.LongLength - tc * Channels) * sizeof(int));
}

for (int ty = tk; ty < smapy; ty++)
Expand All @@ -274,7 +274,7 @@ unsafe protected void LoadBuffer(ushort* bstart, int* tstart, int* mapxstart, in
int* tline = tstart + ty * Channels;

SourceRect.Y = iy + ty;
Source.CopyPixels(SourceRect, Stride * 2, Stride * 2, (IntPtr)bline);
Source.CopyPixels(SourceRect, Stride * sizeof(ushort), Stride * sizeof(ushort), (IntPtr)bline);

Processor.ConvolveSourceLine(bline, tline, IntStride, IntBuff.Length, mapxstart, mapxastart, XMap.SampleCount);
}
Expand Down
4 changes: 2 additions & 2 deletions src/WIC/WicFormatConverters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,9 @@ unsafe public override void CopyPixels(WICRect prc, uint cbStride, uint cbBuffer

byte* op = (byte*)pbBuffer + y * cbStride;
if (HasAlpha)
mapValuesWithAlpha((ushort*)(void*)bstart, op, gtstart, (uint)prc.Width * Bpp / 2);
mapValuesWithAlpha((ushort*)bstart, op, gtstart, (uint)prc.Width * Bpp / sizeof(ushort));
else
mapValues((ushort*)(void*)bstart, op, gtstart, (uint)prc.Width * Bpp / 2);
mapValues((ushort*)bstart, op, gtstart, (uint)prc.Width * Bpp / sizeof(ushort));
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/WIC/WicMatte.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ unsafe public override void CopyPixels(WICRect prc, uint cbStride, uint cbBuffer

if (Format == Consts.GUID_WICPixelFormat64bppBGRA)
{
applyMatteLinear(prc, (ushort*)pbBuffer, (int)(cbStride / 2));
applyMatteLinear(prc, (ushort*)pbBuffer, (int)(cbStride / sizeof(ushort)));
}
else
{
Expand Down
2 changes: 1 addition & 1 deletion src/WIC/WicPlanarSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public WicPlanarCacheSource(IWICPlanarBitmapSourceTransform source, WICBitmapPla
buffHeightY = 16u;

strideC = (uint)(Math.Ceiling(scrop.Width / subsampleRatioX)) * 2u + 3u & ~3u;
buffHeightC = (uint)(buffHeightY / subsampleRatioX);
buffHeightC = (uint)(buffHeightY / subsampleRatioY);

sourceY = new WicPlanarSource(this, WicPlane.Luma, descY);
sourceC = new WicPlanarSource(this, WicPlane.Chroma, descC);
Expand Down
2 changes: 1 addition & 1 deletion src/WIC/WicTransform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ private static IWICColorContext getDefaultColorProfile(Guid pixelFormat)

public WicMetadataReader(WicTransform prev, bool basicOnly = false) : base(prev)
{
var pfi = AddRef(Wic.CreateComponentInfo(Context.PixelFormat) as IWICPixelFormatInfo2);
var pfi = AddRef(Wic.CreateComponentInfo(Context.PixelFormat)) as IWICPixelFormatInfo2;
if (pfi.GetNumericRepresentation() == WICPixelFormatNumericRepresentation.WICPixelFormatNumericRepresentationIndexed)
{
var pal = AddRef(Wic.CreatePalette());
Expand Down

0 comments on commit 4bdfd8f

Please sign in to comment.