Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
#
# This uses the writers.txt file from inside the loci_tools.jar
#
class_list = jutil.make_instance("loci/formats/ClassList",
"(Ljava/lang/String;"
"Ljava/lang/Class;" # base
"Ljava/lang/Class;)V", # location in jar
"writers.txt", base_klass, klass)
class ImageWriter(IFormatWriter):
new_fn = jutil.make_new(class_name, '(Lloci/formats/ClassList;)V')
def __init__(self):
self.new_fn(class_list)
setId = jutil.make_method('setId', '(Ljava/lang/String;)V',
'Sets the current file name.')
addStatusListener = jutil.make_method('addStatusListener', '()Lloci/formats/StatusListener;',
'Adds a listener for status update events.')
close = jutil.make_method('close','()V',
'Closes currently open file(s) and frees allocated memory.')
getFormat = jutil.make_method('getFormat', '()Ljava/lang/String;',
'Gets the name of this file format.')
getNativeDataType = jutil.make_method('getNativeDataType', '()Ljava/lang/Class;',
'Returns the native data type of image planes for this reader, as returned by IFormatReader.openPlane(int, int, int, int, int) or IFormatWriter#saveData.')
getStatusListeners = jutil.make_method('getStatusListeners', '()[Lloci/formats/StatusListener;',
'Gets a list of all registered status update listeners.')
getSuffixes = jutil.make_method('getSuffixes', '()Ljava/lang/String;',
'Gets the default file suffixes for this file format.')
getWriter = jutil.make_method('getWriter', '()Lloci/formats/IFormatWriter;',
'Gets the writer used to save the current file.')
# getWriter = jutil.make_method('getWriter', '(Ljava/lang/Class)Lloci/formats/IFormatWriter;',
# 'Gets the file format writer instance matching the given class.')
# getWriter = jutil.make_method('getWriter', '(Ljava/lang/String;)Lloci/formats/IFormatWriter;',
'Return the dimension order as a five-character string, e.g. "XYCZT"')
getMetadataValue = jutil.make_method('getMetadataValue',
'(Ljava/lang/String;)'
'Ljava/lang/Object;',
'Look up a specific metadata value from the store')
getSeriesMetadata = jutil.make_method('getSeriesMetadata',
'()Ljava/util/Hashtable;',
'Obtains the hashtable contaning the series metadata field/value pairs')
getSeriesCount = jutil.make_method('getSeriesCount',
'()I',
'Return the # of image series in the file')
getSeries = jutil.make_method('getSeries', '()I',
'Return the currently selected image series')
getImageCount = jutil.make_method('getImageCount',
'()I','Determines the number of images in the current file')
getIndex = jutil.make_method('getIndex', '(III)I',
'Get the plane index given z, c, t')
getRGBChannelCount = jutil.make_method('getRGBChannelCount',
'()I','Gets the number of channels per RGB image (if not RGB, this returns 1')
getSizeC = jutil.make_method('getSizeC', '()I',
'Get the number of color planes')
getSizeT = jutil.make_method('getSizeT', '()I',
'Get the number of frames in the image')
getSizeX = jutil.make_method('getSizeX', '()I',
'Get the image width')
getSizeY = jutil.make_method('getSizeY', '()I',
'Get the image height')
getSizeZ = jutil.make_method('getSizeZ', '()I',
'Get the image depth')
getPixelType = jutil.make_method('getPixelType', '()I',
'Get the pixel type: see FormatTools for types')
isLittleEndian = jutil.make_method('isLittleEndian',
stream - the RandomAccessInputStream to be used to read the file contents
Note that both isThisTypeS and isThisTypeStream must return true
for the type to truly be handled.''')
def setId(self, path):
'''Set the name of the file'''
jutil.call(self.o, 'setId',
'(Ljava/lang/String;)V',
path)
getMetadataStore = jutil.make_method('getMetadataStore', '()Lloci/formats/meta/MetadataStore;',
'Retrieves the current metadata store for this reader.')
get8BitLookupTable = jutil.make_method(
'get8BitLookupTable',
'()[[B', 'Get a lookup table for 8-bit indexed images')
get16BitLookupTable = jutil.make_method(
'get16BitLookupTable',
'()[[S', 'Get a lookup table for 16-bit indexed images')
def get_class_name(self):
return jutil.call(jutil.call(self.o, 'getClass', '()Ljava/lang/Class;'),
'getName', '()Ljava/lang/String;')
@property
def suffixNecessary(self):
if self.get_class_name() == 'loci.formats.in.JPKReader':
return True;
env = jutil.get_env()
klass = env.get_object_class(self.o)
field_id = env.get_field_id(klass, "suffixNecessary", "Z")
if field_id is None:
return None
return env.get_boolean_field(self.o, field_id)
setSeries = jutil.make_method('setSeries','(I)V','Set the currently selected image series')
setGroupFiles = jutil.make_method('setGroupFiles', '(Z)V',
'Force reader to group or not to group files in a multi-file set')
setMetadataStore = jutil.make_method('setMetadataStore',
'(Lloci/formats/meta/MetadataStore;)V',
'Sets the default metadata store for this reader.')
setMetadataOptions = jutil.make_method('setMetadataOptions',
'(Lloci/formats/in/MetadataOptions;)V',
'Sets the metadata options used when reading metadata')
setOriginalMetadataPopulated = jutil.make_method(
'setOriginalMetadataPopulated', '(Z)V')
isThisTypeS = jutil.make_method(
'isThisType',
'(Ljava/lang/String;)Z',
'Return true if the filename might be handled by this reader')
isThisTypeSZ = jutil.make_method(
'isThisType',
'(Ljava/lang/String;Z)Z',
'''Return true if the named file is handled by this reader.
filename - name of file
allowOpen - True if the reader is allowed to open files
when making its determination
''')
isThisTypeStream = jutil.make_method(
'isThisType',
'(Lloci/common/RandomAccessInputStream;)Z',
'''Return true if the stream might be parseable by this reader.
stream - the RandomAccessInputStream to be used to read the file contents
def get_parameter_wrapper(parameter):
'''wrap the imagej.plugin.Parameter class'''
class Parameter(object):
def __init__(self):
self.o = parameter
label = J.make_method('label', '()Ljava/lang/String;',
'Label to display in editor')
digits = J.make_method('digits', '()I',
'Number of digits to display to right of decimal point')
columns = J.make_method('columns', '()I',
'Number of columns in edit box')
units = J.make_method('units', '()Ljava/lang/String;',
'Units to display to right of edit box')
widget = J.make_method('widget', '()Ljava/lang/String;',
'Name of display widget')
required = J.make_method('required', '()Z',
'True if required, False if default available')
persist = J.make_method('persist', '()Ljava/lang/String;',
'Key to use when persisting field value')
output = J.make_method('output', '()Z',
'True if field is an output parameter, '
'False if field is an input parameter')
return Parameter()
'()Ljava/util/Hashtable;',
'Obtains the hashtable contaning the series metadata field/value pairs')
getSeriesCount = jutil.make_method('getSeriesCount',
'()I',
'Return the # of image series in the file')
getSeries = jutil.make_method('getSeries', '()I',
'Return the currently selected image series')
getImageCount = jutil.make_method('getImageCount',
'()I','Determines the number of images in the current file')
getIndex = jutil.make_method('getIndex', '(III)I',
'Get the plane index given z, c, t')
getRGBChannelCount = jutil.make_method('getRGBChannelCount',
'()I','Gets the number of channels per RGB image (if not RGB, this returns 1')
getSizeC = jutil.make_method('getSizeC', '()I',
'Get the number of color planes')
getSizeT = jutil.make_method('getSizeT', '()I',
'Get the number of frames in the image')
getSizeX = jutil.make_method('getSizeX', '()I',
'Get the image width')
getSizeY = jutil.make_method('getSizeY', '()I',
'Get the image height')
getSizeZ = jutil.make_method('getSizeZ', '()I',
'Get the image depth')
getPixelType = jutil.make_method('getPixelType', '()I',
'Get the pixel type: see FormatTools for types')
isLittleEndian = jutil.make_method('isLittleEndian',
'()Z','Return True if the data is in little endian order')
isRGB = jutil.make_method('isRGB', '()Z',
'Return True if images in the file are RGB')
isInterleaved = jutil.make_method('isInterleaved', '()Z',
'Return True if image colors are interleaved within a plane')
isIndexed = jutil.make_method('isIndexed', '()Z',
'Gets whether or not the channels in an image are interleaved.')
isSupportedType = jutil.make_method('isSupportedType', '(I)Z',
'Checks if the given pixel type is supported.')
# saveBytes = jutil.make_method('saveBytes', '([BZ)V',
# 'Saves the given byte array to the current file.')
saveBytes = jutil.make_method('saveBytes', '([BIZZ)V',
'Saves the given byte array to the given series in the current file.')
savePlane = jutil.make_method('savePlane', '(Ljava/lang/Object;Z)V',
'Saves the given image plane to the current file.')
# savePlane = jutil.make_method('savePlane', '(Ljava/lang/Object;IZZ)V',
# 'Saves the given image plane to the given series in the current file.')
setColorModel = jutil.make_method('setColorModel', '(Ljava/awt/image/ColorModel;)V',
'Sets the color model.')
setCompression = jutil.make_method('setCompression', '(Ljava/lang/String;)V',
'Sets the current compression type.')
setFramesPerSecond = jutil.make_method('setFramesPerSecond', '(I)V',
'Sets the frames per second to use when writing.')
setInterleaved = jutil.make_method('setInterleaved', '(Z)V',
'Sets whether or not the channels in an image are interleaved.')
setMetadataRetrieve = jutil.make_method('setMetadataRetrieve', '(Lloci/formats/meta/MetadataRetrieve;)V',
'Sets the metadata retrieval object from which to retrieve standardized metadata.')
return IFormatWriter
def wrap_data_view(view):
class DataView(object):
def __init__(self, o=view):
self.o = o
isCompatible = J.make_method("isCompatible", "(Limagej/data/Data;)Z")
initialize = J.make_method("initialize", "(Limagej/data/Data;)V")
getData = J.make_method("getData", "()Limagej/data/Data;")
getPlanePosition = J.make_method(
"getPlanePosition", "()Limagej/data/Position;")
setSelected = J.make_method("setSelected", "(Z)V")
isSelected = J.make_method("isSelected", "()Z")
getPreferredWidth = J.make_method("getPreferredWidth", "()I")
getPreferredHeight = J.make_method("getPreferredHeight", "()I")
update = make_invoke_method("update")
rebuild = make_invoke_method("rebuild")
dispose = make_invoke_method("dispose")
return DataView()
def get_parameter_wrapper(parameter):
'''wrap the imagej.plugin.Parameter class'''
class Parameter(object):
def __init__(self):
self.o = parameter
label = J.make_method('label', '()Ljava/lang/String;',
'Label to display in editor')
digits = J.make_method('digits', '()I',
'Number of digits to display to right of decimal point')
columns = J.make_method('columns', '()I',
'Number of columns in edit box')
units = J.make_method('units', '()Ljava/lang/String;',
'Units to display to right of edit box')
widget = J.make_method('widget', '()Ljava/lang/String;',
'Name of display widget')
required = J.make_method('required', '()Z',
'True if required, False if default available')
persist = J.make_method('persist', '()Ljava/lang/String;',
'Key to use when persisting field value')
output = J.make_method('output', '()Z',
'True if field is an output parameter, '
'False if field is an input parameter')