Page 2 of 2 FirstFirst 12
Results 11 to 20 of 34

Thread: BeRoPNG - A very tiny but complete PNG loader

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Quote Originally Posted by Cybermonkey View Post
    What about the Vampyre Imaging Library?
    ... and it's massive (relying on the monstrous zlib library for png decode), slow (often painfully so), and on the whole completely unsuited to many projects because of it.

    Take on windows for example, where a game I've been puttering around on making for a year or so just had it's executable size cut by two-thirds just by switching to this.

    Could be worse though, could be SDLImage, were you need 200k in two DLL's just to unpack .png

    Thanks BeRo -- this looks to be getting a lot of use from me.

    I should clean up my BMP loader (with RLE4 and RLE8 support) and upload it sometime... sad part is I just ported my BMP loader to PHP as GD actually lacks BMP support. (crappy little one-bit WBMP is NOT Windows BMP!)
    Last edited by deathshadow; 21-08-2011 at 11:36 PM.
    The accessibility of a website from time to time must be refreshed with the blood of designers and owners. It is its natural manure

  2. #2
    Uhm... one thing...

    Code:
    function Swap32(x:word):word;
    begin
     result:=(Swap16(x and $ffff) shl 16) or Swap16((x and $ffff0000) shr 16);
    end;
    That doesn't make any sense. Shouldn't X be longword? Word and $FFFF0000 should always return zero on this. Also, if you are shifting right off a 32 bit integer by 16, there's no reason to do an AND on it.

    I'd probably also hardcode the byte swaps -- the overhead of the function calls slows down each of these functions in turn.

    Playing with checking ifdef cpui386 to add assembler optimized versions of your various routines...
    Code:
    {$ifdef cpui386}
    function Swap16(x:word):word; assembler;
    asm
    	mov ax,x
    	xchg ah,al { thankfully FPC/Delphi treat AX as the return value }
    end;
    {$else}
    function Swap16(x:word):word;
    begin
     result:=(x shl 8) + (x shr 8);
    end;
    {$endif}
    (also another case where the "and" is unnecessary due to the bit width and pascal's strict typecasting.)

    also playing with making a TP7 back-port as I'm still churning out DOS games, and PNG support would be really handy there.
    Last edited by deathshadow; 22-08-2011 at 12:05 AM.
    The accessibility of a website from time to time must be refreshed with the blood of designers and owners. It is its natural manure

  3. #3
    Quote Originally Posted by BeRo View Post
    I do want to share my useful BeRoPNG unit here. It's very tiny but complete PNG loader with a own tiny inflate routine, so it has no external unit dependencies. It supports even extended features such as Apple's proprietary extension CgBI and so on.

    And here is the link: http://rootserver.rosseaux.net/stuff/BeRoPNG.pas (36 kB src)

    It's licensed under the 2-clause simplified BSD license.

    So have a lot fun with it
    Thanks for sharing BeRo!

    Is it ok if I use this in a closed-source DLL for an engine I am writing?

    if so, I was wondering, how does one use this?

    Code:
    function LoadPNG(DataPointer:pointer;DataSize:longword;var ImageData:pointer;var ImageWidth,ImageHeight:integer):boolean;
    is DataPointer just the start of a PNG file, and DataSize the same as the PNG file size?

    cheers,
    Paul

  4. #4
    Woo Hoo! I have now gotten PNG loading working in my engine...thanks BeRo, you rock!!

    I have attached a zip file containing my png loader, my bmp loader, my unfinished tga loader (needs converting to TFileStream still), and my image buffer unit that my loaders and texturing uses in my engine...

    image loaders.zip

    Enjoy
    cheers,
    Paul

  5. #5
    Nice. Thanks for sharing Paul.

  6. #6
    You're welcome I take, and I give LOL

    cheers,
    Paul

  7. #7
    Hey all, just so you know, I tried compiling my engine in Delphi 2010 instead of Lazarus, and the BeRo png file doesn't compile due to ansichar and char incompatibilities, and other similar stuff...

    So I fixed the compiling errors, but now it fails to load my test png file now due to some unknown issue

    Summary, it works using Lazarus, but not D2010 at the moment...no crash, just no image.

    cheers,
    Paul

Page 2 of 2 FirstFirst 12

Tags for this Thread

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
  •