Fix some calculations in opj_tcd_init_tile
authormayeut <mayeut@users.noreply.github.com>
Sun, 23 Aug 2015 09:38:04 +0000 (11:38 +0200)
committermayeut <mayeut@users.noreply.github.com>
Sun, 23 Aug 2015 09:38:04 +0000 (11:38 +0200)
Fixes #486
Fixes #394
Update #480
Update #388

src/lib/openjp2/opj_intmath.h
src/lib/openjp2/tcd.c

index f39f684317574d75ab91b6810fad9be7997d4477..3f7934c470cbbf3bec7e9fab5488df7f8de74018 100644 (file)
@@ -135,7 +135,15 @@ Divide an integer by a power of 2 and round upwards
 @return Returns a divided by 2^b
 */
 static INLINE OPJ_INT32 opj_int_ceildivpow2(OPJ_INT32 a, OPJ_INT32 b) {
-       return (OPJ_INT32)((a + (OPJ_INT64)(1 << b) - 1) >> b);
+       return (OPJ_INT32)((a + ((OPJ_INT64)1 << b) - 1) >> b);
+}
+
+/**
+ Divide a 64bits integer by a power of 2 and round upwards
+ @return Returns a divided by 2^b
+ */
+static INLINE OPJ_INT32 opj_int64_ceildivpow2(OPJ_INT64 a, OPJ_INT32 b) {
+       return (OPJ_INT32)((a + ((OPJ_INT64)1 << b) - 1) >> b);
 }
 
 /**
@@ -143,7 +151,7 @@ static INLINE OPJ_INT32 opj_int_ceildivpow2(OPJ_INT32 a, OPJ_INT32 b) {
  @return Returns a divided by 2^b
  */
 static INLINE OPJ_UINT32 opj_uint_ceildivpow2(OPJ_UINT32 a, OPJ_UINT32 b) {
-       return (OPJ_UINT32)((a + (OPJ_UINT64)(1U << b) - 1U) >> b);
+       return (OPJ_UINT32)((a + ((OPJ_UINT64)1U << b) - 1U) >> b);
 }
 
 /**
@@ -184,8 +192,8 @@ Multiply two fixed-precision rational numbers.
 @return Returns a * b
 */
 static INLINE OPJ_INT32 opj_int_fix_mul(OPJ_INT32 a, OPJ_INT32 b) {
-#if defined(_MSC_VER) && (_MSC_VER >= 1400) && !defined(__INTEL_COMPILER) && defined(_M_IX86)\r
-       OPJ_INT64 temp = __emul(a, b);\r
+#if defined(_MSC_VER) && (_MSC_VER >= 1400) && !defined(__INTEL_COMPILER) && defined(_M_IX86)
+       OPJ_INT64 temp = __emul(a, b);
 #else
        OPJ_INT64 temp = (OPJ_INT64) a * (OPJ_INT64) b ;
 #endif
@@ -196,8 +204,8 @@ static INLINE OPJ_INT32 opj_int_fix_mul(OPJ_INT32 a, OPJ_INT32 b) {
 }
 
 static INLINE OPJ_INT32 opj_int_fix_mul_t1(OPJ_INT32 a, OPJ_INT32 b) {
-#if defined(_MSC_VER) && (_MSC_VER >= 1400) && !defined(__INTEL_COMPILER) && defined(_M_IX86)\r
-       OPJ_INT64 temp = __emul(a, b);\r
+#if defined(_MSC_VER) && (_MSC_VER >= 1400) && !defined(__INTEL_COMPILER) && defined(_M_IX86)
+       OPJ_INT64 temp = __emul(a, b);
 #else
        OPJ_INT64 temp = (OPJ_INT64) a * (OPJ_INT64) b ;
 #endif
index 973ef1e7ac1afbfda141833e6d9edb2e6150301e..8f1c941026af291dc51fcee49cf982cc84ece19c 100644 (file)
@@ -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 */