資料壓縮實驗報告2 TGA轉YUV

2021-10-23 05:12:22 字數 4566 閱讀 9549

寫在前面:

由於大二上學習c++時沒有進行充分的練習,這次的實驗先是自己想了很久但是無果,最後只能參考同學的**。看不懂的地方和同學討論並逐漸理解。感覺自己的情況就是知道大概的思路方法,但是不知道如何用**實現。在沒有參考的前提下沒法自己寫出完整的**,還是需要多思考多練習。

**:pga_struct.h(用來建立pga檔案的結構體)

#pragma once

#include

#include

#include

using

namespace std;

//tga檔案結構體

typedef

struct tgaheader

tgahead;

typedef

struct tgaheader_color

tgahead_color;

typedef

struct tgaheader_info

tgaheader_info;

void

read_rgb

(ifstream& file,

unsigned

char

* r_buffer,

unsigned

char

* g_buffer,

unsigned

char

* b_buffer,

int h1,

int w1)

;void

read_rgb_colormap

(ifstream& file, tgahead_color& color,

unsigned

char

* r_buffer,

unsigned

char

* g_buffer,

unsigned

char

* b_buffer,

int h1,

int w1)

;

rgb2yuv.h(定義rgb2yuv.cpp中所需要的函式)

#pragma once

#include

#include

#include

#include

using

namespace std;

extern

float rgb2yuv02990[

256]

, rgb2yuv05870[

256]

, rgb2yuv01140[

256]

, rgb2yuv01684[

256]

,rgb2yuv03316[

256]

, rgb2yuv05000[

256]

, rgb2yuv04187[

256]

, rgb2yuv00813[

256]

;void

table()

;void

process

(int h1,

int w1,

unsigned

char

* r,

unsigned

char

* g,

unsigned

char

* b,

unsigned

char

* y,

unsigned

char

* u,

unsigned

char

* v)

;void

subsample

(int h2,

int w2,

unsigned

char

* u,

unsigned

char

* v,

unsigned

char

* u2,

unsigned

char

* v2)

;void

write

(int h2,

int w2,

unsigned

char

* y,

unsigned

char

* u,

unsigned

char

* v)

;

tga.cpp(主要包含讀取rgb資料和顏色表的函式)

#include

"tga_struct.h"

void

read_rgb

(ifstream& file,

unsigned

char

* r_buffer,

unsigned

char

* g_buffer,

unsigned

char

* b_buffer,

int h1,

int w1)}}

void

read_rgb_colormap

(ifstream& file, tgahead_color& color,

unsigned

char

* r_buffer,

unsigned

char

* g_buffer,

unsigned

char

* b_buffer,

int h1,

int w1)

for(

int i = h1 -

1; i >=

0; i--)}

if(table_r !=

null

)delete table_r;

if(table_g !=

null

)delete table_g;

if(table_b !=

null

)delete table_b;

if(k !=

null

)delete k;

}

rgb2yuv.cpp(將rgb分量轉換為yuv分量、下取樣、寫檔案的函式)

#include

"rgb2yuv.h"

void

table()

}// 計算yuv分量的值

void

process

(int h1,

int w1,

unsigned

char

* r,

unsigned

char

* g,

unsigned

char

* b,

unsigned

char

* y,

unsigned

char

* u,

unsigned

char

* v)

}//寫yuv檔案

void

write

(int h2,

int w2,

unsigned

char

* y,

unsigned

char

* u,

unsigned

char

* v)

}// uv分量下取樣

void

subsample

(int h2,

int w2,

unsigned

char

* u,

unsigned

char

* v,

unsigned

char

* u2,

unsigned

char

* v2)

}

task2.cpp(主函式)

#include

"rgb2yuv.h"

#include

"tga_struct.h"

float rgb2yuv02990[

256]

, rgb2yuv05870[

256]

, rgb2yuv01140[

256]

, rgb2yuv01684[

256]

,rgb2yuv03316[

256]

, rgb2yuv05000[

256]

, rgb2yuv04187[

256]

, rgb2yuv00813[

256]

;int

main

(int argc,

char

* ar**)

執行結果:

資料壓縮實驗報告2 bmp轉yuv

1 bmp檔案格式 bmp bitmap 是windows作業系統中的標準影象檔案格式,可分為裝置相關位圖 ddb 和裝置無關位圖 dib 使用十分廣泛。它採用位對映存貯格式,除了影象深度可選外,絕大多數無壓縮,因此所佔空間很大。bmp檔案的影象深度可選1bit,4bit,8bit,16bit及24...

資料壓縮實驗 TGA檔案轉YUV檔案

實驗內容 將tga影象檔案轉化為yuv檔案 tga檔案頭有5個字段,共18個位元組 typedef struct tgafileheader tgafileheader tgaheader tga file.read char tgaheader,sizeof tgafileheader int p...

資料壓縮實驗一 yuv轉rgb格式實驗報告

一 實驗基本原理 yuv轉 rgb格式轉換公式 r y 1.4020 v 128 g y 0.3441 u 128 0.7141 v 128 b y 1.7720 u 128 分析 由rgb到 yuv格式的轉換公式 y 0.2990r 0.5870g 0.1140b r y 0.7010r 0.58...