JPEG -- JPEG JFIF File Format

The JPEG JFIF format is supported for reading, and batch writing, but not update in place. JPEG files are represented as one band (greyscale) or three band (RGB) datasets with Byte valued bands.

The driver will automatically convert images whose color space is YCbCr, CMYK or YCbCrK to RGB, unless GDAL_JPEG_TO_RGB is set to NO (YES is the default). When color space translation to RGB is done, the source color space is indicated in the SOURCE_COLOR_SPACE metadata of the IMAGE_STRUCTURE domain.

EXIF metadata can be read from JPEG files (but this will not result in a georeferenced image even if the EXIF_GPSLatitude and EXIF_GPSLongitude tags are set). But if an ESRI world file exists with the .jgw, .jpgw/.jpegw or .wld suffixes, it will be read and used to establish the geotransform for the image. If available a MapInfo .tab file will also be used for georeferencing. Overviews can be built for JPEG files as an external .ovr file.

The driver also supports the "zlib compressed mask appended to the file" approach used by a few data providers to add a bitmask to identify pixels that are not valid data. See RFC 15 for further details.

Starting with GDAL 1.10.1, the driver can deal with bitmask where the bits are ordered with most significant bit first (whereas the usual convention is least significant bit first). The driver will try to autodetect that situation, but the heuristics may fail. In that circumstance, you can set the JPEG_MASK_BIT_ORDER configuration option to MSB. Bitmask can also be completely ignored by specifying JPEG_READ_MASK to NO.

The GDAL JPEG Driver is built using the Independent JPEG Group's jpeg library. Also note that the GeoTIFF driver supports tiled TIFF with JPEG compressed tiles.

To be able to read and write JPEG images with 12-bit sample, you can build GDAL with its internal libjpeg (based on IJG libjpeg-6b, with additional changes for 12-bit sample support), or explicitly pass --with-jpeg12=yes to configure script when building with external libjpeg. See "8 and 12 bit JPEG in TIFF" wiki page for more details.

It is also possible to use the JPEG driver with the libjpeg-turbo, a version of libjpeg, API and ABI compatible with IJG libjpeg-6b, which uses MMX, SSE, and SSE2 SIMD instructions to accelerate baseline JPEG compression/decompression.

Starting with GDAL 1.9.0, XMP metadata can be extracted from the file, and will be stored as XML raw content in the xml:XMP metadata domain.

Starting with GDAL 2.0, embedded EXIF thumbnails (with JPEG compression) can be used as overviews, and generated by GDAL.

Color Profile Metadata

Starting with GDAL 1.11, GDAL can deal with the following color profile metadata in the COLOR_PROFILE domain:

Note that this metadata property can only be used on the original raw pixel data. If automatic conversion to RGB has been done, the color profile information cannot be used.

This metadata tag can be used as creation options.

Error management

While decoding, libjpeg has resiliency towards some errors in the JPEG datastream and will try to recover from them as much of possible. Starting with GDAL 1.11.2, such errors will be reported as GDAL Warnings, but can optionally be considered as true Errors by setting the GDAL_ERROR_ON_LIBJPEG_WARNING configuration option to TRUE.

Creation Options

JPEG files are created using the "JPEG" driver code. Only Byte band types are supported, and only 1 and 3 band (RGB) configurations. JPEG file creation is implemented by the batch (CreateCopy) method. YCbCr, CMYK or YCbCrK colorspaces are not supported in creation. If the source dataset has a nodata mask, it will be appended as a zlib compressed mask to the JPEG file.

EXIF and GPS tags

The below tables list the EXIF and GPS tags that can be written.

Many items have more restrictions on the valid content that are not expressed in the below tables. Consult the EXIF specification for more information.

