Skip to content

Commit

Permalink
Merge branch 'ebremer:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
ebremer authored Oct 10, 2023
2 parents 58d5958 + ee12937 commit ec54c11
Show file tree
Hide file tree
Showing 9 changed files with 98 additions and 133 deletions.
12 changes: 6 additions & 6 deletions dependency-reduced-pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>edu.stonybrook.bmi</groupId>
<artifactId>hatch</artifactId>
<version>3.1.1</version>
<version>3.1.2</version>
<build>
<resources>
<resource>
Expand All @@ -28,7 +28,7 @@
<plugins>
<plugin>
<artifactId>maven-enforcer-plugin</artifactId>
<version>3.3.0</version>
<version>3.4.1</version>
<executions>
<execution>
<id>enforce</id>
Expand Down Expand Up @@ -87,7 +87,7 @@
<plugin>
<groupId>org.graalvm.buildtools</groupId>
<artifactId>native-maven-plugin</artifactId>
<version>0.9.21</version>
<version>0.9.27</version>
<extensions>true</extensions>
<executions>
<execution>
Expand Down Expand Up @@ -129,9 +129,9 @@
</repository>
</repositories>
<properties>
<maven.compiler.target>17</maven.compiler.target>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>21</maven.compiler.target>
<maven.compiler.source>21</maven.compiler.source>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<ver.bioformats>6.12.0</ver.bioformats>
<ver.bioformats>7.0.0</ver.bioformats>
</properties>
</project>
6 changes: 3 additions & 3 deletions nbactions-hatchjar.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<properties>
<exec.vmArgs></exec.vmArgs>
<exec.args>${exec.vmArgs} -classpath %classpath ${exec.mainClass} ${exec.appArgs}</exec.args>
<exec.appArgs>-jp2 -v -src \hatchtest\src -dest \hatchtest\dest</exec.appArgs>
<exec.appArgs>-src \vsi\vsi -dest \vsi\warp</exec.appArgs>
<exec.mainClass>edu.stonybrook.bmi.hatch.Hatch</exec.mainClass>
<exec.executable>java</exec.executable>
</properties>
Expand All @@ -29,7 +29,7 @@
<properties>
<exec.vmArgs>-agentlib:jdwp=transport=dt_socket,server=n,address=${jpda.address}</exec.vmArgs>
<exec.args>${exec.vmArgs} -classpath %classpath ${exec.mainClass} ${exec.appArgs}</exec.args>
<exec.appArgs>-jp2 -v -src \hatchtest\src -dest \hatchtest\dest</exec.appArgs>
<exec.appArgs>-src \vsi\vsi -dest \vsi\warp</exec.appArgs>
<exec.mainClass>edu.stonybrook.bmi.hatch.Hatch</exec.mainClass>
<exec.executable>java</exec.executable>
<jpda.listen>true</jpda.listen>
Expand All @@ -49,7 +49,7 @@
<exec.args>${exec.vmArgs} -classpath %classpath ${exec.mainClass} ${exec.appArgs}</exec.args>
<exec.mainClass>edu.stonybrook.bmi.hatch.Hatch</exec.mainClass>
<exec.executable>java</exec.executable>
<exec.appArgs>-jp2 -v -src \hatchtest\src -dest \hatchtest\dest</exec.appArgs>
<exec.appArgs>-src \vsi\vsi -dest \vsi\warp</exec.appArgs>
</properties>
</action>
</actions>
29 changes: 6 additions & 23 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
<modelVersion>4.0.0</modelVersion>
<groupId>edu.stonybrook.bmi</groupId>
<artifactId>hatch</artifactId>
<version>3.1.1</version>
<version>3.1.2</version>
<packaging>jar</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<ver.bioformats>6.12.0</ver.bioformats>
<maven.compiler.source>21</maven.compiler.source>
<maven.compiler.target>21</maven.compiler.target>
<ver.bioformats>7.0.0</ver.bioformats>
</properties>
<dependencies>
<dependency>
Expand All @@ -29,23 +29,6 @@
<artifactId>jcommander</artifactId>
<version>1.82</version>
</dependency>
<!--
<dependency>
<groupId>org.apache.jena</groupId>
<artifactId>jena-core</artifactId>
<version>4.8.0</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>com.github.jai-imageio</groupId>
<artifactId>jai-imageio-core</artifactId>
<version>1.4.0</version>
</dependency>
<dependency>
<groupId>com.github.jai-imageio</groupId>
<artifactId>jai-imageio-jpeg2000</artifactId>
<version>1.4.0</version>
</dependency>-->
</dependencies>
<build>
<resources>
Expand Down Expand Up @@ -86,7 +69,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>3.3.0</version>
<version>3.4.1</version>
<executions>
<execution>
<id>enforce</id>
Expand Down Expand Up @@ -146,7 +129,7 @@
<plugin>
<groupId>org.graalvm.buildtools</groupId>
<artifactId>native-maven-plugin</artifactId>
<version>0.9.21</version>
<version>0.9.27</version>
<extensions>true</extensions>
<executions>
<execution>
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/edu/stonybrook/bmi/hatch/Hatch.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
* @author erich
*/
public class Hatch {
public static String software = "hatch 3.1.1 by Wing-n-Beak";
public static String software = "hatch 3.1.2 by Wing-n-Beak";
private static final String[] ext = new String[] {".vsi", ".svs", ".tif"};
public static final String HELP = Hatch.software+"\n"+
"""
Expand Down
6 changes: 0 additions & 6 deletions src/main/java/edu/stonybrook/bmi/hatch/HatchParameters.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,8 @@ public boolean isHelp() {
@Parameter(names = "-fp", description = "# of file processors")
public int fp = 1;

@Parameter(names = "-cores", description = "# of cores for processing")
public int cores = Runtime.getRuntime().availableProcessors();

@Parameter(names = {"-v","-verbose"})
public boolean verbose = false;

//@Parameter(names = "-meta")
//public boolean meta = false;

@Parameter(names = "-jp2", hidden = true)
public boolean jp2 = false;
Expand Down
114 changes: 52 additions & 62 deletions src/main/java/edu/stonybrook/bmi/hatch/Pyramid.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,27 @@
import java.awt.geom.AffineTransform;
import java.awt.image.AffineTransformOp;
import java.awt.image.BufferedImage;
import java.io.BufferedInputStream;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.ByteOrder;
import java.util.concurrent.Callable;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.imageio.IIOImage;
import javax.imageio.ImageIO;
import javax.imageio.ImageReader;
import javax.imageio.ImageWriteParam;
import javax.imageio.ImageWriter;
import javax.imageio.stream.ImageInputStream;
import javax.imageio.stream.ImageOutputStream;
import javax.imageio.stream.MemoryCacheImageInputStream;
import javax.imageio.stream.MemoryCacheImageOutputStream;

/**
Expand Down Expand Up @@ -76,7 +79,7 @@ public JPEGBuffer[][] getTiles() {
return tiles;
}

public void put(byte[] raw, int x, int y, int effTileSizeX, int effTileSizeY, float scale) throws IOException {
public void put(byte[] raw, int x, int y, int effTileSizeX, int effTileSizeY, float scale) throws IOException {
BufferedImage bi = ImageIO.read(new ByteArrayInputStream(raw));
bi = bi.getSubimage(0, 0, effTileSizeX, effTileSizeY);
put(bi, x, y);
Expand All @@ -85,7 +88,6 @@ public void put(byte[] raw, int x, int y, int effTileSizeX, int effTileSizeY, fl
private void CalculateHeightandWidth() {
width = (int) Math.round(width*DownScale);
height = (int) Math.round(height*DownScale);
System.out.println("HW : "+width+" X "+height);
}

public int getWidth() {
Expand Down Expand Up @@ -185,65 +187,47 @@ public void put(BufferedImage bi, int x, int y, float scale) {
}

public void Shrink() {
ThreadPoolExecutor engine = new ThreadPoolExecutor(params.cores,params.cores,0L,TimeUnit.MILLISECONDS, new LinkedBlockingQueue<>());
engine.prestartAllCoreThreads();
System.out.println("SHRINK : "+tilesX+" "+tilesY);
JPEGBuffer c = tiles[tilesX-1][tilesY-1];
if (c.GetBufferImage().getWidth()==1) {
System.out.println("shrink clip x");
tilesX--;
}
if (c.GetBufferImage().getHeight()==1) {
System.out.println("shrink clip y");
tilesY--;
}
for (int a=0; a<tilesX; a++) {
for (int b=0; b<tilesY; b++) {
Callable<BufferedImage> worker = new SmushProcessor(this, a, b);
engine.submit(worker);
try (ExecutorService engine = Executors.newVirtualThreadPerTaskExecutor()) {
JPEGBuffer c = tiles[tilesX-1][tilesY-1];
if (c.GetBufferImage().getWidth()==1) {
System.out.println("shrink clip x");
tilesX--;
}
}
engine.shutdown();
while (!engine.isTerminated()) {
try {
Thread.sleep(500);
} catch (InterruptedException ex) {
Logger.getLogger(Pyramid.class.getName()).log(Level.SEVERE, null, ex);
if (c.GetBufferImage().getHeight()==1) {
System.out.println("shrink clip y");
tilesY--;
}
for (int a=0; a<tilesX; a++) {
for (int b=0; b<tilesY; b++) {
engine.submit(new SmushProcessor(this, a, b));
}
}
}
System.out.println("Shrink Process complete...");
CalculateHeightandWidth();
}

public void Lump() {
ThreadPoolExecutor engine = new ThreadPoolExecutor(params.cores,params.cores,0L,TimeUnit.MILLISECONDS, new LinkedBlockingQueue<>());
engine.prestartAllCoreThreads();
xscale++;
int neotilesX = (int) Math.ceil(tilesX/2f);
int neotilesY = (int) Math.ceil(tilesY/2f);
JPEGBuffer[][] neotiles = new JPEGBuffer[neotilesX][neotilesY];
for (int a=0; a<tilesX; a=a+2) {
for (int b=0; b<tilesY; b=b+2) {
Callable<JPEGBuffer> worker = new MergeProcessor(this, neotiles, a, b);
engine.submit(worker);
}
}
engine.shutdown();
while (!engine.isTerminated()) {
try {
Thread.sleep(500);
} catch (InterruptedException ex) {
Logger.getLogger(Pyramid.class.getName()).log(Level.SEVERE, null, ex);
int neotilesX;
int neotilesY;
JPEGBuffer[][] neotiles;
try (ExecutorService engine = Executors.newVirtualThreadPerTaskExecutor()) {
xscale++;
neotilesX = (int) Math.ceil(tilesX/2f);
neotilesY = (int) Math.ceil(tilesY/2f);
neotiles = new JPEGBuffer[neotilesX][neotilesY];
for (int a=0; a<tilesX; a=a+2) {
for (int b=0; b<tilesY; b=b+2) {
engine.submit(new MergeProcessor(this, neotiles, a, b));
}
}
}
System.out.println("Merge Process complete...");
tiles = neotiles;
tilesX = neotilesX;
tilesY = neotilesY;
}
}

class SmushProcessor implements Callable<BufferedImage> {
class SmushProcessor implements Runnable {
private final Pyramid pyramid;
private final int a;
private final int b;
Expand All @@ -255,19 +239,26 @@ public SmushProcessor(Pyramid pyramid, int a, int b) {
}

@Override
public BufferedImage call() throws Exception {
BufferedImage bi = ImageIO.read(new ByteArrayInputStream(pyramid.getTiles()[a][b].GetBytes()));
AffineTransform at = new AffineTransform();
at.scale(Pyramid.DownScale,Pyramid.DownScale);
AffineTransformOp scaleOp = new AffineTransformOp(at, AffineTransformOp.TYPE_BILINEAR);
BufferedImage target = new BufferedImage((int)(Pyramid.DownScale*bi.getWidth()),(int)(Pyramid.DownScale*bi.getHeight()),bi.getType());
scaleOp.filter(bi, target);
pyramid.put(target,a,b);
return null;
public void run() {
ImageInputStream stream = new MemoryCacheImageInputStream(new BufferedInputStream(new DataInputStream(new ByteArrayInputStream(pyramid.getTiles()[a][b].GetBytes())), 102400));
ImageReader reader = ImageIO.getImageReadersByFormatName("jpeg").next();
reader.setInput(stream, true, true);
BufferedImage bi;
try {
bi = reader.read(0);
AffineTransform at = new AffineTransform();
at.scale(Pyramid.DownScale,Pyramid.DownScale);
AffineTransformOp scaleOp = new AffineTransformOp(at, AffineTransformOp.TYPE_BILINEAR);
BufferedImage target = new BufferedImage((int)(Pyramid.DownScale*bi.getWidth()),(int)(Pyramid.DownScale*bi.getHeight()),bi.getType());
scaleOp.filter(bi, target);
pyramid.put(target,a,b);
} catch (IOException ex) {
Logger.getLogger(SmushProcessor.class.getName()).log(Level.SEVERE, null, ex);
}
}
}

class MergeProcessor implements Callable<JPEGBuffer> {
class MergeProcessor implements Runnable {
private final Pyramid pyramid;
private final int a;
private final int b;
Expand Down Expand Up @@ -299,7 +290,7 @@ private BufferedImage Merge(BufferedImage nw, BufferedImage ne, BufferedImage sw
}

@Override
public JPEGBuffer call() throws Exception {
public void run() {
BufferedImage nw = pyramid.getBufferedImage(a,b);
if (nw!=null) {
BufferedImage ne = null;
Expand All @@ -320,6 +311,5 @@ public JPEGBuffer call() throws Exception {
} else {
throw new Error("NW TILE NULL!!!");
}
return null;
}
}
4 changes: 2 additions & 2 deletions src/main/java/edu/stonybrook/bmi/hatch/TiffCompression.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import loci.formats.codec.JPEGCodec;
import loci.formats.codec.JPEGXRCodec;
import loci.formats.codec.LZWCodec;
import loci.formats.codec.LuraWaveCodec;
//import loci.formats.codec.LuraWaveCodec;
import loci.formats.codec.NikonCodec;
import loci.formats.codec.PackbitsCodec;
import loci.formats.codec.PassthroughCodec;
Expand Down Expand Up @@ -163,7 +163,7 @@ public CodecOptions getCompressionCodecOptions(IFD ifd, CodecOptions opt)

},
NIKON(34713, new NikonCodec(), "Nikon"),
LURAWAVE(65535, new LuraWaveCodec(), "LuraWave"),
//LURAWAVE(65535, new LuraWaveCodec(), "LuraWave"),
JPEGXR(22610, new JPEGXRCodec(), "JPEG-XR");

// -- Constants --
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/edu/stonybrook/bmi/hatch/TiffParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -199,10 +199,11 @@ public Boolean checkHeader() throws IOException {
return null;
}

return new Boolean(littleEndian);
return littleEndian;
}

/** Returns whether or not the current TIFF file contains BigTIFF data. */
/** Returns whether or not the current TIFF file contains BigTIFF data.
* @return */
public boolean isBigTiff() {
return bigTiff;
}
Expand Down
Loading

0 comments on commit ec54c11

Please sign in to comment.