Exemplo n.º 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());
        }
Exemplo n.º 2
0
        private void WriteTagTable(ICCDataWriter writer, TagTableEntry[] table)
        {
            //128 = size of ICC header
            writer.DataStream.Position = 128;

            writer.WriteUInt32((uint)table.Length);
            foreach (var entry in table)
            {
                writer.WriteUInt32((uint)entry.Signature);
                writer.WriteUInt32(entry.Offset);
                writer.WriteUInt32(entry.DataSize);
            }
        }
Exemplo n.º 3
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);
        }
Exemplo n.º 4
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());
            }
        }