-
Notifications
You must be signed in to change notification settings - Fork 254
Chunk API: Add new API and functionality for reading and writing chunks #3794
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
dgault
wants to merge
6
commits into
ome:develop
Choose a base branch
from
dgault:chunk-API
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 3 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
7a51c3d
Chunk API: Add chunk functionality for readers and writers
dgault 3cbc78c
Chunk API: Add new API to ReaderWrapper
dgault cf6d2d4
Chunk API: Add new API to WriterWrapper
dgault 68b3c81
Chunk API: Update use of getXYZCT
dgault 81f2dca
Merge branch 'develop' into chunk-API
dgault e718537
BDV: Add support for new chunk API to BDVReader
dgault File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -35,8 +35,10 @@ | |
| import java.awt.image.ColorModel; | ||
| import java.io.IOException; | ||
| import java.util.ArrayList; | ||
| import java.util.Arrays; | ||
| import java.util.List; | ||
|
|
||
| import ome.xml.model.enums.DimensionOrder; | ||
| import ome.xml.model.primitives.PositiveInteger; | ||
|
|
||
| import loci.common.DataTools; | ||
|
|
@@ -162,6 +164,36 @@ public void savePlane(int no, Object plane, int x, int y, int w, int h) | |
| saveBytes(no, (byte[]) plane, x, y, w, h); | ||
| } | ||
|
|
||
| /* @see IFormatWriter#savePlane(byte[], int[], int[]) */ | ||
| @Override | ||
| public void saveBytes(byte[] buf, int[] shape, int[] offsets) | ||
| throws FormatException, IOException | ||
| { | ||
| checkParams(buf, shape, offsets); | ||
| MetadataRetrieve r = getMetadataRetrieve(); | ||
| String order = r.getPixelsDimensionOrder(series).toString(); | ||
| int[] XYZTCshape = FormatTools.getXYZCTIndexes(order, shape); | ||
| int[] XYZTCoffsets = FormatTools.getXYZCTIndexes(order, offsets); | ||
| int num = r.getPixelsSizeZ(series).getValue() * r.getPixelsSizeC(series).getValue() * r.getPixelsSizeT(series).getValue(); | ||
| int bufOffset = 0; | ||
| for (int z = 0; z < XYZTCshape[2]; z++) { | ||
| for (int t = 0; t < XYZTCshape[3]; t++) { | ||
| for (int c = 0; c < XYZTCshape[4]; c++) { | ||
| int no = FormatTools.getIndex(order, r.getPixelsSizeZ(series).getValue(), r.getPixelsSizeC(series).getValue(), | ||
| r.getPixelsSizeT(series).getValue(), num, XYZTCoffsets[2] + z, XYZTCoffsets[4] + c, XYZTCoffsets[3] + t); | ||
| int pixelType = FormatTools.pixelTypeFromString(r.getPixelsType(series).toString()); | ||
| int bpp = FormatTools.getBytesPerPixel(pixelType); | ||
| PositiveInteger samples = r.getChannelSamplesPerPixel(series, 0); | ||
| if (samples == null) samples = new PositiveInteger(1); | ||
| int planeSize = bpp * XYZTCshape[0] * XYZTCshape[1] * samples.getValue(); | ||
| byte[] plane = Arrays.copyOfRange(buf, bufOffset, planeSize); | ||
| saveBytes(no, plane, XYZTCoffsets[0], XYZTCoffsets[1], XYZTCshape[0], XYZTCshape[1]); | ||
| bufOffset += planeSize; | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /* @see IFormatWriter#savePlane(int, Object, Region) */ | ||
| @Override | ||
| public void savePlane(int no, Object plane, Region tile) | ||
|
|
@@ -330,6 +362,20 @@ public int setTileSizeY(int tileSize) throws FormatException { | |
| return height; | ||
| } | ||
|
|
||
| /* @see IFormatWriter#getChunkSize() */ | ||
| @Override | ||
| public int[] getChunkSize() throws FormatException { | ||
| int[] defaultChunkSize = {getTileSizeX(), getTileSizeY(), 1, 1, 1}; | ||
| return defaultChunkSize; | ||
| } | ||
|
|
||
| /* @see IFormatWriter#setChunkSize(int[]) */ | ||
| @Override | ||
| public int[] setChunkSize(int[] chunkSize) throws FormatException { | ||
| int[] returnChunkSize = {setTileSizeX(chunkSize[0]), setTileSizeY(chunkSize[1]), 1, 1, 1}; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Back to @melissalinkert's question about what would test this code, this could warn or error if a >2D chunk size were requested. |
||
| return returnChunkSize; | ||
| } | ||
|
|
||
| /* @see IFormatWriter#setResolutions(List<Resolution>) */ | ||
| @Override | ||
| public void setResolutions(List<Resolution> resolutions) { | ||
|
|
@@ -483,6 +529,51 @@ protected void checkParams(int no, byte[] buf, int x, int y, int w, int h) | |
| } | ||
| } | ||
|
|
||
| /** | ||
| * Ensure that the arguments that are being passed to saveBytes(...) are | ||
| * valid. | ||
| * @throws FormatException if any of the arguments is invalid. | ||
| */ | ||
| protected void checkParams(byte[] buf, int[] shape, int[] offsets) | ||
| throws FormatException | ||
| { | ||
| MetadataRetrieve r = getMetadataRetrieve(); | ||
| MetadataTools.verifyMinimumPopulated(r, series); | ||
|
|
||
| int pixelType = | ||
| FormatTools.pixelTypeFromString(r.getPixelsType(series).toString()); | ||
| PositiveInteger samples = r.getChannelSamplesPerPixel(series, 0); | ||
| if (samples == null) samples = new PositiveInteger(1); | ||
| int minSize = samples.getValue() * FormatTools.getBytesPerPixel(pixelType); | ||
| for (int i = 0; i < shape.length; i++) { | ||
| minSize *= shape[i]; | ||
| } | ||
| if (buf.length < minSize) { | ||
| throw new FormatException("Buffer is too small; expected " + minSize + | ||
| " bytes, got " + buf.length + " bytes."); | ||
| } | ||
|
|
||
| String order = r.getPixelsDimensionOrder(series).toString(); | ||
| int sizeZ = r.getPixelsSizeZ(series).getValue().intValue(); | ||
| int sizeT = r.getPixelsSizeT(series).getValue().intValue(); | ||
| int sizeC = r.getChannelCount(series); | ||
| int[] dimensionSizes = {getSizeX(), getSizeY(), sizeZ, sizeT, sizeC}; | ||
| int[] XYZTCshape = FormatTools.getXYZCTIndexes(order, shape); | ||
| int[] XYZTCoffsets = FormatTools.getXYZCTIndexes(order, offsets); | ||
| for (int i = 0; i < XYZTCoffsets.length; i++) { | ||
| if (XYZTCoffsets[i] < 0 || (XYZTCoffsets[i] + XYZTCshape[i]) > dimensionSizes[i]) { | ||
| char dim = DimensionOrder.XYZCT.toString().charAt(i); | ||
| throw new FormatException("Invalid chunk size: " + dim + " shape = " + XYZTCshape[i] + " " + dim + | ||
| " offset = " + XYZTCoffsets[i] + " " + dim + " maxSize = " + dimensionSizes[i]); | ||
| } | ||
| } | ||
|
|
||
| if (!DataTools.containsValue(getPixelTypes(compression), pixelType)) { | ||
| throw new FormatException("Unsupported image type '" + | ||
| FormatTools.getPixelTypeString(pixelType) + "'."); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Seek to the given (x, y) coordinate of the image that starts at | ||
| * the given offset. | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.