Pro.GIF — API for parsing GIF images

Overview

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

Parsing a GIF image

The following code example demonstrates how to enumerate the segments in a GIF:

from Pro.Core import *
from Pro.GIF import *

def parseGIF(fname):
    c = createContainerFromFile(fname)
    if c.isNull():
        return
    obj = GIFObject()
    if not obj.Load(c):
        return
    segments = obj.LocateSegments()
    obj.SetStoredSegments(segments)
    n = segments.size()
    for i in range(n):
        print(obj.SegmentName(segments.at(i).type))
        r = obj.SegmentData(segments, i)
        print("    data offset:", r.offset, "data size:", r.size)

Module API

Pro.GIF module API.

Classes:

GIFObject()

This class represents a GIF image.

GIFSegment()

This class represents a GIF segment.

GIFSegmentList()

List of GIFSegment elements.

GIFSegmentListIt(obj)

Iterator class for GIFSegmentList.

Attributes:

GIFSegmentType_ApplicationExtension

Segment type.

GIFSegmentType_CommentExtension

Segment type.

GIFSegmentType_End

Segment type.

GIFSegmentType_GlobalColorTable

Segment type.

GIFSegmentType_GraphicControlExtension

Segment type.

GIFSegmentType_Header

Segment type.

GIFSegmentType_Image

Segment type.

GIFSegmentType_PlainTextExtension

Segment type.

class GIFObject

Bases: Pro.Core.CFFObject

This class represents a GIF image.

Methods:

DumpComments(out)

Prints out the comments contained in segments with a GIFSegmentType_CommentExtension type.

GetHeight()

Returns the height of the image.

GetStoredSegments()

Returns the internal list of GIF segments.

GetWidth()

Returns the width of the image.

IsExtension(type)

Checks whether the segment type is an extension type (e.g., GIFSegmentType_ApplicationExtension()).

LocateSegments()

Locates the segments in the GIF.

SegmentData(segments, i)

Computes the offset and size of the data of a GIF segment.

SegmentName(type)

Retrieves the name of the GIF segment based on its type.

SegmentSize(segments, i)

Computes the size of a GIF segment.

SetStoredSegments(chunks)

Sets the internal list of GIF segments.

DumpComments(out: Pro.Core.NTTextStream)None

Prints out the comments contained in segments with a GIFSegmentType_CommentExtension type.

Parameters

out (NTTextStream) – The output stream.

See also Pro.Core.NTTextStream.

GetHeight()int
Returns

Returns the height of the image.

Return type

int

See also GetWidth().

GetStoredSegments()Pro.GIF.GIFSegmentList
Returns

Returns the internal list of GIF segments.

Return type

GIFSegmentList

See also GIFSegment, GIFSegmentList, SetStoredSegments() and LocateSegments().

GetWidth()int
Returns

Returns the width of the image.

Return type

int

See also GetHeight().

IsExtension(type: int)bool

Checks whether the segment type is an extension type (e.g., GIFSegmentType_ApplicationExtension()).

Parameters

type (int) – The segment type.

Returns

Returns True if the segment type is an extension type; otherwise returns False.

Return type

bool

LocateSegments()Pro.GIF.GIFSegmentList

Locates the segments in the GIF.

Returns

Returns the list of located GIF segments.

Return type

GIFSegmentList

See also GIFSegment, GIFSegmentList, SetStoredSegments() and GetStoredSegments().

SegmentData(segments: Pro.GIF.GIFSegmentList, i: int)Pro.Core.NTOffsetRange

Computes the offset and size of the data of a GIF segment.

Parameters
  • segments (GIFSegmentList) – The list of input segments.

  • i (int) – The index of the segment whose data range must be returned.

Returns

Returns the range of the data of the GIF segment if successful; otherwise the returned Pro.Core.NTOffsetRange.offset is Pro.Core.INVALID_STREAM_OFFSET.

Return type

NTOffsetRange

See also GIFSegment.offset, SegmentSize() and SegmentName().

SegmentName(type: int)str

Retrieves the name of the GIF segment based on its type.

Parameters

type (int) – The type of the GIF segment.

Returns

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

Return type

str

See also SegmentSize() and SegmentData().

SegmentSize(segments: Pro.GIF.GIFSegmentList, i: int)int

Computes the size of a GIF segment.

Parameters
  • segments (GIFSegmentList) – The list of input segments.

  • i (int) – The index of the segment whose size must be returned.

Returns

Returns the size of the GIF segment if successful; otherwise returns 1.

Return type

int

See also SegmentData() and SegmentName().

SetStoredSegments(chunks: Pro.GIF.GIFSegmentList)None

Sets the internal list of GIF segments.

Parameters

chunks (GIFSegmentList) – The list of GIF segments.

See also GIFSegment, GIFSegmentList, GetStoredSegments() and LocateSegments().

class GIFSegment

This class represents a GIF segment.

Attributes:

offset

The offset of the segment.

type

The type of the segment.

offset

The offset of the segment.

type

The type of the segment.

class GIFSegmentList

List of GIFSegment elements.

Methods:

append(value)

Inserts value at the end of the vector.

at(i)

Returns the item at index position i in the vector.

clear()

Removes all the elements from the vector and releases the memory used by the vector.

contains(value)

Checks the presence of an element in the vector.

count(value)

Returns the number of occurrences of value in the vector.

indexOf(value[, start])

Searches for an element in the vector.

insert(i, value)

Inserts value at index position i in the vector.

isEmpty()

Checks whether the vector is empty.

iterator()

Creates an iterator for the vector.

reserve(alloc)

Reserve space for alloc elements.

resize(size)

Sets the size of the vector to size.

size()

Returns the number of items in the vector.

append(value: Pro.GIF.GIFSegment)None

Inserts value at the end of the vector.

Parameters

value (GIFSegment) – The value to add to the list.

See also insert().

at(i: int)Pro.GIF.GIFSegment

Returns the item at index position i in the vector. i must be a valid index position in the vector (i.e., 0 <= i < size()).

Parameters

i (int) – The index of the element to return.

Returns

Returns the requested element.

Return type

GIFSegment

clear()None

Removes all the elements from the vector and releases the memory used by the vector.

contains(value: Pro.GIF.GIFSegment)bool

Checks the presence of an element in the vector.

Parameters

value (GIFSegment) – The value to check for.

Returns

Returns True if the vector contains an occurrence of value; otherwise returns False.

Return type

bool

See also indexOf() and count().

count(value: Pro.GIF.GIFSegment)int

Returns the number of occurrences of value in the vector.

Parameters

value (GIFSegment) – The value to count.

Returns

Returns the number of occurrences.

Return type

int

See also indexOf() and contains().

indexOf(value: Pro.GIF.GIFSegment, start: int = 0)int

Searches for an element in the vector.

Parameters
  • value (GIFSegment) – The value to search for.

  • start (int) – The start index.

Returns

Returns the index position of the first occurrence of value in the vector. Returns -1 if no item was found.

Return type

int

See also contains().

insert(i: int, value: Pro.GIF.GIFSegment)None

Inserts value at index position i in the vector. If i is 0, the value is prepended to the vector. If i is size(), the value is appended to the vector.

Parameters
  • i (int) – The position at which to add the value.

  • value (GIFSegment) – The value to add.

See also append().

isEmpty()bool

Checks whether the vector is empty.

Returns

Returns True if the vector contains no items; otherwise returns False.

Return type

bool

See also size().

iterator()Pro.GIF.GIFSegmentListIt

Creates an iterator for the vector.

Returns

Returns the iterator.

Return type

GIFSegmentListIt

reserve(alloc: int)None

Reserve space for alloc elements. Calling this method doesn’t change the size of the vector.

Parameters

alloc (int) – The amount of elements to reserve space for.

resize(size: int)None

Sets the size of the vector to size. If size is greater than the current size, elements are added to the end; the new elements are initialized with a default-constructed value. If size is less than the current size, elements are removed from the end.

Parameters

size (int) – The new size of the vector.

See also size().

size()int
Returns

Returns the number of items in the vector.

Return type

int

See also isEmpty().

class GIFSegmentListIt(obj: Pro.GIF.GIFSegmentList)

Iterator class for GIFSegmentList.

Parameters

obj (GIFSegmentList) – The object to iterate over.

Methods:

hasNext()

Returns True if there is at least one item ahead of the iterator, i.e. the iterator is not at the back of the container; otherwise returns False.

hasPrevious()

Returns True if there is at least one item behind the iterator, i.e. the iterator is not at the front of the container; otherwise returns False.

next()

Returns the next item and advances the iterator by one position.

previous()

Returns the previous item and moves the iterator back by one position.

toBack()

Moves the iterator to the back of the container (after the last item).

toFront()

Moves the iterator to the front of the container (before the first item).

hasNext()bool
Returns

Returns True if there is at least one item ahead of the iterator, i.e. the iterator is not at the back of the container; otherwise returns False.

Return type

bool

See also hasPrevious() and next().

hasPrevious()bool
Returns

Returns True if there is at least one item behind the iterator, i.e. the iterator is not at the front of the container; otherwise returns False.

Return type

bool

See also hasNext() and previous().

next()Pro.GIF.GIFSegment
Returns

Returns the next item and advances the iterator by one position.

Return type

GIFSegment

See also hasNext() and previous().

previous()Pro.GIF.GIFSegment
Returns

Returns the previous item and moves the iterator back by one position.

Return type

GIFSegment

See also hasPrevious() and next().

toBack()None

Moves the iterator to the back of the container (after the last item).

See also toFront() and previous().

toFront()None

Moves the iterator to the front of the container (before the first item).

See also toBack() and next().

GIFSegmentType_ApplicationExtension: Final[int]

Segment type.

GIFSegmentType_CommentExtension: Final[int]

Segment type.

GIFSegmentType_End: Final[int]

Segment type.

GIFSegmentType_GlobalColorTable: Final[int]

Segment type.

GIFSegmentType_GraphicControlExtension: Final[int]

Segment type.

GIFSegmentType_Header: Final[int]

Segment type.

GIFSegmentType_Image: Final[int]

Segment type.

GIFSegmentType_PlainTextExtension: Final[int]

Segment type.