dslinux/user/pixil/packages/dvdview/dvdview/libvideogfx/libvideogfx/graphics/filters Makefile.am Makefile.in linear.cc linear.hh nonlin.cc nonlin.hh resize.cc resize.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/filters
In directory antilope:/tmp/cvs-serv11916/packages/dvdview/dvdview/libvideogfx/libvideogfx/graphics/filters

Added Files:
	Makefile.am Makefile.in linear.cc linear.hh nonlin.cc 
	nonlin.hh resize.cc resize.hh 
Log Message:
adding pristine copy of pixil to HEAD so I can branch from it

--- NEW FILE: nonlin.hh ---
/*********************************************************************
  libvideogfx/graphics/filters/nonlin.hh

  purpose:
    Nonlinear filters:
    - Median YUV 3x3 - only luminance information is used to choose the
                       pixel to be copied. The color information will
		       simply be copied accordingly.

  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:
    24/Aug/1999 - Dirk Farin - functions are not template functions
    21/Jul/1999 - Dirk Farin - cleanup and speed improvements of median filter
    29/Jun/1999 - Dirk Farin - first implementation of median filter
 *********************************************************************/

#ifndef LIBVIDEOGFX_GRAPHICS_FILTERS_NONLIN_HH
#define LIBVIDEOGFX_GRAPHICS_FILTERS_NONLIN_HH

#include "libvideogfx/graphics/basic/image.hh"

template <class Pel> void Median_YUV_3x3(const Image_YUV<Pel>& img,Image_YUV<Pel>& dest);

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

noinst_LTLIBRARIES = libvideogfx-graphics-filters.la

libvideogfx_graphics_filters_la_SOURCES =  	linear.cc		linear.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_filters_la_LDFLAGS = 
libvideogfx_graphics_filters_la_LIBADD = 
libvideogfx_graphics_filters_la_OBJECTS =  linear.lo
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 $@
DIST_COMMON =  Makefile.am Makefile.in


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

