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> > <a href="index.source.html" class="el_package">it.tidalwave.northernwind.frontend.media.impl.interpolator</a> > <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 "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.
*
* *********************************************************************************************************************
*
*
* *********************************************************************************************************************
* #L%
*/
package it.tidalwave.northernwind.frontend.media.impl.interpolator;
import javax.annotation.Nonnull;
import java.text.DecimalFormat;
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="L45"> super("shootingData");</span>
<span class="fc" id="L46"> }</span>
@Override @Nonnull
public String interpolate (@Nonnull final String template, @Nonnull final Context context)
{
<span class="fc" id="L51"> final var tiff = context.getMetadata().getDirectory(TIFF.class);</span>
<span class="fc" id="L52"> final var exif = context.getMetadata().getDirectory(EXIF.class);</span>
<span class="fc" id="L53"> final var xmp = context.getMetadata().getDirectory(XMP.class);</span>
<span class="fc" id="L54"> final var xmpProperties = xmp.getXmpProperties();</span>
<span class="fc" id="L55"> final var modelMap = context.getModelMap();</span>
<span class="fc" id="L56"> final var lensMap = context.getLensMap();</span>
<span class="fc" id="L58"> final var builder = new StringBuilder();</span>
<span class="fc" id="L59"> final var cameraMake = tiff.getMake()</span>
<span class="fc" id="L60"> .or(exif::getMake)</span>
<span class="pc" id="L61"> .or(() -> Optional.ofNullable(xmpProperties.get("tiff:Make")))</span>
<span class="fc" id="L62"> .orElse("");</span>
<span class="fc" id="L63"> final var cameraModel = tiff.getModel()</span>
<span class="fc" id="L64"> .or(exif::getModel)</span>
<span class="pc" id="L65"> .or(() -> Optional.ofNullable(xmpProperties.get("tiff:Model")))</span>
<span class="fc" id="L66"> .orElse("");</span>
<span class="pc bpc" id="L68" title="2 of 4 branches missed."> var camera = (cameraMake + ((!cameraModel.isBlank() && !cameraMake.isBlank()) ? " " : "") + cameraModel).trim();</span>
<span class="fc" id="L69"> camera = modelMap.getOrDefault(camera, camera);</span>
<span class="fc" id="L70"> builder.append(camera);</span>
<span class="fc" id="L71"> builder.append(" + ");</span>
<span class="fc" id="L73"> final var lensMake = exif.getLensMake()</span>
<span class="fc" id="L74"> .or(() -> Optional.ofNullable(xmpProperties.get("exif:LensMake")))</span>
<span class="fc" id="L75"> .orElse("");</span>
<span class="fc" id="L76"> final var lensModel = exif.getLensModel()</span>
<span class="fc" id="L77"> .or(() -> Optional.ofNullable(xmpProperties.get("aux:Lens")))</span>
<span class="fc" id="L78"> .or(() -> Optional.ofNullable(xmpProperties.get("aux:LensID")))</span>
<span class="fc" id="L79"> .orElse("");</span>
<span class="pc bpc" id="L81" title="1 of 4 branches missed."> var lens = (lensMake + ((!lensModel.isBlank() && !lensMake.isBlank()) ? " " : "") + lensModel).trim();</span>
<span class="fc" id="L82"> lens = lensMap.getOrDefault(lens, lens);</span>
<span class="fc" id="L84"> builder.append(lens);</span>
<span class="fc" id="L85"> builder.append(" @ ");</span>
<span class="fc" id="L86"> exif.getFocalLength().ifPresent(fl -> builder.append(fl.intValue()).append(" mm, "));</span>
// FIXME: eventually teleconverter
<span class="fc" id="L88"> exif.getExposureTime().ifPresent(t -> builder.append(t).append(" sec @ ƒ/"));</span>
<span class="fc" id="L89"> exif.getFNumber().map(f -> new DecimalFormat("0.#").format(f.floatValue())).ifPresent(builder::append);</span>
<span class="fc" id="L91"> exif.getExposureBiasValue().ifPresent(exposureBiasValue -></span>
{
<span class="fc bfc" id="L93" title="All 2 branches covered."> if (exposureBiasValue.getNumerator() != 0)</span>
{
<span class="fc" id="L95"> builder.append(String.format(", %+.2f EV", exposureBiasValue.floatValue()));</span>
}
<span class="fc" id="L97"> });</span>
<span class="fc" id="L99"> exif.getISOSpeedRatings().ifPresent(iso -> builder.append(", ISO ").append(iso.intValue()));</span>
<span class="fc" id="L101"> return template.replace("$" + macro + "$", builder.toString());</span>
}
}
</pre><div class="footer"><span class="right">Created with <a href="http://www.jacoco.org/jacoco">JaCoCo</a> 0.8.9.202303310957</span></div></body></html>