资源简介
能将png格式图片转换成YUV格式。
C++实现,并且自带可运行实例。
代码片段和文件信息
#include
#include “png/png.h“
#include
using namespace std;
const char *png_file = “NoSignal.png“;
void rgba_resize(int src_width int src_height int dst_width int dst_height uint8_t *src_buf uint8_t *dst_buf) {
int r_width = src_width * 4;
int w_width = dst_width * 4;
for (int hnum = 0; hnum < dst_height; hnum++){
for (int wnum = 0; wnum < dst_width; wnum++) {
double d_original_img_hnum = hnum * src_height / (double) dst_height;
double d_original_img_wnum = wnum * src_width / (double) dst_width;
int i_original_img_hnum = (int) d_original_img_hnum;
int i_original_img_wnum = (int) d_original_img_wnum;
double distance_to_a_x = d_original_img_wnum - i_original_img_wnum;//在原图像中与a点的水平距离
double distance_to_a_y = d_original_img_hnum - i_original_img_hnum;//在原图像中与a点的垂直距离
int original_point_a =
i_original_img_hnum * r_width + i_original_img_wnum * 4;//数组位置偏移量,对应于图像的各像素点RGB的起点相当于点A
int original_point_b =
i_original_img_hnum * r_width + (i_original_img_wnum + 1) * 4;//数组位置偏移量,对应于图像的各像素点RGB的起点相当于点B
int original_point_c =
(i_original_img_hnum + 1) * r_width + i_original_img_wnum * 4;//数组位置偏移量,对应于图像的各像素点RGB的起点相当于点C
int original_point_d =
(i_original_img_hnum + 1) * r_width + (i_original_img_wnum + 1) * 4;//数组位置偏移量,对应于图像的各像素点RGB的起点相当于点D
if (i_original_img_hnum + 1 == dst_width - 1) {
original_point_c = original_point_a;
original_point_d = original_point_b;
}
if (i_original_img_wnum + 1 == dst_width - 1) {
original_point_b = original_point_a;
original_point_d = original_point_c;
}
int pixel_point = hnum * w_width + wnum * 4;//映射尺度变换图像数组位置偏移量
dst_buf[pixel_point] =
(uint8_t) (src_buf[original_point_a] * (1 - distance_to_a_x) * (1 - distance_to_a_y) +
src_buf[original_point_b] * distance_to_a_x * (1 - distance_to_a_y) +
src_buf[original_point_c] * distance_to_a_y * (1 - distance_to_a_x) +
src_buf[original_point_d] * distance_to_a_y * distance_to_a_x);
dst_buf[pixel_point + 1] =
(uint8_t) (src_buf[original_point_a + 1] * (1 - distance_to_a_x) * (1 - distance_to_a_y) +
src_buf[original_point_b + 1] * distance_to_a_x * (1 - distance_to_a_y) +
src_buf[original_point_c + 1] * distance_to_a_y * (1 - distance_to_a_x) +
src_buf[original_point_d + 1] * distance_to_a_y * distance_to_a_x);
dst_buf[pixel_point + 2] =
(uint8_t) (src_buf[original_point_a + 2] * (1 - distance_to_a_x) * (1 - distance_to_a_y) +
相关资源
- C++从YUV420序列中获得指定一帧数据(
- yuv播放器cif格式c语言
- c++读写BMP JPG 和png 的图像文件linux
- YUV420帧转Bitmap
- YUV色彩空间的白平衡
- yuv422与yuv420互转
- bmp 图片转YUV420数组
- YUV播放器directXVS2008 MFC完成
- c语言 根据坐标 截取yuv420p 区域 保存
- rgb24转yuv420高效率 完整代码,C++实现
- libpng.lib
- YUV数据转换成opencv的Mat的RGB<
- 通过封装的opencv函数进行yuv.nv12到jp
- MFC图片操作(PRO5_PNGDlg.cpp)
- yuv编解码(2x2 YUV图像拼接)
- PNG Encrpyt加密和解密开发里的源码
-
c++ YUVpla
yer - 提取应用程序ICON图标(得到exe图标并
- gdi+绘制png透明按钮
- MFC GDI+ 用png图片做的异形窗口,渐显
- 基于S3C6410+CMOS摄像头的H264图像压缩
- 快速的将YUV444转成YUV420格式数据
评论
共有 条评论