final Pointer<CLong> lPointerToCLong = Pointer.allocateCLong();
lPointerToCLong.setCLong(lCompressedImage.capacity());
int ec = 0;
final StopWatch lCompressionTime = StopWatch.start();
final int lNumberOfRepeats = 1000;
for (int i = 0; i < lNumberOfRepeats; i++)
{
ec = TurbojpegLibrary.tjCompress2(lPointerToCompressor,
Pointer.pointerToBytes(lDmImage),
512,
512,
1024,
(int) TJPF.TJPF_GRAY.value,
lPointerToPointer,
lPointerToCLong,
(int) TJSAMP.TJSAMP_GRAY.value,
90,
TurbojpegLibrary.TJFLAG_NOREALLOC | TurbojpegLibrary.TJFLAG_FORCESSE3
| TurbojpegLibrary.TJFLAG_FASTDCT);
}
final long lCompressionElapsedTime = lCompressionTime.time(TimeUnit.MILLISECONDS);
System.out.format("Compression: %d ms \n",
lCompressionElapsedTime / lNumberOfRepeats);
System.out.println(ec);
lCompressedImage.limit((int) lPointerToCLong.getCLong());
final double ratio = (double) lCompressedImage.limit() / lDmImage.limit();
System.out.format("Compression ratio: %g \n", ratio);
final ByteBuffer lDmImageDecompressed = ByteBuffer.allocateDirect(lDmImage.limit())
.order(ByteOrder.nativeOrder());
final Pointer<?> lPointerToDecompressor = TurbojpegLibrary.tjInitDecompress();
final StopWatch lDecompressionTime = StopWatch.start();
final int ed = TurbojpegLibrary.tjDecompress2(lPointerToDecompressor,
Pointer.pointerToBytes(lCompressedImage),
lCompressedImage.limit(),
Pointer.pointerToBytes(lDmImageDecompressed),
512,
512,
1024,
(int) TJPF.TJPF_GRAY.value,
TurbojpegLibrary.TJFLAG_ACCURATEDCT);
final long lDecompressionElapsedTime = lDecompressionTime.time(TimeUnit.MILLISECONDS);
System.out.format("Decompression: %d ms \n",
lDecompressionElapsedTime);
System.out.println(ed);