1 /* 2 * Copyright 2023 Google Inc. 3 * 4 * Use of this source code is governed by a BSD-style license that can be 5 * found in the LICENSE file. 6 */ 7 8 #ifndef SkJpegConstants_codec_DEFINED 9 #define SkJpegConstants_codec_DEFINED 10 11 #include <cstdint> 12 13 // The first marker of all JPEG files is StartOfImage. 14 static constexpr uint8_t kJpegMarkerStartOfImage = 0xD8; 15 16 // The last marker of all JPEG files (excluding auxiliary data, e.g, MPF images) is EndOfImage. 17 static constexpr uint8_t kJpegMarkerEndOfImage = 0xD9; 18 19 // The header of a JPEG file is the data in all segments before the first StartOfScan. 20 static constexpr uint8_t kJpegMarkerStartOfScan = 0xDA; 21 22 // Metadata and auxiliary images are stored in the APP1 through APP15 markers. 23 static constexpr uint8_t kJpegMarkerAPP0 = 0xE0; 24 25 // The number of bytes in a marker code is two. The first byte is all marker codes is 0xFF. 26 static constexpr size_t kJpegMarkerCodeSize = 2; 27 28 // The number of bytes used to specify the length of a segment's parameters is two. This length 29 // value includes these two bytes. 30 static constexpr size_t kJpegSegmentParameterLengthSize = 2; 31 32 // The first three bytes of all JPEG files is a StartOfImage marker (two bytes) followed by the 33 // first byte of the next marker. 34 static constexpr uint8_t kJpegSig[] = {0xFF, kJpegMarkerStartOfImage, 0xFF}; 35 36 // ICC profile segment marker and signature. 37 static constexpr uint32_t kICCMarker = kJpegMarkerAPP0 + 2; 38 static constexpr uint32_t kICCMarkerHeaderSize = 14; 39 static constexpr uint32_t kICCMarkerIndexSize = 1; 40 static constexpr uint8_t kICCSig[] = { 41 'I', 'C', 'C', '_', 'P', 'R', 'O', 'F', 'I', 'L', 'E', '\0', 42 }; 43 44 // HDR gainmap segment marker and signature. 45 static constexpr uint32_t kGainmapMarker = kJpegMarkerAPP0 + 15; 46 static constexpr uint32_t kGainmapMarkerIndexSize = 2; 47 static constexpr uint8_t kGainmapSig[] = { 48 'H', 'D', 'R', '_', 'G', 'A', 'I', 'N', '_', 'M', 'A', 'P', '\0', 49 }; 50 51 // XMP segment marker and signature. 52 static constexpr uint32_t kXMPMarker = kJpegMarkerAPP0 + 1; 53 static constexpr uint8_t kXMPStandardSig[] = { 54 'h', 't', 't', 'p', ':', '/', '/', 'n', 's', '.', 'a', 'd', 'o', 'b', 'e', '.', 'c', 'o', 55 'm', '/', 'x', 'a', 'p', '/', '1', '.', '0', '/', '\0'}; 56 static constexpr uint8_t kXMPExtendedSig[] = { 57 'h', 't', 't', 'p', ':', '/', '/', 'n', 's', '.', 'a', 'd', 'o', 'b', 'e', '.', 'c', 'o', 58 'm', '/', 'x', 'm', 'p', '/', 'e', 'x', 't', 'e', 'n', 's', 'i', 'o', 'n', '/', '\0'}; 59 60 // EXIF segment marker and signature. 61 static constexpr uint32_t kExifMarker = kJpegMarkerAPP0 + 1; 62 static constexpr uint32_t kExifHeaderSize = 14; 63 constexpr uint8_t kExifSig[] = {'E', 'x', 'i', 'f', '\0'}; 64 65 // MPF segment marker and signature. 66 static constexpr uint32_t kMpfMarker = kJpegMarkerAPP0 + 2; 67 static constexpr uint8_t kMpfSig[] = {'M', 'P', 'F', '\0'}; 68 69 #endif 70