Using the composition coordinates to render the subtitle on the canvas instead of the window position. This matches the FFmpeg implementation.

This commit is contained in:
David Schulte
2024-10-30 23:14:32 +01:00
parent d6926937fd
commit 776861be19
3 changed files with 16 additions and 3 deletions
+2 -1
View File
@@ -188,7 +188,8 @@ export class Pgs {
// Builds the subtitle.
const pixelData = this.getPixelDataFromComposition(compositionObject, palette, ctxObjects);
if (pixelData) {
compositionData.push(new SubtitleCompositionData(window, pixelData));
compositionData.push(new SubtitleCompositionData(
compositionObject.horizontalPosition, compositionObject.verticalPosition, window, pixelData));
}
}
+1 -1
View File
@@ -63,7 +63,7 @@ export class Renderer {
* @param dirtyArea If given, it will extend the dirty rect to include the affected subtitle area.
*/
private drawSubtitleCompositionData(compositionData: SubtitleCompositionData, dirtyArea?: Rect): void {
this.context?.putImageData(compositionData.pixelData, compositionData.window.horizontalPosition, compositionData.window.verticalPosition);
this.context?.putImageData(compositionData.pixelData, compositionData.x, compositionData.y);
// Mark this area as dirty.
dirtyArea?.union(compositionData.window.horizontalPosition, compositionData.window.verticalPosition,
+13 -1
View File
@@ -30,6 +30,16 @@ export class SubtitleData {
* This class contains the compiled subtitle data for a single composition.
*/
export class SubtitleCompositionData {
/**
* The x position of the image in pixels from the left edge of the canvas.
*/
public readonly x: number;
/**
* The y position of the image in pixels from the top edge of the canvas.
*/
public readonly y: number;
/**
* The pgs window to draw on (the on-screen position).
*/
@@ -40,7 +50,9 @@ export class SubtitleCompositionData {
*/
public readonly pixelData: ImageData;
public constructor(window: WindowDefinition, pixelData: ImageData) {
public constructor(x: number, y: number, window: WindowDefinition, pixelData: ImageData) {
this.x = x;
this.y = y;
this.window = window;
this.pixelData = pixelData;
}