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