From 66988aaf7a2089d2ea4d5083f8a646b064140e86 Mon Sep 17 00:00:00 2001 From: RotemDoar Date: Tue, 11 Jun 2024 09:08:33 +0300 Subject: [PATCH] adding colorspace option to createOSD and setOSD set font color. adding extra validation to the font color parameters. adding documentation and example to the function parameters. --- .prettierignore | 1 + lib/media.js | 43 ++++++++++++++++++++++++++++++++----------- 2 files changed, 33 insertions(+), 11 deletions(-) create mode 100644 .prettierignore diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 0000000..fa29cdf --- /dev/null +++ b/.prettierignore @@ -0,0 +1 @@ +** \ No newline at end of file diff --git a/lib/media.js b/lib/media.js index 8835587..d836146 100644 --- a/lib/media.js +++ b/lib/media.js @@ -1255,8 +1255,26 @@ module.exports = function(Cam) { * @param {string} [options.dateFormat] Date to overlay. Must be used with timeFormat, otherwise plaintext will be used. * @param {string} [options.timeFormat] Time to overlay. Must be used with dateFormat, otherwise plaintext will be used. * @param {number} [options.fontSize] The text font size. + * @param {string} [options.colorspace] Colorspace - RGB or YCbCr. Default RGB. * @param {object} [options.fontColor] The color of the text font (OSDColor), should be object with properties - X, Y, Z. + * @param {float} [options.fontColor.X] For RGB - means R value, For YCbCr means Y value. + * @param {float} [options.fontColor.Y] For RGB - means G value, For YCbCr means Cb value. + * @param {float} [options.fontColor.Z] For RGB - means B value, For YCbCr means Cr value. * @param {Cam~GetOSDOptionsCallback} callback + * @example + * await cam.createOSD({ + * position: "LowerLeft", + * timeFormat: "HH:mm:ss", + * dateFormat: "YYYY-MM-DD", + * fontSize: 1, + * colorspace: "RGB", + * fontColor: { + * X: 1, + * Y: 0.7, + * Z: 0.9, + * } + * }); + * */ Cam.prototype.createOSD = function(options, callback) { if (callback === undefined) { callback = options; options = {}; } @@ -1282,10 +1300,11 @@ module.exports = function(Cam) { ${options.plaintext}`} ${options.fontSize ? `${options.fontSize}` : ""} - ${options.fontColor ? ` - - ${''} - ` : ""} + ${ options.fontColor && options.fontColor.X && options.fontColor.Y && options.fontColor.Z ? + ` + + ${ '' } + ` : "" } ` + @@ -1311,8 +1330,13 @@ module.exports = function(Cam) { * @param {string} [options.dateFormat] Date to overlay. Must be used with timeFormat, otherwise plaintext will be used. * @param {string} [options.timeFormat] Time to overlay. Must be used with dateFormat, otherwise plaintext will be used. * @param {number} [options.fontSize] The text font size. + * @param {string} [options.colorspace] Colorspace - RGB or YCbCr. Default RGB. * @param {object} [options.fontColor] The color of the text font (OSDColor), should be object with properties - X, Y, Z. + * @param {float} [options.fontColor.X] For RGB - means R value, For YCbCr means Y value. + * @param {float} [options.fontColor.Y] For RGB - means G value, For YCbCr means Cb value. + * @param {float} [options.fontColor.Z] For RGB - means B value, For YCbCr means Cr value. * @param {Cam~GetOSDOptionsCallback} callback + * @see {Cam~createOSD} */ Cam.prototype.setOSD = function(options, callback) { let mediaType = (this.media2Support ? 'media2' : 'media'); @@ -1342,14 +1366,11 @@ module.exports = function(Cam) { options.fontSize ? `${options.fontSize}` : '' } - ${ - options.fontColor ? +${ options.fontColor && options.fontColor.X && options.fontColor.Y && options.fontColor.Z ? ` - - ${''} - - ` : '' -} + + ${ '' } + ` : "" } ` +