void MixAudio16_SSE2_3(ALshort *dst, alMixEntry *entries)
{
	MixAudio16_SSE2_HEAD(3);
	MIX(1);
	MIX(2);
	MixAudio16_SSE2_TAIL(3);
}
Пример #2
0
void mix_instrument(byte ins_id, float angle, byte vol)
{
	float value;
	byte snd;

	switch (ins_id) {
		default:
		case 0:
			value = sin(angle);
			snd = (value + 1) / 2 * 255;
			break;
		case 1:
			value = saw(angle);
			snd = value * 32 + 127;
			break;
		case 2:
			value = ((rand() % 256) - 128) / 255.0;
			snd = value * 64 + 127;
			break;
	}

#if (MIX_WAY == 0)
		snd_data = MIX(snd_data - 127, vol * snd / 64 - 127) + 127;
#else
	byte m1, m2;
	m1 = snd_data;
	m2 = vol * snd / 64;

	if (m1 + m2 != 0)
		snd_data = MIX(m1, m2);
#endif

}
Пример #3
0
int gettargetposition(int itarget, float time_local, float *x, float *y, float *z){
  targpos *tp;
  int i,nsteps;
  float factor;
  float denom;

  if(itarget<0||itarget>=ntargets)return INVISIBLE;
  tp = target_positions+itarget;
  nsteps = tp->nsteps;
  if(nsteps<=1)return INVISIBLE;
  if(time_local<tp->t[0]||time_local>tp->t[nsteps-1])return INVISIBLE;
  for(i=0;i<nsteps-1;i++){
    if(tp->t[i]<=time_local&&time_local<=tp->t[i+1]){
      denom=tp->t[i+1]-tp->t[i];
      if(denom!=0.0){
        factor=(time_local-tp->t[i])/denom;
      }
      else{
        factor=1.0;
      }
      *x=MIX(factor,tp->x[i+1],tp->x[i]);
      *y=MIX(factor,tp->y[i+1],tp->y[i]);
      *z=MIX(factor,tp->z[i+1],tp->z[i]);
      *x = NORMALIZE_X(*x);
      *y = NORMALIZE_Y(*y);
      *z = NORMALIZE_Z(*z);
      return VISIBLE;
    }
  }
  return INVISIBLE;
}
Пример #4
0
void aead_auth_fin( 
	aead_params_t * params,
	aead_block_t * auth_key,
	aead_block_t * fin_auth_block ) {

	uint64_t m0 = C0 ^ auth_key->r0;
	uint64_t m1 = C1 ^ auth_key->r1;
	uint64_t m2 = C2 ^ auth_key->r2;
	uint64_t m3 = C3 ^ auth_key->r3;
	uint64_t m4 = C4 ^ auth_key->r0;
	uint64_t m5 = C5 ^ auth_key->r1;
	uint64_t m6 = C6 ^ auth_key->r2;
	uint64_t m7 = C7 ^ auth_key->r3;
	uint64_t t04 = 0LLU;
	uint64_t t26 = 0LLU;

#ifdef DEBUG	
	printf( "\n\n\naead_auth_fin\n");
#endif
	
	PRINTSTATE( "Auth fin mix s0,s1,p0,p1" );
	MIX( m0, m1, m2, m3, m4, m5, m6, m7, params->s0, params->s1, params->p0, params->p1 );	
	PRINTSTATE( "" );		
	PARTROUND3( m0, m1, m2, m3 );				
	PARTROUND3( m4, m5, m6, m7 );
	PRINTSTATE( "" );	
	
	// Mix halves (swap 0<->4 and 2<->6)
	t04 = m0; m0 = m4; m4 = t04;	
	t26 = m2; m2 = m6; m6 = t26;

	// Mix in blocks, mode and len
	PRINTSTATE( "Mix blocks, len and mode" );
	MIX( m0, m1, m2, m3, m4, m5, m6, m7, params->block0, params->block1, params->len, params->mode_bits );
	PRINTSTATE( "" );		
	PARTROUND3( m0, m1, m2, m3 );				
	PARTROUND3( m4, m5, m6, m7 );
	PRINTSTATE( "" );		
	
	// Mix halves (swap 0<->4 and 2<->6)
	t04 = m0; m0 = m4; m4 = t04;	
	t26 = m2; m2 = m6; m6 = t26;	

	// Do final transform
	PRINTSTATE( "Final transform" );				
	PARTROUND( m0, m1, m2, m3 );				
	PARTROUND( m4, m5, m6, m7 );
	PRINTSTATE( "" );

	// Finalise
	fin_auth_block->r0 = m0 ^ m4 ^ auth_key->r0;
	fin_auth_block->r1 = m1 ^ m5 ^ auth_key->r1;
	fin_auth_block->r2 = m2 ^ m6 ^ auth_key->r2;
	fin_auth_block->r3 = m3 ^ m7 ^ auth_key->r3;
		
}
void MixAudio16_SSE2_6(ALshort *dst, alMixEntry *entries)
{
	MixAudio16_SSE2_HEAD(6);
	MIX(1);
	MIX(2);
	MIX(3);
	MIX(4);
	MIX(5);
	MixAudio16_SSE2_TAIL(6);
}
Пример #6
0
U32 jhash( SV* str )
{
    STRLEN rawlen;
    char* p;
    U32 a, b, c, len, length;

    /* extract the string data and string length from the perl scalar */
    p = (char*)SvPV(str, rawlen);
    length = len = (U32)rawlen;

    /* Test for undef or null string case and return 0 */
    if ( length == 0 ) {
        DEBUG && printf( "Recieved a null or undef string!\n" );
      return 0;
    }

    DEBUG && printf( "Received string '%.*s'.\n", (int)len, p );

    a = b = 0x9e3779b9;        /* golden ratio suggested by Jenkins */
    c = 0;
    while (len >= 12)
    {
        a += (p[0] + (((U32)p[1])<<8) + (((U32)p[2])<<16) +
              (((U32)p[3])<<24));
        b += (p[4] + (((U32)p[5])<<8) + (((U32)p[6])<<16) +
              (((U32)p[7])<<24));
        c += (p[8] + (((U32)p[9])<<8) + (((U32)p[10])<<16) +
              (((U32)p[11])<<24));
        MIX(a, b, c);
        p += 12;
        len -= 12;
    }
    c += length;
    switch(len) {
    case 11: c+=((U32)p[10]<<24);
    case 10: c+=((U32)p[9]<<16);
    case 9:  c+=((U32)p[8]<<8);
    case 8:  b+=((U32)p[7]<<24);
    case 7:  b+=((U32)p[6]<<16);
    case 6:  b+=((U32)p[5]<<8);
    case 5:  b+=((U32)p[4]);
    case 4:  a+=((U32)p[3]<<24);
    case 3:  a+=((U32)p[2]<<16);
    case 2:  a+=((U32)p[1]<<8);
    case 1:  a+=((U32)p[0]);
    }
    MIX(a, b, c);
    DEBUG && printf( "Hash value is %d.\n", (int)(c) );

    return(c);
}
void MixAudio16_SSE2_11(ALshort *dst, alMixEntry *entries)
{
	MixAudio16_SSE2_HEAD(11);
	MIX(1);
	MIX(2);
	MIX(3);
	MIX(4);
	MIX(5);
	MIX(6);
	MIX(7);
	MIX(8);
	MIX(9);
	MIX(10);
	MixAudio16_SSE2_TAIL(11);
}
Пример #8
0
CAMLprim value caml_bs_hash_string_and_small_int(value obj, value d){
  uint32 h = 0;
  h = caml_hash_mix_string(h,obj);
  MIX(h,d);
  FINAL_MIX(h);
  return Val_int(h & 0x3FFFFFFFU);
}
Пример #9
0
void arc_hash_update(arc_hs *s, unsigned long val)
{
  s->s[s->state] += val;
  s->state = (s->state + 1) % 3;
  if (s->state == 0)
    MIX(s->s[0], s->s[1], s->s[2]);
}
Пример #10
0
CAMLprim value caml_bs_hash_small_int(value d){
  uint32 h = 0; 
  // intnat stamp = Long_val(d); 
  // FIXME: unused value
  MIX(h,d);
  FINAL_MIX(h);
  return Val_int(h & 0x3FFFFFFFU);
}
Пример #11
0
unsigned int Triangle::getColor(const Point& d)
{
    double cd = LENGTH(points[0], d);
    double cb = LENGTH(points[0], points[2]);
    double ca = LENGTH(points[0], points[1]);

    double _cos = ((points[2].first - points[0].first) * (d.first - points[0].first) +
                   (points[2].second - points[0].second) * (d.second - points[0].second)) /
                   (cd * cb);
    double _sin;
    if(static_cast<int>(_cos) == 1)
    {
        _sin = 0;
    }
    else
    {
        _sin = ::sqrt(1 - _cos * _cos);
    }
    int x = cd * _cos + 0.5;
    int y = cd * _sin + 0.5;

    if(imagePoints[0].first > imagePoints[2].first)
    {
        x = imagePoints[0].first - x;
    }
    else
    {
        x = imagePoints[0].first + x;
    }

    if(imagePoints[0].second > imagePoints[1].second)
    {
        y = imagePoints[0].second - y;
    }
    else
    {
        y = imagePoints[0].second + y;
    }

    if(x >= image->width() || y >= image->height()) return 0x0;

    unsigned int rgb = image->pixel(x, y);

    if(blend)
    {
        int alpha = (rgb >> 24) & 0xff; 
        if(alpha != 0xff)
        {
            rgb = MIX(rgb, view->getColor(d.first, d.second), alpha / (float)0xff);
            transparentPixels++;
        }
    }

    return rgb;
}
Пример #12
0
/*
 * http://stackoverflow.com/questions/664014/what-integer-hash-function-are-good-that-accepts-an-integer-hash-key
 * https://en.wikipedia.org/wiki/MurmurHash
 * http://zimbry.blogspot.it/2011/09/better-bit-mixing-improving-on.html
 * http://eternallyconfuzzled.com/tuts/algorithms/jsw_tut_hashing.aspx
 * We gave up the idea to  hash Ident.t (take only one argument)
 * customized hash function for Ident.t, first 
 * argument is stamp, second argument is string 
 * It's not just introducing c stubs, we need make a clear line
 * which part of our libraries depends on Ident.t
 */
