text stringlengths 0 234 |
|---|
Span:= 0; |
Feedback((Interlace_pass*100)/4); |
end if; |
when 4 => |
Y:= Y + 2; |
end case; |
if mode = fast and then Y < image.height then |
Set_X_Y(X, image.height - Y - 1); |
end if; |
else -- not interlaced |
Y:= Y + 1; |
if Y < image.height then |
Set_X_Y(X, image.height - Y - 1); |
end if; |
if Y mod 32 = 0 then |
Feedback((Y*100)/image.height); |
end if; |
end if; |
end if; |
end Next_Pixel; |
-- The string table |
Prefix : array ( 0..4096 ) of Natural:= (others => 0); |
Suffix : array ( 0..4096 ) of Natural:= (others => 0); |
-- Top of Stack was 1024 until files from |
-- https://www.kaggle.com/c/carvana-image-masking-challenge |
-- broke it (July 2017)... |
Stack : array ( 0..2048 ) of Natural; |
-- Special codes (specific to GIF's flavour of LZW) |
ClearCode : constant Natural:= 2 ** CurrSize; -- Reset code |
EndingCode: constant Natural:= ClearCode + 1; -- End of file |
FirstFree : constant Natural:= ClearCode + 2; -- Strings start here |
Slot : Natural:= FirstFree; -- Last read code |
InitCodeSize : constant Code_size_range:= CurrSize + 1; |
TopSlot : Natural:= 2 ** InitCodeSize; -- Highest code for current size |
Code : Natural; |
StackPtr : Integer:= 0; |
Fc : Integer:= 0; |
Oc : Integer:= 0; |
C : Integer; |
BadCodeCount : Natural:= 0; -- the number of bad codes found |
begin -- GIF_Decode |
-- The decoder source and the cool comments are kindly donated by |
-- André van Splunter. |
-- |
CurrSize:= InitCodeSize; |
-- This is the main loop. For each code we get we pass through the |
-- linked list of prefix codes, pushing the corresponding "character" |
-- for each code onto the stack. When the list reaches a single |
-- "character" we push that on the stack too, and then start unstacking |
-- each character for output in the correct order. Special handling is |
-- included for the clear code, and the whole thing ends when we get |
-- an ending code. |
C := Read_Code; |
while C /= EndingCode loop |
-- If the code is a clear code, reinitialize all necessary items. |
if C = ClearCode then |
CurrSize := InitCodeSize; |
Slot := FirstFree; |
TopSlot := 2 ** CurrSize; |
-- Continue reading codes until we get a non-clear code |
-- (Another unlikely, but possible case...) |
C := Read_Code; |
while C = ClearCode loop |
C := Read_Code; |
end loop; |
-- If we get an ending code immediately after a clear code |
-- (Yet another unlikely case), then break out of the loop. |
exit when C = EndingCode; |
-- Finally, if the code is beyond the range of already set codes, |
-- (This one had better NOT happen... I have no idea what will |
-- result from this, but I doubt it will look good...) then set |
-- it to color zero. |
if C >= Slot then |
C := 0; |
end if; |
Oc := C; |
Fc := C; |
-- And let us not forget to output the char... |
Next_Pixel(C); |
else -- C /= ClearCode |
-- In this case, it's not a clear code or an ending code, so |
-- it must be a code code... So we can now decode the code into |
-- a stack of character codes. (Clear as mud, right?) |
Code := C; |
-- Here we go again with one of those off chances... If, on the |
-- off chance, the code we got is beyond the range of those |
-- already set up (Another thing which had better NOT happen...) |
-- we trick the decoder into thinking it actually got the last |
-- code read. (Hmmn... I'm not sure why this works... |
-- But it does...) |
if Code >= Slot then |
if Code > Slot then |
BadCodeCount := BadCodeCount + 1; |
end if; |
Code := Oc; |
Stack (StackPtr) := Fc rem 256; |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.