Skip to content

Conversation

@equinox2k
Copy link
Contributor

@equinox2k equinox2k commented Sep 19, 2019

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 matches 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

This part of work on creating an alternative to TinyPNG / PNGCrush using ImageSharp.

@codecov
Copy link

codecov bot commented Sep 19, 2019

Codecov Report

Merging #1012 into master will increase coverage by 0.02%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1012      +/-   ##
==========================================
+ Coverage   82.58%   82.61%   +0.02%     
==========================================
  Files         694      694              
  Lines       30047    30085      +38     
  Branches     3397     3409      +12     
==========================================
+ Hits        24814    24854      +40     
  Misses       4535     4535              
+ Partials      698      696       -2     
Flag Coverage Δ
#unittests 82.61% <100.00%> (+0.02%) ⬆️
Impacted Files Coverage Δ
src/ImageSharp/Formats/Png/PngEncoder.cs 87.50% <100.00%> (+2.88%) ⬆️
src/ImageSharp/Formats/Png/PngEncoderCore.cs 97.80% <100.00%> (+0.14%) ⬆️
src/ImageSharp/Formats/Png/PngEncoderOptions.cs 100.00% <100.00%> (+4.54%) ⬆️
...ImageSharp/Formats/Png/PngEncoderOptionsHelpers.cs 86.41% <100.00%> (+0.34%) ⬆️
...ssing/Processors/Transforms/Resize/ResizeHelper.cs 50.58% <0.00%> (-0.29%) ⬇️
src/ImageSharp/Formats/Png/Zlib/DeflaterHuffman.cs 98.16% <0.00%> (+0.22%) ⬆️

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 b720219...b817615. Read the comment docs.

@JimBobSquarePants
Copy link
Member

Good idea! I think we should make our chunk preservation more granular though, perhaps an enum so we can choose whether to preserve exif?

Incidentally deleting the relevant metadata will achieve e same result, but this could be a nice shortcut

@equinox2k
Copy link
Contributor Author

@JimBobSquarePants split up optimization into a flagged enum so should let users choose what they would like to do + fixes

@antonfirsov
Copy link
Member

In decoders, we have an IgnoreMetadata property. Can we design it in a way that tries to maintain consistency between decodsrs/encoders accross all codecs?

Copy link
Member

@antonfirsov antonfirsov left a comment

Choose a reason for hiding this comment

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

The most critical issue is the lack of test coverage for the functionality introduced by the PR. We need to define positive & negative tests for all the flags.

I'm also suggesting a different definition & naming for the flag semantics, but we also need @JimBobSquarePants 's approval for that.

/// Provides enumeration of available PNG optimization methods.
/// </summary>
[Flags]
public enum PngOptimizeMethod
Copy link
Member

@antonfirsov antonfirsov Sep 30, 2019

Choose a reason for hiding this comment

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

As I mentioned on gitter, it's better if our naming should reflect functional semantics rather than a specific use case (optimization). In that case "positive" flags may be easier than negative ones expressing the suppression. "positive" flags may be better than negative ones, but I'm not sure about this, need @JimBobSquarePants 's advice.

Suggestion Positive flags:

public enum PngChunkFilter
{
    ExcludeAll = 0,
    IncludePhysicalChunk = 1 << 0,
    IncludeGammaChunk = 1 << 1,
    IncludeExifChunk = 1 << 2,
    IncludeTextChunks = 1 << 3,

    // Default:
    IncludeAll = IncludePhysicalChunk | IncludeGammaChunk | IncludeExifChunk | IncludeTextChunks
}

Negative flags:

public enum PngChunkFilter
{
    // Default:
    IncludeAll = 0,
    ExcludePhysicalChunk = 1 << 0,
    ExcludeGammaChunk = 1 << 1,
    ExcludeExifChunk = 1 << 2,
    ExcludeTextChunks = 1 << 3,
    
    ExcludeAll = ExcludePhysicalChunk | ExcludeGammaChunk | ExcludeExifChunk | ExcludeTextChunks
}

Copy link
Member

Choose a reason for hiding this comment

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

I much prefer the suggested naming definition.

The overall metadata API is designed to preserve as much metadata as possible so I think we should adopt the negative flags. This to me as a consumer would cognitively reflect that intention as I'm building a rule for what to exclude.

Copy link
Collaborator

Choose a reason for hiding this comment

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

this is changed now to negative flags

/// <summary>
/// Make funlly transparent pixels black.
/// </summary>
MakeTransparentBlack = 16,
Copy link
Member

Choose a reason for hiding this comment

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

This one is really different from the other ones, I would rather place this one into a separate property inside PngEncoder.

Copy link
Member

Choose a reason for hiding this comment

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

Agreed. It doesn't seem to fit. Is the naming accurate also? It's not black, it's empty.

Copy link
Collaborator

Choose a reason for hiding this comment

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

i think MakeTransparentBlack is clear in what it does, but im open for other suggestions

/// <summary>
/// All possible optimizations.
/// </summary>
All = 31,
Copy link
Member

Choose a reason for hiding this comment

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

Defining the union of the flags manually is more prone to mistakes when changed in future.

Copy link
Member

Choose a reason for hiding this comment

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

All = ~None.

@brianpopow
Copy link
Collaborator

I like the idea, i want to continue on this.

@brianpopow brianpopow self-assigned this Apr 29, 2020
/// <summary>
/// Enum indicating how the transparency should be handled on encoding.
/// </summary>
public enum PngTransparentColorBehavior
Copy link
Member

Choose a reason for hiding this comment

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

My bad, let's call it PngTransparentColorMode to keep it in line with othernaming.

@JimBobSquarePants JimBobSquarePants modified the milestones: Future, 1.0.0 May 1, 2020
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.

Looks great, let's get it merged 👍

@JimBobSquarePants JimBobSquarePants merged commit 17ec6ee into SixLabors:master May 17, 2020
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.

5 participants