* Allow compilation with webassembly (do not use goto)

This commit is contained in:
Michaël Van Canneyt 2023-07-12 17:08:37 +02:00
parent 37a5130fc3
commit fe873006dc
6 changed files with 465 additions and 178 deletions

View File

@ -19,7 +19,7 @@ begin
P.Directory:=ADirectory;
{$endif ALLPACKAGES}
P.Version:='3.3.1';
P.OSes:=P.OSes-[embedded,msdos,win16,macosclassic,palmos,zxspectrum,msxdos,amstradcpc,sinclairql,wasi];
P.OSes:=P.OSes-[embedded,msdos,win16,macosclassic,palmos,zxspectrum,msxdos,amstradcpc,sinclairql];
if Defaults.CPU=jvm then
P.OSes := P.OSes - [java,android];

View File

@ -1,3 +1,6 @@
{$IFDEF CPUWASM}
{$DEFINE NOGOTO}
{$ENDIF}
{ ----------------------- JPEG_INTERNAL_OPTIONS ---------------------- }

View File

@ -559,8 +559,11 @@ function jpeg_fill_bit_buffer (var state : bitread_working_state;
{register} get_buffer : bit_buf_type;
{register} bits_left : int;
nbits : int) : boolean;
{$IFNDEF NOGOTO}
label
no_more_bytes;
{$ENDIF}
{ Load up the bit buffer to a depth of at least nbits }
var
{ Copy heavily used state fields into locals (hopefully registers) }
@ -570,6 +573,43 @@ var
{register} c : int;
var
cinfo : j_decompress_ptr;
Procedure DoNomoreBytes;
begin
{ We get here if we've read the marker that terminates the compressed
data segment. There should be enough bits in the buffer register
to satisfy the request; if so, no problem. }
if (nbits <= bits_left) then
exit;
{ Uh-oh. Report corrupted data to user and stuff zeroes into
the data stream, so that we can produce some kind of image.
We use a nonvolatile flag to ensure that only one warning message
appears per data segment. }
if not cinfo^.entropy^.insufficient_data then
begin
WARNMS(j_common_ptr(cinfo), JWRN_HIT_MARKER);
cinfo^.entropy^.insufficient_data := TRUE;
end;
{ Fill the buffer with zero bits }
get_buffer := get_buffer shl (MIN_GET_BITS - bits_left);
bits_left := MIN_GET_BITS;
end;
Procedure PrepareExit;
begin
{ Unload the local registers }
state.next_input_byte := next_input_byte;
state.bytes_in_buffer := bytes_in_buffer;
state.get_buffer := get_buffer;
state.bits_left := bits_left;
jpeg_fill_bit_buffer := TRUE;
end;
begin
next_input_byte := state.next_input_byte;
bytes_in_buffer := state.bytes_in_buffer;
@ -640,7 +680,13 @@ begin
cinfo^.unread_marker := c;
{ See if we need to insert some fake zero bits. }
goto no_more_bytes;
{$IFDEF NOGOTO}
DoNomoreBytes;
PrepareExit;
exit;
{$ELSE}
goto no_more_bytes;
{$ENDIF}
end;
end;
@ -651,36 +697,13 @@ begin
end
else
begin
{$IFNDEF NOGOTO}
no_more_bytes:
{ We get here if we've read the marker that terminates the compressed
data segment. There should be enough bits in the buffer register
to satisfy the request; if so, no problem. }
if (nbits > bits_left) then
begin
{ Uh-oh. Report corrupted data to user and stuff zeroes into
the data stream, so that we can produce some kind of image.
We use a nonvolatile flag to ensure that only one warning message
appears per data segment. }
if not cinfo^.entropy^.insufficient_data then
begin
WARNMS(j_common_ptr(cinfo), JWRN_HIT_MARKER);
cinfo^.entropy^.insufficient_data := TRUE;
end;
{ Fill the buffer with zero bits }
get_buffer := get_buffer shl (MIN_GET_BITS - bits_left);
bits_left := MIN_GET_BITS;
end;
{$ENDIF}
DoNomoreBytes;
end;
{ Unload the local registers }
state.next_input_byte := next_input_byte;
state.bytes_in_buffer := bytes_in_buffer;
state.get_buffer := get_buffer;
state.bits_left := bits_left;
jpeg_fill_bit_buffer := TRUE;
prepareExit;
end;
@ -848,8 +871,10 @@ end;
{METHODDEF}
function decode_mcu (cinfo : j_decompress_ptr;
var MCU_data : array of JBLOCKROW) : boolean; far;
{$IFNDEF NOGOTO}
label
label1, label2, label3;
{$ENDIF}
var
entropy : huff_entropy_ptr;
{register} s, k, r : int;
@ -863,8 +888,26 @@ var
state : savable_state;
dctbl : d_derived_tbl_ptr;
actbl : d_derived_tbl_ptr;
skiptolabel1,skiptolabel2,skiptolabel3 : Boolean;
var
nb, look : int; {register}
// Return true if we assign a result and must exit decode_mcu
function DoDecode(aTable : d_derived_tbl_ptr) : Boolean;
begin
s := jpeg_huff_decode(br_state,get_buffer,bits_left,aTable,nb);
if (s < 0) then
begin
decode_mcu := FALSE;
exit(true);
end;
get_buffer := br_state.get_buffer;
bits_left := br_state.bits_left;
DoDecode:=False;
end;
begin
entropy := huff_entropy_ptr (cinfo^.entropy);
@ -904,8 +947,8 @@ begin
dctbl := entropy^.dc_cur_tbls[blkn];
actbl := entropy^.ac_cur_tbls[blkn];
SkipToLabel1:=False;
{ Decode a single block's worth of coefficients }
{ Section F.2.2.1: decode the DC coefficient difference }
{HUFF_DECODE(s, br_state, dctbl, return FALSE, label1);}
if (bits_left < HUFF_LOOKAHEAD) then
@ -920,35 +963,38 @@ begin
if (bits_left < HUFF_LOOKAHEAD) then
begin
nb := 1;
{$IFDEF NOGOTO}
if DoDecode(dctbl) then
exit;
SkipToLabel1:=True;
{$ELSE}
goto label1;
{$ENDIF}
end;
end;
{look := PEEK_BITS(HUFF_LOOKAHEAD);}
look := int(get_buffer shr (bits_left - HUFF_LOOKAHEAD)) and
pred(1 shl HUFF_LOOKAHEAD);
nb := dctbl^.look_nbits[look];
if (nb <> 0) then
begin
{DROP_BITS(nb);}
Dec(bits_left, nb);
s := dctbl^.look_sym[look];
end
else
begin
nb := HUFF_LOOKAHEAD+1;
label1:
s := jpeg_huff_decode(br_state,get_buffer,bits_left,dctbl,nb);
if (s < 0) then
if not SkipToLabel1 then
begin
decode_mcu := FALSE;
exit;
end;
get_buffer := br_state.get_buffer;
bits_left := br_state.bits_left;
end;
{look := PEEK_BITS(HUFF_LOOKAHEAD);}
look := int(get_buffer shr (bits_left - HUFF_LOOKAHEAD)) and
pred(1 shl HUFF_LOOKAHEAD);
nb := dctbl^.look_nbits[look];
if (nb <> 0) then
begin
{DROP_BITS(nb);}
Dec(bits_left, nb);
s := dctbl^.look_sym[look];
end
else
begin
nb := HUFF_LOOKAHEAD+1;
{$IFNDEF NOGOTO}
label1:
{$ENDIF}
if DoDecode(dctbl) then exit;
end;
end;
if (s <> 0) then
begin
{CHECK_BIT_BUFFER(br_state, s, return FALSE);}
@ -993,6 +1039,7 @@ begin
while (k < DCTSIZE2) do { Nomssi: k is incr. in the loop }
begin
{HUFF_DECODE(s, br_state, actbl, return FALSE, label2);}
skiptolabel2:=False;
if (bits_left < HUFF_LOOKAHEAD) then
begin
if (not jpeg_fill_bit_buffer(br_state,get_buffer,bits_left, 0)) then
@ -1005,35 +1052,39 @@ begin
if (bits_left < HUFF_LOOKAHEAD) then
begin
nb := 1;
{$IFDEF NOGOTO}
if DoDecode(actbl) then
exit;
skiptolabel2:=True;
{$ELSE}
goto label2;
{$ENDIF}
end;
end;
{look := PEEK_BITS(HUFF_LOOKAHEAD);}
look := int(get_buffer shr (bits_left - HUFF_LOOKAHEAD)) and
pred(1 shl HUFF_LOOKAHEAD);
nb := actbl^.look_nbits[look];
if (nb <> 0) then
begin
{DROP_BITS(nb);}
Dec(bits_left, nb);
s := actbl^.look_sym[look];
end
else
begin
nb := HUFF_LOOKAHEAD+1;
label2:
s := jpeg_huff_decode(br_state,get_buffer,bits_left,actbl,nb);
if (s < 0) then
if not SkipToLabel2 then
begin
decode_mcu := FALSE;
exit;
end;
get_buffer := br_state.get_buffer;
bits_left := br_state.bits_left;
end;
look := int(get_buffer shr (bits_left - HUFF_LOOKAHEAD)) and
pred(1 shl HUFF_LOOKAHEAD);
nb := actbl^.look_nbits[look];
if (nb <> 0) then
begin
{DROP_BITS(nb);}
Dec(bits_left, nb);
s := actbl^.look_sym[look];
end
else
begin
nb := HUFF_LOOKAHEAD+1;
{$IFNDEF NOGOTO}
label2:
{$ENDIF}
if DoDecode(actbl) then
exit;
end;
end;
r := s shr 4;
s := s and 15;
@ -1084,6 +1135,7 @@ begin
k := 1;
while (k < DCTSIZE2) do
begin
SkipToLabel3:=False;
{HUFF_DECODE(s, br_state, actbl, return FALSE, label3);}
if (bits_left < HUFF_LOOKAHEAD) then
begin
@ -1097,35 +1149,39 @@ begin
if (bits_left < HUFF_LOOKAHEAD) then
begin
nb := 1;
{$IFDEF NOGOTO}
if DoDecode(actbl) then
exit;
SkipToLabel3:=True;
{$ELSE}
goto label3;
{$ENDIF}
end;
end;
{look := PEEK_BITS(HUFF_LOOKAHEAD);}
look := int(get_buffer shr (bits_left - HUFF_LOOKAHEAD)) and
pred(1 shl HUFF_LOOKAHEAD);
nb := actbl^.look_nbits[look];
if (nb <> 0) then
begin
{DROP_BITS(nb);}
Dec(bits_left, nb);
s := actbl^.look_sym[look];
end
else
begin
nb := HUFF_LOOKAHEAD+1;
label3:
s := jpeg_huff_decode(br_state,get_buffer,bits_left,actbl,nb);
if (s < 0) then
if not SkipToLabel3 then
begin
decode_mcu := FALSE;
exit;
end;
get_buffer := br_state.get_buffer;
bits_left := br_state.bits_left;
end;
{look := PEEK_BITS(HUFF_LOOKAHEAD);}
look := int(get_buffer shr (bits_left - HUFF_LOOKAHEAD)) and
pred(1 shl HUFF_LOOKAHEAD);
nb := actbl^.look_nbits[look];
if (nb <> 0) then
begin
{DROP_BITS(nb);}
Dec(bits_left, nb);
s := actbl^.look_sym[look];
end
else
begin
nb := HUFF_LOOKAHEAD+1;
{$IFNDEF NOGOTO}
label3:
{$ENDIF}
if DoDecode(actbl) then exit;
end;
end;
r := s shr 4;
s := s and 15;

View File

@ -537,17 +537,23 @@ end; { get_sof }
{LOCAL}
function get_sos (cinfo : j_decompress_ptr) : boolean;
{ Process a SOS marker }
{$IFNDEF NOGOTO}
label
id_found;
{$ENDIF}
var
length : INT32;
i, ci, n, c, cc : int;
compptr : jpeg_component_info_ptr;
foundid : boolean;
{ Declare and initialize local copies of input pointer/count }
var
datasrc : jpeg_source_mgr_ptr;
next_input_byte : JOCTETptr; { Array[] of JOCTET; }
bytes_in_buffer : size_t;
begin
datasrc := cinfo^.src;
next_input_byte := datasrc^.next_input_byte;
@ -674,16 +680,29 @@ begin
Inc(next_input_byte);
compptr := jpeg_component_info_ptr(cinfo^.comp_info);
FoundID:=False;
for ci := 0 to Pred(cinfo^.num_components) do
begin
if (cc = compptr^.component_id) then
FoundID:=(cc = compptr^.component_id);
if FoundID then
begin
{$IFDEF NOGOTO}
Break;
{$ELSE}
goto id_found;
{$ENDIF}
end;
Inc(compptr);
end;
ERREXIT1(j_common_ptr(cinfo), JERR_BAD_COMPONENT_ID, cc);
if not FoundID then
ERREXIT1(j_common_ptr(cinfo), JERR_BAD_COMPONENT_ID, cc);
{$IFNDEF NOGOTO}
id_found:
{$ENDIF}
cinfo^.cur_comp_info[i] := compptr;
compptr^.dc_tbl_no := (c shr 4) and 15;

View File

@ -308,9 +308,12 @@ end;
{METHODDEF}
function decode_mcu_DC_first (cinfo : j_decompress_ptr;
var MCU_data : array of JBLOCKROW) : boolean;
var MCU_data : array of JBLOCKROW) : boolean;
{$IFNDEF NOGOTO}
label
label1;
{$ENDIF}
var
entropy : phuff_entropy_ptr;
Al : int;
@ -327,6 +330,23 @@ var
compptr : jpeg_component_info_ptr;
var
nb, look : int; {register}
skiptolabel1 : boolean;
// Return true if we assign a result do decode_mcu_dc_first and need to exit
function DoDecode : Boolean;
begin
s := jpeg_huff_decode(br_state,get_buffer,bits_left,tbl,nb);
if (s < 0) then
begin
decode_mcu_DC_first := FALSE;
exit(true);
end;
get_buffer := br_state.get_buffer;
bits_left := br_state.bits_left;
DoDecode:=False;
end;
begin
entropy := phuff_entropy_ptr (cinfo^.entropy);
Al := cinfo^.Al;
@ -372,6 +392,7 @@ begin
{ Section F.2.2.1: decode the DC coefficient difference }
{HUFF_DECODE(s, br_state, tbl, return FALSE, label1);}
skiptolabel1:=False;
if (bits_left < HUFF_LOOKAHEAD) then
begin
if (not jpeg_fill_bit_buffer(br_state,get_buffer,bits_left, 0)) then
@ -384,35 +405,40 @@ begin
if (bits_left < HUFF_LOOKAHEAD) then
begin
nb := 1;
goto label1;
{$IFDEF NOGOTO}
SkipToLabel1:=true;
if DoDecode then
exit;
{$ELSE}
goto label1;
{$ENDIF}
end;
end;
{look := PEEK_BITS(HUFF_LOOKAHEAD);}
look := int(get_buffer shr (bits_left - HUFF_LOOKAHEAD)) and
pred(1 shl HUFF_LOOKAHEAD);
nb := tbl^.look_nbits[look];
if (nb <> 0) then
begin
{DROP_BITS(nb);}
Dec(bits_left, nb);
s := tbl^.look_sym[look];
end
else
begin
nb := HUFF_LOOKAHEAD+1;
label1:
s := jpeg_huff_decode(br_state,get_buffer,bits_left,tbl,nb);
if (s < 0) then
if not SkipToLabel1 then
begin
decode_mcu_DC_first := FALSE;
exit;
end;
get_buffer := br_state.get_buffer;
bits_left := br_state.bits_left;
end;
{look := PEEK_BITS(HUFF_LOOKAHEAD);}
look := int(get_buffer shr (bits_left - HUFF_LOOKAHEAD)) and
pred(1 shl HUFF_LOOKAHEAD);
nb := tbl^.look_nbits[look];
if (nb <> 0) then
begin
{DROP_BITS(nb);}
Dec(bits_left, nb);
s := tbl^.look_sym[look];
end
else
begin
nb := HUFF_LOOKAHEAD+1;
{$IFNDEF NOGOTO}
label1:
{$ENDIF}
if DoDecode then
exit;
end;
end;
if (s <> 0) then
begin
{CHECK_BIT_BUFFER(br_state, s, return FALSE);}
@ -469,8 +495,10 @@ end;
{METHODDEF}
function decode_mcu_AC_first (cinfo : j_decompress_ptr;
var MCU_data : array of JBLOCKROW) : boolean;
{$IFNDEF NOGOTO}
label
label2;
{$ENDIF}
var
entropy : phuff_entropy_ptr;
Se : int;
@ -486,6 +514,19 @@ var
tbl : d_derived_tbl_ptr;
var
nb, look : int; {register}
function DoDecode : boolean;
begin
s := jpeg_huff_decode(br_state,get_buffer,bits_left,tbl,nb);
if (s < 0) then
begin
decode_mcu_AC_first := FALSE;
exit;
end;
get_buffer := br_state.get_buffer;
bits_left := br_state.bits_left;
end;
begin
entropy := phuff_entropy_ptr (cinfo^.entropy);
Se := cinfo^.Se;
@ -544,7 +585,12 @@ begin
if (bits_left < HUFF_LOOKAHEAD) then
begin
nb := 1;
{$IFDEF NOGOTO}
if DoDecode then
exit;
{$ELSE}
goto label2;
{$ENDIF}
end;
end;
{look := PEEK_BITS(HUFF_LOOKAHEAD);}
@ -562,15 +608,11 @@ begin
else
begin
nb := HUFF_LOOKAHEAD+1;
{$IFNDEF NOGOTO}
label2:
s := jpeg_huff_decode(br_state,get_buffer,bits_left,tbl,nb);
if (s < 0) then
begin
decode_mcu_AC_first := FALSE;
{$ENDIF}
if DoDecode then
exit;
end;
get_buffer := br_state.get_buffer;
bits_left := br_state.bits_left;
end;
r := s shr 4;
@ -745,8 +787,10 @@ end;
{METHODDEF}
function decode_mcu_AC_refine (cinfo : j_decompress_ptr;
var MCU_data : array of JBLOCKROW) : boolean;
{$IFNDEF NOGOTO}
label
undoit, label3;
{$ENDIF}
var
entropy : phuff_entropy_ptr;
Se : int;
@ -768,6 +812,30 @@ var
pos : int;
var
nb, look : int; {register}
Function DoDecode: boolean;
begin
s := jpeg_huff_decode(br_state,get_buffer,bits_left,tbl,nb);
if (s < 0) then
exit(True);
get_buffer := br_state.get_buffer;
bits_left := br_state.bits_left;
doDecode:=False;
end;
Procedure FinishDecode;
begin
{ Re-zero any output coefficients that we made newly nonzero }
while (num_newnz > 0) do
begin
Dec(num_newnz);
block^[newnz_pos[num_newnz]] := 0;
end;
decode_mcu_AC_refine := FALSE;
end;
begin
entropy := phuff_entropy_ptr (cinfo^.entropy);
Se := cinfo^.Se;
@ -822,13 +890,28 @@ begin
if (bits_left < HUFF_LOOKAHEAD) then
begin
if (not jpeg_fill_bit_buffer(br_state,get_buffer,bits_left, 0)) then
begin
{$IFDEF NOGOTO}
FinishDecode;
Exit;
{$ELSE}
goto undoit;
{$ENDIF}
end;
get_buffer := br_state.get_buffer;
bits_left := br_state.bits_left;
if (bits_left < HUFF_LOOKAHEAD) then
begin
nb := 1;
{$IFDEF NOGOTO}
if DoDecode then
begin
FinishDecode;
Exit;
end;
{$ELSE}
goto label3;
{$ENDIF}
end;
end;
{look := PEEK_BITS(HUFF_LOOKAHEAD);}
@ -846,12 +929,14 @@ begin
else
begin
nb := HUFF_LOOKAHEAD+1;
{$IFNDEF NOGOTO}
label3:
s := jpeg_huff_decode(br_state,get_buffer,bits_left,tbl,nb);
if (s < 0) then
goto undoit;
get_buffer := br_state.get_buffer;
bits_left := br_state.bits_left;
{$ENDIF}
if DoDecode then
begin
FinishDecode;
Exit;
end;
end;
r := s shr 4;
@ -864,7 +949,14 @@ begin
if (bits_left < 1) then
begin
if (not jpeg_fill_bit_buffer(br_state,get_buffer,bits_left,1)) then
begin
{$IFDEF NOGOTO}
FinishDecode;
Exit;
{$ELSE}
goto undoit;
{$ENDIF}
end;
get_buffer := br_state.get_buffer;
bits_left := br_state.bits_left;
end;
@ -887,7 +979,14 @@ begin
if (bits_left < r) then
begin
if (not jpeg_fill_bit_buffer(br_state,get_buffer,bits_left,r)) then
begin
{$IFDEF NOGOTO}
FinishDecode;
Exit;
{$ELSE}
goto undoit;
{$ENDIF}
end;
get_buffer := br_state.get_buffer;
bits_left := br_state.bits_left;
end;
@ -914,7 +1013,14 @@ begin
if (bits_left < 1) then
begin
if (not jpeg_fill_bit_buffer(br_state,get_buffer,bits_left,1)) then
begin
{$IFDEF NOGOTO}
FinishDecode;
Exit;
{$ELSE}
goto undoit;
{$ENDIF}
end;
get_buffer := br_state.get_buffer;
bits_left := br_state.bits_left;
end;
@ -969,7 +1075,14 @@ begin
if (bits_left < 1) then
begin
if (not jpeg_fill_bit_buffer(br_state,get_buffer,bits_left,1)) then
begin
{$IFDEF NOGOTO}
FinishDecode;
Exit;
{$ELSE}
goto undoit;
{$ENDIF}
end;
get_buffer := br_state.get_buffer;
bits_left := br_state.bits_left;
end;
@ -1009,15 +1122,10 @@ begin
decode_mcu_AC_refine := TRUE;
exit;
{$IFNDEF NOGOTO}
undoit:
{ Re-zero any output coefficients that we made newly nonzero }
while (num_newnz > 0) do
begin
Dec(num_newnz);
block^[newnz_pos[num_newnz]] := 0;
end;
decode_mcu_AC_refine := FALSE;
{$ENDIF}
FinishDecode;
end;

