Browse Source

Can now read and store ICC profile

af/merge-core
James Jackson-South 9 years ago
parent
commit
db9afff904
  1. 6
      src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.Rgb.cs
  2. 5
      src/ImageSharp/Formats/Jpeg/JpegConstants.cs
  3. 55
      src/ImageSharp/Formats/Jpeg/JpegDecoderCore.cs
  4. 5
      src/ImageSharp/MetaData/ImageMetaData.cs
  5. 2
      src/ImageSharp/MetaData/Profiles/ICC/Enums/IccColorSpaceType.cs
  6. 2
      src/ImageSharp/MetaData/Profiles/ICC/Enums/IccDeviceAttribute.cs
  7. 2
      src/ImageSharp/MetaData/Profiles/ICC/Enums/IccPrimaryPlatformType.cs
  8. 2
      src/ImageSharp/MetaData/Profiles/ICC/Enums/IccProfileClass.cs
  9. 2
      src/ImageSharp/MetaData/Profiles/ICC/Enums/IccProfileFlag.cs
  10. 2
      src/ImageSharp/MetaData/Profiles/ICC/Enums/IccProfileTag.cs
  11. 2
      src/ImageSharp/MetaData/Profiles/ICC/Enums/IccRenderingIntent.cs
  12. 2
      src/ImageSharp/MetaData/Profiles/ICC/Enums/IccTypeSignature.cs
  13. 2
      src/ImageSharp/MetaData/Profiles/ICC/IccProfile.cs
  14. 2
      src/ImageSharp/MetaData/Profiles/ICC/IccProfileHeader.cs
  15. 6
      src/ImageSharp/MetaData/Profiles/ICC/IccTagDataEntry.cs
  16. 2
      src/ImageSharp/MetaData/Profiles/ICC/Various/IccProfileId.cs

6
src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.Rgb.cs

@ -144,7 +144,11 @@ namespace ImageSharp.ColorSpaces.Conversion
Guard.NotNull(color, nameof(color));
// Conversion
return YCbCrAndRgbConverter.Convert(color);
Rgb rgb = YCbCrAndRgbConverter.Convert(color);
// Adaptation
// TODO: Check this!
return rgb.WorkingSpace.Equals(this.TargetRgbWorkingSpace) ? rgb : this.Adapt(rgb);
}
}
}

5
src/ImageSharp/Formats/Jpeg/JpegConstants.cs

@ -200,6 +200,11 @@ namespace ImageSharp.Formats
/// </summary>
public const byte APP1 = 0xe1;
/// <summary>
/// Application specific marker for marking where to store ICC profile information.
/// </summary>
public const byte APP2 = 0xe2;
/// <summary>
/// Application specific marker used by Adobe for storing encoding information for DCT filters.
/// </summary>

55
src/ImageSharp/Formats/Jpeg/JpegDecoderCore.cs

@ -83,6 +83,11 @@ namespace ImageSharp.Formats
/// </summary>
private bool isExif;
/// <summary>
/// Whether the image has an ICC header
/// </summary>
private bool isIcc;
/// <summary>
/// The vertical resolution. Calculated if the image has a JFIF header.
/// </summary>
@ -436,6 +441,9 @@ namespace ImageSharp.Formats
case JpegConstants.Markers.APP1:
this.ProcessApp1Marker(remaining, metadata);
break;
case JpegConstants.Markers.APP2:
this.ProcessApp2Marker(remaining, metadata);
break;
case JpegConstants.Markers.APP14:
this.ProcessApp14Marker(remaining);
break;
@ -962,14 +970,57 @@ namespace ImageSharp.Formats
byte[] profile = new byte[remaining];
this.InputProcessor.ReadFull(profile, 0, remaining);
if (profile[0] == 'E' && profile[1] == 'x' && profile[2] == 'i' && profile[3] == 'f' && profile[4] == '\0'
&& profile[5] == '\0')
if (profile[0] == 'E' &&
profile[1] == 'x' &&
profile[2] == 'i' &&
profile[3] == 'f' &&
profile[4] == '\0' &&
profile[5] == '\0')
{
this.isExif = true;
metadata.ExifProfile = new ExifProfile(profile);
}
}
/// <summary>
/// Processes the App2 marker retrieving any stored ICC profile information
/// </summary>
/// <param name="remaining">The remaining bytes in the segment block.</param>
/// <param name="metadata">The image.</param>
private void ProcessApp2Marker(int remaining, ImageMetaData metadata)
{
// Length is 14 though we only need to check 12.
const int Icclength = 14;
if (remaining < Icclength || this.options.IgnoreMetadata)
{
this.InputProcessor.Skip(remaining);
return;
}
byte[] identifier = new byte[Icclength];
this.InputProcessor.ReadFull(identifier, 0, Icclength);
if (identifier[0] == 'I' &&
identifier[1] == 'C' &&
identifier[2] == 'C' &&
identifier[3] == '_' &&
identifier[4] == 'P' &&
identifier[5] == 'R' &&
identifier[6] == 'O' &&
identifier[7] == 'F' &&
identifier[8] == 'I' &&
identifier[9] == 'L' &&
identifier[10] == 'E' &&
identifier[11] == '\0')
{
this.isIcc = true;
remaining -= Icclength;
byte[] profile = new byte[remaining];
this.InputProcessor.ReadFull(profile, 0, remaining);
metadata.IccProfile = new IccProfile(profile);
}
}
/// <summary>
/// Processes the application header containing the JFIF identifier plus extra data.
/// </summary>

