PDA

View Full Version : TDXImageListCompressed



blackvoid
17-01-2006, 01:31 PM
I was looking for a compressed imagelist component but could not find any. What I have found though, is that some mentioning developing one on the GameDev forums. Also a japanese site came up, but that is unusable by me.

Is there such a thing as a compressed imagelist? We need this very badly for our upcoming game, because we have more than 2000 sprites and it EATS memory. We have also noticed that our 8 bit sprites take more memory than they should. It seems they are loaded as 16 bit (we use 16 bit DXG surface).

Possible solution:
1. implement a compressed imagelist
2. somehow force Delphix to load the sprites with 8 bit color depth (possible??)
3. Load the sprites on demand - but how? Atm we are loading them all at the same time from the DXG.

My knowledge in this area is a bit limited, because I am not the programmer who deals with this stuff and the guy responsible does not speak English.
Solution 1 is the best, however we lack the time to do it. I am willing to pay for a custom built compressed imagelist!!! We need it within a month.

Thank you

K4Z
17-01-2006, 11:58 PM
What Image format are you using? I'd recomend not using bitmap.

PNG has very good compression with no quality loss. One project, I used Jpegs (Just add JPEG to the uses), but only for images that didn't need to be drawn with transparency.

I'm not sure, but to use 8 bit sprites, the DX surface has to be 8 bit as well :?:.

There is a way to load sprites into a ImageList as you go, I'll have to dig around in some old code to find a sample...

blackvoid
18-01-2006, 07:29 AM
Thanks for your reply!
DXGEdit does not support PNG. Or are we using an outdated version? Would PNG reduce memory use as well? If it's only the size of the DXG that is reduced, than it does not help us much.

We use BMP, we had to reduce sprites to 8 bit because our sprite files were in excess of 600MB. Quality loss is very little with 8 bit, but load times and disk space usage is halved. They work just fine on a 16 bit surface, but it seems they are converted to 16 bit during the load. This means we do not spare on the memory usage.

Memory use is one of our concerns at the moment, as the game is using in excess of 400MB.

User137
18-01-2006, 10:18 PM
Follow these instructions for installing png for delphi:
http://www.delphigamedev.com/forums/viewtopic.php?t=251

Then place wanted extensions in uses list and that's all there is to it :D After installation you can use png with any component (TImage, TDXImagelist, whatever).

Also you could try not to load everything same time in DXImagelist, but use it dynamically.

blackvoid
19-01-2006, 01:40 PM
Follow these instructions for installing png for delphi:
http://www.delphigamedev.com/forums/viewtopic.php?t=251

Then place wanted extensions in uses list and that's all there is to it :D After installation you can use png with any component (TImage, TDXImagelist, whatever).

Is there a version of DXGEdit that supports PNG? I will check that ]
Also you could try not to load everything same time in DXImagelist, but use it dynamically.[/quote]

Sounds good. Where can I find an example (source)?

cairnswm
19-01-2006, 01:55 PM
As far as I know it doesn;t matter what format you store your images in. Once they are loaded into memory they will always be expanded based on the Surface that you have.

The only way to do what you want as far as I know is to Load and unload images as you need them. My suggestion would be to split the images into multiple lists and dynamically create the required DXImageList when you need it. And free it once you no longer need it.

I do not have DelphiX on my machine anymore but it will be something like:

MyList := DXImageList.Create(Nil);
MyList.LoadFromFile('MyImages.DXExt');
...

MyList.Free;

blackvoid
19-01-2006, 02:11 PM
Thanks for the suggestion, but it would not work that way. We need to select one by one what we need.

I have checked the newest DXGEdit and now it supports JPG. We have checked, we converted the map and memory usage is lower now. However we cannot convert the sprites to JPG, because it screws up the background color. Is there a way to convert to JPG and keep the background intact?

cairnswm
19-01-2006, 02:14 PM
The reason the JPegs are smaller is that the coulor resolution and changes between each pixel are smaller.

What about

MyList := DXImageList.Create(Nil);
...
MyList.Items.Add(DXImageItem.Create(MyList));
DXImageItem.LoadFromFile('SingleImage.jpg');
...
MyList.Free;


As I said - I dont have DelphiX so syntax might be wrong.

FNX
19-01-2006, 02:30 PM
Hello, using DelphiX should be like this:

DXImageList1.Items[0].Picture.LoadFromFile('MyPicture.XXX');
DXImageList1.Items[1].Picture.LoadFromFile('MyPicture1.XXX');
DXImageList1.Items[2].Picture.LoadFromFile('MyPicture2.XXX');
...
DXImageList1.Items[n].Picture.LoadFromFile('MyPictureN.XXX');


where .XXX is your desired image format

cairnswm
19-01-2006, 03:06 PM
Here is an example program for you (I went and installed DelphiX to work it out).

This requires a form with a DXDraw surface and a single DXImageList.

When you press space it will load the image (You need to change it to the image you want it to be).

When you press any other key, it removes the image.

If you press space a few times you will see the image repeated as it gets dynamically loaded into the DXImageList. When they get dynamically removed you will see less images.

This way before each level you can load the images you need and remove all the images you do not need.

(I'm not sure which of the Restores are needed - play around and see what results you can get).


unit Main;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, DXDraws, DXClass;

type
TForm1 = class(TForm)
DXDraw1: TDXDraw;
DXImageList1: TDXImageList;
DXTimer1: TDXTimer;
procedure FormKeyUp(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure DXTimer1Timer(Sender: TObject; LagCount: Integer);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
Y : Integer;
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.FormKeyUp(Sender: TObject; var Key: Word;
Shift: TShiftState);
Var
P : TCollectionItem;
begin
If Key = 32 then
Begin
P := DXImageList1.Items.Add;
TPictureCollectionItem(P).Picture.LoadFromFile('Ni njaID.bmp');
TPictureCollectionItem(P).Transparent := True;
DXImageList1.Items.Restore;
DXDraw1.Restore;
End
Else
Begin
DXDraw1.Finalize;
P := DXImageList1.Items[DXImageList1.Items.Count-1];
DXImageList1.Items.Delete(DXImageList1.Items.Count-1);
DXDraw1.Restore;
DXImageList1.Items.Restore;
DXDraw1.Initialize;
Y := Y + 1;
End;
end;

procedure TForm1.DXTimer1Timer(Sender: TObject; LagCount: Integer);
Var
I : Integer;
begin
Caption := IntToStr(DXImageList1.Items.Count);
DXDraw1.Surface.Fill(0);
For I := 0 to DXImageList1.Items.Count-1 do
DXImageList1.Items[I].Draw(DXDraw1.Surface,I*100,100,0);
DXDraw1.Flip;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
Y := 1;
end;

end.

K4Z
20-01-2006, 12:11 PM
You would need to experiment with the Jpeg compression level a little. Some images would probably need very little compression (High quality), while others could allow for more compression (Low Quality).
And use a good program for converting images, never use Paint or anything that comes with windows :P.

Those that need best quality, or drawn with transparency would have to go PNG, (or stay Bitmap).