コード例 #1
0
        private TagTableEntry[] WriteTagData(ICCDataWriter writer, ICCProfile profile)
        {
            List <TagDataEntry>   InData  = new List <TagDataEntry>(profile.Data);
            List <TagDataEntry[]> DupData = new List <TagDataEntry[]>();

            while (InData.Count > 0)
            {
                var items = InData.Where(t => InData[0].Equals(t)).ToArray();
                DupData.Add(items);
                foreach (var item in items)
                {
                    InData.Remove(item);
                }
            }

            List <TagTableEntry> Table = new List <TagTableEntry>();

            //(Header size) + (entry count) + (nr of entries) * (size of table entry)
            writer.DataStream.Position = 128 + 4 + profile.Data.Count * 12;;

            foreach (var entry in DupData)
            {
                TagTableEntry tentry;
                writer.WriteTagDataEntry(entry[0], out tentry);
                foreach (var item in entry)
                {
                    Table.Add(new TagTableEntry(item.TagSignature, tentry.Offset, tentry.DataSize));
                }
            }
            return(Table.ToArray());
        }
コード例 #2
0
ファイル: ICCProfileReader.cs プロジェクト: vavavr00m/NCM
        /// <summary>
        /// Reads the header of an <see cref="ICCProfile"/> from a given byte array
        /// </summary>
        /// <param name="data">the ICC data</param>
        /// <returns>the read ICC profile header</returns>
        public ICCProfile ReadHeader(byte[] data)
        {
            var reader  = new ICCDataReader(data);
            var profile = new ICCProfile();

            ReadHeader(reader, profile);
            return(profile);
        }
コード例 #3
0
ファイル: ICCProfileReader.cs プロジェクト: vavavr00m/NCM
 private void ReadTagData(ICCDataReader reader, TagTableEntry[] table, ICCProfile profile)
 {
     for (int i = 0; i < table.Length; i++)
     {
         TagDataEntry entry = reader.ReadTagDataEntry(table[i]);
         entry.TagSignature = table[i].Signature;
         profile.Data.Add(entry);
     }
 }
コード例 #4
0
ファイル: ColorspaceICC.cs プロジェクト: vavavr00m/NCM
 /// <summary>
 /// Creates a new instance of the <see cref="ColorspaceICC"/> class
 /// </summary>
 /// <param name="profile">The ICC profile of this colorspace</param>
 public ColorspaceICC(ICCProfile profile)
     : base(new WhitepointD50())//TODO: whitepoint is not always D50 for ICC profile
 {
     if (profile == null)
     {
         throw new ArgumentNullException(nameof(profile));
     }
     _Profile = profile;
 }
コード例 #5
0
ファイル: ICCProfile.cs プロジェクト: vavavr00m/NCM
        /// <summary>
        /// Compares this profile to another object.
        /// <para>Compared values are:</para>
        /// <para> - <see cref="Class"/></para>
        /// <para> - <see cref="DataColorspace"/></para>
        /// <para> - <see cref="PCS"/></para>
        /// <para> - <see cref="PCSIlluminant"/></para>
        /// <para> - <see cref="Data"/></para>
        /// </summary>
        /// <param name="obj">The object to compare to</param>
        /// <returns>True if the listed values are the same, false otherwise</returns>
        public bool Equals(ICCProfile obj)
        {
            if (obj == null)
            {
                return(false);
            }
            if (ReferenceEquals(this, obj))
            {
                return(true);
            }

            return(Class == obj.Class && DataColorspace == obj.DataColorspace && PCS == obj.PCS &&
                   PCSIlluminant == obj.PCSIlluminant && CMP.Compare(Data, obj.Data));
        }
コード例 #6
0
        private void WriteHeader(ICCDataWriter writer, ICCProfile profile)
        {
            writer.DataStream.Position = 0;

            writer.WriteUInt32(profile.Size);
            writer.WriteASCIIString(profile.CMMType, 4);
            writer.WriteVersionNumber(profile.Version);
            writer.WriteUInt32((uint)profile.Class);
            writer.WriteUInt32((uint)profile.DataColorspace);
            writer.WriteUInt32((uint)profile.PCS);
            writer.WriteDateTime(profile.CreationDate);
            writer.WriteASCIIString(profile.FileSignature, 4);
            writer.WriteUInt32((uint)profile.PrimaryPlatformSignature);
            writer.WriteProfileFlag(profile.Flags);
            writer.WriteUInt32(profile.DeviceManufacturer);
            writer.WriteUInt32(profile.DeviceModel);
            writer.WriteDeviceAttribute(profile.DeviceAttributes);
            writer.WriteUInt32((uint)profile.RenderingIntent);
            writer.WriteXYZNumber(profile.PCSIlluminant);
            writer.WriteASCIIString(profile.CreatorSignature, 4);
        }
