Skip to content

Commit

Permalink
Merge pull request #55 from hgy59/remove_thumbnail_fix
Browse files Browse the repository at this point in the history
JPEG: fix removal of thumbnail properties
  • Loading branch information
oozcitak authored Jun 19, 2018
2 parents cf01a93 + 4902394 commit 36520bc
Showing 1 changed file with 13 additions and 33 deletions.
46 changes: 13 additions & 33 deletions ExifLibrary/JPEGFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -161,23 +161,7 @@ protected internal JPEGFile(Stream stream, Encoding encoding)
/// </summary>
public override void Crush()
{
// Keep JFIF Tags
List<ExifProperty> jfifProperties = new List<ExifProperty>();
foreach (ExifProperty prop in Properties)
{
if (prop.IFD == IFD.JFIF)
{
if (prop.Tag == ExifTag.JFIFXThumbnail)
prop.Value = 0;
if (prop.Tag == ExifTag.JFIFYThumbnail)
prop.Value = 0;
if (prop.Tag == ExifTag.JFIFThumbnail)
prop.Value = new JFIFThumbnail(JFIFThumbnail.ImageFormat.JPEG, new byte[0]);
}
}
Properties.Clear();
foreach (ExifProperty prop in jfifProperties)
Properties.Add(prop);

// Remove metadata sections.
// Keep the sections in this whitelist only:
Expand All @@ -191,10 +175,7 @@ public override void Crush()
// DRI
// DHP
// EXP
Sections.RemoveAll((section) =>
{
return (section.Marker < JPEGMarker.SOF0 || section.Marker > JPEGMarker.EXP);
});
Sections.RemoveAll(section => section.Marker < JPEGMarker.SOF0 || section.Marker > JPEGMarker.EXP);
}

/// <summary>
Expand Down Expand Up @@ -653,27 +634,26 @@ private bool WriteExifApp1(bool preserveMakerNote)
thumbSizeLocation = 0;
thumbSizeValue = 0;
// Write thumbnail tags if they are missing, remove otherwise
int indexf = -1;
int indexl = -1;
for (int i = 0; i < Properties.Count; i++)
ExifProperty thumbnailFormatProperty = null;
ExifProperty thumbnailLengthProperty = null;
foreach (var prop in Properties)
{
ExifProperty prop = Properties[i];
if (prop.Tag == ExifTag.ThumbnailJPEGInterchangeFormat) indexf = i;
if (prop.Tag == ExifTag.ThumbnailJPEGInterchangeFormatLength) indexl = i;
if (indexf != -1 && indexl != -1) break;
if (prop.Tag == ExifTag.ThumbnailJPEGInterchangeFormat) thumbnailFormatProperty = prop;
if (prop.Tag == ExifTag.ThumbnailJPEGInterchangeFormatLength) thumbnailLengthProperty = prop;
if (thumbnailFormatProperty != null && thumbnailLengthProperty != null) break;
}
if (Thumbnail == null)
{
if (indexf != -1)
Properties.RemoveAt(indexf);
if (indexl != -1)
Properties.RemoveAt(indexl);
if (thumbnailFormatProperty != null)
Properties.Remove(thumbnailFormatProperty);
if (thumbnailLengthProperty != null)
Properties.Remove(thumbnailLengthProperty);
}
else
{
if (indexf == -1)
if (thumbnailFormatProperty == null)
Properties.Add(new ExifUInt(ExifTag.ThumbnailJPEGInterchangeFormat, 0));
if (indexl == -1)
if (thumbnailLengthProperty == null)
Properties.Add(new ExifUInt(ExifTag.ThumbnailJPEGInterchangeFormatLength, 0));
}

Expand Down

0 comments on commit 36520bc

Please sign in to comment.