text stringlengths 0 234 |
|---|
-- getGray |
-- Gets the grayscale image data. Used as an alpha channel. |
-- ============= |
procedure getGray (buffer : out Byte_Array) is |
begin |
if RLE then |
for b in buffer'Range loop |
RLE_Pixel (8, buffer (b .. b)); |
end loop; |
else |
for b in buffer'Range loop |
Get_Byte (stream_buf, buffer (b)); |
end loop; |
end if; |
the_Image.tex_Format := GL.LUMINANCE; -- ALPHA |
the_Image.tex_pixel_Format := GL.LUMINANCE; |
end getGray; |
-- ============= |
-- getData |
-- Gets the image data for the specified bit depth. |
-- ============= |
procedure getData (iBits : Integer; buffer : out Byte_Array) is |
begin |
Attach_Stream (stream_buf, S); |
case iBits is |
when 32 => |
getRGBA (buffer); |
the_Image.blending_hint := True; |
when 24 => |
getRGB (buffer); |
the_Image.blending_hint := False; |
when 8 => |
getGray (buffer); |
the_Image.blending_hint := True; |
when others => null; |
end case; |
end getData; |
TGA_type : Byte_Array (0 .. 3); |
info : Byte_Array (0 .. 5); |
dummy : Byte_Array (1 .. 8); |
Image_Bits : Integer; |
Image_Type : Integer; |
begin -- to_TGA_Image |
Byte_Array'Read (S, TGA_type); -- read in colormap info and image type |
Byte_Array'Read (S, dummy); -- seek past the header and useless info |
Byte_Array'Read (S, info); |
if TGA_type (1) /= GL.Ubyte'Val (0) then |
Raise_Exception ( |
TGA_Unsupported_Image_Type'Identity, |
"TGA : palette not supported, please use BMP" |
); |
end if; |
-- Image type: |
-- 1=8 - bit palette style |
-- 2=Direct [A]RGB image |
-- 3=grayscale |
-- 9=RLE version of Type 1 |
-- 10=RLE version of Type 2 |
-- 11=RLE version of Type 3 |
Image_Type := GL.Ubyte'Pos (TGA_type (2)); |
RLE := Image_Type >= 9; |
if RLE then |
Image_Type := Image_Type - 8; |
RLE_pixels_remaining := 0; |
end if; |
if Image_Type /= 2 and then Image_Type /= 3 then |
Raise_Exception ( |
TGA_Unsupported_Image_Type'Identity, |
"TGA type =" & Integer'Image (Image_Type) |
); |
end if; |
the_Image.Width := GL.Ubyte'Pos (info (0)) + GL.Ubyte'Pos (info (1)) * 256; |
the_Image.Height := GL.Ubyte'Pos (info (2)) + GL.Ubyte'Pos (info (3)) * 256; |
Image_Bits := GL.Ubyte'Pos (info (4)); |
the_Image.size := the_Image.Width * the_Image.Height; |
-- 30 - Apr - 2006 : dimensions not power of two allowed, but discouraged in the docs. |
-- |
-- -- make sure dimension is a power of 2 |
-- if not (checkSize (imageWidth) and checkSize (imageHeight)) then |
-- raise TGA_BAD_DIMENSION; |
-- end if; |
-- make sure we are loading a supported TGA_type |
if Image_Bits /= 32 and then Image_Bits /= 24 and then Image_Bits /= 8 then |
raise TGA_Unsupported_Bits_per_pixel; |
end if; |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.