minor tweaks to the code
[openjpeg.git] / src / lib / openjp2 / tcd.c
index 973ef1e7ac1afbfda141833e6d9edb2e6150301e..a5a5d272796b38f59fa6263b6b8501ede6fc4939 100644 (file)
@@ -268,7 +268,7 @@ void opj_tcd_makelayer( opj_tcd_t *tcd,
                                                                         n = passno + 1;
                                                                 continue;
                                                         }
-                                                        if (dd / dr >= thresh)
+                                                        if (thresh - (dd / dr) < DBL_EPSILON) /* do not rely on float equality, check with DBL_EPSILON margin */
                                                                 n = passno + 1;
                                                 }
 
@@ -626,7 +626,7 @@ void opj_tcd_destroy(opj_tcd_t *tcd) {
 OPJ_BOOL opj_alloc_tile_component_data(opj_tcd_tilecomp_t *l_tilec)
 {
        if ((l_tilec->data == 00) || ((l_tilec->data_size_needed > l_tilec->data_size) && (l_tilec->ownsData == OPJ_FALSE))) {
-               l_tilec->data = (OPJ_INT32 *) opj_malloc(l_tilec->data_size_needed);
+               l_tilec->data = (OPJ_INT32 *) opj_aligned_malloc(l_tilec->data_size_needed);
                if (! l_tilec->data ) {
                        return OPJ_FALSE;
                }
@@ -635,11 +635,11 @@ OPJ_BOOL opj_alloc_tile_component_data(opj_tcd_tilecomp_t *l_tilec)
                l_tilec->ownsData = OPJ_TRUE;
        }
        else if (l_tilec->data_size_needed > l_tilec->data_size) {
-               OPJ_INT32 * new_data = (OPJ_INT32 *) opj_realloc(l_tilec->data, l_tilec->data_size_needed);
+               OPJ_INT32 * new_data = (OPJ_INT32 *) opj_aligned_realloc(l_tilec->data, l_tilec->data_size_needed);
                /* 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_free(l_tilec->data);
+                       opj_aligned_free(l_tilec->data);
                        l_tilec->data = NULL;
                        l_tilec->data_size = 0;
                        l_tilec->data_size_needed = 0;
@@ -862,10 +862,10 @@ static INLINE OPJ_BOOL opj_tcd_init_tile(opj_tcd_t *p_tcd, OPJ_UINT32 p_tile_no,
                                        /* y0b = 1 if bandno = 2 or 3 */
                                        l_y0b = (OPJ_INT32)((l_band->bandno)>>1);
                                        /* l_band border (global) */
-                                       l_band->x0 = opj_int_ceildivpow2(l_tilec->x0 - (1 << l_level_no) * l_x0b, (OPJ_INT32)(l_level_no + 1));
-                                       l_band->y0 = opj_int_ceildivpow2(l_tilec->y0 - (1 << l_level_no) * l_y0b, (OPJ_INT32)(l_level_no + 1));
-                                       l_band->x1 = opj_int_ceildivpow2(l_tilec->x1 - (1 << l_level_no) * l_x0b, (OPJ_INT32)(l_level_no + 1));
-                                       l_band->y1 = opj_int_ceildivpow2(l_tilec->y1 - (1 << l_level_no) * l_y0b, (OPJ_INT32)(l_level_no + 1));
+                                       l_band->x0 = opj_int64_ceildivpow2(l_tilec->x0 - ((OPJ_INT64)l_x0b << l_level_no), (OPJ_INT32)(l_level_no + 1));
+                                       l_band->y0 = opj_int64_ceildivpow2(l_tilec->y0 - ((OPJ_INT64)l_y0b << l_level_no), (OPJ_INT32)(l_level_no + 1));
+                                       l_band->x1 = opj_int64_ceildivpow2(l_tilec->x1 - ((OPJ_INT64)l_x0b << l_level_no), (OPJ_INT32)(l_level_no + 1));
+                                       l_band->y1 = opj_int64_ceildivpow2(l_tilec->y1 - ((OPJ_INT64)l_y0b << l_level_no), (OPJ_INT32)(l_level_no + 1));
                                }
                                
                                /** avoid an if with storing function pointer */