//---------------------------------------------------------------------------
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;
}
示例#2
0
//---------------------------------------------------------------------------
void __fastcall TFormMain::FormCreate(TObject *Sender)
{
  SetFileName("");
  PaintBox->ControlStyle = PaintBox->ControlStyle << csOpaque;
  SetZoom(11);

  Graphics::TBitmap* BM = new Graphics::TBitmap;
  __try
  {
    BM->Width = 64;
    BM->Height = 64;
    
    for (int i = 0; i < YETI_TEXTURE_MAX; i++)
    {
      for (int y = 0; y < 64; y++)
      {
        for (int x = 0; x < 64; x++)
        {
          int c = textures[i][y][x];
          BM->Canvas->Pixels[x][y] = (TColor) RGB(
            palette[c][0], palette[c][1], palette[c][2]);
        }
      }
      TListItem* LI = ListView->Items->Add();
      LI->Caption = String("#") + i;
      LI->ImageIndex = ILTextures->Add(BM, NULL);
    }
  }
  __finally
  {
    BM->Free();
  }
  ListView->ItemIndex = 0;
}
void __fastcall TCustomDrawDemoEditorForm::mruBkImagePropertiesButtonClick(
      TObject *Sender)
{
  if (OpenDialog->Execute()){
    Graphics::TBitmap *ABitmap = new Graphics::TBitmap();
    ABitmap->LoadFromFile(OpenDialog->FileName);
    GetSelectedDrawItem()->Bitmap = ABitmap;
    ((TcxCustomEdit*)Sender)->EditValue = "User Defined";
    CustomDrawDemoMainForm->cxDBVerticalGrid->Invalidate();
  }
}
void LoadImageFromRes(Graphics::TBitmap* ABitmap, String AResName)
{
    Graphics::TBitmap* Bitmap = new Graphics::TBitmap();
    TResourceStream* Rs = new TResourceStream((int)HInstance, AResName, PChar(RT_RCDATA));
    try {
        Bitmap->LoadFromStream(Rs);
        ABitmap->Assign(Bitmap);
    }
    __finally {
        delete Bitmap;
        delete Rs;
    }
}
示例#5
0
/** basically, it converts =)
    it's just a converter, basically */
