[vlc-commits] [Git][videolan/vlc][master] 9 commits: orient: check unsupported cases earlier

Hugo Beauzée-Luyssen (@chouquette) gitlab at videolan.org
Wed Feb 23 09:23:43 UTC 2022



Hugo Beauzée-Luyssen pushed to branch master at VideoLAN / VLC


Commits:
1a84d94c by Rémi Denis-Courmont at 2022-02-23T08:50:59+00:00
orient: check unsupported cases earlier

Check for unsupported scenarii before allocating memory.

- - - - -
57e258ed by Rémi Denis-Courmont at 2022-02-23T08:50:59+00:00
orient: reorder code

No functional changes.

- - - - -
ae0f467f by Rémi Denis-Courmont at 2022-02-23T08:50:59+00:00
orient: save sample byte size for each plane

This saves the order of magnitude of the sample byte size for each
plane. This will be used in later changes.

- - - - -
0255871c by Rémi Denis-Courmont at 2022-02-23T08:50:59+00:00
orient: factor composite transform plane functions

Rotations and anti-transposition are defined as the composition of
horizontal flip or transposition with one or two "free" vertical flips
(i.e. negated stride). The 3 functions, for 8-, 16- and 32-bit samples
were essentially identical.

This takes them out of the transforms macro and merge the function.
With this size-specific functions and function pointers remain only for
horizontal flip and transposition. This reduces the code size, and more
importantly simplifies writing SIMD-optimised transforms.

- - - - -
c8215298 by Rémi Denis-Courmont at 2022-02-23T08:50:59+00:00
orient: remove redundant macro

- - - - -
5148ff1d by Rémi Denis-Courmont at 2022-02-23T08:50:59+00:00
orient: keep single transform callback

Planes may have different sample size (if NV12 or NV21 chroma), but the
transform is always the same, so per-plane callbacks are no longer
necessary.

- - - - -
b91c228e by Rémi Denis-Courmont at 2022-02-23T08:50:59+00:00
orient: remove redundant break's

- - - - -
e99b7019 by Rémi Denis-Courmont at 2022-02-23T08:50:59+00:00
orient: add support for 64-bit formats

At this point, high-definition RGBA is 64-bit format. Since the support
code is essentially already there in macro form, take it into use.

- - - - -
dc26eb53 by Rémi Denis-Courmont at 2022-02-23T08:50:59+00:00
orient: move typedefs to header file

- - - - -


3 changed files:

- modules/video_chroma/Makefile.am
- modules/video_chroma/orient.c
- + modules/video_chroma/orient.h


Changes:

=====================================
modules/video_chroma/Makefile.am
=====================================
@@ -40,7 +40,7 @@ libyuy2_i422_plugin_la_SOURCES = video_chroma/yuy2_i422.c
 
 libyuvp_plugin_la_SOURCES = video_chroma/yuvp.c
 
-liborient_plugin_la_SOURCES = video_chroma/orient.c
+liborient_plugin_la_SOURCES = video_chroma/orient.c video_chroma/orient.h
 
 chroma_LTLIBRARIES = \
 	libi420_rgb_plugin.la \


=====================================
modules/video_chroma/orient.c
=====================================
@@ -34,22 +34,7 @@
 #include <vlc_mouse.h>
 #include <vlc_picture.h>
 
-static void vflip(void *restrict dst, ptrdiff_t dst_stride,
-                  const void *restrict src, ptrdiff_t src_stride,
-                  int width, int height, int order)
-{
-    const unsigned char *src_pixels = src;
-    unsigned char *restrict dst_pixels = dst;
-    size_t visible_pitch = width << order;
-
-    dst_pixels += dst_stride * height;
-
-    for (int y = 0; y < height; y++) {
-        dst_pixels -= dst_stride;
-        memcpy(dst_pixels, src_pixels, visible_pitch);
-        src_pixels += src_stride;
-    }
-}
+#include "orient.h"
 
 #define TRANSFORMS(bits) \
 static void hflip_##bits(void *restrict dst, ptrdiff_t dst_stride, \
