当前位置:网站首页>YUV422 to RGB (422sp to 420p)
YUV422 to RGB (422sp to 420p)
2022-07-25 20:59:00 【Full stack programmer webmaster】
Hello everyone , I meet you again , I'm your friend, Quan Jun .
YUV420 turn RGB888
yuv420 The data storage method of is planar, Is to save in one frame first y component , End of deposit y save u, next v component . And in the yuv420 There is y component widthheight byte,uv Each component is widthheight1/4, The total data in a frame is widthheight3/2(widthheight12/8). So I thought ,yuv If the component is substituted into the conversion formula ,uv Is the weight less . It's not , Because every four y Components share one u One component v component , But it's not [YiYi+1Yi+2Yi+3] share [Ui],[Vi], Because it's a 22 In the window of Y Components share one uv, therefore [YiYi+1Yi+wYi+w+1], among i It's even .uv Since the components are in the horizontal and vertical directions respectively 2:1 sampling , therefore [U(i/2*w/2+j/2)],V The same goes for components .
#include <iostream>
#include <stdio.h>
#include<fstream>
using namespace std;
bool yuv420ToRgb(char *yuv, int w, int h, char *rgb)
{
unsigned char *y = new unsigned char[w*h];
unsigned char *u = new unsigned char[w*h / 4];
unsigned char *v = new unsigned char[w*h / 4];
memcpy(y, yuv, w*h);
memcpy(u, yuv + w * h, w*h / 4);
memcpy(v, yuv + w * h * 5 / 4, w*h / 4);
for (int i = 0; i < h; i++)
{
for (int j = 0; j < w; j++)
{
rgb[i*w*3 + 3*j] = 1.164*(y[i*w+j] - 16) + 1.596*(v[i / 4 * w + j / 2] - 128);//R
rgb[i*w*3 + 3*j+1] = 1.164*(y[i*w + j] - 16) - 0.392*(u[i / 4*w+j/2] - 128) - 0.813*(v[i / 4 * w + j / 2] - 128);//G
rgb[i*w*3 + 3*j+2] = 1.164*(y[i*w + j] - 16) + 2.017*(u[i / 4 * w + j / 2] - 128); //B
}
}
free(y);
free(u);
free(v);
return true;
}
int main(int argc, char* argv[])
{
FILE *yuv, *out;
int len = 832 * 480 * 3 / 2;
char *yuvbuff = ( char *)malloc(len);
char *rgbbuff = ( char *)malloc(len*2);
char *buff = (char *)malloc(len * 2);
yuv = fopen("D://movie player//BasketballDrill_832x480_50.yuv", "rb");
out= fopen("D://movie player//rgb888.txt", "wb+");
ifstream fl("D://movie player//BasketballDrill_832x480_50.yuv", ios::binary);
fl.seekg(0, ios::end);
int size = fl.tellg();
int inFrameNum = (width*height * 3 / 2);
int frameNum = size / inFrameNum;
for (int i = 0; i <frameNum; i++) {
fread(yuvbuff, 1, width*height * 3/2, yuv);
yuv420ToRgb(yuvbuff, width, height, rgbbuff);
fwrite(rgbbuff, 1, width*height * 3 ,out);
}
return 0;
}Publisher : Full stack programmer stack length , Reprint please indicate the source :https://javaforall.cn/127840.html Link to the original text :https://javaforall.cn
边栏推荐
- An interview question about interface and implementation in golang
- Recommend a website that converts curl commands into PHP code & a website that initiates and executes curl requests online
- [technical dry goods] how to ensure the idempotency of the interface?
- ES6---4个强大运算符(??、??=、?.、?:)
- Leetcode-6127: number of high-quality pairs
- Compilation and operation of program
- ROS_ Rqt toolbox
- kali修改更新源(无法安全的用该源更新)
- Pycharm跑程序时自动进入测试模式
- Scan delete folder problems
猜你喜欢

leetcode-6127:优质数对的数目

结构体,枚举类型与联合体

ROS_ Rqt toolbox

Pychart automatically enters the test mode when running the program

Has baozi ever played in the multi merchant system?

Illustration leetcode - 3. longest substring without repeated characters (difficulty: medium)

Today's sleep quality record 75 points

Cesium polygon gradient texture (canvas)

Force deduction ----- calculate the money of the force deduction bank

Qixin Jushi cloud spectrum new chapter | Haitai Fangyuan and Sichuan Unicom reach ecological strategic cooperation
随机推荐
Niuke-top101-bm37
Unity vs -- the default debugging in VS is to start rather than attach to unity debugging
Brush questions with binary tree (4)
Question and answer 47: geeks have an appointment - the current monitoring system construction of CSC
Huatai Securities account opening process, is it safe to open an account on your mobile phone
文件操作详解
leetcode-919:完全二叉树插入器
Canvas 填充渐变
Leetcode-6131: the shortest dice sequence impossible to get
ES6---4个强大运算符(??、??=、?.、?:)
Card link
预处理指令
process.env
How to use buffer queue to realize high concurrent order business (glory Collection Edition)
两数,三数之和
Vulnhub | dc: 6 | [actual combat]
Leetcode-919: complete binary tree inserter
Today's sleep quality record 75 points
一道golang中defer和函数结合的面试题
Test cases and defect report templates