main() for file-to-file encoding and decoding

Apr 15, 2011 at 8:45 PM

As far as I understand, current version can't be compiled so that the executable reads an infile and writes an outfile.
It would be very convenient to have such functions in the project. Hopefully it's not hard to add this. Is it?

In case someone does this, please let me know. I will test CharLS for the LPCB ( )

Apr 17, 2011 at 8:36 PM

Hi Alex,

The trunk version can!

It supports reading from, and writing to std::basic_streambuf<char>*.

The following code I copied from the unittests:

std::basic_filebuf<char> myFile;, std::ios_base::in | std::ios::binary);
ByteStreamInfo compressedByteStream = {&myFile};
std::basic_stringbuf<char> buf;
ByteStreamInfo rawStreamInfo = { &buf };
err = JpegLsDecodeStream(rawStreamInfo, compressedByteStream, NULL);

The ByteStreamInfo structs allow you to specify a memory buffer or a C++ stream. So you can decode/encode which way you like: disk to memory, disk to disk, ....

The trunk version could be less stable than the release. I haven't spend much time on testing.

Apr 17, 2011 at 10:00 PM
Edited Apr 17, 2011 at 10:09 PM

Sorry, where do I get the trunk version?

I've got and it looks like there's no trunk version inside


Apr 18, 2011 at 9:40 PM

Download from, and use the version in the trunk folder.

Apr 21, 2011 at 11:37 PM

As far as I can see, two files in the /trunk/ folder have function main().

plainc.c - empty main().

main.cpp - can't be compiled so that it would take an image and output a compressed file, or read a compressed file and write and image file.

To print compressed sizes, I would have to modify functions TestEncodeFromStream(), but to read width/height/bpp from a PPM or BMP file, and to write compressed data to a file - that would require much more work.

Apr 24, 2011 at 9:02 PM

Hi, I have added a "-decoderaw" option to the test project, such that it will decode jls to raw format. Not entirely what you requested perhaps, but it's a start.

Assuming I continue to add encoding, do you require BMP or is PPM/PGM only an option too?

Do you intend to run speed benchmarks on file-to-file compression? If so I have some work to to ensure my filestreams are constructed optimally. What software do you use to determine run time?

Apr 24, 2011 at 10:23 PM
Either BMP or PPM, or both.
To determine run time I run scripts like the following:

@if "%1"=="" goto main
@locoe %1.ppm -oNUL
@goto end

@copy/b oly*.ppm nul
@copy/b sta*.ppm nul
@copy/b oly*.ppm nul
@copy/b sta*.ppm nul
@time <nul >>globtime
@call %0 olympus_xz1_01
@call %0 olympus_xz1_02
@call %0 olympus_xz1_03
@call %0 olympus_xz1_27
@call %0 STA13452
@call %0 STA13942
@time <nul >>globtime