Pro.JPEG — API for parsing JPEG images

Overview

The Pro.JPEG module contains the 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:

JPEGThumb_JPEG

JPEG thumbnail type.

JPEGThumb_OnePerPixel

JPEG thumbnail type.

JPEGThumb_Raster

JPEG thumbnail type.

JPEGThumb_ThreePerPixel

JPEG thumbnail type.

Classes:

JPEGThumbnail()

This class represents the information on a JPEG thumbnail.

JPGObject()

This class represents a JPEG image.

JPGSegment()

This class represents a JPEG segment.

JPGSegmentList()

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 returns False.

IsValid()

Returns True if valid; otherwise returns False.

Attributes:

h

The height of the thumbnail.

offset

The offset of the thumbnail.

size

The size of the thumbnail.

type

The type of thumbnail (e.g., JPEGThumb_ThreePerPixel).

w

The width of the thumbnail.

IsNull()bool
Returns

Returns True if invalid; otherwise returns False.

Return type

bool

See also IsValid().

IsValid()bool
Returns

Returns True if valid; otherwise returns False.

Return type

bool

See also IsNull().

h

The height of the thumbnail.

See also w.

offset

The offset of the thumbnail.

See also size.

size

The size of the thumbnail.

See also offset.

type

The type of thumbnail (e.g., JPEGThumb_ThreePerPixel).

w

The width of the thumbnail.

See also h.

class JPGObject

Bases: Pro.Core.CFFObject

This class represents a JPEG image.

Methods:

GetJFIFThumbnail(offset, size)

Retrieves information about a JFIF thumbnail.

GetStoredSegments()

Returns the list of stored JPEG segments.

LocateSegments()

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

JPEGThumbnail

GetStoredSegments()Pro.JPEG.JPGSegmentList
Returns

Returns the list of stored JPEG segments.

Return type

JPGSegmentList

See also SetStoredSegments(), LocateSegments() and JPGSegment.

LocateSegments()Pro.JPEG.JPGSegmentList

Locates JPEG segments.

Returns

Returns the list of JPEG segments found in the image.

Return type

JPGSegmentList

See also GetStoredSegments(), SetStoredSegments() and JPGSegment.

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() and JPGSegment.

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:

offset

The offset of the segment.

tag

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 position i 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

JPGSegment

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 of value; otherwise returns False.

Return type

bool

See also indexOf() and count().

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() and contains().

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 position i in the list. If i is 0, the value is prepended to the list. If i is size(), 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() and removeAt().

isEmpty()bool

Checks whether the list is empty.

Returns

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

Return type

bool

See also size().

iterator()Pro.JPEG.JPGSegmentListIt

Creates an iterator for the list.

Returns

Returns the iterator.

Return type

JPGSegmentListIt

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.

size()int
Returns

Returns the number of items in the list.

Return type

int

See also isEmpty().

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

JPGSegment

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 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.JPEG.JPGSegment
Returns

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

Return type

JPGSegment

See also hasNext() and previous().

previous()Pro.JPEG.JPGSegment
Returns

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

Return type

JPGSegment

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().