Video frame border drawing method and device
By splitting the video frame border into multiple border lines and drawing them using fixed memory, the problems of low efficiency and poor stability in video frame border drawing are solved, achieving more efficient border drawing and improved system performance.
Patent Information
- Application Number
- CN202511351743.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-09-19
- Publication Date
- 2025-12-19
AI Technical Summary
Existing video frame border drawing technologies suffer from low efficiency and poor stability, especially in scenarios where the border position, size, and line width need to be dynamically adjusted, leading to a decline in system performance and stability.
The video frame border is split into multiple border lines (first horizontal line, second horizontal line, first vertical line and second vertical line), memory is allocated only to these lines, and drawing is performed using fixed memory, reducing memory allocation and deallocation operations, and improving drawing efficiency and system performance.
By reducing memory fragmentation, the efficiency of video frame border drawing is improved, thereby enhancing system performance and stability and avoiding resource waste and system instability caused by frequent memory operations.
Smart Images

Figure CN121170072A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of video processing technology, and in particular to a method and apparatus for drawing video frame borders. Background Technology
[0002] Video frame border rendering technology is applied in video output (VO) scenarios involving dynamic border rendering, such as real-time target selection in video surveillance systems, lesion area annotation in medical imaging equipment, touch feedback prompts in intelligent interactive display terminals, and defect area marking in industrial visual inspection. This technology enhances the visualization of key information by overlaying borders onto video frames or image data. Especially in scenarios requiring dynamic adjustment of border position, size, and line width (such as obstacle tracking in autonomous driving and real-time annotation in live streaming platforms), video frame border rendering technology becomes a crucial module supporting core functions, and its performance directly impacts the system's real-time performance and interactive experience.
[0003] To implement the border drawing function, a direct configuration scheme based on hardware registers can be used. By setting the parameters of the dedicated registers of the drawing module, the position and size of the border can be directly defined, and the border can be generated by hardware. Alternatively, a software scheme based on border generation can be used. This involves allocating memory for the entire image area and generating the border by modifying the edge area pixel by pixel. Another approach is to use a line splicing method, which splits the border into four independent line segments. Each line segment is treated as a small rectangle, allocated memory separately, and drawn. Finally, the complete border is formed by splicing them together.
[0004] However, among the above solutions, the hardware register-based approach is limited by chip architecture compatibility and cannot be universally deployed; the full-image memory allocation method wastes video memory resources because it requires allocating memory for the entire image; and the frequent memory allocation and deallocation operations of the line splicing method easily lead to memory fragmentation, resulting in decreased system stability after long-term operation. The inability to balance real-time performance and resource utilization leads to low efficiency in drawing video frame borders, reducing system performance and stability. Summary of the Invention
[0005] To address the aforementioned issues, this application provides a method and apparatus for drawing video frame borders, which can resolve the technical problems of low efficiency and poor stability in drawing borders for video frames.
[0006] To achieve the above objectives, in a first aspect, this application provides a method for drawing video frame borders, comprising: sequentially performing drawing operations on multiple border lines in a video frame, the border lines including a first horizontal line, a second horizontal line, a first vertical line, and a second vertical line; the drawing operations including: obtaining the coordinates and dimensions of the border lines; configuring drawing register parameters according to the coordinates and dimensions of the border lines, and the storage start address of the corresponding horizontal line memory or vertical line memory; the horizontal line memory being used to store bits representing horizontal line pixels, and the vertical line memory being used to store bits representing vertical line pixels; drawing the border lines based on the drawing register parameters; and merging the border lines with the video frame to generate a video frame border.
[0007] In the above method, memory is allocated only for the first horizontal line, the second horizontal line, the first vertical line, and the second vertical line used to form the video frame border. The video frame border can be drawn according to the coordinates and size of the border lines and the starting address of the memory storage, which reduces the memory consumption when drawing the video frame border, improves the efficiency of drawing the video frame border, and thus improves the performance and stability of the system.
[0008] In one possible implementation of the first aspect, the video frame border drawing method further includes: setting the value of all bits in the horizontal line memory to 1, and setting the value of the first target number of bits in each row of the vertical line memory to 1, wherein setting the value of the bits to 1 indicates that the pixels of the horizontal or vertical line need to be drawn.
[0009] In the above method, by setting the value of a bit to 1 in a pre-allocated fixed amount of memory, the video frame border to be drawn can be determined. This avoids multiple memory allocations and releases, and only a fixed portion of memory needs to be processed, reducing memory fragmentation and improving the efficiency of video frame border drawing and system performance.
[0010] In one possible implementation of the first aspect, before configuring the drawing register parameters according to the coordinates and size of the border lines and the storage start address of the corresponding horizontal or vertical line memory, the video frame border drawing method further includes: if the width of the first or second horizontal line is not a multiple of 8, setting the value of the (N+1)th to the Mth bits of each row in the horizontal line memory to 0, and setting the value of the remaining bits to 1; wherein, N is equal to the width of the first or second horizontal line, and M is equal to the value of the width of the first or second horizontal line when the division is 8 plus 1, multiplied by 8.
[0011] Since the minimum processing unit for pixel width is 1 byte, corresponding to 8 pixels, when drawing horizontal lines, the bit value needs to be set according to the actual width of the line. By setting the bit value of the horizontal line memory using the method described above, resource consumption can be saved while ensuring the horizontal line is drawn completely, thereby maximizing system performance.
[0012] In one possible implementation of the first aspect, drawing border lines based on drawing register parameters includes: reading data starting from the storage start address of the horizontal or vertical line memory; determining the number of bits to read from the horizontal or vertical line memory based on the size of the border lines; and determining the position of the border lines in the video frame based on the coordinates of the border lines.
[0013] In the above method, the drawing of video frame borders can be achieved by determining the starting memory address for drawing the border, the required number of memory bits, and the specific position of the border lines.
[0014] In one possible implementation of the first aspect, before performing drawing operations on multiple border lines sequentially in a video frame, the video frame border drawing method further includes: obtaining the size of the video frame, the size including width and height; allocating a block of horizontal line memory, the width of the horizontal line memory being equal to the width of the video frame, and the height of the horizontal line memory being less than or equal to the height of the video frame; allocating a preset number of blocks of vertical line memory, the preset number being less than or equal to the width of the video frame; the height of the preset number of blocks of vertical line memory being equal to the height of the video frame, the width of the preset number of blocks of vertical line memory being equal to a preset constant, and the preset number being less than or equal to a preset constant.
[0015] In the above method, the memory size required for drawing the borders is determined based on the size of the video frame to which the borders need to be drawn. To ensure that the allocated memory can meet the drawing requirements of borders with various heights and widths, before drawing the borders, a horizontal line memory block with a width equal to the width of the video frame, and multiple vertical line memory blocks with heights equal to the height of the video frames but different widths, are allocated. In this way, during the border drawing process for the video frame, only one memory allocation is needed to satisfy the drawing of various different borders, avoiding multiple memory allocations and releases, reducing memory fragmentation, and improving the efficiency of video frame border drawing and system performance.
[0016] In one possible implementation of the first aspect, setting the value of the first target number of bits in each row of the vertical memory to 1 includes:
[0017] Set the target quantity of the first vertical memory block to 1, set the value of the first bit of each row in the first vertical memory block to 1, and set the value of all bits except the first bit of each row in the first vertical memory block to 0; according to the traversal method, increment the target quantity of the preset number of vertical memory blocks by 1 in turn.
[0018] In the above method, when allocating multiple vertical memory blocks, different widths are set for the multiple vertical memory blocks by traversing them to improve the diversity of vertical memory widths.
[0019] In one possible implementation of the first aspect, obtaining the coordinates and dimensions of the border lines includes: obtaining the first coordinates and dimensions of the border, the dimensions including width and height; calculating the coordinates and dimensions of a first horizontal line based on the first coordinates and width of the border; calculating the coordinates and dimensions of a first vertical line based on the first coordinates and height of the border; and calculating the coordinates and dimensions of a second horizontal line and a second vertical line based on the first coordinates, width, and height of the border.
[0020] In the above method, the first horizontal line, the second horizontal line, the first vertical line and the second vertical line to be drawn can be determined based on the coordinates and size of the border. Combined with the memory allocated in advance, the border of the video frame can be drawn.
[0021] In one possible implementation of the first aspect, after merging the border lines with the video frame, the video frame border drawing method further includes: setting the value of all bits in the horizontal line memory to 1, and setting the value of the first target number of bits in each row of the vertical line memory to 1.
[0022] In the above method, after drawing a border, the previously allocated horizontal and vertical line memory needs to be re-initialized to prepare for subsequent border drawing, thereby improving the reusability of the video frame border drawing method.
[0023] In one possible implementation of the first aspect, before performing drawing operations on multiple border lines sequentially in a video frame, the video frame border drawing method further includes: configuring drawing register parameters according to the coordinates, size, and storage address of the video frame; and drawing the video frame based on the drawing register parameters.
[0024] In the above method, since the video frame border is drawn based on the video frame, the video frame is first drawn according to the parameters of the video frame, and then the border lines are drawn separately using a fusion method to finally complete the drawing of the video frame border.
[0025] Secondly, this application also provides a video frame border drawing device, which includes: a border line drawing module configured to: sequentially perform drawing operations on multiple border lines in a video frame, the border lines including a first horizontal line, a second horizontal line, a first vertical line, and a second vertical line; the drawing operations include: obtaining the coordinates and dimensions of the border lines; configuring drawing register parameters according to the coordinates and dimensions of the border lines, and the storage start address of the corresponding horizontal line memory or vertical line memory; the horizontal line memory is used to store bits representing horizontal line pixels, and the vertical line memory is used to store bits representing vertical line pixels; drawing border lines based on the drawing register parameters; and a video frame border generation module configured to: merge the border lines with the video frame to generate a video frame border.
[0026] It is understood that the beneficial effects of the technical solution of the second aspect provided above can be referred to the beneficial effects of the first aspect and any of its optional implementation methods, and will not be repeated here.
[0027] As can be seen from the above technical solutions, this application provides a video frame border drawing method and apparatus. The video frame border drawing method includes: sequentially performing drawing operations on multiple border lines in a video frame, the border lines including a first horizontal line, a second horizontal line, a first vertical line, and a second vertical line; the drawing operations include: obtaining the coordinates and dimensions of the border lines; configuring drawing register parameters according to the coordinates and dimensions of the border lines, and the storage start address of the corresponding horizontal line memory or vertical line memory; the horizontal line memory is used to store the bits representing the horizontal line pixels, and the vertical line memory is used to store the bits representing the vertical line pixels; drawing the border lines based on the drawing register parameters; and merging the border lines with the video frame to generate a video frame border.
[0028] In the above method, memory is allocated only for the first horizontal line, the second horizontal line, the first vertical line, and the second vertical line used to form the video frame border. The video frame border can be drawn according to the coordinates and size of the border lines and the starting address of the memory storage, which reduces the memory consumption when drawing the video frame border, improves the efficiency of drawing the video frame border, and thus improves the performance and stability of the system. Attached Figure Description
[0029] To more clearly illustrate the technical solution of this application, the drawings used in the embodiments will be briefly introduced below. Obviously, for those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0030] Figure 1 A flowchart illustrating a method for applying for fixed memory is provided in this application embodiment;
[0031] Figure 2 This is a schematic diagram of a horizontal line memory initialization method provided in an embodiment of this application;
[0032] Figure 3 This is a schematic diagram of a vertical line memory initialization method provided in an embodiment of this application;
[0033] Figure 4 This is a schematic diagram of another vertical line memory initialization method provided in an embodiment of this application;
[0034] Figure 5 This is a schematic diagram of a video frame border drawing method provided in an embodiment of this application;
[0035] Figure 6 A schematic diagram illustrating a method for setting bits in horizontal memory according to an embodiment of this application;
[0036] Figure 7 This is a schematic diagram of a video frame border drawing device provided in an embodiment of this application. Detailed Implementation
[0037] The embodiments will now be described in detail, examples of which are illustrated in the accompanying drawings. When the following description relates to the drawings, unless otherwise indicated, the same numbers in different drawings represent the same or similar elements. The embodiments described in the following examples do not represent all embodiments consistent with this application.
[0038] It should be noted that the brief descriptions of terms in this application are only for the convenience of understanding the embodiments described below, and are not intended to limit the embodiments of this application. Unless otherwise stated, these terms should be understood in their ordinary and common meaning.
[0039] The terms "first," "second," "third," etc., used in the specification and accompanying drawings of this application are used to distinguish similar or related objects or entities, and do not necessarily imply a specific order or sequence, unless otherwise specified. It should be understood that such terms can be used interchangeably where appropriate.
[0040] Video frame border rendering technology enhances the visualization of key information by overlaying borders onto video frames or image data. Especially in scenarios requiring dynamic adjustment of border position, size, and line width (such as obstacle tracking in autonomous driving and real-time annotation in live streaming platforms), video frame border rendering technology becomes a crucial module supporting core functions, and its performance directly impacts the system's real-time performance and interactive experience.
[0041] In some embodiments, video frame borders can be drawn using a full image memory allocation method. This is achieved by allocating memory for the entire video frame region, where each pixel in the video frame needs to be set to either the border color or the background color.
[0042] In other embodiments, a line-based memory allocation method can be used to draw the video frame border: the video frame border is divided into an upper horizontal line, a lower horizontal line, a left vertical line, and a right vertical line, and memory is allocated for each line. The lines are drawn as small rectangles and finally pieced together to form a frame. After drawing is complete, the memory is released.
[0043] However, the full-image memory allocation method requires allocating memory for the entire image, leading to resource waste and reducing the efficiency of drawing video frame borders. The line memory allocation method, in drawing scenarios where the border area, line width, and size need to be dynamically changed, frequently allocates and releases memory, causing memory fragmentation in the memory system and reducing system performance and stability.
[0044] To address the aforementioned issues, this application provides a method and apparatus for drawing video frame borders, which can improve the efficiency and stability of drawing borders for video frames.
[0045] In some embodiments, in order to reduce memory consumption and improve the drawing efficiency of video frame borders, the video frame border drawing method provided in this application embodiment is based on segmentation drawing. The border is split into a first horizontal line, a second horizontal line, a first vertical line, and a second vertical line, and the drawing operation is performed sequentially. Memory is allocated only to the above four boundary lines, and then the four drawn boundary lines are merged with the video frame respectively.
[0046] In some embodiments, to avoid frequent memory allocation and deallocation when drawing multiple lines, which can lead to memory fragmentation, a fixed amount of memory is allocated once before drawing the video frame borders, and this fixed memory is reused in subsequent border line drawing processes.
[0047] Figure 1 This is a flowchart illustrating a method for applying for fixed memory, as provided in an embodiment of this application.
[0048] like Figure 1 As shown, applying for fixed memory includes steps S101-S103.
[0049] Step S101: Obtain the dimensions of the video frames.
[0050] In some embodiments, the size of the fixed memory allocation needs to be determined based on the dimensions of the video frame, including its width and height. Therefore, the width and height of the video frame must first be obtained.
[0051] For example, the width of the video frame is 4096 pixels and the height is 4096 pixels.
[0052] Step S102: Request a block of horizontal memory.
[0053] In some embodiments, since the drawing operation is a line-by-line horizontal scan, allocating a block of memory with a width equal to the width of the video frame is sufficient to cover the drawing requirements of horizontal lines of different widths. The height of the horizontal line memory can be determined according to the actual situation, as long as it does not exceed the height of the video frame.
[0054] For example, if the width and height of a video frame are 4096 pixels, allocate a horizontal memory block with a width of 4096 pixels and a height of 16 pixels, and initialize all pixels in the horizontal memory block to 1. The size of this horizontal memory block is 4096 * 16 / 8 = 8KB.
[0055] Figure 2 This is a schematic diagram of a horizontal line memory initialization method provided in an embodiment of this application.
[0056] like Figure 2 As shown, the width of the horizontal memory is 4096 pixels, with 8 pixels constituting 1 byte, meaning the total width of the horizontal memory is 4096 / 8 = 512 bytes, and the height is 16 pixels. Initializing all pixels in the horizontal memory to 1 results in each byte having a bit value of 11111111 (0xFF), indicating that each bit in the corresponding byte is 1. This ensures the consistency of the horizontal memory's state during initialization.
[0057] Step S103: Allocate a preset number of vertical line memory blocks.
[0058] In some embodiments, since the drawing operation is a line-by-line horizontal scan, a preset number of blocks of vertical line memory of different widths need to be allocated to meet the drawing requirements of vertical lines of different widths. The preset number is less than or equal to the width of the video frame; the height of the preset number of vertical line memory blocks is equal to the height of the video frame.
[0059] It should be noted that, since the minimum data read by the drawing template within one clock cycle during the actual drawing of the video frame border is 64 bits, the minimum width of the vertical line memory should be 64 pixels. Therefore, to ensure that the width of the vertical line drawn from each allocated vertical line memory block is different, a maximum of 64 vertical line memory blocks with a width of 64 pixels can be allocated, i.e., the default quantity is 64.
[0060] For example, the width and height of a video frame are 4096 pixels. If 64 vertical memory blocks are allocated, each with a height of 4096 pixels and a width of 64 pixels, then the size of each vertical memory block is 4096 * 64 / 8 = 32 KB.
[0061] In some embodiments, to ensure that the preset number of vertical line memory blocks can be used to draw vertical lines of different widths, each vertical line memory block needs to be initialized in a different way.
[0062] In one implementation, the width of the vertical line memory is set to 64 pixels. Less than or equal to 64 vertical line memory blocks can be allocated. Each vertical line memory block is initialized with different bits, thereby fulfilling the requirement of drawing vertical lines of different widths with different vertical line memory blocks.
[0063] For example, 16 vertical memory blocks are allocated, each with a height of 4096 pixels and a width of 64 pixels. Each vertical memory block is initialized differently.
[0064] Specifically, set the target quantity of the first vertical memory block to 1, set the value of the first bit of each row in the first vertical memory block to 1, and set the value of all bits except the first bit of each row in the first vertical memory block to 0; then, according to the traversal method, increment the target quantity of the preset number of vertical memory blocks by 1.
[0065] Below, we will use examples to illustrate how to initialize the memory for drawing vertical lines of different widths.
[0066] Figure 3 This is a schematic diagram of a vertical line memory initialization method provided in an embodiment of this application.
[0067] like Figure 3 As shown, let's take the allocation of memory for drawing a vertical line with a width of 4 pixels as an example. The height of this vertical line memory is 4096 pixels, that is, 4096 rows. To ensure that the vertical line memory can draw a vertical line with a width of 4 pixels, the first 4 bits of the first byte of each row in the vertical line memory are initialized to 1, and the remaining 60 bits are all initialized to 0, indicating that the first 4 pixels of each row are the pixels to be drawn.
[0068] Figure 4 This is a schematic diagram of another vertical line memory initialization method provided in an embodiment of this application.
[0069] like Figure 4 As shown, taking the allocation of memory for drawing a vertical line with a width of 16 pixels as an example, the height of this vertical line memory is 4096 pixels, or 4096 rows. To ensure that the vertical line memory can draw a vertical line with a width of 4 pixels, the first 4 bits of the first byte of each row in the vertical line memory are initialized to 1, and the remaining 60 bits are all initialized to 0, indicating that the first 4 pixels of each row are the pixels for drawing the line.
[0070] It should be understood that the initialization method for the memory used to draw vertical lines of other different widths is similar to the initialization method for the memory used to draw vertical lines with a width of 4 and a width of 16 as described above:
[0071] If a vertical line with a width of 8 is requested for memory, then all 8 bits of the first byte of each row in that vertical line memory are initialized to 1, and the remaining 56 bits are initialized to 0. If a vertical line with a width of 10 is requested for memory, then all bits of the first byte of each row in that vertical line memory and the first 2 bits of the second byte are initialized to 1, and the remaining 54 bits are initialized to 0. The methods for initializing vertical line memory for other widths are not detailed in this embodiment.
[0072] In some embodiments, it is necessary to initialize the allocated fixed memory. Specifically, all bits in the horizontal line memory are set to 1, and the first target number of bits in each row of the vertical line memory are set to 1. Here, the first target number of bits represents the width of the vertical line to be drawn in the vertical line memory, and the bit value is set to 1 to indicate that the pixels of the horizontal or vertical line need to be drawn.
[0073] For example, setting all 4090 bits in the memory for a horizontal line with a width of 4090 pixels to 1, and setting the first 8 bits of each row in the memory for a vertical line with a height of 4090 pixels to 1, indicates that the memory for the vertical line is used to draw a vertical line with a width of 8 pixels.
[0074] In some embodiments, the video frame border can be drawn after the fixed memory allocation is completed. Since the video frame border drawing method provided in this application embodiment is segmented drawing, it is necessary to draw the video frame, the first horizontal line, the second horizontal line, the first vertical line, and the second vertical line sequentially before merging them. Therefore, before performing drawing operations on multiple border lines in the video frame sequentially, the video frame border drawing method needs to configure drawing register parameters according to the coordinates, size, and storage address of the video frame, and then draw the video frame based on the drawing register parameters.
[0075] In one implementation, the video frame and the border are separated into two layers. First, the video frame layer is drawn. When drawing the video frame layer, the drawing register parameters need to be configured. The process of configuring the drawing register parameters includes: first, determining the start and end coordinates of the video frame based on its width and height; second, setting the address parameters in the register according to the video frame's storage address, i.e., the location of the video frame data in memory; and finally, configuring other parameters in the drawing register, such as color and pixel format. After the register parameters are configured, an enable instruction is used to start the hardware module responsible for drawing. The hardware module then performs the video frame drawing operation according to the video frame parameters configured in the drawing register.
[0076] In some embodiments, after the video frame is drawn, the border lines are drawn. First, the border needs to be divided into four border lines: a first horizontal line, a second horizontal line, a first vertical line, and a second vertical line.
[0077] For example, the top horizontal line can be used as the first horizontal line, the bottom horizontal line as the second horizontal line, the left vertical line as the first vertical line, and the right vertical line as the second vertical line.
[0078] In some embodiments, after the border is split into a first horizontal line, a second horizontal line, a first vertical line, and a second vertical line, the four border lines are drawn sequentially in the video frame.
[0079] Figure 5 This is a schematic diagram of a video frame border drawing method provided in an embodiment of this application.
[0080] like Figure 5 As shown, the video frame border drawing method includes steps S100-S400.
[0081] Step S100: Obtain the coordinates and dimensions of the border lines.
[0082] In some embodiments, the coordinates and dimensions of the border lines are determined based on the size of the video frame and a preset border style. It should be noted that the coordinates and dimensions of the border lines have already been determined by previous operations before the video frame border is drawn. Therefore, the coordinates and dimensions of the border lines can be obtained directly.
[0083] For example, the starting coordinates of the first horizontal line and the first vertical line are located at the top left corner of the drawn video frame; the width of the first horizontal line and the second horizontal line is 2048 pixels; the height of the first vertical line and the second vertical line is 2048 pixels; and the width of the border lines can be adjusted according to actual needs to meet the needs of different application scenarios. For example, the width of the first horizontal line, the second horizontal line, the first vertical line and the second vertical line can all be 16 pixels.
[0084] It should be understood that the coordinates of the border lines can also be located at other positions of the drawn video frame, and the size of the border lines can also be other values, as long as the width of the first horizontal line and the second horizontal line are less than or equal to the width of the video frame, and the height of the first vertical line and the second vertical line are less than the height of the video frame. This application does not impose specific limitations on the embodiments.
[0085] In other embodiments, the line widths of the first horizontal line, the second horizontal line, the first vertical line, and the second vertical line may be different, and no specific limitation is made in the embodiments described herein.
[0086] S200: Configure the drawing register parameters based on the coordinates and dimensions of the border lines, as well as the starting address of the corresponding horizontal or vertical line memory.
[0087] In some embodiments, the drawing register parameters include information such as the start coordinates, end coordinates, line width, line color, and storage start address of the border lines. By configuring these parameters, the system can accurately control the drawing process of the border lines.
[0088] In some embodiments, the ending coordinates of the border lines can be determined solely by the starting coordinates and dimensions of the border. Specifically, the first coordinates and dimensions of the border, including width and height, are obtained; the coordinates and dimensions of the first horizontal line are calculated based on the first coordinates and width of the border; the coordinates and dimensions of the first vertical line are calculated based on the first coordinates and height of the border; and the coordinates and dimensions of the second horizontal line and the second vertical line are calculated based on the first coordinates, width, and height of the border.
[0089] For example, the first coordinate of the border is the coordinate of the top-left corner vertex, which is the starting coordinate of the first horizontal line. Adding the horizontal coordinate of the first coordinate to the width of the first horizontal line gives the horizontal coordinate of the ending coordinate of the first horizontal line; the vertical coordinate of the first coordinate is the vertical coordinate of the ending coordinate of the first horizontal line. Adding the vertical coordinate of the first coordinate to the height of the first horizontal line gives the vertical coordinate of the starting coordinate of the first vertical line; the horizontal coordinate of the first coordinate is the horizontal coordinate of the starting coordinate of the first vertical line. Adding the vertical coordinate of the starting coordinate of the first vertical line to the height of the first vertical line gives the vertical coordinate of the ending coordinate of the first vertical line; the horizontal coordinate of the starting coordinate of the first vertical line is the horizontal coordinate of the ending coordinate of the first vertical line. The calculation principles for the second horizontal line and the second vertical line are the same as those described above, and will not be repeated in this embodiment.
[0090] It should be understood that since the horizontal and vertical line memory has already been allocated and initialized, it can be directly used during the drawing of the border lines without recalculating the pixel positions of the lines each time they are drawn. This reduces the memory usage of drawing video frame borders and improves drawing efficiency and system performance. Specifically, the horizontal line memory is the fixed horizontal line memory allocated in step S102 above, used to store the bits representing the horizontal line pixels. The vertical line memory is one of the fixed vertical line memory allocated in step S103 above, used to store the bits representing the vertical line pixels. It should be understood that since a single fixed horizontal line memory can be used to draw horizontal lines of different heights, the fixed horizontal line memory is selected for drawing the first and second horizontal lines.
[0091] For example, firstly, the starting coordinates, ending coordinates, and line colors of the first horizontal line, the second horizontal line, the first vertical line, and the second vertical line are obtained respectively. Then, a fixed horizontal line memory is selected for drawing the first and second horizontal lines, and the starting address of the fixed horizontal line memory is obtained. If the width of the vertical line determined in the previous steps is 6 pixels, then a fixed vertical line memory with an initial width of 6 pixels is selected for drawing the first and second vertical lines, and the starting address of the fixed vertical line memory with an initial width of 6 pixels is obtained. Finally, the drawing register is configured using the above parameters.
[0092] In some embodiments, since the drawing operation is a line-by-line horizontal scan, when drawing the first and second horizontal lines using fixed horizontal line memory, the bit values need to be set based on the actual width of the drawn horizontal line, on top of the already initialized fixed horizontal line memory. Furthermore, since the minimum processing unit for the width of a drawn pixel is 1 byte, or 8 pixels, in order to save resources while fully drawing the horizontal line and thus maximize system performance, the bit values of the horizontal line memory need to be set in units of 8 pixels.
[0093] In one implementation, if the width of the first or second horizontal line is a multiple of 8, then the fixed horizontal line memory, where the value of each pixel bit has been initialized to 1, is scanned line by line based on the width of the first or second horizontal line. Each line is scanned until the bit value equal to the width of the first or second horizontal line is reached, and then the next line is scanned.
[0094] For example, if the width of the first horizontal line to be drawn is 640 pixels, then the first 640 bits, or the first 80 bytes, of each row in the memory of the fixed horizontal line are scanned.
[0095] In another implementation, if the width of the first or second horizontal line is not a multiple of 8, the (N+1)th to the Mth bits of each row in the horizontal line memory are set to 0, and the remaining bits are set to 1. Here, N equals the width of the first or second horizontal line, and M equals the quotient of the width of the first or second horizontal line divided by 8, plus 1, multiplied by 8. During the scanning of each row in the fixed horizontal line memory, scanning stops after completing the scan of bytes including those with bits of 0, and the scan continues to the next row.
[0096] Below is an example illustrating how to set the memory for horizontal lines when drawing the first or second horizontal line whose line width is not a multiple of 8.
[0097] Figure 6 This is a schematic diagram illustrating a method for setting bits in a horizontal memory segment, as provided in an embodiment of this application.
[0098] like Figure 6 As shown, the horizontal line to be drawn needs to be 644 pixels wide, meaning N equals 644. Since each byte contains 8 bits, the divisor is set to 8. The quotient of 644 divided by 8 is 80, indicating that when drawing a horizontal line with a width of 644 pixels, the values of all bits in the first 80 bytes are 1. To draw a horizontal line with a width of 644 pixels, in the 81st byte, only the first 4 bits need to be 1, and the last 4 bits need to be 0. Therefore, M is the total number of bits in the 81 bytes. That is, M is calculated as (80+1)*8 = 648, so M equals 648.
[0099] Therefore, when the required line width is 644 pixels, the values of bits 645 to 648 of each row need to be set to 0, while the values of the remaining bits remain unchanged at 1. During the scanning of each row in the memory containing the fixed horizontal line, scanning can stop after completing the byte containing the bits with a value of 0 (i.e., the 81st byte), and then continue scanning the next row.
[0100] It should be understood that when drawing the first or second horizontal line with other line widths, the above method is used for calculation as long as the line width is not a multiple of 8. This will not be repeated in the embodiments of this application.
[0101] S300: Draws border lines based on drawing register parameters.
[0102] In some embodiments, after the drawing register parameters are configured, the border lines are drawn based on the drawing register parameters. Specifically, an enable instruction is used to start the hardware module responsible for drawing and execute the border line drawing operation.
[0103] In some embodiments, the hardware module includes a graphics processing unit (GPU) or other hardware unit with drawing capabilities. By sending an enable instruction to the hardware module and passing drawing register parameters, the hardware module can draw a first horizontal line, a second horizontal line, a first vertical line, and a second vertical line according to the parameter configuration.
[0104] Specifically, data is read starting from the storage address of the horizontal or vertical memory line; the number of bits to read from the horizontal or vertical memory line is determined based on the size of the border line; and the position of the border line in the video frame is determined based on the coordinates of the border line.
[0105] For example, on a video frame image with a width and height of 4096 pixels, the top-left corner of the video frame is set as the origin, with coordinates (0, 0). Starting from the origin of the video frame, a first horizontal line with a width of 640 pixels and a height of 6 pixels is drawn. First, data is read from the starting address of the fixed horizontal line in memory, reading line by line, for a total of 6 lines of data. After reading the 640th bit (i.e., the 80th byte) of each line, the next line of data is read, until all 6 lines of data have been read.
[0106] For another example, on a video frame image with a width of 4096 pixels and a height of 4096 pixels, the top-left corner of the video frame is set as the origin, with coordinates (0, 0). Starting from (0, 7), a first vertical line with a width of 4 pixels and a height of 2048 pixels is drawn. First, a fixed vertical line memory is selected for drawing the 4-pixel-width vertical line, that is, the first 4 bits of each row are initialized to 1, and the other bits are initialized to 0. The first vertical line is drawn using this fixed vertical line memory. Data is read starting from the starting address of the fixed vertical line memory, and the reading method is line by line, for a total of 2048 rows of data. Since the border needs to be read in bytes, and each byte includes 8 bits, the first byte (8 bits) of each row needs to be read before starting to read the next row of data, until all 2048 rows of data have been read.
[0107] It should be understood that, since the first vertical line is drawn by initializing the first 4 bits of each row to 1 and the other bits to 0 in a fixed vertical line memory, even if 1 byte is read, only the first 4 bits will be drawn, ensuring that the width of the first vertical line is 4 pixels.
[0108] S400: Merges border lines with video frames to generate video frame borders.
[0109] In some embodiments, once a border line is drawn, it can be merged with a video frame. After all border lines are drawn and merged, a video frame border can be generated.
[0110] Specifically, the first horizontal line is first merged with the video frame, and then the second horizontal line is drawn. After the second horizontal line is drawn, it is merged with the video frame, and then the first vertical line is drawn. After the first vertical line is drawn, it is merged with the video frame, and then the second vertical line is drawn. After the second vertical line is drawn, it is merged with the video frame, and finally the complete video frame border is obtained.
[0111] In some embodiments, since the applied fixed horizontal line memory and fixed vertical line memory need to be reused, after merging the border lines with the video frame and completing the drawing of the video frame border, it is necessary to set the value of all bits in the horizontal line memory to 1 and set the value of the first target number of bits in each row of the vertical line memory to 1 to complete the reset of the horizontal line memory and the vertical line memory for drawing other borders in the video frame.
[0112] By employing the methods described above, the video frame border drawing method provided in this application embodiment can improve the efficiency of drawing video frame borders while reducing memory consumption and enhancing system performance and stability. Furthermore, by adopting a segmented drawing and fixed memory allocation approach, it can avoid memory fragmentation issues caused by frequent memory allocation and deallocation when dynamically changing border areas, frame line widths, and sizes.
[0113] In some embodiments, this application also provides a video frame border drawing device. Figure 7 This is a schematic diagram of a video frame border drawing device provided in an embodiment of this application.
[0114] like Figure 7 As shown, the video frame border drawing device includes: a border line drawing module 701, configured to: sequentially perform drawing operations on multiple border lines in the video frame, the border lines including a first horizontal line, a second horizontal line, a first vertical line, and a second vertical line; the drawing operations include: obtaining the coordinates and dimensions of the border lines; configuring drawing register parameters according to the coordinates and dimensions of the border lines, and the storage start address of the corresponding horizontal line memory or vertical line memory; the horizontal line memory is used to store the bits representing the horizontal line pixels, and the vertical line memory is used to store the bits representing the vertical line pixels; drawing the border lines based on the drawing register parameters; and a video frame border generation module 702, configured to: merge the border lines with the video frame to generate a video frame border.
[0115] As can be seen from the above technical solutions, this application provides a video frame border drawing method and apparatus. The video frame border drawing method includes: sequentially performing drawing operations on multiple border lines in a video frame, the border lines including a first horizontal line, a second horizontal line, a first vertical line, and a second vertical line; the drawing operations include: obtaining the coordinates and dimensions of the border lines; configuring drawing register parameters according to the coordinates and dimensions of the border lines, and the storage start address of the corresponding horizontal line memory or vertical line memory; the horizontal line memory is used to store the bits representing the horizontal line pixels, and the vertical line memory is used to store the bits representing the vertical line pixels; drawing the border lines based on the drawing register parameters; and merging the border lines with the video frame to generate a video frame border.
[0116] In the above method, memory is allocated only for the first horizontal line, the second horizontal line, the first vertical line, and the second vertical line used to form the video frame border. The video frame border can be drawn according to the coordinates and size of the border lines and the starting address of the memory storage, which reduces the memory consumption when drawing the video frame border, improves the efficiency of drawing the video frame border, and thus improves the performance and stability of the system.
[0117] Similar parts between the embodiments provided in this application can be referred to mutually. The specific implementation methods provided above are only a few examples under the overall concept of this application and do not constitute a limitation on the scope of protection of this application. For those skilled in the art, any other implementation methods extended from the solution of this application without creative effort shall fall within the scope of protection of this application.
Claims
1. A method for drawing video frame borders, characterized in that, The method includes: In a video frame, multiple border lines are drawn sequentially, including a first horizontal line, a second horizontal line, a first vertical line, and a second vertical line; the drawing operation includes: Obtain the coordinates and dimensions of the border lines; Based on the coordinates and dimensions of the border lines, and the starting address of the corresponding horizontal or vertical line memory, the drawing register parameters are configured; the horizontal line memory is used to store the bits representing the horizontal line pixels, and the vertical line memory is used to store the bits representing the vertical line pixels. The border lines are drawn based on the drawing register parameters; The border lines are merged with the video frame to generate a video frame border.
2. The video frame border drawing method according to claim 1, characterized in that, The method further includes: Set all bits in the horizontal line memory to 1, and set the first target number of bits in each row of the vertical line memory to 1. Setting the bit value to 1 indicates that the pixels of the horizontal or vertical line need to be drawn.
3. The video frame border drawing method according to claim 1, characterized in that, Before configuring the drawing register parameters based on the coordinates and size of the border lines, and the corresponding starting address of the horizontal or vertical line memory, the method further includes: If the width of the first or second horizontal line is not a multiple of 8, set the value of the (N+1)th to the Mth bit of each row in the memory of the horizontal line to 0, and set the value of the remaining bits to 1; where N is equal to the width of the first or second horizontal line, and M is equal to the value of the width of the first or second horizontal line when the divisor is 8, plus 1, multiplied by 8.
4. The video frame border drawing method according to claim 1, characterized in that, Drawing the border lines based on the drawing register parameters includes: Data is read from the starting address of the horizontal or vertical memory. The number of bits to read from the horizontal or vertical memory is determined based on the size of the border lines. The position of the border line in the video frame is determined based on the coordinates of the border line.
5. The video frame border drawing method according to claim 2, characterized in that, Before performing drawing operations on multiple border lines sequentially in a video frame, the method further includes: obtaining the size of the video frame, the size including width and height; Request a horizontal memory block, the width of which is equal to the width of the video frame, and the height of which is less than or equal to the height of the video frame; Request a preset number of vertical memory blocks, wherein the preset number is less than or equal to the width of the video frame; The height of the preset number of vertical memory blocks is equal to the height of the video frame, the width of the preset number of vertical memory blocks is equal to a preset constant, and the preset number is less than or equal to the preset constant.
6. The video frame border drawing method according to claim 5, characterized in that, Setting the value of the first target number of bits in each row of the vertical memory to 1 includes: Set the target number of the first vertical memory block to 1, set the value of the first bit of each row in the first vertical memory block to 1, and set the value of all bits except the first bit of each row in the first vertical memory block to 0. Following the traversal method, the target quantity in the vertical memory of the preset quantity block is incremented by 1 in turn.
7. The video frame border drawing method according to claim 1, characterized in that, Obtaining the coordinates and dimensions of the border lines includes: Obtain the first coordinates and dimensions of the border, where the dimensions include width and height; Calculate the coordinates and dimensions of the first horizontal line based on the first coordinates of the border and the width; Calculate the coordinates and dimensions of the first vertical line based on the first coordinates of the border and the height; The coordinates and dimensions of the second horizontal line and the second vertical line are calculated based on the first coordinates of the border, the width, and the height.
8. The video frame border drawing method according to claim 1, characterized in that, After merging the border lines with the video frame, the method further includes: Set the value of all bits in the horizontal memory to 1, and set the value of the first target number of bits in each row of the vertical memory to 1.
9. The video frame border drawing method according to claim 1, characterized in that, Before performing the drawing operation on multiple border lines sequentially in the video frame, the method further includes: Configure the drawing register parameters according to the coordinates, size, and storage address of the video frame; The video frame is drawn based on the drawing register parameters.
10. A video frame border drawing device, characterized in that, The device includes: The border line drawing module is configured to: sequentially perform drawing operations on multiple border lines in a video frame, wherein the border lines include a first horizontal line, a second horizontal line, a first vertical line, and a second vertical line; the drawing operations include: Obtain the coordinates and dimensions of the border lines; Based on the coordinates and dimensions of the border lines, and the starting address of the corresponding horizontal or vertical line memory, the drawing register parameters are configured; the horizontal line memory is used to store the bits representing the horizontal line pixels, and the vertical line memory is used to store the bits representing the vertical line pixels. The border lines are drawn based on the drawing register parameters; The video frame border generation module is configured to merge the border lines with the video frame to generate a video frame border.