[Mplayer-cvslog] CVS: mpg12play/mpeg2dec/libvo Makefile.am,NONE,1.1 Makefile.in,NONE,1.1 configure.incl,NONE,1.1 hw_bes.h,NONE,1.1 video_out.c,NONE,1.1 video_out_internal.h,NONE,1.1 video_out_mga.c,NONE,1.1 video_out_null.c,NONE,1.1 video_out_pgm.c,NONE,1.1 video_out_sdl.c,NONE,1.1 video_out_x11.c,NONE,1.1 yuv2rgb.c,NONE,1.1 yuv2rgb.h,NONE,1.1 yuv2rgb_mlib.c,NONE,1.1 yuv2rgb_mmx.c,NONE,1.1

Gernot Ziegler madmac at users.sourceforge.net
Thu May 24 15:31:06 CEST 2001


Update of /cvsroot/mplayer/mpg12play/mpeg2dec/libvo
In directory usw-pr-cvs1:/tmp/cvs-serv2994/mpeg2dec/libvo

Added Files:
	Makefile.am Makefile.in configure.incl hw_bes.h video_out.c 
	video_out_internal.h video_out_mga.c video_out_null.c 
	video_out_pgm.c video_out_sdl.c video_out_x11.c yuv2rgb.c 
	yuv2rgb.h yuv2rgb_mlib.c yuv2rgb_mmx.c 
Log Message:
New mpegp version - only once.

--- NEW FILE ---
CFLAGS = @CFLAGS@ @LIBVO_CFLAGS@

lib_LTLIBRARIES = libvo.la
libvo_la_SOURCES = video_out.c video_out_x11.c video_out_sdl.c \
		   video_out_null.c video_out_pgm.c video_out_mga.c \
		   yuv2rgb.c yuv2rgb_mlib.c yuv2rgb_mmx.c
libvo_la_LIBADD = @LIBVO_LIBS@
libvo_la_LDFLAGS = -no-undefined

EXTRA_DIST = configure.incl video_out_internal.h yuv2rgb.h hw_bes.h

--- NEW FILE ---
# 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 = :
host_alias = @host_alias@
host_triplet = @host@
AS = @AS@
CC = @CC@
DLLTOOL = @DLLTOOL@
INCLUDES = @INCLUDES@
LIBTOOL = @LIBTOOL@
LN_S = @LN_S@
MAINT = @MAINT@
MAKEINFO = @MAKEINFO@
OBJDUMP = @OBJDUMP@
PACKAGE = @PACKAGE@
RANLIB = @RANLIB@
VERSION = @VERSION@

CFLAGS = @CFLAGS@ @LIBVO_CFLAGS@

lib_LTLIBRARIES = libvo.la
libvo_la_SOURCES = video_out.c video_out_x11.c video_out_sdl.c 		   video_out_null.c video_out_pgm.c video_out_mga.c 		   yuv2rgb.c yuv2rgb_mlib.c yuv2rgb_mmx.c

libvo_la_LIBADD = @LIBVO_LIBS@
libvo_la_LDFLAGS = -no-undefined

EXTRA_DIST = configure.incl video_out_internal.h yuv2rgb.h hw_bes.h
mkinstalldirs = $(SHELL) $(top_srcdir)/autotools/mkinstalldirs
CONFIG_HEADER = ../include/config.h
CONFIG_CLEAN_FILES = 
LTLIBRARIES =  $(lib_LTLIBRARIES)


DEFS = @DEFS@ -I. -I$(srcdir) -I../include
CPPFLAGS = @CPPFLAGS@
LDFLAGS = @LDFLAGS@
LIBS = @LIBS@
libvo_la_DEPENDENCIES = 
libvo_la_OBJECTS =  video_out.lo video_out_x11.lo video_out_sdl.lo \
video_out_null.lo video_out_pgm.lo video_out_mga.lo yuv2rgb.lo \
yuv2rgb_mlib.lo yuv2rgb_mmx.lo
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/video_out.P .deps/video_out_mga.P \
.deps/video_out_null.P .deps/video_out_pgm.P .deps/video_out_sdl.P \
.deps/video_out_x11.P .deps/yuv2rgb.P .deps/yuv2rgb_mlib.P \
.deps/yuv2rgb_mmx.P
SOURCES = $(libvo_la_SOURCES)
OBJECTS = $(libvo_la_OBJECTS)

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

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


mostlyclean-libLTLIBRARIES:

clean-libLTLIBRARIES:
	-test -z "$(lib_LTLIBRARIES)" || rm -f $(lib_LTLIBRARIES)

distclean-libLTLIBRARIES:

maintainer-clean-libLTLIBRARIES:

install-libLTLIBRARIES: $(lib_LTLIBRARIES)
	@$(NORMAL_INSTALL)
	$(mkinstalldirs) $(DESTDIR)$(libdir)
	@list='$(lib_LTLIBRARIES)'; for p in $$list; do \
	  if test -f $$p; then \
	    echo "$(LIBTOOL)  --mode=install $(INSTALL) $$p $(DESTDIR)$(libdir)/$$p"; \
	    $(LIBTOOL)  --mode=install $(INSTALL) $$p $(DESTDIR)$(libdir)/$$p; \
	  else :; fi; \
	done

uninstall-libLTLIBRARIES:
	@$(NORMAL_UNINSTALL)
	list='$(lib_LTLIBRARIES)'; for p in $$list; do \
	  $(LIBTOOL)  --mode=uninstall rm -f $(DESTDIR)$(libdir)/$$p; \
	done

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

libvo.la: $(libvo_la_OBJECTS) $(libvo_la_DEPENDENCIES)
	$(LINK) -rpath $(libdir) $(libvo_la_LDFLAGS) $(libvo_la_OBJECTS) $(libvo_la_LIBADD) $(LIBS)

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

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 libvo/Makefile
	@for file in $(DISTFILES); do \
	  d=$(srcdir); \
	  if test -d $$d/$$file; then \
	    cp -pr $$/$$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
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-libLTLIBRARIES
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-libLTLIBRARIES
uninstall: uninstall-am
all-am: Makefile $(LTLIBRARIES)
all-redirect: all-am
install-strip:
	$(MAKE) $(AM_MAKEFLAGS) AM_INSTALL_PROGRAM_FLAGS=-s install
installdirs:
	$(mkinstalldirs)  $(DESTDIR)$(libdir)


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-libLTLIBRARIES mostlyclean-compile \
		mostlyclean-libtool mostlyclean-tags mostlyclean-depend \
		mostlyclean-generic

mostlyclean: mostlyclean-am

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

clean: clean-am

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

distclean: distclean-am

maintainer-clean-am:  maintainer-clean-libLTLIBRARIES \
		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-libLTLIBRARIES distclean-libLTLIBRARIES \
clean-libLTLIBRARIES maintainer-clean-libLTLIBRARIES \
uninstall-libLTLIBRARIES install-libLTLIBRARIES 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


# 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 ---
AC_SUBST([LIBVO_CFLAGS])
AC_SUBST([LIBVO_LIBS])

dnl check for X11
AC_PATH_XTRA
if test x"$no_x" != x"yes"; then
    dnl check for Xshm
    AC_CHECK_LIB([Xext],[XShmCreateImage],
	[AC_DEFINE([LIBVO_X11],,[libvo X11 support])
	LIBVO_CFLAGS="$LIBVO_CFLAGS $X_CFLAGS"
	LIBVO_LIBS="$LIBVO_LIBS $X_PRE_LIBS $X_LIBS -lX11 $X_EXTRA_LIBS -lXext"
	dnl check for Xv
	AC_CHECK_LIB([Xv],[XvShmCreateImage],
	    [AC_DEFINE([LIBVO_XV],,[libvo Xv support])
	    LIBVO_LIBS="$LIBVO_LIBS -lXv"],,
	    [$X_PRE_LIBS $X_LIBS -lX11 $X_EXTRA_LIBS -lXext])],,
	[$X_PRE_LIBS $X_LIBS -lX11 $X_EXTRA_LIBS])
fi

dnl check for mlib
AC_ARG_ENABLE([mlib],
    [  --disable-mlib          make a version not using mediaLib])
if test x"$enable_mlib" != x"no"; then
    cflags_save="$CFLAGS"
    CFLAGS="$CFLAGS -L/opt/SUNWmlib/lib -R/opt/SUNWmlib/lib"
    AC_CHECK_LIB([mlib],[mlib_VideoColorYUV2RGB420],
	[AC_DEFINE([LIBVO_MLIB],,[libvo mediaLib support])
	LIBVO_CFLAGS="$LIBVO_CFLAGS -I/opt/SUNWmlib/include"
	LIBVO_LIBS="$LIBVO_LIBS -L/opt/SUNWmlib/lib -R/opt/SUNWmlib/lib -lmlib"])
    CFLAGS="$cflags_save"
fi

dnl following drivers are unsupported - dont expect them to compile or work

dnl check for SDL
AC_ARG_ENABLE([sdl],[  --disable-sdl           make a version not using SDL])
if test x"$enable_sdl" != x"no"; then
    AC_CHECK_PROG([SDLCONFIG],[sdl-config],[yes])
    if test x"$SDLCONFIG" = x"yes"; then
	AC_DEFINE([LIBVO_SDL],,[libvo SDL support])
	LIBVO_CFLAGS="$LIBVO_CFLAGS `sdl-config --cflags`"
	LIBVO_LIBS="$LIBVO_LIBS `sdl-config --libs`"
    fi
fi

dnl check for MGA
AC_ARG_ENABLE([mga],[  --enable-mga            make a version using MGA])
if test x"$enable_mga" = x"yes"; then
    AC_DEFINE([LIBVO_MGA],,[libvo MGA support])
fi

--- NEW FILE ---
/*
 * hw_bes.h
 * Copyright (C) 1999-2001 Aaron Holtzman <aholtzma at ess.engr.uvic.ca>
 *
 * This file is part of mpeg2dec, a free MPEG-2 video stream decoder.
 *
 * mpeg2dec is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * mpeg2dec is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

#ifndef __LINUX_HW_BES_H
#define __LINUX_HW_BES_H

typedef struct mga_vid_config_s
{
uint32_t card_type;
uint32_t ram_size;
uint32_t src_width;
uint32_t src_height;
uint32_t dest_width;
uint32_t dest_height;
uint32_t x_org;
uint32_t y_org;
uint8_t  colkey_on;
uint8_t  colkey_red;
uint8_t  colkey_green;
uint8_t  colkey_blue;
} mga_vid_config_t;

#define MGA_VID_CONFIG    _IOR('J', 1, mga_vid_config_t)
#define MGA_VID_ON        _IO ('J', 2)
#define MGA_VID_OFF       _IO ('J', 3)
#define MGA_VID_FSEL _IOR('J', 4, int)

#define MGA_G200 0x1234
#define MGA_G400 0x5678

#endif

--- NEW FILE ---
/*
 * video_out.c
 * Copyright (C) 1999-2001 Aaron Holtzman <aholtzma at ess.engr.uvic.ca>
 *
 * This file is part of mpeg2dec, a free MPEG-2 video stream decoder.
 *
 * mpeg2dec is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * mpeg2dec is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

#include "config.h"

#include <stdlib.h>
#include <inttypes.h>

#include "video_out.h"
#include "video_out_internal.h"

#ifdef HAVE_MEMALIGN
/* some systems have memalign() but no declaration for it */
void * memalign (size_t align, size_t size);
#else
/* assume malloc alignment is sufficient */
#define memalign(align,size) malloc (size)
#endif

