Skip to content

Instantly share code, notes, and snippets.

View antonfirsov's full-sized avatar

Anton Firszov antonfirsov

View GitHub Profile
public void RunThisOnYourDevice()
{
string inputImagesRoot = "YourRootToImages"; // https://github.com/SixLabors/ImageSharp/tree/master/tests/Images/Input
string reportFile = Path.Combine("WhateverPathYouCanWriteTo", "Report.txt");
string[] files = Directory.EnumerateFiles(
inputImagesRoot,
"*.*",
SearchOption.AllDirectories).Where(
f => Path.GetExtension(f).ToLower() == ".png" || Path.GetExtension(f).ToLower() == ".jpg"
// Contains a general pixel-format independant color definition
public struct Color
{
private Rgba64 data; // Could be also Vector4, but that would probably lead to compatibility issues.
public Color(Rgba64 pixel) { this.data = pixel; }
public Color(Rgba32 pixel) { this.data.FromRgba32(pixel); }
public Color(Vector4 vector) { this.data.FromVector4(vector); }
// No longer a static utility class, but a base class for the pixel-type aware Image<TPixel>.
// Nevertheless, it contains all the static methods, just as before.
public abstract class Image
{
// The generic methods load pixel-aware images:
public static Image<TPixel> Load<TPixel>(....);
// The non-generic methods load pixel-agnostic images:
public static Image Load(...);

DecodeJpegParseStreamOnly

Runs JpegDecoderCore.ParseStream() on jpeg420exif.jpg

Setup

BenchmarkDotNet=v0.11.5, OS=Windows 10.0.17134.706 (1803/April2018Update/Redstone4)
Intel Core i7-7700HQ CPU 2.80GHz (Kaby Lake), 1 CPU, 8 logical and 4 physical cores
Frequency=2742189 Hz, Resolution=364.6722 ns, Timer=TSC
.NET Core SDK=2.2.202
  [Host] : .NET Core 2.1.9 (CoreCLR 4.6.27414.06, CoreFX 4.6.27415.01), 64bit RyuJIT
public unsafe class WriteableBitmapMemoryManager : MemoryManager<Bgra32> {
private readonly WriteableBitmap bitmap;
private IBufferByteAccess pixelBuffer;
private byte* pixelBytes;
private readonly int length;
/// <summary>
/// Initializes a new instance of the <see cref="WriteableBitmapMemoryManager"/> class.
/// </summary>

JPEG & Exif

  • [2018-09-07] #698 - Allow several invalid data types when reading the exif resolution.
  • [2018-09-07] #699 - Fix EXIF overflow and Jpeg decoding
  • [2018-09-11] #686 - Ext.DrawImage generalization to support multiple formats. (Experimental)
  • [2018-10-04] #722 - Fix #721 ||| incorrect App0 markers
  • [2018-10-05] #724 - Decode components in correct order + cleanup + optimizations. ||| interleaved progressive jpegs
  • [2018-11-05] #768 - Various Jpeg optimizations
  • [2018-12-30] #784 - Jpeg 12 bit support
  • [2019-01-06] #801 - #797 throw ImageFormatException when no StartOfFrame marker is found
  • [2019-01-09] #804 - Use bounds checks in Huffman ctr. Fix #798
@antonfirsov
antonfirsov / OldKernelMap.MD
Last active November 29, 2018 02:42
Smart ResizeKernelMap
0.81138 0.24055 -0.05193 0.00000
-0.03204 0.64517 0.44502 -0.05815 0.00000
0.00000 -0.05836 0.44661 0.64748 -0.03216 -0.00357
0.00000 -0.05038 0.23337 0.78718 0.05522 -0.02539
-0.02539 0.05522 0.78718 0.23337 -0.05038 0.00000
-0.00357 -0.03216 0.64748 0.44661 -0.05836 0.00000
0.00000 -0.05836 0.44661 0.64748 -0.03216 -0.00357
Oh no! Gray16(256) != Gray16(257)
Oh no! Gray16(512) != Gray16(514)
Oh no! Gray16(768) != Gray16(771)
Oh no! Gray16(1024) != Gray16(1028)
Oh no! Gray16(1280) != Gray16(1284)
Oh no! Gray16(1536) != Gray16(1542)
Oh no! Gray16(1792) != Gray16(1799)
Oh no! Gray16(2048) != Gray16(2056)
Oh no! Gray16(2304) != Gray16(2313)
@antonfirsov
antonfirsov / PixelConversion_Rgba32_To_Argb32.OldLaptop.txt
Last active October 23, 2018 22:49
Conversion Benchmarks (Old Samsung Notebook)
BenchmarkDotNet=v0.10.14, OS=Windows 10.0.15063.786 (1703/CreatorsUpdate/Redstone2)
Intel Core i7-3630QM CPU 2.40GHz (Ivy Bridge), 1 CPU, 8 logical and 4 physical cores
Frequency=2338446 Hz, Resolution=427.6344 ns, Timer=TSC
.NET Core SDK=2.1.302
[Host] : .NET Core 2.1.2 (CoreCLR 4.6.26628.05, CoreFX 4.6.26629.01), 64bit RyuJIT
DefaultJob : .NET Core 2.1.2 (CoreCLR 4.6.26628.05, CoreFX 4.6.26629.01), 64bit RyuJIT
Method | Count | Mean | Error | StdDev | Median | Scaled | ScaledSD |
------------------------------- |------ |----------:|----------:|-----------:|----------:|-------:|---------:|
@antonfirsov
antonfirsov / Rgba32ToVector4-01.txt
Last active October 14, 2018 22:55
Rgba32ToVector4
BenchmarkDotNet=v0.10.14, OS=Windows 10.0.17134
Intel Core i7-7700HQ CPU 2.80GHz (Kaby Lake), 1 CPU, 8 logical and 4 physical cores
Frequency=2742187 Hz, Resolution=364.6724 ns, Timer=TSC
.NET Core SDK=2.1.400-preview-009063
[Host] : .NET Core 2.0.7 (CoreCLR 4.6.26328.01, CoreFX 4.6.26403.03), 64bit RyuJIT
Clr : .NET Framework 4.7.1 (CLR 4.0.30319.42000), 64bit RyuJIT-v4.7.3190.0
Core : .NET Core 2.0.7 (CoreCLR 4.6.26328.01, CoreFX 4.6.26403.03), 64bit RyuJIT
Method | Job | Runtime | Count | Mean | Error | StdDev | Scaled | ScaledSD |