Determine the method for the pixel of pixel space mask code matrix to the beeline on border
Technical field
The present invention relates to the caption rendering technology in television program designing field, be specifically related to a kind of method of the pixel of pixel space mask code matrix of in based on the caption rendering of pixel space mask code matrix model, determining to the beeline on border.
Background technology
Because TV subtitling has the function of independently expressing the meaning, as a kind of TV programme key element of indispensability, TV subtitling is a kind of form that represents of important teletext.Along with the segmentation of television channel, programme content, the division of labor of each department is also specialized more, for the making of dissimilar programs, has been difficult to meet the demands with the caption system of single type.In addition, improving constantly of the diversity day by day of TV programme and televiewer's appreciation, appreciation level also requires the application model of TV subtitling to develop towards multifarious direction.
From the angle of broad sense, the handled caption object of TV subtitling can be divided into figure and two parts of literal.Compound pattern that figure comprises the figure of various regular shapes, be made up of primary graphic element and irregular figure arbitrarily, literal comprises the literal of various languages in the world.
From the angle that computer represents, the final purpose that caption object is played up is according to patterned Vector Message and image texture, adopts the related algorithm of Digital Image Processing, obtains a two field picture of being made up of the pixel that 32 RGBA represent.Therefore caption object is normalized to a kind of avatars form, helps the unitized of Digital Image Processing algorithm.
From the angle of computer graphics, all types of caption object can be considered as the figure of forming by a series of straight lines and curve.The main research contents of computer graphics is exactly a how presentation graphic and utilize computer to carry out the relative theory and the algorithm of calculating, processing and the demonstration of figure in computer of research.Figure is made up of non-geometric attributes such as geometric elements such as point, line, surface, body and gray scale, color, line style, live widths usually.From treatment technology, figure mainly is divided into two classes, and a class is based on that line information represents, as line frame graph of engineering drawing, contour map, curved surface etc., another kind of is continuous-tone image, just usually said photo realism graphic.Main purpose of computer graphics is exactly to utilize the computer generation to make us pleasing photo realism graphic.For this reason, must set up the geometric representation of the described scene of figure, use certain illumination model again, calculate the optical illumination effect under imaginary light source, texture, material properties.
In computer graphics, the Bezier curve is a kind of important polynomial parameters curve.The individual point of any N in the plane (N>=2) can constitute a Bezier curve.This N point is called the control vertex of Bezier curve, and the polygon of N some composition is called the control polygon of Bezier curve.In the caption rendering technology, can use the Bezier curve to express the Vector Message of all caption object, the original vector outline of caption object is converted into quadratic bezier curve, and an inner self intersection Bezier closed curve is divided into a plurality of closed outlines, according to intersection point a Bezier line segment is divided into some end to end line segments, in the captions vector outline, determine the inner edge/outer side attribute of each bar Bezier line segment, according to inner edge/outer side attribute the captions vector outline is advised and put in order, finally obtain some disjoint closed outlines.Then,, calculate the attribute of the polygon vector outline of caption object,, create out the polygon vector outline that is used for adding inner edge and outside further according to polygonal direction and edged type with the discrete straightway that turns to of the vector outline of caption object.
After the Vector Message at caption object carries out above-mentioned processing, captions are played up, render engine is created the pixel space mask code matrix model, this model is a two-dimensional matrix model, pixel space after the corresponding final rendering, each pixel comprises following attribute data in the matrix: 1. pixel is to the beeline Border on border, 2. pixel to the side directions of outermost side apart from Side, 3. the polygonal area A rea that surrounds through all borders of a pixel, 4. the type Type of a pixel, 5. the sign bAntialiasing whether pixel has carried out anti-aliasing processing.
Since with the original vector outline (Bezier closed curve) of caption object discrete change into the closed polygon of forming by straightway after, can be with 512 times of original pixel space amplifications, promptly a pixel has been divided into 512 parts.The coordinate space of pixel is converted to (0,0,512,512) rounded coordinate space by original (0,0,1,1) floating number coordinate space.The pixel of this moment has been expressed as a square area, and its initial area is 512 * 512.Above Border, Side, the value of Area all are in 512 * 512 coordinate space, therefore, above these data can be used as the mask of a pixel.
After the value of the Border in the pixel space mask code matrix model, S ide, Area and Type has all produced, just can carry out texture mapping and form gradient radial color filling processing to caption object, in the process of pinup picture, carry out the anti-aliasing processing of edge pixel according to the caption rendering texture properties.When caption object being carried out texture mapping and form gradient radial color filling processing, need use pixel and judge locations of pixels to the beeline Border value on border, and the color assignment of edge pixel is carried out anti-aliasing processing according to the Border value, therefore, how to determine the beeline Border value of pixel accurately, for extremely important based on the caption rendering method of pixel space mask code matrix model to the border.But, a large amount of pixels for whole pixel space mask code matrix, if just calculate one by one according to the distance of putting straight line, then amount of calculation is very big, and lack logicality, in addition, pixel is just just valuable in the zone of edged to the beeline Border value on border, so, need find a kind of reasonable method to come to determine accurately the beeline of the pixel of pixel space mask code matrix to the border.
Summary of the invention
The objective of the invention is realization principle at above-mentioned caption rendering technology based on the pixel space mask code matrix model, the method of a kind of pixel of definite pixel space mask code matrix to the beeline on border is provided, and the realization of filling for the texture mapping and the form gradient radial color of caption object provides safeguard.
Technical scheme of the present invention is as follows: a kind of pixel of definite pixel space mask code matrix comprises the steps: to the method for the beeline on border
(1) (P0 P1), determines straightway (P0 to choose straightway on the polygon vector outline border of caption object, P1) coordinate of two end points P0, P1 (P0.x, P0.y), (P1.x, P1.y) and the vector (P0.dx that adds edge direction of two end points, P0.dy), (P1.dx, P1.dy);
(2) set along adding edge direction successively calculated distance k, step-length s, calculate P0, P1 successively at the coordinate that adds on the edge direction P2, P3, P4, P5 at pairing according to the vector that adds edge direction of P0, P1;
(3) surround quadrangle by P2, P3, P4, P5 point, all pixels in the traversal quadrangle according to the computing formula of putting the straight line vertical range, calculate each and put straightway (P0, distance P1).
Further, the pixel of aforesaid definite pixel space mask code matrix is to the method for the beeline on border, the vector that adds edge direction of two end points is to determine according to the angle that adds edge direction in the step (1), and the vector that adds edge direction is as follows with the relation of the angle that adds edge direction:
P0.dx=Cos(A0)P0.dy=Sin(A0)
P1.dx=Cos(A1)P1.dy=Sin(A1)
Wherein, the angle that adds edge direction that P0 is ordered is A0, and the angle that adds edge direction that P1 is ordered is A1.
Further, the pixel of aforesaid definite pixel space mask code matrix is to the method for the beeline on border, and the coordinate that P2, P3, P4, P5 are ordered in the step (2) is determined as follows:
The coordinate of P2, P4 calculates according to the P0 point:
P2.x=P0.x+(k-s)*P0.dx;
P2.y=P0.y+(k-s)*P0.dy;
P4.x=P0.x+k*P0.dx;
P4.y=P0.y+k*P0.dy;
The coordinate of P3, P5 calculates according to the P1 point:
P3.x=P1.x+(k-s)*P1.dx;
P3.y=P1.y+(k-s)*P1.dy;
P5.x=P1.x+k*P1.dx;
P5.y=P1.y+k*P1.dy。
Beneficial effect of the present invention is as follows: the polygon vector outline that the present invention is directed to caption object carries out after edged (inner edge or outside) handles, the pixel of how accurately reasonably determining to add in the edge regions has proposed a kind of practical solution to the distance on polygon vector outline border, from more borderline and successively calculate the point that adds in the edge regions distance more down to profile along adding edge direction separately, thereby guaranteed the precision of calculating, the realization of filling for the texture mapping and the form gradient radial color of follow-up captions rendering program provides guarantee.
Description of drawings
Fig. 1 a is the schematic diagram of pixel space mask code matrix;
Fig. 1 b has filled the later pixel space color matrices schematic diagram of color;
Fig. 2 is the vector that adds edge direction and the angular relationship schematic diagram that adds edge direction of line segment end points;
Fig. 3 puts the method schematic diagram of the beeline on border for calculating pixel successively.
Embodiment
Below in conjunction with the drawings and specific embodiments the present invention is described in detail.
Because the present caption system caption rendering ubiquity rendering efficiency that is used for television program designing is low, the edge sawtooth effect, it is clear that small character is smudgy, the strokes of characters thickness is inhomogeneous, fade effect is untrue, can't realize polygon many shadows rendering effect, can't realize a series of technical and problems of using such as characters in a fancy style effect, therefore, can be converted into one by Vector Message based on isocontour pixel mask matrix with caption object, the technology of carrying out caption rendering is solved on this basis, and this technology is called based on the closed-loop territory of curved profile and the caption rendering method of pixel mask matrix (particular content can referring to the patent of the application same period).
The committed step of said method at first is the generation in limited closed-loop territory.Limited closed-loop territory is the closed region of connection more than of ring in limited, outer shroud (the inner and outer rings direction is opposite) definition, and interior ring must be in an outer shroud.An input primitive is made up of one or more closed outlines, and profile is represented with the quadratic bezier curve that head and the tail link.Closed outline is carried out curve intersection detect,, generate the inner and outer ring in finite ring territory by reducing curve and returning profile.
The crossing detection of curve utilize boundary rectangle to detect to choose may intersection curve to raise the efficiency, recurrence method is cut apart the bounding box detection of carrying out local curve to the Bezier curve that may intersect to dichotomy then, when the curved section of cutting apart satisfies straight line and fits precision, with straight line rule find intersection, it is right to cut apart intersection curve according to intersection point.Calculate the direction of curve that intersection point links to each other and carry out the inner and outer rings class test, reduce the curve that does not satisfy the inner and outer rings attribute, promptly delete by an outer shroud and comprise but consistent curve or that comprised by interior ring and curve interior ring direction unanimity with the outer shroud direction.Connect the curve that the head and the tail end points overlaps, generate the inner and outer ring of sealing.
The thought of algorithm depends on its position with respect to the ring territory based on a certain renderer property of playing up district's (playing up primitive is a pixel), be 0 apart from line promptly with original contour ring territory, play up primitive relative 0 distance by calculating and obtain pixel mask matrix, divide the different districts of playing up by the contour of pixel mask matrix apart from line.Play up the flexible division in district, can realize that the multilayer pel plays up; Different distance calculation modes obtain different contours, thereby realize different zone boundary lead angle characteristics; Pixel mask matrix is done conversions such as depth information, realizes stereoeffects such as embossment.
Therefore, another committed step of algorithm is exactly the calculating of each attribute in the pixel mask matrix.Discretization curve ring territory is according to the symbol (for example, outer shroud is counterclockwise, and then a left side is positive right for negative, and the primitive of some chain process is zero) of each primitive in the direction of advance marking path mapping graph of the profile point chain of discretization.Calculate the distance of playing up primitive, the distance value of the absolute value minimum of each primitive of record in mapping graph in the finite region scope that surrounds by deflection bisector direction vector to the direction vector of each point in the chain and front and back point thereof.
Based on above-mentioned principle, with the Bezier curve vector profile of a caption object discrete turn to polygon vector G after, further, create out the polygon vector G2 that is used for adding the polygon vector G1 of inner edge and is used for adding the outside according to polygonal direction and edged type.Then, just can carry out follow-up rendering to caption object.At first will create a two-dimensional matrix model, pixel space after the corresponding final rendering of this model as shown in Figure 1a, has been filled the later pixel space color matrices of color shown in Fig. 1 b, and the color-values of each pixel comprises four components of RGBA.
Each pixel comprises following attribute data in the pixel space mask code matrix:
(1). a pixel arrives the beeline Border on border.This value is used when adding inner edge, outside.Dissimilar according to corner limit, wedge angle limit, round edge, this distance has different meanings.
(2). pixel to the side directions of outermost side apart from Side.This value is used when adding side.
(3). the polygonal area A rea that surrounds through all borders of a pixel.This value is used when boundary pixel is carried out anti-aliasing pinup picture.Therefore at first will distinguish interior pixels and boundary pixel: for interior pixels, this value is fixing value (512*512); For boundary pixel, this value is a value smaller or equal to 512*512, and expression surrounds polygonal area by limit and this pixel rectangle (height and width are 512) of this pixel.
(4). the type Type of a pixel.This value is used for representing that a pixel is side border, border, outside, inner edge border, interior pixels.
(5). the sign bAntialiasing whether pixel has carried out anti-aliasing processing.Use this Boolean variable to avoid that same pixel is carried out repeatedly anti-aliasing processing.
Above Border, Side, the value of Area all are in the coordinate space of 512*512, therefore, above these data can be used as the mask of a pixel.
The core concept of the Border value of calculating pixel space mask is: from more borderline and successively calculate the point that adds in the edge regions distance to the profile border along adding edge direction separately more down.
As shown in Figure 2, a point on the hypothetical boundary is P0, and next point is P1, the coordinate that P0 is ordered be (P0.x, P0.y), the vector that expression P0 point adds edge direction is (P0.dx, P0.dy), the coordinate that P1 is ordered be (P1.x, P1.y), the vector that expression P1 point adds edge direction is (P1.dx, P1.dy), and straightway (P0, P1) angle is a, along adding the value that edge direction successively calculates is k, and step-length is s.The angle that adds edge direction that P0 is ordered is A0, and the angle that adds edge direction that P1 is ordered is A1, the relation that adds edge-vector dx, dy and A0 that P0 is ordered, and the relation that adds edge-vector dx, dy and A1 that P1 is ordered is as follows:
P0.dx=Cos(A0)P0.dy=Sin(A0)
P1.dx=Cos(A1)P1.dy=Sin(A1)
The angle A that adds edge direction 1 that angle A that adds edge direction 0 that P0 is ordered and P1 are ordered is to disperse at the vector outline with caption object to turn to straightway, calculate the attribute of the polygon vector outline of caption object, further according to polygonal direction and edged type, create out and determine in the process of the polygon vector outline that is used for adding inner edge and outside, this is that the vector outline of caption object is handled the also known technology of edged, considers as known quantity herein.
As shown in Figure 3, go out P0, P1 at the coordinate that adds on the edge direction P2, P3, P4, P5 at pairing according to the edged vector calculation of P0, P1:
The coordinate of P2, P4 calculates according to the P0 point:
P2.x=P0.x+(k-s)*P0.dx;
P2.y=P0.y+(k-s)*P0.dy;
P4.x=P0.x+k*P0.dx;
P4.y=P0.y+k*P0.dy;
The coordinate of P3, P5 calculates according to the P1 point:
P3.x=P1.x+(k-s)*P1.dx;
P3.y=P1.y+(k-s)*P1.dy;
P5.x=P1.x+k*P1.dx;
P5.y=P1.y+k*P1.dy。
Suppose that the quadrangle that P2, P3, P4, P5 point surround is R (dash area among the figure), all pixels in the traversal quadrangle according to the computing formula of putting the straight line vertical range, calculate each and put straightway (P0, distance P1).
Along adding value k and the step-length s that edge direction successively calculates is empirical value, k can be the precision that guarantees that edged calculates for the width on a limit or less than the width on a limit, and the value of s is unsuitable excessive, general desirable 0.009765625 (according to the 512X512 pixel space, this value is 5).
Pass through said method, add value k and the step-length s that edge direction successively calculates for the edge, calculate successively the pixel add in the edge regions to the profile border apart from the Border value, each straightway for caption object polygon vector outline, all the Border value is all calculated by this method, in pixel space mask code matrix, point with identical Border value has constituted a series of contour, utilize these contours, the render effects that can be achieved as follows just: (1). a caption object adds a plurality of outsides, and the different textures of playing up can be used in each outside; (2). a caption object adds a plurality of inner edges, and each inner edge can use the different textures of playing up; (3). the shape according to the vector outline of caption object, realize real " form gradient ".
Method of the present invention is not limited to the embodiment described in the embodiment, and those skilled in the art's technical scheme according to the present invention draws other execution mode, belongs to technological innovation scope of the present invention equally.