dslinux/user/pixil/packages/dvdview/dvdview/libvideogfx/libvideogfx/graphics/fileio Makefile.am Makefile.in 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:41 CEST 2006


Update of /cvsroot/dslinux/dslinux/user/pixil/packages/dvdview/dvdview/libvideogfx/libvideogfx/graphics/fileio
In directory antilope:/tmp/cvs-serv11916/packages/dvdview/dvdview/libvideogfx/libvideogfx/graphics/fileio

Added Files:
	Makefile.am Makefile.in 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: 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: Makefile.in ---
# Makefile.in generated automatically by automake 1.4 from Makefile.am

# Copyright (C) 1994, 1995-8, 1999 Free Software Foundation, Inc.
# This Makefile.in is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
# PARTICULAR PURPOSE.


SHELL = @SHELL@

srcdir = @srcdir@
top_srcdir = @top_srcdir@
VPATH = @srcdir@
prefix = @prefix@
exec_prefix = @exec_prefix@

bindir = @bindir@
sbindir = @sbindir@
libexecdir = @libexecdir@
datadir = @datadir@
sysconfdir = @sysconfdir@
sharedstatedir = @sharedstatedir@
localstatedir = @localstatedir@
libdir = @libdir@
infodir = @infodir@
mandir = @mandir@
includedir = @includedir@
oldincludedir = /usr/include

DESTDIR =

pkgdatadir = $(datadir)/@PACKAGE@
pkglibdir = $(libdir)/@PACKAGE@
pkgincludedir = $(includedir)/@PACKAGE@

top_builddir = ../../..

ACLOCAL = @ACLOCAL@
AUTOCONF = @AUTOCONF@
AUTOMAKE = @AUTOMAKE@
AUTOHEADER = @AUTOHEADER@

INSTALL = @INSTALL@
INSTALL_PROGRAM = @INSTALL_PROGRAM@ $(AM_INSTALL_PROGRAM_FLAGS)
INSTALL_DATA = @INSTALL_DATA@
INSTALL_SCRIPT = @INSTALL_SCRIPT@
transform = @program_transform_name@

NORMAL_INSTALL = :
PRE_INSTALL = :
POST_INSTALL = :
NORMAL_UNINSTALL = :
PRE_UNINSTALL = :
POST_UNINSTALL = :
build_alias = @build_alias@
build_triplet = @build@
host_alias = @host_alias@
host_triplet = @host@
target_alias = @target_alias@
target_triplet = @target@
AS = @AS@
CC = @CC@
CXX = @CXX@
DLLTOOL = @DLLTOOL@
LIBTOOL = @LIBTOOL@
LIBVIDEOGFX_BINARY_AGE = @LIBVIDEOGFX_BINARY_AGE@
LIBVIDEOGFX_INTERFACE_AGE = @LIBVIDEOGFX_INTERFACE_AGE@
LIBVIDEOGFX_MAJOR_VERSION = @LIBVIDEOGFX_MAJOR_VERSION@
LIBVIDEOGFX_MICRO_VERSION = @LIBVIDEOGFX_MICRO_VERSION@
LIBVIDEOGFX_MINOR_VERSION = @LIBVIDEOGFX_MINOR_VERSION@
LIBVIDEOGFX_VERSION = @LIBVIDEOGFX_VERSION@
LN_S = @LN_S@
LT_AGE = @LT_AGE@
LT_CURRENT = @LT_CURRENT@
LT_RELEASE = @LT_RELEASE@
LT_REVISION = @LT_REVISION@
MAINT = @MAINT@
MAKEINFO = @MAKEINFO@
OBJDUMP = @OBJDUMP@
PACKAGE = @PACKAGE@
RANLIB = @RANLIB@
VERSION = @VERSION@
X_LDFLAGS = @X_LDFLAGS@

libvideogfx_graphics_fileio_includedir =  	$(includedir)/libvideogfx/graphics/fileio

