Drawing processing method, device and equipment, computer readable storage medium and computer program product
By extending and filtering floating-point sampling points based on the Bressenham algorithm, and combining them with brush parameters to draw pixels, the problem of precision loss and visual discontinuity in the processing of floating-point coordinates and brush radius in existing algorithms is solved, and high-quality line drawing effects are achieved.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-01-05
- Publication Date
- 2026-04-03
AI Technical Summary
Existing Bressenham algorithms and their variants cannot meet the needs of efficient line and curve drawing in modern computer graphics applications, especially when dealing with floating-point coordinates and brush radii, where they suffer from precision loss and visual discontinuities.
By obtaining the drawing point sequence of floating-point coordinates, extending the original line segment and generating floating-point sampling points, determining candidate pixel points based on the brush radius, and filtering out target pixel points falling within the brush range, and drawing in combination with brush parameters, the problem of missing circular strokes at the endpoints and discontinuous line segment connections in traditional algorithms is solved.
It improves the accuracy and visual effect of line drawing, ensures the integrity and natural smoothness of the drawing trajectory, reduces the cost of invalid pixel judgment, and improves rendering quality and algorithm efficiency.
Smart Images

Figure CN121788643A_ABST
Abstract
Description
Technical Field
[0001] This application relates to computer technology, and more particularly to a drawing processing method, apparatus, device, storage medium, and program product. Background Technology
[0002] In the history of computer graphics, line drawing algorithms have always been a fundamental and important research topic. The Bresenham algorithm is one of the most classic and influential algorithms in this field. Its core idea is error accumulation judgment, assuming that the start and end points of the line are integer coordinates, and using an error term to determine which pixel should be selected at each step. Although this algorithm has spawned several variants, such as the midpoint line drawing algorithm and the Bresenham circle drawing algorithm, which inherit the integer operation characteristics and efficiency of the original algorithm, the limitations of this algorithm and its variants have become increasingly apparent with the rapid development of computer hardware performance and the continuous improvement of application requirements, and can no longer meet the needs of modern graphics applications. Summary of the Invention
[0003] This application provides a drawing processing method, apparatus, electronic device, computer-readable storage medium, and computer program product that can improve the quality of line drawing.
[0004] The technical solution of this application embodiment is implemented as follows: This application provides a drawing processing method, including: In response to a drawing operation, a sequence of target points for the drawing trajectory indicated by the drawing operation is obtained, wherein the sequence of target points includes multiple drawing points with floating-point coordinates; For any two adjacent first and second drawing points in the target point sequence, the original line segment between the first and second drawing points is extended based on the brush radius to obtain the target line segment, and multiple floating-point coordinate sampling points are generated on the target line segment. For each of the plurality of sampling points, the brush range and candidate range corresponding to the sampling point are determined based on the sampling point and the brush radius, and a plurality of candidate pixels falling within the candidate range are determined. Based on the distance from each candidate pixel to the target line segment, target pixels that fall within the brush range are selected from the plurality of candidate pixels, and the target pixels are drawn based on the brush parameters.
[0005] This application provides a drawing processing apparatus, including: The acquisition module is used to acquire, in response to a drawing operation, a sequence of target points for the drawing trajectory indicated by the drawing operation, wherein the sequence of target points includes multiple drawing points with floating-point coordinates; The extension module is used to extend the original line segment between any two adjacent first drawing points and second drawing points in the target point sequence based on the brush radius to obtain the target line segment. The acquisition module is used to generate multiple sampling points with floating-point coordinates on the target line segment; The filtering module is used to determine the brush range and candidate range corresponding to each of the plurality of sampling points based on the sampling point and the brush radius, and to determine a plurality of candidate pixels falling within the candidate range; Based on the distance from each candidate pixel to the target line segment, target pixels that fall within the brush range are selected from the plurality of candidate pixels; The drawing module is used to draw the target pixel points based on brush parameters.
[0006] In the above scheme, the acquisition module is further configured to respond to a drawing operation triggered by an input device, acquire multiple floating-point coordinates of drawing points of the drawing trajectory indicated by the drawing operation through the input device; arrange the multiple drawing points according to the acquisition time order to obtain an initial point sequence, and preprocess the initial point sequence to obtain the target point sequence; wherein, the preprocessing includes at least one of the following: filtering duplicate drawing points, smoothing jittering drawing points, and repairing broken drawing points.
[0007] In the above scheme, before extending the original line segment between the first drawing point and the second drawing point to obtain the target line segment based on the brush radius, the device further includes: a determining module, used to determine the target pressure value of the pressure sensor when the input device of the drawing operation is equipped with a pressure sensor; and to determine the brush radius based on the preset mapping relationship between the pressure value and the radius, the basic radius of the brush, and the target pressure value of the pressure sensor when the drawing operation is triggered.
[0008] In the above scheme, the extension module is further configured to determine the unit direction vector of the original line segment based on the direction vector and length of the original line segment between the first drawing point and the second drawing point; based on the unit direction vector and the brush radius, extend the first drawing point to a first extension point, extend the second drawing point to a second extension point, and determine the line segment between the first extension point and the second extension point as the target line segment obtained by extending the original line segment.
[0009] In the above scheme, the extension module is further configured to determine the curvature of the fitting curve corresponding to the first drawing point based on the first drawing point, the second drawing point, and the third drawing point adjacent to the first drawing point; determine the correspondence between the preset curvature and the extension length, and determine the target extension length corresponding to the first drawing point based on the correspondence, the curvature, and the brush radius; and extend the target extension length from the first drawing point along a direction away from the direction indicated by the unit direction vector to obtain the first extension point.
[0010] In the above scheme, the sampling module is further configured to determine the number of sampling steps to be performed on the target line segment based on the lateral coordinate difference and the longitudinal coordinate difference between the second extension point and the first extension point; use the ratio of the lateral coordinate difference to the number of sampling steps as the lateral increment of each sampling step, and use the ratio of the longitudinal coordinate difference to the number of sampling steps as the longitudinal increment of each sampling step; starting from the first extension point on the target line segment, the lateral increment and the longitudinal increment are accumulated at each step for sampling until the second extension point, generating a target number of floating-point coordinate sampling points, wherein the target number is the number of sampling steps plus 1.
[0011] In the above scheme, the sampling module is further configured to determine the maximum coordinate difference between the horizontal coordinate difference and the vertical coordinate difference between the second extension point and the first extension point; determine the ratio of the distance difference between the first drawing point and the second drawing point to the time difference as the drawing speed; and determine the curvature of the fitting curve between the first drawing point and the second drawing point; and determine the number of sampling steps to sample on the target line segment based on the maximum coordinate difference, the drawing speed, and the curvature, wherein the number of sampling steps is negatively correlated with the drawing speed and positively correlated with the curvature.
[0012] In the above scheme, the filtering module is further configured to determine the circular area centered on the sampling point and with the brush radius as the radius as the brush range corresponding to the sampling point; and to determine the square area centered on the sampling point and with the brush radius as half the side length as the candidate range, wherein the brush range is included within the candidate range.
[0013] In the above scheme, the filtering module is further configured to determine the horizontal difference and horizontal sum between the horizontal coordinate value of the sampling point and the brush radius, and the vertical difference and vertical sum between the vertical coordinate value of the sampling point and the brush radius; determine a plurality of horizontal integer coordinate values located between the horizontal difference and the horizontal sum, and a plurality of vertical integer coordinate values located between the vertical difference and the vertical sum; and filter out a plurality of candidate pixels in the candidate range based on the plurality of horizontal integer coordinate values and the plurality of vertical integer coordinate values.
[0014] In the above scheme, after determining multiple candidate pixels falling within the candidate range, the filtering module is further configured to determine a target range that overlaps between the first candidate range of the first sampling point and the second candidate range of the second sampling point when the distance between adjacent first sampling points and second sampling points among the multiple sampling points is less than twice the brush radius; and to merge the candidate pixels falling within the target range filtered based on the first sampling point and the candidate pixels falling within the target range filtered based on the second sampling point.
[0015] In the above scheme, the filtering module is further configured to, for each of the plurality of candidate pixels, determine the distance between the candidate pixel and its projection point on the target line segment as the distance from the candidate pixel to the target line segment; and filter out candidate pixels whose distance does not exceed the brush radius from the plurality of candidate pixels as target pixels falling within the brush range.
[0016] In the above scheme, before drawing the target pixel based on brush parameters, the drawing module is further configured to respond to a brush preset operation and determine the brush parameters set by the brush preset operation instruction; or, perform brush matching based on the drawing scene of the drawing operation to obtain brush parameters adapted to the drawing scene; wherein, the brush parameters include at least one of the following: brush color, brush hardness, brush transparency, brush texture, and brush edge characteristics.
[0017] In the above scheme, the device further includes: a marking module, configured to, after determining multiple candidate pixels falling within the candidate range, mark the multiple candidate pixels corresponding to all the sampling points with an attribution identifier, the attribution identifier indicating the sampling point to which the candidate pixel belongs; when there are overlapping pixels belonging to multiple sampling points among all candidate pixels, determine the distance from the overlapping pixel to each attribution sampling point; update the attribution identifier of the overlapping pixel based on the distance from the overlapping pixel to each attribution sampling point, the updated attribution identifier indicating that the sampling point to which the overlapping pixel belongs is the sampling point with the smallest distance; correspondingly, the drawing module is further configured to, when the target pixel is the overlapping pixel, draw the overlapping pixel based on brush parameters and the sampling point with the smallest distance.
[0018] In the above scheme, the marking module is further configured to, after generating multiple floating-point coordinate sampling points on the target line segment, determine the vertical distance from the sampling point to the original line segment for each of the multiple sampling points; when the difference between the brush radius and the vertical distance is less than the difference threshold, mark the sampling point as an edge pixel; correspondingly, the drawing module is further configured to, when the target pixel is the edge pixel, draw the edge pixel based on the brush parameters and adjust the transparency of the edge pixel.
[0019] This application provides an electronic device, including: Memory is used to store executable instructions or computer programs. The processor, when executing computer-executable instructions or computer programs stored in the memory, implements the drawing processing method provided in the embodiments of this application.
[0020] This application provides a computer-readable storage medium storing computer-executable instructions or computer programs, which are executed by a processor to implement the drawing processing method provided in this application.
[0021] This application provides a computer program product, including a computer program or computer executable instructions. When the computer program or computer executable instructions are executed by a processor, they implement the drawing processing method provided in this application.
[0022] The embodiments of this application have the following beneficial effects: Applying the embodiments of this application, firstly, the original line segments between adjacent drawing points are extended according to the brush radius. Essentially, this solves the problem of missing circular brush strokes at the endpoints of traditional algorithms by covering the semi-circular area outside the line segment endpoints. Simultaneously, it provides an overlapping basis for the connection of continuous trajectories, avoiding breakpoints and gaps at line segment connections and ensuring the visual integrity of the drawn trajectory. Secondly, floating-point drawing points and floating-point sampling points are generated on the extended target line segments. Compared to integer coordinate points, this method more easily captures the subtle direction of the line segments, avoiding the precision loss caused by integer coordinate quantization. This results in more uniform line sampling, smoother brush edges, and more natural line segment connections. Candidate images are then determined based on the sampling points and the brush radius. The process of defining the target pixel range reduces the cost of invalid pixel judgment by focusing on the core area covered by the brush. Combined with the precise distance from the candidate pixel to the target line segment to filter the target pixel, it ensures that only pixels that truly fall within the brush range are selected. This avoids incomplete lines caused by missed pixel detection and blurry line edges caused by misjudgment, thus improving rendering accuracy. Finally, the target pixel is drawn based on the brush parameters, so that the selected pixels can accurately represent the width, texture and other characteristics of the brush. This ensures that the final drawing effect not only meets the user's expected brush stroke settings, but also presents a smooth and natural visual performance due to the complete trajectory and precise edges, effectively balancing drawing quality and algorithm efficiency. Attached Figure Description
[0023] Figure 1 This is a schematic diagram of the architecture of the drawing processing system 100 provided in an embodiment of this application; Figure 2 This is a schematic diagram of the structure of the electronic device 500 provided in the embodiments of this application; Figure 3 This is a flowchart illustrating the drawing processing method provided in the embodiments of this application. Figure 1 ; Figure 4 This is a schematic flowchart of the line segment extension method provided in the embodiments of this application; Figure 5 This is a schematic diagram of the sampling method provided in the embodiments of this application; Figure 6 This is a line drawing illustration provided in the embodiments of this application. Figure 1 ; Figure 7 This is a flowchart illustrating the drawing processing method provided in the embodiments of this application. Figure 2 ; Figure 8 This is a schematic diagram illustrating the principle of the drawing processing method provided in the embodiments of this application; Figure 9 This is a line drawing illustration provided in the embodiments of this application. Figure 2 ; Figure 10This is a line drawing illustration provided in the embodiments of this application. Figure 3 ; Figure 11 This is a line drawing illustration provided in the embodiments of this application. Figure 4 . Detailed Implementation
[0024] To make the objectives, technical solutions, and advantages of this application clearer, the application will be further described in detail below with reference to the accompanying drawings. The described embodiments should not be regarded as limitations on this application. All other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.
[0025] It is understood that in the embodiments of this application, data such as user information are involved. When the embodiments of this application are applied to specific products or technologies, user permission or consent is required, and the collection, use and processing of related data must comply with relevant laws, regulations and standards.
[0026] In the following description, references are made to “some embodiments,” which describe a subset of all possible embodiments. However, it is understood that “some embodiments” may be the same subset or different subsets of all possible embodiments and may be combined with each other without conflict.
[0027] In the following description, the terms “first, second…” are used merely to distinguish similar objects and do not represent a specific ordering of objects. It is understood that “first, second…” may be interchanged in a specific order or sequence where permitted, so that the embodiments of this application described herein can be implemented in an order other than that illustrated or described herein.
[0028] In the embodiments of this application, the terms "module" or "unit" refer to a computer program or part of a computer program that has a predetermined function and works with other related parts to achieve a predetermined goal, and can be implemented wholly or partially using software, hardware (such as processing circuitry or memory), or a combination thereof. Similarly, a processor (or multiple processors or memory) can be used to implement one or more modules or units. Furthermore, each module or unit can be part of an overall module or unit that includes the functionality of that module or unit.
[0029] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this application belongs. The terminology used herein is for the purpose of describing embodiments of this application only and is not intended to limit this application.
[0030] Before providing a further detailed description of the embodiments of this application, the nouns and terms involved in the embodiments of this application will be explained, and the nouns and terms involved in the embodiments of this application shall be interpreted as follows.
[0031] 1) In response to, used to indicate the conditions or states on which the operation performed depends. When the conditions or states on which it depends are met, one or more operations performed may be performed in real time or with a set delay. Unless otherwise specified, there is no restriction on the order in which the multiple operations are performed.
[0032] This application provides a drawing processing method, apparatus, electronic device, computer-readable storage medium, and computer program product, which can improve the quality of line drawing. The following describes exemplary applications of the electronic device provided in this application. The electronic device provided in this application can be implemented as various types of terminals such as laptops, tablets, desktop computers, set-top boxes, portable music players, personal digital assistants, dedicated messaging devices, portable gaming devices, smartphones, smart speakers, smartwatches, smart TVs, in-vehicle terminals, augmented reality (AR) devices, virtual reality (VR) devices, and graphics tablets, or it can be implemented as a server. The following will describe exemplary applications when the device is implemented as a terminal.
[0033] See Figure 1 , Figure 1 This is a schematic diagram of the architecture of the drawing processing system 100 provided in the embodiment of this application. In order to support an exemplary application, the terminal (terminal 400-1 and terminal 400-2 are shown as examples) connects to the server 200 through the network 300. The network 300 can be a wide area network or a local area network, or a combination of the two.
[0034] In some embodiments, the terminal is equipped with a client with live streaming capabilities, such as a video playback client, instant messaging client, game client, or live streaming client. Server 200 is the backend server corresponding to the client. It can be an independent physical server, a server cluster or distributed system composed of multiple physical servers, or a cloud server providing basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communication, middleware services, domain name services, security services, content delivery networks (CDNs), and big data and artificial intelligence platforms. The terminal and server can be directly or indirectly connected via wired or wireless communication, which is not limited in this embodiment.
[0035] In practical applications, users trigger drawing operations through terminals. The terminal obtains the target point sequence of the drawing trajectory indicated by the drawing operation and sends the target point sequence to server 200. For any two adjacent first and second drawing points in the target point sequence, server 200 extends the original line segment between the first and second drawing points based on the brush radius to obtain the target line segment, and generates multiple sampling points with floating-point coordinates on the target line segment. For each sampling point among the multiple sampling points, the brush range and candidate range corresponding to the sampling point are determined based on the sampling point and the brush radius, and multiple candidate pixels falling within the candidate range are determined. Based on the distance from each candidate pixel to the target line segment, the target pixel falling within the brush range is selected from the multiple candidate pixels, and the target pixel is drawn based on the brush parameters. In this way, the lines between each drawing point in the target point sequence are drawn, and the drawing results are returned to the terminal for display.
[0036] See Figure 2 , Figure 2 This is a schematic diagram of the structure of the electronic device 500 provided in the embodiments of this application, with the electronic device 500 as an example. Figure 1 Taking the terminal in the middle as an example, Figure 2 The illustrated electronic device 500 includes at least one processor 510, a memory 550, at least one network interface 520, and a user interface 530. The various components in the electronic device 500 are coupled together via a bus system 540. It is understood that the bus system 540 is used to implement communication between these components. In addition to a data bus, the bus system 540 also includes a power bus, a control bus, and a status signal bus. However, for clarity, ... Figure 2 The general labeled all buses as Bus System 540.
[0037] The processor 510 can be an integrated circuit chip with signal processing capabilities, such as a general-purpose processor, a digital signal processor (DSP), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. The general-purpose processor can be a microprocessor or any conventional processor, etc.
[0038] Memory 550 may include volatile memory or non-volatile memory, or both. The non-volatile memory may be read-only memory (ROM), and the volatile memory may be random access memory (RAM). The memory 550 described in this application embodiment is intended to include any suitable type of memory. Memory 550 may optionally include one or more storage devices physically located away from processor 510.
[0039] In some embodiments, memory 550 is capable of storing data to support various operations, examples of which include programs, modules, and data structures or subsets or supersets thereof, as illustrated below.
[0040] Operating system 551 includes system programs for handling various basic system services and performing hardware-related tasks, such as framework layer, core library layer, driver layer, etc., for implementing various basic business functions and handling hardware-based tasks; network communication module 552 is used to reach other electronic devices via one or more (wired or wireless) network interfaces 520, exemplary network interfaces 520 include: Bluetooth, WiFi, and Universal Serial Bus (USB), etc.
[0041] In some embodiments, the drawing processing apparatus provided in this application can be implemented in software. The drawing processing apparatus provided in this application can be provided in various software embodiments, including various forms such as applications, software, software modules, scripts or code. Figure 2 A drawing processing device 555 stored in memory 550 is shown. It may be software in the form of programs and plug-ins, and includes a series of modules, including an acquisition module 5551, an extension module 5552, an acquisition module 5553, a filtering module 5554, and a drawing module 5555. These modules are logically connected and can therefore be arbitrarily combined or further divided according to the functions they implement. The functions of each module will be described below.
[0042] In other embodiments, the apparatus provided in this application can be implemented in hardware. As an example, the apparatus provided in this application can be a processor in the form of a hardware decoding processor, which is programmed to execute the drawing processing method provided in this application. For example, the processor in the form of a hardware decoding processor can be one or more application-specific integrated circuits (ASICs), digital signal processors (DSPs), programmable logic devices (PLDs), complex programmable logic devices (CPLDs), field-programmable gate arrays (FPGAs), or other electronic components.
[0043] In some embodiments, the terminal or server can implement the rendering processing method provided in this application by running various computer-executable instructions or computer programs. For example, computer-executable instructions can be microprogram-level commands, machine instructions, or software instructions. Computer programs can be native programs or software modules in an operating system; they can be native applications (APPs), i.e., programs that need to be installed in the operating system to run, such as instant messaging APPs or live streaming APPs; or they can be applets that can be embedded in any APP, i.e., programs that only need to be downloaded to a browser environment to run. In summary, the aforementioned computer-executable instructions can be any form of instruction, and the aforementioned computer programs can be any form of application, module, or plugin.
[0044] As mentioned above, the drawing processing method provided in this application embodiment can be implemented by various types of electronic devices, such as... Figure 1 Either the terminal or the server 200 can be executed independently, or it can be... Figure 1 The terminal and server 200 in the process work together. Next, it will be executed by... Figure 1 The following description uses an example of a terminal executing the drawing processing method provided in this application embodiment. See also... Figure 3 , Figure 3 This is a flowchart illustrating the drawing processing method provided in the embodiments of this application. Figure 1 , will combine Figure 3 The steps shown are explained.
[0045] In step 101, the terminal responds to the drawing operation by acquiring the sequence of target points of the drawing trajectory indicated by the drawing operation.
[0046] The target point sequence includes multiple points plotted using floating-point coordinates.
[0047] In some embodiments, the terminal may respond to a drawing operation and obtain a sequence of target points for the drawing trajectory indicated by the drawing operation in the following manner: in response to a drawing operation triggered by an input device, the terminal acquires multiple floating-point coordinates of drawing points for the drawing trajectory indicated by the drawing operation through the input device; the terminal arranges the multiple drawing points according to the acquisition time order to obtain an initial point sequence, and preprocesses the initial point sequence to obtain a target point sequence; wherein the preprocessing includes at least one of the following: filtering duplicate drawing points, smoothing jittering drawing points, and repairing broken drawing points.
[0048] In practical applications, the terminal establishes communication through the driver interface of the input device (graphics tablet, touch screen, etc.) to detect drawing operations. When the user triggers a drawing operation (such as the pen tip touching the graphics tablet, or a finger pressing the screen), the input device collects position data at a fixed frequency and directly outputs floating-point coordinates to retain sub-pixel accuracy. At the same time, it synchronously collects the timestamp of each coordinate point, forming an initial point sequence arranged according to the drawing time sequence. The terminal performs basic checks on the initial point sequence, such as removing invalid points with abnormal coordinate values (such as points outside the canvas area), filtering duplicate drawing points, smoothing jittery drawing points, and repairing broken drawing points, retaining valid drawing points to form the final input target point sequence.
[0049] For example, when a graphics tablet triggers the pen tip pressure sensor, it outputs floating-point coordinates (with an accuracy of 0.01 pixels) at a sampling frequency of 200-300Hz, simultaneously including pressure values (0-1024 levels) and microsecond-level timestamps. When a touchscreen device detects a finger's capacitive touch signal, it collects the contact point coordinates at a frequency of 120-180Hz, converting the raw integer data into floating-point numbers (e.g., (98.23, 245.67)) using a hardware algorithm to preserve sub-pixel details. A mouse device captures the position through pointer movement events, converts the output integer coordinates into floating-point format (e.g., (150.0, 300.0)), and adds timestamp information. During the data acquisition process, the terminal filters out outliers that exceed the canvas range (e.g., points with x-coordinates < 0 or > 1920 when the canvas resolution is 1920×1080) and those with sudden coordinate changes (single movement distance > 50 pixels) in real time, ensuring the validity of the acquired data.
[0050] The terminal constructs an initial point sequence for the collected valid drawing points, using timestamps as the core sorting criterion. For example, it extracts the collection timestamp 't' for each point and arranges the coordinate points in ascending order of 't' to form a continuous trajectory data chain. For multi-device collaborative drawing scenarios (such as simultaneously connecting a graphics tablet and a mouse), the terminal assigns a unique identifier to each device and adds a device identifier field to the sequence to ensure that point data from the same drawing operation is not mixed up. After the sequence is constructed, the terminal generates basic statistical information, including the point sequence length, coordinate range, and average sampling interval, providing a reference for subsequent preprocessing.
[0051] When preprocessing the drawing points in the initial point sequence, the Euclidean distance between two adjacent drawing points is calculated. If the Euclidean distance is ≤0.05 pixels (floating-point precision threshold) and the time difference is <5 milliseconds, it is determined to be a duplicate drawing point (such as consecutive identical coordinates caused by a brief pause of the pen tip), and only the first drawing point is retained. For mouse drawing scenarios, due to the low sampling frequency, the duplicate point determination threshold can be relaxed to 0.1 pixels to avoid accidentally deleting valid consecutive points. When smoothing jittery drawing points, a "three-point sliding window" algorithm is used. For three consecutive drawing points P1(x1,y1), P2(x2,y2), and P3(x3,y3) in the initial point sequence, when determining whether P2 is a jittery drawing point, the distance differences between P2 and P1, and between P2 and P3 are calculated as Δs1=√[(x2-x1)²+(y2-y1)²] and Δs2=√[(x3-x2)²+(y3-y2)²]. If the ratio of Δs1 to Δs2 is greater than the preset ratio (e.g., Δs1 = 0.2 pixels, Δs2 = 1.1 pixels, preset ratio is 5), then P2 is determined to be a jittery drawing point, and is updated to P2'(x = (x1 + x3) / 2, y = (y1 + y3) / 2) through linear interpolation; in professional drawing scenarios, Gaussian filtering (standard deviation σ = 0.3) can be superimposed to further smooth the trajectory, while retaining the key turning points of the lines. When repairing broken drawing points, the time difference Δt and distance difference Δs between two adjacent drawing points are analyzed. If Δt > 100 milliseconds (the user's short pause threshold) but Δs < 5r (r is the current brush base radius), it is determined to be a repairable break. In this case, transition points are supplemented by quadratic Bézier curve interpolation. For example, taking the last point before the break as the starting point and the first point after the break as the ending point, the midpoint of the line connecting the two points is taken as the control point to generate 3-5 transition floating-point coordinates to fill the trajectory gaps. If Δt > 500 milliseconds or Δs ≥ 10r, it is determined to be an active interruption, the break state is preserved and the break point position is marked.
[0052] Taking the drawing scenario provided in this application embodiment as a two-dimensional animation drawing (digital tablet input) as an example, when the animator uses a digital tablet to outline the character's hair, the digital tablet captures the pen tip position in real time through a 200Hz sampling rate, outputting a set of floating-point coordinates (such as (210.45, 156.82), (211.12, 157.36), (211.89, 157.91)) every 10 milliseconds, simultaneously including the pen tip pressure value (0-1024 levels) and a timestamp. After receiving the data, the terminal first removes invalid drawing points caused by slight pen tip lifting (such as drawing points with pressure values <10), and then sorts them by timestamp to form a sequence of target points. Since hair drawing requires delicate transitions, high-frequency floating-point sampling can completely preserve the subtle movement of pen tip offset of 0.1px, providing a foundation for the subsequent generation of smooth lines.
[0053] Taking the drawing scenario provided in this application embodiment as a mobile handwritten note (touchscreen input) as an example, when a user writes English words on the mobile phone screen with their finger, the touchscreen collects the coordinates of the finger contact point at a sampling rate of 120Hz and outputs position data in floating-point format (such as (89.3,245.6), (90.1,244.2), (91.5,242.8)). The terminal optimizes for accidental touch jumps that are prone to occur on the touchscreen. If the distance between two adjacent drawing points suddenly increases (such as jumping from 1.2 pixels to 8 pixels) and the time difference is <5 milliseconds, it is judged as an accidental touch and the point is removed; at the same time, coordinates that exceed the range of the note canvas (such as x < 0 or x > 1080 pixels) are filtered out, and finally a continuous handwriting trajectory point sequence (that is, the target point sequence) is formed to ensure that details such as letter hooks and strokes are completely reproduced.
[0054] Taking the drawing scenario provided in this application embodiment as desktop vector graphics editing (mouse + pressure-sensitive pen input) as an example, when a designer draws a curve on a tablet computer, the tablet computer, combined with the pressure-sensitive pen's 1024 levels of pressure sensitivity and 150Hz sampling rate, outputs three-dimensional data including coordinates, pressure, and timestamp (e.g., coordinates (345.78, 201.33), pressure value 680, timestamp 1698765420123). The terminal performs duplicate point filtering on this point sequence. If the coordinate deviation of three consecutive points is <0.05 pixels (the slight jitter when the pressure-sensitive pen is stationary), only the first point is retained to simplify the data volume. At the same time, the coordinates of the pressure value change nodes are retained to ensure the smooth transition of the curve and the requirement for line thickness changes corresponding to pressure.
[0055] Taking the online collaborative whiteboard (mouse input) as an example of the drawing scenario provided in this application embodiment, when a user drags the mouse to draw flowchart arrows in a remote meeting, the mouse outputs coordinate data with a sampling rate of 60Hz. The terminal converts integer coordinates (such as (150,300)) into floating-point numbers ((150.0,300.0)) in a unified format, and then supplements the coordinate points of the mouse movement gaps through linear interpolation (such as inserting (151.0,300.5) between (150.0,300.0) and (152.0,301.0)), forming a dense sequence of target points. This solves the problem of "jagged" arrow lines caused by low mouse sampling rate, and enables the floating-point coordinate sequence to simulate continuous drawing trajectory.
[0056] After preprocessing, the terminal outputs a sequence of target points containing floating-point coordinates, timestamps, device identifiers, and trajectory status (continuous / discontinuous), along with preprocessing logs (such as the number of filtered duplicate points and the number of smoothed jitter points), providing a clear data status reference for subsequent stages such as line segment extension and sampling point generation.
[0057] By employing the above methods, high-frequency floating-point data acquisition preserves sub-pixel details of the drawn trajectory from the source, adapting to the characteristics of different input devices and ensuring that both professional and general-purpose devices can output high-quality raw data. The ordered construction based on timestamps guarantees the temporal authenticity of the trajectory, while multi-dimensional preprocessing precisely solves the problems of repetition, jitter, and breakage during the drawing process—repetition filtering reduces subsequent computational redundancy, jitter point smoothing improves trajectory fluency, and breakage point repair avoids gaps in line connections. The final output target point sequence not only fully reproduces the user's drawing intent but also possesses high accuracy and low redundancy, laying a solid data foundation for achieving unbroken, high-precision wide-line drawing in subsequent stages of the algorithm. Simultaneously, it reduces the computational pressure of subsequent processes, balancing drawing quality and execution efficiency.
[0058] In step 102, for any two adjacent first and second drawing points in the target point sequence, the original line segment between the first and second drawing points is extended based on the brush radius to obtain the target line segment, and multiple sampling points with floating-point coordinates are generated on the target line segment.
[0059] In some embodiments, the brush radius can be determined as follows: when the input device for the drawing operation is equipped with a pressure sensor, the target pressure value of the pressure sensor when the drawing operation is triggered is determined; the brush radius is determined based on the preset mapping relationship between the pressure value and the radius, the base radius of the brush, and the target pressure value of the pressure sensor when the drawing operation is triggered.
[0060] In practical applications, the base radius is the baseline value for the brush radius. It can be preset in conjunction with the tool scenario and brush type to ensure that the base radius conforms to the user's usage habits. For example, when presetting the base radius of brushes according to their functions, in the animation coloring tool, a default base radius is set for different function brushes. For example, the base radius r_base of the brush used for line drawing (referred to as "line drawing brush") is 1.5 pixels (adapting to character outline drawing), the base radius r_base of the brush used for area filling (referred to as "filling brush") is 5 pixels (improving filling efficiency), and the base radius r_base of the brush used for detail refining (referred to as "detail brush") is 0.5 pixels (sufficient for fine drawing of hair strands, facial features, etc.). In addition, user-defined adjustments are also supported. For example, the tool provides a base radius adjustment slider, and users can modify the preset value within ±50% according to their drawing needs (such as adjusting the base radius of the line drawing brush from 1.5 pixels to 2 pixels). The adjusted value is stored as the personalized baseline value of the brush. The base radius is stored in floating-point format with a precision of 0.01 pixels to ensure the fineness of subsequent dynamic calculations.
[0061] In practical implementation, the brush radius can be precisely and dynamically generated by combining the characteristics of the input device (whether it has a pressure sensor) and the needs of the drawing scenario, making the brush strokes more closely resemble a realistic drawing experience. For example, if the input device is equipped with a pressure sensor, the brush radius can be dynamically adjusted based on the pressure value corresponding to the drawing operation. Specifically, the terminal establishes real-time communication with the pressure sensor through the input device driver interface. Throughout the entire process of the user triggering the drawing operation (the pen tip touching the graphics tablet), pressure values are collected at a frequency synchronized with coordinate acquisition (200-300Hz). The target pressure value P corresponding to each drawing point is obtained, and the pressure value range is uniformly mapped to an integer from 0 to 1024 (industry-standard). The collected pressure values are double-checked to remove abnormal values caused by input device jitter (such as a single pressure value fluctuation exceeding 100 and a duration of <5 milliseconds), filter low pressure values when the pen tip is lifted (P < 20, which is determined as drawing termination and not included in the radius calculation), and retain the valid target pressure value P_valid. The effective pressure value P_valid of each plotted point is bound to the floating-point coordinates (x, y) and timestamp to form a three-data set of "coordinate-pressure-time", which provides data support for subsequent point-by-point dynamic radius calculation.
[0062] The dynamic mapping mechanism between pressure value and radius is achieved by constructing a "non-linear mapping model" to accurately convert pressure value into radius increments, avoiding the problem of "no change with light pressure and abrupt change with heavy pressure" caused by linear mapping. Specifically, the mathematical model of the mapping relationship is based on the characteristic of real brushes that "light pressure results in slight thickening and heavy pressure results in slower acceleration." The non-linear mapping formula is designed as follows: r = r_base + (P_valid / P_max)² × r_range, where P_max = 1024 (maximum pressure range), (P_valid / P_max)² is the square value after normalization of pressure, making the influence of pressure on radius more ergonomic; r_range is the adjustable range of pressure, set according to brush type. For example, r_range = 2 pixels for line art brushes (radius reaches 1.5 + 2 = 3.5 pixels at maximum pressure), r_range = 8 pixels for fill brushes (maximum radius 13 pixels), and r_range = 0.8 pixels for detail brushes (maximum radius 1.3 pixels), avoiding uncontrolled effects due to pressure adjustment between different brushes.
[0063] In addition, upper and lower limits of the radius can be set to prevent extreme values, such as minimum radius r_min=0.3 pixels (to prevent the stroke from disappearing when the pressure is too low) and maximum radius r_max=r_base+r_range (to prevent the line from being too thick when the pressure is too high); when the pressure value changes from P1 to P2, the intermediate radius value is supplemented by linear interpolation to avoid uneven line thickness caused by abrupt changes in the radius of adjacent points.
[0064] For example, if an animator uses a line drawing pen (r_base=1.5 pixels, r_range=2 pixels) and the pressure value at a certain point is P_valid=512 (half range), then the brush radius corresponding to that point is r=1.5+(512 / 1024)²×2=1.5+0.5=2 pixels; when the pressure increases to 1024, r=1.5+1×2=3.5 pixels, achieving a natural transition from fine to coarse.
[0065] For input devices without pressure sensitivity, such as mice and ordinary touchscreens, the base radius of the brush can be directly used as the brush radius for line segment extension. Drawing speed correlation and scene mode matching can also replace pressure adjustment to ensure the rationality of the dynamic radius. The correlation rule between drawing speed *v* and brush radius is based on a mapping established according to the drawing speed *v* corresponding to the drawing operation. For example, when using a fast drag (*v* > 5 pixels / millisecond), the brush radius is increased by 20% from the base radius (e.g., the brush radius of a fill pen increases from 5 pixels to 6 pixels, improving smoothness); when using a slow, precise pen (*v* < 1 pixel / millisecond), the brush radius is reduced by 10% (e.g., the brush radius of a detail pen decreases from 0.5 pixels to 0.45 pixels, improving precision). For radius enhancement in scene modes, such as in the "handwriting input" scene, the brush radius is fixed at 80% of the base radius when drawing with a mouse to avoid uneven line thickness caused by speed fluctuations; in the "vector editing" scene, users can adjust the brush radius in real time using shortcut keys (e.g., holding down Ctrl + scroll wheel) to simulate pressure sensitivity.
[0066] Through the above methods, a dynamic radius determination mechanism—"basic radius sets the benchmark, pressure sensing makes adjustments, and scene adaptation compensates for differences"—breaks the limitations of fixed brush radii. For professional pressure-sensitive device users, non-linear pressure mapping allows the brush stroke thickness to change naturally with the pressure applied, restoring the controllable experience of a real brush, giving character line art layers of light and dark and detail variations. For ordinary device users, speed association and shortcut key adjustment achieve a substitute effect for dynamic radius, balancing ease of operation and drawing accuracy. At the same time, scene-based basic radius presets and user-defined functions meet the personalized adaptation needs of different drawing requirements, improving the creative efficiency and quality of professional animators while lowering the operating threshold for ordinary users, ensuring a high degree of match between brush effects and drawing intentions, and significantly enhancing the tool's practicality and artistic expression.
[0067] In some embodiments, see Figure 4 , Figure 4 This is a schematic flowchart of the line segment extension method provided in an embodiment of this application. Figure 3 In step 102, "extending the original line segment between the first and second drawing points based on the brush radius to obtain the target line segment" can be achieved through... Figure 4 Steps 1021-1022 shown are implemented as follows: In step 1021, the unit direction vector of the original line segment is determined based on the direction vector and length of the original line segment between the first drawing point and the second drawing point.
[0068] In practical applications, extending the line segment between two drawing points ensures that the endpoints of the line segment can cover the entire circular brush, while also resolving gaps between continuous line segments. The unit direction vector is the direction scale for the line segment extension, calculated based on the coordinate difference and length of the original line segment between the first and second drawing points, ensuring that the extension direction is consistent with the original line segment. Specifically, let the first drawing point be P1(x1,y1) and the second drawing point be P2(x2,y2) (both are floating-point coordinates). First, calculate the coordinate difference between the first and second drawing points on the x-axis and y-axis: dx=x2-x1, dy=y2-y1. The coordinate difference directly reflects the directional trend of the line segment. For example, dx=5.2 and dy=3.1 indicate that the line segment extends from P1 in the positive x-axis and positive y-axis directions.
[0069] Then, the length L of the straight line between P1 and P2 is calculated using the Euclidean distance formula, i.e., L = √(dx² + dy²). To avoid floating-point calculation errors, when L < 1e-6 (the line segments approximately coincide, such as when the user's pen tip pauses briefly), the unit direction vector is directly taken as (0,1) (the default upward direction) to prevent abnormal subsequent division operations.
[0070] Finally, divide the coordinate difference (dx, dy) by the line segment length L to obtain the unit direction vector v(vx, vy), with the formulas vx = dx / L and vy = dy / L. The characteristic of the unit direction vector is that its length is 1, retaining only direction information. For example, if we calculate vx = 0.85 and vy = 0.52, it indicates that the extended direction makes an angle of approximately 32° with the x-axis, ensuring that the extended line segment is completely consistent with the direction of the original line segment.
[0071] In step 1022, based on the unit direction vector and brush radius, the first drawing point is extended to the first extension point, the second drawing point is extended to the second extension point, and the line segment between the first extension point and the second extension point is determined as the target line segment obtained by extending the original line segment.
[0072] In practical applications, line segment extension needs to be done outwards from both ends of the original line segment. The extension length is determined by the brush radius r. For the first drawing point P1 (extending outwards from the starting point of the original line segment), the first extension point P1' is obtained by extending in the opposite direction of the unit direction vector, with the coordinate formula P1'(x1',y1')=(x1-vx×r,y1-vy×r). The reverse direction extension is achieved using a "minus sign" to ensure that the extended part is outside the original line segment P1, not inside the line segment. For the second drawing point P2 (extending outwards from the ending point of the original line segment), the second extension point P2' is obtained by extending in the positive direction of the unit direction vector, with the coordinate formula P2'(x2',y2')=(x2+vx×r,y2+vy×r). The positive direction extension is achieved using a "plus sign" to maintain consistency with the direction of the original line segment. Connecting the first extension point P1' and the second extension point P2' with a straight line yields the target line segment P1'P2'. The length of the target line segment is the original line segment length + 2×r, which not only covers the entire range of the original line segment, but also extends the length corresponding to the brush radius at both ends, providing a basis for generating complete circular endpoints in the future.
[0073] By using the above method and the progressive calculation of "coordinate difference - length - unit vector", the extension direction of the line segment is ensured to be completely consistent with the original line segment, avoiding pen stroke deformation caused by the offset of the extension direction. The floating-point coordinate calculation of the extension point retains sub-pixel precision, providing a precise line segment reference for subsequent sampling point generation and pixel selection. Ultimately, the drawn line endpoints are complete and the corners are natural, which fundamentally improves the visual integrity and accuracy of wide line drawing, and at the same time lays the foundation for the efficient execution of subsequent stages of the algorithm.
[0074] In some embodiments, a first drawing point can be extended to a first extension point based on a unit direction vector and a brush radius as follows: Based on the first drawing point, a second drawing point, and a third drawing point adjacent to the first drawing point, determine the curvature of the fitted curve corresponding to the first drawing point; determine the correspondence between a preset curvature and the extension length, and based on the correspondence, curvature, and brush radius, determine the target extension length corresponding to the first drawing point; extend the target extension length from the first drawing point along a direction opposite to that indicated by the unit direction vector to obtain the first extension point.
[0075] In practical applications, when extending each drawing point, to avoid over-extension or under-extension—for example, avoiding over-extension at sharp angles leading to bloated lines, or under-extension at gentle curves leading to breakpoints—the extension length can be dynamically adjusted in conjunction with curvature. Taking the extension of the first drawing point P1 as an example, the curvature is calculated by fitting a circular arc to the adjacent third drawing point P3 (the predecessor point of P1) and the second drawing point P2 (the successor point of P1), ensuring that the curvature accurately reflects the line turning characteristics at P1. When determining the curvature corresponding to the first drawing point, firstly, coordinate data is prepared: obtain the floating-point coordinates of the three points, let P3(x3,y3), P1(x1,y1), and P2(x2,y2). For example, in a real drawing scenario, the possible coordinates are P3(10.2,20.5), P1(12.8,21.3), and P2(15.4,23.6). Secondly, the parameters of the fitted arc are solved: the center O(ox, oy) and radius R of the arc are calculated using the principle of three points being concyclic. First, the equation of the perpendicular bisector is constructed: the midpoint of P3P1 is M1((x3+x1) / 2,(y3+y1) / 2), and the slope k1=(y1-y3) / (x1-x3). Therefore, the slope of the perpendicular bisector is the negative reciprocal of -k1. Similarly, the equation of the perpendicular bisector of P1P2 is obtained. The intersection of the two equations is the center O. Finally, curvature is calculated and corrected: curvature k=1 / R (R is the distance from the center O to P1, i.e., the radius of the arc). If R>100 pixels (approximately a straight line at P1), then k=0.05 (the threshold for a smooth curve); if the three points are collinear (the radius of the fitted arc is infinite), then k=0 is directly determined to ensure that there are no outliers in the curvature calculation. For example, if the center of the circle at P1 is calculated to be O(8.5, 18.2), and R = √[(12.8-8.5)² + (21.3-18.2)²] ≈ 5.3 pixels, then k = 1 / 5.3 ≈ 0.19, indicating that P1 is a turning point with moderate curvature.
[0076] When dynamically matching the target extension length based on curvature, a corresponding relationship between "curvature - extension coefficient" is preset. Combining the brush radius, the target extension length of the first drawing point is calculated to achieve the adaptation logic of "the greater the curvature, the shorter the extension": The preset corresponding relationship table divides the extension coefficient according to the curvature interval to ensure that the extension coefficient matches the line turning requirement. For example, when the curvature k ≤ 0.1, the curve corresponding to this drawing point is considered a gentle curve / straight line, and the extension coefficient is set to 1.0; when the curvature 0.1 < k ≤ 0.5, the curve corresponding to this drawing point is considered a medium - curvature turn, and the extension coefficient is set to 0.6 - 0.9; when the curvature k > 0.5, the curve corresponding to this drawing point is considered an acute - angle / fold - line turn, and the extension coefficient is set to 0.3 - 0.5. When calculating the target extension length, the formula L_ext = r × λ is used, where λ is determined by linear interpolation according to the actual value of k. For example, if the brush radius r = 3 pixels, and k = 0.19 at P1 (belonging to the interval 0.1 < k ≤ 0.5), it is calculated that λ = 0.9 - (0.19 - 0.1) / (0.5 - 0.1)×0.3 = 0.83. Therefore, L_ext = 3 × 0.83 ≈ 2.49 pixels; if k = 0.6 (acute - angle turn), then λ = 0.4, and L_ext = 3 × 0.4 = 1.2 pixels.
[0077] When extending the first drawing point, the unit direction vector of the original line segment formed by P1 and P2 is used for deviation, ensuring that the extended part is consistent with the line trend. Among them, when solving the unit direction vector, the direction vector v=(x2 - x1, y2 - y1) from P1 to P2 is calculated and normalized to the unit direction vector v_unit=(vx, vy). For example, when P1(12.8, 21.3) and P2(15.4, 23.6), v=(2.6, 2.3), v_unit≈(0.75, 0.66); the unit direction vector is reversed to obtain the extended direction vector v_ext=(-vx, -vy) deviating from P2, that is, the extended direction is completely opposite to the direction from P1 to P2; the coordinates of P1' are calculated through the extended direction and the target extension length, and the formula is P1'(x1', y1')=(x1 + v_ext.x×L_ext, y1 + v_ext.y×L_ext). Combining the above example, v_ext=(-0.75, -0.66), L_ext≈2.49 pixels, then x1' = 12.8+(-0.75)×2.49≈10.9, y1' = 21.3+(-0.66)×2.49≈19.6, that is, P1'≈(10.9, 19.6), completing the precise extension of P1.
[0078] It can be understood that when extending the second drawing point, the extension direction of the second drawing point is the same as the direction indicated by the unit direction vector from P1 to P2, that is, the extension direction of the second drawing point is exactly the same as the direction from P1 to P2.
[0079] By employing the above method and the logic of "three-point fitting to calculate curvature - curvature matching extension coefficient - precise directional extension," the extension length of the drawing points is highly adapted to the line's turning characteristics: a larger extension length is used at gentle curves to ensure the brush endpoints are complete and without breaks; the extension is appropriately shortened at medium curvature turns to balance line connection and smoothness; and the extension is significantly reduced at sharp-angle turns, completely avoiding the "bulge" distortion problem at corners caused by traditional uniform extension. Simultaneously, floating-point coordinates and precise calculations ensure that the positional error of the extension points is ≤0.1 pixels, providing a high-quality line segment foundation for subsequent sampling point generation and pixel selection. This ensures that the drawn lines maintain a uniform width and clear outline in various turning scenarios, significantly improving the accuracy and naturalness of wide line drawing.
[0080] In some embodiments, see Figure 5 , Figure 5 This is a schematic diagram of the sampling method provided in the embodiments of this application. Figure 3 The step 102 shown, "generating multiple floating-point sampling points on the target line segment," can be achieved through... Figure 5 Steps 1023-1025 shown are implemented as follows: In step 1023, the number of sampling steps to be performed on the target line segment is determined based on the difference in lateral and longitudinal coordinates between the second extension point and the first extension point.
[0081] In practical applications, the number of sampling steps directly determines the sampling point density. It is necessary to combine the length characteristics of the target line segment, user drawing behavior, and line trend for comprehensive calculation to ensure that the density matches the requirements of accuracy and efficiency.
[0082] In some embodiments, the number of sampling steps for sampling on the target line segment can be determined based on the lateral and longitudinal coordinate differences between the second extension point and the first extension point as follows: the maximum coordinate difference between the lateral and longitudinal coordinate differences between the second extension point and the first extension point is determined; the ratio of the distance difference between the first drawing point and the second drawing point to the time difference is determined as the drawing speed, and the curvature of the fitted curve between the first drawing point and the second drawing point is determined; the number of sampling steps for sampling on the target line segment is determined based on the maximum coordinate difference, the drawing speed, and the curvature, wherein the number of sampling steps is negatively correlated with the drawing speed and positively correlated with the curvature.
[0083] As an example, let the first extension point be P1'(x1',y1') and the second extension point be P2'(x2',y2'). Calculate the horizontal coordinate difference ΔX=x2'-x1' and the vertical coordinate difference ΔY=y2'-y1'. Take the maximum absolute value of the two as the maximum coordinate difference ΔMax=max(|ΔX|,|ΔY|). This value reflects the effective length of the target line segment and provides a basis for the basic number of steps. When solving the drawing speed, call the behavioral feature data corresponding to the drawing operation, and take the ratio of the distance difference ΔS (i.e., the original line segment length) between the first drawing point P1 and the second drawing point P2 to the time difference ΔT to obtain the drawing speed v=ΔS / ΔT, with the unit being pixels / millisecond. This is used to distinguish between fast dragging (e.g., v>5 pixels / millisecond) and slow fine drawing (e.g., v<1 pixel / millisecond). When obtaining curvature, the curvature k of the line at P1 calculated by the above three-point fitting (P3-P1-P2, where P3 is the previous adjacent point of P1) is reused. This value reflects the turning characteristics of the line and distinguishes between gentle curves (such as k<0.1) and high curvature acute angles (such as k>0.5).
[0084] The dynamic calculation model for sampling steps is based on a pre-established step calculation rule that integrates "length-speed-curvature". The formula is: sampling steps = max(ΔMax×(1+α×k-β×v), min_steps), where α=0.8 (curvature weight), the larger the curvature, the more significant the increase in steps, ensuring dense sampling at acute angles; β=0.3 (speed weight), the faster the speed, the more reasonable the decrease in steps, avoiding overly dense sampling when dragging the pen quickly; min_steps=5 (minimum sampling steps), preventing insufficient steps for short line segments due to ΔMax being too small, ensuring basic sampling accuracy.
[0085] For example, if P1'(10.9,19.6) and P2'(17.9,25.1), then ΔX=7.0, ΔY=5.5, and ΔMax=7.0; ΔS=6.05 pixels and ΔT=12 milliseconds for P1 and P2, and v=6.05 / 12≈0.5 pixels / millisecond (corresponding to slow fine drawing); k=0.19 at P1 (medium curvature), then the number of steps is steps=7.0×(1+0.8×0.19-0.3×0.5)=7.0×(1+0.152-0.15)=7.0×1.002≈7, so steps=7 (satisfying the min_steps requirement).
[0086] In the above manner, by integrating the target line segment length feature (maximum coordinate difference), the user's drawing behavior (drawing speed), and the line trend (curvature) to determine the sampling steps, dynamic intelligent adaptation of the sampling density is achieved: the maximum coordinate difference ensures a basic match between the sampling steps and the line segment length, avoiding over-dense sampling for short line segments or insufficient sampling for long line segments; the negative correlation design between the drawing speed and the sampling steps enables automatic reduction of the sampling steps when dragging the pen quickly to ensure drawing real-time performance, and increases the sampling steps when drawing precisely and slowly to retain line details; the positive correlation design between the curvature and the sampling steps makes the sampling in high-curvature corner / folding line regions denser, effectively avoiding line distortion caused by sparse sampling, and moderately reducing sampling in gentle curve regions to reduce redundant calculations. The overall solution not only balances the drawing accuracy and the algorithm execution efficiency, but also makes the distribution of sampling points highly consistent with the actual drawing requirements, providing high-quality basic data for the subsequent pixel screening and drawing processes, and ultimately improving the smoothness, accuracy, and visual effect consistency of wide line drawing.
[0087] In step 1024, the ratio of the horizontal coordinate difference to the sampling steps is used as the horizontal increment for each sampling step, and the ratio of the vertical coordinate difference to the sampling steps is used as the vertical increment for each sampling step.
[0088] Here, the increment calculation needs to ensure that the sampling points are evenly distributed along the target line segment. By obtaining the ratio of the coordinate difference to the sampling steps, the exact increment for each step of movement can be obtained. For example, the horizontal increment dx_step = (x2' - x1') / steps, which is the moving distance of each sampling step in the x-axis direction, and the floating-point precision is retained to avoid cumulative errors; the vertical increment dy_step = (y2' - y1') / steps, which is similarly the moving distance of each step in the y-axis direction. If x2' < x1', then dx_step is negative, and the sampling points move along the negative x-axis direction, ensuring that the increment direction is consistent with the target line segment trend. Continuing with the above example, x2' - x1' = 7.0, y2' - y1' = 5.5, steps = 7, then dx_step = 7.0 / 7 = 1.0, dy_step = 5.5 / 7 ≈ 0.7857.
[0089] In step 1025, starting from the first extension point on the target line segment, the horizontal increment and the vertical increment are accumulated step by step until the second extension point for sampling, generating sampling points with a target number of floating-point coordinates. The target number is the sampling steps plus 1.
[0090] For the point-by-point generation of floating-point sampling points, starting from the first extension point, sampling points are generated incrementally to ensure that the point sequence covers the entire target line segment and is evenly distributed. For example, starting from the first extension point P1', the coordinate formula of the i-th sampling point (i from 0 to steps) is: x_i=x1'+i×dx_step, y_i=y1'+i×dy_step, where i=0 is P1', i=steps is P2', and the target number is steps+1 (covering both ends of the line segment).
[0091] It should be noted that all sampling point coordinates can be retained to 4 decimal places to avoid floating-point arithmetic errors causing the sampling points to deviate from the target line segment. Continuing with the previous example, the sampling points are i=0: (10.9, 19.6), i=1: (11.9, 20.3857), i=2: (12.9, 21.1714)...i=7: (17.9, 25.1), a total of 8 sampling points, evenly covering the target line segment.
[0092] By employing the above methods, the maximum coordinate difference ensures that the number of sampling steps matches the line segment length. Combined with the dynamic adjustment of drawing speed and curvature, a precise match is achieved: "slow-speed fine drawing with high-density sampling to preserve details, fast-speed dragging with low-density sampling to improve efficiency, and high-curvature sampling with increased density to prevent distortion." The floating-point increment and point-by-point generation rules ensure that the sampling points are evenly distributed along the target line segment without significant offset or uneven density. This provides a continuous and accurate reference benchmark for subsequent pixel selection, which not only improves the accuracy and smoothness of line rasterization but also reduces redundant calculations through on-demand sampling, achieving the optimal balance between drawing quality and algorithm efficiency.
[0093] In step 103, for each of the multiple sampling points, the brush range and candidate range corresponding to the sampling point are determined based on the sampling point and the brush radius, and multiple candidate pixels falling within the candidate range are determined.
[0094] In some embodiments, the brush range and candidate range corresponding to a sampling point can be determined based on the sampling point and the brush radius as follows: a circular area centered on the sampling point and with the brush radius as its radius is determined as the brush range corresponding to the sampling point; a square area centered on the sampling point and with half the brush radius as its side length is determined as the candidate range, and the brush range is included within the candidate range.
[0095] In practical applications, determining the brush range and candidate range is the core prerequisite for pixel selection. It is necessary to take into account both the requirements of "accurate brush shape reproduction" and "efficient selection of candidate pixels". The precise matching of the two is achieved through geometric definition and parameter constraints, as follows: The brush range is the core area of the pixels to be drawn in the end. A circular area is constructed with the sampling point as the center and the brush radius r as the radius. Let the sampling point coordinates be (x0, y0) (floating-point numbers, such as (125.32, 89.76)), and the brush radius r be a dynamically calculated effective value (such as 2.3 pixels obtained by combining pressure sensing). Then the mathematical expression for the brush range is: (px-x0)²+(py-y0)²≤r², where (px, py) are pixel coordinates. This circular area matches the shape of the real brush, ensuring that the target pixels selected later can accurately restore the brush outline. At the same time, considering the difference in floating-point precision, in order to avoid missing boundary pixels, a relaxed threshold is used in the actual calculation. The above inequality can be adjusted to (px-x0)²+(py-y0)²≤r²+1e-6, ensuring that boundary pixels at a distance of exactly r are included in the range.
[0096] The candidate range is a transitional region set to narrow down the pixel selection range. An axis-aligned square region is constructed with the sampling point as the center and the brush radius r as half the side length. The left boundary is x_min=x0-r, the right boundary is x_max=x0+r, the lower boundary is y_min=y0-r, and the upper boundary is y_max=y0+r. That is, the candidate pixel point (px,py) must satisfy x_min≤px≤x_max and y_min≤py≤y_max. The diagonal length of this square is 2r√2≈2.828r, which can completely wrap the circular brush range with radius r. That is, the distance from the midpoint of the four sides of the square to the sampling point is r (equal to the brush radius), and the distance from the four corners to the sampling point is r√2 (greater than the brush radius). This ensures that the brush range is completely contained within the candidate range without excessively expanding the candidate region and causing invalid calculations.
[0097] Understandably, the parameters of the brush range and candidate range are dynamically linked to the sampling point coordinates and brush radius to ensure adaptation to different drawing scenarios. The floating-point coordinates of the sampling point are directly used as the center reference of the two ranges to avoid center offset caused by coordinate transformation and ensure accurate correspondence between the brush range and the sampling point. When the brush radius r is dynamically adjusted through pressure sensing (e.g., from 1.5 pixels to 3 pixels), the boundaries of the two ranges will scale synchronously to always maintain the geometric relationship of "square enclosing circle".
[0098] By combining a circular brush area with a square candidate area, a perfect balance between drawing accuracy and filtering efficiency is achieved. The circular brush area precisely matches the actual brush shape, providing accurate geometric basis for subsequent pixel drawing and avoiding line distortion caused by brush deformation. The square candidate area quickly locks in potential effective pixels with clear boundaries, reducing the range of pixels requiring distance calculation from the entire canvas to a square with a side length of 2r, improving filtering efficiency by more than 90%. At the same time, because the square completely encloses the circle, it ensures that no effective pixels are missed. This solves the problem of low efficiency caused by directly traversing the canvas and avoids the shortcomings of a single area in balancing accuracy and efficiency, laying an efficient and accurate foundation for the subsequent pixel determination process.
[0099] In some embodiments, multiple candidate pixels falling within the candidate range can be determined as follows: determining the horizontal difference and horizontal sum between the horizontal coordinate value of the sampling point and the brush radius, and the vertical difference and vertical sum between the vertical coordinate value of the sampling point and the brush radius; determining multiple horizontal integer coordinate values located between the horizontal difference and the horizontal sum, and multiple vertical integer coordinate values located between the vertical difference and the vertical sum; and filtering out multiple candidate pixels in the candidate range based on the multiple horizontal integer coordinate values and the multiple vertical integer coordinate values.
[0100] In practical applications, after determining the brush range and candidate range, the terminal first quickly filters out a preliminary set of candidate pixels based on the integer boundaries of the candidate range. Since the boundary coordinates (x_min, x_max) of the candidate range are floating-point numbers and the pixel coordinates are integers, they need to be converted to integers to match the integer coordinate characteristics of the pixels, ensuring that all pixels that may contain the brush range are covered. In the horizontal direction, x_min is rounded down to obtain x_min_int = floor(x_min) (e.g., 212.92 is rounded down to 212), and x_max is rounded up to obtain x_max_int = ceil(x_max) (e.g., 218.52 is rounded up to 219). This filters out all horizontal integer coordinate values within the interval [x_min_int, x_max_int] (e.g., 212, 213, 214, 215, 216, 217, 218, 219). Similarly, in the vertical direction, y_min is rounded down to y_min_int and y_max is rounded up to y_max_int, resulting in all vertical integer coordinate values within the interval [y_min_int, y_max_int]. This ensures that all integer coordinate pixels that may contain brush area pixels are included in the candidate range, avoiding the omission of valid pixels due to boundary truncation. If x_min_int = x_max_int or y_min_in = y_max_int (such as when the brush stroke r = 0.5 pixels), then retain this single integer coordinate to ensure that boundary pixels are not lost.
[0101] Using the floating-point coordinates of the sampling points as a reference, the horizontal and vertical boundaries of the candidate range are calculated in conjunction with the dynamic brush radius. Let the sampling point coordinates be (x0, y0) (e.g., (215.72, 138.45) collected by the graphics tablet in the animation scene), and the current dynamic brush radius be r (e.g., 2.8 pixels obtained by combining pressure sensing). In the horizontal direction, calculate the horizontal difference x_min = x0 - r (left boundary of the candidate range) and the horizontal sum x_max = x0 + r (right boundary of the candidate range); in the vertical direction, calculate the vertical difference y_min = y0 - r (lower boundary of the candidate range) and the vertical sum y_max = y0 + r (upper boundary of the candidate range). During the calculation, floating-point precision is preserved (e.g., x_min = 215.72 - 2.8 = 212.92, x_max = 215.72 + 2.8 = 218.52) to avoid missing valid pixels due to boundary truncation.
[0102] It should be noted that when the brush radius r changes dynamically with the pressure value (e.g., from 2.8 pixels to 3.5 pixels), x_min, x_max, y_min, y_max and the corresponding integer coordinate range need to be recalculated in real time to ensure that the candidate range is synchronized with the brush size. For cases where the sampling point coordinates are close to the edge of the canvas (e.g., when x0=1.2 pixels, r=2 pixels, x_min_int=-1), the boundary coordinates are forcibly corrected to the effective range of the canvas (e.g., x_min_int=0) to avoid invalid coordinates from participating in subsequent calculations.
[0103] Then, an initial candidate pixel set is generated by combining the Cartesian products of the horizontal and vertical integer coordinates. This involves traversing all pixels in the canvas with coordinates within [x_min_int, x_max_int] × [y_min_int, y_max_int] to form the initial candidate set. The coordinates (px, py) of each candidate pixel in the initial candidate set satisfy px ∈ [x_min_int, x_max_int] and py ∈ [y_min_int, y_max_int]. For example, when the horizontal integer coordinates are 212~219 and the vertical integer coordinates are 135~141, the set of pixels (212, 135), (212, 136), ..., (219, 141) is generated. After generating the initial candidate set, basic validity checks are performed, such as removing pixels that exceed the canvas range (e.g., pixels with px < 0 or px ≥ 1920 when the canvas resolution is 1920 × 1080) and duplicates that have been marked as processed overlapping pixels, forming the final candidate pixel list.
[0104] By employing the above method, the integrity of the candidate range is ensured through floating-point boundary calculations, and the potential effective pixels are precisely locked in by integer processing. This avoids the inefficiency caused by directly traversing the canvas and prevents the omission of boundary pixels. The independent filtering and combination generation logic of horizontal and vertical coordinates is clear and adaptable to special scenarios such as dynamic changes in brush radius and canvas boundaries. The generated candidate pixel set has the characteristics of "precise range" and "concise quantity", laying an efficient foundation for further filtering of target pixels. While ensuring drawing accuracy, it significantly reduces the computational burden of the algorithm and improves the real-time response performance in the animation drawing process.
[0105] In step 104, based on the distance from each candidate pixel to the target line segment, target pixels that fall within the brush range are selected from multiple candidate pixels, and the target pixels are drawn based on the brush drawing parameters.
[0106] In some embodiments, the terminal can filter target pixels falling within the brush range from multiple candidate pixels based on the distance from each candidate pixel to the target line segment in the following manner: for each candidate pixel among multiple candidate pixels, the distance between the candidate pixel and the projection point of the candidate pixel on the target line segment is determined as the distance from the candidate pixel to the target line segment; and candidate pixels whose distance does not exceed the brush radius are selected from multiple candidate pixels as target pixels falling within the brush range.
[0107] In practical applications, for any sampling point S(x0,y0), after initially filtering out the pixel set M1 through the candidate range (a square with a side length of 2r) of the sampling point S(x0,y0), the target pixel can be directly selected from the pixel set M1. For example, the distance between the candidate pixel in the pixel set M1 and the projection point of the candidate pixel on the target line segment can be obtained, and the candidate pixel in the pixel set M1 with a distance not exceeding the brush radius can be selected as the target pixel falling within the brush range.
[0108] Furthermore, to further improve the computational efficiency of the algorithm, an elliptical filtering equation can be established with the current sampling point S(x0,y0) as the center and the brush radius r as the major and minor semi-axis (i.e., a circle that perfectly matches the brush shape): [(px-x0) / r]²+[(py-y0) / r]²≤1.2, where 1.2 is the fault tolerance coefficient to avoid missing valid pixels at the boundary due to floating-point calculation errors. After initially filtering out the pixel set M1 through the candidate range of the sampling points (a square with a side length of 2r), each pixel (px,py) in M1 is substituted into the elliptical equation, and pixels that do not satisfy the equation (such as pixels located in the corner of the square) are removed to obtain a simplified candidate pixel set M11. The target pixel is then selected from the candidate pixel set M11. This step can reduce the number of candidate pixels, thereby reducing the pressure of subsequent accurate calculations.
[0109] For the candidate pixel set M11 after elliptical pre-screening, the projection distance from each candidate pixel in M11 to the target line segment is calculated to accurately determine whether the candidate pixel falls within the brush range. Specifically, let the two endpoints of the target line segment be the first extension point P1'(x1',y1') and the second extension point P2'(x2',y2'). The line segment is parameterized into a vector form: P(t)=P1'+t×(P2'-P1'), where P(t) is a point on the line segment when t∈[0,1]; when t<0, the projection point is outside P1', and when t>1, the projection point is outside P2'. For any candidate pixel P(px,py) in M11, calculate vectors P1'P=(px-x1',py-y1') and P1'P2'=(x2'-x1',y2'-y1'). Calculate parameter t using the dot product: t=(P1'P·P1'P2') / |P1'P2'|², where "·" represents the dot product operation and |P1'P2'| is the length of the target line segment. Determine the projection point P_ based on the t value for each scene. `proj(x_proj,y_proj)`: When t∈[0,1], the projection point is on the line segment, `P_proj=(x1'+t×(x2'-x1'),y1'+t×(y2'-y1'))`; when t<0, the projection point is the starting point P1' of the line segment, i.e., `P_proj=(x1',y1')`; when t>1, the projection point is the ending point P2' of the line segment, i.e., `P_proj=(x2',y2')`. The distance from the candidate pixel P to the projection point P_proj is calculated using the Euclidean distance formula: `d=√[(px-x_proj)²+(py-y_proj)²]`. This distance is the perpendicular distance from the pixel to the target line segment. If `d≤r` (where `r` is the current dynamic brush radius), the candidate pixel is determined to be the target pixel and included in the drawing range; if `d>r`, it is directly discarded.
[0110] Through the above approach, a perfect balance between efficiency and accuracy is achieved via a dual mechanism of "elliptical pre-screening + precise projection distance judgment": Elliptical pre-screening, based on the circular characteristics of the brush, accurately eliminates invalid pixels within the square candidate range, significantly reducing the computational load of subsequent distance calculations, enabling the algorithm to maintain high efficiency even in fine-grained drawing scenarios with dense sampling points; the distance calculation based on projection points ensures accurate distance calculations from each candidate pixel to the target line segment through parameterized line segment and vector dot product operations, avoiding brush range distortion caused by distance judgment deviations. Furthermore, secondary verification rules for overlapping areas further guarantee the drawing accuracy at line junctions. The entire screening process adapts to the characteristics of dynamic brush radius and floating-point coordinates, and reduces redundant calculations through staged screening, providing a high-quality target pixel set for subsequent pixel output. This results in wide lines that are both clear in outline and free of edge distortion, while also meeting the real-time requirements of different devices.
[0111] In some embodiments, after determining multiple candidate pixels falling within the candidate range, when the distance between adjacent first and second sampling points among the multiple sampling points is less than twice the brush radius, it is determined that there is an overlapping target range in the first candidate range of the first sampling point and the second candidate range of the second sampling point; the candidate pixels falling within the target range selected based on the first sampling point and the candidate pixels falling within the target range selected based on the second sampling point are merged.
[0112] In practical applications, for each sampling point, after identifying multiple candidate pixels falling within the candidate range corresponding to that sampling point, overlapping scenes can be locked by spacing determination, and duplicate candidate pixel sets can be merged to reduce redundant calculations. Specifically, the spacing between adjacent sampling points is first calculated: the floating-point coordinates of the first adjacent sampling point S1(x1,y1) and the second adjacent sampling point S2(x2,y2) on the target line segment are obtained, and the spacing between the two points D=√[(x2-x1)²+(y2-y1)²] is calculated using the Euclidean distance formula. At the same time, the current dynamic brush radius r (e.g., 2.5 pixels obtained by combining pressure sensing) is extracted, and the overlap determination threshold is set to 2r (i.e., 5 pixels). When D<2r, it is determined that the candidate ranges of the two points overlap (because each candidate range is a square with a side length of 2r, an overlapping area will inevitably occur when the spacing is less than 2r); when D≥2r, the candidate ranges do not overlap and are processed independently according to the original rules. For example, S1(100.3,80.5) and S2(102.1,81.8) are calculated to have D≈2.2 pixels <5 pixels, which is determined to be an overlapping scene.
[0113] Then, determine the overlapping target range: obtain the first candidate range of S1 (square boundary x1_min=x1-r, x1_max=x1+r, y1_min=y1-r, y1_max=y1+r) and the second candidate range of S2 (boundary x2_min=x2-r, x2_max=x2+r, y2_min=y2-r, y2_max=y2+r). The target range is the intersection region of the two squares, and its boundary is determined by taking the extreme values of the corresponding boundaries of the two ranges: x_over_min=max(x1_min,x2_min), x_over_max=min(x1_max,x2_max), y_over_min=max(y1_min,y2_min), y_over_max=min(y1_max,y2_max). If x_over_min > x_over_max or y_over_min > y_over_max, then there is no effective overlap (this may occur in special cases when the spacing is close to 2r), and there is no need to merge; otherwise, a complete overlapping target range is formed.
[0114] Then, the candidate pixel merging process within the target range is performed: First, candidate pixel sets M1 (coordinates satisfying x_over_min≤px≤x_over_max and y_over_min≤py≤y_over_max) and M2 (candidate pixel sets M2) within the target range of S1 are selected. Deduplication and merging operations are then performed on M1 and M2: a pixel coordinate hash table is constructed, storing all pixel coordinates in M1 as keys; pixels in M2 are traversed, and if the coordinates already exist in the hash table, they are directly removed (to avoid duplication); if they do not exist, they are added to the hash table. Finally, the pixels in the hash table form the merged candidate pixel set M_over. Simultaneously, each pixel in M_over is marked with a dual-attribute identifier, recording its corresponding sampling point identifiers in S1 and S2, providing a basis for subsequent distance determination.
[0115] Finally, the efficient processing strategy for merged pixels is as follows: For the merged M_over, distance determination is no longer performed separately through S1 and S2. Instead, a "one-time determination, precise matching" strategy is adopted, that is, the distance d from each pixel (px, py) to the target line segment is calculated (reusing the line segment distance calculation result, without associating individual sampling points). If d ≤ r, it is included as a target pixel. At the same time, the non-overlapping areas in the original M1 and M2 are still independently filtered and processed according to the original rules. For example, for the pixel (101.2, 81.0) in M_over, its distance to the target line segment is calculated. If d = 1.8 pixels ≤ 2.5 pixels, it is directly determined as a target pixel, without having to repeatedly calculate the distance from this pixel to S1 and S2.
[0116] By employing the above method and the logic of "spacing threshold determination - overlapping range extraction - pixel deduplication and merging", the scene that needs to be merged is accurately identified, effectively solving the problem of repeated calculations caused by overlapping candidate ranges of adjacent sampling points. At the same time, the merged pixels are determined by directly associating them with the distance of the target line segment, avoiding the judgment deviation that may occur when relying on a single sampling point, and ensuring the pixel selection accuracy in the middle area of the line. In addition, the hash table deduplication and dual-attribution identifier design not only ensure the merging speed, but also provide a clear data association for subsequent distance calculations, achieving a dual improvement in efficiency and accuracy, especially suitable for fine drawing scenarios with dense sampling points.
[0117] In some embodiments, before drawing target pixels based on brush parameters, the terminal may determine brush parameters in the following ways: in response to a brush preset operation, determine the brush parameters set by the brush preset operation instruction; or, perform brush matching based on the drawing scene of the drawing operation to obtain brush parameters adapted to the drawing scene; wherein, the brush parameters include at least one of the following: brush color, brush hardness, brush transparency, brush texture, and brush edge characteristics.
[0118] In practical applications, after selecting the target pixel corresponding to each sampling point, the pixel can be drawn by combining the brush parameters, such as adjusting the pixel color according to the brush texture template (such as the brightness fluctuation of the pencil texture), and setting the transparency according to the edge mode (soft edge mode α=1-(d / r)); at the same time, the associated sampling point identifier, distance d and other data of the target pixel are output to the frame buffer along with the color information to complete the drawing or rendering of the target pixel.
[0119] Drawing parameters can be customized in response to preset brush operations (i.e., user-defined method one), or intelligently matched based on the drawing scenario (corresponding to method two). Method one: The terminal provides a visual brush parameter configuration interface, allowing users to actively define brush characteristics through clicks, swipes, and selections. The setting logic and interaction methods for each brush parameter are as follows: Basic visual parameter settings: Brush color supports methods such as "direct color picking with a color picker," "RGB value input," and "preset color selection." For example, when an animator draws character skin, they can use a color picker to sample the reference skin color next to the line art (RGB: 252, 228, 214). Brush transparency is adjusted via a 0-100% slider, combined with a real-time preview window to display the overlay effect. For example, when drawing character shadows, setting the transparency to 30% achieves a sense of transparency. Brush hardness is related to edge blur; 100% hardness corresponds to a completely hard edge (no edge transition), and 0% hardness corresponds to a completely soft edge (edge blur range reaches 50% of the brush radius), meeting different needs for line art (high hardness) and blending (low hardness). Texture and Characteristic Parameter Settings: Brush textures offer a "Preset Template Library" and "Custom Import" function. The template library includes professional types such as pencil (texture grain density 50%), watercolor (diffusion 30%), and marker (uniform texture). Users can adjust the texture size using the scaling slider. Brush edge characteristics support one-click switching between hard, soft, and jagged edges, and also provide a fine-tuning option for "edge blur radius" (e.g., 0-2 pixels). For example, in hand-drawn scenes, the edge blur radius of jagged edges can be set to 0.5 pixels to simulate the realistic paper and pen friction effect. After setting, users can save parameter combinations by name (e.g., "Character Line Art Pen," "Skin Shadow Pen," etc.) and recall them with one click from the brush list the next time they are used. The brushes automatically remember the most recently used brush parameter sets, improving operational efficiency.
[0120] Method 2: The terminal has a built-in "scene-parameter" mapping model. By recognizing the current drawing scene, it automatically matches the optimal brush parameters without requiring manual settings by the user, adapting to lightweight usage needs. The specific matching rules are as follows: The drawing scene is determined in two ways: First, based on the tool's built-in mode selection (such as the user's drawing operation instruction switching to "animation coloring," "handwritten notes," or other drawing modes); second, through intelligent judgment based on initial drawing characteristics. For example, if the drawing operation instruction is to draw short lines continuously with dense corners, it is determined to be a "line drawing" scene; if the drawing operation instruction is to continuously color a large area, it is determined to be a "region filling" scene. Then, the drawing parameters are matched based on the drawing scene to obtain the drawing parameters adapted to the corresponding drawing scene.
[0121] For example, for animation line art: match the brush color to dark gray (RGB: 30,30,30), hardness 100%, transparency 100%, pencil texture (grain density 30%), and hard edge characteristics to ensure clear and sharp lines for easy subsequent coloring; for handwritten notes (mobile): match the brush color to black, hardness 80%, transparency 90%, no texture, and slightly soft edges (edge blur radius 0.2 pixels) to balance writing clarity with a soft screen display; for children's doodles: match high-saturation colors (random initial color), hardness 50%, transparency 80%, cartoon textures (such as dots, stripes), and jagged edges to meet the fun needs of children's creations; for professional illustration: match an adjustable color palette (default warm colors), hardness 60%, transparency that changes with pressure (the greater the pressure, the lower the transparency), watercolor texture (diffusion 40%), and soft edge characteristics to enhance the artistic expression of the illustration.
[0122] It's important to note that the brush parameters obtained through intelligent matching are not fixed. Users can fine-tune these parameters and record their preferences. Subsequent matching within the same drawing scene will automatically incorporate these preferences, combining intelligent matching with personalized adaptation. When both user-preset operations and scene matching are present, the user-preset priority is followed, and the brush parameters from the user-preset operation are used to draw the target pixels. When there is a correlation between the user-preset operation and the scene-matched brush parameters, such as when the brush hardness is reduced, the edge blur radius is automatically adjusted according to "blur radius = brush radius × (1 - hardness / 100%)", ensuring logical consistency of the parameters. In input devices embedded with pressure sensors, parameters such as transparency and radius can be correlated with pressure values, creating a linkage effect of "the greater the pressure, the larger the radius and the lower the transparency," restoring a realistic drawing experience.
[0123] Through the above methods, the dual mode of "active preset + intelligent matching" satisfies the needs of professional users for fine customization of brush parameters while lowering the operational threshold for ordinary users, achieving a balance between "professionalism and versatility." The detailed settings and linkage logic of each brush parameter make the brush characteristics more aligned with the core needs of different drawing scenarios. Combined with the dynamic adjustment mechanism of the brush radius in the document, the expressiveness of brush strokes is further enriched. The parameter saving and preference memory functions improve the continuity of operation, making the determination of brush parameters flexible, accurate, efficient, and convenient, significantly enhancing the practicality of the drawing tool and the user experience.
[0124] In some embodiments, after the terminal determines multiple candidate pixels falling within the candidate range, it can mark the multiple candidate pixels corresponding to all sampling points with an attribution identifier, which is used to indicate the sampling point to which the candidate pixel belongs; when there are overlapping pixels belonging to multiple sampling points among all candidate pixels (i.e., candidate pixels corresponding to all sampling points), the distance from the overlapping pixel to each attribution sampling point is determined; the attribution identifier of the overlapping pixel is updated based on the distance from the overlapping pixel to each attribution sampling point, and the updated attribution identifier is used to indicate that the sampling point to which the overlapping pixel belongs is the sampling point with the smallest distance; accordingly, the terminal can draw the target pixel based on the drawing parameters in the following manner: when the target pixel is an overlapping pixel, the overlapping pixel is drawn based on the brush parameters and the sampling point with the smallest distance.
[0125] In practical applications, the candidate pixel attribution management and overlap optimization mechanism ensures that each candidate pixel is associated only with the optimal sampling point through a full-process management of "attribution identifier marking - overlapping pixel determination - distance-driven attribution update". This avoids redundant calculations and guarantees drawing accuracy. Specifically, it works as follows: Step 1: Attribution identifier marking of candidate pixels: A unique sampling point identifier (such as S001, S002...Snnn) is assigned to each sampling point. This sampling point identifier is bound and stored with the sampling point's coordinates, generation time, and other information. When candidate pixels are selected based on a certain sampling point, an attribution identifier field is immediately added to each candidate pixel. The identifier content is the corresponding sampling point identifier and the initial distance d_temp from the pixel to the sampling point (an approximate distance derived through the elliptic selection equation). For example, the candidate pixel (101, 81) selected based on sampling point S001 (100.3, 80.5) has its attribution identifier initially set to "S001|d_temp=1.2 pixels", where the distance value is temporarily stored for quick preliminary judgment. The identification information, along with pixel coordinates, color prediction values, and other data, together form the candidate pixel data structure, supporting rapid subsequent querying and modification.
[0126] Step 2: Efficient Identification and Distance Calculation of Overlapping Pixels: Construct a hash mapping table of "pixel coordinates - attribution identifier list", using the integer coordinates (px, py) of the candidate pixel as the key and the attribution identifier list as the value. When traversing all candidate pixels, if the length of the attribution identifier list corresponding to a certain coordinate is ≥2, then the pixel is determined to be an overlapping pixel. For overlapping pixels, initiate a precise distance calculation process, such as calling the Euclidean distance formula to calculate the straight-line distance d from it to each attribution sampling point, with the formula d=√[(px-x_s)²+(py-y_s)²], where (x_s, y_s) are the floating-point coordinates of the sampling points. For example, the overlapping pixel (102, 82) belongs to both S001 (100.3, 80.5) and S002 (103.1, 81.8). The calculated values are d1 = √[(102-100.3)² + (82-80.5)²] ≈ 2.26 pixels and d2 = √[(102-103.1)² + (82-81.8)²] ≈ 1.12 pixels.
[0127] Step 3: Updating the Attribution Identifier and Redundancy Removal Based on Minimum Distance: Multiple distance values of overlapping pixels are sorted, and the sampling point with the smallest distance is selected as the optimal attribution sampling point. The attribution identifier of this overlapping pixel is updated to the identifier of the optimal sampling point and its corresponding precise distance. Simultaneously, the association record between this overlapping pixel and other non-optimal sampling points is removed from the hash map table to avoid redundant processing in subsequent steps. In special cases where distance values are equal (e.g., d1=d2=1.5 pixels), the sampling point with the earlier time sequence is selected as the optimal attribution by default, ensuring a unique determination result. Taking the above overlapping pixel as an example, since d2<d1, its attribution identifier is updated to "S002|d=1.12 pixels", and its association with S001 is deleted.
[0128] Step 4: Re-drawing the updated attribution identifier: When the target pixel is selected and drawing is performed, the terminal reads the attribution identifier of each target pixel: If it is a normal pixel (associated with only one sampling point), it is drawn directly based on the brush parameters (such as dynamic radius, texture) corresponding to the sampling point; if it is an overlapping pixel (already updated to the unique optimal sampling point), the brush parameters of the optimal sampling point and the stored precise distance d are called, and the transparency is calculated according to the edge characteristics (such as α=1-(d / r) in soft edge mode) to ensure that the pixel drawing in the overlapping area conforms to the brush characteristics and accurately matches the line segment trend.
[0129] The above methods achieve precise association between candidate pixels and sampling points through attribution identifiers, and efficiently locate overlapping pixels using a hash mapping table, avoiding the inefficiency of traditional traversal comparisons. An attribution update mechanism based on precise distance ensures that overlapping pixels are always associated with the nearest sampling point, resolving issues such as excessively dark colors and distorted outlines at overlapping lines caused by repeated drawing. The linkage logic between drawing and brush parameters ensures natural stroke transitions in overlapping areas, creating a unified visual effect with non-overlapping areas. The entire process reduces redundant computation while maintaining the clarity and color uniformity of wide lines, especially in curves and polylines with dense sampling points, where the optimization effect is more significant, improving both algorithm efficiency and drawing quality.
[0130] In some embodiments, after the terminal generates multiple floating-point coordinate sampling points on the target line segment, it determines the vertical distance from each sampling point to the original line segment. When the difference between the brush radius and the vertical distance is less than the difference threshold, the sampling point is marked as an edge pixel. Accordingly, the target pixel can be drawn based on the brush parameters in the following way: when the target pixel is an edge pixel, the edge pixel is drawn based on the brush parameters, and the transparency of the edge pixel is adjusted.
[0131] In practical applications, after generating each sampling point, edge characteristic prediction can be added to each sampling point, and the natural transition of edge pixels can be achieved by combining brush parameters. Specifically, the first step is to calculate the vertical distance from the sampling point to the original line segment: taking the original line segment corresponding to the target line segment (the line segment formed by the first drawing point P1 and the second drawing point P2) as the reference, calculate the vertical distance d_ver for each sampling point S(x_s,y_s). Accurate calculation is achieved using vector projection: First, construct the vector P1P2=(x2-x1,y2-y1) of the original line segment, then construct the vector P1S=(x_s-x1,y_s-y1). Calculate the projection length t=(P1S·P1P2) / |P1P2|² using the dot product. Determine the projection point P_proj based on the t value (a point on the line segment when t∈[0,1], P1 for t<0, and P2 for t>1). Finally, obtain d_ver=√[(x_s-x_proj)²+(y_s-y_proj)²] using the Euclidean distance formula. For example, with original line segments P1(10.2,20.5) and P2(15.4,23.6), and sampling point S(13.1,24.8), d_ver≈1.2 pixels is calculated.
[0132] Step 2: Determination of edge pixel points based on the difference threshold: Extract the dynamic brush radius r corresponding to the current sampling point (such as 2.5 pixels obtained by combining pressure sensing), and set the difference threshold Δ_th (default 0.5 pixels, support adjustment according to brush hardness, such as Δ_th = 0.3 pixels for a hard-edge brush and Δ_th = 0.8 pixels for a soft-edge brush). Calculate the difference Δ = r - d_ver between the brush radius and the vertical distance. When Δ ≥ 0 and Δ < Δ_th, determine that the sampling point is an edge pixel point. The brush edge corresponding to the sampling points in this range just touches the outside of the original line segment, which is the key area for anti-aliasing; when Δ ≥ Δ_th, determine that the sampling point is an internal pixel, and when Δ < 0, determine that the sampling point is outside the brush range, and neither is marked as an edge pixel point. Continuing with the above example, for the sampling point S(13.1, 24.8), r = 2.5 pixels, Δ = 2.5 - 1.2 = 1.3 pixels > 0.5 pixels, determine that the sampling point S(13.1, 24.8) is an internal pixel point; if the sampling point S'(13.1, 25.8), d_ver = 2.2 pixels, Δ = 0.3 pixels < 0.5 pixels, mark the sampling point S' as an edge pixel point.
[0133] Step 3: Dynamic adjustment strategy for the transparency of edge pixel points: When drawing the target pixel point, the terminal reads the edge mark of the sampling point and performs differential drawing in combination with the brush parameters. For example, in the case of a hard-edge brush scenario: The transparency α is positively correlated with the difference Δ, and the formula is α = Δ / Δ_th, ensuring that the edge pixel points transition from semi-transparent to transparent. For example, when Δ = 0.3 pixels and Δ_th = 0.3 pixels, α = 1 (completely opaque); when Δ = 0.1 pixels, α ≈ 0.33 (semi-transparent), avoiding the jagged feeling of hard-edge lines. For the soft-edge brush scenario: Based on the hard-edge formula, superimpose the brush hardness coefficient k_h (0 < k_h ≤ 1), α = (Δ / Δ_th) × k_h. The lower the hardness (the smaller k_h), the smoother the transparency transition. For example, when k_h = 0.5 and Δ = 0.3 pixels, α = 0.5, achieving a soft edge like watercolor. For the texture brush scenario: The transparency calculation incorporates the texture gray value g (0 ≤ g ≤ 1), and finally α = (Δ / Δ_th) × g, making the transparency of the edge pixel points match the texture texture and avoiding texture breakage.
[0134] Step 4: Drawing coordination between edge pixel points and non-edge pixel points: Internal pixels are drawn in full according to the brush parameters, and edge pixel points are drawn by superimposing according to the calculated transparency, and the transparency of adjacent edge pixel points is connected by linear interpolation to ensure a natural transition. For example, for adjacent edge pixel points Δ1 = 0.3 pixels, Δ2 = 0.1 pixels, and the corresponding transparencies α1 = 1, α2 = 0.33, the intermediate pixel points obtain a gradually changing transparency through interpolation, avoiding obvious color block breaks.
[0135] By employing the above method, the vertical distance from the sampling point to the original line segment is accurately calculated using vector projection. Combined with brush characteristics, the difference threshold is dynamically adjusted to ensure the accuracy of edge pixel marking. The transparency adjustment strategy based on the difference achieves gradient transition of edge pixels, which not only solves the jaggedness problem of traditional hard edge drawing but also adapts to the texture requirements of different brushes, making the line edges blend naturally with the background. This, along with innovations such as anti-aliasing pre-optimization and brush texture simulation in the document, further enhances the visual delicacy of wide line drawing. At the same time, by marking edge pixels in advance, the repeated distance calculations in the subsequent drawing stage are reduced, ensuring both drawing quality and algorithm efficiency, and adapting to the needs of multiple scenarios such as professional animation rendering and lightweight handwriting input.
[0136] The following will describe an exemplary application of the embodiments of this application in a real-world application scenario.
[0137] See Figure 6 , Figure 6 This is a line drawing illustration provided in the embodiments of this application. Figure 1 When rendering based on the Bresenham algorithm, the core idea is error accumulation-based judgment. Assuming the starting and ending points of the line are integer coordinates, an error term is maintained to determine which pixel should be selected at each step. Specifically, the algorithm starts from the starting point and advances one pixel at a time along the main direction (the direction with the larger absolute value between dx and dy). Simultaneously, it determines whether to advance in the other direction based on the accumulated error. Since the entire process involves only integer addition, subtraction, and shift operations, multiplication and division are completely avoided, and floating-point operations are unnecessary. Therefore, from... Figure 6 The characteristics of integer coordinates and the limitation of single-pixel width are clearly visible, which can no longer meet the needs of modern graphics applications. The main problems are as follows: The first major problem is the line width limitation. The Bresenham algorithm is essentially a single-pixel algorithm, drawing only one pixel per iteration, making it unable to directly draw lines wider than 1. While theoretically the line width can be extended by drawing multiple pixels perpendicular to the line segment, this simple extension produces severe jagged edges and unevenness, especially noticeable visual defects at line endpoints and corners. Some improvements attempt to achieve wider lines by drawing multiple parallel lines or using a brush to fill, but these methods suffer from difficulties in endpoint handling, high computational cost, and unsatisfactory results.
[0138] The second key issue is the limitation of integer coordinates. The Bresenham algorithm requires input coordinates to be integers, meaning rounding is necessary when receiving input data. Modern high-precision input devices such as graphics tablets, pressure-sensitive pens, and high-resolution touchscreens offer sub-pixel coordinate accuracy (typically accurate to 0.01 pixels or even higher), and integerization results in the complete loss of this valuable precision information. In practical applications, this loss of precision leads to jitter, discontinuities, and loss of detail in drawn lines, severely impacting the user experience, especially in scenarios requiring extremely high precision, such as fine painting and calligraphy.
[0139] The third problem is the lack of hardness control. In professional digital painting applications, brush hardness is a crucial parameter, determining the smoothness of brush edges. Hard brushes produce sharp edges, while soft brushes offer smooth transitions. The Bresenham algorithm, due to its binary pixel selection mechanism (pixels are either selected or not), is completely incapable of hardness control. Even adding anti-aliasing or edge feathering to the algorithm's outer layer fails to achieve ideal results because the algorithm itself lacks distance measurement capabilities and cannot determine the relative position of pixels to the center of line segments.
[0140] The fourth problem is the difficulty in handling endpoints and corners. When drawing continuous strokes, the Bresenham algorithm cannot naturally handle the circular stroke effect at the endpoints of line segments. If multiple line segments are simply connected end to end, breaks or overlaps will appear at the connection points, affecting the continuity and aesthetics of the strokes. Although circles can be drawn additionally at the endpoints of line segments, this requires an additional circle drawing algorithm, increasing the implementation complexity, and it is difficult to guarantee pixel consistency.
[0141] The fifth problem is the lack of scalability and flexibility in the algorithm. Because the Bresenham algorithm is designed for extreme performance optimization, its implementation is highly specialized, making it difficult to extend its functionality without compromising its original advantages. Modern graphics applications require support for rich features such as brush textures, transparency blending, color gradients, and pressure sensitivity, but the framework of the Bresenham algorithm is insufficient to accommodate these extended requirements.
[0142] To address these issues, this application provides a systematic solution. First, through a point-to-line distance determination mechanism, the drawing method provided in this application naturally supports brush drawing of arbitrary widths. The brush radius *r* can be any positive real number, accurately handling lines from 0.5 pixels to 100 pixels thick. Second, the drawing method maintains floating-point precision throughout the entire processing flow, fully utilizing coordinate information provided by high-precision input devices and avoiding precision loss. Third, the distance-based determination method provides a mathematical foundation for hardness control, easily achieving edge feathering effects based on the distance from the pixel to the line segment center. Fourth, the line segment extension mechanism automatically solves the problem of drawing circular strokes at endpoints, ensuring natural transitions between continuous strokes. Finally, the drawing framework provided in this application has good extensibility, easily integrating advanced features such as texture mapping, transparency processing, and pressure sensing to meet the needs of professional graphics applications.
[0143] See Figure 7 , Figure 7 This is a flowchart illustrating the drawing processing method provided in the embodiments of this application. Figure 2 The algorithm consists of five main stages from input to output: Step 201 (Phase 1): Preprocessing of Input Data. The algorithm receives a list of points (i.e., the target point sequence mentioned above) and a brush radius r as input parameters. The point list usually comes from the user's drawing operations and may contain tens to thousands of points, each with floating-point coordinates. The algorithm first performs basic input validation, such as checking whether the point list contains at least two points (a single drawing point needs to be processed using a circle drawing algorithm) and whether the brush radius r is positive. In addition, the algorithm initializes a Set data structure to store the drawn pixel coordinates. This Set data structure uses string keys in the form of "x,y", ensuring O(1) lookup and insertion complexity.
[0144] Step 202 (Second Stage): Adjacent Point Pair Traversal and Line Segment Extension. The algorithm uses a sliding window to traverse the point list, processing adjacent pairs of points P1(x1,y1) and P2(x2,y2) at a time. Before processing each pair of points, the extension function (such as extendSegment) is called to extend the line segment. The implementation of this function involves vector operations: first, the direction vector (dx,dy)=(x2-x1,y2-y1) is calculated, then the line segment length L=√(dx²+dy²) is calculated, and then normalized to obtain the unit direction vector v(vx,vy)=(dx / L,dy / L). It should be noted that when two points coincide, L=0, and in this case, the extension operation should be skipped and the origin should be returned directly. The mathematical expressions for the extension operation are P1'(x1',y1')=(x1-vx×r,y1-vy×r) and P2'(x2',y2')=(x2+vx×r,y2+vy×r), which ensures that the line segment extends by the brush radius r in both directions.
[0145] Step 203 (Third Stage): Floating-point interpolation sampling. Using the coordinates of the extended line segment endpoints, let the first extended point be P1'(x1',y1') and the second extended point be P2'(x2',y2'). Calculate the horizontal coordinate difference ΔX = x2' - x1' and the vertical coordinate difference ΔY = y2' - y1'. Take the maximum value of the two as the maximum coordinate difference ΔMax = max(|ΔX|,|ΔY|) as the interpolation step number (i.e., the number of steps mentioned above) steps. The reason for using the maximum absolute value as the interpolation step number is to ensure that the distance between interpolation points does not exceed 1 pixel, thereby avoiding holes. After determining the interpolation step number, calculate the single-step increments ΔX / steps and ΔY / steps in the x and y directions. The interpolation loop goes from 0 to steps, generating a floating-point coordinate point (x_i,y_i) in each iteration. The key here is to maintain floating-point precision and not perform any rounding operations on x_i and y_i. For a line segment of length L pixels, interpolation will generate L floating-point coordinate points (i.e., the sampling points of the floating-point coordinates mentioned above), with a time complexity of O(L).
[0146] Step 204 (Fourth Stage): Adaptive Pixel Sampling. For each floating-point coordinate point generated in the third stage, it is necessary to determine which integer pixels around it might fall within the brush area. First, determine isX=(|ΔX|>|ΔY|). If the main direction is the x-direction (the line segment is close to horizontal), it means the y-coordinate changes little. In this case, iterate through x∈[ xr , x+r For each x value, only the floor (round down) and ceil (round up) values of y are taken, i.e., {(x, y ),(x, y )}. Conversely, if the main direction is the y-direction (the line segment is close to vertical), then traverse y ∈ y - r , y + r , and for each y value, take the floor and ceil of x. This strategy reduces the number of candidate pixels from O(r²) to O(r). For a brush with a radius of 10 pixels, the number of candidate pixel points is reduced from approximately 400 to approximately 40, resulting in a significant improvement in efficiency.
[0147] Step 205 (the fifth stage): Accurate distance determination and pixel output. For each candidate pixel point P(px, py), call the distance calculation function (pointToSegmentDistance) to calculate its exact distance to the line segment. The implementation of this function is based on the principle of projection from a point to a line segment: Let the line segment be AB. First, calculate the vectors AP and AB, then calculate the dot product dot = AP · AB = (px - ax) · (bx - ax) + (py - ay) · (by - ay). Next, calculate the square of the line segment length lenSq = (bx - ax)² + (by - ay)², and the projection coefficient t = dot / lenSq. The key step is to limit t within the range [0, 1]. t = 0 indicates that the projection point is at the starting point A, t = 1 indicates that the projection point is at the ending point B, and 0 < t < 1 indicates that the projection point is inside the line segment. The coordinates of the projection point Q = A + t · (B - A), and the final distance d = |P - Q| = sqrt((px - qx)² + (py - qy)²). If d ≤ r, then add this pixel to the result set. Since it is checked whether this pixel point already exists in the Set (through the before callback function) before adding, duplicate drawing is avoided. This deduplication mechanism is particularly important when dealing with the overlapping regions of adjacent line segments and can prevent the color overlay problem caused by duplicate pixels.
[0148] The time complexity analysis of the algorithm is as follows. Let the length of the point list be n, the average distance between adjacent points be L, and the brush radius be r. Then the total complexity is O(n · L · r). Here n is the number of point pairs, L is the number of interpolation points for each line segment, and r is the number of candidate pixels around each interpolation point (after adaptive sampling). For a typical drawing scenario, n = 100, L = 50, r = 10 pixels, and the total number of distance determinations is approximately 50000 times, which can be completed within a few milliseconds on modern computing devices. The space complexity is mainly determined by the Set structure and is at most O(n · L · r), but in fact, due to the deduplication mechanism, the number of stored pixels is usually much less than this upper bound.
[0149] See Figure 8 , Figure 8This is a schematic diagram illustrating the principle of the drawing processing method provided in this application. (a) shows the geometric principle of line segment extension. Assume the length of the original line segment P1 to P2 (dashed line) is set to 100 pixels, and the brush radius r is set to 25 pixels. By calculating the unit direction vector, P1' is obtained by extending 25 pixels backward from the starting point, and P2' is obtained by extending 25 pixels forward from the ending point. The length of the extended line segment (solid line) becomes 150 pixels. The dashed circle in the figure marks the brush coverage area with a radius of 25 at point P1. It can be seen that if the extension is not performed, the semi-circular area to the left of point P1 will not be covered, resulting in a visual defect of a flat end point of the brush stroke. The extension operation allows the entire circular brush stroke to be processed correctly.
[0150] (b) illustrates the calculation mechanism and determination process for the distance from a point to a line segment. The dark, thick line represents the brush centerline with a width of 2r, and two light-colored parallel lines mark the brush boundary. Assuming point P1 has coordinates (130, 130), its calculated vertical distance to the line segment is approximately 8 pixels, less than the radius r = 20 pixels. Therefore, P1 is determined to be within the brush area and should be drawn. The projection point of point P1 onto the line segment is determined, and the dashed line connecting P1 and the projection point represents the calculated distance. Assuming point P2 has coordinates (150, 180), its distance to the line segment is approximately 28 pixels, exceeding the radius threshold. Therefore, it is determined to be outside the brush area and should be discarded. This precise distance-based determination method ensures the roundness of the brush boundary and produces a more natural visual effect compared to simple rectangular determination.
[0151] (c) illustrates the specific implementation of the adaptive sampling strategy. Assume the interpolation process produces a floating-point coordinate (5.74, 2.34), and the brush radius r = 1.5 pixels. For this point, the floor and ceiling of x are 5 and 6 respectively, and the floor and ceiling of y are 2 and 3 respectively. If the main direction of the line segment is the x-direction, the algorithm will traverse x from... 5.74-1.5 =4 to 5.74 + 1.5 =8, for each x value, take the two values of y, {2,3}. The four green sampling points (5,2), (6,2), (5,3), and (6,3) marked in the figure are the candidate pixels closest to the floating-point coordinates. These pixels will be sent to the distance determination stage. The dashed box marks the complete sampling range, covering 5 pixels in the main direction (let's say x), and only taking the floor and ceil pixel positions in the secondary direction (y), for a total of 10 candidate pixels, which is much fewer than the 25 pixels (5×5) required to traverse the complete rectangular area.
[0152] See Figure 9 , Figure 9 This is a line drawing illustration provided in the embodiments of this application. Figure 2 ,in, Figure 9 (a) shows a line drawn based on the Bresenham algorithm, and (b) shows a line drawn based on the line drawing method provided in this application. It can be seen that when the Bresenham algorithm is extended to a wide line, the edges are noticeably jagged, the endpoints are flat and missing, and the corners are rough and harsh. In contrast, the drawing method provided in this application, through floating-point coordinate sampling and precise distance-based determination, achieves a smooth edge, rounded endpoints, and natural corners, resulting in a fundamental improvement in drawing quality.
[0153] The drawing processing method provided in this application embodiment can be widely applied in various drawing scenarios. For example, as the core of a brush drawing engine for animation coloring tools, it achieves customized implementation for four core scenarios: line drawing, area filling, detail enhancement, and layered drawing. This satisfies the dual needs of professional animators for precision and efficiency while adapting to the tool's layered architecture and real-time interactive features. For instance, line drawing is a fundamental step in drawing animated characters, requiring uniform line thickness, natural corners, and no breaks. The drawing processing method provided in this application embodiment achieves high-quality results through "dynamic extension + intelligent sampling." Specifically, when an animator uses a graphics tablet (terminal) to outline a character, the terminal collects the target point sequence (including floating-point coordinates and pressure data) of the pen tip trajectory in real time. For any adjacent drawing points in the target point sequence, first perform line segment extension based on the brush's base radius: If the line segment between adjacent drawing points is an acute angle line segment such as a character joint, and the curvature k between adjacent drawing points is greater than the curvature threshold (e.g., curvature k>0.5) calculated by three-point fitting, then shorten the extension length according to brush radius = base radius × preset ratio (which can be set according to curvature, such as 0.4) to avoid "bulges" at acute angles; if the line segment between adjacent drawing points is a gentle curve such as a hair (e.g., curvature k<0.1), then maintain the extension length of the base radius to ensure the endpoints are circular and complete. On the extended target line segment, sampling points are dynamically generated based on the drawing speed. For example, when quickly outlining the character's torso (drawing speed > 5 pixels / millisecond), the number of sampling steps is reduced by 30% from the base value (e.g., optimized from 20 sampling steps to 14), ensuring a real-time response of over 60 frame updates per second (i.e., a frame rate of 60fps). When finely depicting the character's facial features (drawing speed < 1 pixel / millisecond), the number of sampling steps is increased by 60% (e.g., optimized from 8 sampling steps to 13), ensuring accurate line details. In the pixel selection stage, the candidate range of the circumscribed square is first determined by the brush radius, and then invalid pixels are filtered out using the ellipse equation, reducing the distance calculation by more than 30%. During the final drawing, the brush radius is dynamically adjusted based on the tablet pressure data (the brush radius increases to 5 pixels when the stroke is heavy and decreases to 0.5 pixels when the stroke is light), combined with the soft edge mode to achieve a smooth transition of line edges, perfectly presenting the layering and fluidity of the character's outline.
[0154] For example, area filling requires rapid filling within enclosed areas such as character clothing and backgrounds. The core requirements are "efficient coverage + precise edges." The drawing processing method provided in this application improves filling performance through "range optimization + overlap merging." Specifically, after the animator selects the enclosed filling area in the drawing tool and triggers drawing, the terminal obtains the target point sequence of the filling trajectory (mostly continuous points at the region boundary). For adjacent drawing points in the target point sequence, the original line segment is extended with a larger brush radius (e.g., brush radius = 10 pixels) to ensure that the filling range covers the entire area without edge gaps. During the sampling point generation stage, since the filling trajectory is mostly a gentle curve, a fixed step size and fast drag sampling strategy can be adopted to reduce redundant sampling points and improve efficiency. When selecting candidate pixels, the candidate ranges of adjacent sampling points are merged based on the enclosed characteristics of the filling area, the pixel ownership identifier of the overlapping area is marked, and only the candidate pixels closest to the sampling point are retained to avoid duplicate calculations. The distance determination process calculates the precise distance from candidate pixels to the target line segment, ensuring that the selected target pixels fall strictly within the brush area and preventing fill color from overflowing outside the line art or missing corners. During output, the drawing tool calls preset fill parameters (such as base color and transparency) and batch outputs target pixel data, enabling large-area fill operations to be completed instantly (e.g., within 100 milliseconds), with the fit error between the fill edge and the line art ≤0.5 pixels, completely solving the problems of "rough edges and discontinuous fill" in traditional drawing tools.
[0155] For example, detail retouching focuses on fine details such as the character's eyes, hair, and textures, requiring high brush precision (e.g., brush radius ≤ 1 pixel) and fast response. The drawing processing method provided in this embodiment ensures drawing quality through "abnormal point repair + sub-pixel anti-aliasing". Specifically, when animators use small brushes (brush radius less than 1 pixel) for retouching, the target point sequence collected by the terminal is prone to jitter due to hand tremors (e.g., fluctuations of more than 2 pixels between three adjacent points). The first stage initiates intelligent abnormal point repair: replacing jittery points through linear interpolation while preserving brush touch details. In the line segment extension stage, because the small brush radius is small, the extension length is controlled to the brush radius, ensuring the integrity of the endpoints while avoiding over-extension that leads to blurred details. When generating sampling points, for high-curvature hair lines, the sampling step calculation model automatically increases the curvature weight, generating dense sampling points (e.g., sampling step = 20), ensuring that short line segments drawn with small brushes have no breaks. Edge pixels are marked simultaneously during sampling, and the transparency is adjusted directly based on the markings during subsequent pixel determination, achieving sub-pixel anti-aliasing and making the edges of hair free of obvious jaggedness. The drawing output adopts a hard-edge mode to ensure accurate positioning of point drawing with small brushes (such as the highlight of a character's pupil), with a pixel brightness error of ≤1 pixel and an algorithm response latency of ≤10 milliseconds, meeting the core requirement of animators for "fine operation without lag".
[0156] For example, layered drawing is a core process in animation production, requiring precise alignment of strokes across different layers and support for subsequent parameter adjustments. The drawing processing method provided in this embodiment achieves cross-layer collaboration through "layered storage + data association." Specifically, when animators draw on "line art layers," "coloring layers," and "shadow layers" respectively, the terminal adds independent identifiers to the target point sequences of each layer, maintaining a unified coordinate baseline and extension rules when processing adjacent drawing points across layers. In the sampling point generation, pixel filtering, and distance determination stages, the algorithm executes corresponding strategies based on the brush characteristics of each layer (such as hard-edged brushes in the line art layer and soft-edged brushes in the shadow layer), while additionally storing data such as "associated layer identifier," "distance," and "brush parameter snapshot" (such as brush radius, texture, and transparency) for each target pixel, in conjunction with the tool's layered management system. When animators adjust the layer order or modify the brush radius of a layer (e.g., changing the brush radius of the line art layer from 1 pixel to 1.5 pixels), the tool does not need to re-call the entire algorithm workflow. It only reads the distance data stored in the pixels, re-determines pixels whose distance is ≤ the new brush radius, and updates the display status, achieving real-time alignment of brush strokes across layers. For example, after modifying the brush opacity of a character's shadow layer, the shadow pixels can quickly blend with the line art layer and the coloring layer, with a positional deviation of ≤ 0.5 pixels. This significantly improves the efficiency of "drawing-modifying-iteration," reducing the minutes-level operation of "deleting, modifying, and redrawing" in the traditional workflow to milliseconds.
[0157] At the functional level, the drawing processing method provided in this application supports a continuously adjustable width range from 1-pixel thin lines to 100-pixel thick lines, meeting various needs from detailed depiction to large-area filling. For example, see... Figure 10 , Figure 10 This is a line drawing illustration provided in the embodiments of this application. Figure 3 The illustration demonstrates the use of the drawing processing method provided in this application to draw S-shaped curves with different brush radii (2.0, 2.2, 2.4, 2.6, 2.8, 3.0). It can be clearly seen that the line width smoothly transitions with the change of brush radius, and the thickness of each curve is uniform, which fully demonstrates the precise support capability for brushes of any width.
[0158] The brush hardness control feature allows animators to choose between hard-edged or soft-edged brushes based on the needs of the artwork. Hard-edged brushes are suitable for line art and flat color styles, while soft-edged brushes are suitable for gradients and smooth transitions. Precise edge pixel detection ensures clear brush stroke boundaries, without any extra or missing pixels, which is crucial for subsequent filling and selection operations.
[0159] Furthermore, the smoothness of stroke connections is a major highlight of the drawing processing method provided in this application. In traditional drawing software, stroke breaks or jagged connections often occur during rapid drawing. However, the drawing processing method provided in this application, through line segment extension and deduplication mechanisms, ensures that strokes remain continuous and smooth at any drawing speed. For example, see... Figure 11 , Figure 11 This is a line drawing illustration provided in the embodiments of this application. Figure 4 The example demonstrates a complex curved path drawn using the drawing processing method provided in this application. It can be seen that the brushstrokes are rounded, the lines are smooth, and the corners are natural, fully demonstrating the high-precision drawing effect brought by floating-point coordinate interpolation. This allows animators to confidently and quickly draw sketches without worrying about technical issues affecting the smoothness of creation.
[0160] Support for input devices is also an important feature. Modern graphics tablets, such as professional equipment, can provide resolutions of 5080 LPI (lines per inch) or even higher, with output coordinate accuracy down to the sub-pixel level. The drawing processing method provided in this application embodiment can fully utilize this high-precision coordinate data, resulting in smoother, more natural lines with enhanced detail. For pressure-sensitive input devices, real-time communication can be established with the pressure sensor through the input device driver interface, allowing for convenient dynamic adjustment of the brush radius based on the pressure value, thus achieving variations in stroke thickness.
[0161] In summary, the drawing processing method provided in this application has several significant advantages over the traditional Bresenham algorithm and its variants. Specifically, in terms of drawing accuracy, the algorithm's floating-point coordinate processing capability brings a qualitative leap. The traditional Bresenham algorithm rounds the input coordinates to integers. This quantization error may not be obvious in a single drawing, but it accumulates during continuous drawing, leading to irregular jagged edges and jitter in the lines. The drawing processing method provided in this application maintains floating-point precision throughout the entire processing flow, only performing integer conversion at the final pixel output stage, accurately reflecting the original coordinate information provided by the input device. In actual testing, when drawing a slow curve with sub-pixel precision (±0.25 pixels) using a graphics tablet, the lines generated by the drawing processing method provided in this application are significantly smoother than those based on integer algorithms, with jitter virtually disappearing, and the feeling is closer to that of real pen and paper drawing.
[0162] In terms of functional completeness, the drawing processing method provided in this application's embodiments solves the fundamental limitations of traditional algorithms by natively supporting brushes of arbitrary width. The Bresenham algorithm can only draw lines 1 pixel wide. To achieve wide lines, additional processing is required outside the algorithm layer. Common methods include drawing multiple parallel lines or using scan lines for filling, but these methods suffer from difficulties in endpoint handling, unnatural corners, and high performance overhead. The drawing processing method provided in this application's embodiments, based on geometric distance determination, naturally supports circular brushes. The radius parameter r can be any real number from 0.5 to 100 pixels or even larger, and it supports decimal precision adjustment, such as 2.0, 2.2, 2.4, etc. In practical use, animators can continuously adjust the brush size using a slider, from a fine 1-pixel sketch edge to a thick 50-pixel thick paint, switching smoothly without changing the underlying algorithm, significantly improving the user experience. From the actual drawing effect, brushes of different widths maintain a high-quality effect with rounded edges, uniform thickness, and natural transitions.
[0163] Regarding stroke continuity, the introduction of the line segment extension mechanism solves the endpoint problem that has plagued wide brush drawing for many years. In traditional implementations, continuous strokes consist of multiple line segments. If each line segment is processed independently, a semi-circular missing stroke appears at the endpoint, causing the overall stroke to break or dent at the turning point. Some software attempts to compensate by drawing additional circles at the endpoints, but this increases implementation complexity and makes it difficult to guarantee pixel consistency in overlapping areas, potentially leading to color overlay issues. The extension mechanism in the drawing processing method provided in this application automatically handles this problem using mathematical methods. The extension distance is precisely equal to the brush radius, ensuring that the circular strokes at the endpoints of each line segment are drawn completely. Combined with the deduplication mechanism, overlapping areas of adjacent line segments will not have duplicated pixels, avoiding color overlay. In tests, when drawing curves containing sharp turns at a speed of 120 points / second, the strokes remained continuous and smooth, without any breaks or overlapping defects.
[0164] In terms of performance optimization, the adaptive sampling strategy fully utilizes the geometric characteristics of line segments. For a given floating-point coordinate and brush radius, if all integer pixels within a square area are simply traversed, the number of candidate pixels is on the order of O(r²). The drawing processing method provided in this application reduces the number of candidate pixels to the order of O(r) by determining the main direction of the line segment, performing a complete traversal in the main direction, and only taking the floor and ceil values in the secondary direction. Specific data comparison: For a brush with a radius r = 5 pixels, the traditional method needs to check approximately 121 pixels (11×11), while the drawing processing method provided in this application only needs to check approximately 22 pixels (11×2), a reduction of approximately 82%; for a brush with a radius r = 10 pixels, the traditional method needs to check approximately 441 pixels (21×21), while the drawing processing method provided in this application only needs to check approximately 42 pixels (21×2), a reduction of approximately 90%. Furthermore, the optimization effect becomes more pronounced as the brush radius increases, allowing the algorithm to maintain real-time performance even when processing large brushes.
[0165] Regarding edge quality, the judgment method based on precise distance calculation produces a more ideal visual effect. While traditional rectangular or rhomboid brushes are simple to calculate, their edges are sharp and do not conform to the rounded characteristics of natural brushstrokes. The drawing processing method provided in this application calculates the precise Euclidean distance from each pixel to the center of the line segment, including only pixels whose distance is less than or equal to the radius, resulting in a near-perfect circular brush effect. More importantly, this distance information can be conveniently used to implement brush hardness control and edge feathering. For example, the pixel transparency can be calculated based on the ratio d / r of distance d to radius r, achieving a smooth transition from the center to the edge, which is crucial for professional digital painting applications.
[0166] In terms of code architecture, the drawing processing method provided in the application embodiment has good scalability and maintainability. The drawing processing method provided in the application embodiment adopts a layered modular design, with each functional module having a clear responsibility: for example, the extension function (extendSegment) is responsible for line segment extension, the line function (hardnessLine) is responsible for interpolation and overall flow control, the sampling function (getPointAround) is responsible for sampling, and the distance calculation function (pointToSegmentDistance) is responsible for distance calculation. This design allows each module to be tested and optimized independently, and also facilitates functional expansion according to needs. For example, when brush texture support is needed, only texture sampling logic needs to be added in the pixel output stage, without affecting the core algorithm. When pressure sensing is needed, only the brush radius r needs to be dynamically adjusted according to the pressure value when traversing point pairs. This flexibility allows the algorithm to adapt to constantly changing application requirements.
[0167] In terms of practical application effects, practice has shown that the drawing processing method provided in the embodiments of this application has achieved significant improvements in both performance and quality. For example, performance tests show that when processing continuous curves containing a large number of sampling points, even with a large brush radius, it can still maintain a smooth real-time rendering effect, fully meeting the performance requirements of interactive painting. User feedback shows a significant increase in satisfaction with brush stroke quality, with brush stroke smoothness and accuracy receiving particularly high praise, fully demonstrating the practical value and technical advantages of the drawing processing method provided in the embodiments of this application.
[0168] The exemplary application and implementation of the electronic device provided in the embodiments of this application have been used to describe the drawing processing method provided in the embodiments of this application. The following will continue to describe the cooperation of various modules in the drawing processing device 555 provided in the embodiments of this application to implement the drawing processing scheme.
[0169] The module 5551 is configured to, in response to a drawing operation, acquire a sequence of target points for the drawing trajectory indicated by the drawing operation, wherein the sequence of target points includes multiple drawing points with floating-point coordinates; the module 5552 is configured to, for any two adjacent first and second drawing points in the sequence of target points, extend the original line segment between the first and second drawing points based on the brush radius to obtain a target line segment; the module 5553 is configured to generate multiple sampling points with floating-point coordinates on the target line segment; the module 5554 is configured to, for each of the multiple sampling points, determine the brush range and candidate range corresponding to the sampling point based on the sampling point and the brush radius, and determine multiple candidate pixels falling within the candidate range; based on the distance from each candidate pixel to the target line segment, filter out target pixels falling within the brush range from the multiple candidate pixels; and the module 5555 is configured to draw the target pixels based on brush parameters.
[0170] In some embodiments, the acquisition module is further configured to, in response to a drawing operation triggered by an input device, acquire multiple floating-point coordinates of drawing points of the drawing trajectory indicated by the drawing operation through the input device; arrange the multiple drawing points according to the acquisition time order to obtain an initial point sequence, and preprocess the initial point sequence to obtain the target point sequence; wherein the preprocessing includes at least one of the following: filtering duplicate drawing points, smoothing jittering drawing points, and repairing broken drawing points.
[0171] In some embodiments, before extending the original line segment between the first drawing point and the second drawing point to obtain the target line segment based on the brush radius, the device further includes: a determining module, configured to determine the target pressure value of the pressure sensor when the input device for the drawing operation is equipped with a pressure sensor; and to determine the brush radius based on a preset mapping relationship between the pressure value and the radius, the base radius of the brush, and the target pressure value of the pressure sensor when the drawing operation is triggered.
[0172] In some embodiments, the extension module is further configured to determine the unit direction vector of the original line segment based on the direction vector and length of the original line segment between the first drawing point and the second drawing point; extend the first drawing point to a first extension point and the second drawing point to a second extension point based on the unit direction vector and the brush radius; and determine the line segment between the first extension point and the second extension point as the target line segment obtained by extending the original line segment.
[0173] In some embodiments, the extension module is further configured to: determine the curvature of the fitted curve corresponding to the first drawing point based on the first drawing point, the second drawing point, and a third drawing point adjacent to the first drawing point; determine the correspondence between the preset curvature and the extension length; and determine the target extension length corresponding to the first drawing point based on the correspondence, the curvature, and the brush radius; and extend the target extension length from the first drawing point along a direction away from the direction indicated by the unit direction vector to obtain the first extension point.
[0174] In some embodiments, the sampling module is further configured to determine the number of sampling steps to be performed on the target line segment based on the lateral coordinate difference and the longitudinal coordinate difference between the second extension point and the first extension point; use the ratio of the lateral coordinate difference to the number of sampling steps as the lateral increment of each sampling step, and use the ratio of the longitudinal coordinate difference to the number of sampling steps as the longitudinal increment of each sampling step; starting from the first extension point on the target line segment, sampling is performed by accumulating the lateral increment and the longitudinal increment at each step until the second extension point, generating a target number of sampling points with floating-point coordinates, wherein the target number is the number of sampling steps plus 1.
[0175] In some embodiments, the sampling module is further configured to: determine the maximum coordinate difference between the lateral coordinate difference and the longitudinal coordinate difference between the second extension point and the first extension point; determine the ratio of the distance difference between the first drawing point and the second drawing point to the time difference as the drawing speed; and determine the curvature of the fitted curve between the first drawing point and the second drawing point; and determine the number of sampling steps to sample on the target line segment based on the maximum coordinate difference, the drawing speed, and the curvature, wherein the number of sampling steps is negatively correlated with the drawing speed and positively correlated with the curvature.
[0176] In some embodiments, the filtering module is further configured to determine a circular region centered on the sampling point and with the brush radius as its radius as the brush range corresponding to the sampling point; and to determine a square region centered on the sampling point and with half the brush radius as its side length as the candidate range, wherein the brush range is included within the candidate range.
[0177] In some embodiments, the filtering module is further configured to determine the horizontal difference and horizontal sum between the horizontal coordinate value of the sampling point and the brush radius, and the vertical difference and vertical sum between the vertical coordinate value of the sampling point and the brush radius; determine a plurality of horizontal integer coordinate values located between the horizontal difference and the horizontal sum, and a plurality of vertical integer coordinate values located between the vertical difference and the vertical sum; and filter out a plurality of candidate pixels in the candidate range based on the plurality of horizontal integer coordinate values and the plurality of vertical integer coordinate values.
[0178] In some embodiments, after determining multiple candidate pixels falling within the candidate range, the filtering module is further configured to: determine a target range that overlaps between the first candidate range of the first sampling point and the second candidate range of the second sampling point when the distance between adjacent first and second sampling points among the multiple sampling points is less than twice the brush radius; and merge the candidate pixels falling within the target range filtered based on the first sampling point and the candidate pixels falling within the target range filtered based on the second sampling point.
[0179] In some embodiments, the filtering module is further configured to, for each of the plurality of candidate pixels, determine the distance between the candidate pixel and its projection point on the target line segment as the distance from the candidate pixel to the target line segment; and filter out candidate pixels whose distance does not exceed the brush radius from the plurality of candidate pixels as target pixels falling within the brush range.
[0180] In some embodiments, before drawing the target pixel based on brush parameters, the drawing module is further configured to determine the brush parameters set by the brush preset operation in response to a brush preset operation; or, perform brush matching based on the drawing scene of the drawing operation to obtain brush parameters adapted to the drawing scene; wherein the brush parameters include at least one of the following: brush color, brush hardness, brush transparency, brush texture, and brush edge characteristics.
[0181] In some embodiments, the apparatus further includes: a marking module, configured to: after determining a plurality of candidate pixels falling within the candidate range, mark the plurality of candidate pixels corresponding to all the sampling points with an attribution identifier, the attribution identifier indicating the sampling point to which the candidate pixel belongs; when there are overlapping pixels belonging to multiple sampling points among all candidate pixels, determine the distance from the overlapping pixel to each attribution sampling point; update the attribution identifier of the overlapping pixel based on the distance from the overlapping pixel to each attribution sampling point, the updated attribution identifier indicating that the sampling point to which the overlapping pixel belongs is the sampling point with the smallest distance; correspondingly, the drawing module is further configured to: when the target pixel is the overlapping pixel, draw the overlapping pixel based on brush parameters and the sampling point with the smallest distance.
[0182] In some embodiments, the marking module is further configured to, after generating a plurality of floating-point coordinate sampling points on the target line segment, determine the vertical distance from the sampling point to the original line segment for each of the plurality of sampling points; when the difference between the brush radius and the vertical distance is less than a difference threshold, mark the sampling point as an edge pixel; correspondingly, the drawing module is further configured to, when the target pixel is the edge pixel, draw the edge pixel based on brush parameters and adjust the transparency of the edge pixel.
[0183] This application provides a computer program product, which includes a computer program or computer-executable instructions stored in a computer-readable storage medium. A processor of an electronic device reads the computer-executable instructions from the computer-readable storage medium and executes the computer-executable instructions, causing the electronic device to perform the drawing processing method described above in this application.
[0184] This application provides a computer-readable storage medium storing computer-executable instructions or a computer program. When the computer-executable instructions or the computer program are executed by a processor, the processor will execute the drawing processing method provided in this application. For example, ... Figure 3The drawing processing method is shown.
[0185] In some embodiments, the computer-readable storage medium may be a memory such as FRAM, ROM, PROM, EPROM, EEPROM, flash memory, magnetic surface memory, optical disk, or CD-ROM; or it may be a variety of devices including one or any combination of the above-mentioned memories.
[0186] In some embodiments, computer-executable instructions may take the form of programs, software, software modules, scripts, or code, written in any form of programming language (including compiled or interpreted languages, or declarative or procedural languages), and may be deployed in any form, including as stand-alone programs or as modules, components, subroutines, or other units suitable for use in a computing environment.
[0187] As an example, computer-executable instructions may, but do not necessarily, correspond to files in a file system. They may be stored as part of a file that holds other programs or data, for example, in one or more scripts in a HyperText Markup Language (HTML) document, in a single file dedicated to the program in question, or in multiple co-located files (e.g., a file that stores one or more modules, subroutines, or code sections).
[0188] As an example, computer-executable instructions can be deployed to execute on a single electronic device, or on multiple electronic devices located at one location, or on multiple electronic devices distributed across multiple locations and interconnected via a communication network.
[0189] The above description is merely an embodiment of this application and is not intended to limit the scope of protection of this application. Any modifications, equivalent substitutions, and improvements made within the spirit and scope of this application are included within the scope of protection of this application.
Claims
1. A drawing processing method, characterized in that, The method includes: In response to a drawing operation, a sequence of target points for the drawing trajectory indicated by the drawing operation is obtained, wherein the sequence of target points includes multiple drawing points with floating-point coordinates; For any two adjacent first and second drawing points in the target point sequence, the original line segment between the first and second drawing points is extended based on the brush radius to obtain the target line segment, and multiple floating-point coordinate sampling points are generated on the target line segment. For each of the plurality of sampling points, the brush range and candidate range corresponding to the sampling point are determined based on the sampling point and the brush radius, and a plurality of candidate pixels falling within the candidate range are determined. Based on the distance from each candidate pixel to the target line segment, target pixels that fall within the brush range are selected from the plurality of candidate pixels, and the target pixels are drawn based on the brush parameters.
2. The method according to claim 1, characterized in that, The step of obtaining the target point sequence of the drawing trajectory indicated by the drawing operation in response to the drawing operation includes: In response to a drawing operation triggered by an input device, the drawing points of multiple floating-point coordinates of the drawing trajectory indicated by the drawing operation are acquired through the input device; The multiple drawing points are arranged according to the acquisition time sequence to obtain an initial point sequence, and the initial point sequence is preprocessed to obtain the target point sequence; The preprocessing includes at least one of the following: filtering duplicate drawing points, smoothing jittery drawing points, and repairing broken drawing points.
3. The method according to claim 1, characterized in that, Before extending the original line segment between the first drawing point and the second drawing point based on the brush radius to obtain the target line segment, the method further includes: When the input device for the drawing operation is equipped with a pressure sensor, the target pressure value of the pressure sensor when the drawing operation is triggered is determined; The brush radius is determined based on the preset mapping relationship between pressure value and radius, the base radius of the brush, and the target pressure value of the pressure sensor when the drawing operation is triggered.
4. The method according to claim 1, characterized in that, The process of extending the original line segment between the first drawing point and the second drawing point based on the brush radius to obtain the target line segment includes: Based on the direction vector and length of the original line segment between the first drawing point and the second drawing point, determine the unit direction vector of the original line segment; Based on the unit direction vector and brush radius, the first drawing point is extended to the first extension point, the second drawing point is extended to the second extension point, and the line segment between the first extension point and the second extension point is determined as the target line segment obtained by extending the original line segment.
5. The method according to claim 4, characterized in that, The step of extending the first drawing point to a first extension point based on the unit direction vector and brush radius includes: Based on the first drawing point, the second drawing point, and the third drawing point adjacent to the first drawing point, determine the curvature of the fitting curve corresponding to the first drawing point; Determine the correspondence between the preset curvature and the extension length, and based on the correspondence, the curvature and the brush radius, determine the target extension length corresponding to the first drawing point; Extend the target extension length from the first drawing point along a direction opposite to the direction indicated by the unit direction vector to obtain the first extension point.
6. The method according to claim 4, characterized in that, The process of generating multiple floating-point sampling points on the target line segment includes: Based on the lateral and longitudinal coordinate differences between the second extension point and the first extension point, the number of sampling steps for sampling on the target line segment is determined. The ratio of the horizontal coordinate difference to the number of sampling steps is used as the horizontal increment of each sampling step, and the ratio of the vertical coordinate difference to the number of sampling steps is used as the vertical increment of each sampling step. Starting from the first extension point on the target line segment, the horizontal increment and the vertical increment are accumulated at each step for sampling until the second extension point, generating a target number of floating-point coordinate sampling points, where the target number is the number of sampling steps plus 1.
7. The method according to claim 6, characterized in that, The step of determining the number of sampling steps for sampling on the target line segment based on the lateral and longitudinal coordinate differences between the second extension point and the first extension point includes: Determine the maximum coordinate difference between the lateral and longitudinal coordinate differences between the second extension point and the first extension point; The ratio of the distance difference between the first drawing point and the second drawing point to the time difference is determined as the drawing speed, and the curvature of the fitting curve between the first drawing point and the second drawing point is determined. Based on the maximum coordinate difference, the drawing speed, and the curvature, the number of sampling steps for sampling on the target line segment is determined, wherein the number of sampling steps is negatively correlated with the drawing speed and positively correlated with the curvature.
8. The method according to claim 1, characterized in that, The step of determining the brush range and candidate range corresponding to the sampling point based on the sampling point and the brush radius includes: The circular area centered on the sampling point and with the brush radius as its radius is defined as the brush range corresponding to the sampling point; The candidate range is defined as a square area centered on the sampling point and with half the radius of the brush as its side length, and the brush range is included within the candidate range.
9. The method according to claim 8, characterized in that, The determination of multiple candidate pixels falling within the candidate range includes: Determine the horizontal difference and horizontal sum between the horizontal coordinate value of the sampling point and the brush radius, and the vertical difference and vertical sum between the vertical coordinate value of the sampling point and the brush radius; Determine a plurality of horizontal integer coordinate values located between the horizontal difference and the horizontal sum, and a plurality of vertical integer coordinate values located between the vertical difference and the vertical sum; Based on the plurality of horizontal integer coordinate values and the plurality of vertical integer coordinate values, a plurality of candidate pixels are selected from the candidate range.
10. The method according to claim 1, characterized in that, After determining the multiple candidate pixels falling within the candidate range, the method further includes: When the distance between adjacent first and second sampling points among the plurality of sampling points is less than twice the brush radius, it is determined that there is an overlapping target range in the first candidate range of the first sampling point and the second candidate range of the second sampling point. The candidate pixels that fall within the target range and those that fall within the target range, selected based on the first sampling point, are merged.
11. The method according to claim 1, characterized in that, The step of selecting target pixels falling within the brush stroke range from the plurality of candidate pixels based on the distance from each candidate pixel to the target line segment includes: For each candidate pixel among the plurality of candidate pixels, the distance between the candidate pixel and its projection point on the target line segment is determined as the distance from the candidate pixel to the target line segment. Among the plurality of candidate pixels, candidate pixels whose distance does not exceed the brush radius are selected as target pixels falling within the brush range.
12. The method according to claim 1, characterized in that, Before drawing the target pixel based on brush parameters, the method further includes: In response to a preset brush operation, determine the brush parameters set by the preset brush operation instruction; or... Brush matching is performed based on the drawing scene of the drawing operation to obtain brush parameters adapted to the drawing scene; The brush parameters include at least one of the following: brush color, brush hardness, brush transparency, brush texture, and brush edge characteristics.
13. The method according to claim 1, characterized in that, After determining the multiple candidate pixels falling within the candidate range, the method further includes: All the candidate pixels corresponding to the sampling points are marked with an attribution identifier, which is used to indicate the sampling point to which the candidate pixel belongs; When there are overlapping pixels belonging to multiple sampling points among all candidate pixels, determine the distance from the overlapping pixel to each belonging sampling point; The belonging identifier of the overlapping pixel is updated based on the distance from the overlapping pixel to each belonging sampling point. The updated belonging identifier is used to indicate that the sampling point to which the overlapping pixel belongs is the sampling point with the smallest distance. The process of drawing the target pixel based on brush parameters includes: When the target pixel is the overlapping pixel, the overlapping pixel is drawn based on the brush parameters and the sampling point with the smallest distance.
14. The method according to claim 1, characterized in that, After generating multiple sampling points with floating-point coordinates on the target line segment, the method further includes: For each of the plurality of sampling points, determine the vertical distance from the sampling point to the original line segment; When the difference between the brush radius and the vertical distance is less than the difference threshold, the sampling point is marked as an edge pixel. The process of drawing the target pixel based on brush parameters includes: When the target pixel is the edge pixel, the edge pixel is drawn based on the brush parameters, and the transparency of the edge pixel is adjusted.
15. A drawing processing apparatus, characterized in that, The device includes: The acquisition module is used to acquire, in response to a drawing operation, a sequence of target points for the drawing trajectory indicated by the drawing operation, wherein the sequence of target points includes multiple drawing points with floating-point coordinates; The extension module is used to extend the original line segment between any two adjacent first drawing points and second drawing points in the target point sequence based on the brush radius to obtain the target line segment. The acquisition module is used to generate multiple sampling points with floating-point coordinates on the target line segment; The filtering module is used to determine the brush range and candidate range corresponding to each of the plurality of sampling points based on the sampling point and the brush radius, and to determine a plurality of candidate pixels falling within the candidate range; Based on the distance from each candidate pixel to the target line segment, target pixels that fall within the brush range are selected from the plurality of candidate pixels; The drawing module is used to draw the target pixel points based on brush parameters.
16. An electronic device, characterized in that, include: Memory is used to store executable instructions or computer programs. A processor, when executing computer-executable instructions or computer programs stored in the memory, implements the drawing processing method according to any one of claims 1 to 14.
17. A computer-readable storage medium, characterized in that, The device stores computer-executable instructions or computer programs, which, when executed by a processor, implement the drawing processing method according to any one of claims 1 to 14.
18. A computer program product comprising a computer program or computer-executable instructions, characterized in that, When the computer program or computer-executable instructions are executed by the processor, the drawing processing method according to any one of claims 1 to 164 is implemented.