private IccProfileInfo readIccProfileInfo()

in src/main/java/org/apache/commons/imaging/icc/IccProfileParser.java [141:296]


    private IccProfileInfo readIccProfileInfo(InputStream is) throws IOException {
        final CachingInputStream cis = new CachingInputStream(is);
        is = cis;

        // setDebug(true);

        // if (LOGGER.isLoggable(Level.FINEST))
        // Debug.debug("length: " + length);

        final int profileSize = read4Bytes("ProfileSize", is, "Not a Valid ICC Profile", getByteOrder());

        // if (length != ProfileSize)
        // {
        // // Debug.debug("Unexpected Length data expected: " +
        // Integer.toHexString((int) length)
        // // + ", encoded: " + Integer.toHexString(ProfileSize));
        // // Debug.debug("Unexpected Length data: " + length
        // // + ", length: " + ProfileSize);
        // // throw new Error("asd");
        // return null;
        // }

        final int cmmTypeSignature = read4Bytes("Signature", is, "Not a Valid ICC Profile", getByteOrder());
        if (LOGGER.isLoggable(Level.FINEST)) {
            logCharQuad("CMMTypeSignature", cmmTypeSignature);
        }

        final int profileVersion = read4Bytes("ProfileVersion", is, "Not a Valid ICC Profile", getByteOrder());

        final int profileDeviceClassSignature = read4Bytes("ProfileDeviceClassSignature", is, "Not a Valid ICC Profile",
                getByteOrder());
        if (LOGGER.isLoggable(Level.FINEST)) {
            logCharQuad("ProfileDeviceClassSignature", profileDeviceClassSignature);
        }

        final int colorSpace = read4Bytes("ColorSpace", is, "Not a Valid ICC Profile", getByteOrder());
        if (LOGGER.isLoggable(Level.FINEST)) {
            logCharQuad("ColorSpace", colorSpace);
        }

        final int profileConnectionSpace = read4Bytes("ProfileConnectionSpace", is, "Not a Valid ICC Profile",
                getByteOrder());
        if (LOGGER.isLoggable(Level.FINEST)) {
            logCharQuad("ProfileConnectionSpace", profileConnectionSpace);
        }

        skipBytes(is, 12, "Not a Valid ICC Profile");

        final int profileFileSignature = read4Bytes("ProfileFileSignature", is, "Not a Valid ICC Profile",
                getByteOrder());
        if (LOGGER.isLoggable(Level.FINEST)) {
            logCharQuad("ProfileFileSignature", profileFileSignature);
        }

        final int primaryPlatformSignature = read4Bytes("PrimaryPlatformSignature", is, "Not a Valid ICC Profile",
                getByteOrder());
        if (LOGGER.isLoggable(Level.FINEST)) {
            logCharQuad("PrimaryPlatformSignature", primaryPlatformSignature);
        }

        final int variousFlags = read4Bytes("VariousFlags", is, "Not a Valid ICC Profile", getByteOrder());
        if (LOGGER.isLoggable(Level.FINEST)) {
            logCharQuad("VariousFlags", profileFileSignature);
        }

        final int deviceManufacturer = read4Bytes("DeviceManufacturer", is, "Not a Valid ICC Profile", getByteOrder());
        if (LOGGER.isLoggable(Level.FINEST)) {
            logCharQuad("DeviceManufacturer", deviceManufacturer);
        }

        final int deviceModel = read4Bytes("DeviceModel", is, "Not a Valid ICC Profile", getByteOrder());
        if (LOGGER.isLoggable(Level.FINEST)) {
            logCharQuad("DeviceModel", deviceModel);
        }

        skipBytes(is, 8, "Not a Valid ICC Profile");

        final int renderingIntent = read4Bytes("RenderingIntent", is, "Not a Valid ICC Profile", getByteOrder());
        if (LOGGER.isLoggable(Level.FINEST)) {
            logCharQuad("RenderingIntent", renderingIntent);
        }

        skipBytes(is, 12, "Not a Valid ICC Profile");

        final int profileCreatorSignature = read4Bytes("ProfileCreatorSignature", is, "Not a Valid ICC Profile",
                getByteOrder());
        if (LOGGER.isLoggable(Level.FINEST)) {
            logCharQuad("ProfileCreatorSignature", profileCreatorSignature);
        }

        skipBytes(is, 16, "Not a Valid ICC Profile");
        // readByteArray("ProfileID", 16, is,
        // "Not a Valid ICC Profile");
        // if (LOGGER.isLoggable(Level.FINEST))
        // System.out
        // .println("ProfileID: '" + new String(ProfileID) + "'");

        skipBytes(is, 28, "Not a Valid ICC Profile");

        // this.setDebug(true);

        final int tagCount = read4Bytes("TagCount", is, "Not a Valid ICC Profile", getByteOrder());

        // List tags = new ArrayList();
        final IccTag[] tags = Allocator.array(tagCount, IccTag[]::new, IccTag.SHALLOW_SIZE);

        for (int i = 0; i < tagCount; i++) {
            final int tagSignature = read4Bytes("TagSignature[" + i + "]", is, "Not a Valid ICC Profile",
                    getByteOrder());
            // Debug.debug("TagSignature t "
            // + Integer.toHexString(TagSignature));

            // this.printCharQuad("TagSignature", TagSignature);
            final int offsetToData = read4Bytes("OffsetToData[" + i + "]", is, "Not a Valid ICC Profile",
                    getByteOrder());
            final int elementSize = read4Bytes("ElementSize[" + i + "]", is, "Not a Valid ICC Profile", getByteOrder());

            final IccTagType fIccTagType = getIccTagType(tagSignature);
            // if (fIccTagType == null)
            // throw new Error("oops.");

            // System.out
            // .println("\t["
            // + i
            // + "]: "
            // + ((fIccTagType == null)
            // ? "unknown"
            // : fIccTagType.name));
            // Debug.debug();

            final IccTag tag = new IccTag(tagSignature, offsetToData, elementSize, fIccTagType);
            // tag.dump("\t" + i + ": ");
            tags[i] = tag;
            // tags .add(tag);
        }

        // read stream to end, filling cache.
        IOUtils.consume(is);

        final byte[] data = cis.getCache();

        if (data.length < profileSize) {
            throw new ImagingException("Couldn't read ICC Profile.");
        }

        final IccProfileInfo result = new IccProfileInfo(data, profileSize, cmmTypeSignature, profileVersion,
                profileDeviceClassSignature, colorSpace, profileConnectionSpace, profileFileSignature,
                primaryPlatformSignature, variousFlags, deviceManufacturer, deviceModel, renderingIntent,
                profileCreatorSignature, null, tags);

        if (LOGGER.isLoggable(Level.FINEST)) {
            LOGGER.finest("issRGB: " + result.isSrgb());
        }

        return result;
    }