RealmeIP / openjpeg

Automatically exported from code.google.com/p/openjpeg
Other
0 stars 0 forks source link

stream_create_buffer_stream() fails with tile in trunk #240

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
openjpeg-trunk-2334 

 succeeds with opj_set_decode_area()
 fails    with opj_get_decoded_tile()

when using stream_create_buffer_stream().

winfried

Original issue reported on code.google.com by szukw...@arcor.de on 10 Sep 2013 at 11:12

GoogleCodeExporter commented 8 years ago
Do you have a test data for this ?

Original comment by mathieu.malaterre on 24 Feb 2014 at 8:44

GoogleCodeExporter commented 8 years ago
Mathieu, you have to wait about 10 days for an answer. I am not at home.
winfried

Original comment by szukw...@gmail.com on 24 Feb 2014 at 5:25

GoogleCodeExporter commented 8 years ago

Original comment by mathieu.malaterre on 25 Feb 2014 at 2:16

GoogleCodeExporter commented 8 years ago
The sample code is attached.

It fails for JP2 images at 'opj_end_decompress()'. 
Succeeds for J2K images.

winfried

Original comment by szukw...@arcor.de on 9 Mar 2014 at 7:46

Attachments:

GoogleCodeExporter commented 8 years ago
See 'stream-bug.cxx':

'Bretagne2.j2k' has 24 tiles.

With
#define TEST_BUFFER_STREAM

e.g.

OPENJPEG.cxx:712:
        opj_get_decoded_tile 12 failed.
or
OPENJPEG.cxx:712:
        opj_get_decoded_tile 1 failed.
or
OPENJPEG.cxx:712:
        opj_get_decoded_tile 23 failed.

With
//#define TEST_BUFFER_STREAM

All tiles succeed.

winfried

Original comment by szukw...@arcor.de on 9 Mar 2014 at 1:14

GoogleCodeExporter commented 8 years ago

Original comment by mathieu.malaterre on 19 Mar 2014 at 1:15

GoogleCodeExporter commented 8 years ago
there is no main function ? how should I compile this beast ?

Original comment by mathieu.malaterre on 25 Mar 2014 at 4:26

GoogleCodeExporter commented 8 years ago
Here is a patch. Tested with 'Bretagne2.j2k'.

winfried

Original comment by szukw...@arcor.de on 26 Mar 2014 at 1:38

Attachments:

GoogleCodeExporter commented 8 years ago

Original comment by mathieu.malaterre on 26 Mar 2014 at 3:38

GoogleCodeExporter commented 8 years ago
opj_end_decompress failed only with JP2 files, not with J2k files.

opj_jp2_exec()
{
jp2.c:1982:
    TRACE i[0]
jp2.c:1989:
    TRACE l_result(0)
}

How can I find out which program has been called at entry[0]?

winfried

Original comment by szukw...@arcor.de on 10 Jul 2014 at 7:17

GoogleCodeExporter commented 8 years ago
Well, I have found the bug.

I have changed:

static OPJ_UINT32 read_from_buffer(void *p_buffer, OPJ_UINT32 p_nb_bytes,
    SampleInfo *sinfo)
{
    OPJ_UINT32 l_nb_read;

    if(sinfo->cur_buf + p_nb_bytes < sinfo->sample_buf + sinfo->sample_size )
   {
    l_nb_read = p_nb_bytes;
   }
    else
   {
    l_nb_read = (OPJ_UINT32)
     (sinfo->sample_buf + sinfo->sample_size - sinfo->cur_buf);
   }
    memcpy(p_buffer, sinfo->cur_buf, l_nb_read);
    sinfo->cur_buf += l_nb_read;

    return l_nb_read ? l_nb_read : ((OPJ_UINT32)-1);
}

to:

static  OPJ_SIZE_T read_from_buffer(void *p_buffer, OPJ_SIZE_T p_nb_bytes,
    SampleInfo *sinfo)
{
    OPJ_SIZE_T l_nb_read;

    if(sinfo->cur_buf + p_nb_bytes < sinfo->sample_buf + sinfo->sample_size )
   {
    l_nb_read = p_nb_bytes;
   }
    else
   {
    l_nb_read = (OPJ_SIZE_T)
     ((sinfo->sample_buf + sinfo->sample_size) - sinfo->cur_buf);
   }

    memcpy(p_buffer, sinfo->cur_buf, l_nb_read);
    sinfo->cur_buf += l_nb_read;

    return l_nb_read ? l_nb_read : (OPJ_SIZE_T)-1;
}

You can now remove this issue.

winfried

Original comment by szukw...@arcor.de on 13 Jul 2014 at 1:32

GoogleCodeExporter commented 8 years ago
At first glance: please do not close this issue.

Here is the second bug:

static OPJ_OFF_T skip_from_buffer(OPJ_OFF_T p_nb_bytes,
    SampleInfo *sinfo)
{
    if(sinfo->cur_buf + p_nb_bytes < sinfo->sample_buf + sinfo->sample_size )
   {
    sinfo->cur_buf += p_nb_bytes;
    return p_nb_bytes;
   }
    sinfo->cur_buf = sinfo->sample_buf + sinfo->sample_size;

//WRONG:    return (OPJ_OFF_T)-1;
    return p_nb_bytes;// CORRECT
}

winfried

Original comment by szukw...@arcor.de on 15 Jul 2014 at 6:23

GoogleCodeExporter commented 8 years ago
The code for opj_seek_from_file() runs:

static OPJ_BOOL opj_seek_from_file (OPJ_OFF_T p_nb_bytes, FILE * p_user_data)
{
    if (OPJ_FSEEK(p_user_data,p_nb_bytes,SEEK_SET)) {
        return OPJ_FALSE;
    }

    return OPJ_TRUE;
}

SEEK_SET means FROM_START. Therefore:
======================================

static OPJ_BOOL seek_from_buffer(OPJ_OFF_T p_nb_bytes,
    BufferInfo *bufinfo)
{
    if(p_nb_bytes <= bufinfo->sample_size )
   {
    bufinfo->cur_buf = bufinfo->sample_buf + p_nb_bytes;
    return OPJ_TRUE;
   }
    bufinfo->cur_buf = bufinfo->sample_buf + bufinfo->sample_size;

    return OPJ_FALSE;
}

instead of:
======================================

static OPJ_BOOL seek_from_buffer(OPJ_OFF_T p_nb_bytes,
    BufferInfo *bufinfo)
{
    if(bufinfo->cur_buf + p_nb_bytes < bufinfo->sample_buf + bufinfo->sample_size )
   {
    bufinfo->cur_buf += p_nb_bytes;
    return OPJ_TRUE;
   }

    bufinfo->cur_buf = bufinfo->sample_buf + bufinfo->sample_size;

    return OPJ_FALSE;
}

This seems to be the last bug.

winfried

Original comment by szukw...@arcor.de on 10 Aug 2014 at 6:50