Background technology
When carrying out H.264 (compression of digital video form) coding, need the pixel of rgb format is converted to yuv format
Pixel.First RGB and YUV is made explanations respectively:
Rgb color pattern (Red, Green, Blue, red, green, blue three-color pattern) is a kind of color mark of industrial quarters
Standard, is by obtaining red (R), green (G), the change of blue (B) three Color Channels and their superpositions each other not
Same color, RGB is i.e. the color representing three passages of red, green, blue, and this standard almost includes human eyesight institute can perception
All colours, be to use at present one of the widest color system.
YUV (colour coding method) form is divided into three components, and " Y " represents lightness (Luminance or Luma), the most just
It it is gray value;That " U " and " V " represents is then colourity (Chrominance or Chroma), and effect is to describe colors of image and satisfy
And degree, for the color of specified pixel.Yuv format is mainly used in television system and analog video field, and it is by monochrome information
(Y) separate with color information (UV), do not have UV information equally can show complete image, only black and white, such
Design solves the compatibling problem of color television receiver and black-and-white television well.Further, YUV requires three solely unlike RGB
Vertical video signal transmits simultaneously, so the frequency range taken by yuv format transmission data is few.
The mode that the storage format of YUV code stream is sampled with it is closely related, and the sample mode of main flow has three kinds, YUV4:4:
4, YUV4:2:2, YUV4:2:0.Yuv format has two big classes: planar planar format and packed pack form.For planar
Yuv format, the Y of the first all pixels of Coutinuous store, and then store the U of all pixels, be followed by all pixels
V.For the yuv format of packed, the Y of each pixel, U, V are continuous stored interleaved.
The pixel of rgb format is converted to the pixel of yuv format when H.264 encoding, needs to utilize related algorithm to exist
Perform on the CPU of computer.Owing to CPU is the working centre of computer, while therefore CPU carries out pixel format conversion, must
So can carry out other work;That is the data transfer bandwidth of pixel format conversion is difficult to reach maximum on CPU, Jin Eryan
Grow the calculating process of pixel format conversion, reduce the conversion efficiency of pixel format conversion.
Summary of the invention
For defect present in prior art, present invention solves the technical problem that into: by the pixel compartments of image on GPU
Formula is converted to NV12 by ARGB, and the present invention can shorten the calculating process of pixel format conversion, improves conversion efficiency.
For reaching object above, method pixel format being converted to NV12 by ARGB by GPU that the present invention provides, should
The image of the NV12 pixel format in method includes 2 planes: brightness Y plane and color UV plane, the method includes following step
Rapid:
The Y plane storing texture of 18 pixel format and 1 is created in the 2 d texture interface of graphical programming interface
The UV plane storing texture of 16 pixel formats;
The ARGB storing texture input needing conversion is passed through HLSL language to GPU, GPU, will ARGB storing texture be schemed
After the pixel format of picture is converted to NV12 by ARGB, the Y plane assignment of the image of NV12 pixel format to described Y plane is stored
Texture, by the UV plane assignment of the image of NV12 pixel format to described UV plane storing texture.
The system that by GPU, pixel format is converted to by ARGB NV12 realizing said method that the present invention provides, bag
Include storing texture creation module and the pixel format conversion module being positioned on GPU;
Storing texture creation module is used for: create 18 pixel format in the 2 d texture interface of graphical programming interface
Y plane storing texture and the UV plane storing texture of 1 16 pixel format;Y plane by the image of NV12 pixel format
Assignment is to described Y plane storing texture, by the UV plane assignment of the image of NV12 pixel format to described UV plane storing texture;
Pixel format conversion module is used for: by HLSL language, it would be desirable to the image in the ARGB storing texture of conversion
Pixel format is converted to NV12 by ARGB.
Compared with prior art, it is an advantage of the current invention that:
The present invention also is provided without in prior art carrying out pixel format conversion method by CPU, but according to HLSL language
(High Level Shader Language, high-order Shader Language) combines the transfer algorithm of independent research, will figure on GPU
The pixel format of picture is converted to what NV12 assignment to the 2 d texture interface advancing with graphical programming interface created by ARGB
In the texture of NV12 pixel format image.Therefore, the present invention can reduce the bandwidth carried out data transmission between CPU and GPU, enters
And data transfer bandwidth when increasing pixel format conversion, i.e. shorten the calculating process of pixel format conversion, improve conversion
Efficiency.
Detailed description of the invention
Below in conjunction with drawings and Examples, the present invention is described in further detail.
First ARGB pixel format and NV12 pixel format are made explanations respectively explanation:
ARGB (Alpha, Red, Green, Blue) pixel format, is the one in RGB color format, uses 32 and carrys out table
Showing a pixel, RGB component respectively spends 8, and remaining 8 are used as Alpha (transparency);The row of each component of ARGB in internal memory
Row order is: B0, G0, R0, A0, B1, G1, R1, A1, B2, G2, R2, A2.
NV12 pixel format, belongs to YUV420 form, and pattern is two-plane (double layer planar), i.e. NV12 pixel format
Image include two plane: Y (brightness) planes and UV (color) plane, UV plane (CbCr) is stored interleaved.The most fixed
The picture traverse of justice one width NV12 pixel format is d, and height is h, then the width of the Y plane of this image and the byte of one-row pixels
Number is d, height is h;The width of the UV plane of this image is d/2, the byte number of one-row pixels is d, height is h/2.
On this basis, shown in Figure 1, pixel format is converted to by ARGB by GPU in the embodiment of the present invention
The method of NV12, comprises the following steps:
S1: create ARGB storing texture (i.e. ARGB pixel format image in the 2 d texture interface of graphical programming interface
Storing texture).
S2: create the Y plane storing texture of 18 pixel format in the 2 d texture interface of graphical programming interface (i.e.
The storing texture of the UV plane of NV12 pixel format image) and UV plane storing texture (the i.e. NV12 picture of 1 16 pixel format
The storing texture of the UV plane of element format-pattern).
Graphical programming interface in S1 and S2 all uses the Direct3D 11 that Microsoft provides, the two of Direct3D 11
Dimension texture interface is ID3D11Texture2D;On this basis:
The form of the ARGB storing texture that ID3D11Texture2D creates is DXGI_FORMAT_B8G8R8A8_UNORM.
The form of the Y plane storing texture that ID3D11Texture2D creates is: DXGI_FORMAT_A8_UNORM.
The form of the UV plane storing texture that ID3D11Texture2D creates is: DXGI_FORMAT_R8G8_UNORM, its
Middle least-significant byte components R 8 represents the U component in UV plane, and most-significant byte component G8 represents the V component in UV plane.
S3: (i.e. as turning after the ARGB storing texture in the image assignment of the ARGB pixel format that needs are changed to S1
The input source image changed);By ARGB storing texture input to GPU.GPU passes through HLSL language, by image in ARGB storing texture
Pixel format be converted to NV12 by ARGB after, by the Y plane assignment of the image of NV12 pixel format to S2 Y plane store
Texture, by the UV plane storing texture in the UV plane assignment of the image of NV12 pixel format to S2.
In S3, GPU passes through HLSL language, and by ARGB, the pixel format of image in ARGB storing texture is converted to NV12's
Transfer algorithm is:
Y=0.257 R+0.504 G+0.098 B+16/255;
U=-0.148 R 0.291 G+0.439 B+0.5;
V=0.439 R 0.368 G 0.071 B+0.5;
Y, U during wherein Y, U and V represent the image of NV12 pixel format respectively and V component, R, G and B represent ARGB respectively
R, G in the image of pixel format and B component.
The embodiment of the present invention utilizes HLSL language to carry out image conversion, and HLSL language works alone on windows platform,
Can only be for the Direct3D of Microsoft, it is a kind of language being programmed for video card, is finally performed by video card.Cause
This, HLSL language is the core of the present invention, and ARGB pixel format conversion that will be traditional is that NV12 pixel format is by HLSL language
Speech realizes, and performs in GPU.
In the embodiment of the present invention realize said method by GPU by pixel format by what ARGB was converted to NV12 be
System, including storing texture creation module and the pixel format conversion module being positioned on GPU.
Storing texture creation module is used for:
(1) in the 2 d texture interface (ID3D11Texture2D) of graphical programming interface (Direct3D 11), create 1
The UV plane of individual ARGB storing texture, the Y plane storing texture of 18 pixel format and 1 16 pixel format stores stricture of vagina
Reason;
(2) the image assignment of the ARGB pixel format of conversion will be needed to ARGB storing texture;
(3) by the Y plane assignment of the image of NV12 pixel format to described Y plane storing texture, by NV12 pixel format
The UV plane assignment of image to described UV plane storing texture.
Pixel format conversion module is used for: by HLSL language, it would be desirable to the image in the ARGB storing texture of conversion
Pixel format is converted to NV12 by ARGB;Transfer algorithm is:
Y=0.257 R+0.504 G+0.098 B+16/255;
U=-0.148 R 0.291 G+0.439 B+0.5;
V=0.439 R 0.368 G 0.071 B+0.5;
Y, U during wherein Y, U and V represent the image of NV12 pixel format respectively and V component, R, G and B represent ARGB respectively
R, G in the image of pixel format and B component.
The present invention is not limited to above-mentioned embodiment, for those skilled in the art, without departing from
On the premise of the principle of the invention, it is also possible to make some improvements and modifications, these improvements and modifications are also considered as the protection of the present invention
Within the scope of.The content not being described in detail in this specification belongs to prior art known to professional and technical personnel in the field.