Skip to content

Package: ShootingDataInterpolator

ShootingDataInterpolator

nameinstructionbranchcomplexitylinemethod
ShootingDataInterpolator()
M: 0 C: 4
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
interpolate(String, MetadataInterpolator.Context)
M: 176 C: 0
0%
M: 8 C: 0
0%
M: 5 C: 0
0%
M: 36 C: 0
0%
M: 1 C: 0
0%
lambda$interpolate$0(Map)
M: 6 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
lambda$interpolate$1(Map)
M: 6 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
lambda$interpolate$2(Map)
M: 6 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
lambda$interpolate$3(Map)
M: 6 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
lambda$interpolate$4(Map)
M: 6 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
lambda$interpolate$5(StringBuilder, Rational)
M: 8 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
lambda$interpolate$6(StringBuilder, Rational)
M: 7 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
lambda$interpolate$7(Rational)
M: 9 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
lambda$interpolate$8(StringBuilder, Rational)
M: 17 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
lambda$interpolate$9(StringBuilder, Integer)
M: 8 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*
2: * *************************************************************************************************************************************************************
3: *
4: * NorthernWind - lightweight CMS
5: * http://tidalwave.it/projects/northernwind
6: *
7: * Copyright (C) 2011 - 2025 Tidalwave s.a.s. (http://tidalwave.it)
8: *
9: * *************************************************************************************************************************************************************
10: *
11: * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
12: * You may obtain a copy of the License at
13: *
14: * http://www.apache.org/licenses/LICENSE-2.0
15: *
16: * 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
17: * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
18: *
19: * *************************************************************************************************************************************************************
20: *
21: * git clone https://bitbucket.org/tidalwave/northernwind-src
22: * git clone https://github.com/tidalwave-it/northernwind-src
23: *
24: * *************************************************************************************************************************************************************
25: */
26: package it.tidalwave.northernwind.frontend.media.impl.interpolator;
27:
28: import javax.annotation.Nonnull;
29: import java.text.DecimalFormat;
30: import java.util.Optional;
31: import it.tidalwave.image.metadata.EXIF;
32: import it.tidalwave.image.metadata.TIFF;
33: import it.tidalwave.image.metadata.XMP;
34:
35: /***************************************************************************************************************************************************************
36: *
37: * @author Fabrizio Giudici
38: *
39: **************************************************************************************************************************************************************/
40: public class ShootingDataInterpolator extends MetadataInterpolatorSupport
41: {
42: public ShootingDataInterpolator()
43: {
44: super("shootingData");
45: }
46:
47: @Override @Nonnull
48: public String interpolate (@Nonnull final String template, @Nonnull final Context context)
49: {
50: final var tiff = context.getMetadata().getDirectory(TIFF.class);
51: final var exif = context.getMetadata().getDirectory(EXIF.class);
52: final var xmp = context.getMetadata().getDirectory(XMP.class);
53: final var xmpProperties = xmp.getXmpProperties();
54: final var modelMap = context.getModelMap();
55: final var lensMap = context.getLensMap();
56:
57: final var builder = new StringBuilder();
58: final var cameraMake = tiff.getMake()
59: .or(exif::getMake)
60: .or(() -> Optional.ofNullable(xmpProperties.get("tiff:Make")))
61: .orElse("");
62: final var cameraModel = tiff.getModel()
63: .or(exif::getModel)
64: .or(() -> Optional.ofNullable(xmpProperties.get("tiff:Model")))
65: .orElse("");
66:
67:• var camera = (cameraMake + ((!cameraModel.isBlank() && !cameraMake.isBlank()) ? " " : "") + cameraModel).trim();
68: camera = modelMap.getOrDefault(camera, camera);
69: builder.append(camera);
70: builder.append(" + ");
71:
72: final var lensMake = exif.getLensMake()
73: .or(() -> Optional.ofNullable(xmpProperties.get("exif:LensMake")))
74: .orElse("");
75: final var lensModel = exif.getLensModel()
76: .or(() -> Optional.ofNullable(xmpProperties.get("aux:Lens")))
77: .or(() -> Optional.ofNullable(xmpProperties.get("aux:LensID")))
78: .orElse("");
79:
80:• var lens = (lensMake + ((!lensModel.isBlank() && !lensMake.isBlank()) ? " " : "") + lensModel).trim();
81: lens = lensMap.getOrDefault(lens, lens);
82:
83: builder.append(lens);
84: builder.append(" @ ");
85: exif.getFocalLength().ifPresent(fl -> builder.append(fl.intValue()).append(" mm, "));
86: // FIXME: eventually teleconverter
87: exif.getExposureTime().ifPresent(t -> builder.append(t).append(" sec @ ƒ/"));
88: exif.getFNumber().map(f -> new DecimalFormat("0.#").format(f.floatValue())).ifPresent(builder::append);
89:
90: exif.getExposureBiasValue().ifPresent(exposureBiasValue ->
91: {
92:• if (exposureBiasValue.getNumerator() != 0)
93: {
94: builder.append(String.format(", %+.2f EV", exposureBiasValue.floatValue()));
95: }
96: });
97:
98: exif.getISOSpeedRatings().ifPresent(iso -> builder.append(", ISO ").append(iso.intValue()));
99:
100: return template.replace("$" + macro + "$", builder.toString());
101: }
102: }