Sample: How to encode RGB buffer with JP2

459 views
Skip to first unread message

ade90036

unread,
May 8, 2018, 6:05:42 AM5/8/18
to OpenJPEG
Hi everyone, 

I need some help with the correct openjpeg functions in order to achieve compress a data buffer into J2K data buffer:

----------------------------------------------------------------------------
GIVEN: 

unsigned char *rgbBuffer;

WHEN

unsigned char* encodedRGB = encodeJP2(rgbBuffer)

THEN

// encodedRGB == encodedJ2K 

----------------------------------------------------------------------------
 
Does anyone has a sample i could base this implementation?

Please don't give me an example using files, as this is not what i'm looking for. 
I'm planning to use the output of the compression to store in a structured pyramid tiff. :P

Regards

Ade

szuk...@arcor.de

unread,
May 8, 2018, 10:01:38 AM5/8/18
to OpenJPEG
@ade

The usual conversion is from SOURCE to JPEG2000. SOURCE may be
a (GRAY | GRAYA | RGB | RGBA) buffer. The JPEG2000 destination
is a complete JPEG2000 file, not an e.g. RGB-buffer.

The JPEG2000 file does contains some header information and some
data information. The same holds for a TIFF file.

So the question is whether you want a complete JPEG2000 file or
RGB data only. The RGB data is either in your SOURCE buffer; or
in the openjpeg image where you can find the e.g. RGB data in the
image->comps[0].data, image->comps[1].data, image->comps[2].data .

A pyramid.tif file usually does contain TIFF images. But if you do want
JPEG2000 images instead, you have to use JPEG2000 files.

In case this assumption is correct you have to convert RGB-SOURCE
buffer to JPEG2000-DEST file.

Supposed this is true, I have some code for you.

winfried

Andrea Rizzini

unread,
May 9, 2018, 2:31:35 AM5/9/18
to open...@googlegroups.com
Yes, the full JPEG2000 file would be fine.
With the Tiff format you can store pretty much anything (IFD), but you are right, if you specify JPEG or JPEG2000, from the "TIFFTAG_COMPRESSION" it needs the full image (with headers) and not just the data buffer.

Regards

ade


--
You are subscribed to the mailing-list of the OpenJPEG project (www.openjpeg.org)
To post: email to open...@googlegroups.com
To unsubscribe: email to openjpeg+u...@googlegroups.com
For more options: visit http://groups.google.com/group/openjpeg
OpenJPEG is mainly supported by :
* UCL Image and Signal Processing Group (http://sites.uclouvain.be/ispgroup)
* IntoPIX (www.intopix.com)

ade90036

unread,
May 9, 2018, 3:43:54 PM5/9/18
to OpenJPEG
Anything that you could share would be most appreciated...

szuk...@arcor.de

unread,
May 9, 2018, 11:39:00 PM5/9/18
to OpenJPEG
ade,

attached is a simple file.

winfried


JP2_file_from_rgb.c.zip

ade90036

unread,
May 15, 2018, 5:34:15 AM5/15/18
to OpenJPEG
Hi Winfriend,

Thanks for sharing the code, it was extremely helpful to understand the sequence of calls.

The only thing i had to change is to output the J2K to a stream rather to a file. :)
I've used the stream implementation which I've cannibalized from here: https://github.com/malaterre/GDCM/blob/master/Source/MediaStorageAndFileFormat/gdcmJPEG2000Codec.cxx#L438

Code works, happy days.

In retrospect what i have found to be a huge stumbling block is the considerable lack of, or existence of developer friendly documentation.
In comparison, libjpeg-turbo, offers this file (https://github.com/libjpeg-turbo/libjpeg-turbo/blob/master/libjpeg.txt) which is linked off README and i challenge you to read it find how long it takes to know what you need to do... i guess minutes..
Also they have a comprehensive unit test which you can understand how certain features are used.

In comparison openjpeg/test/unit/testempty1,2 have the potential to be a strarting point for great samples.
First of all testempty1.c would need to read some real data, RGB data preferably. (everyone understand it)
Second of all testempty2.c, probably would need to read / write from a memory stream rather than a file stream. (Encode/Decode, sequential)
(testempty0.c is a pointless test, it test nothing!!!)

Knowledge on how to use such code should be maintained with the code and not disseminated in forums as it is version sensitive.
For example 1.4 doesn't work but in 2.0 it does.

Regards

Andrea
Regards

Andrea


Reply all
Reply to author
Forward
0 new messages