@LINUX_TRUE at noinst_LTLIBRARIES = 	libvideogfx-graphics-fileio.la			libvideogfx-graphics-fileio-linux.la
@LINUX_FALSE at noinst_LTLIBRARIES = 	libvideogfx-graphics-fileio.la

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


@LINUX_TRUE at libvideogfx_graphics_fileio_linux_la_SOURCES = 	v4l_grab.cc		v4l_grab.hh

INCLUDES =  	-I$(top_srcdir)

mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs
CONFIG_HEADER = ../../../config.h
CONFIG_CLEAN_FILES = 
LTLIBRARIES =  $(noinst_LTLIBRARIES)


DEFS = @DEFS@ -I. -I$(srcdir) -I../../..
CPPFLAGS = @CPPFLAGS@
LDFLAGS = @LDFLAGS@
LIBS = @LIBS@
X_CFLAGS = @X_CFLAGS@
X_LIBS = @X_LIBS@
X_EXTRA_LIBS = @X_EXTRA_LIBS@
X_PRE_LIBS = @X_PRE_LIBS@
libvideogfx_graphics_fileio_la_LDFLAGS = 
libvideogfx_graphics_fileio_la_LIBADD = 
libvideogfx_graphics_fileio_la_OBJECTS =  read_yuv.lo rw_ppm.lo \
rw_uyvy.lo write_yuv.lo
libvideogfx_graphics_fileio_linux_la_LDFLAGS = 
libvideogfx_graphics_fileio_linux_la_LIBADD = 
@LINUX_TRUE at libvideogfx_graphics_fileio_linux_la_OBJECTS =  v4l_grab.lo
libvideogfx_graphics_fileio_la_DEPENDENCIES = 
CXXFLAGS = @CXXFLAGS@
CXXCOMPILE = $(CXX) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS)
LTCXXCOMPILE = $(LIBTOOL) --mode=compile $(CXX) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS)
CXXLD = $(CXX)
CXXLINK = $(LIBTOOL) --mode=link $(CXXLD) $(AM_CXXFLAGS) $(CXXFLAGS) $(LDFLAGS) -o $@
CFLAGS = @CFLAGS@
COMPILE = $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
LTCOMPILE = $(LIBTOOL) --mode=compile $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
CCLD = $(CC)
LINK = $(LIBTOOL) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(LDFLAGS) -o $@
HEADERS =  $(libvideogfx_graphics_fileio_include_HEADERS)

DIST_COMMON =  Makefile.am Makefile.in


DISTFILES = $(DIST_COMMON) $(SOURCES) $(HEADERS) $(TEXINFOS) $(EXTRA_DIST)

TAR = gtar
GZIP_ENV = --best
DEP_FILES =  .deps/read_yuv.P .deps/rw_ppm.P .deps/rw_uyvy.P \
.deps/v4l_grab.P .deps/write_yuv.P
SOURCES = $(libvideogfx_graphics_fileio_la_SOURCES) $(libvideogfx_graphics_fileio_linux_la_SOURCES)
OBJECTS = $(libvideogfx_graphics_fileio_la_OBJECTS) $(libvideogfx_graphics_fileio_linux_la_OBJECTS)

