From e60966aa454ee7b59c91afb2ef9f29de10980196 Mon Sep 17 00:00:00 2001 From: Nigel Tao Date: Sun, 30 Jul 2023 16:05:45 +1000 Subject: [PATCH] pixconv: remove some obsolete swizzle_ycc code --- internal/cgen/base/pixconv-submodule-ycck.c | 85 ------ internal/cgen/cgen.go | 5 + internal/cgen/patch_pixconv.go | 223 -------------- release/c/wuffs-unsupported-snapshot.c | 320 -------------------- 4 files changed, 5 insertions(+), 628 deletions(-) delete mode 100644 internal/cgen/patch_pixconv.go diff --git a/internal/cgen/base/pixconv-submodule-ycck.c b/internal/cgen/base/pixconv-submodule-ycck.c index 168c80d4..2a67bb2e 100644 --- a/internal/cgen/base/pixconv-submodule-ycck.c +++ b/internal/cgen/base/pixconv-submodule-ycck.c @@ -732,91 +732,6 @@ wuffs_base__pixel_swizzler__swizzle_ycc__general__box_filter( // -------- -// Specialized forms of: -// - wuffs_base__pixel_swizzler__swizzle_ycc__general__triangle_filter -// - wuffs_base__pixel_swizzler__swizzle_ycc__general__box_filter - -static void // -wuffs_base__pixel_swizzler__swizzle_ycc__bgrx__hv11( - wuffs_base__pixel_buffer* dst, - uint32_t width, - uint32_t height, - const uint8_t* src_ptr0, - const uint8_t* src_ptr1, - const uint8_t* src_ptr2, - uint32_t stride0, - uint32_t stride1, - uint32_t stride2, - uint32_t inv_h0, - uint32_t inv_h1, - uint32_t inv_h2, - uint32_t inv_v0, - uint32_t inv_v1, - uint32_t inv_v2, - uint32_t half_width_for_2to1, - uint32_t half_height_for_2to1, - uint8_t* scratch_buffer_2k_ptr, - wuffs_base__pixel_swizzler__swizzle_ycc__upsample_func (*upfuncs)[4][4], - wuffs_base__pixel_swizzler__swizzle_ycc__convert_func convfunc) { - uint32_t y = 0u; - for (; y < height; y++) { - const uint8_t* src_iter0 = src_ptr0; - const uint8_t* src_iter1 = src_ptr1; - const uint8_t* src_iter2 = src_ptr2; - - // TODO: call convfunc instead. - size_t dst_stride = dst->private_impl.planes[0].stride; - uint8_t* dst_iter = - dst->private_impl.planes[0].ptr + (dst_stride * ((size_t)y)); - - uint32_t x = 0u; - - for (; (x + 4u) <= width; x += 4u) { - wuffs_base__poke_u32le__no_bounds_check( // - dst_iter + 0x00, // - wuffs_base__color_ycc__as__color_u32( // - src_iter0[0], src_iter1[0], src_iter2[0])); - wuffs_base__poke_u32le__no_bounds_check( // - dst_iter + 0x04, // - wuffs_base__color_ycc__as__color_u32( // - src_iter0[1], src_iter1[1], src_iter2[1])); - wuffs_base__poke_u32le__no_bounds_check( // - dst_iter + 0x08, // - wuffs_base__color_ycc__as__color_u32( // - src_iter0[2], src_iter1[2], src_iter2[2])); - wuffs_base__poke_u32le__no_bounds_check( // - dst_iter + 0x0C, // - wuffs_base__color_ycc__as__color_u32( // - src_iter0[3], src_iter1[3], src_iter2[3])); - dst_iter += 16; - - src_iter0 += 4u; - src_iter1 += 4u; - src_iter2 += 4u; - } - - for (; x < width; x++) { - wuffs_base__poke_u32le__no_bounds_check( // - dst_iter + 0x00, // - wuffs_base__color_ycc__as__color_u32( // - src_iter0[0], src_iter1[0], src_iter2[0])); - dst_iter += 4; - - src_iter0++; - src_iter1++; - src_iter2++; - } - - src_ptr0 += stride0; - src_ptr1 += stride1; - src_ptr2 += stride2; - } -} - -// ¡ INSERT patch_pixconv - -// -------- - // wuffs_base__pixel_swizzler__flattened_length is like // wuffs_base__table__flattened_length but returns uint64_t (not size_t) and // also accounts for subsampling. diff --git a/internal/cgen/cgen.go b/internal/cgen/cgen.go index 962cac46..7534ccf0 100644 --- a/internal/cgen/cgen.go +++ b/internal/cgen/cgen.go @@ -393,6 +393,11 @@ func insertBasePixConvSubmoduleX86Avx2C(buf *buffer) error { return nil } +func insertBasePixConvSubmoduleYcckC(buf *buffer) error { + buf.writes(embedBasePixConvSubmoduleYcckC.Trim()) + return nil +} + func insertBaseUTF8SubmoduleC(buf *buffer) error { buf.writes(embedBaseUTF8SubmoduleC.Trim()) return nil diff --git a/internal/cgen/patch_pixconv.go b/internal/cgen/patch_pixconv.go deleted file mode 100644 index 0cf22312..00000000 --- a/internal/cgen/patch_pixconv.go +++ /dev/null @@ -1,223 +0,0 @@ -// Copyright 2023 The Wuffs Authors. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package cgen - -import ( - "fmt" - "strings" -) - -func insertBasePixConvSubmoduleYcckC(buf *buffer) error { - src := embedBasePixConvSubmoduleYcckC.Trim() - - prefix, suffix := "", "" - const insertPatchPixconv = "// ¡ INSERT patch_pixconv\n\n" - if i := strings.Index(src, insertPatchPixconv); i < 0 { - return fmt.Errorf("internal error: could not find %q", insertPatchPixconv) - } else { - prefix, suffix = src[:i], src[i+len(insertPatchPixconv):] - } - stripCFuncBangComments(buf, prefix) - - // ---- - - const dstIterEtcSansX = "" + - "size_t dst_stride = dst->private_impl.planes[0].stride;\n" + - "uint8_t* dst_iter =\n" + - " dst->private_impl.planes[0].ptr + (dst_stride * ((size_t)y));\n" - const dstIterPlusEq4 = "" + - "dst_iter += 4;\n" - const setColorU32AtOld = "" + - "wuffs_base__pixel_buffer__set_color_u32_at(dst, x, y, color);\n" - const setColorU32AtNew = "" + - "wuffs_base__poke_u32le__no_bounds_check(dst_iter, color);\n" - - // ---- - - patches := []struct { - funcNameLines []string - patchMap map[string]string - }{{ - - []string{ - "wuffs_base__pixel_swizzler__swizzle_ycc__bgrx__hv11(\n", - "wuffs_base__pixel_swizzler__swizzle_ycc__rgbx__hv11(\n", - }, - map[string]string{}, - }, { - - []string{ - "wuffs_base__pixel_swizzler__swizzle_ycc__general__box_filter(\n", - "wuffs_base__pixel_swizzler__swizzle_ycc__bgrx__box_filter(\n", - "wuffs_base__pixel_swizzler__swizzle_ycc__rgbx__box_filter(\n", - }, - map[string]string{ - "// ¡ dst_iter = etc\n": dstIterEtcSansX, - "// ¡ dst_iter += 4\n": dstIterPlusEq4, - setColorU32AtOld: setColorU32AtNew, - }, - }} - - // ---- - - for _, p := range patches { - oldFuncNameLine := p.funcNameLines[0] - - funcSrc, err := extractCFunc(src, "static void //\n"+oldFuncNameLine) - if err != nil { - return err - } - - for _, newFuncNameLine := range p.funcNameLines[1:] { - if err := patchCFunc(buf, funcSrc, oldFuncNameLine, newFuncNameLine, p.patchMap); err != nil { - return err - } - } - } - - stripCFuncBangComments(buf, suffix) - return nil -} - -func extractCFunc(src string, start string) (string, error) { - if i := strings.Index(src, start); i < 0 { - goto fail - } else { - src = src[i:] - } - - if i := strings.Index(src, "\n}\n"); i < 0 { - goto fail - } else { - return src[:i+3], nil - } - -fail: - return "", fmt.Errorf("internal error: could not extractCFunc %q", start) -} - -func stripCFuncBangComments(buf *buffer, s string) { - for { - const slashEtc = "// ¡" - i := strings.Index(s, slashEtc) - if i < 0 { - break - } - - // Extend forwards past (including) the next '\n'. - j := i + len(slashEtc) - for ; (j < len(s)) && (s[j] != '\n'); j++ { - } - if j < len(s) { - j++ - } - - // Extend backwards up to (but excluding) the previous '\n'. - for ; (i > 0) && (s[i-1] != '\n'); i-- { - } - - // Collapse multiple '\n's. - if (i >= 2) && (s[i-2] == '\n') { - for ; (j < len(s)) && (s[j] == '\n'); j++ { - } - } - - buf.writes(s[:i]) - s = s[j:] - } - buf.writes(s) -} - -func patchCFunc(buf *buffer, src string, oldFuncNameLine string, newFuncNameLine string, patchMap map[string]string) error { - m := cloneStringStringMap(patchMap) - m[oldFuncNameLine] = newFuncNameLine - if strings.Contains(newFuncNameLine, "swizzle_ycc__rgbx__") { - m["wuffs_base__color_ycc__as__color_u32( //\n"] = - "wuffs_base__color_ycc__as__color_u32_abgr(\n" - } - - buf.writes("// Generated by internal/cgen/patch_pixconv.go\n") - for src != "" { - line := "" - if i := strings.IndexByte(src, '\n'); i < 0 { - return fmt.Errorf("internal error: patchCFunc failed to find '\n'") - } else { - line, src = src[:i+1], src[i+1:] - } - - key, indent := line, "" - for i := 0; ; i++ { - if i == len(line) { - key, indent = "", line - break - } else if line[i] != ' ' { - key, indent = line[i:], line[:i] - break - } - } - val, ok := m[key] - if !ok { - if !isCFuncComment(line) { - buf.writes(line) - } - continue - } - indentCFunc(buf, indent, val) - if !strings.Contains(key, "¡ BEGIN") { - continue - } - - // Extend forwards past (including) the next '\n'. - j := strings.Index(src, "¡ END ") - if j < 0 { - return fmt.Errorf("internal error: patchCFunc failed to find \"¡ END\"") - } - for ; (j < len(src)) && (src[j] != '\n'); j++ { - } - if j < len(src) { - j++ - } - src = src[j:] - } - buf.writes("\n") - return nil -} - -func isCFuncComment(s string) bool { - for ; (len(s) > 0) && (s[0] <= ' '); s = s[1:] { - } - return (len(s) >= 2) && (s[0] == '/') && (s[1] == '/') -} - -func indentCFunc(buf *buffer, indent string, s string) { - for s != "" { - line := "" - if i := strings.IndexByte(s, '\n'); i < 0 { - line, s = s, "" - } else { - line, s = s[:i+1], s[i+1:] - } - buf.writes(indent) - buf.writes(line) - } -} - -func cloneStringStringMap(m map[string]string) map[string]string { - ret := map[string]string{} - for k, v := range m { - ret[k] = v - } - return ret -} diff --git a/release/c/wuffs-unsupported-snapshot.c b/release/c/wuffs-unsupported-snapshot.c index e98b2e96..79bd1c13 100644 --- a/release/c/wuffs-unsupported-snapshot.c +++ b/release/c/wuffs-unsupported-snapshot.c @@ -24284,326 +24284,6 @@ wuffs_base__pixel_swizzler__swizzle_ycc__general__box_filter( // -------- -// Specialized forms of: -// - wuffs_base__pixel_swizzler__swizzle_ycc__general__triangle_filter -// - wuffs_base__pixel_swizzler__swizzle_ycc__general__box_filter - -static void // -wuffs_base__pixel_swizzler__swizzle_ycc__bgrx__hv11( - wuffs_base__pixel_buffer* dst, - uint32_t width, - uint32_t height, - const uint8_t* src_ptr0, - const uint8_t* src_ptr1, - const uint8_t* src_ptr2, - uint32_t stride0, - uint32_t stride1, - uint32_t stride2, - uint32_t inv_h0, - uint32_t inv_h1, - uint32_t inv_h2, - uint32_t inv_v0, - uint32_t inv_v1, - uint32_t inv_v2, - uint32_t half_width_for_2to1, - uint32_t half_height_for_2to1, - uint8_t* scratch_buffer_2k_ptr, - wuffs_base__pixel_swizzler__swizzle_ycc__upsample_func (*upfuncs)[4][4], - wuffs_base__pixel_swizzler__swizzle_ycc__convert_func convfunc) { - uint32_t y = 0u; - for (; y < height; y++) { - const uint8_t* src_iter0 = src_ptr0; - const uint8_t* src_iter1 = src_ptr1; - const uint8_t* src_iter2 = src_ptr2; - - // TODO: call convfunc instead. - size_t dst_stride = dst->private_impl.planes[0].stride; - uint8_t* dst_iter = - dst->private_impl.planes[0].ptr + (dst_stride * ((size_t)y)); - - uint32_t x = 0u; - - for (; (x + 4u) <= width; x += 4u) { - wuffs_base__poke_u32le__no_bounds_check( // - dst_iter + 0x00, // - wuffs_base__color_ycc__as__color_u32( // - src_iter0[0], src_iter1[0], src_iter2[0])); - wuffs_base__poke_u32le__no_bounds_check( // - dst_iter + 0x04, // - wuffs_base__color_ycc__as__color_u32( // - src_iter0[1], src_iter1[1], src_iter2[1])); - wuffs_base__poke_u32le__no_bounds_check( // - dst_iter + 0x08, // - wuffs_base__color_ycc__as__color_u32( // - src_iter0[2], src_iter1[2], src_iter2[2])); - wuffs_base__poke_u32le__no_bounds_check( // - dst_iter + 0x0C, // - wuffs_base__color_ycc__as__color_u32( // - src_iter0[3], src_iter1[3], src_iter2[3])); - dst_iter += 16; - - src_iter0 += 4u; - src_iter1 += 4u; - src_iter2 += 4u; - } - - for (; x < width; x++) { - wuffs_base__poke_u32le__no_bounds_check( // - dst_iter + 0x00, // - wuffs_base__color_ycc__as__color_u32( // - src_iter0[0], src_iter1[0], src_iter2[0])); - dst_iter += 4; - - src_iter0++; - src_iter1++; - src_iter2++; - } - - src_ptr0 += stride0; - src_ptr1 += stride1; - src_ptr2 += stride2; - } -} - -// Generated by internal/cgen/patch_pixconv.go -static void // -wuffs_base__pixel_swizzler__swizzle_ycc__rgbx__hv11( - wuffs_base__pixel_buffer* dst, - uint32_t width, - uint32_t height, - const uint8_t* src_ptr0, - const uint8_t* src_ptr1, - const uint8_t* src_ptr2, - uint32_t stride0, - uint32_t stride1, - uint32_t stride2, - uint32_t inv_h0, - uint32_t inv_h1, - uint32_t inv_h2, - uint32_t inv_v0, - uint32_t inv_v1, - uint32_t inv_v2, - uint32_t half_width_for_2to1, - uint32_t half_height_for_2to1, - uint8_t* scratch_buffer_2k_ptr, - wuffs_base__pixel_swizzler__swizzle_ycc__upsample_func (*upfuncs)[4][4], - wuffs_base__pixel_swizzler__swizzle_ycc__convert_func convfunc) { - uint32_t y = 0u; - for (; y < height; y++) { - const uint8_t* src_iter0 = src_ptr0; - const uint8_t* src_iter1 = src_ptr1; - const uint8_t* src_iter2 = src_ptr2; - - size_t dst_stride = dst->private_impl.planes[0].stride; - uint8_t* dst_iter = - dst->private_impl.planes[0].ptr + (dst_stride * ((size_t)y)); - - uint32_t x = 0u; - - for (; (x + 4u) <= width; x += 4u) { - wuffs_base__poke_u32le__no_bounds_check( // - dst_iter + 0x00, // - wuffs_base__color_ycc__as__color_u32_abgr( - src_iter0[0], src_iter1[0], src_iter2[0])); - wuffs_base__poke_u32le__no_bounds_check( // - dst_iter + 0x04, // - wuffs_base__color_ycc__as__color_u32_abgr( - src_iter0[1], src_iter1[1], src_iter2[1])); - wuffs_base__poke_u32le__no_bounds_check( // - dst_iter + 0x08, // - wuffs_base__color_ycc__as__color_u32_abgr( - src_iter0[2], src_iter1[2], src_iter2[2])); - wuffs_base__poke_u32le__no_bounds_check( // - dst_iter + 0x0C, // - wuffs_base__color_ycc__as__color_u32_abgr( - src_iter0[3], src_iter1[3], src_iter2[3])); - dst_iter += 16; - - src_iter0 += 4u; - src_iter1 += 4u; - src_iter2 += 4u; - } - - for (; x < width; x++) { - wuffs_base__poke_u32le__no_bounds_check( // - dst_iter + 0x00, // - wuffs_base__color_ycc__as__color_u32_abgr( - src_iter0[0], src_iter1[0], src_iter2[0])); - dst_iter += 4; - - src_iter0++; - src_iter1++; - src_iter2++; - } - - src_ptr0 += stride0; - src_ptr1 += stride1; - src_ptr2 += stride2; - } -} - -// Generated by internal/cgen/patch_pixconv.go -static void // -wuffs_base__pixel_swizzler__swizzle_ycc__bgrx__box_filter( - wuffs_base__pixel_buffer* dst, - uint32_t width, - uint32_t height, - const uint8_t* src_ptr0, - const uint8_t* src_ptr1, - const uint8_t* src_ptr2, - uint32_t stride0, - uint32_t stride1, - uint32_t stride2, - uint32_t inv_h0, - uint32_t inv_h1, - uint32_t inv_h2, - uint32_t inv_v0, - uint32_t inv_v1, - uint32_t inv_v2, - uint32_t half_width_for_2to1, - uint32_t half_height_for_2to1, - uint8_t* scratch_buffer_2k_ptr, - wuffs_base__pixel_swizzler__swizzle_ycc__upsample_func (*upfuncs)[4][4], - wuffs_base__pixel_swizzler__swizzle_ycc__convert_func convfunc) { - wuffs_base__pixel_swizzler__swizzle_ycc__upsample_func upfunc0 = - (*upfuncs)[(inv_h0 - 1u) & 3u][(inv_v0 - 1u) & 3u]; - wuffs_base__pixel_swizzler__swizzle_ycc__upsample_func upfunc1 = - (*upfuncs)[(inv_h1 - 1u) & 3u][(inv_v1 - 1u) & 3u]; - wuffs_base__pixel_swizzler__swizzle_ycc__upsample_func upfunc2 = - (*upfuncs)[(inv_h2 - 1u) & 3u][(inv_v2 - 1u) & 3u]; - - uint32_t y; - for (y = 0u; y < height; y++) { - const uint8_t* src0_major = src_ptr0 + ((y / inv_v0) * (size_t)stride0); - const uint8_t* src1_major = src_ptr1 + ((y / inv_v1) * (size_t)stride1); - const uint8_t* src2_major = src_ptr2 + ((y / inv_v2) * (size_t)stride2); - uint32_t total_src_len0 = 0u; - uint32_t total_src_len1 = 0u; - uint32_t total_src_len2 = 0u; - - uint32_t x = 0u; - while (x < width) { - uint32_t end = x + 672u; - if (end > width) { - end = width; - } - - uint32_t src_len0 = ((end - x) + inv_h0 - 1u) / inv_h0; - uint32_t src_len1 = ((end - x) + inv_h1 - 1u) / inv_h1; - uint32_t src_len2 = ((end - x) + inv_h2 - 1u) / inv_h2; - total_src_len0 += src_len0; - total_src_len1 += src_len1; - total_src_len2 += src_len2; - - const uint8_t* up0 = (*upfunc0)( // - scratch_buffer_2k_ptr + (0u * 672u), // - src0_major + (x / inv_h0), // - src0_major + (x / inv_h0), // - src_len0, // - 0u, false, false); - - const uint8_t* up1 = (*upfunc1)( // - scratch_buffer_2k_ptr + (1u * 672u), // - src1_major + (x / inv_h1), // - src1_major + (x / inv_h1), // - src_len1, // - 0u, false, false); - - const uint8_t* up2 = (*upfunc2)( // - scratch_buffer_2k_ptr + (2u * 672u), // - src2_major + (x / inv_h2), // - src2_major + (x / inv_h2), // - src_len2, // - 0u, false, false); - - (*convfunc)(dst, x, end, y, up0, up1, up2); - x = end; - } - } -} - -// Generated by internal/cgen/patch_pixconv.go -static void // -wuffs_base__pixel_swizzler__swizzle_ycc__rgbx__box_filter( - wuffs_base__pixel_buffer* dst, - uint32_t width, - uint32_t height, - const uint8_t* src_ptr0, - const uint8_t* src_ptr1, - const uint8_t* src_ptr2, - uint32_t stride0, - uint32_t stride1, - uint32_t stride2, - uint32_t inv_h0, - uint32_t inv_h1, - uint32_t inv_h2, - uint32_t inv_v0, - uint32_t inv_v1, - uint32_t inv_v2, - uint32_t half_width_for_2to1, - uint32_t half_height_for_2to1, - uint8_t* scratch_buffer_2k_ptr, - wuffs_base__pixel_swizzler__swizzle_ycc__upsample_func (*upfuncs)[4][4], - wuffs_base__pixel_swizzler__swizzle_ycc__convert_func convfunc) { - wuffs_base__pixel_swizzler__swizzle_ycc__upsample_func upfunc0 = - (*upfuncs)[(inv_h0 - 1u) & 3u][(inv_v0 - 1u) & 3u]; - wuffs_base__pixel_swizzler__swizzle_ycc__upsample_func upfunc1 = - (*upfuncs)[(inv_h1 - 1u) & 3u][(inv_v1 - 1u) & 3u]; - wuffs_base__pixel_swizzler__swizzle_ycc__upsample_func upfunc2 = - (*upfuncs)[(inv_h2 - 1u) & 3u][(inv_v2 - 1u) & 3u]; - - uint32_t y; - for (y = 0u; y < height; y++) { - const uint8_t* src0_major = src_ptr0 + ((y / inv_v0) * (size_t)stride0); - const uint8_t* src1_major = src_ptr1 + ((y / inv_v1) * (size_t)stride1); - const uint8_t* src2_major = src_ptr2 + ((y / inv_v2) * (size_t)stride2); - uint32_t total_src_len0 = 0u; - uint32_t total_src_len1 = 0u; - uint32_t total_src_len2 = 0u; - - uint32_t x = 0u; - while (x < width) { - uint32_t end = x + 672u; - if (end > width) { - end = width; - } - - uint32_t src_len0 = ((end - x) + inv_h0 - 1u) / inv_h0; - uint32_t src_len1 = ((end - x) + inv_h1 - 1u) / inv_h1; - uint32_t src_len2 = ((end - x) + inv_h2 - 1u) / inv_h2; - total_src_len0 += src_len0; - total_src_len1 += src_len1; - total_src_len2 += src_len2; - - const uint8_t* up0 = (*upfunc0)( // - scratch_buffer_2k_ptr + (0u * 672u), // - src0_major + (x / inv_h0), // - src0_major + (x / inv_h0), // - src_len0, // - 0u, false, false); - - const uint8_t* up1 = (*upfunc1)( // - scratch_buffer_2k_ptr + (1u * 672u), // - src1_major + (x / inv_h1), // - src1_major + (x / inv_h1), // - src_len1, // - 0u, false, false); - - const uint8_t* up2 = (*upfunc2)( // - scratch_buffer_2k_ptr + (2u * 672u), // - src2_major + (x / inv_h2), // - src2_major + (x / inv_h2), // - src_len2, // - 0u, false, false); - - (*convfunc)(dst, x, end, y, up0, up1, up2); - x = end; - } - } -} - -// -------- - // wuffs_base__pixel_swizzler__flattened_length is like // wuffs_base__table__flattened_length but returns uint64_t (not size_t) and // also accounts for subsampling.