<commit_before>/*****************************************************************************
 * video_epg.c : EPG manipulation functions
 *****************************************************************************
 * Copyright (C) 2010 <NAME>
 *
 * Author: <NAME> <<EMAIL>>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
 *****************************************************************************/

#ifdef HAVE_CONFIG_H
# include "config.h"
#endif

#include <vlc_common.h>
#include <vlc_vout.h>
#include <vlc_block.h>
#include <vlc_filter.h>
#include <vlc_osd.h>
#include <vlc_events.h>
#include <vlc_input_item.h>
#include <vlc_epg.h>


/* Layout percentage defines */
#define EPG_TOP 0.7
#define EPG_LEFT 0.1
#define EPG_NAME_SIZE 0.05
#define EPG_PROGRAM_SIZE 0.03

#define NO_EPG N_( "No EPG found for this program." )


static subpicture_region_t * vout_OSDEpgSlider( vout_thread_t *p_vout,
                                                int i_x, int i_y,
                                                int i_width, int i_height,
                                                float f_ratio )
{
    video_format_t fmt;
    subpicture_region_t *p_region;

    /* Create a new subpicture region */
    video_format_Init( &fmt, VLC_CODEC_YUVA );
    fmt.i_width = fmt.i_visible_width = i_width;
    fmt.i_height = fmt.i_visible_height = i_height;

    p_region = subpicture_region_New( &fmt );
    if( !p_region )
    {
        msg_Err( p_vout, "Cannot allocate SPU region." );
        return NULL;
    }

    p_region->i_x = i_x;
    p_region->i_y = i_y;

    picture_t *p_picture = p_region->p_picture;

    f_ratio = __MIN( __MAX( f_ratio, 0 ), 1 );
    int i_filled_part_width = f_ratio * i_width;

    for( int j = 0; j < i_height; j++ )
    {
        for( int i = 0; i < i_width; i++ )
        {
            #define WRITE_COMP( plane, value ) \
                p_picture->p[plane].p_pixels[p_picture->p[plane].i_pitch * j + i] = value

            /* Draw the slider. */
            bool is_outline = j == 0 || j == i_height - 1
                              || i == 0 || i == i_width - 1;
            WRITE_COMP( 0, is_outline ? 0x00 : 0xff );
            WRITE_COMP( 1, 0x80 );
            WRITE_COMP( 2, 0x80 );

            /* We can see the video through the part of the slider
               which corresponds to the leaving time. */
            bool is_border = j < 3 || j > i_height - 4
                             || i < 3 || i > i_width - 4
                             || i < i_filled_part_width;
            WRITE_COMP( 3, is_border ? 0xff : 0x00 );

            #undef WRITE_COMP
        }
    }

    return p_region;
}


static subpicture_region_t * vout_OSDEpgText( vout_thread_t *p_vout,
                                              const char *psz_string,
                                              int i_x, int i_y,
                                              int i_size, uint32_t i_color )
{
    video_format_t fmt;
    subpicture_region_t *p_region;

    if( !psz_string )
        return NULL;

    /* Create a new subpicture region */
    video_format_Init( &fmt, VLC_CODEC_TEXT );

    p_region = subpicture_region_New( &fmt );
    if( !p_region )
    {
        msg_Err( p_vout, "Cannot allocate SPU region." );
        return NULL;
    }

    /* Set subpicture parameters */
    p_region->psz_text = strdup( psz_string );<commit_msg>Fixed EPG OSD aspect ratio.<commit_after>/*****************************************************************************
 * video_epg.c : EPG manipulation functions
 *****************************************************************************
 * Copyright (C) 2010 <NAME>
 *
 * Author: <NAME> <<EMAIL>>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
 *****************************************************************************/

#ifdef HAVE_CONFIG_H
# include "config.h"
#endif

#include <vlc_common.h>
#include <vlc_vout.h>
#include <vlc_block.h>
#include <vlc_filter.h>
#include <vlc_osd.h>
#include <vlc_events.h>
#include <vlc_input_item.h>
#include <vlc_epg.h>


/* Layout percentage defines */
#define EPG_TOP 0.7
#define EPG_LEFT 0.1
#define EPG_NAME_SIZE 0.05
#define EPG_PROGRAM_SIZE 0.03

#define NO_EPG N_( "No EPG found for this program." )


static subpicture_region_t * vout_OSDEpgSlider( vout_thread_t *p_vout,
                                                int i_x, int i_y,
                                                int i_width, int i_height,
                                                float f_ratio )
{
    video_format_t fmt;
    subpicture_region_t *p_region;

    /* Create a new subpicture region */
    video_format_Init( &fmt, VLC_CODEC_YUVA );
    fmt.i_width = fmt.i_visible_width = i_width;
    fmt.i_height = fmt.i_visible_height = i_height;
    fmt.i_sar_num = 0;
    fmt.i_sar_den = 1;

    p_region = subpicture_region_New( &fmt );
    if( !p_region )
    {
        msg_Err( p_vout, "Cannot allocate SPU region." );
        return NULL;
    }

    p_region->i_x = i_x;
    p_region->i_y = i_y;

    picture_t *p_picture = p_region->p_picture;

    f_ratio = __MIN( __MAX( f_ratio, 0 ), 1 );
    int i_filled_part_width = f_ratio * i_width;

    for( int j = 0; j < i_height; j++ )
    {
        for( int i = 0; i < i_width; i++ )
        {
            #define WRITE_COMP( plane, value ) \
                p_picture->p[plane].p_pixels[p_picture->p[plane].i_pitch * j + i] = value

            /* Draw the slider. */
            bool is_outline = j == 0 || j == i_height - 1
                              || i == 0 || i == i_width - 1;
            WRITE_COMP( 0, is_outline ? 0x00 : 0xff );
            WRITE_COMP( 1, 0x80 );
            WRITE_COMP( 2, 0x80 );

            /* We can see the video through the part of the slider
               which corresponds to the leaving time. */
            bool is_border = j < 3 || j > i_height - 4
                             || i < 3 || i > i_width - 4
                             || i < i_filled_part_width;
            WRITE_COMP( 3, is_border ? 0xff : 0x00 );

            #undef WRITE_COMP
        }
    }

    return p_region;
}


static subpicture_region_t * vout_OSDEpgText( vout_thread_t *p_vout,
                                              const char *psz_string,
                                              int i_x, int i_y,
                                              int i_size, uint32_t i_color )
{
    video_format_t fmt;
    subpicture_region_t *p_region;

    if( !psz_string )
        return NULL;

    /* Create a new subpicture region */
    video_format_Init( &fmt, VLC_CODEC_TEXT );
    fmt.i_sar_num = 0;
    fmt.i_sar_den = 1;

    p_region = subpicture_region_New( &fmt );
    if( !p_region )
    {
        msg_Err( p_vout, "Cannot allocate SPU region." );
        return NULL;
    }

    /* Set subpicture parameters */
    p_region->psz_text = strdup( psz_string );
{'fraction_non_alphanumeric': 0.1430832927423283, 'fraction_numerical': 0.014612761811982464, 'mean_word_length': 2.129954268292683, 'pattern_counts': {'":': 0, '<': 37, '<?xml version=': 0, '>': 43, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 32, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3802440', 'n_tokens_mistral': 2631, 'n_tokens_neox': 2458, 'n_words': 760}