PDA

View Full Version : Auto loading images to ASDB file , ImageFX error



robert83
25-09-2014, 09:49 PM
Hi all,

I'm trying to create a program that autopopulates my asdb file with images , for testing I'm trying to load a bmp image 32x32 .


procedure TForm1.Button1Click(Sender: TObject);
var
PxFm: TPxFm;
pSize: TPoint;
Image: TBitmap;
Dest: TBitmap;
Tolerance: Integer;
MaskColor: Cardinal;
IsMasked: Boolean;
Stream: TMemoryStream;
begin
ASDB := TAsdb.Create(Self);
ASDB.FileName:='media.asdb';
ASDB.OpenMode:=opUpdate;
if (not ASDb.Update()) then
begin
ShowMessage('Failed opening ASDb archive!');
Exit;
end;
// change the following format, if necessary
PxFm.Format:= COLOR_A8R8G8B8;
// retreive Texture Size from edit boxes
PxFm.TextureWidth := 32;
PxFm.TextureHeight:= 32;
// retreive Pattern Size from edit boxes
PxFm.PatternWidth := 32;
PxFm.PatternHeight:= 32;
// this variable is used for better readability only
pSize:= Point(PxFm.PatternWidth, PxFm.PatternHeight);
// this size can be smaller than pattern size to add padding
PxFm.VisibleWidth := PxFm.PatternWidth;
PxFm.VisibleHeight:= PxFm.PatternHeight;
// retreive mask color and tolerance
IsMasked:= false;
MaskColor := Shape1.Brush.Color and $FFFFFF;
Tolerance:= 15;
// load the image
Image:= TBitmap.Create();
LoadBitmap('0.bmp', Image, ifBMP);
// update some attributes
PxFm.PatternCount:= (Image.Width div pSize.X) * (Image.Height div pSize.Y);
// create destination bitmap
Dest:= TBitmap.Create();
TileBitmap(Dest, Image, Point(PxFm.TextureWidth, PxFm.TextureHeight),
pSize, pSize, IsMasked, MaskColor, Tolerance);
// create auxiliary stream to write PxFm-formatted image data
Stream:= TMemoryStream.Create();
WriteBitmapPxFm(Stream, Dest, PxFm);
// we don't need destination image anymore
Dest.Free();
// position to the beginning of our stream
Stream.Seek(0, soFromBeginning);
ASDb.WriteStream('0.image', Stream, recGraphics);
Stream.Free();
end;



I get a SIGSEGV at TileBitmap , specifically this one :



procedure UnmaskAlpha(Dest: TBitmap);
var
i, j: Integer;
pl: PLongword;
begin
Dest.PixelFormat:= pf32bit;
for j:= 0 to Dest.Height - 1 do
begin
pl:= bmp2xlbmp(Dest).Scanline[j];
for i:= 0 to Dest.Width - 1 do
begin
pl^:= pl^ or $FF000000; <--------------------------- here
Inc(pl);
end;
end;
end;



Any idea what is wrong, manually adding this file with the Asphyre Manager , same properties is working fine. But it takes a lot of time to add 259 images....

Greeetings
Robert

robert83
26-09-2014, 04:48 AM
Hi all,

Anyway after sleeping I think I'll just re-write the editor along with the game itself . The part about the TTileData . After searching a bit online , in the old Afterwarp forums , and looking for some other games
I realized they all use sprite sheets .
So I will not be adding 100 images individually for the MainMenu for example but I will add a complete SpriteSheet. I will alter my TTileData record to look like this (probably) :


TTileData = record
Sheet : String; // sheet name from ASDB archive (menu,level01,level02...etc)
PatternStart : Word; // where my desired image starts
PatternStop : Word; // where my desired image stops (in case it's animated)
// AnimSpeed : Single;
end;


I need to go to work now :( , but I think this might be a better idea , make the ASDB file easier to manage, and far faster to load then with my current 700 ~ individual images.

Greetings
Robert

SilverWarior
26-09-2014, 08:41 AM
Have you checked the code for Asphyre Manager to see how it works? I bet that with litle work you could change it so it is capable of loading multiple images a once itno ASDB.

Also it is ture that loading entire sprite sheats would be much faster than loading individual images but that does require you to create entire spritesheat using some other program, which might in the end be even slower and require more work. Not to mention that by using of sprite sheats you need to change entire spritesheat even if you do just a small change to one of your images.

The reason why ASDB is implemented into Asphyre is that it actually is managed sprite sheat which alows you to load the textures into your game much faster than you would by loading them from individual files.

User137
26-09-2014, 01:37 PM
Some missing info in your first post.

- We don't see where UnmaskAlpha() is called from.
- How is Dest: TBitmap created before sending as parameter?
- You are typecasting it, so couldn't it be procedure UnmaskAlpha(Dest: bmp2xlbmp);
- What is bmp2xlbmp anyway?