[vlc-commits] [Git][videolan/vlc][master] 3 commits: substext: initialize boolean with a boolean expression

Steve Lhomme (@robUx4) gitlab at videolan.org
Wed Oct 25 07:26:08 UTC 2023



Steve Lhomme pushed to branch master at VideoLAN / VLC


Commits:
25817482 by Steve Lhomme at 2023-10-25T08:25:01+02:00
substext: initialize boolean with a boolean expression

- - - - -
f62962f2 by Steve Lhomme at 2023-10-25T08:25:01+02:00
vout_subpictures: make SpuRenderRegion return the region it creates

No need for double pointers here.

- - - - -
a88054ab by Steve Lhomme at 2023-10-25T08:25:02+02:00
freetype: simplify indentation

- - - - -


3 changed files:

- modules/codec/substext.h
- modules/text_renderer/freetype/freetype.c
- src/video_output/vout_subpictures.c


Changes:

=====================================
modules/codec/substext.h
=====================================
@@ -177,8 +177,8 @@ static void SubpictureTextUpdate(subpicture_t *subpic,
         r->p_text = text_segment_Copy( p_updtregion->p_segments );
         r->i_align = p_updtregion->align;
         r->i_text_align = p_updtregion->inner_align;
-        r->b_noregionbg = p_updtregion->flags & UPDT_REGION_IGNORE_BACKGROUND;
-        r->b_gridmode = p_updtregion->flags & UPDT_REGION_USES_GRID_COORDINATES;
+        r->b_noregionbg = (p_updtregion->flags & UPDT_REGION_IGNORE_BACKGROUND) != 0;
+        r->b_gridmode = (p_updtregion->flags & UPDT_REGION_USES_GRID_COORDINATES) != 0;
 
         if (!(p_updtregion->flags & UPDT_REGION_FIXED_DONE))
         {


=====================================
modules/text_renderer/freetype/freetype.c
=====================================
@@ -1036,151 +1036,151 @@ static int Render( filter_t *p_filter, subpicture_region_t *p_region_out,
 
     /* Don't attempt to render text that couldn't be laid out
      * properly. */
-    if( rv == VLC_SUCCESS && text_block.i_count > 0 && bbox.xMin < bbox.xMax && bbox.yMin < bbox.yMax )
+    if (!( rv == VLC_SUCCESS && text_block.i_count > 0 && bbox.xMin < bbox.xMax && bbox.yMin < bbox.yMax ))
     {
-        const vlc_fourcc_t p_chroma_list_yuvp[] = { VLC_CODEC_YUVP, 0 };
-        const vlc_fourcc_t p_chroma_list_rgba[] = { VLC_CODEC_RGBA, 0 };
-
-        int i_margin = (p_sys->p_default_style->i_background_alpha > 0 && !p_region_in->b_gridmode)
-                     ? i_max_face_height / 4 : 0;
-
-        if( (unsigned)i_margin * 2 >= i_max_width || (unsigned)i_margin * 2 >= i_max_height )
-            i_margin = 0;
-
-        if( p_sys->i_forced_chroma == VLC_CODEC_YUVP )
-            p_chroma_list = p_chroma_list_yuvp;
-        else if( !p_chroma_list || *p_chroma_list == 0 )
-            p_chroma_list = p_chroma_list_rgba;
-
-        FT_BBox paddedbbox = bbox;
-        paddedbbox.xMin -= i_margin;
-        paddedbbox.xMax += i_margin;
-        paddedbbox.yMin -= i_margin;
-        paddedbbox.yMax += i_margin;
-
-        FT_BBox regionbbox = paddedbbox;
-
-        /* _______regionbbox_______________
-         * |                               |
-         * |                               |
-         * |                               |
-         * |     _bbox(<paddedbbox)___     |
-         * |    |         rightaligned|    |
-         * |    |            textlines|    |
-         * |    |_____________________|    |
-         * |_______________________________|
-         *
-         * we need at least 3 bounding boxes.
-         * regionbbox containing the whole, including region background pixels
-         * paddedbox an enlarged text box when for drawing text background
-         * bbox the lines bounding box for all glyphs
-         * For simple unstyled subs, bbox == paddedbox == regionbbox
-         */
-
-        unsigned outertext_w = (regionbbox.xMax - regionbbox.xMin);
-        if( outertext_w < (unsigned) p_region_in->i_max_width )
+        rv = VLC_EGENERIC;
+        goto done;
+    }
+
+    const vlc_fourcc_t p_chroma_list_yuvp[] = { VLC_CODEC_YUVP, 0 };
+    const vlc_fourcc_t p_chroma_list_rgba[] = { VLC_CODEC_RGBA, 0 };
+
+    int i_margin = (p_sys->p_default_style->i_background_alpha > 0 && !p_region_in->b_gridmode)
+                    ? i_max_face_height / 4 : 0;
+
+    if( (unsigned)i_margin * 2 >= i_max_width || (unsigned)i_margin * 2 >= i_max_height )
+        i_margin = 0;
+
+    if( p_sys->i_forced_chroma == VLC_CODEC_YUVP )
+        p_chroma_list = p_chroma_list_yuvp;
+    else if( !p_chroma_list || *p_chroma_list == 0 )
+        p_chroma_list = p_chroma_list_rgba;
+
+    FT_BBox paddedbbox = bbox;
+    paddedbbox.xMin -= i_margin;
+    paddedbbox.xMax += i_margin;
+    paddedbbox.yMin -= i_margin;
+    paddedbbox.yMax += i_margin;
+
+    FT_BBox regionbbox = paddedbbox;
+
+    /* _______regionbbox_______________
+        * |                               |
+        * |                               |
+        * |                               |
+        * |     _bbox(<paddedbbox)___     |
+        * |    |         rightaligned|    |
+        * |    |            textlines|    |
+        * |    |_____________________|    |
+        * |_______________________________|
+        *
+        * we need at least 3 bounding boxes.
+        * regionbbox containing the whole, including region background pixels
+        * paddedbox an enlarged text box when for drawing text background
+        * bbox the lines bounding box for all glyphs
+        * For simple unstyled subs, bbox == paddedbox == regionbbox
+        */
+
+    unsigned outertext_w = (regionbbox.xMax - regionbbox.xMin);
+    if( outertext_w < (unsigned) p_region_in->i_max_width )
+    {
+        if( p_region_in->i_text_align & SUBPICTURE_ALIGN_RIGHT )
+            regionbbox.xMin -= (p_region_in->i_max_width - outertext_w);
+        else if( p_region_in->i_text_align & SUBPICTURE_ALIGN_LEFT )
+            regionbbox.xMax += (p_region_in->i_max_width - outertext_w);
+        else
         {
-            if( p_region_in->i_text_align & SUBPICTURE_ALIGN_RIGHT )
-                regionbbox.xMin -= (p_region_in->i_max_width - outertext_w);
-            else if( p_region_in->i_text_align & SUBPICTURE_ALIGN_LEFT )
-                regionbbox.xMax += (p_region_in->i_max_width - outertext_w);
-            else
-            {
-                regionbbox.xMin -= (p_region_in->i_max_width - outertext_w) / 2;
-                regionbbox.xMax += (p_region_in->i_max_width - outertext_w + 1) / 2;
-            }
+            regionbbox.xMin -= (p_region_in->i_max_width - outertext_w) / 2;
+            regionbbox.xMax += (p_region_in->i_max_width - outertext_w + 1) / 2;
         }
+    }
 
-        unsigned outertext_h = (regionbbox.yMax - regionbbox.yMin);
-        if( outertext_h < (unsigned) p_region_in->i_max_height )
+    unsigned outertext_h = (regionbbox.yMax - regionbbox.yMin);
+    if( outertext_h < (unsigned) p_region_in->i_max_height )
+    {
+        if( p_region_in->i_text_align & SUBPICTURE_ALIGN_TOP )
+            regionbbox.yMin -= (p_region_in->i_max_height - outertext_h);
+        else if( p_region_in->i_text_align & SUBPICTURE_ALIGN_BOTTOM )
+            regionbbox.yMax += (p_region_in->i_max_height - outertext_h);
+        else
         {
-            if( p_region_in->i_text_align & SUBPICTURE_ALIGN_TOP )
-                regionbbox.yMin -= (p_region_in->i_max_height - outertext_h);
-            else if( p_region_in->i_text_align & SUBPICTURE_ALIGN_BOTTOM )
-                regionbbox.yMax += (p_region_in->i_max_height - outertext_h);
-            else
-            {
-                regionbbox.yMin -= (p_region_in->i_max_height - outertext_h + 1) / 2;
-                regionbbox.yMax += (p_region_in->i_max_height - outertext_h) / 2;
-            }
+            regionbbox.yMin -= (p_region_in->i_max_height - outertext_h + 1) / 2;
+            regionbbox.yMax += (p_region_in->i_max_height - outertext_h) / 2;
         }
+    }
 
 //        unsigned bboxcolor = 0xFF000000;
-        /* TODO 4.0. No region self BG color for VLC 3.0 API*/
+    /* TODO 4.0. No region self BG color for VLC 3.0 API*/
 
-        /* Avoid useless pixels:
-         *        reshrink/trim Region Box to padded text one,
-         *        but update offsets to keep position and have same rendering */
+    /* Avoid useless pixels:
+        *        reshrink/trim Region Box to padded text one,
+        *        but update offsets to keep position and have same rendering */
 //        if( (bboxcolor & 0xFF) == 0 )
-        {
-            p_region_out->i_x = (paddedbbox.xMin - regionbbox.xMin) + p_region_in->i_x;
-            p_region_out->i_y = (regionbbox.yMax - paddedbbox.yMax) + p_region_in->i_y;
-            regionbbox = paddedbbox;
-        }
+    {
+        p_region_out->i_x = (paddedbbox.xMin - regionbbox.xMin) + p_region_in->i_x;
+        p_region_out->i_y = (regionbbox.yMax - paddedbbox.yMax) + p_region_in->i_y;
+        regionbbox = paddedbbox;
+    }
 //        else /* case where the bounding box is larger and visible */
 //        {
 //            p_region_out->i_x = p_region_in->i_x;
 //            p_region_out->i_y = p_region_in->i_y;
 //        }
 
-        enum
-        {
-            DRAW_YUVA = 0,
-            DRAW_RGBA,
-            DRAW_ARGB,
-        };
+    enum
+    {
+        DRAW_YUVA = 0,
+        DRAW_RGBA,
+        DRAW_ARGB,
+    };
 
-        const ft_drawing_functions drawfuncs[] =
-        {
-            [DRAW_YUVA] = { .extract = YUVFromXRGB,
-                            .fill =    FillYUVAPicture,
-                            .blend =   BlendGlyphToYUVA },
-            [DRAW_RGBA] = { .extract = RGBFromXRGB,
-                            .fill =    FillRGBAPicture,
-                            .blend =   BlendGlyphToRGBA },
-            [DRAW_ARGB] = { .extract = RGBFromXRGB,
-                            .fill =    FillARGBPicture,
-                            .blend =   BlendGlyphToARGB },
-        };
+    const ft_drawing_functions drawfuncs[] =
+    {
+        [DRAW_YUVA] = { .extract = YUVFromXRGB,
+                        .fill =    FillYUVAPicture,
+                        .blend =   BlendGlyphToYUVA },
+        [DRAW_RGBA] = { .extract = RGBFromXRGB,
+                        .fill =    FillRGBAPicture,
+                        .blend =   BlendGlyphToRGBA },
+        [DRAW_ARGB] = { .extract = RGBFromXRGB,
+                        .fill =    FillARGBPicture,
+                        .blend =   BlendGlyphToARGB },
+    };
 
-        rv = VLC_EGENERIC;
-        for( const vlc_fourcc_t *p_chroma = p_chroma_list; *p_chroma != 0; p_chroma++ )
-        {
-            if( *p_chroma == VLC_CODEC_YUVP )
-                rv = RenderYUVP( p_filter, p_region_out, text_block.p_laid,
-                                 &regionbbox, &paddedbbox, &bbox );
-            else if( *p_chroma == VLC_CODEC_YUVA )
-                rv = RenderAXYZ( p_filter, p_region_out, text_block.p_laid,
-                                 &regionbbox, &paddedbbox, &bbox,
-                                 VLC_CODEC_YUVA,
-                                 &p_region_out->fmt,
-                                 drawfuncs[DRAW_YUVA] );
-            else if( *p_chroma == VLC_CODEC_RGBA
-                  || *p_chroma == VLC_CODEC_BGRA )
-                rv = RenderAXYZ( p_filter, p_region_out, text_block.p_laid,
-                                 &regionbbox, &paddedbbox, &bbox,
-                                 *p_chroma,
-                                 &p_region_out->fmt,
-                                 drawfuncs[DRAW_RGBA] );
-            else if( *p_chroma == VLC_CODEC_ARGB
-                  || *p_chroma == VLC_CODEC_ABGR)
-                rv = RenderAXYZ( p_filter, p_region_out, text_block.p_laid,
-                                 &regionbbox, &paddedbbox, &bbox,
-                                 *p_chroma,
-                                 &p_region_out->fmt,
-                                 drawfuncs[DRAW_ARGB] );
-            else
-                continue;
-
-            if( rv == VLC_SUCCESS )
-                break;
-        }
-    }
-    else
+    rv = VLC_EGENERIC;
+    for( const vlc_fourcc_t *p_chroma = p_chroma_list; *p_chroma != 0; p_chroma++ )
     {
-        rv = VLC_EGENERIC;
+        if( *p_chroma == VLC_CODEC_YUVP )
+            rv = RenderYUVP( p_filter, p_region_out, text_block.p_laid,
+                                &regionbbox, &paddedbbox, &bbox );
+        else if( *p_chroma == VLC_CODEC_YUVA )
+            rv = RenderAXYZ( p_filter, p_region_out, text_block.p_laid,
+                                &regionbbox, &paddedbbox, &bbox,
+                                VLC_CODEC_YUVA,
+                                &p_region_out->fmt,
+                                drawfuncs[DRAW_YUVA] );
+        else if( *p_chroma == VLC_CODEC_RGBA
+                || *p_chroma == VLC_CODEC_BGRA )
+            rv = RenderAXYZ( p_filter, p_region_out, text_block.p_laid,
+                                &regionbbox, &paddedbbox, &bbox,
+                                *p_chroma,
+                                &p_region_out->fmt,
+                                drawfuncs[DRAW_RGBA] );
+        else if( *p_chroma == VLC_CODEC_ARGB
+                || *p_chroma == VLC_CODEC_ABGR)
+            rv = RenderAXYZ( p_filter, p_region_out, text_block.p_laid,
+                                &regionbbox, &paddedbbox, &bbox,
+                                *p_chroma,
+                                &p_region_out->fmt,
+                                drawfuncs[DRAW_ARGB] );
+        else
+            continue;
+
+        if( rv == VLC_SUCCESS )
+            break;
     }
 
+done:
     FreeLines( text_block.p_laid );
 
     free( text_block.p_uchars );


=====================================
src/video_output/vout_subpictures.c
=====================================
@@ -784,8 +784,8 @@ spu_SelectSubpictures(spu_t *spu, vlc_tick_t system_now,
 /**
  * It will transform the provided region into another region suitable for rendering.
  */
-static void SpuRenderRegion(spu_t *spu,
-                            subpicture_region_t **dst_ptr, spu_area_t *dst_area,
+static subpicture_region_t *SpuRenderRegion(spu_t *spu,
+                            spu_area_t *dst_area,
                             const spu_render_entry_t *entry, subpicture_region_t *region,
                             const spu_scale_t scale_size,
                             const vlc_fourcc_t *chroma_list,
@@ -805,7 +805,6 @@ static void SpuRenderRegion(spu_t *spu,
 
     /* Invalidate area by default */
     *dst_area = spu_area_create(0,0, 0,0, scale_size);
-    *dst_ptr  = NULL;
 
     /* Render text region */
     if (region->fmt.i_chroma == VLC_CODEC_TEXT)
@@ -813,7 +812,7 @@ static void SpuRenderRegion(spu_t *spu,
         if(SpuRenderText(spu, region,
                       i_original_width, i_original_height,
                       chroma_list) != VLC_SUCCESS)
-            return;
+            return NULL;
         assert(region->fmt.i_chroma != VLC_CODEC_TEXT);
     }
 
@@ -1115,21 +1114,23 @@ static void SpuRenderRegion(spu_t *spu,
     }
 
     assert(video_format_IsSameChroma( &region_fmt, &region_picture->format ));
-    subpicture_region_t *dst = *dst_ptr = subpicture_region_ForPicture(&region_fmt, region_picture);
-    if (dst) {
-        dst->i_x       = x_offset;
-        dst->i_y       = y_offset;
-        dst->i_align   = 0;
-        int fade_alpha = 255;
-        if (subpic->b_fade) {
-            vlc_tick_t fade_start = subpic->i_start + 3 * (subpic->i_stop - subpic->i_start) / 4;
-
-            if (fade_start <= render_date && fade_start < subpic->i_stop)
-                fade_alpha = 255 * (subpic->i_stop - render_date) /
-                                   (subpic->i_stop - fade_start);
-        }
-        dst->i_alpha   = fade_alpha * subpic->i_alpha * region->i_alpha / 65025;
+    subpicture_region_t *dst = subpicture_region_ForPicture(&region_fmt, region_picture);
+    if (dst == NULL)
+        return NULL;
+
+    dst->i_x       = x_offset;
+    dst->i_y       = y_offset;
+    dst->i_align   = 0;
+    int fade_alpha = 255;
+    if (subpic->b_fade) {
+        vlc_tick_t fade_start = subpic->i_start + 3 * (subpic->i_stop - subpic->i_start) / 4;
+
+        if (fade_start <= render_date && fade_start < subpic->i_stop)
+            fade_alpha = 255 * (subpic->i_stop - render_date) /
+                                (subpic->i_stop - fade_start);
     }
+    dst->i_alpha   = fade_alpha * subpic->i_alpha * region->i_alpha / 65025;
+    return dst;
 }
 
 /**
@@ -1253,7 +1254,7 @@ static subpicture_t *SpuRenderSubpictures(spu_t *spu,
             spu_scale_t virtual_scale = external_scale ? (spu_scale_t){ SCALE_UNIT, SCALE_UNIT } : scale;
 
             /* */
-            SpuRenderRegion(spu, output_last_ptr, &area,
+            *output_last_ptr = SpuRenderRegion(spu, &area,
                             entry, region, virtual_scale,
                             chroma_list, fmt_dst,
                             i_original_width, i_original_height,



View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/ddfeaeaa350b585d0d69570cf398781d2bea3c53...a88054ab29e3ed6af212f9d35f678e731032b2c2

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/ddfeaeaa350b585d0d69570cf398781d2bea3c53...a88054ab29e3ed6af212f9d35f678e731032b2c2
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