changeset 1078:ec1c3de5c70b

grayscale images do not use sRGB colorspace any more (fixes bug on Linux OpenJDK 1.6). may change appearance in some cases.
author robcast
date Wed, 23 May 2012 17:25:04 +0200
parents 05960888493c
children 9c2abceb05c5
files common/src/main/java/digilib/image/ImageLoaderDocuImage.java
diffstat 1 files changed, 15 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/common/src/main/java/digilib/image/ImageLoaderDocuImage.java	Thu May 17 23:23:22 2012 +0200
+++ b/common/src/main/java/digilib/image/ImageLoaderDocuImage.java	Wed May 23 17:25:04 2012 +0200
@@ -65,7 +65,7 @@
 public class ImageLoaderDocuImage extends ImageInfoDocuImage {
 
     /** DocuImage version */
-    public static final String version = "ImageLoaderDocuImage 2.1.5";
+    public static final String version = "ImageLoaderDocuImage 2.1.6a";
 
     /** image object */
     protected BufferedImage img;
@@ -97,6 +97,8 @@
     /* lookup table for false-color */
     protected static LookupTable mapBgrByteTable;
     protected static boolean needsMapBgr = false;
+    /* set destination type to sRGB if available, even for non-RGB images */
+    protected static boolean alwaysSetDestSrgb = false;
 
     static {
         /*
@@ -317,7 +319,6 @@
             throw new FileOpException("Can't find Reader to load File!");
         }
         ImageReader reader = readers.next();
-        /* are there more readers? */
         logger.debug("ImageIO: this reader: " + reader.getClass());
         /*
          * while (readers.hasNext()) { logger.debug("ImageIO: next reader: " +
@@ -340,23 +341,28 @@
             if (prescale > 1) {
                 readParam.setSourceSubsampling(prescale, prescale, 0, 0);
             }
-            // try to restrict target color space to sRGB
+            // try to set target color space to sRGB
             for (Iterator<ImageTypeSpecifier> i = reader.getImageTypes(0); i.hasNext();) {
                 ImageTypeSpecifier type = (ImageTypeSpecifier) i.next();
                 ColorModel cm = type.getColorModel();
                 ColorSpace cs = cm.getColorSpace();
-                // logger.debug("loadSubimage: possible color model:"+cm+" color space:"+cs);
+                logger.debug("loadSubimage: possible color model:"+cm+" color space:"+cs);
+                if (cs.getNumComponents() < 3 && ! ImageLoaderDocuImage.alwaysSetDestSrgb) {
+                    // if the first type is not RGB do nothing
+                    logger.debug("loadSubimage: image is not RGB " + type);
+                    break;
+                }
                 if (cs.isCS_sRGB()) {
                     logger.debug("loadSubimage: substituted sRGB destination type " + type);
                     readParam.setDestinationType(type);
-                    // break;
+                    break;
                 }
             }
             // read image
             logger.debug("loadSubimage: loading..");
             img = reader.read(0, readParam);
             logger.debug("loadSubimage: loaded");
-            // invalidate image size
+            // invalidate image size if it was set
             imageSize = null;
             // downconvert highcolor images
             if (img.getColorModel().getComponentSize(0) > 8) {
@@ -365,9 +371,9 @@
                 if (img.getColorModel().hasAlpha()) {
                     type = BufferedImage.TYPE_INT_ARGB;
                 }
-                BufferedImage dest = new BufferedImage(img.getWidth(), img.getHeight(), type);
-                dest.createGraphics().drawImage(img, null, 0, 0);
-                img = dest;
+                BufferedImage lcImg = new BufferedImage(img.getWidth(), img.getHeight(), type);
+                lcImg.createGraphics().drawImage(img, null, 0, 0);
+                img = lcImg;
             }
         } catch (IOException e) {
             throw new FileOpException("Unable to load File!", e);