资源简介
可用,NV21图像,1920*1280,可通过改变变量值换成别的尺寸的图像,缩放应该为2的倍数
代码片段和文件信息
// NV21OperationC.cpp : Defines the entry point for the console application.
//
#include “stdafx.h“
#include
#include
#include
#include
#include
#include
#include
#define max 255
#define min 0
#define NV21 100
using namespace std;
typedef struct _tag_yuvImage{
int imageFormat;
int width;
int height;
unsigned char* image[2];
int pitch[2];
}YUV_Image *PYUV_Image;
int readYUVImage(const char* pFileFullPath PYUV_Image pImgDest)
{
printf(“readYUVImage begin \n“);
if (pFileFullPath == NULL || pImgDest == NULL){
printf(“readYUVImage error 1 \n“);
return -1;
}
int width = 1920;
int height = 1280;
pImgDest->imageFormat = NV21;
pImgDest->width = width;
pImgDest->height = height;
pImgDest->pitch[0] = pImgDest->width;
pImgDest->pitch[1] = pImgDest->width;
int result = 0;
int iamgeSize = 0;
if (pImgDest->imageFormat == NV21)
iamgeSize = pImgDest->pitch[0] * height + pImgDest->pitch[1] * (height/2);
else
printf(“Exception:The input image pixel format is not NV21“);
pImgDest->image[0] = (byte*)malloc(iamgeSize);
if (pImgDest->image[0] == NULL){
printf(“Allocation of memory out of memory“);
result = -1;
}
if (pImgDest->imageFormat == NV21)
pImgDest->image[1] = pImgDest->image[0] + (pImgDest->width) * (pImgDest->height);
else{
printf(“The input image pixel format is not NV21“);
result = -1;
}
int size = -1;
FILE* fp = fopen(pFileFullPath “rb“);
if (NULL != fp){
fseek(fp 0L 2);
size = ftell(fp);
fseek(fp 0L 0);
if (size < iamgeSize){
printf(“ReadDataFromFile filesize < nReadSize “);
result = -1;
}
fread(pImgDest->image[0] 1 iamgeSize fp);
}
if (NULL != fp)
fclose(fp);
if (size == iamgeSize)
result = 0;
return result;
}
int saveYUVImage(const PYUV_Image pframe const char* pSrcFilePath)
{
printf(“Start saving OffScreen\n“);
int result = -1;
if (pframe == NULL || pSrcFilePath == NULL)
return -1;
FILE* fp = NULL;
fp = fopen(pSrcFilePath “wb“);
if (NULL == fp){
printf(“Save filepath is invalid“);
result = -1;
}
else{
do{
int iamgeSize = 0;
if (pframe->imageFormat == NV21){
fwrite(pframe->image[0] 1 pframe->pitch[0] * pframe->height fp);
fwrite(pframe->image[1] 1 pframe->pitch[1] * (pframe->height/2) fp);
}
} while (false);
}
return result;
}
int MyRotate(const PYUV_Image pframe int degree PYUV_Image pOutframe)
{
int result = -1;
if (pframe == NULL || pOutframe == NULL)
return -1;
if (pframe->imageFormat != NV21 || pOutframe->imageFormat != NV21){
printf(“Rotate image failed the image pixel format is not NV21“);
return -1;
}
int width = pframe->width;
int height = pframe->height;
int height2 = (int)(height*1.5);
int kPosition = 0;
switch (degree){
case 90:
for (int i = width - 1; i >= 0; --i){
for (in
- 上一篇:OPCDAAuto.dll
- 下一篇:商品销售统计的C++课程设计
相关资源
- H264 转 YUV
- MFC实现简易画图程序
- MFC 单文档 实现opengl 三维旋转 缩放
- MFC绘制的移动小车,包含了图形的平
- 24位BMP图像用C++实现平移、旋转、镜像
- MFC 图像处理之几何运算 图像平移旋转
- 图像按任意角度旋转C++
- C语言实现图像的旋转缩放裁切
- VC C++数字图像处理实验程序
- 3D图形旋转
- MFC制作的风车可以控制叶片大小和旋
- rgb转YUV源代码
- OpenGL实现鼠标绕任意轴旋转/平移/缩放
- opengl光照旋转交互
- mfc 二维图形的变换 旋转 平移 比例
- 计算机图形学实验代码包括图形旋转
- 数字图像处理实习程序
- 旋转和移动的三维sierpinski镂垫
- GDI+绘制矩形,并且实现可旋转、缩放
- opengl在MFC平台上绘制三维图形并实现
- 基于mfc中opengl鼠标控制视图旋转缩放
- opengl实现导入正方体obj文件+旋转+平移
- c++ 旋转的圆柱
- c++ 图像处理(旋转、水平镜像等)
- yuv 3D 输出
- OpenGL+MFC实现旋转、缩放、平移
- C++方式实现stl、obj、3DS三种3D模型加载
- RGB转 YUV代码 C语言
- YUV合成 YUV裁剪 YUV_to_JPEG 纯c语言编写
- DX绘制三维旋转的立方体
评论
共有 条评论