Skip to content

Commit

Permalink
fix invalid pixel interpretation when sharpening in sRGB blending mod…
Browse files Browse the repository at this point in the history
…e, don't hide color management errors caused by anything other than invalid profiles
  • Loading branch information
saucecontrol committed Dec 23, 2017
1 parent 95210e1 commit 9f30b88
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 43 deletions.
4 changes: 2 additions & 2 deletions doc/web.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ The `WebRSizeModule` must receive event notifications for static image requests
</modules>
</system.webServer>
```
Omit the `preCondition` attribute on the module entry to ensure it will see all requests, managed or not. The `WebRSizeModule` detects when it has been manually registered and will skip self-registration. This option will always work and is the safe way to go if you are in doubt.
Omit the `preCondition` attribute on the module entry to ensure it will see all requests, managed or not. The `WebRSizeModule` detects when it has been manually registered and will skip self-registration. This option will always work and is the safe way to go if you are in doubt.
3. You can set up an explicit handler mapping for image file extension you want to process that maps to a managed `IHttpHandler`.
Expand All @@ -47,7 +47,7 @@ Omit the `preCondition` attribute on the module entry to ensure it will see all
</handlers>
</system.webServer>
```
This is common in scenarios where images will be served from a `VirtualPathProvider` that uses a database or cloud storage. The built-in `StaticFileHandler` will request files from the registered `VirtualPathProvider`, and because the handler is managed, the self-registered `WebRSizeModule` instance will be able to intercept image processing requests.
This is common in scenarios where images will be served from a `VirtualPathProvider` that uses a database or cloud storage. The built-in `StaticFileHandler` will request files from the registered `VirtualPathProvider`, and because the handler is managed, the self-registered `WebRSizeModule` instance will be able to intercept image processing requests.
## Configuration Reference
Expand Down
48 changes: 15 additions & 33 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
MagicScaler
===========

MagicScaler brings high-performance, high-quality image scaling to .NET.
High-performance image processing pipeline for .NET. Implements best-of-breed algorithms, linear light processing, and sharpening for the best image resizing quality available. Speed and efficiency are unmatched by anything else on the .NET platform.

Requirements
------------
Expand All @@ -26,9 +26,15 @@ Basic usage looks something like this:

```C#
using (var outStream = new FileStream(@"c:\smallimage.jpg", FileMode.Create))
{
MagicImageProcessor.ProcessImage(@"c:\bigimage.jpg", outStream, new ProcessImageSettings { Width = 400 });
}
```

The above example will resize `bigimage.jpg` to a width of 400 pixels and save the output to `smallimage.jpg`. The height will be set automatically to preserve the correct aspect ratio. Default settings are optimized for a balance of speed and image quality.

The MagicScaler pipleline is also customizable if you wish to use an alternate pixel source, capture the output pixels for additional processing, or add custom filtering.

See the [documentation page](doc/main.md) for more details.


Expand Down Expand Up @@ -61,44 +67,20 @@ See the [documentation page](doc/web.md) for more details.

Release History
---------------
#### MagicScaler 0.8.2.0
* No longer throws an exception if an image contains an invalid embedded ICC profile. Color management is silently skipped in these cases.

#### MagicScaler 0.8.1.0
* Fixed "Unsupported Pixel Format" error when converting 16-bit CMYK to RGB formats using an ICC profile

#### MagicScaler 0.8.0.0
NOTE: This version contains breaking changes to the API. While your code will most likely not require changes, you will have to rebuild when upgrading.

