Add double-curly blocks

This commit is contained in:
Nigel Tao committed 2020-04-02 21:56:53 +11:00
1 parent 4cfc367a9b
commit 3fe3f84106
8 files changed
+1243 -1192

No files matched your search

+93 -92
View File
@@ -544,105 +544,106 @@ pri func config_decoder.decode_ae?(src: base.io_reader) {
var is_iccp : base.bool
var is_xmp : base.bool
while.goto_done true {
block_size = args.src.read_u8?()
if block_size == 0 {
return ok
}
while.goto_done true {{
block_size = args.src.read_u8?()
if block_size == 0 {
return ok
}
// Look only for an 11 byte "ANIMEXTS1.0", "NETSCAPE2.0" or other
// extension, as per:
// - http://www.vurdalakov.net/misc/gif/animexts-looping-application-extension
// - http://www.vurdalakov.net/misc/gif/netscape-looping-application-extension
//
// Other extensions include XMP metadata.
if block_size <> 11 {
// Look only for an 11 byte "ANIMEXTS1.0", "NETSCAPE2.0" or other
// extension, as per:
// - http://www.vurdalakov.net/misc/gif/animexts-looping-application-extension
// - http://www.vurdalakov.net/misc/gif/netscape-looping-application-extension
//
// Other extensions include XMP metadata.
if block_size <> 11 {
args.src.skip32?(n: block_size as base.u32)
break.goto_done
}
is_animexts = true
is_netscape = true
is_iccp = true
is_xmp = true
block_size = 0 // Re-purpose the block_size variable as a counter.
while block_size < 11 {
c = args.src.read_u8?()
is_animexts = is_animexts and (c == animexts1dot0[block_size])
is_netscape = is_netscape and (c == netscape2dot0[block_size])
is_iccp = is_iccp and (c == iccrgbg1012[block_size])
is_xmp = is_xmp and (c == xmpdataxmp[block_size])
block_size += 1
} endwhile
if is_animexts or is_netscape {
// Those 11 bytes should be followed by 0x03, 0x01 and then the loop
// count.
block_size = args.src.read_u8?()
if block_size <> 3 {
args.src.skip32?(n: block_size as base.u32)
break.goto_done
}
is_animexts = true
is_netscape = true
is_iccp = true
is_xmp = true
block_size = 0 // Re-purpose the block_size variable as a counter.
while block_size < 11 {
c = args.src.read_u8?()
is_animexts = is_animexts and (c == animexts1dot0[block_size])
is_netscape = is_netscape and (c == netscape2dot0[block_size])
is_iccp = is_iccp and (c == iccrgbg1012[block_size])
is_xmp = is_xmp and (c == xmpdataxmp[block_size])
block_size += 1
} endwhile
c = args.src.read_u8?()
if c <> 0x01 {
args.src.skip32?(n: 2)
break.goto_done
}
this.num_loops = args.src.read_u16le_as_u32?()
this.seen_num_loops = true
if is_animexts or is_netscape {
// Those 11 bytes should be followed by 0x03, 0x01 and then the loop
// count.
block_size = args.src.read_u8?()
if block_size <> 3 {
args.src.skip32?(n: block_size as base.u32)
break.goto_done
}
c = args.src.read_u8?()
if c <> 0x01 {
args.src.skip32?(n: 2)
break.goto_done
}
this.num_loops = args.src.read_u16le_as_u32?()
this.seen_num_loops = true
// A loop count of N, in the wire format, actually means "repeat N
// times after the first play", if N is positive. A zero N means to
// loop forever. Playing the frames exactly once is denoted by the
// *absence* of this NETSCAPE2.0 application extension.
//
// For example, if there are four frames: A, B, C, D, and N is 2, then
// each frame is actually played N+1 or 3 times: ABCDABCDABCD.
//
// Thus, we increment N if it is positive. The comparison against
// 0xFFFF will never fail, but is necessary for the overflow checker.
if (0 < this.num_loops) and (this.num_loops <= 0xFFFF) {
this.num_loops += 1
}
} else if this.ignore_metadata {
// No-op.
} else if is_iccp and this.report_metadata_iccp {
while args.src.available() <= 0,
post args.src.available() > 0,
{
yield? base."$short read"
} endwhile
this.metadata_chunk_length_value = args.src.peek_u8_as_u64()
args.src.skip32_fast!(actual: 1, worst_case: 1)
this.metadata_fourcc_value = 'ICCP'be
this.metadata_io_position = args.src.position() ~sat+ this.metadata_chunk_length_value
this.call_sequence = 1
return base."@metadata reported"
} else if is_xmp and this.report_metadata_xmp {
while args.src.available() <= 0,
post args.src.available() > 0,
{
yield? base."$short read"
} endwhile
this.metadata_chunk_length_value = args.src.peek_u8_as_u64()
if this.metadata_chunk_length_value > 0 {
// The +1 is because XMP metadata's encoding includes each
// block's leading byte (the block size) as part of the
// metadata passed to the caller.
this.metadata_chunk_length_value += 1
} else {
args.src.skip32_fast!(actual: 1, worst_case: 1)
}
this.metadata_fourcc_value = 'XMP 'be
this.metadata_io_position = args.src.position() ~sat+ this.metadata_chunk_length_value
this.call_sequence = 1
return base."@metadata reported"
// A loop count of N, in the wire format, actually means "repeat N
// times after the first play", if N is positive. A zero N means to
// loop forever. Playing the frames exactly once is denoted by the
// *absence* of this NETSCAPE2.0 application extension.
//
// For example, if there are four frames: A, B, C, D, and N is 2, then
// each frame is actually played N+1 or 3 times: ABCDABCDABCD.
//
// Thus, we increment N if it is positive. The comparison against
// 0xFFFF will never fail, but is necessary for the overflow checker.
if (0 < this.num_loops) and (this.num_loops <= 0xFFFF) {
this.num_loops += 1
}
break.goto_done
} endwhile.goto_done
} else if this.ignore_metadata {
// No-op.
} else if is_iccp and this.report_metadata_iccp {
while args.src.available() <= 0,
post args.src.available() > 0,
{
yield? base."$short read"
} endwhile
this.metadata_chunk_length_value = args.src.peek_u8_as_u64()
args.src.skip32_fast!(actual: 1, worst_case: 1)
this.metadata_fourcc_value = 'ICCP'be
this.metadata_io_position = args.src.position() ~sat+ this.metadata_chunk_length_value
this.call_sequence = 1
return base."@metadata reported"
} else if is_xmp and this.report_metadata_xmp {
while args.src.available() <= 0,
post args.src.available() > 0,
{
yield? base."$short read"
} endwhile
this.metadata_chunk_length_value = args.src.peek_u8_as_u64()
if this.metadata_chunk_length_value > 0 {
// The +1 is because XMP metadata's encoding includes each
// block's leading byte (the block size) as part of the
// metadata passed to the caller.
this.metadata_chunk_length_value += 1
} else {
args.src.skip32_fast!(actual: 1, worst_case: 1)
}
this.metadata_fourcc_value = 'XMP 'be
this.metadata_io_position = args.src.position() ~sat+ this.metadata_chunk_length_value
this.call_sequence = 1
return base."@metadata reported"
}
break.goto_done
}} endwhile.goto_done
this.skip_blocks?(src: args.src)
}
+93 -92
View File
@@ -619,105 +619,106 @@ pri func decoder.decode_ae?(src: base.io_reader) {
var is_iccp : base.bool
var is_xmp : base.bool
while.goto_done true {
block_size = args.src.read_u8?()
if block_size == 0 {
return ok
}
while.goto_done true {{
block_size = args.src.read_u8?()
if block_size == 0 {
return ok
}
// Look only for an 11 byte "ANIMEXTS1.0", "NETSCAPE2.0" or other
// extension, as per:
// - http://www.vurdalakov.net/misc/gif/animexts-looping-application-extension
// - http://www.vurdalakov.net/misc/gif/netscape-looping-application-extension
//
// Other extensions include XMP metadata.
if block_size <> 11 {
// Look only for an 11 byte "ANIMEXTS1.0", "NETSCAPE2.0" or other
// extension, as per:
// - http://www.vurdalakov.net/misc/gif/animexts-looping-application-extension
// - http://www.vurdalakov.net/misc/gif/netscape-looping-application-extension
//
// Other extensions include XMP metadata.
if block_size <> 11 {
args.src.skip32?(n: block_size as base.u32)
break.goto_done
}
is_animexts = true
is_netscape = true
is_iccp = true
is_xmp = true
block_size = 0 // Re-purpose the block_size variable as a counter.
while block_size < 11 {
c = args.src.read_u8?()
is_animexts = is_animexts and (c == animexts1dot0[block_size])
is_netscape = is_netscape and (c == netscape2dot0[block_size])
is_iccp = is_iccp and (c == iccrgbg1012[block_size])
is_xmp = is_xmp and (c == xmpdataxmp[block_size])
block_size += 1
} endwhile
if is_animexts or is_netscape {
// Those 11 bytes should be followed by 0x03, 0x01 and then the loop
// count.
block_size = args.src.read_u8?()
if block_size <> 3 {
args.src.skip32?(n: block_size as base.u32)
break.goto_done
}
is_animexts = true
is_netscape = true
is_iccp = true
is_xmp = true
block_size = 0 // Re-purpose the block_size variable as a counter.
while block_size < 11 {
c = args.src.read_u8?()
is_animexts = is_animexts and (c == animexts1dot0[block_size])
is_netscape = is_netscape and (c == netscape2dot0[block_size])
is_iccp = is_iccp and (c == iccrgbg1012[block_size])
is_xmp = is_xmp and (c == xmpdataxmp[block_size])
block_size += 1
} endwhile
c = args.src.read_u8?()
if c <> 0x01 {
args.src.skip32?(n: 2)
break.goto_done
}
this.num_loops = args.src.read_u16le_as_u32?()
this.seen_num_loops = true
if is_animexts or is_netscape {
// Those 11 bytes should be followed by 0x03, 0x01 and then the loop
// count.
block_size = args.src.read_u8?()
if block_size <> 3 {
args.src.skip32?(n: block_size as base.u32)
break.goto_done
}
c = args.src.read_u8?()
if c <> 0x01 {
args.src.skip32?(n: 2)
break.goto_done
}
this.num_loops = args.src.read_u16le_as_u32?()
this.seen_num_loops = true
// A loop count of N, in the wire format, actually means "repeat N
// times after the first play", if N is positive. A zero N means to
// loop forever. Playing the frames exactly once is denoted by the
// *absence* of this NETSCAPE2.0 application extension.
//
// For example, if there are four frames: A, B, C, D, and N is 2, then
// each frame is actually played N+1 or 3 times: ABCDABCDABCD.
//
// Thus, we increment N if it is positive. The comparison against
// 0xFFFF will never fail, but is necessary for the overflow checker.
if (0 < this.num_loops) and (this.num_loops <= 0xFFFF) {
this.num_loops += 1
}
} else if this.ignore_metadata {
// No-op.
} else if is_iccp and this.report_metadata_iccp {
while args.src.available() <= 0,
post args.src.available() > 0,
{
yield? base."$short read"
} endwhile
this.metadata_chunk_length_value = args.src.peek_u8_as_u64()
args.src.skip32_fast!(actual: 1, worst_case: 1)
this.metadata_fourcc_value = 'ICCP'be
this.metadata_io_position = args.src.position() ~sat+ this.metadata_chunk_length_value
this.call_sequence = 1
return base."@metadata reported"
} else if is_xmp and this.report_metadata_xmp {
while args.src.available() <= 0,
post args.src.available() > 0,
{
yield? base."$short read"
} endwhile
this.metadata_chunk_length_value = args.src.peek_u8_as_u64()
if this.metadata_chunk_length_value > 0 {
// The +1 is because XMP metadata's encoding includes each
// block's leading byte (the block size) as part of the
// metadata passed to the caller.
this.metadata_chunk_length_value += 1
} else {
args.src.skip32_fast!(actual: 1, worst_case: 1)
}
this.metadata_fourcc_value = 'XMP 'be
this.metadata_io_position = args.src.position() ~sat+ this.metadata_chunk_length_value
this.call_sequence = 1
return base."@metadata reported"
// A loop count of N, in the wire format, actually means "repeat N
// times after the first play", if N is positive. A zero N means to
// loop forever. Playing the frames exactly once is denoted by the
// *absence* of this NETSCAPE2.0 application extension.
//
// For example, if there are four frames: A, B, C, D, and N is 2, then
// each frame is actually played N+1 or 3 times: ABCDABCDABCD.
//
// Thus, we increment N if it is positive. The comparison against
// 0xFFFF will never fail, but is necessary for the overflow checker.
if (0 < this.num_loops) and (this.num_loops <= 0xFFFF) {
this.num_loops += 1
}
break.goto_done
} endwhile.goto_done
} else if this.ignore_metadata {
// No-op.
} else if is_iccp and this.report_metadata_iccp {
while args.src.available() <= 0,
post args.src.available() > 0,
{
yield? base."$short read"
} endwhile
this.metadata_chunk_length_value = args.src.peek_u8_as_u64()
args.src.skip32_fast!(actual: 1, worst_case: 1)
this.metadata_fourcc_value = 'ICCP'be
this.metadata_io_position = args.src.position() ~sat+ this.metadata_chunk_length_value
this.call_sequence = 1
return base."@metadata reported"
} else if is_xmp and this.report_metadata_xmp {
while args.src.available() <= 0,
post args.src.available() > 0,
{
yield? base."$short read"
} endwhile
this.metadata_chunk_length_value = args.src.peek_u8_as_u64()
if this.metadata_chunk_length_value > 0 {
// The +1 is because XMP metadata's encoding includes each
// block's leading byte (the block size) as part of the
// metadata passed to the caller.
this.metadata_chunk_length_value += 1
} else {
args.src.skip32_fast!(actual: 1, worst_case: 1)
}
this.metadata_fourcc_value = 'XMP 'be
this.metadata_io_position = args.src.position() ~sat+ this.metadata_chunk_length_value
this.call_sequence = 1
return base."@metadata reported"
}
break.goto_done
}} endwhile.goto_done
this.skip_blocks?(src: args.src)
}