View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *      http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  package org.apache.commons.imaging.formats.rgbe;
18  
19  import static org.junit.jupiter.api.Assertions.assertNotNull;
20  import static org.junit.jupiter.api.Assertions.assertThrows;
21  
22  import java.awt.image.BufferedImage;
23  import java.io.File;
24  import java.io.IOException;
25  import java.util.List;
26  
27  import org.apache.commons.imaging.ImageInfo;
28  import org.apache.commons.imaging.Imaging;
29  import org.apache.commons.imaging.ImagingException;
30  import org.apache.commons.imaging.bytesource.ByteSource;
31  import org.apache.commons.imaging.common.ImageMetadata;
32  import org.apache.commons.imaging.internal.Debug;
33  import org.apache.commons.imaging.test.TestResources;
34  import org.junit.jupiter.api.Test;
35  
36  public class RgbeReadTest extends RgbeBaseTest {
37  
38      @Test
39      public void test() throws IOException, ImagingException {
40          Debug.debug("start");
41  
42          final List<File> images = getRgbeImages();
43  
44          for (final File imageFile : images) {
45  
46              Debug.debug("imageFile", imageFile);
47  
48              final ImageMetadata metadata = Imaging.getMetadata(imageFile);
49              assertNotNull(metadata);
50  
51              final ImageInfo imageInfo = Imaging.getImageInfo(imageFile);
52              assertNotNull(imageInfo);
53  
54              final BufferedImage image = Imaging.getBufferedImage(imageFile);
55              assertNotNull(image);
56          }
57      }
58  
59      /**
60       * Test that a bad file does not gets the RgbeImageParser stuck reading it.
61       */
62      @Test
63      public void testErrorDecompressingInvalidFile() {
64          // From IMAGING-219
65          final File inputFile = TestResources.resourceToFile("/IMAGING-219/timeout-9713502c9c371f1654b493650c16ab17c0444369.hdr");
66          final ByteSource byteSourceFile = ByteSource.file(inputFile);
67          final RgbeImagingParameters params = new RgbeImagingParameters();
68          assertThrows(ImagingException.class, () -> new RgbeImageParser().getBufferedImage(byteSourceFile, params));
69      }
70  }