Esempio n. 1
0
int DwarfDie::typeSize() const
{
    switch (tag()) {
        case DW_TAG_base_type:
        case DW_TAG_class_type:
        case DW_TAG_enumeration_type:
        case DW_TAG_structure_type:
        case DW_TAG_union_type:
            return attribute(DW_AT_byte_size).toInt();
        case DW_TAG_pointer_type:
        case DW_TAG_reference_type:
        case DW_TAG_rvalue_reference_type:
            return 8; // TODO: support 32bit!
        case DW_TAG_const_type:
        case DW_TAG_restrict_type:
        case DW_TAG_typedef:
        case DW_TAG_volatile_type:
        {
            const auto typeDie = attribute(DW_AT_type).value<DwarfDie*>();
            assert(typeDie);
            return typeDie->typeSize();
        }
        case DW_TAG_array_type:
        {
            const auto typeDie = attribute(DW_AT_type).value<DwarfDie*>();
            assert(typeDie);
            int s = typeDie->typeSize();
            foreach (auto d, arrayDimensions(this))
                s *= d;
            return s;
        }
    }

    return 0;
}
Esempio n. 2
0
bool IndexBuffer::init(size_t count, IndexBufferType type, BufferUsage usage)
{
  m_type = type;
  m_usage = usage;
  m_count = count;

  glGenBuffers(1, &m_bufferID);

  m_context.setCurrentIndexBuffer(this);

  glBufferData(GL_ELEMENT_ARRAY_BUFFER,
               m_count * typeSize(m_type),
               nullptr,
               convertToGL(m_usage));

  if (!checkGL("Error during creation of index buffer of element size %u",
               (uint) typeSize(m_type)))
  {
    m_context.setCurrentIndexBuffer(nullptr);
    return false;
  }

  if (RenderStats* stats = m_context.stats())
    stats->addIndexBuffer(size());

  return true;
}
GLenum IndexDataManager::prepareIndexData(GLenum type, GLsizei count, Buffer *buffer, const void *indices, TranslatedIndexData *translated)
{
	if(!mStreamingBuffer)
	{
		return GL_OUT_OF_MEMORY;
	}

	intptr_t offset = reinterpret_cast<intptr_t>(indices);

	if(buffer != NULL)
	{
		if(typeSize(type) * count + offset > static_cast<std::size_t>(buffer->size()))
		{
			return GL_INVALID_OPERATION;
		}

		indices = static_cast<const GLubyte*>(buffer->data()) + offset;
	}

	StreamingIndexBuffer *streamingBuffer = mStreamingBuffer;

	sw::Resource *staticBuffer = buffer ? buffer->getResource() : NULL;

	if(staticBuffer)
	{
		computeRange(type, indices, count, &translated->minIndex, &translated->maxIndex);

		translated->indexBuffer = staticBuffer;
		translated->indexOffset = offset;
	}
	else
	{
		unsigned int streamOffset = 0;
		int convertCount = count;

		streamingBuffer->reserveSpace(convertCount * typeSize(type), type);
		void *output = streamingBuffer->map(typeSize(type) * convertCount, &streamOffset);

		if(output == NULL)
		{
			ERR("Failed to map index buffer.");
			return GL_OUT_OF_MEMORY;
		}

		copyIndices(type, staticBuffer ? buffer->data() : indices, convertCount, output);
		streamingBuffer->unmap();

		computeRange(type, indices, count, &translated->minIndex, &translated->maxIndex);

		translated->indexBuffer = streamingBuffer->getResource();
		translated->indexOffset = streamOffset;
	}

	return GL_NO_ERROR;
}
Esempio n. 4
0
int typeSize(refObject type)
{ switch (toHook(car(type)))
  { case arrayHook:
    { type = cdr(type);
      return toInteger(car(type)) * typeSize(cadr(type)); }
    case char0Hook:
    { return sizeof(char0Type); }
    case char1Hook:
    { return sizeof(char1Type); }
    case int0Hook:
    { return sizeof(int0Type); }
    case int1Hook:
    { return sizeof(int1Type); }
    case int2Hook:
    { return sizeof(int2Type); }
    case nullHook:
    case referHook:
    case rowHook:
    { return sizeof(pointerType); }
    case procHook:
    { return sizeof(procType); }
    case real0Hook:
    { return sizeof(real0Type); }
    case real1Hook:
    { return sizeof(real1Type); }
    case skoHook:
    case varHook:
    { return typeSize(cadr(type)); }
    case strTypeHook:
    { return toInteger(cadddr(type)); }
    case tupleHook:
    { int slotAlign;
      refObject slotType;
      int tupleAlign = 1;
      int tupleSize = 0;
      type = cdr(type);
      while (type != nil)
      { slotType = car(type);
        slotAlign = typeAlign(slotType);
        tupleAlign = (slotAlign > tupleAlign ? slotAlign : tupleAlign);
        tupleSize += typeSize(slotType);
        tupleSize += rounder(tupleSize, slotAlign);
        type = cddr(type); }
      return tupleSize + rounder(tupleSize, tupleAlign); }
    case voidHook:
    { return sizeof(voidType); }
    default:
    { fail("Type has undefined size in typeSize!"); }}}
