Page 2 of 3 FirstFirst 123 LastLast
Results 11 to 20 of 24

Thread: Native PNG Loader with no 3rd party requirements

  1. #11

    Re: Native PNG Loader with no 3rd party requirements

    Quote Originally Posted by User137
    Testing this kind now: http://next3d.webs.com/test1.png

    It didn't crash but dimensions are 1024x512 so opposite than previous. Didn't try your new version yet...

    Edit: Now run that with new version but it didn't make difference. This is how it looks in program:
    http://i32.tinypic.com/ibe5bt.jpg
    Ahh, that's an sRGB image. Haven't implemented sRGB reader yet so it actually doesn't ever truly load your image. Hopefully I get that part done some time soon, but I'll keep this image and keep trying to load it as I make updates.

    - Jeremy

  2. #12

    Re: Native PNG Loader with no 3rd party requirements

    @User137:
    Well, I was wrong... It had nothing to do with sRGB (oops), it had to do with how I was reading in the IDAT sub-section headers. The problem is fixed now and the pas file is updated. Tried loading your png and now it loads just fine.

    Thanks for finding the bug, and hopefully this fix helps you out.

    @Everyone:
    I did forget to mention that right now I'm only decoding non-interlaced PNG's. Once I get all the sections figured out and the bugs fixed, then I'll start on Interlaced images.

    - Jeremy

  3. #13

    Re: Native PNG Loader with no 3rd party requirements

    Both works now, MsPaint and Gimp formats. But they are still upside down Notice that normal perspective view has higher (+ side) Y coordinate at top of screen. My screen is set up on ortho mode this way, so upper left is 0,0:
    [pascal]glViewport(X,Y,_Width,_Height);
    ...
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity; gluOrtho2D(X,X+_Width,Y+_Height,Y);
    glMatrixMode(GL_MODELVIEW);[/pascal]

    Nice work, hope to see it finished.

  4. #14

    Re: Native PNG Loader with no 3rd party requirements

    Nice one Jeremy

    If anyone is interested, there is also now this version of a no 3rd party PNG reader/writer that is open source and works with FPC (written by Christian-W. Budde in the graphics32 forums):

    http://sourceforge.net/projects/gr32pnglibrary/

    It loads a png file into a TBitmap32 class, but I think the underlying classes could also be used to load png files into other things too instead of just Graphics32 classes

    cheers,
    Paul

  5. #15

    Re: Native PNG Loader with no 3rd party requirements

    Quote Originally Posted by User137
    Both works now, MsPaint and Gimp formats. But they are still upside down Notice that normal perspective view has higher (+ side) Y coordinate at top of screen. My screen is set up on ortho mode this way, so upper left is 0,0:
    [pascal]glViewport(X,Y,_Width,_Height);
    ...
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity; gluOrtho2D(X,X+_Width,Y+_Height,Y);
    glMatrixMode(GL_MODELVIEW);[/pascal]

    Nice work, hope to see it finished.
    Ahh.. yes, the scan lines were inverted. Fixed now, same download. Pixel[0,0] is now equal to Data^ and Pixel[width-1, height-1] is now (Data+(width*height)-1)^ (IOTW: Upper left is now 0, 0).

    - Jeremy

  6. #16

    Re: Native PNG Loader with no 3rd party requirements

    Yep, it looks correct now.

  7. #17

    Re: Native PNG Loader with no 3rd party requirements

    Quick update, I've added Scanline[] and Pixel[x,y] accessors to the class. Not sure if this will be any use to anyone, but just in case they were easy enough to add.

    pas file has been updated, but since this is a new page, here is the DL link:
    http://www.eonclash.com/gl/uPNGSupport.pas

    Also, will be starting a new post about a TGA loader that follows the same model as this one in case anyone is interested.

    - Jeremy

  8. #18

    Re: Native PNG Loader with no 3rd party requirements

    Thanks for this present, jdarling. May be I can hack it and use it with my Allegro.pas wrapper or something.
    No signature provided yet.

  9. #19
    PGDCE Developer de_jean_7777's Avatar
    Join Date
    Nov 2006
    Location
    Bosnia and Herzegovina (Herzegovina)
    Posts
    287

    Re: Native PNG Loader with no 3rd party requirements

    Hey jdarling. Your PNG loader is quite useful. I incorporated your loader into my image library to load PNGs. It works nicely, but there are several problems, which at first I thought were my fault, but I made a simple test program that includes only your loader just to be sure, and it was not my fault .

    Here's the test program that loads PNGs using your unit:
    [pascal]
    PROGRAM upngtest;

    USES heaptrc, uPNGSupport;

    CONST
    imgFN = 'vlad.png';

    VAR
    p: TRawPNG = nil;
    fn: string = imgFN;

    BEGIN
    writeln('upngtest');
    writeln();

    if(ParamCount > 0) then
    fn := ParamStr(1);

    writeln('Loading ', fn);
    p := TRawPNG.Create(fn);
    if(p.LoadError = 0) then begin
    writeln('Loaded image: ', fn)
    end else
    writeln('Error: ', p.LoadError, '|', p.LoadErrorMessage);

    p.Free();
    writeln('Done');
    END.
    [/pascal]

    In the above program, heaptrc will make the loader report strange errors, while without heaptrc it will load the PNGs normally.

    Another thing is a range check error:
    Code:
    An unhandled exception occurred at $00412E5F :
    ERangeError : Range check error
     $00412E5F TRAWPNG__FILTERROW, line 644 of C:/Programming/FPC_PP/Projects/dIm
    age/Units/uPNGSupport.pas
     $004127EF TRAWPNG__DECODENONINTERLACED, line 564 of C:/Programming/FPC_PP/Pr
    ojects/dImage/Units/uPNGSupport.pas
     $00411AD5 TRAWPNG__READIDAT, line 345 of C:/Programming/FPC_PP/Projects/dIma
    ge/Units/uPNGSupport.pas
     $00414036 TRAWPNG__LOADFROMSTREAM, line 837 of C:/Programming/FPC_PP/Project
    s/dImage/Units/uPNGSupport.pas
     $00413AB9 TRAWPNG__CREATE, line 771 of C:/Programming/FPC_PP/Projects/dImage
    /Units/uPNGSupport.pas
     $0040163A main, line 20 of upngtest.pp
    This range check error causes crashing when loading a certain PNG, but when the check is disabled that same PNG loads OK. The particular PNG I've used is named vlad.png from your SDL, Lua and FPC game demo which I downloaded from your site. Or for easier access I've uploaded it to imagebin.

    I suspect you've got memory corruption somewhere in your code, but could be something else.
    Existence is pain

  10. #20

    Re: Native PNG Loader with no 3rd party requirements

    Yeah, I've noticed that you can't use HeapTrace or any of the other stuff to "debug" the PNG's that are loaded. While there may be a leak or an overrun/override I can't find it. Running the code in a VM and monitoring actual memory usage there are no leaks found (same amount of free memory before as after the run), so I'm a bit lost.

    Anyone finds something I'd love to hear it. The "errors" thrown move depending on machine and version you compile in, so this points more to a Memory Overrun than it does a typical leak.

    - Jeremy

Page 2 of 3 FirstFirst 123 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
  •