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

Ability to set font size and color in setOSD and createOSD methods. #326

Merged
merged 6 commits into from
Jun 14, 2024

Conversation

RotemDoar
Copy link
Contributor

I implemented the capability to adjust font size and color within both the 'setOSD' and 'createOSD' methods.

While working, I recognized the necessity to customize font attributes like size and color in the screen display.

Upon reviewing the Onvif MediaBinding spec (both media and media2 versions) -
https://www.onvif.org/ver10/media/wsdl/media.wsdl
https://www.onvif.org/ver20/media/wsdl/media.wsdl
I found that in the setOSD and createOSD function it is possible to set the font color and size.

To adding the ability, I introduced new parameters to the method options for setting font size and color in the 'setOSD' and 'createOSD' functions defined in media.js file:

* @param {number} [options.fontSize] The text font size.
* @param {object} [options.fontColor] The color of the text font (OSDColor), should be object with properties - X, Y, Z.

And in the request body as part of the TextString I added :

${
	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>`
        : ''
}

Example of request options while I run the changes for one of my cameras -

{
          videoSourceConfigurationToken: "VideoSourceConfigToken-01-0",
          OSDToken: "OSDDateTimeToken-0",
          position: "LowerLeft",
          timeFormat: "HH:mm:ss",
          dateFormat: "YYYY-MM-DD",
          fontSize: 1,
          fontColor: {
            X: 82,
            Y: 90,
            Z: 240,
          }
} 

As a result the font color configuration (X,Y,Z) changed the OSD color to red with minimum size of the font .

Moreover, I enhanced the 'create OSD' method to include the functionality of setting custom position, date, and time, aligning with the capabilities offered in the 'set OSD' method.

lib/media.js Outdated
${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 + '"/>'}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe add Colorspace="http://www.onvif.org/ver10/colorspace/RGB" here? Or add optional param to choose between YCbCr and RGB?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added new options parameter - colorspace.
Supporting YCbCr and RGB.

lib/media.js Outdated
* @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 {object} [options.fontColor] The color of the text font (OSDColor), should be object with properties - X, Y, Z.
* @param {Cam~GetOSDOptionsCallback} callback
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can add your example here:

* @example
* await cam.createOSD({
*           videoSourceConfigurationToken: "VideoSourceConfigToken-01-0",
*           OSDToken: "OSDDateTimeToken-0",
*           position: "LowerLeft",
*           timeFormat: "HH:mm:ss",
*           dateFormat: "YYYY-MM-DD",
*           fontSize: 1,
*           fontColor: {
*             X: 82,
*             Y: 90,
*             Z: 240,
*           }
* });

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added example to create osd.

@@ -1293,6 +1310,8 @@ module.exports = function(Cam) {
* @param {string} [options.plaintext] Plain text to overlay
* @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 {object} [options.fontColor] The color of the text font (OSDColor), should be object with properties - X, Y, Z.
* @param {Cam~GetOSDOptionsCallback} callback
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And here link to createOSD method:

* @see {Cam~createOSD}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added the link to create osd method.

adding extra validation to the font color parameters.
adding documentation and example to the function parameters.
@RotemDoar
Copy link
Contributor Author

@agsh

I have added an optional parameter - 'colorspace', allowing support for both YCbCr and RGB. The default setting is RGB.
(see line 1259 in createOSD and line 1334 in setOSD).

* @param {string} [options.colorspace] Colorspace - RGB or YCbCr. Default RGB.

and fix the request for the support (with extra validation to the parameters X,Y,Z) -
(line 1304 and 1369)

${ 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>` : "" }

I added extra documentation to the font color parameter.

* @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.

I added example to the parameters for createOSD method.

* 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,
   *           }
   * });

I added the link to create osd method in the setOSD method.

* @see {Cam~createOSD}

@agsh agsh merged commit 9d010b9 into agsh:master Jun 14, 2024
3 checks passed
@agsh
Copy link
Owner

agsh commented Jun 14, 2024

@RotemDoar Great, thanks! Nice and detailed comments 😸

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

Successfully merging this pull request may close these issues.

2 participants