Content of file HistogramJava2D.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>HistogramJava2D.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 Operations</a> > <a href="index.source.html" class="el_package">it.tidalwave.image.java2d</a> > <span class="el_source">HistogramJava2D.java</span></div><h1>HistogramJava2D.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 java.awt.image.BufferedImage;
import java.awt.image.Raster;
import java.awt.image.RenderedImage;
import it.tidalwave.image.Histogram;
import it.tidalwave.image.render.PreviewSettings;
import lombok.extern.slf4j.Slf4j;
/***********************************************************************************************************************
*
* @author Fabrizio Giudici
*
**********************************************************************************************************************/
<span class="nc" id="L41">@Slf4j</span>
public class HistogramJava2D extends Histogram
{
private RenderedImage renderedImage;
private int[][] bandData;
private int[] max;
private int[] min;
private int shift;
/*******************************************************************************************************************
*
* @param image
*
******************************************************************************************************************/
/* package */ HistogramJava2D (final RenderedImage renderedImage)
{
<span class="nc" id="L58"> super(renderedImage);</span>
<span class="nc" id="L59"> this.renderedImage = renderedImage;</span>
<span class="nc" id="L60"> compute();</span>
<span class="nc" id="L61"> }</span>
/*******************************************************************************************************************
*
* {@inheritDoc}
*
******************************************************************************************************************/
@Override
public int[] getFrequencies (final int band)
{
<span class="nc" id="L71"> validateBand(band);</span>
<span class="nc" id="L73"> synchronized (this)</span>
{
<span class="nc bnc" id="L75" title="All 2 branches missed."> if (bandData == null)</span>
{
<span class="nc" id="L77"> compute();</span>
}
<span class="nc" id="L79"> }</span>
<span class="nc" id="L81"> return bandData[band];</span>
}
/*******************************************************************************************************************
*
* {@inheritDoc}
*
******************************************************************************************************************/
@Override
public int getMin (final int band)
{
<span class="nc" id="L92"> validateBand(band);</span>
<span class="nc" id="L94"> return min[band];</span>
}
/*******************************************************************************************************************
*
* {@inheritDoc}
*
******************************************************************************************************************/
@Override
public int getMax (final int band)
{
<span class="nc" id="L105"> validateBand(band);</span>
<span class="nc" id="L107"> return max[band];</span>
}
/*******************************************************************************************************************
*
******************************************************************************************************************/
private void compute()
{
<span class="nc" id="L115"> log.info("compute()");</span>
<span class="nc" id="L116"> bandCount = renderedImage.getSampleModel().getNumBands();</span>
<span class="nc" id="L117"> bitsPerBand = renderedImage.getSampleModel().getSampleSize(0);</span>
<span class="nc" id="L118"> shift = 0;</span>
<span class="nc bnc" id="L120" title="All 2 branches missed."> if (bitsPerBand == 16)</span>
{
<span class="nc" id="L122"> shift = 16 - 8; // FIXME: should be only for 12bbp files such as NEF </span>
| should be only for 12bbp files such as NEF | |
}
<span class="nc" id="L125"> bandData = new int[bandCount][1 << (bitsPerBand - shift)];</span>
<span class="nc" id="L126"> min = new int[bandCount];</span>
<span class="nc" id="L127"> max = new int[bandCount];</span>
<span class="nc" id="L128"> log.info(">>>> Allocated bandData[" + bandData.length + "][" + bandData[0].length + "]");</span>
<span class="nc" id="L129"> genericCompute();</span>
//DataBuffer dataBuffer = raster.getDataBuffer();
//int dataBufferSize = DataBuffer.getDataTypeSize(dataBuffer.getDataType());
// if (dataBuffer instanceof DataBufferInt)
// DataBufferInt dbs = (DataBufferInt)dataBuffer;
// int[][] bankData = dbs.getBankData();
// log.info(">>>> bankData[" + bankData.length + "][" + bankData[0].length + "]");
// int[] offsets = dbs.getOffsets();
// int scanStride = w;
<span class="nc" id="L139"> }</span>
/*******************************************************************************************************************
*
* {@inheritDoc}
*
******************************************************************************************************************/
@Override
public it.tidalwave.image.Histogram getPreview (final PreviewSettings previewSetting)
{
<span class="nc" id="L149"> final var previewHistogram = new HistogramJava2D(null);</span>
<span class="nc" id="L150"> previewHistogram.bandCount = bandCount;</span>
<span class="nc" id="L151"> previewHistogram.bandData = new int[bandCount][];</span>
<span class="nc" id="L153"> final var lut8bit = previewSetting.getLookupTable8bit().getTable();</span>
<span class="nc" id="L154"> final var lut16bit = previewSetting.getLookupTable16bit().getTable();</span>
<span class="nc bnc" id="L156" title="All 2 branches missed."> for (var band = 0; band < bandCount; band++)</span>
{
<span class="nc" id="L158"> final var len = bandData[band].length;</span>
<span class="nc" id="L159"> previewHistogram.bandData[band] = new int[len];</span>
<span class="nc bnc" id="L161" title="All 2 branches missed."> for (var i = 0; i < len; i++)</span>
{
<span class="nc bnc" id="L163" title="All 2 branches missed."> final var dst = (len <= 256) ? (lut8bit[band][i] & 0xff) : (lut16bit[band][i] & 0xffff);</span>
<span class="nc" id="L164"> previewHistogram.bandData[band][dst] += bandData[band][i];</span>
}
}
<span class="nc" id="L168"> return previewHistogram;</span>
}
/*******************************************************************************************************************
*
* Works with every kind of data buffer, but it's not fast.
*
* @param raster
* @param shift
* @param w
* @param h
* @param first
*
******************************************************************************************************************/
private void genericCompute()
{
<span class="nc" id="L184"> final Raster raster = ((BufferedImage)image).getRaster();</span>
<span class="nc" id="L185"> final var w = renderedImage.getWidth();</span>
<span class="nc" id="L186"> final var h = renderedImage.getHeight();</span>
<span class="nc" id="L187"> var first = true;</span>
<span class="nc bnc" id="L189" title="All 2 branches missed."> for (var y = 0; y < h; y++)</span>
{
<span class="nc bnc" id="L191" title="All 2 branches missed."> for (var x = 0; x < w; x++)</span>
{
<span class="nc bnc" id="L193" title="All 2 branches missed."> for (var b = 0; b < bandCount; b++)</span>
{
<span class="nc" id="L195"> final var v = raster.getSample(x, y, b) >> shift;</span>
<span class="nc" id="L197"> bandData[b][v]++;</span>
<span class="nc bnc" id="L199" title="All 2 branches missed."> if (first)</span>
{
<span class="nc" id="L201"> min[b] = max[b] = v;</span>
}
else
{
<span class="nc bnc" id="L206" title="All 2 branches missed."> if (v < min[b])</span>
{
<span class="nc" id="L208"> min[b] = v;</span>
}
<span class="nc bnc" id="L211" title="All 2 branches missed."> else if (v > max[b])</span>
{
<span class="nc" id="L213"> max[b] = v;</span>
}
}
}
<span class="nc" id="L218"> first = false;</span>
}
}
<span class="nc" id="L221"> }</span>
}
</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>