int c_invert( double incoef[6], /* Transformation coefficients--input */ double coef[6] /* Inverted transformation coefficients */ ) { double det; /* Determinate */ double maximum; /* Maximum input coefficient value */ double max1, max2; /* Temporary variables for max calculation */ /* Find the determinate ---------------------*/ det = ( incoef[3] * incoef[1] ) - ( incoef[4] * incoef[0] ); /* Find the maximum coefficent value ----------------------------------*/ max1 = CMAX( fabs( incoef[0] ), fabs( incoef[1] ) ); max2 = CMAX( fabs( incoef[3] ), fabs( incoef[4] ) ); maximum = CMAX( max1, max2 ); /* Is the determinant of the coefficients too near zero? ----------------------------------------------------------------------*/ if ( fabs( det ) < ( EPSLNX * maximum ) ) { ErrorHandler( FALSE, "c_invert", ERROR_PROJECTION_MATH, "Determinant too near zero" ); return ( E_GEO_FAIL ); } /* Compute inverse coefficients -----------------------------*/ coef[0] = -( incoef[4] ) / det; coef[1] = incoef[1] / det; coef[2] = ( ( incoef[4] * incoef[2] ) - ( incoef[1] * incoef[5] ) ) / det; coef[3] = incoef[3] / det; coef[4] = -( incoef[0] ) / det; coef[5] = ( ( incoef[0] * incoef[5] ) - ( incoef[3] * incoef[2] ) ) / det; return ( E_GEO_SUCC ); }
void BvcEncoder::decompose_block(const u_char* in, int8_t* out) { int32_t scratch[CMAX(2*8*18/4, 64)]; u_int8_t* l = (u_int8_t*)scratch; int8_t* h = (int8_t*)&l[8*18]; int stride = width_; in -= 1; for (int w = 18; --w >= 0; ) { int8_t* cl = (int8_t*)(l++); int8_t* ch = h++; const u_char* p = in++; int in0 = p[-stride]; int in1 = *p; p += stride; for (int th = 8; --th >= 0; ) { int in2 = *p; p += stride; int in3 = *p; p += stride; /* multiply by 3 */ int m1 = in1 + (in1 << 1); int m2 = in2 + (in2 << 1); /* -1 3 3 -1 */ int v = m1 + m2 - in0 - in3; v >>= 2; if (v & ~0xff) v = (v < 0) ? 0 : 255; *cl = v; cl += 18; /* 1 -3 3 -1 */ v = in0 - m1 + m2 - in3; v >>= 2; if ((v + 127) & ~0xff) v = (v < -128) ? -128 : 127; *ch = v; ch += 18; in0 = in2; in1 = in3; } } /* rows */ const u_int8_t* p = (u_int8_t*)scratch; l = (u_int8_t*)out; h = out + 2*64; int th; for (th = 8; --th >= 0; ) { int in0 = *p++; int in1 = *p++; for (int w = 8; --w >= 0; ) { int in2 = *p++; int in3 = *p++; /* multiply by 3 */ int m1 = in1 + (in1 << 1); int m2 = in2 + (in2 << 1); /* -1 3 3 -1 */ int v = m1 + m2 - in0 - in3; v >>= 2; if (v & ~0xff) v = (v < 0) ? 0 : 255; *l++ = v; /* 1 -3 3 -1 */ v = in0 - m1 + m2 - in3; v >>= 2; if ((v + 127) & ~0xff) v = (v < -128) ? -128 : 127; *h++ = v; in0 = in2; in1 = in3; } } for (th = 8; --th >= 0; ) { int in0 = *(int8_t*)(p++); int in1 = *(int8_t*)(p++); for (int w = 8; --w >= 0; ) { int in2 = *(int8_t*)(p++); int in3 = *(int8_t*)(p++); /* multiply by 3 */ int m1 = in1 + (in1 << 1); int m2 = in2 + (in2 << 1); /* -1 3 3 -1 */ int v = m1 + m2 - in0 - in3; *l++ = v >> 2; #ifdef HAVE_HH /* 1 -3 3 -1 */ v = in0 - m1 + m2 - in3; *h++ = v >> 2; #endif in0 = in2; in1 = in3; } } /* now apply fully separable Haar tranform remaining 8x8 subimage */ /* columns */ l = (u_int8_t*)out; int32_t* o = scratch; int k; for (k = 8; --k >= 0; ) { /* use fixed point arithmetic with 2 bits of fraction */ int t0 = l[0*8]; int t1 = l[1*8]; int t2 = t0 + t1; o[4*8] = (t1 - t0) << 2; t0 = l[2*8]; t1 = l[3*8]; int t3 = t0 + t1; o[5*8] = (t1 - t0) << 2; t0 = l[4*8]; t1 = l[5*8]; int t4 = t0 + t1; o[6*8] = (t1 - t0) << 2; t0 = l[6*8]; t1 = l[7*8]; int t5 = t0 + t1; o[7*8] = (t1 - t0) << 2; t0 = t2 + t3; t1 = t4 + t5; o[0*8] = t0 + t1; o[1*8] = t1 - t0; o[2*8] = (t3 - t2) << 1; o[3*8] = (t5 - t4) << 1; ++o; ++l; } /* rows */ o = scratch; l = (u_int8_t*)out; for (k = 8; --k >= 0; ) { int t0 = o[0]; int t1 = o[1]; int t2 = t0 + t1; l[4] = (t1 - t0 + 7) >> 4; t0 = o[2]; t1 = o[3]; int t3 = t0 + t1; l[5] = (t1 - t0 + 7) >> 4; t0 = o[4]; t1 = o[5]; int t4 = t0 + t1; l[6] = (t1 - t0 + 7) >> 4; t0 = o[6]; t1 = o[7]; int t5 = t0 + t1; l[7] = (t1 - t0 + 7) >> 4; t0 = t2 + t3; t1 = t4 + t5; l[0] = (t0 + t1 + 31) >> 6; l[1] = (t1 - t0 + 31) >> 6; l[2] = (t3 - t2 + 15) >> 5; l[3] = (t5 - t4 + 15) >> 5; l += 8; o += 8; } }