uint32_t vo_mm_accel = 0;

/* Externally visible list of all vo drivers */

extern vo_open_t vo_xv_open;
extern vo_open_t vo_x11_open;
extern vo_open_t vo_sdl_open;
extern vo_open_t vo_mga_open;
extern vo_open_t vo_null_open;
extern vo_open_t vo_nullslice_open;
extern vo_open_t vo_nullrgb16_open;
extern vo_open_t vo_nullrgb32_open;
extern vo_open_t vo_pgm_open;
extern vo_open_t vo_pgmpipe_open;
extern vo_open_t vo_md5_open;

void vo_accel (uint32_t accel)
{
    vo_mm_accel = accel;
}

static vo_driver_t video_out_drivers[] =
{
#ifdef LIBVO_XV
    {"xv", vo_xv_open},
#endif
#ifdef LIBVO_X11
    {"x11", vo_x11_open},
#endif
#ifdef LIBVO_MGA
    {"mga", vo_mga_open},
#endif
#ifdef LIBVO_SDL
    {"sdl", vo_sdl_open},
#endif
    {"null", vo_null_open},
    {"nullslice", vo_nullslice_open},
    {"nullrgb16", vo_nullrgb16_open},
    {"nullrgb32", vo_nullrgb32_open},
    {"pgm", vo_pgm_open},
    {"pgmpipe", vo_pgmpipe_open},
    {"md5", vo_md5_open},
    {NULL, NULL}
};

vo_driver_t * vo_drivers (void)
{
    return video_out_drivers;
}

typedef struct common_instance_s {
    vo_instance_t vo;
    int prediction_index;
    vo_frame_t * frame_ptr[3];
} common_instance_t;

int libvo_common_alloc_frames (vo_instance_t * _instance,
			       int width, int height, int frame_size,
			       void (* copy) (vo_frame_t *, uint8_t **),
			       void (* field) (vo_frame_t *, int),
			       void (* draw) (vo_frame_t *))
{
    common_instance_t * instance;
    int size;
    uint8_t * alloc;
    int i;

    instance = (common_instance_t *) _instance;
    instance->prediction_index = 1;
    size = width * height / 4;
    alloc = memalign (16, 18 * size);
    if (alloc == NULL)
	return 1;

    for (i = 0; i < 3; i++) {
	instance->frame_ptr[i] =
	    (vo_frame_t *) (((char *) instance) + sizeof (common_instance_t) +
			    i * frame_size);
	instance->frame_ptr[i]->base[0] = alloc;
	instance->frame_ptr[i]->base[1] = alloc + 4 * size;
	instance->frame_ptr[i]->base[2] = alloc + 5 * size;
	instance->frame_ptr[i]->copy = copy;
	instance->frame_ptr[i]->field = field;
	instance->frame_ptr[i]->draw = draw;
	instance->frame_ptr[i]->instance = (vo_instance_t *) instance;
	alloc += 6 * size;
    }

    return 0;
}

void libvo_common_free_frames (vo_instance_t * _instance)
{
    common_instance_t * instance;

    instance = (common_instance_t *) _instance;
    free (instance->frame_ptr[0]->base[0]);
}

vo_frame_t * libvo_common_get_frame (vo_instance_t * _instance, int flags)
{
    common_instance_t * instance;

    instance = (common_instance_t *)_instance;
    if (flags & VO_PREDICTION_FLAG) {
	instance->prediction_index ^= 1;
	return instance->frame_ptr[instance->prediction_index];
    } else
	return instance->frame_ptr[2];
}

--- NEW FILE ---
/*
 * video_out_internal.h
 * Copyright (C) 1999-2001 Aaron Holtzman <aholtzma at ess.engr.uvic.ca>
 *
 * This file is part of mpeg2dec, a free MPEG-2 video stream decoder.
 *
 * mpeg2dec is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * mpeg2dec is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

extern uint32_t vo_mm_accel;

int libvo_common_alloc_frames (vo_instance_t * instance, int width, int height,
			       int frame_size,
			       void (* copy) (vo_frame_t *, uint8_t **),
			       void (* field) (vo_frame_t *, int),
			       void (* draw) (vo_frame_t *));
void libvo_common_free_frames (vo_instance_t * instance);
vo_frame_t * libvo_common_get_frame (vo_instance_t * instance, int prediction);

--- NEW FILE ---
/*
 * video_out_mga.c
 * Copyright (C) 1999-2001 Aaron Holtzman <aholtzma at ess.engr.uvic.ca>
 *
 * This file is part of mpeg2dec, a free MPEG-2 video stream decoder.
 *
 * mpeg2dec is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * mpeg2dec is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

/* FIXME this should allocate AGP memory via agpgart and then we */
/* can use AGP transfers to the framebuffer */

#include "config.h"

#ifdef LIBVO_MGA

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <sys/ioctl.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/mman.h>
#include <inttypes.h>

#include "video_out.h"
#include "video_out_internal.h"

#include "hw_bes.h"
#include "attributes.h"
#include "mmx.h"

static void yuvinterleave (uint8_t * dst, uint8_t * pu, uint8_t * pv,
			   int width)
{
    width >>= 3;
    do {
	dst[0] = pu[0];
	dst[1] = pv[0];
	dst[2] = pu[1];
	dst[3] = pv[1];
	dst[4] = pu[2];
	dst[5] = pv[2];
	dst[6] = pu[3];
	dst[7] = pv[3];
	dst += 8;
	pu += 4;
	pv += 4;
    } while (--width);
}

static void yuv2g200_c (uint8_t * dst, uint8_t * py,
			uint8_t * pu, uint8_t * pv,
			int width, int height,
			int bes_stride, int y_stride, int uv_stride)
{
    int i;

    i = height;
    do {
	memcpy (dst, py, width);
	py += y_stride;
	dst += bes_stride;
    } while (--i);

    i = height >> 1;
    do {
	yuvinterleave (dst, pu, pv, width);
	pu += uv_stride;
	pv += uv_stride;
	dst += bes_stride;
    } while (--i);
}

static void yuv2g400_c (uint8_t * dst, uint8_t * py,
			uint8_t * pu, uint8_t * pv,
			int width, int height,
			int bes_stride, int y_stride, int uv_stride)
{
    int i;

    i = height;
    do {
	memcpy (dst, py, width);
	py += y_stride;
	dst += bes_stride;
    } while (--i);

    width >>= 1;
    bes_stride >>= 1;
    i = height >> 1;
    do {
	memcpy (dst, pu, width);
	pu += uv_stride;
	dst += bes_stride;
    } while (--i);

    i = height >> 1;
    do {
	memcpy (dst, pv, width);
	pv += uv_stride;
	dst += bes_stride;
    } while (--i);
}

typedef struct mga_instance_s {
    vo_instance_t vo;
    int prediction_index;
    vo_frame_t * frame_ptr[3];
    vo_frame_t frame[3];

    int fd;
    mga_vid_config_t mga_vid_config;
    uint8_t * vid_data;
    uint8_t * frame0;
    uint8_t * frame1;
    int next_frame;
    int stride;
} mga_instance_t;

static void mga_draw_frame (vo_frame_t * frame)
{
    mga_instance_t * instance;

    instance = (mga_instance_t *) frame->instance;

    yuv2g400_c (instance->vid_data,
		frame->base[0], frame->base[1], frame->base[2],
		instance->mga_vid_config.src_width,
		instance->mga_vid_config.src_height,
		instance->stride, instance->mga_vid_config.src_width,
		instance->mga_vid_config.src_width >> 1);

    ioctl (instance->fd, MGA_VID_FSEL, &instance->next_frame);

    instance->next_frame ^= 2; /* switch between fields A1 and B1 */
    if (instance->next_frame) 
	instance->vid_data = instance->frame1;
    else
	instance->vid_data = instance->frame0;
}

static void mga_close (vo_instance_t * _instance)
{
    mga_instance_t * instance;

    instance = (mga_instance_t *) _instance;

    close (instance->fd);
    libvo_common_free_frames ((vo_instance_t *) instance);
}

static int mga_setup (vo_instance_t * _instance, int width, int height)
{
    mga_instance_t * instance;
    char * frame_mem;
    int frame_size;

    instance = (mga_instance_t *) _instance;

    if (ioctl (instance->fd, MGA_VID_ON, 0)) {
	close (instance->fd);
	return 1;
    }

    instance->mga_vid_config.src_width = width;
    instance->mga_vid_config.src_height = height;
    instance->mga_vid_config.dest_width = width;
    instance->mga_vid_config.dest_height = height;
    instance->mga_vid_config.x_org = 10;
    instance->mga_vid_config.y_org = 10;
    instance->mga_vid_config.colkey_on = 1;

    if (ioctl (instance->fd, MGA_VID_CONFIG, &(instance->mga_vid_config)))
	perror ("Error in instance->mga_vid_config ioctl");
    ioctl (instance->fd, MGA_VID_ON, 0);

    instance->stride = (width + 31) & ~31;
    frame_size = instance->stride * height * 3 / 2;
    frame_mem = (char*)mmap (0, frame_size*2, PROT_WRITE, MAP_SHARED, instance->fd, 0);
    instance->frame0 = frame_mem;
    instance->frame1 = frame_mem + frame_size;
    instance->vid_data = frame_mem;
    instance->next_frame = 0;

    return libvo_common_alloc_frames ((vo_instance_t *) instance,
				      width, height, sizeof (vo_frame_t),
				      NULL, NULL, mga_draw_frame);
}

vo_instance_t * vo_mga_open (void)
{
    mga_instance_t * instance;

    instance = malloc (sizeof (mga_instance_t));
    if (instance == NULL)
	return NULL;

    instance->fd = open ("/dev/mga_vid", O_RDWR);
    if (instance->fd < 0) {
	free (instance);
	return NULL;
    }

    instance->vo.setup = mga_setup;
    instance->vo.close = mga_close;
    instance->vo.get_frame = libvo_common_get_frame;

    return (vo_instance_t *) instance;
}
#endif

