public ImageInfo getImageInfo()

in src/main/java/org/apache/commons/imaging/formats/webp/WebPImageParser.java [224:293]


    public ImageInfo getImageInfo(final ByteSource byteSource, final WebPImagingParameters params) throws ImagingException, IOException {
        try (ChunksReader reader = new ChunksReader(byteSource, WebPChunkType.VP8, WebPChunkType.VP8L, WebPChunkType.VP8X, WebPChunkType.ANMF)) {
            final String formatDetails;
            final int width;
            final int height;
            int numberOfImages;
            boolean hasAlpha = false;
            ImageInfo.ColorType colorType = ImageInfo.ColorType.RGB;

            AbstractWebPChunk chunk = reader.readChunk();
            if (chunk instanceof WebPChunkVp8) {
                formatDetails = "WebP/Lossy";
                numberOfImages = 1;

                final WebPChunkVp8 vp8 = (WebPChunkVp8) chunk;
                width = vp8.getWidth();
                height = vp8.getHeight();
                colorType = ImageInfo.ColorType.YCbCr;
            } else if (chunk instanceof WebPChunkVp8l) {
                formatDetails = "WebP/Lossless";
                numberOfImages = 1;

                final WebPChunkVp8l vp8l = (WebPChunkVp8l) chunk;
                width = vp8l.getImageWidth();
                height = vp8l.getImageHeight();
            } else if (chunk instanceof WebPChunkVp8x) {
                final WebPChunkVp8x vp8x = (WebPChunkVp8x) chunk;
                width = vp8x.getCanvasWidth();
                height = vp8x.getCanvasHeight();
                hasAlpha = ((WebPChunkVp8x) chunk).hasAlpha();

                if (vp8x.hasAnimation()) {
                    formatDetails = "WebP/Animation";

                    numberOfImages = 0;
                    while ((chunk = reader.readChunk()) != null) {
                        if (chunk.getType() == WebPChunkType.ANMF.value) {
                            numberOfImages++;
                        }
                    }

                } else {
                    numberOfImages = 1;
                    chunk = reader.readChunk();

                    if (chunk == null) {
                        throw new ImagingException("Image has no content");
                    }

                    if (chunk.getType() == WebPChunkType.ANMF.value) {
                        throw new ImagingException("Non animated image should not contain ANMF chunks");
                    }

                    if (chunk.getType() == WebPChunkType.VP8.value) {
                        formatDetails = "WebP/Lossy (Extended)";
                        colorType = ImageInfo.ColorType.YCbCr;
                    } else if (chunk.getType() == WebPChunkType.VP8L.value) {
                        formatDetails = "WebP/Lossless (Extended)";
                    } else {
                        throw new ImagingException("Unknown WebP chunk type: " + chunk);
                    }
                }
            } else {
                throw new ImagingException("Unknown WebP chunk type: " + chunk);
            }

            return new ImageInfo(formatDetails, 32, new ArrayList<>(), ImageFormats.WEBP, "webp", height, "image/webp", numberOfImages, -1, -1, -1, -1, width,
                    false, hasAlpha, false, colorType, ImageInfo.CompressionAlgorithm.UNKNOWN);
        }
    }