Пример #1
0
void FunctionVessel::resize(){
  if( getAction()->derivativesAreRequired() ){
     unsigned nderivatives=getAction()->getNumberOfDerivatives();
     getFinalValue()->resizeDerivatives( nderivatives );
     resizeBuffer( (1+nderivatives)*2 ); 
     diffweight=getAction()->weightHasDerivatives;
  } else {
     resizeBuffer(2);
     diffweight=false;  // Don't need to worry about differentiable weights if no derivatives
  }
}
Пример #2
0
void GradientVessel::resize(){
  if( getAction()->derivativesAreRequired() ){
     unsigned nder=getAction()->getNumberOfDerivatives();
     resizeBuffer( (1+nder)*(ncomponents+1)*nweights );
     setNumberOfDerivatives( nder );
     val_interm.resize( ncomponents*nweights );
     der_interm.resize( ncomponents*nweights, nder );
  } else {
     setNumberOfDerivatives(0); 
     resizeBuffer( (ncomponents+1)*nweights );
     val_interm.resize( ncomponents*nweights );
  }
}
Пример #3
0
void AudioIO::framesPerBuffer(int n) {
    if(mImpl->mIsOpen) {
        warn("the number of frames/buffer cannnot be set with the stream open", "AudioIO");
        return;
    }

    if(framesPerBuffer() != n) {
        mFramesPerBuffer = n;
        resizeBuffer(true);
        resizeBuffer(false);
        channelsBus(AudioIOData::channelsBus());
        resize(mBufT, mFramesPerBuffer);
    }
}
Пример #4
0
bool CursorShape::setProperties(const Dimension *newDim,
                                const PixelFormat *pixelFormat)
{
  bool result = m_pixels.setDimension(newDim) &&
                m_pixels.setPixelFormat(pixelFormat);
  return result && resizeBuffer();
}
Пример #5
0
BridgeVessel::BridgeVessel( const VesselOptions& da ):
Vessel(da),
inum(0),
in_normal_calculate(false)
{
  resizeBuffer(0);
}
Пример #6
0
Container::Container() :
	count( 0 ),
	bufferSize( 0 ),
	items( 0 )
{
	resizeBuffer( initialBufferSize );
}
Пример #7
0
void MessageTable::processMessage(int inletIndex, PdMessage *message) {
  // TODO(mhroth): process all of the commands which can be sent to tables
  if (message->isSymbol(0, "read")) {
    if (message->isSymbol(1))  {
      // read the file and fill the table
    }
  } else if (message->isSymbol(0, "write")) {
    // write the contents of the table to file
  } else if (message->isSymbol(0, "normalize")) {
    // normalise the contents of the table to the given value. Default to 1.
    float total = 0.0f;
    for (int i = 0; i < bufferLength; i++) {
      total += buffer[i];
    }
    if (total != 0.0f) {
      float normalisedTotal = message->isFloat(1) ? message->getFloat(1) : 1.0f;
      total /= normalisedTotal;
      for (int i = 0; i < bufferLength; i++) {
        buffer[i] /= total;
      }
    }
  } else if (message->isSymbol(0, "resize")) {
    if (message->isFloat(1)) {
      int newBufferLength = (int) message->getFloat(1);
      resizeBuffer(newBufferLength);
    }
  }
}
Пример #8
0
bool ANIObject::drawANI(Surface &dest, int16 &left, int16 &top,
                        int16 &right, int16 &bottom) {

    if (!hasBuffer()) {
        uint16 width, height;

        _ani->getMaxSize(width, height);

        resizeBuffer(width, height);
    }

    const ANIFile::Animation &animation = _ani->getAnimationInfo(_animation);
    if (_frame >= animation.frameCount)
        return false;

    const ANIFile::FrameArea &area = animation.frameAreas[_frame];

    left   = _x + area.left;
    top    = _y + area.top;
    right  = _x + area.right;
    bottom = _y + area.bottom;

    if (!saveScreen(dest, left, top, right, bottom))
        return false;

    _ani->draw(dest, _animation, _frame, _x, _y);

    return true;
}
Пример #9
0
/* Each vertex has a set of attributes (such as position, normals, texture coords, etc)
 * Each attribute has a set of components (such as the x, y, and z coordinate of the position)
 *
 * They may be laid out in video memory as follows:
 *
 * Interlaced:
 *   ________________Vertex1_______________ _______Vertex2_ ...
 *  | Attribute1 | Attribute2 | Attribute3 | Attribute1 | At...
 *  | x  y  z  w | x  y  z  w | x  y  z  w | x  y  z  w | x ...
 *
 * Separate:
 *   ___Vertex1__ ___Vertex2__ ___Vertex3__ ...___Vertex1__ ___Ver...
 *  | Attribute1 | Attribute1 | Attribute1 |... Attribute2 | Attri...
 *  | x  y  z  w | x  y  z  w | x  y  z  w |... x  y  z  w | x y z...
 *
 * attr_offset is the distance to offset from the beginning of the array to get to the first
 * instance of the given attribute.
 *
 * attr_stride is the space between the start of one vertex and the start of another
 * ie from the start of one attribute and the start to the next instance of that same attribute.
 *
 * This can be even further complicated by the fact that the stride can be 0 on all arrays
 * but yet have multiple attributes by having everything within different arrays and binding
 * a new array before calling the appropriate glVertexAttribPointer call.
 * THIS IS NOT CURRENTLY HANDLED (setting up and managing the order of attrib arrays is complex)
 *
 * buffer_type specifies whether you are binding an index buffer "GL_ELEMENT_ARRAY_BUFFER" or a
 * vertex buffer "GL_ARRAY_BUFFER"
 */
