Skip to content
Permalink
Browse files

openjpeg linking

  • Loading branch information...
aglv committed Nov 7, 2017
1 parent d101e69 commit 1ffe39a88401dff30e7a6c525d8b3a0a3677c3f6
@@ -13,3 +13,6 @@
[submodule "GDCM"]
path = GDCM
url = git://git.code.sf.net/p/gdcm/gdcm
[submodule "OpenJPEG"]
path = OpenJPEG
url = git@github.com:uclouvain/openjpeg.git
@@ -111,7 +111,7 @@ This file is part of the Horos Project (www.horosproject.org)
#include <stdlib.h>

#import "url.h"
#include "opj_config.h"
#include <OpenJPEG/opj_config.h>
#define BUILTIN_DCMTK YES

#define MAXSCREENS 10
@@ -61,7 +61,7 @@
extern short Use_kdu_IfAvailable;

#include "OPJSupport.h"
#include "../Binaries/openjpeg/openjpeg.h"
#include <OpenJPEG/openjpeg.h>

#include "options.h"

BIN -298 KB Binaries/openjpeg.zip
Binary file not shown.
@@ -39,8 +39,8 @@

#include "OPJSupport.h"

#include "openjpeg.h"
#include "format_defs.h"
#include <OpenJPEG/openjpeg.h>
#include <OpenJPEG/format_defs.h>

#include <assert.h>
#include <stdlib.h>
@@ -53,6 +53,125 @@
//#define OPJ_VERBOSE


typedef struct opj_buffer_info {
OPJ_BYTE *buf;
OPJ_BYTE *cur;
OPJ_SIZE_T len;
} opj_buffer_info_t;

static OPJ_SIZE_T opj_read_from_buffer(void* pdst, OPJ_SIZE_T len, opj_buffer_info_t* psrc) {
OPJ_SIZE_T n = psrc->buf + psrc->len - psrc->cur;

if (n) {
if (n > len)
n = len;

memcpy (pdst, psrc->cur, n);
psrc->cur += n;
}
else
n = (OPJ_SIZE_T)-1;

return n;
}

static OPJ_SIZE_T opj_write_to_buffer(void* p_buffer, OPJ_SIZE_T p_nb_bytes, opj_buffer_info_t* p_source_buffer) {
OPJ_BYTE* pbuf = p_source_buffer->buf;
OPJ_BYTE* pcur = p_source_buffer->cur;

OPJ_SIZE_T len = p_source_buffer->len;

if (0 == len)
len = 1;

OPJ_SIZE_T dist = pcur - pbuf, n = len - dist;
assert (dist <= len);

while (n < p_nb_bytes) {
len *= 2;
n = len - dist;
}

if (len != p_source_buffer->len) {
pbuf = (OPJ_BYTE*)malloc(len);

if (0 == pbuf)
return (OPJ_SIZE_T)-1;

if (p_source_buffer->buf) {
memcpy (pbuf, p_source_buffer->buf, dist);
free(p_source_buffer->buf);
}

p_source_buffer->buf = pbuf;
p_source_buffer->cur = pbuf + dist;
p_source_buffer->len = len;
}

memcpy (p_source_buffer->cur, p_buffer, p_nb_bytes);
p_source_buffer->cur += p_nb_bytes;

return p_nb_bytes;
}

static OPJ_SIZE_T opj_skip_from_buffer(OPJ_SIZE_T len, opj_buffer_info_t* psrc) {
OPJ_SIZE_T n = psrc->buf + psrc->len - psrc->cur;

if (n) {
if (n > len)
n = len;

psrc->cur += len;
}
else
n = (OPJ_SIZE_T)-1;

return n;
}

static OPJ_BOOL opj_seek_from_buffer(OPJ_OFF_T len, opj_buffer_info_t* psrc) {
OPJ_SIZE_T n = psrc->len;

if (n > len)
n = len;

psrc->cur = psrc->buf + n;

return OPJ_TRUE;
}

static void opj_free_buffer(opj_buffer_info_t* psrc) {
delete psrc;
}

opj_stream_t * OPJ_CALLCONV opj_stream_create_buffer_stream(OPJ_BYTE *data, OPJ_SIZE_T len, OPJ_BOOL input) {
if (!data)
return NULL;

opj_stream_t* ps = opj_stream_default_create(input);
if (!ps)
return NULL;

opj_buffer_info_t* psrc = new opj_buffer_info_t;
if (!psrc)
return NULL;

psrc->buf = psrc->cur = data;
psrc->len = len;

opj_stream_set_user_data(ps, psrc, (opj_stream_free_user_data_fn)opj_free_buffer);
opj_stream_set_user_data_length(ps, psrc->len);

if (input)
opj_stream_set_read_function (ps, (opj_stream_read_fn)opj_read_from_buffer);
else opj_stream_set_write_function(ps,(opj_stream_write_fn) opj_write_to_buffer);

opj_stream_set_skip_function(ps, (opj_stream_skip_fn)opj_skip_from_buffer);
opj_stream_set_seek_function(ps, (opj_stream_seek_fn)opj_seek_from_buffer);

return ps;
}

typedef struct decode_info
{
opj_codec_t *codec;
@@ -61,7 +180,6 @@ typedef struct decode_info
opj_codestream_info_v2_t* cstr_info;
opj_codestream_index_t* cstr_index;
OPJ_BOOL deleteImage;

} decode_info_t;

#define JP2_RFC3745_MAGIC "\x00\x00\x00\x0c\x6a\x50\x20\x20\x0d\x0a\x87\x0a"
@@ -197,13 +315,16 @@ void* OPJSupport::decompressJPEG2KWithBuffer(void* inputBuffer,
opj_set_default_decoder_parameters(&parameters);
parameters.decod_format = buffer_format(jp2Data);

// Create the stream
/* RONIN OpenJPEG // Create the stream
opj_buffer_info_t bufferInfo;
bufferInfo.cur = bufferInfo.buf = (OPJ_BYTE *)jp2Data;
bufferInfo.len = (OPJ_SIZE_T) jp2DataSize;
// Create the stream
decodeInfo.stream = opj_stream_create_buffer_stream(&bufferInfo , OPJ_STREAM_READ);
*/

// OpenJPEG
decodeInfo.stream = opj_stream_create_buffer_stream((OPJ_BYTE *)jp2Data, jp2DataSize, OPJ_STREAM_READ);

//GROK
//decodeInfo.stream = opj_stream_create_buffer_stream((OPJ_BYTE *)jp2Data, (OPJ_SIZE_T) jp2DataSize , OPJ_STREAM_READ);
Oops, something went wrong.

0 comments on commit 1ffe39a

Please sign in to comment.
You can’t perform that action at this time.