@@ -72,24 +57,6 @@ static void hflip_##bits(void *restrict dst, ptrdiff_t dst_stride, \
     } \
 } \
 \
-static void vflip_##bits(void *restrict dst, ptrdiff_t dst_stride, \
-                         const void *restrict src, ptrdiff_t src_stride, \
-                         int width, int height) \
-{ \
-    vflip(dst, dst_stride, src, src_stride, width, height, ctz(bits / 8)); \
-} \
-\
-static void r180_##bits(void *restrict dst, ptrdiff_t dst_stride, \
-                        const void *restrict src, ptrdiff_t src_stride, \
-                        int width, int height) \
-{ \
-    const unsigned char *src_pixels = src; \
-\
-    src_pixels += (height - 1) * src_stride; \
-    src_stride *= -1; \
-    hflip_##bits(dst, dst_stride, src_pixels, src_stride, width, height); \
-} \
-\
 static void transpose_##bits(void *restrict dst, ptrdiff_t dst_stride, \
                              const void *restrict src, ptrdiff_t src_stride, \
                              int src_width, int src_height) \
@@ -106,75 +73,116 @@ static void transpose_##bits(void *restrict dst, ptrdiff_t dst_stride, \
         src_pixels += src_stride; \
         dst_pixels++; \
     } \
-} \
-\
-static void r270_##bits(void *restrict dst, ptrdiff_t dst_stride, \
-                        const void *restrict src, ptrdiff_t src_stride, \
-                        int src_width, int src_height) \
-{ \
-    unsigned char *dst_pixels = dst; \
-\
-    dst_pixels += (src_width - 1) * dst_stride; \
-    dst_stride *= -1; \
-    transpose_##bits(dst_pixels, dst_stride, src, src_stride, \
-                     src_width, src_height); \
-} \
-\
-static void r90_##bits(void *restrict dst, ptrdiff_t dst_stride, \
-                       const void *restrict src, ptrdiff_t src_stride, \
-                       int src_width, int src_height) \
-{ \
-    const unsigned char *src_pixels = src; \
-\
-    src_pixels += (src_height - 1) * src_stride; \
-    src_stride *= -1; \
-    transpose_##bits(dst, dst_stride, src_pixels, src_stride, \
-                     src_width, src_height); \
-} \
-\
-static void antitranspose_##bits(void *restrict dst, ptrdiff_t dst_stride, \
-                                 const void *restrict src, \
-                                 ptrdiff_t src_stride, \
-                                 int src_width, int src_height) \
-{ \
-    const unsigned char *src_pixels = src; \
-\
-    src_pixels += (src_height - 1) * src_stride; \
-    src_stride *= -1; \
-    r270_##bits(dst, dst_stride, src_pixels, src_stride, \
-                src_width, src_height);\
 }
 
 TRANSFORMS(8)
 TRANSFORMS(16)
 TRANSFORMS(32)
