Ejemplo n.º 1
0
 void PngReader::ReadFromMemory(const std::string& buffer)
 {
   if (buffer.size() != 0)
   {
     ReadFromMemory(&buffer[0], buffer.size());
   }
   else
   {
     ReadFromMemory(NULL, 0);
   }
 }
Ejemplo n.º 2
0
size_t Word::ReadFromFile(std::fstream &file)
{
  const size_t memAlloc = sizeof(UINT64) + sizeof(char);
  char mem[sizeof(UINT64) + sizeof(char)];
  file.read(mem, memAlloc);

  size_t memUsed = ReadFromMemory(mem);
  CHECK(memAlloc == memUsed);

  return memAlloc;
}
Ejemplo n.º 3
0
size_t Word::ReadFromFile(std::fstream &file, size_t numFactors)
{
	size_t memAlloc = numFactors * sizeof(UINT64) + sizeof(char);
	char *mem = (char*) malloc(memAlloc);
	file.read(mem, memAlloc);
	
	size_t memUsed = ReadFromMemory(mem, numFactors);
	assert(memAlloc == memUsed);
	free(mem);
	
	return memUsed;
}
Ejemplo n.º 4
0
size_t Word::ReadFromFile(std::fstream &file)
{
  size_t memAlloc = sizeof(UINT64) + sizeof(char);
  char *mem = (char*) malloc(memAlloc);
  file.read(mem, memAlloc);

  size_t memUsed = ReadFromMemory(mem);
  CHECK(memAlloc == memUsed);
  free(mem);

  return memUsed;
}
Ejemplo n.º 5
0
// Get the size of an image if a memoryshare sender is running
bool spoutMemoryShare::GetImageSizeFromSharedMemory(unsigned int &width, unsigned int &height)
{
		BITMAPINFOHEADER bmih;
		BITMAPINFOHEADER * pbmih;
		pbmih = (BITMAPINFOHEADER *)&bmih; // pointer to a bitmap info header
	
		pbmih->biWidth = 0;
		pbmih->biHeight = 0;

		// int i = sizeof(BITMAPINFOHEADER);

		if(ReadFromMemory((unsigned char *)pbmih, sizeof(BITMAPINFOHEADER))) {
			if(pbmih->biWidth > 0 && pbmih->biHeight > 0) {
				// if(width == 0 && height == 0) {
					width  = pbmih->biWidth;
					height = pbmih->biHeight;
				// }
				return true;
			}
		}
		return false;
}
Ejemplo n.º 6
0
/**
  Write data to a FileDescriptor. On success number of bytes written is returned. Zero indicates
  nothing was written. On error -1 is returned.

  @param  FileDescriptor   Device to talk to.
  @param  Buffer           Buffer to hold Count bytes that are to be written
  @param  Count            Number of bytes to transfer.

  @retval -1               Error
  @retval {other}          Number of bytes written.

**/
INTN
GdbWrite (
  IN  INTN          FileDescriptor,
  OUT CONST VOID    *Buffer,
  IN  UINTN         Count
  )
{
  CHAR8   Packet[128];
  UINTN   Size;
  INTN    RetCode;
  UINTN   ErrNo;
  BOOLEAN ReceiveDone = FALSE;

  // Send:
  // #Fwrite,XX,YYYYYYYY,XX$SS
  //
  // XX - FileDescriptor in ASCII
  // YYYYYYYY - Buffer address in ASCII
  // XX - Count in ASCII
  // SS - check sum
  //
  Size = AsciiSPrint (Packet, sizeof (Packet), "Fwrite,%x,%x,%x", FileDescriptor, Buffer, Count);
  // Packet array is too small if you got this ASSERT
  ASSERT (Size < sizeof (Packet));

  SendPacket (Packet);
  Print ((CHAR16 *)L"Packet sent..\n");

  do {
    // Reply:
    ReceivePacket (Packet, sizeof (Packet));
    Print ((CHAR16 *)L"Command received..%c\n", Packet[0]);

    // Process GDB commands
    switch (Packet[0]) {
      //Read memory command.
      //m addr,length.
      case    'm':
        ReadFromMemory (Packet);
        break;

      //Fretcode, errno, Ctrl-C flag
      //retcode - Count read
      case    'F':
        //Once target receives F reply packet that means the previous
        //transactions are finished.
        ReceiveDone = TRUE;
        break;

      //Send empty buffer
      default    :
        SendNotSupported();
        break;
    }
  } while (ReceiveDone == FALSE);

  RetCode = GdbParseFReplyPacket (Packet, &ErrNo);
  Print ((CHAR16 *)L"RetCode: %x..ErrNo: %x..\n", RetCode, ErrNo);

  //Send error to the host if there is any.
  if (ErrNo > 0) {
    SendError((UINT8)ErrNo);
  }

  return RetCode;
}