From 31d7560eeccb3245e5d8ab4f302fb55b344d3df4 Mon Sep 17 00:00:00 2001
From: felmer <felmer>
Date: Wed, 10 Sep 2014 06:54:19 +0000
Subject: [PATCH] SSDM-782: bug in Hdf5ThumbnailGenerator fixed: In case of
 original RGB images only thumbnails for one color were correct.

SVN: 32427
---
 .../dss/etl/Hdf5ThumbnailGenerator.java        | 18 +++++++-----------
 1 file changed, 7 insertions(+), 11 deletions(-)

diff --git a/screening/source/java/ch/systemsx/cisd/openbis/dss/etl/Hdf5ThumbnailGenerator.java b/screening/source/java/ch/systemsx/cisd/openbis/dss/etl/Hdf5ThumbnailGenerator.java
index d2701402984..b0e4a87b871 100644
--- a/screening/source/java/ch/systemsx/cisd/openbis/dss/etl/Hdf5ThumbnailGenerator.java
+++ b/screening/source/java/ch/systemsx/cisd/openbis/dss/etl/Hdf5ThumbnailGenerator.java
@@ -434,9 +434,7 @@ public class Hdf5ThumbnailGenerator implements IHDF5WriterClient
     private List<ThumbnailData> generateThumbnailInternally(ImageFileInfo imageFileInfo,
             String imageIdOrNull, ByteArrayOutputStream bufferOutputStream) throws IOException
     {
-        BufferedImage image =
-                loadUnchangedImage(imageFileInfo.getImageRelativePath(), imageIdOrNull);
-
+        BufferedImage image = loadUnchangedImage(imageFileInfo.getImageRelativePath(), imageIdOrNull);
         int widht = thumbnailsStorageFormat.getMaxWidth();
         int height = thumbnailsStorageFormat.getMaxHeight();
         if (thumbnailsStorageFormat.getZoomLevel() != null)
@@ -445,17 +443,15 @@ public class Hdf5ThumbnailGenerator implements IHDF5WriterClient
             height = (int) Math.round(thumbnailsStorageFormat.getZoomLevel() * image.getHeight());
         }
 
-        BufferedImage thumbnail =
-                ImageUtil.rescale(image, widht, height, false,
-                        thumbnailsStorageFormat.isHighQuality());
-
+        boolean highQuality = thumbnailsStorageFormat.isHighQuality();
+        BufferedImage rescaledImage = ImageUtil.rescale(image, widht, height, false, highQuality);
+        
         final List<ThumbnailData> thumbnails = new ArrayList<ThumbnailData>();
         for (String channelCode : getChannelsToProcess(imageFileInfo.getChannelCode()))
         {
-            thumbnail =
-                    applyTransformationsChain(thumbnail, channelCode,
-                            channelColors.get(channelCode));
-
+            ColorComponent colorComponent = channelColors.get(channelCode);
+            BufferedImage thumbnail = applyTransformationsChain(rescaledImage, channelCode, colorComponent);
+            bufferOutputStream.reset();
             thumbnailsStorageFormat.getFileFormat().writeImage(thumbnail, bufferOutputStream);
             thumbnails.add(new ThumbnailData(bufferOutputStream.toByteArray(),
                     thumbnail.getWidth(), thumbnail.getHeight(), thumbnail.getColorModel()
-- 
GitLab