Pro.PNG — API for parsing PNG images

Overview

The Pro.PNG module contains the API for parsing PNG images.

PNG Chunks Enumeration

The following code example demonstrates how enumerate the chunks inside of a PNG image:

from Pro.Core import *
from Pro.PNG import *

def parsePNG(fname):
    c = createContainerFromFile(fname)
    if c.isNull():
        return
    obj = PNGObject()
    if not obj.Load(c) or not obj.Initialize():
        return
    chunks = obj.GetStoredChunks()
    it = chunks.iterator()
    while it.hasNext():
        offset = it.next()
        name = obj.ChunkName(offset)
        size = obj.ChunkSize(offset)
        print("segment:", name, "- offset:", hex(offset), "- size:", hex(size))

Module API

Pro.PNG module API.

Classes:

PNGObject()

This class represents a PNG image.

class PNGObject

Bases: Pro.Core.CFFObject

This class represents a PNG image.

Methods:

ChunkName(offset)

Retrieves the name of a PNG chunk.

ChunkSize(offset)

Retrieves the size of a PNG chunk.

ChunkType(offset)

Retrieves the type of a PNG chunk.

GetStoredChunks()

Returns the list of internally stored PNG chunks.

IsChunkNecessary(type)

Checks whether a PNG chunk is essential.

LocateChunks([wo])

Find all PNG chunks in the image.

SetStoredChunks(chunks)

Sets the list of internally stored PNG chunks.

ChunkName(offset: int) → str

Retrieves the name of a PNG chunk.

Parameters

offset (int) – The offset of the chunk.

Returns

Returns the name of the chunk if successful; otherwise returns an empty string.

Return type

str

See also ChunkSize() and ChunkType().

ChunkSize(offset: int) → int

Retrieves the size of a PNG chunk.

Parameters

offset (int) – The offset of the chunk.

Returns

Returns the size of the chunk.

Return type

int

See also ChunkName() and ChunkType().

ChunkType(offset: int) → int

Retrieves the type of a PNG chunk.

Parameters

offset (int) – The offset of the chunk.

Returns

Returns the type of the PNG chunk.

Return type

int

See also ChunkName() and ChunkSize().

GetStoredChunks() → Pro.Core.NTUIntVector
Returns

Returns the list of internally stored PNG chunks.

Return type

NTUIntVector

See also SetStoredChunks() and LocateChunks().

IsChunkNecessary(type: int) → bool

Checks whether a PNG chunk is essential.

Parameters

type (int) – The PNG chunk type.

Returns

Returns True if the PNG chunk is essential; otherwise returns False.

Return type

bool

LocateChunks(wo: Optional[Pro.Core.NTIWait] = None) → Pro.Core.NTUIntVector

Find all PNG chunks in the image.

Parameters

wo (NTIWait) – Optional wait object.

Returns

Returns the list of PNG chunks found.

Return type

NTUIntVector

See also SetStoredChunks() and GetStoredChunks().

SetStoredChunks(chunks: Pro.Core.NTUIntVector) → None

Sets the list of internally stored PNG chunks.

Parameters

chunks (NTUIntVector) – The PNG chunk list.

See also LocateChunks() and GetStoredChunks().