Skip to content
Snippets Groups Projects
Commit 7fefba93 authored by anttil's avatar anttil
Browse files

BIS-676 / SP-1229: Do not abort image merge just because image component size...

BIS-676 / SP-1229: Do not abort image merge just because image component size could not be determined.

SVN: 31125
parent 216a8093
No related branches found
No related tags found
No related merge requests found
...@@ -18,10 +18,15 @@ package ch.systemsx.cisd.common.image; ...@@ -18,10 +18,15 @@ package ch.systemsx.cisd.common.image;
import java.awt.Color; import java.awt.Color;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
import java.awt.image.ColorModel;
import org.apache.log4j.Logger;
import ch.systemsx.cisd.common.logging.LogCategory;
import ch.systemsx.cisd.common.logging.LogFactory;
/** /**
* A class for calculating a mixed color from a set of pure colors of different relative * A class for calculating a mixed color from a set of pure colors of different relative intensities.
* intensities.
* <p> * <p>
* It uses an additive (physiological) color mixture, optionally weighted. * It uses an additive (physiological) color mixture, optionally weighted.
* *
...@@ -34,6 +39,8 @@ public class MixColors ...@@ -34,6 +39,8 @@ public class MixColors
private static final float MAX_COMPONENT_VALUE_FLOAT = MAX_COMPONENT_VALUE; private static final float MAX_COMPONENT_VALUE_FLOAT = MAX_COMPONENT_VALUE;
private static final Logger operationLog = LogFactory.getLogger(LogCategory.OPERATION, MixColors.class);
private static int getMaxComponent(int r, int g, int b) private static int getMaxComponent(int r, int g, int b)
{ {
int cmax = (r > g) ? r : g; int cmax = (r > g) ? r : g;
...@@ -252,10 +259,9 @@ public class MixColors ...@@ -252,10 +259,9 @@ public class MixColors
* Calculate a new image by mixing the given gray-scale </var>images</var>. * Calculate a new image by mixing the given gray-scale </var>images</var>.
* *
* @param images The images to merge. * @param images The images to merge.
* @param quadratic If <code>true</code>, use a quadratic (weighted) additive color mixture, * @param quadratic If <code>true</code>, use a quadratic (weighted) additive color mixture, otherwise use a linear (unweighted) additive color
* otherwise use a linear (unweighted) additive color mixture. * mixture.
* @param saturationEnhancementFactor If > 0, perform a saturation enhancement step with the * @param saturationEnhancementFactor If > 0, perform a saturation enhancement step with the given factor.
* given factor.
* @return Returns the mixed image. * @return Returns the mixed image.
*/ */
public static BufferedImage mixImages(BufferedImage[] images, Color[] colors, public static BufferedImage mixImages(BufferedImage[] images, Color[] colors,
...@@ -320,7 +326,17 @@ public class MixColors ...@@ -320,7 +326,17 @@ public class MixColors
for (int i = 0; i < numberOfImages; ++i) for (int i = 0; i < numberOfImages; ++i)
{ {
isGrayscale = isGrayscale && images[i].getColorModel().getNumColorComponents() == 1; isGrayscale = isGrayscale && images[i].getColorModel().getNumColorComponents() == 1;
if (images[i].getColorModel().getComponentSize(0) != 8) ColorModel colorModel = images[i].getColorModel();
int componentSize;
try
{
componentSize = colorModel.getComponentSize(0);
} catch (NullPointerException e)
{
operationLog.info("Could not determine the componentSize of an image. Potentially using non 8-bit image in merging");
continue;
}
if (componentSize != 8)
{ {
throw new IllegalArgumentException("Only 8-bit images can be merged."); throw new IllegalArgumentException("Only 8-bit images can be merged.");
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment