Esempio n. 1
0
CHARLS_IMEXPORT JLS_ERROR JpegLsEncode(void* pdataCompressed, size_t cbyteBuffer, size_t* pcbyteWritten, const void* pdataUncompressed, size_t cbyteUncompressed, const JlsParamaters* pparams)
{
	JlsParamaters info = *pparams;
	if(info.bytesperline == 0)
	{
		info.bytesperline = info.width * ((info.bitspersample + 7)/8);
		if (info.ilv != ILV_NONE)
		{
			info.bytesperline *= info.components;
		}
	}
	
	JLS_ERROR parameterError = CheckInput(pdataCompressed, cbyteBuffer, pdataUncompressed, cbyteUncompressed, &info);

	if (parameterError != OK)
		return parameterError;

	if (pcbyteWritten == NULL)
		return InvalidJlsParameters;

	Size size = Size(info.width, info.height);
	LONG cbit = info.bitspersample;
	JLSOutputStream stream;
	
	stream.Init(size, info.bitspersample, info.components);
	
	if (info.colorTransform != 0)
	{
		stream.AddColorTransform(info.colorTransform);
	}

	if (info.ilv == ILV_NONE)
	{
		LONG cbyteComp = size.cx*size.cy*((cbit +7)/8);
		for (LONG icomp = 0; icomp < info.components; ++icomp)
		{
			const BYTE* pbyteComp = static_cast<const BYTE*>(pdataUncompressed) + icomp*cbyteComp;
			stream.AddScan(pbyteComp, &info);
		}
	}
	else 
	{
		stream.AddScan(pdataUncompressed, &info);
	}

	
	stream.Write((BYTE*)pdataCompressed, cbyteBuffer);
	
	*pcbyteWritten = stream.GetBytesWritten();	
	return OK;
}
Esempio n. 2
0
CHARLS_IMEXPORT(JLS_ERROR) JpegLsEncode(void* compressedData, size_t compressedLength, size_t* pcbyteWritten, const void* uncompressedData, size_t uncompressedLength, struct JlsParameters* pparams)
{
	JlsParameters info = *pparams;
	if(info.bytesperline == 0)
	{
		info.bytesperline = info.width * ((info.bitspersample + 7)/8);
		if (info.ilv != ILV_NONE)
		{
			info.bytesperline *= info.components;
		}
	}
	
	JLS_ERROR parameterError = CheckInput(compressedData, compressedLength, uncompressedData, uncompressedLength, &info);

	if (parameterError != OK)
		return parameterError;

	if (pcbyteWritten == NULL)
		return InvalidJlsParameters;

	Size size = Size(info.width, info.height);
	JLSOutputStream stream;
	
	stream.Init(size, info.bitspersample, info.components);
	
	if (info.colorTransform != 0)
	{
		stream.AddColorTransform(info.colorTransform);
	}

	if (info.ilv == ILV_NONE)
	{
		LONG cbyteComp = size.cx*size.cy*((info.bitspersample +7)/8);
		for (LONG component = 0; component < info.components; ++component)
		{
			const BYTE* compareData = static_cast<const BYTE*>(uncompressedData) + component*cbyteComp;
			stream.AddScan(compareData, &info);
		}
	}
	else 
	{
		stream.AddScan(uncompressedData, &info);
	}

	
	stream.Write((BYTE*)compressedData, compressedLength);
	
	*pcbyteWritten = stream.GetBytesWritten();	
	return OK;
}
Esempio n. 3
0
CHARLS_IMEXPORT JLS_ERROR JpegLsVerifyEncode(const void* pdataUncompressed, size_t cbyteUncompressed, const void* pdataCompressed, size_t cbyteBuffer)
{
	JlsParamaters params = JlsParamaters();

	JLS_ERROR error = JpegLsReadHeader(pdataCompressed, cbyteBuffer, &params);
	if (error != OK)
		return error;

	error = CheckInput(pdataCompressed, cbyteBuffer, pdataUncompressed, cbyteUncompressed, &params);

	if (error != OK)
		return error;
	
	Size size = Size(params.width, params.height);
	LONG cbit = params.bitspersample;
	
	JLSOutputStream stream;
	
	stream.Init(size, params.bitspersample, params.components);

	if (params.ilv == ILV_NONE)
	{
		LONG cbyteComp = size.cx*size.cy*((cbit +7)/8);
		for (LONG icomp = 0; icomp < params.components; ++icomp)
		{
			const BYTE* pbyteComp = static_cast<const BYTE*>(pdataUncompressed) + icomp*cbyteComp;
			stream.AddScan(pbyteComp, &params);
		}
	}
	else 
	{
		stream.AddScan(pdataUncompressed, &params);
	}

	std::vector<BYTE> rgbyteCompressed;
	rgbyteCompressed.resize(cbyteBuffer + 16);
	memcpy(&rgbyteCompressed[0], pdataCompressed, cbyteBuffer);
	

	stream.EnableCompare(true);
	stream.Write(&rgbyteCompressed[0], cbyteBuffer);
	
	return OK;
}
Esempio n. 4
0
	CHARLS_IMEXPORT(JLS_ERROR) JpegLsVerifyEncode(const void* uncompressedData, size_t uncompressedLength, const void* compressedData, size_t compressedLength)
	{
		JlsParameters info = JlsParameters();

		JLS_ERROR error = JpegLsReadHeader(compressedData, compressedLength, &info);
		if (error != OK)
			return error;

		ByteStreamInfo rawStreamInfo = FromByteArray(uncompressedData, uncompressedLength);

		error = CheckInput(compressedData, compressedLength, rawStreamInfo, &info);

		if (error != OK)
			return error;

		Size size = Size(info.width, info.height);

		JLSOutputStream stream;	
		stream.Init(size, info.bitspersample, info.components);

		if (info.ilv == ILV_NONE)
		{
			LONG fieldLength = size.cx*size.cy*((info.bitspersample +7)/8);
			for (LONG component = 0; component < info.components; ++component)
			{					
				stream.AddScan(rawStreamInfo, &info);
				SkipBytes(&rawStreamInfo, fieldLength);
			}
		}
		else 
		{
			stream.AddScan(rawStreamInfo, &info);
		}

		std::vector<BYTE> rgbyteCompressed(compressedLength + 16);

		memcpy(&rgbyteCompressed[0], compressedData, compressedLength);

		stream.EnableCompare(true);
		stream.Write(&rgbyteCompressed[0], rgbyteCompressed.size());

		return OK;
	}
Esempio n. 5
0
CHARLS_IMEXPORT(JLS_ERROR) JpegLsVerifyEncode(const void* uncompressedData, size_t uncompressedLength, const void* compressedData, size_t compressedLength)
{
	JlsParameters info = JlsParameters();

	JLS_ERROR error = JpegLsReadHeader(compressedData, compressedLength, &info);
	if (error != OK)
		return error;

	error = CheckInput(compressedData, compressedLength, uncompressedData, uncompressedLength, &info);

	if (error != OK)
		return error;
	
	Size size = Size(info.width, info.height);
	
	JLSOutputStream stream;
	
	stream.Init(size, info.bitspersample, info.components);

	if (info.ilv == ILV_NONE)
	{
		LONG cbyteComp = size.cx*size.cy*((info.bitspersample +7)/8);
		for (LONG component = 0; component < info.components; ++component)
		{
			const BYTE* compareData = static_cast<const BYTE*>(uncompressedData) + component*cbyteComp;
			stream.AddScan(compareData, &info);
		}
	}
	else 
	{
		stream.AddScan(uncompressedData, &info);
	}

	std::vector<BYTE> rgbyteCompressed(compressedLength + 16);
	
	memcpy(&rgbyteCompressed[0], compressedData, compressedLength);
	
	stream.EnableCompare(true);
	stream.Write(&rgbyteCompressed[0], compressedLength);
	
	return OK;
}