Changed subpicture_region_t->picture into a picture_t *
authorLaurent Aimar <fenrir@videolan.org>
Fri, 19 Sep 2008 22:09:37 +0000 (00:09 +0200)
committerLaurent Aimar <fenrir@videolan.org>
Sat, 20 Sep 2008 14:38:01 +0000 (16:38 +0200)
It will avoid useless picture copy.

24 files changed:
include/vlc_vout.h
modules/codec/csri.c
modules/codec/cvdsub.c
modules/codec/dvbsub.c
modules/codec/kate.c
modules/codec/libass.c
modules/codec/spudec/parse.c
modules/codec/subtitles/subsusf.c
modules/codec/svcdsub.c
modules/codec/zvbi.c
modules/gui/fbosd.c
modules/misc/freetype.c
modules/misc/quartztext.c
modules/misc/svg.c
modules/misc/win32text.c
modules/video_filter/dynamicoverlay/dynamicoverlay.c
modules/video_filter/logo.c
modules/video_filter/mosaic.c
modules/video_filter/osdmenu.c
modules/video_filter/remoteosd.c
modules/video_filter/rss.c
src/osd/osd_widgets.c
src/video_output/vout_intf.c
src/video_output/vout_subpictures.c

index 377448d..b3b2afd 100644 (file)
@@ -289,6 +289,11 @@ struct picture_heap_t
  * @{
  */
 
+/**
+ * Video subtitle region spu core private
+ */
+typedef struct subpicture_region_private_t subpicture_region_private_t;
+
 /**
  * Video subtitle region
  *
@@ -299,7 +304,7 @@ struct picture_heap_t
 struct subpicture_region_t
 {
     video_format_t  fmt;                          /**< format of the picture */
-    picture_t       picture;             /**< picture comprising this region */
+    picture_t       *p_picture;          /**< picture comprising this region */
 
     int             i_x;                             /**< position of region */
     int             i_y;                             /**< position of region */
@@ -311,7 +316,7 @@ struct subpicture_region_t
     text_style_t    *p_style;        /**< a description of the text style formatting */
 
     subpicture_region_t *p_next;                /**< next region in the list */
-    subpicture_region_t *p_cache;       /**< modified version of this region */
+    subpicture_region_private_t *p_private;  /**< modified version of this region */
 };
 
 /**
index 6bc21f0..919e086 100644 (file)
@@ -305,14 +305,14 @@ static void UpdateRegions( spu_t *p_spu, subpicture_t *p_subpic,
 
         /* */
         p_spu_region->i_align = SUBPICTURE_ALIGN_TOP | SUBPICTURE_ALIGN_LEFT;
-        memset( p_spu_region->picture.Y_PIXELS, 0x00, p_spu_region->picture.Y_PITCH * p_sys->fmt_cached.i_height );
+        memset( p_spu_region->p_picture->Y_PIXELS, 0x00, p_spu_region->p_picture->Y_PITCH * p_sys->fmt_cached.i_height );
 
         /* */
         //msg_Dbg( p_dec, "TS %lf", ts * 0.000001 );
         memset( &csri_frame, 0, sizeof(csri_frame) );
         csri_frame.pixfmt = CSRI_F_BGRA;
-        csri_frame.planes[0] = (unsigned char*)p_spu_region->picture.Y_PIXELS;
-        csri_frame.strides[0] = p_spu_region->picture.Y_PITCH;
+        csri_frame.planes[0] = (unsigned char*)p_spu_region->p_picture->Y_PIXELS;
+        csri_frame.strides[0] = p_spu_region->p_picture->Y_PITCH;
         csri_render( p_sys->p_instance, &csri_frame, ts * 0.000001 );
     }
 }