TAR = gtar
GZIP_ENV = --best
DEP_FILES =  .deps/linear.P
SOURCES = $(libvideogfx_graphics_filters_la_SOURCES)
OBJECTS = $(libvideogfx_graphics_filters_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/filters/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-filters.la: $(libvideogfx_graphics_filters_la_OBJECTS) $(libvideogfx_graphics_filters_la_DEPENDENCIES)
	$(CXXLINK)  $(libvideogfx_graphics_filters_la_LDFLAGS) $(libvideogfx_graphics_filters_la_OBJECTS) $(libvideogfx_graphics_filters_la_LIBADD) $(LIBS)
.cc.o:
	$(CXXCOMPILE) -c $<
.cc.lo:
	$(LTCXXCOMPILE) -c $<

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

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/filters/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-data: install-data-am

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


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 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: Makefile.am ---
## Makefile.am for libvideogfx/libvideogfx/graphics/filters

noinst_LTLIBRARIES = libvideogfx-graphics-filters.la

libvideogfx_graphics_filters_la_SOURCES = \
	linear.cc	\
	linear.hh

INCLUDES = \
	-I$(top_srcdir)

.PHONY: files

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

--- NEW FILE: linear.hh ---
/*********************************************************************
  libvideogfx/graphics/filters/linear.hh

  purpose:
    linear filters:
    - LowPass ( 0 1 0 / 1 4 1 / 0 1 0 )
    - LowPass ( 1 1 1 / 1 1 1 / 1 1 1 )

  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:
    21/Jul/1999 - Dirk Farin - first implementation
 *********************************************************************/

#ifndef LIBVIDEOGFX_GRAPHICS_FILTERS_LINEAR_HH
#define LIBVIDEOGFX_GRAPHICS_FILTERS_LINEAR_HH

#include "libvideogfx/graphics/basic/image.hh"
#include "libvideogfx/containers/array.hh"


/* Low-pass filtering is done using this kernel:

   1   /  0  1  0  \
   - * |  1  4  1  |
   8   \  0  1  0  /
*/
void LowPass_5pt(const Image_YUV<Pixel>& img,Image_YUV<Pixel>& dest);


/* Low-pass filtering is done using this kernel:

   1   /  1  1  1  \
   - * |  1  1  1  |
   9   \  1  1  1  /
*/
void LowPass_3x3mean(const Image_YUV<Pixel>& img,Image_YUV<Pixel>& dest);


template <class Pel> void ConvolveH(const Bitmap<Pel>& src,Bitmap<Pel>& dst,
				    const Array<double>& filter,bool useborder=true);
template <class Pel> void ConvolveV(const Bitmap<Pel>& src,Bitmap<Pel>& dst,
				    const Array<double>& filter,bool useborder=true);
template <class Pel> void ConvolveHV(const Bitmap<Pel>& src,Bitmap<Pel>& dst,
				     const Array<double>& filter,bool useborder=true);

void NormalizeFilter(Array<double>& filter); // Make coefficients sum up to 1.0 .


void CreateGaussFilter     (Array<double>& filter,double sigma,double cutoffval=0.01,bool normalize=true);
void CreateGaussDerivFilter(Array<double>& filter,double sigma,double cutoffval=0.01);

#endif

--- NEW FILE: linear.cc ---
/*
 *  linear.cc
 */

#include <math.h>
#include <iostream.h>

#include "linear.hh"


void LowPass_5pt(const Image_YUV<Pixel>& img,Image_YUV<Pixel>& dest)
{
  // Get image parameters and assure that they are in the right format.
  ImageParam_YUV param;
  img.GetParam(param);

  ImageParam_YUV param2;
  dest.GetParam(param2);

  assert(param.chroma ==Chroma444);
  assert(param2.chroma==Chroma444);
  assert(&img != &dest);  // Lowpass needs two image buffers for correct operation.

  // Give hint as the destination image will be completely overwritten.
  dest.Hint_ContentsIsNotUsedAnymore();


  Pixel*const* yp2  = dest.AskFrameY();
  Pixel*const* up2  = dest.AskFrameU();
  Pixel*const* vp2  = dest.AskFrameV();

  const Pixel*const* yp  = img.AskFrameY_const();
  const Pixel*const* up  = img.AskFrameU_const();
  const Pixel*const* vp  = img.AskFrameV_const();

  /* Do lowpass filtering.
     We filter all of the image except a one pixel wide border because the
     filter size is 3x3. This border will simply be copied from the original
     image.
  */
     
  int w = param.width;
  int h = param.height;

  for (int y=1;y<param.height-1;y++)
    for (int x=1;x<param.width-1;x++)
      {
	yp2[y][x] = (  yp[y-1][x  ] +
		       yp[y+1][x  ] +
		       yp[y  ][x-1] +
		       yp[y  ][x+1] +
		     4*yp[y  ][x  ]    +4)/8;
	up2[y][x] = (  up[y-1][x  ] +
 		       up[y+1][x  ] +
		       up[y  ][x-1] +
		       up[y  ][x+1] +
		     4*up[y  ][x  ]    +4)/8;
	vp2[y][x] = (  vp[y-1][x  ] +
		       vp[y+1][x  ] +
		       vp[y  ][x-1] +
		       vp[y  ][x+1] +
		     4*vp[y  ][x  ]    +4)/8;
      }

  // Copy border from old image to filtered one.

  for (int x=0;x<param.width;x++)
    {
      yp2[  0][x]=yp[  0][x]; up2[  0][x]=up[  0][x]; vp2[  0][x]=vp[  0][x];
      yp2[h-1][x]=yp[h-1][x]; up2[h-1][x]=up[h-1][x]; vp2[h-1][x]=vp[h-1][x];
    }

  for (int y=0;y<param.height;y++)
    {
      yp2[y][  0]=yp[y][  0]; up2[y][0  ]=up[y][  0]; vp2[y][  0]=vp[y][  0];
      yp2[y][w-1]=yp[y][w-1]; up2[y][w-1]=up[y][w-1]; vp2[y][w-1]=vp[y][w-1];
    }
}



void LowPass_3x3mean(const Image_YUV<Pixel>& img,Image_YUV<Pixel>& dest)
{
  // Get image parameters and assure that they are in the right format.
  ImageParam_YUV param;
  img.GetParam(param);

  ImageParam_YUV param2;
  dest.GetParam(param2);

  assert(param.chroma ==Chroma444);
  assert(param2.chroma==Chroma444);
  assert(&img != &dest);  // Lowpass needs two image buffers for correct operation.

  // Give hint as the destination image will be completely overwritten.
  dest.Hint_ContentsIsNotUsedAnymore();


  Pixel*const* yp2  = dest.AskFrameY();
  Pixel*const* up2  = dest.AskFrameU();
  Pixel*const* vp2  = dest.AskFrameV();

  const Pixel*const* yp  = img.AskFrameY_const();
  const Pixel*const* up  = img.AskFrameU_const();
  const Pixel*const* vp  = img.AskFrameV_const();

  /* Do lowpass filtering.
     We filter all of the image except a one pixel wide border because the
     filter size is 3x3. This border will simply be copied from the original
     image.
  */
     
  int w = param.width;
  int h = param.height;

  for (int y=1;y<param.height-1;y++)
    for (int x=1;x<param.width-1;x++)
      {
	yp2[y][x] = (  yp[y-1][x-1] +
		       yp[y-1][x  ] +
		       yp[y-1][x+1] +
		       yp[y  ][x-1] +
		       yp[y  ][x  ] +
		       yp[y  ][x+1] +
		       yp[y+1][x-1] +
		       yp[y+1][x  ] +
		       yp[y+1][x+1]    +4)/9;
	up2[y][x] = (  up[y-1][x-1] +
		       up[y-1][x  ] +
		       up[y-1][x+1] +
		       up[y  ][x-1] +
		       up[y  ][x  ] +
		       up[y  ][x+1] +
		       up[y+1][x-1] +
		       up[y+1][x  ] +
		       up[y+1][x+1]    +4)/9;
	vp2[y][x] = (  vp[y-1][x-1] +
		       vp[y-1][x  ] +
		       vp[y-1][x+1] +
		       vp[y  ][x-1] +
		       vp[y  ][x  ] +
		       vp[y  ][x+1] +
		       vp[y+1][x-1] +
		       vp[y+1][x  ] +
		       vp[y+1][x+1]    +4)/9;
      }

  // Copy border from old image to filtered one.

  for (int x=0;x<param.width;x++)
    {
      yp2[  0][x]=yp[  0][x]; up2[  0][x]=up[  0][x]; vp2[  0][x]=vp[  0][x];
      yp2[h-1][x]=yp[h-1][x]; up2[h-1][x]=up[h-1][x]; vp2[h-1][x]=vp[h-1][x];
    }

  for (int y=0;y<param.height;y++)
    {
      yp2[y][  0]=yp[y][  0]; up2[y][0  ]=up[y][  0]; vp2[y][  0]=vp[y][  0];
      yp2[y][w-1]=yp[y][w-1]; up2[y][w-1]=up[y][w-1]; vp2[y][w-1]=vp[y][w-1];
    }
}


template <class Pel> void ConvolveH(const Bitmap<Pel>& src,Bitmap<Pel>& dst,
				    const Array<double>& filter,bool useborder)
{
  int left = -filter.AskBase();
  int right=  filter.AskSize()-left-1;

  int border=0;
  if (useborder) border=src.AskBorderWidth();

  int xs = -border+left; if (xs<0) xs=0;
  int xe = src.AskWidth()-1+border-right; if (xe>src.AskWidth()-1) xe=src.AskWidth()-1;

  // cout << "H-Filtering from " << xs << " to " << xe << endl;

  int h = src.AskHeight();
  int borderw = src.AskBorderWidth();

  dst.Create(xe-xs+1,h,1,1,borderw);

  const double* f = filter.Data_const();

  const Pel*const* sp = src.AskFrame_const();
        Pel*const* dp = dst.AskFrame();

  for (int y=-borderw;y<h+borderw;y++)
    for (int x=xs;x<=xe;x++)
      {
	double sum=0.0;
	for (int xx=-left;xx<=right;xx++)
	  sum += f[xx]*sp[y][x+xx];
    
	dp[y][x-xs] = (Pel)sum;
      }
}


template <class Pel> void ConvolveV(const Bitmap<Pel>& src,Bitmap<Pel>& dst,
				    const Array<double>& filter,bool useborder)
{
  int top   = -filter.AskBase();
  int bottom=  filter.AskSize()-top-1;

  int border=0;
  if (useborder) border=src.AskBorderWidth();

  int ys = -border+top; if (ys<0) ys=0;
  int ye = src.AskHeight()-1+border-bottom; if (ye>src.AskHeight()-1) ye=src.AskHeight()-1;

  // cout << "V-Filtering from " << ys << " to " << ye << endl;

  int w = src.AskWidth();
  int borderw = src.AskBorderWidth();

  dst.Create(w,ye-ys+1,1,1,borderw);

  const double* f = filter.Data_const();

  const Pel*const* sp = src.AskFrame_const();
        Pel*const* dp = dst.AskFrame();

  for (int y=ys;y<=ye;y++)
    for (int x=-borderw;x<w+borderw;x++)
      {
	double sum=0.0;
	for (int yy=-top;yy<=bottom;yy++)
	  sum += f[yy]*sp[y+yy][x];
    
	dp[y-ys][x] = (Pel)sum;
      }
}


template <class Pel> void ConvolveHV(const Bitmap<Pel>& src,Bitmap<Pel>& dst,
				     const Array<double>& filter,bool useborder)
{
  Bitmap<Pel> tmpbm;
  ConvolveH(src,tmpbm,filter,useborder);
  ConvolveV(tmpbm,dst,filter,useborder);
}


void NormalizeFilter(Array<double>& filter)
{
  double sum=0.0;
  int i0 = filter.AskStartIdx();
  int i1 = filter.AskEndIdx();

  double* f = filter.Data();

  for (int i=i0;i<=i1;i++)
    sum += f[i];

  const double fact = 1.0/sum;

  for (int i=i0;i<=i1;i++)
    f[i] *= fact;
}


void CreateGaussFilter(Array<double>& filter,double sigma,double cutoffval,bool normalize)
{
#define MAXRANGE 100
  double filt[MAXRANGE];

  double minus_twosigma2inv = -1.0/(2*sigma*sigma);

  int lastidx=MAXRANGE-1;
  for (int i=0;i<MAXRANGE;i++)
    {
      filt[i] = exp(i*i*minus_twosigma2inv);

      if (filt[i] < cutoffval)
	{ lastidx = i-1; break; }
    }

  if (lastidx==MAXRANGE-1)
    throw "CreateGaussFilter(): Gauss filter is too wide.";

  filter.Create(2*lastidx+1 , -lastidx);
  double* f = filter.Data();

  for (int i=0;i<=lastidx;i++)
    f[-i]=f[i]=filt[i];

  if (normalize) NormalizeFilter(filter);
}


void CreateGaussDerivFilter(Array<double>& filter,double sigma,double cutoffval=0.01)
{
  CreateGaussFilter(filter,sigma,cutoffval,false);

  for (int i=filter.AskStartIdx();i<=filter.AskEndIdx();i++)
    filter.Data()[i] *= i;

  // normalize

  double sum=0.0;

  int i0 = filter.AskStartIdx();
  int i1 = filter.AskEndIdx();

  double* f = filter.Data();

  for (int i=i0;i<=i1;i++)
    sum += i*f[i];

  const double fact = 1.0/sum;

  for (int i=i0;i<=i1;i++)
    f[i] *= fact;
}


template class Array<double>;
template void ConvolveH (const Bitmap<Pixel>&,Bitmap<Pixel>&,const Array<double>&,bool);
template void ConvolveV (const Bitmap<Pixel>&,Bitmap<Pixel>&,const Array<double>&,bool);
template void ConvolveHV(const Bitmap<Pixel>&,Bitmap<Pixel>&,const Array<double>&,bool);

template void ConvolveH (const Bitmap<double>&,Bitmap<double>&,const Array<double>&,bool);
template void ConvolveV (const Bitmap<double>&,Bitmap<double>&,const Array<double>&,bool);
template void ConvolveHV(const Bitmap<double>&,Bitmap<double>&,const Array<double>&,bool);

#include "libvideogfx/containers/array.cc"

--- NEW FILE: resize.cc ---

#include "libvideogfx/graphics/filters/resize.hh"

void HalfSize_Subsample(const Image_YUV<Pixel>& img,Image_YUV<Pixel>& dest)
{












  // Get image parameters and assure that they are in the right format.
  ImageParam_YUV param;
  img.GetParam(param);

  ImageParam_YUV param2;
  dest.GetParam(param2);

  assert(param.chroma ==Chroma444);
  assert(param2.chroma==Chroma444);
  assert(&img != &dest);  // Lowpass needs two image buffers for correct operation.

  // Give hint as the destination image will be completely overwritten.
  dest.Hint_ContentsIsNotUsedAnymore();


  Pixel*const* yp2  = dest.AskFrameY();
  Pixel*const* up2  = dest.AskFrameU();
  Pixel*const* vp2  = dest.AskFrameV();

  const Pixel*const* yp  = img.AskFrameY_const();
  const Pixel*const* up  = img.AskFrameU_const();
  const Pixel*const* vp  = img.AskFrameV_const();

  /* Do lowpass filtering.
     We filter all of the image except a one pixel wide border because the
     filter size is 3x3. This border will simply be copied from the original
     image.
  */
     
  int w = param.width;
  int h = param.height;

  for (int y=1;y<param.height-1;y++)
    for (int x=1;x<param.width-1;x++)
      {
	yp2[y][x] = (  yp[y-1][x  ] +
		       yp[y+1][x  ] +
		       yp[y  ][x-1] +
		       yp[y  ][x+1] +
		     4*yp[y  ][x  ]    +4)/8;
	up2[y][x] = (  up[y-1][x  ] +
 		       up[y+1][x  ] +
		       up[y  ][x-1] +
		       up[y  ][x+1] +
		     4*up[y  ][x  ]    +4)/8;
	vp2[y][x] = (  vp[y-1][x  ] +
		       vp[y+1][x  ] +
		       vp[y  ][x-1] +
		       vp[y  ][x+1] +
		     4*vp[y  ][x  ]    +4)/8;
      }

  // Copy border from old image to filtered one.

  for (int x=0;x<param.width;x++)
    {
      yp2[  0][x]=yp[  0][x]; up2[  0][x]=up[  0][x]; vp2[  0][x]=vp[  0][x];
      yp2[h-1][x]=yp[h-1][x]; up2[h-1][x]=up[h-1][x]; vp2[h-1][x]=vp[h-1][x];
    }

  for (int y=0;y<param.height;y++)
    {
      yp2[y][  0]=yp[y][  0]; up2[y][0  ]=up[y][  0]; vp2[y][  0]=vp[y][  0];
      yp2[y][w-1]=yp[y][w-1]; up2[y][w-1]=up[y][w-1]; vp2[y][w-1]=vp[y][w-1];
    }
}


--- NEW FILE: nonlin.cc ---

#include "libvideogfx/graphics/filters/nonlin.hh"

struct SortData
{
  int val;
  int u,v;
};

template <class Pel> void Median_YUV_3x3(const Image_YUV<Pel>& img,Image_YUV<Pel>& dest)
{
  // Get image parameters and assure that they are in the right format.
  ImageParam_YUV param;
  img.GetParam(param);

  ImageParam_YUV param2;
  dest.GetParam(param2);

  const bool color = !(param.nocolor);

  if (color)
    {
      assert(param.chroma ==Chroma444);
      assert(param2.chroma==Chroma444);
    }
  assert(&img != &dest);  // Median needs two image buffers for correct operation.

  // Give hint as the destination image will be completely overwritten.
  dest.Hint_ContentsIsNotUsedAnymore();

  Pel*const* yp2  = dest.AskFrameY();
  Pel*const* up2  = (color ? dest.AskFrameU() : 0);
  Pel*const* vp2  = (color ? dest.AskFrameV() : 0);

  const Pel*const* yp  = img.AskFrameY_const();
  const Pel*const* up  = (color ? img.AskFrameU_const() : 0);
  const Pel*const* vp  = (color ? img.AskFrameV_const() : 0);

  SortData a[9];


  /* Do median filtering.
     We filter all of the image except a one pixel wide border because the
     filter size is 3x3. This border will simply be copied from the original
     image.
  */
     
  int w = param.width;
  int h = param.height;

  for (int y=1;y<param.height-1;y++)
    for (int x=1;x<param.width-1;x++)
      {
	// Fill array with filter kernel for sorting.

	a[0].val = yp[y-1][x-1];
	a[1].val = yp[y-1][x  ];
	a[2].val = yp[y-1][x+1];
	a[3].val = yp[y  ][x-1];
	a[4].val = yp[y  ][x  ];
	a[5].val = yp[y  ][x+1];
	a[6].val = yp[y+1][x-1];
	a[7].val = yp[y+1][x  ];
	a[8].val = yp[y+1][x+1];

	if (color)
	  {
	    a[0].u   = up[y-1][x-1];
	    a[0].v   = vp[y-1][x-1];
	    a[1].u   = up[y-1][x  ];
	    a[1].v   = vp[y-1][x  ];
	    a[2].u   = up[y-1][x+1];
	    a[2].v   = vp[y-1][x+1];
	    a[3].u   = up[y  ][x-1];
	    a[3].v   = vp[y  ][x-1];
	    a[4].u   = up[y  ][x  ];
	    a[4].v   = vp[y  ][x  ];
	    a[5].u   = up[y  ][x+1];
	    a[5].v   = vp[y  ][x+1];
	    a[6].u   = up[y+1][x-1];
	    a[6].v   = vp[y+1][x-1];
	    a[7].u   = up[y+1][x  ];
	    a[7].v   = vp[y+1][x  ];
	    a[8].u   = up[y+1][x+1];
	    a[8].v   = vp[y+1][x+1];
	  }

#if 0
	// --- Bubble Sort ---

	/* We only need 5 passes over the array because then the middle element of the
	   array keeps stable. */
	for (int i=0;i<5;i++)
	  for (int j=0;j<8-i;j++)
	    {
	      if (a[j].d.val>a[j+1].d.val)
		{
		  int m;
		  m = a[j].dummy; a[j].dummy=a[j+1].dummy; a[j+1].dummy=m;
		}
	    }

	// copy result into image

	yp2[y][x] = a[4].d.val;
	up2[y][x] = a[4].d.u;
	vp2[y][x] = a[4].d.v;
#endif

#if 1
	/* This is an alternative implementation of finding the median.
	   It works by sorting out the minimum and maximum element four times
	   which leaves the median.
	   This version is equivalent to the above bubble sort implementation
	   except ties (which could result in different chrominance information).
	   It is a little bit faster than the bubble sort.
	*/

	int last=8;
	for (int i=0;i<4;i++)
	  {
	    int maxid=0,maxval=a[0].val;
	    int minid=0,minval=a[0].val;

	    // Find minimum and maximum element.

	    for (int j=1;j<=last;j++)
	      {
		if (a[j].val > maxval) { maxval=a[j].val; maxid=j; }
		else if (a[j].val < minval) { minval=a[j].val; minid=j; }
	      }

	    // Compress the array by leaving out the two extreme elements.
	    if (minid==last)
	      {
		a[maxid]=a[last-1];
	      }
	    else
	      {
		a[maxid]=a[last  ];
		a[minid]=a[last-1];
	      }

	    last-=2;
	  }

	// copy result into image

	yp2[y][x] = a[0].val;
	if (color)
	  {
	    up2[y][x] = a[0].u;
	    vp2[y][x] = a[0].v;
	  }
#endif
      }

  // Copy border from old image to filtered one.

  for (int x=0;x<param.width;x++)
    {
      yp2[  0][x]=yp[  0][x]; if (color) { up2[  0][x]=up[  0][x]; vp2[  0][x]=vp[  0][x]; }
      yp2[h-1][x]=yp[h-1][x]; if (color) { up2[h-1][x]=up[h-1][x]; vp2[h-1][x]=vp[h-1][x]; }
    }

  for (int y=0;y<param.height;y++)
    {
      yp2[y][  0]=yp[y][  0]; if (color) { up2[y][0  ]=up[y][  0]; vp2[y][  0]=vp[y][  0]; }
      yp2[y][w-1]=yp[y][w-1]; if (color) { up2[y][w-1]=up[y][w-1]; vp2[y][w-1]=vp[y][w-1]; }
    }
}


--- NEW FILE: resize.hh ---
/*********************************************************************
  libvideogfx/graphics/filters/resize.hh

  purpose:

  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 - first implementation
 *********************************************************************/

#ifndef LIBVIDEOGFX_GRAPHICS_FILTERS_RESIZE_HH
#define LIBVIDEOGFX_GRAPHICS_FILTERS_RESIZE_HH

#include "libvideogfx/graphics/basic/image.hh"

void HalfSize_Subsample(const Image_YUV<Pixel>& img,Image_YUV<Pixel>& dest);

#endif




More information about the dslinux-commit mailing list