A two-pixel width line segment anti-aliasing method

By calculating the slope of the straight line and determining the compensation point, the Wu algorithm is used to draw a two-pixel width line segment, which solves the problems of complex algorithms and large calculations in the existing technology, and achieves good anti-aliasing effects and endpoint stability under limited processor resources. sex.

CN114332296BActive Publication Date: 2024-10-01TAIYUAN AERO INSTR
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202111658619.8
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-12-30
Publication Date
2024-10-01
Estimated Expiration
2041-12-30

AI Technical Summary

Technical Problem

When drawing a line segment with a width of two pixels, the existing technology has problems such as complex algorithm and large amount of calculation, resulting in performance loss and endpoint jitter. It is especially difficult to achieve a good anti-aliasing effect when processor resources are limited.

Method used

By calculating the slope of the straight line and determining the compensation points at the endpoints, the Wu algorithm is used to draw the line segments, and the grayscale of the compensation points is calculated based on the compensation coefficient, which reduces the amount of calculation and improves the anti-aliasing effect.

Benefits of technology

Under the condition of limited processor resources, it achieves better anti-aliasing effect, reduces endpoint jitter, and optimizes CPU calculation amount and display effect.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114332296B_ABST
    Figure CN114332296B_ABST
Patent Text Reader

Abstract

The present invention belongs to the field of graphics processing, and specifically relates to an anti-aliasing method for a two-pixel width line segment. Calculate the slope k of a straight line; determine the compensation points of the endpoints (X1, Y1) and (X2, Y2) as well as the starting point P4 and the end point Q1 and calculate the compensation coefficients of each compensation point, wherein the starting point P4 is (X1int+1, Y1int‑1) and the end point Q1 is (X2int, Y2int), X1int is the integer part of X1, Y1int is the integer part of Y1, X2int is the integer part of X2, and Y2int is the integer part of Y2; calculate the correction coefficient of the starting point from the straight line Distance, the corrected distance is dP4=k‑k×X1real+Y1real+0.5, X1real is the fractional part of X1, Y1real is the fractional part of Y1; take the initial point as point P4, dP4 as the initial distance of point P4, use Wu algorithm to draw the line segment from P1 to Q1, P1 is the point after the coordinates of the endpoint (X1, Y1) are rounded; determine the grayscale of the compensation point according to the compensation coefficient of each compensation point, compensation point grayscale = background color + (foreground color‑background color) * compensation coefficient. Reduce the phenomenon of obvious jitter of the endpoints of a two-pixel width line segment when rotating.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to the field of graphics processing, and particularly relates to an anti-aliasing method for a two-pixel-wide line segment. Background Art

[0002] A line segment is one of the basic primitives for graphic display, and the drawing of a two-pixel-wide straight line is widely used in on-board cockpit displays. The line segment is visualized as a rectangle, but raster discrete pixelation is required during display, resulting in aliasing. Common anti-aliasing methods are as follows: Method 1: Use the supersampling algorithm to perform anti-aliasing drawing of any line segment. This method refines each pixel point into multiple sub-pixel points again, and obtains the color of the pixel through sampling and weighted averaging of the sub-pixel points. The drawing effect obtained by this method is good, but the number of pixel points to be processed is multiple times the initial number, and a large number of floating-point operations are required, which has a great impact on performance. Method 2: Use the Wu algorithm to perform anti-aliasing drawing of any line segment. This method is all integer operations and the drawing speed is relatively fast; however, the display aliasing at the line segment endpoints is obvious, and the rectangular line segments with different slopes are displayed as parallelogram shapes. Method 3: After visualizing the line segment, use raster row / column scanning to calculate the distance between the points and the straight line, calculate the color weight of the points, and perform anti-aliasing drawing. This method has high applicability and is effective for drawing line segments of any thickness, but the calculation amount is still large. Summary of the Invention

[0003] The object of the present invention is to provide an anti-aliasing method for a two-pixel-wide line segment to achieve a better anti-aliasing effect without causing a large loss of performance.

[0004] The technical solution of the present invention:

[0005] An anti-aliasing method for a two-pixel-wide line segment, comprising:

[0006] Calculate the slope k of the straight line, where the slope k is determined according to the endpoint coordinates (X1, Y1) and (X2, Y2);

[0007] For a straight line with a slope of 0 to 1 and X1 < X2:

