/* * M A I N */ int main(int argc, char **argv) { unsigned char *inbuf; unsigned char *outbuf; int *rout, *gout, *bout; long int out_width; long int i; int eof_seen; if ( !get_args( argc, argv ) ) { (void)fputs(usage, stderr); bu_exit ( 1, NULL ); } /* autosize input? */ if ( fileinput && autosize ) { unsigned long int w, h; if ( fb_common_file_size(&w, &h, file_name, 3) ) { file_width = (long)w; } else { fprintf(stderr, "pixhalve: unable to autosize\n"); } } out_width = file_width/2; /* Allocate 1-scanline input & output buffers */ inbuf = malloc( 3*file_width+8 ); outbuf = malloc( 3*(out_width+2)+8 ); /* Allocate 5 integer arrays for each color */ /* each width+2 elements wide */ for ( i=0; i<5; i++ ) { rlines[i] = (int *)bu_calloc( (file_width+4)+1, sizeof(long), "rlines" ); glines[i] = (int *)bu_calloc( (file_width+4)+1, sizeof(long), "glines" ); blines[i] = (int *)bu_calloc( (file_width+4)+1, sizeof(long), "blines" ); } /* Allocate an integer array for each color, for output */ rout = (int *)bu_malloc( out_width * sizeof(long) + 8, "rout" ); gout = (int *)bu_malloc( out_width * sizeof(long) + 8, "gout" ); bout = (int *)bu_malloc( out_width * sizeof(long) + 8, "bout" ); /* * Prime the pumps with 5 lines of image. * Repeat the bottom most line three times to generate a "fill" * line on the bottom. This will have to be matched on the top. */ if ( fread( inbuf, 3, file_width, infp ) != file_width ) { perror(file_name); fprintf(stderr, "pixhalve: fread error\n"); bu_exit (1, NULL); } separate( &rlines[0][2], &glines[0][2], &blines[0][2], inbuf, file_width ); separate( &rlines[1][2], &glines[1][2], &blines[1][2], inbuf, file_width ); separate( &rlines[2][2], &glines[2][2], &blines[2][2], inbuf, file_width ); for ( i=3; i<5; i++ ) { if ( fread( inbuf, 3, file_width, infp ) != file_width ) { perror(file_name); fprintf(stderr, "pixhalve: fread error\n"); bu_exit (1, NULL); } separate( &rlines[i][2], &glines[i][2], &blines[i][2], inbuf, file_width ); } eof_seen = 0; for (;;) { filter3( rout, rlines, out_width ); filter5( gout, glines, out_width ); filter5( bout, blines, out_width ); combine( outbuf, rout, gout, bout, out_width ); if ( fwrite( (void*)outbuf, 3, out_width, stdout ) != out_width ) { perror("stdout"); bu_exit (2, NULL); } /* Ripple down two scanlines, and acquire two more */ if ( fread( inbuf, 3, file_width, infp ) != file_width ) { if ( eof_seen >= 2 ) break; /* EOF, repeat last line 2x for final output line */ eof_seen++; /* Fall through */ } ripple( rlines, 5 ); ripple( glines, 5 ); ripple( blines, 5 ); separate( &rlines[4][2], &glines[4][2], &blines[4][2], inbuf, file_width ); if ( fread( inbuf, 3, file_width, infp ) != file_width ) { if ( eof_seen >= 2 ) break; /* EOF, repeat last line 2x for final output line */ eof_seen++; /* Fall through */ } ripple( rlines, 5 ); ripple( glines, 5 ); ripple( blines, 5 ); separate( &rlines[4][2], &glines[4][2], &blines[4][2], inbuf, file_width ); } bu_free(rlines, "rlines"); bu_free(glines, "glines"); bu_free(blines, "blines"); bu_free(rout, "rout"); bu_free(gout, "gout"); bu_free(bout, "bout"); }
//========================================================= // HandleAnimEvent - catches the monster-specific messages // that occur when tagged animation frames are played. // // Returns number of events handled, 0 if none. //========================================================= void CNPC_AlienGrunt::HandleAnimEvent( animevent_t *pEvent ) { switch( pEvent->event ) { case AGRUNT_AE_HORNET1: case AGRUNT_AE_HORNET2: case AGRUNT_AE_HORNET3: case AGRUNT_AE_HORNET4: case AGRUNT_AE_HORNET5: { // m_vecEnemyLKP should be center of enemy body Vector vecArmPos; QAngle angArmDir; Vector vecDirToEnemy; QAngle angDir; if (HasCondition( COND_SEE_ENEMY) && GetEnemy()) { Vector vecEnemyLKP = GetEnemy()->GetAbsOrigin(); vecDirToEnemy = ( ( vecEnemyLKP ) - GetAbsOrigin() ); VectorAngles( vecDirToEnemy, angDir ); VectorNormalize( vecDirToEnemy ); } else { angDir = GetAbsAngles(); angDir.x = -angDir.x; Vector vForward; AngleVectors( angDir, &vForward ); vecDirToEnemy = vForward; } DoMuzzleFlash(); // make angles +-180 if (angDir.x > 180) { angDir.x = angDir.x - 360; } // SetBlending( 0, angDir.x ); GetAttachment( "0", vecArmPos, angArmDir ); vecArmPos = vecArmPos + vecDirToEnemy * 32; CPVSFilter filter( GetAbsOrigin() ); te->Sprite( filter, 0.0, &vecArmPos, iAgruntMuzzleFlash, random->RandomFloat( 0.4, 0.8 ), 128 ); CBaseEntity *pHornet = CBaseEntity::Create( "hornet", vecArmPos, QAngle( 0, 0, 0 ), this ); Vector vForward; AngleVectors( angDir, &vForward ); pHornet->SetAbsVelocity( vForward * 300 ); pHornet->SetOwnerEntity( this ); EmitSound( "Weapon_Hornetgun.Single" ); CHL1BaseNPC *pHornetMonster = (CHL1BaseNPC *)pHornet->MyNPCPointer(); if ( pHornetMonster ) { pHornetMonster->SetEnemy( GetEnemy() ); } } break; case AGRUNT_AE_LEFT_FOOT: // left foot { CPASAttenuationFilter filter2( this ); EmitSound( filter2, entindex(), "AlienGrunt.LeftFoot" ); } break; case AGRUNT_AE_RIGHT_FOOT: // right foot { CPASAttenuationFilter filter3( this ); EmitSound( filter3, entindex(), "AlienGrunt.RightFoot" ); } break; case AGRUNT_AE_LEFT_PUNCH: { Vector vecMins = GetHullMins(); Vector vecMaxs = GetHullMaxs(); vecMins.z = vecMins.x; vecMaxs.z = vecMaxs.x; CBaseEntity *pHurt = CheckTraceHullAttack( AGRUNT_MELEE_DIST, vecMins, vecMaxs, sk_agrunt_dmg_punch.GetFloat(), DMG_CLUB ); CPASAttenuationFilter filter4( this ); if ( pHurt ) { if ( pHurt->GetFlags() & ( FL_NPC | FL_CLIENT ) ) pHurt->ViewPunch( QAngle( -25, 8, 0) ); Vector vRight; AngleVectors( GetAbsAngles(), NULL, &vRight, NULL ); // OK to use gpGlobals without calling MakeVectors, cause CheckTraceHullAttack called it above. if ( pHurt->IsPlayer() ) { // this is a player. Knock him around. pHurt->SetAbsVelocity( pHurt->GetAbsVelocity() + vRight * 250 ); } EmitSound(filter4, entindex(), "AlienGrunt.AttackHit" ); Vector vecArmPos; QAngle angArmAng; GetAttachment( 0, vecArmPos, angArmAng ); SpawnBlood(vecArmPos, g_vecAttackDir, pHurt->BloodColor(), 25);// a little surface blood. } else { // Play a random attack miss sound EmitSound(filter4, entindex(), "AlienGrunt.AttackMiss" ); } } break; case AGRUNT_AE_RIGHT_PUNCH: { Vector vecMins = GetHullMins(); Vector vecMaxs = GetHullMaxs(); vecMins.z = vecMins.x; vecMaxs.z = vecMaxs.x; CBaseEntity *pHurt = CheckTraceHullAttack( AGRUNT_MELEE_DIST, vecMins, vecMaxs, sk_agrunt_dmg_punch.GetFloat(), DMG_CLUB ); CPASAttenuationFilter filter5( this ); if ( pHurt ) { if ( pHurt->GetFlags() & ( FL_NPC | FL_CLIENT ) ) pHurt->ViewPunch( QAngle( 25, 8, 0) ); // OK to use gpGlobals without calling MakeVectors, cause CheckTraceHullAttack called it above. if ( pHurt->IsPlayer() ) { // this is a player. Knock him around. Vector vRight; AngleVectors( GetAbsAngles(), NULL, &vRight, NULL ); pHurt->SetAbsVelocity( pHurt->GetAbsVelocity() + vRight * -250 ); } EmitSound( filter5, entindex(), "AlienGrunt.AttackHit" ); Vector vecArmPos; QAngle angArmAng; GetAttachment( 0, vecArmPos, angArmAng ); SpawnBlood(vecArmPos, g_vecAttackDir, pHurt->BloodColor(), 25);// a little surface blood. } else { // Play a random attack miss sound EmitSound( filter5, entindex(), "AlienGrunt.AttackMiss" ); } } break; default: BaseClass::HandleAnimEvent( pEvent ); break; } }
/****************************************************************************** * * Function : filter_bank * Purpose : Divide input signal into bands and calculate level of * the signal in each band * ******************************************************************************* */ static void filter_bank( VadVars *st, /* i/o : State struct */ float in[], /* i : input frame */ float level[] /* 0 : signal levels at each band */ ) { Word16 i; float tmp_buf[FRAME_LEN]; /* shift input 1 bit down for safe scaling */ for (i = 0; i < FRAME_LEN; i++) { tmp_buf[i] = in[i]/2.0f; } /* run the filter bank */ for (i = 0;i < FRAME_LEN/2; i++) { filter5(&tmp_buf[2*i],&tmp_buf[2*i+1],st->a_data5[0]); } for (i = 0;i < FRAME_LEN/4; i++) { filter5(&tmp_buf[4*i],&tmp_buf[4*i+2],st->a_data5[1]); filter5(&tmp_buf[4*i+1],&tmp_buf[4*i+3],st->a_data5[2]); } for (i = 0; i < FRAME_LEN/8; i++) { filter5(&tmp_buf[8*i], &tmp_buf[8*i+4], st->a_data5[3]); filter5(&tmp_buf[8*i+2], &tmp_buf[8*i+6], st->a_data5[4]); filter3(&tmp_buf[8*i+3],&tmp_buf[8*i+7],&st->a_data3[0]); } for (i = 0; i < FRAME_LEN/16; i++) { filter3(&tmp_buf[16*i+0], &tmp_buf[16*i+8], &st->a_data3[1]); filter3(&tmp_buf[16*i+4], &tmp_buf[16*i+12], &st->a_data3[2]); filter3(&tmp_buf[16*i+6], &tmp_buf[16*i+14], &st->a_data3[3]); } for (i = 0; i < FRAME_LEN/32; i++) { filter3(&tmp_buf[32*i+0], &tmp_buf[32*i+16], &st->a_data3[4]); filter3(&tmp_buf[32*i+8], &tmp_buf[32*i+24], &st->a_data3[5]); } /* calculate levels in each frequency band */ /* 4800 - 6400 Hz*/ level[11] = level_calculation(tmp_buf, &st->sub_level[11], FRAME_LEN/4-48, FRAME_LEN/4, 4, 1, 0.25); /* 4000 - 4800 Hz*/ level[10] = level_calculation(tmp_buf, &st->sub_level[10], FRAME_LEN/8-24, FRAME_LEN/8, 8, 7, 0.5); /* 3200 - 4000 Hz*/ level[9] = level_calculation(tmp_buf, &st->sub_level[9], FRAME_LEN/8-24, FRAME_LEN/8, 8, 3, 0.5); /* 2400 - 3200 Hz*/ level[8] = level_calculation(tmp_buf, &st->sub_level[8], FRAME_LEN/8-24, FRAME_LEN/8, 8, 2, 0.5); /* 2000 - 2400 Hz*/ level[7] = level_calculation(tmp_buf, &st->sub_level[7], FRAME_LEN/16-12, FRAME_LEN/16, 16, 14, 1.0); /* 1600 - 2000 Hz*/ level[6] = level_calculation(tmp_buf, &st->sub_level[6], FRAME_LEN/16-12, FRAME_LEN/16, 16, 6, 1.0); /* 1200 - 1600 Hz*/ level[5] = level_calculation(tmp_buf, &st->sub_level[5], FRAME_LEN/16-12, FRAME_LEN/16, 16, 4, 1.0); /* 800 - 1200 Hz*/ level[4] = level_calculation(tmp_buf, &st->sub_level[4], FRAME_LEN/16-12, FRAME_LEN/16, 16, 12, 1.0); /* 600 - 800 Hz*/ level[3] = level_calculation(tmp_buf, &st->sub_level[3], FRAME_LEN/32-6, FRAME_LEN/32, 32, 8, 2.0); /* 400 - 600 Hz*/ level[2] = level_calculation(tmp_buf, &st->sub_level[2], FRAME_LEN/32-6, FRAME_LEN/32, 32, 24, 2.0); /* 200 - 400 Hz*/ level[1] = level_calculation(tmp_buf, &st->sub_level[1], FRAME_LEN/32-6, FRAME_LEN/32, 32, 16, 2.0); /* 0 - 200 Hz*/ level[0] = level_calculation(tmp_buf, &st->sub_level[0], FRAME_LEN/32-6, FRAME_LEN/32, 32, 0, 2.0); }
/**************************************************************************** * * Function : filter_bank * Purpose : Divides input signal into 9-bands and calculas level of * the signal in each band * ***************************************************************************/ void filter_bank(vadState1 *st, /* i/o : State struct */ Word16 in[], /* i : input frame */ Word16 level[] /* 0 : signal levels at each band */ ) { Word16 i; Word16 tmp_buf[FRAME_LEN]; /* calculate the filter bank */ first_filter_stage(in, tmp_buf, st->a_data5[0]); for (i = 0; i < FRAME_LEN/4; i++) { filter5(&tmp_buf[4*i], &tmp_buf[4*i+2], st->a_data5[1]); filter5(&tmp_buf[4*i+1], &tmp_buf[4*i+3], st->a_data5[2]); } for (i = 0; i < FRAME_LEN/8; i++) { filter3(&tmp_buf[8*i+0], &tmp_buf[8*i+4], &st->a_data3[0]); filter3(&tmp_buf[8*i+2], &tmp_buf[8*i+6], &st->a_data3[1]); filter3(&tmp_buf[8*i+3], &tmp_buf[8*i+7], &st->a_data3[4]); } for (i = 0; i < FRAME_LEN/16; i++) { filter3(&tmp_buf[16*i+0], &tmp_buf[16*i+8], &st->a_data3[2]); filter3(&tmp_buf[16*i+4], &tmp_buf[16*i+12], &st->a_data3[3]); } /* calculate levels in each frequency band */ /* 3000 - 4000 Hz*/ level[8] = level_calculation(tmp_buf, &st->sub_level[8], FRAME_LEN/4-8, FRAME_LEN/4, 4, 1, 15); /* 2500 - 3000 Hz*/ level[7] = level_calculation(tmp_buf, &st->sub_level[7], FRAME_LEN/8-4, FRAME_LEN/8, 8, 7, 16); /* 2000 - 2500 Hz*/ level[6] = level_calculation(tmp_buf, &st->sub_level[6], FRAME_LEN/8-4, FRAME_LEN/8, 8, 3, 16); /* 1500 - 2000 Hz*/ level[5] = level_calculation(tmp_buf, &st->sub_level[5], FRAME_LEN/8-4, FRAME_LEN/8, 8, 2, 16); /* 1000 - 1500 Hz*/ level[4] = level_calculation(tmp_buf, &st->sub_level[4], FRAME_LEN/8-4, FRAME_LEN/8, 8, 6, 16); /* 750 - 1000 Hz*/ level[3] = level_calculation(tmp_buf, &st->sub_level[3], FRAME_LEN/16-2, FRAME_LEN/16, 16, 4, 16); /* 500 - 750 Hz*/ level[2] = level_calculation(tmp_buf, &st->sub_level[2], FRAME_LEN/16-2, FRAME_LEN/16, 16, 12, 16); /* 250 - 500 Hz*/ level[1] = level_calculation(tmp_buf, &st->sub_level[1], FRAME_LEN/16-2, FRAME_LEN/16, 16, 8, 16); /* 0 - 250 Hz*/ level[0] = level_calculation(tmp_buf, &st->sub_level[0], FRAME_LEN/16-2, FRAME_LEN/16, 16, 0, 16); }