Example #1
0
void CompressorTurboJPEG::_decompress( const void* const* inData,
                                       const eq_uint64_t inSize,
                                       const unsigned nInputs,
                                       void* const outData,
                                       eq_uint64_t* const outDims,
                                       const bool useAlpha )
{
    assert( !_encoder );
    if( !_decoder )
        _decoder = tjInitDecompress();
    void* const data = const_cast< void* const >( inData[0] );

    if( tjDecompress( _decoder, reinterpret_cast< unsigned char* >(data),
                      inSize, reinterpret_cast< unsigned char*>(outData),
                      outDims[1], outDims[1] * _tokenSize, outDims[3],
                      _tokenSize, _flags ))
    {
        assert( false );
    }
    else if( useAlpha && _tokenSize == 4 )
    {
        assert( nInputs == 2 );
        const eq_uint64_t size = outDims[3] * outDims[1];
        _addAlpha( inData[1], reinterpret_cast< unsigned* >( outData ), size);
    }

}
bool ofxTurboJpeg::load(const ofBuffer& buf, ofPixels &pix)
{
	int w, h;
	int subsamp;
	int ok = tjDecompressHeader2(handleDecompress, (unsigned char*)buf.getData(), buf.size(), &w, &h, &subsamp);
	
	if (ok != 0)
	{
		printf("Error in tjDecompressHeader2():\n%s\n", tjGetErrorStr());
		return false;
	}
	
	pix.allocate(w, h, 3);
	
	tjDecompress(handleDecompress, (unsigned char*)buf.getData(), buf.size(), pix.getData(), w, 0, h, 3, 0);
	
	return true;
}
bool ofxRemoteCameraClient::decompress(unsigned char *pixels, int size, int w, int h, int pixelsize){
	return tjDecompress(handle, pixels, size, compressedData, w, 0, h, pixelsize, 0);
}
Example #4
0
int RRTileDecompressor::run(TileVector *tv, RRFrame *frame, bool deleteTileBuffer)
{
    if (tv->begin() >= tv->end())
    {
        return 0; // Nothing to do
    }

    frame->lock();
    {
        const int n = tv->size();
#ifdef _OPENMP
#pragma omp parallel for schedule(static, 1)
#endif
        for (int i = 0; i < n; ++i)
        {
            RRCompressedTile &tile = tv->at(i);

#ifdef _OPENMP
            const int tnum = omp_get_thread_num();
#pragma omp critical
            {
                if (tjctx.size() <= tnum)
                {
                    tjctx.resize(tnum + 1);
                }
                tjhandle &tj = tjctx[tnum];
                if (tj == 0)
                    tj = tjInitDecompress();
            }
#else
            const int tnum = 0;
#endif

            tjhandle tj = tjctx[tnum];
            int w = std::min(tile.w, frame->getWidth() - tile.x);
            int h = std::min(tile.h, frame->getHeight() - tile.y);
            int x = tile.x;
            int y = tile.y;

            if (planar)
            {
                unsigned char *planes[4] = {
                    frame->yData(x, y),
                    frame->uData(x, y),
                    frame->vData(x, y),
                    NULL
                };

                tjDecompressPlanar(tj,
                                   tile.buffer,
                                   tile.size,
                                   planes,
                                   w,
                                   frame->getRowBytes(),
                                   h,
                                   3,
                                   frame->getSubSampling(),
                                   TJ_BGR);
            }
            else
            {
                tjDecompress(tj,
                             tile.buffer,
                             tile.size,
                             frame->getData() + y * frame->getRowBytes() + x * frame->getPixelSize(),
                             w,
                             frame->getRowBytes(),
                             h,
                             frame->getPixelSize(),
                             TJ_BGR);
            }

            if (deleteTileBuffer)
            {
                delete[] tile.buffer;
            }
        }
    }
    frame->unlock();

    return 0;
}
Example #5
0
DLLEXPORT int DLLCALL tjDecompressToYUV(tjhandle h,
	unsigned char *srcbuf, unsigned long size,
	unsigned char *dstbuf, int flags)
{
	return tjDecompress(h, srcbuf, size, dstbuf, 1, 0, 1, 3, flags|TJ_YUV);
}