PDA

View Full Version : How store TDirectDrawSurface to TDIB ?



ijcro
22-09-2004, 06:19 AM
Please, how store TDirectDrawSurface as picture to TDIB ?

like
Procedure XY(Source:TDirectDrawSurface)
begin
...
Source...SaveToDIB(FilenameOfDIB)
end;

its posible ?

Useless Hacker
22-09-2004, 11:11 AM
var
DIB: TDIB;
Source: TDirectDrawSurface;
...
DIB.Assign(Source);
...

ijcro
22-09-2004, 12:29 PM
Ooh, is it that simply???

Thanx

ijcro
22-09-2004, 12:52 PM
var
DIB: TDIB;
Source: TDirectDrawSurface;
...
DIB.Assign(Source);
...

EXCELLENT ! Thanks

Works fine.

But I have a little question. On SOURCE is set up Transparent and discrete TransparentColor. How get information from TDirectDrawSurface?
Exist any tutorial how work with TDirectDrawSurface?

Regards

Useless Hacker
22-09-2004, 09:16 PM
But I have a little question. On SOURCE is set up Transparent and discrete TransparentColor. How get information from TDirectDrawSurface?
Exist any tutorial how work with TDirectDrawSurface?I don't really understand what you mean. What information do you want to get from the TDirectDrawSurface?

ijcro
23-09-2004, 07:26 AM
Sorry, my English is too poor :oops: .

I want get value of transparent color (or one value color that be use as transparent color). Do you understand me, please?

I am trying like
color:TDDColorKey;
..
TDirectDrawSurface.IDDSurface.GetColorKey(DDCKEY_S RCBLT,color);

but it returned strange color. I thing that is wrong parameter, no know.

Useless Hacker
23-09-2004, 12:40 PM
What's wrong with reading the TDirectDrawSurface.TransparentColor property?

ijcro
23-09-2004, 06:16 PM
My problem:

Cannot read a write-only property

Useless Hacker
23-09-2004, 10:02 PM
Ah, sorry, I didn't realise it was write-only.

Here is a (untested) function to get the TransparentColor from a surface:
function GetSurfaceTransparentColor(Surface: TDirectDrawSurface): Longint;
var
hr: HResult;
ddck: TDDColorKey;
begin
if (Surface <> nil) and (Surface.ISurface <> nil) then begin
hr := Surface.ISurface.GetColorKey(DDCKEY_SRCBLT, ddck);
if (hr = DD_OK) then begin
Result := ddck.dwColorSpaceLowValue;
end else begin
// failed to read ColorKey
Result := 0;
end;
end else begin
// surface is invalid
Result := 0;
end;
end;
I am not sure of the exact difference between dwColorSpaceLowValue and dwColorSpaceHighValue; the SetTransparentColor methods sets them both to the TransparentColor, so I'm assuming it is the same in this case (you could try replacing dwColorSpaceLowValue with dwColorSpaceHighValue if this doesn't work.) I don't have a copy of the DirectDraw documentation handy, so I can't check right now.

I don't really see why you need to read the TransparentColor of a surface anyway, seeing as you must have set it previously.

ijcro
24-09-2004, 10:13 AM
Values dwColorSpaceLowValue and dwColorSpaceHighValue are equal.
Transparent color returned is not true yet.
As test was setup clLime color for transparent. Structures under TDirectDrawSurface not contain similar value represented clLime or its parts :(

Where is error?

P.S. I am using anonymous painting with TDirectDrawSurface. I don't know from a object come TDirectDrawSurface ...

ijcro
30-09-2004, 10:36 AM
Where is error? What is wrong ? :cry:

My simulation is here :

var ddck:TDDColorKey; TranspCol :Integer;
..
if DXImageList1.Items.Find('picture1').PatternSurface s[0].ISurface.GetColorKey(DDCKEY_SRCBLT, ddck) = DD_OK then
TranspCol := ddck.dwColorSpaceLowValue;

On picture is really set transparent color clLime $00FF00.

But TranspCol contain stupid color $7E0 :shock:

Why, please? :(

Useless Hacker
30-09-2004, 11:46 AM
What bit-depth is your surface using?

ijcro
30-09-2004, 01:44 PM
Using 16b as standard (for tests 32 b too).

EDIT:
Have to I convert color and how?

czar
12-10-2004, 12:02 AM
:? //------------------------------------------------------------------------------
// ColourTo16BitRGB
//
// Convert a standard TColor to it's 16 bit RGB value
//
// BY Codetapper and Czar
//------------------------------------------------------------------------------
function ColourTo16BitRGB(InitialCol: TColor): Cardinal;
var aRed, aGreen, aBlue, sRed, sGreen, sBlue: integer;
begin
sRed := InitialCol and $ff;
sGreen := (InitialCol shr 8) and $ff;
sBlue := (InitialCol shr 16) and $ff;

aRed := (32 * sRed) div 256;
aGreen := (64 * sGreen) div 256;
aBlue := (32 * sBlue) div 256;

Result := (aRed shl 11) + (aGreen shl 5) + (aBlue shl 0);
end;

I figured I would post this reply here. We too had problems with the 16 bit colour depth. In order to be able to draw on the surface we decided it was easier to convert TColor to 16bit colour using the code above.

ijcro
12-10-2004, 07:15 AM
My function


function LoadTextures(dds:TDirectDrawSurface;Transparent:Bo olean):Boolean;
Var
DIB: TDIB;
ddck:TDDColorKey;
COL:Integer;
TEX: TDirect3DTexture2; {now as local, else as public}
Begin
Result := True;
Try
DIB := TDIB.Create;
Try
DIB.AsSign(dds); // picture here now
DIB.Transparent := Transparent; //is transparent
//FDDraw is TCustomDXDraw for me
TEX := TDirect3DTexture2.Create(FDDraw, DIB, False); //create texture from DIB
If dds.IDDSurface <> NIL Then //exists
if dds.ISurface.GetColorKey(DDCKEY_SRCBLT,ddck) = DD_OK Then //get color
COL := ddck.dwColorSpaceLowValue; //transparent color here
Tex.Transparent := Transparent; //set up flag transparent
Tex.TransparentColor := COL; //and main color
//Problem when draw to 16 bit target surface only (but 32 bit is OK)
//COL here is decreased as 16 bit but Tex is stil 32 bit
//no match COL in TEX = ERROR, no transparency show
Finally
DIB.Free;
End;
Except
Result := False;
End;
End;


Problem in comment described.

Very thanks for any answer.