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 
30 static inline void
31 spuregion_CreateVGradientPalette( video_palette_t *p_palette, uint8_t i_splits,
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 
48 static 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 
65 static 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 }
subpicture_region_t * subpicture_region_New(const video_format_t *p_fmt)
This function will create a new subpicture region.
Definition: subpicture.c:240
bool no_interact
Definition: vlc_objects.h:51
int i_visible_lines
How many visible lines are there?
Definition: vlc_picture.h:59
Video picture.
Definition: vlc_picture.h:127
#define image_ReadUrl(a, b, c)
Definition: vlc_image.h:69
Video subtitle region.
Definition: vlc_subpicture.h:59
int i_pitch
Number of bytes in a line, including margins.
Definition: vlc_picture.h:53
picture_t * p_picture
picture comprising this region
Definition: vlc_subpicture.h:62
Definition: vlc_image.h:39
uint8_t * p_pixels
Start of the plane&#39;s data.
Definition: vlc_picture.h:49
int i_entries
to keep the compatibility with libavcodec&#39;s palette
Definition: vlc_es.h:45
This file defines functions and structures for image conversions in vlc.
Definition: vlc_es.h:43
#define RGB2YUV(R, G, B)
Definition: vout_spuregion_helper.h:22
uint8_t palette[256][4]
4-byte RGBA/YUVA palette
Definition: vlc_es.h:46
static void picture_Release(picture_t *picture)
Decrements the picture reference count.
Definition: vlc_picture.h:241
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
video format description
Definition: vlc_es.h:349
int i_lines
Number of lines, including margins.
Definition: vlc_picture.h:52
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
Definition: messages.c:54
Description of a planar graphic field.
Definition: vlc_picture.h:47
void image_HandlerDelete(image_handler_t *p_image)
Delete the image_handler_t instance.
Definition: image.c:115
struct vlc_logger * logger
Definition: vlc_objects.h:45
#define p(t)
Definition: fourcc_gen.c:51
VLC object common members.
Definition: vlc_objects.h:43
#define image_HandlerCreate(a)
Definition: vlc_image.h:65