dslinux/user/pixil/packages/dvdview/dvdview/oldlibgfx/libvideogfx/graphics/fileio .cvsignore Makefile.am read_yuv.cc read_yuv.hh rw_ppm.cc rw_ppm.hh rw_uyvy.cc rw_uyvy.hh v4l_grab.cc v4l_grab.hh write_yuv.cc write_yuv.hh
amadeus
dslinux_amadeus at user.in-berlin.de
Tue Oct 3 13:25:52 CEST 2006
Update of /cvsroot/dslinux/dslinux/user/pixil/packages/dvdview/dvdview/oldlibgfx/libvideogfx/graphics/fileio
In directory antilope:/tmp/cvs-serv11916/packages/dvdview/dvdview/oldlibgfx/libvideogfx/graphics/fileio
Added Files:
.cvsignore Makefile.am read_yuv.cc read_yuv.hh rw_ppm.cc
rw_ppm.hh rw_uyvy.cc rw_uyvy.hh v4l_grab.cc v4l_grab.hh
write_yuv.cc write_yuv.hh
Log Message:
adding pristine copy of pixil to HEAD so I can branch from it
--- NEW FILE: v4l_grab.hh ---
/*********************************************************************
v4l_grab.hh
purpose:
Interface to Video4Linux-grabbing interfaces.
notes:
to do:
author(s):
- Dirk Farin, farin at ti.uni-mannheim.de
University Mannheim, Dept. Circuitry and Simulation
B 6,26 EG, room 0.10 / D-68131 Mannheim / Germany
modifications:
11/Jul/2000 - Dirk Farin - first implementation
*********************************************************************/
#ifndef LIBVIDEOGFX_GRAPHICS_FILEIO_V4L_GRAB_HH
#define LIBVIDEOGFX_GRAPHICS_FILEIO_V4L_GRAB_HH
#include "libvideogfx/graphics/basic/image.hh"
class V4L_Grabber
{
public:
V4L_Grabber();
~V4L_Grabber();
// initialization
void SetDevice(const char* device);
void SetAlignment(const ImageInfo_Alignment& align) { d_align=align; }
void SetBorder(int border) { d_border=border; }
void SetResolution(int w,int h);
void AskResolutin(int& w,int& h) { w = d_width; h = d_height; }
void StartGrabbing(bool greyscale);
void Grab(Image_YUV<Pixel>&);
private:
// bool d_initialized;
const char* d_device;
int d_fd;
int d_width,d_height;
bool d_greyscale;
ImageInfo_Alignment d_align;
int d_border;
struct GrabData* d_grabdata;
int d_nextbuf;
};
#endif
--- NEW FILE: .cvsignore ---
Makefile
Makefile.in
*.lo
_libs
.libs
.deps
libvideogfx-graphics-fileio.la
libvideogfx-graphics-fileio-linux.la
--- NEW FILE: write_yuv.hh ---
/*********************************************************************
fileio/writeyuv.hh
purpose:
Write an YUV image to a ostream as follows: First the complete
Y plane is written. Then the U and V components are written
either one after the other or interleaved.
If you're saving a greyscale only image you can choose between
saving dummy color information or omitting the U,V data.
The alpha mask that may be available in the image will be saved
into a separate ostream if specified.
notes:
- You may save entire YUV sequences into a single file by simply
calling WriteImage() several times.
to do:
author(s):
- Dirk Farin, farin at ti.uni-mannheim.de
University Mannheim, Dept. Circuitry and Simulation
B 6,26 EG, room 0.10 / D-68131 Mannheim / Germany
modifications:
15/Jul/99 - Dirk Farin - complete rewrite, interleaved output,
greyscale output
25/May/99 - Dirk Farin - first implementation
*********************************************************************/
#ifndef LIBVIDEOGFX_GRAPHICS_FILEIO_WRITEYUV_HH
#define LIBVIDEOGFX_GRAPHICS_FILEIO_WRITEYUV_HH
#include <fstream.h>
#include "libvideogfx/graphics/basic/image.hh"
class FileWriter_YUV1
{
public:
FileWriter_YUV1();
~FileWriter_YUV1() { }
void SetYUVStream(ostream& str) { d_yuvstr = &str; }
void SetAlphaStream(ostream& str) { d_alphastr = &str; }
void SetWriteGreyscaleAsColor(bool flag=true) { d_write_greyscale_as_color=flag; }
void WriteInterleaved(bool flag=true) { d_write_interleaved=flag; }
void WriteImage(const Image_YUV<Pixel>&);
private:
ostream* d_yuvstr;
ostream* d_alphastr;
bool d_write_greyscale_as_color;
bool d_write_interleaved;
};
#endif
--- NEW FILE: rw_ppm.cc ---
/*
* rw_ppm.cc
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "rw_ppm.hh"
Image_RGB<Pixel> ReadImage_PPM(istream& stream,Image_RGB<Pixel>* srcimg,ImageSpec* spec)
{
char buffer[100+1];
stream.getline(buffer,100);
assert(strlen(buffer)==2);
assert(buffer[0]=='P');
bool greyscale;
if (buffer[1]=='5')
greyscale=true;
else if (buffer[1]=='6')
greyscale=false;
else
{ assert(0); }
int width,height,maxval;
do
{
stream.getline(buffer,100);
} while(buffer[0] == '#');
sscanf(buffer,"%d %d",&width,&height);
do
{
stream.getline(buffer,100);
} while(buffer[0] == '#');
maxval=atoi(buffer);
assert(maxval==255);
Image_RGB<Pixel> img;
if (spec)
{
spec->width = width;
spec->height = height;
img.Create(*spec);
}
else
if (srcimg)
{
ImageParam param;
srcimg->GetParam(param);
assert(param.width == width);
assert(param.height == height);
img = *srcimg;
}
else
{
ImageSpec spec;
spec.width = width;
spec.height = height;
img.Create(spec);
}
Pixel*const* r = img.AskFrameR();
Pixel*const* g = img.AskFrameG();
Pixel*const* b = img.AskFrameB();
if (greyscale)
{
for (int y=0;y<height;y++)
{
stream.read(r[y],width);
memcpy(g[y],r[y],width);
memcpy(b[y],r[y],width);
}
}
else
{
uint8* linebuf = new uint8[width * 3];
for (int y=0;y<height;y++)
{
stream.read(linebuf,width*3);
uint8* p = linebuf;
uint8* rp = r[y];
uint8* gp = g[y];
uint8* bp = b[y];
for (int x=0;x<width;x++)
{
*rp++ = *p++;
*gp++ = *p++;
*bp++ = *p++;
}
}
delete[] linebuf;
}
return img;
}
Image_YUV<Pixel> ReadImage_PPM5(istream& stream,Image_YUV<Pixel>* srcimg,ImageSpec_YUV* spec)
{
char buffer[100+1];
stream.getline(buffer,100);
assert(strlen(buffer)==2);
assert(buffer[0]=='P');
assert(buffer[1]=='5');
int width,height,maxval;
do
{
stream.getline(buffer,100);
} while(buffer[0] == '#');
sscanf(buffer,"%d %d",&width,&height);
do
{
stream.getline(buffer,100);
} while(buffer[0] == '#');
maxval=atoi(buffer);
assert(maxval==255);
Image_YUV<Pixel> img;
if (spec)
{
spec->width = width;
spec->height = height;
spec->nocolor = true;
img.Create(*spec);
}
else
if (srcimg)
{
ImageParam_YUV param;
srcimg->GetParam(param);
assert(param.width == width);
assert(param.height == height);
assert(param.nocolor == true);
img = *srcimg;
}
else
{
ImageSpec_YUV spec;
spec.width = width;
spec.height = height;
spec.nocolor = true;
img.Create(spec);
}
Pixel*const* yy = img.AskFrameY();
for (int y=0;y<height;y++)
{
stream.read(yy[y],width);
}
return img;
}
void WriteImage_PPM6(const Image_RGB<Pixel>& img,ostream& stream)
{
ImageParam param;
img.GetParam(param);
const Pixel*const* R = img.AskFrameR_const();
const Pixel*const* G = img.AskFrameG_const();
const Pixel*const* B = img.AskFrameB_const();
// Write file
stream << "P6\n" << param.width << ' ' << param.height << "\n255\n";
uint8* linebuf = new uint8[param.width*3];
for (int y=0;y<param.height;y++)
{
uint8* p = linebuf;
for (int x=0;x<param.width;x++)
{
// This ugly code allows the compiler to schedule the
// commands to parallel pipelines.
uint8 a,b,c;
a = R[y][x];
b = G[y][x];
c = B[y][x];
*p++ = R[y][x];
*p++ = G[y][x];
*p++ = B[y][x];
}
stream.write(linebuf,param.width*3);
}
delete[] linebuf;
}
void WriteImage_PPM5(const Image_YUV<Pixel>& img,ostream& stream)
{
ImageParam param;
img.Image<Pixel>::GetParam(param);
const Pixel*const* Y = img.AskFrameY_const();
// Write file
stream << "P5\n" << param.width << ' ' << param.height << "\n255\n";
for (int y=0;y<param.height;y++)
{
stream.write(Y[y],param.width);
}
}
--- NEW FILE: Makefile.am ---
## Makefile.am for libvideogfx/libvideogfx/graphics/fileio
libvideogfx_graphics_fileio_includedir = \
$(includedir)/libvideogfx/graphics/fileio
if LINUX
noinst_LTLIBRARIES = \
libvideogfx-graphics-fileio.la \
libvideogfx-graphics-fileio-linux.la
else
noinst_LTLIBRARIES = \
libvideogfx-graphics-fileio.la
endif
libvideogfx_graphics_fileio_la_SOURCES = \
read_yuv.cc \
read_yuv.hh \
rw_ppm.cc \
rw_ppm.hh \
rw_uyvy.cc \
rw_uyvy.hh \
write_yuv.cc \
write_yuv.hh
libvideogfx_graphics_fileio_include_HEADERS = \
read_yuv.hh
if LINUX
libvideogfx_graphics_fileio_linux_la_SOURCES = \
v4l_grab.cc \
v4l_grab.hh
endif
INCLUDES = \
-I$(top_srcdir)
.PHONY: files
files:
@files=`ls $(DISTFILES) 2> /dev/null`; for p in $$files; do \
echo $$p; \
done
--- NEW FILE: rw_ppm.hh ---
/*********************************************************************
fileio/writeppm.hh
purpose:
Functions to save RGB images into PPM P6-type (24bit binary)
files and to save the luminance part of YUV images into PPM
P5-type (8bit greyscale) files.
notes:
to do:
author(s):
- Dirk Farin, farin at ti.uni-mannheim.de
University Mannheim, Dept. Circuitry and Simulation
B 6,26 EG, room 0.10 / D-68131 Mannheim / Germany
modifications:
03/Aug/1999 - Dirk Farin - new functions: ReadImage_PPM()
ReadImage_PPM5()
29/Jul/1999 - Dirk Farin - files renamed to rw_ppm.*
- added ppm loading
19/Jul/1999 - Dirk Farin - completely rewritten
29/Jun/1999 - Dirk Farin - first implementation
*********************************************************************/
#ifndef LIBVIDEOGFX_GRAPHICS_FILEIO_RWPPM_HH
#define LIBVIDEOGFX_GRAPHICS_FILEIO_RWPPM_HH
#include <fstream.h>
#include "libvideogfx/graphics/basic/image.hh"
/* Reads PPM P5 and P6 types images.
* If the 'srcimg' parameter is filled in, this image will be used for loading the file.
* It is a requirement that the image size is the same as the image file size.
* If the 'spec' parameter is filled in, a new image will be created that uses most of
* the fields set in 'spec'. But width and height will be overwritten with the values from the file.
* If none of both is specified, a completely new image without border and alignment is created.
*/
Image_RGB<Pixel> ReadImage_PPM (istream& stream,Image_RGB<Pixel>* srcimg=NULL,ImageSpec* spec=NULL);
Image_YUV<Pixel> ReadImage_PPM5(istream& stream,Image_YUV<Pixel>* srcimg=NULL,ImageSpec_YUV* spec=NULL);
/* Write RGB image tnto PPM P6-type file.
*/
void WriteImage_PPM6(const Image_RGB<Pixel>&,ostream& stream);
/* Write luminance part of YUV image into PPM P5-type file.
* NOTE: the chrominance will simply be ignored.
*/
void WriteImage_PPM5(const Image_YUV<Pixel>&,ostream& stream);
#endif
--- NEW FILE: rw_uyvy.cc ---
/*
* rw_uyvy.cc
*/
#include "rw_uyvy.hh"
bool CheckImageSize(ifstream& istr,const ImageInfo_Base& sizespec)
{
long pos = istr.tellg();
istr.seekg(0,ios::end);
long filelength = istr.tellg();
istr.seekg(pos,ios::beg);
return filelength == sizespec.width*sizespec.height*2;
}
void ReadImage_UYVY(Image_YUV<Pixel>& img,ifstream& istr,const ImageSpec_YUV& spec)
{
assert(istr.is_open());
ImageSpec_YUV myspec = spec;
myspec.chroma = Chroma422;
myspec.nocolor = false;
img.Create(myspec);
Pixel*const* yp = img.AskFrameY();
Pixel*const* up = img.AskFrameU();
Pixel*const* vp = img.AskFrameV();
uint8* linebuf = new uint8[spec.width*2];
for (int y=0;y<spec.height;y++)
{
istr.read(linebuf,spec.width*2);
uint8* lp = linebuf;
for (int x=0;x<spec.width/2;x++)
{
// This ugly piece of code helps the compiler to optimize
// this a bit further as he doesn't have to mind the pointers
// pointing to the same memory locations.
// Thus all four assignments could be performed in parallel.
uint8 a,b,c,d;
a = *lp++;
b = *lp++;
c = *lp++;
d = *lp++;
up[y][x] = a;
yp[y][2*x ] = b;
vp[y][x] = c;
yp[y][2*x+1] = d;
}
}
delete[] linebuf;
}
void WriteImage_UYVY(Image_YUV<Pixel>& img,ofstream& ostr)
{
ImageParam_YUV param;
img.GetParam(param);
assert(param.chroma == Chroma422);
assert(param.nocolor == false);
// Write file
const Pixel*const* yp = img.AskFrameY_const();
const Pixel*const* up = img.AskFrameU_const();
const Pixel*const* vp = img.AskFrameV_const();
uint8* linebuf = new uint8[param.width*2];
for (int y=0;y<param.height;y++)
{
#if 1
uint8* lp;
const uint8* p;
// luminance
lp = &linebuf[1];
p = yp[y];
for (int x=0;x<param.width;x++)
{
*lp = *p++;
lp+=2;
}
// chrominance
for (int x=0;x<param.width/2;x++)
{
// The same ugly code as in ReadImage_UYVY().
uint8 a,b;
a = up[y][x];
b = vp[y][x];
linebuf[4*x ] = a;
linebuf[4*x+2] = b;
}
#endif
ostr.write(linebuf,param.width*2);
}
delete[] linebuf;
}
--- NEW FILE: v4l_grab.cc ---
/*
* v4l_grab.cc
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
#include <sys/mman.h>
#include <fcntl.h>
#include <linux/videodev.h>
#include <string.h>
#include "v4l_grab.hh"
struct GrabData
{
unsigned char* d_map;
struct video_mbuf d_vidmbuf;
struct video_mmap d_vidmmap;
};
V4L_Grabber::V4L_Grabber()
: d_device("/dev/video"),
d_fd(-1),
d_border(0)
{
d_width = 384;
d_height = 288;
d_grabdata = new GrabData;
}
V4L_Grabber::~V4L_Grabber()
{
if (d_fd>=0)
close(d_fd);
delete d_grabdata;
}
// initialization
void V4L_Grabber::SetDevice(const char* device)
{
d_device=device;
}
void V4L_Grabber::SetResolution(int w,int h)
{
d_width = w;
d_height = h;
}
void V4L_Grabber::StartGrabbing(bool greyscale)
{
d_fd = open(d_device,O_RDWR);
if (d_fd==-1)
{ perror("open video-device: "); exit(10); }
if (-1 == ioctl(d_fd,VIDIOCGMBUF,&d_grabdata->d_vidmbuf)) {
perror("ioctl VIDIOCGMBUF");
}
d_greyscale = greyscale;
d_grabdata->d_map = (unsigned char*)mmap(0,d_grabdata->d_vidmbuf.size,
PROT_READ|PROT_WRITE,MAP_SHARED,d_fd,0);
if ((unsigned char*)-1 == d_grabdata->d_map) {
perror("mmap on video device");
}
// Grabbing starten
d_grabdata->d_vidmmap.width =d_width;
d_grabdata->d_vidmmap.height=d_height;
d_grabdata->d_vidmmap.format = (greyscale ? VIDEO_PALETTE_GREY : VIDEO_PALETTE_YUV422);
for (int i=0;i<d_grabdata->d_vidmbuf.frames;i++)
{
d_grabdata->d_vidmmap.frame =i;
if (-1 == ioctl(d_fd,VIDIOCMCAPTURE,&d_grabdata->d_vidmmap)) {
perror("ioctl VIDIOCMCAPTURE");
exit(10);
}
}
d_nextbuf=0;
}
void V4L_Grabber::Grab(Image_YUV<Pixel>& img)
{
ImageSpec_YUV spec;
spec.width = d_width;
spec.height = d_height;
spec.nocolor = (d_greyscale==true);
spec.halign = 16;
spec.chroma = Chroma420;
spec.border = d_border;
spec.ImageInfo_Alignment::operator=(d_align);
img.Create(spec);
if (-1 == ioctl(d_fd,VIDIOCSYNC,&d_nextbuf)) {
perror("ioctl VIDIOCSYNC");
exit(10);
}
if (d_greyscale)
{
Pixel*const* yp=img.AskFrameY();
unsigned char* mapptr=d_grabdata->d_map + d_grabdata->d_vidmbuf.offsets[d_nextbuf];
for (int y=0;y<d_height;y++)
{
memcpy(yp[y],mapptr,d_width);
mapptr += d_width;
}
}
else
{
Pixel*const* yp=img.AskFrameY();
Pixel*const* up=img.AskFrameU();
Pixel*const* vp=img.AskFrameV();
unsigned char* mapptr=d_grabdata->d_map + d_grabdata->d_vidmbuf.offsets[d_nextbuf];
for (int y=0;y<d_height;y++)
{
for (int x=0;x<d_width;x++)
{
yp[y ][x] = *mapptr++;
up[y>>1][x>>1] = *mapptr++;
x++;
yp[y ][x] = *mapptr++;
vp[y>>1][x>>1] = *mapptr++;
}
y++;
for (int x=0;x<d_width;x++)
{
yp[y][x] = *mapptr;
mapptr++;
mapptr++;
}
}
}
d_grabdata->d_vidmmap.frame =d_nextbuf;
if (-1 == ioctl(d_fd,VIDIOCMCAPTURE,&d_grabdata->d_vidmmap)) {
perror("ioctl VIDIOCMCAPTURE");
exit(10);
}
d_nextbuf=1-d_nextbuf;
}
--- NEW FILE: write_yuv.cc ---
/*
* write_yuv.cc
*/
#include "write_yuv.hh"
FileWriter_YUV1::FileWriter_YUV1()
: d_yuvstr(NULL),
d_alphastr(NULL),
d_write_greyscale_as_color(false),
d_write_interleaved(false)
{
}
void FileWriter_YUV1::WriteImage(const Image_YUV<Pixel>& img)
{
ImageParam_YUV param;
img.GetParam(param);
const Pixel*const* Y = img.AskFrameY_const();
const Pixel*const* U = (param.nocolor ? NULL : img.AskFrameU_const());
const Pixel*const* V = (param.nocolor ? NULL : img.AskFrameV_const());
// write Y
for (int y=0;y<param.height;y++)
d_yuvstr->write(Y[y],param.width);
// write chrominance
int cw,ch;
param.GetChromaSizes(cw,ch);
if (d_write_greyscale_as_color && param.nocolor)
{
uint8* buf;
buf = new uint8[2*cw];
for (int i=0;i<2*cw;i++)
buf[i]=128;
for (int y=0;y<ch;y++)
d_yuvstr->write(buf,2*cw);
delete[] buf;
}
else if (param.nocolor)
{
// write no color information
}
else
{
if (d_write_interleaved)
{
uint8* buf;
buf = new uint8[2*cw];
for (int y=0;y<ch;y++)
{
for (int i=0;i<cw;i++)
{
buf[2*i ] = U[y][i];
buf[2*i+1] = V[y][i];
}
d_yuvstr->write(buf,2*cw);
}
delete[] buf;
}
else
{
for (int y=0;y<ch;y++)
d_yuvstr->write(U[y],cw);
for (int y=0;y<ch;y++)
d_yuvstr->write(V[y],cw);
}
}
// alpha
if (d_alphastr && param.has_alphamask)
{
const Pixel*const* A = img.AskFrameA_const();
for (int y=0;y<param.height;y++)
d_alphastr->write(A[y],param.width);
}
}
--- NEW FILE: read_yuv.cc ---
/*
* read_yuv.cc
*/
#include "read_yuv.hh"
FileReader_YUV1::FileReader_YUV1()
: d_yuvstr(NULL), d_alphastr(NULL),
d_greyscale_input(false),
d_interleavedUV(false),
d_initialized(false)
{
}
void FileReader_YUV1::Init()
{
if (d_initialized)
return;
// Get file length to calculate number of frames in file.
assert(d_yuvstr);
d_yuvstr->seekg(0,ios::end);
long length = d_yuvstr->tellg();
d_yuvstr->seekg(0,ios::beg);
// Calculate the size of one frame.
switch (d_spec.chroma)
{
case Chroma420: d_Framesize = d_spec.width * d_spec.height *3/2; break;
case Chroma422: d_Framesize = d_spec.width * d_spec.height *2; break;
case Chroma444: d_Framesize = d_spec.width * d_spec.height *3; break;
default: assert(0); break;
}
d_nFrames = length/d_Framesize;
if (d_nFrames * d_Framesize != length)
{
cerr << "Input file has strange file size, continuing anyway.\n";
// TOOD: Put exceptionhandling here.
}
//cout << d_nFrames << " frames\n";
d_nextFrame=0;
d_initialized=true;
}
int FileReader_YUV1::AskNFrames() const
{
if (d_initialized)
return d_nFrames;
(const_cast<FileReader_YUV1*>(this))->Init();
return d_nFrames;
}
bool FileReader_YUV1::IsEOF() const
{
(const_cast<FileReader_YUV1*>(this))->Init();
return d_nextFrame >= d_nFrames;
}
void FileReader_YUV1::SkipToImage(int nr)
{
if (!d_initialized)
Init();
assert(nr>=0);
assert(nr<d_nFrames);
d_yuvstr->seekg(nr*d_Framesize,ios::beg);
if (d_alphastr) d_alphastr->seekg(nr * d_spec.width * d_spec.height , ios::beg);
d_nextFrame=nr;
}
void FileReader_YUV1::ReadImage(Image_YUV<Pixel>& img)
{
if (!d_initialized)
Init();
img.Create(d_spec);
Pixel*const* yp = img.AskFrameY();
Pixel*const* up = (d_greyscale_input ? NULL : img.AskFrameU());
Pixel*const* vp = (d_greyscale_input ? NULL : img.AskFrameV());
// Y
for (int y=0;y<d_spec.height;y++)
d_yuvstr->read(yp[y],d_spec.width);
// color
if (!d_greyscale_input)
{
int ch,cw;
d_spec.GetChromaSizes(cw,ch);
if (d_interleavedUV)
{
uint8* buf = new uint8[cw*2];
for (int y=0;y<ch;y++)
{
d_yuvstr->read(buf,cw*2);
// demangle U,V components
for (int x=0;x<cw;x++)
{
up[y][x] = buf[x*2 ];
vp[y][x] = buf[x*2+1];
}
}
delete[] buf;
}
else
{
// U
for (int y=0;y<ch;y++)
d_yuvstr->read(up[y],cw);
// V
for (int y=0;y<ch;y++)
d_yuvstr->read(vp[y],cw);
}
}
// Alpha mask
if (d_alphastr)
{
assert(!img.AskBitmap(Image<Pixel>::Bitmap_Alpha).IsEmpty());
Pixel*const* aa = img.AskFrameA();
for (int y=0;y<d_spec.height;y++)
d_alphastr->read(aa[y],d_spec.width);
}
d_nextFrame++;
}
--- NEW FILE: read_yuv.hh ---
/*********************************************************************
readyuv.hh
purpose:
Read in YUV-Files. The format of the files is as follows:
First the complete Y-plane is continuously saved. The
following U- and V-planes are either saved continuously
one after the other (U comes first) or interleaved.
That is the bytes are taken alternatingly from the U- and
V-planes. The chrominance channels may be horizontally or
vertically (or both) subsampled by a factor of two.
Additionally a separate alpha-mask file can be read in.
This mask always has full resolution.
notes:
to do:
author(s):
- Dirk Farin, farin at ti.uni-mannheim.de
University Mannheim, Dept. Circuitry and Simulation
B 6,26 EG, room 0.10 / D-68131 Mannheim / Germany
modifications:
15/Jul/99 - Dirk Farin - complete rework, greyscale input
25/May/99 - Dirk Farin - first implementation
*********************************************************************/
#ifndef LIBVIDEOGFX_GRAPHICS_FILEIO_READYUV_HH
#define LIBVIDEOGFX_GRAPHICS_FILEIO_READYUV_HH
#include <fstream.h>
#include "libvideogfx/graphics/basic/image.hh"
class FileReader_YUV1
{
public:
FileReader_YUV1();
~FileReader_YUV1() { }
// initialization
void SetYUVStream (istream& yuvstream) { d_yuvstr = &yuvstream; d_initialized=false; }
void SetAlphaStream(istream& alphastream) { d_alphastr = &alphastream; d_initialized=false; }
void SetImageSpec(const ImageSpec_YUV& spec) { d_spec = spec; d_initialized=false; }
void SetInterleavedUV(bool flag=true) { d_interleavedUV = flag; d_initialized=false; }
void SetInputIsGreyscale(bool flag=true) { d_greyscale_input = flag; d_initialized=false; }
// usage
int AskNFrames() const;
bool IsEOF() const;
void SkipToImage(int nr);
void ReadImage(Image_YUV<Pixel>&);
private:
istream* d_yuvstr;
istream* d_alphastr;
ImageSpec_YUV d_spec;
bool d_interleavedUV;
bool d_greyscale_input;
int d_nFrames;
int d_Framesize;
int d_nextFrame;
void Init();
bool d_initialized;
};
#endif
--- NEW FILE: rw_uyvy.hh ---
/*********************************************************************
fileio/rw_uyvy.hh
purpose:
Functions for loading and saving of UYVY files of any size.
The image to write the image into will be created by
ReadImage_UYVY() according to the specification given in
the spec-argument. The chroma and nocolors fields need not
be set. But note that the size of the saved image must be
equal to the values in 'spec'.
notes:
to do:
author(s):
- Dirk Farin, farin at ti.uni-mannheim.de
University Mannheim, Dept. Circuitry and Simulation
B 6,26 EG, room 0.10 / D-68131 Mannheim / Germany
modifications:
15/Jul/1999 - Dirk Farin - completely rewritten
18/Jun/9999 - Dirk Farin - first implementation
*********************************************************************/
#ifndef LIBVIDEOGFX_GRAPHICS_FILEIO_RW_UYVY_HH
#define LIBVIDEOGFX_GRAPHICS_FILEIO_RW_UYVY_HH
#include <fstream.h>
#include "libvideogfx/graphics/basic/image.hh"
// Return true if the image file size matches the size specified in sizespec.
bool CheckImageSize (ifstream& istr,const ImageInfo_Base& sizespec);
void ReadImage_UYVY (Image_YUV<Pixel>&,ifstream& istr,const ImageSpec_YUV& spec);
void WriteImage_UYVY(Image_YUV<Pixel>&,ofstream& ostr);
#endif
More information about the dslinux-commit
mailing list