Metadata item nameHex codeTypeNumber of valuesOptionality
EXIF_Document_Name0x010DASCIIvariableOptional
EXIF_ImageDescription0x010EASCIIvariableRecommended
EXIF_Make0x010FASCIIvariableRecommended
EXIF_Model0x0110ASCIIvariableRecommended
EXIF_Orientation0x0112SHORT1Recommended
EXIF_XResolution0x011ARATIONAL1Mandatory
EXIF_YResolution0x011BRATIONAL1Mandatory
EXIF_ResolutionUnit0x0128SHORT1Mandatory
EXIF_TransferFunction0x012DSHORT768Optional
EXIF_Software0x0131ASCIIvariableOptional
EXIF_DateTime0x0132ASCII20Recommended
EXIF_Artist0x013BASCIIvariableOptional
EXIF_WhitePoint0x013ERATIONAL2Optional
EXIF_PrimaryChromaticities0x013FRATIONAL6Optional
EXIF_YCbCrCoefficients0x0211RATIONAL3Optional
EXIF_YCbCrPositioning0x0213SHORT1Mandatory
EXIF_ReferenceBlackWhite0x0214RATIONAL6Optional
EXIF_Copyright0x8298ASCIIvariableOptional
EXIF_ExposureTime0x829ARATIONAL1Recommended
EXIF_FNumber0x829DRATIONAL1Optional
EXIF_ExposureProgram0x8822SHORT1Optional
EXIF_SpectralSensitivity0x8824ASCIIvariableOptional
EXIF_ISOSpeedRatings0x8827SHORTvariableOptional
EXIF_OECF0x8828UNDEFINEDvariableOptional
EXIF_SensitivityType0x8830SHORT1Optional
EXIF_StandardOutputSensitivity0x8831LONG1Optional
EXIF_RecommendedExposureIndex0x8832LONG1Optional
EXIF_ISOSpeed0x8833LONG1Optional
EXIF_ISOSpeedLatitudeyyy0x8834LONG1Optional
EXIF_ISOSpeedLatitudezzz0x8835LONG1Optional
EXIF_ExifVersion0x9000UNDEFINED4Mandatory
EXIF_DateTimeOriginal0x9003ASCII20Optional
EXIF_DateTimeDigitized0x9004ASCII20Optional
EXIF_OffsetTime0x9010ASCII7Optional
EXIF_OffsetTimeOriginal0x9011ASCII7Optional
EXIF_OffsetTimeDigitized0x9012ASCII7Optional
EXIF_ComponentsConfiguration0x9101UNDEFINED4Mandatory
EXIF_CompressedBitsPerPixel0x9102RATIONAL1Optional
EXIF_ShutterSpeedValue0x9201SRATIONAL1Optional
EXIF_ApertureValue0x9202RATIONAL1Optional
EXIF_BrightnessValue0x9203SRATIONAL1Optional
EXIF_ExposureBiasValue0x9204SRATIONAL1Optional
EXIF_MaxApertureValue0x9205RATIONAL1Optional
EXIF_SubjectDistance0x9206RATIONAL1Optional
EXIF_MeteringMode0x9207SHORT1Optional
EXIF_LightSource0x9208SHORT1Optional
EXIF_Flash0x9209SHORT1Recommended
EXIF_FocalLength0x920ARATIONAL1Optional
EXIF_SubjectArea0x9214SHORTvariableOptional
EXIF_MakerNote0x927CUNDEFINEDvariableOptional
EXIF_UserComment0x9286UNDEFINEDvariableOptional
EXIF_SubSecTime0x9290ASCIIvariableOptional
EXIF_SubSecTime_Original0x9291ASCIIvariableOptional
EXIF_SubSecTime_Digitized0x9292ASCIIvariableOptional
EXIF_FlashpixVersion0xA000UNDEFINED4Mandatory
EXIF_ColorSpace0xA001SHORT1Mandatory
EXIF_PixelXDimension0xA002LONG1Mandatory
EXIF_PixelYDimension0xA003LONG1Mandatory
EXIF_RelatedSoundFile0xA004ASCII13Optional
EXIF_FlashEnergy0xA20BRATIONAL1Optional
EXIF_SpatialFrequencyResponse0xA20CUNDEFINEDvariableOptional
EXIF_FocalPlaneXResolution0xA20ERATIONAL1Optional
EXIF_FocalPlaneYResolution0xA20FRATIONAL1Optional
EXIF_FocalPlaneResolutionUnit0xA210SHORT1Optional
EXIF_SubjectLocation0xA214SHORT2Optional
EXIF_ExposureIndex0xA215RATIONAL1Optional
EXIF_SensingMethod0xA217SHORT1Optional
EXIF_FileSource0xA300UNDEFINED1Optional
EXIF_SceneType0xA301UNDEFINED1Optional
EXIF_CFAPattern0xA302UNDEFINEDvariableOptional
EXIF_CustomRendered0xA401SHORT1Optional
EXIF_ExposureMode0xA402SHORT1Recommended
EXIF_WhiteBalance0xA403SHORT1Recommended
EXIF_DigitalZoomRatio0xA404RATIONAL1Optional
EXIF_FocalLengthIn35mmFilm0xA405SHORT1Optional
EXIF_SceneCaptureType0xA406SHORT1Recommended
EXIF_GainControl0xA407RATIONAL1Optional
EXIF_Contrast0xA408SHORT1Optional
EXIF_Saturation0xA409SHORT1Optional
EXIF_Sharpness0xA40ASHORT1Optional
EXIF_DeviceSettingDescription0xA40BUNDEFINEDvariableOptional
EXIF_SubjectDistanceRange0xA40CSHORT1Optional
EXIF_ImageUniqueID0xA420ASCII33Optional
EXIF_CameraOwnerName0xA430ASCIIvariableOptional
EXIF_BodySerialNumber0xA431ASCIIvariableOptional
EXIF_LensSpecification0xA432RATIONAL4Optional
EXIF_LensMake0xA433ASCIIvariableOptional
EXIF_LensModel0xA434ASCIIvariableOptional
EXIF_LensSerialNumber0xA435ASCIIvariableOptional

