Background technique
When carrying out H.264 (compression of digital video format) coding, need the pixel of rgb format being converted to yuv format
Pixel.It makes explanations respectively to RGB and YUV first:
Rgb color mode (Red, Green, Blue, red, green, blue three-color mode) is a kind of color mark of industry
Standard is by obtaining not to red (R), green (G), the variation of blue (B) three Color Channels and their mutual superpositions
Same color, RGB is the color for representing three channels of red, green, blue, this standard almost includes that human eyesight can perceive
All colours, be current to use most wide one of color system.
YUV (colour coding method) format is divided into three components, and " Y " indicates brightness (Luminance or Luma), also
It is gray value;And that " U " and " V " is indicated is then coloration (Chrominance or Chroma), effect is description colors of image and satisfies
And degree, the color for specified pixel.Yuv format is mainly used for television system and analog video field, it is by luminance information
(Y) it is separated with color information (UV), no UV information can equally show complete image, only black and white, such
Design has well solved the compatibling problem of colour television set and black-and-white television.Also, YUV required unlike RGB three solely
Vertical vision signal simultaneous transmission, so few with the bandwidth that yuv format transmission data occupy.
The storage format of YUV code stream and the mode that it is sampled are closely related, and there are three types of the sample modes of mainstream, YUV4:4:
4, YUV4:2:2, YUV4:2:0.Yuv format has two major classes: planar planar format and packed are packaged format.For planar
Yuv format, the Y of first Coutinuous store all pixels point, and then store all pixels point U, be followed by all pixels point
V.For the yuv format of packed, the Y of each pixel, U, V are continuous stored interleaveds.
H.264, when the pixel that the pixel of rgb format is converted to yuv format is encoded, need to exist using related algorithm
It is executed on the CPU of computer.Since CPU is that the working centre of computer must while CPU carries out pixel format conversion
It so will do it other work;That is the data transfer bandwidth of pixel format conversion is difficult to reach maximum on CPU, Jin Eryan
The calculating process for having grown pixel format conversion reduces the transfer efficiency of pixel format conversion.
Summary of the invention
In view of the deficiencies in the prior art, present invention solves the technical problem that are as follows: 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 transfer efficiency.
To achieve the above objectives, the method provided by the invention that pixel format is converted to NV12 by ARGB by GPU, should
The image of NV12 pixel format in method includes 2 planes: brightness Y plane and color UV plane, this method include following step
It is rapid:
Created in the 2 d texture interface of graphical programming interface 18 pixel format Y plane storing texture and 1
The UV plane storing texture of 16 pixel formats;
The ARGB storing texture converted will be needed to be input to GPU, GPU will be schemed by HLSL language in ARGB storing texture
After the pixel format of picture is converted to NV12 by ARGB, the Y plane assignment of the image of NV12 pixel format to the Y plane is stored
Texture, by the UV plane assignment of the image of NV12 pixel format to the UV plane storing texture.
The system that pixel format is converted to by ARGB by NV12 by GPU provided by the invention for realizing the above method, packet
Include storing texture creation module and the pixel format conversion module on GPU;
Storing texture creation module is used for: 18 pixel format is created in the 2 d texture interface of graphical programming interface
Y plane storing texture and 1 16 pixel format UV plane storing texture;By the Y plane of the image of NV12 pixel format
Assignment is to the Y plane storing texture, by the UV plane assignment of the image of NV12 pixel format to the UV plane storing texture;
Pixel format conversion module is used for: by HLSL language, by the image in the ARGB storing texture for needing to convert
Pixel format is converted to NV12 by ARGB.
Compared with the prior art, the advantages of the present invention are as follows:
The present invention does not use and carries out pixel format conversion method by CPU in the prior art, 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 by ARGB is converted to NV12 and assignment creates to the 2 d texture interface for advancing with graphical programming interface
In the texture of NV12 pixel format image.Therefore, the present invention can reduce the bandwidth carried out data transmission between CPU and GPU, into
And data transfer bandwidth when increasing pixel format conversion, that is, the calculating process of pixel format conversion is shortened, conversion is improved
Efficiency.
Specific embodiment
Invention is further described in detail with reference to the accompanying drawings and embodiments.
It makes explanations respectively explanation to ARGB pixel format and NV12 pixel format first:
ARGB (Alpha, Red, Green, Blue) pixel format, is one of RGB color format, carrys out table using 32
Show a pixel, RGB component respectively spends 8, and remaining 8 are used as Alpha (transparency);The row of each component of ARGB in memory
Column sequence are as follows: B0, G0, R0, A0, B1, G1, R1, A1, B2, G2, R2, A2.
NV12 pixel format, belongs to YUV420 format, and mode is two-plane (double layer planar), i.e. NV12 pixel format
Image include two planes: Y (brightness) plane and UV (color) plane, UV plane (CbCr) is stored interleaved.Such as it is fixed
The picture traverse of an adopted width NV12 pixel format is d, is highly h, then the byte of the width of the Y plane of the image and one-row pixels
Number is d, is highly h;The width of the UV plane of the image is d/2, the byte number of one-row pixels is d, is highly h/2.
On this basis, shown in Figure 1, pixel format being converted to by ARGB by GPU in the embodiment of the present invention
The method of NV12, comprising the following steps:
S1: ARGB storing texture (i.e. ARGB pixel format image is created in the 2 d texture interface of graphical programming interface
Storing texture).
S2: the Y plane storing texture of 18 pixel format is created (i.e. in the 2 d texture interface of graphical programming interface
The storing texture of the UV plane of NV12 pixel format image) and 1 16 pixel format UV plane storing texture (i.e. NV12 picture
The storing texture of the UV plane of plain format-pattern).
Graphical programming interface in S1 and S2 be all made of Microsoft offer Direct3D 11, the two of Direct3D 11
Dimension texture interface is ID3D11Texture2D;On this basis:
The format of the ARGB storing texture of ID3D11Texture2D creation is DXGI_FORMAT_B8G8R8A8_UNORM.
The format of the Y plane storing texture of ID3D11Texture2D creation are as follows: DXGI_FORMAT_A8_UNORM.
The format of the UV plane storing texture of ID3D11Texture2D creation are as follows: DXGI_FORMAT_R8G8_UNORM,
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: it (will be used as and turns after ARGB storing texture of the image assignment for the ARGB pixel format converted into S1 will be needed
The input source images changed);ARGB storing texture is input to GPU.GPU is by HLSL language, by image in ARGB storing texture
Pixel format NV12 is converted to by ARGB after, Y plane of the Y plane assignment of the image of NV12 pixel format into S2 is stored
Texture, by UV plane storing texture of the UV plane assignment of the image of NV12 pixel format into S2.
The pixel format of image in ARGB storing texture is converted to NV12's by ARGB by HLSL language by GPU in S3
Transfer algorithm are as follows:
Y=0.257R+0.504G+0.098B+16/255;
U=-0.148R -0.291G+0.439B+0.5;
V=0.439R -0.368G -0.071B+0.5;
Wherein Y, U and V respectively represent Y, U and V component in the image of NV12 pixel format, and R, G and B respectively represent ARGB
R, G and B component in the image of pixel format.
The embodiment of the present invention carries out image conversion using HLSL language, and HLSL language works independently on windows platform,
It can only be used for the Direct3D of Microsoft, it is a kind of language being programmed for video card, is finally executed by video card.Cause
This, HLSL language is core of the invention, i.e., is that NV12 pixel format passes through HLSL language by traditional ARGB pixel format conversion
Speech is realized, is executed in GPU.
Pixel format is by the realization above method in the embodiment of the present invention by what ARGB was converted to NV12 by GPU
System, the pixel format conversion module including storing texture creation module and on GPU.
Storing texture creation module is used for:
(1) creation 1 in the 2 d texture interface (ID3D11Texture2D) of graphical programming interface (Direct3D 11)
The UV plane of a ARGB storing texture, the Y plane storing texture of 18 pixel format and 1 16 pixel format stores line
Reason;
(2) by the image assignment for the ARGB pixel format for needing to convert to ARGB storing texture;
(3) by the Y plane assignment of the image of NV12 pixel format to the Y plane storing texture, by NV12 pixel format
Image UV plane assignment to the UV plane storing texture.
Pixel format conversion module is used for: by HLSL language, by the image in the ARGB storing texture for needing to convert
Pixel format is converted to NV12 by ARGB;Transfer algorithm are as follows:
Y=0.257R+0.504G+0.098B+16/255;
U=-0.148R -0.291G+0.439B+0.5;
V=0.439R -0.368G -0.071B+0.5;
Wherein Y, U and V respectively represent Y, U and V component in the image of NV12 pixel format, and R, G and B respectively represent ARGB
R, G and B component in the image of pixel format.
The present invention is not limited to the above-described embodiments, for those skilled in the art, is not departing from
Under the premise of the principle of the invention, several improvements and modifications can also be made, these improvements and modifications are also considered as protection of the invention
Within the scope of.The content being not described in detail in this specification belongs to the prior art well known to professional and technical personnel in the field.