Content of file ImageModelJ2D.java.html
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml" lang="en"><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/><link rel="stylesheet" href="../../jacoco-resources/report.css" type="text/css"/><link rel="shortcut icon" href="../../jacoco-resources/report.gif" type="image/gif"/><title>ImageModelJ2D.java</title><link rel="stylesheet" href="../../jacoco-resources/prettify.css" type="text/css"/><script type="text/javascript" src="../../jacoco-resources/prettify.js"></script></head><body onload="window['PR_TAB_WIDTH']=4;prettyPrint()"><div class="breadcrumb" id="breadcrumb"><span class="info"><a href="../../jacoco-sessions.html" class="el_session">Sessions</a></span><a href="../../index.html" class="el_report">Mistral Examples Miscellaneous</a> > <a href="../index.html" class="el_bundle">image-core</a> > <a href="index.source.html" class="el_package">it.tidalwave.image.java2d</a> > <span class="el_source">ImageModelJ2D.java</span></div><h1>ImageModelJ2D.java</h1><pre class="source lang-java linenums">/*
* *********************************************************************************************************************
*
* Mistral: open source imaging engine
* http://tidalwave.it/projects/mistral
*
* Copyright (C) 2003 - 2023 by Tidalwave s.a.s. (http://tidalwave.it)
*
* *********************************************************************************************************************
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*
* *********************************************************************************************************************
*
* git clone https://bitbucket.org/tidalwave/mistral-src
* git clone https://github.com/tidalwave-it/mistral-src
*
* *********************************************************************************************************************
*/
package it.tidalwave.image.java2d;
import javax.annotation.Nonnegative;
import javax.annotation.Nonnull;
import java.util.HashMap;
import java.util.Map;
import java.awt.RenderingHints;
import java.awt.image.AffineTransformOp;
import java.awt.image.BufferedImage;
import java.awt.image.ColorModel;
import java.awt.image.RenderedImage;
import java.awt.image.SampleModel;
import it.tidalwave.image.EditableImage;
import it.tidalwave.image.ImageModel;
import it.tidalwave.image.InterpolationType;
import it.tidalwave.image.op.ImplementationFactory;
import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;
/***********************************************************************************************************************
*
* An opaque class which encapsulates all the image manipulation logics,
* and allows the implementation of these logics to be transparently changed
* (e.g. by using or not JAI, etc...)
*
* @author Fabrizio Giudici
*
**********************************************************************************************************************/
<span class="pc" id="L55">@NoArgsConstructor /* for serialization */ @Slf4j</span>
public class ImageModelJ2D extends ImageModel
{
<span class="fc" id="L58"> private static final Map<InterpolationType, Object> interpolationMap = new HashMap<>();</span>
<span class="fc" id="L60"> private static final Map<InterpolationType, Integer> interpolationMap2 = new HashMap<>();</span>
// private static final List<String> ICC_PROFILES_WORKAROUND = Arrays.asList(new String[]
// {
// "sRGB IEC61966-2.1", "Nikon sRGB 4.0.0.3000", "Nikon sRGB 4.0.0.3001"
// });
static
{
<span class="fc" id="L69"> interpolationMap.put(InterpolationType.FASTEST, RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR);</span>
<span class="fc" id="L70"> interpolationMap.put(InterpolationType.NEAREST_NEIGHBOR, RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR);</span>
<span class="fc" id="L71"> interpolationMap.put(InterpolationType.BILINEAR, RenderingHints.VALUE_INTERPOLATION_BILINEAR);</span>
<span class="fc" id="L72"> interpolationMap.put(InterpolationType.BICUBIC, RenderingHints.VALUE_INTERPOLATION_BICUBIC);</span>
<span class="fc" id="L73"> interpolationMap.put(InterpolationType.BEST, RenderingHints.VALUE_INTERPOLATION_BICUBIC);</span>
<span class="fc" id="L75"> interpolationMap2.put(InterpolationType.FASTEST, AffineTransformOp.TYPE_NEAREST_NEIGHBOR);</span>
<span class="fc" id="L76"> interpolationMap2.put(InterpolationType.NEAREST_NEIGHBOR, AffineTransformOp.TYPE_NEAREST_NEIGHBOR);</span>
<span class="fc" id="L77"> interpolationMap2.put(InterpolationType.BILINEAR, AffineTransformOp.TYPE_BILINEAR);</span>
<span class="fc" id="L78"> interpolationMap2.put(InterpolationType.BICUBIC, AffineTransformOp.TYPE_BILINEAR);</span>
<span class="fc" id="L79"> interpolationMap2.put(InterpolationType.BEST, AffineTransformOp.TYPE_BILINEAR);</span>
<span class="fc" id="L80"> }</span>
/*******************************************************************************************************************
*
* Creates a new EditableImage given a BufferedImage
*
* @param bufferedImage the buffered image
*
******************************************************************************************************************/
public ImageModelJ2D (@Nonnull final Object bufferedImage)
{
<span class="fc" id="L91"> super(bufferedImage);</span>
<span class="pc bpc" id="L93" title="1 of 2 branches missed."> if (!(bufferedImage instanceof BufferedImage))</span>
{
<span class="nc" id="L95"> throw new IllegalArgumentException("bufferedImage is not an instance of BufferedImage");</span>
}
<span class="fc" id="L97"> }</span>
/*******************************************************************************************************************
*
* {@inheritDoc}
*
******************************************************************************************************************/
@Override @Nonnull
public ImplementationFactory getFactory()
{
<span class="nc" id="L107"> return ImplementationFactoryJ2D.getDefault();</span>
}
/*******************************************************************************************************************
*
*
*
******************************************************************************************************************/
@Nonnull
public static EditableImage createImage (@Nonnull final BufferedImage bufferedImage) // FIXME: try to remove this
{
<span class="nc" id="L118"> return new EditableImage(new ImageModelJ2D(bufferedImage));</span>
}
/*******************************************************************************************************************
*
* {@inheritDoc}
*
******************************************************************************************************************/
@Override @Nonnegative
public int getWidth()
{
<span class="fc" id="L129"> return getBufferedImage().getWidth();</span>
}
/*******************************************************************************************************************
*
* {@inheritDoc}
*
******************************************************************************************************************/
@Override @Nonnegative
public int getHeight()
{
<span class="fc" id="L140"> return getBufferedImage().getHeight();</span>
}
/*******************************************************************************************************************
*
* {@inheritDoc}
*
******************************************************************************************************************/
@Override @Nonnull
public EditableImage.DataType getDataType()
{
<span class="fc" id="L151"> return EditableImage.DataType.valueOf(getBufferedImage().getRaster().getDataBuffer().getDataType());</span>
}
/*******************************************************************************************************************
*
* {@inheritDoc}
*
******************************************************************************************************************/
@Override @Nonnegative
public int getBandCount()
{
<span class="fc" id="L162"> return getBufferedImage().getRaster().getNumBands();</span>
}
/*******************************************************************************************************************
*
* {@inheritDoc}
*
******************************************************************************************************************/
@Override @Nonnull
public ColorModel getColorModel()
{
<span class="nc" id="L173"> return getBufferedImage().getColorModel();</span>
}
/*******************************************************************************************************************
*
* {@inheritDoc}
*
******************************************************************************************************************/
@Override @Nonnegative
public long getMemorySize()
{
<span class="nc bnc" id="L184" title="All 2 branches missed."> return (getBufferedImage() == null) ? 0 : getBufferedImage().getRaster().getDataBuffer().getSize();</span>
}
/*******************************************************************************************************************
*
* {@inheritDoc}
*
******************************************************************************************************************/
@Override @Nonnull
public EditableImage createCopy (final boolean copyContents)
{
<span class="nc" id="L195"> log.trace("createCopy({})", copyContents);</span>
<span class="nc" id="L197"> final var time = System.currentTimeMillis();</span>
<span class="nc" id="L198"> log.warn(">>>> **** WARNING CREATECOPY DISABLED");</span>
<span class="nc" id="L200"> final var result = getBufferedImage(); // createCopy2(copyContents);</span>
<span class="nc" id="L201"> log.trace(">>>> createCopy() completed ok in {} msec", (System.currentTimeMillis() - time));</span>
<span class="nc" id="L203"> return createImage(result);</span>
}
/* private BufferedImage createCopy2 (boolean copyContents)
{
SampleModel sampleModel = image.getSampleModel();
WritableRaster newRaster = Raster.createWritableRaster(sampleModel, null);
ColorModel colorModel = image.getColorModel();
BufferedImage result = new BufferedImage(colorModel, newRaster, false, getProperties(image));
if (copyContents)
copyDataBuffer(image.getRaster(), newRaster);
return result;
}*/
/*******************************************************************************************************************
*
* {@inheritDoc}
*
******************************************************************************************************************/
@Override @Nonnull @SuppressWarnings("unchecked")
public <T> T getInnerProperty (@Nonnull final Class<T> propertyClass)
{
<span class="fc bfc" id="L227" title="All 2 branches covered."> if (propertyClass.equals(BufferedImage.class))</span>
{
<span class="fc" id="L229"> return (T)getBufferedImage();</span>
}
<span class="pc bpc" id="L232" title="1 of 2 branches missed."> if (propertyClass.equals(SampleModel.class))</span>
{
<span class="fc" id="L234"> return (T)getBufferedImage().getSampleModel();</span>
}
<span class="nc bnc" id="L237" title="All 2 branches missed."> if (propertyClass.equals(ColorModel.class))</span>
{
<span class="nc" id="L239"> return (T)getBufferedImage().getColorModel();</span>
}
<span class="nc" id="L242"> throw new IllegalArgumentException(propertyClass.getName());</span>
}
/*******************************************************************************************************************
*
* {@inheritDoc}
*
******************************************************************************************************************/
@Override @Nonnull
protected RenderedImage toRenderedImageForSerialization()
{
<span class="nc" id="L253"> return getBufferedImage();</span>
}
/*******************************************************************************************************************
*
* {@inheritDoc}
*
******************************************************************************************************************/
@Override @Nonnull
protected Object toObjectForDeserialization (@Nonnull final RenderedImage renderedImage)
{
<span class="nc" id="L264"> return renderedImage;</span>
}
@Nonnull
private BufferedImage getBufferedImage()
{
<span class="fc" id="L270"> return (BufferedImage)model;</span>
}
/*
private void copyDataBuffer (WritableRaster raster, WritableRaster newRaster)
{
int type = raster.getDataBuffer().getDataType();
switch (type)
{
case DataBuffer.TYPE_BYTE:
DataBufferByte sourceDataBuffer1 = (DataBufferByte)raster.getDataBuffer();
DataBufferByte destDataBuffer1 = (DataBufferByte)newRaster.getDataBuffer();
System.arraycopy(sourceDataBuffer1.getData(), 0,
destDataBuffer1.getData(), 0,
sourceDataBuffer1.getData().length);
break;
case DataBuffer.TYPE_USHORT:
DataBufferUShort sourceDataBuffer2 = (DataBufferUShort)raster.getDataBuffer();
DataBufferUShort destDataBuffer2 = (DataBufferUShort)newRaster.getDataBuffer();
System.arraycopy(sourceDataBuffer2.getData(), 0,
destDataBuffer2.getData(), 0,
sourceDataBuffer2.getData().length);
break;
default:
throw new IllegalArgumentException("Unsupported databuffer type: " + type);
}
}
*/
}
</pre><div class="footer"><span class="right">Created with <a href="http://www.jacoco.org/jacoco">JaCoCo</a> 0.8.7.202105040129</span></div></body></html>