Pro.JPEG
— API for parsing JPEG images¶
JPEG Segments Enumeration¶
The following code example demonstrates how enumerate the segments inside of a JPEG image:
from Pro.Core import *
from Pro.JPEG import *
def parseJPEG(jpeg_name):
c = createContainerFromFile(jpeg_name)
obj = JPGObject()
if not obj.Load(c):
return
segments = obj.LocateSegments()
obj.SetStoredSegments(segments)
it = segments.iterator()
while it.hasNext():
seg = it.next()
name = obj.SegmentName(seg.tag)
size = obj.SegmentSize(seg.tag, seg.offset)
print("segment:", name, "- offset:", hex(seg.offset), "- size:", hex(size))
Module API¶
Pro.JPEG module API.
Attributes:
JPEG thumbnail type.
JPEG thumbnail type.
JPEG thumbnail type.
JPEG thumbnail type.
Classes:
This class represents the information on a JPEG thumbnail.
This class represents a JPEG image.
This class represents a JPEG segment.
List of
JPGSegment
elements.
JPGSegmentListIt
(obj)Iterator class for
JPGSegmentList
.
- JPEGThumb_JPEG: Final[int]¶
JPEG thumbnail type.
See also
JPEGThumbnail.type
.
- JPEGThumb_OnePerPixel: Final[int]¶
JPEG thumbnail type.
See also
JPEGThumbnail.type
.
- JPEGThumb_Raster: Final[int]¶
JPEG thumbnail type.
See also
JPEGThumbnail.type
.
- JPEGThumb_ThreePerPixel: Final[int]¶
JPEG thumbnail type.
See also
JPEGThumbnail.type
.
- class JPEGThumbnail¶
This class represents the information on a JPEG thumbnail.
See also
JPGObject.GetJFIFThumbnail
.Methods:
IsNull
()Returns
True
if invalid; otherwise returnsFalse
.
IsValid
()Returns
True
if valid; otherwise returnsFalse
.Attributes:
The height of the thumbnail.
The offset of the thumbnail.
The size of the thumbnail.
The type of thumbnail (e.g.,
JPEGThumb_ThreePerPixel
).The width of the thumbnail.
- IsNull() → bool¶
- Returns
Returns
True
if invalid; otherwise returnsFalse
.- Return type
bool
See also
IsValid()
.
- IsValid() → bool¶
- Returns
Returns
True
if valid; otherwise returnsFalse
.- Return type
bool
See also
IsNull()
.
- type¶
The type of thumbnail (e.g.,
JPEGThumb_ThreePerPixel
).
- class JPGObject¶
Bases:
Pro.Core.CFFObject
This class represents a JPEG image.
Methods:
GetJFIFThumbnail
(offset, size)Retrieves information about a JFIF thumbnail.
Returns the list of stored JPEG segments.
Locates JPEG segments.
SegmentName
(tag)Retrieves the name of a JPEG segment from its tag.
SegmentSize
(tag, offset)Computes the size of a JPEG segment.
SetStoredSegments
(segments)Sets the list of stored JPEG segments.
SkipEntropyData
(offset)Skips the entropy data at the end of a segment.
- GetJFIFThumbnail(offset: int, size: int) → Pro.JPEG.JPEGThumbnail¶
Retrieves information about a JFIF thumbnail.
- Parameters
offset (int) – The offset of the segment data (not including the marker).
size (int) – The size of the segment data (not including the marker).
- Returns
Retrieves the information about the thumbnail if successful; otherwise returns an invalid
JPEGThumbnail
instance.- Return type
- GetStoredSegments() → Pro.JPEG.JPGSegmentList¶
- Returns
Returns the list of stored JPEG segments.
- Return type
See also
SetStoredSegments()
,LocateSegments()
andJPGSegment
.
- LocateSegments() → Pro.JPEG.JPGSegmentList¶
Locates JPEG segments.
- Returns
Returns the list of JPEG segments found in the image.
- Return type
See also
GetStoredSegments()
,SetStoredSegments()
andJPGSegment
.
- SegmentName(tag: int) → str¶
Retrieves the name of a JPEG segment from its tag.
- Parameters
tag (int) – The tag of the JPEG segment.
- Returns
Returns the name of the JPEG segment if successful; otherwise returns
"Unknown"
.- Return type
str
See also
SegmentSize()
.
- SegmentSize(tag: int, offset: int) → int¶
Computes the size of a JPEG segment.
- Parameters
tag (int) – The tag of the segment.
offset (int) – The offset of the segment.
- Returns
Returns the size of the JPEG segment if successful; otherwise returns
-1
.- Return type
int
See also
SegmentName()
.
- SetStoredSegments(segments: Pro.JPEG.JPGSegmentList) → None¶
Sets the list of stored JPEG segments.
- Parameters
segments (JPGSegmentList) – The segment list to store.
See also
GetStoredSegments()
,LocateSegments()
andJPGSegment
.
- SkipEntropyData(offset: int) → int¶
Skips the entropy data at the end of a segment.
- Parameters
offset (int) – The offset of the entropy data.
- Returns
Returns the offset after the entropy data if successful; otherwise returns
Pro.Core.INVALID_STREAM_OFFSET
.- Return type
int
- class JPGSegment¶
This class represents a JPEG segment.
Attributes:
The offset of the segment.
The tag of the segment.
- offset¶
The offset of the segment.
Hint
The offset points at the marker of the segment. The data of the segment starts at
offset + 2
.
- tag¶
The tag of the segment.
- class JPGSegmentList¶
List of
JPGSegment
elements.Methods:
append
(value)Inserts
value
at the end of the list.
at
(i)Returns the item at index position
i
in the list.
clear
()Removes all items from the list.
contains
(value)Checks the presence of an element in the list.
count
(value)Returns the number of occurrences of
value
in the list.
indexOf
(value[, start])Searches for an element in the list.
insert
(i, value)Inserts
value
at index positioni
in the list.
isEmpty
()Checks whether the list is empty.
iterator
()Creates an iterator for the list.
removeAll
(value)Removes all occurrences of
value
in the list and returns the number of entries removed.
removeAt
(i)Removes the item at index position
i
.
reserve
(alloc)Reserve space for
alloc
elements.
size
()Returns the number of items in the list.
takeAt
(i)Removes the item at index position
i
and returns it.
- append(value: Pro.JPEG.JPGSegment) → None¶
Inserts
value
at the end of the list.
- Parameters
value (JPGSegment) – The value to add to the list.
See also
insert()
.
- at(i: int) → Pro.JPEG.JPGSegment¶
Returns the item at index position
i
in the list.i
must be a valid index position in the list (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 items from the list.
- contains(value: Pro.JPEG.JPGSegment) → bool¶
Checks the presence of an element in the list.
- Parameters
value (JPGSegment) – The value to check for.
- Returns
Returns
True
if the list contains an occurrence ofvalue
; otherwise returnsFalse
.- Return type
bool
- count(value: Pro.JPEG.JPGSegment) → int¶
Returns the number of occurrences of
value
in the list.
- Parameters
value (JPGSegment) – The value to count.
- Returns
Returns the number of occurrences.
- Return type
int
See also
indexOf()
andcontains()
.
- indexOf(value: Pro.JPEG.JPGSegment, start: int = 0) → int¶
Searches for an element in the list.
- Parameters
value (JPGSegment) – The value to search for.
start (int) – The start index.
- Returns
Returns the index position of the first occurrence of
value
in the list. Returns-1
if no item was found.- Return type
int
See also
contains()
.
- insert(i: int, value: Pro.JPEG.JPGSegment) → None¶
Inserts
value
at index positioni
in the list. Ifi
is0
, the value is prepended to the list. Ifi
issize()
, the value is appended to the list.
- Parameters
i (int) – The position at which to add the value.
value (JPGSegment) – The value to add.
See also
append()
andremoveAt()
.
- isEmpty() → bool¶
Checks whether the list is empty.
- Returns
Returns
True
if the list contains no items; otherwise returnsFalse
.- Return type
bool
See also
size()
.
- iterator() → Pro.JPEG.JPGSegmentListIt¶
Creates an iterator for the list.
- Returns
Returns the iterator.
- Return type
- removeAll(value: Pro.JPEG.JPGSegment) → int¶
Removes all occurrences of
value
in the list and returns the number of entries removed.
- Parameters
value (JPGSegment) – The value to remove from the list.
- Returns
Returns the number of entries removed.
- Return type
int
See also
removeAt()
.
- removeAt(i: int) → None¶
Removes the item at index position
i
.i
must be a valid index position in the list (i.e.,0 <= i < size()
).
- Parameters
i (int) – The index of the item to remove.
See also
removeAll()
.
- reserve(alloc: int) → None¶
Reserve space for
alloc
elements. Calling this method doesn’t change the size of the list.
- Parameters
alloc (int) – The amount of elements to reserve space for.
- takeAt(i: int) → Pro.JPEG.JPGSegment¶
Removes the item at index position
i
and returns it.i
must be a valid index position in the list (i.e.,0 <= i < size()
).
- Parameters
i (int) – The index of the element to remove from the list.
- Returns
Returns the removed element. If you don’t use the return value,
removeAt()
is more efficient.- Return type
See also
removeAt()
.
- class JPGSegmentListIt(obj: Pro.JPEG.JPGSegmentList)¶
Iterator class for
JPGSegmentList
.
- Parameters
obj (JPGSegmentList) – 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.JPEG.JPGSegment¶
- Returns
Returns the next item and advances the iterator by one position.
- Return type
See also
hasNext()
andprevious()
.
- previous() → Pro.JPEG.JPGSegment¶
- 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()
.