没有合适的资源?快使用搜索试试~ 我知道了~
首页yuv420sp图像的裁剪,后放到指定位置,再将一张图片分成四张,再合成回来成为一张
资源详情
资源评论
资源推荐

https://blog.csdn.net/q2519008/article/details/80667535
YUV420SP
//将一张 1280*720 YUV420sp 的图像截取出制定区间的图像。然后放到一张新的图像指定的位置
// ConsoleApplication1.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include <fstream>
#include<string.h>
#include<vector>
#include<malloc.h>
#include<memory.h>
#include <math.h>
#include <iostream>
using namespace std;
int main()
{
typedef struct yuvImage
{
int width; /* Image width */
int height; /* Image height */
unsigned char *y; /* y: data pointer */
unsigned char *u; /* u: data pointer */
unsigned char *v; /* v: data pointer */
} YUV_IMAGE;
YUV_IMAGE* yuvImage = (YUV_IMAGE*)malloc(sizeof(YUV_IMAGE));

yuvImage->height = 720;
yuvImage->width = 1280;
int width = 1280;
int height = 720;
unsigned char *input_bu?;
unsigned char *output_bu?;
unsigned char *output_bu?Y;
unsigned char *output_bu?UV;
int readsize;
int i = 0;
int j = 0;
int k = 0;
int size = 1280 * 720;
input_bu? = (unsigned char *)malloc((width*height * 3 / 2) * sizeof(unsigned char));
output_bu? = (unsigned char *)malloc((width*height * 3 / 2) * sizeof(unsigned char));
output_bu?Y = (unsigned char *)malloc((width*height) * sizeof(unsigned char));
output_bu?UV = (unsigned char *)malloc((width*height / 2) * sizeof(unsigned char));
unsigned char *tarYuv, *srcYuv;
int yuvType, startW = 0, startH = 0, cutW = 1024, cutH = 640, srcW = 1280, srcH =
720, startW1 = 128, startH1 = 40;
unsigned char *tmpY = (unsigned char *)malloc(cutW*cutH);
unsigned char *tmpUV = (unsigned char *)malloc(cutW*cutH / 2);
tarYuv = (unsigned char *)malloc((cutW*cutH * 3 / 2) * sizeof(unsigned char));
srcYuv = input_bu?;
FILE * out = fopen("D:\\work\\124\\ConsoleApplication1\\ConsoleApplication1\\test\\
31.nv12", "wb");
FILE* yuvInJle = fopen("D:\\work\\124\\ConsoleApplication1\\ConsoleApplication1\\
test\\30.nv12", "rb");
if (yuvInJle == NULL)
printf("cannot open Jle\n");
fread(input_bu?, sizeof(unsigned char), width*height * 3 / 2, yuvInJle);
for (i = startH; i<cutH + startH; i++) {
// 逐行拷贝 Y 分量,共拷贝 cutW*cutH
memcpy(tmpY + j*cutW, srcYuv + startW + i*srcW, cutW);
j++;
}

for (i = startH / 2; i<(cutH + startH) / 2; i++) {
//逐行拷贝 UV 分量,共拷贝 cutW*cutH/2
memcpy(tmpUV + k*cutW, srcYuv + startW + srcW*srcH + i*srcW, cutW);
k++;
}
//将拷贝好的 Y,UV 分量拷贝到目标内存中,如果是只要截图就行了,就注释掉下面的两个 for 循环,
然后 fwrite(tarYuv。。。这一行
//如果是将截好的图放到指定的位置,就不注释下面的两个 for 循环,但是得注释
fwrite((tarYuv。。。这一行
memcpy(tarYuv, tmpY, cutW*cutH);
memcpy(tarYuv + cutW*cutH, tmpUV, cutW*cutH / 2);
i = 0;
j = 0;
k = 0;
for (i = 0; i< cutH; i++) {
// 逐行拷贝 Y 分量,共拷贝 cutW*cutH
memcpy(output_bu?Y + startW1 + startH1*srcW + j*srcW, tmpY + i*cutW,
cutW);
j++;
}
for (i = 0; i<(cutH) / 2; i++) {
//逐行拷贝 UV 分量,共拷贝 cutW*cutH/2
memcpy(output_bu?UV + startW1 + startH1*srcW / 2 + k*srcW, tmpUV +
i*cutW, cutW);//写到这里
k++;
}
// fwrite(tarYuv, sizeof(unsigned char), cutW*cutH * 3 / 2, out);
memcpy(output_bu?, output_bu?Y, srcW*srcH);
memcpy(output_bu? + srcW*srcH, output_bu?UV, srcW*srcH / 2);
fwrite(output_bu?, sizeof(unsigned char), srcW*srcH * 3 / 2, out);
fclose(yuvInJle);
fclose(out);
free(input_bu?);
free(output_bu?);
free(output_bu?Y);
free(output_bu?UV);
free(yuvImage);
free(tarYuv);
剩余10页未读,继续阅读


















安全验证
文档复制为VIP权益,开通VIP直接复制

评论0