parent
dd81b5892d
commit
83249c318f
|
@ -9947,6 +9947,7 @@ OPJ_BOOL opj_j2k_encode(opj_j2k_t * p_j2k,
|
||||||
OPJ_UINT32 l_nb_tiles;
|
OPJ_UINT32 l_nb_tiles;
|
||||||
OPJ_UINT32 l_max_tile_size = 0, l_current_tile_size;
|
OPJ_UINT32 l_max_tile_size = 0, l_current_tile_size;
|
||||||
OPJ_BYTE * l_current_data = 00;
|
OPJ_BYTE * l_current_data = 00;
|
||||||
|
OPJ_BOOL l_reuse_data = OPJ_FALSE;
|
||||||
opj_tcd_t* p_tcd = 00;
|
opj_tcd_t* p_tcd = 00;
|
||||||
|
|
||||||
/* preconditions */
|
/* preconditions */
|
||||||
|
@ -9957,6 +9958,17 @@ OPJ_BOOL opj_j2k_encode(opj_j2k_t * p_j2k,
|
||||||
p_tcd = p_j2k->m_tcd;
|
p_tcd = p_j2k->m_tcd;
|
||||||
|
|
||||||
l_nb_tiles = p_j2k->m_cp.th * p_j2k->m_cp.tw;
|
l_nb_tiles = p_j2k->m_cp.th * p_j2k->m_cp.tw;
|
||||||
|
if (l_nb_tiles == 1) {
|
||||||
|
l_reuse_data = OPJ_TRUE;
|
||||||
|
#ifdef __SSE__
|
||||||
|
for (j=0;j<p_j2k->m_tcd->image->numcomps;++j) {
|
||||||
|
opj_image_comp_t * l_img_comp = p_tcd->image->comps + j;
|
||||||
|
if (((size_t)l_img_comp->data & 0xFU) != 0U) { /* tile data shall be aligned on 16 bytes */
|
||||||
|
l_reuse_data = OPJ_FALSE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
for (i=0;i<l_nb_tiles;++i) {
|
for (i=0;i<l_nb_tiles;++i) {
|
||||||
if (! opj_j2k_pre_write_tile(p_j2k,i,p_stream,p_manager)) {
|
if (! opj_j2k_pre_write_tile(p_j2k,i,p_stream,p_manager)) {
|
||||||
if (l_current_data) {
|
if (l_current_data) {
|
||||||
|
@ -9969,7 +9981,7 @@ OPJ_BOOL opj_j2k_encode(opj_j2k_t * p_j2k,
|
||||||
/* otherwise, allocate the data */
|
/* otherwise, allocate the data */
|
||||||
for (j=0;j<p_j2k->m_tcd->image->numcomps;++j) {
|
for (j=0;j<p_j2k->m_tcd->image->numcomps;++j) {
|
||||||
opj_tcd_tilecomp_t* l_tilec = p_tcd->tcd_image->tiles->comps + j;
|
opj_tcd_tilecomp_t* l_tilec = p_tcd->tcd_image->tiles->comps + j;
|
||||||
if (l_nb_tiles == 1) {
|
if (l_reuse_data) {
|
||||||
opj_image_comp_t * l_img_comp = p_tcd->image->comps + j;
|
opj_image_comp_t * l_img_comp = p_tcd->image->comps + j;
|
||||||
l_tilec->data = l_img_comp->data;
|
l_tilec->data = l_img_comp->data;
|
||||||
l_tilec->ownsData = OPJ_FALSE;
|
l_tilec->ownsData = OPJ_FALSE;
|
||||||
|
@ -9984,7 +9996,7 @@ OPJ_BOOL opj_j2k_encode(opj_j2k_t * p_j2k,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
l_current_tile_size = opj_tcd_get_encoded_tile_size(p_j2k->m_tcd);
|
l_current_tile_size = opj_tcd_get_encoded_tile_size(p_j2k->m_tcd);
|
||||||
if (l_nb_tiles > 1) {
|
if (!l_reuse_data) {
|
||||||
if (l_current_tile_size > l_max_tile_size) {
|
if (l_current_tile_size > l_max_tile_size) {
|
||||||
OPJ_BYTE *l_new_current_data = (OPJ_BYTE *) opj_realloc(l_current_data, l_current_tile_size);
|
OPJ_BYTE *l_new_current_data = (OPJ_BYTE *) opj_realloc(l_current_data, l_current_tile_size);
|
||||||
if (! l_new_current_data) {
|
if (! l_new_current_data) {
|
||||||
|
|
|
@ -79,8 +79,7 @@ static inline void *opj_aligned_realloc_n(void *ptr, size_t alignment, size_t si
|
||||||
* allocated array (eg. _msize on Windows, malloc_size on MacOS,
|
* allocated array (eg. _msize on Windows, malloc_size on MacOS,
|
||||||
* malloc_usable_size on systems with glibc) */
|
* malloc_usable_size on systems with glibc) */
|
||||||
a_ptr = opj_aligned_alloc_n(alignment, size);
|
a_ptr = opj_aligned_alloc_n(alignment, size);
|
||||||
/* memory may overlap, do not use memcpy */
|
memcpy(a_ptr, r_ptr, size);
|
||||||
memmove(a_ptr, r_ptr, size);
|
|
||||||
free( r_ptr );
|
free( r_ptr );
|
||||||
return a_ptr;
|
return a_ptr;
|
||||||
/* _MSC_VER */
|
/* _MSC_VER */
|
||||||
|
|
|
@ -635,18 +635,15 @@ OPJ_BOOL opj_alloc_tile_component_data(opj_tcd_tilecomp_t *l_tilec)
|
||||||
l_tilec->ownsData = OPJ_TRUE;
|
l_tilec->ownsData = OPJ_TRUE;
|
||||||
}
|
}
|
||||||
else if (l_tilec->data_size_needed > l_tilec->data_size) {
|
else if (l_tilec->data_size_needed > l_tilec->data_size) {
|
||||||
OPJ_INT32 * new_data = (OPJ_INT32 *) opj_aligned_realloc(l_tilec->data, l_tilec->data_size_needed);
|
/* We don't need to keep old data */
|
||||||
/* opj_event_msg(p_manager, EVT_ERROR, "Not enough memory to handle tile datan"); */
|
|
||||||
/* fprintf(stderr, "Not enough memory to handle tile data"); */
|
|
||||||
if (! new_data) {
|
|
||||||
opj_aligned_free(l_tilec->data);
|
opj_aligned_free(l_tilec->data);
|
||||||
l_tilec->data = NULL;
|
l_tilec->data = (OPJ_INT32 *) opj_aligned_malloc(l_tilec->data_size_needed);
|
||||||
|
if (! l_tilec->data ) {
|
||||||
l_tilec->data_size = 0;
|
l_tilec->data_size = 0;
|
||||||
l_tilec->data_size_needed = 0;
|
l_tilec->data_size_needed = 0;
|
||||||
l_tilec->ownsData = OPJ_FALSE;
|
l_tilec->ownsData = OPJ_FALSE;
|
||||||
return OPJ_FALSE;
|
return OPJ_FALSE;
|
||||||
}
|
}
|
||||||
l_tilec->data = new_data;
|
|
||||||
/*fprintf(stderr, "tReallocate data of tilec (int): from %d to %d x OPJ_UINT32n", l_tilec->data_size, l_data_size);*/
|
/*fprintf(stderr, "tReallocate data of tilec (int): from %d to %d x OPJ_UINT32n", l_tilec->data_size, l_data_size);*/
|
||||||
l_tilec->data_size = l_tilec->data_size_needed;
|
l_tilec->data_size = l_tilec->data_size_needed;
|
||||||
l_tilec->ownsData = OPJ_TRUE;
|
l_tilec->ownsData = OPJ_TRUE;
|
||||||
|
@ -1521,7 +1518,7 @@ static void opj_tcd_free_tile(opj_tcd_t *p_tcd)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (l_tile_comp->ownsData && l_tile_comp->data) {
|
if (l_tile_comp->ownsData && l_tile_comp->data) {
|
||||||
opj_free(l_tile_comp->data);
|
opj_aligned_free(l_tile_comp->data);
|
||||||
l_tile_comp->data = 00;
|
l_tile_comp->data = 00;
|
||||||
l_tile_comp->ownsData = 0;
|
l_tile_comp->ownsData = 0;
|
||||||
l_tile_comp->data_size = 0;
|
l_tile_comp->data_size = 0;
|
||||||
|
|
Loading…
Reference in New Issue