Package turbojpeg.utils

Examples of turbojpeg.utils.StopWatch


    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);
View Full Code Here


                                    final ByteBuffer p8BitImageByteBuffer)
  {
    if (mPointerToCompressor == null)
      return false;
    allocateCompressedBuffer((int) (1.5 * p8BitImageByteBuffer.limit()));
    final StopWatch lCompressionTime = StopWatch.start();
    p8BitImageByteBuffer.position(0);

    final Pointer lPointerTo8BitImageByteBuffer = Pointer.pointerToBytes(p8BitImageByteBuffer);

    final int lErrorCode = TurbojpegLibrary.tjCompress2(mPointerToCompressor,
                                                        lPointerTo8BitImageByteBuffer,
                                                        pWidth,
                                                        0,
                                                        pHeight,
                                                        (int) TJPF.TJPF_GRAY.value,
                                                        mPointerToCompressedImageByteBufferPointer,
                                                        mPointerToCompressedBufferEffectiveSize,
                                                        (int) TJSAMP.TJSAMP_GRAY.value,
                                                        mQuality,
                                                        TurbojpegLibrary.TJFLAG_NOREALLOC | TurbojpegLibrary.TJFLAG_FORCESSE3
                                                            | TurbojpegLibrary.TJFLAG_FASTDCT);
    mLastCompressionElapsedTimeInMs = lCompressionTime.time(TimeUnit.MILLISECONDS);
    mCompressedImageByteBuffer.limit((int) mPointerToCompressedBufferEffectiveSize.getCLong());
    mLastCompressionRatio = ((double) mCompressedImageByteBuffer.limit()) / p8BitImageByteBuffer.limit();

    lPointerTo8BitImageByteBuffer.release();
    return lErrorCode == 0;
View Full Code Here

  {
    if (mPointerToDecompressor == null)
      return false;

    // allocateCompressedBuffer(p8BitImageByteBuffer.limit());
    final StopWatch lCompressionTime = StopWatch.start();

    final long lCompressedImageBufferSize = p8BitImageCompressedByteBuffer.limit();

    p8BitImageCompressedByteBuffer.position(0);



    final Pointer lPointerTo8BitImageCompressedByteBuffer = Pointer.pointerToBytes(p8BitImageCompressedByteBuffer);
    TurbojpegLibrary.tjDecompressHeader(mPointerToDecompressor,
                                        lPointerTo8BitImageCompressedByteBuffer,
                                        lCompressedImageBufferSize,
                                        mPointerToWidth,
                                        mPointerToHeight);
    lPointerTo8BitImageCompressedByteBuffer.release();

    final int lWidth = mPointerToWidth.getInt();
    final int lHeight = mPointerToHeight.getInt();

    allocateDecompressedBuffer(lWidth * lHeight);
    mDecompressedImageByteBuffer.rewind();
   
    final int lErrorCode = TurbojpegLibrary.tjDecompress2(mPointerToDecompressor,
                                                          lPointerTo8BitImageCompressedByteBuffer,
                                                          lCompressedImageBufferSize,
                                                          mPointerToDecompressedImageByteBuffer,
                                                          lWidth,
                                                          0,
                                                          lHeight,
                                                          (int) TJPF.TJPF_GRAY.value,
                                                          TurbojpegLibrary.TJFLAG_NOREALLOC | TurbojpegLibrary.TJFLAG_FORCESSE3
                                                              | TurbojpegLibrary.TJFLAG_FASTDCT);

    mLastDecompressionElapsedTimeInMs = lCompressionTime.time(TimeUnit.MILLISECONDS);

    lPointerTo8BitImageCompressedByteBuffer.release();
   
   
    return lErrorCode == 0;
View Full Code Here

TOP

Related Classes of turbojpeg.utils.StopWatch

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.