summaryrefslogtreecommitdiff
path: root/src/lib/openjp2/t2.c
diff options
context:
space:
mode:
authorEven Rouault <even.rouault@spatialys.com>2017-06-02 16:49:26 +0200
committerEven Rouault <even.rouault@spatialys.com>2017-06-02 18:24:07 +0200
commit532243f1fd9997db63ea7f6b199d21138ccf58a3 (patch)
tree3e204ebb64f2a1ceb5c73af30c3ff377dde55b9a /src/lib/openjp2/t2.c
parent9b39fc4bccb3e9e4e9a9f61c4dc672fb7f05d865 (diff)
MQC/RAW decoder: use an artificial 0xFF 0xFF terminating marker.
This saves comparing the current pointer with the end of buffer pointer. This results at least in tiny speed improvement for raw decoding, and smaller code size for MQC as well. This kills the remains of the raw.h/.c files that were only used for decoding. Encoding using the mqc structure already.
Diffstat (limited to 'src/lib/openjp2/t2.c')
-rw-r--r--src/lib/openjp2/t2.c13
1 files changed, 9 insertions, 4 deletions
diff --git a/src/lib/openjp2/t2.c b/src/lib/openjp2/t2.c
index b0990963..7d27f688 100644
--- a/src/lib/openjp2/t2.c
+++ b/src/lib/openjp2/t2.c
@@ -38,6 +38,8 @@
*/
#include "opj_includes.h"
+#include "opj_common.h"
+
/** @defgroup T2 T2 - Implementation of a tier-2 coding */
/*@{*/
@@ -1233,7 +1235,8 @@ static OPJ_BOOL opj_t2_read_packet_data(opj_t2_t* p_t2,
#endif /* USE_JPWL */
/* Check possible overflow on size */
- if ((l_cblk->data_current_size + l_seg->newlen) < l_cblk->data_current_size) {
+ if ((l_cblk->data_current_size + l_seg->newlen + OPJ_COMMON_CBLK_DATA_EXTRA) <
+ l_cblk->data_current_size) {
opj_event_msg(p_manager, EVT_ERROR,
"read: segment too long (%d) with current size (%d > %d) for codeblock %d (p=%d, b=%d, r=%d, c=%d)\n",
l_seg->newlen, l_cblk->data_current_size, 0xFFFFFFFF - l_seg->newlen, cblkno,
@@ -1241,9 +1244,10 @@ static OPJ_BOOL opj_t2_read_packet_data(opj_t2_t* p_t2,
return OPJ_FALSE;
}
/* Check if the cblk->data have allocated enough memory */
- if ((l_cblk->data_current_size + l_seg->newlen) > l_cblk->data_max_size) {
+ if ((l_cblk->data_current_size + l_seg->newlen + OPJ_COMMON_CBLK_DATA_EXTRA) >
+ l_cblk->data_max_size) {
OPJ_BYTE* new_cblk_data = (OPJ_BYTE*) opj_realloc(l_cblk->data,
- l_cblk->data_current_size + l_seg->newlen);
+ l_cblk->data_current_size + l_seg->newlen + OPJ_COMMON_CBLK_DATA_EXTRA);
if (! new_cblk_data) {
opj_free(l_cblk->data);
l_cblk->data = NULL;
@@ -1251,7 +1255,8 @@ static OPJ_BOOL opj_t2_read_packet_data(opj_t2_t* p_t2,
/* opj_event_msg(p_manager, EVT_ERROR, "Not enough memory to realloc code block cata!\n"); */
return OPJ_FALSE;
}
- l_cblk->data_max_size = l_cblk->data_current_size + l_seg->newlen;
+ l_cblk->data_max_size = l_cblk->data_current_size + l_seg->newlen +
+ OPJ_COMMON_CBLK_DATA_EXTRA;
l_cblk->data = new_cblk_data;
}