CAMLprim value caml_bs_hash_stamp_and_name(value d, value obj ){
  uint32 h = 0;
  intnat stamp = Long_val(d); 
  if (stamp){
    MIX(h,d);
  } else {
    h = caml_hash_mix_string(h,obj);
  }
  
  FINAL_MIX(h);
  return Val_int(h & 0x3FFFFFFFU);
}
Пример #13
0
/**
 * Shade the given color according to the illumination value.
 *
 * illum = 64: Contour, mixed with 50% brown
 * illum < 0:  Shadow, mixed with up to 50% dark blue
 * illum > 0:  Highlight, mixed with up to 25% yellow
 * illum = 0:  No shading
 */
gcc_const
inline BGRColor
TerrainShading(const int illum, RGB8Color color)
{
  if (illum == -64) {
    // brown color mixed in for contours
    return BGRColor(MIX(100, color.Red(), 64),
                    MIX(70, color.Green(), 64),
                    MIX(26, color.Blue(), 64));
  } else if (illum < 0) {
    // shadow to blue
    int x = std::min(63, -illum);
    return BGRColor(MIX(0, color.Red(), x),
                    MIX(0, color.Green(), x),
                    MIX(64, color.Blue(), x));
  } else if (illum > 0) {
    // highlight to yellow
    int x = std::min(32, illum / 2);
    return BGRColor(MIX(255, color.Red(), x),
                    MIX(255, color.Green(), x),
                    MIX(16, color.Blue(), x));
  } else
    return BGRColor(color.Red(), color.Green(), color.Blue());
}
Пример #14
0
inline void TerrainShading(const short illum, uint8_t &r, uint8_t &g, uint8_t &b) {
    char x;
    if (illum < 0) { // shadow to blue
        x = min((int) tshadow_h, -illum);
        r = MIX(tshadow_r, r, x);
        g = MIX(tshadow_g, g, x);
        b = MIX(tshadow_b, b, x);
    } else if (illum > 0) { // highlight to yellow
        if (thighlight_h == 255) return; // 101016
        x = min((int) thighlight_h, illum / 2);
        r = MIX(thighlight_r, r, x);
        g = MIX(thighlight_g, g, x);
        b = MIX(thighlight_b, b, x);
    }
}
Пример #15
0
unsigned ctnr_murmur32(BUFF_t buff, size_t size, unsigned seed)
{
	const unsigned int s = 0x5BD1E995;
	const  signed  int t = 0x00000018;

	/**/

	register const uint8_t *data = ctnr_cast(const uint8_t *, buff);

	unsigned h = seed ^ size;

	while(size >= 4)
	{
		uint32_t k = *ctnr_cast(uint32_t *, data);

		MIX(h, k);

		data += 4;
		size -= 4;
	}
	
	switch(size)
	{
		case 3:
			h ^= data[2] << 0x10;
		case 2:
			h ^= data[1] << 0x08;
		case 1:
			h ^= data[0] << 0x00;

			h *= s;
	}

	h ^= h >> 13;
	h *= s;
	h ^= h >> 15;

	return h;
}
Пример #16
0
inline void
TerrainShading(const short illum, BYTE &r, BYTE &g, BYTE &b)
{
  char x;
  if (illum < 0) {
    // shadow to blue
    x = min(63, -illum);
    r = MIX(0,r,x);
    g = MIX(0,g,x);
    b = MIX(64,b,x);
  } else if (illum > 0) {
    // highlight to yellow
    x = min(32, illum / 2);
    r = MIX(255,r,x);
    g = MIX(255,g,x);
    b = MIX(16,b,x);
  }
}
Пример #17
0
void aead_enc_block( 
	aead_params_t * params,
	aead_state_t * pre_state,
	aead_block_t * fin_stream,
	aead_block_t * fin_auth,
	uint32_t flags  ) {

	uint64_t m0 = 0LLU;
	uint64_t m1 = 0LLU;
	uint64_t m2 = 0LLU;
	uint64_t m3 = 0LLU;
	uint64_t m4 = 0LLU;
	uint64_t m5 = 0LLU;
	uint64_t m6 = 0LLU;
	uint64_t m7 = 0LLU;
	uint64_t t04 = 0LLU;
	uint64_t t26 = 0LLU;

#ifdef DEBUG
	printf( "\n\n\naead_enc_block; block = %llu\n", params->block0 );
#endif
	
	if ( ! ( FLG_PRE_CALC & flags ) ) {
	
		m0 = params->k0 ^ C0;
		m1 = params->k1 ^ C1;
		m2 = params->k2 ^ C2;
		m3 = params->k3 ^ C3;
		m4 = params->k0 ^ C4;
		m5 = params->k1 ^ C5;
		m6 = params->k2 ^ C6;
		m7 = params->k3 ^ C7;  	  
		
		// Mix in s0, s1
		PRINTSTATE( "Mix s0,s1,p0,p1" );
		MIX( m0, m1, m2, m3, m4, m5, m6, m7, params->s0, params->s1, params->p0, params->p1 );
		PRINTSTATE( "" );		
		PARTROUND3( m0, m1, m2, m3 );				
		PARTROUND3( m4, m5, m6, m7 );
		PRINTSTATE( "" );	
		
		// Mix halves (swap 0<->4 and 2<->6)
		t04 = m0; m0 = m4; m4 = t04;	
		t26 = m2; m2 = m6; m6 = t26;
		
		// Save pre-state for future use
		pre_state->r0 = m0;
		pre_state->r1 = m1;
		pre_state->r2 = m2;
		pre_state->r3 = m3;
		pre_state->r4 = m4;
		pre_state->r5 = m5;
		pre_state->r6 = m6;
		pre_state->r7 = m7;
	
	} else {
		
		m0 = pre_state->r0;
		m1 = pre_state->r1;
		m2 = pre_state->r2;
		m3 = pre_state->r3;
		m4 = pre_state->r4;
		m5 = pre_state->r5;
		m6 = pre_state->r6;
		m7 = pre_state->r7;
				
	}
	    
	// Mix in blocks and mode and len
	PRINTSTATE( "Mix block0, block1, len, mode" );
	MIX( m0, m1, m2, m3, m4, m5, m6, m7, params->block0, params->block1, params->len, params->mode_bits );		
	PRINTSTATE( "" );		
	PARTROUND3( m0, m1, m2, m3 );				
	PARTROUND3( m4, m5, m6, m7 );
	PRINTSTATE( "" );		
	
	// Mix halves (swap 0<->4 and 2<->6)
	t04 = m0; m0 = m4; m4 = t04;	
	t26 = m2; m2 = m6; m6 = t26;
		
	// Do final transform
	PRINTSTATE( "Final transform" );				
	PARTROUND( m0, m1, m2, m3 );				
	PARTROUND( m4, m5, m6, m7 );
	PRINTSTATE( "" );		

	// Mix halves (swap 0<->4 and 2<->6)
	t04 = m0; m0 = m4; m4 = t04;	
	t26 = m2; m2 = m6; m6 = t26;

	// Finalise
	PRINTSTATE( "XOR key" );
	m0 ^= params->k0;
	m1 ^= params->k1;
	m2 ^= params->k2;
	m3 ^= params->k3;
	m4 ^= params->k0;
	m5 ^= params->k1;
	m6 ^= params->k2;
	m7 ^= params->k3;
		
	PRINTSTATE( "Result" );

	fin_stream->r0 = m0;
	fin_stream->r1 = m1;
	fin_stream->r2 = m2;
	fin_stream->r3 = m3;
	fin_auth->r0 = m4;
	fin_auth->r1 = m5;
	fin_auth->r2 = m6;
	fin_auth->r3 = m7;

}
/*XLS function to process the non-full last block of plaintexts*/
void XLS(const u32 rk[], const u8 Lprime[], const u8 p[], unsigned long long int fb_ptlen, unsigned int nfb_ptlen, u8 c[], u8 tag[]){
    u8 mask1[16], mask2[16];
    u8 temp[16];
	// CHANGE VLA allocation changed to dynamic (for MSVC compiler)
	// u8 pt[16], ct[16], byte1[nfb_ptlen], byte2[nfb_ptlen];
	u8 pt[16], ct[16];
	u8* byte1 = new u8[nfb_ptlen];
	u8* byte2 = new u8[nfb_ptlen];
    int i;

    /*produce mask 3^2*Lprime, and save it to mask1[]*/
    memcpy(mask1, Lprime, 16);
    for(i=0; i<2; ++i){
        memcpy(temp, mask1, 16);
        double_mask(mask1);
        xor_byte_string(temp, mask1, 16);
    }

    /*produce mask 7^2*Lprime, and save it to mask2[]*/
    memcpy(mask2, Lprime, 16);
    for(i=0; i<2; ++i){
        memcpy(temp, mask2, 16);
        double_mask(mask2);
        xor_byte_string(mask2, temp, 16);
        double_mask(mask2);
        xor_byte_string(temp, mask2, 16);
    }

    /*produce the masks for E' and E'', and save them to mask1[] and mask2[] respectively*/
    while(fb_ptlen!=0){
        double_mask(mask1);
        double_mask(mask2);
        fb_ptlen-=16;
    }
    double_mask(mask1);
    double_mask(mask2);

    /*First round of XLS*/

    memcpy(pt, p, nfb_ptlen);
    memcpy(pt+nfb_ptlen, tag, 16-nfb_ptlen);

    /*apply E'*/
    xor_byte_string(mask1, pt, 16);
    aesEncrypt(rk, pt, ct);
    xor_byte_string(mask1, ct, 16);

    /*flip one bit*/
    ct[15-nfb_ptlen]^=0x01;

    memcpy(byte1, ct+16-nfb_ptlen, nfb_ptlen);
    memcpy(byte2, tag+16-nfb_ptlen, nfb_ptlen);

    /*MIX function*/
    MIX(byte1, byte2, nfb_ptlen);

    memcpy(ct+16-nfb_ptlen, byte1, nfb_ptlen);

    memcpy(pt, ct, 16);

    /*Second round of XLS*/

    /*apply E''*/
    xor_byte_string(mask2, pt, 16);
    aesEncrypt(rk, pt, ct);
    xor_byte_string(mask2, ct, 16);

    ct[15-nfb_ptlen]^=0x01;

    memcpy(byte1, ct+16-nfb_ptlen, nfb_ptlen);
    MIX(byte1, byte2, nfb_ptlen);

    memcpy(ct+16-nfb_ptlen, byte1, nfb_ptlen);
    memcpy(pt, ct, 16);

    /*the third round of XLS*/

    xor_byte_string(mask1, pt, 16);
    aesEncrypt(rk, pt, ct);
    xor_byte_string(mask1, ct, 16);

    /*produce ciphertext and tag*/
    memcpy(c, ct, nfb_ptlen);
    memcpy(tag, ct+nfb_ptlen, 16-nfb_ptlen);
    memcpy(tag+16-nfb_ptlen, byte2, nfb_ptlen);

	// CHANGE memory management (VLA allocation changed to dynamic)
	delete[] byte1;
	delete[] byte2;
}
/*inverse of XLS*/
void XLSInv(const u32 irk[], const u8 Lprime[], const u8 c[], unsigned long long fb_ctlen, unsigned int nfb_ctlen, u8 p[], u8 tag[]){
    u8 pt[16], ct[16];
    u8 temp[16];
    u8 mask1[16], mask2[16];
	// CHANGE VLA allocation changed to dynamic (for MSVC compiler)
	// u8 byte1[nfb_ctlen], byte2[nfb_ctlen];
	u8* byte1 = new u8[nfb_ctlen];
	u8* byte2 = new u8[nfb_ctlen];

    int i;

    /*produce mask 3^2*Lprime, and save it to mask1[]*/
    memcpy(mask1, Lprime, 16);
    for(i=0; i<2; ++i){
        memcpy(temp, mask1, 16);
        double_mask(mask1);
        xor_byte_string(temp, mask1, 16);
    }

    /*produce mask 7^2*Lprime, and save it to mask2[]*/
    memcpy(mask2, Lprime, 16);
    for(i=0; i<2; ++i){
        memcpy(temp, mask2, 16);
        double_mask(mask2);
        xor_byte_string(mask2, temp, 16);
        double_mask(mask2);
        xor_byte_string(temp, mask2, 16);
    }

    /*produce the masks for E' and E'', and save them to mask1[] and mask2[] respectively*/
    while(fb_ctlen!=0){
        double_mask(mask1);
        double_mask(mask2);
        fb_ctlen-=16;
    }
    double_mask(mask1);
    double_mask(mask2);

    memcpy(ct, c, nfb_ctlen);
    memcpy(ct+nfb_ctlen, tag, 16-nfb_ctlen);
    memcpy(byte2, tag+16-nfb_ctlen, nfb_ctlen);

    /*the first round */

    xor_byte_string(mask1, ct, 16);
    aesDecrypt(irk, ct, pt);
    xor_byte_string(mask1, pt, 16);

    pt[15-nfb_ctlen]^=0x01;
    memcpy(byte1, pt+16-nfb_ctlen, nfb_ctlen);
    MIX(byte1, byte2, nfb_ctlen);
    memcpy(pt+16-nfb_ctlen, byte1, nfb_ctlen);
    memcpy(ct, pt, 16);

    /*The second round*/

    xor_byte_string(mask2, ct, 16);
    aesDecrypt(irk, ct, pt);
    xor_byte_string(mask2, pt, 16);

    pt[15-nfb_ctlen]^=0x01;
    memcpy(byte1, pt+16-nfb_ctlen, nfb_ctlen);
    MIX(byte1, byte2, nfb_ctlen);

    memcpy(pt+16-nfb_ctlen, byte1, nfb_ctlen);
    memcpy(ct, pt, 16);

    /*the third round */

    xor_byte_string(mask1, ct, 16);
    aesDecrypt(irk, ct, pt);
    xor_byte_string(mask1, pt, 16);

    /*separate the output to plaintext and tag*/
    memcpy(p, pt, nfb_ctlen);
    memcpy(tag, pt+nfb_ctlen, 16-nfb_ctlen);
    memcpy(tag+16-nfb_ctlen, byte2, nfb_ctlen);

	// CHANGE memory management (VLA allocation changed to dynamic)
	delete[] byte1;
	delete[] byte2;
}
Пример #20
0
void mouse_idle(short type)
{
	if (mouse_active) {
    
  //DCW Not present on ios
/*#ifdef __APPLE__
		// In raw mode, get unaccelerated deltas from HID system
		if (input_preferences->raw_mouse_input)
			OSX_Mouse_GetMouseMovement(&snapshot_delta_x, &snapshot_delta_y);
#endif*/
		
    
		// Calculate axis deltas
		float dx = snapshot_delta_x;
		float dy = -snapshot_delta_y;
		snapshot_delta_x = 0;
		snapshot_delta_y = 0;
    
    slurpMouseDelta(&dx, &dy);
    if(dx>0 || dy>0)
    {
      snapshot_delta_x = 0;
      snapshot_delta_y = 0;
    }
    
		// Mouse inversion
		if (TEST_FLAG(input_preferences->modifiers, _inputmod_invert_mouse))
			dy = -dy;
		
		// scale input by sensitivity
		const float sensitivityScale = 1.f / (66.f * FIXED_ONE);
		float sx = sensitivityScale * input_preferences->sens_horizontal;
		float sy = sensitivityScale * input_preferences->sens_vertical;
		switch (input_preferences->mouse_accel_type)
		{
			case _mouse_accel_classic:
				sx *= MIX(1.f, fabs(dx * sx) * 4.f, input_preferences->mouse_accel_scale);
				sy *= MIX(1.f, fabs(dy * sy) * 4.f, input_preferences->mouse_accel_scale);
				break;
			case _mouse_accel_none:
			default:
				break;
		}
		dx *= sx;
		dy *= sy;
    
      //Add post-sensitivity lost precision, in case we can use it this time around.
    dx += lost_x;
    dy += lost_y;
    
		// 1 dx unit = 1 * 2^ABSOLUTE_YAW_BITS * (360 deg / 2^ANGULAR_BITS)
		//           = 90 deg
		//
		// 1 dy unit = 1 * 2^ABSOLUTE_PITCH_BITS * (360 deg / 2^ANGULAR_BITS)
		//           = 22.5 deg
		
		// Largest dx for which both -dx and +dx can be represented in 1 action flags bitset
		float dxLimit = 0.5f - 1.f / (1<<ABSOLUTE_YAW_BITS);  // 0.4921875 dx units (~44.30 deg)
		
		// Largest dy for which both -dy and +dy can be represented in 1 action flags bitset
		float dyLimit = 0.5f - 1.f / (1<<ABSOLUTE_PITCH_BITS);  // 0.46875 dy units (~10.55 deg)
		
		dxLimit = MIN(dxLimit, input_preferences->mouse_max_speed);
		dyLimit = MIN(dyLimit, input_preferences->mouse_max_speed);
		
		dx = PIN(dx, -dxLimit, dxLimit);
		dy = PIN(dy, -dyLimit, dyLimit);
		
		snapshot_delta_yaw   = static_cast<_fixed>(dx * FIXED_ONE);
		snapshot_delta_pitch = static_cast<_fixed>(dy * FIXED_ONE);
    
    //DCW what the f**k is the point of keeping the lower 9 or whatever bits in there? They just get thrown out later anyway...
    //Lets bitshift off the unused bits, so we can add in that lost precision the next time around.
    snapshot_delta_yaw >>= (FIXED_FRACTIONAL_BITS-ABSOLUTE_YAW_BITS);
    snapshot_delta_yaw <<= (FIXED_FRACTIONAL_BITS-ABSOLUTE_YAW_BITS);
    snapshot_delta_pitch >>= (FIXED_FRACTIONAL_BITS-ABSOLUTE_PITCH_BITS);
    snapshot_delta_pitch <<= (FIXED_FRACTIONAL_BITS-ABSOLUTE_PITCH_BITS);

    //DCW Lets track how much precision we lost, so we can stuff it back into the input next time this function is called.
    lost_x = (dx * (float)FIXED_ONE) - (float)snapshot_delta_yaw;
    lost_y = (dy * (float)FIXED_ONE) - (float)snapshot_delta_pitch;
    lost_x /= (float)FIXED_ONE;
    lost_y /= (float)FIXED_ONE;
    
    short game_state = get_game_state();
    smooth_mouselook = smoothMouselookPreference() ;//&& (game_state==_game_in_progress || game_state ==_switch_demo) && (game_state==_single_player || game_state==_network_player);

 	}
}
Пример #21
0
void MemMgr_GetWindowSizes (WINDOWSIZES *pSizes)
{
   RECT rClient;
   GetClientRect (l.hManager, &rClient);
   InflateRect (&rClient, 0-cBORDER, 0-cBORDER);

   pSizes->rLabelAverage.right = rClient.right -cxBETWEEN*2;
   pSizes->rLabelAverage.top = rClient.top +8 +cyBETWEEN;
   pSizes->rLabelAverage.left = pSizes->rLabelAverage.right -cxVALUES;
   pSizes->rLabelAverage.bottom = pSizes->rLabelAverage.top +cyLABELS;

   pSizes->rLabelSize = pSizes->rLabelAverage;
   pSizes->rLabelSize.left -= cxBETWEEN + cxVALUES;
   pSizes->rLabelSize.right -= cxBETWEEN + cxVALUES;

   pSizes->rLabelCount = pSizes->rLabelSize;
   pSizes->rLabelCount.left -= cxBETWEEN + cxVALUES;
   pSizes->rLabelCount.right -= cxBETWEEN + cxVALUES;

   pSizes->rLabelCpp.left = rClient.left +cxBETWEEN;
   pSizes->rLabelCpp.top = pSizes->rLabelCount.bottom +cyBETWEEN;
   pSizes->rLabelCpp.right = pSizes->rLabelCpp.left +cxLABELS;
   pSizes->rLabelCpp.bottom = pSizes->rLabelCpp.top +cyLABELS;

   pSizes->rLabelOther = pSizes->rLabelCpp;
   pSizes->rLabelOther.top += cyBETWEEN + cyLABELS;
   pSizes->rLabelOther.bottom += cyBETWEEN + cyLABELS;

   pSizes->rLabelTotal = pSizes->rLabelOther;
   pSizes->rLabelTotal.top += cyBETWEEN + cyLABELS;
   pSizes->rLabelTotal.bottom += cyBETWEEN + cyLABELS;

   pSizes->rLabelTared = pSizes->rLabelTotal;
   pSizes->rLabelTared.top += cyBETWEEN + cyLABELS;
   pSizes->rLabelTared.bottom += cyBETWEEN + cyLABELS;

   pSizes->rBoxAlloc = rClient;
   pSizes->rBoxAlloc.bottom = pSizes->rLabelTared.bottom +cyBETWEEN;

   MIX (&pSizes->rValueCppCount, &pSizes->rLabelCpp, &pSizes->rLabelCount);
   MIX (&pSizes->rValueOtherCount, &pSizes->rLabelOther, &pSizes->rLabelCount);
   MIX (&pSizes->rValueTaredCount, &pSizes->rLabelTared, &pSizes->rLabelCount);
   MIX (&pSizes->rValueTotalCount, &pSizes->rLabelTotal, &pSizes->rLabelCount);

   MIX (&pSizes->rValueCppSize, &pSizes->rLabelCpp, &pSizes->rLabelSize);
   MIX (&pSizes->rValueOtherSize, &pSizes->rLabelOther, &pSizes->rLabelSize);
   MIX (&pSizes->rValueTaredSize, &pSizes->rLabelTared, &pSizes->rLabelSize);
   MIX (&pSizes->rValueTotalSize, &pSizes->rLabelTotal, &pSizes->rLabelSize);

   MIX (&pSizes->rValueCppAverage, &pSizes->rLabelCpp, &pSizes->rLabelAverage);
   MIX (&pSizes->rValueOtherAverage, &pSizes->rLabelOther, &pSizes->rLabelAverage);
   MIX (&pSizes->rValueTaredAverage, &pSizes->rLabelTared, &pSizes->rLabelAverage);
   MIX (&pSizes->rValueTotalAverage, &pSizes->rLabelTotal, &pSizes->rLabelAverage);

   pSizes->rBoxDetails = rClient;
   pSizes->rBoxDetails.top = pSizes->rBoxAlloc.bottom +cyBETWEEN;
   pSizes->rBoxDetails.bottom -= cyBUTTONS +cyBETWEEN;

   pSizes->rList = pSizes->rBoxDetails;
   pSizes->rList.top += 8;
   InflateRect (&pSizes->rList, 0-cBORDER, 0-cBORDER);

   pSizes->rClose = rClient;
   pSizes->rClose.top = pSizes->rClose.bottom - cyBUTTONS;
   pSizes->rClose.left = pSizes->rClose.right - cxBUTTONS;

   pSizes->rReset = pSizes->rClose;
   pSizes->rReset.right = pSizes->rClose.left - cxBETWEEN;
   pSizes->rReset.left = pSizes->rReset.right - cxBUTTONS;

   pSizes->rTare = pSizes->rClose;
   pSizes->rTare.right = pSizes->rReset.left - cxBETWEEN;
   pSizes->rTare.left = pSizes->rTare.right - cxBUTTONS;

   pSizes->rLabel = pSizes->rTare;
   pSizes->rLabel.right = pSizes->rTare.left - cxBETWEEN;
   pSizes->rLabel.left = pSizes->rLabel.right - cxBUTTONS;

   pSizes->rHide = pSizes->rLabel;
   pSizes->rHide.right = pSizes->rLabel.left - cxBETWEEN;
   pSizes->rHide.left = pSizes->rHide.right - cxBUTTONS;
}
Пример #22
0
/* Encrypt one block */
static void 
rc2_Encrypt1Block(RC2Context *cx, RC2Block *output, RC2Block *input)
{
    register PRUint16 R0, R1, R2, R3;

    /* step 1. Initialize input. */
    R0 = input->s[0];
    R1 = input->s[1];
    R2 = input->s[2];
    R3 = input->s[3];

    /* step 2.  Expand Key (already done, in context) */
    /* step 3.  j = 0 */
    /* step 4.  Perform 5 mixing rounds. */

    MIX(0);
    MIX(1);
    MIX(2);
    MIX(3);
    MIX(4);

    /* step 5. Perform 1 mashing round. */
    MASH;

    /* step 6. Perform 6 mixing rounds. */

    MIX(5);
    MIX(6);
    MIX(7);
    MIX(8);
    MIX(9);
    MIX(10);

    /* step 7. Perform 1 mashing round. */
    MASH;

    /* step 8. Perform 5 mixing rounds. */

    MIX(11);
    MIX(12);
    MIX(13);
    MIX(14);
    MIX(15);

    /* output results */
    output->s[0] = R0;
    output->s[1] = R1;
    output->s[2] = R2;
    output->s[3] = R3;
}
Пример #23
0
// *oob: output argument, means we hit the limit specified by 'bound'
static uptrint_t bounded_hash(value_t a, int bound, int *oob)
{
    *oob = 0;
    union {
        double d;
        int64_t i64;
    } u;
    numerictype_t nt;
    size_t i, len;
    cvalue_t *cv;
    cprim_t *cp;
    void *data;
    uptrint_t h = 0;
    int oob2, tg = tag(a);
    switch(tg) {
    case TAG_NUM :
    case TAG_NUM1:
        u.d = (double)numval(a);
        return doublehash(u.i64);
    case TAG_FUNCTION:
        if (uintval(a) > N_BUILTINS)
            return bounded_hash(((function_t*)ptr(a))->bcode, bound, oob);
        return inthash(a);
    case TAG_SYM:
        return ((symbol_t*)ptr(a))->hash;
    case TAG_CPRIM:
        cp = (cprim_t*)ptr(a);
        data = cp_data(cp);
        if (cp_class(cp) == wchartype)
            return inthash(*(int32_t*)data);
        nt = cp_numtype(cp);
        u.d = conv_to_double(data, nt);
        return doublehash(u.i64);
    case TAG_CVALUE:
        cv = (cvalue_t*)ptr(a);
        data = cv_data(cv);
        return memhash(data, cv_len(cv));

    case TAG_VECTOR:
        if (bound <= 0) {
            *oob = 1;
            return 1;
        }
        len = vector_size(a);
        for(i=0; i < len; i++) {
            h = MIX(h, bounded_hash(vector_elt(a,i), bound/2, &oob2)^1);
            if (oob2)
                bound/=2;
            *oob = *oob || oob2;
        }
        return h;

    case TAG_CONS:
        do {
            if (bound <= 0) {
                *oob = 1;
                return h;
            }
            h = MIX(h, bounded_hash(car_(a), bound/2, &oob2));
            // bounds balancing: try to share the bounds efficiently
            // so we can hash better when a list is cdr-deep (a common case)
            if (oob2)
                bound/=2;
            else
                bound--;
            // recursive OOB propagation. otherwise this case is slow:
            // (hash '#2=((#0=(#1=(#1#) . #0#)) . #2#))
            *oob = *oob || oob2;
            a = cdr_(a);
        } while (iscons(a));
        h = MIX(h, bounded_hash(a, bound-1, &oob2)^2);
        *oob = *oob || oob2;
        return h;
    }
    return 0;
}
void MixAudio16_SSE2_21(ALshort *dst, alMixEntry *entries)
{
	MixAudio16_SSE2_HEAD(21);
	MIX(1);
	MIX(2);
	MIX(3);
	MIX(4);
	MIX(5);
	MIX(6);
	MIX(7);
	MIX(8);
	MIX(9);
	MIX(10);
	MIX(11);
	MIX(12);
	MIX(13);
	MIX(14);
	MIX(15);
	MIX(16);
	MIX(17);
	MIX(18);
	MIX(19);
	MIX(20);
	MixAudio16_SSE2_TAIL(21);
}
void MixAudio16_SSE2_32(ALshort *dst, alMixEntry *entries)
{
	MixAudio16_SSE2_HEAD(32);
	MIX(1);
	MIX(2);
	MIX(3);
	MIX(4);
	MIX(5);
	MIX(6);
	MIX(7);
	MIX(8);
	MIX(9);
	MIX(10);
	MIX(11);
	MIX(12);
	MIX(13);
	MIX(14);
	MIX(15);
	MIX(16);
	MIX(17);
	MIX(18);
	MIX(19);
	MIX(20);
	MIX(21);
	MIX(22);
	MIX(23);
	MIX(24);
	MIX(25);
	MIX(26);
	MIX(27);
	MIX(28);
	MIX(29);
	MIX(30);
	MIX(31);
	MixAudio16_SSE2_TAIL(32);
}
Пример #26
0
/* The meat of the producer code. This callback is called repeatedly during a burn.
	It's this function's job to write data into the passed in buffer each time it's 
	called.  It's best if you can fill up the buffer completely. The buffer is
	a multiple of the track's block size in length. */