View File

@ -368,10 +368,13 @@ end;
{LOCAL}
procedure update_box (cinfo : j_decompress_ptr; var boxp : box);
{$IFNDEF NOGOTO}
label
have_c0min, have_c0max,
have_c1min, have_c1max,
have_c2min, have_c2max;
{$ENDIF}
{ Shrink the min/max bounds of a box to enclose only nonzero elements, }
{ and recompute its volume and population }
var
@ -382,6 +385,9 @@ var
c0min,c0max,c1min,c1max,c2min,c2max : int;
dist0,dist1,dist2 : INT32;
ccount : long;
{$IFDEF NOGOTO}
doBreak : boolean;
{$ENDIF}
begin
cquantize := my_cquantize_ptr(cinfo^.cquantize);
histogram := cquantize^.histogram;
@ -390,8 +396,12 @@ begin
c1min := boxp.c1min; c1max := boxp.c1max;
c2min := boxp.c2min; c2max := boxp.c2max;
{$IFDEF NOGOTO}
DoBreak:=False;
{$ENDIF}
if (c0max > c0min) then
for c0 := c0min to c0max do
begin
for c1 := c1min to c1max do
begin
histp := @(histogram^[c0]^[c1][c2min]);
@ -401,29 +411,60 @@ begin
begin
c0min := c0;
boxp.c0min := c0min;
{$IFDEF NOGOTO}
DoBreak:=True;
Break; // inner loop
{$ELSE}
goto have_c0min;
{$ENDIF}
end;
Inc(histp);
end;
end;
{$IFDEF NOGOTO}
if DoBreak then
Break;
{$ENDIF}
end;
{$IFNDEF NOGOTO}
have_c0min:
{$ELSE}
DoBreak:=False;
{$ENDIF}
if (c0max > c0min) then
for c0 := c0max downto c0min do
for c1 := c1min to c1max do
begin
histp := @(histogram^[c0]^[c1][c2min]);
for c2 := c2min to c2max do
for c1 := c1min to c1max do
begin
if ( histp^ <> 0) then
histp := @(histogram^[c0]^[c1][c2min]);
for c2 := c2min to c2max do
begin
c0max := c0;
boxp.c0max := c0;
goto have_c0max;
if ( histp^ <> 0) then
begin
c0max := c0;
boxp.c0max := c0;
{$IFDEF NOGOTO}
DoBreak:=True;
Break; // inner loop
{$ELSE}
goto have_c0max;
{$ENDIF}
end;
Inc(histp);
end;
Inc(histp);
end;
{$IFDEF NOGOTO}
if DoBreak then
Break;
{$ENDIF}
end;
have_c0max:
{$IFNDEF NOGOTO}
have_c0max:
{$ELSE}
DoBreak:=False;
{$ENDIF}
if (c1max > c1min) then
for c1 := c1min to c1max do
for c0 := c0min to c0max do
@ -435,12 +476,26 @@ begin
begin
c1min := c1;
boxp.c1min := c1;
{$IFDEF NOGOTO}
DoBreak:=True;
Break; // inner loop
{$ELSE}
goto have_c1min;
{$ENDIF}
end;
Inc(histp);
end;
{$IFDEF NOGOTO}
if DoBreak then
Break;
{$ENDIF}
end;
have_c1min:
{$IFNDEF NOGOTO}
have_c1min:
{$ELSE}
DoBreak:=False;
{$ENDIF}
if (c1max > c1min) then
for c1 := c1max downto c1min do
for c0 := c0min to c0max do
@ -452,46 +507,92 @@ begin
begin
c1max := c1;
boxp.c1max := c1;
{$IFDEF NOGOTO}
DoBreak:=True;
Break; // inner loop
{$ELSE}
goto have_c1max;
{$ENDIF}
end;
Inc(histp);
end;
{$IFDEF NOGOTO}
if DoBreak then
Break;
{$ENDIF}
end;
have_c1max:
{$IFNDEF NOGOTO}
have_c1max:
{$ELSE}
DoBreak:=False;
{$ENDIF}
if (c2max > c2min) then
for c2 := c2min to c2max do
for c0 := c0min to c0max do
begin
histp := @(histogram^[c0]^[c1min][c2]);
for c1 := c1min to c1max do
for c0 := c0min to c0max do
begin
if (histp^ <> 0) then
histp := @(histogram^[c0]^[c1min][c2]);
for c1 := c1min to c1max do
begin
c2min := c2;
boxp.c2min := c2min;
goto have_c2min;
if (histp^ <> 0) then
begin
c2min := c2;
boxp.c2min := c2min;
{$IFDEF NOGOTO}
DoBreak:=True;
Break; // inner loop
{$ELSE}
goto have_c2min;
{$ENDIF}
end;
Inc(histp, HIST_C2_ELEMS);
end;
Inc(histp, HIST_C2_ELEMS);
end;
{$IFDEF NOGOTO}
if DoBreak then
Break;
{$ENDIF}
end;
have_c2min:
{$IFNDEF NOGOTO}
have_c2min:
{$ELSE}
DoBreak:=False;
{$ENDIF}
if (c2max > c2min) then
for c2 := c2max downto c2min do
for c0 := c0min to c0max do
begin
histp := @(histogram^[c0]^[c1min][c2]);
for c1 := c1min to c1max do
for c0 := c0min to c0max do
begin
if (histp^ <> 0) then
histp := @(histogram^[c0]^[c1min][c2]);
for c1 := c1min to c1max do
begin
c2max := c2;
boxp.c2max := c2max;
goto have_c2max;
if (histp^ <> 0) then
begin
c2max := c2;
boxp.c2max := c2max;
{$IFDEF NOGOTO}
DoBreak:=True;
Break; // inner loop
{$ELSE}
goto have_c2max;
{$ENDIF}
end;
Inc(histp, HIST_C2_ELEMS);
end;
Inc(histp, HIST_C2_ELEMS);
end;
{$IFDEF NOGOTO}
if DoBreak then
Break;
{$ENDIF}
end;
have_c2max:
{$IFNDEF NOGOTO}
have_c2max:
{$ELSE}
DoBreak:=False;
{$ENDIF}
{ Update box volume.
We use 2-norm rather than real volume here; this biases the method