xref: /aosp_15_r20/external/skia/src/codec/SkJpegConstants.h (revision c8dee2aa9b3f27cf6c858bd81872bdeb2c07ed17)
1 /*
2  * Copyright 2023 Google LLC
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 <cstddef>
12 #include <cstdint>
13 
14 // The first marker of all JPEG files is StartOfImage.
15 static constexpr uint8_t kJpegMarkerStartOfImage = 0xD8;
16 
17 // The last marker of all JPEG files (excluding auxiliary data, e.g, MPF images) is EndOfImage.
18 static constexpr uint8_t kJpegMarkerEndOfImage = 0xD9;
19 
20 // The header of a JPEG file is the data in all segments before the first StartOfScan.
21 static constexpr uint8_t kJpegMarkerStartOfScan = 0xDA;
22 
23 // Metadata and auxiliary images are stored in the APP1 through APP15 markers.
24 static constexpr uint8_t kJpegMarkerAPP0 = 0xE0;
25 
26 // The number of bytes in a marker code is two. The first byte is all marker codes is 0xFF.
27 static constexpr size_t kJpegMarkerCodeSize = 2;
28 
29 // The number of bytes used to specify the length of a segment's parameters is two. This length
30 // value includes these two bytes.
31 static constexpr size_t kJpegSegmentParameterLengthSize = 2;
32 
33 // The first three bytes of all JPEG files is a StartOfImage marker (two bytes) followed by the
34 // first byte of the next marker.
35 static constexpr uint8_t kJpegSig[] = {0xFF, kJpegMarkerStartOfImage, 0xFF};
36 
37 // ICC profile segment marker and signature.
38 static constexpr uint32_t kICCMarker = kJpegMarkerAPP0 + 2;
39 static constexpr uint32_t kICCMarkerHeaderSize = 14;
40 static constexpr uint32_t kICCMarkerIndexSize = 1;
41 static constexpr uint8_t kICCSig[] = {
42         'I', 'C', 'C', '_', 'P', 'R', 'O', 'F', 'I', 'L', 'E', '\0',
43 };
44 
45 // XMP segment marker and signature.
46 static constexpr uint32_t kXMPMarker = kJpegMarkerAPP0 + 1;
47 static constexpr uint8_t kXMPStandardSig[] = {
48         'h', 't', 't', 'p', ':', '/', '/', 'n', 's', '.', 'a', 'd', 'o', 'b', 'e', '.', 'c', 'o',
49         'm', '/', 'x', 'a', 'p', '/', '1', '.', '0', '/', '\0'};
50 static constexpr uint8_t kXMPExtendedSig[] = {
51         'h', 't', 't', 'p', ':', '/', '/', 'n', 's', '.', 'a', 'd', 'o', 'b', 'e', '.', 'c', 'o',
52         'm', '/', 'x', 'm', 'p', '/', 'e', 'x', 't', 'e', 'n', 's', 'i', 'o', 'n', '/', '\0'};
53 
54 // EXIF segment marker and signature.
55 static constexpr uint32_t kExifMarker = kJpegMarkerAPP0 + 1;
56 constexpr uint8_t kExifSig[] = {'E', 'x', 'i', 'f', '\0'};
57 
58 // MPF segment marker and signature.
59 static constexpr uint32_t kMpfMarker = kJpegMarkerAPP0 + 2;
60 static constexpr uint8_t kMpfSig[] = {'M', 'P', 'F', '\0'};
61 
62 // ISO 21496-1 marker and signature.
63 static constexpr uint32_t kISOGainmapMarker = kJpegMarkerAPP0 + 2;
64 static constexpr uint8_t kISOGainmapSig[] = {'u', 'r', 'n', ':', 'i', 's', 'o', ':', 's', 't',
65                                              'd', ':', 'i', 's', 'o', ':', 't', 's', ':', '2',
66                                              '1', '4', '9', '6', ':', '-', '1', '\0'};
67 
68 #endif
69