Beispiel #1
0
CDVDSubtitlesLibass::~CDVDSubtitlesLibass()
{
  if(m_track)
    ass_free_track(m_track);
  ass_renderer_done(m_renderer);
  ass_library_done(m_library);
}
Beispiel #2
0
static csri_inst *libass_init_stream(csri_rend *renderer,
	const void *header, size_t headerlen,
	struct csri_openflag *flags)
{
	csri_inst *rv;

	if (renderer != &csri_libass)
		return NULL;

	rv = (csri_inst *)malloc(sizeof(csri_inst));
	if (!rv)
		return NULL;

	rv->ass_renderer = ass_renderer_init(renderer->ass_library);
	if (!rv->ass_renderer) {
		free(rv);
		return NULL;
	}
	ass_set_font_scale(rv->ass_renderer, 1.);
	ass_set_fonts(rv->ass_renderer, NULL, "Sans");
	rv->ass_track = ass_new_track(csri_libass.ass_library);
	if (!rv->ass_track) {
		ass_renderer_done(rv->ass_renderer);
		free(rv);
		return NULL;
	}
	ass_process_codec_private(rv->ass_track, (void *)header, headerlen);
	return rv;
}
Beispiel #3
0
csri_inst *csri_open_mem(csri_rend *renderer,
	const void *data, size_t length, struct csri_openflag *flags)
{
	csri_inst *rv;
	if (renderer != &csri_libass)
		return NULL;

	rv = (csri_inst *)malloc(sizeof(csri_inst));
	if (!rv)
		return NULL;

	rv->ass_renderer = ass_renderer_init(renderer->ass_library);
	if (!rv->ass_renderer) {
		free(rv);
		return NULL;
	}
	ass_set_font_scale(rv->ass_renderer, 1.);
	ass_set_fonts(rv->ass_renderer, NULL, "Sans");
	rv->ass_track = ass_read_memory(csri_libass.ass_library,
		(void *)data, length, "UTF-8");
	if (!rv->ass_track) {
		ass_renderer_done(rv->ass_renderer);
		free(rv);
		return NULL;
	}
	return rv;
}
Beispiel #4
0
int main(int argc, char *argv[])
{
    const int frame_w = 640;
    const int frame_h = 480;

    if (argc < 4) {
        printf("usage: %s <image file> <subtitle file> <time>\n", argv[0]);
        exit(1);
    }
    char *imgfile = argv[1];
    char *subfile = argv[2];
    double tm = strtod(argv[3], 0);

    init(frame_w, frame_h);
    ASS_Track *track = ass_read_file(ass_library, subfile, NULL);
    if (!track) {
        printf("track init failed!\n");
        return 1;
    }

    ASS_Image *img =
        ass_render_frame(ass_renderer, track, (int) (tm * 1000), NULL);
    image_t *frame = gen_image(frame_w, frame_h);
    blend(frame, img);

    ass_free_track(track);
    ass_renderer_done(ass_renderer);
    ass_library_done(ass_library);

    write_png(imgfile, frame);

    return 0;
}
void dvbsub_ass_clear(void)
{
	OpenThreads::ScopedLock<OpenThreads::Mutex> m_lock(ass_mutex);

	while(ass_queue.size()) {
		ass_data *a = (ass_data *) ass_queue.pop();
		if (a) {
			avsubtitle_free(&a->sub);
			delete a;
		}
	}
	while(!sem_trywait(&ass_sem));

	ass_track = NULL;
	for(std::map<int,ASS_Track*>::iterator it = ass_map.begin(); it != ass_map.end(); ++it)
		ass_free_track(it->second);
	ass_map.clear();
	if (ass_renderer) {
		ass_renderer_done(ass_renderer);
		ass_renderer = NULL;
	}
	if (ass_library) {
		ass_library_done(ass_library);
		ass_library = NULL;
	}
	clear_queue();
}
Beispiel #6
0
void uninit_sub_renderer(struct MPContext *mpctx)
{
    if (mpctx->ass_renderer)
        ass_renderer_done(mpctx->ass_renderer);
    mpctx->ass_renderer = NULL;
    if (mpctx->ass_library)
        ass_library_done(mpctx->ass_library);
    mpctx->ass_library = NULL;
}
Beispiel #7
0
static void VS_CC assFree(void *instanceData, VSCore *core, const VSAPI *vsapi)
{
    AssData *d = (AssData *)instanceData;
    vsapi->freeNode(d->node);
    ass_renderer_done(d->ass_renderer);
    ass_library_done(d->ass_library);
    ass_free_track(d->ass);
    free(d);
}
Beispiel #8
0
static void uninit(struct vf_instance_s* vf)
{
    if (vf->priv) {
#ifdef USE_ASS
        if (vf->priv->ass_priv)
            ass_renderer_done(vf->priv->ass_priv);
#endif
        free(vf->priv);
    }
}
Beispiel #9
0
static av_cold void uninit(AVFilterContext *ctx)
{
    AssContext *ass = ctx->priv;

    if (ass->track)
        ass_free_track(ass->track);
    if (ass->renderer)
        ass_renderer_done(ass->renderer);
    if (ass->library)
        ass_library_done(ass->library);
}
Beispiel #10
0
void LibASS::closeOSD()
{
	if (osd_renderer)
		ass_renderer_done(osd_renderer);
	if (osd_track)
		ass_free_track(osd_track);
	osd_track = NULL;
	osd_style = NULL;
	osd_event = NULL;
	osd_renderer = NULL;
}
	ExitCode Entry() {
		const char *config_path = NULL;
#ifdef __APPLE__
		std::string conf_path = agi::util::OSX_GetBundleResourcesDirectory() + "/etc/fonts/fonts.conf";
		config_path = conf_path.c_str();
#endif

		if (ass_library) ass_renderer = ass_renderer_init(ass_library);
		ass_set_fonts(ass_renderer, NULL, "Sans", 1, config_path, true);
		if (ass_library) ass_renderer_done(ass_renderer);
		*thisPtr = NULL;
		return EXIT_SUCCESS;
	}
