Directed distance field image, text effect image generation method, device and medium
By changing the pixel point counting method during the shape drawing stage, the position of pixel points in the closed curve overlap area in the undirected distance field image is accurately determined, which solves the problem of inaccurate generation of directed distance field images in the prior art, and achieves higher image generation accuracy.
Patent Information
- Application Number
- CN202110121068.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-01-28
- Publication Date
- 2025-03-18
- Estimated Expiration
- 2041-01-28
AI Technical Summary
In the prior art, when generating directed distance field images, there is a problem that the pixel point position information of overlapping regions between multiple closed curves is inaccurate, resulting in the generated directed distance field images being inaccurate.
By changing the pixel point counting method in the shape drawing stage, specifically, the target closing curve in the undirected distance field image of the target text is determined, and the target triangle is drawn with two adjacent sampling points and the origin on it as vertices. The pixel points are counted based on the drawing direction of the triangle. The pixel points with the counting result 0 are determined as the external area, otherwise it is the internal area.
The accuracy of determining the inner and outer positions of pixel points in the overlapping area of the closed curve in the target text is improved, and the accuracy of directed distance field image generation is improved.
Smart Images

Figure CN114820836B_ABST
Abstract
Description
Technical Field
[0001] The present disclosure relates to the field of data processing, and in particular, to a method and apparatus for generating a signed distance field image, a method and system for generating a text effect image, as well as a device, a storage medium, and a computer program product. Background Art
[0002] Since the distance field image does not distort at a relatively large scale compared to ordinary bitmap text, the distance field image is more suitable for text effect processing.
[0003] Among them, the distance field image of text records the shortest distance value (also called the distance field value) of each pixel point inside and around the text to the text contour (also called the boundary); and the signed distance field image refers to a distance field image in which the distance field value of the pixel points inside the text is set to a negative number, and the distance field value of the pixel points outside the text is set to a positive number.
[0004] Currently, the method for generating the signed distance field image of text is implemented using the rendering pipeline of OpenGL, including the line drawing stage, the shape drawing stage, and the signed orientation stage. Among them, the line drawing stage is used to draw the unsigned distance field image of text, and in the shape drawing stage, it is necessary to determine whether each pixel point in the unsigned distance field image is in the internal area or the external area of the text, so that based on the position information of the internal and external areas of each determined pixel point, the internal area of the unsigned distance field image is subjected to color inversion processing in the signed orientation stage, and finally the signed distance field image of text is obtained.
[0005] Specifically, in the shape drawing stage, currently, by sequentially taking adjacent pixel sampling points on the closed curve in the unsigned distance field image and the origin as vertices to draw triangles, and accumulating and counting each pixel point in the triangle area, the accumulated counting result of each pixel point in the unsigned distance field image is obtained, and it is judged whether the accumulated counting result of each pixel point is odd or even to determine whether it is in the internal area or the external area of the text, so as to realize the generation of the signed distance field image.
[0006] However, for text with overlapping areas between multiple closed curves, if the internal and external position information of each pixel point is determined based on the parity of the accumulated counting result in the above-mentioned shape drawing method, there will be a problem of inaccurate determination of the position information. As Figure 1 shown, it is a schematic diagram of the unsigned distance field image of the text "十". For the pixel points in the overlapping area of the text "十", the accumulated counting result determined based on the above-mentioned accumulation counting method is 2, and since 2 is an even number, the pixel points in the overlapping area will be wrongly determined to be in the external area of the text, resulting in an inaccurate signed distance field image finally generated. Summary of the invention
[0007] In order to solve the above technical problems or at least partially solve the above technical problems, the present disclosure provides a method, device, equipment and storage medium for generating a signed distance field image, which can accurately generate the corresponding signed distance field image for text with overlapping areas between multiple closed curves.
[0008] In a first aspect, the present disclosure provides a method for generating a signed distance field image, the method comprising:
[0009] Determine a target closed curve in the undirected distance field image of the target text, and determine an origin corresponding to the target closed curve;
[0010] Taking two adjacent sampling points on the target closed curve and the origin as vertices, and drawing a target triangle according to the sampling order of the adjacent sampling points; wherein the sampling order is a preset direction along the target closed curve;
[0011] Based on the drawing direction of the target triangle, counting the pixels within the target triangle area; wherein the drawing direction of the target triangle is a clockwise direction or a counterclockwise direction, and when the drawing direction is a clockwise direction or a counterclockwise direction, the corresponding counting methods are opposite, and the counting methods include increasing N or subtracting N, and N is a non-zero number;
[0012] Determine that the pixel points whose count results in the unoriented distance field image are 0 are located in the outer region of the target text, and determine that the pixel points whose count results in the unoriented distance field image are not 0 are located in the inner region of the target text;
[0013] A directed distance field image of the target text is generated according to the pixel points in the outer area of the target text, the pixel points in the inner area of the target text, and the undirected distance field image.
[0014] In an optional implementation manner, when the drawing direction is clockwise or counterclockwise, the corresponding counting methods are opposite, including:
[0015] When the drawing direction is clockwise, the pixel points in the triangular area are counted by adding N each time they are counted; when the drawing direction is counterclockwise, the pixel points in the triangular area are counted by subtracting N each time they are counted;
[0016] Alternatively, when the drawing direction is clockwise, the pixel points in the triangular area are counted by subtracting N each time they are counted; when the drawing direction is counterclockwise, the pixel points in the triangular area are counted by adding N each time they are counted, where N is not 0.
[0017] In an optional implementation manner, the method further includes:
[0018] Splitting the distance field value corresponding to the pixel point on the signed distance field image into four 8-bit unsigned integers;
[0019] The four 8-bit unsigned integers are stored respectively using the four color channels of RGBA.
[0020] In an optional implementation manner, splitting the distance field value corresponding to the pixel point on the signed distance field image into four 8-bit unsigned integers includes:
[0021] The integer part of the distance field value corresponding to the pixel point on the signed distance field image, [1 / 256,1], [1 / 256 2 ,1 / 256]、[1 / 256 3 ,1 / 256 2 ] The values of the four parts are multiplied by 1, 256, and 256 respectively 2 ,256 3 After that, 4 8-bit unsigned integers are obtained.
[0022] In an optional implementation manner, the method further includes:
[0023] In response to the application operation on the signed distance field image, the four 8-bit unsigned integers are divided by 1, 256, 256 respectively. 2 256 3 The values obtained are accumulated to obtain a 32-bit floating point number as the distance field value of the pixel point.
[0024] In an optional implementation manner, before generating the undirected distance field image of the target text based on the vector contour information of the target text, the method further includes:
[0025] Convert the third-order Bezier curve in the target font file into a second-order Bezier curve to obtain the converted target font file;
[0026] Accordingly, the step of generating an undirected distance field image of the target text based on the vector contour information of the target text includes:
[0027] The converted target font file and the vector outline information of the target text are combined to generate an unoriented distance field image of the target text.
[0028] In an optional implementation manner, the method further includes:
[0029] The directed distance field image of the target text is cached.
[0030] In an optional implementation, the directed distance field image of the target text is generated in real time.
[0031] In a second aspect, the present disclosure provides a method for generating a text effect image, the method comprising:
[0032] Generate a signed distance field image of the target text using any of the above-mentioned signed distance field image generation methods;
[0033] Based on the effect resource file and the directed distance field image of the target text, a text effect image corresponding to the target text is generated.
[0034] In an optional implementation manner, generating a text effect image corresponding to the target text based on the effect resource file and the directed distance field image of the target text includes:
[0035] In response to the selection operation of the effect resource file, determining the drawing layer effect parameters of the target text based on the effect resource file;
[0036] Based on the distance field image of the target text and the drawing layer effect parameters, a text effect image corresponding to the target text is drawn layer by layer.
[0037] In a third aspect, the present disclosure provides a device for generating a signed distance field image, the device comprising:
[0038] A first determination module is used to determine a target closed curve in an undirected distance field image of a target text, and determine an origin corresponding to the target closed curve;
[0039] A triangle drawing module, used to draw a target triangle using two adjacent sampling points on the target closed curve and the origin as vertices according to a sampling order of the adjacent sampling points; wherein the sampling order is a preset direction along the target closed curve;
[0040] A counting module, configured to count the pixels within the target triangle region based on the drawing direction of the target triangle; wherein the drawing direction of the target triangle is clockwise or counterclockwise, and the corresponding counting methods are opposite when the drawing direction is clockwise or counterclockwise, and the counting methods include increasing N or subtracting N for each count, where N is a non-zero number;
[0041] a second determination module, configured to determine, after all pixel sampling points on each closed curve in the undirected distance field image are used as vertices to complete drawing of a triangle, whether pixel points with a count result of 0 in the undirected distance field image are located in an external area of the target text, and whether pixel points with a count result of not 0 in the undirected distance field image are located in an internal area of the target text;
[0042] The first generating module is used to generate a directed distance field image of the target text according to the pixel points in the external area of the target text, the pixel points in the internal area of the target text and the undirected distance field image.
[0043] In a fourth aspect, the present disclosure provides an effect text generation system, the system comprising:
[0044] A distance field generating unit, used to generate a directed distance field image of the target text using the directed distance field image generating method mentioned above;
[0045] The effect text generating unit is used to generate the effect text corresponding to the target text based on the effect resource file and the directed distance field image of the target text generated by the distance field generating unit.
[0046] In a fifth aspect, the present disclosure provides a computer-readable storage medium, wherein the computer-readable storage medium stores instructions, and when the instructions are executed on a terminal device, the terminal device implements the above method.
[0047] In a sixth aspect, the present disclosure provides a device, comprising: a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the above method when executing the computer program.
[0048] In a seventh aspect, the present disclosure provides a computer program product, wherein the computer program product comprises a computer program / instructions, and the computer program / instructions implement the above-mentioned method when executed by a processor.
[0049] Compared with the prior art, the technical solution provided by the embodiments of the present disclosure has at least the following advantages:
[0050] Embodiments of the present disclosure provide a method for generating a directed distance field image. Specifically, pixels within a triangular region are counted based on the drawing direction of the triangle, and pixels with a count result of 0 are determined to be in the external region of the target text, otherwise they are determined to be in the internal region of the target text, more accurately determining the positions of pixels within the overlapping region of the closed curve in the target text. It can be seen that the embodiments of the present disclosure improve the accuracy of determining whether pixels within the overlapping region of the closed curve in the target text are in the internal region of the target text by changing the pixel counting method in the shape drawing stage and the determination method for determining whether a pixel is in the internal region of the text based on the count result, thereby improving the accuracy of generating the directed distance field image. BRIEF DESCRIPTION OF THE DRAWINGS
[0051] The accompanying drawings herein are incorporated into the specification and form a part of the specification, showing embodiments consistent with the present disclosure and, together with the specification, are used to explain the principles of the present disclosure.
[0052] To more clearly illustrate the technical solutions in the embodiments of the present disclosure or in the prior art, the following will briefly introduce the accompanying drawings required for use in the description of the embodiments or the prior art. Obviously, for those of ordinary skill in the art, other drawings can also be obtained based on these drawings without creative efforts.
[0053] Figure 1 A schematic diagram of an undirected distance field image of the character "十" provided by an embodiment of the present disclosure;
[0054] Figure 2 A flowchart of a method for generating a directed distance field image provided by an embodiment of the present disclosure;
[0055] Figure 3 A schematic diagram of the effect of converting a third-order Bezier curve into a second-order Bezier curve provided by an embodiment of the present disclosure;
[0056] Figure 4 A schematic diagram of the structure of a text effect image generation system provided by an embodiment of the present disclosure;
[0057] Figure 5 A schematic diagram of the structure of a directed distance field image generation device provided by an embodiment of the present disclosure;
[0058] Figure 6 A schematic diagram of the structure of a directed distance field image generation device provided by an embodiment of the present disclosure;
[0059] Figure 7 A schematic diagram of the structure of a text effect image generation device provided by an embodiment of the present disclosure. DETAILED DESCRIPTION OF THE EMBODIMENTS
[0060] In order to more clearly understand the above-mentioned objectives, features and advantages of the present disclosure, the scheme of the present disclosure will be further described below. It should be noted that the embodiments of the present disclosure and the features in the embodiments can be combined with each other without conflict.
[0061] In the following description, many specific details are set forth to facilitate a full understanding of the present disclosure, but the present disclosure may also be implemented in other ways different from those described herein; it is obvious that the embodiments in the specification are only part of the embodiments of the present disclosure, rather than all of the embodiments.
[0062] The distance field image of the text records the shortest distance value between each pixel point inside the text and outside the text and the text outline (also called the boundary), also known as the distance field value. Among them, the distance field value in the directed distance field image of the text can distinguish whether each pixel point is in the internal area of the text or in the external area around the text. Specifically, the distance field value of the pixel point in the internal area of the text is set to a negative number, while the distance field value of the pixel point in the external area around the text is set to a positive number.
[0063] At present, the method for generating a signed distance field image of text includes a line drawing stage, a shape drawing stage, and a color inversion directed stage. Among them, the line drawing stage is used to draw the undirected distance field image of the text, and in the shape drawing stage, it is necessary to determine whether each pixel point in the undirected distance field image is in the internal area of the text or the external area around the text, and then in the color inversion directed stage, the internal area of the text in the undirected distance field image is inverted, and finally the signed distance field image of the text is obtained.
[0064] In the method for determining whether each pixel point in the undirected distance field image is in the text internal area or in the text external area, currently, the pixel point is determined to be in the text internal area or in the text external area by the parity of the accumulated counting result of each pixel point. Specifically, the pixel point with an odd accumulated counting result is determined to be in the text internal area, and the pixel point with an even accumulated counting result is determined to be in the text external area.
[0065] like Figure 1As shown in the figure, it is a schematic diagram of the undirected distance field image of the target character "十". Among them, the dotted line represents the closed curve 1, the solid line represents the closed curve 2, and the shaded part is the overlapping area of the closed curves 1 and 2. For the closed curve 1, assuming that the origin is A0, the pixel points on the closed curve 1 are uniformly sampled, and the pixel sampling points A1, A2... Ak on the closed curve 1 are determined. Triangles are drawn in turn with two adjacent pixel sampling points on the closed curve 1 and the origin A0 as vertices. For example, a triangle A1A2A0 is drawn with A1, A2, and A0 as vertices, and the count of the pixel points in the internal area of the triangle A1A2A0 is incremented by 1. Continue to determine the vertices and draw triangles in the above manner. When a triangle A(n - 1)AnA0 is drawn with A(n - 1), An, and A0 as vertices, the count of the pixel points in the internal area of the drawn triangle A(n - 1)AnA0 is incremented by 1. It can be understood that at this time, the count result of the pixel points in the internal area of the triangle A1A2A0 is 2, and the count result of the pixel points in the area A(n - 1)AnA1A2 is 1. It can be seen that based on the above method of determining whether a pixel point is in the internal area of the character, when the count result of the pixel point is even, it can be determined that the pixel point is in the external area around the character, and when the count result of the pixel point is odd, it can be determined that the pixel point is in the internal area of the character.
[0066] However, for characters with multiple closed curves, such as Figure 1 not only includes the closed curve 1, but also includes the closed curve 2. For the overlapping area of the closed curves, there is a problem that the position of the pixel point is not accurately determined by the above method. Specifically, for the closed curve 2, assuming that the processing method of the above closed curve 1 is used, it can be determined that the count result of the pixel points in the area A(n - 1)AnA1A2 is incremented by 1 to get 2. If the count result is used as an even number to determine that the pixel point is in the external area around the character, the result is obviously inaccurate. Therefore, the inventor believes that for characters with overlapping areas of multiple closed curves, if it is determined whether a pixel point is in the internal area of the character based on the parity of the count result, the judgment result is obviously inaccurate, which will further lead to inaccurate generation of the directed distance field image based on this judgment result.
[0067] For this reason, the present disclosure provides a method for generating a directed distance field image, which improves the accuracy of determining the internal and external positions of pixel points in the overlapping area of the closed curves in the character by changing the counting method of pixel points in the shape drawing stage and the method of determining whether a pixel point is in the internal area of the character based on the count result, and further improves the accuracy of generating the directed distance field image.
[0068] Specifically, for each closed curve in the undirected distance field image of the target text, the origin corresponding to the closed curve is determined, and a pixel counting process is performed for the closed curve. The specific pixel counting process includes: first, pixel sampling points are determined in sequence along a preset direction on the closed curve, and then two pixel points at adjacent positions in the pixel sampling points and the origin are used as vertices in sequence, a drawing direction is determined based on the sampling sequence between the two pixel sampling points, and a triangle is drawn based on the drawing direction and the vertices, and then a counting method for the pixel points in the triangle area is determined based on the drawing direction, and then the pixel points in the triangle area are counted based on the counting method. When the pixel sampling points on each closed curve in the undirected distance field image of the target text are used as vertices to complete the drawing of the triangle, whether the pixel point is in the internal and external position information of the internal area of the target text is determined according to whether the counting result of the pixel point in the undirected distance field image is 0, and finally, based on the internal and external position information of each pixel point in the undirected distance field image and the undirected distance field image, a directed distance field image of the target text is generated.
[0069] In the embodiment of the present disclosure, the counting method of the pixels in the triangle area is determined based on the drawing direction of the triangle, for example, adding N or subtracting N, so that the counting result of the pixels in the overlapping area is the number of overlapping closed curves corresponding to the overlapping area, such as Figure 1 The number of overlapping closed curves corresponding to the overlapping area is 2, which are closed curves 1 and 2. Since the pixel point in the external area of the target text is not only in the internal area of the triangle A1A2A0 drawn counterclockwise (count plus N), but also in the internal area of the triangle A(n-1)AnA0 drawn clockwise (count minus N), its counting result is 0. The embodiment of the present disclosure determines whether it is in the internal area of the target text based on whether the counting result of the pixel point is 0. For the target text with overlapping areas between multiple closed curves, it can accurately determine whether each pixel point is in the internal area of the target text, and then accurately generate the directed distance field image of the target text.
[0070] Based on this, the present disclosure provides a method for generating a directed distance field image. Figure 2 , is a flow chart of a method for generating a directed distance field image provided by an embodiment of the present disclosure, the method comprising:
[0071] S201: Determine a target closed curve in an undirected distance field image of a target text, and determine an origin corresponding to the target closed curve.
[0072] In the disclosed embodiment, before generating a directed distance field image for a target text, first, an undirected distance field image of the target text is generated based on the vector contour information of the target text. The undirected distance field image records the shortest distance value between each pixel point inside the text and the text contour (also called the boundary), which is also called the distance field value. Since it is impossible to determine whether the pixel point is in the internal area of the target text according to the distance field value of each pixel point in the undirected distance field image, in the process of generating a directed distance field image from the undirected distance field image, the key is to determine the pixel points in the undirected distance field image that are in the internal area of the target text, and at the same time determine the pixel points that are in the external area around the target text, which will be described in detail later.
[0073] In the disclosed embodiment, the vector contour information of the target text may include a vector image or a bitmap of the target text. In the line drawing stage of generating the directed distance field image of the target text, according to the vector contour information of the target text, for each curve segment in the glyph of the target text, a cuboid containing the body of the curve segment is drawn, and then for each pixel point in the cuboid, the distance value from the curve segment is calculated by analytical geometry and other methods, and the distance value is used as color information (the larger the distance value, the darker the color) for drawing, and the data of each curve segment in the glyph of the target text is fused by the depth test method of the GPU, and for the pixel point with more than one distance value, the shortest distance value corresponding to the pixel point is retained as the distance field value of the pixel point. The above method can calculate the distance field values corresponding to each pixel point on the glyph of the target text and the pixel points within a certain range around it, forming an undirected distance field image of the target text.
[0074] In the embodiment of the present disclosure, after the undirected distance field image of the target text is obtained, each closed curve in the undirected distance field image is used as the target closed curve of the embodiment of the present disclosure, and the corresponding origins are determined, and then the following pixel counting process is performed for the target closed curves.
[0075] In the disclosed embodiment, the origin of each closed curve may be randomly determined, and the origin of each closed curve may be the same or different.
[0076] The processing process for each closed curve in the embodiment of the present disclosure is the same. Each closed curve can be processed in parallel or in sequence, which is not limited in the embodiment of the present disclosure. Figure 1 The closed curves 1 and 2 in FIG. 1 are taken as target closed curves as examples, and the processing process of the target closed curves is specifically introduced.
[0077] S202: Using two adjacent sampling points on the target closed curve and the origin as vertices, and drawing a target triangle according to a sampling order of the adjacent sampling points; wherein the sampling order is a preset direction along the target closed curve.
[0078] In a practical application, pixel sampling points are determined in sequence along a preset direction on a target closed curve; two adjacent sampling points among the pixel sampling points and the origin are used as vertices in sequence, a drawing direction is determined based on a sampling order between the two adjacent sampling points, and a target triangle is drawn based on the drawing direction and the determined vertices; wherein the drawing direction is a clockwise direction or a counterclockwise direction.
[0079] In the embodiment of the present disclosure, after determining the target closed curve, uniform sampling is performed on the target closed curve in a clockwise direction or a counterclockwise direction to determine the pixel sampling points on the closed curve. Figure 1 As shown in the closed curve 1 in the figure, the pixel points on the closed curve are uniformly sampled along the clockwise direction A1A2…A(n-1)An to obtain the pixel sampling points A1, A2…A(n-1), An…Am.
[0080] Then, two pixel sampling points at adjacent positions on the target closed curve are determined as two adjacent sampling points, such as A1 and A2 on closed curve 1, and the origin A0 is used as a vertex, and triangle A1A2A0 is drawn along the sampling order of A1→A2. Based on the sampling order of A1→A2, it can be determined that the drawing direction of triangle A1A2A0 is counterclockwise.
[0081] For another example, two pixel sampling points A(n-1) and An at adjacent positions on closed curve 1 are used as vertices together with the origin A0, and triangle A(n-1)AnA0 is drawn along the sampling order of A(n-1)→An. Based on the sampling order of A(n-1)→An, it can be determined that the drawing direction of triangle A(n-1)AnA0 is clockwise.
[0082] S203: Count the pixels within the target triangle area based on the drawing direction of the target triangle; wherein, the drawing direction of the target triangle is clockwise or counterclockwise, and the corresponding counting methods are opposite when the drawing direction is clockwise or counterclockwise, and the counting methods include adding N or subtracting N, and N is a non-zero number.
[0083] In the embodiment of the present disclosure, after determining the drawing direction corresponding to the drawn target triangle, the counting method of the pixels in the target triangle area is determined based on the drawing direction. Specifically, the counting methods corresponding to the clockwise or counterclockwise drawing directions are opposite.
[0084] In an optional implementation, when the target triangle is drawn in a clockwise direction, the pixel points in the target triangle region are counted by adding N; meanwhile, when the target triangle is drawn in a counterclockwise direction, the pixel points in the target triangle region are counted by subtracting N, where N is not 0. For example, N may be 1.
[0085] In another optional implementation, when the target triangle is drawn in a clockwise direction, the pixel points in the target triangle region are counted in a manner of subtracting N; and when the target triangle is drawn in a counterclockwise direction, the pixel points in the target triangle region are counted in a manner of adding N, where N is not 0. For example, N may be 1.
[0086] In the embodiment of the present disclosure, after determining the counting method of the pixels in the target triangular region, the pixels in the target triangular region are counted respectively. Figure 1 For example, the drawing direction of triangle A1A2A0 is counterclockwise. Assuming that the count of the pixel points in triangle A1A2A0 is increased by 1 based on a certain counting method, and the drawing direction of triangle A(n-1)AnA0 is clockwise, the count of the pixel points in triangle A(n-1)AnA0 is reduced by 1.
[0087] The pixels in the triangle A1A2A0 also exist in the triangle A(n-1)AnA0. Therefore, the pixels in the triangle A1A2A0 (the pixels outside the target text) need to be counted twice, that is, first add 1 and then subtract 1, and the count result is 0. The pixels in the area formed by A(n-1)An A1A2 are only counted once, that is, add 1, and the count result is 1.
[0088] Based on the above method, the embodiment of the present disclosure is for Figure 1 It is understood that for the pixel points in the closed curve 2 that are in the internal area of the target text, it is only necessary to count once, that is, add 1. Therefore, based on the processing results of the above closed curve 1, the pixel points in the overlapping area represented by the shaded area are counted twice, that is, the counting result is 2, and the counting results for the pixel points in the external area of the target text are all 0.
[0089] It is understandable that based on the counting method provided by the embodiment of the present disclosure, the counting result for the pixel points in the outer area of the target text is 0, while the counting result for the pixel points in the inner area of the target text is not 0. Based on the above rule, the embodiment of the present disclosure can determine whether the pixel point is in the inner area of the target text.
[0090] In practical applications, pixel sampling points on each closed curve in the undirected distance field image of the target text are used as vertices to complete the drawing of the target triangle and the counting of the pixel points within the target triangle area.
[0091] In the disclosed embodiment, each closed curve in the undirected distance field image may be processed in parallel as a target closed curve; or each closed curve may be processed in sequence as a target closed curve.
[0092] In an optional implementation, after a closed curve is determined as a target closed curve to complete the drawing of a target triangle and the counting of pixels in a target triangle area, another closed curve is again used as a target closed curve, and the process of drawing a target triangle and counting pixels in a target triangle area is continued for the target closed curve, until it is determined that each closed curve in the undirected distance field image completes the process of drawing a target triangle and counting pixels in the target triangle area, thereby obtaining a counting result of each pixel in the undirected distance field image.
[0093] S204: Determine whether the pixel points whose count results are 0 in the unoriented distance field image are located in the inner region of the target text, and determine whether the pixel points whose count results are not 0 in the unoriented distance field image are located in the outer region of the target text.
[0094] In the disclosed embodiment, after the target triangle is drawn for each closed curve in the undirected distance field image of the target text and the pixel counting process within the target triangle area is executed, it is determined whether the pixel point is in the external area of the target text or in the internal area of the target text according to the counting result of each pixel point in the undirected distance field image.
[0095] Specifically, based on the above-mentioned method of counting according to the drawing direction of the triangle, it can be determined that the counting result of the pixel points in the external area of the target text is 0, while the counting result of the pixel points in the internal area of the target text is not 0. Therefore, in the embodiment of the present disclosure, the pixel points with a counting result of 0 in the undirected distance field image can be determined to be in the internal area of the target text, and the pixel points with a counting result of not 0 in the undirected distance field image can be determined to be in the external area of the target text.
[0096] S205: Generate a directed distance field image of the target text according to the pixel points in the outer area of the target text, the pixel points in the inner area of the target text, and the undirected distance field image.
[0097] In the disclosed embodiment, after determining whether a pixel point on an unoriented distance field image of a target text is located in an internal area of the target text, a directed distance field image of the target text is generated according to the pixel points located in an external area of the target text, the pixel points located in an internal area of the target text, and the unoriented distance field image.
[0098] In an optional implementation, in the inversion and orientation stage of generating a signed distance field image, the pixel points in the undirected distance field image that are located in the internal area of the target text are inverted, and the undirected distance field image is processed into a signed distance field image to distinguish the internal and external areas of the target text.
[0099] In the method for generating a signed distance field image provided by the embodiment of the present disclosure, by changing the counting method of pixels in the shape drawing stage and the judgment method of determining whether the pixels are in the internal area of the text based on the counting result, the accuracy of determining whether the pixels in the overlapping area of the closed curves in the target text are in the internal area of the target text is improved, thereby improving the accuracy of generating the signed distance field image.
[0100] In an application scenario, in order to avoid the storage pressure caused by pre-generating distance field images of a large amount of text, the embodiment of the present disclosure generates a directed distance field image of the target text for the user in real time through real-time processing when receiving the target text input by the user, thereby avoiding storage pressure.
[0101] In addition, the embodiments of the present disclosure may provide a cache mechanism to cache the generated directed distance field image of the target text, and specifically cache it in a GPU for later use.
[0102] In addition, currently one of the RGBA4 color channels is used to store the distance field value of the pixel in the signed distance field image, and one color channel can only store an 8-bit unsigned integer, and cannot fully store the distance field value of a 32-bit floating point number. Therefore, the current storage method causes the quality of the signed distance field image to be severely damaged, so that when it is scaled to a higher ratio during application, jagged edge artifacts will appear.
[0103] To this end, in order to ensure that the distance field value of each pixel point in the directed distance field image of the target text is completely stored, thereby ensuring the quality of the entire image, the embodiment of the present disclosure uses four color channels to simultaneously store the distance field value of the pixel points. Specifically, the four color channels of RGBA are used to store the distance field values of the pixel points respectively.
[0104] In practical applications, when storing the signed distance field image of the target text, the distance field value corresponding to the pixel point on the signed distance field image is split into 4 8-bit unsigned integers. Among them, the distance field value is a 32-bit floating point number. Specifically, the 32-bit floating point number is split into 4 8-bit unsigned integers. Then, the 4 8-bit unsigned integers obtained by splitting are stored respectively using the 4 color channels of RGBA. After the distance field values of each pixel point on the signed distance field image of the target text are stored respectively in the above manner, the lossless storage of the signed distance field image is completed, and the quality of the signed distance field image is guaranteed.
[0105] In an optional implementation, the integer part of the distance field value corresponding to the pixel point on the signed distance field image, [1 / 256 2 , 1 / 256], [1 / 256 3 , 1 / 256 2 ] The values of the four parts are multiplied by 1, 256, and 256 respectively 2 , 256 3 After that, 4 8-bit unsigned integers are obtained.
[0106] In an optional implementation, the floor() function may be used to split the distance value of the 32-bit floating point number into four 8-bit unsigned integers. The specific four 8-bit unsigned integers are:
[0107] a1 = floor(X);
[0108] a2 = floor((X-a1)*256);
[0109] a3=floor((X-a1-a2*256)*256 2 ;
[0110] a4=floor((X-a1-a2*256-a3*256 2 )*256 3 ).
[0111] In actual applications, after the distance field values of each pixel in the directed distance field image of the target text are stored in the above manner, when the directed distance field image is applied, in response to the application operation on the directed distance field image, the distance field values stored in four 8-bit unsigned integers need to be restored to 32-bit floating point numbers. Specifically, the four 8-bit unsigned integers of the distance field value are divided by 1, 256, and 256 respectively. 2 ,256 3The values obtained after the calculation are accumulated to obtain a 32-bit floating point number as the distance field value of the corresponding pixel point. For example, based on the above calculation method, the restored distance field value Y = a1 + a2 / 256 + a3 / 256 2 +a4 / 256 3 .
[0112] Through the above processing, the lossless distance field value of the pixel point can be obtained, thereby avoiding the precision loss of the directed distance field image of the target text.
[0113] In addition, in the embodiment of the present disclosure, before generating a signed distance field image for the target text, it is necessary not only to determine the target text but also to determine the target font file corresponding to the target text, for example, a font file such as Songti file, and generate a signed distance field image of the target text by combining the determined target text and the target font file.
[0114] However, since the current method for generating a directed distance field image does not support a target font file containing a third-order Bezier curve, when the embodiment of the present disclosure determines that the target font file is a font file containing a third-order Bezier curve, the third-order Bezier curve in the target font file is first converted into a second-order Bezier curve, and then, the converted target font file and the vector contour information of the target text are combined to generate an undirected distance field image of the target text, and then the directed distance field image of the target text is generated.
[0115] Among them, the otf font file and the ttc font file contain a 3rd-order Bezier curve. Therefore, it is necessary to convert the 3rd-order Bezier curve into a 2nd-order Bezier curve before generating the distance field image.
[0116] It is worth noting that for other font files containing third-order Bezier curves, if used in the method for generating an undirected distance field image provided in an embodiment of the present disclosure, the third-order Bezier curves also need to be converted into second-order Bezier curves first.
[0117] In addition, because the amount of information carried by the second-order Bezier curve is much larger than that of the straight line segment, the number of segment divisions will be greatly reduced. Therefore, converting the third-order Bezier curve into a second-order Bezier curve can reduce the data burden of the embodiment of the present disclosure.
[0118] In an optional implementation, the method for converting a third-order Bezier curve into a second-order Bezier curve includes: firstly selecting a plurality of sampling points on the third-order Bezier curve and calculating the tangent direction of each sampling point; then, for two adjacent sampling points, Figure 3By finding the intersection of the tangents of P0 and P1 in the above example, the control point C0 of the corresponding second-order Bezier curve can be obtained, and the three points P0C0P1 form a second-order Bezier curve. According to the above method, the tangents of two adjacent sampling points such as P1 and P2 are continued to be found to intersect, and the control point C1 of the corresponding second-order Bezier curve can be obtained, and the three points P1C1P2 form another second-order Bezier curve. According to the above method, each sampling point on the third-order Bezier curve is processed in turn, and finally a second-order Bezier curve including P0C0P1C1P2 is obtained.
[0119] In addition, in the embodiment of the present disclosure, a corresponding text effect image may be generated for the target text based on the directed distance field image of the target text.
[0120] To this end, based on the above embodiments, the embodiments of the present disclosure also provide a method for generating a text effect image.
[0121] Specifically, first, a signed distance field image of the target text is generated using the signed distance field image generation method in the above embodiment; then, a text effect image corresponding to the target text is generated based on the effect resource file and the signed distance field image of the target text.
[0122] The effect resource file may be a configuration file for text effects, for example, a configuration file for inner and outer shadow effects, including configuration parameters such as inner and outer shadow colors and shadow widths.
[0123] In actual applications, after the effect resource file and the signed distance field image of the target text are determined, the effect text corresponding to the target text is generated based on the effect resource file and the signed distance field image.
[0124] In an optional implementation, in response to a selection operation of an effect resource file, a drawing layer effect parameter of the target text is determined based on the effect resource file; then, based on the distance field image of the target text and the drawing layer effect parameter, a text effect image corresponding to the target text is drawn layer by layer.
[0125] In an optional implementation, each drawing layer effect parameter can be determined for the target text based on the effect resource file, the target text can have multiple drawing layers, each drawing layer effect includes multiple outline effects, and each outline effect includes specific effect parameters. After receiving the selection operation of the effect resource file, each drawing layer effect parameter of the target text is determined based on the effect resource file, and then based on each drawing layer effect parameter and the distance field image, the effect text of the target text is drawn layer by layer.
[0126] Each drawing layer effect parameter may include offset parameters, edge gradient coefficients, etc. Each drawing layer may be configured with inner / outer shadows, glow, dynamic changes, etc. Each drawing layer may also include multiple outline effects, each of which may have parameters such as outline width, and the outlines of different texts may be displayed in a fused manner. In addition, each outline effect may be configured with gradient colors, texture fill modes, etc. The gradient colors may be selected to be single color, two-color, three-color gradient, etc.
[0127] Based on the setting of the above drawing layer effect parameters, a top-down three-order protocol can be implemented, so that the setting based on the above protocol can realize almost all text effects and meet various text effect display requirements.
[0128] Based on the contents in the above embodiments, refer to Figure 4 , a text effect image generation system 400 provided in an embodiment of the present disclosure includes a distance field generation unit 401 and an effect text generation unit 402.
[0129] The distance field generating unit 401 is used to generate a directed distance field image of the target text using the directed distance field image generating method described above;
[0130] The effect text generating unit 402 is configured to generate effect text corresponding to the target text based on the effect resource file and the directed distance field image of the target text generated by the distance field generating unit.
[0131] It can be understood that the function of generating a signed distance field image is independent of other functions in the text effect image generation system. By selecting different effect resource files and combining the signed distance field image of the target text generated by the distance field generation unit, various effects of the target text can be obtained.
[0132] In addition, by selecting different font files and combining the directed distance field image of the target text generated by the distance field generating unit, various font effects corresponding to the target text can be obtained.
[0133] In addition, animation effects, bubble effects, etc. corresponding to the target text may be obtained by selecting different animation resources and bubble resources in combination with the directed distance field image of the target text generated by the distance field generation unit.
[0134] It is worth noting that in the system for generating text effect images of target text based on signed distance field images provided in the embodiment of the present disclosure, there is no limitation on the effect resource file, and the text effect image generation system based on the embodiment of the present disclosure can obtain various effects for the target text.
[0135] Based on the above method embodiment, the present disclosure provides a device for generating a directed distance field image, referring to Figure 5 , is a schematic structural diagram of a device for generating a directed distance field image provided by an embodiment of the present disclosure, the device comprising:
[0136] A first determination module 501 is used to determine a target closed curve in an undirected distance field image of a target text, and determine an origin corresponding to the target closed curve;
[0137] A triangle drawing module 502 is used to draw a target triangle using two adjacent sampling points on the target closed curve and the origin as vertices according to a sampling order of the adjacent sampling points; wherein the sampling order is a preset direction along the target closed curve;
[0138] A counting module 503 is used to count the pixel points in the target triangle area based on the drawing direction of the target triangle; wherein the drawing direction of the target triangle is clockwise or counterclockwise, and the counting methods corresponding to the clockwise and counterclockwise directions are opposite, and the counting methods include increasing N or subtracting N for each counting, and N is a non-zero number;
[0139] A second determination module 504 is configured to determine whether the pixel points whose count results in the unoriented distance field image are 0 are located in an outer region of the target text, and determine whether the pixel points whose count results in the unoriented distance field image are not 0 are located in an inner region of the target text;
[0140] The first generating module 505 is configured to generate a directed distance field image of the target text according to the pixel points in the outer area of the target text, the pixel points in the inner area of the target text and the undirected distance field image.
[0141] In an optional implementation manner, when the drawing direction is clockwise or counterclockwise, the corresponding counting methods are opposite, including:
[0142] When the drawing direction is clockwise, the pixel points in the triangular area are counted by adding N each time they are counted; when the drawing direction is counterclockwise, the pixel points in the triangular area are counted by subtracting N each time they are counted;
[0143] Alternatively, when the drawing direction is clockwise, the pixel points in the triangular area are counted by subtracting N each time they are counted; and when the drawing direction is counterclockwise, the pixel points in the triangular area are counted by adding N each time they are counted.
[0144] In an optional implementation, the device further includes:
[0145] A splitting module, used for splitting the distance field value corresponding to the pixel point on the signed distance field image into four 8-bit unsigned integers;
[0146] The storage module is used to store the four 8-bit unsigned integers respectively using the four color channels of RGBA.
[0147] In an optional implementation manner, the splitting module is specifically used to:
[0148] The integer part of the distance field value corresponding to the pixel point on the signed distance field image, [1 / 256,1], [1 / 256 2 ,1 / 256]、[1 / 256^3,1 / 256 2 ] The values of the four parts are multiplied by 1, 256, and 256 respectively 2 ,256 3 After that, 4 8-bit unsigned integers are obtained.
[0149] In an optional implementation, the device further includes:
[0150] A recovery module is configured to, in response to an application trigger operation for the directed distance field image, divide the four 8-bit unsigned integers by 1, 256, and 256, respectively. 2 ,256 3 The values obtained are accumulated to obtain a 32-bit floating point number as the distance field value of the pixel point.
[0151] In an optional implementation, the device further includes:
[0152] A conversion module, used for converting the third-order Bezier curve in the target font file into a second-order Bezier curve to obtain a converted target font file;
[0153] The second generating module is used to generate an undirected distance field image of the target text by combining the converted target font file and the vector contour information of the target text.
[0154] In an optional implementation, the device further includes:
[0155] The cache module is used to cache the directed distance field image of the target text.
[0156] In an optional implementation, the directed distance field image of the target text is generated in real time.
[0157] The device for generating a signed distance field image provided by the embodiment of the present disclosure improves the accuracy of determining whether a pixel point in an overlapping area of a closed curve in a target text is in an internal area of the target text by changing the counting method of the pixel points in the shape drawing stage and the judgment method of determining whether the pixel point is in an internal area of the text based on the counting result, thereby improving the accuracy of generating a signed distance field image.
[0158] In addition to the above-mentioned method and apparatus, the embodiments of the present disclosure further provide a computer-readable storage medium, in which instructions are stored. When the instructions are executed on a terminal device, the terminal device implements the directed distance field image generation method or text effect image generation method described in the embodiments of the present disclosure.
[0159] The embodiments of the present disclosure also provide a computer program product, including a computer program / instruction, characterized in that when the computer program / instruction is executed by a processor, the method for generating a signed distance field image or the method for generating a text effect image described in the embodiments of the present disclosure is implemented.
[0160] In addition, the present disclosure also provides a device for generating a directed distance field image, see Figure 6 As shown, it may include:
[0161] Processor 601, memory 602, input device 603 and output device 604. The number of processors 601 in the device for generating a directed distance field image can be one or more. Figure 6 In some embodiments of the present disclosure, the processor 501, the memory 602, the input device 603 and the output device 604 may be connected via a bus or other means, wherein: Figure 6 The example of connecting through bus is taken in the following.
[0162] The memory 602 can be used to store software programs and modules. The processor 601 executes various functional applications and data processing of the device for generating the oriented distance field image by running the software programs and modules stored in the memory 602. The memory 602 can mainly include a program storage area and a data storage area, wherein the program storage area can store an operating system, an application required for at least one function, etc. In addition, the memory 602 can include a high-speed random access memory, and can also include a non-volatile memory, such as at least one disk storage device, a flash memory device, or other volatile solid-state storage devices. The input device 603 can be used to receive input digital or character information, and generate signal input related to user settings and function control of the device for generating the oriented distance field image.
[0163] Specifically in this embodiment, the processor 601 loads the executable files corresponding to the processes of one or more application programs into the memory 602 according to the following instructions, and the processor 601 runs the application programs stored in the memory 602, thereby realizing various functions of the above-mentioned device for generating a directed distance field image.
[0164] In addition, the present disclosure also provides a text effect image generation device, see Figure 7 As shown, it may include:
[0165] Processor 701, memory 702, input device 703 and output device 704. The number of processors 701 in the text effect image generation device can be one or more. Figure 7 In some embodiments of the present disclosure, the processor 701, the memory 702, the input device 703 and the output device 704 may be connected via a bus or other means, wherein: Figure 7 The example of connecting through bus is taken in the following.
[0166] The memory 702 can be used to store software programs and modules. The processor 701 executes various functional applications and data processing of the text effect image generation device by running the software programs and modules stored in the memory 702. The memory 702 can mainly include a program storage area and a data storage area, wherein the program storage area can store an operating system, at least one application required for a function, etc. In addition, the memory 702 can include a high-speed random access memory, and can also include a non-volatile memory, such as at least one disk storage device, a flash memory device, or other volatile solid-state storage devices. The input device 703 can be used to receive input digital or character information, and generate signal input related to user settings and function control of the text effect image generation device.
[0167] Specifically in this embodiment, the processor 701 will load the executable files corresponding to the processes of one or more applications into the memory 702 according to the following instructions, and the processor 701 will run the applications stored in the memory 702, thereby realizing the various functions of the above-mentioned text effect image generation device.
[0168] It should be noted that, in this article, relational terms such as "first" and "second" are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the existence of other identical elements in the process, method, article or device including the elements.
[0169] The above description is only a specific embodiment of the present disclosure, so that those skilled in the art can understand or implement the present disclosure. Various modifications to these embodiments will be apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the present disclosure. Therefore, the present disclosure will not be limited to the embodiments described herein, but will conform to the widest scope consistent with the principles and novel features disclosed herein.
Claims
1. A method for generating a signed distance field image, characterized in that: The method comprises: Determine a target closed curve in the undirected distance field image of the target text, and determine an origin corresponding to the target closed curve; Taking two adjacent sampling points on the target closed curve and the origin as vertices, and drawing a target triangle according to the sampling order of the adjacent sampling points; wherein the sampling order is a preset direction along the target closed curve; Based on the drawing direction of the target triangle, counting the pixels within the target triangle area; wherein the drawing direction of the target triangle is a clockwise direction or a counterclockwise direction, and the corresponding counting methods are opposite when the drawing direction is a clockwise direction or a counterclockwise direction, and the counting methods include increasing N for each count or subtracting N for each count, and N is a non-zero number; Determine that the pixel points whose count results in the unoriented distance field image are 0 are located in the outer region of the target text, and determine that the pixel points whose count results in the unoriented distance field image are not 0 are located in the inner region of the target text; A directed distance field image of the target text is generated according to the pixel points in the outer area of the target text, the pixel points in the inner area of the target text, and the undirected distance field image.
2. The method according to claim 1, characterized in that When the drawing direction is clockwise or counterclockwise, the corresponding counting methods are opposite, including: When the drawing direction is clockwise, the pixel points in the triangular area are counted by adding N each time they are counted; when the drawing direction is counterclockwise, the pixel points in the triangular area are counted by subtracting N each time they are counted; Alternatively, when the drawing direction is clockwise, the pixel points in the triangular area are counted by subtracting N each time they are counted; and when the drawing direction is counterclockwise, the pixel points in the triangular area are counted by adding N each time they are counted.
3. The method according to claim 1, characterized in that The method further comprises: Splitting the distance field value corresponding to the pixel point on the signed distance field image into four 8-bit unsigned integers; The four 8-bit unsigned integers are stored respectively using four color channels.
4. The method according to claim 3, characterized in that The step of splitting the distance field value corresponding to the pixel point on the signed distance field image into four 8-bit unsigned integers includes: The integer part of the distance field value corresponding to the pixel point on the directed distance field image, [1 / 256, 1], [1 / 256 2 , 1 / 256], [1 / 256 3 , 1 / 256 2 ] The values of the four parts are multiplied by 1, 256, and 256 respectively 2 and 256 3 After that, 4 8-bit unsigned integers are obtained.
5. The method according to claim 4, characterized in that The method further comprises: In response to an application trigger operation for the signed distance field image, the four 8-bit unsigned integers are divided by 1, 256, and 256, respectively. 2 , 256 3 The values obtained are accumulated to obtain a 32-bit floating point number as the distance field value of the pixel point.
6. The method according to claim 1, characterized in that Before determining the target closed curve in the undirected distance field image of the target text, the method further includes: Convert the third-order Bezier curve in the target font file into a second-order Bezier curve to obtain the converted target font file; The converted target font file and the vector outline information of the target text are combined to generate an unoriented distance field image of the target text.
7. The method according to claim 1, characterized in that The method further comprises: The directed distance field image of the target text is cached.
8. The method according to claim 1, characterized in that The directed distance field image of the target text is generated in real time.
9. A method for generating a text effect image, characterized in that: The method comprises: Generate a directed distance field image of the target text using the directed distance field image generation method described in any one of claims 1 to 8; Based on the effect resource file and the directed distance field image of the target text, a text effect image corresponding to the target text is generated.
10. The method according to claim 9, characterized in that The step of generating a text effect image corresponding to the target text based on the effect resource file and the directed distance field image of the target text comprises: In response to the selection operation of the effect resource file, determining the drawing layer effect parameters of the target text based on the effect resource file; Based on the distance field image of the target text and the drawing layer effect parameters, a text effect image corresponding to the target text is drawn layer by layer.
11. A device for generating a signed distance field image, characterized in that: The device comprises: A first determination module is used to determine a target closed curve in an undirected distance field image of a target text, and determine an origin corresponding to the target closed curve; A triangle drawing module, used to draw a target triangle using two adjacent sampling points on the target closed curve and the origin as vertices according to a sampling order of the adjacent sampling points; wherein the sampling order is a preset direction along the target closed curve; A counting module, configured to count the pixels within the target triangle region based on the drawing direction of the target triangle; wherein the drawing direction of the target triangle is clockwise or counterclockwise, and the counting methods corresponding to the clockwise or counterclockwise drawing directions are opposite, and the counting methods include increasing N or subtracting N, where N is a non-zero number; a second determination module, configured to determine whether the pixel points whose count results in the unoriented distance field image are 0 are located in an outer region of the target text, and determine whether the pixel points whose count results in the unoriented distance field image are not 0 are located in an inner region of the target text; The first generating module is used to generate a directed distance field image of the target text according to the pixel points in the external area of the target text, the pixel points in the internal area of the target text and the undirected distance field image.
12. A text effect image generation system, characterized in that: The system comprises: A distance field generating unit, configured to generate a directed distance field image of the target text by using the directed distance field image generating method according to any one of claims 1 to 8; The effect text generating unit is used to generate a text effect image corresponding to the target text based on the effect resource file and the directed distance field image of the target text generated by the distance field generating unit.
13. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores instructions, and when the instructions are executed on a terminal device, the terminal device implements the method according to any one of claims 1 to 10.
14. A device, characterized in that include: A memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the computer program, the method according to any one of claims 1 to 10 is implemented.
15. A computer program product, characterized in that The computer program product comprises a computer program / instruction, and when the computer program / instruction is executed by a processor, the method according to any one of claims 1 to 10 is implemented.
Citation Information
Patent Citations
Methods for converting hollow characters into stylized stroke characters
CN102292721A
Fluid simulation method for combining SPH and dynamic surface mesh
CN103714575A