CHARLS_IMEXPORT(JLS_ERROR) JpegLsReadHeader(const void* compressedData, size_t compressedLength, JlsParameters* pparams) { return JpegLsReadHeaderStream(FromByteArray(compressedData, compressedLength), pparams); }
void JPEGLSCodec::decompress(const DataChunk &data) { ByteStreamInfo inStream = FromByteArray(data.Data, data.Size); struct JlsParameters info; JLS_ERROR err = JpegLsReadHeaderStream(inStream, &info); if(err == OK) { const int width = info.width; const int height = info.height; assert(info.components == (_channels == JPEGLS_RGBA ? 4 : 3)); assert(info.colorTransform == COLORXFORM_NONE); const PixelType pixType = (_depth == JPEGLS_8 ? UINT8 : _depth == JPEGLS_10 ? UINT10 : _depth == JPEGLS_12 ? UINT12 : _depth == JPEGLS_16 ? UINT16 : UINT8); const size_t pixSize = PixelSize(pixType); const unsigned int bitDepth = PixelBits(pixType); assert(info.bitspersample == bitDepth); const size_t pixelSize = (info.components * PixelSize(pixType)); const size_t rowBytes = (width * pixelSize); const size_t bufSize = (height * rowBytes); DataChunkPtr frameData = new DataChunk(bufSize); char *buf = (char *)frameData->Data; const Box2i dataW = dataWindow(); assert(width == (dataW.max.x - dataW.min.x + 1)); assert(height == (dataW.max.y - dataW.min.y + 1)); assert(dataW.min.x == 0); assert(dataW.min.y == 0); FrameBufferPtr frameBuffer = new FrameBuffer(dataW); frameBuffer->insert("R", Slice(pixType, &buf[0 * pixSize], pixelSize, rowBytes)); frameBuffer->insert("G", Slice(pixType, &buf[1 * pixSize], pixelSize, rowBytes)); frameBuffer->insert("B", Slice(pixType, &buf[2 * pixSize], pixelSize, rowBytes)); if(info.components >= 4) frameBuffer->insert("A", Slice(pixType, &buf[3 * pixSize], pixelSize, rowBytes)); frameBuffer->attachData(frameData); ByteStreamInfo outStream = FromByteArray(frameData->Data, frameData->Size); err = JpegLsDecodeStream(outStream, inStream, &info); if(err == OK) { storeFrame(frameBuffer); } } if(err != OK) throw MoxMxf::ArgExc("JPEG-LS decompression error"); }