View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *      http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  package org.apache.commons.imaging.formats.jpeg;
18  
19  import java.util.Arrays;
20  import java.util.Collections;
21  import java.util.List;
22  
23  import org.apache.commons.imaging.common.BinaryConstant;
24  import org.apache.commons.imaging.common.BinaryFunctions;
25  
26  public final class JpegConstants {
27      public static final int MAX_SEGMENT_SIZE = 0xffff;
28  
29      public static final BinaryConstant JFIF0_SIGNATURE = new BinaryConstant(new byte[] { 0x4a, // J
30              0x46, // F
31              0x49, // I
32              0x46, // F
33              0x0, //
34      });
35      public static final BinaryConstant JFIF0_SIGNATURE_ALTERNATIVE = new BinaryConstant(new byte[] { 0x4a, // J
36              0x46, // F
37              0x49, // I
38              0x46, // F
39              0x20, //
40      });
41  
42      public static final BinaryConstant EXIF_IDENTIFIER_CODE = new BinaryConstant(new byte[] { 0x45, // E
43              0x78, // x
44              0x69, // i
45              0x66, // f
46      });
47  
48      public static final BinaryConstant XMP_IDENTIFIER = new BinaryConstant(new byte[] { 0x68, // h
49              0x74, // t
50              0x74, // t
51              0x70, // p
52              0x3A, // :
53              0x2F, // /
54              0x2F, // /
55              0x6E, // n
56              0x73, // s
57              0x2E, // .
58              0x61, // a
59              0x64, // d
60              0x6F, // o
61              0x62, // b
62              0x65, // e
63              0x2E, // .
64              0x63, // c
65              0x6F, // o
66              0x6D, // m
67              0x2F, // /
68              0x78, // x
69              0x61, // a
70              0x70, // p
71              0x2F, // /
72              0x31, // 1
73              0x2E, // .
74              0x30, // 0
75              0x2F, // /
76              0, // 0-terminated us-ascii string.
77      });
78  
79      public static final BinaryConstant SOI = new BinaryConstant(new byte[] { (byte) 0xff, (byte) 0xd8 });
80      public static final BinaryConstant EOI = new BinaryConstant(new byte[] { (byte) 0xff, (byte) 0xd9 });
81  
82      public static final int JPEG_APP0 = 0xE0;
83      public static final int JPEG_APP0_MARKER = 0xff00 | JPEG_APP0;
84      public static final int JPEG_APP1_MARKER = 0xff00 | JPEG_APP0 + 1;
85      public static final int JPEG_APP2_MARKER = 0xff00 | JPEG_APP0 + 2;
86      public static final int JPEG_APP13_MARKER = 0xff00 | JPEG_APP0 + 13;
87      public static final int JPEG_APP14_MARKER = 0xff00 | JPEG_APP0 + 14;
88      public static final int JPEG_APP15_MARKER = 0xff00 | JPEG_APP0 + 15;
89  
90      public static final int JFIF_MARKER = 0xFFE0;
91      public static final int SOF0_MARKER = 0xFFc0;
92      public static final int SOF1_MARKER = 0xFFc0 + 0x1;
93      public static final int SOF2_MARKER = 0xFFc0 + 0x2;
94      public static final int SOF3_MARKER = 0xFFc0 + 0x3;
95      public static final int DHT_MARKER = 0xFFc0 + 0x4;
96      public static final int SOF5_MARKER = 0xFFc0 + 0x5;
97      public static final int SOF6_MARKER = 0xFFc0 + 0x6;
98      public static final int SOF7_MARKER = 0xFFc0 + 0x7;
99      public static final int SOF8_MARKER = 0xFFc0 + 0x8;
100     public static final int SOF9_MARKER = 0xFFc0 + 0x9;
101     public static final int SOF10_MARKER = 0xFFc0 + 0xa;
102     public static final int SOF11_MARKER = 0xFFc0 + 0xb;
103     public static final int DAC_MARKER = 0xFFc0 + 0xc;
104     public static final int SOF13_MARKER = 0xFFc0 + 0xd;
105     public static final int SOF14_MARKER = 0xFFc0 + 0xe;
106     public static final int SOF15_MARKER = 0xFFc0 + 0xf;
107 
108     // marker for restart intervals
109     public static final int DRI_MARKER = 0xFFdd;
110     public static final int RST0_MARKER = 0xFFd0;
111     public static final int RST1_MARKER = 0xFFd0 + 0x1;
112     public static final int RST2_MARKER = 0xFFd0 + 0x2;
113     public static final int RST3_MARKER = 0xFFd0 + 0x3;
114     public static final int RST4_MARKER = 0xFFd0 + 0x4;
115     public static final int RST5_MARKER = 0xFFd0 + 0x5;
116     public static final int RST6_MARKER = 0xFFd0 + 0x6;
117     public static final int RST7_MARKER = 0xFFd0 + 0x7;
118 
119     public static final int EOI_MARKER = 0xFFd9;
120     public static final int SOS_MARKER = 0xFFda;
121     public static final int DQT_MARKER = 0xFFdb;
122     public static final int DNL_MARKER = 0xFFdc;
123     public static final int COM_MARKER = 0xFFfe;
124 
125     public static final List<Integer> MARKERS = Collections.unmodifiableList(
126             Arrays.asList(JPEG_APP0, JPEG_APP0_MARKER, JPEG_APP1_MARKER, JPEG_APP2_MARKER, JPEG_APP13_MARKER, JPEG_APP14_MARKER, JPEG_APP15_MARKER, JFIF_MARKER,
127                     SOF0_MARKER, SOF1_MARKER, SOF2_MARKER, SOF3_MARKER, DHT_MARKER, SOF5_MARKER, SOF6_MARKER, SOF7_MARKER, SOF8_MARKER, SOF9_MARKER,
128                     SOF10_MARKER, SOF11_MARKER, DAC_MARKER, SOF13_MARKER, SOF14_MARKER, SOF15_MARKER, EOI_MARKER, SOS_MARKER, DQT_MARKER, DNL_MARKER,
129                     COM_MARKER, DRI_MARKER, RST0_MARKER, RST1_MARKER, RST2_MARKER, RST3_MARKER, RST4_MARKER, RST5_MARKER, RST6_MARKER, RST7_MARKER));
130 
131     public static final BinaryConstant ICC_PROFILE_LABEL = new BinaryConstant(
132             new byte[] { 0x49, 0x43, 0x43, 0x5F, 0x50, 0x52, 0x4F, 0x46, 0x49, 0x4C, 0x45, 0x0 });
133 
134     public static final BinaryConstant PHOTOSHOP_IDENTIFICATION_STRING = new BinaryConstant(new byte[] { 0x50, // P
135             0x68, // h
136             0x6F, // o
137             0x74, // t
138             0x6F, // o
139             0x73, // s
140             0x68, // h
141             0x6F, // o
142             0x70, // p
143             0x20, //
144             0x33, // 3
145             0x2E, // .
146             0x30, // 0
147             0, });
148     public static final int CONST_8BIM = BinaryFunctions.charsToQuad('8', 'B', 'I', 'M');
149 
150     private JpegConstants() {
151     }
152 }