Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for loading exif data from PNG "Raw profile type exif" text chunk #1877

Merged

Conversation

jubilant-enigma
Copy link
Contributor

I don't really have much experience in C# outside of toy projects, so I don't really have a good idea of what best practices are for C# these days.

Some more optimal functions (span related, etc) seemed available with some of the newer .net versions, however, then .netstandard1.3 would produce build errors. Yet that tests don't seem to be run on that target? Not sure what's going on there.

Prerequisites

  • I have written a descriptive pull-request title
  • I have verified that there are no overlapping pull-requests open
  • I have verified that I am following the existing coding patterns and practice as demonstrated in the repository. These follow strict Stylecop rules 👮.
  • I have provided test coverage for my change (where applicable)

Description

See #1875.

@CLAassistant
Copy link

CLAassistant commented Dec 5, 2021

CLA assistant check
All committers have signed the CLA.

src/ImageSharp/Formats/Png/PngDecoderCore.cs Outdated Show resolved Hide resolved
src/ImageSharp/Formats/Png/PngDecoderCore.cs Outdated Show resolved Hide resolved
src/ImageSharp/Formats/Png/PngDecoderCore.cs Outdated Show resolved Hide resolved
src/ImageSharp/Formats/Png/PngDecoderCore.cs Outdated Show resolved Hide resolved
src/ImageSharp/Formats/Png/PngDecoderCore.cs Outdated Show resolved Hide resolved
jubilant-enigma and others added 2 commits December 6, 2021 10:18
Co-authored-by: Günther Foidl <gue@korporal.at>
Co-authored-by: Günther Foidl <gue@korporal.at>
@jubilant-enigma
Copy link
Contributor Author

Additional design decision: should the Raw profile type exif text chunk be removed from the PngMetadata after successful parsing?

@JimBobSquarePants
Copy link
Member

Additional design decision: should the Raw profile type exif text chunk be removed from the PngMetadata after successful parsing?

Once we have that profile, absolutely.

@codecov
Copy link

codecov bot commented Dec 7, 2021

Codecov Report

Merging #1877 (3c421bb) into master (f7b332a) will decrease coverage by 0%.
The diff coverage is 73%.

Impacted file tree graph

@@          Coverage Diff           @@
##           master   #1877   +/-   ##
======================================
- Coverage      87%     87%   -1%     
======================================
  Files         961     962    +1     
  Lines       51034   51121   +87     
  Branches     6324    6342   +18     
======================================
+ Hits        44863   44925   +62     
- Misses       5133    5148   +15     
- Partials     1038    1048   +10     
Flag Coverage Δ
unittests 87% <73%> (-1%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
src/ImageSharp/Formats/Png/PngDecoderCore.cs 88% <70%> (-2%) ⬇️
src/ImageSharp/Common/Helpers/HexConverter.cs 77% <77%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update f7b332a...3c421bb. Read the comment docs.

if (name.Equals("Raw profile type exif", StringComparison.OrdinalIgnoreCase) &&
this.TryReadLegacyExifTextChunk(baseMetadata, uncompressed))
{
// Successfully parsed exif data stored as text in this chunk
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reverse the condition here so you don't have the odd empty scope.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I ended up moving this into its own function, TryReadTextChunkMetadata, since I was missing support for loading legacy exif data from uncompressed text chunks, and I also wanted to have an easy spot to add support for other metadata chunks in the future. I suppose I could also just add IPTC support in this PR too if you want, but I figure it's getting somewhat large and it might be better to just make another PR with that feature after this one gets merged.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, let's keep IPTC separate for now.

Copy link
Member

@JimBobSquarePants JimBobSquarePants left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jubilant-enigma Can you double check that your local fork is using the updated submodules. There shouldn't be a change to them compared to our master.

EDIT. I pulled your fork and did the update myself to fix.

@JimBobSquarePants JimBobSquarePants added this to the 2.0.0 milestone Jan 4, 2022
Copy link
Member

@JimBobSquarePants JimBobSquarePants left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Great job 👍

@JimBobSquarePants JimBobSquarePants merged commit e20410c into SixLabors:master Jan 4, 2022
}

HexConverter.HexStringToBytes(dataSpan.Slice(0, exifHeader.Length * 2), tempExifBuf);
if (!tempExifBuf.AsSpan().Slice(0, exifHeader.Length).SequenceEqual(exifHeader))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if (!tempExifBuf.AsSpan(0, exifHeader.Length).SequenceEqual(exifHeader))

lineSpan = dataSpan.Slice(0, newlineIndex);
}

i += HexConverter.HexStringToBytes(lineSpan, exifBlob.AsSpan().Slice(i));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i += HexConverter.HexStringToBytes(lineSpan, exifBlob.AsSpan(i));

// Skip to the data length
dataSpan = dataSpan.Slice(4).TrimStart();
int dataLengthEnd = dataSpan.IndexOf('\n');
int dataLength = ParseInt32(dataSpan.Slice(0, dataSpan.IndexOf('\n')));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

int dataLength = ParseInt32(dataSpan.Slice(0, dataLengthEnd));

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for pointing these issues out @turbedi. Ideally I'll fix them sometime next week when I create a PR for IPTC metadata loading from text chunks.

@jubilant-enigma
Copy link
Contributor Author

@jubilant-enigma Can you double check that your local fork is using the updated submodules. There shouldn't be a change to them compared to our master.

EDIT. I pulled your fork and did the update myself to fix.

Sorry about that, thanks for taking care of it! Unfortunately my available free time has been more intermittent than I hoped.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants