1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.imaging.formats.tiff.photometricinterpreters.floatingpoint;
18
19 import java.awt.Color;
20
21
22
23
24
25 public class PaletteEntryForValue implements PaletteEntry {
26
27 private final float value;
28 private final int iColor;
29 private final Color color;
30 private final boolean isNull;
31
32
33
34
35
36
37
38
39
40 public PaletteEntryForValue(final float value, final Color color) {
41 if (color == null) {
42 throw new IllegalArgumentException("Null colors not allowed");
43 }
44 this.value = value;
45 this.color = color;
46 this.iColor = color.getRGB();
47 isNull = Float.isNaN(value);
48
49 }
50
51 @Override
52 public boolean coversSingleEntry() {
53 return true;
54 }
55
56 @Override
57 public int getArgb(final float f) {
58 if (isNull && Float.isNaN(f)) {
59 return iColor;
60 }
61 if (f == value) {
62 return iColor;
63 }
64 return 0;
65 }
66
67 @Override
68 public Color getColor(final float f) {
69 if (isNull && Float.isNaN(f)) {
70 return color;
71 }
72 if (f == value) {
73 return color;
74 }
75 return null;
76 }
77
78 @Override
79 public float getLowerBound() {
80 return value;
81 }
82
83 @Override
84 public float getUpperBound() {
85 return value;
86 }
87
88 @Override
89 public boolean isCovered(final float f) {
90 if (isNull) {
91 return Float.isNaN(f);
92 }
93 return f == value;
94 }
95
96 @Override
97 public String toString() {
98 return "PaletteEntry for single value" + value;
99 }
100 }