1. with Allegro.Bitmaps;                   use Allegro.Bitmaps; 
  2. with Allegro.Files;                     use Allegro.Files; 
  3. with Allegro.Palettes;                  use Allegro.Palettes; 
  4. with Allegro_Ids;                       use Allegro_Ids; 
  5. with System;                            use System; 
  6.  
  7. package LoadPNG is 
  8.  
  9.     function LoadPNG_Version return String; 
  10.     pragma Postcondition( LoadPNG_Version'Result'Length > 0 ); 
  11.  
  12.     -- png_screen_gamma is slightly overloaded (sorry): 
  13.     -- 
  14.     -- A value of 0.0 means: Don't do any gamma correction in load_png() 
  15.     -- and load_memory_png().  This meaning was introduced in v1.4. 
  16.     -- 
  17.     -- A value of -1.0 means: Use the value from the environment variable 
  18.     -- SCREEN_GAMMA (if available), otherwise fallback to a value of 2.2 
  19.     -- (a good guess for PC monitors, and the value for sRGB colourspace). 
  20.     -- This is the default. 
  21.     -- 
  22.     -- Otherwise, the value of png_screen_gamma is taken as-is. 
  23.     procedure Set_PNG_Screen_Gamma( gamma : Long_Float ); 
  24.  
  25.     -- Choose zlib compression level for saving file. 
  26.     -- Default is Z_BEST_COMPRESSION. 
  27.     procedure Set_PNG_Compression_Level( level : Integer ); 
  28.  
  29.     -- Load a PNG from disk. 
  30.     function Load_PNG( filename : String; pal : A_RGB ) return A_Bitmap; 
  31.     pragma Precondition( filename'Length > 0 ); 
  32.  
  33.     -- Load a PNG from some place. 
  34.     function Load_PNG_Pf( fp : not null A_Packfile; pal : A_RGB ) return A_Bitmap; 
  35.  
  36.     -- Load a PNG from memory. 
  37.     function Load_Memory_PNG( buffer      : Address; 
  38.                               buffer_size : Natural; 
  39.                               pal         : A_RGB ) return A_Bitmap; 
  40.  
  41.     -- Save a bitmap to disk in PNG format. Returns 0 on success. 
  42.     function Save_PNG( filename : String; bmp : A_Bitmap; pal : A_RGB ) return Integer; 
  43.     pragma Precondition( filename'Length > 0 ); 
  44.  
  45.     -- Adds `PNG' to Allegro's internal file type table. 
  46.     -- You can then just use load_bitmap and save_bitmap as usual. 
  47.     procedure Register_PNG_File_Type; 
  48.  
  49.     -- Register an datafile type ID with Allegro, so that when an object 
  50.     -- with that type ID is encountered while loading a datafile, that 
  51.     -- object will be loaded as a PNG file. 
  52.     procedure Register_PNG_Datafile_Object( id : AL_ID ); 
  53.  
  54.     -- This is supposed to resemble jpgalleg_init in JPGalleg 2.0, just in 
  55.     -- case you are lazier than lazy.  It contains these 3 lines of code: 
  56.     --   register_png_datafile_object(DAT_ID('P','N','G',' ')); 
  57.     --   register_png_file_type(); 
  58.     --   return 0; 
  59.     function LoadPNG_Init return Integer; 
  60.  
  61. private 
  62.  
  63.     pragma Import( C, Load_PNG_Pf, "load_png_pf" ); 
  64.     pragma Import( C, Load_Memory_PNG, "load_memory_png" ); 
  65.     pragma Import( C, Register_PNG_File_Type, "register_png_file_type" ); 
  66.     pragma Import( C, Register_PNG_Datafile_Object, "register_png_datafile_object" ); 
  67.     pragma Import( C, LoadPNG_Init, "loadpng_init" ); 
  68.  
  69. end LoadPNG;