Esempio n. 1
0
void String::Fill(s_char c, int ct)
{
	MUTEX_LOCK(str_mutex);

#ifdef SCRATCH_NO_UTF8
	char* szBuffer = new char[ct + 1];
	memset(szBuffer, c, ct);
	szBuffer[ct] = '\0';
	CopyToBuffer(szBuffer);
	delete[] szBuffer;
#else
	size_t charSize = utf8codepointsize(c);
	char* szChar = new char[charSize];
	utf8catcodepoint(szChar, c, charSize);
	size_t size = ct * charSize;
	char* szBuffer = new char[size + 1];
	for (int i = 0; i < ct; i++) {
		memcpy(szBuffer + i * charSize, szChar, charSize);
	}
	delete[] szChar;
	szBuffer[size] = '\0';
	CopyToBuffer(szBuffer);
	delete[] szBuffer;
#endif
}
Esempio n. 2
0
// Function to capture an area of the screen immediately prior to sending
// an update.
void
vncDesktop::CaptureScreen(const rfb::Rect &rect, BYTE *scrBuff, UINT scrBuffSize)
{
	assert(rect.enclosed_by(m_bmrect));

	// Select the memory bitmap into the memory DC
	HBITMAP oldbitmap;
	if ((oldbitmap = (HBITMAP) SelectObject(m_hmemdc, m_membitmap)) == NULL)
		return;

	// Capture screen into bitmap
	BOOL blitok = BitBlt(m_hmemdc, rect.tl.x, rect.tl.y,
		(rect.br.x-rect.tl.x),
		(rect.br.y-rect.tl.y),
		m_hrootdc, rect.tl.x, rect.tl.y, SRCCOPY);

	// Select the old bitmap back into the memory DC
	SelectObject(m_hmemdc, oldbitmap);

	if (blitok) {
		// Copy the new data to the screen buffer (CopyToBuffer optimises this if possible)
		CopyToBuffer(rect, scrBuff, scrBuffSize);
	}

}
Esempio n. 3
0
Lin_StatusType Lin_GetStatus( uint8 Channel, uint8** Lin_SduPtr )
{
	volatile struct LINFLEX_tag * LINFLEXHw = LINFLEX(Channel);

	VALIDATE_W_RV( (LinDriverStatus != LIN_UNINIT), LIN_GETSTATUS_SERVICE_ID, LIN_E_UNINIT, LIN_NOT_OK);
	VALIDATE_W_RV( (LinChannelStatus[Channel] != LIN_CH_UNINIT), LIN_GETSTATUS_SERVICE_ID, LIN_E_CHANNEL_UNINIT, LIN_NOT_OK);
	VALIDATE_W_RV( (Channel < LIN_CONTROLLER_CNT), LIN_GETSTATUS_SERVICE_ID, LIN_E_INVALID_CHANNEL, LIN_NOT_OK);
	VALIDATE_W_RV( (Lin_SduPtr!=NULL), LIN_GETSTATUS_SERVICE_ID, LIN_E_INVALID_POINTER, LIN_NOT_OK);

	imask_t state;
    Irq_Save(state);
	Lin_StatusType res = LinChannelStatus[Channel];
	/* We can only check for valid sdu ptr when LIN_RX_OK */
	if(LinChannelStatus[Channel] == LIN_RX_OK || LinChannelStatus[Channel] == LIN_RX_ERROR){
		CopyToBuffer(LinBufRx[Channel], LINFLEXHw);
		*Lin_SduPtr = LinBufRx[Channel];
		if(LinChannelStatus[Channel] == LIN_RX_ERROR){
			ResyncDriver(Channel);
		}
		LinChannelStatus[Channel]=LIN_CH_OPERATIONAL;
	} else if(LinChannelStatus[Channel] == LIN_TX_OK || LinChannelStatus[Channel] == LIN_TX_ERROR){
		if(LinChannelStatus[Channel] == LIN_TX_ERROR){
			ResyncDriver(Channel);
		}
		LinChannelStatus[Channel]=LIN_CH_OPERATIONAL;
	}
    Irq_Restore(state);
	return res;
}
Esempio n. 4
0
// Add the mouse pointer to the buffer
void
vncDesktop::CaptureMouse(BYTE *scrBuff, UINT scrBuffSize)
{
	POINT CursorPos;
	ICONINFO IconInfo;

	// If the mouse cursor handle is invalid then forget it
	if (m_hcursor == NULL)
		return;

	// Get the cursor position
	if (!GetCursorPos(&CursorPos))
		return;

	// Translate position for hotspot
	if (GetIconInfo(m_hcursor, &IconInfo))
	{
		CursorPos.x -= ((int) IconInfo.xHotspot);
		CursorPos.y -= ((int) IconInfo.yHotspot);
		if (IconInfo.hbmMask != NULL)
			DeleteObject(IconInfo.hbmMask);
		if (IconInfo.hbmColor != NULL)
			DeleteObject(IconInfo.hbmColor);
	}

	// Select the memory bitmap into the memory DC
	HBITMAP oldbitmap;
	if ((oldbitmap = (HBITMAP) SelectObject(m_hmemdc, m_membitmap)) == NULL)
		return;

	// Draw the cursor
	DrawIconEx(
		m_hmemdc,									// handle to device context 
		CursorPos.x, CursorPos.y,
		m_hcursor,									// handle to icon to draw 
		0,0,										// width of the icon 
		0,											// index of frame in animated cursor 
		NULL,										// handle to background brush 
		DI_NORMAL | DI_COMPAT						// icon-drawing flags 
		);

	// Select the old bitmap back into the memory DC
	SelectObject(m_hmemdc, oldbitmap);

	// Save the bounding rectangle
	m_cursorpos.tl = CursorPos;
	m_cursorpos.br = rfb::Point(GetSystemMetrics(SM_CXCURSOR),
		GetSystemMetrics(SM_CYCURSOR)).translate(CursorPos);

	// Clip the bounding rect to the screen
	// Copy the mouse cursor into the screen buffer, if any of it is visible
	m_cursorpos = m_cursorpos.intersect(m_bmrect);
	if (!m_cursorpos.is_empty()) {
		CopyToBuffer(m_cursorpos, scrBuff, scrBuffSize);
	}
}
Esempio n. 5
0
void	CanvasRGB::SetHeight(int height)
{
	if (height != _height && height > 0)
	{
		char *data = 0;
		if (_width > 0 && height > 0)
		{
			data = new char[_width * height * 3];
			if (_height > 0)
				CopyToBuffer(data, _width, height, 0, 0);
		}
		_height = height;
		delete [] _data;
		_data = data;
	}
}
Esempio n. 6
0
void	CanvasRGB::SetWidth(int width)
{
	if (width != _width)
	{
		char *data = 0;
		if (width > 0 && _height > 0)
		{
			data = new char[width * _height * 3];
			if (_width > 0)
				CopyToBuffer(data, width, _height, 0, 0);
		}
		_width = width;
		delete [] _data;
		_data = data;
	}
}
Esempio n. 7
0
std::string RopePiece::ToString() const {
  if (string_ != nullptr) {
    return std::string(string_);
  }

  if (prefix_ == nullptr) {
    if (suffix_ == nullptr) {
      return std::string();
    }
    return suffix_->ToString();
  }

  if (suffix_ == nullptr) {
    return prefix_->ToString();
  }

  char* buffer = new char[length_ + 1];
  CopyToBuffer(buffer);
  std::string ret_val(buffer);
  delete [] buffer;
  return ret_val;
}
Esempio n. 8
0
STDMETHODIMP CDataCallback::BandedDataCallback(
    LONG   lReason,
    LONG   lStatus,
    LONG   lPercentComplete,
    LONG   lOffset,
    LONG   lLength,
    LONG, LONG,
    PBYTE  pbBuffer
)
{
    HRESULT hr;

    // Parse the message

    switch (lReason)
    {
        case IT_MSG_DATA_HEADER:
        {
            PWIA_DATA_CALLBACK_HEADER pHeader = (PWIA_DATA_CALLBACK_HEADER) pbBuffer;

            // Determine if this is a BMP transfer

            m_bBMP = pHeader->guidFormatID == WiaImgFmt_MEMORYBMP || pHeader->guidFormatID == WiaImgFmt_BMP;

            // For WiaImgFmt_MEMORYBMP transfers, WIA does not send a BITMAPFILEHEADER before the data.
            // In this program, we desire all BMP files to contain a BITMAPFILEHEADER, so add it manually

            m_nHeaderSize = pHeader->guidFormatID == WiaImgFmt_MEMORYBMP ? sizeof(BITMAPFILEHEADER) : 0;

            // Allocate memory for the image if the size is given in the header

            if (pHeader != NULL && pHeader->lBufferSize != 0)
            {
                hr = ReAllocBuffer(m_nHeaderSize + pHeader->lBufferSize);

                if (FAILED(hr))
                {
                    return hr;
                }
            }
        
            break;
        }

        case IT_MSG_DATA:
        {
            // Invoke the callback function

            hr = m_pfnProgressCallback(lStatus, lPercentComplete, m_pProgressCallbackParam);

            if (FAILED(hr) || hr == S_FALSE)
            {
                return hr;
            }

            // If the buffer is not allocated yet and this is the first block, 
            // and the transferred image is in BMP format, allocate the buffer
            // according to the size information in the bitmap header

            if (m_pStream == NULL && lOffset == 0 && m_bBMP)
            {
                LONG nBufferSize = BitmapUtil::GetBitmapSize(pbBuffer);

                if (nBufferSize != 0)
                {
                    hr = ReAllocBuffer(m_nHeaderSize + nBufferSize);

                    if (FAILED(hr))
                    {
                        return hr;
                    }
                }
            }

            if (m_nHeaderSize + lOffset + lLength < 0)
            {
                return E_OUTOFMEMORY;
            }

            // If the transfer goes past the buffer, try to expand it
            if (m_nHeaderSize + lOffset + lLength > m_nDataSize)
            {
                hr = ReAllocBuffer(m_nHeaderSize + lOffset + lLength);

                if (FAILED(hr))
                {
                    return hr;
                }
            }

            // copy the transfer buffer

            hr = CopyToBuffer(m_nHeaderSize + lOffset, pbBuffer, lLength);

            if (FAILED(hr))
            {
                return hr;
            }

            break;
        }

        case IT_MSG_STATUS:
        {
            // Invoke the callback function

            hr = m_pfnProgressCallback(lStatus, lPercentComplete, m_pProgressCallbackParam);

            if (FAILED(hr) || hr == S_FALSE)
            {
                return hr;
            }

            break;
        }

        case IT_MSG_TERMINATION:
        case IT_MSG_NEW_PAGE:
        {
            if (m_pStream != NULL)
            {
                // For BMP files, we should validate the the image header
                // So, obtain the memory buffer from the stream

                if (m_bBMP)
                {
                    // Since the stream is created using CreateStreamOnHGlobal,
                    // we can get the memory buffer with GetHGlobalFromStream.

                    HGLOBAL hBuffer;

                    hr = GetHGlobalFromStream(m_pStream, &hBuffer);

                    if (FAILED(hr))
                    {
                        return hr;
                    }

                    PBITMAPFILEHEADER pBuffer = (PBITMAPFILEHEADER) GlobalLock(hBuffer);

                    if (pBuffer == NULL)
                    {
                        return HRESULT_FROM_WIN32(GetLastError());
                    }

                    // Some scroll-fed scanners may return 0 as the bitmap height
                    // In this case, calculate the image height and modify the header

                    BitmapUtil::FixBitmapHeight(pBuffer + 1, m_nDataSize, TRUE);

                    // For WiaImgFmt_MEMORYBMP transfers, the WIA service does not 
                    // include a BITMAPFILEHEADER preceeding the bitmap data. 
                    // In this case, fill in the BITMAPFILEHEADER structure.
        
                    if (m_nHeaderSize != 0)
                    {
                        BitmapUtil::FillBitmapFileHeader(pBuffer + 1, pBuffer);
                    }

                    GlobalUnlock(hBuffer);
                }

                // Store this buffer in the successfully transferred images array

                hr = StoreBuffer();

                if (FAILED(hr))
                {
                    return hr;
                }
            }

            break;
        }
    }

    return S_OK;
}
/* as a result, updates the jello structure */
void RK4(cloth *clothItem)
{
	int index;
	point *F1p, *F1v,
		*F2p, *F2v,
		*F3p, *F3v,
		*F4p, *F4v;

	F1p = (point*)calloc(clothItem->cArrayLength, sizeof(point));
	F1v = (point*)calloc(clothItem->cArrayLength, sizeof(point));
	F2p = (point*)calloc(clothItem->cArrayLength, sizeof(point));
	F2v = (point*)calloc(clothItem->cArrayLength, sizeof(point));
	F3p = (point*)calloc(clothItem->cArrayLength, sizeof(point));
	F3v = (point*)calloc(clothItem->cArrayLength, sizeof(point));
	F4p = (point*)calloc(clothItem->cArrayLength, sizeof(point));
	F4v = (point*)calloc(clothItem->cArrayLength, sizeof(point));

	cloth *buffer = (cloth*)malloc(1 * sizeof(cloth));

	CopyToBuffer(buffer, clothItem);

	computeAcceleration(clothItem);

	for(int row = 0; row < clothItem->height; row++)
	{
		for(int col = 0; col < clothItem->width; col++)
		{
			index = FindIndexInArray(row, col, clothItem->width);
			
			// Pin Check
			if(gPin == PINNED)
			{
				if(index == 0 || index == clothItem->width-1)
				continue;
			}
			else if(gPin == UNPINLEFT)
			{
				if(index == clothItem->width-1)
				continue;
			}
			else if(gPin == UNPINRIGHT)
			{
				if(index == 0)
				continue;
			}

			pMULTIPLY(clothItem->velocities[index], clothItem->tStep, F1p[index]);
			pMULTIPLY(clothItem->acceleration[index], clothItem->tStep, F1v[index]);
			pMULTIPLY(F1p[index], 0.5, buffer->positions[index]);
			pMULTIPLY(F1v[index], 0.5, buffer->velocities[index]);
			pSUM(clothItem->positions[index], buffer->positions[index], buffer->positions[index]);
			pSUM(clothItem->velocities[index], buffer->velocities[index], buffer->velocities[index]);
		}
	}

	for(int  i= 0; i < clothItem->cArrayLength; i++)
	{
		pCPY(clothItem->acceleration[i], buffer->acceleration[i]); 
	}

	computeAcceleration(buffer);

	for(int row = 0; row < clothItem->height; row++)
	{
		for(int col = 0; col < clothItem->width; col++)
		{
			index = FindIndexInArray(row, col, clothItem->width);

			// Pin Check
			if(gPin == PINNED)
			{
				if(index == 0 || index == clothItem->width-1)
				continue;
			}
			else if(gPin == UNPINLEFT)
			{
				if(index == clothItem->width-1)
				continue;
			}
			else if(gPin == UNPINRIGHT)
			{
				if(index == 0)
				continue;
			}

			pMULTIPLY(buffer->velocities[index], clothItem->tStep, F2p[index]);
			pMULTIPLY(buffer->acceleration[index], clothItem->tStep, F2v[index]);
			pMULTIPLY(F2p[index], 0.5, buffer->positions[index]);
			pMULTIPLY(F2v[index], 0.5, buffer->velocities[index]);
			pSUM(clothItem->positions[index], buffer->positions[index], buffer->positions[index]);
			pSUM(clothItem->velocities[index], buffer->velocities[index], buffer->velocities[index]);
		}
	}

	computeAcceleration(buffer);

	for(int row = 0; row < clothItem->height; row++)
	{
		for(int col = 0; col < clothItem->width; col++)
		{
			index = FindIndexInArray(row, col, clothItem->width);

			// Pin Check
			if(gPin == PINNED)
			{
				if(index == 0 || index == clothItem->width-1)
				continue;
			}
			else if(gPin == UNPINLEFT)
			{
				if(index == clothItem->width-1)
				continue;
			}
			else if(gPin == UNPINRIGHT)
			{
				if(index == 0)
				continue;
			}

			pMULTIPLY(buffer->velocities[index], clothItem->tStep, F3p[index]);
			pMULTIPLY(buffer->acceleration[index], clothItem->tStep, F3v[index]);
			pMULTIPLY(F3p[index], 0.5, buffer->positions[index]);
			pMULTIPLY(F3v[index], 0.5, buffer->velocities[index]);
			pSUM(clothItem->positions[index], buffer->positions[index], buffer->positions[index]);
			pSUM(clothItem->velocities[index], buffer->velocities[index], buffer->velocities[index]);
		}
	}
         
	computeAcceleration(buffer);

	for(int row = 0; row < clothItem->height; row++)
	{
		for(int col = 0; col < clothItem->width; col++)
		{
			index = FindIndexInArray(row, col, clothItem->width);

			// Pin Check
			if(gPin == PINNED)
			{
				if(index == 0 || index == clothItem->width-1)
				continue;
			}
			else if(gPin == UNPINLEFT)
			{
				if(index == clothItem->width-1)
				continue;
			}
			else if(gPin == UNPINRIGHT)
			{
				if(index == 0)
				continue;
			}

			pMULTIPLY(buffer->velocities[index], clothItem->tStep, F4p[index]);
			pMULTIPLY(buffer->acceleration[index], clothItem->tStep, F4v[index]);
			pMULTIPLY(F2p[index], 2, buffer->positions[index]);
			pMULTIPLY(F3p[index], 2, buffer->velocities[index]);
			pSUM(buffer->positions[index], buffer->velocities[index], buffer->positions[index]);
			pSUM(buffer->positions[index], F1p[index], buffer->positions[index]);
			pSUM(buffer->positions[index], F4p[index], buffer->positions[index]); 
			pMULTIPLY(buffer->positions[index], 1.0 / 6, buffer->positions[index]);
			pSUM(buffer->positions[index], clothItem->positions[index], clothItem->positions[index]);
			 
			pMULTIPLY(F2v[index], 2, buffer->positions[index]);
			pMULTIPLY(F3v[index], 2, buffer->velocities[index]);
			pSUM(buffer->positions[index], buffer->velocities[index], buffer->positions[index]);
			pSUM(buffer->positions[index], F1v[index], buffer->positions[index]);
			pSUM(buffer->positions[index], F4v[index], buffer->positions[index]);
			pMULTIPLY(buffer->positions[index], 1.0 / 6, buffer->positions[index]);
			pSUM(buffer->positions[index], clothItem->velocities[index], clothItem->velocities[index]);
		}
	}

	for(int  i= 0; i < clothItem->cArrayLength; i++)
	{
		pCPY(buffer->acceleration[i], clothItem->acceleration[i]); 
	}

	for(int  i= 0; i < clothItem->cArrayLength; i++)
	{
		// Pin Check
		if(gPin == PINNED)
		{
			if(index == 0 || index == clothItem->width-1)
			continue;
		}
		else if(gPin == UNPINLEFT)
		{
			if(index == clothItem->width-1)
			continue;
		}
		else if(gPin == UNPINRIGHT)
		{
			if(index == 0)
			continue;
		}

		pMULTIPLY(clothItem->velocities[i], gDelta, underWaterDamp);
		pSUM(clothItem->velocities[i], underWaterDamp, clothItem->velocities[i]);
		pSUM(clothItem->force[i], gravity, clothItem->force[i]);
	}

	free(buffer);
  return;  
}