5
src/ImageSharp/MetaData/ImageMetaData.cs

@ -116,6 +116,11 @@ namespace ImageSharp
/// </summary>
public ExifProfile ExifProfile { get; set; }
/// <summary>
/// Gets or sets the ICC profile.
/// </summary>
public IccProfile IccProfile { get; set; }
/// <summary>
/// Gets or sets the frame delay for animated images.
/// If not 0, this field specifies the number of hundredths (1/100) of a second to

2
src/ImageSharp/MetaData/Profiles/ICC/Enums/IccColorSpaceType.cs

@ -8,7 +8,7 @@ namespace ImageSharp
/// <summary>
/// Color Space Type
/// </summary>
internal enum IccColorSpaceType : uint
public enum IccColorSpaceType : uint
{
/// <summary>
/// CIE XYZ

2
src/ImageSharp/MetaData/Profiles/ICC/Enums/IccDeviceAttribute.cs

@ -13,7 +13,7 @@ namespace ImageSharp
/// the rest can be used for vendor specific values
/// </summary>
[Flags]
internal enum IccDeviceAttribute : long
public enum IccDeviceAttribute : long
{
/// <summary>
/// Opacity transparent

2
src/ImageSharp/MetaData/Profiles/ICC/Enums/IccPrimaryPlatformType.cs

@ -8,7 +8,7 @@ namespace ImageSharp
/// <summary>
/// Enumerates the primary platform/operating system framework for which the profile was created
/// </summary>
internal enum IccPrimaryPlatformType : uint
public enum IccPrimaryPlatformType : uint
{
/// <summary>
/// No platform identified

2
src/ImageSharp/MetaData/Profiles/ICC/Enums/IccProfileClass.cs

@ -8,7 +8,7 @@ namespace ImageSharp
/// <summary>
/// Profile Class Name
/// </summary>
internal enum IccProfileClass : uint
public enum IccProfileClass : uint
{
/// <summary>
/// Input profiles are generally used with devices such as scanners and

2
src/ImageSharp/MetaData/Profiles/ICC/Enums/IccProfileFlag.cs

@ -13,7 +13,7 @@ namespace ImageSharp
/// the rest can be used for vendor specific values
/// </summary>
[Flags]
internal enum IccProfileFlag : int
public enum IccProfileFlag : int
{
/// <summary>
/// No flags (equivalent to NotEmbedded and Independent)

2
src/ImageSharp/MetaData/Profiles/ICC/Enums/IccProfileTag.cs

@ -13,7 +13,7 @@ namespace ImageSharp
/// Each tag value represent the size of the tag in the profile.
/// </remarks>
/// </summary>
internal enum IccProfileTag : uint
public enum IccProfileTag : uint
{
/// <summary>
/// Unknown tag

2
src/ImageSharp/MetaData/Profiles/ICC/Enums/IccRenderingIntent.cs

@ -8,7 +8,7 @@ namespace ImageSharp
/// <summary>
/// Rendering intent
/// </summary>
internal enum IccRenderingIntent : uint
public enum IccRenderingIntent : uint
{
/// <summary>
/// In perceptual transforms the PCS values represent hypothetical

2
src/ImageSharp/MetaData/Profiles/ICC/Enums/IccTypeSignature.cs

@ -8,7 +8,7 @@ namespace ImageSharp
/// <summary>
/// Type Signature
/// </summary>
internal enum IccTypeSignature : uint
public enum IccTypeSignature : uint
{
/// <summary>
/// Unknown type signature

2
src/ImageSharp/MetaData/Profiles/ICC/IccProfile.cs

@ -14,7 +14,7 @@ namespace ImageSharp
/// <summary>
/// Represents an ICC profile
/// </summary>
internal class IccProfile
public sealed class IccProfile
{
/// <summary>
/// The byte array to read the ICC profile from

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

@ -11,7 +11,7 @@ namespace ImageSharp
/// <summary>
/// Contains all values of an ICC profile header
/// </summary>
internal sealed class IccProfileHeader
public sealed class IccProfileHeader
{
/// <summary>
/// Gets or sets the profile size in bytes (will be ignored when writing a profile)

6
src/ImageSharp/MetaData/Profiles/ICC/IccTagDataEntry.cs

@ -10,7 +10,7 @@ namespace ImageSharp
/// <summary>
/// The data of an ICC tag entry
/// </summary>
internal abstract class IccTagDataEntry : IEquatable<IccTagDataEntry>
public abstract class IccTagDataEntry : IEquatable<IccTagDataEntry>
{
private IccProfileTag tagSignature = IccProfileTag.Unknown;
@ -45,8 +45,8 @@ namespace ImageSharp
/// </summary>
public IccProfileTag TagSignature
{
get { return this.tagSignature; }
set { this.tagSignature = value; }
get => this.tagSignature;
set => this.tagSignature = value;
}
/// <inheritdoc/>

2
src/ImageSharp/MetaData/Profiles/ICC/Various/IccProfileId.cs

@ -10,7 +10,7 @@ namespace ImageSharp
/// <summary>
/// ICC Profile ID
/// </summary>
internal struct IccProfileId : IEquatable<IccProfileId>
public struct IccProfileId : IEquatable<IccProfileId>
{
/// <summary>
/// A profile ID with all values set to zero

Loading…
Cancel
Save