GPS tags:

Metadata item nameHex codeTypeNumber of valuesOptionality
EXIF_GPSVersionID0x0000BYTE4Optional
EXIF_GPSLatitudeRef0x0001ASCII2Optional
EXIF_GPSLatitude0x0002RATIONAL3Optional
EXIF_GPSLongitudeRef0x0003ASCII2Optional
EXIF_GPSLongitude0x0004RATIONAL3Optional
EXIF_GPSAltitudeRef0x0005BYTE1Optional
EXIF_GPSAltitude0x0006RATIONAL1Optional
EXIF_GPSTimeStamp0x0007RATIONAL3Optional
EXIF_GPSSatellites0x0008ASCIIvariableOptional
EXIF_GPSStatus0x0009ASCII2Optional
EXIF_GPSMeasureMode0x000AASCII2Optional
EXIF_GPSDOP0x000BRATIONAL1Optional
EXIF_GPSSpeedRef0x000CASCII2Optional
EXIF_GPSSpeed0x000DRATIONAL1Optional
EXIF_GPSTrackRef0x000EASCII2Optional
EXIF_GPSTrack0x000FRATIONAL1Optional
EXIF_GPSImgDirectionRef0x0010ASCII2Optional
EXIF_GPSImgDirection0x0011RATIONAL1Optional
EXIF_GPSMapDatum0x0012ASCIIvariableOptional
EXIF_GPSDestLatitudeRef0x0013ASCII2Optional
EXIF_GPSDestLatitude0x0014RATIONAL3Optional
EXIF_GPSDestLongitudeRef0x0015ASCII2Optional
EXIF_GPSDestLongitude0x0016RATIONAL3Optional
EXIF_GPSDestBearingRef0x0017ASCII2Optional
EXIF_GPSDestBearing0x0018RATIONAL1Optional
EXIF_GPSDestDistanceRef0x0019ASCII2Optional
EXIF_GPSDestDistance0x001ARATIONAL1Optional
EXIF_GPSProcessingMethod0x001BUNDEFINEDvariableOptional
EXIF_GPSAreaInformation0x001CUNDEFINEDvariableOptional
EXIF_GPSDateStamp0x001DASCII11Optional
EXIF_GPSDifferential0x001ESHORT1Optional
EXIF_GPSHPositioningError0x001FRATIONAL1Optional

See Also: