/*****************************************************************************
FileName: <yuvconverter.cpp>
File Description:
Convert any YUV format to another
*****************************************************************************/
#include <iostream.h>
#include <fstream.h>
#include <stdio.h>
#include <process.h>
#include <stdlib.h>
#include "yuvconverter.h"
unsigned char bufinframe[MAXWIDTH*MAXHEIGHT*3];
unsigned char bufoutframe[MAXWIDTH*MAXHEIGHT*3];
/*****************************************************************************
Module Name: <main>
Module Description:
Wrapper main to convert any YUV format to another
*****************************************************************************/
int main(int argc, char **argv)
{
ifstream infile;
ofstream outfile;
char *infile_name, *outfile_name;
int width, height, inframesize, outframesize;
unsigned char *ptrbufinframe, *ptrbufoutframe;
int conv_code;
void (*yuvconvert) (unsigned char*, unsigned char *, int, int);
if (argc < NUMARGS){
printf("\n");
printf("\n +------------------------------------------------------------+");
printf("\n | Usage: <infile> <outfile> <width> <height> <conv_code> |");
printf("\n +------------------------------------------------------------+");
printf("\n | Input Format | Output Format | ConvCode |");
printf("\n +------------------------------------------------------------+");
printf("\n | YUV420 Prog Planar | YUV420 Int Planar | 110111 |");
printf("\n | YUV420 Prog Planar | YVU420 Prog Planar | 110120 |");
printf("\n | YUV420 Prog Planar | YVU420 Int Planar | 110121 |");
printf("\n +------------------------------------------------------------+");
printf("\n | YUV420 Prog Planar | YUV422 Prog Planar | 110210 |");
printf("\n | YUV420 Prog Planar | YUV422 Int Planar | 110211 |");
printf("\n | YUV420 Prog Planar | YVU422 Prog Planar | 110220 |");
printf("\n | YUV420 Prog Planar | YVU422 Int Planar | 110221 |");
printf("\n +------------------------------------------------------------+");
printf("\n | YUV420 Prog Planar | UYVY Prog | 110230 |");
printf("\n | YUV420 Prog Planar | UYVY Int | 110231 |");
printf("\n | YUV420 Prog Planar | YUYV Prog | 110240 |");
printf("\n | YUV420 Prog Planar | YUYV Int | 110241 |");
printf("\n | YUV420 Prog Planar | YVYU Prog | 110250 |");
printf("\n | YUV420 Prog Planar | YVYU Int | 110251 |");
printf("\n +------------------------------------------------------------+");
printf("\n | YUV420 Prog Planar | YUV444 Prog Planar | 110310 |");
printf("\n | YUV420 Prog Planar | YUV444 Int Planar | 110311 |");
printf("\n | YUV420 Prog Planar | YVU444 Prog Planar | 110320 |");
printf("\n | YUV420 Prog Planar | YVU444 Int Planar | 110321 |");
printf("\n | YUV420 Prog Planar | UYV444 Prog Planar | 110330 |");
printf("\n | YUV420 Prog Planar | UYV444 Int Planar | 110331 |");
printf("\n +------------------------------------------------------------+");
printf("\n | YUV420 Prog Planar | YUV444 Prog Packed | 110340 |");
printf("\n | YUV420 Prog Planar | YUV444 Int Packed | 110341 |");
printf("\n | YUV420 Prog Planar | YVU444 Prog Packed | 110350 |");
printf("\n | YUV420 Prog Planar | YVU444 Int Packed | 110351 |");
printf("\n | YUV420 Prog Planar | UYV444 Prog Packed | 110360 |");
printf("\n | YUV420 Prog Planar | UYV444 Int Packed | 110361 |");
printf("\n +------------------------------------------------------------+");
printf("\n | YUV420 Prog Planar | RGB Prog Planar | 110410 |");
printf("\n | YUV420 Prog Planar | BGR Prog Planar | 110420 |");
printf("\n | YUV420 Prog Planar | RGB Prog Packed | 110430 |");
printf("\n | YUV420 Prog Planar | BGR Prog Packed | 110440 |");
printf("\n +------------------------------------------------------------+");
printf("\n | |");
printf("\n +------------------------------------------------------------+");
printf("\n | YUV420 Int Planar | YUV420 Prog Planar | 111110 |");
printf("\n | YVU420 Prog Planar | YUV420 Prog Planar | 120110 |");
printf("\n | YVU420 Int Planar | YUV420 Prog Planar | 121110 |");
printf("\n +------------------------------------------------------------+");
printf("\n | YUV422 Prog Planar | YUV420 Prog Planar | 210110 |");
printf("\n | YUV422 Int Planar | YUV420 Prog Planar | 211110 |");
printf("\n | YVU422 Prog Planar | YUV420 Prog Planar | 220110 |");
printf("\n | YVU422 Int Planar | YUV420 Prog Planar | 221110 |");
printf("\n +------------------------------------------------------------+");
printf("\n | UYVY Prog | YUV420 Prog Planar | 230110 |");
printf("\n | UYVY Int | YUV420 Prog Planar | 231110 |");
printf("\n | YUYV Prog | YUV420 Prog Planar | 240110 |");
printf("\n | YUYV Int | YUV420 Prog Planar | 241110 |");
printf("\n | YVYU Prog | YUV420 Prog Planar | 250110 |");
printf("\n | YVYU Int | YUV420 Prog Planar | 251110 |");
printf("\n +------------------------------------------------------------+");
printf("\n | YUV444 Prog Planar | YUV420 Prog Planar | 310110 |");
printf("\n | YUV444 Int Planar | YUV420 Prog Planar | 311110 |");
printf("\n | YVU444 Prog Planar | YUV420 Prog Planar | 320110 |");
printf("\n | YVU444 Int Planar | YUV420 Prog Planar | 321110 |");
printf("\n | UYV444 Prog Planar | YUV420 Prog Planar | 330110 |");
printf("\n | UYV444 Int Planar | YUV420 Prog Planar | 331110 |");
printf("\n +------------------------------------------------------------+");
printf("\n | YUV444 Prog Packed | YUV420 Prog Planar | 340110 |");
printf("\n | YUV444 Int Packed | YUV420 Prog Planar | 341110 |");
printf("\n | YVU444 Prog Packed | YUV420 Prog Planar | 350110 |");
printf("\n | YVU444 Int Packed | YUV420 Prog Planar | 351110 |");
printf("\n | UYV444 Prog Packed | YUV420 Prog Planar | 360110 |");
printf("\n | UYV444 Int Packed | YUV420 Prog Planar | 361110 |");
printf("\n +------------------------------------------------------------+");
printf("\n | RGB Prog Planar | YUV420 Prog Planar | 410110 |");
printf("\n | BGR Prog Planar | YUV420 Prog Planar | 420110 |");
printf("\n | RGB Prog Packed | YUV420 Prog Planar | 430110 |");
printf("\n | BGR Prog Packed | YUV420 Prog Planar | 440110 |");
printf("\n +------------------------------------------------------------+");
printf("\n");
exit (-1);
}
infile_name = argv[1];
outfile_name = argv[2];
width = atoi(argv[3]);
height = atoi(argv[4]);
conv_code = atoi(argv[5]);
infile.open(infile_name, ios::binary);
outfile.open(outfile_name, ios::binary);
if(infile == NULL)
{
cout << "\nCannot open file "<<infile_name;
cout << "\n\n";
infile.close();
return 2;
}
if(outfile == NULL)
{
cout << "\nCannot open file "<<outfile_name;
cout << "\n\n";
infile.close();
outfile.close();
return 2;
}
switch(conv_code)
{
/* YUV420 Output */
case 110111:
yuvconvert = yuv420_prog_planar_to_yuv420_int_planar;
inframesize = (width * height * 3)>>1;
outframesize = (wi