Skip to content
Merged
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
9 changes: 3 additions & 6 deletions .github/workflows/maven.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,14 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v6

- name: Set up JDK 11
uses: actions/setup-java@v3
uses: actions/setup-java@v5
with:
java-version: '11'
distribution: 'temurin'
cache: maven

- name: Build with Maven
run: mvn -B package --file pom.xml

# - name: Submit Dependency Snapshot
# uses: advanced-security/maven-dependency-submission-action@v3
run: mvn -B verify --file pom.xml
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@
<executions>
<execution>
<id>sign-artifacts</id>
<phase>verify</phase>
<phase>deploy</phase>
<goals>
<goal>sign</goal>
</goals>
Expand Down
8 changes: 5 additions & 3 deletions src/main/java/be/twofold/tinybcdec/BC1.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package be.twofold.tinybcdec;

import java.nio.*;

final class BC1 extends BlockDecoder {
private static final int BPP = 4;

Expand All @@ -13,8 +15,8 @@ final class BC1 extends BlockDecoder {
}

@Override
public void decodeBlock(byte[] src, int srcPos, byte[] dst, int dstPos, int stride) {
long block = ByteArrays.getLong(src, srcPos);
public void decodeBlock(ByteBuffer src, int srcPos, ByteBuffer dst, int dstPos, int stride) {
long block = ByteIO.getLong(src, srcPos);

int c0 = (int) (block/* */) & 0xFFFF;
int c1 = (int) (block >>> 16) & 0xFFFF;
Expand Down Expand Up @@ -54,7 +56,7 @@ public void decodeBlock(byte[] src, int srcPos, byte[] dst, int dstPos, int stri
for (int y = 0; y < BLOCK_HEIGHT; y++) {
for (int x = 0; x < BLOCK_WIDTH; x++) {
int color = colors[indices & 0x03];
ByteArrays.setInt(dst, dstPos + x * BPP, color);
ByteIO.setInt(dst, dstPos + x * BPP, color);
indices >>>= 2;
}
dstPos += stride;
Expand Down
10 changes: 6 additions & 4 deletions src/main/java/be/twofold/tinybcdec/BC2.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package be.twofold.tinybcdec;

import java.nio.*;

final class BC2 extends BlockDecoder {
private static final int BPP = 4;
private static final BC1 COLOR_DECODER = new BC1(BC1Mode.BC2OR3);
Expand All @@ -11,18 +13,18 @@ private BC2() {
}

@Override
public void decodeBlock(byte[] src, int srcPos, byte[] dst, int dstPos, int stride) {
public void decodeBlock(ByteBuffer src, int srcPos, ByteBuffer dst, int dstPos, int stride) {
COLOR_DECODER.decodeBlock(src, srcPos + 8, dst, dstPos, stride);
decodeAlpha(src, srcPos, dst, dstPos + 3, stride);
}

private void decodeAlpha(byte[] src, int srcPos, byte[] dst, int dstPos, int stride) {
long alphas = ByteArrays.getLong(src, srcPos);
private void decodeAlpha(ByteBuffer src, int srcPos, ByteBuffer dst, int dstPos, int stride) {
long alphas = ByteIO.getLong(src, srcPos);

for (int y = 0; y < BLOCK_HEIGHT; y++) {
for (int x = 0; x < BLOCK_WIDTH; x++) {
byte alpha = (byte) ((alphas & 15) * 17);
dst[dstPos + x * BPP] = alpha;
ByteIO.setByte(dst, dstPos + x * BPP, alpha);
alphas >>>= 4;
}
dstPos += stride;
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/be/twofold/tinybcdec/BC3.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package be.twofold.tinybcdec;

import java.nio.*;

final class BC3 extends BlockDecoder {
private static final int BPP = 4;
private static final BC1 COLOR_DECODER = new BC1(BC1Mode.BC2OR3);
Expand All @@ -12,7 +14,7 @@ private BC3() {
}

@Override
public void decodeBlock(byte[] src, int srcPos, byte[] dst, int dstPos, int stride) {
public void decodeBlock(ByteBuffer src, int srcPos, ByteBuffer dst, int dstPos, int stride) {
COLOR_DECODER.decodeBlock(src, srcPos + 8, dst, dstPos/**/, stride);
ALPHA_DECODER.decodeBlock(src, srcPos/**/, dst, dstPos + 3, stride);
}
Expand Down
8 changes: 5 additions & 3 deletions src/main/java/be/twofold/tinybcdec/BC4S.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package be.twofold.tinybcdec;

import java.nio.*;

final class BC4S extends BlockDecoder {
BC4S(int pixelStride) {
super(pixelStride, 8);
}

@Override
public void decodeBlock(byte[] src, int srcPos, byte[] dst, int dstPos, int stride) {
long block = ByteArrays.getLong(src, srcPos);
public void decodeBlock(ByteBuffer src, int srcPos, ByteBuffer dst, int dstPos, int stride) {
long block = ByteIO.getLong(src, srcPos);

int a0 = Math.max(-127, (byte) (block/* */));
int a1 = Math.max(-127, (byte) (block >>> 8));
Expand All @@ -31,7 +33,7 @@ public void decodeBlock(byte[] src, int srcPos, byte[] dst, int dstPos, int stri
for (int y = 0; y < BLOCK_HEIGHT; y++) {
for (int x = 0; x < BLOCK_WIDTH; x++) {
byte alpha = alphas[(int) (indices & 0x07)];
dst[dstPos + x * bytesPerPixel] = alpha;
ByteIO.setByte(dst, dstPos + x * bytesPerPixel, alpha);
indices >>>= 3;
}
dstPos += stride;
Expand Down
8 changes: 5 additions & 3 deletions src/main/java/be/twofold/tinybcdec/BC4U.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package be.twofold.tinybcdec;

import java.nio.*;

final class BC4U extends BlockDecoder {
BC4U(int pixelStride) {
super(pixelStride, 8);
}

@Override
public void decodeBlock(byte[] src, int srcPos, byte[] dst, int dstPos, int stride) {
long block = ByteArrays.getLong(src, srcPos);
public void decodeBlock(ByteBuffer src, int srcPos, ByteBuffer dst, int dstPos, int stride) {
long block = ByteIO.getLong(src, srcPos);

int a0 = (int) (block/* */) & 0xFF;
int a1 = (int) (block >>> 8) & 0xFF;
Expand All @@ -31,7 +33,7 @@ public void decodeBlock(byte[] src, int srcPos, byte[] dst, int dstPos, int stri
for (int y = 0; y < BLOCK_HEIGHT; y++) {
for (int x = 0; x < BLOCK_WIDTH; x++) {
byte alpha = alphas[(int) (indices & 0x07)];
dst[dstPos + x * bytesPerPixel] = alpha;
ByteIO.setByte(dst, dstPos + x * bytesPerPixel, alpha);
indices >>>= 3;
}
dstPos += stride;
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/be/twofold/tinybcdec/BC5S.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package be.twofold.tinybcdec;

import java.nio.*;

final class BC5S extends BlockDecoder {
private static final int BPP = 2;
private static final BC4S DECODER = new BC4S(BPP);
Expand All @@ -11,7 +13,7 @@ private BC5S() {
}

@Override
public void decodeBlock(byte[] src, int srcPos, byte[] dst, int dstPos, int stride) {
public void decodeBlock(ByteBuffer src, int srcPos, ByteBuffer dst, int dstPos, int stride) {
DECODER.decodeBlock(src, srcPos/**/, dst, dstPos/**/, stride);
DECODER.decodeBlock(src, srcPos + 8, dst, dstPos + 1, stride);
}
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/be/twofold/tinybcdec/BC5U.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package be.twofold.tinybcdec;

import java.nio.*;

final class BC5U extends BlockDecoder {
private static final int BPP = 2;
private static final BC4U DECODER = new BC4U(BPP);
Expand All @@ -11,7 +13,7 @@ private BC5U() {
}

@Override
public void decodeBlock(byte[] src, int srcPos, byte[] dst, int dstPos, int stride) {
public void decodeBlock(ByteBuffer src, int srcPos, ByteBuffer dst, int dstPos, int stride) {
DECODER.decodeBlock(src, srcPos/**/, dst, dstPos/**/, stride);
DECODER.decodeBlock(src, srcPos + 8, dst, dstPos + 1, stride);
}
Expand Down
18 changes: 6 additions & 12 deletions src/main/java/be/twofold/tinybcdec/BC6H.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package be.twofold.tinybcdec;

import java.nio.*;
import java.util.*;

final class BC6H extends BPTC {
Expand Down Expand Up @@ -30,12 +31,12 @@ final class BC6H extends BPTC {
}

@Override
public void decodeBlock(byte[] src, int srcPos, byte[] dst, int dstPos, int stride) {
public void decodeBlock(ByteBuffer src, int srcPos, ByteBuffer dst, int dstPos, int stride) {
Bits bits = Bits.from(src, srcPos);

int modeIndex = mode(bits);
if (modeIndex >= MODES.size()) {
fillInvalidBlock(dst, dstPos, stride);
fillInvalidBlock(dst, dstPos, stride, BPP);
return;
}
Mode mode = MODES.get(modeIndex);
Expand Down Expand Up @@ -95,9 +96,9 @@ public void decodeBlock(byte[] src, int srcPos, byte[] dst, int dstPos, int stri
partitions >>>= 2;

int o = dstPos + x * BPP;
ByteArrays.setShort(dst, o/**/, r);
ByteArrays.setShort(dst, o + 2, g);
ByteArrays.setShort(dst, o + 4, b);
ByteIO.setShort(dst, o/**/, r);
ByteIO.setShort(dst, o + 2, g);
ByteIO.setShort(dst, o + 4, b);
}
dstPos += stride;
}
Expand Down Expand Up @@ -184,13 +185,6 @@ private int transformInverse(int value, int value0, int bits, boolean signed) {
return signed ? extendSign(value, bits) : value;
}

private static void fillInvalidBlock(byte[] dst, int dstPos, int stride) {
for (int y = 0; y < BLOCK_HEIGHT; y++) {
Arrays.fill(dst, dstPos, dstPos + BLOCK_WIDTH * BPP, (byte) 0);
dstPos += stride;
}
}

private static final class Mode {
private final boolean te;
private final boolean pb;
Expand Down
16 changes: 5 additions & 11 deletions src/main/java/be/twofold/tinybcdec/BC7.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package be.twofold.tinybcdec;

import java.nio.*;
import java.util.*;

final class BC7 extends BPTC {
Expand All @@ -23,10 +24,10 @@ private BC7() {
}

@Override
public void decodeBlock(byte[] src, int srcPos, byte[] dst, int dstPos, int stride) {
int modeIndex = Integer.numberOfTrailingZeros(src[srcPos]);
public void decodeBlock(ByteBuffer src, int srcPos, ByteBuffer dst, int dstPos, int stride) {
int modeIndex = Integer.numberOfTrailingZeros(ByteIO.getByte(src, srcPos));
if (modeIndex >= MODES.size()) {
fillInvalidBlock(dst, dstPos, stride);
fillInvalidBlock(dst, dstPos, stride, BPP);
return;
}

Expand Down Expand Up @@ -149,19 +150,12 @@ public void decodeBlock(byte[] src, int srcPos, byte[] dst, int dstPos, int stri
}

int rgba = r | g << 8 | b << 16 | a << 24;
ByteArrays.setInt(dst, dstPos + x * BPP, rgba);
ByteIO.setInt(dst, dstPos + x * BPP, rgba);
}
dstPos += stride;
}
}

private static void fillInvalidBlock(byte[] dst, int dstPos, int stride) {
for (int y = 0; y < BLOCK_HEIGHT; y++) {
Arrays.fill(dst, dstPos, dstPos + BLOCK_WIDTH * BPP, (byte) 0);
dstPos += stride;
}
}

private int unpack(int i, int n) {
i = i << (8 - n);
return i | i >>> n;
Expand Down
19 changes: 14 additions & 5 deletions src/main/java/be/twofold/tinybcdec/BPTC.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package be.twofold.tinybcdec;

import java.nio.*;

abstract class BPTC extends BlockDecoder {
private static final int[][] PARTITIONS = {
{},
Expand Down Expand Up @@ -74,8 +76,8 @@ abstract class BPTC extends BlockDecoder {
super(pixelStride, 16);
}

static int partitions(int numPartitions, int partitionIndex) {
return PARTITIONS[numPartitions][partitionIndex];
static int partitions(int numPartitions, int partition) {
return PARTITIONS[numPartitions][partition];
}

static byte[] weights(int numIndexBits) {
Expand Down Expand Up @@ -106,6 +108,13 @@ static int interpolate(int e0, int e1, int weight) {
return (e0 * (64 - weight) + e1 * weight + 32) >>> 6;
}

static void fillInvalidBlock(ByteBuffer dst, int dstPos, int stride, int bpp) {
for (int y = 0; y < BLOCK_HEIGHT; y++) {
ByteIO.fill(dst, dstPos, BLOCK_WIDTH * bpp, (byte) 0);
dstPos += stride;
}
}

static final class Bits {
private long lo;
private long hi;
Expand All @@ -115,9 +124,9 @@ private Bits(long lo, long hi) {
this.hi = hi;
}

static Bits from(byte[] array, int index) {
long lo = ByteArrays.getLong(array, index);
long hi = ByteArrays.getLong(array, index + 8);
static Bits from(ByteBuffer buffer, int index) {
long lo = ByteIO.getLong(buffer, index);
long hi = ByteIO.getLong(buffer, index + 8);
return new Bits(lo, hi);
}

Expand Down
Loading