Pro.GIF
— 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:
This class represents a GIF image.
This class represents a GIF segment.
List of
GIFSegment
elements.
GIFSegmentListIt
(obj)Iterator class for
GIFSegmentList
.Attributes:
Segment type.
Segment type.
Segment type.
Segment type.
Segment type.
Segment type.
Segment type.
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.Returns the height of the image.
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
([wo])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
See also
GIFSegment
,GIFSegmentList
,SetStoredSegments()
andLocateSegments()
.
- 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 returnsFalse
.- Return type
bool
- LocateSegments(wo: Optional[Pro.Core.NTIWait] = None) → Pro.GIF.GIFSegmentList¶
Locates the segments in the GIF.
- Parameters
wo (NTIWait) – Optional wait object.
- Returns
Returns the list of located GIF segments.
- Return type
See also
GIFSegment
,GIFSegmentList
,SetStoredSegments()
andGetStoredSegments()
.
- 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
isPro.Core.INVALID_STREAM_OFFSET
.- Return type
See also
GIFSegment.offset
,SegmentSize()
andSegmentName()
.
- 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()
andSegmentData()
.
- 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()
andSegmentName()
.
- 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()
andLocateSegments()
.
- class GIFSegment¶
This class represents a GIF segment.
Attributes:
The offset of the segment.
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 positioni
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
- 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 returnsFalse
.- Return type
bool
- 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()
andcontains()
.
- 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 positioni
in the vector. Ifi
is0
, the value is prepended to the vector. Ifi
issize()
, 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 returnsFalse
.- Return type
bool
See also
size()
.
- iterator() → Pro.GIF.GIFSegmentListIt¶
Creates an iterator for the vector.
- Returns
Returns the iterator.
- Return type
- 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
. Ifsize
is greater than the current size, elements are added to the end; the new elements are initialized with a default-constructed value. Ifsize
is less than the current size, elements are removed from the end.
- Parameters
size (int) – The new size of the vector.
See also
size()
.
- 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 returnsFalse
.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 returnsFalse
.
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 returnsFalse
.- Return type
bool
See also
hasPrevious()
andnext()
.
- 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 returnsFalse
.- Return type
bool
See also
hasNext()
andprevious()
.
- next() → Pro.GIF.GIFSegment¶
- Returns
Returns the next item and advances the iterator by one position.
- Return type
See also
hasNext()
andprevious()
.
- previous() → Pro.GIF.GIFSegment¶
- Returns
Returns the previous item and moves the iterator back by one position.
- Return type
See also
hasPrevious()
andnext()
.
- toBack() → None¶
Moves the iterator to the back of the container (after the last item).
See also
toFront()
andprevious()
.
- 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.