+TRANSFORMS(64)
+
+static const struct plane_transforms transforms = {
+    { hflip_8, hflip_16, hflip_32, hflip_64, },
+    { transpose_8, transpose_16, transpose_32, transpose_64, },
+};
+
+static void hflip(void *restrict dst, ptrdiff_t dst_stride,
+                  const void *restrict src, ptrdiff_t src_stride,
+                  int width, int height, int order)
+{
+    transforms.hflip[order](dst, dst_stride, src, src_stride, width, height);
+}
+
+static void vflip(void *restrict dst, ptrdiff_t dst_stride,
+                  const void *restrict src, ptrdiff_t src_stride,
+                  int width, int height, int order)
+{
+    const unsigned char *src_pixels = src;
+    unsigned char *restrict dst_pixels = dst;
+    size_t visible_pitch = width << order;
 
-typedef void (*plane_transform_cb)(void *, ptrdiff_t, const void *, ptrdiff_t,
-                                   int, int);
+    dst_pixels += dst_stride * height;
+
+    for (int y = 0; y < height; y++) {
+        dst_pixels -= dst_stride;
+        memcpy(dst_pixels, src_pixels, visible_pitch);
+        src_pixels += src_stride;
+    }
+}
+
+static void r180(void *restrict dst, ptrdiff_t dst_stride,
+                 const void *restrict src, ptrdiff_t src_stride,
+                 int width, int height, int order)
+{
+    const unsigned char *src_pixels = src;
+
+    src_pixels += (height - 1) * src_stride;
+    src_stride *= -1;
+    hflip(dst, dst_stride, src_pixels, src_stride, width, height, order);
+}
+
+static void transpose(void *restrict dst, ptrdiff_t dst_stride,
+                      const void *restrict src, ptrdiff_t src_stride,
+                      int src_width, int src_height, int order)
+{
+    transforms.transpose[order](dst, dst_stride, src, src_stride,
+                                src_width, src_height);
+}
+
+static void r270(void *restrict dst, ptrdiff_t dst_stride,
+                 const void *restrict src, ptrdiff_t src_stride,
+                 int src_width, int src_height, int order)
+{
+    unsigned char *dst_pixels = dst;
+
+    dst_pixels += (src_width - 1) * dst_stride;
+    dst_stride *= -1;
+    transpose(dst_pixels, dst_stride, src, src_stride, src_width, src_height,
+              order);
+}
+
+static void r90(void *restrict dst, ptrdiff_t dst_stride,
+                const void *restrict src, ptrdiff_t src_stride,
+                int src_width, int src_height, int order)
+{
+    const unsigned char *src_pixels = src;
+
+    src_pixels += (src_height - 1) * src_stride;
+    src_stride *= -1;
+    transpose(dst, dst_stride, src_pixels, src_stride, src_width, src_height,
+              order);
+}
+
+static void antitranspose(void *restrict dst, ptrdiff_t dst_stride,
+                          const void *restrict src,
+                          ptrdiff_t src_stride,
+                          int src_width, int src_height, int order)
+{
+    const unsigned char *src_pixels = src;
 
-typedef struct {
-    plane_transform_cb plane8;
-    plane_transform_cb plane16;
-    plane_transform_cb plane32;
-} transform_description_t;
+    src_pixels += (src_height - 1) * src_stride;
+    src_stride *= -1;
+    r270(dst, dst_stride, src_pixels, src_stride, src_width, src_height,
+         order);
+}
 
