do not generate thumbnails for very small images
authorSvjatoslav Agejenko <svjatoslav@svjatoslav.eu>
Fri, 17 Oct 2014 20:07:47 +0000 (23:07 +0300)
committerSvjatoslav Agejenko <svjatoslav@svjatoslav.eu>
Fri, 17 Oct 2014 20:07:47 +0000 (23:07 +0300)
src/main/java/eu/svjatoslav/meviz/htmlindexer/metadata/fileTypes/Picture.java

index 02a29b9..dfc883f 100755 (executable)
@@ -1,7 +1,7 @@
 /*
  * Meviz - Various tools collection to work with multimedia.
  * Copyright (C) 2012, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
- * 
+ *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of version 2 of the GNU General Public License
  * as published by the Free Software Foundation.
@@ -34,56 +34,6 @@ import eu.svjatoslav.meviz.htmlindexer.metadata.Dimension;
 
 public class Picture extends AbstractFile {
 
-       private static final long serialVersionUID = -4156533490858298387L;
-
-       /**
-        * Picture dimensions.
-        */
-       private Dimension dimensions;
-
-       public Picture(final File parentDirectory, final String fileName)
-                       throws IOException, ImageFormatError {
-               super(parentDirectory, fileName);
-       }
-
-       private String computeThumbnailHash(final Dimension targetDimension) {
-
-               // compute new thumbnails hash number
-               final String forMagicHash = fileName + " "
-                               + String.valueOf(targetDimension.width) + " "
-                               + String.valueOf(targetDimension.height) + " "
-                               + String.valueOf(getFileLength()) + " "
-                               + Constants.THUMBNAIL_VERSION;
-
-               // System.out.println("Computing hash from: " + forMagicHash);
-               return Utils.getStringCrcAsHex(forMagicHash);
-       }
-
-       public Dimension getDimensions() {
-               return dimensions;
-       };
-
-       /**
-        * Get thumbnail file name for this image and desired thumbnail dimensions
-        * relative to designated thumbnails directory within parent directory.
-        */
-       public String getRelativeThumbnailFileName(final Dimension targetDimension) {
-               return FilePathParser.getFileNameWithoutExtension(fileName) + " ("
-                               + computeThumbnailHash(targetDimension) + ").jpeg";
-       }
-
-       @Override
-       public void updateFileMetainfo(final File parentDirectory)
-                       throws IOException {
-               BufferedImage image;
-               try {
-                       image = Utils.getBufferedImage(getFile(parentDirectory));
-               } catch (final ImageFormatError e) {
-                       throw new RuntimeException(e);
-               }
-               dimensions = new Dimension(image.getWidth(), image.getHeight());
-       }
-
        /**
         * Actual returned target thumbnail size will be adjusted from desired one
         * by attempting to generate as large as possible thumbnail, while not
@@ -123,7 +73,7 @@ public class Picture extends AbstractFile {
                final ArrayList<Dimension> result = new ArrayList<Dimension>();
                result.add(current);
 
-               while (current.getArea() > 100000) {
+               while (current.getArea() > 1000000) {
                        current = current.getScaled(0.5d);
                        result.add(current);
                }
@@ -186,4 +136,54 @@ public class Picture extends AbstractFile {
                return imageIcon.getImage();
        }
 
+       private static final long serialVersionUID = -4156533490858298387L;;
+
+       /**
+        * Picture dimensions.
+        */
+       private Dimension dimensions;
+
+       public Picture(final File parentDirectory, final String fileName)
+                       throws IOException, ImageFormatError {
+               super(parentDirectory, fileName);
+       }
+
+       private String computeThumbnailHash(final Dimension targetDimension) {
+
+               // compute new thumbnails hash number
+               final String forMagicHash = fileName + " "
+                               + String.valueOf(targetDimension.width) + " "
+                               + String.valueOf(targetDimension.height) + " "
+                               + String.valueOf(getFileLength()) + " "
+                               + Constants.THUMBNAIL_VERSION;
+
+               // System.out.println("Computing hash from: " + forMagicHash);
+               return Utils.getStringCrcAsHex(forMagicHash);
+       }
+
+       public Dimension getDimensions() {
+               return dimensions;
+       }
+
+       /**
+        * Get thumbnail file name for this image and desired thumbnail dimensions
+        * relative to designated thumbnails directory within parent directory.
+        */
+       public String getRelativeThumbnailFileName(final Dimension targetDimension) {
+               return FilePathParser.getFileNameWithoutExtension(fileName) + " ("
+                               + computeThumbnailHash(targetDimension) + ").jpeg";
+       }
+
+       @Override
+       public void updateFileMetainfo(final File parentDirectory)
+                       throws IOException {
+               BufferedImage image;
+               try {
+                       image = Utils.getBufferedImage(getFile(parentDirectory));
+               } catch (final ImageFormatError e) {
+                       throw new RuntimeException(e);
+               }
+               dimensions = new Dimension(image.getWidth(), image.getHeight());
+       }
+
 }