Method, apparatus and medium for eliminating quantization jaggies in graphics in gdi
By constructing integer straight lines and calculating vertex coordinate correction vectors in the GDI environment, and cyclically correcting vertex coordinates, the problem of jagged edges in track graphics quantization is solved, achieving efficient drawing and shape consistency.
Patent Information
- Application Number
- CN202511230280.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-08-29
- Publication Date
- 2026-08-25
- Estimated Expiration
- 2045-08-29
AI Technical Summary
In the GDI environment, the quantization error caused by rounding in the track pattern results in a jagged effect, which cannot be effectively solved by existing technologies.
By acquiring the vertex data of the graphic to be processed, calculating the slope and intercept of the line formed by two adjacent vertices, constructing integer lines and calculating vertex coordinate correction vectors, iteratively correcting vertex coordinates, rounding them, and writing them back to the graphic data to eliminate jagged edges.
GDI effectively eliminates jagged edges in graphic quantization, maintains the shape consistency of graphics when integerized, improves drawing efficiency, and adapts to the drawing of orbital graphics in various special cases.
Smart Images

Figure CN121190343B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of railway station map drawing, and in particular to a method, apparatus and medium for eliminating graphic quantization jagged edges in GDI. Background Technology
[0002] In the field of 2D graphics rendering, to meet the needs of the renderer, 2D graphics undergo numerous affine transformations, such as translation, rotation, stretching, and shearing, to process the original graphic into the desired shape. If the rendering software uses a graphics library such as GDI+ at the underlying level, the corresponding 2D graphic coordinates can be represented with floating-point precision. Such graphics will not have coordinate point offsets after affine transformations because floating-point coordinates have sufficiently high precision. However, the trade-off for this is higher performance requirements and slower rendering speed when rendering a large number of graphics.
[0003] In the field of station map drawing, a single station map contains a large number of track graphics. Using the aforementioned method would severely impact drawing performance. Therefore, graphics drawing software employs the simpler and more efficient GDI graphics library when drawing track graphics. In the GDI environment, the coordinates of 2D graphics are represented with integer precision, while affine transformation matrices are represented with floating-point precision. Therefore, after an affine transformation, the 2D graphic is automatically converted to a floating-point number, and then needs to be rounded back to integers before being submitted to GDI for drawing. Quantization error originates from this rounding process.
[0004] In conclusion, quantization errors lead to noticeable jagged edges in the graphics. This is because the rounding algorithm treats each vertex of the 2D graphic in isolation, obtaining coordinates through simple nonlinear transformations. While two vertices on the hypotenuse of the track graphic might lie on the same straight line in the floating-point stage, rounding may cause them to be scattered on opposite sides of that line. The line connecting these two integer vertices will then be drawn as a jagged line in GDI. If only the coordinates of a single vertex on a straight line were offset, such coordinate correction algorithms would be easy. However, the problem lies in the fact that the track graphic is a closed quadrilateral that may have hypotenuses; correcting one hypotenuse might deform the adjacent side. Therefore, a holistic, interconnected, and dynamic approach to the entire quantization process of the graphic coordinates is necessary to solve this problem.
[0005] A search revealed that U.S. Patent Application Publication No. US11417058B2 discloses an anti-aliasing process for two-dimensional vector graphics using a multi-vertex buffer, comprising: instructions that, when executed by at least one processor, cause a computing device to: determine a control triangle representing a vector path in the two-dimensional vector graphics; and generate extended geometry for the control triangle according to the anti-aliasing direction of the vector path in the following manner:
[0006] The method involves generating an extended rectangle that encloses a control triangle and extends beyond the corresponding enclosing rectangle of the control triangle in the anti-aliasing direction; determining a first triangle and a second triangle within the extended rectangle based on the vertices of the extended rectangle; generating a first multi-vertex buffer entry including the vertex positions of the vertices in the first triangle and a second multi-vertex buffer entry including the vertex positions of the vertices in the first triangle by combining each vertex data of the vertices in the second triangle into the second multi-vertex buffer entry; and processing the first and second multi-vertex buffer entries by a graphics processing unit to render a two-dimensional vector graphic with anti-aliasing for a vector path. This prior art patent application suffers from an inability to resolve the aliasing issue caused by rounding in graphics quantization.
[0007] How to eliminate aliasing in orbital graphics quantization in GDI has become a technical problem that needs to be solved. Summary of the Invention
[0008] The purpose of this invention is to overcome the defects of the prior art by providing a method, apparatus and medium for eliminating jagged edges in graphic quantization in GDI.
[0009] The objective of this invention can be achieved through the following technical solutions:
[0010] According to a first aspect of the present invention, a method for eliminating graphics quantization aliasing in GDI is provided, comprising:
[0011] Obtain the vertex data of the graphic to be processed, and cache the vertex data after affine transformation;
[0012] Construct an integer line based on the slope and intercept of the line formed by two adjacent vertices, and calculate the vertex coordinate correction vector;
[0013] Iterate through each vertex, and use the vertex coordinate correction vector calculated from the coordinates of the previous vertex to iteratively correct the coordinates of the next adjacent vertex. Round the corrected vertex coordinates to obtain integer vertex coordinates, and update the vertex coordinate correction vector for the correction of the next vertex.
[0014] Once the traversal is complete, write the integer vertex coordinates back to the graphics data and clear the cache.
[0015] Preferably, the calculation process of the vertex coordinate correction vector includes:
[0016] Assuming two adjacent vertices form a real line with slope k, and the intercept is b, after rounding the intercept b to an integer, we obtain the reference distance Δb for the integer line:
[0017] The shortest distance vector from the real line to the integer line is calculated based on Δb, and denoted as the vertex coordinate correction vector. More preferably, the specific formula for calculating the vertex coordinate correction vector is:
[0018] x Offset = (-k×Δb) / (1+k) 2 )
[0019] y Offset =Δb / (1+k) 2 )
[0020] in, x Offset and y offset These are the correction values of the vertex coordinate correction vector on the x-axis and y-axis, respectively.
[0021] Preferably, in the initialization correction vector stage, the first vertex and the last vertex are used as two adjacent vertices, the last vertex is defined as the previous vertex, and the first vertex is defined as the next vertex. An integer straight line is constructed based on the slope and intercept of the straight line formed by the two adjacent vertices to calculate the initial vertex coordinate correction vector.
[0022] Preferably, during the traversal process, if the currently traversed vertex shares the same point as the previous vertex, the current vertex coordinate correction vector is directly passed down to correct the next vertex.
[0023] Preferably, during the traversal, if the vertex coordinate correction vector is collinear with the vector formed by the coordinates of the preceding and following vertices, then the currently traversed vertex and the vertex immediately following it are taken as the preceding and following vertices, respectively. An integer straight line is constructed based on the two adjacent vertices, and the vertex coordinate correction vector is updated.
[0024] More preferably, the method for determining collinearity of vectors is: if the following conditions are met... Then determine the vertex coordinate correction vector. The vector formed by the coordinates of the front and rear vertices Collinear.
[0025] in,
[0026] Preferably, the process of cyclically correcting the coordinates of the next adjacent vertex based on the vertex coordinate correction vector includes:
[0027] Get the current vertex coordinate correction vector, apply it to the current vertex coordinates during loop iteration, and output the vertex coordinate update value;
[0028] Update the vertex coordinate correction vector using the current vertex coordinate update value and the current vertex coordinate update.
[0029] More preferably, the process of outputting the current vertex coordinate update value includes:
[0030] Get the current vertex coordinate correction vector It is applied to the coordinates of the current vertex reached in the current loop iteration, defining the current vertex pt. i =(x i ,y i The updated vertex coordinates of the output are defined as Output = (ptO1, ptO2, ..., ptO2). n ), stn≥2, where any point ptO i =(m i ,n i The formula for calculating ) is:
[0031]
[0032] Where n is the number of vertices, x Offset and y Offset These are the correction values of the vertex coordinate correction vector on the x-axis and y-axis, respectively.
[0033] More preferably, the process of updating the vertex coordinate correction vector using the current vertex coordinate update value and the current vertex coordinate includes:
[0034] Update the value ptO using the current vertex coordinates. i =(m i ,n i ) and the current vertex coordinates pt i =(x i ,y i Update the correction vector Make the correction vector The vertex coordinates are corrected for the next iteration, with the update formula being:
[0035] x Offset =m i -x i (i = 1, 2, ..., n)
[0036] y Offset =n i -y i (i = 1, 2, ..., n).
[0037] Preferably, if the graphic to be processed has only one vertex, the integer vertex coordinates obtained by rounding after affine transformation are used to write back the vertex data.
[0038] Preferably, if the straight line formed by two adjacent vertices is horizontal or vertical, the vertex coordinate correction vector is set to zero.
[0039] According to a second aspect of the present invention, an electronic device is provided, including a memory and a processor, wherein the memory stores a computer program, and the processor executes the program to implement the method described thereon.
[0040] According to a third aspect of the present invention, a computer-readable storage medium is provided having a computer program stored thereon, which, when executed by a processor, implements the method described thereon.
[0041] Compared with the prior art, the present invention has the following beneficial effects:
[0042] 1) This invention treats the edges of a graphic as straight lines, constructs integer straight lines based on two adjacent fixed points, and calculates vertex coordinate correction vectors by integerizing the straight line parameters. It iterates through the vertex positions of the graphic and iteratively corrects the coordinates of the adjacent next vertex based on the vertex coordinate correction vector calculated from the previous vertex coordinates to obtain integerized vertex coordinates. Ultimately, this makes the graphic maintain the same shape as in the real number domain when it is integerized, thus solving the problem of jagged edges caused by quantization errors.
[0043] 2) The present invention standardizes the integerization process of line parameters and the integerization process of graphic vertices, making full use of the positional relationship of each adjacent vertex. While maintaining efficient GDI drawing, the same shape is maintained during integerization as in the real number field, overcoming the defect of the prior art that the graphic vertices are viewed in isolation, which leads to graphic deformation.
[0044] 3) This invention takes into account the boundary conditions of various graphic vertices to adapt to various special situations that exist in actual drawing. While optimizing the track graphics in three cases of horizontal, vertical, and 45-degree oblique slant, it will not affect the normal drawing of other cases and other graphics.
[0045] 4) The above solution can automatically calibrate the vertex positions after the graphic undergoes affine transformation, without the need for the drawing staff to manually adjust the position of each vertex, thus improving the work efficiency of the drawing staff. Attached Figure Description
[0046] Figure 1 A schematic diagram illustrating the jagged edges caused by rounding quantization errors;
[0047] Figure 2 This invention utilizes an integerized linear equation method to iteratively correct quantization sawtooth patterns.
[0048] Figure 3 This is a schematic diagram illustrating the calculation of the correction vector and its effect using integerized linear equations.
[0049] Figure 4 This is a schematic diagram of the track pattern and the changes before and after a 45-degree rotation correction in an embodiment of the present invention. Detailed Implementation
[0050] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some, not all, of the embodiments of the present invention. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort should fall within the scope of protection of the present invention.
[0051] The method of this invention is specifically used to solve the problem of jagged edges in track graphics under GDI environment due to rounding quantization errors, such as... Figure 1 In the GDI environment, vertex data for orbital graphics is stored as integers. After an affine transformation, the vertex coordinates are converted to floating-point numbers. At this point, the graphic remains undistorted, and the reference dashed line closely aligns with the edge of the graphic. To store the transformed vertex data in the graphic, the vertex data needs to be converted from floating-point coordinates to integer coordinates. Simply rounding the vertex coordinates in isolation can cause some vertices originally on the same real-number line to shift their decimal parts to the left of the reference dashed line, while others may shift their decimal parts to the right, resulting in coordinate quantization errors. From a macroscopic GDI perspective, the edges of the graphic drawn from these two vertices are no longer smooth straight lines; the slope of the line is no longer 1. Therefore, GDI is forced to draw jagged edges.
[0052] Mathematically, it's impossible to guarantee that a straight line at two-dimensional integer coordinates will be jagged-free regardless of rotation angle. Furthermore, in practical applications of station map drawing, track graphics are mostly used for horizontal, vertical, and 45-degree angled maneuvers. Therefore, this invention focuses on how to eliminate quantized jagged edges in these three scenarios, enabling graphics drawing software to produce jagged-free track graphics within the existing GDI high-efficiency drawing environment without manual calibration by the drawing personnel.
[0053] Example 1
[0054] This embodiment relates to a method for eliminating aliasing in orbital pattern quantization in GDI, such as... Figure 2 ,include:
[0055] Step S1: Obtain the vertex data of the graphics to be processed, handle the boundary conditions, and cache the processed vertex data;
[0056] Step S2: Construct an integer-based straight line equation based on the slope and intercept of the straight line formed by two adjacent vertices, and select the first and last vertices to calculate the initial vertex coordinate correction vector;
[0057] Step S3: Traverse each vertex. If the current vertex and the next vertex are the same, pass the vertex coordinate correction vector directly and proceed to step S5; otherwise, proceed to step S4; if the traversal is complete, proceed to step S6.
[0058] Step S4: If the vertex coordinate correction vector (referred to as the correction vector) is collinear with the vector formed by the coordinates of the previous and next vertices (the current vertex and the adjacent previous vertex), then construct an integer straight line equation based on the current vertex and the adjacent next vertex, update the correction vector, and proceed to step S5; otherwise, proceed directly to step S5.
[0059] Step S5: Based on the correction vector calculated from the previous vertex coordinates, iteratively correct the coordinates of the adjacent next vertex. Round the corrected vertex coordinates to obtain integer vertex coordinates, update the correction vector for the next vertex correction, and return to step S3 to continue traversing. After the traversal is completed, write the rounded integer vertex coordinate values back to the graphics data, clear the calculation cache during the calculation process, and end.
[0060] Step S1 is as follows:
[0061] Step S11: Read the vertex data of the graphic;
[0062] Step S12: If the graph has only one vertex, use an affine transformation, round it off, and write back the vertex data.
[0063] Step S13: If the graph has two or more vertices, then perform an affine transformation and cache the vertex data after the affine transformation, defined as pt = (pt1, pt2, ..., pt2). n ), n≥2, where n is the number of vertices.
[0064] Step S2 is as follows:
[0065] Step S21: Obtain the coordinates of two adjacent vertices in the cache, and define the previous vertex pt. i =(x i ,y i ) and the next vertex pt j =(x j ,y j );
[0066] Step S22: Determine if two points are concurrent. If they are concurrent, do not process the correction vector. Skip step S2, the formula for determining concurrent points is:
[0067] Δx ij =x i -x j (i=1,2,…,n; j=1,2,…,n; i≠j)
[0068] Δy ij =y i -y j (i=1,2,…,n; j=1,2,…,n; i≠j)
[0069]
[0070] in,
[0071] Step S23: Determine whether the line formed by the two points is horizontal or perpendicular. If it is horizontal or perpendicular, then adjust the vector. Set the value to zero, then skip step S2. The formula for determining the level is:
[0072] Δy ij =y i -y j =0(i=1,2,…,n; j=1,2,…,n; i≠j),
[0073] The formula for determining perpendicularity is:
[0074] Δx ij =x i -x j =0(i=1,2,…,n; j=1,2,…,n; i≠j),
[0075] Step S24: Calculate the point-slope form of the real line formed by these two vertices. The specific formula is as follows:
[0076] y = kx + b
[0077] k=(y j -y i ) / (x j -x i )
[0078] b = (y j ×x i -y i ×x j ) / (x j -x i )
[0079] (i=1,2,…,n; j=1,2,…,n; i≠j),
[0080] In calculating the slope k and intercept b, a precision of 5 decimal places is retained to avoid the influence of floating-point precision.
[0081] Step S25: Round the intercept b to an integer to obtain the reference direction and reference distance Δb of the integer line.
[0082]
[0083] Step S26: Calculate the shortest distance vector from the current real line to the integer line based on Δb, and denot it as the vertex coordinate correction vector. The specific formula is as follows:
[0084] x offset = (-k×Δb) / (1+k) 2 )
[0085] y Offset =Δb / (1+k) 2 )
[0086] Step S27, in the initialization correction vector stage, the first vertex pt1 and the last vertex pt are used. n Define pt n Given the previous vertex, define pt1 as the next vertex, and repeat steps S21 to S26 to calculate the vertex coordinate correction vector.
[0087] Step S3 is as follows:
[0088] Step S31: When iterating through each vertex of the graph, obtain the currently visited vertex pt. Cur And the vertex adjacent to the previous vertex pt Prev The formula for calculating the index Prev is:
[0089]
[0090] Where n represents the number of vertices in the graph;
[0091] Step S32, determine pt Cur and pt Prev The method for determining whether points are concurrent is the same as in step S22.
[0092] Step S33: When the above conditions are met, it is considered that pt Cur and pt Prev Concurrent points, at this point the correction vector will be used. It is passed on in a loop.
[0093] Step S4 is as follows:
[0094] Step S41: When iterating through each vertex of the graph, obtain the currently visited vertex pt. Cur The previous vertex adjacent to this vertex pt Prev This step is the same as S31;
[0095] Step S42: Determine the correction vector The vector formed by the coordinates of the front and rear vertices Collinearity, the formula for determining collinearity is:
[0096]
[0097] When the above conditions are met, obtain the currently visited vertex pt. Cur The next vertex adjacent to this vertex, pt Next The formula for calculating the index Next is:
[0098]
[0099] Where n represents the number of vertices in the graph;
[0100] Step S43: Use the current vertex pt Cur and the next adjacent vertex pt Next Define pt Cur Let pt be the front vertex. Next For the last vertex, repeat steps S21 to S26 to calculate the new correction vector.
[0101] Step S5 is as follows:
[0102] Step S51: Obtain the current vertex coordinate correction vector. It is applied to the coordinates of the vertex currently traversed by the loop, defining the current vertex pt. i =(x i ,y i The output result (vertices coordinate update values) is defined as Output = (ptO1, ptO2, ..., ptO2). n ), stn≥2, where ptO is the vertex currently traversed. i =(m i ,n i The formula for calculating ) is:
[0103]
[0104] Where x Offset and y Offset These are the correction values of the vertex coordinate correction vector on the x-axis and y-axis, respectively.
[0105] Step S52, use the output result ptO i =(m i ,n i ) and the current vertex coordinates pt i =(x i ,y i Update the correction vector Make the correction vector The vertex coordinates are corrected for the next iteration, with the update formula being:
[0106] x Offset =m i -x i (i = 1, 2, ..., n)
[0107] y Offset =n i -y i (i = 1, 2, ..., n),
[0108] Where x Offset and y Offset These are the correction values of the vertex coordinate correction vector on the x-axis and y-axis, respectively.
[0109] Step S53: Repeat steps S3, S4 and S5 to update the next adjacent vertex until the output coordinates of all vertices of the graph have been updated.
[0110] After the traversal is complete, the integer vertex coordinates obtained by rounding are written back to the graphics data. The calculation cache during the calculation process is cleared, including: writing the output coordinates Output back to the graphics data; and clearing the calculation cache pt during the calculation process.
[0111] Example 2
[0112] This embodiment also relates to a method for eliminating aliasing in orbital graphics quantization in GDI, including:
[0113] Step S1: Obtain the vertex data of the graphics to be processed, handle boundary conditions, and cache the processed vertex data; the specific algorithm is as follows:
[0114]
[0115] Where PointD represents the vertex coordinates of floating-point type, and its definition is:
[0116]
[0117] Step S2: Construct an integer line equation based on the slope and intercept of the line formed by two adjacent vertices, and calculate the initial vertex coordinate correction vector by selecting the first and last vertices; the specific algorithm is as follows:
[0118]
[0119]
[0120] Among them, isZero() is used to determine whether a floating-point number is zero, and RoundValue() is used for rounding. Their definitions are as follows:
[0121]
[0122] At the end of step S1, the method is called using the first and last vertices:
[0123]
[0124] Step S3: Traverse each vertex. If the current vertex and the next vertex are the same, directly pass the vertex coordinate correction vector and proceed to step S5; otherwise, proceed to step S4; if the traversal is complete, proceed to step S6; the specific algorithm is as follows:
[0125]
[0126] Step S4: If the coordinate correction vector is collinear with the vector formed by the coordinates of the current vertex and the adjacent previous vertex, then construct an integer-based straight line equation based on the current vertex and the adjacent next vertex, update the vertex coordinate correction value, and proceed to step S5; otherwise, directly proceed to step S5; the specific algorithm is as follows:
[0127]
[0128]
[0129] Step S5: Based on the correction vector calculated from the coordinates of the previous vertex, iteratively correct the coordinates of the adjacent vertex. Round the corrected vertex coordinates to obtain integer vertex coordinates, update the correction vector, and use it for the correction of the next vertex. Return to step S3 to continue traversing; the specific algorithm is as follows:
[0130]
[0131]
[0132] After the traversal is complete, the rounded integer vertex coordinates are written back to the graphics data, the computation cache is cleared, and the process ends. The specific algorithm is as follows:
[0133] void ChangeValue(LPPOINT ptPoints,int nCount)
[0134] { ......
[0136] / / Clear cache
[0137] delete[]pt;
[0138] }
[0139] refer to Figure 3 This invention introduces the calculation of correction vectors and their effects using integer-based linear equations. First, the reason for calculating the correction vector according to step S3 is explained: Among lines with slopes k = 1, -1, 0, ∞, lines with integer intercepts b are integer lines, and lines with real intercepts b are real lines. As shown in the left figure, any point on the real line y = x + 1.2, after rounding, will fall at the position of the red dot in the figure. The pattern observed from the red dot's position is that any point, after rounding, will either fall on the integer line y = x + 1 or y = x + 2. This means that although rounding itself is a non-linear mapping, by integerizing the real line intercept b = 1.2 to 1 or 2, it can indicate the rounded position of any point on the real line. Based on the principle of minimizing quantization error, in this example, this invention will choose to correct towards the integer line y = x + 1. The specific calculation formula is easily proven, and its applicability to other cases described above is also easily proven.
[0140] Secondly, let's explain why the correction vector works correctly on a track with a 45-degree incline. As shown in the right figure, any point on the integer line y = x + 1, after rounding, will fall on the position of the red dot in the figure, and the position of the red dot will always coincide with the real number line. This means that after the preceding vertex is corrected, applying the correction vector to the following vertex is equivalent to correcting the following vertex to the same integer line, thus determining the rounding result of the following vertex. The integer vector formed by the corrected preceding and following vertices is always in the same direction as the real number vector formed by the preceding and following vertices before correction, thus preventing jagged edges when quantizing the vertices of the figure into integers.
[0141] The changes in coordinate values of a selected trajectory graphic after a 45-degree rotation are illustrated in Table 1. This demonstrates how direct rounding of vertex buffers after affine transformation affects the slope of the graphic, and the effect of the correction using this invention. Figure 4 As shown. Figure 4 From left to right, the images show the trajectory before transformation, before correction, and after correction. The input trajectory is a common right-angled trapezoid. Figure 4 (Left image) The slopes of its four edges are calculated from the current coordinate and the previous coordinate, and are 0, -1, 0, and ∞ respectively. Subsequent slopes are calculated in the same way. It can be seen that directly caching and rounding the vertices resulted in two coordinate values being abnormal (highlighted in bold), causing errors in the slopes of adjacent edges and ultimately leading to jagged edges, as shown in the image. Figure 4 The edges are highlighted in red. After correcting the vertex cache using the corrected vector, the slope takes values within the normal range of {-1, 0, 1, ∞}, and the resulting trajectory graph no longer has jagged edges. Figure 4 (Right image).
[0142] Table 1
[0143]
[0144] Example 3
[0145] The electronic device of this invention includes a central processing unit (CPU), which can perform various appropriate actions and processes according to computer program instructions stored in read-only memory (ROM) or loaded from a storage unit into random access memory (RAM). The RAM may also store various programs and data required for device operation. The CPU, ROM, and RAM are interconnected via a bus. Input / output (I / O) interfaces are also connected to the bus.
[0146] Multiple components in the device are connected to the I / O interface, including: input units such as keyboards and mice; output units such as various types of displays and speakers; storage units such as disks and optical discs; and communication units such as network interface cards (NICs), modems, and wireless transceivers. The communication unit allows the device to exchange information / data with other devices through computer networks such as the Internet and / or various telecommunications networks.
[0147] The processing unit performs the various methods and processes described above. For example, in some embodiments, the methods may be implemented as computer software programs tangibly contained in a machine-readable medium, such as a storage unit. In some embodiments, part or all of the computer program may be loaded and / or installed on the device via ROM and / or a communication unit. When the computer program is loaded into RAM and executed by the CPU, one or more steps of the methods described above may be performed. Alternatively, in other embodiments, the CPU may be configured to execute the methods by any other suitable means (e.g., by means of firmware).
[0148] The functions described above in this document can be performed, at least in part, by one or more hardware logic components. For example, exemplary types of hardware logic components that can be used, without limitation, include: Field Programmable Gate Arrays (FPGAs), Application-Specific Integrated Circuits (ASICs), Application Standard Products (ASSPs), System-on-Chip (SoCs), Complex Programmable Logic Devices (CPLDs), and so on.
[0149] The program code used to implement the methods of the present invention can be written in any combination of one or more programming languages. This program code can be provided to a processor or controller of a general-purpose computer, special-purpose computer, or other programmable data processing device, such that when executed by the processor or controller, the program code causes the functions / operations specified in the flowcharts and / or block diagrams to be implemented. The program code can be executed entirely on the machine, partially on the machine, as a standalone software package partially on the machine and partially on a remote machine, or entirely on a remote machine or server.
[0150] In the context of this invention, a machine-readable medium can be a tangible medium that may contain or store a program for use by or in conjunction with an instruction execution system, apparatus, or device. A machine-readable medium can be a machine-readable signal medium or a machine-readable storage medium. Machine-readable media can include, but are not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, apparatus, or devices, or any suitable combination of the foregoing. More specific examples of machine-readable storage media include electrical connections based on one or more wires, portable computer disks, hard disks, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fibers, portable compact disk read-only memory, optical storage devices, magnetic storage devices, or any suitable combination of the foregoing.
[0151] The above description is merely a specific embodiment of the present invention, but the scope of protection of the present invention is not limited thereto. Any person skilled in the art can easily conceive of various equivalent modifications or substitutions within the technical scope disclosed in the present invention, and these modifications or substitutions should all be covered within the scope of protection of the present invention. Therefore, the scope of protection of the present invention should be determined by the scope of the claims.
Claims
1. A method for eliminating aliasing in graphics quantization in GDI, characterized in that, include: Obtain the vertex data of the graphic to be processed, and cache the vertex data after affine transformation; Construct an integer line based on the slope and intercept of the line formed by two adjacent vertices, and calculate the vertex coordinate correction vector; The calculation process of the vertex coordinate correction vector includes: assuming that two adjacent vertices form a real straight line with a slope of... k The intercept is b The intercept is rounded to the nearest whole number. b After integerization, obtain the reference distance of the integer line. ; according to Calculate the shortest distance vector from the real number line to the integer line, denoted as the vertex coordinate correction vector. The specific calculation formula is as follows: , ,in, and These are the vertex coordinate correction vectors. x shaft and y Axis correction value; Iterate through each vertex, and use the vertex coordinate correction vector calculated from the coordinates of the previous vertex to iteratively correct the coordinates of the next adjacent vertex. Round the corrected vertex coordinates to obtain integer vertex coordinates, and update the vertex coordinate correction vector for the correction of the next vertex. The process of cyclically correcting the coordinates of the next adjacent vertex includes: obtaining the current vertex coordinate correction vector, applying it to the current vertex coordinates traversed in the loop, and outputting the vertex coordinate update value; Update the vertex coordinate correction vector using the current vertex coordinate update value and the current vertex coordinate update; The process of outputting the updated vertex coordinates involves: obtaining the current vertex coordinate correction vector. It applies it to the coordinates of the current vertex reached in the current iteration of the loop, defining the current vertex. =( The output vertex coordinate update value is defined as follows: , stn ≥ 2, where any one point =( The formula for calculating ) is: , , in n The number of vertices. and The vertex coordinate correction vectors are respectively in x shaft and y Correction value on the axis; Once the traversal is complete, write the integer vertex coordinates back to the graphics data and clear the cache.
2. The method for eliminating jagged edges in graphic quantization in GDI according to claim 1, characterized in that, In the initialization correction vector stage, the first and last vertices are used as adjacent vertices, the last vertex is defined as the previous vertex, and the first vertex is defined as the next vertex. Integer lines are constructed based on the slope and intercept of the line formed by the adjacent vertices to calculate the initial vertex coordinate correction vector.
3. The method for eliminating aliasing in GDI according to claim 1, characterized in that, During the traversal, if the currently traversed vertex shares the same point as the previous vertex, the current vertex coordinate correction vector is directly passed down to correct the next vertex.
4. A method for eliminating jagged edges in graphic quantization in GDI according to claim 1, characterized in that, During the traversal, if the vertex coordinate correction vector is collinear with the vector formed by the coordinates of the preceding and following vertices, then the currently traversed vertex and the vertex immediately following it are taken as the preceding and following vertices, respectively. An integer straight line is constructed based on the two adjacent vertices, and the vertex coordinate correction vector is updated.
5. A method for eliminating jagged edges in graphics quantization in GDI according to claim 4, characterized in that, The method for determining whether vectors are collinear is: if they satisfy... Then determine the vertex coordinate correction vector. The vector formed by the coordinates of the front and rear vertices Collinear.
6. A method for eliminating jagged edges in graphics quantization in GDI according to claim 1, characterized in that, The process of updating the vertex coordinate correction vector using the current vertex coordinate update value and the current vertex coordinate update includes: Update values using current vertex coordinates. =( ) and current vertex coordinates =( Update the correction vector This makes the correction vector The vertex coordinates are corrected for the next iteration, with the update formula being: , 。 7. A method for eliminating jagged edges in graphic quantization in GDI according to claim 1, characterized in that, If the graphic to be processed has only one vertex, then the integer vertex coordinates obtained by rounding after affine transformation are written back as vertex data.
8. A method for eliminating aliasing in GDI according to claim 1, characterized in that, If the line formed by two adjacent vertices is horizontal or vertical, then the vertex coordinate correction vector is set to zero.
9. An electronic device comprising a memory and a processor, wherein the memory stores a computer program, characterized in that, When the processor executes the program, it implements the method as described in any one of claims 1 to 8.
10. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the program is executed by the processor, it implements the method as described in any one of claims 1 to 8.
Citation Information
Patent Citations
Anti-aliasing two-dimensional vector graphics using a multi-vertex buffer
US11417058B2
Image anti-aliasing processing method and electronic equipment
CN113837955A
Scale method and device of Canvas and storage medium
CN118365734A