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  
18  package org.apache.commons.imaging.formats.jpeg;
19  
20  import static org.junit.Assert.assertEquals;
21  import static org.junit.Assert.assertNotNull;
22  
23  import java.awt.image.BufferedImage;
24  import java.io.File;
25  import java.util.Collection;
26  import java.util.HashMap;
27  import java.util.Map;
28  
29  import org.apache.commons.imaging.ImageInfo;
30  import org.apache.commons.imaging.ImageReadException;
31  import org.apache.commons.imaging.Imaging;
32  import org.apache.commons.imaging.ImagingConstants;
33  import org.apache.commons.imaging.common.ImageMetadata;
34  import org.apache.commons.imaging.util.Debug;
35  import org.junit.Test;
36  import org.junit.runner.RunWith;
37  import org.junit.runners.Parameterized;
38  
39  @RunWith(Parameterized.class)
40  public class JpegReadTest extends JpegBaseTest {
41  
42      private final File imageFile;
43  
44      @Parameterized.Parameters
45      public static Collection<File> data() throws Exception{
46          return getJpegImages();
47      }
48  
49      public JpegReadTest(final File imageFile) {
50          this.imageFile = imageFile;
51      }
52  
53      @Test
54      public void test() throws Exception {
55          final Map<String, Object> params = new HashMap<>();
56          final boolean ignoreImageData = isPhilHarveyTestImage(imageFile);
57          params.put(ImagingConstants.PARAM_KEY_READ_THUMBNAILS, Boolean.valueOf(!ignoreImageData));
58  
59          final ImageMetadata metadata = Imaging.getMetadata(imageFile, params);
60          // TODO only run this tests with images that have metadata...
61          //assertNotNull(metadata);
62          Debug.debug("metadata", metadata);
63          
64          Debug.debug("ICC profile", Imaging.getICCProfile(imageFile, params));
65  
66          final ImageInfo imageInfo = Imaging.getImageInfo(imageFile, params);
67          assertNotNull(imageInfo);
68          
69          try {
70              final BufferedImage image = Imaging.getBufferedImage(imageFile, params);
71              assertNotNull(image);
72          } catch (final ImageReadException imageReadException) {
73              assertEquals("Only sequential, baseline JPEGs are supported at the moment",
74                      imageReadException.getMessage());
75          }
76      }
77  
78  }