Browse Source

Update Session._renderMedia()

customisations
alemart 10 months ago
parent
commit
6248041831
1 changed files with 9 additions and 6 deletions
  1. 9
    6
      src/core/session.ts

+ 9
- 6
src/core/session.ts View File

541
         // render user media
541
         // render user media
542
         if(this._primarySource !== null) {
542
         if(this._primarySource !== null) {
543
             const media = this._primarySource._internalMedia;
543
             const media = this._primarySource._internalMedia;
544
-            this._renderMedia(ctx, media);
544
+            this._renderMedia(ctx, media, true);
545
         }
545
         }
546
 
546
 
547
-        // render output image(s)
547
+        // render output image(s) for debugging
548
         for(let i = 0; i < this._trackers.length; i++) {
548
         for(let i = 0; i < this._trackers.length; i++) {
549
             const media = this._trackers[i]._output.image;
549
             const media = this._trackers[i]._output.image;
550
             if(media !== undefined)
550
             if(media !== undefined)
551
-                this._renderMedia(ctx, media);
551
+                this._renderMedia(ctx, media, false);
552
         }
552
         }
553
 
553
 
554
         // render gizmos
554
         // render gizmos
559
      * Render a SpeedyMedia
559
      * Render a SpeedyMedia
560
      * @param ctx rendering context
560
      * @param ctx rendering context
561
      * @param media
561
      * @param media
562
+     * @param stretch
562
      */
563
      */
563
-    private _renderMedia(ctx: CanvasRenderingContext2D, media: SpeedyMedia): void
564
+    private _renderMedia(ctx: CanvasRenderingContext2D, media: SpeedyMedia, stretch: boolean): void
564
     {
565
     {
565
         const canvas = ctx.canvas;
566
         const canvas = ctx.canvas;
567
+        const width = stretch ? canvas.width : media.width;
568
+        const height = stretch ? canvas.height : media.height;
566
 
569
 
567
         if(media.type != 'data') {
570
         if(media.type != 'data') {
568
             const image = media.source as Exclude<SpeedyMediaSourceNativeElement, ImageData>;
571
             const image = media.source as Exclude<SpeedyMediaSourceNativeElement, ImageData>;
569
-            ctx.drawImage(image, 0, 0, canvas.width, canvas.height);
572
+            ctx.drawImage(image, 0, 0, width, height);
570
         }
573
         }
571
         else {
574
         else {
572
             const image = media.source as ImageData;
575
             const image = media.source as ImageData;
573
-            ctx.putImageData(image, 0, 0, 0, 0, canvas.width, canvas.height);
576
+            ctx.putImageData(image, 0, 0, 0, 0, width, height);
574
         }
577
         }
575
     }
578
     }
576
 
579
 

Loading…
Cancel
Save