Use boost.gil for overlaying images from libass
This commit is contained in:
parent
6bd6ed5e5b
commit
2113ed9580
2 changed files with 20 additions and 37 deletions
|
@ -80,7 +80,7 @@ endif
|
||||||
# SUBTITLES
|
# SUBTITLES
|
||||||
###########
|
###########
|
||||||
ifeq (yes, $(HAVE_LIBASS))
|
ifeq (yes, $(HAVE_LIBASS))
|
||||||
subtitles_provider_libass.o: CXXFLAGS += $(CFLAGS_LIBASS)
|
subtitles_provider_libass.o: CXXFLAGS += $(CFLAGS_LIBASS) -Wno-c++11-narrowing
|
||||||
subtitles_provider.o: CXXFLAGS += $(CFLAGS_LIBASS)
|
subtitles_provider.o: CXXFLAGS += $(CFLAGS_LIBASS)
|
||||||
LIBS += $(LIBS_LIBASS)
|
LIBS += $(LIBS_LIBASS)
|
||||||
SRC += subtitles_provider_libass.cpp
|
SRC += subtitles_provider_libass.cpp
|
||||||
|
|
|
@ -137,49 +137,32 @@ void LibassSubtitlesProvider::DrawSubtitles(AegiVideoFrame &frame,double time) {
|
||||||
// libass actually returns several alpha-masked monochrome images.
|
// 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.
|
// 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.
|
// This is repeated for all of them.
|
||||||
while (img) {
|
|
||||||
|
using namespace boost::gil;
|
||||||
|
auto dst = interleaved_view(frame.w, frame.h, (bgra8_pixel_t*)frame.data, frame.pitch);
|
||||||
|
if (frame.flipped)
|
||||||
|
dst = flipped_up_down_view(dst);
|
||||||
|
|
||||||
|
for (; img; img = img->next) {
|
||||||
unsigned int opacity = 255 - ((unsigned int)_a(img->color));
|
unsigned int opacity = 255 - ((unsigned int)_a(img->color));
|
||||||
unsigned int r = (unsigned int)_r(img->color);
|
unsigned int r = (unsigned int)_r(img->color);
|
||||||
unsigned int g = (unsigned int)_g(img->color);
|
unsigned int g = (unsigned int)_g(img->color);
|
||||||
unsigned int b = (unsigned int)_b(img->color);
|
unsigned int b = (unsigned int)_b(img->color);
|
||||||
|
|
||||||
// Prepare copy
|
auto srcview = interleaved_view(img->w, img->h, (gray8_pixel_t*)img->bitmap, img->stride);
|
||||||
int src_stride = img->stride;
|
auto dstview = subimage_view(dst, img->dst_x, img->dst_y, img->w, img->h);
|
||||||
int dst_stride = frame.pitch;
|
|
||||||
const unsigned char *src = img->bitmap;
|
|
||||||
|
|
||||||
unsigned char *dst = frame.data;
|
transform_pixels(dstview, srcview, dstview, [=](const bgra8_pixel_t frame, const gray8_pixel_t src) -> bgra8_pixel_t {
|
||||||
if (frame.flipped) {
|
unsigned int k = ((unsigned)src) * opacity / 255;
|
||||||
dst += dst_stride * (frame.h - 1);
|
unsigned int ck = 255 - k;
|
||||||
dst_stride *= -1;
|
|
||||||
}
|
|
||||||
dst += (img->dst_y * dst_stride + img->dst_x * 4);
|
|
||||||
|
|
||||||
// Copy image to destination frame
|
bgra8_pixel_t ret;
|
||||||
for (int y = 0; y < img->h; y++) {
|
ret[0] = (k * b + ck * frame[0]) / 255;
|
||||||
unsigned char *dstp = dst;
|
ret[1] = (k * g + ck * frame[1]) / 255;
|
||||||
|
ret[2] = (k * r + ck * frame[2]) / 255;
|
||||||
for (int x = 0; x < img->w; ++x) {
|
ret[3] = 0;
|
||||||
unsigned int k = ((unsigned)src[x]) * opacity / 255;
|
return ret;
|
||||||
unsigned int ck = 255 - k;
|
});
|
||||||
|
|
||||||
*dstp = (k * b + ck * *dstp) / 255;
|
|
||||||
++dstp;
|
|
||||||
|
|
||||||
*dstp = (k * g + ck * *dstp) / 255;
|
|
||||||
++dstp;
|
|
||||||
|
|
||||||
*dstp = (k * r + ck * *dstp) / 255;
|
|
||||||
++dstp;
|
|
||||||
|
|
||||||
++dstp;
|
|
||||||
}
|
|
||||||
|
|
||||||
dst += dst_stride;
|
|
||||||
src += src_stride;
|
|
||||||
}
|
|
||||||
|
|
||||||
img = img->next;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue