Page 2 of 4 FirstFirst 1234 LastLast
Results 11 to 20 of 34

Thread: BeRoPNG - A very tiny but complete PNG loader

  1. #11
    Quote Originally Posted by virtual View Post
    thanks for sharing , i like tiny stuff

    by the way , i like your program picatune , are there any chance that i can use it in my demos ? , i have "kb" v2m pascal port , but gives much size than c++ version .
    Yes, if you give me more informations about your demo work. Anyway Picatune2 is released now, http://audio.rosseauxnet.de/software...cer/picatune2/ , which was also used in "fr-080: Strobo-plus-32767: Pacemaker" (Youtube, Pouet), and yeah fr-080 is a (Object-)Pascal-powered 64k intro, which was compiled with the Delphi 5 compiler with a own tiny system unit from me.

  2. #12
    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

  3. #13
    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

  4. #14
    Nice. Thanks for sharing Paul.

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

    cheers,
    Paul

  6. #16
    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

  7. #17
    Ok, I have fixed it now and it runs under D2010! yay
    I also replaced all #0 with AnsiChar(#0)...

    BeRoPNG.zip

    cheers,
    Paul

  8. #18
    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

  9. #19
    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

  10. #20
    I just realised that I have a problem

    I have my LoadPNGFromFile() routine, and I wanted to make a LoadPNGFromStream() version...

    The problem is that in the loading code below requires a pointer to a PNG file, and the length!!

    Code:
    function LoadPNGFromFile(FileName: String; Buffer: TImageBuffer32): Boolean;
    var
      PNGFile  : TMemoryStream;
      PNGData  : Pointer;
      PNGWidth : Integer;
      PNGHeight: Integer;
      PNGAddr  : PRGBA;
      BufferRow: PRGBAArray;
      x,y      : Integer;
    begin
      Result := False;
    
      if not FileExists(FileName) then Exit;
    
      PNGFile := TMemoryStream.Create;
      try
        PNGFile.LoadFromFile(FileName);
        Result := LoadPNG(PNGFile.Memory,PNGFile.Size,PNGData,PNGWidth,PNGHeight);
        if not Result then Exit;
    
        Buffer.SetSize(PNGWidth,PNGHeight);
    
        PNGAddr := PNGData;
        // copy bitmap pixels to buffer pixels
        for y := 0 to PNGHeight - 1 do
        begin
          BufferRow := Buffer.ScanLine[y];
          for x := 0 to PNGWidth - 1 do
          begin
            BufferRow^[x].r := PNGAddr^.r;
            BufferRow^[x].g := PNGAddr^.g;
            BufferRow^[x].b := PNGAddr^.b;
            BufferRow^[x].a := PNGAddr^.a;
            Inc(PNGAddr);
          end;
        end;
      finally
        PNGFile.Free;
      end;
    end;
    the loading code in the BeRo file uses the DataSize parameter as an indicator of when the PNG file has been read in, I would like to be able to change this so that the code knows when to stop without the user passing in the size.

    Any ideas?

    cheers,
    Paul

Page 2 of 4 FirstFirst 1234 LastLast

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
  •