Esempio n. 5
0
void processSimpleVariable(SymbolTable *table, Node *ptr, Specifier spec, Qualifier qual)
{
    int sign = 1;

    Node *p = ptr->son;
    Node *q = ptr->next;

    if (ptr->token.tokenNumber != SIMPLE_VAR) {
        fprintf(stderr, "error in SIMPLE_VAR\n");
    }

    if (qual == QUAL_CONST) {
        int init;
        if (q == NULL) {
            fprintf(stderr, "%s must have a constant value\n", ptr->token.tokenValue);
            return;
        }
        if (q->token.tokenNumber == UNARY_MINUS) {
            sign = -1;
            q = q->son;
        }
        init = sign * atoi(q->token.tokenValue);
        insert(table, p->token.tokenValue, spec, qual, 0, 0, init);

    } else { // variable type
        int size;
        size = typeSize(spec);
        insert(table, p->token.tokenValue, spec, qual, table->offset, 1, 0);
        table->offset += size;
    }
}
Esempio n. 6
0
void Light::setAmbientLight(Vec4<GLfloat> light)
{
        UBOUniform ambientLight = uniforms[std::string("ambientLight")];

        size_t size =  ambientLight.getSize() * typeSize(ambientLight.getType());
        memcpy(lightData + ambientLight.getOffset(), light.getData(), size);
}
Esempio n. 7
0
void Light::enableDiffuse(GLboolean enabled)
{
        UBOUniform diffuse = uniforms[std::string("enableDiffuse")];

        size_t size = diffuse.getSize() * typeSize(diffuse.getType());
        memcpy(lightData + diffuse.getOffset(), &enabled, sizeof(enabled));
}
Esempio n. 8
0
void Light::enableSpecular(GLboolean enabled)
{
        UBOUniform specular = uniforms[std::string("enableSpecular")];

        size_t size = specular.getSize() * typeSize(specular.getType());
        memcpy(lightData + specular.getOffset(), &enabled, sizeof(enabled));
}
Esempio n. 9
0
void Light::setSpecularLight(Vec4<GLfloat> light)
{
        UBOUniform specularLight = uniforms[std::string("specularLight")];

        size_t size =  specularLight.getSize() * typeSize(specularLight.getType());
        memcpy(lightData + specularLight.getOffset(), light.getData(), size);
}
Esempio n. 10
0
void Light::setPosition(Vec4<GLfloat> pos)
{
        UBOUniform position = uniforms[std::string("position")];

        size_t size = position.getSize() * typeSize(position.getType());
        memcpy(lightData + position.getOffset(), pos.getData(), size);
}
Esempio n. 11
0
const void *getp(MyBuf const &b, int x, int y)
{
	assert(x>=0 && x<b.w);
	assert(y>=0 && y<b.h);
	int nt = typeSize(b.type);
	const char *p = (char*)b.p +y*b.linestep + nt*x;
	return p;
}
Esempio n. 12
0
void emitDeclaration(refVoidFunc etc, refObject type)
{ switch (toHook(car(type)))

//  An array or tuple type becomes a STRUCT name (see ORSON/SIZE).

  { case arrayHook:
    case tupleHook:
    { writeDirtyName(target, "type", typeSize(type));
      etc();
      break; }

//  The CHAR0 type becomes CHAR0 STRING (see ORSON/GLOBAL).

    case char0Hook:
    { writeFormat(target, "%s", char0String);
      etc();
      break; }

//  The CHAR1 type becomes CHAR1 STRING (see ORSON/GLOBAL).

    case char1Hook:
    { writeFormat(target, "%s", char1String);
      etc();
      break; }

//  The INT0 type becomes INT0 STRING (see ORSON/GLOBAL).

    case int0Hook:
    { writeFormat(target, "%s", int0String);
      etc();
      break; }

//  The INT1 type becomes INT1 STRING (see ORSON/GLOBAL).

    case int1Hook:
    { writeFormat(target, "%s", int1String);
      etc();
      break; }

//  The INT2 type becomes INT2 STRING (see ORSON/GLOBAL).

    case int2Hook:
    { writeFormat(target, "%s", int2String);
      etc();
      break; }

//  NULL, REF, and ROW types become pointers to C's VOID type.

    case nullHook:
    case referHook:
    case rowHook:
    { emitDeclaration(
       ({ void lambda()
          { writeChar(target, '*');
            etc(); }
          lambda; }),
       voidExternal);
      break; }
Esempio n. 13
0
Vec4<GLfloat> Light::getAmbientLight()
{
        GLfloat ambientLight[3];
        UBOUniform ambientLightUbo = uniforms[std::string("ambientLight")];
        size_t size = ambientLightUbo.getSize() * typeSize(ambientLightUbo.getType());
        memcpy(ambientLight, lightData + ambientLightUbo.getOffset(), size);

        return Vec4<GLfloat>(ambientLight[0], ambientLight[1], ambientLight[2], 0.0f);
}
Esempio n. 14
0
Vec4<GLfloat> Light::getDiffuseLight()
{
        GLfloat diffuseLight[4];
        UBOUniform diffuseLightUbo = uniforms[std::string("diffuseLight")];
        size_t size = diffuseLightUbo.getSize() * typeSize(diffuseLightUbo.getType());
        memcpy(diffuseLight, lightData + diffuseLightUbo.getOffset(), size);

        return Vec4<GLfloat>(diffuseLight[0], diffuseLight[1], diffuseLight[2], 0.0f);
}
Esempio n. 15
0
Vec4<GLfloat> Light::getSpecularLight()
{
        GLfloat specularLight[4];
        UBOUniform specularLightUbo = uniforms[std::string("specularLight")];
        size_t size = specularLightUbo.getSize() * typeSize(specularLightUbo.getType());
        memcpy(specularLight, lightData + specularLightUbo.getOffset(), size);

        return Vec4<GLfloat>(specularLight[0], specularLight[1], specularLight[2], 0.0f);
}
Esempio n. 16
0
void Node::read()
{
	for(int i = 0; i < tableInstance.attrList.size(); i++)
		if (tableInstance.attrList[i].name == indexName)
		{
			switch(tableInstance.attrList[i].datatype)
			{
			case -1:attrType = _TYPE_FLOAT;break;
			case 0:attrType = _TYPE_INT;break;
			case 1:attrType = _TYPE_STRING;break;
			}
			break;
		}
	memcpy(&nodeType,block.content,1);
	memcpy(&count,block.content + 1,sizeof(int));
	for(int i = 0; i < (ptrN - 1); i++)
	{
		float tempFloat = 0;
		int tempInt = 0;
		string tempString = "";
		PtrType tempPtr = 0;
		Value tempValue(attrType);

		//read ptr//TODO:+5?
		memcpy(&tempPtr,block.content + 5 + i*( typeSize(attrType) + sizeof(int) ),typeSize(_TYPE_INT));
		Value ptrTempValue(_TYPE_INT,tempPtr);//TODO:设置ptr类型
		info.push_back(ptrTempValue);

		//read key
		switch(attrType)//TODO:+5?
		{
		case _TYPE_FLOAT:
			{
				memcpy(&tempFloat,block.content + 5 + i*( typeSize(attrType) + sizeof(int) ) + sizeof(int),typeSize(_TYPE_FLOAT));
				tempValue.setKey(tempFloat);
				break;
			}
		case _TYPE_INT:
			{
				memcpy(&tempInt,block.content + 5 + i*( typeSize(attrType) + sizeof(int) ) + sizeof(int),typeSize(_TYPE_INT));
				tempValue.setKey(tempInt);
				break;
			}
		case _TYPE_STRING:
			{
				memcpy(&tempString,block.content + 5 + i*( typeSize(attrType) + sizeof(int) ) + sizeof(int),typeSize(_TYPE_STRING));
				tempValue.setKey(tempString);
				break;
			}
		}//switch
		info.push_back(tempValue);
		
	}//for
	PtrType tempPtr = 0;
	memcpy(&tempPtr,block.content + 5 + (ptrN - 1)*( typeSize(attrType) + sizeof(int) ),typeSize(_TYPE_INT));
	Value ptrTempValue(_TYPE_INT,tempPtr);//TODO:设置ptr类型
	info.push_back(ptrTempValue);
}
Esempio n. 17
0
int tiffSize_(TIFF *image, int *W, int *H, int *linestep, BufType *Type)
{
  uint16 bps, spp, sfm;
  uint32 width;
  tsize_t stripSize;
  unsigned long imageOffset;
  int stripMax;
  
  //unsigned long bufferSize, count;
  
  // Check that it is of a type that we support
  if((TIFFGetField(image, TIFFTAG_BITSPERSAMPLE, &bps) == 0) ){
    return(42);
  }
  
  MyTRACE( "bits per sample(%d)\n", bps);

  //float type
   if((TIFFGetField(image, TIFFTAG_SAMPLEFORMAT, &sfm) == 0) ){
    
    return(42);
  }

   MyTRACE( "TIFFTAG_SAMPLEFORMAT(%d)\n", sfm);

   if (bps == 32 && sfm == SAMPLEFORMAT_IEEEFP)
	   *Type = TYPE_32F;
   else if (bps == 16 && (sfm == SAMPLEFORMAT_INT))
	   *Type = TYPE_16S;
   else if (bps == 16 && (sfm == SAMPLEFORMAT_UINT))
	   *Type = TYPE_16U;
   else
	   return 43;

  if((TIFFGetField(image, TIFFTAG_SAMPLESPERPIXEL, &spp) == 0) || (spp != 1)){
    MyTRACE( "Either undefined or unsupported number of samples per pixel\n");
    return(42);
  }
  // Read in the possibly multiple strips
  stripSize = TIFFStripSize (image);
  *linestep = stripSize;
  stripMax = TIFFNumberOfStrips (image);
  imageOffset = 0;
  long height = stripMax;
  *H = height;
  // Do whatever it is we do with the buffer -- we dump it in hex
  if(TIFFGetField(image, TIFFTAG_IMAGEWIDTH, &width) == 0){
    MyTRACE( "Image does not define its width\n");
    return(42);
  }
  *W = width;

  assert(typeSize(*Type)*width <= stripSize);
  return 0;
}
Esempio n. 18
0
bool QgsRasterBlock::reset( QGis::DataType theDataType, int theWidth, int theHeight, double theNoDataValue )
{
  QgsDebugMsg( QString( "theWidth= %1 theHeight = %2 theDataType = %3 theNoDataValue = %4" ).arg( theWidth ).arg( theHeight ).arg( theDataType ).arg( theNoDataValue ) );

  qgsFree( mData );
  mData = nullptr;
  delete mImage;
  mImage = nullptr;
  qgsFree( mNoDataBitmap );
  mNoDataBitmap = nullptr;
  mDataType = QGis::UnknownDataType;
  mTypeSize = 0;
  mWidth = 0;
  mHeight = 0;
  mHasNoDataValue = false;
  mNoDataValue = std::numeric_limits<double>::quiet_NaN();
  mValid = false;

  if ( typeIsNumeric( theDataType ) )
  {
    QgsDebugMsg( "Numeric type" );
    qgssize tSize = typeSize( theDataType );
    QgsDebugMsg( QString( "allocate %1 bytes" ).arg( tSize * theWidth * theHeight ) );
    mData = qgsMalloc( tSize * theWidth * theHeight );
    if ( !mData )
    {
      QgsDebugMsg( QString( "Couldn't allocate data memory of %1 bytes" ).arg( tSize * theWidth * theHeight ) );
      return false;
    }
  }
  else if ( typeIsColor( theDataType ) )
  {
    QgsDebugMsg( "Color type" );
    QImage::Format format = imageFormat( theDataType );
    mImage = new QImage( theWidth, theHeight, format );
  }
  else
  {
    QgsDebugMsg( "Wrong data type" );
    return false;
  }

  mValid = true;
  mDataType = theDataType;
  mTypeSize = QgsRasterBlock::typeSize( mDataType );
  mWidth = theWidth;
  mHeight = theHeight;
  mHasNoDataValue = true;
  mNoDataValue = theNoDataValue;
  QgsDebugMsg( QString( "mWidth= %1 mHeight = %2 mDataType = %3 mData = %4 mImage = %5" ).arg( mWidth ).arg( mHeight ).arg( mDataType )
               .arg( reinterpret_cast< ulong >( mData ) ).arg( reinterpret_cast< ulong >( mImage ) ) );
  return true;
}
Esempio n. 19
0
void Light::setDiffuseLight(Vec4<GLfloat> light)
{
        UBOUniform diffuseLight = uniforms[std::string("diffuseLight")];

        struct LightProperties* sss = (struct LightProperties*)0;
        int *asdf = (int*)&sss->diffuseLight;

        size_t size =  diffuseLight.getSize() * typeSize(diffuseLight.getType());
        struct LightProperties *blah = (struct LightProperties*)lightData;
        size_t test = sizeof(struct LightProperties);
        memcpy(lightData + diffuseLight.getOffset(), light.getData(), size);
}
Esempio n. 20
0
void * QgsRasterInterface::convert( void *srcData, QgsRasterInterface::DataType srcDataType, QgsRasterInterface::DataType destDataType, int size )
{
  int destDataTypeSize = typeSize( destDataType ) / 8;
  void *destData = VSIMalloc( destDataTypeSize * size );
  for ( int i = 0; i < size; i++ )
  {
    double value = readValue( srcData, srcDataType, i );
    writeValue( destData, destDataType, i, value );
    //double newValue = readValue( destData, destDataType, i );
    //QgsDebugMsg( QString("convert type %1 to %2: %3 -> %4").arg(srcDataType).arg(destDataType).arg( value ).arg( newValue ) );
  }
  return destData;
}
Esempio n. 21
0
bool QgsRasterBlock::setIsNoData()
{
  QgsDebugMsg( "Entered" );
  if ( typeIsNumeric( mDataType ) )
  {
    if ( mHasNoDataValue )
    {
      if ( !mData )
      {
        QgsDebugMsg( "Data block not allocated" );
        return false;
      }

      QgsDebugMsg( "set mData to mNoDataValue" );
      int dataTypeSize = typeSize( mDataType );
      QByteArray noDataByteArray = valueBytes( mDataType, mNoDataValue );

      char *nodata = noDataByteArray.data();
      for ( qgssize i = 0; i < static_cast< qgssize >( mWidth )*mHeight; i++ )
      {
        memcpy( reinterpret_cast< char* >( mData ) + i*dataTypeSize, nodata, dataTypeSize );
      }
    }
    else
    {
      // use bitmap
      if ( !mNoDataBitmap )
      {
        if ( !createNoDataBitmap() )
        {
          return false;
        }
      }
      QgsDebugMsg( "set mNoDataBitmap to 1" );
      memset( mNoDataBitmap, 0xff, mNoDataBitmapSize );
    }
    return true;
  }
  else
  {
    // image
    if ( !mImage )
    {
      QgsDebugMsg( "Image not allocated" );
      return false;
    }
    QgsDebugMsg( "Fill image" );
    mImage->fill( mNoDataColor );
    return true;
  }
}
Esempio n. 22
0
size_t getShaderAttributeSize( const EShaderAttributeType type, const EShaderAttributeTypeComponents components )
{
    size_t typeSize(4);
    switch (type)
    {
    case eShaderAttributeType_Float:
    case eShaderAttributeType_Int32:
    case eShaderAttributeType_UInt32: 
        typeSize = 4; break;
    default:
        LOG(LogType_ProgrammerAssert, "Unknown EShaderAttributeType when getting size! %d", type);
    }
    return typeSize * components;
}
Esempio n. 23
0
void IndexBuffer::copyFrom(const void* source, size_t sourceCount, size_t start)
{
  if (start + sourceCount > m_count)
  {
    logError("Too many indices submitted to index buffer");
    return;
  }

  m_context.setCurrentIndexBuffer(this);

  const size_t size = typeSize(m_type);
  glBufferSubData(GL_ELEMENT_ARRAY_BUFFER, start * size, sourceCount * size, source);

#if WENDY_DEBUG
  checkGL("Error during copy to index buffer");
#endif
}
Esempio n. 24
0
void IndexBuffer::copyTo(void* target, size_t targetCount, size_t start)
{
  if (start + targetCount > m_count)
  {
    logError("Too many indices requested from index buffer");
    return;
  }

  m_context.setCurrentIndexBuffer(this);

  const size_t size = typeSize(m_type);
  glGetBufferSubData(GL_ELEMENT_ARRAY_BUFFER, start * size, targetCount * size, target);

#if WENDY_DEBUG
  checkGL("Error during copy from index buffer");
#endif
}
Esempio n. 25
0
void internSize(int length, refObject type)
{ if (isSized(type))
  { int count = length * typeSize(type);
    refSize subtree = sizes;
    while (true)
    { if (count < count(subtree))
      { if (left(subtree) == nil)
        { left(subtree) = makeSize(count);
          return; }
        else
        { subtree = left(subtree); }}
      else if (count > count(subtree))
           { if (right(subtree) == nil)
             { right(subtree) = makeSize(count);
               return; }
             else
             { subtree = right(subtree); }}
           else
           { return; }}}}
Esempio n. 26
0
int
pcl::ASCIIReader::readHeader (const std::string& file_name,
  pcl::PCLPointCloud2& cloud, Eigen::Vector4f& origin,
  Eigen::Quaternionf& orientation, int& file_version, int& data_type,
  unsigned int& data_idx, const int offset)
{
	(void)offset; //offset is not used for ascii file implementation
	
  boost::filesystem::path fpath = file_name;

  if (!boost::filesystem::exists (fpath))
  {
    PCL_ERROR ("[%s] File %s does not exist.\n", name_.c_str (), file_name.c_str ());
    return (-1);
  }
  if (boost::filesystem::extension (fpath) != extension_)
  {
    PCL_ERROR ("[%s] File does not have %s extension. \n", name_.c_str(), extension_.c_str());
    return -1;
  }

  cloud.fields = fields_;
  cloud.point_step = 0;
  for (int i = 0; i < fields_.size (); i++) 
    cloud.point_step += typeSize (cloud.fields[i].datatype);

  std::fstream ifile (file_name.c_str (), std::fstream::in);
  std::string line;
  int total = 0;
  while (std::getline (ifile, line))
    total++;

  origin = Eigen::Vector4f::Zero ();
  orientation = Eigen::Quaternionf ();
  cloud.width = total;
  cloud.height = 1;
  cloud.is_dense = true;
  file_version = -1;
  data_type = 0;
  data_idx  = 0;
  return (total);
}
Esempio n. 27
0
void processArrayVariable(SymbolTable *table, Node *ptr, int spec, int qual)
{
    Node *p = ptr->son;
    int size;

    if (ptr->token.tokenNumber != ARRAY_VAR) {
        fprintf(file, "error in ARRAY_VAR\n");
        return;
    }

    if (p->next == NULL) {
        fprintf(file, "array size must be specified\n");
    } else {
        size = atoi(p->next->token.tokenValue);
    }

    size *= typeSize(spec);

    insert(table, p->token.tokenValue, spec, qual, table->offset, size, 0);
    table->offset += size;
}
Esempio n. 28
0
int DwarfDie::typeAlignment() const
{
    switch (tag()) {
        case DW_TAG_base_type:
        case DW_TAG_enumeration_type:
            return std::min(typeSize(), 8); // TODO: 32bit support
        case DW_TAG_array_type:
        case DW_TAG_const_type:
        case DW_TAG_restrict_type:
        case DW_TAG_typedef:
        case DW_TAG_volatile_type:
        {
            const auto typeDie = attribute(DW_AT_type).value<DwarfDie*>();
            assert(typeDie);
            return typeDie->typeAlignment();
        }
        case DW_TAG_pointer_type:
        case DW_TAG_reference_type:
        case DW_TAG_rvalue_reference_type:
            return 8; // TODO: 32bit support
        case DW_TAG_class_type:
        case DW_TAG_structure_type:
        case DW_TAG_union_type:
        {
            int align = 1;
            foreach (const auto child, children()) {
                if (child->tag() != DW_TAG_member && child->tag() != DW_TAG_inheritance)
                    continue;
                if (child->isStaticMember())
                    continue;
                const auto typeDie = child->attribute(DW_AT_type).value<DwarfDie*>();
                assert(typeDie);
                align = std::max(align, typeDie->typeAlignment());
            }
            return align;
        }
    }

    return 0;
}
Esempio n. 29
0
int logBuf(MyBuf const &b, const char*file)
{
	FILE *fp = fopen(file, "w");
	if (!fp)
		return -1;
	fprintf(fp, "%d %d %d\n", b.w, b.h, b.type);
	int nt = typeSize(b.type);
	for (int y = 0; y < b.h; y++)
	{
		for (int x = 0; x < b.w; x++)
		{
			const char *p = (char*)b.p +y*b.linestep + nt*x;
			if (b.type == TYPE_16S)
				fprintf(fp, "%hd ", (short&)*p);
			else if (b.type == TYPE_16U)
				fprintf(fp, "%hu ", (unsigned short&)*p);
			else if (b.type == TYPE_32F)
				fprintf(fp, "%f ", (float&)*p);
		}
		fprintf(fp, "\n");
	}
	fclose(fp);
	return 0;
}
Esempio n. 30
0
bool QgsRasterBlock::setIsNoDataExcept( const QRect & theExceptRect )
{
  int top = theExceptRect.top();
  int bottom = theExceptRect.bottom();
  int left = theExceptRect.left();
  int right = theExceptRect.right();
  top = qMin( qMax( top, 0 ), mHeight - 1 );
  left = qMin( qMax( left, 0 ), mWidth - 1 );
  bottom = qMax( 0, qMin( bottom, mHeight - 1 ) );
  right = qMax( 0, qMin( right, mWidth - 1 ) );

  QgsDebugMsg( "Entered" );
  if ( typeIsNumeric( mDataType ) )
  {
    if ( mHasNoDataValue )
    {
      if ( !mData )
      {
        QgsDebugMsg( "Data block not allocated" );
        return false;
      }

      QgsDebugMsg( "set mData to mNoDataValue" );
      int dataTypeSize = typeSize( mDataType );
      QByteArray noDataByteArray = valueBytes( mDataType, mNoDataValue );

      char *nodata = noDataByteArray.data();
      char *nodataRow = new char[mWidth*dataTypeSize]; // full row of no data
      for ( int c = 0; c < mWidth; c++ )
      {
        memcpy( nodataRow + c*dataTypeSize, nodata, dataTypeSize );
      }

      // top and bottom
      for ( int r = 0; r < mHeight; r++ )
      {
        if ( r >= top && r <= bottom ) continue; // middle
        qgssize i = static_cast< qgssize >( r ) * mWidth;
        memcpy( reinterpret_cast< char* >( mData ) + i*dataTypeSize, nodataRow, dataTypeSize*mWidth );
      }
      // middle
      for ( int r = top; r <= bottom; r++ )
      {
        qgssize i = static_cast< qgssize >( r ) * mWidth;
        // middle left
        memcpy( reinterpret_cast< char* >( mData ) + i*dataTypeSize, nodataRow, dataTypeSize*left );
        // middle right
        i += right + 1;
        int w = mWidth - right - 1;
        memcpy( reinterpret_cast< char* >( mData ) + i*dataTypeSize, nodataRow, dataTypeSize*w );
      }
      delete [] nodataRow;
    }
    else
    {
      // use bitmap
      if ( !mNoDataBitmap )
      {
        if ( !createNoDataBitmap() )
        {
          return false;
        }
      }
      QgsDebugMsg( "set mNoDataBitmap to 1" );

      char *nodataRow = new char[mNoDataBitmapWidth]; // full row of no data
      // TODO: we can simply set all bytes to 11111111 (~0) I think
      memset( nodataRow, 0, mNoDataBitmapWidth );
      for ( int c = 0; c < mWidth; c ++ )
      {
        int byte = c / 8;
        int bit = c % 8;
        char nodata = 0x80 >> bit;
        memset( nodataRow + byte, nodataRow[byte] | nodata, 1 );
      }

      // top and bottom
      for ( int r = 0; r < mHeight; r++ )
      {
        if ( r >= top && r <= bottom ) continue; // middle
        qgssize i = static_cast< qgssize >( r ) * mNoDataBitmapWidth;
        memcpy( mNoDataBitmap + i, nodataRow, mNoDataBitmapWidth );
      }
      // middle
      memset( nodataRow, 0, mNoDataBitmapWidth );
      for ( int c = 0; c < mWidth; c ++ )
      {
        if ( c >= left && c <= right ) continue; // middle
        int byte = c / 8;
        int bit = c % 8;
        char nodata = 0x80 >> bit;
        memset( nodataRow + byte, nodataRow[byte] | nodata, 1 );
      }
      for ( int r = top; r <= bottom; r++ )
      {
        qgssize i = static_cast< qgssize >( r ) * mNoDataBitmapWidth;
        memcpy( mNoDataBitmap + i, nodataRow, mNoDataBitmapWidth );
      }
      delete [] nodataRow;
    }
    return true;
  }
  else
  {
    // image
    if ( !mImage )