• Welcome to Vampyre Imaging Library Forum. Please login or sign up.
 

Show posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.

Messages - dbots

1
To display 32bit images in last version of unDelphiX, use :

form1.DXImageList1.Items.Find('image1dib').Draw(form1.DXDraw1.Surface, tmpx, 100, 0);

All work fine with that, except memory.

I tried to switch to Andorra 2D, since I read that it's not very difficult to transfer a project written for DelphiX to Andorra2D, but I found some unexplained parts there, asked the maintainer and got some answers but not all, so I started transferring my project, done almost half work and now I am stack.

With the code you sent, OK I can transform to DIB32 but the old DelphiX I use cannot handle alpha channels in DIB32. Only latest unDelphiX can, but this has the memory problems.
Also, the maintainer of unDelphiX has written a tool "PNG2DIB" that does exactly this. But as things are not, with that memory problem, I see no usage to do that.

I would like to have a quick solution for that problem I have now (displaying of DDS or PNG images) but of course if this is not possible I have to start using to other library.
But I would like the new library to :
- have very good support
- very good documentation and examples
- be able to do modern projects

Do you have any suggestions ?
2
Quote from: Galfar on  5 April 2010, 19:37:58
Check out TDXImageList class mentioned in this forum thread http://delphigamedev.com/forums/viewtopic.php?f=2&t=1185.

I think you can't get any alpha blending simply by using Surface.Draw methods (http://www.gamedev.net/community/forums/topic.asp?topic_id=303701 - it would have to be hardware supported to work).


Thanks for replying. I have been using a previous version of DelphiX until now (before having the need to use images that contain alpha channels [dds/png]) and up to now everything was just fine.
I have also found this article you sent about TDXImagelist and tried that using the latest version of UnDelphiX, but that version has a very bad memory management. My project that with previous version used about 150 MB or RAM with everything loaded, compiled with new version and no other changes uses about 1,2 GB of RAM. Well, this is bad.
On the other hand, that latest UnDelphiX version displays 32bit bitmaps (with alpha channel) fine, but what can I do if memory management is so bad ?
I contact the maintainer of unDelphiX many times but had no reply about this so I returned back to previous version I used and try to find some other solutions to use together with that previous version of DelphiX.
BTW, that old version of DelphiX I use, supports hardware acceleration by using Do3D=TRUE and I use it like that - no problem with that.
What would you suggest ? (please note that if I could use PNG images that keep alpha channel, that also would be fine for me). As I wrote in the past, I used PNG images by adding PNGImage in the uses clause of my application, but the only way I could draw them so that they keep their alpha channel over DX surface, was by drawing on the canvas of the DXSurface (form1.dxdraw1.surface.canvas.draw) that needs a "form1.dxdraw1.surface.canvas.release" afterwards, not directly on the form1.dxdraw1.surface. So this (drawing on canvas) made things very slow on most systems.
Please send any suggestions.
3
Hi Galfar,

did you have any news please ?
(even on using PNG if DDS is a problem)

Thank you.
4
Hi Galfar,
do you have any news about the problem with DDS ?
Please note that if it's possible to make it work even with PNG images for me it's fine, but keeping the alpha channel is the most important.
I tried and used pngimage in delphi but to make it work with DelphiX I have to use the dxdraw.surface.canvas.Draw and not the dxdraw.surface.Draw so this makes things much slower.
If you have any solution for PNG, please post.
5
Hi, still no success. Currently with the code :


var
  Form1: TForm1;
  DIB : TDIB;
  img: TImageData;
  dxsurf : TDirectDrawSurface;

implementation

{$R *.dfm}

procedure TForm1.DXTimer1Timer(Sender: TObject; LagCount: Integer);
begin
  form1.DXDraw1.Surface.Fill(clSilver);
  form1.DXDraw1.Surface.Draw(1,1,dxsurf);
  form1.DXDraw1.Flip;
end;

procedure TForm1.DXDraw1Initialize(Sender: TObject);
var linebytes,i : integer;
begin
  InitImage(img);
  LoadImageFromFile('mydds.dds', img);

  DIB := TDIB.Create;
  DIB.SetSize(img.Width, img.Height, 32);

  // make sure both are 32bit
  //DIB.BitCount := 32;

  ConvertImage(img, ifA8R8G8B8);

  // copy bits
  LineBytes := DIB.WidthBytes;
  for I := 0 to Img.Height - 1 do
    begin
    Move(PByteArray(Img.Bits)[I * LineBytes], DIB.Scanline[I]^, LineBytes);
    end;

  dxsurf := TDirectDrawSurface.Create(form1.DXDraw1.DDraw);
  dxsurf.LoadFromDIB(dib);

  form1.DXTimer1.Enabled := TRUE;
end;



I see the picture but with no alpha channel. It's like I have saved it as bitmap.

