[jira] [Work logged] (IMAGING-339) Basic WebP support

2023-01-15 Thread ASF GitHub Bot (Jira)


 [ 
https://issues.apache.org/jira/browse/IMAGING-339?focusedWorklogId=839286=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-839286
 ]

ASF GitHub Bot logged work on IMAGING-339:
--

Author: ASF GitHub Bot
Created on: 16/Jan/23 01:09
Start Date: 16/Jan/23 01:09
Worklog Time Spent: 10m 
  Work Description: Glavo commented on PR #254:
URL: https://github.com/apache/commons-imaging/pull/254#issuecomment-1383319953

   I updated this PR, added the `@since` tag and more detailed javadoc.




Issue Time Tracking
---

Worklog Id: (was: 839286)
Time Spent: 1.5h  (was: 1h 20m)

> 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: 1.5h
>  Remaining Estimate: 0h
>
> Placeholder for https://github.com/apache/commons-imaging/pull/254



--
This message was sent by Atlassian Jira
(v8.20.10#820010)


[jira] [Work logged] (IMAGING-339) Basic WebP support

2023-01-12 Thread ASF GitHub Bot (Jira)


 [ 
https://issues.apache.org/jira/browse/IMAGING-339?focusedWorklogId=838966=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-838966
 ]

ASF GitHub Bot logged work on IMAGING-339:
--

Author: ASF GitHub Bot
Created on: 12/Jan/23 21:40
Start Date: 12/Jan/23 21:40
Worklog Time Spent: 10m 
  Work Description: Glavo commented on PR #254:
URL: https://github.com/apache/commons-imaging/pull/254#issuecomment-1381023692

   @kinow I went back to this work and completed the missing documents.
   
   Can you take a look at my question here at  
https://github.com/apache/commons-imaging/pull/254/files/08d6a0dff607eefa633c89d231a01623e3ad90c6#r1049312581?
 
   I feel that the usage of `ImageReadException` and `IOException` is often 
confused, so I don't know which one to choose.




Issue Time Tracking
---

Worklog Id: (was: 838966)
Time Spent: 1h 20m  (was: 1h 10m)

> 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 20m
>  Remaining Estimate: 0h
>
> Placeholder for https://github.com/apache/commons-imaging/pull/254



--
This message was sent by Atlassian Jira
(v8.20.10#820010)


[jira] [Work logged] (IMAGING-339) Basic WebP support

2023-01-12 Thread ASF GitHub Bot (Jira)


 [ 
https://issues.apache.org/jira/browse/IMAGING-339?focusedWorklogId=838965=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-838965
 ]

ASF GitHub Bot logged work on IMAGING-339:
--

Author: ASF GitHub Bot
Created on: 12/Jan/23 21:37
Start Date: 12/Jan/23 21:37
Worklog Time Spent: 10m 
  Work Description: garydgregory commented on code in PR #254:
URL: https://github.com/apache/commons-imaging/pull/254#discussion_r1068685156


##
src/main/java/org/apache/commons/imaging/formats/webp/chunks/WebPChunk.java:
##
@@ -0,0 +1,80 @@
+/*
+ * 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.chunks;
+
+import org.apache.commons.imaging.ImageReadException;
+import org.apache.commons.imaging.common.BinaryFileParser;
+
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.nio.ByteOrder;
+import java.nio.charset.StandardCharsets;
+
+public abstract class WebPChunk extends BinaryFileParser {
+public static final int TYPE_VP8 = 0x20385056;
+public static final int TYPE_VP8L = 0x4C385056;
+public static final int TYPE_VP8X = 0x58385056;
+public static final int TYPE_ANIM = 0x4D494E41;
+public static final int TYPE_ANMF = 0x464D4E41;
+public static final int TYPE_ICCP = 0x50434349;
+public static final int TYPE_EXIF = 0x46495845;
+public static final int TYPE_XMP = 0x20504D58;
+
+private final int type;
+private final int size;
+protected final byte[] bytes;
+
+WebPChunk(int type, int size, byte[] bytes) throws ImageReadException {
+super(ByteOrder.LITTLE_ENDIAN);
+
+if (size != bytes.length) {
+throw new AssertionError("Chunk size must match bytes length");

Review Comment:
   Which leads to consider if we should present the smallest API surface for 
this new code, IOW the minimal elements that should be public or protected. 
Once public or protected, it's set in stone within a major release line.





Issue Time Tracking
---

Worklog Id: (was: 838965)
Time Spent: 1h 10m  (was: 1h)

> 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 10m
>  Remaining Estimate: 0h
>
> Placeholder for https://github.com/apache/commons-imaging/pull/254



--
This message was sent by Atlassian Jira
(v8.20.10#820010)


[jira] [Work logged] (IMAGING-339) Basic WebP support

2023-01-12 Thread ASF GitHub Bot (Jira)


 [ 
https://issues.apache.org/jira/browse/IMAGING-339?focusedWorklogId=838958=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 
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: 

[jira] [Work logged] (IMAGING-339) Basic WebP support

2023-01-12 Thread ASF GitHub Bot (Jira)


 [ 
https://issues.apache.org/jira/browse/IMAGING-339?focusedWorklogId=838954=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-838954
 ]

ASF GitHub Bot logged work on IMAGING-339:
--

Author: ASF GitHub Bot
Created on: 12/Jan/23 21:12
Start Date: 12/Jan/23 21:12
Worklog Time Spent: 10m 
  Work Description: Glavo commented on code in PR #254:
URL: https://github.com/apache/commons-imaging/pull/254#discussion_r1068659362


##
src/main/java/org/apache/commons/imaging/formats/webp/chunks/WebPChunk.java:
##
@@ -0,0 +1,80 @@
+/*
+ * 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.chunks;
+
+import org.apache.commons.imaging.ImageReadException;
+import org.apache.commons.imaging.common.BinaryFileParser;
+
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.nio.ByteOrder;
+import java.nio.charset.StandardCharsets;
+
+public abstract class WebPChunk extends BinaryFileParser {
+public static final int TYPE_VP8 = 0x20385056;
+public static final int TYPE_VP8L = 0x4C385056;
+public static final int TYPE_VP8X = 0x58385056;
+public static final int TYPE_ANIM = 0x4D494E41;
+public static final int TYPE_ANMF = 0x464D4E41;
+public static final int TYPE_ICCP = 0x50434349;
+public static final int TYPE_EXIF = 0x46495845;
+public static final int TYPE_XMP = 0x20504D58;
+
+private final int type;
+private final int size;
+protected final byte[] bytes;
+
+WebPChunk(int type, int size, byte[] bytes) throws ImageReadException {
+super(ByteOrder.LITTLE_ENDIAN);
+
+if (size != bytes.length) {
+throw new AssertionError("Chunk size must match bytes length");

Review Comment:
   > You must be thinking of IllegalStateException, we should not throw Errors.
   
   In my understanding, here I am asserting that throwing an exception is an 
unreachable path.
   
   But I thought again, maybe it is also feasible to throw 
`IllegalArgumentException`, because Chunk may also be constructed by users 
themselves.





Issue Time Tracking
---

Worklog Id: (was: 838954)
Time Spent: 50m  (was: 40m)

> 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: 50m
>  Remaining Estimate: 0h
>
> Placeholder for https://github.com/apache/commons-imaging/pull/254



--
This message was sent by Atlassian Jira
(v8.20.10#820010)


[jira] [Work logged] (IMAGING-339) Basic WebP support

2023-01-12 Thread ASF GitHub Bot (Jira)


 [ 
https://issues.apache.org/jira/browse/IMAGING-339?focusedWorklogId=838953=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-838953
 ]

ASF GitHub Bot logged work on IMAGING-339:
--

Author: ASF GitHub Bot
Created on: 12/Jan/23 21:09
Start Date: 12/Jan/23 21:09
Worklog Time Spent: 10m 
  Work Description: garydgregory commented on code in PR #254:
URL: https://github.com/apache/commons-imaging/pull/254#discussion_r1068651074


##
src/main/java/org/apache/commons/imaging/formats/webp/chunks/WebPChunk.java:
##
@@ -0,0 +1,80 @@
+/*
+ * 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.chunks;
+
+import org.apache.commons.imaging.ImageReadException;
+import org.apache.commons.imaging.common.BinaryFileParser;
+
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.nio.ByteOrder;
+import java.nio.charset.StandardCharsets;
+
+public abstract class WebPChunk extends BinaryFileParser {
+public static final int TYPE_VP8 = 0x20385056;
+public static final int TYPE_VP8L = 0x4C385056;
+public static final int TYPE_VP8X = 0x58385056;
+public static final int TYPE_ANIM = 0x4D494E41;
+public static final int TYPE_ANMF = 0x464D4E41;
+public static final int TYPE_ICCP = 0x50434349;
+public static final int TYPE_EXIF = 0x46495845;
+public static final int TYPE_XMP = 0x20504D58;
+
+private final int type;
+private final int size;
+protected final byte[] bytes;
+
+WebPChunk(int type, int size, byte[] bytes) throws ImageReadException {
+super(ByteOrder.LITTLE_ENDIAN);
+
+if (size != bytes.length) {
+throw new AssertionError("Chunk size must match bytes length");

Review Comment:
   You must be thinking of IllegalStateException or IllegalArgumentException we 
should not throw Errors.





Issue Time Tracking
---

Worklog Id: (was: 838953)
Time Spent: 40m  (was: 0.5h)

> 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: 40m
>  Remaining Estimate: 0h
>
> Placeholder for https://github.com/apache/commons-imaging/pull/254



--
This message was sent by Atlassian Jira
(v8.20.10#820010)


[jira] [Work logged] (IMAGING-339) Basic WebP support

2023-01-12 Thread ASF GitHub Bot (Jira)


 [ 
https://issues.apache.org/jira/browse/IMAGING-339?focusedWorklogId=838952=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-838952
 ]

ASF GitHub Bot logged work on IMAGING-339:
--

Author: ASF GitHub Bot
Created on: 12/Jan/23 21:08
Start Date: 12/Jan/23 21:08
Worklog Time Spent: 10m 
  Work Description: kinow commented on code in PR #254:
URL: https://github.com/apache/commons-imaging/pull/254#discussion_r1068655185


##
src/main/java/org/apache/commons/imaging/formats/webp/chunks/WebPChunk.java:
##
@@ -0,0 +1,80 @@
+/*
+ * 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.chunks;
+
+import org.apache.commons.imaging.ImageReadException;
+import org.apache.commons.imaging.common.BinaryFileParser;
+
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.nio.ByteOrder;
+import java.nio.charset.StandardCharsets;
+
+public abstract class WebPChunk extends BinaryFileParser {
+public static final int TYPE_VP8 = 0x20385056;
+public static final int TYPE_VP8L = 0x4C385056;
+public static final int TYPE_VP8X = 0x58385056;
+public static final int TYPE_ANIM = 0x4D494E41;
+public static final int TYPE_ANMF = 0x464D4E41;
+public static final int TYPE_ICCP = 0x50434349;
+public static final int TYPE_EXIF = 0x46495845;
+public static final int TYPE_XMP = 0x20504D58;
+
+private final int type;
+private final int size;
+protected final byte[] bytes;
+
+WebPChunk(int type, int size, byte[] bytes) throws ImageReadException {
+super(ByteOrder.LITTLE_ENDIAN);
+
+if (size != bytes.length) {
+throw new AssertionError("Chunk size must match bytes length");

Review Comment:
   I think it'd be important to be consistent, so users are not surprised when 
using the API. Have a look at the other parsers, @Glavo , and see what 
exceptions are being used. If you believe we must change it to another 
exception type, then we can create a follow up issue to discuss and plan how to 
do that in all other parsers :+1: 





Issue Time Tracking
---

Worklog Id: (was: 838952)
Time Spent: 0.5h  (was: 20m)

> 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: 0.5h
>  Remaining Estimate: 0h
>
> Placeholder for https://github.com/apache/commons-imaging/pull/254



--
This message was sent by Atlassian Jira
(v8.20.10#820010)


[jira] [Work logged] (IMAGING-339) Basic WebP support

2023-01-12 Thread ASF GitHub Bot (Jira)


 [ 
https://issues.apache.org/jira/browse/IMAGING-339?focusedWorklogId=838950=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-838950
 ]

ASF GitHub Bot logged work on IMAGING-339:
--

Author: ASF GitHub Bot
Created on: 12/Jan/23 21:04
Start Date: 12/Jan/23 21:04
Worklog Time Spent: 10m 
  Work Description: garydgregory commented on code in PR #254:
URL: https://github.com/apache/commons-imaging/pull/254#discussion_r1068651074


##
src/main/java/org/apache/commons/imaging/formats/webp/chunks/WebPChunk.java:
##
@@ -0,0 +1,80 @@
+/*
+ * 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.chunks;
+
+import org.apache.commons.imaging.ImageReadException;
+import org.apache.commons.imaging.common.BinaryFileParser;
+
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.nio.ByteOrder;
+import java.nio.charset.StandardCharsets;
+
+public abstract class WebPChunk extends BinaryFileParser {
+public static final int TYPE_VP8 = 0x20385056;
+public static final int TYPE_VP8L = 0x4C385056;
+public static final int TYPE_VP8X = 0x58385056;
+public static final int TYPE_ANIM = 0x4D494E41;
+public static final int TYPE_ANMF = 0x464D4E41;
+public static final int TYPE_ICCP = 0x50434349;
+public static final int TYPE_EXIF = 0x46495845;
+public static final int TYPE_XMP = 0x20504D58;
+
+private final int type;
+private final int size;
+protected final byte[] bytes;
+
+WebPChunk(int type, int size, byte[] bytes) throws ImageReadException {
+super(ByteOrder.LITTLE_ENDIAN);
+
+if (size != bytes.length) {
+throw new AssertionError("Chunk size must match bytes length");

Review Comment:
   You must be thinking of IllegalStateException, we should not throw Errors.





Issue Time Tracking
---

Worklog Id: (was: 838950)
Time Spent: 20m  (was: 10m)

> 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: 20m
>  Remaining Estimate: 0h
>
> Placeholder for https://github.com/apache/commons-imaging/pull/254



--
This message was sent by Atlassian Jira
(v8.20.10#820010)


[jira] [Work logged] (IMAGING-339) Basic WebP support

2023-01-12 Thread ASF GitHub Bot (Jira)


 [ 
https://issues.apache.org/jira/browse/IMAGING-339?focusedWorklogId=838948=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-838948
 ]

ASF GitHub Bot logged work on IMAGING-339:
--

Author: ASF GitHub Bot
Created on: 12/Jan/23 21:00
Start Date: 12/Jan/23 21:00
Worklog Time Spent: 10m 
  Work Description: Glavo commented on code in PR #254:
URL: https://github.com/apache/commons-imaging/pull/254#discussion_r1068648410


##
src/main/java/org/apache/commons/imaging/formats/webp/chunks/WebPChunk.java:
##
@@ -0,0 +1,80 @@
+/*
+ * 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.chunks;
+
+import org.apache.commons.imaging.ImageReadException;
+import org.apache.commons.imaging.common.BinaryFileParser;
+
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.nio.ByteOrder;
+import java.nio.charset.StandardCharsets;
+
+public abstract class WebPChunk extends BinaryFileParser {
+public static final int TYPE_VP8 = 0x20385056;
+public static final int TYPE_VP8L = 0x4C385056;
+public static final int TYPE_VP8X = 0x58385056;
+public static final int TYPE_ANIM = 0x4D494E41;
+public static final int TYPE_ANMF = 0x464D4E41;
+public static final int TYPE_ICCP = 0x50434349;
+public static final int TYPE_EXIF = 0x46495845;
+public static final int TYPE_XMP = 0x20504D58;
+
+private final int type;
+private final int size;
+protected final byte[] bytes;
+
+WebPChunk(int type, int size, byte[] bytes) throws ImageReadException {
+super(ByteOrder.LITTLE_ENDIAN);
+
+if (size != bytes.length) {
+throw new AssertionError("Chunk size must match bytes length");

Review Comment:
   @kinow I think `AssertionError` should be used here.
   
   I think `ImageReadException` should be thrown only when there is no error in 
commons-imaging itself, e.g. we encountered illegal input at runtime.
   
   However, here, illegal input data will not cause this problem. An exception 
will be thrown only if commons-imaging itself has logical errors, so I use 
`AssertionError` here.





Issue Time Tracking
---

Worklog Id: (was: 838948)
Remaining Estimate: 0h
Time Spent: 10m

> 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: 10m
>  Remaining Estimate: 0h
>
> Placeholder for https://github.com/apache/commons-imaging/pull/254



--
This message was sent by Atlassian Jira
(v8.20.10#820010)