Beispiel #12
0
static void enable_output(struct sd *sd, bool enable)
{
    struct sd_ass_priv *ctx = sd->priv;
    if (enable == !!ctx->ass_renderer)
        return;
    if (ctx->ass_renderer) {
        ass_renderer_done(ctx->ass_renderer);
        ctx->ass_renderer = NULL;
    } else {
        ctx->ass_renderer = ass_renderer_init(ctx->ass_library);

        mp_ass_configure_fonts(ctx->ass_renderer, sd->opts->sub_text_style,
                               sd->global, sd->log);
    }
}
void CacheFonts() {
	// Initialize the cache worker thread
	cache_queue = agi::dispatch::Create();

	// Initialize libass
	library = ass_library_init();
	ass_set_message_cb(library, msg_callback, nullptr);

	// Initialize a renderer to force fontconfig to update its cache
	cache_queue->Async([]{
		auto ass_renderer = ass_renderer_init(library);
		ass_set_fonts(ass_renderer, nullptr, "Sans", 1, CONFIG_PATH, true);
		ass_renderer_done(ass_renderer);
	});
}
Beispiel #14
0
void LibASS::closeASS()
{
	while (ass_sub_styles_copy.size())
	{
		ASS_Style *style = ass_sub_styles_copy.takeFirst();
		if (style->FontName)
			free(style->FontName);
		delete style;
	}
	if (ass_sub_renderer)
		ass_renderer_done(ass_sub_renderer);
	if (ass_sub_track)
		ass_free_track(ass_sub_track);
	ass_sub_track = NULL;
	ass_sub_renderer = NULL;
}
SubtitleProcessorLibASS::~SubtitleProcessorLibASS()
{
    if (!ass::api::loaded())
        return;
    if (m_track) {
        ass_free_track(m_track);
        m_track = 0;
    }
    if (m_renderer) {
        ass_renderer_done(m_renderer);
        m_renderer = 0;
    }
    if (m_ass) {
        ass_library_done(m_ass);
        m_ass = 0;
    }
}
Beispiel #16
0
static void AssHandleRelease( ass_handle_t *p_ass )
{
    vlc_mutex_lock( &libass_lock );
    p_ass->i_refcount--;
    if( p_ass->i_refcount > 0 )
    {
        vlc_mutex_unlock( &libass_lock );
        return;
    }

    ass_renderer_done( p_ass->p_renderer );
    ass_library_done( p_ass->p_library );

    vlc_value_t val;
    val.p_address = NULL;
    var_Set( p_ass->p_libvlc, "libass-handle", val );

    vlc_mutex_unlock( &libass_lock );
    free( p_ass );
}
Beispiel #17
0
static void DecSysRelease( decoder_sys_t *p_sys )
{
    /* */
    vlc_mutex_lock( &p_sys->lock );
    p_sys->i_refcount--;
    if( p_sys->i_refcount > 0 )
    {
        vlc_mutex_unlock( &p_sys->lock );
        return;
    }
    vlc_mutex_unlock( &p_sys->lock );
    vlc_mutex_destroy( &p_sys->lock );

    if( p_sys->p_track )
        ass_free_track( p_sys->p_track );
    if( p_sys->p_renderer )
        ass_renderer_done( p_sys->p_renderer );
    if( p_sys->p_library )
        ass_library_done( p_sys->p_library );

    free( p_sys );
}
Beispiel #18
0
void BigPotSubtitleAss::destroy()
{
	ass_renderer_done(_ren);
	ass_library_done(_lib);
}
Beispiel #19
0
int main(int argc, char *argv[])
{
	POINT mouse;
	//while (true)
	{
		GetCursorPos(&mouse);
		printf("\r%d-%d         ", mouse.x, mouse.y);
	}
	

	return interlace_RGB();
	return matrix();

//	char URI[] = "//mnt/sdcard/%E9%98%BF%E4%B8%BD%E4%BA%9A%E5%A8%9C%E5%90%89%E5%88%A9%E6%96%AF-%20Shake%E8%8B%B9%E6%9E%9C.3dv";
	char URI[] = "//mnt/sdcard/HELLO!.3dv";
	char decoded_URI[1024];

	URIDecode(URI, decoded_URI, sizeof(decoded_URI));

	char k = 0xef;

	bool a = k == 0xef;


    const int frame_w = 1920;
    const int frame_h = 1080;

	setlocale(LC_ALL, "CHS");

    if (argc < 4) {
        printf("usage: %s <image file> <subtitle file> <time>\n", argv[0]);
        exit(1);
    }

    char *imgfile = argv[1];
    char *subfile = argv[2];
    double tm = strtod(argv[3], 0);

	FILE * f = fopen(subfile, "rb");
	fseek(f, 0, SEEK_END);
	int file_size = ftell(f);
	fseek(f, 0, SEEK_SET);
	char *src = (char*)malloc(file_size);
	char *utf8 = (char*)malloc(file_size*3);
	fread(src, 1, file_size, f);
	fclose(f);

	int utf8_size = ConvertToUTF8(src, file_size, utf8, file_size*3);

	ass_library = ass_library_init();
	if (!ass_library) {
		printf("ass_library_init failed!\n");
		exit(1);
		}

	//ass_set_message_cb(ass_library, msg_callback, NULL);

	//ass_set_extract_fonts(ass_library, 0);
	//ass_set_style_overrides(ass_library, NULL);


	ass_renderer = ass_renderer_init(ass_library);
	if (!ass_renderer) {
		printf("ass_renderer_init failed!\n");
		exit(1);
		}


	ass_set_frame_size(ass_renderer, frame_w, frame_h);
	ass_set_font_scale(ass_renderer, 1.0);
	//ass_set_hinting(ass_renderer, ASS_HINTING_NORMAL);
	ass_set_fonts(ass_renderer, "Arial", "Sans", 1, "Z:\\fonts.conf", 1);
	
	ASS_Track *track = ass_read_memory(ass_library, utf8, utf8_size, NULL);

	free(src);
	free(utf8);

    if (!track) {
        printf("track init failed!\n");
        return 1;
    }

    ASS_Image *img = NULL;
	int n = 0;
	int changed = 0;
	image_t *frame = gen_image(frame_w, frame_h);
	int n2 = 0;
	int l = GetTickCount();
	timeBeginPeriod(1);
	for(int i=0; i<int(tm*1000); i+=40)
	{
		img = ass_render_frame(ass_renderer, track, i, &changed);

		if (n==0) l = GetTickCount();
		if (changed && img)
		{
			int l = timeGetTime();
			n++;
			memset(frame->buffer, 63, frame->stride * frame->height);
			blend(frame, img);
			wchar_t pathname[MAX_PATH];
			wsprintfW(pathname, L"Z:\\ass%02d.bmp", n);
			save_bitmap((DWORD*)frame->buffer, pathname, frame_w, frame_h);

			//printf("\rrender cost %dms.\t\t\n", timeGetTime()-l);
		}

		n2 ++;

		if (i%10000 == 0)
		printf("\r%d/%d ms rendered, %d frame output.", i, int(tm*1000), n);
	}

    ass_free_track(track);
    ass_renderer_done(ass_renderer);
    ass_library_done(ass_library);


    free(frame->buffer);
    free(frame);

    return 0;
}
Beispiel #20
0
void csri_close(csri_inst *inst)
{
	ass_free_track(inst->ass_track);
	ass_renderer_done(inst->ass_renderer);
	free(inst);
}
/// @brief Destructor
///
LibassSubtitlesProvider::~LibassSubtitlesProvider() {
	if (ass_track) ass_free_track(ass_track);
	if (ass_renderer) ass_renderer_done(ass_renderer);
}
Beispiel #22
0
static ass_handle_t *AssHandleHold( decoder_t *p_dec )
{
    vlc_mutex_lock( &libass_lock );

    ass_handle_t *p_ass = NULL;
    ASS_Library *p_library = NULL;
    ASS_Renderer *p_renderer = NULL;
    vlc_value_t val;

    var_Create( p_dec->p_libvlc, "libass-handle", VLC_VAR_ADDRESS );
    if( var_Get( p_dec->p_libvlc, "libass-handle", &val ) )
        val.p_address = NULL;

    if( val.p_address )
    {
        p_ass = val.p_address;

        p_ass->i_refcount++;

        vlc_mutex_unlock( &libass_lock );
        return p_ass;
    }

    /* */
    p_ass = malloc( sizeof(*p_ass) );
    if( !p_ass )
        goto error;

    /* */
    p_ass->p_libvlc = VLC_OBJECT(p_dec->p_libvlc);
    p_ass->i_refcount = 1;

    /* Create libass library */
    p_ass->p_library = p_library = ass_library_init();
    if( !p_library )
        goto error;

    /* load attachments */
    input_attachment_t  **pp_attachments;
    int                   i_attachments;

    if( decoder_GetInputAttachments( p_dec, &pp_attachments, &i_attachments ))
    {
        i_attachments = 0;
        pp_attachments = NULL;
    }
    for( int k = 0; k < i_attachments; k++ )
    {
        input_attachment_t *p_attach = pp_attachments[k];

        if( !strcasecmp( p_attach->psz_mime, "application/x-truetype-font" ) )
        {
            msg_Dbg( p_dec, "adding embedded font %s", p_attach->psz_name );

            ass_add_font( p_ass->p_library, p_attach->psz_name, p_attach->p_data, p_attach->i_data );
        }
        vlc_input_attachment_Delete( p_attach );
    }
    free( pp_attachments );

    ass_set_extract_fonts( p_library, true );
    ass_set_style_overrides( p_library, NULL );

    /* Create the renderer */
    p_ass->p_renderer = p_renderer = ass_renderer_init( p_library );
    if( !p_renderer )
        goto error;

    ass_set_use_margins( p_renderer, false);
    //if( false )
    //    ass_set_margins( p_renderer, int t, int b, int l, int r);
    ass_set_hinting( p_renderer, ASS_HINTING_LIGHT );
    ass_set_font_scale( p_renderer, 1.0 );
    ass_set_line_spacing( p_renderer, 0.0 );

    const char *psz_font = NULL; /* We don't ship a default font with VLC */
    const char *psz_family = "Arial"; /* Use Arial if we can't find anything more suitable */

#ifdef HAVE_FONTCONFIG
#if defined(WIN32)
    dialog_progress_bar_t *p_dialog = dialog_ProgressCreate( p_dec,
        _("Building font cache"),
        _( "Please wait while your font cache is rebuilt.\n"
        "This should take less than a minute." ), NULL );
    if( p_dialog )
        dialog_ProgressSet( p_dialog, NULL, 0.2 );
#endif
#if defined( LIBASS_VERSION ) && LIBASS_VERSION >= 0x00907000
    ass_set_fonts( p_renderer, psz_font, psz_family, true, NULL, 1 );  // setup default font/family
#else
    ass_set_fonts( p_renderer, psz_font, psz_family );  // setup default font/family
#endif
#ifdef WIN32
    if( p_dialog )
    {
        dialog_ProgressSet( p_dialog, NULL, 1.0 );
        dialog_ProgressDestroy( p_dialog );
        p_dialog = NULL;
    }
#endif
#else
    /* FIXME you HAVE to give him a font if no fontconfig */
#if defined( LIBASS_VERSION ) && LIBASS_VERSION >= 0x00907000
    ass_set_fonts( p_renderer, psz_font, psz_family, false, NULL, 1 );
#else
    ass_set_fonts_nofc( p_renderer, psz_font, psz_family );
#endif
#endif
    memset( &p_ass->fmt, 0, sizeof(p_ass->fmt) );

    /* */
    val.p_address = p_ass;
    var_Set( p_dec->p_libvlc, "libass-handle", val );

    /* */
    vlc_mutex_unlock( &libass_lock );
    return p_ass;

error:
    if( p_renderer )
        ass_renderer_done( p_renderer );
    if( p_library )
        ass_library_done( p_library );

    msg_Warn( p_dec, "Libass creation failed" );

    free( p_ass );
    vlc_mutex_unlock( &libass_lock );
    return NULL;
}
Beispiel #23
0
static void eosd_ass_uninit(struct mp_eosd_source *src)
{
	eosd_image_remove_all(src);
	ass_renderer_done(ass_renderer);
}