--- NEW FILE ---
/* 
 * video_out_null.c
 * Copyright (C) 1999-2001 Aaron Holtzman <aholtzma at ess.engr.uvic.ca>
 *
 * This file is part of mpeg2dec, a free MPEG-2 video stream decoder.
 *
 * mpeg2dec is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * mpeg2dec is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

#include "config.h"

#include <stdlib.h>
#include <inttypes.h>

#include "video_out.h"
#include "video_out_internal.h"
#include "yuv2rgb.h"

typedef struct null_frame_s {
    vo_frame_t vo;
    uint8_t * rgb_ptr;
    int rgb_stride;
    int yuv_stride;
} null_frame_t;

typedef struct null_instance_s {
    vo_instance_t vo;
    int prediction_index;
    vo_frame_t * frame_ptr[3];
    null_frame_t frame[3];
    uint8_t * rgbdata;
    int rgbstride;
    int width;
    int bpp;
} null_instance_t;

static void null_draw_frame (vo_frame_t * frame)
{
}

static int null_setup (vo_instance_t * instance, int width, int height)
{
    return libvo_common_alloc_frames (instance, width, height,
				      sizeof (null_frame_t),
				      NULL, NULL, null_draw_frame);
}

vo_instance_t * vo_null_open (void)
{
    null_instance_t * instance;

    instance = malloc (sizeof (null_instance_t));
    if (instance == NULL)
	return NULL;

    instance->vo.setup = null_setup;
    instance->vo.close = libvo_common_free_frames;
    instance->vo.get_frame = libvo_common_get_frame;

    return (vo_instance_t *) instance;
}

static void null_copy_slice (vo_frame_t * frame, uint8_t ** src)
{
}

static int nullslice_setup (vo_instance_t * instance, int width, int height)
{
    return libvo_common_alloc_frames (instance, width, height,
				      sizeof (null_frame_t),
				      null_copy_slice, NULL, null_draw_frame);
}

vo_instance_t * vo_nullslice_open (void)
{
    null_instance_t * instance;

    instance = malloc (sizeof (null_instance_t));
    if (instance == NULL)
	return NULL;

    instance->vo.setup = nullslice_setup;
    instance->vo.close = libvo_common_free_frames;
    instance->vo.get_frame = libvo_common_get_frame;

    return (vo_instance_t *) instance;
}

static vo_frame_t * rgb_get_frame (vo_instance_t * _instance, int flags)
{
    null_instance_t * instance;
    null_frame_t * frame;

    instance = (null_instance_t *) _instance;
    frame =
	(null_frame_t *) libvo_common_get_frame ((vo_instance_t *) instance,
						 flags);

    frame->rgb_ptr = instance->rgbdata;
    frame->rgb_stride = instance->rgbstride;
    frame->yuv_stride = instance->width;
    if ((flags & VO_TOP_FIELD) == 0)
        frame->rgb_ptr += frame->rgb_stride;
    if ((flags & VO_BOTH_FIELDS) != VO_BOTH_FIELDS) {
        frame->rgb_stride <<= 1;
        frame->yuv_stride <<= 1;
    }

    return (vo_frame_t *) frame;
}

static void rgb_copy_slice (vo_frame_t * _frame, uint8_t ** src)
{
    null_frame_t * frame;
    null_instance_t * instance;

    frame = (null_frame_t *) _frame;
    instance = (null_instance_t *) frame->vo.instance;

    yuv2rgb (frame->rgb_ptr, src[0], src[1], src[2], instance->width, 16,
	     frame->rgb_stride, frame->yuv_stride, frame->yuv_stride >> 1);
    frame->rgb_ptr += frame->rgb_stride << 4;
}

static void rgb_field (vo_frame_t * _frame, int flags)
{
    null_frame_t * frame;
    null_instance_t * instance;

    frame = (null_frame_t *) _frame;
    instance = (null_instance_t *) frame->vo.instance;

    frame->rgb_ptr = instance->rgbdata;
    if ((flags & VO_TOP_FIELD) == 0)
	frame->rgb_ptr += instance->rgbstride;
}

static int nullrgb_setup (vo_instance_t * _instance, int width, int height)
{
    null_instance_t * instance;

    instance = (null_instance_t *) _instance;

    instance->width = width;
    instance->rgbstride = width * instance->bpp / 8;
    instance->rgbdata = malloc (instance->rgbstride * height);

    yuv2rgb_init (instance->bpp, MODE_RGB);

    return libvo_common_alloc_frames ((vo_instance_t *) instance,
				      width, height, sizeof (null_frame_t),
				      rgb_copy_slice, rgb_field,
				      null_draw_frame);
}

vo_instance_t * vo_nullrgb16_open (void)
{
    null_instance_t * instance;

    instance = malloc (sizeof (null_instance_t));
    if (instance == NULL)
	return NULL;

    instance->vo.setup = nullrgb_setup;
    instance->vo.close = libvo_common_free_frames;
    instance->vo.get_frame = rgb_get_frame;
    instance->bpp = 16;

    return (vo_instance_t *) instance;
}

vo_instance_t * vo_nullrgb32_open (void)
{
    null_instance_t * instance;

    instance = malloc (sizeof (null_instance_t));
    if (instance == NULL)
	return NULL;

    instance->vo.setup = nullrgb_setup;
    instance->vo.close = libvo_common_free_frames;
    instance->vo.get_frame = rgb_get_frame;
    instance->bpp = 32;

    return (vo_instance_t *) instance;
}

--- NEW FILE ---
/*
 * video_out_pgm.c
 * Copyright (C) 1999-2001 Aaron Holtzman <aholtzma at ess.engr.uvic.ca>
 *
 * This file is part of mpeg2dec, a free MPEG-2 video stream decoder.
 *
 * mpeg2dec is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * mpeg2dec is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

#include "config.h"

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <inttypes.h>

#include "video_out.h"
#include "video_out_internal.h"

typedef struct pgm_instance_s {
    vo_instance_t vo;
    int prediction_index;
    vo_frame_t * frame_ptr[3];
    vo_frame_t frame[3];
    int width;
    int height;
    int framenum;
    char header[1024];
    char filename[128];
} pgm_instance_t;

static void internal_draw_frame (pgm_instance_t * instance, FILE * file,
				 vo_frame_t * frame)
{
    int i;

    fwrite (instance->header, strlen (instance->header), 1, file);
    fwrite (frame->base[0], instance->width, instance->height, file);
    for (i = 0; i < instance->height >> 1; i++) {
	fwrite (frame->base[1]+i*instance->width/2, instance->width/2, 1,
		file);
	fwrite (frame->base[2]+i*instance->width/2, instance->width/2, 1,
		file);
    }
}

static int internal_setup (vo_instance_t * _instance, int width, int height,
			   void (* draw_frame) (vo_frame_t *))
{
    pgm_instance_t * instance;

    instance = (pgm_instance_t *) _instance;

    instance->vo.close = libvo_common_free_frames;
    instance->vo.get_frame = libvo_common_get_frame;
    instance->width = width;
    instance->height = height;
    sprintf (instance->header, "P5\n\n%d %d\n255\n", width, height * 3 / 2);
    return libvo_common_alloc_frames ((vo_instance_t *) instance,
				      width, height, sizeof (vo_frame_t),
				      NULL, NULL, draw_frame);
}

static void pgm_draw_frame (vo_frame_t * frame)
{
    pgm_instance_t * instance;
    FILE * file;

    instance = (pgm_instance_t *) frame->instance;
    if (++(instance->framenum) < 0)
	return;
    sprintf (instance->filename, "%d.pgm", instance->framenum);
    file = fopen (instance->filename, "wb");
    if (!file)
	return;
    internal_draw_frame (instance, file, frame);
    fclose (file);
}

static int pgm_setup (vo_instance_t * instance, int width, int height)
{
    return internal_setup (instance, width, height, pgm_draw_frame);
}

vo_instance_t * vo_pgm_open (void)
{
    pgm_instance_t * instance;

    instance = malloc (sizeof (pgm_instance_t));
    if (instance == NULL)
        return NULL;

    instance->vo.setup = pgm_setup;
    instance->framenum = -2;
    return (vo_instance_t *) instance;
}

static void pgmpipe_draw_frame (vo_frame_t * frame)
{
    pgm_instance_t * instance;

    instance = (pgm_instance_t *)frame->instance;
    if (++(instance->framenum) >= 0)
	internal_draw_frame (instance, stdout, frame);
}

static int pgmpipe_setup (vo_instance_t * instance, int width, int height)
{
    return internal_setup (instance, width, height, pgmpipe_draw_frame);
}

vo_instance_t * vo_pgmpipe_open (void)
{
    pgm_instance_t * instance;

    instance = malloc (sizeof (pgm_instance_t));
    if (instance == NULL)
        return NULL;

    instance->vo.setup = pgmpipe_setup;
    instance->framenum = -2;
    return (vo_instance_t *) instance;
}

static void md5_draw_frame (vo_frame_t * frame)
{
    pgm_instance_t * instance;
    char buf[100];

    instance = (pgm_instance_t *) frame->instance;
    pgm_draw_frame (frame);
    if (instance->framenum < 0)
	return;
    sprintf (buf, "md5sum -b %s", instance->filename);
    system (buf);
    remove (instance->filename);
}

static int md5_setup (vo_instance_t * instance, int width, int height)
{
    return internal_setup (instance, width, height, md5_draw_frame);
}

vo_instance_t * vo_md5_open (void)
{
    pgm_instance_t * instance;

    instance = malloc (sizeof (pgm_instance_t));
    if (instance == NULL)
        return NULL;

    instance->vo.setup = md5_setup;
    instance->framenum = -2;
    return (vo_instance_t *) instance;
}

--- NEW FILE ---
/*
 * video_out_sdl.c
 *
 * Copyright (C) 2000-2001 Ryan C. Gordon <icculus at lokigames.com> and
 *                         Dominik Schnitzer <aeneas at linuxvideo.org>
 *
 * SDL info, source, and binaries can be found at http://www.libsdl.org/
 *
 * This file is part of mpeg2dec, a free MPEG-2 video stream decoder.
 *
 * mpeg2dec is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * mpeg2dec is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

#include "config.h"

#ifdef LIBVO_SDL

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <inttypes.h>
#include <SDL/SDL.h>

#include "video_out.h"
#include "video_out_internal.h"

typedef struct sdl_frame_s {
    vo_frame_t vo;
    SDL_Overlay * overlay;
} sdl_frame_t;

typedef struct sdl_instance_s {
    vo_instance_t vo;
    int prediction_index;
    vo_frame_t * frame_ptr[3];
    sdl_frame_t frame[3];

    SDL_Surface * surface;
    Uint32 sdlflags;
    Uint8 bpp;
} sdl_instance_t;

static vo_frame_t * sdl_get_frame (vo_instance_t * _instance, int flags)
{
    sdl_instance_t * instance;
    sdl_frame_t * frame;

    instance = (sdl_instance_t *) _instance;
    frame = (sdl_frame_t *) libvo_common_get_frame ((vo_instance_t *) instance,
						    flags);
    SDL_LockYUVOverlay (frame->overlay);
    return (vo_frame_t *) frame;
}

static void check_events (sdl_instance_t * instance)
{
    SDL_Event event;

    while (SDL_PollEvent (&event))
	if (event.type == SDL_VIDEORESIZE)
	    instance->surface =
		SDL_SetVideoMode (event.resize.w, event.resize.h,
				  instance->bpp, instance->sdlflags);
}

static void sdl_draw_frame (vo_frame_t * _frame)
{
    sdl_frame_t * frame;
    sdl_instance_t * instance;

    frame = (sdl_frame_t *) _frame;
    instance = (sdl_instance_t *) frame->vo.instance;

    SDL_UnlockYUVOverlay (frame->overlay);
    SDL_DisplayYUVOverlay (frame->overlay, &(instance->surface->clip_rect));
    check_events (instance);
}

static int sdl_alloc_frames (sdl_instance_t * instance, int width, int height)
{
    int i;

    for (i = 0; i < 3; i++) {
	instance->frame[i].overlay =
	    SDL_CreateYUVOverlay (width, height, SDL_YV12_OVERLAY,
				  instance->surface);
	if (instance->frame[i].overlay == NULL)
	    return 1;
	instance->frame_ptr[i] = (vo_frame_t *) (instance->frame + i);
	instance->frame[i].vo.base[0] = instance->frame[i].overlay->pixels[0];
	instance->frame[i].vo.base[1] = instance->frame[i].overlay->pixels[2];
	instance->frame[i].vo.base[2] = instance->frame[i].overlay->pixels[1];
	instance->frame[i].vo.copy = NULL;
	instance->frame[i].vo.field = NULL;
	instance->frame[i].vo.draw = sdl_draw_frame;
	instance->frame[i].vo.instance = (vo_instance_t *) instance;
    }

    return 0;
}

static void sdl_close (vo_instance_t * _instance)
{
    sdl_instance_t * instance;
    int i;

    instance = (sdl_instance_t *) _instance;
    for (i = 0; i < 3; i++)
	SDL_FreeYUVOverlay (instance->frame[i].overlay);
    SDL_FreeSurface (instance->surface);
    SDL_QuitSubSystem (SDL_INIT_VIDEO);
}

static int sdl_setup (vo_instance_t * _instance, int width, int height)
{
    sdl_instance_t * instance;

    instance = (sdl_instance_t *) _instance;

    instance->surface = SDL_SetVideoMode (width, height, instance->bpp,
					  instance->sdlflags);
    if (! (instance->surface)) {
	fprintf (stderr, "sdl could not set the desired video mode\n");
	return 1;
    }

    if (sdl_alloc_frames (instance, width, height)) {
	fprintf (stderr, "sdl could not allocate frame buffers\n");
	return 1;
    }

    return 0;
}

vo_instance_t * vo_sdl_open (void)
{
    sdl_instance_t * instance;
    const SDL_VideoInfo * vidInfo;

    instance = malloc (sizeof (sdl_instance_t));
    if (instance == NULL)
	return NULL;

    instance->vo.setup = sdl_setup;
    instance->vo.close = sdl_close;
    instance->vo.get_frame = sdl_get_frame;

    instance->surface = NULL;
    instance->sdlflags = SDL_HWSURFACE | SDL_RESIZABLE;

    setenv("SDL_VIDEO_YUV_HWACCEL", "1", 1);
    setenv("SDL_VIDEO_X11_NODIRECTCOLOR", "1", 1);

    if (SDL_Init (SDL_INIT_VIDEO)) {
	fprintf (stderr, "sdl video initialization failed.\n");
	return NULL;
    }

    vidInfo = SDL_GetVideoInfo ();
    if (!SDL_ListModes (vidInfo->vfmt, SDL_HWSURFACE | SDL_RESIZABLE)) {
	instance->sdlflags = SDL_RESIZABLE;
	if (!SDL_ListModes (vidInfo->vfmt, SDL_RESIZABLE)) {
	    fprintf (stderr, "sdl couldn't get any acceptable video mode\n");
	    return NULL;
	}
    }
    instance->bpp = vidInfo->vfmt->BitsPerPixel;
    if (instance->bpp < 16) {
	fprintf(stderr, "sdl has to emulate a 16 bit surfaces, "
		"that will slow things down.\n");
	instance->bpp = 16;
    }

    return (vo_instance_t *) instance;
}
#endif

--- NEW FILE ---
/*
 * video_out_x11.c
 * Copyright (C) 1999-2001 Aaron Holtzman <aholtzma at ess.engr.uvic.ca>
 *
 * This file is part of mpeg2dec, a free MPEG-2 video stream decoder.
 *
 * mpeg2dec is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * mpeg2dec is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

#include "config.h"

#ifdef LIBVO_X11

#include <stdio.h>
#include <stdlib.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <inttypes.h>

#include <sys/ipc.h>
#include <sys/shm.h>
#include <X11/extensions/XShm.h>
/* since it doesn't seem to be defined on some platforms */
int XShmGetEventBase (Display *);

