示例#1
0
 public ExifWriter(Document doc, IDictionary <MetadataKey, MetadataEntry> entries, ExifColorSpace exifColorSpace)
 {
     metadata = CreateTagDictionary(doc, entries, exifColorSpace);
 }
示例#2
0
        private static Dictionary <MetadataSection, Dictionary <ushort, MetadataEntry> > CreateTagDictionary(
            Document doc,
            IDictionary <MetadataKey, MetadataEntry> entries,
            ExifColorSpace exifColorSpace)
        {
            Dictionary <MetadataSection, Dictionary <ushort, MetadataEntry> > metadataEntries = new Dictionary <MetadataSection, Dictionary <ushort, MetadataEntry> >
            {
                {
                    MetadataSection.Image,
                    new Dictionary <ushort, MetadataEntry>
                    {
                        {
                            MetadataKeys.Image.Orientation.TagId,
                            new MetadataEntry(MetadataKeys.Image.Orientation,
                                              TagDataType.Short,
                                              MetadataHelpers.EncodeShort(TiffConstants.Orientation.TopLeft))
                        }
                    }
                },
                {
                    MetadataSection.Exif,
                    new Dictionary <ushort, MetadataEntry>()
                }
            };

            // Add the image size tags.
            if (IsUncompressedImage(entries))
            {
                Dictionary <ushort, MetadataEntry> imageSection = metadataEntries[MetadataSection.Image];
                imageSection.Add(MetadataKeys.Image.ImageWidth.TagId,
                                 new MetadataEntry(MetadataKeys.Image.ImageWidth,
                                                   TagDataType.Long,
                                                   MetadataHelpers.EncodeLong((uint)doc.Width)));
                imageSection.Add(MetadataKeys.Image.ImageLength.TagId,
                                 new MetadataEntry(MetadataKeys.Image.ImageLength,
                                                   TagDataType.Long,
                                                   MetadataHelpers.EncodeLong((uint)doc.Height)));

                entries.Remove(MetadataKeys.Image.ImageWidth);
                entries.Remove(MetadataKeys.Image.ImageLength);
                // These tags should not be included in uncompressed images.
                entries.Remove(MetadataKeys.Exif.PixelXDimension);
                entries.Remove(MetadataKeys.Exif.PixelYDimension);
            }
            else
            {
                Dictionary <ushort, MetadataEntry> exifSection = metadataEntries[MetadataSection.Exif];
                exifSection.Add(MetadataKeys.Exif.PixelXDimension.TagId,
                                new MetadataEntry(MetadataKeys.Exif.PixelXDimension,
                                                  TagDataType.Long,
                                                  MetadataHelpers.EncodeLong((uint)doc.Width)));
                exifSection.Add(MetadataKeys.Exif.PixelYDimension.TagId,
                                new MetadataEntry(MetadataKeys.Exif.PixelYDimension,
                                                  TagDataType.Long,
                                                  MetadataHelpers.EncodeLong((uint)doc.Height)));

                entries.Remove(MetadataKeys.Exif.PixelXDimension);
                entries.Remove(MetadataKeys.Exif.PixelYDimension);
                // These tags should not be included in compressed images.
                entries.Remove(MetadataKeys.Image.ImageWidth);
                entries.Remove(MetadataKeys.Image.ImageLength);
            }

            // Add the EXIF color space tag.
            if (!entries.ContainsKey(MetadataKeys.Exif.ColorSpace))
            {
                metadataEntries[MetadataSection.Exif].Add(MetadataKeys.Exif.ColorSpace.TagId,
                                                          new MetadataEntry(MetadataKeys.Exif.ColorSpace,
                                                                            TagDataType.Short,
                                                                            MetadataHelpers.EncodeShort((ushort)exifColorSpace)));
            }

            foreach (KeyValuePair <MetadataKey, MetadataEntry> kvp in entries)
            {
                MetadataEntry entry = kvp.Value;

                MetadataSection section = entry.Section;

                if (section == MetadataSection.Image && !ExifTagHelper.CanWriteImageSectionTag(entry.TagId))
                {
                    continue;
                }

                if (metadataEntries.TryGetValue(section, out Dictionary <ushort, MetadataEntry> values))
                {
                    if (!values.ContainsKey(entry.TagId))
                    {
                        values.Add(entry.TagId, entry);
                    }
                }
                else
                {
                    metadataEntries.Add(section, new Dictionary <ushort, MetadataEntry>
                    {
                        { entry.TagId, entry }
                    });
                }
            }

            AddVersionEntries(ref metadataEntries);

            return(metadataEntries);
        }