index 90cdc33..eb934b5 100644 (file)
@@ -569,7 +569,7 @@ static void RenderImage( decoder_t *p_dec, block_t *p_data,
                          subpicture_region_t *p_region )
 {
     decoder_sys_t *p_sys = p_dec->p_sys;
-    uint8_t *p_dest = p_region->picture.Y_PIXELS;
+    uint8_t *p_dest = p_region->p_picture->Y_PIXELS;
     int i_field;            /* The subtitles are interlaced */
     int i_row, i_column;    /* scanline row/column number */
     uint8_t i_color, i_count;
@@ -591,7 +591,7 @@ static void RenderImage( decoder_t *p_dec, block_t *p_data,
                     /* Fill the rest of the line with next color */
                     i_color = bs_read( &bs, 4 );
 
-                    memset( &p_dest[i_row * p_region->picture.Y_PITCH +
+                    memset( &p_dest[i_row * p_region->p_picture->Y_PITCH +
                                     i_column], i_color,
                             p_sys->i_width - i_column );
                     i_column = p_sys->i_width;
@@ -605,7 +605,7 @@ static void RenderImage( decoder_t *p_dec, block_t *p_data,
 
                     i_count = __MIN( i_count, p_sys->i_width - i_column );
 
-                    memset( &p_dest[i_row * p_region->picture.Y_PITCH +
+                    memset( &p_dest[i_row * p_region->p_picture->Y_PITCH +
                                     i_column], i_color, i_count );
                     i_column += i_count - 1;
                     continue;
index 30db44e..baf589c 100644 (file)
@@ -1571,8 +1571,8 @@ static subpicture_t *render( decoder_t *p_dec )
         }
 
         p_src = p_region->p_pixbuf;
-        p_dst = p_spu_region->picture.Y_PIXELS;
-        i_pitch = p_spu_region->picture.Y_PITCH;
+        p_dst = p_spu_region->p_picture->Y_PIXELS;
+        i_pitch = p_spu_region->p_picture->Y_PITCH;
 
         /* Copy pixel buffer */
         for( j = 0; j < p_region->i_height; j++ )
@@ -1710,11 +1710,11 @@ static subpicture_t *YuvaYuvp( subpicture_t *p_subpic )
 #else
         int *pi_delta;
 #endif
-        int i_pixels = p_region->picture.p[0].i_visible_lines
-                        * p_region->picture.p[0].i_pitch;
-        int i_iterator = p_region->picture.p[0].i_visible_lines * 3 / 4
-                            * p_region->picture.p[0].i_pitch
-                        + p_region->picture.p[0].i_pitch * 1 / 3;
+        int i_pixels = p_region->p_picture->p[0].i_visible_lines
+                        * p_region->p_picture->p[0].i_pitch;
+        int i_iterator = p_region->p_picture->p[0].i_visible_lines * 3 / 4
+                            * p_region->p_picture->p[0].i_pitch
+                        + p_region->p_picture->p[0].i_pitch * 1 / 3;
         int i_tolerance = 0;
 
 #ifdef DEBUG_DVBSUB
@@ -1754,10 +1754,10 @@ static subpicture_t *YuvaYuvp( subpicture_t *p_subpic )
             for( i = 0; i < i_pixels ; )
             {
                 uint8_t y, u, v, a;
-                y = p_region->picture.p[0].p_pixels[i];
-                u = p_region->picture.p[1].p_pixels[i];
-                v = p_region->picture.p[2].p_pixels[i];
-                a = p_region->picture.p[3].p_pixels[i];
+                y = p_region->p_picture->p[0].p_pixels[i];
+                u = p_region->p_picture->p[1].p_pixels[i];
+                v = p_region->p_picture->p[2].p_pixels[i];
+                a = p_region->p_picture->p[3].p_pixels[i];
                 for( j = 0; j < p_fmt->p_palette->i_entries; j++ )
                 {
                     if( abs((int)p_fmt->p_palette->palette[j][0] - (int)y) <= i_tolerance &&
@@ -1799,29 +1799,29 @@ static subpicture_t *YuvaYuvp( subpicture_t *p_subpic )
 #endif
 
 #ifndef RANDOM_DITHERING
-        pi_delta = malloc( ( p_region->picture.p[0].i_pitch + 1 )
+        pi_delta = malloc( ( p_region->p_picture->p[0].i_pitch + 1 )
                             * sizeof(int) * 4  );
-        for( i = 0; i < (p_region->picture.p[0].i_pitch + 1) * 4 ; i++ )
+        for( i = 0; i < (p_region->p_picture->p[0].i_pitch + 1) * 4 ; i++ )
         {
             pi_delta[ i ] = 0;
         }
 #endif
 
         /* Fill image with our new colours */
-        for( p = 0; p < p_region->picture.p[0].i_visible_lines ; p++ )
+        for( p = 0; p < p_region->p_picture->p[0].i_visible_lines ; p++ )
         {
             int i_ydelta = 0, i_udelta = 0, i_vdelta = 0, i_adelta = 0;
 
-            for( n = 0; n < p_region->picture.p[0].i_pitch ; n++ )
+            for( n = 0; n < p_region->p_picture->p[0].i_pitch ; n++ )
             {
-                int i_offset = p * p_region->picture.p[0].i_pitch + n;
+                int i_offset = p * p_region->p_picture->p[0].i_pitch + n;
                 int y, u, v, a;
                 int i_mindist, i_best;
 
-                y = (int)p_region->picture.p[0].p_pixels[i_offset];
-                u = (int)p_region->picture.p[1].p_pixels[i_offset];
-                v = (int)p_region->picture.p[2].p_pixels[i_offset];
-                a = (int)p_region->picture.p[3].p_pixels[i_offset];
+                y = (int)p_region->p_picture->p[0].p_pixels[i_offset];
+                u = (int)p_region->p_picture->p[1].p_pixels[i_offset];
+                v = (int)p_region->p_picture->p[2].p_pixels[i_offset];
+                a = (int)p_region->p_picture->p[3].p_pixels[i_offset];
 
                 /* Add dithering compensation */
 #ifdef RANDOM_DITHERING
@@ -1854,7 +1854,7 @@ static subpicture_t *YuvaYuvp( subpicture_t *p_subpic )
                 }
 
                 /* Set pixel to best color */
-                p_region->picture.p[0].p_pixels[i_offset] = i_best;
+                p_region->p_picture->p[0].p_pixels[i_offset] = i_best;
 
                 /* Update dithering state */
 #ifdef RANDOM_DITHERING
@@ -2364,8 +2364,8 @@ static void encode_pixel_line_2bp( bs_t *s, subpicture_region_t *p_region,
                                    int i_line )
 {
     unsigned int i, i_length = 0;
-    int i_pitch = p_region->picture.p->i_pitch;
-    uint8_t *p_data = &p_region->picture.p->p_pixels[ i_pitch * i_line ];
+    int i_pitch = p_region->p_picture->p->i_pitch;
+    uint8_t *p_data = &p_region->p_picture->p->p_pixels[ i_pitch * i_line ];
     int i_last_pixel = p_data[0];
 
     for( i = 0; i <= p_region->fmt.i_visible_width; i++ )
@@ -2455,8 +2455,8 @@ static void encode_pixel_line_4bp( bs_t *s, subpicture_region_t *p_region,
                                    int i_line )
 {
     unsigned int i, i_length = 0;
-    int i_pitch = p_region->picture.p->i_pitch;
-    uint8_t *p_data = &p_region->picture.p->p_pixels[ i_pitch * i_line ];
+    int i_pitch = p_region->p_picture->p->i_pitch;
+    uint8_t *p_data = &p_region->p_picture->p->p_pixels[ i_pitch * i_line ];
     int i_last_pixel = p_data[0];
 
     for( i = 0; i <= p_region->fmt.i_visible_width; i++ )
@@ -2553,8 +2553,8 @@ static void encode_pixel_line_8bp( bs_t *s, subpicture_region_t *p_region,
                                    int i_line )
 {
     unsigned int i, i_length = 0;
-    int i_pitch = p_region->picture.p->i_pitch;
-    uint8_t *p_data = &p_region->picture.p->p_pixels[ i_pitch * i_line ];
+    int i_pitch = p_region->p_picture->p->i_pitch;
+    uint8_t *p_data = &p_region->p_picture->p->p_pixels[ i_pitch * i_line ];
     int i_last_pixel = p_data[0];
 
     for( i = 0; i <= p_region->fmt.i_visible_width; i++ )
index b014bc4..b8646ae 100644 (file)
@@ -640,7 +640,7 @@ static subpicture_t *DecodePacket( decoder_t *p_dec, kate_packet *p_kp, block_t
         CreateKatePalette( fmt.p_palette, ev->palette );
 
         /* create the bitmap */
-        CreateKateBitmap( &p_bitmap_region->picture, ev->bitmap );
+        CreateKateBitmap( p_bitmap_region->p_picture, ev->bitmap );
 
         msg_Dbg(p_dec, "Created bitmap, %zux%zu, %zu colors\n", ev->bitmap->width, ev->bitmap->height, ev->palette->ncolors);
     }
index 74b5e10..582cb72 100644 (file)
@@ -569,7 +569,7 @@ static int BuildRegions( spu_t *p_spu, rectangle_t *p_region, int i_max_region,
 
 static void RegionDraw( subpicture_region_t *p_region, ass_image_t *p_img )
 {
-    const plane_t *p = &p_region->picture.p[0];
+    const plane_t *p = &p_region->p_picture->p[0];
     const int i_x = p_region->i_x;
     const int i_y = p_region->i_y;
     const int i_width  = p_region->fmt.i_width;
index 3e0efff..4e118e0 100644 (file)
@@ -676,8 +676,8 @@ static void Render( decoder_t *p_dec, subpicture_t *p_spu,
 
     p_spu->p_region->i_x = p_spu_properties->i_x;
     p_spu->p_region->i_y = p_spu_properties->i_y + p_spu_data->i_y_top_offset;
-    p_p = p_spu->p_region->picture.p->p_pixels;
-    i_pitch = p_spu->p_region->picture.p->i_pitch;
+    p_p = p_spu->p_region->p_picture->p->p_pixels;
+    i_pitch = p_spu->p_region->p_picture->p->i_pitch;
 
     /* Build palette */
     fmt.p_palette->i_entries = 4;
index c603532..b03be78 100644 (file)
@@ -1208,7 +1208,8 @@ static subpicture_region_t *LoadEmbeddedImage( decoder_t *p_dec,
         return NULL;
     }
     assert( p_pic->format.i_chroma == VLC_FOURCC('Y','U','V','A') );
-    picture_CopyPixels( &p_region->picture, p_pic );
+    /* FIXME the copy is probably not needed anymore */
+    picture_CopyPixels( p_region->p_picture, p_pic );
 
     /* This isn't the best way to do this - if you really want transparency, then
      * you're much better off using an image type that supports it like PNG. The
@@ -1231,11 +1232,11 @@ static subpicture_region_t *LoadEmbeddedImage( decoder_t *p_dec,
         {
             for( unsigned int x = 0; x < p_region->fmt.i_width; x++ )
             {
-                if( p_region->picture.Y_PIXELS[y*p_region->picture.Y_PITCH + x] != i_y ||
-                    p_region->picture.U_PIXELS[y*p_region->picture.U_PITCH + x] != i_u ||
-                    p_region->picture.V_PIXELS[y*p_region->picture.V_PITCH + x] != i_v )
+                if( p_region->p_picture->Y_PIXELS[y*p_region->p_picture->Y_PITCH + x] != i_y ||
+                    p_region->p_picture->U_PIXELS[y*p_region->p_picture->U_PITCH + x] != i_u ||
+                    p_region->p_picture->V_PIXELS[y*p_region->p_picture->V_PITCH + x] != i_v )
                     continue;
-                p_region->picture.A_PIXELS[y*p_region->picture.A_PITCH + x] = 0;
+                p_region->p_picture->A_PIXELS[y*p_region->p_picture->A_PITCH + x] = 0;
 
             }
         }
index 2c54c17..5a1ecbf 100644 (file)
@@ -544,7 +544,7 @@ static void SVCDSubRenderImage( decoder_t *p_dec, block_t *p_data,
                 subpicture_region_t *p_region )
 {
     decoder_sys_t *p_sys = p_dec->p_sys;
-    uint8_t *p_dest = p_region->picture.Y_PIXELS;
+    uint8_t *p_dest = p_region->p_picture->Y_PIXELS;
     int i_field;            /* The subtitles are interlaced */
     int i_row, i_column;    /* scanline row/column number */
     uint8_t i_color, i_count;
@@ -563,13 +563,13 @@ static void SVCDSubRenderImage( decoder_t *p_dec, block_t *p_data,
                 if( i_color == 0 && (i_count = bs_read( &bs, 2 )) )
                 {
                     i_count = __MIN( i_count, p_sys->i_width - i_column );
-                    memset( &p_dest[i_row * p_region->picture.Y_PITCH +
+                    memset( &p_dest[i_row * p_region->p_picture->Y_PITCH +
                                     i_column], 0, i_count + 1 );
                     i_column += i_count;
                     continue;
                 }
 
-                p_dest[i_row * p_region->picture.Y_PITCH + i_column] = i_color;
+                p_dest[i_row * p_region->p_picture->Y_PITCH + i_column] = i_color;
             }
 
             bs_align( &bs );
index 88fe5bd..5e26f45 100644 (file)
@@ -418,12 +418,12 @@ static subpicture_t *Decode( decoder_t *p_dec, block_t **pp_block )
     }
     else
     {
-        picture_t *p_pic = &p_spu->p_region->picture;
+        picture_t *p_pic = p_spu->p_region->p_picture;
 
         /* ZVBI is stupid enough to assume pitch == width */
         p_pic->p->i_pitch = 4 * fmt.i_width;
         vbi_draw_vt_page( &p_page, ZVBI_PIXFMT_RGBA32,
-                          p_spu->p_region->picture.p->p_pixels, 1, 1 );
+                          p_spu->p_region->p_picture->p->p_pixels, 1, 1 );
 
         vlc_mutex_lock( &p_sys->lock );
         memcpy( p_sys->nav_link, &p_page.nav_link, sizeof( p_sys->nav_link )) ;
index 4c1f657..710452c 100644 (file)
@@ -883,23 +883,22 @@ static picture_t *RenderText( intf_thread_t *p_intf, const char *psz_string,
             fmt_out.i_bits_per_pixel = 32;
             vlc_memcpy( p_fmt, &fmt_out, sizeof(video_format_t) );
 
+            /* FIXME not needed to copy the picture anymore no ? */
             p_dest = AllocatePicture( VLC_OBJECT(p_intf), &fmt_out );
             if( !p_dest )
             {
-                if( p_region->picture.pf_release )
-                    p_region->picture.pf_release( &p_region->picture );
+                picture_Release( p_region->p_picture );
                 free( p_region->psz_text );
                 free( p_region );
                 return NULL;
             }
-            vout_CopyPicture( VLC_OBJECT(p_intf), p_dest, &p_region->picture );
+            vout_CopyPicture( VLC_OBJECT(p_intf), p_dest, p_region->p_picture );
 #else
             fmt_out.i_chroma = p_fmt->i_chroma;
-            p_dest = ConvertImage( p_intf, &p_region->picture,
+            p_dest = ConvertImage( p_intf, &p_region->p_picture,
                                    &p_region->fmt, &fmt_out );
 #endif
-            if( p_region->picture.pf_release )
-                p_region->picture.pf_release( &p_region->picture );
+            picture_Release( p_region->p_picture );
             free( p_region->psz_text );
             free( p_region );
             return p_dest;
index c586430..ff72294 100644 (file)
@@ -662,7 +662,6 @@ static int Render( filter_t *p_filter, subpicture_region_t *p_region,
     int i, x, y, i_pitch;
     uint8_t i_y; /* YUV values, derived from incoming RGB */
     int8_t i_u, i_v;
-    subpicture_region_t *p_region_tmp;
 
     /* Create a new subpicture region */
     memset( &fmt, 0, sizeof(video_format_t) );
@@ -675,16 +674,12 @@ static int Render( filter_t *p_filter, subpicture_region_t *p_region,
     if( p_region->fmt.i_visible_height > 0 )
         fmt.i_visible_height = p_region->fmt.i_visible_height;
     fmt.i_x_offset = fmt.i_y_offset = 0;
-    p_region_tmp = spu_CreateRegion( p_filter, &fmt );
-    if( !p_region_tmp )
-    {
-        msg_Err( p_filter, "cannot allocate SPU region" );
-        return VLC_EGENERIC;
-    }
 
-    p_region->fmt = p_region_tmp->fmt;
-    p_region->picture = p_region_tmp->picture;
-    free( p_region_tmp );
+    assert( !p_region->p_picture );
+    p_region->p_picture = picture_New( fmt.i_chroma, fmt.i_width, fmt.i_height, fmt.i_aspect );
+    if( !p_region->p_picture )
+        return VLC_EGENERIC;
+    p_region->fmt = fmt;
 
     /* Calculate text color components */
     i_y = (uint8_t)(( 66 * p_line->i_red  + 129 * p_line->i_green +
@@ -715,8 +710,8 @@ static int Render( filter_t *p_filter, subpicture_region_t *p_region,
             (int)fmt.p_palette->palette[i][3] * (255 - p_line->i_alpha) / 255;
     }
 
-    p_dst = p_region->picture.Y_PIXELS;
-    i_pitch = p_region->picture.Y_PITCH;
+    p_dst = p_region->p_picture->Y_PIXELS;
+    i_pitch = p_region->p_picture->Y_PITCH;
 
     /* Initialize the region pixels */
     memset( p_dst, 0, i_pitch * p_region->fmt.i_height );
@@ -768,21 +763,21 @@ static int Render( filter_t *p_filter, subpicture_region_t *p_region,
     /* Outlining (find something better than nearest neighbour filtering ?) */
     if( 1 )
     {
-        uint8_t *p_dst = p_region->picture.Y_PIXELS;
+        uint8_t *p_dst = p_region->p_picture->Y_PIXELS;
         uint8_t *p_top = p_dst; /* Use 1st line as a cache */
         uint8_t left, current;
 
         for( y = 1; y < (int)fmt.i_height - 1; y++ )
         {
             if( y > 1 ) memcpy( p_top, p_dst, fmt.i_width );
-            p_dst += p_region->picture.Y_PITCH;
+            p_dst += p_region->p_picture->Y_PITCH;
             left = 0;
 
             for( x = 1; x < (int)fmt.i_width - 1; x++ )
             {
                 current = p_dst[x];
                 p_dst[x] = ( 8 * (int)p_dst[x] + left + p_dst[x+1] + p_top[x -1]+ p_top[x] + p_top[x+1] +
-                             p_dst[x -1 + p_region->picture.Y_PITCH ] + p_dst[x + p_region->picture.Y_PITCH] + p_dst[x + 1 + p_region->picture.Y_PITCH]) / 16;
+                             p_dst[x -1 + p_region->p_picture->Y_PITCH ] + p_dst[x + p_region->p_picture->Y_PITCH] + p_dst[x + 1 + p_region->p_picture->Y_PITCH]) / 16;
                 left = current;
             }
         }
@@ -803,11 +798,11 @@ static void UnderlineGlyphYUVA( int i_line_thickness, int i_line_offset, bool b_
     int i_pitch;
     uint8_t *p_dst_y,*p_dst_u,*p_dst_v,*p_dst_a;
 
-    p_dst_y = p_region->picture.Y_PIXELS;
-    p_dst_u = p_region->picture.U_PIXELS;
-    p_dst_v = p_region->picture.V_PIXELS;
-    p_dst_a = p_region->picture.A_PIXELS;
-    i_pitch = p_region->picture.A_PITCH;
+    p_dst_y = p_region->p_picture->Y_PIXELS;
+    p_dst_u = p_region->p_picture->U_PIXELS;
+    p_dst_v = p_region->p_picture->V_PIXELS;
+    p_dst_a = p_region->p_picture->A_PIXELS;
+    i_pitch = p_region->p_picture->A_PITCH;
 
     int i_offset = ( p_this_glyph_pos->y + i_glyph_tmax + i_line_offset + 3 ) * i_pitch +
                      p_this_glyph_pos->x + p_this_glyph->left + 3 + i_align_offset;
@@ -866,8 +861,8 @@ static void UnderlineGlyphYUVA( int i_line_thickness, int i_line_offset, bool b_
 
 static void DrawBlack( line_desc_t *p_line, int i_width, subpicture_region_t *p_region, int xoffset, int yoffset )
 {
-    uint8_t *p_dst = p_region->picture.A_PIXELS;
-    int i_pitch = p_region->picture.A_PITCH;
+    uint8_t *p_dst = p_region->p_picture->A_PIXELS;
+    int i_pitch = p_region->p_picture->A_PITCH;
     int x,y;
 
     for( ; p_line != NULL; p_line = p_line->p_next )
@@ -930,7 +925,6 @@ static int RenderYUVA( filter_t *p_filter, subpicture_region_t *p_region,
     video_format_t fmt;
     int i, x, y, i_pitch, i_alpha;
     uint8_t i_y, i_u, i_v; /* YUV values, derived from incoming RGB */
-    subpicture_region_t *p_region_tmp;
 
     if( i_width == 0 || i_height == 0 )
         return VLC_SUCCESS;
@@ -946,16 +940,11 @@ static int RenderYUVA( filter_t *p_filter, subpicture_region_t *p_region,
     if( p_region->fmt.i_visible_height > 0 )
         fmt.i_visible_height = p_region->fmt.i_visible_height;
     fmt.i_x_offset = fmt.i_y_offset = 0;
-    p_region_tmp = spu_CreateRegion( p_filter, &fmt );
-    if( !p_region_tmp )
-    {
-        msg_Err( p_filter, "cannot allocate SPU region" );
-        return VLC_EGENERIC;
-    }
 
-    p_region->fmt = p_region_tmp->fmt;
-    p_region->picture = p_region_tmp->picture;
-    free( p_region_tmp );
+    p_region->p_picture = picture_New( fmt.i_chroma, fmt.i_width, fmt.i_height, fmt.i_aspect );
+    if( !p_region->p_picture )
+        return VLC_EGENERIC;
+    p_region->fmt = fmt;
 
     /* Calculate text color components */
     YUVFromRGB( (p_line->i_red   << 16) |
@@ -964,11 +953,11 @@ static int RenderYUVA( filter_t *p_filter, subpicture_region_t *p_region,
                 &i_y, &i_u, &i_v);
     i_alpha = p_line->i_alpha;
 
-    p_dst_y = p_region->picture.Y_PIXELS;
-    p_dst_u = p_region->picture.U_PIXELS;
-    p_dst_v = p_region->picture.V_PIXELS;
-    p_dst_a = p_region->picture.A_PIXELS;
-    i_pitch = p_region->picture.A_PITCH;
+    p_dst_y = p_region->p_picture->Y_PIXELS;
+    p_dst_u = p_region->p_picture->U_PIXELS;
+    p_dst_v = p_region->p_picture->V_PIXELS;
+    p_dst_a = p_region->p_picture->A_PIXELS;
+    i_pitch = p_region->p_picture->A_PITCH;
 
     /* Initialize the region pixels */
     if( p_filter->p_sys->i_effect != EFFECT_BACKGROUND )
index f0d6a41..fb345a5 100644 (file)
@@ -1321,7 +1321,6 @@ static int RenderYUVA( filter_t *p_filter, subpicture_region_t *p_region, UniCha
     video_format_t fmt;
     int x, y, i_offset, i_pitch;
     uint8_t i_y, i_u, i_v; // YUV values, derived from incoming RGB
-    subpicture_region_t *p_region_tmp;
 
     // Create a new subpicture region
     memset( &fmt, 0, sizeof(video_format_t) );
@@ -1330,21 +1329,17 @@ static int RenderYUVA( filter_t *p_filter, subpicture_region_t *p_region, UniCha
     fmt.i_width = fmt.i_visible_width = i_width;
     fmt.i_height = fmt.i_visible_height = i_textblock_height + VERTICAL_MARGIN * 2;
     fmt.i_x_offset = fmt.i_y_offset = 0;
-    p_region_tmp = spu_CreateRegion( p_filter, &fmt );
-    if( !p_region_tmp )
-    {
-        msg_Err( p_filter, "cannot allocate SPU region" );
+
+    p_region->p_picture = picture_New( fmt.i_chroma, fmt.i_width, fmt.i_height, fmt.i_aspect );
+    if( !p_region->p_picture )
         return VLC_EGENERIC;
-    }
-    p_region->fmt = p_region_tmp->fmt;
-    p_region->picture = p_region_tmp->picture;
-    free( p_region_tmp );
-
-    p_dst_y = p_region->picture.Y_PIXELS;
-    p_dst_u = p_region->picture.U_PIXELS;
-    p_dst_v = p_region->picture.V_PIXELS;
-    p_dst_a = p_region->picture.A_PIXELS;
-    i_pitch = p_region->picture.A_PITCH;
+    p_region->fmt = fmt;
+
+    p_dst_y = p_region->p_picture->Y_PIXELS;
+    p_dst_u = p_region->p_picture->U_PIXELS;
+    p_dst_v = p_region->p_picture->V_PIXELS;
+    p_dst_a = p_region->p_picture->A_PIXELS;
+    i_pitch = p_region->p_picture->A_PITCH;
 
     i_offset = VERTICAL_MARGIN *i_pitch;
     for( y=0; y<i_textblock_height; y++)
index 296e7cc..5841aeb 100644 (file)
@@ -257,7 +257,6 @@ static int Render( filter_t *p_filter, subpicture_region_t *p_region,
     int channels_in;
     int alpha;
     picture_t *p_pic;
-    subpicture_region_t *p_region_tmp;
 
     if ( p_filter->p_sys->i_width != i_width ||
          p_filter->p_sys->i_height != i_height )
@@ -284,31 +283,27 @@ static int Render( filter_t *p_filter, subpicture_region_t *p_region,
     fmt.i_width = fmt.i_visible_width = i_width;
     fmt.i_height = fmt.i_visible_height = i_height;
     fmt.i_x_offset = fmt.i_y_offset = 0;
-    p_region_tmp = spu_CreateRegion( p_filter, &fmt );
-    if( !p_region_tmp )
-    {
-        msg_Err( p_filter, "cannot allocate SPU region" );
+
+    p_region->p_picture = picture_New( fmt.i_chroma, fmt.i_width, fmt.i_height, fmt.i_aspect );
+    if( !p_region->p_picture )
         return VLC_EGENERIC;
-    }
-    p_region->fmt = p_region_tmp->fmt;
-    p_region->picture = p_region_tmp->picture;
-    free( p_region_tmp );
+    p_region->fmt = fmt;
 
     p_region->i_x = p_region->i_y = 0;
-    p_y = p_region->picture.Y_PIXELS;
-    p_u = p_region->picture.U_PIXELS;
-    p_v = p_region->picture.V_PIXELS;
-    p_a = p_region->picture.A_PIXELS;
+    p_y = p_region->p_picture->Y_PIXELS;
+    p_u = p_region->p_picture->U_PIXELS;
+    p_v = p_region->p_picture->V_PIXELS;
+    p_a = p_region->p_picture->A_PIXELS;
 
-    i_pitch = p_region->picture.Y_PITCH;
-    i_u_pitch = p_region->picture.U_PITCH;
+    i_pitch = p_region->p_picture->Y_PITCH;
+    i_u_pitch = p_region->p_picture->U_PITCH;
 
     /* Initialize the region pixels (only the alpha will be changed later) */
     memset( p_y, 0x00, i_pitch * p_region->fmt.i_height );
     memset( p_u, 0x80, i_u_pitch * p_region->fmt.i_height );
     memset( p_v, 0x80, i_u_pitch * p_region->fmt.i_height );
 
-    p_pic = &p_region->picture;
+    p_pic = p_region->p_picture;
 
     /* Copy the data */
 
index 75ad54b..9c16c12 100644 (file)
@@ -217,7 +217,6 @@ static int Render( filter_t *p_filter, subpicture_region_t *p_region,
     uint8_t *p_dst;
     video_format_t fmt;
     int i, i_pitch;
-    subpicture_region_t *p_region_tmp;
     bool b_outline = true;
 
     /* Create a new subpicture region */
@@ -226,12 +225,6 @@ static int Render( filter_t *p_filter, subpicture_region_t *p_region,
     fmt.i_width = fmt.i_visible_width = i_width + (b_outline ? 4 : 0);
     fmt.i_height = fmt.i_visible_height = i_height + (b_outline ? 4 : 0);
     fmt.i_x_offset = fmt.i_y_offset = 0;
-    p_region_tmp = spu_CreateRegion( p_filter, &fmt );
-    if( !p_region_tmp )
-    {
-        msg_Err( p_filter, "cannot allocate SPU region" );
-        return VLC_EGENERIC;
-    }
 
     /* Build palette */
     fmt.p_palette->i_entries = 16;
@@ -243,17 +236,18 @@ static int Render( filter_t *p_filter, subpicture_region_t *p_region,
         fmt.p_palette->palette[i][3] = pi_gamma[i];
     }
 
-    p_region->fmt = p_region_tmp->fmt;
-    p_region->picture = p_region_tmp->picture;
-    free( p_region_tmp );
+    p_region->p_picture = picture_New( fmt.i_chroma, fmt.i_width, fmt.i_height, fmt.i_aspect );
+    if( !p_region->p_picture )
+        return VLC_EGENERIC;
+    p_region->fmt = fmt;
 
-    p_dst = p_region->picture.Y_PIXELS;
-    i_pitch = p_region->picture.Y_PITCH;
+    p_dst = p_region->p_picture->Y_PIXELS;
+    i_pitch = p_region->p_picture->Y_PITCH;
 
     if( b_outline )
     {
         memset( p_dst, 0, i_pitch * fmt.i_height );
-        p_dst += p_region->picture.Y_PITCH * 2 + 2;
+        p_dst += p_region->p_picture->Y_PITCH * 2 + 2;
     }
 
     for( i = 0; i < i_height; i++ )
@@ -270,7 +264,7 @@ static int Render( filter_t *p_filter, subpicture_region_t *p_region,
         uint8_t left, current;
         int x, y;
 
-        p_dst = p_region->picture.Y_PIXELS;
+        p_dst = p_region->p_picture->Y_PIXELS;
 
         for( y = 1; y < (int)fmt.i_height - 1; y++ )
         {
index 80800d9..0c85468 100644 (file)
@@ -365,7 +365,8 @@ static subpicture_t *Filter( filter_t *p_filter, mtime_t date )
         }
         else
         {
-            vout_CopyPicture( p_filter, &p_region->picture, p_overlay->data.p_pic );
+            /* FIXME the copy is probably not needed anymore */
+            vout_CopyPicture( p_filter, p_region->p_picture, p_overlay->data.p_pic );
         }
         p_region->i_x = p_overlay->i_x;
         p_region->i_y = p_overlay->i_y;
index 4c7321d..9e1791b 100644 (file)
@@ -873,7 +873,8 @@ static subpicture_t *Filter( filter_t *p_filter, mtime_t date )
         return NULL;
     }
 
-    vout_CopyPicture( p_filter, &p_region->picture, p_pic );
+    /* FIXME the copy is probably not needed anymore */
+    vout_CopyPicture( p_filter, &p_region->p_picture, p_pic );
     vlc_mutex_unlock( &p_logo_list->lock );
 
     /*  where to locate the logo: */
index 661eb77..169155d 100644 (file)
@@ -642,9 +642,9 @@ static subpicture_t *Filter( filter_t *p_filter, mtime_t date )
         }
 
         p_region = p_spu->pf_create_region( VLC_OBJECT(p_filter), &fmt_out );
-        /* XXX That's a pity to do a copy, but it is needed for now */
+        /* FIXME the copy is probably not needed anymore */
         if( p_region )
-            picture_Copy( &p_region->picture, p_converted );
+            picture_Copy( &p_region->p_picture, p_converted );
         if( !p_sys->b_keep )
             picture_Release( p_converted );
 
index d8f68f7..1c3d5bb 100644 (file)
@@ -426,8 +426,9 @@ static subpicture_region_t *create_picture_region( filter_t *p_filter, subpictur
         p_region->fmt.i_width = p_region->fmt.i_visible_width = 0;
         p_region->fmt.i_height = p_region->fmt.i_visible_height = 0;
     }
+    /* FIXME the copy is probably not needed anymore */
     if( p_pic )
-        vout_CopyPicture( p_filter, &p_region->picture, p_pic );
+        vout_CopyPicture( p_filter, p_region->p_picture, p_pic );
 
     p_region->i_x = 0;
     p_region->i_y = 0;
index 04ef5d2..a6a253b 100644 (file)
@@ -1171,7 +1171,8 @@ static subpicture_t *Filter( filter_t *p_filter, mtime_t date )
         return NULL;
     }
 
-    vout_CopyPicture( p_filter, &p_region->picture, p_pic );
+    /* FIXME the copy is probably not needed anymore */
+    vout_CopyPicture( p_filter, p_region->p_picture, p_pic );
 
     p_sys->b_need_update = false;
 
index 29a42de..dbb5dbe 100644 (file)
@@ -557,7 +557,8 @@ static subpicture_t *Filter( filter_t *p_filter, mtime_t date )
         {
             p_region->i_x = p_sys->i_xoff;
             p_region->i_y = p_sys->i_yoff;
-            vout_CopyPicture( p_filter, &p_region->picture, p_pic );
+            /* FIXME the copy is probably not needed anymore */
+            vout_CopyPicture( p_filter, p_region->p_picture, p_pic );
             p_spu->p_region->p_next = p_region;
         }
 
index 5d8fafd..2d384d1 100644 (file)
@@ -52,8 +52,8 @@ static void DrawRect( subpicture_t *p_subpic, int i_x1, int i_y1,
                       int i_x2, int i_y2, short fill )
 {
     int x, y;
-    uint8_t *p_a = p_subpic->p_region->picture.A_PIXELS;
-    int i_pitch = p_subpic->p_region->picture.Y_PITCH;
+    uint8_t *p_a = p_subpic->p_region->p_picture->A_PIXELS;
+    int i_pitch = p_subpic->p_region->p_picture->Y_PITCH;
 
     if( fill == STYLE_FILLED )
     {
@@ -88,8 +88,8 @@ static void DrawTriangle( subpicture_t *p_subpic, int i_x1, int i_y1,
                           int i_x2, int i_y2, short fill )
 {
     int x, y, i_mid, h;
-    uint8_t *p_a = p_subpic->p_region->picture.A_PIXELS;
-    int i_pitch = p_subpic->p_region->picture.Y_PITCH;
+    uint8_t *p_a = p_subpic->p_region->p_picture->A_PIXELS;
+    int i_pitch = p_subpic->p_region->p_picture->Y_PITCH;
 
     i_mid = i_y1 + ( ( i_y2 - i_y1 ) >> 1 );
 
@@ -173,11 +173,11 @@ static int CreatePicture( spu_t *p_spu, subpicture_t *p_subpic,
 
     p_subpic->p_region->i_x = i_x;
     p_subpic->p_region->i_y = i_y;
-    p_y = p_subpic->p_region->picture.Y_PIXELS;
-    p_u = p_subpic->p_region->picture.U_PIXELS;
-    p_v = p_subpic->p_region->picture.V_PIXELS;
-    p_a = p_subpic->p_region->picture.A_PIXELS;
-    i_pitch = p_subpic->p_region->picture.Y_PITCH;
+    p_y = p_subpic->p_region->p_picture->Y_PIXELS;
+    p_u = p_subpic->p_region->p_picture->U_PIXELS;
+    p_v = p_subpic->p_region->p_picture->V_PIXELS;
+    p_a = p_subpic->p_region->p_picture->A_PIXELS;
+    i_pitch = p_subpic->p_region->p_picture->Y_PITCH;
 
     /* Initialize the region pixels (only the alpha will be changed later) */
     memset( p_y, 0xff, i_pitch * p_subpic->p_region->fmt.i_height );
@@ -328,8 +328,8 @@ int osd_Icon( vlc_object_t *p_this, spu_t *p_spu,
                       STYLE_FILLED );
         if( i_type == OSD_MUTE_ICON )
         {
-            uint8_t *p_a = p_subpic->p_region->picture.A_PIXELS;
-            int i_pitch = p_subpic->p_region->picture.Y_PITCH;
+            uint8_t *p_a = p_subpic->p_region->p_picture->A_PIXELS;
+            int i_pitch = p_subpic->p_region->p_picture->Y_PITCH;
             int i;
             for( i = 1; i < i_pitch; i++ )
             {
index 2d48bb7..a57e88b 100644 (file)
@@ -477,8 +477,14 @@ static int VoutSnapshotPip( vout_thread_t *p_vout, image_handler_t *p_image, pic
 
     p_subpic->p_region = spu_CreateRegion( p_vout->p_spu, &fmt_out );
     if( p_subpic->p_region )
-        vout_CopyPicture( p_image->p_parent, &p_subpic->p_region->picture, p_pip );
-    picture_Release( p_pip );
+    {
+        picture_Release( p_subpic->p_region->p_picture );
+        p_subpic->p_region->p_picture = p_pip;
+    }
+    else
+    {
+        picture_Release( p_pip );
+    }
 
     spu_DisplaySubpicture( p_vout->p_spu, p_subpic );
     return VLC_SUCCESS;
index 1ed1021..cf8ac2e 100644 (file)
@@ -70,6 +70,39 @@ struct filter_owner_sys_t
 
 #define SCALE_UNIT (1000)
 
+/* */
+struct subpicture_region_private_t
+{
+    video_format_t fmt;
+    picture_t      *p_picture;
+};
+
+static subpicture_region_private_t *SpuRegionPrivateCreate( video_format_t *p_fmt )
+{
+    subpicture_region_private_t *p_private = malloc( sizeof(*p_private) );
+
+    if( !p_private )
+        return NULL;
+
+    p_private->fmt = *p_fmt;
+    if( p_fmt->p_palette )
+    {
+        p_private->fmt.p_palette = malloc( sizeof(*p_private->fmt.p_palette) );
+        if( p_private->fmt.p_palette )
+            *p_private->fmt.p_palette = *p_fmt->p_palette;
+    }
+    p_private->p_picture = NULL;
+
+    return p_private;
+}
+static void SpuRegionPrivateDestroy( subpicture_region_private_t *p_private )
+{
+    if( p_private->p_picture )
+        picture_Release( p_private->p_picture );
+    free( p_private->fmt.p_palette );
+    free( p_private );
+}
+
 /* */
 static void SpuRenderCreateAndLoadText( spu_t *p_spu );
 static void SpuRenderCreateAndLoadScale( spu_t *p_spu );
@@ -215,19 +248,6 @@ void spu_Attach( spu_t *p_spu, vlc_object_t *p_this, bool b_attach )
     }
 }
 
-
-/* */
-static void RegionPictureRelease( picture_t *p_picture )
-{
-    if( --p_picture->i_refcount > 0 )
-        return;
-
-    assert( p_picture->i_refcount == 0 );
-    free( p_picture->p_q );
-    free( p_picture->p_data_orig );
-    free( p_picture->p_sys );
-}
-
 /**
  * Create a subpicture region
  *
@@ -250,26 +270,23 @@ subpicture_region_t *__spu_CreateRegion( vlc_object_t *p_this,
     p_region->fmt = *p_fmt;
     p_region->i_alpha = 0xff;
     p_region->p_next = NULL;
-    p_region->p_cache = NULL;
+    p_region->p_private = NULL;
     p_region->psz_text = NULL;
     p_region->p_style = NULL;
+    p_region->p_picture = NULL;
 
     if( p_fmt->i_chroma == VLC_FOURCC('T','E','X','T') )
         return p_region;
 
-    vout_AllocatePicture( p_this, &p_region->picture, p_fmt->i_chroma,
-                          p_fmt->i_width, p_fmt->i_height, p_fmt->i_aspect );
-
-    if( !p_region->picture.i_planes )
+    p_region->p_picture = picture_New( p_fmt->i_chroma, p_fmt->i_width, p_fmt->i_height,
+                                       p_fmt->i_aspect );
+    if( !p_region->p_picture )
     {
         free( p_fmt->p_palette );
         free( p_region );
         return NULL;
     }
 
-    p_region->picture.i_refcount = 1;
-    p_region->picture.pf_release = RegionPictureRelease;
-
     return p_region;
 }
 
@@ -284,11 +301,13 @@ void __spu_DestroyRegion( vlc_object_t *p_this, subpicture_region_t *p_region )
     if( !p_region )
         return;
 
-    picture_Release( &p_region->picture );
+    if( p_region->p_private )
+        SpuRegionPrivateDestroy( p_region->p_private );
+
+    if( p_region->p_picture )
+        picture_Release( p_region->p_picture );
 
     free( p_region->fmt.p_palette );
-    if( p_region->p_cache )
-        __spu_DestroyRegion( p_this, p_region->p_cache );
 
     free( p_region->psz_text );
     free( p_region->psz_html );
@@ -902,6 +921,9 @@ static void SpuRenderRegion( spu_t *p_spu,
     int i_y_offset;
     filter_t *p_scale;
 
+    video_format_t *p_region_fmt;
+    picture_t *p_region_picture;
+
     vlc_assert_locked( &p_spu->subpicture_lock );
 
     /* Invalidate area by default */
@@ -958,6 +980,7 @@ static void SpuRenderRegion( spu_t *p_spu,
     i_x_offset = spu_scale_w( p_area->i_x, p_area->scale );
     i_y_offset = spu_scale_h( p_area->i_y, p_area->scale );
 
+    /* */
     if( b_force_palette )
     {
         /* It looks so wrong I won't comment
@@ -968,12 +991,14 @@ static void SpuRenderRegion( spu_t *p_spu,
         memcpy( p_region->fmt.p_palette->palette, p_spu->palette, 4*sizeof(uint32_t) );
     }
 
-    if( b_using_palette )
-        p_scale = p_spu->p_scale_yuvp;
-    else
-        p_scale = p_spu->p_scale;
+    /* */
+    p_region_fmt = &p_region->fmt;
+    p_region_picture = p_region->p_picture;
+
 
     /* Scale from rendered size to destination size */
+    p_scale = b_using_palette ? p_spu->p_scale_yuvp : p_spu->p_scale;
+
     if( p_scale &&
         ( scale_size.w != SCALE_UNIT || scale_size.h != SCALE_UNIT || b_force_palette ) )
     {
@@ -983,21 +1008,17 @@ static void SpuRenderRegion( spu_t *p_spu,
         /* TODO when b_using_palette is true, we should first convert it to YUVA to allow
          * a proper rescaling */
 
-        /* Destroy if cache is unusable */
-        if( p_region->p_cache )
+        /* Destroy if cache is unusable
+         * FIXME do not always destroy the region it can sometimes be reused 
+         * if same size and same palette if present */
+        if( p_region->p_private )
         {
-            if( p_region->p_cache->fmt.i_width  != i_dst_width ||
-                p_region->p_cache->fmt.i_height != i_dst_height ||
-                b_force_palette )
-            {
-                p_subpic->pf_destroy_region( VLC_OBJECT(p_spu),
-                                             p_region->p_cache );
-                p_region->p_cache = NULL;
-            }
+            SpuRegionPrivateDestroy( p_region->p_private );
+            p_region->p_private = NULL;
         }
 
         /* Scale if needed into cache */
-        if( !p_region->p_cache )
+        if( !p_region->p_private )
         {
             picture_t *p_pic;
 
@@ -1012,52 +1033,33 @@ static void SpuRenderRegion( spu_t *p_spu,
             p_scale->fmt_out.video.i_visible_height =
                 spu_scale_h( p_region->fmt.i_visible_height, scale_size );
 
-            p_region->p_cache =
-                p_subpic->pf_create_region( VLC_OBJECT(p_spu),
-                                            &p_scale->fmt_out.video );
+            p_region->p_private = SpuRegionPrivateCreate( &p_scale->fmt_out.video );
 
-            p_pic = NULL;
             if( p_scale->p_module )
             {
-                picture_Yield( &p_region->picture );
-                p_pic = p_scale->pf_video_filter( p_scale, &p_region->picture );
+                picture_Yield( p_region->p_picture );
+                p_region->p_private->p_picture = p_scale->pf_video_filter( p_scale, p_region->p_picture );
             }
-            if( p_pic )
-            {
-                picture_CopyPixels( &p_region->p_cache->picture, p_pic );
-                picture_Release( p_pic );
-
-                if( p_region->p_cache->fmt.p_palette )
-                    *p_region->p_cache->fmt.p_palette = *p_region->fmt.p_palette;
-
-                /* i_x/i_y of cached region should NOT be used. I set them to
-                 * an invalid value to catch it (assert) */
-                p_region->p_cache->i_x = INT_MAX;
-                p_region->p_cache->i_y = INT_MAX;
-                p_region->p_cache->i_align = p_region->i_align;
-                p_region->p_cache->i_alpha = p_region->i_alpha;
-            }
-            else
+            if( !p_region->p_private->p_picture )
             {
                 msg_Err( p_spu, "scaling failed (module not loaded)" );
-                p_subpic->pf_destroy_region( VLC_OBJECT(p_spu),
-                                             p_region->p_cache );
-                p_region->p_cache = NULL;
+                SpuRegionPrivateDestroy( p_region->p_private );
+                p_region->p_private = NULL;
             }
         }
 
         /* And use the scaled picture */
-        if( p_region->p_cache )
+        if( p_region->p_private )
         {
-            p_region = p_region->p_cache;
-            fmt_original = p_region->fmt;
+            p_region_fmt = &p_region->p_private->fmt;
+            p_region_picture = p_region->p_private->p_picture;
         }
     }
 
     /* Force cropping if requested */
     if( b_force_crop )
     {
-        video_format_t *p_fmt = &p_region->fmt;
+        video_format_t *p_fmt = p_region_fmt;
         int i_crop_x = spu_scale_w( p_spu->i_crop_x, scale_size );
         int i_crop_y = spu_scale_h( p_spu->i_crop_y, scale_size );
         int i_crop_width = spu_scale_w( p_spu->i_crop_width, scale_size );
@@ -1094,14 +1096,14 @@ static void SpuRenderRegion( spu_t *p_spu,
     }
 
     /* Update the blender */
-    SpuRenderUpdateBlend( p_spu, p_fmt->i_width, p_fmt->i_height, &p_region->fmt );
+    SpuRenderUpdateBlend( p_spu, p_fmt->i_width, p_fmt->i_height, p_region_fmt );
 
     if( p_spu->p_blend->p_module )
     {
         const int i_alpha = SpuRegionAlpha( p_subpic, p_region );
 
         p_spu->p_blend->pf_video_blend( p_spu->p_blend, p_pic_dst,
-            &p_region->picture, i_x_offset, i_y_offset, i_alpha );
+            p_region_picture, i_x_offset, i_y_offset, i_alpha );
     }
     else
     {
@@ -1118,8 +1120,13 @@ exit:
          * pre-rendered state, so the next time through everything is
          * calculated again.
          */
-        p_region->picture.pf_release( &p_region->picture );
-        memset( &p_region->picture, 0, sizeof( picture_t ) );
+        picture_Release( p_region->p_picture );
+        p_region->p_picture = NULL;
+        if( p_region->p_private )
+        {
+            SpuRegionPrivateDestroy( p_region->p_private );
+            p_region->p_private = NULL;
+        }
         p_region->i_align &= ~SUBPICTURE_RENDERED;
     }
     if( b_restore_format )