Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions src/main/java/dev/zarr/zarrjava/v3/codec/CodecBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,45 @@ public CodecBuilder withZstd() {
return withZstd(5, true);
}

public CodecBuilder withJpeg(int quality) {
try {
codecs.add(new JpegCodec(new JpegCodec.Configuration(quality)));
} catch (ZarrException e) {
throw new RuntimeException(e);
}
return this;
}

/**
* Adds a 3-component jpeg codec with the conventional subsampling for the color space: 4:2:0
* for {@code ycbcr}, none for {@code rgb}.
*/
public CodecBuilder withJpeg(int quality, String encodedColorSpace) {
int[][] subsampling = "rgb".equals(encodedColorSpace)
? new int[][]{{1, 1}, {1, 1}, {1, 1}}
: new int[][]{{2, 2}, {1, 1}, {1, 1}};
return withJpeg(quality, encodedColorSpace, subsampling);
}

public CodecBuilder withJpeg(int quality, String encodedColorSpace, int[][] subsampling) {
try {
codecs.add(new JpegCodec(
new JpegCodec.Configuration(quality, encodedColorSpace, subsampling)));
} catch (ZarrException e) {
throw new RuntimeException(e);
}
return this;
}

public CodecBuilder withJpeg() {
try {
codecs.add(new JpegCodec());
} catch (ZarrException e) {
throw new RuntimeException(e);
}
return this;
}

public CodecBuilder withZstd(int level) {
return withZstd(level, true);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public class CodecRegistry {
addType("blosc", BloscCodec.class);
addType("gzip", GzipCodec.class);
addType("zstd", ZstdCodec.class);
addType("jpeg", JpegCodec.class);
addType("crc32c", Crc32cCodec.class);
addType("sharding_indexed", ShardingIndexedCodec.class);
}
Expand Down
Loading
Loading