Browse Source

[ICC] Eliminate Version allocation using custom struct

pull/639/head
Jason Nelson 8 years ago
parent
commit
60bec41221
  1. 4
      src/ImageSharp/MetaData/Profiles/ICC/DataReader/IccDataReader.NonPrimitives.cs
  2. 16
      src/ImageSharp/MetaData/Profiles/ICC/DataWriter/IccDataWriter.NonPrimitives.cs
  3. 34
      src/ImageSharp/MetaData/Profiles/ICC/IccProfileHeader.cs
  4. 45
      src/ImageSharp/MetaData/Profiles/ICC/Various/IccVersion.cs

4
src/ImageSharp/MetaData/Profiles/ICC/DataReader/IccDataReader.NonPrimitives.cs

@ -38,7 +38,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc
/// Reads an ICC profile version number
/// </summary>
/// <returns>the version number</returns>
public Version ReadVersionNumber()
public IccVersion ReadVersionNumber()
{
int version = this.ReadInt32();
@ -46,7 +46,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc
int minor = (version >> 20) & 0x0F;
int bugfix = (version >> 16) & 0x0F;
return new Version(major, minor, bugfix);
return new IccVersion(major, minor, bugfix);
}
/// <summary>

16
src/ImageSharp/MetaData/Profiles/ICC/DataWriter/IccDataWriter.NonPrimitives.cs

@ -31,11 +31,11 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc
/// </summary>
/// <param name="value">The value to write</param>
/// <returns>the number of bytes written</returns>
public int WriteVersionNumber(Version value)
public int WriteVersionNumber(in IccVersion value)
{
int major = value.Major.Clamp(0, byte.MaxValue);
int minor = value.Minor.Clamp(0, 15);
int bugfix = value.Build.Clamp(0, 15);
int bugfix = value.Patch.Clamp(0, 15);
// TODO: This is not used?
byte mb = (byte)((minor << 4) | bugfix);
@ -61,7 +61,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc
/// </summary>
/// <param name="value">The value to write</param>
/// <returns>the number of bytes written</returns>
public int WriteProfileId(IccProfileId value)
public int WriteProfileId(in IccProfileId value)
{
return this.WriteUInt32(value.Part1)
+ this.WriteUInt32(value.Part2)
@ -74,7 +74,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc
/// </summary>
/// <param name="value">The value to write</param>
/// <returns>the number of bytes written</returns>
public int WritePositionNumber(IccPositionNumber value)
public int WritePositionNumber(in IccPositionNumber value)
{
return this.WriteUInt32(value.Offset)
+ this.WriteUInt32(value.Size);
@ -85,7 +85,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc
/// </summary>
/// <param name="value">The value to write</param>
/// <returns>the number of bytes written</returns>
public int WriteResponseNumber(IccResponseNumber value)
public int WriteResponseNumber(in IccResponseNumber value)
{
return this.WriteUInt16(value.DeviceCode)
+ this.WriteFix16(value.MeasurementValue);
@ -96,7 +96,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc
/// </summary>
/// <param name="value">The value to write</param>
/// <returns>the number of bytes written</returns>
public int WriteNamedColor(IccNamedColor value)
public int WriteNamedColor(in IccNamedColor value)
{
return this.WriteAsciiString(value.Name, 32, true)
+ this.WriteArray(value.PcsCoordinates)
@ -108,7 +108,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc
/// </summary>
/// <param name="value">The value to write</param>
/// <returns>the number of bytes written</returns>
public int WriteProfileDescription(IccProfileDescription value)
public int WriteProfileDescription(in IccProfileDescription value)
{
return this.WriteUInt32(value.DeviceManufacturer)
+ this.WriteUInt32(value.DeviceModel)
@ -125,7 +125,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc
/// </summary>
/// <param name="value">The value to write</param>
/// <returns>the number of bytes written</returns>
public int WriteScreeningChannel(IccScreeningChannel value)
public int WriteScreeningChannel(in IccScreeningChannel value)
{
return this.WriteFix16(value.Frequency)
+ this.WriteFix16(value.Angle)

34
src/ImageSharp/MetaData/Profiles/ICC/IccProfileHeader.cs

@ -7,42 +7,42 @@ using System.Numerics;
namespace SixLabors.ImageSharp.MetaData.Profiles.Icc
{
/// <summary>
/// Contains all values of an ICC profile header
/// Contains all values of an ICC profile header.
/// </summary>
public sealed class IccProfileHeader
{
/// <summary>
/// Gets or sets the profile size in bytes (will be ignored when writing a profile)
/// Gets or sets the profile size in bytes (will be ignored when writing a profile).
/// </summary>
public uint Size { get; set; }
/// <summary>
/// Gets or sets the preferred CMM (Color Management Module) type
/// Gets or sets the preferred CMM (Color Management Module) type.
/// </summary>
public string CmmType { get; set; }
/// <summary>
/// Gets or sets the profiles version number
/// Gets or sets the profiles version number.
/// </summary>
public Version Version { get; set; }
public IccVersion Version { get; set; }
/// <summary>
/// Gets or sets the type of the profile
/// Gets or sets the type of the profile.
/// </summary>
public IccProfileClass Class { get; set; }
/// <summary>
/// Gets or sets the data colorspace
/// Gets or sets the data colorspace.
/// </summary>
public IccColorSpaceType DataColorSpace { get; set; }
/// <summary>
/// Gets or sets the profile connection space
/// Gets or sets the profile connection space.
/// </summary>
public IccColorSpaceType ProfileConnectionSpace { get; set; }
/// <summary>
/// Gets or sets the date and time this profile was created
/// Gets or sets the date and time this profile was created.
/// </summary>
public DateTime CreationDate { get; set; }
@ -59,42 +59,42 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc
/// <summary>
/// Gets or sets the profile flags to indicate various options for the CMM
/// such as distributed processing and caching options
/// such as distributed processing and caching options.
/// </summary>
public IccProfileFlag Flags { get; set; }
/// <summary>
/// Gets or sets the device manufacturer of the device for which this profile is created
/// Gets or sets the device manufacturer of the device for which this profile is created.
/// </summary>
public uint DeviceManufacturer { get; set; }
/// <summary>
/// Gets or sets the model of the device for which this profile is created
/// Gets or sets the model of the device for which this profile is created.
/// </summary>
public uint DeviceModel { get; set; }
/// <summary>
/// Gets or sets the device attributes unique to the particular device setup such as media type
/// Gets or sets the device attributes unique to the particular device setup such as media type.
/// </summary>
public IccDeviceAttribute DeviceAttributes { get; set; }
/// <summary>
/// Gets or sets the rendering Intent
/// Gets or sets the rendering Intent.
/// </summary>
public IccRenderingIntent RenderingIntent { get; set; }
/// <summary>
/// Gets or sets The normalized XYZ values of the illuminant of the PCS
/// Gets or sets The normalized XYZ values of the illuminant of the PCS.
/// </summary>
public Vector3 PcsIlluminant { get; set; }
/// <summary>
/// Gets or sets Profile creator signature
/// Gets or sets profile creator signature.
/// </summary>
public string CreatorSignature { get; set; }
/// <summary>
/// Gets or sets the profile ID (hash)
/// Gets or sets the profile ID (hash).
/// </summary>
public IccProfileId Id { get; set; }
}

45
src/ImageSharp/MetaData/Profiles/ICC/Various/IccVersion.cs

@ -0,0 +1,45 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
namespace SixLabors.ImageSharp.MetaData.Profiles.Icc
{
/// <summary>
/// Represents the ICC profile version number.
/// </summary>
public readonly struct IccVersion
{
/// <summary>
/// Initializes a new instance of the <see cref="IccVersion"/> struct.
/// </summary>
/// <param name="major">The major version number.</param>
/// <param name="minor">The minor version number.</param>
/// <param name="patch">The patch version number.</param>
public IccVersion(int major, int minor, int patch)
{
this.Major = major;
this.Minor = minor;
this.Patch = patch;
}
/// <summary>
/// Gets the major version number.
/// </summary>
public int Major { get; }
/// <summary>
/// Gets the minor version number.
/// </summary>
public int Minor { get; }
/// <summary>
/// Gets the patch number.
/// </summary>
public int Patch { get; }
/// <inheritdoc/>
public override string ToString()
{
return string.Join(".", this.Major, this.Minor, this.Patch);
}
}
}
Loading…
Cancel
Save