1. with Allegro.Bitmaps;                   use Allegro.Bitmaps; 
  2. with Allegro.Files;                     use Allegro.Files; 
  3. with Allegro.Palettes;                  use Allegro.Palettes; 
  4. with Interfaces.C.Strings;              use Interfaces.C.Strings; 
  5.  
  6. package Allegro.Image_Files is 
  7.  
  8.     -- Allegro 4.2.2 - Loading image files 
  9.     -- This package is complete 
  10.  
  11.     -- filename is a string no longer than MAX_PATH_LEN, terminated by Nul. 
  12.     type A_Bitmap_Loader is 
  13.         access function( filename : C.Strings.chars_ptr; pal : A_RGB ) return A_Bitmap; 
  14.  
  15.     -- filename is a string no longer than MAX_PATH_LEN, terminated by Nul. 
  16.     -- return zero on success, anything else on error. 
  17.     type A_Bitmap_Saver is 
  18.         access function( filename : C.Strings.chars_ptr; 
  19.                          bmp      : A_Bitmap; 
  20.                          pal      : A_RGB ) return Integer; 
  21.  
  22.     subtype Conv_Type is Unsigned_32; 
  23.  
  24.     ---------------------------------------------------------------------------- 
  25.  
  26.     COLORCONV_NONE      : constant Conv_Type; 
  27.  
  28.     COLORCONV_8_TO_15   : constant Conv_Type; 
  29.     COLORCONV_8_TO_16   : constant Conv_Type; 
  30.     COLORCONV_8_TO_24   : constant Conv_Type; 
  31.     COLORCONV_8_TO_32   : constant Conv_Type; 
  32.  
  33.     COLORCONV_15_TO_8   : constant Conv_Type; 
  34.     COLORCONV_15_TO_16  : constant Conv_Type; 
  35.     COLORCONV_15_TO_24  : constant Conv_Type; 
  36.     COLORCONV_15_TO_32  : constant Conv_Type; 
  37.  
  38.     COLORCONV_16_TO_8   : constant Conv_Type; 
  39.     COLORCONV_16_TO_15  : constant Conv_Type; 
  40.     COLORCONV_16_TO_24  : constant Conv_Type; 
  41.     COLORCONV_16_TO_32  : constant Conv_Type; 
  42.  
  43.     COLORCONV_24_TO_8   : constant Conv_Type; 
  44.     COLORCONV_24_TO_15  : constant Conv_Type; 
  45.     COLORCONV_24_TO_16  : constant Conv_Type; 
  46.     COLORCONV_24_TO_32  : constant Conv_Type; 
  47.  
  48.     COLORCONV_32_TO_8   : constant Conv_Type; 
  49.     COLORCONV_32_TO_15  : constant Conv_Type; 
  50.     COLORCONV_32_TO_16  : constant Conv_Type; 
  51.     COLORCONV_32_TO_24  : constant Conv_Type; 
  52.  
  53.     COLORCONV_32A_TO_8  : constant Conv_Type; 
  54.     COLORCONV_32A_TO_15 : constant Conv_Type; 
  55.     COLORCONV_32A_TO_16 : constant Conv_Type; 
  56.     COLORCONV_32A_TO_24 : constant Conv_Type; 
  57.  
  58.     COLORCONV_DITHER_PAL : constant Conv_Type; 
  59.     COLORCONV_DITHER_HI  : constant Conv_Type; 
  60.     COLORCONV_KEEP_TRANS : constant Conv_Type; 
  61.  
  62.     COLORCONV_DITHER            : constant Conv_Type; 
  63.     COLORCONV_EXPAND_256        : constant Conv_Type; 
  64.     COLORCONV_REDUCE_TO_256     : constant Conv_Type; 
  65.     COLORCONV_EXPAND_15_TO_16   : constant Conv_Type; 
  66.     COLORCONV_REDUCE_16_TO_15   : constant Conv_Type; 
  67.     COLORCONV_EXPAND_HI_TO_TRUE : constant Conv_Type; 
  68.     COLORCONV_REDUCE_TRUE_TO_HI : constant Conv_Type; 
  69.     COLORCONV_24_EQUALS_32      : constant Conv_Type; 
  70.     COLORCONV_TOTAL             : constant Conv_Type; 
  71.     COLORCONV_PARTIAL           : constant Conv_Type; 
  72.     COLORCONV_MOST              : constant Conv_Type; 
  73.     COLORCONV_KEEP_ALPHA        : constant Conv_Type; 
  74.  
  75.     --------------------------------------------------------------------------- 
  76.  
  77.     function Get_Color_Conversion return Conv_Type; 
  78.  
  79.     function Load_Bitmap( filename : String; pal : A_RGB ) return A_Bitmap; 
  80.  
  81.     function Load_BMP( filename : String; pal : A_RGB ) return A_Bitmap; 
  82.  
  83.     function Load_BMP_pf( f : not null A_Packfile; pal : A_RGB ) return A_Bitmap; 
  84.  
  85.     function Load_LBM( filename : String; pal : A_RGB ) return A_Bitmap; 
  86.  
  87.     function Load_PCX( filename : String; pal : A_RGB ) return A_Bitmap; 
  88.  
  89.     function Load_PCX_pf( filename : String; pal : A_RGB ) return A_Bitmap; 
  90.  
  91.     function Load_TGA( filename : String; pal : A_RGB ) return A_Bitmap; 
  92.  
  93.     function Load_TGA_pf( filename : String; pal : A_RGB ) return A_Bitmap; 
  94.  
  95.     procedure Register_Bitmap_File_Type( ext  : String; 
  96.                                          load : A_Bitmap_Loader; 
  97.                                          save : A_Bitmap_Saver ); 
  98.  
  99.     -- Returns False on error. 
  100.     function Save_Bitmap( filename : String; bmp : A_Bitmap; pal : A_RGB ) return Boolean; 
  101.  
  102.     -- Returns False on error. 
  103.     function Save_BMP( filename : String; bmp : A_Bitmap; pal : A_RGB ) return Boolean; 
  104.  
  105.     -- Returns False on error. 
  106.     function Save_BMP_pf( f : A_Packfile; bmp : A_Bitmap; pal : A_RGB ) return Boolean; 
  107.  
  108.     -- Returns False on error. 
  109.     function Save_PCX( filename : String; bmp : A_Bitmap; pal : A_RGB ) return Boolean; 
  110.  
  111.     -- Returns False on error. 
  112.     function Save_PCX_pf( f : A_Packfile; bmp : A_Bitmap; pal : A_RGB ) return Boolean; 
  113.  
  114.     -- Returns False on error. 
  115.     function Save_TGA( filename : String; bmp : A_Bitmap; pal : A_RGB ) return Boolean; 
  116.  
  117.     -- Returns False on error. 
  118.     function Save_TGA_pf( f : A_Packfile; bmp : A_Bitmap; pal : A_RGB ) return Boolean; 
  119.  
  120.     procedure Set_Color_Conversion( mode : Conv_Type ); 
  121.  
  122. private 
  123.  
  124.     COLORCONV_NONE      : constant Conv_Type := 16#00000000#; 
  125.  
  126.     COLORCONV_8_TO_15   : constant Conv_Type := 16#00000001#; 
  127.     COLORCONV_8_TO_16   : constant Conv_Type := 16#00000002#; 
  128.     COLORCONV_8_TO_24   : constant Conv_Type := 16#00000004#; 
  129.     COLORCONV_8_TO_32   : constant Conv_Type := 16#00000008#; 
  130.  
  131.     COLORCONV_15_TO_8   : constant Conv_Type := 16#00000010#; 
  132.     COLORCONV_15_TO_16  : constant Conv_Type := 16#00000020#; 
  133.     COLORCONV_15_TO_24  : constant Conv_Type := 16#00000040#; 
  134.     COLORCONV_15_TO_32  : constant Conv_Type := 16#00000080#; 
  135.  
  136.     COLORCONV_16_TO_8   : constant Conv_Type := 16#00000100#; 
  137.     COLORCONV_16_TO_15  : constant Conv_Type := 16#00000200#; 
  138.     COLORCONV_16_TO_24  : constant Conv_Type := 16#00000400#; 
  139.     COLORCONV_16_TO_32  : constant Conv_Type := 16#00000800#; 
  140.  
  141.     COLORCONV_24_TO_8   : constant Conv_Type := 16#00001000#; 
  142.     COLORCONV_24_TO_15  : constant Conv_Type := 16#00002000#; 
  143.     COLORCONV_24_TO_16  : constant Conv_Type := 16#00004000#; 
  144.     COLORCONV_24_TO_32  : constant Conv_Type := 16#00008000#; 
  145.  
  146.     COLORCONV_32_TO_8   : constant Conv_Type := 16#00010000#; 
  147.     COLORCONV_32_TO_15  : constant Conv_Type := 16#00020000#; 
  148.     COLORCONV_32_TO_16  : constant Conv_Type := 16#00040000#; 
  149.     COLORCONV_32_TO_24  : constant Conv_Type := 16#00080000#; 
  150.  
  151.     COLORCONV_32A_TO_8  : constant Conv_Type := 16#00100000#; 
  152.     COLORCONV_32A_TO_15 : constant Conv_Type := 16#00200000#; 
  153.     COLORCONV_32A_TO_16 : constant Conv_Type := 16#00400000#; 
  154.     COLORCONV_32A_TO_24 : constant Conv_Type := 16#00800000#; 
  155.  
  156.     COLORCONV_DITHER_PAL : constant Conv_Type := 16#01000000#; 
  157.     COLORCONV_DITHER_HI  : constant Conv_Type := 16#02000000#; 
  158.     COLORCONV_KEEP_TRANS : constant Conv_Type := 16#04000000#; 
  159.  
  160.     COLORCONV_DITHER     : constant Conv_Type := COLORCONV_DITHER_PAL or 
  161.                                                  COLORCONV_DITHER_HI; 
  162.  
  163.     COLORCONV_EXPAND_256 : constant Conv_Type := COLORCONV_8_TO_15 or 
  164.                                                  COLORCONV_8_TO_16 or 
  165.                                                  COLORCONV_8_TO_24 or 
  166.                                                  COLORCONV_8_TO_32; 
  167.  
  168.     COLORCONV_REDUCE_TO_256 : constant Conv_Type := COLORCONV_15_TO_8 or 
  169.                                                     COLORCONV_16_TO_8 or 
  170.                                                     COLORCONV_24_TO_8 or 
  171.                                                     COLORCONV_32_TO_8 or 
  172.                                                     COLORCONV_32A_TO_8; 
  173.  
  174.     COLORCONV_EXPAND_15_TO_16 : constant Conv_Type := COLORCONV_15_TO_16; 
  175.  
  176.     COLORCONV_REDUCE_16_TO_15 : constant Conv_Type := COLORCONV_16_TO_15; 
  177.  
  178.     COLORCONV_EXPAND_HI_TO_TRUE : constant Conv_Type := COLORCONV_15_TO_24 or 
  179.                                                         COLORCONV_15_TO_32 or 
  180.                                                         COLORCONV_16_TO_24 or 
  181.                                                         COLORCONV_16_TO_32; 
  182.  
  183.     COLORCONV_REDUCE_TRUE_TO_HI : constant Conv_Type := COLORCONV_24_TO_15 or 
  184.                                                         COLORCONV_24_TO_16 or 
  185.                                                         COLORCONV_32_TO_15 or 
  186.                                                         COLORCONV_32_TO_16; 
  187.  
  188.     COLORCONV_24_EQUALS_32 : constant Conv_Type := COLORCONV_24_TO_32 or 
  189.                                                    COLORCONV_32_TO_24; 
  190.  
  191.     COLORCONV_TOTAL : constant Conv_Type := COLORCONV_EXPAND_256 or 
  192.                                             COLORCONV_REDUCE_TO_256 or 
  193.                                             COLORCONV_EXPAND_15_TO_16 or 
  194.                                             COLORCONV_REDUCE_16_TO_15 or 
  195.                                             COLORCONV_EXPAND_HI_TO_TRUE or 
  196.                                             COLORCONV_REDUCE_TRUE_TO_HI or 
  197.                                             COLORCONV_24_EQUALS_32 or 
  198.                                             COLORCONV_32A_TO_15 or 
  199.                                             COLORCONV_32A_TO_16 or 
  200.                                             COLORCONV_32A_TO_24; 
  201.  
  202.     COLORCONV_PARTIAL : constant Conv_Type := COLORCONV_EXPAND_15_TO_16 or 
  203.                                               COLORCONV_REDUCE_16_TO_15 or 
  204.                                               COLORCONV_24_EQUALS_32; 
  205.  
  206.     COLORCONV_MOST : constant Conv_Type := COLORCONV_EXPAND_15_TO_16 or 
  207.                                            COLORCONV_REDUCE_16_TO_15 or 
  208.                                            COLORCONV_EXPAND_HI_TO_TRUE or 
  209.                                            COLORCONV_REDUCE_TRUE_TO_HI or 
  210.                                            COLORCONV_24_EQUALS_32; 
  211.  
  212.     COLORCONV_KEEP_ALPHA : constant Conv_Type := COLORCONV_TOTAL and not 
  213.                                                  (COLORCONV_32A_TO_8 or 
  214.                                                   COLORCONV_32A_TO_15 or 
  215.                                                   COLORCONV_32A_TO_16 or 
  216.                                                   COLORCONV_32A_TO_24); 
  217.  
  218.     ---------------------------------------------------------------------------- 
  219.  
  220.     pragma Convention( C, A_Bitmap_Loader ); 
  221.     pragma Convention( C, A_Bitmap_Saver ); 
  222.  
  223.     pragma Import( C, Get_Color_Conversion, "get_color_conversion" ); 
  224.     pragma Import( C, Load_BMP_pf, "load_bmp_pf" ); 
  225.     pragma Import( C, Load_PCX_pf, "load_pcx_pf" ); 
  226.     pragma Import( C, Load_TGA_pf, "load_tga_pf" ); 
  227.     pragma Import( C, Set_Color_Conversion, "set_color_conversion" ); 
  228.  
  229. end Allegro.Image_Files;