#ifdef LIBVO_XV
#include <string.h>	/* strcmp */
#include <X11/extensions/Xvlib.h>
#define FOURCC_YV12 0x32315659
#endif

#include "video_out.h"
#include "video_out_internal.h"
#include "yuv2rgb.h"

typedef struct x11_frame_s {
    vo_frame_t vo;
    uint8_t * rgb_ptr;
    int rgb_stride;
    int yuv_stride;
    XImage * ximage;
    int wait_completion;
#ifdef LIBVO_XV
    XvImage * xvimage;	/* FIXME have only one ximage/xvimage pointer ? */
#endif
} x11_frame_t;

typedef struct x11_instance_s {
    vo_instance_t vo;
    int prediction_index;
    vo_frame_t * frame_ptr[3];
    x11_frame_t frame[3];

    /* local data */
    int width;
    int height;

    /* X11 related variables */
    Display * display;
    Window window;
    GC gc;
    XVisualInfo vinfo;
    XShmSegmentInfo shminfo;
    int completion_type;
#ifdef LIBVO_XV
    XvPortID port;
#endif
} x11_instance_t;

static int open_display (x11_instance_t * instance)
{
    int major;
    int minor;
    Bool pixmaps;
    XVisualInfo visualTemplate;
    XVisualInfo * XvisualInfoTable;
    XVisualInfo * XvisualInfo;
    int number;
    int i;
    XSetWindowAttributes attr;
    XGCValues gcValues;

    instance->display = XOpenDisplay (NULL);
    if (! (instance->display)) {
	fprintf (stderr, "Can not open display\n");
	return 1;
    }

    if ((XShmQueryVersion (instance->display, &major, &minor,
			   &pixmaps) == 0) ||
	(major < 1) || ((major == 1) && (minor < 1))) {
	fprintf (stderr, "No xshm extension\n");
	return 1;
    }

    instance->completion_type =
	XShmGetEventBase (instance->display) + ShmCompletion;

    /* list truecolor visuals for the default screen */
    visualTemplate.class = TrueColor;
    visualTemplate.screen = DefaultScreen (instance->display);
    XvisualInfoTable = XGetVisualInfo (instance->display,
				       VisualScreenMask | VisualClassMask,
				       &visualTemplate, &number);
    if (XvisualInfoTable == NULL) {
	fprintf (stderr, "No truecolor visual\n");
	return 1;
    }

    /* find the visual with the highest depth */
    XvisualInfo = XvisualInfoTable;
    for (i = 1; i < number; i++)
	if (XvisualInfoTable[i].depth > XvisualInfo->depth)
	    XvisualInfo = XvisualInfoTable + i;

    instance->vinfo = *XvisualInfo;
    XFree (XvisualInfoTable);

    attr.background_pixmap = None;
    attr.backing_store = NotUseful;
    attr.border_pixel = 0;
    attr.event_mask = 0;
    /* fucking sun blows me - you have to create a colormap there... */
    attr.colormap = XCreateColormap (instance->display,
				     RootWindow (instance->display,
						 instance->vinfo.screen),
				     instance->vinfo.visual, AllocNone);
    instance->window =
	XCreateWindow (instance->display,
		       DefaultRootWindow (instance->display),
		       0 /* x */, 0 /* y */, instance->width, instance->height,
		       0 /* border_width */, instance->vinfo.depth,
		       InputOutput, instance->vinfo.visual,
		       (CWBackPixmap | CWBackingStore | CWBorderPixel |
			CWEventMask | CWColormap), &attr);

    instance->gc = XCreateGC (instance->display, instance->window, 0,
			      &gcValues);

    return 0;
}

static int shmerror = 0;

static int handle_error (Display * display, XErrorEvent * error)
{
    shmerror = 1;
    return 0;
}

static void * create_shm (x11_instance_t * instance, int size)
{
    instance->shminfo.shmid = shmget (IPC_PRIVATE, size, IPC_CREAT | 0777);
    if (instance->shminfo.shmid == -1)
	goto error;

    instance->shminfo.shmaddr = shmat (instance->shminfo.shmid, 0, 0);
    if (instance->shminfo.shmaddr == (char *)-1)
	goto error;

    /* on linux the IPC_RMID only kicks off once everyone detaches the shm */
    /* doing this early avoids shm leaks when we are interrupted. */
    /* this would break the solaris port though :-/ */
    /* shmctl (instance->shminfo.shmid, IPC_RMID, 0); */

    /* XShmAttach fails on remote displays, so we have to catch this event */

    XSync (instance->display, False);
    XSetErrorHandler (handle_error);

    instance->shminfo.readOnly = True;
    if (! (XShmAttach (instance->display, &(instance->shminfo))))
	shmerror = 1;

    XSync (instance->display, False);
    XSetErrorHandler (NULL);
    if (shmerror) {
    error:
	fprintf (stderr, "cannot create shared memory\n");
	return NULL;
    }

    return instance->shminfo.shmaddr;
}

