Skip to content

Commit

Permalink
pngexif: Import pngexifinfo as an externally-contributed project
Browse files Browse the repository at this point in the history
We used this experimental project in the development of the PNG-EXIF
("eXIf") specification, back in 2017. The project evolved together
with the draft specification, which was finalized on 2017-Jun-15 and
approved by the PNG Group on 2017-Jul-13.

The EXIF specification, outside of the scope of PNG and libpng, is
quite complex. The libpng implementation cannot grow too much beyond
performing basic integrity checks on top of serialization. In order
to create and manipulate PNG-EXIF image files, the use of external
libraries and tools such as ExifTool is necessary.

Now, with the addition of contrib/pngexif to the libpng repository,
offline tasks like metadata inspection and linting can be performed
without importing external dependencies.
  • Loading branch information
ctruta committed Feb 22, 2024
1 parent 7b88809 commit ec2e58c
Show file tree
Hide file tree
Showing 10 changed files with 607 additions and 0 deletions.
11 changes: 11 additions & 0 deletions contrib/pngexif/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# https://editorconfig.org

root = true

[*]
charset = utf-8
indent_style = space
insert_final_newline = true
max_doc_length = 79
max_line_length = 79
trim_trailing_whitespace = true
3 changes: 3 additions & 0 deletions contrib/pngexif/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
__pycache__
*.py[co]
*$py.class
8 changes: 8 additions & 0 deletions contrib/pngexif/.pylintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[COMPATIBILITY]
disable=consider-using-f-string

[COMPLEXITY]
disable=too-many-branches,too-many-instance-attributes

[STYLE]
disable=consider-using-in
19 changes: 19 additions & 0 deletions contrib/pngexif/LICENSE_MIT.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
MIT License

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
20 changes: 20 additions & 0 deletions contrib/pngexif/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
pngexifinfo
===========

Show the EXIF information embedded in a PNG file.


Sample usage
------------

Show the EXIF info inside a PNG file:

pngexifinfo /path/to/file.png

Show the EXIF info inside a raw `.exif` file, using base 16 for the EXIF tags:

pngexifinfo --hex /path/to/file.exif

Show the help text:

pngexifinfo --help
48 changes: 48 additions & 0 deletions contrib/pngexif/bytepack.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/usr/bin/env python

"""
Byte packing and unpacking utilities.
Copyright (C) 2017-2020 Cosmin Truta.
Use, modification and distribution are subject to the MIT License.
Please see the accompanying file LICENSE_MIT.txt
"""

from __future__ import absolute_import, division, print_function

import struct


def unpack_uint32be(buffer, offset=0):
"""Unpack an unsigned int from its 32-bit big-endian representation."""
return struct.unpack(">I", buffer[offset:offset + 4])[0]


def unpack_uint32le(buffer, offset=0):
"""Unpack an unsigned int from its 32-bit little-endian representation."""
return struct.unpack("<I", buffer[offset:offset + 4])[0]


def unpack_uint16be(buffer, offset=0):
"""Unpack an unsigned int from its 16-bit big-endian representation."""
return struct.unpack(">H", buffer[offset:offset + 2])[0]


def unpack_uint16le(buffer, offset=0):
"""Unpack an unsigned int from its 16-bit little-endian representation."""
return struct.unpack("<H", buffer[offset:offset + 2])[0]


def unpack_uint8(buffer, offset=0):
"""Unpack an unsigned int from its 8-bit representation."""
return struct.unpack("B", buffer[offset:offset + 1])[0]


if __name__ == "__main__":
# For testing only.
assert unpack_uint32be(b"ABCDEF", 1) == 0x42434445
assert unpack_uint32le(b"ABCDEF", 1) == 0x45444342
assert unpack_uint16be(b"ABCDEF", 1) == 0x4243
assert unpack_uint16le(b"ABCDEF", 1) == 0x4342
assert unpack_uint8(b"ABCDEF", 1) == 0x42
Loading

0 comments on commit ec2e58c

Please sign in to comment.