Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proposal: Horizontal and vertical flipping of the output ... #25

Open
Martin-Luckow opened this issue Aug 1, 2019 · 3 comments
Open
Assignees

Comments

@Martin-Luckow
Copy link

Most FrontCams provide a horizontally mirrored image. Since I want to record this picture, I have to mirror the mirroring :)

The most efficient way is in CanvasCamera.js.

My proposal:
Expand the options by Booleans flipH and flipV.
Replace CanvasCamera.Renderer.prototype.draw with:

        ```
CanvasCamera.Renderer.prototype.draw = function (frame) {
            this.canvasCamera.dispatch ('beforeframerendering', this, frame);
            if (frame) {
                if (this.canvasCamera.options.flipH === true || this.canvasCamera.options.flipV === true) {
                    var scaleH = this.canvasCamera.options.flipH? -1: 1; // Set horizontal scale to -1 if flip horizontal
                    var scaleV = this.canvasCamera.options.flipV? -1: 1; // Set verical scale to -1 if flip vertical
                    var posX = this.canvasCamera.options.flipH? frame.dWidth * -1: 0; // set x position to -100% if flip horizontal
                    var posY = this.canvasCamera.options.flipV? frame.dHeight * -1: 0; // Set y position to -100% if flip vertical
                    this.context.save (); // save the current state
                    this.context.scale (scaleH, scaleV); // Set scale to flip the image
                    this.context.drawImage (frame.image, frame.sx, frame.sy, frame.sWidth, frame.sHeight, posX, posY, frame.dWidth, frame.dHeight); // draw the image
                    this.context.restore (); // Restore the last saved state
                }
                else {
                    this.context.drawImage (frame.image, frame.sx, frame.sy, frame.sWidth, frame.sHeight, frame.dx, frame.dy, frame.dWidth, frame.dHeight);
                }
            }
            this.canvasCamera.dispatch ('afterframerendering', this, frame);
            return this;
        };

@Sami-Radi Sami-Radi self-assigned this Aug 28, 2019
@Sami-Radi
Copy link
Collaborator

Hello,

I'll implement this in my next release.

Best Regards.

@Martin-Luckow
Copy link
Author

Should I send you my working version?

Best regards

Martin

@Sami-Radi
Copy link
Collaborator

Sami-Radi commented Oct 8, 2019

Hello,

There are (not yet) documented listeners in the plugin :

  • beforeFrameRendering
window.plugin.CanvasCamera.beforeFrameRendering(function(event,frame)){
  this; // is the renderer
} 
  • afterFrameRendering
window.plugin.CanvasCamera.afterFrameRendering(function(event, frame)){
  this; // is the renderer
} 
  • beforeFrameInitialization
window.plugin.CanvasCamera.beforeFrameInitialization(function(event)){
  this; // is the frame
} 
  • afterFrameInitialization
window.plugin.CanvasCamera.afterFrameInitialization(function(event)){
  this; // is the frame
} 
  • beforeRenderingPresets
window.plugin.CanvasCamera.beforeFrameRendering(function(event)){
  this; // is the canvascamera plugin
} 
  • afterRenderingPresets
window.plugin.CanvasCamera.afterRenderingPresets(function(event)){
  this; // is the canvascamera plugin
} 

You can implement the vertical and/or horizontal flipping using these without changing anything to the plugin core logic. I've updated the CanvasCamera demo with a flip action (see here).

Best Regards

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants