Autor Beitrag
Phantom1
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 390



BeitragVerfasst: So 10.04.05 15:59 
Hallo,

bräuchte mal eure Hilfe.

Ich möchte den TV-Eingang meiner Grafikkarte (X800Pro) benutzen.
Das Bild mit Overlay anzuzeigen ist kein problem, jedoch möchte ich jedes einzelne Bild bearbeiten bevor ich es anzeigen lassen will.

Ich dachte mir jetzt das ich das einfach mit WM_CAP_GET_VIDEOFORMAT machen kann. Ich erhalte dann jedoch eine TBitmapInfo-Struktur.

Mit dem TBitmapInfo kenne ich mich allerdings garnicht aus, wie kann ich denn da einzelne Pixel abfragen bzw setzten? besser wäre es noch
wenn ich es irgendwie in TBitmap umwandeln könnte.

Wie in dem Code unten zu sehen ist, habe ich versucht die Daten per Move() zu verschieben, klappt leider nicht.

Laut BitmapInfo.bmiHeader.biBitCount liegen die Farben in 16bit vor, bzw in 15bit da das meist signifikante Bit nicht benutzt wird.

Hier der Code:
ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ExtCtrls, StdCtrls;

type
  TForm1 = class(TForm)
    Image1: TImage;
    Panel1: TPanel;
    procedure FormCreate(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;
  CapHandle: THandle;

Const
  WM_CAP_SET_CALLBACK_FRAME = WM_USER +  5;
  WM_CAP_DRIVER_CONNECT     = WM_USER + 10;
  WM_CAP_DRIVER_DISCONNECT  = WM_USER + 11;
  WM_CAP_GET_VIDEOFORMAT    = WM_USER + 44;
  WM_CAP_SET_PREVIEW        = WM_USER + 50;
  WM_CAP_SET_OVERLAY        = WM_USER + 51;
  WM_CAP_SET_PREVIEWRATE    = WM_USER + 52;

implementation

{$R *.dfm}

function capCreateCaptureWindow(lpszWindowName  : LPCSTR;
                                dwStyle         : DWORD;
                                x, y            : Integer;
                                nWidth          : Integer;
                                nHeight         : Integer;
                                hwndParent      : HWND;
                                nID             : Integer ): HWND; stdcall;
                                external 'AVICAP32.DLL' name 'capCreateCaptureWindowA';

procedure OnFrame;
var BitmapInfo: TBitmapInfo;
begin
  FillChar(BitmapInfo, SizeOf(BitmapInfo), 0);
  SendMessage(CapHandle, WM_CAP_GET_VIDEOFORMAT, SizeOf(BitmapInfo), Integer(@BitmapInfo));

  with Form1, Image1.Picture, BitmapInfo.bmiHeader do begin
    Caption:=IntToStr(biWidth)+' '+IntToStr(biHeight)+' '+IntToStr(biBitCount);

    Bitmap.Width:=biWidth;
    Bitmap.Height:=biHeight;
    Bitmap.PixelFormat:=pf15bit;

    Move(BitmapInfo.bmiColors[0], Bitmap.ScanLine[biHeight-1]^, biSizeImage); // geht nicht !!
  end;

  //Form1.Image1.Repaint;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  CapHandle:=capCreateCaptureWindow('Video', ws_child + ws_visible, 0, 0, 720, 576, Panel1.Handle, 1);
  SendMessage(CapHandle, WM_CAP_DRIVER_CONNECT, 0, 0 );
  SendMessage(CapHandle, WM_CAP_SET_CALLBACK_FRAME, 0, Integer(@OnFrame));
  SendMessage(CapHandle, WM_CAP_SET_PREVIEWRATE, 25, 0 );
  SendMessage(CapHandle, WM_CAP_SET_PREVIEW, 1, 0 );
  //sendMessage(handle, WM_CAP_SET_OVERLAY, 1, 0 );
end;

procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  SendMessage(handle, WM_CAP_DRIVER_DISCONNECT, 0, 0);
end;

end.


mfg
Phantom1
wdbee
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 628
Erhaltene Danke: 1



BeitragVerfasst: So 10.04.05 17:09 
Nachdem was in der Hilfe steht, bekommst du so kein Bild, sondern die Beschreibung, wie das Bild aufgebaut ist (VideoFormat).

Such mal unter WM_CAP_GRAB_FRAME bzw. WM_CAP_SET_CALLBACK_FRAME. Frame heißt ein Bild bzw. Halbbild je nach Verfahren.
Phantom1 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 390



BeitragVerfasst: So 10.04.05 17:24 
user profile iconwdbee hat folgendes geschrieben:
Nachdem was in der Hilfe steht, bekommst du so kein Bild, sondern die Beschreibung, wie das Bild aufgebaut ist (VideoFormat).

Such mal unter WM_CAP_GRAB_FRAME bzw. WM_CAP_SET_CALLBACK_FRAME. Frame heißt ein Bild bzw. Halbbild je nach Verfahren.


Ich benutze doch schon WM_CAP_SET_CALLBACK_FRAME, siehe oben im Quelltext.

Ich dachte eigentlich das die Pixel dann in BitmapInfo.bmiColors[0] stehen?

Kann mir da jemand weiterhelfen?

MfG
Phantom1
wdbee
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 628
Erhaltene Danke: 1



BeitragVerfasst: So 10.04.05 17:34 
Das was hier definiert ist, ist der erste Eintrag der Farbpalette (bmiColors[1])
ausblenden Quelltext
1:
2:
3:
4:
typedef struct tagBITMAPINFO { // bmi  
   BITMAPINFOHEADER bmiHeader; 
   RGBQUAD          bmiColors[1]; 
} BITMAPINFO;


Je nach Anzahl der in bmiHeader.biClrUsed angegeben Anzahl von Farben folgen dann die anderen. Aber es ist kein Bild, nur die Beschreibung über den Bildaufbau.
Phantom1 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 390



BeitragVerfasst: So 10.04.05 18:15 
user profile iconwdbee hat folgendes geschrieben:
Das was hier definiert ist, ist der erste Eintrag der Farbpalette (bmiColors[1])

Je nach Anzahl der in bmiHeader.biClrUsed angegeben Anzahl von Farben folgen dann die anderen. Aber es ist kein Bild, nur die Beschreibung über den Bildaufbau.


Achso ist das, nur wie komme ich jetzt am einfachsten an das Bild?

Mfg
Phantom1
Phantom1 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 390



BeitragVerfasst: Mo 11.04.05 15:00 
Hab inzwischen das Problem selbst gelöst.

Vollständigkeitshalber hier die Lösung:

Die Callback function hatte noch Paramenter, über die man dann an das Bild rankommt. Komisch das das nicht in der MSDN steht?!

Desweiteren lagen die Pixel im YUV Format vor, was aber kein problem darstellt.

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
type
  PVIDEOHDR=^TVIDEOHDR;
  TVIDEOHDR=record
    lpData              : PBYTE;                // pointer to locked data buffer
    dwBufferLength      : DWORD;                // Length of data buffer
    dwBytesUsed         : DWORD;                // Bytes actually used
    dwTimeCaptured      : DWORD;                // Milliseconds from start of stream
    dwUser              : DWORD;                // for client's use
    dwFlags             : DWORD;                // assorted flags (see defines)
    dwReserved          : array[0..3] of DWORD; // reserved for driver
  end;

function OnFrame(hCapWnd: HWND; lpVHDR: PVideoHdr): DWord; stdcall;
var BitmapInfo: TBitmapInfo;
begin
  Result:=1;
  FillChar(BitmapInfo, SizeOf(BitmapInfo), 0);
  SendMessage(hCapWnd, WM_CAP_GET_VIDEOFORMAT, SizeOf(BitmapInfo), Integer(@BitmapInfo));

  with BitmapInfo.bmiHeader do
    UYVYtoRGB(lpVHdr^.lpData, Form1.Image1.Picture.Bitmap.ScanLine[biHeight-1], biWidth, biHeight);

end;



MfG
Phantom1
wdbee
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 628
Erhaltene Danke: 1



BeitragVerfasst: Mo 11.04.05 15:27 
Nur mal zum Verständnis:

Warum rufst du eigentlich das Video-Format für jedes Bild erneut ab?
Es würde doch wohl reichen, das vor dem ersten Bild einmal zu tun. Dann hast du alle Informationen, die du für deinen Aufruf von UYVYtoRGB brauchst.
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
var 
  BI: TBitmapInfo;
  BIHeight, BIWidth: Integer;
  ...
  FillChar(BI, SizeOf(BI), 0);  
  SendMessage(hCapWnd, WM_CAP_GET_VIDEOFORMAT, SizeOf(BI), Integer(@BI));  
  BIHeight := BI.biHeight;
  BIWidth := BI.biWidth;
  ...

function OnFrame(hCapWnd: HWND; lpVHDR: PVideoHdr): DWord; stdcall;  
begin  
  Result := 1;  
  UYVYtoRGB(lpVHdr^.lpData, Form1.Image1.Picture.Bitmap.ScanLine[BIHeight-], BIWidth, BIHeight);  
end;


Zuletzt bearbeitet von wdbee am Mo 11.04.05 15:46, insgesamt 1-mal bearbeitet
Phantom1 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 390



BeitragVerfasst: Mo 11.04.05 15:44 
Ja stimmt, anfangs dachte ich ja noch das man durch abrufen der TBitmapInfo an die PixelDaten rankommt, deshalb jedesmal der Aufruf.

Mfg
Phantom1