Content of file PaintJ2DOp.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>PaintJ2DOp.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 Core</a> &gt; <a href="index.source.html" class="el_package">it.tidalwave.image.java2d</a> &gt; <span class="el_source">PaintJ2DOp.java</span></div><h1>PaintJ2DOp.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 &quot;License&quot;); 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 &quot;AS IS&quot; 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.RenderingHints;
import java.awt.image.BufferedImage;
import java.awt.image.DataBuffer;
import java.awt.image.LookupOp;
import java.awt.image.LookupTable;
import it.tidalwave.image.EditableImage;
import it.tidalwave.image.op.OperationImplementation;
import it.tidalwave.image.op.PaintOp;
import it.tidalwave.image.render.PreviewSettings;
import lombok.extern.slf4j.Slf4j;

/***********************************************************************************************************************
 *
 * @author Fabrizio Giudici
 *
 **********************************************************************************************************************/
<span class="nc" id="L45">@Slf4j</span>
<span class="nc" id="L46">public class PaintJ2DOp extends OperationImplementation&lt;PaintOp, BufferedImage&gt;</span>
  {
    /*******************************************************************************************************************
     *
     * {@inheritDoc}
     *
     ******************************************************************************************************************/
    @Override
    protected BufferedImage execute (final PaintOp operation,
                                     final EditableImage image,
                                     final BufferedImage bufferedImage)
      {
<span class="nc" id="L58">        final var x = operation.getX();</span>
<span class="nc" id="L59">        final var y = operation.getY();</span>
<span class="nc" id="L60">        final var w = operation.getW();</span>
<span class="nc" id="L61">        final var h = operation.getH();</span>
<span class="nc" id="L62">        final var g2 = operation.getGraphics2D();</span>
<span class="nc" id="L63">        final var previewSettings = operation.getPreviewSettings();</span>
<span class="nc" id="L64">        final var imageObserver = operation.getImageObserver();</span>
<span class="nc" id="L65">        final var quality = operation.getQuality();</span>
<span class="nc" id="L66">        log.debug(&quot;execute(&quot; + x + &quot;, &quot; + y + &quot;, &quot; + w + &quot;, &quot; + h + &quot;, &quot; + quality + &quot;)&quot;);</span>

<span class="nc bnc" id="L68" title="All 2 branches missed.">        if (w != 0)</span>
          {
<span class="nc" id="L70">            final var saveRenderingHints = g2.getRenderingHint(RenderingHints.KEY_INTERPOLATION);</span>
<span class="nc" id="L71">            final var interpolation = Java2DUtils.findRenderingHintsInterpolation(quality);</span>
<span class="nc" id="L72">            g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, interpolation);</span>
<span class="nc" id="L73">            g2.drawImage(applyPreviewSettings(bufferedImage, previewSettings), x, y, w, h, imageObserver);</span>

<span class="nc bnc" id="L75" title="All 2 branches missed.">            if (saveRenderingHints != null)</span>
              {
<span class="nc" id="L77">                g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, saveRenderingHints);</span>
              }
<span class="nc" id="L79">          }</span>

        else
          {
<span class="nc" id="L83">            g2.drawImage(applyPreviewSettings(bufferedImage, previewSettings), x, y, imageObserver);</span>
          }

<span class="nc" id="L86">        return bufferedImage;</span>
      }

    /*******************************************************************************************************************
     *
     *
     ******************************************************************************************************************/

    // FIXME: ottimizzalo, fallo lavorare solo sulla subimage visualizzata
    // FIXME: aggiungi un parametro sulla qualita', da mettere dentro PreviewSettings
    private BufferedImage applyPreviewSettings (final BufferedImage image, final PreviewSettings previewSettings)
      {
<span class="nc" id="L98">        var theImage = image;</span>

<span class="nc bnc" id="L100" title="All 2 branches missed.">        if (previewSettings != null)</span>
          {
<span class="nc" id="L102">            final var size = DataBuffer.getDataTypeSize(image.getSampleModel().getDataType());</span>
<span class="nc" id="L103">            LookupTable lookupTable = null;</span>

<span class="nc bnc" id="L105" title="All 3 branches missed.">            switch (size)</span>
              {
                case 8:
                case 32: // packed model
<span class="nc" id="L109">                  lookupTable = previewSettings.getLookupTable8bit();</span>

<span class="nc" id="L111">                  break;</span>

                case 16:
<span class="nc" id="L114">                  lookupTable = previewSettings.getLookupTable16bit();</span>

<span class="nc" id="L116">                  break;</span>

                default:
<span class="nc" id="L119">                  throw new IllegalArgumentException(&quot;DataSize is &quot; + size);</span>
              }

<span class="nc bnc" id="L122" title="All 2 branches missed.">            if (lookupTable != null)</span>
              {
<span class="nc" id="L124">                final var lOp = new LookupOp(lookupTable, null); // FIXME: hints</span>
hints
<span class="nc" id="L125"> Java2DUtils.logImage(log, &quot;applyPreviewSettings: &quot;, image);</span> <span class="nc" id="L126"> theImage = lOp.filter(image, null);</span> } } <span class="nc" id="L130"> return theImage;</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>