void VBuffer::loadBuffer(int data_size, GLubyte *data, int data_offset, int num_attr, attrib_info *attr_info)
{
    // does nothing if data is already allocated
    resizeBuffer(data_size + data_offset);

    // save parameters for future updates
    if (m_num_attr < num_attr)
    {
        delete [] m_attr_info;
        m_attr_info = NULL;
    }
    m_num_attr = num_attr;

    if (!m_attr_info)
        m_attr_info = new attrib_info[num_attr];

    // update our internal attribute info
    memcpy(m_attr_info, attr_info, num_attr * sizeof(attrib_info));

    // update our internal data
    memcpy(m_local_data + data_offset, data, data_size);

#ifdef DEBUG
    GLenum err =  glGetError();
    if (err != GL_NO_ERROR)
    {
        fprintf(stderr, "Buffer Assignment Failed: %08x\n", err);
    }
#endif
}
Пример #10
0
void Container::removeAt( long index )
{
	memmove( &items[index], &items[index + 1],
			 (count - index - 1) * sizeof( void * ) );

	if( bufferSize - count > bufferSizeDelta )
		resizeBuffer( bufferSize - bufferSizeDelta );
}
void DinamicArray::putBack(int element)
{
	if (getSize() == m_max_size)
	{
		resizeBuffer();
	}
	m_buffer[getSize()] = element;
	++m_size;
}
Пример #12
0
void CBuffer::operator+(const char *pstr)
{
    unsigned long p, sp = strlen(pstr);

    for(p=0; p<sp; p++)
    {
      if(m_buffer_state) m_pBuffer[m_buffer_pos++] = pstr[p];   // Copy string contents
      if(m_buffer_pos >= m_byte_size) resizeBuffer();           // Resize buffer if necessary
	}
}
Пример #13
0
void CBuffer::operator +(DWORD dw)
{
    DWORD *pdw = (DWORD*)(m_pBuffer + m_buffer_pos);

    if(m_buffer_state)
	{
      if((m_buffer_pos + 4) >= m_byte_size) resizeBuffer();  // Resize buffer if necessary
      if(m_buffer_state) { *pdw = dw; m_buffer_pos += 4; }
	}
}
Пример #14
0
void CBuffer::operator +(WORD n)
{
    WORD *pn = (WORD*)(m_pBuffer + m_buffer_pos);

    if(m_buffer_state)
	{
      if((m_buffer_pos + 2) >= m_byte_size) resizeBuffer();  // Resize buffer if necessary
      if(m_buffer_state) { *pn = n; m_buffer_pos += 2; }
	}
}
Пример #15
0
TexturePacker::TexturePacker(glm::ivec2 initialSize)
{
	resizeBuffer(initialSize);

	rootNode = std::make_unique<TextureNode>();
	rootNode->origin = glm::ivec2(0,0);
	rootNode->size = glm::ivec2(INT_MAX,INT_MAX);
	rootNode->empty = true;
	rootNode->left = nullptr;
	rootNode->right = nullptr;
}
Пример #16
0
BOOL CBuffer::copy(void *ptr, DWORD size)
{
    char *pc = (char*)ptr;

    for(DWORD i=0; i<size; i++)
	{
      if(m_buffer_state) m_pBuffer[m_buffer_pos++] = pc[i];  // Store data only if buffer allocated
      if(m_buffer_pos >= m_byte_size) resizeBuffer();        // Resize buffer if necessary	
	}

    return TRUE;
}
Пример #17
0
bool LfpDisplayNode::enable()
{

	if (resizeBuffer())
	{
		LfpDisplayEditor* editor = (LfpDisplayEditor*) getEditor();
		editor->enable();
		return true;
	} else {
		return false;
	}

}
Пример #18
0
void StoreDataVessel::resize(){
  vecsize=getAction()->getNumberOfQuantities();
  plumed_dbg_assert( vecsize>0 );

  if( getAction()->lowmem || !getAction()->derivativesAreRequired() ){
     nspace = 1;
     active_der.resize( max_lowmem_stash * ( 1 + getAction()->getNumberOfDerivatives() ) );
  } else {
     nspace = 1 + getAction()->maxderivatives;
     active_der.resize( getNumberOfStoredValues() * ( 1 + getAction()->maxderivatives ) );
  }
  resizeBuffer( getNumberOfStoredValues()*vecsize*nspace );
  local_buffer.resize( getNumberOfStoredValues()*vecsize*nspace );
}
Пример #19
0
static AllocHeader* getAllocHeader(OamState *oam, int index)
{
	// Note that this function may resize the allocBuffer any time you refer to
	// a new 'index' for the first time. This will invalidate any pointers that
	// getAllocHeader() has previously returned, since the buffer may have moved
	// to a different location in memory. The pointers returned by this function
	// must be discarded any time a new allocHeader may have been allocated.

	//resize buffer if needed
	if(index >= oam->allocBufferSize)
		resizeBuffer(oam);

	return &oam->allocBuffer[index];
}
Пример #20
0
void StoreDataVessel::resize(){
  plumed_dbg_assert( vecsize>0 );
  if( getAction()->derivativesAreRequired() ) final_derivatives.resize( getAction()->getNumberOfDerivatives() );

  if( getAction()->lowmem || !getAction()->derivativesAreRequired() ){
     nspace = 1;
     active_der.resize( max_lowmem_stash * ( 1 + getAction()->getNumberOfDerivatives() ) );
     local_derivatives.resize( max_lowmem_stash * vecsize * getAction()->getNumberOfDerivatives() );
  } else {
     nspace = 1 + getAction()->maxderivatives;
     active_der.resize( getAction()->getFullNumberOfTasks() * ( 1 + getAction()->maxderivatives ) );
  }
  active_val.resize( getAction()->getFullNumberOfTasks() );
  resizeBuffer( getAction()->getFullNumberOfTasks()*vecsize*nspace );
}
void QXlibWindowSurface::beginPaint(const QRegion &region)
{
    Q_UNUSED(region);
    resizeBuffer(size());

    if (shm_img.hasAlphaChannel()) {
        QPainter p(&shm_img);
        p.setCompositionMode(QPainter::CompositionMode_Source);
        const QVector<QRect> rects = region.rects();
        const QColor blank = Qt::transparent;
        for (QVector<QRect>::const_iterator it = rects.begin(); it != rects.end(); ++it) {
            p.fillRect(*it, blank);
        }
    }
}
Пример #22
0
long Container::insert( void *i )
{
//	if( hasItem( i ) )
//		{
//		return( getIndexOf( i ) );
//		}

	if( count == bufferSize )
		resizeBuffer( bufferSize + bufferSizeDelta );

	items[count] = i;
	count++;

	return (count - 1);
}
Пример #23
0
/** \param[in] ptr Add an object pointer at the end of the list.
  \retval RET_OK No problemo.
  \retval RET_MEMORYSPACE No more memory space. */
