forked from imagej/ImageJ
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRaw.java
68 lines (59 loc) · 1.92 KB
/
Raw.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package ij.plugin;
import java.awt.*;
import java.io.*;
import ij.*;
import ij.io.*;
/** This plugin implements the File/Import/Raw command. */
public class Raw implements PlugIn {
private static String defaultDirectory = null;
public void run(String arg) {
OpenDialog od = new OpenDialog("Open Raw...", arg);
String directory = od.getDirectory();
String fileName = od.getFileName();
if (fileName==null)
return;
ImportDialog d = new ImportDialog(fileName, directory);
d.openImage();
}
/** Opens the image at 'filePath' using the format specified by 'fi'. */
public static ImagePlus open(String filePath, FileInfo fi) {
File f = new File(filePath);
String parent = f.getParent();
if (parent!=null)
fi.directory = parent+ "/";
fi.fileName = f.getName();
return (new FileOpener(fi)).open(false);
}
/** Opens all the images in the specified directory as a stack,
using the format specified by 'fi'. */
public static ImagePlus openAll(String directory, FileInfo fi) {
ImagePlus imp = openAllVirtual(directory,fi);
if (imp!=null)
return imp.duplicate();
else
return null;
}
/** Opens all the images in the specified directory as a virtual stack,
using the format specified by 'fi'. */
public static ImagePlus openAllVirtual(String directory, FileInfo fi) {
String[] list = new File(directory).list();
if (list==null)
return null;
FolderOpener fo = new FolderOpener();
list = fo.trimFileList(list);
list = fo.sortFileList(list);
if (list==null)
return null;
if (directory!=null && !(directory.endsWith(File.separator)||directory.endsWith("/")))
directory += "/";
FileInfo[] info = new FileInfo[list.length];
for (int i=0; i<list.length; i++) {
info[i] = (FileInfo)fi.clone();
info[i].directory = directory;
info[i].fileName = list[i];
}
VirtualStack stack = new FileInfoVirtualStack(info);
ImagePlus imp = new ImagePlus(directory, stack);
return imp;
}
}