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 AVIF sanitizer tool #210

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

leo-barnes
Copy link
Collaborator

No description provided.

@leo-barnes
Copy link
Collaborator Author

@y-guyon
Can't add you as a reviewer for some reason

@cconcolato
Copy link
Collaborator

@y-guyon Can't add you as a reviewer for some reason

Just added him as "Team member" and Maintainer.

Copy link
Collaborator

@y-guyon y-guyon left a comment

Choose a reason for hiding this comment

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

Nice!

  • I am not a fan of one big file.
  • The concise functions were easy to read.
  • I feel like there is some overlap with the Compliance Warden.

Tools/sanitize_avif.py Show resolved Hide resolved


def write_integer_array_of_size(values: list[int], nbytes: int, unsigned: bool = True) -> bytes:
"""Writes a value as an integer of nbytes size."""
Copy link
Collaborator

Choose a reason for hiding this comment

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

"""Writes values as integers each of nbytes size."""

self.file.seek(position)

def read_integer_of_size(self, end: int, nbytes: int, unsigned: bool = True) -> int:
"""Reads an integer of size nbytes from file."""
Copy link
Collaborator

Choose a reason for hiding this comment

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

Note: There could be some comment about endianness

self, nbytes: int, end: Optional[int] = None
) -> "FileReader.BitReader":
"""Returns a BitReader for the next nbytes of data."""
data = self.read_data(nbytes, end=end)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is end=end suggested by pylint?

buf.append(byte[0])
if len(buf) > 0:
return decode_data_to_string(buf)
return None
Copy link
Collaborator

Choose a reason for hiding this comment

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

Inconsistent

            return decode_data_to_string(buf) if len(buf) > 0 else None

vs

            if len(buf) > 0:
                return decode_data_to_string(buf)
            return None

def add_property_association(
self, item_id: int, ipco_index: int, essential: bool, position: Optional[int] = None
) -> None:
"""Add an association from an item to a property in the ipco box."""
Copy link
Collaborator

Choose a reason for hiding this comment

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

"""... if not already present."""?

description = "No 'pixi' present. This is a requirement by MIAF."
else:
description = (
"'pixi' does not match Sequence Header OBU." + f" {existing_pixi} != {generated_pixi}."
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe "AV1" before "Sequence Header OBU" would be clearer for novices

fixed_clap["v_offset"] = [round(fixed_offset[1] * 2), 2]
parsed_file.replace_property_for_item(BoxType("clap"), {}, fixed_clap, item_id)

issue.add_fix(_fix_clap_origin, f"Truncate origin to {trunc_origin[0]}x{trunc_origin[1]}")
Copy link
Collaborator

Choose a reason for hiding this comment

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

"Truncate 'clap' origin"?



def validate_file(parsed_file: ParsedFile, default_nclx: dict[str, list[int]]) -> list[BoxIssue]:
"""Validates that a AVIF file is correct."""
Copy link
Collaborator

Choose a reason for hiding this comment

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

an*

)
parser.add_argument(
"-o",
"--only-verify",
Copy link
Collaborator

Choose a reason for hiding this comment

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

"--dry-run" maybe?

@leo-barnes
Copy link
Collaborator Author

  • I am not a fan of one big file.

Agreed. It would have been nicer from a readability perspective to have it split into submodules, but I decided to keep it monolithic due to the following:

  • It was easier to get through Apple Open Source contribution review
  • It's convenient to have a self contained file that you can send around/point to
  • The concise functions were easy to read.
  • I feel like there is some overlap with the Compliance Warden.

Again agreed. I mention in the help text that it's not a replacement for Compliance Warden since it will only detect a subset of actually fixable issues.

@podborski podborski added the tools Spec related tools / scripts / etc. label Aug 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tools Spec related tools / scripts / etc.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants