[
https://issues.apache.org/jira/browse/IMAGING-339?focusedWorklogId=838958&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-838958
]
ASF GitHub Bot logged work on IMAGING-339:
------------------------------------------
Author: ASF GitHub Bot
Created on: 12/Jan/23 21:15
Start Date: 12/Jan/23 21:15
Worklog Time Spent: 10m
Work Description: Glavo commented on code in PR #254:
URL: https://github.com/apache/commons-imaging/pull/254#discussion_r1068661686
##########
src/main/java/org/apache/commons/imaging/formats/webp/WebPImageParser.java:
##########
@@ -0,0 +1,351 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.imaging.formats.webp;
+
+import org.apache.commons.imaging.ImageFormat;
+import org.apache.commons.imaging.ImageFormats;
+import org.apache.commons.imaging.ImageInfo;
+import org.apache.commons.imaging.ImageParser;
+import org.apache.commons.imaging.ImageReadException;
+import org.apache.commons.imaging.common.XmpEmbeddable;
+import org.apache.commons.imaging.common.XmpImagingParameters;
+import org.apache.commons.imaging.common.bytesource.ByteSource;
+import org.apache.commons.imaging.formats.tiff.TiffImageMetadata;
+import org.apache.commons.imaging.formats.tiff.TiffImageParser;
+import org.apache.commons.imaging.formats.webp.chunks.WebPChunk;
+import org.apache.commons.imaging.formats.webp.chunks.WebPChunkANIM;
+import org.apache.commons.imaging.formats.webp.chunks.WebPChunkANMF;
+import org.apache.commons.imaging.formats.webp.chunks.WebPChunkEXIF;
+import org.apache.commons.imaging.formats.webp.chunks.WebPChunkICCP;
+import org.apache.commons.imaging.formats.webp.chunks.WebPChunkVP8;
+import org.apache.commons.imaging.formats.webp.chunks.WebPChunkVP8L;
+import org.apache.commons.imaging.formats.webp.chunks.WebPChunkVP8X;
+import org.apache.commons.imaging.formats.webp.chunks.WebPChunkXMP;
+import org.apache.commons.imaging.formats.webp.chunks.WebPChunkXYZW;
+
+import java.awt.Dimension;
+import java.awt.image.BufferedImage;
+import java.io.Closeable;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.PrintWriter;
+import java.nio.ByteOrder;
+import java.util.ArrayList;
+
+import static org.apache.commons.imaging.common.BinaryFunctions.read4Bytes;
+import static org.apache.commons.imaging.common.BinaryFunctions.readBytes;
+import static org.apache.commons.imaging.common.BinaryFunctions.skipBytes;
+
+public class WebPImageParser extends ImageParser<WebPImagingParameters>
implements XmpEmbeddable {
+
+ private static final String DEFAULT_EXTENSION =
ImageFormats.WEBP.getDefaultExtension();
+ private static final String[] ACCEPTED_EXTENSIONS =
ImageFormats.WEBP.getExtensions();
+
+ @Override
+ public WebPImagingParameters getDefaultParameters() {
+ return new WebPImagingParameters();
+ }
+
+ @Override
+ public String getName() {
+ return "WebP-Custom";
+ }
+
+ @Override
+ public String getDefaultExtension() {
+ return DEFAULT_EXTENSION;
+ }
+
+ @Override
+ protected String[] getAcceptedExtensions() {
+ return ACCEPTED_EXTENSIONS;
+ }
+
+ @Override
+ protected ImageFormat[] getAcceptedTypes() {
+ return new ImageFormat[]{ImageFormats.WEBP};
+ }
+
+ static int readFileHeader(InputStream is) throws IOException,
ImageReadException {
+ byte[] buffer = new byte[4];
+ if (is.read(buffer) < 4 ||
!WebPConstants.RIFF_SIGNATURE.equals(buffer)) {
+ throw new IOException("Not a Valid WebP File");
+ }
+
+ int fileSize = read4Bytes("File Size", is, "Not a Valid WebP File",
ByteOrder.LITTLE_ENDIAN);
+ if (fileSize < 0) {
+ throw new ImageReadException("File Size is too long:" + fileSize);
+ }
+
+ if (is.read(buffer) < 4 ||
!WebPConstants.WEBP_SIGNATURE.equals(buffer)) {
+ throw new IOException("Not a Valid WebP File");
Review Comment:
@kinow Can you take a look at this question?
Issue Time Tracking
-------------------
Worklog Id: (was: 838958)
Time Spent: 1h (was: 50m)
> Basic WebP support
> ------------------
>
> Key: IMAGING-339
> URL: https://issues.apache.org/jira/browse/IMAGING-339
> Project: Commons Imaging
> Issue Type: Improvement
> Components: Format: WebP
> Affects Versions: 1.0-alpha2
> Reporter: Bruno P. Kinoshita
> Assignee: Bruno P. Kinoshita
> Priority: Minor
> Fix For: 1.0-alpha3
>
> Time Spent: 1h
> Remaining Estimate: 0h
>
> Placeholder for https://github.com/apache/commons-imaging/pull/254
--
This message was sent by Atlassian Jira
(v8.20.10#820010)