Skip to content

Commit

Permalink
Using the composition coordinates to render the subtitle on the canva…
Browse files Browse the repository at this point in the history
…s instead of the window position. This matches the FFmpeg implementation.
  • Loading branch information
Arcus92 committed Oct 30, 2024
1 parent d692693 commit eb5c42d
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/pgs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
14 changes: 13 additions & 1 deletion src/subtitleData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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).
*/
Expand All @@ -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;
}
Expand Down

0 comments on commit eb5c42d

Please sign in to comment.