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