MCPcopy Create free account
hub / github.com/AstroImageJ/astroimagej / createStack

Method createStack

ij/src/main/java/ij/gui/NewImage.java:37–122  ·  view source on GitHub ↗
(ImagePlus imp, ImageProcessor ip, int nSlices, int type, int options)

Source from the content-addressed store, hash-verified

35 }
36
37 static boolean createStack(ImagePlus imp, ImageProcessor ip, int nSlices, int type, int options) {
38 int fill = getFill(options);
39 int width = imp.getWidth();
40 int height = imp.getHeight();
41 long bytesPerPixel = 1;
42 if (type==GRAY16) bytesPerPixel = 2;
43 else if (type==GRAY32||type==RGB) bytesPerPixel = 4;
44 long size = (long)width*height*nSlices*bytesPerPixel;
45 int sizeThreshold = fill==FILL_NOISE?10:250;
46 boolean bigStack = size/(1024*1024)>=sizeThreshold;
47 String size2 = size/(1024*1024)+"MB ("+width+"x"+height+"x"+nSlices+")";
48 if ((options&CHECK_AVAILABLE_MEMORY)!=0) {
49 long max = IJ.maxMemory(); // - 100*1024*1024;
50 if (max>0) {
51 long inUse = IJ.currentMemory();
52 long available = max - inUse;
53 if (size>available)
54 System.gc();
55 inUse = IJ.currentMemory();
56 available = max-inUse;
57 if (size>available) {
58 IJ.error("Insufficient Memory", "There is not enough free memory to allocate a \n"
59 + size2+" stack.\n \n"
60 + "Memory available: "+available/(1024*1024)+"MB\n"
61 + "Memory in use: "+IJ.freeMemory()+"\n \n"
62 + "More information can be found in the \"Memory\"\n"
63 + "sections of the ImageJ installation notes at\n"
64 + "\""+IJ.URL2+"/docs/install/\".");
65 return false;
66 }
67 }
68 }
69 ImageStack stack = imp.createEmptyStack();
70 boolean signedInt = (options&SIGNED_INT)!=0;
71 if (type==RGB && signedInt)
72 stack.setOptions("32-bit int");
73 int inc = nSlices/40;
74 if (inc<1) inc = 1;
75 if (bigStack)
76 IJ.showStatus("Allocating "+size2+". Press 'Esc' to abort.");
77 IJ.resetEscape();
78 try {
79 stack.addSlice(null, ip);
80 for (int i=2; i<=nSlices; i++) {
81 if ((i%inc)==0 && bigStack)
82 IJ.showProgress(i, nSlices);
83 Object pixels2 = null;
84 switch (type) {
85 case GRAY8: pixels2 = new byte[width*height];
86 if (fill==FILL_NOISE)
87 fillNoiseByte(new ByteProcessor(width,height,(byte[])pixels2));
88 break;
89 case GRAY16: pixels2 = new short[width*height];
90 if (fill==FILL_NOISE)
91 fillNoiseShort(new ShortProcessor(width,height,(short[])pixels2,null));
92 break;
93 case GRAY32: pixels2 = new float[width*height];
94 if (fill==FILL_NOISE)

Callers 5

createByteImageMethod · 0.95
createRGBImageMethod · 0.95
createIntImageMethod · 0.95
createShortImageMethod · 0.95
createFloatImageMethod · 0.95

Calls 15

getFillMethod · 0.95
maxMemoryMethod · 0.95
currentMemoryMethod · 0.95
errorMethod · 0.95
freeMemoryMethod · 0.95
setOptionsMethod · 0.95
showStatusMethod · 0.95
resetEscapeMethod · 0.95
addSliceMethod · 0.95
showProgressMethod · 0.95
fillNoiseByteMethod · 0.95
fillNoiseShortMethod · 0.95

Tested by

no test coverage detected