I used dib.savetofile to see if dib is OK but the problem starts from there. When I open this saved dib, it's like what I see - image is fine but with no alpha channel - like bitmap.

Note that DIB unit that I use is from unDelphiX - don't know if that makes any difference.
6
Thank you for replying.

When I use

Move(img.Bits, DIB.PBits, img.Size);

I get error : Constant object cannot be passed as var paramater.
The syntax of Move (I use Delphi 7) is :
procedure  Move( const Source; var Dest; count : Integer );
7
Hi Galfar,

did you have any time to make that sample code ?

Thank you.
8
Hi, just to inform, I tried :

  img := TImagingGraphic.Create;
  img.LoadFromFile('mydds.dds');
  dxsurf := TDirectDrawSurface.Create(form1.DXDraw1.DDraw);
  dxsurf.SetSize(img.Width, img.Height);
  dxsurf.Fill(0);
  dxsurf.LoadFromGraphic(img);

and I get the DDS image displayed but alpha channel is completely lost and I see some transparent parts on it- it's like having converted it to BMP and displaying a surface loaded from BMP.

If I add :

Move(img, dxsurf, SizeOf(img);

after

dxsurf.LoadFromGraphic(img);

then program hangs on that line with "Move".
9
OK, I will wait for that, thank you.
10
So I tried the second solution but won't work.

I load the DDS file like this :

var img : TImagingGraphic;
     dxsurf : TDirectDrawSurface;  //that's the DX surface I will use later

img := TImagingGraphic.Create;
img.LoadFromFile('mydds.dds');


but then trying to test if all OK until now, I do  :

img.SaveToFile('test.dds');

and the produced test.dds file has a bitmap header, it's not a dds file.

Anyway, I continue with :

dxsurf := TDirectDrawSurface.Create(form1.DXDraw1.DDraw);
dxsurf.SetSize(img.Width, img.Height);
dxsurf.Fill(0);


and then either of the following two :

dxsurf.Lock;
Move(img, dxsurf, SizeOf(img);
dxsurf.UnLock;


OR


mmm := TMemoryStream.Create;
img.SaveToStream(mmm);
dxsurf.Lock;
move(mmm, dxsurf, sizeof(mmm));
dxsurf.UnLock;


When "unlocking" the program hangs.
Also, if I use sizeof(img), it's always = 4, is that strange ?

and finally I start the DXTimer :


form1.dxtimer1.enabled := TRUE;


As usual, I try to draw the surface on the main DXDraw Surface, in the OnTimer event of DXTimer, using :

form1.DXDraw1.Surface.Fill(clSilver);
form1.DXDraw1.Surface.Draw(0,0,dxsurf);


I read somewhere that when I use Move, I must copy after the 5th byte of the DDS file that is in memory.
Does it make any sense to try that ?

Thank you.
11
Quote from: Galfar on 31 March 2010, 16:12:23
One way is to load DDS file into TImagingGraphic (see ImagingComponents.pas unit). It's regular TGraphic descendant so you can then use TDirectDrawSurface.LoadFromGraphic method to load the surface. But I looked at the code of LoadFromGraphic and it won't preserve alpha channel.
Better way would be to create empty surface, lock it, and copy bits from image to the surface (and unlock).
Somewhat simpler may be to convert TImageData contents to DelphiX's TDIB. You can then create surface with preserved alpha from TDIB easily.


Thank you very much for replying.
It's necessary to keep the alpha channel and opacity so the first solution won't fit.
I will try other solutions and inform of any success.
About the third solution, how can I convert TImageData to DelphiX's TDIB ?
I would be grateful if you could post some sample code about 2nd and 3rd solution.
For example, how to convert TImageData to DelphiX's TDIB ? Does TDIB keep alpha channel ?
There is a tool called PNG2DIB that was developed by Jaro Benes, the person who updates unDelphiX, and says that keeps alpha channel. What I did was load DDS from Paint.NET, save it as PNG and kept all alpha channel and opacity but then I had problem to display PNG over DX surfaces using DelphiX - made things very slow because PNG draws on surface.canvas while all others draw on surface.
So I used PNG2DIB to transform to DIB and use directly from DelphiX but after the conversion I lost all alpha channel and opacity.
12
Hi all,
I am using DelphiX in an application I wrote to display bitmaps and jpeg images.
Now, a client gave to me DDS files and asked to use these.
I tried to use Vampyre imaging library to load DDS with code :

InitImage(Img);
LoadImageFromFile('data51.dds', Img);


where Img is TImageData, but then cannot find out how to transfer this on TDirectDrawSurface of DelphiX, so that I finally display it on the application's DirectX Surface.

Any recommendations or help would be greatly appreciated.
Thank you in advance.
SMF spam blocked by CleanTalk