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

Method setZoom

ij/src/main/java/ij/plugin/Zoom.java:156–257  ·  view source on GitHub ↗

Based on Albert Cardona's ZoomExact plugin: http://albert.rierol.net/software.html

(ImagePlus imp, double mag, int x, int y)

Source from the content-addressed store, hash-verified

154 /** Based on Albert Cardona's ZoomExact plugin:
155 http://albert.rierol.net/software.html */
156 void setZoom(ImagePlus imp, double mag, int x, int y) {
157 waitUntilActivated(imp);
158 ImageCanvas ic = imp.getCanvas();
159 if (ic==null)
160 return;
161 int width = imp.getWidth();
162 int height = imp.getHeight();
163 if (x==-1) {
164 x = width/2;
165 y = height/2;
166 }
167 Rectangle srcRect = ic.getSrcRect();
168 Roi roi = imp.getRoi();
169 boolean areaSelection = false;
170 if (roi!=null) {
171 Rectangle bounds = roi.getBounds();
172 x = bounds.x + bounds.width/2;
173 y = bounds.y + bounds.height/2;
174 areaSelection = roi.isArea();
175 if (areaSelection)
176 srcRect = bounds;
177 }
178 ImageWindow win = imp.getWindow();
179 int srcWidth = srcRect.width;
180 int srcHeight = srcRect.height;
181 if (mag==-1) {
182 GenericDialog gd = new GenericDialog("Set Zoom");
183 gd.addNumericField("Zoom:", ic.getMagnification() * 200, 0, 4, "%");
184 gd.addNumericField("X center:", x, 0, 5, "");
185 gd.addNumericField("Y center:", y, 0, 5, "");
186 if (areaSelection) {
187 gd.addNumericField("Width:", srcRect.width, 0, 5, "");
188 gd.addNumericField("Height:", srcRect.height, 0, 5, "");
189 }
190 gd.showDialog();
191 if (gd.wasCanceled()) return;
192 mag = gd.getNextNumber()/100.0;
193 int x2 = (int)gd.getNextNumber();
194 int y2 = (int)gd.getNextNumber();
195 boolean defaultLocation = x==x2 && y==y2;
196 x = x2;
197 y = y2;
198 if (areaSelection) {
199 srcWidth = (int)gd.getNextNumber();
200 srcHeight = (int)gd.getNextNumber();
201 }
202 if (defaultLocation)
203 Recorder.recordCall("Zoom.set(imp, "+mag+");");
204 else
205 Recorder.recordCall("Zoom.set(imp, "+mag+", "+x+", "+y+");");
206 }
207 if (x<0) x=0;
208 if (y<0) y=0;
209 String options = IJ.macroRunning()?Macro.getOptions():null;
210 boolean legacyMacro = areaSelection && options!=null && options.contains("x=") && !options.contains("width=");
211 Rectangle bounds = GUI.getMaxWindowBounds(win);
212 boolean smallImage = mag>1.0 && width*mag<bounds.width && height*mag<bounds.height;
213 if ((areaSelection||smallImage||srcWidth!=srcRect.width||srcHeight!=srcRect.height) && !legacyMacro) {

Callers 2

setMethod · 0.95
runMethod · 0.95

Calls 15

waitUntilActivatedMethod · 0.95
getSrcRectMethod · 0.95
getBoundsMethod · 0.95
isAreaMethod · 0.95
addNumericFieldMethod · 0.95
getMagnificationMethod · 0.95
showDialogMethod · 0.95
wasCanceledMethod · 0.95
getNextNumberMethod · 0.95
recordCallMethod · 0.95
macroRunningMethod · 0.95
getOptionsMethod · 0.95

Tested by

no test coverage detected