text stringlengths 0 234 |
|---|
generic |
-- Parameter(s) that are constant through |
-- the whole image. Macro-expanded generics and |
-- some optimization will trim corresponding "if's" |
interlaced : Boolean; |
transparency : Boolean; |
pixel_mask : U32; |
-- |
procedure GIF_Decode; |
procedure GIF_Decode is |
procedure Pixel_with_palette(b: U8) is |
pragma Inline(Pixel_with_palette); |
function Times_257(x: Primary_color_range) return Primary_color_range is |
pragma Inline(Times_257); |
begin |
return 16 * (16 * x) + x; -- this is 257 * x, = 16#0101# * x |
-- Numbers 8-bit -> no OA warning at instanciation. Returns x if type Primary_color_range is mod 2**8. |
end Times_257; |
full_opaque: constant Primary_color_range:= Primary_color_range'Last; |
begin |
if transparency and then b = Transp_color then |
Put_Pixel(0,0,0, 0); |
return; |
end if; |
case Primary_color_range'Modulus is |
when 256 => |
Put_Pixel( |
Primary_color_range(local.palette(Integer(b)).red), |
Primary_color_range(local.palette(Integer(b)).green), |
Primary_color_range(local.palette(Integer(b)).blue), |
full_opaque |
); |
when 65_536 => |
Put_Pixel( |
Times_257(Primary_color_range(local.palette(Integer(b)).red)), |
Times_257(Primary_color_range(local.palette(Integer(b)).green)), |
Times_257(Primary_color_range(local.palette(Integer(b)).blue)), |
-- Times_257 makes max intensity FF go to FFFF |
full_opaque |
); |
when others => |
raise invalid_primary_color_range; |
end case; |
end Pixel_with_palette; |
-- Interlacing |
Interlace_pass : Natural range 1..4:= 1; |
Span : Natural:= 7; |
-- Local procedure to draw a pixel |
procedure Next_Pixel(code: Natural) is |
pragma Inline(Next_Pixel); |
c : constant Color_type:= Color_type(U32(code) and pixel_mask); |
begin |
-- Actually draw the pixel on screen buffer |
if X < image.width then |
if interlaced and mode = nice then |
for i in reverse 0..Span loop |
if Y+i < image.height then |
Set_X_Y(X, image.height - (Y+i) - 1); |
Pixel_with_palette(c); |
end if; |
end loop; |
elsif Y < image.height then |
Pixel_with_palette(c); |
end if; |
end if; |
-- Move on to next pixel |
X:= X + 1; |
-- Or next row, if necessary |
if X = brX then |
X:= tlX; |
if interlaced then |
case Interlace_pass is |
when 1 => |
Y:= Y + 8; |
if Y >= brY then |
Y:= 4; |
Interlace_pass:= 2; |
Span:= 3; |
Feedback((Interlace_pass*100)/4); |
end if; |
when 2 => |
Y:= Y + 8; |
if Y >= brY then |
Y:= 2; |
Interlace_pass:= 3; |
Span:= 1; |
Feedback((Interlace_pass*100)/4); |
end if; |
when 3 => |
Y:= Y + 4; |
if Y >= brY then |
Y:= 1; |
Interlace_pass:= 4; |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.