//---------------------------------------------------------------------------
int __stdcall run(Block *aBlock)
{
	if(aBlock->input.size() != 1 || aBlock->input[0].getConnectedType().IsEmpty())
		return 1;

	Graphics::TBitmap* picture = new Graphics::TBitmap();
	AnsiString connectedType(aBlock->input[0].getConnectedType());
	
	if(connectedType == "Bitmap1bit")
		picture->Assign(const_cast<Graphics::TBitmap*>(&(IBitmap1bit::getBitmap(aBlock->input[0].getObject()))));

	else	if(connectedType == "Bitmap4bit")
		picture->Assign(const_cast<Graphics::TBitmap*>(&(IBitmap4bit::getBitmap(aBlock->input[0].getObject()))));

	else	if(connectedType == "Bitmap8bit")
		picture->Assign(const_cast<Graphics::TBitmap*>(&(IBitmap8bit::getBitmap(aBlock->input[0].getObject()))));

	else	if(connectedType == "Bitmap16bit")
		picture->Assign(const_cast<Graphics::TBitmap*>(&(IBitmap16bit::getBitmap(aBlock->input[0].getObject()))));

	else	if(connectedType == "Bitmap24bit")
		picture->Assign(const_cast<Graphics::TBitmap*>(&(IBitmap24bit::getBitmap(aBlock->input[0].getObject()))));

	else	if(connectedType == "Bitmap32bit")
		picture->Assign(const_cast<Graphics::TBitmap*>(&(IBitmap32bit::getBitmap(aBlock->input[0].getObject()))));

	int mode=aBlock->getConfig()->getInt("mode");

	if(mode == 0)
	{
		if(!Binarization(picture))
		{
			aBlock->output[0].setErrorCode(2);
			aBlock->output[0].setErrorDescription("Pusta bitmapa");
			picture->Free();
			return 2;
		}
	}
	else
	{
		int limitB(aBlock->getConfig()->getInt("limitB"));
		if(!BinarizationBalance(picture,limitB,clWhite,clBlack))
		{
			aBlock->output[0].setErrorCode(2);
			aBlock->output[0].setErrorDescription("Pusta bitmapa");
			picture->Free();
			return 2;
		}
	}
    
	TypeConfig* copy = IBitmap1bit::getNew();

	IBitmap1bit::setBitmap(copy, *picture);
	aBlock->output[0].setObject(*copy);

	picture->Free();
	delete copy;

	return 0;
}
//---------------------------------------------------------------------------
int __stdcall run(Block *aBlock)
{
	if(aBlock->input.size() != 1 || aBlock->input[0].getConnectedType().IsEmpty())
		return 1;

	Graphics::TBitmap* picture = new Graphics::TBitmap();
	AnsiString connectedType(aBlock->input[0].getConnectedType());
	
	if(connectedType == "Bitmap1bit")
		picture->Assign(const_cast<Graphics::TBitmap*>(&(IBitmap1bit::getBitmap(aBlock->input[0].getObject()))));

	else	if(connectedType == "Bitmap4bit")
		picture->Assign(const_cast<Graphics::TBitmap*>(&(IBitmap4bit::getBitmap(aBlock->input[0].getObject()))));

	else	if(connectedType == "Bitmap8bit")
		picture->Assign(const_cast<Graphics::TBitmap*>(&(IBitmap8bit::getBitmap(aBlock->input[0].getObject()))));

	else	if(connectedType == "Bitmap16bit")
		picture->Assign(const_cast<Graphics::TBitmap*>(&(IBitmap16bit::getBitmap(aBlock->input[0].getObject()))));

	else	if(connectedType == "Bitmap24bit")
		picture->Assign(const_cast<Graphics::TBitmap*>(&(IBitmap24bit::getBitmap(aBlock->input[0].getObject()))));

	else	if(connectedType == "Bitmap32bit")
		picture->Assign(const_cast<Graphics::TBitmap*>(&(IBitmap32bit::getBitmap(aBlock->input[0].getObject()))));
	Graphics::TBitmap** pict;
	if(picture->Width==picture->Height)
	{
		pict = Fimage(picture);
		if(pict[0]==NULL || pict[1]==NULL)//na razie dzial tylko dla obrazow NxN
		{
                aBlock->output[0].setErrorCode(2);
                aBlock->output[0].setErrorDescription("Pusta bitmapa");
                picture->Free();
                return 2;
		}
	}
	else {
                aBlock->output[0].setErrorCode(2);
                aBlock->output[0].setErrorDescription("Bitmapa musi byc kwadratowa");
                picture->Free();
                return 2;
	}

	TypeConfig* copy1;
    TypeConfig* copy2;

    copy1 = IBitmap8bit::getNew();
    IBitmap8bit::setBitmap(copy1, *pict[0]);

    copy2 = IBitmap8bit::getNew();
    IBitmap8bit::setBitmap(copy2, *pict[1]);


	aBlock->output[0].setObject(*copy1);
	aBlock->output[1].setObject(*copy2);
	
	pict[0]->Free();
    pict[1]->Free();
    delete pict;
	delete copy1;
    delete copy2;

	return 0;
}
//---------------------------------------------------------------------------
int __stdcall run(Block *aBlock)
{
	if(aBlock->input.size() != 1 || aBlock->input[0].getConnectedType().IsEmpty()||aBlock->getConfig()->getString("path").IsEmpty())
		return 1;

	Graphics::TBitmap* picture = new Graphics::TBitmap();
	AnsiString connectedType(aBlock->input[0].getConnectedType());

	if(connectedType == "Bitmap1bit")
		picture->Assign(const_cast<Graphics::TBitmap*>(&(IBitmap1bit::getBitmap(aBlock->input[0].getObject()))));

	else if(connectedType == "Bitmap4bit")
		picture->Assign(const_cast<Graphics::TBitmap*>(&(IBitmap4bit::getBitmap(aBlock->input[0].getObject()))));

	else	if(connectedType == "Bitmap8bit")
		picture->Assign(const_cast<Graphics::TBitmap*>(&(IBitmap8bit::getBitmap(aBlock->input[0].getObject()))));

	else if(connectedType == "Bitmap16bit")
		picture->Assign(const_cast<Graphics::TBitmap*>(&(IBitmap16bit::getBitmap(aBlock->input[0].getObject()))));

	else	if(connectedType == "Bitmap24bit")
		picture->Assign(const_cast<Graphics::TBitmap*>(&(IBitmap24bit::getBitmap(aBlock->input[0].getObject()))));

	else	if(connectedType == "Bitmap32bit")
		picture->Assign(const_cast<Graphics::TBitmap*>(&(IBitmap32bit::getBitmap(aBlock->input[0].getObject()))));


	AnsiString path(aBlock->getConfig()->getString("path"));
	AnsiString bitrate(aBlock->getConfig()->getString("bitrate"));

	if(bitrate == "Bitmap1bit")
	{
		if(!SaveImage(picture,path,bit_1))
		{
			aBlock->output[0].setErrorCode(2);
			aBlock->output[0].setErrorDescription("B³¹d zapisu obrazu");
			picture->Free();
			return 2;
		}
	}
	else if(bitrate == "Bitmap4bit")
	{
		if(!SaveImage(picture,path,bit_4))
		{
			aBlock->output[0].setErrorCode(2);
			aBlock->output[0].setErrorDescription("B³¹d zapisu obrazu");
			picture->Free();
			return 2;
		}
	}
	else if(bitrate == "Bitmap8bit")
	{
		if(!SaveImage(picture,path,bit_8))
		{
			aBlock->output[0].setErrorCode(2);
			aBlock->output[0].setErrorDescription("B³¹d zapisu obrazu");
			picture->Free();
			return 2;
		}
	}
	else if(bitrate == "Bitmap16bit")
	{
		if(!SaveImage(picture,path,bit_16))
		{
			aBlock->output[0].setErrorCode(2);
			aBlock->output[0].setErrorDescription("B³¹d zapisu obrazu");
			picture->Free();
			return 2;
		}
	}
	else if(bitrate == "Bitmap24bit")
	{
		if(!SaveImage(picture,path,bit_24))
		{
			aBlock->output[0].setErrorCode(2);
			aBlock->output[0].setErrorDescription("B³¹d zapisu obrazu");
			picture->Free();
			return 2;
		}
	}
	else if(bitrate == "Bitmap32bit")
	{
		if(!SaveImage(picture,path,bit_32))
		{
			aBlock->output[0].setErrorCode(2);
			aBlock->output[0].setErrorDescription("B³¹d zapisu obrazu");
			picture->Free();
			return 2;
		}
	}

	picture->Free();
	return 0;	
}
示例#4
0
//---------------------------------------------------------------------------
int __stdcall run(Block *aBlock)
{
	if(aBlock->input.size() != 1 || aBlock->input[0].getConnectedType().IsEmpty())
		return 1;

	Graphics::TBitmap* picture = new Graphics::TBitmap();
	AnsiString connectedType(aBlock->input[0].getConnectedType());
	
	if(connectedType == "Bitmap1bit")
		picture->Assign(const_cast<Graphics::TBitmap*>(&(IBitmap1bit::getBitmap(aBlock->input[0].getObject()))));

	else if(connectedType == "Bitmap4bit")
		picture->Assign(const_cast<Graphics::TBitmap*>(&(IBitmap4bit::getBitmap(aBlock->input[0].getObject()))));

	else	if(connectedType == "Bitmap8bit")
		picture->Assign(const_cast<Graphics::TBitmap*>(&(IBitmap8bit::getBitmap(aBlock->input[0].getObject()))));

	else if(connectedType == "Bitmap16bit")
		picture->Assign(const_cast<Graphics::TBitmap*>(&(IBitmap16bit::getBitmap(aBlock->input[0].getObject()))));

	else	if(connectedType == "Bitmap24bit")
		picture->Assign(const_cast<Graphics::TBitmap*>(&(IBitmap24bit::getBitmap(aBlock->input[0].getObject()))));

	else	if(connectedType == "Bitmap32bit")
		picture->Assign(const_cast<Graphics::TBitmap*>(&(IBitmap32bit::getBitmap(aBlock->input[0].getObject()))));

	if(!InversionColors(picture))
	{
		aBlock->output[0].setErrorCode(2);
		aBlock->output[0].setErrorDescription("Pusta bitmapa");
		picture->Free();
		return 2;
	}
    
	TypeConfig* copy;

	if(connectedType == "Bitmap1bit")
	{
		copy = IBitmap1bit::getNew();
		IBitmap1bit::setBitmap(copy, *picture);
	}
	else if(connectedType == "Bitmap4bit")
	{
		copy = IBitmap4bit::getNew();
		IBitmap4bit::setBitmap(copy, *picture);
	}
	else if(connectedType == "Bitmap8bit")
	{
		copy = IBitmap8bit::getNew();
		IBitmap8bit::setBitmap(copy, *picture);
	}
	else if(connectedType == "Bitmap16bit")
	{
		copy = IBitmap16bit::getNew();
		IBitmap16bit::setBitmap(copy, *picture);
	}
	else if(connectedType == "Bitmap24bit")
	{
		copy = IBitmap24bit::getNew();
		IBitmap24bit::setBitmap(copy, *picture);
	}
	else if(connectedType == "Bitmap32bit")
	{
		copy = IBitmap32bit::getNew();
		IBitmap32bit::setBitmap(copy, *picture);
	}

	aBlock->output[0].setObject(*copy);
	
	picture->Free();
	delete copy;

	return 0;
}