[0008] Determine the compensation points of the endpoints (X1, Y1) and (X2, Y2), as well as the starting point P4 and the ending point Q1, and calculate the compensation coefficients of each compensation point, where the starting point P4 is (X1int + 1, Y1int - 1) and the ending point Q1 (X2int, Y2int), where X1int is the integer part of X1, Y1int is the integer part of Y1, X2int is the integer part of X2, and Y2int is the integer part of Y2;

[0009] Calculate the corrected distance between the starting point and the straight line. The corrected distance is dP4=kk×X1real+Y1real+0.5, where X1real is the decimal part of X1 and Y1real is the decimal part of Y1.

[0010] Take P4 as the initial point and dP4 as the initial distance of P4, and use Wu algorithm to draw the line segment from P1 to Q1, where P1 is the point after the coordinates of the endpoint (X1, Y1) are rounded off;

[0011] The grayscale of the compensation point is determined according to the compensation coefficient of each compensation point. The grayscale of the compensation point = background color + (foreground color - background color) * compensation coefficient.

[0012] Furthermore, the compensation point of the endpoint (X1, Y1) is determined as follows:

[0013] The compensation points of the endpoint (X1, Y1) are P0 (X1int, Y1int-1), P1 (X1int, Y1int), P2 (X1int, Y1int+1), and P3 (X1int, Y1int+2).

[0014] Furthermore, the compensation point of the endpoint (X2, Y2) is determined as follows:

