Skip to content

Commit

Permalink
#28 : Start of support for burn in subtitles
Browse files Browse the repository at this point in the history
  • Loading branch information
fstark committed Feb 13, 2022
1 parent b10f0b0 commit be05922
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 3 deletions.
4 changes: 4 additions & 0 deletions src/flimcompressor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,10 @@ class flimcompressor

round_corners( dest );
::watermark( dest, watermark );

// ::burn_subtitle( dest, "HELLO WORLD" );


// DEBUG frame count
// {
// char buffer[1024];
Expand Down
1 change: 1 addition & 0 deletions src/image.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ void write_image( const char *file, const image &img );
#include <string>

void watermark( image &img, const std::string &s );
void burn_subtitle( image &img, const std::string &sub );

void copy( image &destination, const image &source, bool black_bars=true );

Expand Down
27 changes: 24 additions & 3 deletions src/watermark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,15 +141,20 @@ uint8_t sFont[128][8] = {
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} // U+007F
};

// Draws a single 8x9 character
static void putc( image &img, char c, size_t posx, size_t posy )
{
c &= 0x7f;

// A black line (only on the top, as the font have a bottom black line)
for (int x=0;x!=8;x++)
img.at( 8+posx*8+x, posy*8+3 ) = 0;
img.at( posx+x, posy ) = 0;

posy++;
// The 8 lines
for (int y=0;y!=8;y++)
for (int x=0;x!=8;x++)
img.at(8+posx*8+x,y+posy*8+4) = (sFont[c][y] & (1<<(x))) ? 1 : 0;
img.at(posx+x,y+posy) = (sFont[c][y] & (1<<(x))) ? 1 : 0;
}

void watermark( image &img, const std::string &s )
Expand All @@ -160,7 +165,7 @@ void watermark( image &img, const std::string &s )
{
if (c>=32)
{
putc( img, c, x, y );
putc( img, c, 8+x*8, y*8+3 );
x++;
if (x==62)
{
Expand All @@ -176,3 +181,19 @@ void watermark( image &img, const std::string &s )
}
}
}

using namespace std::string_literals;

void burn_subtitle( image &img, const std::string &sub )
{
size_t char_width = img.W()/8;
auto s = " "s + sub + " "s;
s = s.substr(0, char_width );

size_t l = s.size();
size_t x = (char_width-l)/2;
size_t y = img.H()-9-3;

for (auto c:s)
putc( img, c, x++*8, y );
}

0 comments on commit be05922

Please sign in to comment.