Пример #1
0
void HuffmanProcessor::WriteToFile()
{
    
    int counter = 0;
    std::vector<bool> code;
    for(int curr_byte = 0; curr_byte < size; ++curr_byte)
    {
        counter += 1;
        code = encoding[buffer[curr_byte]];
        if(curr_byte == size - 1)
        {
            // Write extra bits to fill out a byte if we're on the last byte of the file
            for(vector<bool>::iterator itr = code.begin(); itr != code.end(); ++itr)
            {
                WriteBit((*itr));
            }

            int remaining_space = 8 - numBits;
            for(int i = 0; i < remaining_space; ++i)
            {
                WriteBit(false);
            }
        } else {

            for(vector<bool>::iterator itr = code.begin(); itr != code.end(); ++itr)
            {
                WriteBit((*itr));
            }
        }
    }

}
Пример #2
0
WorldPacket const* WorldPackets::CombatLog::SpellHealLog::Write()
{
    *this << TargetGUID;
    *this << CasterGUID;
    *this << int32(SpellID);
    *this << int32(Health);
    *this << int32(OverHeal);
    *this << int32(Absorbed);
    WriteBit(Crit);
    WriteBit(CritRollMade.is_initialized());
    WriteBit(CritRollNeeded.is_initialized());
    WriteLogDataBit();
    WriteBit(SandboxScaling.is_initialized());
    FlushBits();

    if (CritRollMade)
        *this << *CritRollMade;

    if (CritRollNeeded)
        *this << *CritRollNeeded;

    WriteLogData();

    if (SandboxScaling)
        *this << *SandboxScaling;

    return &_worldPacket;
}
Пример #3
0
void CompressFile ( FILE *input, BFILE *output)
{
	int i;
	int c;
	int look_ahead_bytes;
	int current_pos;
	int replace_count;
	int match_len;
	int match_pos;
	
	current_pos = 1;
	
	for ( i = 0; i < LOOK_AHEAD_SIZE; i++)
	{
		if ( (c = getc (input)) == EOF )
			break;
		window [current_pos + i] = (uchar) c;
	}
	
	look_ahead_bytes = i;
	InitTree (current_pos);
	match_len = 0;
	match_pos = 0;
	
	while (look_ahead_bytes > 0)
	{
		if (match_len > look_ahead_bytes)
			match_len = look_ahead_bytes;
		if (match_len <= BREAK_EVEN)
		{
			replace_count = 1;
			WriteBit ( output, 1);
			WriteBits ( output, (ulong) window [current_pos], 8);
		}
		else
		{
			WriteBit  ( output, 0);
			WriteBits ( output, (ulong) match_pos, INDEX_BITS);
			WriteBits ( output, (ulong) ( match_len - (BREAK_EVEN + 1)),
				LENGTH_BITS);
			replace_count = match_len;
		}
		
		for ( i = 0; i < replace_count; i++)
		{
			DeleteString ( MODULO (current_pos + LOOK_AHEAD_SIZE));
			if ( (c = getc (input)) == EOF )
				look_ahead_bytes--;
			else
				window [MODULO (current_pos + LOOK_AHEAD_SIZE)] = (uchar) c;
			current_pos = MODULO (current_pos + 1);
			if (look_ahead_bytes)
				match_len = AddString ( current_pos, &match_pos);
		}
	}
	
	WriteBit  ( output, 0);
	WriteBits ( output, (ulong) END_OF_STREAM, INDEX_BITS);
}
Пример #4
0
void BitStream::Reverse()
{
    uint32 len = GetLength();
    std::vector<uint8> b = _data;
    Clear();

    for(uint32 i = len; i > 0; --i)
        WriteBit(b[i-1]);
}
Пример #5
0
void WriteBinaryByteToAudio(unsigned char inputByte)
// Take the passed byte, go through its bits, and pack the audio data into a file.
// Data is encoded most significant bit first.
{
	signed int
		i;
	
	for(i=7;i>-1;i--)
	{
		if(inputByte&(1<<i))
		{
			WriteBit(1);
		}
		else
		{
			WriteBit(0);
		}
	}
}
Пример #6
0
RVNET_DATATYPE RVnetSlaveProcess(uint8 *px_buf, RVNET_DATATYPE pkSize,
    uint8 device_address)
  {
    volatile uint8 *pxPack = px_buf;
    if (*pxPack == device_address)
      {
        if (CheckCRC(pxPack, pkSize))
          {
            pxPack++;
            switch (*pxPack)
              {
            case 0x00:
              pxPack++;
              pkSize = ReadDeviceID(pxPack);
              break;
            case 0x01:
            case 0x02:
              pxPack++;
              pkSize = ReadNBits(pxPack);
              break;
            case 0x03:
            case 0x04:
              pxPack++;
              pkSize = ReadNWords(pxPack);
              break;
            case 0x05:
              pxPack++;
              pkSize = WriteBit(pxPack);
              break;
            case 0x10:
              pxPack++;
              pkSize = WriteNWords(pxPack);
              break;
            default:
              pxPack++;
              pkSize = ErrorAddress(pxPack);
              break;

              }
          }
        else
          return 0;
      }
    else
      return 0;
    pkSize += 2; // Add heder
    SetCRC(px_buf, pkSize);
    pkSize += 2; // Add CRC
    return pkSize;
  }
Пример #7
0
WorldPacket const* WorldPackets::CombatLog::SpellPeriodicAuraLog::Write()
{
    *this << TargetGUID;
    *this << CasterGUID;
    *this << int32(SpellID);
    *this << uint32(Effects.size());

    for (SpellLogEffect const& effect : Effects)
    {
        *this << int32(effect.Effect);
        *this << int32(effect.Amount);
        *this << int32(effect.OverHealOrKill);
        *this << int32(effect.SchoolMaskOrPower);
        *this << int32(effect.AbsorbedOrAmplitude);
        *this << int32(effect.Resisted);
        WriteBit(effect.Crit);
        WriteBit(effect.DebugInfo.is_initialized());
        WriteBit(effect.SandboxScaling.is_initialized());
        FlushBits();

        if (effect.SandboxScaling)
            *this << *effect.SandboxScaling;

        if (effect.DebugInfo)
        {
            *this << float(effect.DebugInfo->CritRollMade);
            *this << float(effect.DebugInfo->CritRollNeeded);
        }

    }

    WriteLogDataBit();
    FlushBits();
    WriteLogData();

    return &_worldPacket;
}
Пример #8
0
WorldPacket const* WorldPackets::CombatLog::SpellNonMeleeDamageLog::Write()
{
    *this << Me;
    *this << CasterGUID;
    *this << CastID;
    *this << int32(SpellID);
    *this << int32(Damage);
    *this << int32(Overkill);
    *this << uint8(SchoolMask);
    *this << int32(ShieldBlock);
    *this << int32(Resisted);
    *this << int32(Absorbed);
    WriteBit(Periodic);
    WriteBits(Flags, 7);
    WriteBit(false); // Debug info
    WriteLogDataBit();
    WriteBit(SandboxScaling.is_initialized());
    FlushBits();
    WriteLogData();
    if (SandboxScaling)
        *this << *SandboxScaling;

    return &_worldPacket;
}
Пример #9
0
/** Set sleep mode status.
 * @param enabled New sleep mode enabled status
 * @see MPU6050_GetSleepModeStatus()
 * @see MPU6050_RA_PWR_MGMT_1
 * @see MPU6050_PWR1_SLEEP_BIT
 */
void clMPU6050::SetSleepModeStatus(FunctionalState NewState)
{
	WriteBit(MPU6050_DEFAULT_ADDRESS, MPU6050_RA_PWR_MGMT_1, MPU6050_PWR1_SLEEP_BIT, NewState);
}
Пример #10
0
/**
 * @par Implementation notes:
 */