void convert (AnsiString textfile, AnsiString bmpfile)
{
    int i,j,left=5,top=5,x=left,y=top;
    Graphics::TBitmap *Bitmap = new Graphics::TBitmap;
    TExprClass *Expr;
    char Str[10000];

    Bitmap->Width = 1000;
    Bitmap->Height = 4000;

    TList *Text = loadText(textfile, new TList);
#ifdef DEBUG
    for(int i=0; i<Text->Count; ++i)
        printf("\"%s\"\n", (char *)Text->Items[i]);
#endif

    /*
    Text->Add("String(\"# Тема - JOB \")");
    Text->Add("String(\"Вариант   1, задача 1.\")");
    Text->Add("String(\"Вычислить предел:\")");
    Text->Add("lim(x->4, (-3*x^2+15*x)/(3*x^2+15*x))=...");
    Text->Add("String(@Часть преподавателя )");
    Text->Add("String(\"Тема - JOB \")");
    Text->Add("String(ВАРИАНТ 1, решение задачи 1, ключ 865)");
    Text->Add("lim(x->4, (-3*x^2+15*x)/(3*x^2+15*x))=(1/9)");
    */

    TFont *font = new TFont;
    font->PixelsPerInch = 1000;
    font->Name = "Trebuchet MS";
    font->Size=10;
    for(i=0; i<Text->Count; i++)
    {
        strcpy(Str, (char*)Text->Items[i]);
        Expr = BuildExpr(Str);
        Expr->Canvas = Bitmap->Canvas;
        Expr->Font = font;
        Expr->Draw(left, y, 1000, 4000);
        y = y + Expr->Height;
        if (x<Expr->Width)
            x = Expr->Width;
        delete Expr;
    }
    Bitmap->Width = x+left + 5;
    Bitmap->Height = y + 5;
    Bitmap->SaveToFile(bmpfile);
    delete Bitmap;
    delete font;
}
示例#6
0
Pixmap::Pixmap(const string &f){
        Graphics::TBitmap* AuxBMP = new Graphics::TBitmap();
        AuxBMP->LoadFromFile(f.c_str());
        cols=AuxBMP->Width;
        rows=AuxBMP->Height;
        matrix = new colorRGBA[cols*rows];
        int c = 0;
        for (int i = 0; i < rows; i++)
                for (int j = 0; j < cols; j++) {
                        c = i * cols + j;
                        matrix[c][0]=GetRValue(AuxBMP->Canvas->Pixels[j][rows-i-1]);
                        matrix[c][1]=GetGValue(AuxBMP->Canvas->Pixels[j][rows-i-1]);
                        matrix[c][2]=GetBValue(AuxBMP->Canvas->Pixels[j][rows-i-1]);
                }
}
示例#7
0
HBITMAP mcmUpdateText(HANDLE hObj, HBITMAP hDest, LPCSTR pText)
{
	ASSERT(hObj);
	ASSERT(hDest);
	CItem *pItem = (CItem *)hObj;

	// Draw object to hDest
	Graphics::TBitmap *pDest = new Graphics::TBitmap;
	pDest->Handle = hDest;
	pDest = pItem->Draw(pDest, pText);

	HBITMAP hb = pDest->ReleaseHandle();
	delete pDest;
	return (hb != hDest) ? hb : NULL;
}
示例#8
0
void __fastcall TMode::TurnBoard ()
{

Graphics::TBitmap *pBitmap = new Graphics::TBitmap();
pBitmap->LoadFromResourceName(0,"board");
Game->Board->Left=0;
Game->Board->Top=0;
Game->Board->Width=pBitmap->Width;
Game->Board->Height=pBitmap->Height;


for(int j=0; j < pBitmap->Height; j++)

Game->Board->Canvas->CopyRect(Rect(0,j,pBitmap->Width,j+1),
pBitmap->Canvas,Rect(0,j,pBitmap->Width,j+1));

delete pBitmap;

}
示例#9
0
void __fastcall THSVFormOrg::btn_Hue_Img_loadClick(TObject * Sender)
{
    if (!OpenDialog1->Execute())
	return;
    String Fpath;
    //Hue_Img->Picture->LoadFromFile(Fpath);

    Fpath = OpenDialog1->FileName;
    Graphics::TBitmap * Bitmap;

    Graphics::TBitmap * RefGraph;
    RefGraph = new Graphics::TBitmap();
    RefGraph->Height = Hue_Img->Height;
    RefGraph->Width = Hue_Img->Width;
    RefGraph->LoadFromFile(Fpath);
    Hue_Img->Picture->Graphic = RefGraph;
//        Hue_Img->Canvas->Draw(0,0,RefGraph);
    delete RefGraph;

}
示例#10
0
void __fastcall TMatdet::Button4Click(TObject *Sender)
{
        Graphics::TBitmap * bmv = new Graphics::TBitmap();

        if ( !Memo1->Lines->Count )
                Button1->Click();
        /*Memo1->Lines->SaveToFile("txtout.txt");
        WinExec("txt2bmp.exe",SW_SHOWDEFAULT);
        Preview->Image1->Picture->LoadFromFile("out.bmp");*/

        TxtToBmp( Memo1->Lines, bmv, qvar->FontDialog1->Font, 0, 0 );
        bmv->SaveToFile( "out.bmp" );

        Preview->ImageEnIO1->LoadFromFile( "out.bmp" );
        //Preview->ImageEnProc1->Resample( -1, Screen->Height - 40, rfBSpline );

        unlink( "out.bmp" );
        delete bmv;
        
        Preview->ShowModal();
}
示例#11
0
/*

1. 103	0	241
2. 91	0	241
3.  24	0	240
4.  0	121	231
5.  0	194	209
6.  0	255	164
7.  0	255	0
8.  136	232	0
9.  173	219	0
10. 201	204	0
11. 244	172	0
12. 255	134	0
13. 255	86	0
14. 255	0	0


*/
void __fastcall TMainForm::ViewPalette1Click(TObject *Sender)
{
    Graphics::TBitmap* bmp = new Graphics::TBitmap();

    bmp->Width = 1920;
    bmp->Height = 1080;

    bmp->Canvas->Brush->Color = clWhite;
    TRect rect;
    rect.left = 0;
    rect.top  = 0;
    rect.right = 1920;
    rect.top   = 1080;

    bmp->Canvas->FillRect(rect);
    rect.left = 70;
    rect.top = 60;
    rect.right = 1850;
    rect.bottom = 1050;

    bmp->Canvas->Pen->Color = clRed;
    bmp->Canvas->Pen->Width = 3;
    bmp->Canvas->Rectangle(rect);

    int count = 0;
    for (int y = 0; y < 48; y++)
    {
        for (int x = 0; x < 54; x++)
        {
            if (count >= m_database.Count)/*this->m_Entries->Count*/
                continue;

            TRect r;
            r.left = 80+ x*32;
            r.right = 80+ x*32 +32;
            r.top = 80+ y*26;
            r.Bottom = 80 + y*26+26;
            if (r.top > 500)
            {
                r.top    += 100;
                r.bottom += 100;
            }

            TPantoneColorEntry* ee = m_database.Get(count);//(TPantoneColorEntry*)m_Entries->Items[count];
            bmp->Canvas->Brush->Color =  (TColor)RGB(ee->Red, ee->Green, ee->Blue);
            bmp->Canvas->FillRect(r);
            count++;

        }
    }

    bmp->Canvas->Brush->Color = clBlack;

    rect.left =  800;
    rect.right = 1120;
    rect.top   = 522;
    rect.bottom = 622;

    bmp->Canvas->FillRect(rect);

    /*1*/
    bmp->Canvas->Brush->Color = (TColor)RGB( 103,	0,	241);;

    rect.left =  80;
    rect.right = 100;
    rect.top   = 522;
    rect.bottom = 622;

    bmp->Canvas->FillRect(rect);

    /*2*/
    bmp->Canvas->Brush->Color = (TColor)RGB( 103,	0,	241);;

    rect.left =  100;
    rect.right = 120;
    rect.top   = 522;
    rect.bottom = 622;

    bmp->Canvas->FillRect(rect);
    /*3*/
    bmp->Canvas->Brush->Color = (TColor)RGB( 24,	0,	240);;

    rect.left =  120;
    rect.right = 140;
    rect.top   = 522;
    rect.bottom = 622;

    bmp->Canvas->FillRect(rect);
    /*4*/
    bmp->Canvas->Brush->Color = (TColor)RGB( 0,	121,	231);;

    rect.left =  140;
    rect.right = 160;
    rect.top   = 522;
    rect.bottom = 622;

    bmp->Canvas->FillRect(rect);
    /*5*/
    bmp->Canvas->Brush->Color = (TColor)RGB(0,	194,	209);;

    rect.left =  160;
    rect.right = 180;
    rect.top   = 522;
    rect.bottom = 622;

    bmp->Canvas->FillRect(rect);
    /*6*/
    bmp->Canvas->Brush->Color = (TColor)RGB( 0 ,	255,	164);;

    rect.left =  180;
    rect.right = 200;
    rect.top   = 522;
    rect.bottom = 622;

    bmp->Canvas->FillRect(rect);
    /*7*/
    bmp->Canvas->Brush->Color = (TColor)RGB( 0,	255,	0);;

    rect.left =  200;
    rect.right = 220;
    rect.top   = 522;
    rect.bottom = 622;

    bmp->Canvas->FillRect(rect);
    /*8*/
    bmp->Canvas->Brush->Color = (TColor)RGB(  136 ,	232,	0);;

    rect.left =  220;
    rect.right = 240;
    rect.top   = 522;
    rect.bottom = 622;

    bmp->Canvas->FillRect(rect);
    /*9*/
    bmp->Canvas->Brush->Color = (TColor)RGB(173,	219,	0);;

    rect.left =  240;
    rect.right = 260;
    rect.top   = 522;
    rect.bottom = 622;

    bmp->Canvas->FillRect(rect);
    /*10*/
    bmp->Canvas->Brush->Color = (TColor)RGB( 201,	204,	0);;

    rect.left =  260;
    rect.right = 280;
    rect.top   = 522;
    rect.bottom = 622;

    bmp->Canvas->FillRect(rect);
    /*11*/
    bmp->Canvas->Brush->Color = (TColor)RGB( 244,	172,	0);;

    rect.left =  280;
    rect.right = 300;
    rect.top   = 522;
    rect.bottom = 622;

    bmp->Canvas->FillRect(rect);
    /*12*/
    bmp->Canvas->Brush->Color = (TColor)RGB( 103,	0,	241);;

    rect.left =  300;
    rect.right = 320;
    rect.top   = 522;
    rect.bottom = 622;

    bmp->Canvas->FillRect(rect);
    /*13*/
    bmp->Canvas->Brush->Color = (TColor)RGB( 255,	86,	0);;

    rect.left =  320;
    rect.right = 340;
    rect.top   = 522;
    rect.bottom = 622;

    bmp->Canvas->FillRect(rect);
    /*14*/
    bmp->Canvas->Brush->Color = (TColor)RGB( 255, 0,0);;

    rect.left =  340;
    rect.right = 360;
    rect.top   = 522;
    rect.bottom = 622;

    bmp->Canvas->FillRect(rect);


    bmp->SaveToFile(L"pantone.bmp");
    delete bmp;

    PaletteForm->Show();
}
//---------------------------------------------------------------------------
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;
}
示例#13
0
//---------------------------------------------------------------------------
void __fastcall TMainForm::IdTCPServerExecute(TIdPeerThread *AThread)
{

    AnsiString s;
    AnsiString sCommand;
    AnsiString sAction;
    TFileStream* tmpfStream;
    Graphics::TBitmap *tbm;

try
{
s = UpperCase(AThread->Connection->ReadLn("",5000));

sCommand = s.SubString (1,3);
sAction = s.SubString(5,s.Length()-4);

if (sCommand == "LST")
   {
    AThread->Connection->WriteLn(GetList());
    AThread->Connection->Disconnect();
   }
else if (sCommand == "PIC")
    {
    if (FileExists(ExtractFileDir(ParamStr(0)) + "\\images\\" + sAction))
        {
        lstRequests->Items->Add("Serving up: " + sAction);
        // open file stream to image requested
        tmpfStream = new TFileStream(ExtractFileDir(ParamStr(0)) + "\\images\\" + sAction,fmOpenRead |fmShareDenyNone);
        // copy file stream to write stream
        AThread->Connection->OpenWriteBuffer(-1);
        AThread->Connection->WriteStream(tmpfStream,true,false);
        AThread->Connection->CloseWriteBuffer();
        // free the file stream
        delete tmpfStream;
        tmpfStream=NULL;
        lstRequests->Items->Add("File transfer completed");
        AThread->Connection->Disconnect();
        }
        else
          {AThread->Connection->WriteLn("ERR - Requested file does not exist");
           AThread->Connection->Disconnect();
          }
    }
else if (sCommand == "SRN")
   {
    // in production version you would use a unique file name such as one generated
    // from a tickcount plus clint IP / id etc.
    // take snapshot
    lstRequests->Items->Add("Taking screen snap shot");

    tbm = new Graphics::TBitmap();

    ScreenShot(0,0,Screen->Width,Screen->Height,tbm);
    if (FileExists (ExtractFileDir(ParamStr(0)) + "\\images\\ScreenShot.BMP"))
        DeleteFile(ExtractFileDir(ParamStr(0)) + "\\images\\ScreenShot.BMP");
    tbm->SaveToFile(ExtractFileDir(ParamStr(0)) + "\\images\\ScreenShot.BMP");
    tbm->FreeImage();
    delete tbm;
    tbm=NULL;

    lstRequests->Items->Add("Serving up: SCREENSHOT.BMP");
    // open file stream to image requested
    tmpfStream = new TFileStream(ExtractFileDir(ParamStr(0)) + "\\images\\ScreenShot.BMP",fmOpenRead | fmShareDenyNone);
    // copy file stream to write stream
    AThread->Connection->OpenWriteBuffer(-1);
    AThread->Connection->WriteStream(tmpfStream,true,false);
    AThread->Connection->CloseWriteBuffer();
    // free the file stream
    delete tmpfStream;
    tmpfStream=NULL;
    lstRequests->Items->Add("File transfer completed");
    AThread->Connection->Disconnect();
    }
else
if ((sCommand != "LST") && (sCommand != "PIC") && (sCommand != "SRN"))
     {
     AThread->Connection->WriteLn("ERR : Unknown command / action");
     AThread->Connection->Disconnect();
     }

     }


catch (Exception& E)
{
ShowMessage(E.Message);
}


}
示例#14
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;	
}
示例#15
0
// Class functions.
TPresError
TGUIView::SetStyle( const char  *inStyleName )
{
  // Load the colors and widths of view elements from a bitmap resource or file.
  // The rows of the bitmap represent the elements in the order given by
  // the TGUIElements enumeration in GUI.h. An element's width is taken
  // by counting the number of pixels in its row that have the same color
  // as the leftmost one.

  if( inStyleName == NULL || *inStyleName == '\0' )
    return presNoError;

  TPresError  result = presNoError;
  Graphics::TBitmap   *bitmap = new Graphics::TBitmap();

  std::string fileName( inStyleName );
  for( std::string::iterator i = fileName.begin(); i != fileName.end(); ++i )
    *i = toupper( *i );
  fileName += ".BMP";

  // Look for a bitmap resource for the style given.
  try
  {
    bitmap->LoadFromResourceName( ( int )HInstance, fileName.c_str() );
  }
  catch( const EResNotFound& )
  {
    result = presResNotFoundError;
  }

  // No resource found, look for a bitmap file in the application default path.
  if( result == presResNotFoundError )
  {
    result = presNoError;
    try
    {
      bitmap->LoadFromFile( fileName.c_str() );
    }
    catch( ... )
    {
      result = presFileOpeningError;
    }
  }

  // No file found, look in the resource directory.
  if( result == presFileOpeningError )
  {
    result = presNoError;

    Util::TPath curPath;
    fileName = curPath + fileName;

    try
    {
      bitmap->LoadFromFile( fileName.c_str() );
    }
    catch( ... )
    {
      result = presFileOpeningError;
      gPresErrors.AddError( result, fileName.c_str() );
    }
  }

  if( result == presNoError )
  {
    for( int i = 0; i < MIN( int( numGUIElements ), bitmap->Height ); ++i )
    {
      TColor  curColor = bitmap->Canvas->Pixels[ 0 ][ i ];
      ElementColors[ i ].cl = curColor;
      int j = 0;
      while( j < bitmap->Width && bitmap->Canvas->Pixels[ j ][ i ] == curColor )
        ++j;
      ElementWidths[ i ] = j;
    }
  }

  delete bitmap;
  return result;
}
示例#16
0
// ---------------------------------------------------------------------------
void __fastcall ShmThread::Execute()
{
    NameThreadForDebugging("ShmThread");

    status = shmbuf;
    cmd = shmbuf +sizeof(char);
    data = shmbuf +sizeof(char)+sizeof(char);
    shmbuf[0] = SHM_READY;
    shme->ResetEvent();

    while (1)
    {
        shme->WaitFor(INFINITE);

        if (status[0] != SHM_RREADY)
        {
            deb("shm signaled");
            shme->ResetEvent();
            continue;
        }

        // deb("shm cmd %d", cmd[0]);

        shme->ResetEvent();
        // Synchronize(Do);
        // shme->SetEvent();
        // }
        // }
        //
        // void __fastcall ShmThread::Do(void)
        // {

        if (!shmbuf)
        {
            MessageBox(Application->MainFormHandle, "error no shmbuf", "err", MB_OK);
            ExitProcess(0);
        }

        switch(cmd[0])
        {
            case LO_UPDWNDPIC:
            // deb("L:O_UPDWNDPIC");
            // ReadFile(hPipe, &hid, sizeof(hid), &dwRead, false);
            HANDLE hid;
            LPVOID p;
            HDC hdc;
            BITMAPINFO *pbmi;
            LPVOID dbuf;
            Graphics::TBitmap *ub;

            memcpy(&hid, data, sizeof(hid));
            // data += sizeof(HANDLE);

            bool fail;
            fail = false;
            wcs->Acquire();
            bool found;
            found = false;
            WNDBUTTONS *pwnd;
            pwnd = NULL;

            try
            {
                pwnd = (WNDBUTTONS*)hid;
                for (wnd_buttons_v::iterator it = wnd_buttons.begin();it!=wnd_buttons.end();it++)
                {
                    // deb("%x > %x",(*it)->id,hid);

                    if ((*it)->id == hid)
                    {
                        // deb("found %x",hid);
                        found = true;
                        break;
                    }
                }

                if (!found || IsBadReadPtr(pwnd, sizeof(WNDBUTTONS)))
                {
                    fail = true;
                }
                else
                {

                    // deb(" LO_UPDWNDPIC => %x ", pwnd);
                    // deb("%d:%d", pwnd->rect.left, pwnd->rect.top);

                    if (pwnd->pic)
                    {
                        // deb(" SHM:LO_UPDWNDPIC @ %p deleting %p", pwnd, pwnd->pic);
                        delete pwnd->pic;

                    }

                    ub = new Graphics::TBitmap();

                    pbmi = (BITMAPINFO*)(data +sizeof(HANDLE));
                    dbuf = data +sizeof(BITMAPINFO)+sizeof(HANDLE);

                    hdc = CreateCompatibleDC(0);

                    ub->SetSize(pwnd->rect.right - pwnd->rect.left, pwnd->rect.bottom - pwnd->rect.top);

                    if (!SetDIBits(hdc, ub->Handle, 0, pbmi->bmiHeader.biHeight, dbuf, pbmi, DIB_PAL_COLORS))
                    {
                        deb("bmi->h: %d bits %d", pbmi->bmiHeader.biHeight, pbmi->bmiHeader.biBitCount);
                        deb("bmihdr sz %d", pbmi->bmiHeader.biSize);
                        deb("updwndpic setdibits: %s", fmterr());
                    }
                    DeleteDC(hdc);

                    pwnd->pic = ub;

                }
            }
            catch(...)
            {
                char sz1[1024];
                // deb("exception in shmthread: %s", deunicode(e.Message.c_str(), sz1, sizeof(sz1)));
                deb("shmthread exception");
                fail = true;
                data[0] = SHM_FAIL;
            }

            if (!fail && found)
            {
                if (pwnd->visible)
                {
                    extern TEvent *bgraphics_event;

                    bgraphics_event->SetEvent();
                    graphics_event->SetEvent();
                }

                // deb("success update %x %d:%d v:%d", hid, pwnd->rect.left, pwnd->rect.top, pwnd->visible);
                data[0] = SHM_READY;
            }
            else
            {
                // deb("unsuccessfull update of %x", hid);
                data[0] = SHM_FAIL;
            }
            wcs->Release();
            break;

            /////////////////            /////////////////            /////////////////            /////////////////            /////////////////

            case LO_UPDATEBGBITMAP:
            //shmb->Acquire();
            // deb("case LO_UPDATEBGBITMAP:");
            extern Graphics::TBitmap *BackgroundBitmap;
            BackgroundBitmap = (Graphics::TBitmap*)1;
            procId = (DWORD*)data;

            BackgroundProcessId = (DWORD)*procId;

            bgupd->Enter();

            memcpy(&bgbmi, data+sizeof(DWORD) , sizeof(bgbmi));

            if (!bgbmi.bmiHeader.biSizeImage ||!bgbmi.bmiHeader.biHeight)
                deb("bmi bg height %d", bgbmi.bmiHeader.biHeight);
         //   deb("size %d", bgbmi.bmiHeader.biSizeImage);

            try
            {
                memcpy(bgbuf, data +sizeof(bgbmi)+sizeof(DWORD), bgbmi.bmiHeader.biSizeImage);
            }
            catch(...)
            {
                deb("exception while shmcopy bg");
            }
            //

            bgupd->Leave();

            bg_change->SetEvent();
         //   shmb->Release();

            graphics_event->SetEvent();

      //      deb("done bg upd");
            data[0] = SHM_READY;
            break;

            default:
            deb("unknwon shm cmd %d", *cmd);
            break;
        }

        *status = SHM_READY;

        // shmb->Release();

    }
}
示例#17
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;
}