Пример #1
0
bool Bitmap::bitIsOn(int bitPos)
{
   int bytePos = getBytePos(bitPos);
   char c = bitmap[bytePos];
   bitPos = std::abs((bytePos*8) - bitPos);
   return (c  & (1 << bitPos)) != 0;
}
Пример #2
0
	uint8 Matrix::as_uint8At(uint16 row, uint16 column) const
	{
		//return the uint8 at the requested position
		return m_data.read_uint8(getBytePos(row, column));
	}
Пример #3
0
	float Matrix::as_floatAt(uint16 row, uint16 column) const
	{
		//return the float at the requested position
		return m_data.read_float(getBytePos(row, column));
	}
Пример #4
0
void Bitmap::turnOffBit(int bitPos)
{
   int bytePos = getBytePos(bitPos);
   bitPos = std::abs((bytePos*8) - bitPos);
   bitmap[bytePos] &= ~(1<<bitPos);
}
Пример #5
0
void Bitmap::toggleBit(int bitPos)
{
   int bytePos = getBytePos(bitPos);
   bitPos = std::abs((bytePos*8) - bitPos);
   bitmap[bytePos] ^= (1<< bitPos);
}
Пример #6
0
bool DTSC::File::seek_time(unsigned int ms, unsigned int trackNo, bool forceSeek) {
  seekPos tmpPos;
  tmpPos.trackID = trackNo;
  if (!forceSeek && myPack && ms >= myPack.getTime() && trackNo >= myPack.getTrackId()) {
    tmpPos.seekTime = myPack.getTime();
    tmpPos.bytePos = getBytePos();
  } else {
    tmpPos.seekTime = 0;
    tmpPos.bytePos = 0;
  }
  if (reachedEOF()) {
    clearerr(F);
    seek_bpos(0);
    tmpPos.bytePos = 0;
    tmpPos.seekTime = 0;
  }
  DTSC::Track & trackRef = metadata.tracks[trackNo];
  for (unsigned int i = 0; i < trackRef.keys.size(); i++) {
    long keyTime = trackRef.keys[i].getTime();
    if (keyTime > ms) {
      break;
    }
    if ((long long unsigned int)keyTime > tmpPos.seekTime) {
      tmpPos.seekTime = keyTime;
      tmpPos.bytePos = trackRef.keys[i].getBpos();
    }
  }
  bool foundPacket = false;
  while (!foundPacket) {
    lastreadpos = ftell(F);
    if (reachedEOF()) {
      DEBUG_MSG(DLVL_WARN, "Reached EOF during seek to %u in track %d - aborting @ %lld", ms, trackNo, lastreadpos);
      return false;
    }
    //Seek to first packet after ms.
    seek_bpos(tmpPos.bytePos);
    //read the header
    char header[20];
    if (fread((void *)header, 20, 1, F) != 1){
      DEBUG_MSG(DLVL_WARN, "Could not read header from file. Much sadface.");
      return false;
    }
    //check if packetID matches, if not, skip size + 8 bytes.
    int packSize = ntohl(((int *)header)[1]);
    unsigned int packID = ntohl(((int *)header)[2]);
    if (memcmp(header, Magic_Packet2, 4) != 0 || packID != trackNo) {
      if (memcmp(header, "DT", 2) != 0) {
        DEBUG_MSG(DLVL_WARN, "Invalid header during seek to %u in track %d @ %lld - resetting bytePos from %lld to zero", ms, trackNo, lastreadpos, tmpPos.bytePos);
        tmpPos.bytePos = 0;
        continue;
      }
      tmpPos.bytePos += 8 + packSize;
      continue;
    }
    //get timestamp of packet, if too large, break, if not, skip size bytes.
    long long unsigned int myTime = ((long long unsigned int)ntohl(((int *)header)[3]) << 32);
    myTime += ntohl(((int *)header)[4]);
    tmpPos.seekTime = myTime;
    if (myTime >= ms) {
      foundPacket = true;
    } else {
      tmpPos.bytePos += 8 + packSize;
      continue;
    }
  }
  //DEBUG_MSG(DLVL_HIGH, "Seek to %u:%d resulted in %lli", trackNo, ms, tmpPos.seekTime);
  if (tmpPos.seekTime > 0xffffffffffffff00ll){
    tmpPos.seekTime = 0;
  }
  currentPositions.insert(tmpPos);
  return true;
}
Пример #7
0
/// Reads the packet available at the current file position.
/// If the packet could not be read for any reason, the reason is printed.
/// Reading the packet means the file position is increased to the next packet.
void DTSC::File::seekNext() {
  if (!currentPositions.size()) {
    DEBUG_MSG(DLVL_WARN, "No seek positions set - returning empty packet.");
    myPack.null();
    return;
  }
  seekPos thisPos = *currentPositions.begin();
  fseek(F, thisPos.bytePos, SEEK_SET);
  if (reachedEOF()) {
    myPack.null();
    return;
  }
  clearerr(F);
  currentPositions.erase(currentPositions.begin());
  lastreadpos = ftell(F);
  if (fread(buffer, 4, 1, F) != 1) {
    if (feof(F)) {
      DEBUG_MSG(DLVL_DEVEL, "End of file reached while seeking @ %i", (int)lastreadpos);
    } else {
      DEBUG_MSG(DLVL_ERROR, "Could not seek to next @ %i", (int)lastreadpos);
    }
    myPack.null();
    return;
  }
  if (memcmp(buffer, DTSC::Magic_Header, 4) == 0) {
    seek_time(myPack.getTime(), myPack.getTrackId(), true);
    return seekNext();
  }
  long long unsigned int version = 0;
  if (memcmp(buffer, DTSC::Magic_Packet, 4) == 0) {
    version = 1;
  }
  if (memcmp(buffer, DTSC::Magic_Packet2, 4) == 0) {
    version = 2;
  }
  if (version == 0) {
    DEBUG_MSG(DLVL_ERROR, "Invalid packet header @ %#x - %.4s != %.4s @ %d", (unsigned int)lastreadpos, (char *)buffer, DTSC::Magic_Packet2, (int)lastreadpos);
    myPack.null();
    return;
  }
  if (fread(buffer, 4, 1, F) != 1) {
    DEBUG_MSG(DLVL_ERROR, "Could not read packet size @ %d", (int)lastreadpos);
    myPack.null();
    return;
  }
  long packSize = ntohl(((unsigned long *)buffer)[0]);
  char * packBuffer = (char *)malloc(packSize + 8);
  if (version == 1) {
    memcpy(packBuffer, "DTPD", 4);
  } else {
    memcpy(packBuffer, "DTP2", 4);
  }
  memcpy(packBuffer + 4, buffer, 4);
  if (fread((void *)(packBuffer + 8), packSize, 1, F) != 1) {
    DEBUG_MSG(DLVL_ERROR, "Could not read packet @ %d", (int)lastreadpos);
    myPack.null();
    free(packBuffer);
    return;
  }
  myPack.reInit(packBuffer, packSize + 8);
  free(packBuffer);
  if (metadata.merged) {
    int tempLoc = getBytePos();
    char newHeader[20];
    bool insert = false;
    seekPos tmpPos;
    if (fread((void *)newHeader, 20, 1, F) == 1) {
      if (memcmp(newHeader, DTSC::Magic_Packet2, 4) == 0) {
        tmpPos.bytePos = tempLoc;
        tmpPos.trackID = ntohl(((int *)newHeader)[2]);
        tmpPos.seekTime = 0;
        if (selectedTracks.find(tmpPos.trackID) != selectedTracks.end()) {
          tmpPos.seekTime = ((long long unsigned int)ntohl(((int *)newHeader)[3])) << 32;
          tmpPos.seekTime += ntohl(((int *)newHeader)[4]);
          insert = true;
        } else {
          long tid = myPack.getTrackId();
          for (unsigned int i = 0; i != metadata.tracks[tid].keys.size(); i++) {
            if ((unsigned long long)metadata.tracks[tid].keys[i].getTime() > myPack.getTime()) {
              tmpPos.seekTime = metadata.tracks[tid].keys[i].getTime();
              tmpPos.bytePos = metadata.tracks[tid].keys[i].getBpos();
              tmpPos.trackID = tid;
              insert = true;
              break;
            }
          }
        }
        if (currentPositions.size()) {
          for (std::set<seekPos>::iterator curPosIter = currentPositions.begin(); curPosIter != currentPositions.end(); curPosIter++) {
            if ((*curPosIter).trackID == tmpPos.trackID && (*curPosIter).seekTime >= tmpPos.seekTime) {
              insert = false;
              break;
            }
          }
        }
      }
    }
    if (insert){
      if (tmpPos.seekTime > 0xffffffffffffff00ll){
        tmpPos.seekTime = 0;
      }
      currentPositions.insert(tmpPos);
    } else {
      seek_time(myPack.getTime(), myPack.getTrackId(), true);
    }
    seek_bpos(tempLoc);
  }else{
    seek_time(thisPos.seekTime, thisPos.trackID);
    fseek(F, thisPos.bytePos, SEEK_SET);
  }
}