2007-04-04 06:12:38 +02:00
|
|
|
// Copyright (c) 2006-2007, Rodrigo Braz Monteiro, Evgeniy Stepanov
|
|
|
|
// All rights reserved.
|
|
|
|
//
|
|
|
|
// Redistribution and use in source and binary forms, with or without
|
|
|
|
// modification, are permitted provided that the following conditions are met:
|
|
|
|
//
|
|
|
|
// * Redistributions of source code must retain the above copyright notice,
|
|
|
|
// this list of conditions and the following disclaimer.
|
|
|
|
// * Redistributions in binary form must reproduce the above copyright notice,
|
|
|
|
// this list of conditions and the following disclaimer in the documentation
|
|
|
|
// and/or other materials provided with the distribution.
|
|
|
|
// * Neither the name of the Aegisub Group nor the names of its contributors
|
|
|
|
// may be used to endorse or promote products derived from this software
|
|
|
|
// without specific prior written permission.
|
|
|
|
//
|
|
|
|
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
|
|
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
|
|
|
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
// POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
//
|
2009-07-29 07:43:02 +02:00
|
|
|
// Aegisub Project http://www.aegisub.org/
|
2007-04-04 06:12:38 +02:00
|
|
|
//
|
2009-07-29 07:43:02 +02:00
|
|
|
// $Id$
|
|
|
|
|
|
|
|
/// @file subtitles_provider_libass.cpp
|
|
|
|
/// @brief libass-based subtitle renderer
|
|
|
|
/// @ingroup subtitle_rendering
|
|
|
|
///
|
2007-04-04 06:12:38 +02:00
|
|
|
|
|
|
|
///////////
|
|
|
|
// Headers
|
2009-01-04 07:31:48 +01:00
|
|
|
#include "config.h"
|
|
|
|
|
2008-01-16 19:29:29 +01:00
|
|
|
|
2007-12-31 07:46:22 +01:00
|
|
|
#ifdef WITH_LIBASS
|
|
|
|
|
2008-03-05 04:24:01 +01:00
|
|
|
#include "subtitles_provider_libass.h"
|
2007-04-04 06:12:38 +02:00
|
|
|
#include "ass_file.h"
|
|
|
|
#include "video_context.h"
|
|
|
|
#include "utils.h"
|
2008-11-20 23:08:34 +01:00
|
|
|
#include "standard_paths.h"
|
|
|
|
#include <wx/filefn.h>
|
2007-04-04 06:12:38 +02:00
|
|
|
|
2009-07-12 22:10:25 +02:00
|
|
|
#ifdef __APPLE__
|
2009-07-14 00:32:11 +02:00
|
|
|
extern "C" {
|
2009-07-11 19:28:27 +02:00
|
|
|
#include "libosxutil/libosxutil.h"
|
|
|
|
#include <sys/param.h>
|
2009-07-14 00:32:11 +02:00
|
|
|
}
|
2009-07-14 00:38:43 +02:00
|
|
|
#endif
|
2007-04-04 06:12:38 +02:00
|
|
|
|
Note: This was done using a script! it's far from perfect but 95% of the work has been done already formatting-wise.
Document all functions, class, struct, union, enum, macro, variable, typedefs. This isn't the actual document in itself but empty documentation using any old documentation if it was there.
This was done using exuberant ctags to get tag info, then a TCL script to parse/remove old comments and convert them into Doxygen-style.
Some notes:
* Anything labeled 'DOCME' needs to be documented, @param and @return have been left blank as it would be annoying to delete the 'DOCME' from every one of those.
* Some multiline comments may have been munged into single line comments
* Leave the /// comments above global variables with a space, if they're harder to read then we'll be less likey to use them.
* Enum comments can go after the enumeration itself '[value] /// comment'
* include/aegisub/*.h haven't been converted yet, this will be done in a later commit
* Some documentation blocks are in the wrong place, in the .h when it should be in the .cpp, or vice versa.
See http://devel.aegisub.org/wiki/Doxygen for some details on Doxygen and a 'style guide'.
Originally committed to SVN as r3312.
2009-07-30 00:59:22 +02:00
|
|
|
|
|
|
|
/// @brief Constructor
|
|
|
|
///
|
2007-04-04 06:12:38 +02:00
|
|
|
LibassSubtitlesProvider::LibassSubtitlesProvider() {
|
|
|
|
// Initialize library
|
|
|
|
static bool first = true;
|
|
|
|
if (first) {
|
|
|
|
ass_library = ass_library_init();
|
|
|
|
if (!ass_library) throw _T("ass_library_init failed");
|
2008-11-20 23:08:34 +01:00
|
|
|
|
|
|
|
wxString fonts_dir = StandardPaths::DecodePath(_T("?user/libass_fonts/"));
|
|
|
|
if (!wxDirExists(fonts_dir))
|
|
|
|
// It's only one level below the user dir, and we assume the user dir already exists at this point.
|
|
|
|
wxMkdir(fonts_dir);
|
|
|
|
|
|
|
|
ass_set_fonts_dir(ass_library, fonts_dir.mb_str(wxConvFile));
|
2007-04-04 06:12:38 +02:00
|
|
|
ass_set_extract_fonts(ass_library, 0);
|
|
|
|
ass_set_style_overrides(ass_library, NULL);
|
|
|
|
first = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Initialize renderer
|
|
|
|
ass_track = NULL;
|
|
|
|
ass_renderer = ass_renderer_init(ass_library);
|
|
|
|
if (!ass_renderer) throw _T("ass_renderer_init failed");
|
|
|
|
ass_set_font_scale(ass_renderer, 1.);
|
2009-07-11 19:28:27 +02:00
|
|
|
|
2009-07-12 22:10:25 +02:00
|
|
|
#ifdef __APPLE__
|
2009-07-11 19:28:27 +02:00
|
|
|
char config_path[MAXPATHLEN];
|
|
|
|
char *config_dir;
|
|
|
|
|
|
|
|
config_dir = OSX_GetBundleResourcesDirectory();
|
|
|
|
snprintf(config_path, MAXPATHLEN, "%s/etc/fonts/fonts.conf", config_dir);
|
|
|
|
free(config_dir);
|
|
|
|
#else
|
2009-07-12 22:10:25 +02:00
|
|
|
const char *config_path = NULL;
|
2009-07-11 19:28:27 +02:00
|
|
|
#endif
|
|
|
|
|
2009-07-19 21:33:29 +02:00
|
|
|
ass_set_fonts(ass_renderer, NULL, "Sans", 1, config_path, 1);
|
2007-04-04 06:12:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
Note: This was done using a script! it's far from perfect but 95% of the work has been done already formatting-wise.
Document all functions, class, struct, union, enum, macro, variable, typedefs. This isn't the actual document in itself but empty documentation using any old documentation if it was there.
This was done using exuberant ctags to get tag info, then a TCL script to parse/remove old comments and convert them into Doxygen-style.
Some notes:
* Anything labeled 'DOCME' needs to be documented, @param and @return have been left blank as it would be annoying to delete the 'DOCME' from every one of those.
* Some multiline comments may have been munged into single line comments
* Leave the /// comments above global variables with a space, if they're harder to read then we'll be less likey to use them.
* Enum comments can go after the enumeration itself '[value] /// comment'
* include/aegisub/*.h haven't been converted yet, this will be done in a later commit
* Some documentation blocks are in the wrong place, in the .h when it should be in the .cpp, or vice versa.
See http://devel.aegisub.org/wiki/Doxygen for some details on Doxygen and a 'style guide'.
Originally committed to SVN as r3312.
2009-07-30 00:59:22 +02:00
|
|
|
|
|
|
|
/// @brief Destructor
|
|
|
|
///
|
2007-04-04 06:12:38 +02:00
|
|
|
LibassSubtitlesProvider::~LibassSubtitlesProvider() {
|
|
|
|
}
|
|
|
|
|
|
|
|
|
Note: This was done using a script! it's far from perfect but 95% of the work has been done already formatting-wise.
Document all functions, class, struct, union, enum, macro, variable, typedefs. This isn't the actual document in itself but empty documentation using any old documentation if it was there.
This was done using exuberant ctags to get tag info, then a TCL script to parse/remove old comments and convert them into Doxygen-style.
Some notes:
* Anything labeled 'DOCME' needs to be documented, @param and @return have been left blank as it would be annoying to delete the 'DOCME' from every one of those.
* Some multiline comments may have been munged into single line comments
* Leave the /// comments above global variables with a space, if they're harder to read then we'll be less likey to use them.
* Enum comments can go after the enumeration itself '[value] /// comment'
* include/aegisub/*.h haven't been converted yet, this will be done in a later commit
* Some documentation blocks are in the wrong place, in the .h when it should be in the .cpp, or vice versa.
See http://devel.aegisub.org/wiki/Doxygen for some details on Doxygen and a 'style guide'.
Originally committed to SVN as r3312.
2009-07-30 00:59:22 +02:00
|
|
|
|
|
|
|
/// @brief Load subtitles
|
|
|
|
/// @param subs
|
|
|
|
///
|
2007-04-04 06:12:38 +02:00
|
|
|
void LibassSubtitlesProvider::LoadSubtitles(AssFile *subs) {
|
|
|
|
// Prepare subtitles
|
|
|
|
std::vector<char> data;
|
|
|
|
subs->SaveMemory(data,_T("UTF-8"));
|
|
|
|
delete subs;
|
|
|
|
|
|
|
|
// Load file
|
|
|
|
if (ass_track) ass_free_track(ass_track);
|
2007-04-04 06:22:05 +02:00
|
|
|
ass_track = ass_read_memory(ass_library, &data[0], data.size(),"UTF-8");
|
2007-04-04 06:12:38 +02:00
|
|
|
if (!ass_track) throw _T("libass failed to load subtitles.");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
Note: This was done using a script! it's far from perfect but 95% of the work has been done already formatting-wise.
Document all functions, class, struct, union, enum, macro, variable, typedefs. This isn't the actual document in itself but empty documentation using any old documentation if it was there.
This was done using exuberant ctags to get tag info, then a TCL script to parse/remove old comments and convert them into Doxygen-style.
Some notes:
* Anything labeled 'DOCME' needs to be documented, @param and @return have been left blank as it would be annoying to delete the 'DOCME' from every one of those.
* Some multiline comments may have been munged into single line comments
* Leave the /// comments above global variables with a space, if they're harder to read then we'll be less likey to use them.
* Enum comments can go after the enumeration itself '[value] /// comment'
* include/aegisub/*.h haven't been converted yet, this will be done in a later commit
* Some documentation blocks are in the wrong place, in the .h when it should be in the .cpp, or vice versa.
See http://devel.aegisub.org/wiki/Doxygen for some details on Doxygen and a 'style guide'.
Originally committed to SVN as r3312.
2009-07-30 00:59:22 +02:00
|
|
|
|
|
|
|
/// DOCME
|
2007-04-04 06:12:38 +02:00
|
|
|
#define _r(c) ((c)>>24)
|
Note: This was done using a script! it's far from perfect but 95% of the work has been done already formatting-wise.
Document all functions, class, struct, union, enum, macro, variable, typedefs. This isn't the actual document in itself but empty documentation using any old documentation if it was there.
This was done using exuberant ctags to get tag info, then a TCL script to parse/remove old comments and convert them into Doxygen-style.
Some notes:
* Anything labeled 'DOCME' needs to be documented, @param and @return have been left blank as it would be annoying to delete the 'DOCME' from every one of those.
* Some multiline comments may have been munged into single line comments
* Leave the /// comments above global variables with a space, if they're harder to read then we'll be less likey to use them.
* Enum comments can go after the enumeration itself '[value] /// comment'
* include/aegisub/*.h haven't been converted yet, this will be done in a later commit
* Some documentation blocks are in the wrong place, in the .h when it should be in the .cpp, or vice versa.
See http://devel.aegisub.org/wiki/Doxygen for some details on Doxygen and a 'style guide'.
Originally committed to SVN as r3312.
2009-07-30 00:59:22 +02:00
|
|
|
|
|
|
|
/// DOCME
|
2007-04-04 06:12:38 +02:00
|
|
|
#define _g(c) (((c)>>16)&0xFF)
|
Note: This was done using a script! it's far from perfect but 95% of the work has been done already formatting-wise.
Document all functions, class, struct, union, enum, macro, variable, typedefs. This isn't the actual document in itself but empty documentation using any old documentation if it was there.
This was done using exuberant ctags to get tag info, then a TCL script to parse/remove old comments and convert them into Doxygen-style.
Some notes:
* Anything labeled 'DOCME' needs to be documented, @param and @return have been left blank as it would be annoying to delete the 'DOCME' from every one of those.
* Some multiline comments may have been munged into single line comments
* Leave the /// comments above global variables with a space, if they're harder to read then we'll be less likey to use them.
* Enum comments can go after the enumeration itself '[value] /// comment'
* include/aegisub/*.h haven't been converted yet, this will be done in a later commit
* Some documentation blocks are in the wrong place, in the .h when it should be in the .cpp, or vice versa.
See http://devel.aegisub.org/wiki/Doxygen for some details on Doxygen and a 'style guide'.
Originally committed to SVN as r3312.
2009-07-30 00:59:22 +02:00
|
|
|
|
|
|
|
/// DOCME
|
2007-04-04 06:12:38 +02:00
|
|
|
#define _b(c) (((c)>>8)&0xFF)
|
Note: This was done using a script! it's far from perfect but 95% of the work has been done already formatting-wise.
Document all functions, class, struct, union, enum, macro, variable, typedefs. This isn't the actual document in itself but empty documentation using any old documentation if it was there.
This was done using exuberant ctags to get tag info, then a TCL script to parse/remove old comments and convert them into Doxygen-style.
Some notes:
* Anything labeled 'DOCME' needs to be documented, @param and @return have been left blank as it would be annoying to delete the 'DOCME' from every one of those.
* Some multiline comments may have been munged into single line comments
* Leave the /// comments above global variables with a space, if they're harder to read then we'll be less likey to use them.
* Enum comments can go after the enumeration itself '[value] /// comment'
* include/aegisub/*.h haven't been converted yet, this will be done in a later commit
* Some documentation blocks are in the wrong place, in the .h when it should be in the .cpp, or vice versa.
See http://devel.aegisub.org/wiki/Doxygen for some details on Doxygen and a 'style guide'.
Originally committed to SVN as r3312.
2009-07-30 00:59:22 +02:00
|
|
|
|
|
|
|
/// DOCME
|
2007-04-04 06:12:38 +02:00
|
|
|
#define _a(c) ((c)&0xFF)
|
|
|
|
|
Note: This was done using a script! it's far from perfect but 95% of the work has been done already formatting-wise.
Document all functions, class, struct, union, enum, macro, variable, typedefs. This isn't the actual document in itself but empty documentation using any old documentation if it was there.
This was done using exuberant ctags to get tag info, then a TCL script to parse/remove old comments and convert them into Doxygen-style.
Some notes:
* Anything labeled 'DOCME' needs to be documented, @param and @return have been left blank as it would be annoying to delete the 'DOCME' from every one of those.
* Some multiline comments may have been munged into single line comments
* Leave the /// comments above global variables with a space, if they're harder to read then we'll be less likey to use them.
* Enum comments can go after the enumeration itself '[value] /// comment'
* include/aegisub/*.h haven't been converted yet, this will be done in a later commit
* Some documentation blocks are in the wrong place, in the .h when it should be in the .cpp, or vice versa.
See http://devel.aegisub.org/wiki/Doxygen for some details on Doxygen and a 'style guide'.
Originally committed to SVN as r3312.
2009-07-30 00:59:22 +02:00
|
|
|
|
|
|
|
/// @brief Draw subtitles
|
|
|
|
/// @param frame
|
|
|
|
/// @param time
|
|
|
|
/// @return
|
|
|
|
///
|
2007-04-04 06:12:38 +02:00
|
|
|
void LibassSubtitlesProvider::DrawSubtitles(AegiVideoFrame &frame,double time) {
|
|
|
|
// Set size
|
|
|
|
ass_set_frame_size(ass_renderer, frame.w, frame.h);
|
|
|
|
|
|
|
|
// Get frame
|
|
|
|
ass_image_t* img = ass_render_frame(ass_renderer, ass_track, int(time * 1000), NULL);
|
|
|
|
|
|
|
|
// libass actually returns several alpha-masked monochrome images.
|
|
|
|
// Here, we loop through their linked list, get the colour of the current, and blend into the frame.
|
|
|
|
// This is repeated for all of them.
|
|
|
|
while (img) {
|
|
|
|
// Get colours
|
|
|
|
unsigned int opacity = 255 - ((unsigned int)_a(img->color));
|
|
|
|
unsigned int r = (unsigned int)_r(img->color);
|
|
|
|
unsigned int g = (unsigned int)_g(img->color);
|
|
|
|
unsigned int b = (unsigned int) _b(img->color);
|
|
|
|
|
|
|
|
// Prepare copy
|
|
|
|
int src_stride = img->stride;
|
|
|
|
int dst_stride = frame.pitch[0];
|
|
|
|
int dst_delta = dst_stride - img->w*4;
|
|
|
|
//int stride = MIN(src_stride,dst_stride);
|
|
|
|
const unsigned char *src = img->bitmap;
|
|
|
|
unsigned char *dst = frame.data[0] + (img->dst_y * dst_stride + img->dst_x * 4);
|
|
|
|
unsigned int k,ck,t;
|
|
|
|
|
|
|
|
// Copy image to destination frame
|
|
|
|
for (int y=0;y<img->h;y++) {
|
|
|
|
//memcpy(dst,src,stride);
|
|
|
|
for (int x = 0; x < img->w; ++x) {
|
|
|
|
k = ((unsigned)src[x]) * opacity / 255;
|
|
|
|
ck = 255 - k;
|
|
|
|
t = *dst;
|
|
|
|
*dst++ = (k*b + ck*t) / 255;
|
|
|
|
t = *dst;
|
|
|
|
*dst++ = (k*g + ck*t) / 255;
|
|
|
|
t = *dst;
|
|
|
|
*dst++ = (k*r + ck*t) / 255;
|
|
|
|
dst++;
|
|
|
|
}
|
|
|
|
|
|
|
|
dst += dst_delta;
|
|
|
|
src += src_stride;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Next image
|
|
|
|
img = img->next;
|
|
|
|
}
|
|
|
|
}
|
2007-12-31 07:46:22 +01:00
|
|
|
|
2008-03-05 04:46:29 +01:00
|
|
|
|
Note: This was done using a script! it's far from perfect but 95% of the work has been done already formatting-wise.
Document all functions, class, struct, union, enum, macro, variable, typedefs. This isn't the actual document in itself but empty documentation using any old documentation if it was there.
This was done using exuberant ctags to get tag info, then a TCL script to parse/remove old comments and convert them into Doxygen-style.
Some notes:
* Anything labeled 'DOCME' needs to be documented, @param and @return have been left blank as it would be annoying to delete the 'DOCME' from every one of those.
* Some multiline comments may have been munged into single line comments
* Leave the /// comments above global variables with a space, if they're harder to read then we'll be less likey to use them.
* Enum comments can go after the enumeration itself '[value] /// comment'
* include/aegisub/*.h haven't been converted yet, this will be done in a later commit
* Some documentation blocks are in the wrong place, in the .h when it should be in the .cpp, or vice versa.
See http://devel.aegisub.org/wiki/Doxygen for some details on Doxygen and a 'style guide'.
Originally committed to SVN as r3312.
2009-07-30 00:59:22 +02:00
|
|
|
|
|
|
|
/// DOCME
|
2008-03-05 04:46:29 +01:00
|
|
|
ass_library_t* LibassSubtitlesProvider::ass_library;
|
|
|
|
|
|
|
|
|
2007-12-31 07:46:22 +01:00
|
|
|
#endif // WITH_LIBASS
|
2009-07-29 07:43:02 +02:00
|
|
|
|
Note: This was done using a script! it's far from perfect but 95% of the work has been done already formatting-wise.
Document all functions, class, struct, union, enum, macro, variable, typedefs. This isn't the actual document in itself but empty documentation using any old documentation if it was there.
This was done using exuberant ctags to get tag info, then a TCL script to parse/remove old comments and convert them into Doxygen-style.
Some notes:
* Anything labeled 'DOCME' needs to be documented, @param and @return have been left blank as it would be annoying to delete the 'DOCME' from every one of those.
* Some multiline comments may have been munged into single line comments
* Leave the /// comments above global variables with a space, if they're harder to read then we'll be less likey to use them.
* Enum comments can go after the enumeration itself '[value] /// comment'
* include/aegisub/*.h haven't been converted yet, this will be done in a later commit
* Some documentation blocks are in the wrong place, in the .h when it should be in the .cpp, or vice versa.
See http://devel.aegisub.org/wiki/Doxygen for some details on Doxygen and a 'style guide'.
Originally committed to SVN as r3312.
2009-07-30 00:59:22 +02:00
|
|
|
|