Skip to content

Commit

Permalink
Updates from code review and regression testing
Browse files Browse the repository at this point in the history
  • Loading branch information
drewnoakes committed Nov 20, 2023
1 parent 99db9f2 commit 4ee02e0
Show file tree
Hide file tree
Showing 8 changed files with 107 additions and 96 deletions.
18 changes: 0 additions & 18 deletions Source/com/drew/lang/SequentialReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -362,9 +362,6 @@ public StringValue getNullTerminatedStringValue(int maxLengthBytes, Charset char

/**
* Returns the sequence of bytes punctuated by a <code>\0</code> value.
* It will place the cursor after the first occurrence of <code>\0</code>.
* <br/>
* Use <code>getNullTerminatedStringAndSkipToNextPosition</code> if you want the cursor to move moved at the end of <code>maxLengthBytes</code>.
*
* @param maxLengthBytes The maximum number of bytes to read. If a <code>\0</code> byte is not reached within this limit,
* the returned array will be <code>maxLengthBytes</code> long.
Expand All @@ -389,19 +386,4 @@ public byte[] getNullTerminatedBytes(int maxLengthBytes) throws IOException
System.arraycopy(buffer, 0, bytes, 0, length);
return bytes;
}

/**
* Read until the null terminated byte and automatically move the end of the requested position.
* @param maxLengthBytes
* @param charset
* @return
* @throws IOException
*/
public StringValue getNullTerminatedStringAndSkipToNextPosition(int maxLengthBytes, Charset charset) throws IOException {
byte[] bytes = this.getNullTerminatedBytes(maxLengthBytes);
if (bytes.length < maxLengthBytes - 1) {
this.trySkip(maxLengthBytes - bytes.length - 1);
}
return new StringValue(bytes, charset);
}
}
3 changes: 0 additions & 3 deletions Source/com/drew/lang/StreamReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,10 @@
package com.drew.lang;

import com.drew.lang.annotations.NotNull;
import com.drew.metadata.StringValue;

import java.io.EOFException;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.Charset;

/**
*
Expand Down Expand Up @@ -143,5 +141,4 @@ private long skipInternal(long n) throws IOException
_pos += skippedTotal;
return skippedTotal;
}

}
2 changes: 1 addition & 1 deletion Source/com/drew/metadata/exif/ExifTiffHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ public boolean customProcessTag(final int tagOffset,
_metadata.addDirectory(directory);
return true;
} else if (byteCount == 74) {
//TODO:
//TODO NikonPictureControl3Directory
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,16 @@
import static com.drew.metadata.exif.makernotes.NikonPictureControl1Directory.TAG_PICTURE_CONTROL_ADJUST;
import static com.drew.metadata.exif.makernotes.NikonPictureControl1Directory.TAG_TONING_EFFECT;

public final class NikonPictureControl1Descriptor extends TagDescriptor<NikonPictureControl1Directory> {
public NikonPictureControl1Descriptor(NikonPictureControl1Directory directory) {
public final class NikonPictureControl1Descriptor extends TagDescriptor<NikonPictureControl1Directory>
{
public NikonPictureControl1Descriptor(NikonPictureControl1Directory directory)
{
super(directory);
}

@Override
public String getDescription(int tagType) {
public String getDescription(int tagType)
{
switch (tagType) {
case TAG_PICTURE_CONTROL_ADJUST:
return getPictureControlAdjustDescription();
Expand All @@ -25,7 +28,8 @@ public String getDescription(int tagType) {
}
}

public String getPictureControlAdjustDescription() {
public String getPictureControlAdjustDescription()
{
return getIndexedDescription(
TAG_PICTURE_CONTROL_ADJUST,
"Default Settings",
Expand All @@ -34,58 +38,60 @@ public String getPictureControlAdjustDescription() {
);
}

public String getFilterEffectDescription() {
byte[] value = _directory.getByteArray(TAG_FILTER_EFFECT);
public String getFilterEffectDescription()
{
Integer value = _directory.getInteger(TAG_FILTER_EFFECT);
if (value == null) {
return null;
}

switch (value[0]) {
case (byte) 0x80:
switch (value) {
case 0x80:
return "Off";
case (byte) 0x81:
case 0x81:
return "Yellow";
case (byte) 0x82:
case 0x82:
return "Orange";
case (byte) 0x83:
case 0x83:
return "Red";
case (byte) 0x84:
case 0x84:
return "Green";
case (byte) 0xFF:
case 0xFF:
return "N/A";
default:
return super.getDescription(TAG_FILTER_EFFECT);
}
}

public String getToningEffectDescription() {
byte[] value = _directory.getByteArray(TAG_TONING_EFFECT);
public String getToningEffectDescription()
{
Integer value = _directory.getInteger(TAG_TONING_EFFECT);
if (value == null) {
return null;
}

switch (value[0]) {
case (byte) 0x80:
switch (value) {
case 0x80:
return "B&W";
case (byte) 0x81:
case 0x81:
return "Sepia";
case (byte) 0x82:
case 0x82:
return "Cyanotype";
case (byte) 0x83:
case 0x83:
return "Red";
case (byte) 0x84:
case 0x84:
return "Yellow";
case (byte) 0x85:
case 0x85:
return "Green";
case (byte) 0x86:
case 0x86:
return "Blue-green";
case (byte) 0x87:
case 0x87:
return "Blue";
case (byte) 0x88:
case 0x88:
return "Purple-blue";
case (byte) 0x89:
case 0x89:
return "Red-purple";
case (byte) 0xFF:
case 0xFF:
return "N/A";
default:
return super.getDescription(TAG_TONING_EFFECT);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,21 @@

import com.drew.lang.Charsets;
import com.drew.lang.SequentialByteArrayReader;
import com.drew.lang.annotations.NotNull;
import com.drew.metadata.Directory;

import java.io.IOException;
import java.util.HashMap;

public final class NikonPictureControl1Directory extends Directory {
public final class NikonPictureControl1Directory extends Directory
{
// Tag values are offsets into the underlying data.
// Data from https://exiftool.org/TagNames/Nikon.html#PictureControl

public static final int TAG_PICTURE_CONTROL_VERSION = 0;
public static final int TAG_PICTURE_CONTROL_NAME = 4;
public static final int TAG_PICTURE_CONTROL_BASE = 24;
// skip 4
public static final int TAG_PICTURE_CONTROL_ADJUST = 48;
public static final int TAG_PICTURE_CONTROL_QUICK_ADJUST = 49;
public static final int TAG_SHARPNESS = 50;
Expand All @@ -24,7 +30,8 @@ public final class NikonPictureControl1Directory extends Directory {

private static final HashMap<Integer, String> TAG_NAME_MAP = new HashMap<>();

static {
static
{
TAG_NAME_MAP.put(TAG_PICTURE_CONTROL_VERSION, "Picture Control Version");
TAG_NAME_MAP.put(TAG_PICTURE_CONTROL_NAME, "Picture Control Name");
TAG_NAME_MAP.put(TAG_PICTURE_CONTROL_BASE, "Picture Control Base");
Expand All @@ -40,22 +47,28 @@ public final class NikonPictureControl1Directory extends Directory {
TAG_NAME_MAP.put(TAG_TONING_SATURATION, "Toning Saturation");
}

public NikonPictureControl1Directory() {
public NikonPictureControl1Directory()
{
setDescriptor(new NikonPictureControl1Descriptor(this));
}

@NotNull
@Override
public String getName() {
public String getName()
{
return "Nikon PictureControl 1";
}

@NotNull
@Override
protected HashMap<Integer, String> getTagNameMap() {
protected HashMap<Integer, String> getTagNameMap()
{
return TAG_NAME_MAP;
}

public static NikonPictureControl1Directory read(byte[] bytes) throws IOException {
int EXPECTED_LENGTH = 58;
public static NikonPictureControl1Directory read(byte[] bytes) throws IOException
{
final int EXPECTED_LENGTH = 58;

if (bytes.length != EXPECTED_LENGTH) {
throw new IllegalArgumentException("Must have " + EXPECTED_LENGTH + " bytes.");
Expand All @@ -65,21 +78,20 @@ public static NikonPictureControl1Directory read(byte[] bytes) throws IOExceptio

NikonPictureControl1Directory directory = new NikonPictureControl1Directory();

directory.setString(TAG_PICTURE_CONTROL_VERSION, reader.getNullTerminatedStringAndSkipToNextPosition(4, Charsets.UTF_8).toString());
directory.setString(TAG_PICTURE_CONTROL_NAME, reader.getNullTerminatedStringAndSkipToNextPosition(20, Charsets.UTF_8).toString());
directory.setString(TAG_PICTURE_CONTROL_BASE, reader.getNullTerminatedStringAndSkipToNextPosition(20, Charsets.UTF_8).toString());

directory.setObject(TAG_PICTURE_CONTROL_VERSION, reader.getStringValue(4, Charsets.UTF_8));
directory.setObject(TAG_PICTURE_CONTROL_NAME, reader.getStringValue(20, Charsets.UTF_8));
directory.setObject(TAG_PICTURE_CONTROL_BASE, reader.getStringValue(20, Charsets.UTF_8));
reader.skip(4);
directory.setObject(TAG_PICTURE_CONTROL_ADJUST, reader.getByte());
directory.setObject(TAG_PICTURE_CONTROL_QUICK_ADJUST, reader.getByte());
directory.setObject(TAG_SHARPNESS, reader.getByte());
directory.setObject(TAG_CONTRAST, reader.getByte());
directory.setObject(TAG_BRIGHTNESS, reader.getByte());
directory.setObject(TAG_SATURATION, reader.getByte());
directory.setObject(TAG_HUE_ADJUSTMENT, reader.getByte());
directory.setObject(TAG_FILTER_EFFECT, reader.getByte());
directory.setObject(TAG_TONING_EFFECT, reader.getByte());
directory.setObject(TAG_TONING_SATURATION, reader.getByte());
directory.setObject(TAG_PICTURE_CONTROL_ADJUST, reader.getUInt8());
directory.setObject(TAG_PICTURE_CONTROL_QUICK_ADJUST, reader.getUInt8());
directory.setObject(TAG_SHARPNESS, reader.getUInt8());
directory.setObject(TAG_CONTRAST, reader.getUInt8());
directory.setObject(TAG_BRIGHTNESS, reader.getUInt8());
directory.setObject(TAG_SATURATION, reader.getUInt8());
directory.setObject(TAG_HUE_ADJUSTMENT, reader.getUInt8());
directory.setObject(TAG_FILTER_EFFECT, reader.getUInt8());
directory.setObject(TAG_TONING_EFFECT, reader.getUInt8());
directory.setObject(TAG_TONING_SATURATION, reader.getUInt8());

assert (reader.getPosition() == EXPECTED_LENGTH);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,16 @@
import static com.drew.metadata.exif.makernotes.NikonPictureControl2Directory.TAG_PICTURE_CONTROL_ADJUST;
import static com.drew.metadata.exif.makernotes.NikonPictureControl2Directory.TAG_TONING_EFFECT;

public final class NikonPictureControl2Descriptor extends TagDescriptor<NikonPictureControl2Directory> {
public NikonPictureControl2Descriptor(NikonPictureControl2Directory directory) {
public final class NikonPictureControl2Descriptor extends TagDescriptor<NikonPictureControl2Directory>
{
public NikonPictureControl2Descriptor(NikonPictureControl2Directory directory)
{
super(directory);
}

@Override
public String getDescription(int tagType) {
public String getDescription(int tagType)
{
switch (tagType) {
case TAG_PICTURE_CONTROL_ADJUST:
return getPictureControlAdjustDescription();
Expand All @@ -25,7 +28,8 @@ public String getDescription(int tagType) {
}
}

public String getPictureControlAdjustDescription() {
public String getPictureControlAdjustDescription()
{
return getIndexedDescription(
TAG_PICTURE_CONTROL_ADJUST,
"Default Settings",
Expand All @@ -34,7 +38,8 @@ public String getPictureControlAdjustDescription() {
);
}

public String getFilterEffectDescription() {
public String getFilterEffectDescription()
{
byte[] value = _directory.getByteArray(TAG_FILTER_EFFECT);
if (value == null) {
return null;
Expand All @@ -58,7 +63,8 @@ public String getFilterEffectDescription() {
}
}

public String getToningEffectDescription() {
public String getToningEffectDescription()
{
byte[] value = _directory.getByteArray(TAG_TONING_EFFECT);
if (value == null) {
return null;
Expand Down
Loading

0 comments on commit 4ee02e0

Please sign in to comment.