Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add getter and setter for each command line option #97

Merged
merged 4 commits into from
Apr 3, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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