Method and device for merging connection lines in a graph, electronic device and computer-readable storage medium
By mixing the pixels of overlapping connecting lines in the graphic to generate the target lines, the problem of color chaos caused by overlapping connecting lines is solved, and a cleaner and more uniform connecting line effect is achieved.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- WANGXU TECH CO LTD
- Filing Date
- 2022-12-28
- Publication Date
- 2026-07-10
AI Technical Summary
In existing technologies, connecting lines in graphics tend to overlap, leading to color confusion and affecting neatness.
The target line is generated by responding to user actions and blending the pixels of the connecting lines in overlapping areas. The GPU is used for parallel computing to improve efficiency.
It eliminates the color distortion caused by the direct superposition of pixels in overlapping line segments, making the connecting lines appear cleaner and more uniform.
Smart Images

Figure CN115984411B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of computer graphics technology, and in particular to a method, apparatus, electronic device, and computer-readable storage medium for drawing merging lines in a mind map. Background Technology
[0002] Graphics with connecting lines, such as mind maps (also known as brainstorming maps, concept maps, or thought maps), flowcharts, and tree diagrams, generally include nodes at various levels and connecting lines that link each node to the next. Because nodes can be placed arbitrarily, overlapping connecting lines between nodes can easily occur. Furthermore, in some use cases, to improve the overall visual effect of the graphic, some nodes may be folded or expanded, which can also cause overlapping connecting lines between nodes.
[0003] Since connecting lines are drawn one by one in a conventional drawing system, if two connecting lines overlap, the pixels at the overlapping position are darker than the surrounding pixels, making the connecting lines appear messy. Summary of the Invention
[0004] This application provides a method, apparatus, electronic device, and computer-readable storage medium for drawing merging connecting lines in a graphic, thereby keeping two connecting lines with overlapping segments neat.
[0005] In a first aspect, embodiments of this application provide a method for merging and drawing connecting lines in a graphic. The method includes: generating a first connecting line in response to a first user-triggered operation, and generating a second connecting line in response to a second user-triggered operation; when the second connecting line and the first connecting line have overlapping segments, mixing corresponding first pixels and second pixels of the overlapping segments to obtain overlapping segments; wherein the first pixels are pixels of the first connecting line, and the second pixels are pixels of the second connecting line; and generating corresponding target lines based on the overlapping and non-overlapping segments. The above-described method for merging and drawing connecting lines in a graphic processes the overlapping connecting lines to ensure that the two connecting lines can be seamlessly connected or superimposed.
[0006] Secondly, embodiments of this application provide a device for merging and drawing connecting lines in a graphic. The device includes a single-line generation module, a mixing processing module, and a target line generation module. The single-line generation module generates a first connecting line in response to a first operation triggered by a user, and generates a second connecting line in response to a second operation triggered by a user. The mixing processing module is used to, when the second connecting line and the first connecting line have overlapping segments, mix a plurality of corresponding first pixels and a plurality of second pixels of the overlapping segments to obtain overlapping segments; wherein the first pixels are pixels of the first connecting line, and the second pixels are pixels of the second connecting line. The target line generation module is used to generate corresponding target lines based on the overlapping and non-overlapping segments.
[0007] Thirdly, embodiments of this application provide a computer-readable storage medium. The computer-readable storage medium stores a computer-executable program, which is executed by a processor to implement the method for merging and drawing connecting lines in the above-described drawing.
[0008] Fourthly, embodiments of this application provide an electronic device for drawing the merging of connecting lines in a drawing. The electronic device includes a memory and a processor. The memory stores a computer-executable program. The processor executes the computer-executable program to implement the aforementioned method for drawing the merging of connecting lines in a drawing.
[0009] The method for merging connecting lines in the above figure mixes the pixels of the overlapping segments of the first and second connecting lines, and generates the target line segment based on the mixed and unmixed segments. This eliminates the phenomenon of the color becoming darker due to the direct superposition of pixels of overlapping segments, thereby making the pixels of the target line appear more uniform and the connecting lines appear cleaner. Attached Figure Description
[0010] To more clearly illustrate the technical solutions in the embodiments of this application or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on the structures shown in these drawings without creative effort.
[0011] Figure 1 This is a schematic diagram illustrating an application scenario of the method for merging connecting lines in a graphic provided in this application embodiment.
[0012] Figure 2 This is a flowchart illustrating the method for merging connecting lines in a drawing provided in an embodiment of this application.
[0013] Figure 3 This is a gridded schematic diagram of two lines with overlapping line segments provided for an embodiment of this application.
[0014] Figure 4 This is a schematic diagram illustrating the reading and writing scenario of two overlapping lines provided in an embodiment of this application.
[0015] Figure 5 A flowchart illustrating the sub-steps of the method for merging connecting lines in a drawing provided in the application embodiment.
[0016] Figure 6 A schematic diagram of the functional modules of the device for merging and drawing connecting lines in the graphics provided in the application embodiment.
[0017] Figure 7 This is a schematic diagram of an electronic device for implementing adaptive display, provided in an embodiment of this application.
[0018] The realization of the purpose, functional features and advantages of this application will be further explained in conjunction with the embodiments and with reference to the accompanying drawings. Detailed Implementation
[0019] To make the objectives, technical solutions, and advantages of this application clearer, the following detailed description is provided in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative and not intended to limit the scope of this application. All other embodiments obtained by those skilled in the art based on the embodiments in this application without inventive effort are within the scope of protection of this application.
[0020] The terms “first,” “second,” “third,” “fourth,” etc. (if present) in the specification, claims, and accompanying drawings of this application are used to distinguish similar planned objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data are interchangeable where appropriate; in other words, the described embodiments are implemented according to a sequence other than that illustrated or described herein. Furthermore, the terms “comprising” and “having,” and any variations thereof, may also include other content; for example, a process, method, system, product, or apparatus that comprises a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to such processes, methods, products, or apparatus.
[0021] It should be noted that the use of terms such as "first" and "second" in this application is for descriptive purposes only and should not be construed as indicating or implying their relative importance or implicitly specifying the number of technical features indicated. Therefore, features defined with "first" and "second" may explicitly or implicitly include one or more of that feature. Furthermore, the technical solutions of the various embodiments can be combined with each other, but this must be based on the ability of those skilled in the art to implement them. If the combination of technical solutions is contradictory or impossible to implement, it should be considered that such a combination of technical solutions does not exist and is not within the scope of protection claimed in this application.
[0022] The present application provides a method for merging connecting lines in a graphic, which can merge the pixels of the overlapping parts of two lines in the graphic, so that the pixels of the line segments of the overlapping parts of the two lines are the merged pixels, so that the lines can be seamlessly connected and superimposed.
[0023] Please refer to Figure 1 , Figure 1 This diagram illustrates an application scenario of the method for merging connecting lines in graphics. The method provided in this embodiment is primarily used in graphics software such as mind maps, flowcharts, and tree diagrams. This software can draw several nodes and connecting lines to link them, thereby representing the relationships between different levels of topics using hierarchical diagrams of mutual subordination and correlation, and establishing memory links between topic keywords and images, colors, etc. During the drawing process, overlapping segments may appear between connecting lines. The method for merging connecting lines in graphics processes these overlapping segments to eliminate the phenomenon of pixel overlap causing color distortion, thus making the target lines appear more uniform in pixel density and the connecting lines cleaner.
[0024] by Figure 1 Taking the scenario in the example, the graphics software runs on the electronic device 100 to allow the user to draw the required graphics F. Graphic F includes several nodes i1-i4 and several connecting lines L1-L3, with each node representing a different theme. Connecting lines L1-L3 connect the nodes i1-i4 to represent the hierarchical relationship between the themes. There is an overlapping line segment L12 between L1 and L2. The connecting line merging drawing method provided in this application is used to merge the overlapping line segment L12.
[0025] Please refer to Figure 2 , Figure 2 A flowchart illustrating the method for merging and drawing connecting lines is shown. The method for merging and drawing connecting lines includes steps S201-S205.
[0026] Step S201: Generate a first connection line in response to a first operation triggered by the user, and generate a second connection line in response to a second operation triggered by the user.
[0027] In step S201, the user inputs the corresponding first and second operations through an input device in the graphical interface provided by the graphics software. The first and second operations can be obtained by selecting a line style provided by the graphics software and then sliding the mouse, or by stretching, rotating, or dragging the lines provided by the graphics software. In this embodiment, the generation order of the first and second connecting lines is the order in which the first and second operations are triggered. That is, if the first operation is triggered first and the second operation is triggered later, then the first connecting line is drawn before the second connecting line is drawn. Furthermore, when drawing the first and second connecting lines, they are generated pixel by pixel based on the trajectories traversed by the first and second operations in the graphical interface.
[0028] In this embodiment, all first pixels of the first connecting line and all second pixels of the second connecting line are stored in a first buffer frame and a second buffer frame, respectively. The first buffer frame and the second buffer frame are two regions in the buffer used to store the connecting lines.
[0029] Please refer to the following: Figure 3 and Figure 4 , Figure 3 This diagram illustrates the rasterized representation of the first and second connecting lines. Rasterizing the first and second connecting lines means representing them using pixels. Figure 3 In the diagram, the pixel of the first connecting line L1 is represented by P1, and the pixel of the second connecting line L2 is represented by P2.
[0030] Figure 4 The diagram illustrates the relationship between the first and second connecting lines and the first and second buffer frames. Figure 4 In the process of generating the first line segment L1 and the second line segment L2, all pixels P1 on the first connecting line L1 and the second connecting line L2 are stored in the first buffer frame M1 and the second buffer frame M2 of the buffer M, respectively.
[0031] Step S203: When the second connecting line and the first connecting line have overlapping segments, the corresponding first pixel points and second pixel points of the overlapping segments are mixed to obtain overlapping segments; wherein, the first pixel point is the pixel point of the first connecting line, and the second pixel point is the pixel point of the second connecting line.
[0032] Step S203 is executed when the first connecting line and the second connecting line have overlapping segments. In step S203, the first pixel and the second pixel corresponding to the overlapping segment are extracted from the first buffer frame and the second buffer frame and blended to obtain the overlapping segment.
[0033] Since the first and second pixels are stored in different buffer frames, during blending, the corresponding first and second pixels can be read from the first and second buffer frames in parallel and blended, thereby improving the pixel blending efficiency. In the specific implementation, a graphics processing unit (GPU) 10 is used to implement the blending of the first and second pixels of overlapping line segments.
[0034] Still with Figure 3 Taking the first connecting line L1 and the second connecting line L2 as examples, line segment L12 is the line segment where the first connecting line L1 and the second connecting line L2 coincide, while line segments L11 and L22 are the line segments where the first connecting line L1 and the second connecting line L2 do not coincide. Understandably, the pixel P12 of the first connecting line L1 and the second connecting line L2 overlaps in the portion of line segment L12. The pixels P11 and P22 of the portions of line segments L11 and L22 do not overlap.
[0035] Please refer to the following: Figure 4 , Figure 4 The relationship between the first and second pixels of the overlapping line segment after they are blended and the first and second buffer frames is also shown.
[0036] exist Figure 4 In the first cache frame, GPU 10 retrieves the first and second pixel points P1(2) of the overlapping line segment from the first cache frame, and mixes them to obtain the corresponding pixel point, i.e., generates the overlapping line segment L12, and writes it into the first cache frame, thereby covering the line segment of the overlapping part of the first connecting line L1 and the second connecting line L2 in the first cache frame M1. At the same time, the second pixel point P22 corresponding to the line segment L22 of the second connecting line L2 that does not overlap with the first connecting line L1 is written into the first cache frame M1. That is to say, at this time, the pixel points stored in the first cache frame M1 are the pixel points corresponding to the overlapping and non-overlapping line segments of the first and second connecting lines.
[0037] In this embodiment, the specific implementation scheme of step S203 is described below. It is understood that step S203 can also be implemented using existing methods for mixing two overlapping line segments.
[0038] Step S205: Generate corresponding target lines based on the overlapping and non-overlapping line segments.
[0039] In step S205, loading the pixels in the first buffer frame generates the target line in the user's graphical interface.
[0040] In the above embodiments, when two lines overlap, the pixels of the overlapping line segments are blended, and then the target line is generated based on the blended overlapping and non-overlapping line segments. Since the pixels of the overlapping line segments are blended, the phenomenon of color distortion caused by direct pixel superposition is eliminated, resulting in more uniform pixels in the target line and a cleaner connecting line. Simultaneously, this application also caches two unblended connecting lines containing overlapping line segments using two buffer frames, and utilizes the GPU for blending calculations. This allows for parallel blending calculations on each pixel of the overlapping line segments, significantly improving blending efficiency.
[0041] Please refer to the following: Figure 5 , Figure 5 The specific implementation steps of step S203 are shown. In this embodiment, each first pixel includes several first color channel values and a first pixel transparency value, each second pixel includes several second color channel values and a second pixel transparency value, and each overlapping line segment pixel includes several target color channel values and a target pixel transparency value. Step S203 includes sub-steps S501-S503.
[0042] Step S501: Calculate the target transparency value of each overlapping line segment pixel.
[0043] In this embodiment, the transparency value of each target pixel is calculated based on the line transparency value and the corresponding second pixel transparency value. Each target color channel value is calculated based on the corresponding first color channel value, second color channel value, and the line transparency value. The line transparency value is the transparency value of the second connecting line. The line transparency value represents the light transmittance of the line; the smaller the line transparency value, the more transparent the line. The line transparency value is a value between 0 and 1. The pixel transparency value represents the light transmittance of the pixel; similarly, the smaller the pixel transparency value, the more transparent the pixel. The pixel transparency of a line is less than or equal to the line transparency.
[0044] In this embodiment, the transparency value of each target pixel includes: calculating the transparency value of each overlapping line segment pixel by parallel calculation of the line transparency value and the corresponding second pixel transparency value according to a first formula, whereby A3 = 1 - CA2 + A2, where A3 represents the transparency value of each target pixel, CA2 represents the line transparency value of the second connecting line, and A2 represents the transparency value of the corresponding second pixel. In other words, the transparency value of each target pixel can be calculated solely based on the second line transparency value and the second pixel transparency value corresponding to the overlapping line segment. The second pixel transparency value and the second line transparency value are pre-provided by the graphics software according to the style of the drawn lines; therefore, parallel calculation can be achieved when calculating the transparency value of each target pixel.
[0045] Step S503: Calculate the color channel value of each overlapping line segment pixel based on the transparency value of the target pixel, the color channel value of the corresponding first pixel, and the color channel value of the second pixel.
[0046] In step S503, each target color channel value is calculated based on the corresponding first color channel value, second color channel value, and the line transparency value. In this embodiment, each target color channel value includes values for multiple color channels. Understandably, the number of color channels can be set according to the desired color. For example, a CMYK image has four channels by default: cyan, magenta, yellow, and black. By default, bitmap, grayscale, duotone, and indexed color images have only one channel. RGB and Lab images have three channels, and CMYK images have four channels. In this embodiment, three channels of RGB are used as an example.
[0047] Specifically, the corresponding first color channel value, second color channel value, and line transparency value of the overlapping line segments are calculated in parallel according to the second formula to obtain several target color channel values corresponding to each pixel point of the overlapping line segment. The second formula is: W3=(W1*(1-CA2)+W2) / A3, where CA2 represents the line transparency value of the second connecting line, and W3, W1, and W2 represent the target color channel values of the target pixel point, the first pixel point, and the second pixel point on the same channel, respectively.
[0048] For example, consider a target pixel P in the overlapping line segment L12. Target pixel P in the overlapping line segment L12 is obtained by mixing the first pixel PA1 in the first connecting line L1 and the second pixel P2A in the second connecting line L2. The first pixel P1A is represented as [R1, G1, B1, A1], where R1 represents the red channel value of the first pixel P1A, G1 represents the green channel value of the first pixel P1A, B1 represents the blue channel value of the first pixel P1A, and A1 represents the transparency value of the first pixel P1A. The second pixel P2A is represented as [R2, G2, B2, A2], where R2 represents the red channel value of the second pixel P2A, G2 represents the green channel value of the second pixel P2A, B2 represents the blue channel value of the second pixel P2A, and A2 represents the transparency value of the second pixel P2A. The transparency value of the second connecting line is still represented by CA2. The target pixel P is represented as [R3, G3, B3, A3], where R3 represents the red channel value of the target pixel P, G3 represents the green channel value of the target pixel P, B3 represents the blue channel value of the target pixel P, and A3 represents the transparency value of the target pixel P.
[0049] The transparency value of the target pixel P is: A3 = 1 - CA2 + A2. R3 represents the red channel value of the target pixel P, expressed as:
[0050] R3 = (R1*A1*(1-CA2) + R2*A2) / A3.
[0051] G3= (G1*A1*(1-CA2) + G2*A2) / A3;
[0052] B3= (B1*A1*(1-CA2) + B2*A2) / A3.
[0053] Since the calculation of one color channel value of the target pixel P is not related to the calculation of the other color channel value, but only to the value of its own color channel and the pixel transparency value of the target pixel, the color channel value of each target pixel can be calculated in parallel when the pixel transparency value of the target pixel is obtained.
[0054] In the above embodiments, the first calculation formula and the second calculation formula enable parallel computing in each calculation process, which greatly improves the efficiency of computing.
[0055] Please refer to Figure 6 , Figure 6A schematic diagram of a drawing device 100 for merging connecting lines in a drawing provided in this application is shown. The drawing device 100 for merging connecting lines in a drawing can implement a method for merging connecting lines in a drawing. The drawing device 100 for merging connecting lines in a drawing includes a single line generation module 101, a mixing processing module 102, and a target line generation module 103.
[0056] The single-line generation module 101 is used to generate a first connecting line in response to a first operation triggered by the user, and to generate a second connecting line in response to a second operation triggered by the user.
[0057] In this embodiment, the user inputs corresponding first and second operations through an input device in the graphical interface provided by the graphics software. The first and second operations can be obtained by selecting a line style provided by the graphics software and then sliding the mouse, or by stretching, rotating, or dragging the lines provided by the graphics software. In this embodiment, the generation order of the first and second connecting lines is the order in which the first and second operations are triggered. That is, if the first operation is triggered first and the second operation is triggered later, then the first connecting line is drawn before the second connecting line is drawn. Furthermore, when drawing the first and second connecting lines, they are generated pixel by pixel based on the trajectories traversed by the first and second operations in the graphical interface.
[0058] All first pixels of the first connecting line and all second pixels of the second connecting line are stored in a first buffer frame and a second buffer frame, respectively. The first buffer frame and the second buffer frame are two regions in the buffer used to store the connecting lines.
[0059] Please refer to the following: Figure 3 and Figure 4 , Figure 3 This diagram illustrates the rasterized representation of the first and second connecting lines. Rasterizing the first and second connecting lines means representing them using pixels. Figure 3 In the diagram, the pixel of the first connecting line L1 is represented by P1, and the pixel of the second connecting line L2 is represented by P2.
[0060] Figure 4 The diagram illustrates the relationship between the first and second connecting lines and the first and second buffer frames. Figure 4 In the process of generating the first line segment L1 and the second line segment L2, all pixels P1 on the first connecting line L1 and the second connecting line L2 are stored in the first buffer frame M1 and the second buffer frame M2 of the buffer M, respectively.
[0061] The mixing processing module 102 is used to mix a number of first pixels and a number of second pixels corresponding to the overlapping line segments when there are overlapping line segments between the second connecting line and the first connecting line; wherein, the first pixels are pixels of the first connecting line and the second pixels are pixels of the second connecting line.
[0062] In this embodiment, the mixing processing module 102 starts operating when overlapping line segments appear in the first and second connecting lines. Specifically, the mixing processing module 102 extracts the first and second pixels corresponding to the overlapping line segments from the first and second buffer frames and mixes them to obtain the overlapping line segments.
[0063] Since the first and second pixels are stored in different buffer frames, during blending, the corresponding first and second pixels can be read from the first and second buffer frames in parallel and blended, thereby improving the pixel blending efficiency. In the specific implementation, a graphics processing unit (GPU) 10 is used to implement the blending of the first and second pixels of overlapping line segments.
[0064] Still with Figure 3 Taking the first connecting line L1 and the second connecting line L2 as examples, line segment L12 is the line segment where the first connecting line L1 and the second connecting line L2 coincide, while line segments L11 and L22 are the line segments where the first connecting line L1 and the second connecting line L2 do not coincide. Understandably, the pixel P12 of the first connecting line L1 and the second connecting line L2 overlaps in the portion of line segment L12. The pixels P11 and P22 of the portions of line segments L11 and L22 do not overlap.
[0065] Please refer to the following: Figure 4 , Figure 4 The relationship between the first and second pixels of the overlapping line segment after they are blended and the first and second buffer frames is also shown.
[0066] exist Figure 4 In the first cache frame, GPU 10 retrieves the first and second pixel points P1(2) of the overlapping line segment from the first cache frame, and mixes them to obtain the corresponding pixel point, i.e., generates the overlapping line segment L12, and writes it into the first cache frame, thereby covering the line segment of the overlapping part of the first connecting line L1 and the second connecting line L2 in the first cache frame M1. At the same time, the second pixel point P22 corresponding to the line segment L22 of the second connecting line L2 that does not overlap with the first connecting line L1 is written into the first cache frame M1. That is to say, at this time, the pixel points stored in the first cache frame M1 are the pixel points corresponding to the overlapping and non-overlapping line segments of the first and second connecting lines.
[0067] In this embodiment, the specific implementation scheme of the mixing processing module 102 is described below. It can be understood that the mixing processing module 102 can also be implemented using existing methods for mixing two overlapping line segments.
[0068] The target line generation module 103 is used to generate corresponding target lines based on the overlapping and non-overlapping line segments.
[0069] In this embodiment, the target line generation module 103 can generate the target line in the user's graphical interface by loading the pixels in the first buffer frame.
[0070] In the above embodiments, when two lines overlap, the pixels of the overlapping line segments are blended, and then the target line is generated based on the blended overlapping and non-overlapping line segments. Since the pixels of the overlapping line segments are blended, the phenomenon of color distortion caused by direct pixel superposition is eliminated, resulting in more uniform pixels in the target line and a cleaner connecting line. Simultaneously, this application also caches two unblended connecting lines containing overlapping line segments using two buffer frames, and utilizes the GPU for blending calculations. This allows for parallel blending calculations on each pixel of the overlapping line segments, significantly improving blending efficiency.
[0071] The mixing module 102 includes a transparency value mixing unit 1021 and a color value mixing unit 1023.
[0072] The transparency value blending unit 1021 is used to calculate the target transparency value of each overlapping line segment pixel.
[0073] In this embodiment, the transparency value of each target pixel is calculated based on the line transparency value and the corresponding second pixel transparency value. Each target color channel value is calculated based on the corresponding first color channel value, second color channel value, and the line transparency value. The line transparency value is the transparency value of the second connecting line. The line transparency value represents the light transmittance of the line; the smaller the line transparency value, the more transparent the line. The line transparency value is a value between 0 and 1. The pixel transparency value represents the light transmittance of the pixel; similarly, the smaller the pixel transparency value, the more transparent the pixel. The pixel transparency of a line is less than or equal to the line transparency.
[0074] In this embodiment, the transparency value of each target pixel includes: calculating the transparency value of each overlapping line segment pixel by parallel calculation of the line transparency value and the corresponding second pixel transparency value according to a first formula, whereby A3 = 1 - CA2 + A2, where A3 represents the transparency value of each target pixel, CA2 represents the line transparency value of the second connecting line, and A2 represents the transparency value of the corresponding second pixel. In other words, the transparency value of each target pixel can be calculated solely based on the second line transparency value and the second pixel transparency value corresponding to the overlapping line segment. The second pixel transparency value and the second line transparency value are pre-provided by the graphics software according to the style of the drawn lines; therefore, parallel calculation can be achieved when calculating the transparency value of each target pixel.
[0075] The color value mixing unit 1023 is used to calculate the color channel value of each overlapping line segment pixel based on the transparency value of the target pixel, the color channel value of the corresponding first pixel, and the color channel value of the second pixel.
[0076] In this embodiment, each target color channel value is calculated based on the corresponding first color channel value, second color channel value, and the line transparency value. In this embodiment, each target color channel value includes values from multiple color channels. Understandably, the number of color channels can be set according to the desired color. For example, a CMYK image has four channels by default: cyan, magenta, yellow, and black. By default, bitmap, grayscale, duotone, and indexed color images have only one channel. RGB and Lab images have three channels, and CMYK images have four channels. In this embodiment, three channels of RGB are used as an example.
[0077] Specifically, the corresponding first color channel value, second color channel value, and line transparency value of the overlapping line segments are calculated in parallel according to the second formula to obtain several target color channel values corresponding to each pixel point of the overlapping line segment. The second formula is: W3=W1*(1-CA2)+W2, where W3 represents the line transparency value of the second connecting line, CA2 represents the line transparency value of the second connecting line, and W3, W1, and W represent the target color channel values of the target pixel point, the first pixel point, and the second pixel point on the same channel, respectively.
[0078] For example, consider a target pixel P in the overlapping line segment L12. Target pixel P in the overlapping line segment L12 is obtained by mixing the first pixel PA1 in the first connecting line L1 and the second pixel P2A in the second connecting line L2. The first pixel P1A is represented as [R1, G1, B1, A1], where R1 represents the red channel value of the first pixel P1A, G1 represents the green channel value of the first pixel P1A, B1 represents the blue channel value of the first pixel P1A, and A1 represents the transparency value of the first pixel P1A. The second pixel P2A is represented as [R2, G2, B2, A2], where R2 represents the red channel value of the second pixel P2A, G2 represents the green channel value of the second pixel P2A, B2 represents the blue channel value of the second pixel P2A, and A2 represents the transparency value of the second pixel P2A. The transparency value of the second connecting line is still represented by CA2. The target pixel P is represented as [R3, G3, B3, A3], where R3 represents the red channel value of the target pixel P, G3 represents the green channel value of the target pixel P, B3 represents the blue channel value of the target pixel P, and A3 represents the transparency value of the target pixel P.
[0079] The transparency value of the target pixel P is: A3 = 1 - CA2 + A2. R3 represents the red channel value of the target pixel P, expressed as:
[0080] R3 = (R1*A1*(1-CA2) + R2*A2) / A3;
[0081] G3= (G1*A1*(1-CA2) + G2*A2) / A3;
[0082] B3= (B1*A1*(1-CA2) + B2*A2) / A3.
[0083] Since the calculation of one color channel value of the target pixel P is not related to the calculation of the other color channel value, but only to the value of its own color channel and the pixel transparency value of the target pixel, the color channel value of each target pixel can be calculated in parallel when the pixel transparency value of the target pixel is obtained.
[0084] In the above embodiments, the first calculation formula and the second calculation formula enable parallel computing in each calculation process, which greatly improves the efficiency of computing.
[0085] Please refer to Figure 7 This is a schematic diagram of an electronic device that implements the merging of connecting lines in the drawing provided in this application embodiment. The electronic device 90 includes a memory 901 and a processor 902.
[0086] The memory 901 is used to store computer instructions for drawing the merging of connecting lines in a graphic.
[0087] Processor 902 is used to execute computer instructions for merging and drawing in memory 901 to implement the method of merging and drawing connecting lines in the graphic. In this embodiment, processor 902 uses a GPU to achieve parallel computing.
[0088] The memory 901 includes at least one type of readable storage medium, including flash memory, hard disk, multimedia card, card-type memory (e.g., SD or DX memory), magnetic memory, magnetic disk, optical disk, etc. In some embodiments, the memory 901 can be an internal storage unit of a computer device, such as a hard disk. In other embodiments, the memory 901 can be an external storage device of a computer device, such as a plug-in hard disk, Smart Media Card (SMC), Secure Digital (SD) card, Flash Card, etc., configured in the computer device. Furthermore, the memory 901 can include both internal and external storage units of a computer device. The memory 901 can be used not only to store application software and various types of data installed on the computer device, such as code for displaying WPF lists, but also to temporarily store data that has been output or will be output.
[0089] Obviously, those skilled in the art can make various modifications and variations to this application without departing from the spirit and scope of this application. Therefore, if such modifications and variations fall within the scope of the claims of this application and their equivalents, this application also intends to include such modifications and variations.
[0090] The above-listed embodiments are merely preferred embodiments of this application and should not be construed as limiting the scope of this application. Therefore, any equivalent variations made in accordance with the claims of this application shall still fall within the scope of this application.
Claims
1. A method for drawing merging connecting lines in a graphic, characterized in that, The method for merging connecting lines in the graphic includes: A first connection line is generated in response to a first operation triggered by the user, and a second connection line is generated in response to a second operation triggered by the user; When the second connecting line and the first connecting line have overlapping segments, the corresponding first pixels and second pixels of the overlapping segments are mixed to obtain overlapping segments; wherein, the first pixels are pixels of the first connecting line, and the second pixels are pixels of the second connecting line; Generate corresponding target lines based on the overlapping and non-overlapping line segments; Each first pixel includes several first color channel values and a first pixel transparency value; each second pixel includes several second color channel values and a second pixel transparency value; each target pixel of an overlapping line segment includes several target color channel values and a target pixel transparency value; and the process of mixing corresponding first pixels and second pixels of an overlapping line segment to obtain an overlapping line segment includes: generating the line transparency value of the second connecting line, wherein the transparency value of each target pixel is calculated based on the line transparency value and the corresponding second pixel transparency value. The transparency values of the lines and the corresponding second pixel are calculated in parallel according to the first formula to obtain the transparency value of the target pixel of each overlapping line segment. The first formula is: A3=1-CA2+A2, where A3 represents the transparency value of each target pixel, CA2 represents the line transparency value of the second connecting line, and A2 represents the transparency value of the corresponding second pixel. The pixel transparency of a line is less than or equal to the line transparency. Calculate the color channel value of the target pixel for each overlapping line segment based on the transparency value of the target pixel, the color channel value of the corresponding first pixel, and the color channel value of the second pixel. The target color channel values corresponding to the target pixel point of each overlapping line segment are calculated using the second formula W3=(W1*(1-CA2)+W2) / A3, where CA2 represents the line transparency value of the second connecting line, and W3, W1 and W2 represent the color channel values of the target pixel point, the first pixel point and the second pixel point on the same channel, respectively.
2. The method for merging and drawing connecting lines in a graphic as described in claim 1, characterized in that, The method for merging connecting lines in the graphic also includes: All first pixels of the first connecting line and all second pixels of the second connecting line are stored in the first buffer frame and the second buffer frame, respectively. The first pixel in the first buffer frame is replaced with the target pixel of the overlapping line segment, and the second pixel corresponding to the non-overlapping line segment is added to the first buffer frame from the second buffer frame. The pixels in the first buffer frame are the pixels of the target line.
3. The method for merging connecting lines in the figure as described in claim 2, characterized in that, The GPU is used to perform parallel mixing of corresponding first pixels and second pixels of overlapping line segments to obtain the target pixels of the overlapping line segments.
4. A device for drawing merging connecting lines in a graphic, characterized in that, The device for merging connecting lines in a drawing includes: The single-line generation module generates a first connecting line in response to a first operation triggered by the user, and generates a second connecting line in response to a second operation triggered by the user. A mixing processing module is used to, when there is an overlapping segment between the second connecting line and the first connecting line, mix a number of first pixels and a number of second pixels corresponding to the overlapping segment to obtain an overlapping segment; wherein, the first pixels are pixels of the first connecting line, and the second pixels are pixels of the second connecting line; The target line generation module is used to generate corresponding target lines based on the overlapping and non-overlapping line segments. Each first pixel includes several first color channel values and a first pixel transparency value; each second pixel includes several second color channel values and a second pixel transparency value; each target pixel of an overlapping line segment includes several target color channel values and a target pixel transparency value; mixing the corresponding several first pixels and several second pixels of the overlapping line segment to obtain the overlapping line segment includes: generating the line transparency value of the second connecting line, wherein each target pixel transparency value is calculated based on the line transparency value and the corresponding second pixel transparency value; The transparency values of the lines and the corresponding second pixel are calculated in parallel according to the first formula to obtain the transparency value of the target pixel of each overlapping line segment. The first formula is: A3=1-CA2+A2, where A3 represents the transparency value of each target pixel, CA2 represents the line transparency value of the second connecting line, and A2 represents the transparency value of the corresponding second pixel. The pixel transparency of a line is less than or equal to the line transparency. Calculate the color channel value of the target pixel for each overlapping line segment based on the transparency value of the target pixel, the color channel value of the corresponding first pixel, and the color channel value of the second pixel. The target color channel values corresponding to the target pixel point of each overlapping line segment are calculated using the second formula W3=(W1*(1-CA2)+W2) / A3, where CA2 represents the line transparency value of the second connecting line, and W3, W1 and W2 represent the color channel values of the target pixel point, the first pixel point and the second pixel point on the same channel, respectively.
5. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer-executable program, which is executed by a processor to implement the method for merging and drawing connecting lines in a graphic as described in any one of claims 1-3.
6. An electronic device that uses merged connecting lines in a graphic, characterized in that, The electronic device includes: Memory, used to store computer executable programs; and A processor is configured to execute the computer-executable program to implement the method for merging and drawing connecting lines in a graphic as described in any one of claims 1-3.