Esempio n. 1
0
void ImageProximityFFT::MulAndScaleSpectrums(Image& Source, Image& Template, Image& Dest, float scale)
{
   CheckSameSize(Source, Template);
   CheckSameSize(Source, Dest);

   // Verify image types
   if (Source.DataType() != SImage::F32 || Template.DataType() != SImage::F32 || Dest.DataType() != SImage::F32)
      throw cl::Error(CL_IMAGE_FORMAT_NOT_SUPPORTED, "The function works only with F32 images");

   // Verify image types
   if (Source.NbChannels() != 2 || Template.NbChannels() != 2 || Dest.NbChannels() != 2)
      throw cl::Error(CL_IMAGE_FORMAT_NOT_SUPPORTED, "The function works only with 2 channel images");

   Kernel(mulAndScaleSpectrums, Source, Template, Dest, Source.Step(), Template.Step(), Dest.Step(), Source.Width(), Source.Height(), scale);
}
Esempio n. 2
0
/*
====================
Update
====================
*/
VOID EChunk::Update()
{
	GUARD(EChunk::Update);

	// erase the layer that is invalid
	std::vector<Layer>::iterator it = mLayers.begin();
	while(it != mLayers.end())
	{
		Layer& layer = (*it);
		if(layer.total==0)
		{
			it = mLayers.erase(it);
		}
		else
		{
			++it;
		}
	}

	// update the alpha texture
	U32 width = U2P(ALPHA_STRIDE);
	U32 height = U2P(ALPHA_STRIDE);
	for(I32 k = 0; k < mLayers.size(); k++)
	{
		Layer& layer = mLayers[k];
		Image* image = GNEW(Image); CHECK(image);
		image->Width(width);
		image->Height(height);
		image->PixelFormat(PF_ALPHA);
		image->DataType(DT_UNSIGNED_BYTE);
		image->MipmapCount(1);
		if(k==0)
		{
			image->Mipmap(0,NULL,width*height*sizeof(U8));
			U8* data = (U8*)image->Mipmap(0);
			for(U32 j = 0; j < height; j++)
			{
				for( U32 i = 0; i < width; i++)
				{
					U8& alpha = layer.alpha[i+j*width];
					U8& mask = mMask[i+j*width];
					if(mask == 0) data[i+j*width] = (U8)(((F32)alpha)/255.0f*127.0f);
					else data[i+j*width] = (U8)(((F32)alpha)/255.0f*127.0f)+128;
				}
			}
			layer.texture->Load(image);
			layer.primitive->SetShader(dynamic_cast<Shader*>(mShaderKey->Ptr()), "base");
		}
		else
		{
			image->Mipmap(0,&layer.alpha[0],width*height*sizeof(U8));
			layer.texture->Load(image);
			layer.primitive->SetShader(dynamic_cast<Shader*>(mShaderKey->Ptr()), "layer");
		}
	}

	UNGUARD;
}
Esempio n. 3
0
void Conversions::Convert(Image& Source, Image& Dest)
{
   CheckSameSize(Source, Dest);

   if (SameType(Source, Dest))
   {
      Copy(Source, Dest);
      return;
   }

   switch (Dest.DataType())
   {
   case SImage::U8:
      Kernel(to_uchar, Source, Dest, Source.Step(), Dest.Step());
      break;
   case SImage::S8:
      Kernel(to_char, Source, Dest, Source.Step(), Dest.Step());
      break;
   case SImage::U16:
      Kernel(to_ushort, Source, Dest, Source.Step(), Dest.Step());
      break;
   case SImage::S16:
      Kernel(to_short, Source, Dest, Source.Step(), Dest.Step());
      break;
   case SImage::U32:
      Kernel(to_uint, Source, Dest, Source.Step(), Dest.Step());
      break;
   case SImage::S32:
      Kernel(to_int, Source, Dest, Source.Step(), Dest.Step());
      break;
   case SImage::F32:
      Kernel(to_float, Source, Dest, Source.Step(), Dest.Step());
      break;
   case SImage::F64:
      Kernel(to_double, Source, Dest, Source.Step(), Dest.Step());
      break;
   case SImage::NbDataTypes:
   default:
      throw cl::Error(CL_IMAGE_FORMAT_NOT_SUPPORTED, "Unsupported data type");
   }
   
}
Esempio n. 4
0
void Conversions::Scale(Image& Source, Image& Dest, int Offset, float Ratio)
{
   CheckSameSize(Source, Dest);

   switch (Dest.DataType())
   {
   case SImage::U8:
      Kernel(scale_to_uchar, Source, Dest, Source.Step(), Dest.Step(), Offset, Ratio);
      break;
   case SImage::S8:
      Kernel(scale_to_char, Source, Dest, Source.Step(), Dest.Step(), Offset, Ratio);
      break;
   case SImage::U16:
      Kernel(scale_to_ushort, Source, Dest, Source.Step(), Dest.Step(), Offset, Ratio);
      break;
   case SImage::S16:
      Kernel(scale_to_short, Source, Dest, Source.Step(), Dest.Step(), Offset, Ratio);
      break;
   case SImage::U32:
      Kernel(scale_to_uint, Source, Dest, Source.Step(), Dest.Step(), Offset, Ratio);
      break;
   case SImage::S32:
      Kernel(scale_to_int, Source, Dest, Source.Step(), Dest.Step(), Offset, Ratio);
      break;
   case SImage::F32:
      Kernel(scale_to_float, Source, Dest, Source.Step(), Dest.Step(), Offset, Ratio);
      break;
   case SImage::F64:
      Kernel(scale_to_double, Source, Dest, Source.Step(), Dest.Step(), Offset, Ratio);
      break;
   case SImage::NbDataTypes:
   default:
      throw cl::Error(CL_IMAGE_FORMAT_NOT_SUPPORTED, "Unsupported data type");
   }

}
Esempio n. 5
0
/*
====================
build
====================
*/
VOID Game::build()
{
    GUARD(Game::build);

    // build the color texture
    Image* image = GNEW(Image);
    CHECK(image);
    image->Width(256);
    image->Height(256);
    image->Depth(1);
    image->PixelFormat(PF_RGBA);
    image->DataType(DT_UNSIGNED_BYTE);
    mColorTexPtr = GNEW(Texture);
    CHECK(mColorTexPtr);
    mColorTexPtr->Load(image);

    // build the color rt
    mColorRTPtr = GNEW(Target(mColorTexPtr.Ptr()));
    CHECK(mColorRTPtr);

    // build the primitive
    mQuadPtr = GNEW(Primitive);
    CHECK(mQuadPtr);
    mQuadPtr->SetType(Primitive::PT_TRIANGLES);

    // set the wvp
    Constant* wvp_constant_ptr = GNEW(Constant);
    CHECK(wvp_constant_ptr);
    wvp_constant_ptr->SetMatrix(Matrix());
    mQuadPtr->SetConstant("gWVP",wvp_constant_ptr);

    // set the color texture
    Constant* texture_constant_ptr = GNEW(Constant);
    CHECK(texture_constant_ptr);
    texture_constant_ptr->SetTexture(mColorTexPtr.Ptr());
    mQuadPtr->SetConstant("gBaseTex",texture_constant_ptr);

    // set the shader
    Str shader_key_name = "shader/default.xml";
    KeyPtr shader_key_ptr = Key::Find(shader_key_name.c_str());
    if(shader_key_ptr == NULL)
    {
        Shader*shader = GNEW(Shader);
        CHECK(shader);
        shader->Load(GLoad(shader_key_name.c_str()));
        shader_key_ptr = GNEW(Key(shader_key_name.c_str(), shader));
        CHECK(shader_key_ptr);
    }
    mKeys.push_back(shader_key_ptr);
    mQuadPtr->SetShader(dynamic_cast<Shader*>(shader_key_ptr->Ptr()),"p0");

    // build the vertex buffer
    F32 x = 0.0f, y = 0.0f, w = 256, h = 256;
    DVT vertexes[] =
    {
        {x,		y,		0,		0,		0},
        {x+w,	y,		0,		1,		0},
        {x+w,	y+h,	0,		1,		1},
        {x,		y+h,	0,		0,		1},
    };
    VertexBufferPtr vb_ptr = GNEW(VertexBuffer);
    CHECK(vb_ptr);
    {
        GDataPtr vd_ptr = GNEW(GData);
        CHECK(vd_ptr);
        vd_ptr->Size(3*sizeof(U32) + 3*sizeof(U8) + sizeof(vertexes));
        U8*data_ptr = (U8*)vd_ptr->Ptr();
        *(U32*)data_ptr = MAKEFOURCC('G','V','B','O');
        data_ptr += sizeof(U32);
        *(U32*)data_ptr = sizeof(vertexes)/sizeof(DVT);
        data_ptr += sizeof(U32);
        *(U32*)data_ptr = sizeof(DVT);
        data_ptr += sizeof(U32);
        *(U8*)data_ptr = 2;
        data_ptr += sizeof(U8);
        *(U8*)data_ptr = VertexBuffer::VT_3F;
        data_ptr += sizeof(U8);
        *(U8*)data_ptr = VertexBuffer::VT_2F;
        data_ptr += sizeof(U8);
        ::memcpy(data_ptr, vertexes, sizeof(vertexes));
        data_ptr += sizeof(vertexes);
        vb_ptr->Load(vd_ptr.Ptr());
    }
    mQuadPtr->SetVertexBuffer(vb_ptr.Ptr());

    // build the index
    const U16 indexes[] = { 3, 0, 2, 2, 0, 1 };
    IndexBufferPtr ib_ptr = GNEW(IndexBuffer);
    CHECK(ib_ptr);
    {
        GDataPtr id_ptr = GNEW(GData);
        CHECK(id_ptr);
        id_ptr->Size(3*sizeof(U32) + sizeof(indexes));
        U8*data_ptr = (U8*)id_ptr->Ptr();
        *(U32*)data_ptr = MAKEFOURCC('G','I','B','O');
        data_ptr += sizeof(U32);
        *(U32*)data_ptr = sizeof(indexes)/sizeof(U16);
        data_ptr += sizeof(U32);
        *(U32*)data_ptr = sizeof(U16);
        data_ptr += sizeof(U32);
        ::memcpy(data_ptr, &indexes[0], sizeof(indexes));
        data_ptr += sizeof(indexes);
        ib_ptr->Load(id_ptr.Ptr());
    }
    mQuadPtr->SetIndexBuffer(ib_ptr.Ptr());

    // build the bounding box
    BoundingBox box;
    box.set(MAX_F32,MAX_F32,MAX_F32,MIN_F32,MIN_F32,MIN_F32);
    for(U32 i = 0; i < sizeof(vertexes)/sizeof(DVTN); i++)box.expand(vertexes[i].point);
    mQuadPtr->SetBox(box);

    UNGUARD;
}
Esempio n. 6
0
/*
====================
Find
====================
*/
U32 EChunk::Find(const CHAR* name, const Vector2& st)
{
	GUARD(EChunk::Find);	

	CHECK(name);
	
	// searche the layer table
	for(U32 i = 0; i < mLayers.size(); i++)
	{
		if(mLayers[i].name == name && mLayers[i].st == st) return i;
	}

	// create the new layer
	Layer layer;
	layer.name = name;
	layer.st = st;
	layer.alpha.resize(U2P(ALPHA_STRIDE)*U2P(ALPHA_STRIDE), 0);
	layer.total = 0;

	// create the new primitive
	layer.primitive = GNEW(Primitive); CHECK(layer.primitive);
	layer.primitive->SetType(Primitive::PT_TRIANGLES);
	layer.primitive->SetVertexBuffer(mVBPtr.Ptr());
	layer.primitive->SetIndexBuffer(mIBPtr.Ptr());	
	layer.primitive->SetConstant("gWVP",GNEW(Constant(Matrix())));

	// get the color texture
	KeyPtr texture_key_ptr = Key::Find(name);
	if(texture_key_ptr == NULL)
	{
		const Image* image = Image::Load(GLoad(name)); CHECK(image);
		BaseTexture* base_texture = GNEW(Texture); CHECK(base_texture);
		base_texture->Load(image);
		texture_key_ptr = GNEW(Key(name, base_texture)); CHECK(texture_key_ptr);
	}
	mKeys.push_back(texture_key_ptr);
	layer.primitive->SetConstant("gColorTex",GNEW(Constant((BaseTexture*)texture_key_ptr->Ptr())));

	// set the scale st	
	layer.primitive->SetConstant("gScaleST",GNEW(Constant(Vector4(st[0],st[1],0,0))));	

	// set the alpha
	U32 width = U2P(ALPHA_STRIDE);
	U32 height = U2P(ALPHA_STRIDE);
	Image* image = GNEW(Image); CHECK(image);
	image->Width(width);
	image->Height(height);
	image->PixelFormat(PF_ALPHA);
	image->DataType(DT_UNSIGNED_BYTE);
	image->MipmapCount(1);
	image->Mipmap(0,&layer.alpha[0],width*height*sizeof(U8));		
	BaseTexture *alpha_texture = GNEW(Texture); CHECK(alpha_texture);
	alpha_texture->Load(image);
	layer.primitive->SetConstant("gAlphaTex",GNEW(Constant(alpha_texture)));
	layer.texture = alpha_texture;

	// load the shader
	layer.primitive->SetShader(dynamic_cast<Shader*>(mShaderKey->Ptr()), "layer");
	
	// add the layer to the table
	mLayers.push_back(layer);
	return mLayers.size() - 1;

	UNGUARD;
}