(ImagePlus imp, ImageProcessor ip, int nSlices, int type, int options)
| 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) |
no test coverage detected