* Changed parameter names on public methods to be more descriptive.
* Changed ProcessImage() overloads that accepted byte[] to accept ArraySegment&lt;byte&gt;.
* Added metadata support (including Exif auto-rotation) to the .NET Core version.
* Added ImageFileInfo class to expose basic information read from image headers.
* Added IPixelSource interface to allow clients to feed pixels into the pipeline from custom sources.
* Added IPixelTransform class to allow custom filtering.
* Added ProcessingPipeline class to allow clients to request pixels from the pipeline without saving directly to an image file.
* Added ProcessImageResults class to expose calculated settings used and basic instrumentation.
* Added sample IPixelSource and IPixelTransform implementations.
* Improved fixed-point math accuracy for non-SIMD implementation.
* Improved RGBA performance in SIMD implementation.
* Improved Auto output format logic to match WebRSize.
* Fixed invalid crop values when using Hybrid scaling.
* Fixed invalid crop offsets when using Planar mode.
* UnsharpMaskSettings no longer overrides the Sharpen setting. If Sharpen is false, there will be no auto-sharpening regardless of UnsharpMaskSettings.

#### WebRSize 0.3.0.0
NOTE: Cache file naming has changed in this version. You should empty your WebRSize disk cache when upgrading.

* Changed cache file name generator to use the correct file extension when transcoding to a different format.
* Fixed a bug in the cache file name generator that caused duplicate cache files.
* Improved speed and reduced allocations in the HTTP intercept module.
#### WebRSize 0.3.1.0
* Require MagicScaler 0.8.3 or later
* Fix nuget config transform to place `configSections` as the first child of `configuration`

#### MagicScaler 0.8.3.0
* Fixed image corruption (and possible access violation) when sharpening BGR/BGRA images in sRGB blending mode.
* Use latest System.Buffers version for .NET Framework installations

See the [releases page](https://github.com/saucecontrol/PhotoSauce/releases) for previous updates.

Versioning
----------

This project is using [semantic versioning](http://semver.org/). Releases without an alpha/beta/RC tag are considered release quality and are safe for production use. The major version number will remain at 0, however, until the APIs are complete and stabilized. You can expect significant API changes coming in MagicScaler 0.8.
This project is using [semantic versioning](http://semver.org/). Releases without an alpha/beta/RC tag are considered release quality and are safe for production use. The major version number will remain at 0, however, until the APIs are complete and stabilized.

Contributing
------------
Expand Down
2 changes: 1 addition & 1 deletion src/MagicScaler/Interop/PropVariant.cs
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ unsafe public IntPtr MarshalManagedToNative(object o)

int cbNative = Marshal.SizeOf<UnmanagedPropVariant>();
var pNativeData = Marshal.AllocCoTaskMem(cbNative);
Unsafe.InitBlock(pNativeData.ToPointer(), default(byte), (uint)cbNative);
Unsafe.InitBlock(pNativeData.ToPointer(), default, (uint)cbNative);

if (o == null)
return pNativeData;
Expand Down
4 changes: 3 additions & 1 deletion src/MagicScaler/Interop/WinCodec.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,9 @@ internal enum WinCodecError
WINCODEC_ERR_REQUESTONLYVALIDATMETADATAROOT = unchecked((int)0x88982f92),
WINCODEC_ERR_INVALIDQUERYCHARACTER = unchecked((int)0x88982f93),
WINCODEC_ERR_WIN32ERROR = unchecked((int)0x88982f94),
WINCODEC_ERR_INVALIDPROGRESSIVELEVEL = unchecked((int)0x88982f95)
WINCODEC_ERR_INVALIDPROGRESSIVELEVEL = unchecked((int)0x88982f95),

ERROR_INVALID_PROFILE = unchecked((int)0x800707DB)
}

[Flags]
Expand Down
3 changes: 2 additions & 1 deletion src/MagicScaler/Magic/ConvolutionTransform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ public ConvolutionTransform(PixelSource source, KernelMap<TWeight> mapx, KernelM
if (fmt.ColorRepresentation == PixelColorRepresentation.Bgr || fmt.ColorRepresentation == PixelColorRepresentation.Grey)
fmt = fmt.NumericRepresentation == PixelNumericRepresentation.Float ? PixelFormat.Cache[Consts.GUID_WICPixelFormat32bppGrayFloat] :
fmt.NumericRepresentation == PixelNumericRepresentation.Fixed ? PixelFormat.Grey16BppUQ15 :
Format;
fmt.NumericRepresentation == PixelNumericRepresentation.UnsignedInteger ? PixelFormat.Cache[Consts.GUID_WICPixelFormat8bppGray] :
throw new NotSupportedException("Unsupported pixel format");
else
throw new NotSupportedException("Unsupported pixel format");
}
Expand Down
4 changes: 2 additions & 2 deletions src/MagicScaler/Magic/KernelMap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ unsafe private KernelMap<T> clamp()
Unsafe.Write(mpw + k, a);

for (int j = 1; j < samp; j++)
Unsafe.Write(mpw + j * chan + k, j < samp - o ? Unsafe.Read<T>(mpw + j * chan + o * chan + k) : default(T));
Unsafe.Write(mpw + j * chan + k, j < samp - o ? Unsafe.Read<T>(mpw + j * chan + o * chan + k) : default);
}
}
else if (start + samp > ipix)
Expand All @@ -122,7 +122,7 @@ unsafe private KernelMap<T> clamp()
Unsafe.Write(mpw + last * chan + k, a);