示例#3
0
        private static WebPNative.MetadataParams CreateWebPMetadata(Document doc, Surface scratchSurface)
        {
            byte[] iccProfileBytes = null;
            byte[] exifBytes       = null;
            byte[] xmpBytes        = null;

            string colorProfile = doc.Metadata.GetUserValue(WebPMetadataNames.ColorProfile);

            if (!string.IsNullOrEmpty(colorProfile))
            {
                iccProfileBytes = Convert.FromBase64String(colorProfile);
            }

            string exif = doc.Metadata.GetUserValue(WebPMetadataNames.EXIF);

            if (!string.IsNullOrEmpty(exif))
            {
                exifBytes = Convert.FromBase64String(exif);
            }

            string xmp = doc.Metadata.GetUserValue(WebPMetadataNames.XMP);

            if (!string.IsNullOrEmpty(xmp))
            {
                xmpBytes = Convert.FromBase64String(xmp);
            }

            if (iccProfileBytes == null || exifBytes == null)
            {
                Dictionary <MetadataKey, MetadataEntry> propertyItems = GetMetadataFromDocument(doc);

                if (propertyItems != null)
                {
                    ExifColorSpace exifColorSpace = ExifColorSpace.Srgb;

                    if (iccProfileBytes != null)
                    {
                        exifColorSpace = ExifColorSpace.Uncalibrated;
                    }
                    else
                    {
                        MetadataKey iccProfileKey = MetadataKeys.Image.InterColorProfile;

                        if (propertyItems.TryGetValue(iccProfileKey, out MetadataEntry iccProfileItem))
                        {
                            iccProfileBytes = iccProfileItem.GetData();
                            propertyItems.Remove(iccProfileKey);
                            exifColorSpace = ExifColorSpace.Uncalibrated;
                        }
                    }

                    if (exifBytes == null)
                    {
                        exifBytes = new ExifWriter(doc, propertyItems, exifColorSpace).CreateExifBlob();
                    }
                }
            }

            if (iccProfileBytes != null || exifBytes != null || xmpBytes != null)
            {
                return(new WebPNative.MetadataParams(iccProfileBytes, exifBytes, xmpBytes));
            }

            return(null);
        }
示例#4
0
        private static WebPNative.MetadataParams CreateWebPMetadata(Document doc)
        {
            byte[] iccProfileBytes = null;
            byte[] exifBytes       = null;
            byte[] xmpBytes        = null;

            string colorProfile = doc.Metadata.GetUserValue(WebPMetadataNames.ColorProfile);

            if (!string.IsNullOrEmpty(colorProfile))
            {
                iccProfileBytes = Convert.FromBase64String(colorProfile);
            }

            string exif = doc.Metadata.GetUserValue(WebPMetadataNames.EXIF);

            if (!string.IsNullOrEmpty(exif))
            {
                exifBytes = Convert.FromBase64String(exif);
            }

            string xmp = doc.Metadata.GetUserValue(WebPMetadataNames.XMP);

            if (!string.IsNullOrEmpty(xmp))
            {
                xmpBytes = Convert.FromBase64String(xmp);
            }

            if (iccProfileBytes == null || exifBytes == null)
            {
                Dictionary <MetadataKey, MetadataEntry> propertyItems = GetMetadataFromDocument(doc);

                if (propertyItems != null)
                {
                    ExifColorSpace exifColorSpace = ExifColorSpace.Srgb;

                    if (iccProfileBytes != null)
                    {
                        exifColorSpace = ExifColorSpace.Uncalibrated;
                    }
                    else
                    {
                        MetadataKey iccProfileKey = MetadataKeys.Image.InterColorProfile;

                        if (propertyItems.TryGetValue(iccProfileKey, out MetadataEntry iccProfileItem))
                        {
                            iccProfileBytes = iccProfileItem.GetData();
                            propertyItems.Remove(iccProfileKey);
                            exifColorSpace = ExifColorSpace.Uncalibrated;
                        }
                    }

                    if (exifBytes == null)
                    {
                        exifBytes = new ExifWriter(doc, propertyItems, exifColorSpace).CreateExifBlob();
                    }
                }
            }

#if !PDN_3_5_X
            if (xmpBytes == null)
            {
                PaintDotNet.Imaging.XmpPacket xmpPacket = doc.Metadata.TryGetXmpPacket();

                if (xmpPacket != null)
                {
                    string xmpPacketAsString = xmpPacket.ToString();

                    xmpBytes = System.Text.Encoding.UTF8.GetBytes(xmpPacketAsString);
                }
            }
#endif

            if (iccProfileBytes != null || exifBytes != null || xmpBytes != null)
            {
                return(new WebPNative.MetadataParams(iccProfileBytes, exifBytes, xmpBytes));
            }

            return(null);
        }
示例#5
0
 public ExifWriter(Document doc, IDictionary <ExifPropertyPath, ExifValue> entries, ExifColorSpace exifColorSpace)
 {
     metadata = CreateTagDictionary(doc, entries, exifColorSpace);
 }
示例#6
0
 public IExifColorSpaceColorContext CreateColorContext(ExifColorSpace exifColorSpace) =>
 base.innerRefT.CreateColorContext(exifColorSpace);
示例#7
0
 private static string GetDisplayString(ExifColorSpace tag)
 {
     return(ExifColorSpaceStrings.ContainsKey(tag) ? ExifColorSpaceStrings[tag] : tag.ToString());
 }