static void destroy_shm (x11_instance_t * instance)
{
    XShmDetach (instance->display, &(instance->shminfo));
    shmdt (instance->shminfo.shmaddr);
    shmctl (instance->shminfo.shmid, IPC_RMID, 0);
}

static void x11_event (x11_instance_t * instance)
{
    XEvent event;
    char * addr;
    int i;

    XNextEvent (instance->display, &event);
    if (event.type == instance->completion_type) {
	addr = (instance->shminfo.shmaddr +
		((XShmCompletionEvent *)&event)->offset);
	for (i = 0; i < 3; i++)
	    if (addr == instance->frame[i].ximage->data)
		instance->frame[i].wait_completion = 0;
    }
}

static vo_frame_t * x11_get_frame (vo_instance_t * _instance, int flags)
{
    x11_instance_t * instance;
    x11_frame_t * frame;

    instance = (x11_instance_t *) _instance;
    frame = (x11_frame_t *) libvo_common_get_frame ((vo_instance_t *) instance,
						    flags);

    while (frame->wait_completion)
	x11_event (instance);

    frame->rgb_ptr = frame->ximage->data;
    frame->rgb_stride = frame->ximage->bytes_per_line;
    frame->yuv_stride = instance->width;
    if ((flags & VO_TOP_FIELD) == 0)
	frame->rgb_ptr += frame->rgb_stride;
    if ((flags & VO_BOTH_FIELDS) != VO_BOTH_FIELDS) {
	frame->rgb_stride <<= 1;
	frame->yuv_stride <<= 1;
    }

    return (vo_frame_t *) frame;
}

static void x11_copy_slice (vo_frame_t * _frame, uint8_t ** src)
{
    x11_frame_t * frame;
    x11_instance_t * instance;

    frame = (x11_frame_t *) _frame;
    instance = (x11_instance_t *) frame->vo.instance;

    yuv2rgb (frame->rgb_ptr, src[0], src[1], src[2], instance->width, 16,
	     frame->rgb_stride, frame->yuv_stride, frame->yuv_stride >> 1);
    frame->rgb_ptr += frame->rgb_stride << 4;
}

static void x11_field (vo_frame_t * _frame, int flags)
{
    x11_frame_t * frame;

    frame = (x11_frame_t *) _frame;
    frame->rgb_ptr = frame->ximage->data;
    if ((flags & VO_TOP_FIELD) == 0)
	frame->rgb_ptr += frame->ximage->bytes_per_line;
}

static void x11_draw_frame (vo_frame_t * _frame)
{
    x11_frame_t * frame;
    x11_instance_t * instance;

    frame = (x11_frame_t *) _frame;
    instance = (x11_instance_t *) frame->vo.instance;

    XShmPutImage (instance->display, instance->window, instance->gc,
		  frame->ximage, 0, 0, 0, 0, instance->width, instance->height,
		  True);
    XFlush (instance->display);
    frame->wait_completion = 1;
}

static int x11_alloc_frames (x11_instance_t * instance)
{
    int size;
    uint8_t * alloc;
    int i;

    size = 0;
    alloc = NULL;
    for (i = 0; i < 3; i++) {
	instance->frame[i].wait_completion = 0;
	instance->frame[i].ximage =
	    XShmCreateImage (instance->display, instance->vinfo.visual,
			     instance->vinfo.depth, ZPixmap, NULL /* data */,
			     &(instance->shminfo),
			     instance->width, instance->height);
	if (instance->frame[i].ximage == NULL) {
	    fprintf (stderr, "Cannot create ximage\n");
	    return 1;
	} else if (i == 0) {
	    size = (instance->frame[0].ximage->bytes_per_line * 
		    instance->frame[0].ximage->height);
	    alloc = create_shm (instance, 3 * size);
	    if (alloc == NULL)
		return 1;
	} else if (size != (instance->frame[0].ximage->bytes_per_line *
			    instance->frame[0].ximage->height)) {
	    fprintf (stderr, "unexpected ximage data size\n");
	    return 1;
	}

	instance->frame[i].ximage->data = alloc;
	alloc += size;
    }

#ifdef WORDS_BIGENDIAN 
    if (instance->frame[0].ximage->byte_order != MSBFirst) {
	fprintf (stderr, "No support for non-native byte order\n");
	return 1;
    }
#else
    if (instance->frame[0].ximage->byte_order != LSBFirst) {
	fprintf (stderr, "No support for non-native byte order\n");
	return 1;
    }
#endif

    /*
     * depth in X11 terminology land is the number of bits used to
     * actually represent the colour.
     *
     * bpp in X11 land means how many bits in the frame buffer per
     * pixel. 
     *
     * ex. 15 bit color is 15 bit depth and 16 bpp. Also 24 bit
     *     color is 24 bit depth, but can be 24 bpp or 32 bpp.
     *
     * If we have blue in the lowest bit then "obviously" RGB
     * (the guy who wrote this convention never heard of endianness ?)
     */

    yuv2rgb_init (((instance->vinfo.depth == 24) ?
		   instance->frame[0].ximage->bits_per_pixel :
		   instance->vinfo.depth),
		  ((instance->frame[0].ximage->blue_mask & 0x01) ?
		   MODE_RGB : MODE_BGR));

    if (libvo_common_alloc_frames ((vo_instance_t *) instance,
				   instance->width, instance->height,
				   sizeof (x11_frame_t), x11_copy_slice,
				   x11_field, x11_draw_frame)) {
	fprintf (stderr, "Can not allocate yuv backing buffers\n");
	return 1;
    }

    return 0;
}

static void x11_close (vo_instance_t * _instance)
{
    x11_instance_t * instance = (x11_instance_t *) _instance;
    int i;

    libvo_common_free_frames ((vo_instance_t *) instance);
    for (i = 0; i < 3; i++) {
	while (instance->frame[i].wait_completion)
	    x11_event (instance);
	XDestroyImage (instance->frame[i].ximage);
    }
    destroy_shm (instance);
    XFreeGC (instance->display, instance->gc);
    XDestroyWindow (instance->display, instance->window);
    XCloseDisplay (instance->display);
}

#ifdef LIBVO_XV
static void xv_event (x11_instance_t * instance)
{
    XEvent event;
    char * addr;
    int i;

    XNextEvent (instance->display, &event);
    if (event.type == instance->completion_type) {
	addr = (instance->shminfo.shmaddr +
		((XShmCompletionEvent *)&event)->offset);
	for (i = 0; i < 3; i++)
	    if (addr == instance->frame[i].xvimage->data)
		instance->frame[i].wait_completion = 0;
    }
}

static vo_frame_t * xv_get_frame (vo_instance_t * _instance, int flags)
{
    x11_instance_t * instance;
    x11_frame_t * frame;

    instance = (x11_instance_t *) _instance;
    frame = (x11_frame_t *) libvo_common_get_frame ((vo_instance_t *) instance,
						    flags);

    while (frame->wait_completion)
	xv_event (instance);

    return (vo_frame_t *) frame;
}

static void xv_draw_frame (vo_frame_t * _frame)
{
    x11_frame_t * frame;
    x11_instance_t * instance;

    frame = (x11_frame_t *) _frame;
    instance = (x11_instance_t *) frame->vo.instance;

    XvShmPutImage (instance->display, instance->port, instance->window,
		   instance->gc, frame->xvimage, 0, 0,
		   instance->width, instance->height, 0, 0,
		   instance->width, instance->height, True);
    XFlush (instance->display);
    frame->wait_completion = 1;
}

static int xv_check_yv12 (x11_instance_t * instance, XvPortID port)
{
    XvImageFormatValues * formatValues;
    int formats;
    int i;

    formatValues = XvListImageFormats (instance->display, port, &formats);
    for (i = 0; i < formats; i++)
	if ((formatValues[i].id == FOURCC_YV12) &&
	    (! (strcmp (formatValues[i].guid, "YV12")))) {
	    XFree (formatValues);
	    return 0;
	}
    XFree (formatValues);
    return 1;
}

static int xv_check_extension (x11_instance_t * instance)
{
    unsigned int version;
    unsigned int release;
    unsigned int dummy;
    int adaptors;
    int i;
    unsigned long j;
    XvAdaptorInfo * adaptorInfo;

    if ((XvQueryExtension (instance->display, &version, &release,
			   &dummy, &dummy, &dummy) != Success) ||
	(version < 2) || ((version == 2) && (release < 2))) {
	fprintf (stderr, "No xv extension\n");
	return 1;
    }

    XvQueryAdaptors (instance->display, instance->window, &adaptors,
		     &adaptorInfo);

    for (i = 0; i < adaptors; i++)
	if (adaptorInfo[i].type & XvImageMask)
	    for (j = 0; j < adaptorInfo[i].num_ports; j++)
		if ((! (xv_check_yv12 (instance,
				       adaptorInfo[i].base_id + j))) &&
		    (XvGrabPort (instance->display, adaptorInfo[i].base_id + j,
				 0) == Success)) {
		    instance->port = adaptorInfo[i].base_id + j;
		    XvFreeAdaptorInfo (adaptorInfo);
		    return 0;
		}

    XvFreeAdaptorInfo (adaptorInfo);
    fprintf (stderr, "Cannot find xv port\n");
    return 1;
}

static int xv_alloc_frames (x11_instance_t * instance)
{
    int size;
    uint8_t * alloc;
    int i;

    size = instance->width * instance->height / 4;
    alloc = create_shm (instance, 18 * size);
    if (alloc == NULL)
	return 1;

    for (i = 0; i < 3; i++) {
	instance->frame_ptr[i] = (vo_frame_t *) (instance->frame + i);
	instance->frame[i].vo.base[0] = alloc;
	instance->frame[i].vo.base[1] = alloc + 5 * size;
	instance->frame[i].vo.base[2] = alloc + 4 * size;
	instance->frame[i].vo.copy = NULL;
	instance->frame[i].vo.field = NULL;
	instance->frame[i].vo.draw = xv_draw_frame;
	instance->frame[i].vo.instance = (vo_instance_t *) instance;
	instance->frame[i].wait_completion = 0;
	instance->frame[i].xvimage =
	    XvShmCreateImage (instance->display, instance->port, FOURCC_YV12,
			      alloc, instance->width, instance->height,
			      &(instance->shminfo));
	if ((instance->frame[i].xvimage == NULL) ||
	    (instance->frame[i].xvimage->data_size != 6 * size)) { /* FIXME */
	    fprintf (stderr, "Cannot create xvimage\n");
	    return 1;
	}
	alloc += 6 * size;
    }

    return 0;
}