for (int j = last - 1; j >= 0; j--)
Unsafe.Write(mpw + j * chan + k, j >= o ? Unsafe.Read<T>(mpw + j * chan - o * chan + k) : default(T));
Unsafe.Write(mpw + j * chan + k, j >= o ? Unsafe.Read<T>(mpw + j * chan - o * chan + k) : default);
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/MagicScaler/MagicScaler.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<RuntimeFrameworkVersion Condition=" '$(TargetFramework)' == 'netcoreapp1.0' ">1.0.4</RuntimeFrameworkVersion>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<LangVersion>latest</LangVersion>
<VersionPrefix>0.8.2</VersionPrefix>
<VersionPrefix>0.8.3</VersionPrefix>
<Authors>Clinton Ingram</Authors>
<Company>PhotoSauce</Company>
<Product>MagicScaler</Product>
Expand Down Expand Up @@ -44,7 +44,7 @@
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'net46' Or '$(TargetFramework)' == 'netstandard1.3' ">
<PackageReference Include="System.Buffers" Version="4.3.0" />
<PackageReference Include="System.Buffers" Version="4.4.0" />
<PackageReference Include="System.Numerics.Vectors" Version="4.4.0" />
</ItemGroup>

Expand Down
4 changes: 4 additions & 0 deletions src/MagicScaler/Utilities/WinCodecExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Runtime.InteropServices;

namespace PhotoSauce.MagicScaler.Interop
{
Expand Down Expand Up @@ -67,6 +68,9 @@ public static bool TrySetMetadataByName(this IWICMetadataQueryWriter meta, strin
public static bool TryInitialize(this IWICColorTransform trans, IWICBitmapSource source, IWICColorContext ctxSrc, IWICColorContext ctxDest, Guid fmtDest)
{
int hr = ProxyFunctions.InitializeColorTransform(trans, source, ctxSrc, ctxDest, fmtDest);
if (hr < 0 && hr != (int)WinCodecError.ERROR_INVALID_PROFILE)
Marshal.ThrowExceptionForHR(hr);

return hr >= 0;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/WebRSize/WebRSize.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<AssemblyTitle>WebRSize</AssemblyTitle>
<TargetFramework>net46</TargetFramework>
<LangVersion>latest</LangVersion>
<VersionPrefix>0.3.0</VersionPrefix>
<VersionPrefix>0.3.1</VersionPrefix>
<Authors>Clinton Ingram</Authors>
<Description>Web extensions for the MagicScaler library, inlcluding an HTTP request intercept module for automatic image processing.</Description>
<Company>PhotoSauce</Company>
Expand Down

0 comments on commit 9f30b88

Please sign in to comment.