]> granicus.if.org Git - libass/commitdiff
Added profile program and corresponding configure options
author11rcombs <rodger.combs@gmail.com>
Tue, 31 Dec 2013 17:49:30 +0000 (11:49 -0600)
committer11rcombs <rodger.combs@gmail.com>
Sat, 25 Jan 2014 19:56:06 +0000 (13:56 -0600)
Makefile.am
configure.ac
profile/Makefile.am [new file with mode: 0644]
profile/profile.c [new file with mode: 0644]

index 5a17a083092c21f1794ec639b1e741d752161c17..4cd26e6235c3dc827f817974ddd9984fe5fc58c4 100644 (file)
@@ -9,5 +9,9 @@ if HAVE_LIBPNG
     test = test
 endif
 
-SUBDIRS = libass $(test)
+if ENABLE_PROFILE
+    profile = profile
+endif
+
+SUBDIRS = libass $(test) $(profile)
 
index a05cf8f3078099652a85be874c387b7db4ccd07e..11c1f7951701d6f0333a83c36071454a2e43e939 100644 (file)
@@ -36,6 +36,8 @@ AC_CHECK_LIB([m], [fabs])
 # Check for libraries via pkg-config
 AC_ARG_ENABLE([test], AS_HELP_STRING([--enable-test],
     [enable test program (requires libpng) @<:@default=no@:>@]))
+AC_ARG_ENABLE([profile], AS_HELP_STRING([--enable-profile],
+    [enable profiling program @<:@default=no@:>@]))
 AC_ARG_ENABLE([enca], AS_HELP_STRING([--disable-enca],
     [disable enca (charset autodetect) support @<:@default=check@:>@]))
 AC_ARG_ENABLE([fontconfig], AS_HELP_STRING([--disable-fontconfig],
@@ -92,6 +94,8 @@ fi
 
 AM_CONDITIONAL([HAVE_LIBPNG], [test x$libpng = xtrue])
 
+AM_CONDITIONAL([ENABLE_PROFILE], [test x$enable_profile = xyes])
+
 # add libraries/packages to pkg-config for static linking
 pkg_libs="-lm"
 pkg_requires="freetype2 >= 9.10.3"
@@ -114,5 +118,5 @@ AC_SUBST([PKG_REQUIRES_PRIVATE], [$(test x$enable_shared = xno || echo ${pkg_req
 # Setup output beautifier.
 m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])
 
-AC_CONFIG_FILES([Makefile libass/Makefile test/Makefile libass.pc])
+AC_CONFIG_FILES([Makefile libass/Makefile test/Makefile profile/Makefile libass.pc])
 AC_OUTPUT
diff --git a/profile/Makefile.am b/profile/Makefile.am
new file mode 100644 (file)
index 0000000..598c96b
--- /dev/null
@@ -0,0 +1,7 @@
+AM_CFLAGS = -Wall
+
+noinst_PROGRAMS = profile
+profile_SOURCES = profile.c
+profile_CPPFLAGS = -I../libass
+profile_LDADD = ../libass/.libs/libass.a
+profile_LDFLAGS = $(AM_LDFLAGS) -static
diff --git a/profile/profile.c b/profile/profile.c
new file mode 100644 (file)
index 0000000..749c331
--- /dev/null
@@ -0,0 +1,99 @@
+/*
+ * Copyright (C) 2006 Evgeniy Stepanov <eugeni.stepanov@gmail.com>
+ * Copyright (C) 2009 Grigori Goronzy <greg@geekmind.org>
+ * Copyright (C) 2013 Rodger Combs <rcombs@rcombs.me>
+ *
+ * This file is part of libass.
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdarg.h>
+#include <ass.h>
+
+typedef struct image_s {
+    int width, height, stride;
+    unsigned char *buffer;      // RGB24
+} image_t;
+
+ASS_Library *ass_library;
+ASS_Renderer *ass_renderer;
+
+void msg_callback(int level, const char *fmt, va_list va, void *data)
+{
+    if (level > 6)
+        return;
+    printf("libass: ");
+    vprintf(fmt, va);
+    printf("\n");
+}
+
+static void init(int frame_w, int frame_h)
+{
+    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_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_fonts(ass_renderer, NULL, "Sans", 1, NULL, 1);
+}
+
+int main(int argc, char *argv[])
+{
+    const int frame_w = 1280;
+    const int frame_h = 720;
+
+    if (argc < 5) {
+        printf("usage: %s <subtitle file> <start time> <fps> <time to render>\n", argv[0]);
+        exit(1);
+    }
+    char *subfile = argv[1];
+    double tm = strtod(argv[2], 0);
+    double fps = strtod(argv[3], 0);
+    double time = strtod(argv[4], 0);
+    
+    if(fps == 0){
+        printf("fps cannot equal 0\n");
+        exit(1);
+    }
+
+    init(frame_w, frame_h);
+    ASS_Track *track = ass_read_file(ass_library, subfile, NULL);
+    if (!track) {
+        printf("track init failed!\n");
+        exit(1);
+    }
+
+    while(tm < time){
+        ass_render_frame(ass_renderer, track, (int) (tm * 1000), NULL);
+        tm += 1 / fps;
+    }
+
+    ass_free_track(track);
+    ass_renderer_done(ass_renderer);
+    ass_library_done(ass_library);
+
+    return 0;
+}