Page 2 of 7 FirstFirst 1234 ... LastLast
Results 11 to 20 of 63

Thread: Loading DX Textures in an imagelist - which is the fastest?

  1. #11

    Loading DX Textures in an imagelist - which is the fastest?

    I just tried the following code
    Code:
    procedure TImageListCollection.LoadFromFile(const Filename: string);
    var
      Stream: TFileStream;
    begin
      Stream := TFileStream.Create(Filename, fmOpenRead or fmShareDenyNone);
      try
        LoadFromStream(Stream);
      finally
        Stream.Free;
      end;
    end;
    and it loaded the images fine. I'm not sure why it would have given you a 'stream not working' or similar error.

    Working on the Image.Init now.

  2. #12

    Loading DX Textures in an imagelist - which is the fastest?

    Hmmm - I have to test it. The error could be because I am using an addition Cryption on my imagelist, if it works fine for you...

    I can test that. If you have our Imegalisteditor, you can take a look there, it can also use that optional Cryption. I you need any source or maybe the Imagelisteditor please tell me, I have most things from Bobbys site at home.

    Thanks!
    Firle

  3. #13

    Loading DX Textures in an imagelist - which is the fastest?

    I wasn't using encryption. I'm not sure how that callback works. It takes a stream and returns a stream. Is it the same stream it returns or a new stream?

  4. #14
    Anonymous
    Guest

    Loading DX Textures in an imagelist - which is the fastest?

    Hi Sly,

    this is the Decryption method:
    Code:
    function MyDecrypt(s: TStream): TStream;
    var arrbyte: array of byte;
        i, size: Integer;
        r: byte;
        Key: Word;
    begin
     size := s.Size; SetLength(arrbyte, size);
     s.Position := 0; s.Read(arrbyte[0], SizeOf(arrbyte[0]) * size);
     Key := password;
     for i := 0 to High(arrbyte) do // for every byte in the stream
     begin
      r := arrbyte[i];
      arrbyte[i] := arrbyte[i] xor (Key shr 8);
      Key := (r + Key) * C1 + C2;
     end;
     s.Position := 0; s.Write(arrbyte[0], SizeOf(arrbyte[0]) * size);
     result := s;
    end;
    I load an Imagelist like this:

    ImageListEditor.ImageList.DecodeFunction := MyDecrypt;
    imagelisteditor.ImageList.LoadFromFile('grafix\ima gelisteditor.oil');
    Imagelisteditor.init;

    Does this help?

    Firle

  5. #15

    Loading DX Textures in an imagelist - which is the fastest?

    Was me again, sorry. If you get it to work without the encryption, it is also fine, it is a nice feature but not so important I think for most Omega users, because Dan already wrote a tool which can hack it so the encryption is not very good anyway.

    Firle

  6. #16

    Loading DX Textures in an imagelist - which is the fastest?

    Quote Originally Posted by Anonymous
    Hi Sly,

    this is the Decryption method:
    Code:
    function MyDecrypt(s: TStream): TStream;
    var arrbyte: array of byte;
        i, size: Integer;
        r: byte;
        Key: Word;
    begin
     size := s.Size; SetLength(arrbyte, size);
     s.Position := 0; s.Read(arrbyte[0], SizeOf(arrbyte[0]) * size);
     Key := password;
     for i := 0 to High(arrbyte) do // for every byte in the stream
     begin
      r := arrbyte[i];
      arrbyte[i] := arrbyte[i] xor (Key shr 8);
      Key := (r + Key) * C1 + C2;
     end;
     s.Position := 0; s.Write(arrbyte[0], SizeOf(arrbyte[0]) * size);
     result := s;
    end;
    I load an Imagelist like this:

    ImageListEditor.ImageList.DecodeFunction := MyDecrypt;
    imagelisteditor.ImageList.LoadFromFile('grafix\ima gelisteditor.oil');
    Imagelisteditor.init;

    Does this help?

    Firle
    That's going to be a huge timesink as well, plus it forces the use of TMemoryStream unless you want to write back over the same file you loaded from.

    In your case, the LoadFromFile method will allocate 19MB and load the entire file into it. The DecodeFunction will then allocate another 19MB buffer, copy the entirity of the memory stream into that buffer, walk over every byte of that buffer, and copy the entire buffer back into the same stream that was passed in. Then it proceeds to save each image separately back to a memory stream and load the image back from the memory stream.

    I'm at work now, so I cannot do any more stuff on the speed-up until I get home tonight. There is probably only so much that can be done with the existing file format. What it really needs is a new file format that does not go through the component streaming system.

  7. #17

    Loading DX Textures in an imagelist - which is the fastest?

    I'm just had a look at this thread. I have some comments about the use of TMemroyStream. This can be a great little class to use. However in order to make the most of it I would make use of the capacity property. Also you coul d try and only have one TMemroyStream that all the Init calls use.

    You set the capacity to your max size of image then continually use that same stream as a buffer. One of the problems with TMemoryStream is it allocates memory on the fly if you write to it and the capacity < size. it's always better to grad a whole chunk in one go.

    Hopefully using one TMemoryStream buffer will cut down on having to create and destroy the stream each time as well.

    Hope this helps.
    <A HREF="http://www.myhpf.co.uk/banner.asp?friend=139328">
    <br /><IMG SRC="http://www.myhpf.co.uk/banners/60x468.gif" BORDER="0">
    <br /></A>

  8. #18

    Loading DX Textures in an imagelist - which is the fastest?

    That might help a bit for the part of the code where it saves the image back to the stream, but I don't think that is the major timesink.

  9. #19

    Loading DX Textures in an imagelist - which is the fastest?

    I'm going to have to call shenanigans on this issue. Trying to interpret the bitmap data and write it into a texture is driving me nuts. Plus the Delphi 2005 IDE is working against me. Why do Borland make such a crap IDE and crap debugger?

  10. #20

    Loading DX Textures in an imagelist - which is the fastest?

    Hi Sly! (sounds cool, Hi Sly )

    Can't you perhaps use D3DXSaveTextureToFile to make an Export to texture format? Or does that not help?

    How do you get along? Found some improvements or something?
    Or will you make something new for loading and exporting?

    Firle

Page 2 of 7 FirstFirst 1234 ... LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •