#include <iostream>
#include <cstdio>
#include <fstream>
using namespace std;
const char* inCIF = "miss.cif";
const char* outQCIF = "miss.qcif";
int main()
{
ifstream in(inCIF, ios::binary);
ofstream out(outQCIF, ios::binary);
if (!(in.is_open() & in.is_open()))
{
cout << "open failed." << endl;
exit(1);
}
int height = 288, width = 352;
int newHeight = 144, newWidth = 176;
unsigned char* yBuffer, * uBuffer, * vBuffer;
unsigned char* newYBuffer, * newUBuffer, * newVBuffer;
yBuffer = new unsigned char[height * width];
for (auto i : { &uBuffer, &vBuffer })
*i = new unsigned char[height * width / 4];
newYBuffer = new unsigned char[newWidth * newHeight];
for( auto i : {&newUBuffer, &newVBuffer})
*i = new unsigned char[newHeight * newWidth / 4];
while( !in.eof() )
{
bool flag = 0;
if (!in.read((char*)yBuffer, width * height))
break;
for (auto i : { &uBuffer, &vBuffer })
if (!in.read((char*)(*i), height * width / 4))
{
break; flag = 1;
}
int pos = 0;
for (int i = 0; i < width * height; ++i)
{
int h = i / width, w = i % width;
if ((h & 1) || (w & 1)) continue;
newYBuffer[pos++] = yBuffer[i];
}
pos = 0;
for (int i = 0; i < width * height / 4; ++i)
{
int h = i * 2/ width, w = i % ( width / 2);
if ((h & 1) || (w & 1)) continue;
newUBuffer[pos] = uBuffer[i];
newVBuffer[pos++] = vBuffer[i];
}
if (flag) break;
out.write((char*)newYBuffer, newWidth * newHeight);
for (auto& i : { &newUBuffer, &newVBuffer })
out.write((char*)(*i), newWidth * newHeight / 4 );
}
in.close(); out.close();
for (auto& i : { &yBuffer, &uBuffer, &vBuffer, &newYBuffer, &newUBuffer, &newVBuffer })
delete[] * i;
}
CIF文件转换为QCIF
最新推荐文章于 2025-04-17 15:22:29 发布