[0015] The compensation points of the endpoint ((X2, Y2) are Q4 (X2int+1, Y2int-1), Q5 (X2int+1, Y2int), Q6 (X2int+1, Y2int+1), and Q7 (X2int+1, Y2int+2).

[0016] Furthermore, the compensation coefficient of each compensation point is calculated, specifically including:

[0017] The compensation coefficient of P0 is: coeColorGreyP0 = (1-X1real) × (0.5-Y1real-k / 4);

[0018] The compensation coefficient of P3 is: coeColorGreyP3=(1-X1real)×(Y1real-0.5+k / 4).

[0019] Furthermore, the compensation coefficient of each compensation point is calculated, specifically including:

[0020] When Y1real is less than or equal to 0.5,

[0021] The compensation coefficient of P1 is: coeColorGreyP1 = (1-X1real) × (1-(1.0+Y1real) × k / 4);

[0022] The compensation coefficient of P2 is: coeColorGreyP2 = (1-X1real) × (0.5+Y1real+k / 4);

[0023] When Y1real is greater than 0.5,

[0024] The compensation coefficient of P1 is: coeColorGreyP1 = (1-X1real) × (1.5-Y1real-k / 4);

[0025] The compensation coefficient of P2 is: coeColorGreyP2 = (1-X1real)×(1-(Y1real-0.5)×k / 4).

[0026] Furthermore, the compensation coefficient of each compensation point is calculated, specifically including:

[0027] The compensation coefficient of Q4 is: coeColorGreyQ4=X2real×(0.5-Y2real+k / 4);

[0028] The compensation coefficient of Q7 is: coeColorGreyQ7=X2real×(Y2real-0.5-k / 4).

[0029] Furthermore, the compensation coefficient of each compensation point is calculated, specifically including:

[0030] When Y2real is less than or equal to 0.5,

[0031] The compensation coefficient of Q5 is: coeColorGreyQ5=X2real×(1-(0.5-Y2real)×k / 4);

[0032] The compensation coefficient of Q6 is: coeColorGreyQ6=X2real×(0.5+Y2real-k / 4);

[0033] When Y2real is greater than 0.5,

[0034] The compensation coefficient of Q5 is: coeColorGreyQ5=X2real×(1.5-Y2real+k / 4);

[0035] The compensation coefficient of Q6 is: coeColorGreyQ6=X2real×(1-(1.5-Y2real)×k / 4).

[0036] An anti-aliasing device for a line segment with a width of two pixels, comprising:

[0037] A first calculation module is specifically used to calculate the slope k of the straight line, wherein the slope k is determined according to the coordinates of the endpoints (X1, Y1) and (X2, Y2);

[0038] A determination and calculation module, used to determine the compensation points of the endpoints (X1, Y1) and (X2, Y2) as well as the starting point P4 and the end point Q1 and calculate the compensation coefficients of the respective compensation points, wherein the starting point P4 is (X1int+1, Y1int-1) and the end point Q1 is (X2int, Y2int), wherein X1int is the integer part of X1, Y1int is the integer part of Y1, X2int is the integer part of X2, and Y2int is the integer part of Y2;

[0039] The second calculation module is used to calculate the corrected distance between the starting point and the straight line, and the corrected distance is dP4=k-(k×X1real-Y1real-1)-0.5, where X1real is the decimal part of X1 and Y1real is the decimal part of Y1;

[0040] The line segment drawing module is used to draw the line segment from P1 to Q1 using the Wu algorithm with the initial point as point P4 and dP4 as the initial distance of point P4, wherein P1 is the point after the coordinates of the endpoints (X1, Y1) are rounded off;

[0041] The compensation point grayscale determination module is used to determine the compensation point grayscale according to the compensation coefficient of each compensation point, where the compensation point grayscale = background color + (foreground color - background color) * compensation coefficient.

[0042] Beneficial effects of the present invention:

[0043] The present invention performs a filler process on the endpoints of commonly used two-pixel width line segments, so that the two-pixel width line segments do not cause a large performance loss when drawing under the condition of limited processor resources, and can achieve a better anti-aliasing effect. The phenomenon of obvious jitter of the endpoints of the two-pixel width line segments when rotating is reduced, and at the same time, the CPU calculation amount and display effect are combined, providing a more suitable method for drawing two-pixel width line segments. BRIEF DESCRIPTION OF THE DRAWINGS

[0044] Figure 1 This is the display effect diagram of the two-pixel width line segment after enlargement; the upper straight line is the two-pixel width line segment after endpoint compensation, and the lower line segment is the two-pixel width line segment without endpoint compensation.

[0045] The black dotted line in the figure is a schematic diagram of the visually similar effect.

[0046] Figure 2 Schematic diagram of the position of the compensation point at the end point of the line segment.

[0047] Figure 3 The order of drawing anti-aliased segments with endpoint compensation;

[0048] Figure 4It is a schematic diagram of the positions of the anti-aliasing points and foreground color filling points of the Wu algorithm. Specific implementation mode

[0049] The present invention mainly solves the problems of complex algorithm and large amount of calculation encountered in drawing anti-aliased line segments with a common two-pixel width in a miniaturized and graphics driver-free processor according to the existing technical solutions. The present invention performs head supplementation processing on the endpoints of common two-pixel width line segments, so that when drawing under the condition of limited processor resources, the two-pixel width line segments will not cause a large loss of performance and can achieve a better anti-aliasing effect.

[0050] The following will clearly and completely describe the technical solutions in the embodiments of the present invention with reference to the accompanying drawings in the embodiments of the present invention. Obviously, the described embodiments are only a part of the embodiments of the present invention, rather than all the embodiments. All other embodiments obtained by those of ordinary skill in the art based on the embodiments of the present invention without creative efforts shall fall within the protection scope of the present invention.

[0051] For a line segment with a width of two pixels and any slope, the four-point compensation method is adopted for its endpoints, so that it visually appears as a rectangle rather than a parallelogram (see Figure 1 ), thereby enhancing its anti-aliasing effect.

[0052] Taking a straight line with a slope of 0 to 1 and X1 < X2 as an example (as shown in Figure 2 ), for the line segment {(X1, Y1), (X2, Y2)}, let X1int and Y1int represent the integer parts of X1 and Y1 respectively, and X1real and Y1real represent the fractional parts of X1 and Y1 respectively. Then X1 = X1int + X1real, and Y1 = Y1int + Y1real. For the left endpoint (X1, Y1), endpoint compensation is performed through P0(X1int, Y1int - 1), P1(X1int, Y1int), P2(X1int, Y1int + 1), and P3(X1int, Y1int + 2). As shown in Figure 3 , the specific implementation of its endpoint compensation is as follows:

[0053] Step 1: Calculate the slope k of the straight line;

[0054] k = (Y2 - Y1) / (X2 - X1);

[0055] Step 2: Perform compensation on the endpoint (X1, Y1) using points P0, P1, P2, and P3, and calculate the compensation coefficients of each point;

[0056] P0 compensation coefficient: coeColorGreyP0 = (1 - X1real) × (0.5 - Y1real - k / 4);

[0057] P3 compensation coefficient: coeColorGreyP3 = (1-X1real) × (Y1real-0.5+k / 4);

[0058] When Y1real is less than or equal to 0.5,

[0059] P1 compensation coefficient: coeColorGreyP1 = (1-X1real) × (1-(1.0+Y1real) × k / 4);

[0060] P2 compensation coefficient: coeColorGreyP2 = (1-X1real) × (0.5+Y1real+k / 4);

[0061] When Y1real is greater than 0.5,

[0062] P1 compensation coefficient: coeColorGreyP1 = (1-X1real) × (1.5-Y1real-k / 4);

[0063] P2 compensation coefficient: coeColorGreyP2 = (1-X1real) × (1-(Y1real-0.5) × k / 4);

[0064] Step 3: Use points Q4, Q5, Q6, and Q7 to compensate the endpoints (X2, Y2) and calculate the compensation coefficients of each point;

[0065] Q4 compensation coefficient: coeColorGreyQ4=X2real×(0.5-Y2real+k / 4);

[0066] Q7 compensation coefficient: coeColorGreyQ7=X2real×(Y2real-0.5-k / 4);

[0067] When Y2real is less than or equal to 0.5,

[0068] Q5 compensation coefficient: coeColorGreyQ5=X2real×(1-(0.5-Y2real)×k / 4);

[0069] Q6 compensation coefficient: coeColorGreyQ6=X2real×(0.5+Y2real-k / 4);

[0070] When Y2real is greater than 0.5,

[0071] Q5 compensation coefficient: coeColorGreyQ5=X2real×(1.5-Y2real+k / 4);

[0072] Q6 compensation coefficient: coeColorGreyQ6 = X2real × (1 - (1.5 - Y2real) × k / 4);

[0073] Step 5: Calculate the perpendicular distance dP0 from point P0 to the straight line (the straight line determined by endpoints (X1, Y1) and (X2, Y2)): dP0 = k × X1real - Y1real - 1;

[0074] Step 6: Calculate the corrected distance of point P4 from the straight line (the straight line determined by endpoints (X1, Y1) and (X2, Y2)): dP4 = k - dP0 - 0.5;

[0075] Step 7: With the initial point being point P4 and dP4 being the initial distance of point P4, use the Wu algorithm to draw the line segment from P1 to Q1, where P1 is the point obtained by rounding the coordinates of endpoint (X1, Y1);

[0076] Specifically: With the initial point being point P4 and dP4 being the initial distance of point P4, use the Wu algorithm to draw a 1-pixel-wide line segment with a slope of k and the x-axis coordinate in the interval [X1int + 1, X2int]. After drawing the first anti-aliasing point in each column, fill the foreground color at the pixel point whose ordinate is 1 greater than the ordinate of the first anti-aliasing point, draw the second anti-aliasing point at the position whose ordinate is 2 greater than the ordinate of the first anti-aliasing point, and complete the drawing column by column; The position schematic diagram of the anti-aliasing points and the filling points is as Figure 4 shown;

[0077] Step 8: Draw each compensation point;

[0078] Compensation point color = background color + (foreground color - background color) * compensation coefficient.

[0079] For the drawing of a straight line with a slope between 0 and 1 and X2 < X1, when drawing, just swap the left and right endpoints of the line segment, and the compensation points do not need to change.

[0080] For the drawing between -1 and 0 and X1 < X2, when using the Wu algorithm for line breaks, use y = y - 1 and swap the compensation points of the left and right endpoints.

[0081] For the drawing between -1 and 0 and X2 < X1, swap the left and right endpoints of the line segment, and when using the Wu algorithm for line breaks, use y = y - 1 and swap the compensation points of the left and right endpoints.

[0082] For the case where the absolute value of the slope is greater than 1, when drawing, swap the x and y coordinates of all points.

[0083] The above is only a specific embodiment of the present invention, and the present invention is described in detail. The unexplained part is a conventional technology. However, the protection scope of the present invention is not limited to this. Any changes or substitutions that can be easily thought of by any technician familiar with the technical field within the technical scope disclosed by the present invention should be included in the protection scope of the present invention. The protection scope of the present invention shall be based on the protection scope of the claims.

Claims

1. A two-pixel width line segment anti-aliasing method, characterized in that: It includes: Calculate the slope k of the straight line, where the slope k is determined according to the endpoint coordinates (X1, Y1) and (X2, Y2); For a straight line with a slope of 0 to 1 and X1 < X2: Determine the compensation points of the endpoints (X1, Y1) and (X2, Y2), as well as the starting point P4 and the ending point Q1, and calculate the compensation coefficients of each compensation point. The starting point P4 is (X1int + 1, Y1int - 1), and the ending point Q1 is (X2int, Y2int), where X1int is the integer part of X1, Y1int is the integer part of Y1, X2int is the integer part of X2, and Y2int is the integer part of Y2; Calculate the corrected distance from the starting point to the straight line. The corrected distance is dP4 = k - k × X1real + Y1real + 0.5, where X1real is the fractional part of X1 and Y1real is the fractional part of Y1; Taking the initial point as point P4 and dP4 as the initial distance of point P4, use the Wu algorithm to draw the line segment from P1 to Q1, where P1 is the point obtained by rounding the coordinates of the endpoint (X1, Y1); Determine the grayscale of the compensation points according to the compensation coefficients of each compensation point. The grayscale of the compensation point = background color + (foreground color - background color) * compensation coefficient.

2. The anti-aliasing method according to claim 1, characterized in that: Determine the compensation point of the endpoint (X1, Y1), specifically: The compensation points of the endpoint (X1, Y1) are P0(X1int, Y1int - 1), P1(X1int, Y1int), P2(X1int, Y1int + 1), P3(X1int, Y1int + 2).

3. The anti-aliasing method according to claim 1, characterized in that: Determine the compensation point of the endpoint (X2, Y2), specifically: The compensation points of the endpoint ((X2, Y2) are Q4(X2int + 1, Y2int - 1), Q5(X2int + 1, Y2int), Q6(X2int + 1, Y2int + 1), Q7(X2int + 1, Y2int + 2).

4. The anti-aliasing method according to claim 1, characterized in that: Calculate the compensation coefficients of each compensation point, specifically including: The compensation coefficient of P0 is: coeColorGreyP0 = (1 - X1real) × (0.5 - Y1real - k / 4); The compensation coefficient of P3 is: coeColorGreyP3 = (1 - X1real) × (Y1real - 0.5 + k / 4).

5. The anti-aliasing method according to claim 1, characterized in that: Calculate the compensation coefficients of each compensation point, specifically including: When Y1real is less than or equal to 0.5, The compensation coefficient of P1 is: coeColorGreyP1 = (1 - X1real) × (1 - (1.0 + Y1real) × k / 4); The compensation coefficient of P2 is: coeColorGreyP2 = (1 - X1real) × (0.5 + Y1real + k / 4); When Y1real is greater than 0.5, The compensation coefficient of P1 is: coeColorGreyP1 = (1 - X1real) × (1.5 - Y1real - k / 4); The compensation coefficient of P2 is: coeColorGreyP2 = (1-X1real)×(1-(Y1real-0.5)×k / 4).

6. The anti-aliasing method according to claim 1, characterized in that: Calculate the compensation coefficient of each compensation point, including: The compensation coefficient of Q4 is: coeColorGreyQ4=X2real×(0.5-Y2real+k / 4); The compensation coefficient of Q7 is: coeColorGreyQ7=X2real×(Y2real-0.5-k / 4).

7. The anti-aliasing method according to claim 1, characterized in that: Calculate the compensation coefficient of each compensation point, including: When Y2real is less than or equal to 0.5, The compensation coefficient of Q5 is: coeColorGreyQ5=X2real×(1-(0.5-Y2real)×k / 4); The compensation coefficient of Q6 is: coeColorGreyQ6=X2real×(0.5+Y2real-k / 4); When Y2real is greater than 0.5, The compensation coefficient of Q5 is: coeColorGreyQ5=X2real×(1.5-Y2real+k / 4); The compensation coefficient of Q6 is: coeColorGreyQ6=X2real×(1-(1.5-Y2real)×k / 4).

8. An anti-aliasing device for a two-pixel width line segment, characterized in that: include: A first calculation module is specifically used to calculate the slope k of the straight line, wherein the slope k is determined according to the coordinates of the endpoints (X1, Y1) and (X2, Y2); A determination and calculation module, used to determine the compensation points of the endpoints (X1, Y1) and (X2, Y2) as well as the starting point P4 and the end point Q1 and calculate the compensation coefficients of the respective compensation points, wherein the starting point P4 is (X1int+1, Y1int-1) and the end point Q1 is (X2int, Y2int), wherein X1int is the integer part of X1, Y1int is the integer part of Y1, X2int is the integer part of X2, and Y2int is the integer part of Y2; The second calculation module is used to calculate the corrected distance between the starting point and the straight line, and the corrected distance is dP4=k-(k×X1real-Y1real-1)-0.5, where X1real is the decimal part of X1 and Y1real is the decimal part of Y1; The line segment drawing module is used to draw the line segment from P1 to Q1 using the Wu algorithm with the initial point as point P4 and dP4 as the initial distance of point P4, wherein P1 is the point after the coordinates of the endpoints (X1, Y1) are rounded off; The compensation point grayscale determination module is used to determine the compensation point grayscale according to the compensation coefficient of each compensation point, where the compensation point grayscale = background color + (foreground color - background color) * compensation coefficient.