static void xv_close (vo_instance_t * _instance)
{
    x11_instance_t * instance = (x11_instance_t *) _instance;
    int i;

    for (i = 0; i < 3; i++) {
	while (instance->frame[i].wait_completion)
	    xv_event (instance);
	XFree (instance->frame[i].xvimage);
    }
    destroy_shm (instance);
    XvUngrabPort (instance->display, instance->port, 0);
    XFreeGC (instance->display, instance->gc);
    XDestroyWindow (instance->display, instance->window);
    XCloseDisplay (instance->display);
}
#endif

static int common_setup (x11_instance_t * instance, int width, int height,
			 int xv)
{
    instance->width = width;
    instance->height = height;

    if (open_display (instance))
	return 1;

#ifdef LIBVO_XV
    if (xv && (! (xv_check_extension (instance)))) {
	if (xv_alloc_frames (instance))
	    return 1;
	instance->vo.close = xv_close;
	instance->vo.get_frame = xv_get_frame;
    } else
#endif
    {
	if (x11_alloc_frames (instance))
	    return 1;
	instance->vo.close = x11_close;
	instance->vo.get_frame = x11_get_frame;
    }

    XMapWindow (instance->display, instance->window);

    return 0;
}

static int x11_setup (vo_instance_t * instance, int width, int height)
{
    return common_setup ((x11_instance_t *) instance, width, height, 0);
}

vo_instance_t * vo_x11_open (void)
{
    x11_instance_t * instance;

    instance = malloc (sizeof (x11_instance_t));
    if (instance == NULL)
	return NULL;

    instance->vo.setup = x11_setup;
    return (vo_instance_t *) instance;
}

#ifdef LIBVO_XV
static int xv_setup (vo_instance_t * instance, int width, int height)
{
    return common_setup ((x11_instance_t *) instance, width, height, 1);
}

vo_instance_t * vo_xv_open (void)
{
    x11_instance_t * instance;

    instance = malloc (sizeof (x11_instance_t));
    if (instance == NULL)
	return NULL;

    instance->vo.setup = xv_setup;
    return (vo_instance_t *) instance;
}
#endif
#endif

--- NEW FILE ---
/*
 * yuv2rgb.c
 * Copyright (C) 1999-2001 Aaron Holtzman <aholtzma at ess.engr.uvic.ca>
 *
 * This file is part of mpeg2dec, a free MPEG-2 video stream decoder.
 *
 * mpeg2dec is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * mpeg2dec is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

#include "config.h"

#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>

#include "yuv2rgb.h"
#include "mm_accel.h"
#include "video_out.h"
#include "video_out_internal.h"

uint32_t matrix_coefficients = 6;

const int32_t Inverse_Table_6_9[8][4] = {
    {117504, 138453, 13954, 34903}, /* no sequence_display_extension */
    {117504, 138453, 13954, 34903}, /* ITU-R Rec. 709 (1990) */
    {104597, 132201, 25675, 53279}, /* unspecified */
    {104597, 132201, 25675, 53279}, /* reserved */
    {104448, 132798, 24759, 53109}, /* FCC */
    {104597, 132201, 25675, 53279}, /* ITU-R Rec. 624-4 System B, G */
    {104597, 132201, 25675, 53279}, /* SMPTE 170M */
    {117579, 136230, 16907, 35559}  /* SMPTE 240M (1987) */
};

static void yuv2rgb_c_init (int bpp, int mode);

yuv2rgb_fun yuv2rgb;

static void (* yuv2rgb_c_internal) (uint8_t *, uint8_t *,
				    uint8_t *, uint8_t *,
				    void *, void *, int);

static void yuv2rgb_c (void * dst, uint8_t * py,
		       uint8_t * pu, uint8_t * pv,
		       int width, int height,
		       int rgb_stride, int y_stride, int uv_stride)
{
    height >>= 1;
    do {
	yuv2rgb_c_internal (py, py + y_stride, pu, pv,
			    dst, ((uint8_t *)dst) + rgb_stride, width);

	py += 2 * y_stride;
	pu += uv_stride;
	pv += uv_stride;
	dst = ((uint8_t *)dst) + 2 * rgb_stride;
    } while (--height);
}

void yuv2rgb_init (int bpp, int mode) 
{
    yuv2rgb = NULL;
#ifdef ARCH_X86
    if ((yuv2rgb == NULL) && (vo_mm_accel & MM_ACCEL_X86_MMXEXT)) {
	yuv2rgb = yuv2rgb_init_mmxext (bpp, mode);
	if (yuv2rgb != NULL)
	    fprintf (stderr, "Using MMXEXT for colorspace transform\n");
    }
    if ((yuv2rgb == NULL) && (vo_mm_accel & MM_ACCEL_X86_MMX)) {
	yuv2rgb = yuv2rgb_init_mmx (bpp, mode);
	if (yuv2rgb != NULL)
	    fprintf (stderr, "Using MMX for colorspace transform\n");
    }
#endif
#ifdef LIBVO_MLIB
    if ((yuv2rgb == NULL) && (vo_mm_accel & MM_ACCEL_MLIB)) {
	yuv2rgb = yuv2rgb_init_mlib (bpp, mode);
	if (yuv2rgb != NULL)
	    fprintf (stderr, "Using mlib for colorspace transform\n");
    }
#endif
    if (yuv2rgb == NULL) {
	fprintf (stderr, "No accelerated colorspace conversion found\n");
	yuv2rgb_c_init (bpp, mode);
	yuv2rgb = (yuv2rgb_fun) yuv2rgb_c;
    }
}

void * table_rV[256];
void * table_gU[256];
int table_gV[256];
void * table_bU[256];

#define RGB(i)							\
	U = pu[i];						\
	V = pv[i];						\
	r = table_rV[V];					\
	g = (void *) (((uint8_t *)table_gU[U]) + table_gV[V]);	\
	b = table_bU[U];

#define DST1(i)					\
	Y = py_1[2*i];				\
	dst_1[2*i] = r[Y] + g[Y] + b[Y];	\
	Y = py_1[2*i+1];			\
	dst_1[2*i+1] = r[Y] + g[Y] + b[Y];

#define DST2(i)					\
	Y = py_2[2*i];				\
	dst_2[2*i] = r[Y] + g[Y] + b[Y];	\
	Y = py_2[2*i+1];			\
	dst_2[2*i+1] = r[Y] + g[Y] + b[Y];

#define DST1RGB(i)							\
	Y = py_1[2*i];							\
	dst_1[6*i] = r[Y]; dst_1[6*i+1] = g[Y]; dst_1[6*i+2] = b[Y];	\
	Y = py_1[2*i+1];						\
	dst_1[6*i+3] = r[Y]; dst_1[6*i+4] = g[Y]; dst_1[6*i+5] = b[Y];

#define DST2RGB(i)							\
	Y = py_2[2*i];							\
	dst_2[6*i] = r[Y]; dst_2[6*i+1] = g[Y]; dst_2[6*i+2] = b[Y];	\
	Y = py_2[2*i+1];						\
	dst_2[6*i+3] = r[Y]; dst_2[6*i+4] = g[Y]; dst_2[6*i+5] = b[Y];

#define DST1BGR(i)							\
	Y = py_1[2*i];							\
	dst_1[6*i] = b[Y]; dst_1[6*i+1] = g[Y]; dst_1[6*i+2] = r[Y];	\
	Y = py_1[2*i+1];						\
	dst_1[6*i+3] = b[Y]; dst_1[6*i+4] = g[Y]; dst_1[6*i+5] = r[Y];

#define DST2BGR(i)							\
	Y = py_2[2*i];							\
	dst_2[6*i] = b[Y]; dst_2[6*i+1] = g[Y]; dst_2[6*i+2] = r[Y];	\
	Y = py_2[2*i+1];						\
	dst_2[6*i+3] = b[Y]; dst_2[6*i+4] = g[Y]; dst_2[6*i+5] = r[Y];

static void yuv2rgb_c_32 (uint8_t * py_1, uint8_t * py_2,
			  uint8_t * pu, uint8_t * pv,
			  void * _dst_1, void * _dst_2, int width)
{
    int U, V, Y;
    uint32_t * r, * g, * b;
    uint32_t * dst_1, * dst_2;

    width >>= 3;
    dst_1 = _dst_1;
    dst_2 = _dst_2;

    do {
	RGB(0);
	DST1(0);
	DST2(0);

	RGB(1);
	DST2(1);
	DST1(1);

	RGB(2);
	DST1(2);
	DST2(2);

	RGB(3);
	DST2(3);
	DST1(3);

	pu += 4;
	pv += 4;
	py_1 += 8;
	py_2 += 8;
	dst_1 += 8;
	dst_2 += 8;
    } while (--width);
}

/* This is very near from the yuv2rgb_c_32 code */
static void yuv2rgb_c_24_rgb (uint8_t * py_1, uint8_t * py_2,
			      uint8_t * pu, uint8_t * pv,
			      void * _dst_1, void * _dst_2, int width)
{
    int U, V, Y;
    uint8_t * r, * g, * b;
    uint8_t * dst_1, * dst_2;

    width >>= 3;
    dst_1 = _dst_1;
    dst_2 = _dst_2;

    do {
	RGB(0);
	DST1RGB(0);
	DST2RGB(0);

	RGB(1);
	DST2RGB(1);
	DST1RGB(1);

	RGB(2);
	DST1RGB(2);
	DST2RGB(2);

	RGB(3);
	DST2RGB(3);
	DST1RGB(3);

	pu += 4;
	pv += 4;
	py_1 += 8;
	py_2 += 8;
	dst_1 += 24;
	dst_2 += 24;
    } while (--width);
}

/* only trivial mods from yuv2rgb_c_24_rgb */
static void yuv2rgb_c_24_bgr (uint8_t * py_1, uint8_t * py_2,
			      uint8_t * pu, uint8_t * pv,
			      void * _dst_1, void * _dst_2, int width)
{
    int U, V, Y;
    uint8_t * r, * g, * b;
    uint8_t * dst_1, * dst_2;

    width >>= 3;
    dst_1 = _dst_1;
    dst_2 = _dst_2;

    do {
	RGB(0);
	DST1BGR(0);
	DST2BGR(0);

	RGB(1);
	DST2BGR(1);
	DST1BGR(1);

	RGB(2);
	DST1BGR(2);
	DST2BGR(2);

	RGB(3);
	DST2BGR(3);
	DST1BGR(3);

	pu += 4;
	pv += 4;
	py_1 += 8;
	py_2 += 8;
	dst_1 += 24;
	dst_2 += 24;
    } while (--width);
}

