text
stringlengths
0
234
idx := y * width * 3; -- GL destination picture is 24 bit
x3 := idx;
x3_max := idx + (width - 1) * 3;
case BMP_bits is
when 1 => -- B/W
while x3 <= x3_max loop
if bit = 0 then
Get_Byte (stream_buf, b01);
end if;
b := (b01 and 16#80#) / 16#80#;
Fill_palettized;
b01 := b01 * 2; -- cannot overflow.
if bit = 7 then
bit := 0;
else
bit := bit + 1;
end if;
x3 := x3 + 3;
end loop;
when 4 => -- 16 colour image
while x3 <= x3_max loop
if pair then
Get_Byte (stream_buf, b01);
b := (b01 and 16#F0#) / 16#10#;
else
b := (b01 and 16#0F#);
end if;
pair := not pair;
Fill_palettized;
x3 := x3 + 3;
end loop;
when 8 => -- 256 colour image
while x3 <= x3_max loop
Get_Byte (stream_buf, b);
Fill_palettized;
x3 := x3 + 3;
end loop;
when others =>
null;
end case;
end loop;
end Load_BMP_Image;
Width : X_Loc;
Height : Y_Loc;
offset : U32;
BMP_bits, imagebits : Integer;
BMP_Size : Integer;
BMP_tex_format : GL.TexFormatEnm;
BMP_tex_pixel_format : GL.TexPixelFormatEnm;
begin
Read_BMP_Header (S, Width, Height, BMP_bits, offset);
imagebits := 24;
blending_hint := False; -- no blending with BMP's
BMP_tex_format := GL.RGB;
BMP_tex_pixel_format := GL.RGB;
Load_BMP_Palette (S, BMP_bits, Palette);
BMP_Size := Width * Height;
-- Allocation
imageData := new Byte_Array (0 .. (imagebits / 8) * BMP_Size - 1);
Load_BMP_Image
(S, Width, Height, imageData.all,
BMP_bits, Palette);
Insert_into_GL (id => Id,
Insert_Size => BMP_Size,
width => Width,
height => Height,
texFormat => BMP_tex_format,
texPixelFormat => BMP_tex_pixel_format,
image_p => imageData
);
-- release our data, its been uploaded to the GL system
Free (imageData);
end Load_BMP;
procedure i_Load_BMP is new Load_XXX (Stream_Loader => Load_BMP);
procedure Load_BMP (Name : String; Id : Integer; blending_hint : out Boolean) renames i_Load_BMP;
procedure Load (name : String; -- file name
format : Supported_format; -- expected file format
ID : Integer; -- ID is the texture identifier to bind to
blending_hint : out Boolean) is -- has blending / transparency /alpha ?
begin
case format is
when BMP => Load_BMP (name, ID, blending_hint);
when TGA => Load_TGA (name, ID, blending_hint);
end case;
end Load;
procedure Load (s : Ada.Streams.Stream_IO.Stream_Access; -- input data stream (e.g. Unzip.Streams)
format : Supported_format; -- expected file format