From 9851c2b81b1e502dc00c04f155a5ef6516be9c20 Mon Sep 17 00:00:00 2001 From: Adam Goode Date: Tue, 9 Dec 2008 16:42:56 -0500 Subject: [PATCH] Rename to OpenSlide --- .classpath | 2 +- .gitignore | 6 +- .project | 2 +- LICENSE.txt | 4 +- Makefile | 14 +-- TODO.txt | 4 +- build.xml | 10 +- openslide.i | 79 ++++++++++++++ .../Wholeslide.java => openslide/OpenSlide.java} | 65 +++++------ .../cs/openslide/OpenSlideDisposedException.java | 31 ++++++ .../OpenSlideException.java} | 20 ++-- src/edu/cmu/cs/{wholeslide => openslide}/Test.java | 52 ++++----- .../cmu/cs/{wholeslide => openslide}/gui/Demo.java | 30 +++--- .../gui/OpenSlideView.java} | 120 ++++++++++----------- .../cs/wholeslide/WholeslideDisposedException.java | 31 ------ wholeslide.i | 78 -------------- 16 files changed, 275 insertions(+), 273 deletions(-) create mode 100644 openslide.i rename src/edu/cmu/cs/{wholeslide/Wholeslide.java => openslide/OpenSlide.java} (74%) create mode 100644 src/edu/cmu/cs/openslide/OpenSlideDisposedException.java rename src/edu/cmu/cs/{wholeslide/WholeslideException.java => openslide/OpenSlideException.java} (51%) rename src/edu/cmu/cs/{wholeslide => openslide}/Test.java (83%) rename src/edu/cmu/cs/{wholeslide => openslide}/gui/Demo.java (74%) rename src/edu/cmu/cs/{wholeslide/gui/WholeslideView.java => openslide/gui/OpenSlideView.java} (85%) delete mode 100644 src/edu/cmu/cs/wholeslide/WholeslideDisposedException.java delete mode 100644 wholeslide.i diff --git a/.classpath b/.classpath index 12d91ec..75f7bc1 100644 --- a/.classpath +++ b/.classpath @@ -2,7 +2,7 @@ - + diff --git a/.gitignore b/.gitignore index aac120f..14a3e6d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,7 @@ /bin -/wholeslide_wrap.c -/wholeslidejava.jar +/openslide_wrap.c +/openslidejava.jar -/src/edu/cmu/cs/wholeslide/glue +/src/edu/cmu/cs/openslide/glue *.so diff --git a/.project b/.project index 7050802..a90a062 100644 --- a/.project +++ b/.project @@ -1,6 +1,6 @@ - Wholeslide + OpenSlide diff --git a/LICENSE.txt b/LICENSE.txt index 676d142..4f440c9 100644 --- a/LICENSE.txt +++ b/LICENSE.txt @@ -1,8 +1,8 @@ -Wholeslide +OpenSlide Carnegie Mellon University -http://wholeslide.cs.cmu.edu/ +http://openslide.cs.cmu.edu/ ==================== diff --git a/Makefile b/Makefile index d30d8f7..16f28d7 100644 --- a/Makefile +++ b/Makefile @@ -3,20 +3,20 @@ CC = gcc JAVAC = javac -all: libwholeslidejava.so src/edu/cmu/cs/wholeslide/glue/Wholeslide.java +all: libopenslidejava.so src/edu/cmu/cs/openslide/glue/OpenSlide.java ant -wholeslide_wrap.c src/edu/cmu/cs/wholeslide/glue/Wholeslide.java: wholeslide.i - mkdir -p src/edu/cmu/cs/wholeslide/glue - swig -includeall -Wall -I/usr/include -java $$(pkg-config wholeslide --cflags-only-I) -package edu.cmu.cs.wholeslide.glue -outdir src/edu/cmu/cs/wholeslide/glue $< +openslide_wrap.c src/edu/cmu/cs/openslide/glue/OpenSlide.java: openslide.i + mkdir -p src/edu/cmu/cs/openslide/glue + swig -includeall -Wall -I/usr/include -java $$(pkg-config openslide --cflags-only-I) -package edu.cmu.cs.openslide.glue -outdir src/edu/cmu/cs/openslide/glue $< -libwholeslidejava.so: wholeslide_wrap.c - $(CC) $(CFLAGS) -fPIC -fno-strict-aliasing -shared -g -O2 -Wall -o $@ $< $$(pkg-config wholeslide --cflags --libs) +libopenslidejava.so: openslide_wrap.c + $(CC) $(CFLAGS) -fPIC -fno-strict-aliasing -shared -g -O2 -Wall -o $@ $< $$(pkg-config openslide --cflags --libs) clean: ant clean - $(RM) libwholeslidejava.so wholeslide_wrap.c src/edu/cmu/cs/wholeslide/glue/*.java *~ bin + $(RM) libopenslidejava.so openslide_wrap.c src/edu/cmu/cs/openslide/glue/*.java *~ bin diff --git a/TODO.txt b/TODO.txt index 95fddea..bd00298 100644 --- a/TODO.txt +++ b/TODO.txt @@ -1,6 +1,6 @@ -Fancy zooming/scrolling in WholeslideView +Fancy zooming/scrolling in OpenSlideView -Rotation in WholeslideView +Rotation in OpenSlideView Make swig generated Java code not public diff --git a/build.xml b/build.xml index f397e1b..bbbdeab 100644 --- a/build.xml +++ b/build.xml @@ -1,10 +1,10 @@ - + - + @@ -15,11 +15,11 @@ - + - + @@ -27,7 +27,7 @@ - + diff --git a/openslide.i b/openslide.i new file mode 100644 index 0000000..d1059d4 --- /dev/null +++ b/openslide.i @@ -0,0 +1,79 @@ +/* -*- c -*- */ +/* + * OpenSlide, a library for reading whole slide image files + * + * Copyright (c) 2007-2008 Carnegie Mellon University + * All rights reserved. + * + * OpenSlide is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 2. + * + * OpenSlide is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with OpenSlide. If not, see . + * + * Linking OpenSlide statically or dynamically with other modules is + * making a combined work based on OpenSlide. Thus, the terms and + * conditions of the GNU General Public License cover the whole + * combination. + */ + +%module OpenSlide + +%include "typemaps.i" +%include "arrays_java.i" +%include "various.i" + +#include + +%javaconst(1); + +%{ +#include "openslide.h" +%} + +%pragma(java) jniclasscode=%{ + static { + try { + System.loadLibrary("openslidejava"); + } catch (UnsatisfiedLinkError e) { + System.err.println("Native code library failed to load. \n" + e); + } + } +%} + +%newobject openslide_open; + +%apply long long[] {int64_t *}; +%apply int[] {uint32_t *}; + +typedef struct _openslide openslide_t; + +bool openslide_can_open(const char *filename); + +openslide_t *openslide_open(const char *filename); + +void openslide_get_layer_dimensions(openslide_t *osr, int32_t layer, + int64_t *OUTPUT, int64_t *OUTPUT); + +int32_t openslide_get_layer_count(openslide_t *osr); + +void openslide_close(openslide_t *osr); + +const char *openslide_get_comment(openslide_t *osr); + +int32_t openslide_get_best_layer_for_downsample(openslide_t *osr, + double downsample); + +double openslide_get_layer_downsample(openslide_t *osr, int32_t layer); + +void openslide_read_region(openslide_t *osr, + uint32_t *dest, + int64_t x, int64_t y, + int32_t layer, + int64_t w, int64_t h); diff --git a/src/edu/cmu/cs/wholeslide/Wholeslide.java b/src/edu/cmu/cs/openslide/OpenSlide.java similarity index 74% rename from src/edu/cmu/cs/wholeslide/Wholeslide.java rename to src/edu/cmu/cs/openslide/OpenSlide.java index 897db54..0421929 100644 --- a/src/edu/cmu/cs/wholeslide/Wholeslide.java +++ b/src/edu/cmu/cs/openslide/OpenSlide.java @@ -1,28 +1,28 @@ /* - * Wholeslide, a library for reading whole slide image files + * OpenSlide, a library for reading whole slide image files * * Copyright (c) 2007-2008 Carnegie Mellon University * All rights reserved. * - * Wholeslide is free software: you can redistribute it and/or modify + * OpenSlide is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, version 2. * - * Wholeslide is distributed in the hope that it will be useful, + * OpenSlide is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with Wholeslide. If not, see . + * along with OpenSlide. If not, see . * - * Linking Wholeslide statically or dynamically with other modules is - * making a combined work based on Wholeslide. Thus, the terms and + * Linking OpenSlide statically or dynamically with other modules is + * making a combined work based on OpenSlide. Thus, the terms and * conditions of the GNU General Public License cover the whole * combination. */ -package edu.cmu.cs.wholeslide; +package edu.cmu.cs.openslide; import java.awt.Color; import java.awt.Graphics2D; @@ -30,10 +30,10 @@ import java.awt.image.DataBufferInt; import java.io.File; -import edu.cmu.cs.wholeslide.glue.SWIGTYPE_p__wholeslide; +import edu.cmu.cs.openslide.glue.SWIGTYPE_p__openslide; -public class Wholeslide { - private SWIGTYPE_p__wholeslide wsd; +public class OpenSlide { + private SWIGTYPE_p__openslide osr; final private long layerWidths[]; @@ -42,21 +42,22 @@ final private int layerCount; public static boolean fileIsValid(File file) { - return edu.cmu.cs.wholeslide.glue.Wholeslide - .ws_can_open(file.getPath()); + return edu.cmu.cs.openslide.glue.OpenSlide.openslide_can_open(file + .getPath()); } - public Wholeslide(File file) { - wsd = edu.cmu.cs.wholeslide.glue.Wholeslide.ws_open(file.getPath()); + public OpenSlide(File file) { + osr = edu.cmu.cs.openslide.glue.OpenSlide + .openslide_open(file.getPath()); - if (wsd == null) { + if (osr == null) { // TODO not just file not found - throw new WholeslideException(); + throw new OpenSlideException(); } // store layer count - layerCount = edu.cmu.cs.wholeslide.glue.Wholeslide - .ws_get_layer_count(wsd); + layerCount = edu.cmu.cs.openslide.glue.OpenSlide + .openslide_get_layer_count(osr); // store dimensions layerWidths = new long[layerCount]; @@ -65,17 +66,17 @@ public Wholeslide(File file) { for (int i = 0; i < layerCount; i++) { long w[] = new long[1]; long h[] = new long[1]; - edu.cmu.cs.wholeslide.glue.Wholeslide.ws_get_layer_dimensions(wsd, - i, w, h); + edu.cmu.cs.openslide.glue.OpenSlide.openslide_get_layer_dimensions( + osr, i, w, h); layerWidths[i] = w[0]; layerHeights[i] = h[0]; } } public void dispose() { - if (wsd != null) { - edu.cmu.cs.wholeslide.glue.Wholeslide.ws_close(wsd); - wsd = null; + if (osr != null) { + edu.cmu.cs.openslide.glue.OpenSlide.openslide_close(osr); + osr = null; } } @@ -90,8 +91,8 @@ public int getLayerCount() { } private void checkDisposed() { - if (wsd == null) { - throw new WholeslideDisposedException(); + if (osr == null) { + throw new OpenSlideDisposedException(); } } @@ -114,7 +115,7 @@ public long getLayerHeight(int layer) { public String getComment() { checkDisposed(); - return edu.cmu.cs.wholeslide.glue.Wholeslide.ws_get_comment(wsd); + return edu.cmu.cs.openslide.glue.OpenSlide.openslide_get_comment(osr); } public void paintRegion(Graphics2D g, int dx, int dy, int sx, int sy, @@ -127,12 +128,12 @@ public void paintRegion(Graphics2D g, int dx, int dy, int sx, int sy, } // get the layer - int layer = edu.cmu.cs.wholeslide.glue.Wholeslide - .ws_get_best_layer_for_downsample(wsd, downsample); + int layer = edu.cmu.cs.openslide.glue.OpenSlide + .openslide_get_best_layer_for_downsample(osr, downsample); // figure out its downsample - double layerDS = edu.cmu.cs.wholeslide.glue.Wholeslide - .ws_get_layer_downsample(wsd, layer); + double layerDS = edu.cmu.cs.openslide.glue.OpenSlide + .openslide_get_layer_downsample(osr, layer); // compute the difference double relativeDS = downsample / layerDS; @@ -181,8 +182,8 @@ public void paintRegion(Graphics2D g, int dx, int dy, int sx, int sy, int data[] = ((DataBufferInt) img.getRaster().getDataBuffer()) .getData(); - edu.cmu.cs.wholeslide.glue.Wholeslide.ws_read_region(wsd, data, baseX, - baseY, layer, img.getWidth(), img.getHeight()); + edu.cmu.cs.openslide.glue.OpenSlide.openslide_read_region(osr, data, + baseX, baseY, layer, img.getWidth(), img.getHeight()); // g.scale(1.0 / relativeDS, 1.0 / relativeDS); g.drawImage(img, dx, dy, w, h, null); diff --git a/src/edu/cmu/cs/openslide/OpenSlideDisposedException.java b/src/edu/cmu/cs/openslide/OpenSlideDisposedException.java new file mode 100644 index 0000000..d2a0929 --- /dev/null +++ b/src/edu/cmu/cs/openslide/OpenSlideDisposedException.java @@ -0,0 +1,31 @@ +/* + * OpenSlide, a library for reading whole slide image files + * + * Copyright (c) 2007-2008 Carnegie Mellon University + * All rights reserved. + * + * OpenSlide is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 2. + * + * OpenSlide is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with OpenSlide. If not, see . + * + * Linking OpenSlide statically or dynamically with other modules is + * making a combined work based on OpenSlide. Thus, the terms and + * conditions of the GNU General Public License cover the whole + * combination. + */ + +package edu.cmu.cs.openslide; + +public class OpenSlideDisposedException extends OpenSlideException { + public OpenSlideDisposedException() { + super("OpenSlide object has been disposed"); + } +} diff --git a/src/edu/cmu/cs/wholeslide/WholeslideException.java b/src/edu/cmu/cs/openslide/OpenSlideException.java similarity index 51% rename from src/edu/cmu/cs/wholeslide/WholeslideException.java rename to src/edu/cmu/cs/openslide/OpenSlideException.java index f5eb5e3..b74b754 100644 --- a/src/edu/cmu/cs/wholeslide/WholeslideException.java +++ b/src/edu/cmu/cs/openslide/OpenSlideException.java @@ -1,35 +1,35 @@ /* - * Wholeslide, a library for reading whole slide image files + * OpenSlide, a library for reading whole slide image files * * Copyright (c) 2007-2008 Carnegie Mellon University * All rights reserved. * - * Wholeslide is free software: you can redistribute it and/or modify + * OpenSlide is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, version 2. * - * Wholeslide is distributed in the hope that it will be useful, + * OpenSlide is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with Wholeslide. If not, see . + * along with OpenSlide. If not, see . * - * Linking Wholeslide statically or dynamically with other modules is - * making a combined work based on Wholeslide. Thus, the terms and + * Linking OpenSlide statically or dynamically with other modules is + * making a combined work based on OpenSlide. Thus, the terms and * conditions of the GNU General Public License cover the whole * combination. */ -package edu.cmu.cs.wholeslide; +package edu.cmu.cs.openslide; -public class WholeslideException extends RuntimeException { - public WholeslideException(String string) { +public class OpenSlideException extends RuntimeException { + public OpenSlideException(String string) { super(string); } - public WholeslideException() { + public OpenSlideException() { super(); } } diff --git a/src/edu/cmu/cs/wholeslide/Test.java b/src/edu/cmu/cs/openslide/Test.java similarity index 83% rename from src/edu/cmu/cs/wholeslide/Test.java rename to src/edu/cmu/cs/openslide/Test.java index 7ab559f..ff3b85b 100644 --- a/src/edu/cmu/cs/wholeslide/Test.java +++ b/src/edu/cmu/cs/openslide/Test.java @@ -1,28 +1,28 @@ /* - * Wholeslide, a library for reading whole slide image files + * OpenSlide, a library for reading whole slide image files * * Copyright (c) 2007-2008 Carnegie Mellon University * All rights reserved. * - * Wholeslide is free software: you can redistribute it and/or modify + * OpenSlide is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, version 2. * - * Wholeslide is distributed in the hope that it will be useful, + * OpenSlide is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with Wholeslide. If not, see . + * along with OpenSlide. If not, see . * - * Linking Wholeslide statically or dynamically with other modules is - * making a combined work based on Wholeslide. Thus, the terms and + * Linking OpenSlide statically or dynamically with other modules is + * making a combined work based on OpenSlide. Thus, the terms and * conditions of the GNU General Public License cover the whole * combination. */ -package edu.cmu.cs.wholeslide; +package edu.cmu.cs.openslide; import java.awt.*; import java.awt.event.MouseAdapter; @@ -36,7 +36,7 @@ private static final int MIN_SIZE = 100; - final transient private Wholeslide wsd; + final transient private OpenSlide osr; private int downsampleFactor = 0; @@ -60,12 +60,12 @@ private double getDownsample() { return Math.pow(DOWNSAMPLE_BASE, downsampleFactor); } - public Test(Wholeslide w) { - wsd = w; + public Test(OpenSlide w) { + osr = w; - maxDownsampleFactor = (int) Math.max(Math.log(wsd.getLayer0Height() + maxDownsampleFactor = (int) Math.max(Math.log(osr.getLayer0Height() / MIN_SIZE) - / Math.log(DOWNSAMPLE_BASE), Math.log(wsd.getLayer0Width() + / Math.log(DOWNSAMPLE_BASE), Math.log(osr.getLayer0Width() / MIN_SIZE) / Math.log(DOWNSAMPLE_BASE)); @@ -73,8 +73,8 @@ public Test(Wholeslide w) { } private void updateSize() { - long w = wsd.getLayer0Width(); - long h = wsd.getLayer0Height(); + long w = osr.getLayer0Width(); + long h = osr.getLayer0Height(); double downsample = getDownsample(); w /= downsample; h /= downsample; @@ -94,7 +94,7 @@ private void updateSize() { public static void main(String[] args) { File f = new File(args[0]); - Wholeslide w = new Wholeslide(f); + OpenSlide w = new OpenSlide(f); JFrame j = new JFrame("OMG"); @@ -214,31 +214,31 @@ protected void paintComponent(Graphics g) { int offsetX = 0; int offsetY = 0; - long wsdW = wsd.getLayer0Width(); - long wsdH = wsd.getLayer0Height(); + long osrW = osr.getLayer0Width(); + long osrH = osr.getLayer0Height(); double downsample = getDownsample(); - wsdW /= downsample; - wsdH /= downsample; + osrW /= downsample; + osrH /= downsample; int w = getWidth(); int h = getHeight(); - if (w > wsdW) { - offsetX = (int) ((w - wsdW) / 2); + if (w > osrW) { + offsetX = (int) ((w - osrW) / 2); } - if (h > wsdH) { - offsetY = (int) ((h - wsdH) / 2); + if (h > osrH) { + offsetY = (int) ((h - osrH) / 2); } Rectangle clip = g2.getClipBounds(); g2.setColor(Color.BLACK); int rectVal = 3; - g2.fillRect(offsetX + rectVal, offsetY + rectVal, (int) wsdW, - (int) wsdH); + g2.fillRect(offsetX + rectVal, offsetY + rectVal, (int) osrW, + (int) osrH); // System.out.println(clip); - wsd.paintRegion(g2, clip.x, clip.y, clip.x - offsetX, clip.y - offsetY, + osr.paintRegion(g2, clip.x, clip.y, clip.x - offsetX, clip.y - offsetY, clip.width, clip.height, downsample); } } diff --git a/src/edu/cmu/cs/wholeslide/gui/Demo.java b/src/edu/cmu/cs/openslide/gui/Demo.java similarity index 74% rename from src/edu/cmu/cs/wholeslide/gui/Demo.java rename to src/edu/cmu/cs/openslide/gui/Demo.java index 8ae9de0..906b67e 100644 --- a/src/edu/cmu/cs/wholeslide/gui/Demo.java +++ b/src/edu/cmu/cs/openslide/gui/Demo.java @@ -1,28 +1,28 @@ /* - * Wholeslide, a library for reading whole slide image files + * OpenSlide, a library for reading whole slide image files * * Copyright (c) 2007-2008 Carnegie Mellon University * All rights reserved. * - * Wholeslide is free software: you can redistribute it and/or modify + * OpenSlide is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, version 2. * - * Wholeslide is distributed in the hope that it will be useful, + * OpenSlide is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with Wholeslide. If not, see . + * along with OpenSlide. If not, see . * - * Linking Wholeslide statically or dynamically with other modules is - * making a combined work based on Wholeslide. Thus, the terms and + * Linking OpenSlide statically or dynamically with other modules is + * making a combined work based on OpenSlide. Thus, the terms and * conditions of the GNU General Public License cover the whole * combination. */ -package edu.cmu.cs.wholeslide.gui; +package edu.cmu.cs.openslide.gui; import java.awt.BorderLayout; import java.awt.event.*; @@ -30,11 +30,11 @@ import javax.swing.*; -import edu.cmu.cs.wholeslide.Wholeslide; +import edu.cmu.cs.openslide.OpenSlide; public class Demo { public static void main(String[] args) { - JFrame jf = new JFrame("Wholeslide"); + JFrame jf = new JFrame("OpenSlide"); jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); switch (args.length) { @@ -43,8 +43,8 @@ public static void main(String[] args) { return; case 1: - final WholeslideView wv = new WholeslideView(new Wholeslide( - new File(args[0])), true); + final OpenSlideView wv = new OpenSlideView(new OpenSlide(new File( + args[0])), true); wv.setBorder(BorderFactory.createTitledBorder(args[0])); jf.getContentPane().add(wv); @@ -68,10 +68,10 @@ public void mouseExited(MouseEvent e) { break; case 2: - final WholeslideView w1 = new WholeslideView(new Wholeslide( - new File(args[0])), true); - final WholeslideView w2 = new WholeslideView(new Wholeslide( - new File(args[1])), true); + final OpenSlideView w1 = new OpenSlideView(new OpenSlide(new File( + args[0])), true); + final OpenSlideView w2 = new OpenSlideView(new OpenSlide(new File( + args[1])), true); Box b = Box.createHorizontalBox(); b.add(w1); b.add(w2); diff --git a/src/edu/cmu/cs/wholeslide/gui/WholeslideView.java b/src/edu/cmu/cs/openslide/gui/OpenSlideView.java similarity index 85% rename from src/edu/cmu/cs/wholeslide/gui/WholeslideView.java rename to src/edu/cmu/cs/openslide/gui/OpenSlideView.java index 8cf5dd7..8f1b779 100644 --- a/src/edu/cmu/cs/wholeslide/gui/WholeslideView.java +++ b/src/edu/cmu/cs/openslide/gui/OpenSlideView.java @@ -1,28 +1,28 @@ /* - * Wholeslide, a library for reading whole slide image files + * OpenSlide, a library for reading whole slide image files * * Copyright (c) 2007-2008 Carnegie Mellon University * All rights reserved. * - * Wholeslide is free software: you can redistribute it and/or modify + * OpenSlide is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, version 2. * - * Wholeslide is distributed in the hope that it will be useful, + * OpenSlide is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with Wholeslide. If not, see . + * along with OpenSlide. If not, see . * - * Linking Wholeslide statically or dynamically with other modules is - * making a combined work based on Wholeslide. Thus, the terms and + * Linking OpenSlide statically or dynamically with other modules is + * making a combined work based on OpenSlide. Thus, the terms and * conditions of the GNU General Public License cover the whole * combination. */ -package edu.cmu.cs.wholeslide.gui; +package edu.cmu.cs.openslide.gui; import java.awt.*; import java.awt.event.*; @@ -33,16 +33,16 @@ import javax.swing.*; -import edu.cmu.cs.wholeslide.Wholeslide; +import edu.cmu.cs.openslide.OpenSlide; -public class WholeslideView extends JComponent { +public class OpenSlideView extends JComponent { private static final int KEYBOARD_SCROLL_AMOUNT = 100; final private double downsampleBase; final private int maxDownsampleExponent; - transient final private Wholeslide wsd; + transient final private OpenSlide osr; private int rotation; @@ -52,7 +52,7 @@ private Point viewPosition = new Point(); - private WholeslideView otherView; + private OpenSlideView otherView; protected Shape selection; @@ -66,25 +66,25 @@ private final boolean startWithZoomFit; - public WholeslideView(Wholeslide w) { + public OpenSlideView(OpenSlide w) { this(w, false); } - public WholeslideView(Wholeslide w, boolean startWithZoomFit) { + public OpenSlideView(OpenSlide w, boolean startWithZoomFit) { this(w, 1.2, 40, startWithZoomFit); } - public WholeslideView(Wholeslide w, double downsampleBase, + public OpenSlideView(OpenSlide w, double downsampleBase, int maxDownsampleExponent, boolean startWithZoomFit) { // TODO support w > 2^31 and h > 2^31 if (w.getLayer0Width() > Integer.MAX_VALUE || w.getLayer0Height() > Integer.MAX_VALUE) { throw new IllegalArgumentException( - "Wholeslide size must not exceed (" + Integer.MAX_VALUE + "OpenSlide size must not exceed (" + Integer.MAX_VALUE + "," + Integer.MAX_VALUE + ")"); } - wsd = w; + osr = w; this.downsampleBase = downsampleBase; this.maxDownsampleExponent = maxDownsampleExponent; this.startWithZoomFit = startWithZoomFit; @@ -104,14 +104,14 @@ public void setBackground(Color bg) { } } - static private void translateHelper(WholeslideView ws, int dX, int dY) { + static private void translateHelper(OpenSlideView ws, int dX, int dY) { if (ws == null) { return; } ws.translateSlidePrivate(dX, dY); } - static private void repaintHelper(WholeslideView w) { + static private void repaintHelper(OpenSlideView w) { if (w == null) { return; } @@ -119,7 +119,7 @@ static private void repaintHelper(WholeslideView w) { w.repaint(); } - static private void centerHelper(WholeslideView w) { + static private void centerHelper(OpenSlideView w) { if (w == null) { return; } @@ -165,7 +165,7 @@ private void translateSlidePrivate(int dX, int dY) { g.dispose(); } - static private double zoomHelper(WholeslideView w, int x, int y, int amount) { + static private double zoomHelper(OpenSlideView w, int x, int y, int amount) { if (w == null) { return 1.0; } @@ -178,7 +178,7 @@ static private double zoomHelper(WholeslideView w, int x, int y, int amount) { return oldDS / newDS; } - static private void zoomHelper2(WholeslideView w, double relDS, int x, int y) { + static private void zoomHelper2(OpenSlideView w, double relDS, int x, int y) { if (w == null) { return; } @@ -196,7 +196,7 @@ static private void zoomHelper2(WholeslideView w, double relDS, int x, int y) { } } - static private void zoomHelper3(WholeslideView w, double relDS) { + static private void zoomHelper3(OpenSlideView w, double relDS) { if (w == null) { return; } @@ -210,15 +210,15 @@ private void registerEventHandlers() { // mouse wheel addMouseWheelListener(new MouseWheelListener() { public void mouseWheelMoved(MouseWheelEvent e) { - double ds1 = zoomHelper(WholeslideView.this, e.getX(), - e.getY(), e.getWheelRotation()); + double ds1 = zoomHelper(OpenSlideView.this, e.getX(), e.getY(), + e.getWheelRotation()); double ds2 = zoomHelper(otherView, e.getX(), e.getY(), e .getWheelRotation()); - zoomHelper2(WholeslideView.this, ds1, e.getX(), e.getY()); + zoomHelper2(OpenSlideView.this, ds1, e.getX(), e.getY()); zoomHelper2(otherView, ds2, e.getX(), e.getY()); - zoomHelper3(WholeslideView.this, ds1); + zoomHelper3(OpenSlideView.this, ds1); zoomHelper3(otherView, ds2); - repaintHelper(WholeslideView.this); + repaintHelper(OpenSlideView.this); repaintHelper(otherView); } }); @@ -286,9 +286,9 @@ public void mouseDragged(MouseEvent e) { switch (selectionMode) { case SELECTION_MODE_NONE: - translateHelper(WholeslideView.this, relX, relY); + translateHelper(OpenSlideView.this, relX, relY); translateHelper(otherView, relX, relY); - repaintHelper(WholeslideView.this); + repaintHelper(OpenSlideView.this); repaintHelper(otherView); break; @@ -362,9 +362,9 @@ public void mouseReleased(MouseEvent e) { inputMap.put(KeyStroke.getKeyStroke("SPACE"), "center"); actionMap.put("center", new AbstractAction() { public void actionPerformed(ActionEvent e) { - centerHelper(WholeslideView.this); + centerHelper(OpenSlideView.this); centerHelper(otherView); - repaintHelper(WholeslideView.this); + repaintHelper(OpenSlideView.this); repaintHelper(otherView); } }); @@ -373,9 +373,9 @@ public void actionPerformed(ActionEvent e) { inputMap.put(KeyStroke.getKeyStroke("W"), "scroll up"); actionMap.put("scroll up", new AbstractAction() { public void actionPerformed(ActionEvent e) { - translateHelper(WholeslideView.this, 0, -KEYBOARD_SCROLL_AMOUNT); + translateHelper(OpenSlideView.this, 0, -KEYBOARD_SCROLL_AMOUNT); translateHelper(otherView, 0, -KEYBOARD_SCROLL_AMOUNT); - repaintHelper(WholeslideView.this); + repaintHelper(OpenSlideView.this); repaintHelper(otherView); } }); @@ -384,9 +384,9 @@ public void actionPerformed(ActionEvent e) { inputMap.put(KeyStroke.getKeyStroke("S"), "scroll down"); actionMap.put("scroll down", new AbstractAction() { public void actionPerformed(ActionEvent e) { - translateHelper(WholeslideView.this, 0, KEYBOARD_SCROLL_AMOUNT); + translateHelper(OpenSlideView.this, 0, KEYBOARD_SCROLL_AMOUNT); translateHelper(otherView, 0, KEYBOARD_SCROLL_AMOUNT); - repaintHelper(WholeslideView.this); + repaintHelper(OpenSlideView.this); repaintHelper(otherView); } }); @@ -395,9 +395,9 @@ public void actionPerformed(ActionEvent e) { inputMap.put(KeyStroke.getKeyStroke("A"), "scroll left"); actionMap.put("scroll left", new AbstractAction() { public void actionPerformed(ActionEvent e) { - translateHelper(WholeslideView.this, -KEYBOARD_SCROLL_AMOUNT, 0); + translateHelper(OpenSlideView.this, -KEYBOARD_SCROLL_AMOUNT, 0); translateHelper(otherView, -KEYBOARD_SCROLL_AMOUNT, 0); - repaintHelper(WholeslideView.this); + repaintHelper(OpenSlideView.this); repaintHelper(otherView); } }); @@ -406,9 +406,9 @@ public void actionPerformed(ActionEvent e) { inputMap.put(KeyStroke.getKeyStroke("D"), "scroll right"); actionMap.put("scroll right", new AbstractAction() { public void actionPerformed(ActionEvent e) { - translateHelper(WholeslideView.this, KEYBOARD_SCROLL_AMOUNT, 0); + translateHelper(OpenSlideView.this, KEYBOARD_SCROLL_AMOUNT, 0); translateHelper(otherView, KEYBOARD_SCROLL_AMOUNT, 0); - repaintHelper(WholeslideView.this); + repaintHelper(OpenSlideView.this); repaintHelper(otherView); } }); @@ -439,13 +439,13 @@ public void actionPerformed(ActionEvent e) { inputMap.put(KeyStroke.getKeyStroke("EQUALS"), "zoom in"); actionMap.put("zoom in", new AbstractAction() { public void actionPerformed(ActionEvent e) { - double d1 = zoomHelper(WholeslideView.this, -1); + double d1 = zoomHelper(OpenSlideView.this, -1); double d2 = zoomHelper(otherView, -1); - zoomHelper2(WholeslideView.this, d1); + zoomHelper2(OpenSlideView.this, d1); zoomHelper2(otherView, d2); - zoomHelper3(WholeslideView.this, d1); + zoomHelper3(OpenSlideView.this, d1); zoomHelper3(otherView, d2); - repaintHelper(WholeslideView.this); + repaintHelper(OpenSlideView.this); repaintHelper(otherView); } }); @@ -453,13 +453,13 @@ public void actionPerformed(ActionEvent e) { inputMap.put(KeyStroke.getKeyStroke("MINUS"), "zoom out"); actionMap.put("zoom out", new AbstractAction() { public void actionPerformed(ActionEvent e) { - double d1 = zoomHelper(WholeslideView.this, 1); + double d1 = zoomHelper(OpenSlideView.this, 1); double d2 = zoomHelper(otherView, 1); - zoomHelper2(WholeslideView.this, d1); + zoomHelper2(OpenSlideView.this, d1); zoomHelper2(otherView, d2); - zoomHelper3(WholeslideView.this, d1); + zoomHelper3(OpenSlideView.this, d1); zoomHelper3(otherView, d2); - repaintHelper(WholeslideView.this); + repaintHelper(OpenSlideView.this); repaintHelper(otherView); } }); @@ -479,13 +479,13 @@ public void actionPerformed(ActionEvent e) { actionMap.put("zoom to 1:1", new AbstractAction() { public void actionPerformed(ActionEvent e) { System.out.println("zoom 1:1"); - double d1 = zoomHelper(WholeslideView.this, Integer.MIN_VALUE); + double d1 = zoomHelper(OpenSlideView.this, Integer.MIN_VALUE); double d2 = zoomHelper(otherView, Integer.MIN_VALUE); - zoomHelper2(WholeslideView.this, d1); + zoomHelper2(OpenSlideView.this, d1); zoomHelper2(otherView, d2); - zoomHelper3(WholeslideView.this, d1); + zoomHelper3(OpenSlideView.this, d1); zoomHelper3(otherView, d2); - repaintHelper(WholeslideView.this); + repaintHelper(OpenSlideView.this); repaintHelper(otherView); } }); @@ -499,14 +499,14 @@ public void actionPerformed(ActionEvent e) { oldActionMap.setParent(actionMap); } - protected void zoomHelper2(WholeslideView w, double d) { + protected void zoomHelper2(OpenSlideView w, double d) { if (w == null) { return; } zoomHelper2(w, d, w.getWidth() / 2, w.getHeight() / 2); } - static protected double zoomHelper(WholeslideView w, int i) { + static protected double zoomHelper(OpenSlideView w, int i) { if (w == null) { return 1.0; } @@ -570,7 +570,7 @@ private void centerOnSelectionPrivate() { } private void centerSlidePrivate() { - centerSlidePrivate((int) (wsd.getLayer0Width() / 2), (int) (wsd + centerSlidePrivate((int) (osr.getLayer0Width() / 2), (int) (osr .getLayer0Height() / 2)); } @@ -607,8 +607,8 @@ private void zoomToFit() { return; } - double ws = (double) wsd.getLayer0Width() / w; - double hs = (double) wsd.getLayer0Height() / h; + double ws = (double) osr.getLayer0Width() / w; + double hs = (double) osr.getLayer0Height() / h; double maxS = Math.max(ws, hs); @@ -634,7 +634,7 @@ private void rotateSlide(int quads) { } } - public void linkWithOther(WholeslideView otherView) { + public void linkWithOther(OpenSlideView otherView) { this.otherView = otherView; otherView.otherView = this; } @@ -725,7 +725,7 @@ private void paintBackingStore(Graphics2D g) { g.setBackground(getBackground()); g.clearRect(clip.x, clip.y, clip.width, clip.height); - wsd.paintRegion(g, clip.x, clip.y, offsetX + clip.x, offsetY + clip.y, + osr.paintRegion(g, clip.x, clip.y, offsetX + clip.x, offsetY + clip.y, clip.width, clip.height, ds); } @@ -787,8 +787,8 @@ public void setSelection(Shape s) { repaint(); } - public Wholeslide getWholeslide() { - return wsd; + public OpenSlide getOpenSlide() { + return osr; } public long getSlideX(int x) { diff --git a/src/edu/cmu/cs/wholeslide/WholeslideDisposedException.java b/src/edu/cmu/cs/wholeslide/WholeslideDisposedException.java deleted file mode 100644 index 7852bfb..0000000 --- a/src/edu/cmu/cs/wholeslide/WholeslideDisposedException.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Wholeslide, a library for reading whole slide image files - * - * Copyright (c) 2007-2008 Carnegie Mellon University - * All rights reserved. - * - * Wholeslide is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, version 2. - * - * Wholeslide is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Wholeslide. If not, see . - * - * Linking Wholeslide statically or dynamically with other modules is - * making a combined work based on Wholeslide. Thus, the terms and - * conditions of the GNU General Public License cover the whole - * combination. - */ - -package edu.cmu.cs.wholeslide; - -public class WholeslideDisposedException extends WholeslideException { - public WholeslideDisposedException() { - super("Wholeslide object has been disposed"); - } -} diff --git a/wholeslide.i b/wholeslide.i deleted file mode 100644 index 7d95fb7..0000000 --- a/wholeslide.i +++ /dev/null @@ -1,78 +0,0 @@ -/* -*- c -*- */ -/* - * Wholeslide, a library for reading whole slide image files - * - * Copyright (c) 2007-2008 Carnegie Mellon University - * All rights reserved. - * - * Wholeslide is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, version 2. - * - * Wholeslide is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Wholeslide. If not, see . - * - * Linking Wholeslide statically or dynamically with other modules is - * making a combined work based on Wholeslide. Thus, the terms and - * conditions of the GNU General Public License cover the whole - * combination. - */ - -%module Wholeslide - -%include "typemaps.i" -%include "arrays_java.i" -%include "various.i" - -#include - -%javaconst(1); - -%{ -#include "wholeslide.h" -%} - -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary("wholeslidejava"); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. \n" + e); - } - } -%} - -%newobject ws_open; - -%apply long long[] {int64_t *}; -%apply int[] {uint32_t *}; - -typedef struct _wholeslide wholeslide_t; - -bool ws_can_open(const char *filename); - -wholeslide_t *ws_open(const char *filename); - -void ws_get_layer_dimensions(wholeslide_t *wsd, int32_t layer, - int64_t *OUTPUT, int64_t *OUTPUT); - -int32_t ws_get_layer_count(wholeslide_t *wsd); - -void ws_close(wholeslide_t *wsd); - -const char *ws_get_comment(wholeslide_t *wsd); - -int32_t ws_get_best_layer_for_downsample(wholeslide_t *wsd, double downsample); - -double ws_get_layer_downsample(wholeslide_t *wsd, int32_t layer); - -void ws_read_region(wholeslide_t *wsd, - uint32_t *dest, - int64_t x, int64_t y, - int32_t layer, - int64_t w, int64_t h);