/* This is exactly the same code as yuv2rgb_c_32 except for the types of */
/* r, g, b, dst_1, dst_2 */
static void yuv2rgb_c_16 (uint8_t * py_1, uint8_t * py_2,
			  uint8_t * pu, uint8_t * pv,
			  void * _dst_1, void * _dst_2, int width)
{
    int U, V, Y;
    uint16_t * r, * g, * b;
    uint16_t * dst_1, * dst_2;

    width >>= 3;
    dst_1 = _dst_1;
    dst_2 = _dst_2;

    do {
	RGB(0);
	DST1(0);
	DST2(0);

	RGB(1);
	DST2(1);
	DST1(1);

	RGB(2);
	DST1(2);
	DST2(2);

	RGB(3);
	DST2(3);
	DST1(3);

	pu += 4;
	pv += 4;
	py_1 += 8;
	py_2 += 8;
	dst_1 += 8;
	dst_2 += 8;
    } while (--width);
}

static int div_round (int dividend, int divisor)
{
    if (dividend > 0)
	return (dividend + (divisor>>1)) / divisor;
    else
	return -((-dividend + (divisor>>1)) / divisor);
}

static void yuv2rgb_c_init (int bpp, int mode)
{  
    int i;
    uint8_t table_Y[1024];
    uint32_t * table_32 = 0;
    uint16_t * table_16 = 0;
    uint8_t * table_8 = 0;
    int entry_size = 0;
    void *table_r = 0, *table_g = 0, *table_b = 0;

    int crv = Inverse_Table_6_9[matrix_coefficients][0];
    int cbu = Inverse_Table_6_9[matrix_coefficients][1];
    int cgu = -Inverse_Table_6_9[matrix_coefficients][2];
    int cgv = -Inverse_Table_6_9[matrix_coefficients][3];

    for (i = 0; i < 1024; i++) {
	int j;

	j = (76309 * (i - 384 - 16) + 32768) >> 16;
	j = (j < 0) ? 0 : ((j > 255) ? 255 : j);
	table_Y[i] = j;
    }

    switch (bpp) {
    case 32:
	yuv2rgb_c_internal = yuv2rgb_c_32;

	table_32 = malloc ((197 + 2*682 + 256 + 132) * sizeof (uint32_t));

	entry_size = sizeof (uint32_t);
	table_r = table_32 + 197;
	table_b = table_32 + 197 + 685;
	table_g = table_32 + 197 + 2*682;

	for (i = -197; i < 256+197; i++)
	    ((uint32_t *) table_r)[i] =
		table_Y[i+384] << ((mode==MODE_RGB) ? 16 : 0);
	for (i = -132; i < 256+132; i++)
	    ((uint32_t *) table_g)[i] = table_Y[i+384] << 8;
	for (i = -232; i < 256+232; i++)
	    ((uint32_t *) table_b)[i] =
		table_Y[i+384] << ((mode==MODE_RGB) ? 0 : 16);
	break;

    case 24:
	yuv2rgb_c_internal = (mode==MODE_RGB) ? yuv2rgb_c_24_rgb : yuv2rgb_c_24_bgr;

	table_8 = malloc ((256 + 2*232) * sizeof (uint8_t));

	entry_size = sizeof (uint8_t);
	table_r = table_g = table_b = table_8 + 232;

	for (i = -232; i < 256+232; i++)
	    ((uint8_t * )table_b)[i] = table_Y[i+384];
	break;

    case 15:
    case 16:
	yuv2rgb_c_internal = yuv2rgb_c_16;

	table_16 = malloc ((197 + 2*682 + 256 + 132) * sizeof (uint16_t));

	entry_size = sizeof (uint16_t);
	table_r = table_16 + 197;
	table_b = table_16 + 197 + 685;
	table_g = table_16 + 197 + 2*682;

	for (i = -197; i < 256+197; i++) {
	    int j = table_Y[i+384] >> 3;

	    if (mode == MODE_RGB)
		j <<= ((bpp==16) ? 11 : 10);

	    ((uint16_t *)table_r)[i] = j;
	}
	for (i = -132; i < 256+132; i++) {
	    int j = table_Y[i+384] >> ((bpp==16) ? 2 : 3);

	    ((uint16_t *)table_g)[i] = j << 5;
	}
	for (i = -232; i < 256+232; i++) {
	    int j = table_Y[i+384] >> 3;

	    if (mode == MODE_BGR)
		j <<= ((bpp==16) ? 11 : 10);

	    ((uint16_t *)table_b)[i] = j;
	}
	break;

    default:
	fprintf (stderr, "%ibpp not supported by yuv2rgb\n", bpp);
	exit (1);
    }

    for (i = 0; i < 256; i++) {
	table_rV[i] = (((uint8_t *)table_r) +
		       entry_size * div_round (crv * (i-128), 76309));
	table_gU[i] = (((uint8_t *)table_g) +
		       entry_size * div_round (cgu * (i-128), 76309));
	table_gV[i] = entry_size * div_round (cgv * (i-128), 76309);
	table_bU[i] = (((uint8_t *)table_b) +
		       entry_size * div_round (cbu * (i-128), 76309));
    }
}

--- NEW FILE ---
/*
 * yuv2rgb.h
 * Copyright (C) 1999-2001 Aaron Holtzman <aholtzma at ess.engr.uvic.ca>
 *
 * This file is part of mpeg2dec, a free MPEG-2 video stream decoder.
 *
 * mpeg2dec is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * mpeg2dec is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

#define MODE_RGB  0x1
#define MODE_BGR  0x2

typedef void (* yuv2rgb_fun) (uint8_t * image, uint8_t * py,
			      uint8_t * pu, uint8_t * pv,
			      int h_size, int v_size,
			      int rgb_stride, int y_stride, int uv_stride);

extern yuv2rgb_fun yuv2rgb;

void yuv2rgb_init (int bpp, int mode);
yuv2rgb_fun yuv2rgb_init_mmxext (int bpp, int mode);
yuv2rgb_fun yuv2rgb_init_mmx (int bpp, int mode);
yuv2rgb_fun yuv2rgb_init_mlib (int bpp, int mode);

--- NEW FILE ---
/*
 * yuv2rgb_mlib.c
 * Copyright (C) 2000-2001 Håkan Hjort <d95hjort at dtek.chalmers.se>
 *
 * This file is part of mpeg2dec, a free MPEG-2 video stream decoder.
 *
 * mpeg2dec is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * mpeg2dec is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

#include "config.h"

#ifdef LIBVO_MLIB

#include <stddef.h>
#include <inttypes.h>
#include <mlib_types.h>
#include <mlib_status.h>
#include <mlib_sys.h>
#include <mlib_video.h>

#include "yuv2rgb.h"

static void mlib_YUV2ARGB420_32 (uint8_t * image, uint8_t * py, 
				 uint8_t * pu, uint8_t * pv, 
				 int h_size, int v_size, 
				 int rgb_stride, int y_stride, int uv_stride)
{
    mlib_VideoColorYUV2ARGB420 (image, py, pu, pv, h_size,
				v_size, rgb_stride, y_stride, uv_stride);
}

static void mlib_YUV2ABGR420_32 (uint8_t * image, uint8_t * py, 
				 uint8_t * pu, uint8_t * pv, 
				 int h_size, int v_size, 
				 int rgb_stride, int y_stride, int uv_stride)
{
    mlib_VideoColorYUV2ABGR420 (image, py, pu, pv, h_size,
				v_size, rgb_stride, y_stride, uv_stride);
}

static void mlib_YUV2RGB420_24 (uint8_t * image, uint8_t * py, 
				uint8_t * pu, uint8_t * pv, 
				int h_size, int v_size, 
				int rgb_stride, int y_stride, int uv_stride)
{
    mlib_VideoColorYUV2RGB420 (image, py, pu, pv, h_size,
			       v_size, rgb_stride, y_stride, uv_stride);
}

yuv2rgb_fun yuv2rgb_init_mlib(int bpp, int mode) 
{
    if (bpp == 24) {
	if (mode == MODE_RGB)
	    return mlib_YUV2RGB420_24;
    } else if(bpp == 32) {
	if (mode == MODE_RGB)
	    return mlib_YUV2ARGB420_32;
	else if (mode == MODE_BGR)
	    return mlib_YUV2ABGR420_32;
    }
  
    return NULL;
}

#endif

--- NEW FILE ---
/*
 * yuv2rgb_mmx.c
 * Copyright (C) 2000-2001 Silicon Integrated System Corp.
 * All Rights Reserved.
 *
 * Author: Olie Lho <ollie at sis.com.tw>
 *
 * This file is part of mpeg2dec, a free MPEG-2 video stream decoder.
 *
 * mpeg2dec is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * mpeg2dec is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

#include "config.h"

#ifdef ARCH_X86

#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>

#include "attributes.h"
#include "mmx.h"
#include "yuv2rgb.h"

#define CPU_MMXEXT 0
#define CPU_MMX 1

/* CPU_MMXEXT/CPU_MMX adaptation layer */

#define movntq(src,dest)	\
do {				\
    if (cpu == CPU_MMXEXT)	\
	movntq_r2m (src, dest);	\
    else			\
	movq_r2m (src, dest);	\
} while (0)

