Skip to content
Snippets Groups Projects
Commit 7662a4e6 authored by Vojtěch Moravec's avatar Vojtěch Moravec
Browse files

Add setWorkerCount() in IPlaneLoader.

With this API you can set worker count for plane loader.
Plane loader may want to use more than one thread in some operations.
parent d971b564
No related branches found
No related tags found
No related merge requests found
......@@ -233,7 +233,6 @@ public class ImageDecompressor extends CompressorDecompressorBase {
return true;
}
// TODO(Moravec): Return optional to get rid of null check.
public Optional<ImageU16Dataset> decompressInMemory() {
try (FileInputStream fileInputStream = new FileInputStream(options.getInputDataInfo().getFilePath());
DataInputStream dataInputStream = new DataInputStream(fileInputStream)) {
......
......@@ -207,6 +207,7 @@ public class VQImageCompressor extends CompressorDecompressorBase implements IIm
final IPlaneLoader planeLoader;
try {
planeLoader = PlaneLoaderFactory.getPlaneLoaderForInputFile(options.getInputDataInfo());
planeLoader.setWorkerCount(options.getWorkerCount());
} catch (Exception e) {
throw new ImageCompressionException("Unable to create reader. " + e.getMessage());
}
......@@ -308,6 +309,7 @@ public class VQImageCompressor extends CompressorDecompressorBase implements IIm
final int[] huffmanSymbols = createHuffmanSymbols(getCodebookSize());
try {
planeLoader = PlaneLoaderFactory.getPlaneLoaderForInputFile(options.getInputDataInfo());
planeLoader.setWorkerCount(options.getWorkerCount());
} catch (Exception e) {
throw new ImageCompressionException("Unable to create plane reader. " + e.getMessage());
}
......
......@@ -8,6 +8,7 @@ import java.io.IOException;
public abstract class BasicLoader {
protected final V3i dims;
protected int threadCount = 1;
protected BasicLoader(final V3i datasetDims) {
this.dims = datasetDims;
......@@ -83,15 +84,13 @@ public abstract class BasicLoader {
* Load specified planes from dataset to voxel of specified dimensions.
* This overload uses the valueAt function to read src data.
*
* @param voxelDim Single voxel dimensions.
* @param planeRange Range of planes to load voxels from.
* @param threadCount Number of threads used for loading.
* @param voxelDim Single voxel dimensions.
* @param planeRange Range of planes to load voxels from.
* @return Voxel data arranged in arrays.
* @throws IOException When fails to load plane data.
*/
protected int[][] loadVoxelsImplByValueAt(final V3i voxelDim,
final Range<Integer> planeRange,
final int threadCount) throws IOException {
final Range<Integer> planeRange) throws IOException {
// TODO(Moravec): Improve performance of loading.
final Voxel dstVoxel = new Voxel(voxelDim);
......@@ -155,4 +154,8 @@ public abstract class BasicLoader {
return voxels;
}
public void setWorkerCount(final int threadCount) {
this.threadCount = threadCount;
}
}
......@@ -55,4 +55,11 @@ public interface IPlaneLoader {
* @throws IOException when fails to load plane data.
*/
int[][] loadVoxels(final V3i voxelDim, final Range<Integer> planeRange) throws IOException;
/**
* Set thread count, which can be used by the loader if needed.
*
* @param threadCount Available thread count for loader.
*/
void setWorkerCount(final int threadCount);
}
......@@ -35,7 +35,6 @@ public final class ImageJBufferLoader extends BasicLoader implements IPlaneLoade
protected int valueAt(int plane, int offset) {
final short value = ((short[]) bufferInputData.getPixelBuffer(plane))[offset];
return TypeConverter.shortToInt(value);
// return ((value & 0xFF00) | (value & 0x00FF));
}
@Override
......@@ -94,8 +93,7 @@ public final class ImageJBufferLoader extends BasicLoader implements IPlaneLoade
@Override
public int[][] loadVoxels(final V3i voxelDim, final Range<Integer> planeRange) throws IOException {
// TODO(Moravec): Thread count, now 4, should be configurable.
return loadVoxelsImplByValueAt(voxelDim, planeRange, 1);
return loadVoxelsImplByValueAt(voxelDim, planeRange);
}
}
......@@ -4,8 +4,6 @@ import azgracompress.io.BufferInputData;
import azgracompress.io.FileInputData;
import azgracompress.io.InputData;
import java.nio.Buffer;
public final class PlaneLoaderFactory {
/**
......@@ -26,6 +24,5 @@ public final class PlaneLoaderFactory {
default:
throw new Exception("Unsupported data loader.");
}
// return null;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment