1 /*
2  * Copyright (C) 2007-2019 the xine project
3  *
4  * This file is part of xine, a free video player.
5  *
6  * xine is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * xine 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 General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License along
17  * with this program; if not, write to the Free Software Foundation, Inc.,
18  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19  *
20  */
21 
22 #ifdef HAVE_CONFIG_H
23 #include "config.h"
24 #endif
25 
26 #include <xine/configfile.h>
27 #include <xine/xine_internal.h>
28 #include <xine/spu.h>
29 #include <xine.h>
30 
31 #define BLACK_OPACITY   67
32 #define COLOUR_OPACITY 100
33 
_x_spu_misc_init(xine_t * this)34 void _x_spu_misc_init (xine_t *this)
35 {
36   this->config->register_range (this->config, "subtitles.bitmap.black_opacity",
37                                 BLACK_OPACITY, 0, 100,
38                                 _("opacity for the black parts of bitmapped subtitles"),
39                                 NULL,
40                                 10, NULL, NULL);
41   this->config->register_range (this->config, "subtitles.bitmap.colour_opacity",
42                                 COLOUR_OPACITY, 0, 100,
43                                 _("opacity for the colour parts of bitmapped subtitles"),
44                                 NULL,
45                                 10, NULL, NULL);
46 }
47 
_x_spu_get_opacity(xine_t * this,xine_spu_opacity_t * opacity)48 void _x_spu_get_opacity (xine_t *this, xine_spu_opacity_t *opacity)
49 {
50   cfg_entry_t *entry;
51 
52   entry = this->config->lookup_entry (this->config, "subtitles.bitmap.black_opacity");
53   opacity->black = entry ? entry->num_value : BLACK_OPACITY;
54   entry = this->config->lookup_entry (this->config, "subtitles.bitmap.colour_opacity");
55   opacity->colour = entry ? entry->num_value : COLOUR_OPACITY;
56 }
57 
_x_spu_calculate_opacity(const clut_t * clut,uint8_t trans,const xine_spu_opacity_t * opacity)58 int _x_spu_calculate_opacity (const clut_t *clut, uint8_t trans, const xine_spu_opacity_t *opacity)
59 {
60   int value = (clut->y == 0 || (clut->y == 16 && clut->cb == 128 && clut->cr == 128))
61 	      ? opacity->black
62 	      : opacity->colour;
63   return value * (255 - trans) / 100;
64 }
65