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 != "" {