Add wuffs_base__table_u8__subtable_ij

This commit is contained in:
Nigel Tao committed 2021-11-15 09:58:02 +11:00
1 parent 8025bf1bd7
commit 962a515dd2
5 files changed
+57 -4

No files matched your search

+19
View File
@@ -1357,6 +1357,25 @@ wuffs_base__slice_u8__subslice_ij(wuffs_base__slice_u8 s,
return wuffs_base__make_slice_u8(NULL, 0);
}
// wuffs_base__table_u8__subtable_ij returns t[ix:jx, iy:jy].
//
// It returns an empty table if i or j is out of bounds.
static inline wuffs_base__table_u8 //
wuffs_base__table_u8__subtable_ij(wuffs_base__table_u8 t,
uint64_t ix,
uint64_t iy,
uint64_t jx,
uint64_t jy) {
if ((ix <= jx) && (jx <= SIZE_MAX) && (jx <= t.width) && //
(iy <= jy) && (jy <= SIZE_MAX) && (jy <= t.height)) {
return wuffs_base__make_table_u8(t.ptr + ix + (iy * t.stride), //
((size_t)(jx - ix)), //
((size_t)(jy - iy)), //
t.stride); //
}
return wuffs_base__make_table_u8(NULL, 0, 0, 0);
}
// wuffs_base__table__flattened_length returns the number of elements covered
// by the 1-dimensional span that backs a 2-dimensional table. This counts the
// elements inside the table and, when width != stride, the elements outside
+9
View File
@@ -1034,6 +1034,15 @@ func (g *gen) writeBuiltinTable(b *buffer, recv *a.Expr, method t.ID, args []*a.
}
b.writes(", ")
return g.writeArgs(b, args, depth)
case t.IDSubtable:
// TODO: don't assume that the table is a table of base.u8.
b.writes("wuffs_base__table_u8__subtable_ij(")
if err := g.writeExpr(b, recv, false, depth); err != nil {
return err
}
b.writes(", ")
return g.writeArgs(b, args, depth)
}
if field != "" {
+2
View File
@@ -964,6 +964,8 @@ var TableFuncs = []string{
"GENERIC T2.width() u64",
"GENERIC T2.row(y: u32) T1",
"GENERIC T2.subtable(" +
"min_incl_x: u64, min_incl_y: u64, max_incl_x: u64, max_incl_y: u64) T2",
}
func ParseFuncs(tm *t.Map, ss []string, callback func(*a.Func) error) error {
+8 -4
View File
@@ -670,10 +670,12 @@ const (
IDPrefix = ID(0x244)
IDRow = ID(0x245)
IDStride = ID(0x246)
IDSuffix = ID(0x247)
IDUintptrLow12Bits = ID(0x248)
IDValidUTF8Length = ID(0x249)
IDWidth = ID(0x24A)
IDSubslice = ID(0x247)
IDSubtable = ID(0x248)
IDSuffix = ID(0x249)
IDUintptrLow12Bits = ID(0x24A)
IDValidUTF8Length = ID(0x24B)
IDWidth = ID(0x24C)
IDLimitedSwizzleU32InterleavedFromReader = ID(0x280)
IDSwizzleInterleavedFromReader = ID(0x281)
@@ -1094,6 +1096,8 @@ var builtInsByID = [nBuiltInIDs]string{
IDPrefix: "prefix",
IDRow: "row",
IDStride: "stride",
IDSubslice: "subslice",
IDSubtable: "subtable",
IDSuffix: "suffix",
IDUintptrLow12Bits: "uintptr_low_12_bits",
IDValidUTF8Length: "valid_utf_8_length",
+19
View File
@@ -1612,6 +1612,25 @@ wuffs_base__slice_u8__subslice_ij(wuffs_base__slice_u8 s,
return wuffs_base__make_slice_u8(NULL, 0);
}
// wuffs_base__table_u8__subtable_ij returns t[ix:jx, iy:jy].
//
// It returns an empty table if i or j is out of bounds.
static inline wuffs_base__table_u8 //
wuffs_base__table_u8__subtable_ij(wuffs_base__table_u8 t,
uint64_t ix,
uint64_t iy,
uint64_t jx,
uint64_t jy) {
if ((ix <= jx) && (jx <= SIZE_MAX) && (jx <= t.width) && //
(iy <= jy) && (jy <= SIZE_MAX) && (jy <= t.height)) {
return wuffs_base__make_table_u8(t.ptr + ix + (iy * t.stride), //
((size_t)(jx - ix)), //
((size_t)(jy - iy)), //
t.stride); //
}
return wuffs_base__make_table_u8(NULL, 0, 0, 0);
}
// wuffs_base__table__flattened_length returns the number of elements covered
// by the 1-dimensional span that backs a 2-dimensional table. This counts the
// elements inside the table and, when width != stride, the elements outside