| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package android.hardware.camera2.params; |
| 18 |
|
| 19 |
import static android.hardware.camera2.params.RggbChannelVector.BLUE; |
| 20 |
import static android.hardware.camera2.params.RggbChannelVector.COUNT; |
| 21 |
import static android.hardware.camera2.params.RggbChannelVector.GREEN_EVEN; |
| 22 |
import static android.hardware.camera2.params.RggbChannelVector.GREEN_ODD; |
| 23 |
import static android.hardware.camera2.params.RggbChannelVector.RED; |
| 24 |
|
| 25 |
import static com.android.internal.util.Preconditions.checkArgumentNonnegative; |
| 26 |
import static com.android.internal.util.Preconditions.checkArgumentPositive; |
| 27 |
import static com.android.internal.util.Preconditions.checkArrayElementsInRange; |
| 28 |
|
| 29 |
import android.hardware.camera2.CaptureResult; |
| 30 |
import android.hardware.camera2.utils.HashCodeHelpers; |
| 31 |
|
| 32 |
import java.util.Arrays; |
| 33 |
import java.util.Objects; |
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
public final class LensShadingMap { |
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
public static final float MINIMUM_GAIN_FACTOR = 1.0f; |
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
public LensShadingMap(final float[] elements, final int rows, final int columns) { |
| 70 |
|
| 71 |
mRows = checkArgumentPositive(rows, "rows must be positive"); |
| 72 |
mColumns = checkArgumentPositive(columns, "columns must be positive"); |
| 73 |
mElements = Objects.requireNonNull(elements, "elements must not be null"); |
| 74 |
|
| 75 |
if (elements.length != getGainFactorCount()) { |
| 76 |
throw new IllegalArgumentException("elements must be " + getGainFactorCount() + |
| 77 |
" length, received " + elements.length); |
| 78 |
} |
| 79 |
|
| 80 |
|
| 81 |
checkArrayElementsInRange(elements, MINIMUM_GAIN_FACTOR, Float.MAX_VALUE, "elements"); |
| 82 |
} |
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
public int getRowCount() { |
| 88 |
return mRows; |
| 89 |
} |
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
public int getColumnCount() { |
| 95 |
return mColumns; |
| 96 |
} |
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
public int getGainFactorCount() { |
| 105 |
return mRows * mColumns * COUNT; |
| 106 |
} |
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
public float getGainFactor(final int colorChannel, final int column, final int row) { |
| 136 |
if (colorChannel < 0 || colorChannel > COUNT) { |
| 137 |
throw new IllegalArgumentException("colorChannel out of range"); |
| 138 |
} else if (column < 0 || column >= mColumns) { |
| 139 |
throw new IllegalArgumentException("column out of range"); |
| 140 |
} else if (row < 0 || row >= mRows) { |
| 141 |
throw new IllegalArgumentException("row out of range"); |
| 142 |
} |
| 143 |
|
| 144 |
return mElements[colorChannel + (row * mColumns + column) * COUNT ]; |
| 145 |
} |
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
public RggbChannelVector getGainFactorVector(final int column, final int row) { |
| 164 |
if (column < 0 || column >= mColumns) { |
| 165 |
throw new IllegalArgumentException("column out of range"); |
| 166 |
} else if (row < 0 || row >= mRows) { |
| 167 |
throw new IllegalArgumentException("row out of range"); |
| 168 |
} |
| 169 |
|
| 170 |
final int offset = (row * mColumns + column) * COUNT; |
| 171 |
|
| 172 |
final float red = |
| 173 |
mElements[RED + offset]; |
| 174 |
final float greenEven = |
| 175 |
mElements[GREEN_EVEN + offset]; |
| 176 |
final float greenOdd = |
| 177 |
mElements[GREEN_ODD + offset]; |
| 178 |
final float blue = |
| 179 |
mElements[BLUE + offset]; |
| 180 |
|
| 181 |
return new RggbChannelVector(red, greenEven, greenOdd, blue); |
| 182 |
} |
| 183 |
|
| 184 |
|
| 185 |
|
| 186 |
|
| 187 |
|
| 188 |
|
| 189 |
|
| 190 |
|
| 191 |
|
| 192 |
|
| 193 |
|
| 194 |
|
| 195 |
|
| 196 |
|
| 197 |
|
| 198 |
|
| 199 |
|
| 200 |
|
| 201 |
|
| 202 |
|
| 203 |
|
| 204 |
public void copyGainFactors(final float[] destination, final int offset) { |
| 205 |
checkArgumentNonnegative(offset, "offset must not be negative"); |
| 206 |
Objects.requireNonNull(destination, "destination must not be null"); |
| 207 |
if (destination.length + offset < getGainFactorCount()) { |
| 208 |
throw new ArrayIndexOutOfBoundsException("destination too small to fit elements"); |
| 209 |
} |
| 210 |
|
| 211 |
System.arraycopy(mElements, 0, destination, offset, getGainFactorCount()); |
| 212 |
} |
| 213 |
|
| 214 |
|
| 215 |
|
| 216 |
|
| 217 |
|
| 218 |
|
| 219 |
|
| 220 |
|
| 221 |
|
| 222 |
@Override |
| 223 |
public boolean equals(final Object obj) { |
| 224 |
if (obj == null) { |
| 225 |
return false; |
| 226 |
} |
| 227 |
if (this == obj) { |
| 228 |
return true; |
| 229 |
} |
| 230 |
if (obj instanceof LensShadingMap) { |
| 231 |
final LensShadingMap other = (LensShadingMap) obj; |
| 232 |
return mRows == other.mRows |
| 233 |
&& mColumns == other.mColumns |
| 234 |
&& Arrays.equals(mElements, other.mElements); |
| 235 |
} |
| 236 |
return false; |
| 237 |
} |
| 238 |
|
| 239 |
|
| 240 |
|
| 241 |
|
| 242 |
@Override |
| 243 |
public int hashCode() { |
| 244 |
int elemsHash = HashCodeHelpers.hashCode(mElements); |
| 245 |
return HashCodeHelpers.hashCode(mRows, mColumns, elemsHash); |
| 246 |
} |
| 247 |
|
| 248 |
|
| 249 |
|
| 250 |
|
| 251 |
|
| 252 |
|
| 253 |
|
| 254 |
|
| 255 |
|
| 256 |
|
| 257 |
|
| 258 |
|
| 259 |
@Override |
| 260 |
public String toString() { |
| 261 |
StringBuilder str = new StringBuilder(); |
| 262 |
str.append("LensShadingMap{"); |
| 263 |
|
| 264 |
final String channelPrefix[] = {"R:(", "G_even:(", "G_odd:(", "B:("}; |
| 265 |
|
| 266 |
for (int ch = 0; ch < COUNT; ch++) { |
| 267 |
str.append(channelPrefix[ch]); |
| 268 |
|
| 269 |
for (int r = 0; r < mRows; r++) { |
| 270 |
str.append("["); |
| 271 |
for (int c = 0; c < mColumns; c++) { |
| 272 |
float gain = getGainFactor(ch, c, r); |
| 273 |
str.append(gain); |
| 274 |
if (c < mColumns - 1) { |
| 275 |
str.append(", "); |
| 276 |
} |
| 277 |
} |
| 278 |
str.append("]"); |
| 279 |
if (r < mRows - 1) { |
| 280 |
str.append(", "); |
| 281 |
} |
| 282 |
} |
| 283 |
|
| 284 |
str.append(")"); |
| 285 |
if (ch < COUNT - 1) { |
| 286 |
str.append(", "); |
| 287 |
} |
| 288 |
} |
| 289 |
|
| 290 |
str.append("}"); |
| 291 |
return str.toString(); |
| 292 |
} |
| 293 |
|
| 294 |
private final int mRows; |
| 295 |
private final int mColumns; |
| 296 |
private final float[] mElements; |
| 297 |
} |