long Flist::add( void* ptr)
{
  long ret = RET_OK;

  if( firstElementFree >= lastElement) // Is the table full ?
    ret = resizeBuffer( INC_ELEMENTS); // ...Resize the buffer of pointers

  if( ret == RET_OK)  // if all OK, then really add
  {
    *firstElementFree = ptr;
    firstElementFree++;
  }

  return ret;
}
Пример #24
0
bool AudioIO::open(){
	Impl& i = *mImpl;

	i.mErrNum = paNoError;

	if(!(i.mIsOpen || i.mIsRunning)){

		resizeBuffer(false);
		resizeBuffer(true);

		resize(mBufT, mFramesPerBuffer);
		
		PaStreamParameters * inParams = &i.mInParams;
		PaStreamParameters * outParams = &i.mOutParams;
		
		// Must pass in 0s for input- or output-only streams.
		// Stream will not be opened if no device or channel count is zero
		if((paNoDevice ==  inParams->device) || (0 ==  inParams->channelCount)) inParams  = 0;
		if((paNoDevice == outParams->device) || (0 == outParams->channelCount)) outParams = 0;

		i.mErrNum = Pa_OpenStream(
			&i.mStream,			// PortAudioStream **
			inParams,			// PaStreamParameters * in
			outParams,			// PaStreamParameters * out
			mFramesPerSecond,	// frames/sec (double)
			mFramesPerBuffer,	// frames/buffer (unsigned long)
            paNoFlag,			// paNoFlag, paClipOff, paDitherOff
			paCallback,			// static callback function (PaStreamCallback *)
			this
		);

		i.mIsOpen = paNoError == i.mErrNum;
	}
	//printf("AudioIO::open()\n"); printError();
	return paNoError == i.mErrNum;
}
Пример #25
0
  void cudaCloverField::loadFullField(void *even, void *evenNorm, void *odd, void *oddNorm, 
				      const void *h_clover, const QudaPrecision cpu_prec, 
				      const CloverFieldOrder cpu_order)
  {
    // use pinned memory                  
    void *packedEven, *packedOdd, *packedEvenNorm=0, *packedOddNorm=0;

    if (precision == QUDA_DOUBLE_PRECISION && cpu_prec != QUDA_DOUBLE_PRECISION) {
      errorQuda("Cannot have CUDA double precision without CPU double precision");
    }
    if (cpu_order != QUDA_LEX_PACKED_CLOVER_ORDER) {
      errorQuda("Invalid clover order");
    }

    resizeBuffer(bytes + norm_bytes);
    packedEven = bufferPinned;
    packedOdd = (char*)bufferPinned + bytes/2;

    if (precision == QUDA_HALF_PRECISION) {
      packedEvenNorm = (char*)bufferPinned + bytes;
      packedOddNorm = (char*)bufferPinned + bytes + norm_bytes/2;
    }
    
    if (precision == QUDA_DOUBLE_PRECISION) {
      packFullClover((double2 *)packedEven, (double2 *)packedOdd, (double *)clover, x, pad);
    } else if (precision == QUDA_SINGLE_PRECISION) {
      if (cpu_prec == QUDA_DOUBLE_PRECISION) {
	packFullClover((float4 *)packedEven, (float4 *)packedOdd, (double *)clover, x, pad);
      } else {
	packFullClover((float4 *)packedEven, (float4 *)packedOdd, (float *)clover, x, pad);    
      }
    } else {
      if (cpu_prec == QUDA_DOUBLE_PRECISION) {
	packFullCloverHalf((short4 *)packedEven, (float *)packedEvenNorm, (short4 *)packedOdd,
			   (float *) packedOddNorm, (double *)clover, x, pad);
      } else {
	packFullCloverHalf((short4 *)packedEven, (float *)packedEvenNorm, (short4 *)packedOdd,
			   (float * )packedOddNorm, (float *)clover, x, pad);    
      }
    }

    cudaMemcpy(even, packedEven, bytes/2, cudaMemcpyHostToDevice);
    cudaMemcpy(odd, packedOdd, bytes/2, cudaMemcpyHostToDevice);
    if (precision == QUDA_HALF_PRECISION) {
      cudaMemcpy(evenNorm, packedEvenNorm, norm_bytes/2, cudaMemcpyHostToDevice);
      cudaMemcpy(oddNorm, packedOddNorm, norm_bytes/2, cudaMemcpyHostToDevice);
    }
  }
