This is an automated email from the ASF dual-hosted git repository. ggregory pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/commons-imaging.git
commit e2cc2f8016c0806b3d172e857016ef7f932e0755 Author: Gary Gregory <garydgreg...@gmail.com> AuthorDate: Wed Aug 24 11:42:59 2022 -0400 Use LF line endings --- src/conf/spotbugs-exclude-filter.xml | 406 ++++++++++----------- src/site/xdoc/download_imaging.xml | 230 ++++++------ .../formats/jpeg/iptc/IptcFullDiscardTest.java | 140 +++---- .../imaging/formats/png/PngWritePredictorTest.java | 268 +++++++------- .../imaging/formats/pnm/PnmImageParserTest.java | 202 +++++----- 5 files changed, 623 insertions(+), 623 deletions(-) diff --git a/src/conf/spotbugs-exclude-filter.xml b/src/conf/spotbugs-exclude-filter.xml index a5b779dd..f090917f 100644 --- a/src/conf/spotbugs-exclude-filter.xml +++ b/src/conf/spotbugs-exclude-filter.xml @@ -1,203 +1,203 @@ -<?xml version="1.0"?> -<!-- - 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. ---> - -<!-- - This file contains some false positive bugs detected by spotbugs. Their - false positive nature has been analyzed individually and they have been - put here to instruct findbugs it must ignore them. ---> -<FindBugsFilter - xmlns="https://github.com/spotbugs/filter/3.0.0" - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="https://github.com/spotbugs/filter/3.0.0 https://raw.githubusercontent.com/spotbugs/spotbugs/3.1.0/spotbugs/etc/findbugsfilter.xsd"> - <!-- Reason: Intentionally exposing an array --> - <Match> - <Class name="org.apache.commons.imaging.common.bytesource.ByteSourceArray" /> - <Method name="getAll" /> - <Bug pattern="EI_EXPOSE_REP" /> - </Match> - <Match> - <Class name="org.apache.commons.imaging.common.bytesource.ByteSourceArray" /> - <Bug pattern="EI_EXPOSE_REP2" /> - </Match> - <Match> - <Class name="org.apache.commons.imaging.formats.jpeg.iptc.IptcBlock" /> - <Bug pattern="EI_EXPOSE_REP2" /> - </Match> - <Match> - <Class name="org.apache.commons.imaging.formats.jpeg.segments.DqtSegment$QuantizationTable" /> - <Method name="getElements" /> - <Bug pattern="EI_EXPOSE_REP" /> - </Match> - <Match> - <Class name="org.apache.commons.imaging.formats.jpeg.segments.DqtSegment$QuantizationTable" /> - <Bug pattern="EI_EXPOSE_REP2" /> - </Match> - <Match> - <Class name="org.apache.commons.imaging.formats.tiff.TiffElement$DataElement" /> - <Bug pattern="EI_EXPOSE_REP2" /> - </Match> - <Match> - <Class name="org.apache.commons.imaging.formats.tiff.TiffField" /> - <Bug pattern="EI_EXPOSE_REP2" /> - </Match> - <Match> - <Class name="org.apache.commons.imaging.formats.tiff.TiffImageData$Strips" /> - <Method name="getImageData" /> - <Bug pattern="EI_EXPOSE_REP" /> - </Match> - <Match> - <Class name="org.apache.commons.imaging.formats.tiff.TiffImageData$Strips" /> - <Bug pattern="EI_EXPOSE_REP2" /> - </Match> - <Match> - <Class name="org.apache.commons.imaging.formats.tiff.TiffRasterData" /> - <Method name="getData" /> - <Bug pattern="EI_EXPOSE_REP" /> - </Match> - <Match> - <Class name="org.apache.commons.imaging.formats.tiff.TiffRasterData" /> - <Bug pattern="EI_EXPOSE_REP2" /> - </Match> - <Match> - <Class name="org.apache.commons.imaging.formats.tiff.TiffRasterDataFloat" /> - <Method name="getData" /> - <Bug pattern="EI_EXPOSE_REP" /> - </Match> - <Match> - <Class name="org.apache.commons.imaging.formats.tiff.TiffRasterDataFloat" /> - <Bug pattern="EI_EXPOSE_REP2" /> - </Match> - <Match> - <Class name="org.apache.commons.imaging.formats.tiff.TiffRasterDataInt" /> - <Method name="getIntData" /> - <Bug pattern="EI_EXPOSE_REP" /> - </Match> - <Match> - <Class name="org.apache.commons.imaging.formats.tiff.TiffRasterDataInt" /> - <Bug pattern="EI_EXPOSE_REP2" /> - </Match> - <Match> - <Class name="org.apache.commons.imaging.formats.tiff.datareaders.ImageDataReader" /> - <Bug pattern="EI_EXPOSE_REP2" /> - </Match> - <Match> - <Class name="org.apache.commons.imaging.formats.tiff.photometricinterpreters.PhotometricInterpreter" /> - <Bug pattern="EI_EXPOSE_REP2" /> - </Match> - <Match> - <Class name="org.apache.commons.imaging.formats.tiff.write.TiffImageWriterLossless" /> - <Bug pattern="EI_EXPOSE_REP2" /> - </Match> - <Match> - <Class name="org.apache.commons.imaging.formats.tiff.write.TiffOutputField" /> - <Bug pattern="EI_EXPOSE_REP2" /> - </Match> - <Match> - <Class name="org.apache.commons.imaging.icc.IccProfileInfo" /> - <Method name="getTags" /> - <Bug pattern="EI_EXPOSE_REP" /> - </Match> - <Match> - <Class name="org.apache.commons.imaging.icc.IccProfileInfo" /> - <Bug pattern="EI_EXPOSE_REP2" /> - </Match> - <Match> - <Class name="org.apache.commons.imaging.icc.IccTag" /> - <Method name="setData" /> - <Bug pattern="EI_EXPOSE_REP2" /> - </Match> - <Match> - <Class name="org.apache.commons.imaging.palette.SimplePalette" /> - <Bug pattern="EI_EXPOSE_REP2" /> - </Match> - <Match> - <Class name="org.apache.commons.imaging.formats.tiff.write.TiffOutputDirectory" /> - <Method name="setNextDirectory" /> - <Bug pattern="EI_EXPOSE_REP2" /> - </Match> - <Match> - <Class name="org.apache.commons.imaging.formats.tiff.TiffImageMetadata$Directory" /> - <Method name="<init>" /> - <Bug pattern="EI_EXPOSE_REP2" /> - </Match> - <Match> - <Class name="org.apache.commons.imaging.formats.tiff.TiffField" /> - <Method name="getFieldType" /> - <Bug pattern="EI_EXPOSE_REP" /> - </Match> - <Match> - <Class name="org.apache.commons.imaging.formats.jpeg.decoder.JpegDecoder" /> - <Method name="decode" /> - <Bug pattern="EI_EXPOSE_REP" /> - </Match> - <Match> - <Class name="org.apache.commons.imaging.formats.jpeg.JpegImageMetadata" /> - <Method name="getExif" /> - <Bug pattern="EI_EXPOSE_REP" /> - </Match> - <Match> - <Class name="org.apache.commons.imaging.formats.jpeg.JpegImageMetadata" /> - <Method name="getPhotoshop" /> - <Bug pattern="EI_EXPOSE_REP" /> - </Match> - <Match> - <Class name="org.apache.commons.imaging.formats.jpeg.JpegImageMetadata" /> - <Method name="<init>" /> - <Bug pattern="EI_EXPOSE_REP2" /> - </Match> - <Match> - <Class name="org.apache.commons.imaging.common.mylzw.MyLzwCompressor" /> - <Method name="<init>" /> - <Bug pattern="EI_EXPOSE_REP2" /> - </Match> - <Match> - <Class name="org.apache.commons.imaging.common.mylzw.MyBitOutputStream" /> - <Method name="<init>" /> - <Bug pattern="EI_EXPOSE_REP2" /> - </Match> - <Match> - <Class name="org.apache.commons.imaging.common.mylzw.BitsToByteInputStream" /> - <Method name="<init>" /> - <Bug pattern="EI_EXPOSE_REP2" /> - </Match> - <Match> - <Class name="org.apache.commons.imaging.common.BinaryOutputStream" /> - <Method name="<init>" /> - <Bug pattern="EI_EXPOSE_REP2" /> - </Match> - <Match> - <Class name="org.apache.commons.imaging.formats.tiff.TiffImagingParameters" /> - <Method name="getOutputSet" /> - <Bug pattern="EI_EXPOSE_REP" /> - </Match> - <Match> - <Class name="org.apache.commons.imaging.formats.tiff.TiffImagingParameters" /> - <Method name="setOutputSet" /> - <Bug pattern="EI_EXPOSE_REP2" /> - </Match> - <!-- Reason: For code clarity, we could use a simple 'else', but instead keep a complete expression --> - <Match> - <Class name="org.apache.commons.imaging.formats.pnm.PnmImageParser" /> - <Bug pattern="UC_USELESS_CONDITION" /> - </Match> - <!-- Reason: false positives with JVM >= 14 - https://github.com/spotbugs/spotbugs/issues/868 --> - <Match> - <Bug pattern="RCN_REDUNDANT_NULLCHECK_WOULD_HAVE_BEEN_A_NPE" /> - </Match> -</FindBugsFilter> +<?xml version="1.0"?> +<!-- + 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. +--> + +<!-- + This file contains some false positive bugs detected by spotbugs. Their + false positive nature has been analyzed individually and they have been + put here to instruct findbugs it must ignore them. +--> +<FindBugsFilter + xmlns="https://github.com/spotbugs/filter/3.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="https://github.com/spotbugs/filter/3.0.0 https://raw.githubusercontent.com/spotbugs/spotbugs/3.1.0/spotbugs/etc/findbugsfilter.xsd"> + <!-- Reason: Intentionally exposing an array --> + <Match> + <Class name="org.apache.commons.imaging.common.bytesource.ByteSourceArray" /> + <Method name="getAll" /> + <Bug pattern="EI_EXPOSE_REP" /> + </Match> + <Match> + <Class name="org.apache.commons.imaging.common.bytesource.ByteSourceArray" /> + <Bug pattern="EI_EXPOSE_REP2" /> + </Match> + <Match> + <Class name="org.apache.commons.imaging.formats.jpeg.iptc.IptcBlock" /> + <Bug pattern="EI_EXPOSE_REP2" /> + </Match> + <Match> + <Class name="org.apache.commons.imaging.formats.jpeg.segments.DqtSegment$QuantizationTable" /> + <Method name="getElements" /> + <Bug pattern="EI_EXPOSE_REP" /> + </Match> + <Match> + <Class name="org.apache.commons.imaging.formats.jpeg.segments.DqtSegment$QuantizationTable" /> + <Bug pattern="EI_EXPOSE_REP2" /> + </Match> + <Match> + <Class name="org.apache.commons.imaging.formats.tiff.TiffElement$DataElement" /> + <Bug pattern="EI_EXPOSE_REP2" /> + </Match> + <Match> + <Class name="org.apache.commons.imaging.formats.tiff.TiffField" /> + <Bug pattern="EI_EXPOSE_REP2" /> + </Match> + <Match> + <Class name="org.apache.commons.imaging.formats.tiff.TiffImageData$Strips" /> + <Method name="getImageData" /> + <Bug pattern="EI_EXPOSE_REP" /> + </Match> + <Match> + <Class name="org.apache.commons.imaging.formats.tiff.TiffImageData$Strips" /> + <Bug pattern="EI_EXPOSE_REP2" /> + </Match> + <Match> + <Class name="org.apache.commons.imaging.formats.tiff.TiffRasterData" /> + <Method name="getData" /> + <Bug pattern="EI_EXPOSE_REP" /> + </Match> + <Match> + <Class name="org.apache.commons.imaging.formats.tiff.TiffRasterData" /> + <Bug pattern="EI_EXPOSE_REP2" /> + </Match> + <Match> + <Class name="org.apache.commons.imaging.formats.tiff.TiffRasterDataFloat" /> + <Method name="getData" /> + <Bug pattern="EI_EXPOSE_REP" /> + </Match> + <Match> + <Class name="org.apache.commons.imaging.formats.tiff.TiffRasterDataFloat" /> + <Bug pattern="EI_EXPOSE_REP2" /> + </Match> + <Match> + <Class name="org.apache.commons.imaging.formats.tiff.TiffRasterDataInt" /> + <Method name="getIntData" /> + <Bug pattern="EI_EXPOSE_REP" /> + </Match> + <Match> + <Class name="org.apache.commons.imaging.formats.tiff.TiffRasterDataInt" /> + <Bug pattern="EI_EXPOSE_REP2" /> + </Match> + <Match> + <Class name="org.apache.commons.imaging.formats.tiff.datareaders.ImageDataReader" /> + <Bug pattern="EI_EXPOSE_REP2" /> + </Match> + <Match> + <Class name="org.apache.commons.imaging.formats.tiff.photometricinterpreters.PhotometricInterpreter" /> + <Bug pattern="EI_EXPOSE_REP2" /> + </Match> + <Match> + <Class name="org.apache.commons.imaging.formats.tiff.write.TiffImageWriterLossless" /> + <Bug pattern="EI_EXPOSE_REP2" /> + </Match> + <Match> + <Class name="org.apache.commons.imaging.formats.tiff.write.TiffOutputField" /> + <Bug pattern="EI_EXPOSE_REP2" /> + </Match> + <Match> + <Class name="org.apache.commons.imaging.icc.IccProfileInfo" /> + <Method name="getTags" /> + <Bug pattern="EI_EXPOSE_REP" /> + </Match> + <Match> + <Class name="org.apache.commons.imaging.icc.IccProfileInfo" /> + <Bug pattern="EI_EXPOSE_REP2" /> + </Match> + <Match> + <Class name="org.apache.commons.imaging.icc.IccTag" /> + <Method name="setData" /> + <Bug pattern="EI_EXPOSE_REP2" /> + </Match> + <Match> + <Class name="org.apache.commons.imaging.palette.SimplePalette" /> + <Bug pattern="EI_EXPOSE_REP2" /> + </Match> + <Match> + <Class name="org.apache.commons.imaging.formats.tiff.write.TiffOutputDirectory" /> + <Method name="setNextDirectory" /> + <Bug pattern="EI_EXPOSE_REP2" /> + </Match> + <Match> + <Class name="org.apache.commons.imaging.formats.tiff.TiffImageMetadata$Directory" /> + <Method name="<init>" /> + <Bug pattern="EI_EXPOSE_REP2" /> + </Match> + <Match> + <Class name="org.apache.commons.imaging.formats.tiff.TiffField" /> + <Method name="getFieldType" /> + <Bug pattern="EI_EXPOSE_REP" /> + </Match> + <Match> + <Class name="org.apache.commons.imaging.formats.jpeg.decoder.JpegDecoder" /> + <Method name="decode" /> + <Bug pattern="EI_EXPOSE_REP" /> + </Match> + <Match> + <Class name="org.apache.commons.imaging.formats.jpeg.JpegImageMetadata" /> + <Method name="getExif" /> + <Bug pattern="EI_EXPOSE_REP" /> + </Match> + <Match> + <Class name="org.apache.commons.imaging.formats.jpeg.JpegImageMetadata" /> + <Method name="getPhotoshop" /> + <Bug pattern="EI_EXPOSE_REP" /> + </Match> + <Match> + <Class name="org.apache.commons.imaging.formats.jpeg.JpegImageMetadata" /> + <Method name="<init>" /> + <Bug pattern="EI_EXPOSE_REP2" /> + </Match> + <Match> + <Class name="org.apache.commons.imaging.common.mylzw.MyLzwCompressor" /> + <Method name="<init>" /> + <Bug pattern="EI_EXPOSE_REP2" /> + </Match> + <Match> + <Class name="org.apache.commons.imaging.common.mylzw.MyBitOutputStream" /> + <Method name="<init>" /> + <Bug pattern="EI_EXPOSE_REP2" /> + </Match> + <Match> + <Class name="org.apache.commons.imaging.common.mylzw.BitsToByteInputStream" /> + <Method name="<init>" /> + <Bug pattern="EI_EXPOSE_REP2" /> + </Match> + <Match> + <Class name="org.apache.commons.imaging.common.BinaryOutputStream" /> + <Method name="<init>" /> + <Bug pattern="EI_EXPOSE_REP2" /> + </Match> + <Match> + <Class name="org.apache.commons.imaging.formats.tiff.TiffImagingParameters" /> + <Method name="getOutputSet" /> + <Bug pattern="EI_EXPOSE_REP" /> + </Match> + <Match> + <Class name="org.apache.commons.imaging.formats.tiff.TiffImagingParameters" /> + <Method name="setOutputSet" /> + <Bug pattern="EI_EXPOSE_REP2" /> + </Match> + <!-- Reason: For code clarity, we could use a simple 'else', but instead keep a complete expression --> + <Match> + <Class name="org.apache.commons.imaging.formats.pnm.PnmImageParser" /> + <Bug pattern="UC_USELESS_CONDITION" /> + </Match> + <!-- Reason: false positives with JVM >= 14 - https://github.com/spotbugs/spotbugs/issues/868 --> + <Match> + <Bug pattern="RCN_REDUNDANT_NULLCHECK_WOULD_HAVE_BEEN_A_NPE" /> + </Match> +</FindBugsFilter> diff --git a/src/site/xdoc/download_imaging.xml b/src/site/xdoc/download_imaging.xml index dc146765..704c1524 100644 --- a/src/site/xdoc/download_imaging.xml +++ b/src/site/xdoc/download_imaging.xml @@ -1,118 +1,118 @@ -<?xml version="1.0"?> -<!-- -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. ---> -<!-- - +======================================================================+ - |**** ****| - |**** THIS FILE IS GENERATED BY THE COMMONS BUILD PLUGIN ****| - |**** DO NOT EDIT DIRECTLY ****| - |**** ****| - +======================================================================+ - | TEMPLATE FILE: download-page-template.xml | - | commons-build-plugin/trunk/src/main/resources/commons-xdoc-templates | - +======================================================================+ - | | - | 1) Re-generate using: mvn commons-build:download-page | - | | - | 2) Set the following properties in the component's pom: | - | - commons.componentid (required, alphabetic, lower case) | - | - commons.release.version (required) | - | - commons.release.name (required) | - | - commons.binary.suffix (optional) | - | (defaults to "-bin", set to "" for pre-maven2 releases) | - | - commons.release.desc (optional) | - | - commons.release.subdir (optional) | - | - commons.release.hash (optional, lowercase, default sha512) | - | | - | - commons.release.[234].version (conditional) | - | - commons.release.[234].name (conditional) | - | - commons.release.[234].binary.suffix (optional) | - | - commons.release.[234].desc (optional) | - | - commons.release.[234].subdir (optional) | - | - commons.release.[234].hash (optional, lowercase, [sha512])| - | | - | 3) Example Properties | - | (commons.release.name inherited by parent: | - | ${project.artifactId}-${commons.release.version} | - | | - | <properties> | - | <commons.componentid>math</commons.componentid> | - | <commons.release.version>1.2</commons.release.version> | - | </properties> | - | | - +======================================================================+ ---> -<document> - <properties> - <title>Download Apache Commons Imaging</title> - <author email="d...@commons.apache.org">Apache Commons Documentation Team</author> - </properties> - <body> - <section name="Download Apache Commons Imaging"> - <subsection name="Using a Mirror"> - <p> - We recommend you use a mirror to download our release - builds, but you <strong>must</strong> <a href="https://www.apache.org/info/verification.html">verify the integrity</a> of - the downloaded files using signatures downloaded from our main - distribution directories. Recent releases (48 hours) may not yet - be available from all the mirrors. - </p> - - <p> - You are currently using <b>[preferred]</b>. If you - encounter a problem with this mirror, please select another - mirror. If all mirrors are failing, there are <i>backup</i> - mirrors (at the end of the mirrors list) that should be - available. - <br></br> - [if-any logo]<a href="[link]"><img align="right" src="[logo]" border="0"></img></a>[end] - </p> - - <form action="[location]" method="get" id="SelectMirror"> - <p> - Other mirrors: - <select name="Preferred"> - [if-any http] - [for http]<option value="[http]">[http]</option>[end] - [end] - [if-any ftp] - [for ftp]<option value="[ftp]">[ftp]</option>[end] - [end] - [if-any backup] - [for backup]<option value="[backup]">[backup] (backup)</option>[end] - [end] - </select> - <input type="submit" value="Change"></input> - </p> - </form> - - <p> - It is essential that you - <a href="https://www.apache.org/info/verification.html">verify the integrity</a> - of downloaded files, preferably using the <code>PGP</code> signature (<code>*.asc</code> files); - failing that using the <code>SHA512</code> hash (<code>*.sha512</code> checksum files). - </p> - <p> - The <a href="https://www.apache.org/dist/commons/KEYS">KEYS</a> - file contains the public PGP keys used by Apache Commons developers - to sign releases. - </p> - </subsection> - </section> +<?xml version="1.0"?> +<!-- +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. +--> +<!-- + +======================================================================+ + |**** ****| + |**** THIS FILE IS GENERATED BY THE COMMONS BUILD PLUGIN ****| + |**** DO NOT EDIT DIRECTLY ****| + |**** ****| + +======================================================================+ + | TEMPLATE FILE: download-page-template.xml | + | commons-build-plugin/trunk/src/main/resources/commons-xdoc-templates | + +======================================================================+ + | | + | 1) Re-generate using: mvn commons-build:download-page | + | | + | 2) Set the following properties in the component's pom: | + | - commons.componentid (required, alphabetic, lower case) | + | - commons.release.version (required) | + | - commons.release.name (required) | + | - commons.binary.suffix (optional) | + | (defaults to "-bin", set to "" for pre-maven2 releases) | + | - commons.release.desc (optional) | + | - commons.release.subdir (optional) | + | - commons.release.hash (optional, lowercase, default sha512) | + | | + | - commons.release.[234].version (conditional) | + | - commons.release.[234].name (conditional) | + | - commons.release.[234].binary.suffix (optional) | + | - commons.release.[234].desc (optional) | + | - commons.release.[234].subdir (optional) | + | - commons.release.[234].hash (optional, lowercase, [sha512])| + | | + | 3) Example Properties | + | (commons.release.name inherited by parent: | + | ${project.artifactId}-${commons.release.version} | + | | + | <properties> | + | <commons.componentid>math</commons.componentid> | + | <commons.release.version>1.2</commons.release.version> | + | </properties> | + | | + +======================================================================+ +--> +<document> + <properties> + <title>Download Apache Commons Imaging</title> + <author email="d...@commons.apache.org">Apache Commons Documentation Team</author> + </properties> + <body> + <section name="Download Apache Commons Imaging"> + <subsection name="Using a Mirror"> + <p> + We recommend you use a mirror to download our release + builds, but you <strong>must</strong> <a href="https://www.apache.org/info/verification.html">verify the integrity</a> of + the downloaded files using signatures downloaded from our main + distribution directories. Recent releases (48 hours) may not yet + be available from all the mirrors. + </p> + + <p> + You are currently using <b>[preferred]</b>. If you + encounter a problem with this mirror, please select another + mirror. If all mirrors are failing, there are <i>backup</i> + mirrors (at the end of the mirrors list) that should be + available. + <br></br> + [if-any logo]<a href="[link]"><img align="right" src="[logo]" border="0"></img></a>[end] + </p> + + <form action="[location]" method="get" id="SelectMirror"> + <p> + Other mirrors: + <select name="Preferred"> + [if-any http] + [for http]<option value="[http]">[http]</option>[end] + [end] + [if-any ftp] + [for ftp]<option value="[ftp]">[ftp]</option>[end] + [end] + [if-any backup] + [for backup]<option value="[backup]">[backup] (backup)</option>[end] + [end] + </select> + <input type="submit" value="Change"></input> + </p> + </form> + + <p> + It is essential that you + <a href="https://www.apache.org/info/verification.html">verify the integrity</a> + of downloaded files, preferably using the <code>PGP</code> signature (<code>*.asc</code> files); + failing that using the <code>SHA512</code> hash (<code>*.sha512</code> checksum files). + </p> + <p> + The <a href="https://www.apache.org/dist/commons/KEYS">KEYS</a> + file contains the public PGP keys used by Apache Commons developers + to sign releases. + </p> + </subsection> + </section> <section name="Apache Commons Imaging 1.0-alpha3 "> <subsection name="Binaries"> <table> diff --git a/src/test/java/org/apache/commons/imaging/formats/jpeg/iptc/IptcFullDiscardTest.java b/src/test/java/org/apache/commons/imaging/formats/jpeg/iptc/IptcFullDiscardTest.java index ddc8272a..37e7d7c2 100644 --- a/src/test/java/org/apache/commons/imaging/formats/jpeg/iptc/IptcFullDiscardTest.java +++ b/src/test/java/org/apache/commons/imaging/formats/jpeg/iptc/IptcFullDiscardTest.java @@ -1,70 +1,70 @@ -/* - * 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.jpeg.iptc; - -import java.awt.Graphics2D; -import java.awt.image.BufferedImage; -import java.io.ByteArrayOutputStream; -import java.util.Collections; - -import javax.imageio.ImageIO; - -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Test; - -public class IptcFullDiscardTest { - - private byte[] addMetaData(final byte[] bytes) throws Exception { - final IptcRecord record = new IptcRecord(IptcTypes.KEYWORDS, "meta; data"); - final PhotoshopApp13Data data = new PhotoshopApp13Data(Collections.singletonList(record), Collections.emptyList()); - final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); - new JpegIptcRewriter().writeIPTC(bytes, byteArrayOutputStream, data); - return byteArrayOutputStream.toByteArray(); - } - - private byte[] generateImage() throws Exception { - final BufferedImage image = new BufferedImage(100, 50, BufferedImage.TYPE_3BYTE_BGR); // was TYPE_INT_ARGB but that fails on Continuum - final Graphics2D graphics2D = image.createGraphics(); - graphics2D.drawString("Hello World!", 10, 10); - final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); - ImageIO.write(image, "jpg", byteArrayOutputStream); - return byteArrayOutputStream.toByteArray(); - } - - private byte[] removeMetaData(final byte[] bytes, final boolean removeApp13Segment) throws Exception { - final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); - new JpegIptcRewriter().removeIPTC(bytes, byteArrayOutputStream, removeApp13Segment); - return byteArrayOutputStream.toByteArray(); - } - - @Test - public void leaveApp13Segment() throws Exception { - final byte[] originalImage = generateImage(); - final byte[] taggedImage = addMetaData(originalImage); - final byte[] untaggedImage = removeMetaData(taggedImage, false); - Assertions.assertEquals(18, untaggedImage.length - originalImage.length); - } - - @Test - public void removeApp13Segment() throws Exception { - final byte[] originalImage = generateImage(); - final byte[] taggedImage = addMetaData(originalImage); - final byte[] untaggedImage = removeMetaData(taggedImage, true); - Assertions.assertEquals(originalImage.length, untaggedImage.length); - } -} +/* + * 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.jpeg.iptc; + +import java.awt.Graphics2D; +import java.awt.image.BufferedImage; +import java.io.ByteArrayOutputStream; +import java.util.Collections; + +import javax.imageio.ImageIO; + +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +public class IptcFullDiscardTest { + + private byte[] addMetaData(final byte[] bytes) throws Exception { + final IptcRecord record = new IptcRecord(IptcTypes.KEYWORDS, "meta; data"); + final PhotoshopApp13Data data = new PhotoshopApp13Data(Collections.singletonList(record), Collections.emptyList()); + final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + new JpegIptcRewriter().writeIPTC(bytes, byteArrayOutputStream, data); + return byteArrayOutputStream.toByteArray(); + } + + private byte[] generateImage() throws Exception { + final BufferedImage image = new BufferedImage(100, 50, BufferedImage.TYPE_3BYTE_BGR); // was TYPE_INT_ARGB but that fails on Continuum + final Graphics2D graphics2D = image.createGraphics(); + graphics2D.drawString("Hello World!", 10, 10); + final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + ImageIO.write(image, "jpg", byteArrayOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + private byte[] removeMetaData(final byte[] bytes, final boolean removeApp13Segment) throws Exception { + final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + new JpegIptcRewriter().removeIPTC(bytes, byteArrayOutputStream, removeApp13Segment); + return byteArrayOutputStream.toByteArray(); + } + + @Test + public void leaveApp13Segment() throws Exception { + final byte[] originalImage = generateImage(); + final byte[] taggedImage = addMetaData(originalImage); + final byte[] untaggedImage = removeMetaData(taggedImage, false); + Assertions.assertEquals(18, untaggedImage.length - originalImage.length); + } + + @Test + public void removeApp13Segment() throws Exception { + final byte[] originalImage = generateImage(); + final byte[] taggedImage = addMetaData(originalImage); + final byte[] untaggedImage = removeMetaData(taggedImage, true); + Assertions.assertEquals(originalImage.length, untaggedImage.length); + } +} diff --git a/src/test/java/org/apache/commons/imaging/formats/png/PngWritePredictorTest.java b/src/test/java/org/apache/commons/imaging/formats/png/PngWritePredictorTest.java index 2ef113fd..4641a387 100644 --- a/src/test/java/org/apache/commons/imaging/formats/png/PngWritePredictorTest.java +++ b/src/test/java/org/apache/commons/imaging/formats/png/PngWritePredictorTest.java @@ -1,134 +1,134 @@ -/* - * 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.png; - -import java.awt.image.BufferedImage; -import java.io.BufferedOutputStream; -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; -import javax.imageio.ImageIO; -import org.apache.commons.imaging.ImageWriteException; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.*; - -/** - * Provides a test for the PngWriter using predictors - */ -public class PngWritePredictorTest { - - public PngWritePredictorTest() { - } - - @BeforeAll - public static void setUpClass() { - } - - @BeforeEach - public void setUp() { - } - - /** - * Populate an integer pixel array for a 256-by-256 image - * with varied colors across the image area and a white and - * black line down the main diagonal. - * @return a valid array of integers. - */ - private int[] populateARGB() { - //populate array with a blend of color components - final int[] argb = new int[256 * 256]; - for (int i = 0; i < 256; i++) { - for (int j = 0; j < 256; j++) { - final int red = i; - final int green = (255 - i); - final int blue = j; - argb[i * 256 + j] = ((((0xff00 | red) << 8) | green) << 8) | blue; - } - } - - // also draw a black and white strip down main diagonal - for (int i = 0; i < 256; i++) { - argb[i * 256 + i] = 0xff000000; - if (i < 255) { - argb[i * 256 + i + 1] = 0xffffffff; - } - } - return argb; - } - - @Test - void testWriteWithPredictor() { - final int[] argb = populateARGB(); - - // Test the RGB (no alpha) case --------------------- - BufferedImage bImage = new BufferedImage(256, 256, BufferedImage.TYPE_INT_RGB); - bImage.setRGB(0, 0, 256, 256, argb, 0, 256); - - File tempFile = null; - - try { - tempFile = File.createTempFile("PngWritePredictorRGB", ".png"); - } catch (final IOException ioex) { - fail("Failed to create temporary file, " + ioex.getMessage()); - } - final PngImagingParameters params = new PngImagingParameters(); - params.setPredictorEnabled(true); - final PngImageParser parser = new PngImageParser(); - try ( FileOutputStream fos = new FileOutputStream(tempFile); BufferedOutputStream bos = new BufferedOutputStream(fos)) { - parser.writeImage(bImage, bos, params); - bos.flush(); - } catch (IOException | ImageWriteException ex) { - fail("Failed writing RGB with exception " + ex.getMessage()); - } - - try { - final int[] brgb = new int[256 * 256]; - bImage = ImageIO.read(tempFile); - bImage.getRGB(0, 0, 256, 256, brgb, 0, 256); - assertArrayEquals(argb, brgb, "Round trip for RGB failed"); - } catch (final IOException ex) { - fail("Failed reading RGB with exception " + ex.getMessage()); - } - - // Test the ARGB (some semi-transparent alpha) case --------------------- - for (int i = 0; i < 256; i++) { - argb[i * 256 + i] &= 0x88ffffff; - } - bImage = new BufferedImage(256, 256, BufferedImage.TYPE_INT_ARGB); - bImage.setRGB(0, 0, 256, 256, argb, 0, 256); - try ( FileOutputStream fos = new FileOutputStream(tempFile); BufferedOutputStream bos = new BufferedOutputStream(fos)) { - parser.writeImage(bImage, bos, params); - bos.flush(); - } catch (IOException | ImageWriteException ex) { - fail("Failed writing ARGB with exception " + ex.getMessage()); - } - try { - final int[] brgb = new int[256 * 256]; - bImage = ImageIO.read(tempFile); - bImage.getRGB(0, 0, 256, 256, brgb, 0, 256); - assertArrayEquals(argb, brgb, "Round trip for ARGB failed"); - } catch (final IOException ex) { - fail("Failed reading ARGB with exception " + ex.getMessage()); - } - - } -} +/* + * 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.png; + +import java.awt.image.BufferedImage; +import java.io.BufferedOutputStream; +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import javax.imageio.ImageIO; +import org.apache.commons.imaging.ImageWriteException; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.*; + +/** + * Provides a test for the PngWriter using predictors + */ +public class PngWritePredictorTest { + + public PngWritePredictorTest() { + } + + @BeforeAll + public static void setUpClass() { + } + + @BeforeEach + public void setUp() { + } + + /** + * Populate an integer pixel array for a 256-by-256 image + * with varied colors across the image area and a white and + * black line down the main diagonal. + * @return a valid array of integers. + */ + private int[] populateARGB() { + //populate array with a blend of color components + final int[] argb = new int[256 * 256]; + for (int i = 0; i < 256; i++) { + for (int j = 0; j < 256; j++) { + final int red = i; + final int green = (255 - i); + final int blue = j; + argb[i * 256 + j] = ((((0xff00 | red) << 8) | green) << 8) | blue; + } + } + + // also draw a black and white strip down main diagonal + for (int i = 0; i < 256; i++) { + argb[i * 256 + i] = 0xff000000; + if (i < 255) { + argb[i * 256 + i + 1] = 0xffffffff; + } + } + return argb; + } + + @Test + void testWriteWithPredictor() { + final int[] argb = populateARGB(); + + // Test the RGB (no alpha) case --------------------- + BufferedImage bImage = new BufferedImage(256, 256, BufferedImage.TYPE_INT_RGB); + bImage.setRGB(0, 0, 256, 256, argb, 0, 256); + + File tempFile = null; + + try { + tempFile = File.createTempFile("PngWritePredictorRGB", ".png"); + } catch (final IOException ioex) { + fail("Failed to create temporary file, " + ioex.getMessage()); + } + final PngImagingParameters params = new PngImagingParameters(); + params.setPredictorEnabled(true); + final PngImageParser parser = new PngImageParser(); + try ( FileOutputStream fos = new FileOutputStream(tempFile); BufferedOutputStream bos = new BufferedOutputStream(fos)) { + parser.writeImage(bImage, bos, params); + bos.flush(); + } catch (IOException | ImageWriteException ex) { + fail("Failed writing RGB with exception " + ex.getMessage()); + } + + try { + final int[] brgb = new int[256 * 256]; + bImage = ImageIO.read(tempFile); + bImage.getRGB(0, 0, 256, 256, brgb, 0, 256); + assertArrayEquals(argb, brgb, "Round trip for RGB failed"); + } catch (final IOException ex) { + fail("Failed reading RGB with exception " + ex.getMessage()); + } + + // Test the ARGB (some semi-transparent alpha) case --------------------- + for (int i = 0; i < 256; i++) { + argb[i * 256 + i] &= 0x88ffffff; + } + bImage = new BufferedImage(256, 256, BufferedImage.TYPE_INT_ARGB); + bImage.setRGB(0, 0, 256, 256, argb, 0, 256); + try ( FileOutputStream fos = new FileOutputStream(tempFile); BufferedOutputStream bos = new BufferedOutputStream(fos)) { + parser.writeImage(bImage, bos, params); + bos.flush(); + } catch (IOException | ImageWriteException ex) { + fail("Failed writing ARGB with exception " + ex.getMessage()); + } + try { + final int[] brgb = new int[256 * 256]; + bImage = ImageIO.read(tempFile); + bImage.getRGB(0, 0, 256, 256, brgb, 0, 256); + assertArrayEquals(argb, brgb, "Round trip for ARGB failed"); + } catch (final IOException ex) { + fail("Failed reading ARGB with exception " + ex.getMessage()); + } + + } +} diff --git a/src/test/java/org/apache/commons/imaging/formats/pnm/PnmImageParserTest.java b/src/test/java/org/apache/commons/imaging/formats/pnm/PnmImageParserTest.java index b711d8a3..6aa3b51c 100644 --- a/src/test/java/org/apache/commons/imaging/formats/pnm/PnmImageParserTest.java +++ b/src/test/java/org/apache/commons/imaging/formats/pnm/PnmImageParserTest.java @@ -1,101 +1,101 @@ -/* - * 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.pnm; - -import org.apache.commons.imaging.ImageFormats; -import org.apache.commons.imaging.ImageInfo; -import org.apache.commons.imaging.ImageReadException; -import org.apache.commons.imaging.ImageWriteException; -import org.apache.commons.imaging.Imaging; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Test; - -import java.awt.image.BufferedImage; -import java.awt.image.DataBufferInt; -import java.io.IOException; -import java.nio.charset.Charset; -import java.nio.charset.StandardCharsets; - -import static org.junit.jupiter.api.Assertions.assertArrayEquals; -import static org.junit.jupiter.api.Assertions.assertEquals; - -public class PnmImageParserTest { - - private static final Charset US_ASCII = StandardCharsets.US_ASCII; - - @Test - public void testGetImageInfo_happyCase() throws ImageReadException, IOException { - final byte[] bytes = "P1\n3 2\n0 1 0\n1 0 1\n".getBytes(US_ASCII); - final PnmImagingParameters params = new PnmImagingParameters(); - final PnmImageParser underTest = new PnmImageParser(); - final ImageInfo results = underTest.getImageInfo(bytes, params); - assertEquals(results.getBitsPerPixel(), 1); - assertEquals(results.getWidth(), 3); - assertEquals(results.getHeight(), 2); - assertEquals(results.getNumberOfImages(), 1); - } - - @Test - public void testWriteImageRaw_happyCase() throws ImageWriteException, - ImageReadException, IOException { - final BufferedImage srcImage = new BufferedImage(10, 10, BufferedImage.TYPE_INT_ARGB); - - final byte[] dstBytes = Imaging.writeImageToBytes(srcImage, ImageFormats.PNM); - final BufferedImage dstImage = Imaging.getBufferedImage(dstBytes); - - assertEquals(srcImage.getWidth(), dstImage.getWidth()); - assertEquals(srcImage.getHeight(), dstImage.getHeight()); - - final DataBufferInt srcData = (DataBufferInt) srcImage.getRaster().getDataBuffer(); - final DataBufferInt dstData = (DataBufferInt) dstImage.getRaster().getDataBuffer(); - - for (int bank = 0; bank < srcData.getNumBanks(); bank++) { - final int[] actual = srcData.getData(bank); - final int[] expected = dstData.getData(bank); - - assertArrayEquals(actual, expected); - } - } - - /** - * If an invalid width is specified, should throw {@link ImageReadException} rather than - * {@link NumberFormatException}. - */ - @Test - public void testGetImageInfo_invalidWidth() { - final byte[] bytes = "P1\na 2\n0 0 0 0 0 0 0 0 0 0 0\n1 1 1 1 1 1 1 1 1 1 1\n".getBytes(US_ASCII); - final PnmImagingParameters params = new PnmImagingParameters(); - final PnmImageParser underTest = new PnmImageParser(); - Assertions.assertThrows(ImageReadException.class, () -> underTest.getImageInfo(bytes, params)); - } - - @Test - public void testGetImageInfo_invalidHeight() { - final byte[] bytes = "P1\n2 a\n0 0\n0 0\n0 0\n0 0\n0 0\n0 1\n1 1\n1 1\n1 1\n1 1\n1 1\n".getBytes(US_ASCII); - final PnmImagingParameters params = new PnmImagingParameters(); - final PnmImageParser underTest = new PnmImageParser(); - Assertions.assertThrows(ImageReadException.class, () -> underTest.getImageInfo(bytes, params)); - } - - @Test - public void testGetImageInfo_missingWidthValue() { - final byte[] bytes = "P7\nWIDTH \n".getBytes(US_ASCII); - final PnmImagingParameters params = new PnmImagingParameters(); - final PnmImageParser underTest = new PnmImageParser(); - Assertions.assertThrows(ImageReadException.class, () -> underTest.getImageInfo(bytes, params)); - } -} +/* + * 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.pnm; + +import org.apache.commons.imaging.ImageFormats; +import org.apache.commons.imaging.ImageInfo; +import org.apache.commons.imaging.ImageReadException; +import org.apache.commons.imaging.ImageWriteException; +import org.apache.commons.imaging.Imaging; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +import java.awt.image.BufferedImage; +import java.awt.image.DataBufferInt; +import java.io.IOException; +import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; + +import static org.junit.jupiter.api.Assertions.assertArrayEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; + +public class PnmImageParserTest { + + private static final Charset US_ASCII = StandardCharsets.US_ASCII; + + @Test + public void testGetImageInfo_happyCase() throws ImageReadException, IOException { + final byte[] bytes = "P1\n3 2\n0 1 0\n1 0 1\n".getBytes(US_ASCII); + final PnmImagingParameters params = new PnmImagingParameters(); + final PnmImageParser underTest = new PnmImageParser(); + final ImageInfo results = underTest.getImageInfo(bytes, params); + assertEquals(results.getBitsPerPixel(), 1); + assertEquals(results.getWidth(), 3); + assertEquals(results.getHeight(), 2); + assertEquals(results.getNumberOfImages(), 1); + } + + @Test + public void testWriteImageRaw_happyCase() throws ImageWriteException, + ImageReadException, IOException { + final BufferedImage srcImage = new BufferedImage(10, 10, BufferedImage.TYPE_INT_ARGB); + + final byte[] dstBytes = Imaging.writeImageToBytes(srcImage, ImageFormats.PNM); + final BufferedImage dstImage = Imaging.getBufferedImage(dstBytes); + + assertEquals(srcImage.getWidth(), dstImage.getWidth()); + assertEquals(srcImage.getHeight(), dstImage.getHeight()); + + final DataBufferInt srcData = (DataBufferInt) srcImage.getRaster().getDataBuffer(); + final DataBufferInt dstData = (DataBufferInt) dstImage.getRaster().getDataBuffer(); + + for (int bank = 0; bank < srcData.getNumBanks(); bank++) { + final int[] actual = srcData.getData(bank); + final int[] expected = dstData.getData(bank); + + assertArrayEquals(actual, expected); + } + } + + /** + * If an invalid width is specified, should throw {@link ImageReadException} rather than + * {@link NumberFormatException}. + */ + @Test + public void testGetImageInfo_invalidWidth() { + final byte[] bytes = "P1\na 2\n0 0 0 0 0 0 0 0 0 0 0\n1 1 1 1 1 1 1 1 1 1 1\n".getBytes(US_ASCII); + final PnmImagingParameters params = new PnmImagingParameters(); + final PnmImageParser underTest = new PnmImageParser(); + Assertions.assertThrows(ImageReadException.class, () -> underTest.getImageInfo(bytes, params)); + } + + @Test + public void testGetImageInfo_invalidHeight() { + final byte[] bytes = "P1\n2 a\n0 0\n0 0\n0 0\n0 0\n0 0\n0 1\n1 1\n1 1\n1 1\n1 1\n1 1\n".getBytes(US_ASCII); + final PnmImagingParameters params = new PnmImagingParameters(); + final PnmImageParser underTest = new PnmImageParser(); + Assertions.assertThrows(ImageReadException.class, () -> underTest.getImageInfo(bytes, params)); + } + + @Test + public void testGetImageInfo_missingWidthValue() { + final byte[] bytes = "P7\nWIDTH \n".getBytes(US_ASCII); + final PnmImagingParameters params = new PnmImagingParameters(); + final PnmImageParser underTest = new PnmImageParser(); + Assertions.assertThrows(ImageReadException.class, () -> underTest.getImageInfo(bytes, params)); + } +}