[Qt] optimize PNG files #5489

pull jonasschnelli wants to merge 4 commits into bitcoin:master from jonasschnelli:2014_12_color_profle_strip changing 82 files +73 −0
  1. jonasschnelli commented at 4:20 PM on December 16, 2014: contributor

    According to report on #5488 there can be libpng warnings while starting bitcoin-qt. This PR will strip out unnecessary data (especially color profiles) from all PNG files.

  2. laanwj commented at 4:29 PM on December 16, 2014: member

    Can you give the exact command line used? I'd like to reproduce this.

  3. jonasschnelli commented at 4:40 PM on December 16, 2014: contributor

    i used convert -strip <filename>.png <filename>.png.

  4. paveljanik commented at 5:13 PM on December 16, 2014: contributor

    Doesn't print the warning as the master itself. For the reference, the warning was:

    libpng warning: iCCP: known incorrect sRGB profile
    
  5. sipa commented at 12:06 AM on December 17, 2014: member

    The result of that command is not identical here. Running the command on top of your output gives an even different result.

  6. jonasschnelli commented at 8:00 AM on December 17, 2014: contributor

    Analyzed. It needs two (or even three runs). After then that file SHA1 keep the same. I also provided a script under ./contrib/strip_pngs.sh

    I also assume it could depend on installed imagemagick and libpng version.

    Here you can see the process of one file. The DIFF is from imagemagicks identify -verbose (full bash dump of all files is here: http://paste.ubuntu.com/9548096/)

    Jonass-MacBook-Pro-2:bitcoin jonasschnelli$ convert --version
    Version: ImageMagick 6.8.9-8 Q16 x86_64 2014-10-23 http://www.imagemagick.org
    Copyright: Copyright (C) 1999-2014 ImageMagick Studio LLC
    Features: DPC Modules
    Delegates: bzlib freetype jng jpeg ltdl lzma png xml zlib
    
    Jonass-MacBook-Pro-2:bitcoin jonasschnelli$ contrib/strip_pngs.sh src/qt/res/icons
    stripping ./about.png
    SHA1 before: 
    SHA1(./about.png)= e6f23d98c69892f0a26613c23a68a610030f745b
    SHA1 after: 
    SHA1(./about.png)= 8b56adeec521bba7bc6d49e7dc54f96216af0f7f
    
    DIFF:
    8c8
    <   Base type: GrayscaleAlpha
    ---
    >   Base type: Grayscale
    532,538c532,533
    <   Rendering intent: Perceptual
    <   Gamma: 0.454545
    <   Chromaticity:
    <     red primary: (0.64,0.33)
    <     green primary: (0.3,0.6)
    <     blue primary: (0.15,0.06)
    <     white point: (0.3127,0.329)
    ---
    >   Rendering intent: Undefined
    >   Gamma: 1
    544c539
    <   Intensity: Undefined
    ---
    >   Intensity: Rec709Luminance
    552,553c547,550
    <     date:create: 2014-12-17T08:51:59+01:00
    <     date:modify: 2014-12-17T08:51:59+01:00
    ---
    >     date:create: 2014-12-17T08:52:20+01:00
    >     date:modify: 2014-12-17T08:52:20+01:00
    >     png:bKGD: chunk was found (see Background color, above)
    >     png:cHRM: chunk was found (see Chromaticity, above)
    556,557c553,554
    <     png:IHDR.color-type-orig: 6
    <     png:IHDR.color_type: 6 (RGBA)
    ---
    >     png:IHDR.color-type-orig: 4
    >     png:IHDR.color_type: 4 (GrayAlpha)
    560,561d556
    <     png:sRGB: intent=0 (Perceptual Intent)
    <     png:text: 1 tEXt/zTXt/iTXt chunks were found
    563d557
    <     Software: Adobe ImageReady
    567,568c561,562
    <   Tainted: True
    <   Filesize: 5.92KB
    ---
    >   Tainted: False
    >   Filesize: 4.35KB
    
    Jonass-MacBook-Pro-2:bitcoin jonasschnelli$ contrib/strip_pngs.sh src/qt/res/icons
    stripping ./about.png
    SHA1 before: 
    SHA1(./about.png)= 8b56adeec521bba7bc6d49e7dc54f96216af0f7f
    SHA1 after: 
    SHA1(./about.png)= 4a7719bc47e073de262fddf940e774712d999c8e
    
    DIFF:
    547,548c547,548
    <     date:create: 2014-12-17T08:52:20+01:00
    <     date:modify: 2014-12-17T08:52:20+01:00
    ---
    >     date:create: 2014-12-17T08:52:34+01:00
    >     date:modify: 2014-12-17T08:52:34+01:00
    550c550
    <     png:cHRM: chunk was found (see Chromaticity, above)
    ---
    >     png:gAMA: gamma=1 (See Gamma, above)
    562c562
    <   Filesize: 4.35KB
    ---
    >   Filesize: 4.32KB
    
    
    Jonass-MacBook-Pro-2:bitcoin jonasschnelli$ contrib/strip_pngs.sh src/qt/res/icons
    stripping ./about.png
    SHA1 before: 
    SHA1(./about.png)= 4a7719bc47e073de262fddf940e774712d999c8e
    SHA1 after: 
    SHA1(./about.png)= 4a7719bc47e073de262fddf940e774712d999c8e
    
    DIFF:
    547,548c547,548
    <     date:create: 2014-12-17T08:52:34+01:00
    <     date:modify: 2014-12-17T08:52:34+01:00
    ---
    >     date:create: 2014-12-17T08:52:42+01:00
    >     date:modify: 2014-12-17T08:52:42+01:00
    
  7. jonasschnelli force-pushed on Dec 17, 2014
  8. laanwj commented at 1:57 PM on December 17, 2014: member

    OK this freaks me out. My output differs from yours. From your diff above I thought the problem was an embedded timestamp, however I get no different result from

        export LD_PRELOAD=/usr/lib/x86_64-linux-gnu/faketime/libfaketime.so.1
        export FAKETIME='2012-12-12 12:12:12'
        git reset --hard
        find -name \*.png -print0 | xargs -0 -I FILENAME convert -strip FILENAME FILENAME
        find -name \*.png -print0 | xargs -0 sha256sum > /tmp/a.txt
    

    As from

        unset LD_PRELOAD
        unset FAKETIME
        git reset --hard
        find -name \*.png -print0 | xargs -0 -I FILENAME convert -strip FILENAME FILENAME
        find -name \*.png -print0 | xargs -0 sha256sum > /tmp/b.txt
    

    As it seems, identify.im6 just shows the current timestamp as date:create and date:modify. Confusing. But indeed I get the same output every time: http://paste.ubuntu.com/9550689/

    So probably it's just a version difference. My IM is much older:

    Version: ImageMagick 6.7.7-10 2014-03-06 Q16 http://www.imagemagick.org
    

    Edit: OH, I'm running it only one time, not until fixpoint. Will try.

  9. laanwj commented at 2:05 PM on December 17, 2014: member

    Now ran it three times, hash was not longer changing. However, still not all match the files in this pull (though some do). See diff here http://paste.ubuntu.com/9550744/

  10. jonasschnelli commented at 2:09 PM on December 17, 2014: contributor

    I assume this happens because of different imagemagick/libpng versions. I mean, the core business of these tools is to deal with png/bitmap internas. So there might be some byte differences because of different handling. Adding imagemagick and libpng to the depends would probably solve this but is a overkill IMO.

  11. laanwj commented at 2:28 PM on December 17, 2014: member

    Yes, it's not that important. I primarily wanted to be able to reproduce this when people add files (which the script does). Determinism would be a plus, but adding imagemagick to depends would be overkill.

  12. fanquake commented at 10:02 AM on January 3, 2015: member

    Needs Rebase

  13. jonasschnelli force-pushed on Jan 3, 2015
  14. jonasschnelli force-pushed on Jan 3, 2015
  15. jonasschnelli commented at 7:14 PM on January 3, 2015: contributor

    Rebased.

  16. laanwj added the label GUI on Jan 8, 2015
  17. jonasschnelli force-pushed on Jan 9, 2015
  18. jonasschnelli force-pushed on Jan 9, 2015
  19. jonasschnelli force-pushed on Jan 9, 2015
  20. jonasschnelli commented at 3:47 PM on January 9, 2015: contributor

    Updated the script as well as the images so it will use pngcrush to crush the convert-stripped images.

  21. zander commented at 6:51 AM on January 13, 2015: none

    Would a tool like optipng or pngcrush or trimage be more appropriate ?

  22. jonasschnelli commented at 7:14 AM on January 13, 2015: contributor

    @zander: pngcrush is included. See my last comment.

  23. laanwj commented at 9:52 AM on January 13, 2015: member

    Your script needs set -e at the top to make it fail when one of the tools fails. (e.g. I didn't have pngcrush installed and it happily continued)

    Also let's move it to contrib/devtools, leaving the script in the contrib toplevel is a bit untidy.

  24. [Qt] optimize PNG files
    - provide a python script
    - add optimized png files
    059c889440
  25. jonasschnelli force-pushed on Jan 13, 2015
  26. jonasschnelli commented at 12:38 PM on January 13, 2015: contributor

    Rewrote script, placed it under contrib/devtools. Output of processing is here: https://gist.github.com/jonasschnelli/dad302d9b9b8a3163259

  27. jonasschnelli commented at 12:42 PM on January 13, 2015: contributor

    A second run of the script won't change the PNG sha256 (at least in my environment).

  28. add checking to strip_pngs.py
    Check that image contents match pre- and post- crushing.
    Also remove use of external tool to compute sha256 in favor of hashlib.
    41dc934ffc
  29. laanwj commented at 12:54 PM on January 14, 2015: member

    Looks good to me now. When I re-run this script I get the same output as well. In https://github.com/laanwj/bitcoin/commit/41dc934ffc111a900d9262cd1bb1ad84492a4e6e I've improved the script a little bit:

    • Add pre/post check of image contents
    • remove use of external tool to compute sha256 in favor of hashlib
  30. contrib: remove all use of shell=True in strip_pngs.py
    Using `shell=True` can be a security hazard. See e.g.
    https://docs.python.org/2/library/subprocess.html#subprocess.check_output
    2c77c15070
  31. laanwj commented at 1:12 PM on January 14, 2015: member

    Added another commit https://github.com/laanwj/bitcoin/commit/2c77c150703952764aaeb43ab5f836d5b7fb0f7a that replaces uses of shell=True with the Python equivalent (as shell=True is less portable, and can be a security hazard).

  32. rename png_strip to optimize-png d691709706
  33. jonasschnelli commented at 3:10 PM on January 14, 2015: contributor

    Nice. Thanks for the additions. I also added a rename commit because strip_png.py is no longer a adequate name.

  34. laanwj referenced this in commit d1aa3c67f0 on Jan 14, 2015
  35. laanwj commented at 4:25 PM on January 14, 2015: member

    Merged via d1aa3c6 (squashed into two commits, one with your changes one with mine)

  36. jonasschnelli commented at 10:05 AM on January 16, 2015: contributor

    Was merged. Closing.

  37. jonasschnelli closed this on Jan 16, 2015

  38. DrahtBot locked this on Sep 8, 2021

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-04-21 18:15 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me