Пример #26
0
void IBuffer::loadBuffer(int num_elem, int elem_size, int *data, int data_offset)
{
    if (data == NULL)
        return;

    m_elem_size = elem_size;
    resizeBuffer(num_elem * elem_size + data_offset); // does nothing if data is already allocated and large enough
    memcpy(m_local_data, data, num_elem * elem_size);     // note: don't use m_size. This method allows partial copies

#ifdef DEBUG
    GLenum err =  glGetError();
    if (err != GL_NO_ERROR)
    {
        fprintf(stderr, "Buffer Assignment Failed: %08x\n", err);
    }
#endif
}
void GridMap::setGeometry(const Eigen::Array2d& length, const double resolution, const Eigen::Vector2d& position)
{
  assert(length(0) > 0.0);
  assert(length(1) > 0.0);
  assert(resolution > 0.0);

  Array2i bufferSize;
  bufferSize(0) = static_cast<int>(round(length(0) / resolution)); // There is no round() function in Eigen.
  bufferSize(1) = static_cast<int>(round(length(1) / resolution));
  resizeBuffer(bufferSize);
  clearAll();

  resolution_ = resolution;
  length_ = (bufferSize_.cast<double>() * resolution_).matrix();
  position_ = position;
  bufferStartIndex_.setZero();

  return;
}
Пример #28
0
// Vẽ board
void VeBoardMenu()
{
	cBoard board;
	system("Color 3F");
	resizeBuffer(79, 35);
	Logo();
	board.drawBoard(27, 20, 51, 30, 2, 14, "* Menu *", 14);
	board.drawBoard(28, 21, 50, 29, 2);
	gotoxy(30, 23);
	cout << "_ So nguyen 8 byte";
	gotoxy(30, 25);
	cout << "_ So nguyen 16 byte";
	gotoxy(30, 27);
	cout << "_ So thuc 16 byte";
	gotoxy(21, 32);
	cout << "* Su dung phim mui ten de di chuyen";
	gotoxy(25, 33);
	cout << "* Su dung phim ENTER de chon";
}
Пример #29
0
void processHostRequest(char* inBuf, char* key, priqueue_t* q, int sockfd, int browserfd)
{
  const int toRead = 256;
  int bytesRead = 0;
  int read = -1;
  int inSize = strlen(inBuf);
  int bufSize = 256;
  int loop = 0;
  struct timeval timeo;
  char* buffer = (char*)malloc(bufSize*sizeof(char));
  fd_set readset;

  timeo.tv_sec  = 5; /* Wait up to 5 seconds for data */
  timeo.tv_usec = 0;

  /* Send in bite-sized chunks :) */
  loop = chunkSend(sockfd, inBuf, inSize);
  
  while(loop) {
    FD_ZERO(&readset);
    FD_SET(sockfd, &readset);
    select(sockfd+1, &readset, NULL, NULL, &timeo);
    if(FD_ISSET(sockfd, &readset)) {
      read = recv(sockfd, buffer+bytesRead, toRead, 0);
      if(read < 1)
        break;
      /* Back to client in bite-size chunks as we can get them */
      loop = chunkSend(browserfd, buffer+bytesRead, read);
      bytesRead += read;
      resizeBuffer(&buffer, &bufSize, toRead, bytesRead);
    } else { /* Is everything read? */
        break;
    }
  }

  buffer[bytesRead] = '\0';
  if(cacheHTTPResponse(buffer) && read > -1) {
    cacheResponse(q, key, (void*)buffer, bytesRead);
  } else {
    free(buffer);
  }
}
Пример #30
0
/** \param[in] idx Position index to insert the object.
	\param[in] ptr Object pointer to insert.
	\retval RET_OK No problemo.
  \retval RET_MEMORYSPACE No more memory space. */
long Flist::insert( long idx, void* ptr)
{
  long ret = RET_OK;
  
  void** elementIdx = ( ( void**) firstElement) + idx;

  if( firstElementFree >= lastElement) // Is the table full ?
    ret = resizeBuffer( INC_ELEMENTS); // ...Resize the buffer of pointers

  if( ret == RET_OK)  // if all OK, then really add
  {
    // Move the end of the list to creat place for the new element
    memmove( ( elementIdx + 1), elementIdx, ( ( firstElementFree - elementIdx) * sizeof( void*)));

    *elementIdx = ptr;
    firstElementFree++;    
  }

  return ret;  
}