VLC 4.0.0-dev
vout_spuregion_helper.h
Go to the documentation of this file.
1/*****************************************************************************
2 * vout_spuregion_helper.h : vout subpicture region helpers
3 *****************************************************************************
4 * Copyright (C) 2017 VLC authors, VideoLAN and VideoLabs
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU Lesser General Public License as published by
8 * the Free Software Foundation; either version 2.1 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
19 *****************************************************************************/
20#include <vlc_image.h>
21
22#define RGB2YUV( R, G, B ) \
23 ((0.257 * R) + (0.504 * G) + (0.098 * B) + 16), \
24 (-(0.148 * R) - (0.291 * G) + (0.439 * B) + 128),\
25 ((0.439 * R) - (0.368 * G) - (0.071 * B) + 128)
26
27#define HEX2YUV( rgb ) \
28 RGB2YUV( (rgb >> 16), ((rgb & 0xFF00) >> 8), (rgb & 0xFF) )
29
30static inline void
32 uint32_t argb1, uint32_t argb2 )
33{
34 for( uint8_t i = 0; i<i_splits; i++ )
35 {
36 uint32_t rgb1 = argb1 & 0x00FFFFFF;
37 uint32_t rgb2 = argb2 & 0x00FFFFFF;
38
39 uint32_t r = ((((rgb1 >> 16) * (i_splits - i)) + (rgb2 >> 16) * i)) / i_splits;
40 uint32_t g = (((((rgb1 >> 8) & 0xFF) * (i_splits - i)) + ((rgb2 >> 8) & 0xFF) * i)) / i_splits;
41 uint32_t b = ((((rgb1 & 0xFF) * (i_splits - i)) + (rgb2 & 0xFF) * i)) / i_splits;
42 uint8_t entry[4] = { RGB2YUV( r,g,b ), argb1 >> 24 };
43 memcpy( p_palette->palette[i], entry, 4 );
44 }
45 p_palette->i_entries = i_splits;
46}
47
48static inline void
50{
51 const int i_split = p->i_visible_lines / i_splits;
52 const int i_left = p->i_visible_lines % i_splits + p->i_lines - p->i_visible_lines;
53 for( int i = 0; i<i_splits; i++ )
54 {
55 memset( &p->p_pixels[p->i_pitch * (i * i_split)],
56 i,
57 p->i_pitch * i_split );
58 }
59 memset( &p->p_pixels[p->i_pitch * (i_splits - 1) * i_split],
60 i_splits - 1,
61 p->i_pitch * i_left );
62}
63
64
65static inline subpicture_region_t *
67 const char *psz_uri )
68{
69 picture_t *p_pic = NULL;
70 struct vlc_logger *logger = p_this->logger;
71 bool no_interact = p_this->no_interact;
72 p_this->logger = NULL;
73 p_this->no_interact = true;
74 image_handler_t *p_image = image_HandlerCreate( p_this );
75 if( p_image )
76 {
77 p_pic = image_ReadUrl( p_image, psz_uri, p_fmt );
78 image_HandlerDelete( p_image );
79 }
80 p_this->no_interact = no_interact;
81 p_this->logger = logger;
82
83 if(!p_pic)
84 return NULL;
85
87 if (!region)
88 {
89 picture_Release( p_pic );
90 return NULL;
91 }
92
93 picture_Release( region->p_picture );
94 region->p_picture = p_pic;
95
96 return region;
97}
#define p(t)
static void picture_Release(picture_t *picture)
Decrements the picture reference count.
Definition: vlc_picture.h:374
subpicture_region_t * subpicture_region_New(const video_format_t *p_fmt)
This function will create a new subpicture region.
Definition: subpicture.c:240
void image_HandlerDelete(image_handler_t *p_image)
Delete the image_handler_t instance.
Definition: image.c:116
Definition: fourcc_gen.c:52
Definition: vlc_image.h:40
Video picture.
Definition: vlc_picture.h:130
Description of a planar graphic field.
Definition: vlc_picture.h:50
Video subtitle region.
Definition: vlc_subpicture.h:60
picture_t * p_picture
picture comprising this region
Definition: vlc_subpicture.h:62
video format description
Definition: vlc_es.h:352
Definition: vlc_es.h:44
int i_entries
number of in-use palette entries
Definition: vlc_es.h:45
uint8_t palette[256][4]
4-byte RGBA/YUVA palette
Definition: vlc_es.h:46
Definition: messages.c:85
VLC object common members.
Definition: vlc_objects.h:45
struct vlc_logger * logger
Definition: vlc_objects.h:46
bool no_interact
Definition: vlc_objects.h:52
This file defines functions and structures for image conversions in vlc.
#define image_HandlerCreate(a)
Definition: vlc_image.h:65
#define image_ReadUrl(a, b, c)
Definition: vlc_image.h:69
#define RGB2YUV(R, G, B)
Definition: vout_spuregion_helper.h:22
static void spuregion_CreateVGradientPalette(video_palette_t *p_palette, uint8_t i_splits, uint32_t argb1, uint32_t argb2)
Definition: vout_spuregion_helper.h:31
static void spuregion_CreateVGradientFill(plane_t *p, uint8_t i_splits)
Definition: vout_spuregion_helper.h:49
static subpicture_region_t * spuregion_CreateFromPicture(vlc_object_t *p_this, video_format_t *p_fmt, const char *psz_uri)
Definition: vout_spuregion_helper.h:66