History

sub/osd: fix rounding when rescaling bitmap subtitle rects

With multiple rects touching each other without any gaps, the current scale method can cause gaps or overlaps between rects. To make sure that this does not happen, scale on the edges of the rects instead, and then calculate the width and height from the results. NB: while this is better than the status quo, it does not fix all scaling artifacts because of the following: - When two rects share a vertical edge but have different heights, misalignment will occur: after rounding rect heights to pixels, the height scale factor for the two rects will be slightly different. As a result, there will be misalignment between the scaled images. - With a GPU renderer, different bitmap subtitle parts are rendered as different textures. This means that the pixel contents of the parts have different boundary conditions from the whole combined image. As a result, there will still be small gaps when the subtitle is scaled up. The only way to properly address these points is to make sure that the parts are combined to a single image at the native resolution before being scaled. This can be partly achieved with --blend-subtitles=video.

nanahi committed 2 years ago

Commit dec73f51 parent e20ca151 file · +10 −4Browse files

Unified · Split

sub/osd.c+10−4
@@ -515,10 +515,16 @@ void osd_rescale_bitmaps(struct sub_bitmaps *imgs, int frame_w, int frame_h, · 514 unmodified lines
515 int cy = vidh / 2 - (int)(frame_h * yscale) / 2;515 int cy = vidh / 2 - (int)(frame_h * yscale) / 2;
516 for (int i = 0; i < imgs->num_parts; i++) {516 for (int i = 0; i < imgs->num_parts; i++) {
517 struct sub_bitmap *bi = &imgs->parts[i];517 struct sub_bitmap *bi = &imgs->parts[i];
518 bi->x = (int)(bi->x * xscale) + cx + res.ml;518 struct mp_rect rc = {
519 bi->y = (int)(bi->y * yscale) + cy + res.mt;519 .x0 = lrint(bi->x * xscale),
520 bi->dw = (int)(bi->w * xscale + 0.5);520 .y0 = lrint(bi->y * yscale),
521 bi->dh = (int)(bi->h * yscale + 0.5);521 .x1 = lrint((bi->x + bi->w) * xscale),
522 .y1 = lrint((bi->y + bi->h) * yscale),
523 };
524 bi->x = rc.x0 + cx + res.ml;
525 bi->y = rc.y0 + cy + res.mt;
526 bi->dw = mp_rect_w(rc);
527 bi->dh = mp_rect_h(rc);
522 }528 }
523}529}
524 530

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t