diff --git a/piexif/_webp.py b/piexif/_webp.py index f9cc42e..38b18c4 100644 --- a/piexif/_webp.py +++ b/piexif/_webp.py @@ -93,50 +93,118 @@ def _get_size_from_anmf(chunk): height = height_minus_one + 1 return (width, height) -def set_vp8x(chunks): - width = None - height = None - flags = [b"0", b"0", b"0", b"0", b"0", b"0", b"0", b"0"] # [0, 0, ICC, Alpha, EXIF, XMP, Anim, 0] +def _get_sub_chunks_from_anmf(anmf_chunk): + """ + Extracts and returns sub-chunks from the ANMF chunk data. - for chunk in chunks: - if chunk["fourcc"] == b"VP8X": + :param anmf_chunk: Dictionary containing the 'fourcc', 'length_bytes', and 'data' for the ANMF chunk. + :return: List of dictionaries representing sub-chunks found within the ANMF chunk. + """ + data = anmf_chunk['data'] + sub_chunks = [] + offset = 0 + + # Fixed size for the ANMF header (Frame X, Frame Y, Width, Height, Duration, Reserved, B, D) + anmf_header_size = 16 + + # Skip the ANMF header to get to the Frame Data + offset += anmf_header_size + + data_length = len(data) + while offset < data_length: + # Ensure there's enough data left for a new chunk (4 bytes for fourcc + 4 bytes for length) + if offset + 8 > data_length: + break + + # Read the fourcc code (4 bytes) + fourcc = data[offset:offset + 4] + offset += 4 + + # Read the length of the chunk (4 bytes, little-endian) + length = struct.unpack(' data_length: + break + + # Read the chunk data + chunk_data = data[offset:offset + length] + offset += length + + # Append the sub-chunk to the list + sub_chunks.append({ + 'fourcc': fourcc, + 'length_bytes': struct.pack('