Skip to content

Commit

Permalink
Merge pull request #97 from melissalinkert/api-updates
Browse files Browse the repository at this point in the history
Add getter and setter for each command line option
  • Loading branch information
melissalinkert authored Apr 3, 2023
2 parents c91d805 + dda535a commit 8862cd4
Show file tree
Hide file tree
Showing 6 changed files with 377 additions and 92 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/**
* Copyright (c) 2023 Glencoe Software, Inc. All rights reserved.
*
* This software is distributed under the terms described by the LICENSE.txt
* file you can find at the root of the distribution bundle. If the file is
* missing please request a copy by contacting [email protected]
*/

package com.glencoesoftware.pyramid;

import loci.formats.codec.CodecOptions;
import loci.formats.codec.JPEG2000CodecOptions;

import picocli.CommandLine.ITypeConverter;

/**
* Convert a string to a CodecOptions.
*/
public class CompressionQualityConverter
implements ITypeConverter<CodecOptions>
{
@Override
public CodecOptions convert(String value) throws Exception {
// JPEG2000CodecOptions used here as it's the only way to pass
// a quality value through to the JPEG-2000 codecs
// this could be changed later if/when we support options on other codecs
CodecOptions options = JPEG2000CodecOptions.getDefaultOptions();
options.quality = Double.parseDouble(value);
return options;
}
}
70 changes: 70 additions & 0 deletions src/main/java/com/glencoesoftware/pyramid/CompressionType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/**
* Copyright (c) 2019-2020 Glencoe Software, Inc. All rights reserved.
*
* This software is distributed under the terms described by the LICENSE.txt
* file you can find at the root of the distribution bundle. If the file is
* missing please request a copy by contacting [email protected]
*/
package com.glencoesoftware.pyramid;

import java.util.EnumSet;
import loci.formats.out.TiffWriter;
import loci.formats.tiff.TiffCompression;

/**
* List of valid compression types for the output OME-TIFF file.
*/
public enum CompressionType {
UNCOMPRESSED(
TiffWriter.COMPRESSION_UNCOMPRESSED, TiffCompression.UNCOMPRESSED),
LZW(TiffWriter.COMPRESSION_LZW, TiffCompression.LZW),
JPEG(TiffWriter.COMPRESSION_JPEG, TiffCompression.JPEG),
JPEG_2000(TiffWriter.COMPRESSION_J2K, TiffCompression.JPEG_2000),
JPEG_2000_LOSSY(
TiffWriter.COMPRESSION_J2K_LOSSY, TiffCompression.JPEG_2000_LOSSY);

private String compressionName;
private TiffCompression compressionType;

/**
* Construct a list of valid compression types.
*
* @param name compression name (used in command line arguments)
* @param type corresponding TIFF compression
*/
private CompressionType(String name, TiffCompression type) {
compressionName = name;
compressionType = type;
}

/**
* Find the compression corresponding to the given name.
* If there is no matching name, return the uncompressed type.
*
* @param compressionName desired compression name
* @return corresponding CompressionType, or UNCOMPRESSED if no match
*/
public static CompressionType lookup(String compressionName) {
for (CompressionType t : EnumSet.allOf(CompressionType.class)) {
if (t.getName().equals(compressionName)) {
return t;
}
}
return UNCOMPRESSED;
}

/**
* @return name of this compression type
*/
public String getName() {
return compressionName;
}

/**
* @return TiffCompression for this compression type
*/
public TiffCompression getTIFFCompression() {
return compressionType;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/**
* Copyright (c) 2023 Glencoe Software, Inc. All rights reserved.
*
* This software is distributed under the terms described by the LICENSE.txt
* file you can find at the root of the distribution bundle. If the file is
* missing please request a copy by contacting [email protected]
*/

package com.glencoesoftware.pyramid;

import picocli.CommandLine.ITypeConverter;

/**
* Convert a string to a CompressionType.
*/
public class CompressionTypeConverter
implements ITypeConverter<CompressionType>
{
@Override
public CompressionType convert(String value) throws Exception {
return CompressionType.lookup(value);
}
}
62 changes: 0 additions & 62 deletions src/main/java/com/glencoesoftware/pyramid/CompressionTypes.java

This file was deleted.

Loading

0 comments on commit 8862cd4

Please sign in to comment.