Skip to content

Commit

Permalink
adding colorspace option to createOSD and setOSD set font color.
Browse files Browse the repository at this point in the history
adding extra validation to the font color parameters.
adding documentation and example to the function parameters.
  • Loading branch information
RotemDoar committed Jun 11, 2024
1 parent 4ecc50f commit 66988aa
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 11 deletions.
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
**
43 changes: 32 additions & 11 deletions lib/media.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}; }
Expand All @@ -1282,10 +1300,11 @@ module.exports = function(Cam) {
<sch:PlainText>${options.plaintext}</sch:PlainText>`}
${options.fontSize ? `<sch:FontSize>${options.fontSize}</sch:FontSize>` : ""}
${options.fontColor ? `
<sch:FontColor>
${'<sch:Color Z="' + options.fontColor.Z + '" Y="' + options.fontColor.Y + '" X="' + options.fontColor.X + '"/>'}
</sch:FontColor>` : ""}
${ options.fontColor && options.fontColor.X && options.fontColor.Y && options.fontColor.Z ?
`
<sch:FontColor>
${ '<sch:Color Z="' + options.fontColor.Z + '" Y="' + options.fontColor.Y + '" X="' + options.fontColor.X + '" Colorspace="' + `${ options.colorspace === "YCbCr" ? "http://www.onvif.org/ver10/colorspace/YCbCr" : "http://www.onvif.org/ver10/colorspace/RGB" }` + '"/>' }
</sch:FontColor>` : "" }
</sch:TextString>
</wsdl:OSD>
</wsdl:CreateOSD>` +
Expand All @@ -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');
Expand Down Expand Up @@ -1342,14 +1366,11 @@ module.exports = function(Cam) {
options.fontSize ?
`<sch:FontSize>${options.fontSize}</sch:FontSize>` : ''
}
${
options.fontColor ?
${ options.fontColor && options.fontColor.X && options.fontColor.Y && options.fontColor.Z ?
`
<sch:FontColor>
${'<sch:Color Z="' + options.fontColor.Z + '" Y="' + options.fontColor.Y + '" X="' + options.fontColor.X + '"/>'}
</sch:FontColor>
` : ''
}
<sch:FontColor>
${ '<sch:Color Z="' + options.fontColor.Z + '" Y="' + options.fontColor.Y + '" X="' + options.fontColor.X + '" Colorspace="' + `${ options.colorspace === "YCbCr" ? "http://www.onvif.org/ver10/colorspace/YCbCr" : "http://www.onvif.org/ver10/colorspace/RGB" }` + '"/>' }
</sch:FontColor>` : "" }
</sch:TextString>
</wsdl:OSD>
</wsdl:SetOSD>` +
Expand Down

0 comments on commit 66988aa

Please sign in to comment.