bool
W1::_Searcher(uint8_t command, Address &address, Token &token)
{

    // Note: 1-based bit counting
    uint8_t  last_zero_path = 0;    // Last zero taken at a discrepancy
    uint8_t  current_bit    = 0;    // Current bit counter
    uint8_t  search_dir     = 0;    // 1 or 0 for next bit?
    uint8_t  bits;


    // Did we finish last time? Reset state for next call.
    if(token == 0xFF) {
        token = 0;
        return false;
    }

    // Always reset when beginning a new search
    if(!Reset()) {
        return false;
    }

    // Begin search
    WriteByte(command);


    // Scan down 64 bits of the ROM...
    while(++current_bit <= 64) {

        bits  = ReadBit();       // Next bit value
        bits |= ReadBit() << 1;  // Complement

        switch(bits) {
        case 0: // Discrepancy
            if(current_bit == token) {

                // We took the 0 path, now take the 1 path
                search_dir = 1;

            }else if(current_bit > token) {

                // New discrepancy... take the 0 path
                search_dir      = 0;
                last_zero_path  = current_bit;

            }else{

                // Old discrepancy... take the old path from the address
                if(GetBit(address, current_bit-1) == 0) {
                    search_dir      = 0;
                    last_zero_path  = current_bit;
                }else{
                    search_dir      = 1;
                }

            }
            break;

        case 1: // Only a 1
            search_dir = 1;
            break;

        case 2: // Only a 0
            search_dir = 0;
            break;

        case 3: // No devices!
            // Fallthrough
        default:
            return false;
        }
        SetBit(address, current_bit-1, search_dir);
        WriteBit(search_dir);
    }

    token = last_zero_path;

    // Check if we're done (no more 0 paths for which we still need to search the 1's path)
    if(token == 0) {
        token = 0xFF;
    }

    return true;
}
Пример #11
0
void BufferedWriter::WriteByte(unsigned char val) {
  for(size_t i = 0; i < kByteSize; i++) {
    bool bit = (val & (1 << i)) != 0;
    WriteBit(bit);
  }
}
Пример #12
0
static void CompressACSign(JPEGCompressor *self,int comp,unsigned int k,int absvalue,
const JPEGBlock *current,const JPEGBlock *north,const JPEGBlock *west,
const JPEGQuantizationTable *quantization)
{
	int sign=current->c[k]<0;

	// Calculate sign context, or compress with fixed probability.
	int predictedsign;
	if(IsFirstRowOrColumn(k))
	{
		int bdr=BDR(k,current,north,west,quantization);

		if(bdr==0)
		{
			WriteBit(&self->encoder,sign,0x800);
			return;
		}

		predictedsign=(bdr<0);
	}
	else if(k==4)
	{
		int sign1=Sign(north->c[k]);
		int sign2=Sign(west->c[k]);

		if(sign1+sign2==0)
		{
			WriteBit(&self->encoder,sign,0x800);
			return;
		}

		predictedsign=(sign1+sign2<0);
	}
	else if(IsSecondRow(k))
	{
		if(north->c[k]==0)
		{
			WriteBit(&self->encoder,sign,0x800);
			return;
		}

		predictedsign=(north->c[k]<0);
	}
	else if(IsSecondColumn(k))
	{
		if(west->c[k]==0)
		{
			WriteBit(&self->encoder,sign,0x800);
			return;
		}

		predictedsign=(west->c[k]<0);
	}
	else
	{
		WriteBit(&self->encoder,sign,0x800);
		return;
	}

	static const int n_for_k[64]={
		 0,
		 0, 1,
		 2, 3, 4,
		 5, 6, 7, 8,
		 9,10, 0,11,12,
		13,14, 0, 0,15,16,
		17,18, 0, 0, 0,19,20,
		21,22, 0, 0, 0, 0,23,24,
		25, 0, 0, 0, 0, 0,26,
		 0, 0, 0, 0, 0, 0,
		 0, 0, 0, 0, 0,
		 0, 0, 0, 0,
		 0, 0, 0,
		 0, 0,
		 0,
	};
	int n=n_for_k[k];

	int signcontext1=Min(Category(absvalue)/2,2);

	WriteDynamicBit(&self->encoder,sign,
	&self->acsignbins[comp][n][signcontext1][predictedsign],
	self->acsignshift);
}