static inline void mmx_yuv2rgb (uint8_t * py, uint8_t * pu, uint8_t * pv)
{
    static mmx_t mmx_80w = {0x0080008000800080};
    static mmx_t mmx_U_green = {0xf37df37df37df37d};
    static mmx_t mmx_U_blue = {0x4093409340934093};
    static mmx_t mmx_V_red = {0x3312331233123312};
    static mmx_t mmx_V_green = {0xe5fce5fce5fce5fc};
    static mmx_t mmx_10w = {0x1010101010101010};
    static mmx_t mmx_00ffw = {0x00ff00ff00ff00ff};
    static mmx_t mmx_Y_coeff = {0x253f253f253f253f};

    movd_m2r (*pu, mm0);		// mm0 = 00 00 00 00 u3 u2 u1 u0
    movd_m2r (*pv, mm1);		// mm1 = 00 00 00 00 v3 v2 v1 v0
    movq_m2r (*py, mm6);		// mm6 = Y7 Y6 Y5 Y4 Y3 Y2 Y1 Y0
    pxor_r2r (mm4, mm4);		// mm4 = 0
    /* XXX might do cache preload for image here */

    /*
     * Do the multiply part of the conversion for even and odd pixels
     * register usage:
     * mm0 -> Cblue, mm1 -> Cred, mm2 -> Cgreen even pixels
     * mm3 -> Cblue, mm4 -> Cred, mm5 -> Cgreen odd  pixels
     * mm6 -> Y even, mm7 -> Y odd
     */

    punpcklbw_r2r (mm4, mm0);		// mm0 = u3 u2 u1 u0
    punpcklbw_r2r (mm4, mm1);		// mm1 = v3 v2 v1 v0
    psubsw_m2r (mmx_80w, mm0);		// u -= 128
    psubsw_m2r (mmx_80w, mm1);		// v -= 128
    psllw_i2r (3, mm0);			// promote precision
    psllw_i2r (3, mm1);			// promote precision
    movq_r2r (mm0, mm2);		// mm2 = u3 u2 u1 u0
    movq_r2r (mm1, mm3);		// mm3 = v3 v2 v1 v0
    pmulhw_m2r (mmx_U_green, mm2);	// mm2 = u * u_green
    pmulhw_m2r (mmx_V_green, mm3);	// mm3 = v * v_green
    pmulhw_m2r (mmx_U_blue, mm0);	// mm0 = chroma_b
    pmulhw_m2r (mmx_V_red, mm1);	// mm1 = chroma_r
    paddsw_r2r (mm3, mm2);		// mm2 = chroma_g

    psubusb_m2r (mmx_10w, mm6);		// Y -= 16
    movq_r2r (mm6, mm7);		// mm7 = Y7 Y6 Y5 Y4 Y3 Y2 Y1 Y0
    pand_m2r (mmx_00ffw, mm6);		// mm6 =    Y6    Y4    Y2    Y0
    psrlw_i2r (8, mm7);			// mm7 =    Y7    Y5    Y3    Y1
    psllw_i2r (3, mm6);			// promote precision
    psllw_i2r (3, mm7);			// promote precision
    pmulhw_m2r (mmx_Y_coeff, mm6);	// mm6 = luma_rgb even
    pmulhw_m2r (mmx_Y_coeff, mm7);	// mm7 = luma_rgb odd

    /*
     * Do the addition part of the conversion for even and odd pixels
     * register usage:
     * mm0 -> Cblue, mm1 -> Cred, mm2 -> Cgreen even pixels
     * mm3 -> Cblue, mm4 -> Cred, mm5 -> Cgreen odd  pixels
     * mm6 -> Y even, mm7 -> Y odd
     */

    movq_r2r (mm0, mm3);		// mm3 = chroma_b
    movq_r2r (mm1, mm4);		// mm4 = chroma_r
    movq_r2r (mm2, mm5);		// mm5 = chroma_g
    paddsw_r2r (mm6, mm0);		// mm0 = B6 B4 B2 B0
    paddsw_r2r (mm7, mm3);		// mm3 = B7 B5 B3 B1
    paddsw_r2r (mm6, mm1);		// mm1 = R6 R4 R2 R0
    paddsw_r2r (mm7, mm4);		// mm4 = R7 R5 R3 R1
    paddsw_r2r (mm6, mm2);		// mm2 = G6 G4 G2 G0
    paddsw_r2r (mm7, mm5);		// mm5 = G7 G5 G3 G1
    packuswb_r2r (mm0, mm0);		// saturate to 0-255
    packuswb_r2r (mm1, mm1);		// saturate to 0-255
    packuswb_r2r (mm2, mm2);		// saturate to 0-255
    packuswb_r2r (mm3, mm3);		// saturate to 0-255
    packuswb_r2r (mm4, mm4);		// saturate to 0-255
    packuswb_r2r (mm5, mm5);		// saturate to 0-255
    punpcklbw_r2r (mm3, mm0);		// mm0 = B7 B6 B5 B4 B3 B2 B1 B0
    punpcklbw_r2r (mm4, mm1);		// mm1 = R7 R6 R5 R4 R3 R2 R1 R0
    punpcklbw_r2r (mm5, mm2);		// mm2 = G7 G6 G5 G4 G3 G2 G1 G0
}

static inline void mmx_unpack_16rgb (uint8_t * image, int cpu)
{
    static mmx_t mmx_bluemask = {0xf8f8f8f8f8f8f8f8};
    static mmx_t mmx_greenmask = {0xfcfcfcfcfcfcfcfc};
    static mmx_t mmx_redmask = {0xf8f8f8f8f8f8f8f8};

    /*
     * convert RGB plane to RGB 16 bits
     * mm0 -> B, mm1 -> R, mm2 -> G
     * mm4 -> GB, mm5 -> AR pixel 4-7
     * mm6 -> GB, mm7 -> AR pixel 0-3
     */

    pand_m2r (mmx_bluemask, mm0);	// mm0 = b7b6b5b4b3______
    pand_m2r (mmx_greenmask, mm2);	// mm2 = g7g6g5g4g3g2____
    pand_m2r (mmx_redmask, mm1);	// mm1 = r7r6r5r4r3______
    psrlq_i2r (3, mm0);			// mm0 = ______b7b6b5b4b3
    pxor_r2r (mm4, mm4);		// mm4 = 0
    movq_r2r (mm0, mm5);		// mm5 = ______b7b6b5b4b3
    movq_r2r (mm2, mm7);		// mm7 = g7g6g5g4g3g2____

    punpcklbw_r2r (mm4, mm2);
    punpcklbw_r2r (mm1, mm0);
    psllq_i2r (3, mm2);
    por_r2r (mm2, mm0);
    movntq (mm0, *image);

    punpckhbw_r2r (mm4, mm7);
    punpckhbw_r2r (mm1, mm5);
    psllq_i2r (3, mm7);
    por_r2r (mm7, mm5);
    movntq (mm5, *(image+8));
}

static inline void mmx_unpack_32rgb (uint8_t * image, int cpu)
{
    /*
     * convert RGB plane to RGB packed format,
     * mm0 -> B, mm1 -> R, mm2 -> G, mm3 -> 0,
     * mm4 -> GB, mm5 -> AR pixel 4-7,
     * mm6 -> GB, mm7 -> AR pixel 0-3
     */

    pxor_r2r (mm3, mm3);
    movq_r2r (mm0, mm6);
    movq_r2r (mm1, mm7);
    movq_r2r (mm0, mm4);
    movq_r2r (mm1, mm5);
    punpcklbw_r2r (mm2, mm6);
    punpcklbw_r2r (mm3, mm7);
    punpcklwd_r2r (mm7, mm6);
    movntq (mm6, *image);
    movq_r2r (mm0, mm6);
    punpcklbw_r2r (mm2, mm6);
    punpckhwd_r2r (mm7, mm6);
    movntq (mm6, *(image+8));
    punpckhbw_r2r (mm2, mm4);
    punpckhbw_r2r (mm3, mm5);
    punpcklwd_r2r (mm5, mm4);
    movntq (mm4, *(image+16));
    movq_r2r (mm0, mm4);
    punpckhbw_r2r (mm2, mm4);
    punpckhwd_r2r (mm5, mm4);
    movntq (mm4, *(image+24));
}

static inline void yuv420_rgb16 (uint8_t * image,
				 uint8_t * py, uint8_t * pu, uint8_t * pv,
				 int width, int height,
				 int rgb_stride, int y_stride, int uv_stride,
				 int cpu)
{
    int i;

    rgb_stride -= 2 * width;
    y_stride -= width;
    uv_stride -= width >> 1;
    width >>= 3;

    do {
	i = width;
	do {
	    mmx_yuv2rgb (py, pu, pv);
	    mmx_unpack_16rgb (image, cpu);
	    py += 8;
	    pu += 4;
	    pv += 4;
	    image += 16;
	} while (--i);

	py += y_stride;
	image += rgb_stride;
	if (height & 1) {
	    pu += uv_stride;
	    pv += uv_stride;
	} else {
	    pu -= 4 * width;
	    pv -= 4 * width;
	}
    } while (--height);
}

static inline void yuv420_argb32 (uint8_t * image, uint8_t * py,
				  uint8_t * pu, uint8_t * pv,
				  int width, int height,
				  int rgb_stride, int y_stride, int uv_stride,
				  int cpu)
{
    int i;

    rgb_stride -= 4 * width;
    y_stride -= width;
    uv_stride -= width >> 1;
    width >>= 3;

    do {
	i = width;
	do {
	    mmx_yuv2rgb (py, pu, pv);
	    mmx_unpack_32rgb (image, cpu);
	    py += 8;
	    pu += 4;
	    pv += 4;
	    image += 32;
	} while (--i);

	py += y_stride;
	image += rgb_stride;
	if (height & 1) {
	    pu += uv_stride;
	    pv += uv_stride;
	} else {
	    pu -= 4 * width;
	    pv -= 4 * width;
	}
    } while (--height);
}

static void mmxext_rgb16 (uint8_t * image,
			  uint8_t * py, uint8_t * pu, uint8_t * pv,
			  int width, int height,
			  int rgb_stride, int y_stride, int uv_stride)
{
    yuv420_rgb16 (image, py, pu, pv, width, height,
		  rgb_stride, y_stride, uv_stride, CPU_MMXEXT);
}

static void mmxext_argb32 (uint8_t * image,
			   uint8_t * py, uint8_t * pu, uint8_t * pv,
			   int width, int height,
			   int rgb_stride, int y_stride, int uv_stride)
{
    yuv420_argb32 (image, py, pu, pv, width, height,
		   rgb_stride, y_stride, uv_stride, CPU_MMXEXT);
}

static void mmx_rgb16 (uint8_t * image,
		       uint8_t * py, uint8_t * pu, uint8_t * pv,
		       int width, int height,
		       int rgb_stride, int y_stride, int uv_stride)
{
    yuv420_rgb16 (image, py, pu, pv, width, height,
		  rgb_stride, y_stride, uv_stride, CPU_MMX);
}

static void mmx_argb32 (uint8_t * image,
			uint8_t * py, uint8_t * pu, uint8_t * pv,
			int width, int height,
			int rgb_stride, int y_stride, int uv_stride)
{
    yuv420_argb32 (image, py, pu, pv, width, height,
		   rgb_stride, y_stride, uv_stride, CPU_MMX);
}

yuv2rgb_fun yuv2rgb_init_mmxext (int bpp, int mode)
{
    if ((bpp == 16) && (mode == MODE_RGB))
	return mmxext_rgb16;
    else if ((bpp == 32) && (mode == MODE_RGB))
	return mmxext_argb32;

    return NULL; /* Fallback to C */
}

yuv2rgb_fun yuv2rgb_init_mmx (int bpp, int mode)
{
    if ((bpp == 16) && (mode == MODE_RGB))
	return mmx_rgb16;
    else if ((bpp == 32) && (mode == MODE_RGB))
	return mmx_argb32;

    return NULL; /* Fallback to C */
}
#endif


_______________________________________________
Mplayer-cvslog mailing list
Mplayer-cvslog at lists.sourceforge.net
http://lists.sourceforge.net/lists/listinfo/mplayer-cvslog



More information about the MPlayer-cvslog mailing list