-#define DESC(g) \
-    { g##_8, g##_16, g##_32, }
+typedef void (*transform_description_t)(void *, ptrdiff_t, const void *,
+                                        ptrdiff_t, int, int, int);
 
 static const transform_description_t descriptions[] = {
-    [TRANSFORM_R90] =            DESC(r90),
-    [TRANSFORM_R180] =           DESC(r180),
-    [TRANSFORM_R270] =           DESC(r270),
-    [TRANSFORM_HFLIP] =          DESC(hflip),
-    [TRANSFORM_VFLIP] =          DESC(vflip),
-    [TRANSFORM_TRANSPOSE] =      DESC(transpose),
-    [TRANSFORM_ANTI_TRANSPOSE] = DESC(antitranspose),
+    [TRANSFORM_R90] =            r90,
+    [TRANSFORM_R180] =           r180,
+    [TRANSFORM_R270] =           r270,
+    [TRANSFORM_HFLIP] =          hflip,
+    [TRANSFORM_VFLIP] =          vflip,
+    [TRANSFORM_TRANSPOSE] =      transpose,
+    [TRANSFORM_ANTI_TRANSPOSE] = antitranspose,
 };
 
 typedef struct
 {
     video_transform_t transform;
-    plane_transform_cb plane[PICTURE_PLANE_MAX];
+    transform_description_t plane;
+    unsigned char plane_size_order[PICTURE_PLANE_MAX];
 } filter_sys_t;
 
 static picture_t *Filter(filter_t *filter, picture_t *src)
@@ -184,10 +192,10 @@ static picture_t *Filter(filter_t *filter, picture_t *src)
 
     if (likely(dst != NULL)) {
         for (int i = 0; i < src->i_planes; i++)
-            (sys->plane[i])(dst->p[i].p_pixels, dst->p[i].i_pitch,
-                            src->p[i].p_pixels, src->p[i].i_pitch,
-                            src->p[i].i_visible_pitch / src->p[i].i_pixel_pitch,
-                            src->p[i].i_visible_lines);
+            sys->plane(dst->p[i].p_pixels, dst->p[i].i_pitch,
+                       src->p[i].p_pixels, src->p[i].i_pitch,
+                       src->p[i].i_visible_pitch / src->p[i].i_pixel_pitch,
+                       src->p[i].i_visible_lines, sys->plane_size_order[i]);
 
         picture_CopyProperties(dst, src);
     }
@@ -281,42 +289,38 @@ static int Open(filter_t *filter)
     if (chroma == NULL)
         return VLC_ENOTSUP;
 
-    filter_sys_t *sys = vlc_obj_malloc(VLC_OBJECT(filter), sizeof(*sys));
-    if (unlikely(sys == NULL))
-        return VLC_ENOMEM;
-
-    const transform_description_t *const dsc = &descriptions[transform];
-
-    sys->transform = transform;
+    if (ORIENT_IS_SWAP(transform)) /* Cannot transform non-square samples */
+        for (unsigned i = 0; i < chroma->plane_count; i++)
+            if (chroma->p[i].w.num * chroma->p[i].h.den
+             != chroma->p[i].h.num * chroma->p[i].w.den)
+                return VLC_ENOTSUP;
 
     switch (chroma->pixel_size) {
         case 1:
-            sys->plane[0] = dsc->plane8;
-            break;
         case 2:
-            sys->plane[0] = dsc->plane16;
-            break;
         case 4:
-            sys->plane[0] = dsc->plane32;
+        case 8:
             break;
         default:
             return VLC_ENOTSUP;
     }
 
-    for (unsigned i = 1; i < PICTURE_PLANE_MAX; i++)
-        sys->plane[i] = sys->plane[0];
+    filter_sys_t *sys = vlc_obj_malloc(VLC_OBJECT(filter), sizeof(*sys));
+    if (unlikely(sys == NULL))
+        return VLC_ENOMEM;
 
-    if (ORIENT_IS_SWAP(transform)) /* Cannot transform non-square samples */
-        for (unsigned i = 0; i < chroma->plane_count; i++)
-            if (chroma->p[i].w.num * chroma->p[i].h.den
-             != chroma->p[i].h.num * chroma->p[i].w.den)
-                return VLC_ENOTSUP;
+    int order = vlc_ctz(chroma->pixel_size);
+
+    sys->transform = transform;
+    sys->plane = descriptions[transform];
+    memset(sys->plane_size_order, order, sizeof (sys->plane_size_order));
 
     /* Deal with weird packed formats */
     switch (src->i_chroma) {
         case VLC_CODEC_NV12:
         case VLC_CODEC_NV21:
-            sys->plane[1] = dsc->plane16;
+            /* Double-size samples on second plane */
+            sys->plane_size_order[1]++;
             break;
     }
 


=====================================
modules/video_chroma/orient.h
=====================================
@@ -0,0 +1,33 @@
+/*****************************************************************************
+ * orient.h: image reorientation video conversion
+ *****************************************************************************
+ * Copyright (C) 2010 Laurent Aimar
+ * Copyright (C) 2012 Rémi Denis-Courmont
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+
+#include <stdint.h>
+
+typedef void (*plane_transform_cb)(void *, ptrdiff_t, const void *, ptrdiff_t,
+                                   int, int);
+
+#define PLANE_TRANSFORM_MAX_ORDER 3
+
+struct plane_transforms {
+    plane_transform_cb hflip[PLANE_TRANSFORM_MAX_ORDER + 1];
+    plane_transform_cb transpose[PLANE_TRANSFORM_MAX_ORDER + 1];
+};
+



View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/74f98c98529afce3951e5cb3473131ded3df2dea...dc26eb5389b55e688ce1a647a76a8c995cd3ee84

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/74f98c98529afce3951e5cb3473131ded3df2dea...dc26eb5389b55e688ce1a647a76a8c995cd3ee84
You're receiving this email because of your account on code.videolan.org.


VideoLAN code repository instance


More information about the vlc-commits mailing list