Skip to content

Content of file ShootingDataInterpolator.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>ShootingDataInterpolator.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">NorthernWind :: Frontend :: Media</a> &gt; <a href="index.source.html" class="el_package">it.tidalwave.northernwind.frontend.media.impl.interpolator</a> &gt; <span class="el_source">ShootingDataInterpolator.java</span></div><h1>ShootingDataInterpolator.java</h1><pre class="source lang-java linenums">/*
 * #%L
 * *********************************************************************************************************************
 *
 * NorthernWind - lightweight CMS
 * http://northernwind.tidalwave.it - git clone https://bitbucket.org/tidalwave/northernwind-src.git
 * %%
 * Copyright (C) 2011 - 2023 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.
 *
 * *********************************************************************************************************************
 *
 *
 * *********************************************************************************************************************
 * #L%
 */
package it.tidalwave.northernwind.frontend.media.impl.interpolator;

import java.text.DecimalFormat;
import javax.annotation.Nonnull;
import java.util.Map;
import java.util.Optional;
import it.tidalwave.image.metadata.EXIF;
import it.tidalwave.image.metadata.TIFF;
import it.tidalwave.image.metadata.XMP;

/***********************************************************************************************************************
 *
 * @author  Fabrizio Giudici
 *
 **********************************************************************************************************************/
public class ShootingDataInterpolator extends MetadataInterpolatorSupport
  {
    public ShootingDataInterpolator()
      {
<span class="fc" id="L46">        super(&quot;shootingData&quot;);</span>
<span class="fc" id="L47">      }</span>

    @Override @Nonnull
    public String interpolate (@Nonnull final String template, @Nonnull final Context context)
      {
<span class="fc" id="L52">        final TIFF tiff = context.getMetadata().getDirectory(TIFF.class);</span>
<span class="fc" id="L53">        final EXIF exif = context.getMetadata().getDirectory(EXIF.class);</span>
<span class="fc" id="L54">        final XMP xmp = context.getMetadata().getDirectory(XMP.class);</span>
<span class="fc" id="L55">        final Map&lt;String, String&gt; xmpProperties = xmp.getXmpProperties();</span>
<span class="fc" id="L56">        final Map&lt;String, String&gt; modelMap = context.getModelMap();</span>
<span class="fc" id="L57">        final Map&lt;String, String&gt; lensMap = context.getLensMap();</span>

<span class="fc" id="L59">        final StringBuilder builder = new StringBuilder();</span>
<span class="fc" id="L60">        String cameraMake = tiff.getMake()</span>
<span class="pc" id="L61">                                .or(() -&gt; exif.getMake())</span>
<span class="pc" id="L62">                                .or(() -&gt; Optional.ofNullable(xmpProperties.get(&quot;tiff:Make&quot;)))</span>
<span class="fc" id="L63">                                .orElse(&quot;&quot;);</span>
<span class="fc" id="L64">        String cameraModel = tiff.getModel()</span>
<span class="pc" id="L65">                                 .or(() -&gt; exif.getModel())</span>
<span class="pc" id="L66">                                 .or(() -&gt; Optional.ofNullable(xmpProperties.get(&quot;tiff:Model&quot;)))</span>
<span class="fc" id="L67">                                 .orElse(&quot;&quot;);</span>

<span class="pc bpc" id="L69" title="2 of 4 branches missed.">        String camera = (cameraMake + ((!cameraModel.isBlank() &amp;&amp; !cameraMake.isBlank()) ? &quot; &quot; : &quot;&quot;) + cameraModel).trim();</span>
<span class="fc" id="L70">        camera = modelMap.getOrDefault(camera, camera);</span>
<span class="fc" id="L71">        builder.append(camera);</span>
<span class="fc" id="L72">        builder.append(&quot; + &quot;);</span>

<span class="fc" id="L74">        String lensMake = exif.getLensMake()</span>
<span class="fc" id="L75">                              .or(() -&gt; Optional.ofNullable(xmpProperties.get(&quot;exif:LensMake&quot;)))</span>
<span class="fc" id="L76">                              .orElse(&quot;&quot;);</span>
<span class="fc" id="L77">        String lensModel = exif.getLensModel()</span>
<span class="fc" id="L78">                               .or(() -&gt; Optional.ofNullable(xmpProperties.get(&quot;aux:Lens&quot;)))</span>
<span class="fc" id="L79">                               .or(() -&gt; Optional.ofNullable(xmpProperties.get(&quot;aux:LensID&quot;)))</span>
<span class="fc" id="L80">                               .orElse(&quot;&quot;);</span>

<span class="pc bpc" id="L82" title="1 of 4 branches missed.">        String lens = (lensMake + ((!lensModel.isBlank() &amp;&amp; !lensMake.isBlank()) ? &quot; &quot; : &quot;&quot;) + lensModel).trim();</span>
<span class="fc" id="L83">        lens = lensMap.getOrDefault(lens, lens);</span>

<span class="fc" id="L85">        builder.append(lens);</span>
<span class="fc" id="L86">        builder.append(&quot; @ &quot;);</span>
<span class="fc" id="L87">        exif.getFocalLength().ifPresent(fl -&gt; builder.append(fl.intValue()).append(&quot; mm, &quot;));</span>
        // FIXME: eventually teleconverter
eventually teleconverter
<span class="fc" id="L89"> exif.getExposureTime().ifPresent(t -&gt; builder.append(t).append(&quot; sec @ \u0192/&quot;));</span> <span class="fc" id="L90"> exif.getFNumber().map(f -&gt; new DecimalFormat(&quot;0.#&quot;).format(f.floatValue())).ifPresent(builder::append);</span> <span class="fc" id="L92"> exif.getExposureBiasValue().ifPresent(exposureBiasValue -&gt;</span> { <span class="fc bfc" id="L94" title="All 2 branches covered."> if (exposureBiasValue.getNumerator() != 0)</span> { <span class="fc" id="L96"> builder.append(String.format(&quot;, %+.2f EV&quot;, exposureBiasValue.floatValue()));</span> } <span class="fc" id="L98"> });</span> <span class="fc" id="L100"> exif.getISOSpeedRatings().ifPresent(iso -&gt; builder.append(&quot;, ISO &quot;).append(iso.intValue()));</span> <span class="fc" id="L102"> return template.replace(&quot;$&quot; + macro + &quot;$&quot;, builder.toString());</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>