1 /*****************************************************************************
2 * vout_spuregion_helper.h : vout subpicture region helpers
3 *****************************************************************************
4 * Copyright (C) 2017 VLC authors, VideoLAN and VideoLabs
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.
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.
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>
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)
27 #define HEX2YUV( rgb ) \
28 RGB2YUV( (rgb >> 16), ((rgb & 0xFF00) >> 8), (rgb & 0xFF) )
31 spuregion_CreateVGradientPalette( video_palette_t
*p_palette
, uint8_t i_splits
,
32 uint32_t argb1
, uint32_t argb2
)
34 for( uint8_t i
= 0; i
<i_splits
; i
++ )
36 uint32_t rgb1
= argb1
& 0x00FFFFFF;
37 uint32_t rgb2
= argb2
& 0x00FFFFFF;
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 );
45 p_palette
->i_entries
= i_splits
;
49 spuregion_CreateVGradientFill( plane_t
*p
, uint8_t i_splits
)
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
++ )
55 memset( &p
->p_pixels
[p
->i_pitch
* (i
* i_split
)],
57 p
->i_pitch
* i_split
);
59 memset( &p
->p_pixels
[p
->i_pitch
* (i_splits
- 1) * i_split
],
61 p
->i_pitch
* i_left
);
65 static inline subpicture_region_t
*
66 spuregion_CreateFromPicture( vlc_object_t
*p_this
, video_format_t
*p_fmt
,
69 video_format_t fmt_in
;
70 video_format_Init( &fmt_in
, 0 );
72 picture_t
*p_pic
= NULL
;
73 int i_flags
= p_this
->obj
.flags
;
74 p_this
->obj
.flags
|= OBJECT_FLAGS_NOINTERACT
|OBJECT_FLAGS_QUIET
;
75 image_handler_t
*p_image
= image_HandlerCreate( p_this
);
78 p_pic
= image_ReadUrl( p_image
, psz_uri
, &fmt_in
, p_fmt
);
79 image_HandlerDelete( p_image
);
81 p_this
->obj
.flags
= i_flags
;
86 subpicture_region_t
*region
= subpicture_region_New(p_fmt
);
90 picture_Release( region
->p_picture
);
91 region
->p_picture
= p_pic
;