Skip to content

Commit

Permalink
skip blanks lines when rendering to text
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthew Szatmary committed Sep 20, 2017
1 parent c08ffcc commit cb1d0d8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
1 change: 1 addition & 0 deletions examples/ts2srt.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ int main(int argc, char** argv)

FILE* file = fopen(path, "rb+");

// This fread 188 bytes at a time is VERY slow. Need to rewrite that
while (TS_PACKET_SIZE == fread(&pkt[0], 1, TS_PACKET_SIZE, file)) {
switch (ts_parse_packet(&ts, &pkt[0])) {
case LIBCAPTION_OK:
Expand Down
17 changes: 8 additions & 9 deletions src/caption.c
Original file line number Diff line number Diff line change
Expand Up @@ -398,27 +398,26 @@ int caption_frame_from_text(caption_frame_t* frame, const utf8_char_t* data)
////////////////////////////////////////////////////////////////////////////////
size_t caption_frame_to_text(caption_frame_t* frame, utf8_char_t* data)
{
int r, c, uln, a, b = 0;
int r, c, uln, crlf = 0, count = 0;
size_t s, size = 0;
eia608_style_t sty;

data[0] = 0;

for (r = 0; r < SCREEN_ROWS; ++r) {
a = b, b = 0;
crlf += count, count = 0;
for (c = 0; c < SCREEN_COLS; ++c) {
const utf8_char_t* chr = caption_frame_read_char(frame, r, c, &sty, &uln);

if (0 < utf8_char_length(chr) && (0 < b || !utf8_char_whitespace(chr))) {
if (0 < a) {
// insert a new line if necessary
utf8_char_copy(data + 0, "\r");
utf8_char_copy(data + 1, "\n");
data += 2, size += 2, a = 0;
// dont start a new line until we encounter at least one printable character
if (0 < utf8_char_length(chr) && (0 < count || !utf8_char_whitespace(chr))) {
if (0 < crlf) {
memcpy(data, "\r\n", 2);
data += 2, size += 2, crlf = 0;
}

s = utf8_char_copy(data, chr);
data += s, size += s, ++b;
data += s, size += s, ++count;
}
}
}
Expand Down

0 comments on commit cb1d0d8

Please sign in to comment.