mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-23 16:52:18 +01:00
Add wuffs_base__table_u8__subtable_ij
This commit is contained in:
1 parent
8025bf1bd7
commit
962a515dd2
5 files changed
+57
-4
No files matched your search
@@ -1357,6 +1357,25 @@ wuffs_base__slice_u8__subslice_ij(wuffs_base__slice_u8 s,
|
|||||||
return wuffs_base__make_slice_u8(NULL, 0);
|
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
|
// 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
|
// 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
|
// elements inside the table and, when width != stride, the elements outside
|
||||||
|
|||||||
@@ -1034,6 +1034,15 @@ func (g *gen) writeBuiltinTable(b *buffer, recv *a.Expr, method t.ID, args []*a.
|
|||||||
}
|
}
|
||||||
b.writes(", ")
|
b.writes(", ")
|
||||||
return g.writeArgs(b, args, depth)
|
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 != "" {
|
if field != "" {
|
||||||
|
|||||||
@@ -964,6 +964,8 @@ var TableFuncs = []string{
|
|||||||
"GENERIC T2.width() u64",
|
"GENERIC T2.width() u64",
|
||||||
|
|
||||||
"GENERIC T2.row(y: u32) T1",
|
"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 {
|
func ParseFuncs(tm *t.Map, ss []string, callback func(*a.Func) error) error {
|
||||||
|
|||||||
+8
-4
@@ -670,10 +670,12 @@ const (
|
|||||||
IDPrefix = ID(0x244)
|
IDPrefix = ID(0x244)
|
||||||
IDRow = ID(0x245)
|
IDRow = ID(0x245)
|
||||||
IDStride = ID(0x246)
|
IDStride = ID(0x246)
|
||||||
IDSuffix = ID(0x247)
|
IDSubslice = ID(0x247)
|
||||||
IDUintptrLow12Bits = ID(0x248)
|
IDSubtable = ID(0x248)
|
||||||
IDValidUTF8Length = ID(0x249)
|
IDSuffix = ID(0x249)
|
||||||
IDWidth = ID(0x24A)
|
IDUintptrLow12Bits = ID(0x24A)
|
||||||
|
IDValidUTF8Length = ID(0x24B)
|
||||||
|
IDWidth = ID(0x24C)
|
||||||
|
|
||||||
IDLimitedSwizzleU32InterleavedFromReader = ID(0x280)
|
IDLimitedSwizzleU32InterleavedFromReader = ID(0x280)
|
||||||
IDSwizzleInterleavedFromReader = ID(0x281)
|
IDSwizzleInterleavedFromReader = ID(0x281)
|
||||||
@@ -1094,6 +1096,8 @@ var builtInsByID = [nBuiltInIDs]string{
|
|||||||
IDPrefix: "prefix",
|
IDPrefix: "prefix",
|
||||||
IDRow: "row",
|
IDRow: "row",
|
||||||
IDStride: "stride",
|
IDStride: "stride",
|
||||||
|
IDSubslice: "subslice",
|
||||||
|
IDSubtable: "subtable",
|
||||||
IDSuffix: "suffix",
|
IDSuffix: "suffix",
|
||||||
IDUintptrLow12Bits: "uintptr_low_12_bits",
|
IDUintptrLow12Bits: "uintptr_low_12_bits",
|
||||||
IDValidUTF8Length: "valid_utf_8_length",
|
IDValidUTF8Length: "valid_utf_8_length",
|
||||||
|
|||||||
@@ -1612,6 +1612,25 @@ wuffs_base__slice_u8__subslice_ij(wuffs_base__slice_u8 s,
|
|||||||
return wuffs_base__make_slice_u8(NULL, 0);
|
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
|
// 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
|
// 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
|
// elements inside the table and, when width != stride, the elements outside
|
||||||
|
|||||||
Reference in new issue
Block a user