loci.formats.services

## Class JPEGTurboServiceImpl

- java.lang.Object
- - loci.formats.services.JPEGTurboServiceImpl

- All Implemented Interfaces:
    loci.common.services.Service, JPEGTurboService

      public class JPEGTurboServiceImpl
      extends java.lang.Object
      implements JPEGTurboService

  Based upon the NDPI to OME-TIFF converter by Matthias Baldauf: http://matthias-baldauf.at/software/ndpi_converter/
  Author:
    Melissa Linkert

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `private static int` | `DRI`
    `private static int` | `EOI`
    `private byte[]` | `header`
    `private long` | `imageDimensions`
    `private int` | `imageHeight`
    `private int` | `imageWidth`
    `private loci.common.RandomAccessInputStream` | `in`
    `private static boolean` | `libraryLoaded`
    `private java.util.logging.Logger` | `logger`
    `private static org.slf4j.Logger` | `LOGGER`
    `private int` | `mcuHeight`
    `private int` | `mcuWidth`
    `private static java.lang.String` | `NATIVE_LIB_CLASS`
    `private long` | `offset`
    `private int` | `restartInterval`
    `private java.util.ArrayList<java.lang.Long>` | `restartMarkers`
    `private static int` | `RST0`
    `private static int` | `RST7`
    `private static int` | `SOF0`
    `private long` | `sos`
    `private static int` | `SOS`
    `private int` | `tileHeight`
    `private int` | `tileWidth`
    `private int` | `xTiles`
    `private int` | `yTiles`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `JPEGTurboServiceImpl()`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `close()` Free resources associated with the initialized stream.
    `byte[]` | `getCompressedTile(byte[] data, int tileX, int tileY)` Similar to getTile(int, int), but returns the JPEG-compressed bytes.
    `byte[]` | `getCompressedTile(int tileX, int tileY)` Similar to getTile(int, int), but returns the JPEG-compressed bytes.
    `private byte[]` | `getFixedHeader()`
    `long[]` | `getRestartMarkers()`
    `byte[]` | `getTile(byte[] buf, int xCoordinate, int yCoordinate, int width, int height)` Get the uncompressed bytes representing the given bounding box.
    `byte[]` | `getTile(int tileX, int tileY)` Get the uncompressed bytes representing the given tile index.
    `int` | `getTileColumns()`
    `int` | `getTileHeight()`
    `int` | `getTileRows()`
    `int` | `getTileWidth()`
    `void` | `initialize(loci.common.RandomAccessInputStream jpeg, int width, int height)` Initialize the given stream, which represents an image of the given width and height.
    `boolean` | `isLibraryLoaded()`
    `private void` | `parseSOF()`
    `void` | `setRestartMarkers(long[] markers)`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### LOGGER

          private static final org.slf4j.Logger LOGGER

    - #### NATIVE_LIB_CLASS

          private static final java.lang.String NATIVE_LIB_CLASS

      See Also:
        Constant Field Values

    - #### SOF0

          private static final int SOF0

      See Also:
        Constant Field Values

    - #### DRI

          private static final int DRI

      See Also:
        Constant Field Values

    - #### SOS

          private static final int SOS

      See Also:
        Constant Field Values

    - #### RST0

          private static final int RST0

      See Also:
        Constant Field Values

    - #### RST7

          private static final int RST7

      See Also:
        Constant Field Values

    - #### EOI

          private static final int EOI

      See Also:
        Constant Field Values

    - #### logger

          private transient java.util.logging.Logger logger

    - #### imageWidth

          private int imageWidth

    - #### imageHeight

          private int imageHeight

    - #### offset

          private long offset

    - #### in

          private loci.common.RandomAccessInputStream in

    - #### restartInterval

          private int restartInterval

    - #### sos

          private long sos

    - #### imageDimensions

          private long imageDimensions

    - #### mcuWidth

          private int mcuWidth

    - #### mcuHeight

          private int mcuHeight

    - #### tileWidth

          private int tileWidth

    - #### tileHeight

          private int tileHeight

    - #### xTiles

          private int xTiles

    - #### yTiles

          private int yTiles

    - #### restartMarkers

          private java.util.ArrayList<java.lang.Long> restartMarkers

    - #### header

          private byte[] header

    - #### libraryLoaded

          private static boolean libraryLoaded

  - ### Constructor Detail

    - #### JPEGTurboServiceImpl

          public JPEGTurboServiceImpl()

  - ### Method Detail

    - #### setRestartMarkers

          public void setRestartMarkers(long[] markers)

      Specified by:
        `setRestartMarkers` in interface `JPEGTurboService`
      Parameters:
        `markers` - precalculated restart markers associated with the current JPEG stream

    - #### getRestartMarkers

          public long[] getRestartMarkers()

      Specified by:
        `getRestartMarkers` in interface `JPEGTurboService`
      Returns:
        the restart markers associated with the current JPEG stream

    - #### initialize

          public void initialize(loci.common.RandomAccessInputStream jpeg,
                                 int width,
                                 int height)
                          throws loci.common.services.ServiceException,
                                 java.io.IOException

      Description copied from interface: `JPEGTurboService`
      Initialize the given stream, which represents an image of the given width and height. This service is primarily intended for very large JPEG images whose width and/or height exceed 65535 (the maximum that can be recorded in a JPEG stream).
      Specified by:
        `initialize` in interface `JPEGTurboService`
      Parameters:
        `jpeg` - open stream containing JPEG data
        `width` - total image width
        `height` - total image height
      Throws:
        `loci.common.services.ServiceException`
        `java.io.IOException`

    - #### getTileWidth

          public int getTileWidth()

      Specified by:
        `getTileWidth` in interface `JPEGTurboService`
      Returns:
        the width (in pixels) of a tile

    - #### getTileHeight

          public int getTileHeight()

      Specified by:
        `getTileHeight` in interface `JPEGTurboService`
      Returns:
        the height (in pixels) of a tile

    - #### getTileRows

          public int getTileRows()

      Specified by:
        `getTileRows` in interface `JPEGTurboService`
      Returns:
        the number of rows of tiles

    - #### getTileColumns

          public int getTileColumns()

      Specified by:
        `getTileColumns` in interface `JPEGTurboService`
      Returns:
        the number of columns of tiles

    - #### getTile

          public byte[] getTile(byte[] buf,
                                int xCoordinate,
                                int yCoordinate,
                                int width,
                                int height)
                         throws java.io.IOException

      Description copied from interface: `JPEGTurboService`
      Get the uncompressed bytes representing the given bounding box.
      Specified by:
        `getTile` in interface `JPEGTurboService`
      Parameters:
        `buf` - array in which to store uncompressed bytes
        `xCoordinate` - upper-left X coordinate of bounding box
        `yCoordinate` - upper-left Y coordinate of bounding box
        `width` - width of bounding box
        `height` - height of bounding box
      Returns:
        uncompressed bytes
      Throws:
        `java.io.IOException`

    - #### getTile

          public byte[] getTile(int tileX,
                                int tileY)
                         throws java.io.IOException

      Description copied from interface: `JPEGTurboService`
      Get the uncompressed bytes representing the given tile index.
      Specified by:
        `getTile` in interface `JPEGTurboService`
      Parameters:
        `tileX` - column index of the tile
        `tileY` - row index of the tile
      Returns:
        uncompressed bytes
      Throws:
        `java.io.IOException`

    - #### getCompressedTile

          public byte[] getCompressedTile(int tileX,
                                          int tileY)
                                   throws java.io.IOException

      Description copied from interface: `JPEGTurboService`
      Similar to getTile(int, int), but returns the JPEG-compressed bytes.
      Specified by:
        `getCompressedTile` in interface `JPEGTurboService`
      Parameters:
        `tileX` - column index of the tile
        `tileY` - row index of the tile
      Returns:
        JPEG-compressed bytes
      Throws:
        `java.io.IOException`

    - #### getCompressedTile

          public byte[] getCompressedTile(byte[] data,
                                          int tileX,
                                          int tileY)
                                   throws java.io.IOException

      Description copied from interface: `JPEGTurboService`
      Similar to getTile(int, int), but returns the JPEG-compressed bytes.
      Specified by:
        `getCompressedTile` in interface `JPEGTurboService`
      Parameters:
        `data` - preallocated array for storing tile
        `tileX` - column index of the tile
        `tileY` - row index of the tile
      Returns:
        JPEG-compressed bytes
      Throws:
        `java.io.IOException`

    - #### close

          public void close()
                     throws java.io.IOException

      Description copied from interface: `JPEGTurboService`
      Free resources associated with the initialized stream.
      Specified by:
        `close` in interface `JPEGTurboService`
      Throws:
        `java.io.IOException`

    - #### isLibraryLoaded

          public boolean isLibraryLoaded()

      Specified by:
        `isLibraryLoaded` in interface `JPEGTurboService`
      Returns:
        true if the underlying native library was successfully loaded

    - #### getFixedHeader

          private byte[] getFixedHeader()
                                 throws java.io.IOException

      Throws:
        `java.io.IOException`

    - #### parseSOF

          private void parseSOF()
                         throws java.io.IOException

      Throws:
        `java.io.IOException`

Copyright © 2026 Open Microscopy Environment