コード例 #7
0
        /// <summary>
        /// Writes an <see cref="ICCProfile"/> into a byte array
        /// </summary>
        /// <param name="profile">the ICC profile to write</param>
        /// <returns>the ICC data</returns>
        public byte[] WriteProfile(ICCProfile profile)
        {
            if (profile == null)
            {
                throw new ArgumentNullException(nameof(profile));
            }

            using (var stream = new MemoryStream(128))
            {
                var writer = new ICCDataWriter(stream);

                TagTableEntry[] table = WriteTagData(writer, profile);
                WriteTagTable(writer, table);

                profile.Size = (uint)stream.Length;
                WriteHeader(writer, profile);
                profile.ID = ICCProfile.CalculateHash(stream.ToArray());
                writer.WriteProfileID(profile.ID);

                return(stream.ToArray());
            }
        }
コード例 #8
0
ファイル: ICCProfileReader.cs プロジェクト: vavavr00m/NCM
        private ICCProfile ReadAll(ICCDataReader reader)
        {
            var profile = new ICCProfile();

            ReadHeader(reader, profile);
            var table = ReadTagTable(reader);

            ReadTagData(reader, table, profile);

            var calcHash = ICCProfile.CalculateHash(reader.Data);

            if (!profile.ID.IsSet)
            {
                profile.ID = calcHash;
            }
            else if (profile.ID != calcHash)
            {
                throw new CorruptProfileException("Hash stored in profile does not match");
            }

            return(profile);
        }
コード例 #9
0
ファイル: ICCProfileReader.cs プロジェクト: vavavr00m/NCM
 private void ReadHeader(ICCDataReader reader, ICCProfile profile)
 {
     reader.Index           = 0;
     profile.Size           = reader.ReadUInt32();
     profile.CMMType        = reader.ReadASCIIString(4);
     profile.Version        = reader.ReadVersionNumber();
     profile.Class          = (ProfileClassName)reader.ReadUInt32();
     profile.DataColorspace = (ColorSpaceType)reader.ReadUInt32();
     profile.PCS            = (ColorSpaceType)reader.ReadUInt32();
     profile.CreationDate   = reader.ReadDateTime();
     if (reader.ReadASCIIString(4) != "acsp")
     {
         throw new CorruptProfileException("FileSignature has to be \"acsp\"");
     }
     profile.PrimaryPlatformSignature = (PrimaryPlatformType)reader.ReadUInt32();
     profile.Flags = reader.ReadProfileFlag();
     profile.DeviceManufacturer = reader.ReadUInt32();
     profile.DeviceModel        = reader.ReadUInt32();
     profile.DeviceAttributes   = reader.ReadDeviceAttribute();
     profile.RenderingIntent    = (RenderingIntent)reader.ReadUInt32();
     profile.PCSIlluminant      = reader.ReadXYZNumber();
     profile.CreatorSignature   = reader.ReadASCIIString(4);
     profile.ID = reader.ReadProfileID();
 }
コード例 #10
0
        /// <summary>
        /// Writes an <see cref="ICCProfile"/> into a <see cref="Stream"/>
        /// </summary>
        /// <param name="profile">the ICC profile to write</param>
        /// <param name="stream">the stream to which the ICC data will be written to</param>
        public void WriteProfile(ICCProfile profile, Stream stream)
        {
            var data = WriteProfile(profile);

            stream.Write(data, 0, data.Length);
        }
コード例 #11
0
        /// <summary>
        /// Writes an <see cref="ICCProfile"/> into a file
        /// </summary>
        /// <param name="profile">the ICC profile to write</param>
        /// <param name="path">the path to the new ICC file</param>
        public void WriteProfile(ICCProfile profile, string path)
        {
            var data = WriteProfile(profile);

            File.WriteAllBytes(path, data);
        }
コード例 #12
0
        //LTODO: implement ICCValidator (partially see Annex G)

        /// <summary>
        /// Validates an ICC profile
        /// </summary>
        /// <param name="profile">The profile to validate</param>
        /// <returns>True if valid; false otherwise</returns>
        public static bool Validate(ICCProfile profile)
        {
            throw new NotImplementedException();
        }