    001/*
    002 * Licensed to the Apache Software Foundation (ASF) under one or more
    003 * contributor license agreements.  See the NOTICE file distributed with
    004 * this work for additional information regarding copyright ownership.
    005 * The ASF licenses this file to You under the Apache License, Version 2.0
    006 * (the "License"); you may not use this file except in compliance with
    007 * the License.  You may obtain a copy of the License at
    008 *
    009 *      http://www.apache.org/licenses/LICENSE-2.0
    010 *
    011 * Unless required by applicable law or agreed to in writing, software
    012 * distributed under the License is distributed on an "AS IS" BASIS,
    013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    014 * See the License for the specific language governing permissions and
    015 * limitations under the License.
    016 */
    017package org.apache.commons.imaging.formats.jpeg;
    018
    019import java.util.Arrays;
    020import java.util.Collections;
    021import java.util.List;
    022
    023import org.apache.commons.imaging.common.BinaryConstant;
    024import org.apache.commons.imaging.common.BinaryFunctions;
    025
    026public final class JpegConstants {
    027    public static final int MAX_SEGMENT_SIZE = 0xffff;
    028
    029    public static final BinaryConstant JFIF0_SIGNATURE = new BinaryConstant(
    030            new byte[] { 0x4a, // J
    031                    0x46, // F
    032                    0x49, // I
    033                    0x46, // F
    034                    0x0, //
    035            });
    036    public static final BinaryConstant JFIF0_SIGNATURE_ALTERNATIVE = new BinaryConstant(
    037            new byte[] { 0x4a, // J
    038                    0x46, // F
    039                    0x49, // I
    040                    0x46, // F
    041                    0x20, //
    042            });
    043
    044    public static final BinaryConstant EXIF_IDENTIFIER_CODE = new BinaryConstant(
    045            new byte[] { 0x45, // E
    046                    0x78, // x
    047                    0x69, // i
    048                    0x66, // f
    049            });
    050
    051    public static final BinaryConstant XMP_IDENTIFIER = new BinaryConstant(
    052            new byte[] { 0x68, // h
    053                    0x74, // t
    054                    0x74, // t
    055                    0x70, // p
    056                    0x3A, // :
    057                    0x2F, // /
    058                    0x2F, // /
    059                    0x6E, // n
    060                    0x73, // s
    061                    0x2E, // .
    062                    0x61, // a
    063                    0x64, // d
    064                    0x6F, // o
    065                    0x62, // b
    066                    0x65, // e
    067                    0x2E, // .
    068                    0x63, // c
    069                    0x6F, // o
    070                    0x6D, // m
    071                    0x2F, // /
    072                    0x78, // x
    073                    0x61, // a
    074                    0x70, // p
    075                    0x2F, // /
    076                    0x31, // 1
    077                    0x2E, // .
    078                    0x30, // 0
    079                    0x2F, // /
    080                    0, // 0-terminated us-ascii string.
    081            });
    082
    083    public static final BinaryConstant SOI = new BinaryConstant(new byte[] {
    084            (byte) 0xff, (byte) 0xd8 });
    085    public static final BinaryConstant EOI = new BinaryConstant(new byte[] {
    086            (byte) 0xff, (byte) 0xd9 });
    087
    088    public static final int JPEG_APP0 = 0xE0;
    089    public static final int JPEG_APP0_MARKER = (0xff00) | (JPEG_APP0);
    090    public static final int JPEG_APP1_MARKER = (0xff00) | (JPEG_APP0 + 1);
    091    public static final int JPEG_APP2_MARKER = (0xff00) | (JPEG_APP0 + 2);
    092    public static final int JPEG_APP13_MARKER = (0xff00) | (JPEG_APP0 + 13);
    093    public static final int JPEG_APP14_MARKER = (0xff00) | (JPEG_APP0 + 14);
    094    public static final int JPEG_APP15_MARKER = (0xff00) | (JPEG_APP0 + 15);
    095
    096    public static final int JFIF_MARKER = 0xFFE0;
    097    public static final int SOF0_MARKER = 0xFFc0;
    098    public static final int SOF1_MARKER = 0xFFc0 + 0x1;
    099    public static final int SOF2_MARKER = 0xFFc0 + 0x2;
    100    public static final int SOF3_MARKER = 0xFFc0 + 0x3;
    101    public static final int DHT_MARKER = 0xFFc0 + 0x4;
    102    public static final int SOF5_MARKER = 0xFFc0 + 0x5;
    103    public static final int SOF6_MARKER = 0xFFc0 + 0x6;
    104    public static final int SOF7_MARKER = 0xFFc0 + 0x7;
    105    public static final int SOF8_MARKER = 0xFFc0 + 0x8;
    106    public static final int SOF9_MARKER = 0xFFc0 + 0x9;
    107    public static final int SOF10_MARKER = 0xFFc0 + 0xa;
    108    public static final int SOF11_MARKER = 0xFFc0 + 0xb;
    109    public static final int DAC_MARKER = 0xFFc0 + 0xc;
    110    public static final int SOF13_MARKER = 0xFFc0 + 0xd;
    111    public static final int SOF14_MARKER = 0xFFc0 + 0xe;
    112    public static final int SOF15_MARKER = 0xFFc0 + 0xf;
    113
    114    // marker for restart intervals
    115    public static final int DRI_MARKER = 0xFFdd;
    116    public static final int RST0_MARKER = 0xFFd0;
    117    public static final int RST1_MARKER = 0xFFd0 + 0x1;
    118    public static final int RST2_MARKER = 0xFFd0 + 0x2;
    119    public static final int RST3_MARKER = 0xFFd0 + 0x3;
    120    public static final int RST4_MARKER = 0xFFd0 + 0x4;
    121    public static final int RST5_MARKER = 0xFFd0 + 0x5;
    122    public static final int RST6_MARKER = 0xFFd0 + 0x6;
    123    public static final int RST7_MARKER = 0xFFd0 + 0x7;
    124
    125    public static final int EOI_MARKER = 0xFFd9;
    126    public static final int SOS_MARKER = 0xFFda;
    127    public static final int DQT_MARKER = 0xFFdb;
    128    public static final int DNL_MARKER = 0xFFdc;
    129    public static final int COM_MARKER = 0xFFfe;
    130
    131    public static final List<Integer> MARKERS = Collections.unmodifiableList(Arrays.asList(
    132            JPEG_APP0, JPEG_APP0_MARKER,
    133            JPEG_APP1_MARKER, JPEG_APP2_MARKER, JPEG_APP13_MARKER,
    134            JPEG_APP14_MARKER, JPEG_APP15_MARKER, JFIF_MARKER,
    135            SOF0_MARKER, SOF1_MARKER, SOF2_MARKER, SOF3_MARKER, DHT_MARKER,
    136            SOF5_MARKER, SOF6_MARKER, SOF7_MARKER, SOF8_MARKER, SOF9_MARKER,
    137            SOF10_MARKER, SOF11_MARKER, DAC_MARKER, SOF13_MARKER,
    138            SOF14_MARKER, SOF15_MARKER, EOI_MARKER, SOS_MARKER, DQT_MARKER,
    139            DNL_MARKER, COM_MARKER, DRI_MARKER, RST0_MARKER, RST1_MARKER, RST2_MARKER,
    140            RST3_MARKER, RST4_MARKER, RST5_MARKER, RST6_MARKER, RST7_MARKER ));
    141
    142    public static final BinaryConstant ICC_PROFILE_LABEL = new BinaryConstant(
    143            new byte[] { 0x49, 0x43, 0x43, 0x5F, 0x50, 0x52, 0x4F, 0x46, 0x49,
    144                    0x4C, 0x45, 0x0 });
    145
    146    public static final BinaryConstant PHOTOSHOP_IDENTIFICATION_STRING = new BinaryConstant(
    147            new byte[] { 0x50, // P
    148                    0x68, // h
    149                    0x6F, // o
    150                    0x74, // t
    151                    0x6F, // o
    152                    0x73, // s
    153                    0x68, // h
    154                    0x6F, // o
    155                    0x70, // p
    156                    0x20, //
    157                    0x33, // 3
    158                    0x2E, // .
    159                    0x30, // 0
    160                    0, });
    161    public static final int CONST_8BIM = BinaryFunctions.charsToQuad('8', 'B', 'I', 'M');
    162
    163    private JpegConstants() {
    164    }
    165}