TGA格式转YUV

本文探讨了TGA格式文件的结构,指出在将TGA格式转换为YUV过程中遇到的问题,即TGA像素从左下角开始排列与实际实验中从左上角开始的不一致。这个问题源于一个通过ACDsee20将BMP另存为TGA的文件,目前此疑点还在研究中。
摘要由CSDN通过智能技术生成

TGA扩展文件结构由五部分组成:文件头、图像/颜色表数据、开发者自定义区域、扩展区域和文件尾。在这里插入图片描述
由头文件中的二三字节00 02可以看出是未压缩的真彩色图像,00 00 00 00 18说明一个像素是24位,所以与RGB的格式非常相似,借鉴了之前RGB转YUV的方法。
代码如下:

#include<stdio.h>
#include<stdlib.h>
const int width = 256;
const int height = 256;
int main(int argc,char *argv[])
{
   
    unsigned char* buffer_tga = new unsigned char[3 * width * height + 18];
    unsigned char* buffer_rgb = new unsigned char[ 3 * width * height];
    unsigned char* buffer_y = new unsigned char[width * height];
    unsigned char* buffer_u = new unsigned char[width * height / 4];
    unsigned char* buffer_v = new unsigned char[width * height / 4];
    FILE* rgb=NULL;
    FILE* yuv=NULL;
    fopen_s(&rgb,argv[1], "rb");
    if (rgb == NULL)
        printf("cannot find rgb file\n");
    fread(buffer_tga, sizeof(unsigned char), 3 * width * height+18,rgb);
    for (int i = 0; i < 3 * width * height; i++)
 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值