Skip to content

Commit

Permalink
Update LCMSTransform.java
Browse files Browse the repository at this point in the history
  • Loading branch information
mrserb committed Jul 28, 2023
1 parent 65315c9 commit 4551fbc
Showing 1 changed file with 37 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -163,38 +163,9 @@ private void doTransform(LCMSImageLayout in, LCMSImageLayout out) {
}
}
if (panama) {
try (Arena arena = Arena.ofConfined()) {
MemorySegment srcNative;
if (in.dataType == DT_INT) {
srcNative = arena.allocateArray(JAVA_INT,
(int[]) in.dataArray);
} else if (in.dataType == DT_SHORT) {
srcNative = arena.allocateArray(JAVA_SHORT,
(short[]) in.dataArray);
} else {
srcNative = arena.allocateArray(JAVA_BYTE,
(byte[]) in.dataArray);
}
MemorySegment dstNative = arena.allocate(out.dataArrayLength);
cmsDoTransformLineStride.invoke(MemorySegment.ofAddress(tfm.ID),
srcNative.asSlice(in.offset),
dstNative.asSlice(out.offset),
in.width, in.height,
in.nextRowOffset,
out.nextRowOffset, 0, 0);
MemorySegment dst;
if (out.dataType == DT_INT) {
dst = MemorySegment.ofArray((int[]) out.dataArray);
} else if (out.dataType == DT_SHORT) {
dst = MemorySegment.ofArray((short[]) out.dataArray);
} else {
dst = MemorySegment.ofArray((byte[]) out.dataArray);
}
dst.copyFrom(dstNative);
} catch (Throwable e) {
throw new CMMException(e.getMessage());
}
panama(in, out, tfm);
} else {
// via jni
LCMS.colorConvert(tfm.ID, in.width, in.height, in.offset,
in.nextRowOffset, out.offset, out.nextRowOffset,
in.dataArray, out.dataArray,
Expand All @@ -203,6 +174,41 @@ private void doTransform(LCMSImageLayout in, LCMSImageLayout out) {
Reference.reachabilityFence(tfm); // prevent deallocation of "tfm.ID"
}

private static void panama(LCMSImageLayout in, LCMSImageLayout out,
NativeTransform tfm) {
try (Arena arena = Arena.ofConfined()) {
MemorySegment srcNative;
if (in.dataType == DT_INT) {
srcNative = arena.allocateArray(JAVA_INT,
(int[]) in.dataArray);
} else if (in.dataType == DT_SHORT) {
srcNative = arena.allocateArray(JAVA_SHORT,
(short[]) in.dataArray);
} else {
srcNative = arena.allocateArray(JAVA_BYTE,
(byte[]) in.dataArray);
}
MemorySegment dstNative = arena.allocate(out.dataArrayLength);
cmsDoTransformLineStride.invoke(MemorySegment.ofAddress(tfm.ID),
srcNative.asSlice(in.offset),
dstNative.asSlice(out.offset),
in.width, in.height,
in.nextRowOffset,
out.nextRowOffset, 0, 0);
MemorySegment dst;
if (out.dataType == DT_INT) {
dst = MemorySegment.ofArray((int[]) out.dataArray);
} else if (out.dataType == DT_SHORT) {
dst = MemorySegment.ofArray((short[]) out.dataArray);
} else {
dst = MemorySegment.ofArray((byte[]) out.dataArray);
}
dst.copyFrom(dstNative);
} catch (Throwable e) {
throw new CMMException(e.getMessage());
}
}

/**
* Returns {@code true} if lcms may support this format directly.
*/
Expand Down

0 comments on commit 4551fbc

Please sign in to comment.