all: all-redirect
.SUFFIXES:
.SUFFIXES: .S .c .cc .lo .o .s
$(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ Makefile.am $(top_srcdir)/configure.in $(ACLOCAL_M4) 
	cd $(top_srcdir) && $(AUTOMAKE) --gnu libvideogfx/graphics/fileio/Makefile

Makefile: $(srcdir)/Makefile.in  $(top_builddir)/config.status $(BUILT_SOURCES)
	cd $(top_builddir) \
	  && CONFIG_FILES=$(subdir)/$@ CONFIG_HEADERS= $(SHELL) ./config.status


mostlyclean-noinstLTLIBRARIES:

clean-noinstLTLIBRARIES:
	-test -z "$(noinst_LTLIBRARIES)" || rm -f $(noinst_LTLIBRARIES)

distclean-noinstLTLIBRARIES:

maintainer-clean-noinstLTLIBRARIES:

.s.o:
	$(COMPILE) -c $<

.S.o:
	$(COMPILE) -c $<

mostlyclean-compile:
	-rm -f *.o core *.core

clean-compile:

distclean-compile:
	-rm -f *.tab.c

maintainer-clean-compile:

.s.lo:
	$(LIBTOOL) --mode=compile $(COMPILE) -c $<

.S.lo:
	$(LIBTOOL) --mode=compile $(COMPILE) -c $<

mostlyclean-libtool:
	-rm -f *.lo

clean-libtool:
	-rm -rf .libs _libs

distclean-libtool:

maintainer-clean-libtool:

libvideogfx-graphics-fileio.la: $(libvideogfx_graphics_fileio_la_OBJECTS) $(libvideogfx_graphics_fileio_la_DEPENDENCIES)
	$(CXXLINK)  $(libvideogfx_graphics_fileio_la_LDFLAGS) $(libvideogfx_graphics_fileio_la_OBJECTS) $(libvideogfx_graphics_fileio_la_LIBADD) $(LIBS)

libvideogfx-graphics-fileio-linux.la: $(libvideogfx_graphics_fileio_linux_la_OBJECTS) $(libvideogfx_graphics_fileio_linux_la_DEPENDENCIES)
	$(CXXLINK)  $(libvideogfx_graphics_fileio_linux_la_LDFLAGS) $(libvideogfx_graphics_fileio_linux_la_OBJECTS) $(libvideogfx_graphics_fileio_linux_la_LIBADD) $(LIBS)

libvideogfx-graphics-fileio.la: $(libvideogfx_graphics_fileio_la_OBJECTS) $(libvideogfx_graphics_fileio_la_DEPENDENCIES)
	$(LINK)  $(libvideogfx_graphics_fileio_la_LDFLAGS) $(libvideogfx_graphics_fileio_la_OBJECTS) $(libvideogfx_graphics_fileio_la_LIBADD) $(LIBS)
.cc.o:
	$(CXXCOMPILE) -c $<
.cc.lo:
	$(LTCXXCOMPILE) -c $<

install-libvideogfx_graphics_fileio_includeHEADERS: $(libvideogfx_graphics_fileio_include_HEADERS)
	@$(NORMAL_INSTALL)
	$(mkinstalldirs) $(DESTDIR)$(libvideogfx_graphics_fileio_includedir)
	@list='$(libvideogfx_graphics_fileio_include_HEADERS)'; for p in $$list; do \
	  if test -f "$$p"; then d= ; else d="$(srcdir)/"; fi; \
	  echo " $(INSTALL_DATA) $$d$$p $(DESTDIR)$(libvideogfx_graphics_fileio_includedir)/$$p"; \
	  $(INSTALL_DATA) $$d$$p $(DESTDIR)$(libvideogfx_graphics_fileio_includedir)/$$p; \
	done

uninstall-libvideogfx_graphics_fileio_includeHEADERS:
	@$(NORMAL_UNINSTALL)
	list='$(libvideogfx_graphics_fileio_include_HEADERS)'; for p in $$list; do \
	  rm -f $(DESTDIR)$(libvideogfx_graphics_fileio_includedir)/$$p; \
	done

tags: TAGS

ID: $(HEADERS) $(SOURCES) $(LISP)
	list='$(SOURCES) $(HEADERS)'; \
	unique=`for i in $$list; do echo $$i; done | \
	  awk '    { files[$$0] = 1; } \
	       END { for (i in files) print i; }'`; \
	here=`pwd` && cd $(srcdir) \
	  && mkid -f$$here/ID $$unique $(LISP)

TAGS:  $(HEADERS) $(SOURCES)  $(TAGS_DEPENDENCIES) $(LISP)
	tags=; \
	here=`pwd`; \
	list='$(SOURCES) $(HEADERS)'; \
	unique=`for i in $$list; do echo $$i; done | \
	  awk '    { files[$$0] = 1; } \
	       END { for (i in files) print i; }'`; \
	test -z "$(ETAGS_ARGS)$$unique$(LISP)$$tags" \
	  || (cd $(srcdir) && etags $(ETAGS_ARGS) $$tags  $$unique $(LISP) -o $$here/TAGS)

mostlyclean-tags:

clean-tags:

distclean-tags:
	-rm -f TAGS ID

maintainer-clean-tags:

distdir = $(top_builddir)/$(PACKAGE)-$(VERSION)/$(subdir)

subdir = libvideogfx/graphics/fileio

distdir: $(DISTFILES)
	here=`cd $(top_builddir) && pwd`; \
	top_distdir=`cd $(top_distdir) && pwd`; \
	distdir=`cd $(distdir) && pwd`; \
	cd $(top_srcdir) \
	  && $(AUTOMAKE) --include-deps --build-dir=$$here --srcdir-name=$(top_srcdir) --output-dir=$$top_distdir --gnu libvideogfx/graphics/fileio/Makefile
	@for file in $(DISTFILES); do \
	  d=$(srcdir); \
	  if test -d $$d/$$file; then \
	    cp -pr $$d/$$file $(distdir)/$$file; \
	  else \
	    test -f $(distdir)/$$file \
	    || ln $$d/$$file $(distdir)/$$file 2> /dev/null \
	    || cp -p $$d/$$file $(distdir)/$$file || :; \
	  fi; \
	done

DEPS_MAGIC := $(shell mkdir .deps > /dev/null 2>&1 || :)

-include $(DEP_FILES)

mostlyclean-depend:

clean-depend:

distclean-depend:
	-rm -rf .deps

maintainer-clean-depend:

%.o: %.c
	@echo '$(COMPILE) -c $<'; \
	$(COMPILE) -Wp,-MD,.deps/$(*F).pp -c $<
	@-cp .deps/$(*F).pp .deps/$(*F).P; \
	tr ' ' '\012' < .deps/$(*F).pp \
	  | sed -e 's/^\\$$//' -e '/^$$/ d' -e '/:$$/ d' -e 's/$$/ :/' \
	    >> .deps/$(*F).P; \
	rm .deps/$(*F).pp

%.lo: %.c
	@echo '$(LTCOMPILE) -c $<'; \
	$(LTCOMPILE) -Wp,-MD,.deps/$(*F).pp -c $<
	@-sed -e 's/^\([^:]*\)\.o[ 	]*:/\1.lo \1.o :/' \
	  < .deps/$(*F).pp > .deps/$(*F).P; \
	tr ' ' '\012' < .deps/$(*F).pp \
	  | sed -e 's/^\\$$//' -e '/^$$/ d' -e '/:$$/ d' -e 's/$$/ :/' \
	    >> .deps/$(*F).P; \
	rm -f .deps/$(*F).pp

%.o: %.cc
	@echo '$(CXXCOMPILE) -c $<'; \
	$(CXXCOMPILE) -Wp,-MD,.deps/$(*F).pp -c $<
	@-cp .deps/$(*F).pp .deps/$(*F).P; \
	tr ' ' '\012' < .deps/$(*F).pp \
	  | sed -e 's/^\\$$//' -e '/^$$/ d' -e '/:$$/ d' -e 's/$$/ :/' \
	    >> .deps/$(*F).P; \
	rm .deps/$(*F).pp

%.lo: %.cc
	@echo '$(LTCXXCOMPILE) -c $<'; \
	$(LTCXXCOMPILE) -Wp,-MD,.deps/$(*F).pp -c $<
	@-sed -e 's/^\([^:]*\)\.o[ 	]*:/\1.lo \1.o :/' \
	  < .deps/$(*F).pp > .deps/$(*F).P; \
	tr ' ' '\012' < .deps/$(*F).pp \
	  | sed -e 's/^\\$$//' -e '/^$$/ d' -e '/:$$/ d' -e 's/$$/ :/' \
	    >> .deps/$(*F).P; \
	rm -f .deps/$(*F).pp
info-am:
info: info-am
dvi-am:
dvi: dvi-am
check-am: all-am
check: check-am
installcheck-am:
installcheck: installcheck-am
install-exec-am:
install-exec: install-exec-am

install-data-am: install-libvideogfx_graphics_fileio_includeHEADERS
install-data: install-data-am

install-am: all-am
	@$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am
install: install-am
uninstall-am: uninstall-libvideogfx_graphics_fileio_includeHEADERS
uninstall: uninstall-am
all-am: Makefile $(LTLIBRARIES) $(HEADERS)
all-redirect: all-am
install-strip:
	$(MAKE) $(AM_MAKEFLAGS) AM_INSTALL_PROGRAM_FLAGS=-s install
installdirs:
	$(mkinstalldirs)  $(DESTDIR)$(libvideogfx_graphics_fileio_includedir)


mostlyclean-generic:

clean-generic:

distclean-generic:
	-rm -f Makefile $(CONFIG_CLEAN_FILES)
	-rm -f config.cache config.log stamp-h stamp-h[0-9]*

maintainer-clean-generic:
mostlyclean-am:  mostlyclean-noinstLTLIBRARIES mostlyclean-compile \
		mostlyclean-libtool mostlyclean-tags mostlyclean-depend \
		mostlyclean-generic

mostlyclean: mostlyclean-am

clean-am:  clean-noinstLTLIBRARIES clean-compile clean-libtool \
		clean-tags clean-depend clean-generic mostlyclean-am

clean: clean-am

distclean-am:  distclean-noinstLTLIBRARIES distclean-compile \
		distclean-libtool distclean-tags distclean-depend \
		distclean-generic clean-am
	-rm -f libtool

distclean: distclean-am

maintainer-clean-am:  maintainer-clean-noinstLTLIBRARIES \
		maintainer-clean-compile maintainer-clean-libtool \
		maintainer-clean-tags maintainer-clean-depend \
		maintainer-clean-generic distclean-am
	@echo "This command is intended for maintainers to use;"
	@echo "it deletes files that may require special tools to rebuild."

maintainer-clean: maintainer-clean-am

.PHONY: mostlyclean-noinstLTLIBRARIES distclean-noinstLTLIBRARIES \
clean-noinstLTLIBRARIES maintainer-clean-noinstLTLIBRARIES \
mostlyclean-compile distclean-compile clean-compile \
maintainer-clean-compile mostlyclean-libtool distclean-libtool \
clean-libtool maintainer-clean-libtool \
uninstall-libvideogfx_graphics_fileio_includeHEADERS \
install-libvideogfx_graphics_fileio_includeHEADERS tags \
mostlyclean-tags distclean-tags clean-tags maintainer-clean-tags \
distdir mostlyclean-depend distclean-depend clean-depend \
maintainer-clean-depend info-am info dvi-am dvi check check-am \
installcheck-am installcheck install-exec-am install-exec \
install-data-am install-data install-am install uninstall-am uninstall \
all-redirect all-am all installdirs mostlyclean-generic \
distclean-generic clean-generic maintainer-clean-generic clean \
mostlyclean distclean maintainer-clean


.PHONY: files

files:
	@files=`ls $(DISTFILES) 2> /dev/null`; for p in $$files; do \
	  echo $$p; \
	done

# Tell versions [3.59,3.63) of GNU make to not export all variables.
# Otherwise a system limit (for SysV at least) may be exceeded.
.NOEXPORT:

--- 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