OSStatus productionCallback(DRTrackRef track, DRTrackProductionInfo* prodInfo)
{
	unsigned long		expectedFrames = (prodInfo->reqCount / 4);
	unsigned long		readSize, readLen;
	char*				tempBuffer;
	char*				outBuffer = prodInfo->buffer;
	unsigned long		outLength;
	unsigned long		i;
	unsigned long		step;
	AIFFFileInfo*		info = (AIFFFileInfo*)DRGetRefCon(track);

	readSize = (info->sampleBytes * info->numChannels) * expectedFrames;
	step = info->sampleBytes*info->numChannels;

	if (readSize + info->cursor > info->dataEnd)
		readSize = info->dataEnd - info->cursor;

	tempBuffer = (char*)malloc(readSize);
	
	readLen = read(info->fd, tempBuffer, readSize);
	if (readSize != readLen) return kDRDataProductionErr;

	outLength = 0;
	for (i=0; i<readSize; i += step)
	{
		unsigned short			leftSample = 0, rightSample = 0;
		unsigned const char*	sampleFrame = tempBuffer + i;
		
		#define READ_SAMPLE_POINT(frame,index)		\
			((*(uint16_t*)(frame + info->sampleBytes*index)) & info->mask)
		#define MIX(a,b)							\
			(((a * 2) / 3) + ((b * 2) / 3))
		
		/* Handle our wonderful multichannel logic.  Yeah, it's almost certainly unnecessary,
		   but it took an extra 2 minutes to write it this way since I was already thinking
		   about how to parse the AIFF properly.  Maybe it'll make someone's world a better place. */
		if (info->numChannels == 2)
		{
			leftSample = READ_SAMPLE_POINT(sampleFrame,0);
			rightSample = READ_SAMPLE_POINT(sampleFrame,1);
		}
		else if (info->numChannels == 1)
		{
			leftSample = READ_SAMPLE_POINT(sampleFrame,0);
			rightSample = leftSample;
		}
		else if (info->numChannels == 3)
		{
			unsigned short	centerSample = READ_SAMPLE_POINT(sampleFrame,2);
			leftSample = MIX(READ_SAMPLE_POINT(sampleFrame,0),centerSample);
			rightSample = MIX(READ_SAMPLE_POINT(sampleFrame,1),centerSample);
		}
		else if (info->numChannels == 4)
		{
			/* The spec is unclear on how to distinguish quadrophonic vs 4 ch surround AIFFs, as
			   they both have four channels.  Since surround seems to be the winner of these
			   ancient audio wars, for now I'm going to assume 4 channels means surround.
			   unsigned short that it matters. */
			UInt16	centerSample = MIX(READ_SAMPLE_POINT(sampleFrame,1),READ_SAMPLE_POINT(sampleFrame,3));
			leftSample = MIX(READ_SAMPLE_POINT(sampleFrame,0),centerSample);
			rightSample = MIX(READ_SAMPLE_POINT(sampleFrame,2),centerSample);
		}
		else if (info->numChannels == 6)
		{
			unsigned short	centerSample = MIX(READ_SAMPLE_POINT(sampleFrame,2),READ_SAMPLE_POINT(sampleFrame,5));
			leftSample = MIX(MIX(READ_SAMPLE_POINT(sampleFrame,0),READ_SAMPLE_POINT(sampleFrame,1)),centerSample);
			rightSample = MIX(MIX(READ_SAMPLE_POINT(sampleFrame,3),READ_SAMPLE_POINT(sampleFrame,4)),centerSample);
		}
		else
			return kDRDataProductionErr;
			
		#undef READ_SAMPLE_POINT
		#undef MIX
		
		// Dump the samples into the output.
		((unsigned short*)outBuffer)[0] = ((leftSample & 0xFF00) >> 8) + ((leftSample & 0x00FF) << 8);
		((unsigned short*)outBuffer)[1] = ((rightSample & 0xFF00) >> 8) + ((rightSample & 0x00FF) << 8);
		outBuffer += 4;
		outLength += 4;
	}
	
	free(tempBuffer);
	
	info->cursor += outLength;
	prodInfo->actCount = outLength;
	return noErr;
}
Пример #27
0
int viterbi_stream_word_partitioned(DATA_STREAM* dstream, float* opt_res, int thrid)
{
//	if (NTHREADS > 1)		pthread_barrier_wait(&dstream->barrier);

	return 0;

	int L = dstream->L;
	P7_PROFILE* gm = dstream->gm;
	ESL_DSQ** ddsq = dstream->seqs;
	int M = gm->M, i, k, v, t, j;
	const int PARTITION = dstream->partition;
	__m128i** oprmsc = (__m128i**) dstream->rsc_msc;
	__m128i* xmxEv = dstream->xmxE;
	__m128i xmxB, xmxE, xmxC, moveC, Vinf = _mm_set1_epi16(-WORDMAX);

	__m128i dmx[PARTITION];
	__m128i mmx[PARTITION];
	__m128i imx[PARTITION];
	__m128i xmm[24];
	__m128i *mscore[8];
	__m128i overflowlimit, overflows;
	overflowlimit = overflows = Vinf;

	if (thrid == NTHREADS-1) 
	{	overflowlimit = _mm_set1_epi16(WORDMAX-1);
		overflows= _mm_xor_si128(overflows,overflows);	// zero out
	}

	t = ((dstream->Npartitions+thrid)%NTHREADS)*PARTITION;
	tprintf("START viterbiThr %d in %d L %d | Seq %d\n", thrid, t, L, 0); // ccount[thrid]++);

	xmxC  = Vinf;
	moveC = _mm_set1_epi16(discretize(dstream->scale, gm->xsc[p7P_C][p7P_MOVE]));
	xmxB  = _mm_set1_epi16(dstream->wordoffset + discretize(dstream->scale, gm->xsc[p7P_N][p7P_MOVE]));

	for (	; t < M; t += NTHREADS*PARTITION)
	{
		volatile uchar* synchflags1 = dstream->synchflags[t/PARTITION];
		volatile uchar* synchflags2 = dstream->synchflags[t/PARTITION+1];
		int t8 = t/8;

		for (k = 0; k < PARTITION; k++)
			dmx[k] = mmx[k] = imx[k] = Vinf;

		for (i = 1; i <= L; i++)
		{
		//	tprintf("Iter Thr %d t %d: I %d\n", thrid, t, i);
			__m128i sc, dcv, temp, mpv, ipv, dpv;
			__m128i *ttsc = dstream->tsc_all + t*8;
			v = i-1;
			ttsc += 3;

			if (t == 0)
				xmxE = mpv = dpv = ipv = sc = dcv = Vinf;
			else {
				if (NTHREADS > 1)
					 while (!synchflags1[v]) sched_yield();
				xmxE = xmxEv[v];
				dcv = dstream->pdcv[v];
				sc  = dstream->psc[v];
			}

			for (j = 0; j < 8; j++)
				mscore[j] = oprmsc[ddsq[j][i]] + t8;

			for (k = 0; k < PARTITION && t+k < M; )
			{
#if 0
#define EMLOAD(i)	xmm[i+24] = _mm_load_si128(mscore[i]); 
				EMLOAD(0) 	EMLOAD(1) 
				EMLOAD(2) 	EMLOAD(3) 
				EMLOAD(4) 	EMLOAD(5) 
				EMLOAD(6) 	EMLOAD(7) 

#define MIX16(i,r,range)	\
	xmm[r  ] = _mm_unpacklo_epi##range(xmm[24+i], xmm[24+i+1]);	\
	xmm[r+1] = _mm_unpackhi_epi##range(xmm[24+i], xmm[24+i+1]);
				MIX16(0,0,16)	MIX16(2,2,16)
				MIX16(4,4,16)	MIX16(6,6,16)
#else

#define MMLOAD(a,b)		\
	xmm[a] = _mm_unpacklo_epi16(*mscore[a], *mscore[b]);	\
	xmm[b] = _mm_unpackhi_epi16(*mscore[a], *mscore[b]);

				MMLOAD(0,1)	MMLOAD(2,3)
				MMLOAD(4,5)	MMLOAD(6,7)
#endif

#define MIX(i,r,range)	\
	xmm[r  ] = _mm_unpacklo_epi##range(xmm[i], xmm[i+2]);	\
	xmm[r+1] = _mm_unpackhi_epi##range(xmm[i], xmm[i+2]);

				MIX(0, 8,32)	MIX(1,12,32)
				MIX(4,10,32)	MIX(5,14,32)

				MIX( 8,16,64)	MIX( 9,18,64)
				MIX(12,20,64)	MIX(13,22,64)


#define TRIPLETCOMPUTE(k,j)	\
{	/* Calculate new M(k), delay store */	\
	sc = _mm_max_epi16(sc, _mm_adds_epi16(xmxB, *ttsc)); ttsc++;	\
	sc = _mm_adds_epi16(sc,  xmm[j]);		\
	/* Update E */							\
	xmxE = _mm_max_epi16(xmxE, sc);			\
	\
	/* Pre-emptive load of M, D, I */		\
	dpv = dmx[k];	\
	ipv = imx[k];	\
	mpv = mmx[k];	\
	\
	/* Calculate current I(k) */			\
	temp = _mm_adds_epi16(mpv, *ttsc); ttsc++;	\
	imx[k] = _mm_max_epi16(temp, _mm_adds_epi16(ipv, *ttsc)); ttsc++;\
	\
	/* Delayed stores of M and D */			\
	mmx[k] = sc;	\
	dmx[k] = dcv;	\
	\
	/* Calculate next D, D(k+1) */			\
	sc	= _mm_adds_epi16(sc, *ttsc); ttsc++;	\
	dcv = _mm_max_epi16(sc, _mm_adds_epi16(dcv, *ttsc));ttsc++;	\
	\
	/* Pre-emptive partial calculation of M(k+1) */	\
	sc = _mm_adds_epi16(mpv, *ttsc); ttsc++;	\
	sc = _mm_max_epi16(sc, _mm_adds_epi16(ipv, *ttsc)); ttsc++;	\
	sc = _mm_max_epi16(sc, _mm_adds_epi16(dpv, *ttsc)); ttsc++;	\
	k++;			\
}
				TRIPLETCOMPUTE(k,16+0)	TRIPLETCOMPUTE(k,16+1)
				TRIPLETCOMPUTE(k,16+2)	TRIPLETCOMPUTE(k,16+3)
				TRIPLETCOMPUTE(k,16+4)	TRIPLETCOMPUTE(k,16+5)
				TRIPLETCOMPUTE(k,16+6)	TRIPLETCOMPUTE(k,16+7)

				mscore[0]++; mscore[1]++; mscore[2]++; mscore[3]++;
				mscore[4]++; mscore[5]++; mscore[6]++; mscore[7]++;
			}

			if (t+k < M)
			{	v = i-1;
				xmxEv[v] = xmxE;
				dstream->pdcv[v] = dcv;
				dstream->psc [v] = sc;

				if (NTHREADS > 1) synchflags2[v] = 1;
			}
			else	// executed only by main thread (NTHRS-1)
			{
				__m128i overfs = _mm_cmpgt_epi16(xmxE, overflowlimit);
				overflows = _mm_or_si128(overflows, overfs);	// select the overflowed channels
				xmxC	= _mm_max_epi16(xmxC, xmxE);
			}
		}
	}

	xmxC = _mm_adds_epi16(xmxC, moveC);

	if (opt_res != NULL)
	{
		float offset = (float) dstream->wordoffset;
		int16_t res[8] __attribute__ ((aligned (16)));
		int16_t ovs[8] __attribute__ ((aligned (16)));

		memmove(res, &xmxC, sizeof(xmxC));
		memmove(ovs, &overflows, sizeof(overflows));

		for (i = 0; i < 8; i++)
			if (ovs[i])	opt_res[i] = eslINFINITY;	// signal overflow
			else		opt_res[i] = ((float) res[i] - offset) / dstream->scale - 2.0;
												// 2.0 nat approximation, UNILOCAL mode
	}

	tprintf("END viterbi Thr %d - t %d\n", thrid, t);
	return eslOK;
}
Пример #28
0
static void tonemap(TonemapContext *s, AVFrame *out, const AVFrame *in,
                    const AVPixFmtDescriptor *desc, int x, int y, double peak)
{
    const float *r_in = (const float *)(in->data[0] + x * desc->comp[0].step + y * in->linesize[0]);
    const float *b_in = (const float *)(in->data[1] + x * desc->comp[1].step + y * in->linesize[1]);
    const float *g_in = (const float *)(in->data[2] + x * desc->comp[2].step + y * in->linesize[2]);
    float *r_out = (float *)(out->data[0] + x * desc->comp[0].step + y * out->linesize[0]);
    float *b_out = (float *)(out->data[1] + x * desc->comp[1].step + y * out->linesize[1]);
    float *g_out = (float *)(out->data[2] + x * desc->comp[2].step + y * out->linesize[2]);
    float sig, sig_orig;

    /* load values */
    *r_out = *r_in;
    *b_out = *b_in;
    *g_out = *g_in;

    /* desaturate to prevent unnatural colors */
    if (s->desat > 0) {
        float luma = s->coeffs->cr * *r_in + s->coeffs->cg * *g_in + s->coeffs->cb * *b_in;
        float overbright = FFMAX(luma - s->desat, 1e-6) / FFMAX(luma, 1e-6);
        *r_out = MIX(*r_in, luma, overbright);
        *g_out = MIX(*g_in, luma, overbright);
        *b_out = MIX(*b_in, luma, overbright);
    }

    /* pick the brightest component, reducing the value range as necessary
     * to keep the entire signal in range and preventing discoloration due to
     * out-of-bounds clipping */
    sig = FFMAX(FFMAX3(*r_out, *g_out, *b_out), 1e-6);
    sig_orig = sig;

    switch(s->tonemap) {
    default:
    case TONEMAP_NONE:
        // do nothing
        break;
    case TONEMAP_LINEAR:
        sig = sig * s->param / peak;
        break;
    case TONEMAP_GAMMA:
        sig = sig > 0.05f ? pow(sig / peak, 1.0f / s->param)
                          : sig * pow(0.05f / peak, 1.0f / s->param) / 0.05f;
        break;
    case TONEMAP_CLIP:
        sig = av_clipf(sig * s->param, 0, 1.0f);
        break;
    case TONEMAP_HABLE:
        sig = hable(sig) / hable(peak);
        break;
    case TONEMAP_REINHARD:
        sig = sig / (sig + s->param) * (peak + s->param) / peak;
        break;
    case TONEMAP_MOBIUS:
        sig = mobius(sig, s->param, peak);
        break;
    }

    /* apply the computed scale factor to the color,
     * linearly to prevent discoloration */
    *r_out *= sig / sig_orig;
    *g_out *= sig / sig_orig;
    *b_out *= sig / sig_orig;
}