完善目录结构
完善了目录结构,添加了以前的web段com组件调用的代码(在/测试目录下)(部署没有使用到)
This commit is contained in:
@@ -0,0 +1 @@
|
||||
Makefile *.plg *.aps *.o .libs
|
||||
@@ -0,0 +1,80 @@
|
||||
EXTRA_DIST = highgui.dsp highgui.vcproj highgui.rc resource.h \
|
||||
cvcap_cmu.cpp cvcap_tyzx.cpp cvcap_vfw.cpp cvcap_mil.cpp \
|
||||
cvcap_qt.cpp cvcap_dc1394.cpp cvcap_ffmpeg.cpp \
|
||||
cvcap_v4l.cpp cvcap_xine.cpp \
|
||||
window.cpp window_carbon.cpp window_gtk.cpp window_w32.cpp
|
||||
|
||||
INCLUDES = -I. -I$(top_srcdir)/cxcore/include \
|
||||
-I$(top_srcdir)/cv/include @GTHREAD_CFLAGS@ @GTK_CFLAGS@ \
|
||||
@QUICKTIME_CFLAGS@ @CARBON_CFLAGS@
|
||||
|
||||
noinst_HEADERS = \
|
||||
_highgui.h bitstrm.h grfmt_base.h grfmt_bmp.h \
|
||||
grfmt_jpeg.h grfmt_pxm.h grfmt_png.h grfmt_sunras.h grfmt_tiff.h grfmts.h utils.h
|
||||
noinst_LTLIBRARIES = lib_highgui.la
|
||||
lib_LTLIBRARIES = libhighgui.la
|
||||
|
||||
if BUILD_DC1394
|
||||
TMP_DC1394=cvcap_dc1394.cpp
|
||||
else
|
||||
TMP_DC1394=
|
||||
endif
|
||||
|
||||
if BUILD_V4L
|
||||
TMP_V4L=cvcap_v4l.cpp
|
||||
else
|
||||
TMP_V4L=
|
||||
endif
|
||||
|
||||
if BUILD_FFMPEG
|
||||
TMP_FFMPEG=cvcap_ffmpeg.cpp
|
||||
else
|
||||
TMP_FFMPEG=
|
||||
endif
|
||||
|
||||
if BUILD_XINE
|
||||
TMP_XINE=cvcap_xine.cpp
|
||||
else
|
||||
TMP_XINE=
|
||||
endif
|
||||
|
||||
if BUILD_QUICKTIME
|
||||
TMP_QT=cvcap_qt.cpp
|
||||
else
|
||||
TMP_QT=
|
||||
endif
|
||||
|
||||
if BUILD_CARBON
|
||||
TMP_CARBON=window_carbon.cpp
|
||||
else
|
||||
TMP_CARBON=
|
||||
endif
|
||||
|
||||
if BUILD_GTK
|
||||
TMP_GTK=window_gtk.cpp
|
||||
else
|
||||
TMP_GTK=
|
||||
endif
|
||||
|
||||
|
||||
# convenience library
|
||||
lib_highgui_la_SOURCES = \
|
||||
bitstrm.cpp grfmt_base.cpp grfmt_bmp.cpp grfmt_jpeg.cpp \
|
||||
grfmt_png.cpp grfmt_pxm.cpp grfmt_jpeg2000.cpp grfmt_exr.cpp \
|
||||
grfmt_sunras.cpp grfmt_tiff.cpp image.cpp loadsave.cpp \
|
||||
precomp.cpp utils.cpp cvcap.cpp \
|
||||
$(TMP_DC1394) $(TMP_V4L) $(TMP_FFMPEG) $(TMP_QT) \
|
||||
$(TMP_XINE) $(TMP_GTK) $(TMP_CARBON)
|
||||
lib_highgui_la_LDFLAGS = -no-undefined @LDFLAGS@
|
||||
|
||||
# real library
|
||||
libhighguiincludedir = $(includedir)/opencv
|
||||
libhighguiinclude_HEADERS = highgui.h
|
||||
libhighgui_la_SOURCES = dummy.cpp
|
||||
libhighgui_la_LDFLAGS = -no-undefined -version-info @LT_VERSION@ @LDFLAGS@
|
||||
libhighgui_la_LIBADD = \
|
||||
lib_highgui.la \
|
||||
$(top_builddir)/cxcore/src/libcxcore.la \
|
||||
$(top_builddir)/cv/src/libcv.la \
|
||||
@GTHREAD_LIBS@ @GTK_LIBS@ @IMAGELIBS@ @FFMPEGLIBS@ @IEEE1394LIBS@ \
|
||||
@QUICKTIME_LIBS@ @CARBON_LIBS@ @XINE_LIBS@ @LTLIBOBJS@
|
||||
@@ -0,0 +1,682 @@
|
||||
# Makefile.in generated by automake 1.9.6 from Makefile.am.
|
||||
# @configure_input@
|
||||
|
||||
# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
|
||||
# 2003, 2004, 2005 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.
|
||||
|
||||
@SET_MAKE@
|
||||
|
||||
|
||||
srcdir = @srcdir@
|
||||
top_srcdir = @top_srcdir@
|
||||
VPATH = @srcdir@
|
||||
pkgdatadir = $(datadir)/@PACKAGE@
|
||||
pkglibdir = $(libdir)/@PACKAGE@
|
||||
pkgincludedir = $(includedir)/@PACKAGE@
|
||||
top_builddir = ../..
|
||||
am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd
|
||||
INSTALL = @INSTALL@
|
||||
install_sh_DATA = $(install_sh) -c -m 644
|
||||
install_sh_PROGRAM = $(install_sh) -c
|
||||
install_sh_SCRIPT = $(install_sh) -c
|
||||
INSTALL_HEADER = $(INSTALL_DATA)
|
||||
transform = $(program_transform_name)
|
||||
NORMAL_INSTALL = :
|
||||
PRE_INSTALL = :
|
||||
POST_INSTALL = :
|
||||
NORMAL_UNINSTALL = :
|
||||
PRE_UNINSTALL = :
|
||||
POST_UNINSTALL = :
|
||||
build_triplet = @build@
|
||||
host_triplet = @host@
|
||||
target_triplet = @target@
|
||||
subdir = otherlibs/highgui
|
||||
DIST_COMMON = $(libhighguiinclude_HEADERS) $(noinst_HEADERS) \
|
||||
$(srcdir)/Makefile.am $(srcdir)/Makefile.in
|
||||
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
|
||||
am__aclocal_m4_deps = $(top_srcdir)/autotools/aclocal/az_python.m4 \
|
||||
$(top_srcdir)/autotools/aclocal/pkg.m4 \
|
||||
$(top_srcdir)/autotools/aclocal/swig_complete.m4 \
|
||||
$(top_srcdir)/autotools/aclocal/version_at_least.m4 \
|
||||
$(top_srcdir)/configure.in
|
||||
am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
|
||||
$(ACLOCAL_M4)
|
||||
mkinstalldirs = $(SHELL) $(top_srcdir)/autotools/mkinstalldirs
|
||||
CONFIG_HEADER = $(top_builddir)/cvconfig.h
|
||||
CONFIG_CLEAN_FILES =
|
||||
am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`;
|
||||
am__vpath_adj = case $$p in \
|
||||
$(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \
|
||||
*) f=$$p;; \
|
||||
esac;
|
||||
am__strip_dir = `echo $$p | sed -e 's|^.*/||'`;
|
||||
am__installdirs = "$(DESTDIR)$(libdir)" \
|
||||
"$(DESTDIR)$(libhighguiincludedir)"
|
||||
libLTLIBRARIES_INSTALL = $(INSTALL)
|
||||
LTLIBRARIES = $(lib_LTLIBRARIES) $(noinst_LTLIBRARIES)
|
||||
lib_highgui_la_LIBADD =
|
||||
am__lib_highgui_la_SOURCES_DIST = bitstrm.cpp grfmt_base.cpp \
|
||||
grfmt_bmp.cpp grfmt_jpeg.cpp grfmt_png.cpp grfmt_pxm.cpp \
|
||||
grfmt_jpeg2000.cpp grfmt_exr.cpp grfmt_sunras.cpp \
|
||||
grfmt_tiff.cpp image.cpp loadsave.cpp precomp.cpp utils.cpp \
|
||||
cvcap.cpp cvcap_dc1394.cpp cvcap_v4l.cpp cvcap_ffmpeg.cpp \
|
||||
cvcap_qt.cpp cvcap_xine.cpp window_gtk.cpp window_carbon.cpp
|
||||
@BUILD_DC1394_TRUE@am__objects_1 = cvcap_dc1394.lo
|
||||
@BUILD_V4L_TRUE@am__objects_2 = cvcap_v4l.lo
|
||||
@BUILD_FFMPEG_TRUE@am__objects_3 = cvcap_ffmpeg.lo
|
||||
@BUILD_QUICKTIME_TRUE@am__objects_4 = cvcap_qt.lo
|
||||
@BUILD_XINE_TRUE@am__objects_5 = cvcap_xine.lo
|
||||
@BUILD_GTK_TRUE@am__objects_6 = window_gtk.lo
|
||||
@BUILD_CARBON_TRUE@am__objects_7 = window_carbon.lo
|
||||
am_lib_highgui_la_OBJECTS = bitstrm.lo grfmt_base.lo grfmt_bmp.lo \
|
||||
grfmt_jpeg.lo grfmt_png.lo grfmt_pxm.lo grfmt_jpeg2000.lo \
|
||||
grfmt_exr.lo grfmt_sunras.lo grfmt_tiff.lo image.lo \
|
||||
loadsave.lo precomp.lo utils.lo cvcap.lo $(am__objects_1) \
|
||||
$(am__objects_2) $(am__objects_3) $(am__objects_4) \
|
||||
$(am__objects_5) $(am__objects_6) $(am__objects_7)
|
||||
lib_highgui_la_OBJECTS = $(am_lib_highgui_la_OBJECTS)
|
||||
libhighgui_la_DEPENDENCIES = lib_highgui.la \
|
||||
$(top_builddir)/cxcore/src/libcxcore.la \
|
||||
$(top_builddir)/cv/src/libcv.la @LTLIBOBJS@
|
||||
am_libhighgui_la_OBJECTS = dummy.lo
|
||||
libhighgui_la_OBJECTS = $(am_libhighgui_la_OBJECTS)
|
||||
DEFAULT_INCLUDES = -I. -I$(srcdir) -I$(top_builddir)
|
||||
depcomp = $(SHELL) $(top_srcdir)/autotools/depcomp
|
||||
am__depfiles_maybe = depfiles
|
||||
COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
|
||||
$(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
|
||||
LTCOMPILE = $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) \
|
||||
$(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) \
|
||||
$(AM_CFLAGS) $(CFLAGS)
|
||||
CCLD = $(CC)
|
||||
LINK = $(LIBTOOL) --tag=CC --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
|
||||
$(AM_LDFLAGS) $(LDFLAGS) -o $@
|
||||
CXXCOMPILE = $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \
|
||||
$(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS)
|
||||
LTCXXCOMPILE = $(LIBTOOL) --tag=CXX --mode=compile $(CXX) $(DEFS) \
|
||||
$(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) \
|
||||
$(AM_CXXFLAGS) $(CXXFLAGS)
|
||||
CXXLD = $(CXX)
|
||||
CXXLINK = $(LIBTOOL) --tag=CXX --mode=link $(CXXLD) $(AM_CXXFLAGS) \
|
||||
$(CXXFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@
|
||||
SOURCES = $(lib_highgui_la_SOURCES) $(libhighgui_la_SOURCES)
|
||||
DIST_SOURCES = $(am__lib_highgui_la_SOURCES_DIST) \
|
||||
$(libhighgui_la_SOURCES)
|
||||
libhighguiincludeHEADERS_INSTALL = $(INSTALL_HEADER)
|
||||
HEADERS = $(libhighguiinclude_HEADERS) $(noinst_HEADERS)
|
||||
ETAGS = etags
|
||||
CTAGS = ctags
|
||||
DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
|
||||
ACLOCAL = @ACLOCAL@
|
||||
ALLOCA = @ALLOCA@
|
||||
AMDEP_FALSE = @AMDEP_FALSE@
|
||||
AMDEP_TRUE = @AMDEP_TRUE@
|
||||
AMTAR = @AMTAR@
|
||||
AR = @AR@
|
||||
AS = @AS@
|
||||
AUTOCONF = @AUTOCONF@
|
||||
AUTOHEADER = @AUTOHEADER@
|
||||
AUTOMAKE = @AUTOMAKE@
|
||||
AWK = @AWK@
|
||||
BUILD_APPS_FALSE = @BUILD_APPS_FALSE@
|
||||
BUILD_APPS_TRUE = @BUILD_APPS_TRUE@
|
||||
BUILD_CARBON_FALSE = @BUILD_CARBON_FALSE@
|
||||
BUILD_CARBON_TRUE = @BUILD_CARBON_TRUE@
|
||||
BUILD_DC1394_FALSE = @BUILD_DC1394_FALSE@
|
||||
BUILD_DC1394_TRUE = @BUILD_DC1394_TRUE@
|
||||
BUILD_FFMPEG_FALSE = @BUILD_FFMPEG_FALSE@
|
||||
BUILD_FFMPEG_TRUE = @BUILD_FFMPEG_TRUE@
|
||||
BUILD_GTK_FALSE = @BUILD_GTK_FALSE@
|
||||
BUILD_GTK_TRUE = @BUILD_GTK_TRUE@
|
||||
BUILD_PYTHON_WRAPPERS_FALSE = @BUILD_PYTHON_WRAPPERS_FALSE@
|
||||
BUILD_PYTHON_WRAPPERS_TRUE = @BUILD_PYTHON_WRAPPERS_TRUE@
|
||||
BUILD_QUICKTIME_FALSE = @BUILD_QUICKTIME_FALSE@
|
||||
BUILD_QUICKTIME_TRUE = @BUILD_QUICKTIME_TRUE@
|
||||
BUILD_V4L_FALSE = @BUILD_V4L_FALSE@
|
||||
BUILD_V4L_TRUE = @BUILD_V4L_TRUE@
|
||||
BUILD_XINE_FALSE = @BUILD_XINE_FALSE@
|
||||
BUILD_XINE_TRUE = @BUILD_XINE_TRUE@
|
||||
CARBON_CFLAGS = @CARBON_CFLAGS@
|
||||
CARBON_LIBS = @CARBON_LIBS@
|
||||
CC = @CC@
|
||||
CCDEPMODE = @CCDEPMODE@
|
||||
CFLAGS = @CFLAGS@
|
||||
CPP = @CPP@
|
||||
CPPFLAGS = @CPPFLAGS@
|
||||
CXX = @CXX@
|
||||
CXXCPP = @CXXCPP@
|
||||
CXXDEPMODE = @CXXDEPMODE@
|
||||
CXXFLAGS = @CXXFLAGS@
|
||||
CYGPATH_W = @CYGPATH_W@
|
||||
DEBUG = @DEBUG@
|
||||
DEFS = @DEFS@
|
||||
DEPDIR = @DEPDIR@
|
||||
DLLTOOL = @DLLTOOL@
|
||||
ECHO = @ECHO@
|
||||
ECHO_C = @ECHO_C@
|
||||
ECHO_N = @ECHO_N@
|
||||
ECHO_T = @ECHO_T@
|
||||
EGREP = @EGREP@
|
||||
EXEEXT = @EXEEXT@
|
||||
F77 = @F77@
|
||||
FFLAGS = @FFLAGS@
|
||||
FFMPEGLIBS = @FFMPEGLIBS@
|
||||
GREP = @GREP@
|
||||
GTHREAD_CFLAGS = @GTHREAD_CFLAGS@
|
||||
GTHREAD_LIBS = @GTHREAD_LIBS@
|
||||
GTK_CFLAGS = @GTK_CFLAGS@
|
||||
GTK_LIBS = @GTK_LIBS@
|
||||
IEEE1394LIBS = @IEEE1394LIBS@
|
||||
IMAGELIBS = @IMAGELIBS@
|
||||
INSTALL_DATA = @INSTALL_DATA@
|
||||
INSTALL_PROGRAM = @INSTALL_PROGRAM@
|
||||
INSTALL_SCRIPT = @INSTALL_SCRIPT@
|
||||
INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@
|
||||
LDFLAGS = @LDFLAGS@
|
||||
LIBOBJS = @LIBOBJS@
|
||||
LIBS = @LIBS@
|
||||
LIBTOOL = @LIBTOOL@
|
||||
LN_S = @LN_S@
|
||||
LTLIBOBJS = @LTLIBOBJS@
|
||||
LT_VERSION = @LT_VERSION@
|
||||
MAKEINFO = @MAKEINFO@
|
||||
MMAJOR = @MMAJOR@
|
||||
MMINOR = @MMINOR@
|
||||
MSUBMINOR = @MSUBMINOR@
|
||||
OBJDUMP = @OBJDUMP@
|
||||
OBJEXT = @OBJEXT@
|
||||
PACKAGE = @PACKAGE@
|
||||
PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@
|
||||
PACKAGE_NAME = @PACKAGE_NAME@
|
||||
PACKAGE_STRING = @PACKAGE_STRING@
|
||||
PACKAGE_TARNAME = @PACKAGE_TARNAME@
|
||||
PACKAGE_VERSION = @PACKAGE_VERSION@
|
||||
PATH_SEPARATOR = @PATH_SEPARATOR@
|
||||
PKG_CONFIG = @PKG_CONFIG@
|
||||
PYTHON = @PYTHON@
|
||||
PYTHON_CSPEC = @PYTHON_CSPEC@
|
||||
PYTHON_EXEC_PREFIX = @PYTHON_EXEC_PREFIX@
|
||||
PYTHON_LSPEC = @PYTHON_LSPEC@
|
||||
PYTHON_PLATFORM = @PYTHON_PLATFORM@
|
||||
PYTHON_PREFIX = @PYTHON_PREFIX@
|
||||
PYTHON_VERSION = @PYTHON_VERSION@
|
||||
QUICKTIME_CFLAGS = @QUICKTIME_CFLAGS@
|
||||
QUICKTIME_LIBS = @QUICKTIME_LIBS@
|
||||
RANLIB = @RANLIB@
|
||||
SET_MAKE = @SET_MAKE@
|
||||
SHELL = @SHELL@
|
||||
STRIP = @STRIP@
|
||||
SWIG = @SWIG@
|
||||
SWIG_PYTHON_LIBS = @SWIG_PYTHON_LIBS@
|
||||
SWIG_PYTHON_OPT = @SWIG_PYTHON_OPT@
|
||||
SWIG_RUNTIME_LIBS_DIR = @SWIG_RUNTIME_LIBS_DIR@
|
||||
SWIG_VERSION = @SWIG_VERSION@
|
||||
UPDATE_SWIG_WRAPPERS_FALSE = @UPDATE_SWIG_WRAPPERS_FALSE@
|
||||
UPDATE_SWIG_WRAPPERS_TRUE = @UPDATE_SWIG_WRAPPERS_TRUE@
|
||||
VERSION = @VERSION@
|
||||
XINE_LIBS = @XINE_LIBS@
|
||||
ac_ct_CC = @ac_ct_CC@
|
||||
ac_ct_CXX = @ac_ct_CXX@
|
||||
ac_ct_F77 = @ac_ct_F77@
|
||||
am__fastdepCC_FALSE = @am__fastdepCC_FALSE@
|
||||
am__fastdepCC_TRUE = @am__fastdepCC_TRUE@
|
||||
am__fastdepCXX_FALSE = @am__fastdepCXX_FALSE@
|
||||
am__fastdepCXX_TRUE = @am__fastdepCXX_TRUE@
|
||||
am__include = @am__include@
|
||||
am__leading_dot = @am__leading_dot@
|
||||
am__quote = @am__quote@
|
||||
am__tar = @am__tar@
|
||||
am__untar = @am__untar@
|
||||
bindir = @bindir@
|
||||
build = @build@
|
||||
build_alias = @build_alias@
|
||||
build_cpu = @build_cpu@
|
||||
build_os = @build_os@
|
||||
build_vendor = @build_vendor@
|
||||
datadir = @datadir@
|
||||
datarootdir = @datarootdir@
|
||||
docdir = @docdir@
|
||||
dvidir = @dvidir@
|
||||
exec_prefix = @exec_prefix@
|
||||
host = @host@
|
||||
host_alias = @host_alias@
|
||||
host_cpu = @host_cpu@
|
||||
host_os = @host_os@
|
||||
host_vendor = @host_vendor@
|
||||
htmldir = @htmldir@
|
||||
includedir = @includedir@
|
||||
infodir = @infodir@
|
||||
install_sh = @install_sh@
|
||||
libdir = @libdir@
|
||||
libexecdir = @libexecdir@
|
||||
localedir = @localedir@
|
||||
localstatedir = @localstatedir@
|
||||
mandir = @mandir@
|
||||
mkdir_p = @mkdir_p@
|
||||
oldincludedir = @oldincludedir@
|
||||
pdfdir = @pdfdir@
|
||||
pkgpyexecdir = @pkgpyexecdir@
|
||||
pkgpythondir = @pkgpythondir@
|
||||
prefix = @prefix@
|
||||
program_transform_name = @program_transform_name@
|
||||
psdir = @psdir@
|
||||
pyexecdir = @pyexecdir@
|
||||
pythondir = @pythondir@
|
||||
sbindir = @sbindir@
|
||||
sharedstatedir = @sharedstatedir@
|
||||
sysconfdir = @sysconfdir@
|
||||
target = @target@
|
||||
target_alias = @target_alias@
|
||||
target_cpu = @target_cpu@
|
||||
target_os = @target_os@
|
||||
target_vendor = @target_vendor@
|
||||
EXTRA_DIST = highgui.dsp highgui.vcproj highgui.rc resource.h \
|
||||
cvcap_cmu.cpp cvcap_tyzx.cpp cvcap_vfw.cpp cvcap_mil.cpp \
|
||||
cvcap_qt.cpp cvcap_dc1394.cpp cvcap_ffmpeg.cpp \
|
||||
cvcap_v4l.cpp cvcap_xine.cpp \
|
||||
window.cpp window_carbon.cpp window_gtk.cpp window_w32.cpp
|
||||
|
||||
INCLUDES = -I. -I$(top_srcdir)/cxcore/include \
|
||||
-I$(top_srcdir)/cv/include @GTHREAD_CFLAGS@ @GTK_CFLAGS@ \
|
||||
@QUICKTIME_CFLAGS@ @CARBON_CFLAGS@
|
||||
|
||||
noinst_HEADERS = \
|
||||
_highgui.h bitstrm.h grfmt_base.h grfmt_bmp.h \
|
||||
grfmt_jpeg.h grfmt_pxm.h grfmt_png.h grfmt_sunras.h grfmt_tiff.h grfmts.h utils.h
|
||||
|
||||
noinst_LTLIBRARIES = lib_highgui.la
|
||||
lib_LTLIBRARIES = libhighgui.la
|
||||
@BUILD_DC1394_FALSE@TMP_DC1394 =
|
||||
@BUILD_DC1394_TRUE@TMP_DC1394 = cvcap_dc1394.cpp
|
||||
@BUILD_V4L_FALSE@TMP_V4L =
|
||||
@BUILD_V4L_TRUE@TMP_V4L = cvcap_v4l.cpp
|
||||
@BUILD_FFMPEG_FALSE@TMP_FFMPEG =
|
||||
@BUILD_FFMPEG_TRUE@TMP_FFMPEG = cvcap_ffmpeg.cpp
|
||||
@BUILD_XINE_FALSE@TMP_XINE =
|
||||
@BUILD_XINE_TRUE@TMP_XINE = cvcap_xine.cpp
|
||||
@BUILD_QUICKTIME_FALSE@TMP_QT =
|
||||
@BUILD_QUICKTIME_TRUE@TMP_QT = cvcap_qt.cpp
|
||||
@BUILD_CARBON_FALSE@TMP_CARBON =
|
||||
@BUILD_CARBON_TRUE@TMP_CARBON = window_carbon.cpp
|
||||
@BUILD_GTK_FALSE@TMP_GTK =
|
||||
@BUILD_GTK_TRUE@TMP_GTK = window_gtk.cpp
|
||||
|
||||
# convenience library
|
||||
lib_highgui_la_SOURCES = \
|
||||
bitstrm.cpp grfmt_base.cpp grfmt_bmp.cpp grfmt_jpeg.cpp \
|
||||
grfmt_png.cpp grfmt_pxm.cpp grfmt_jpeg2000.cpp grfmt_exr.cpp \
|
||||
grfmt_sunras.cpp grfmt_tiff.cpp image.cpp loadsave.cpp \
|
||||
precomp.cpp utils.cpp cvcap.cpp \
|
||||
$(TMP_DC1394) $(TMP_V4L) $(TMP_FFMPEG) $(TMP_QT) \
|
||||
$(TMP_XINE) $(TMP_GTK) $(TMP_CARBON)
|
||||
|
||||
lib_highgui_la_LDFLAGS = -no-undefined @LDFLAGS@
|
||||
|
||||
# real library
|
||||
libhighguiincludedir = $(includedir)/opencv
|
||||
libhighguiinclude_HEADERS = highgui.h
|
||||
libhighgui_la_SOURCES = dummy.cpp
|
||||
libhighgui_la_LDFLAGS = -no-undefined -version-info @LT_VERSION@ @LDFLAGS@
|
||||
libhighgui_la_LIBADD = \
|
||||
lib_highgui.la \
|
||||
$(top_builddir)/cxcore/src/libcxcore.la \
|
||||
$(top_builddir)/cv/src/libcv.la \
|
||||
@GTHREAD_LIBS@ @GTK_LIBS@ @IMAGELIBS@ @FFMPEGLIBS@ @IEEE1394LIBS@ \
|
||||
@QUICKTIME_LIBS@ @CARBON_LIBS@ @XINE_LIBS@ @LTLIBOBJS@
|
||||
|
||||
all: all-am
|
||||
|
||||
.SUFFIXES:
|
||||
.SUFFIXES: .c .cpp .lo .o .obj
|
||||
$(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(am__configure_deps)
|
||||
@for dep in $?; do \
|
||||
case '$(am__configure_deps)' in \
|
||||
*$$dep*) \
|
||||
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh \
|
||||
&& exit 0; \
|
||||
exit 1;; \
|
||||
esac; \
|
||||
done; \
|
||||
echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu otherlibs/highgui/Makefile'; \
|
||||
cd $(top_srcdir) && \
|
||||
$(AUTOMAKE) --gnu otherlibs/highgui/Makefile
|
||||
.PRECIOUS: Makefile
|
||||
Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
|
||||
@case '$?' in \
|
||||
*config.status*) \
|
||||
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \
|
||||
*) \
|
||||
echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \
|
||||
cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \
|
||||
esac;
|
||||
|
||||
$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES)
|
||||
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
|
||||
|
||||
$(top_srcdir)/configure: $(am__configure_deps)
|
||||
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
|
||||
$(ACLOCAL_M4): $(am__aclocal_m4_deps)
|
||||
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
|
||||
install-libLTLIBRARIES: $(lib_LTLIBRARIES)
|
||||
@$(NORMAL_INSTALL)
|
||||
test -z "$(libdir)" || $(mkdir_p) "$(DESTDIR)$(libdir)"
|
||||
@list='$(lib_LTLIBRARIES)'; for p in $$list; do \
|
||||
if test -f $$p; then \
|
||||
f=$(am__strip_dir) \
|
||||
echo " $(LIBTOOL) --mode=install $(libLTLIBRARIES_INSTALL) $(INSTALL_STRIP_FLAG) '$$p' '$(DESTDIR)$(libdir)/$$f'"; \
|
||||
$(LIBTOOL) --mode=install $(libLTLIBRARIES_INSTALL) $(INSTALL_STRIP_FLAG) "$$p" "$(DESTDIR)$(libdir)/$$f"; \
|
||||
else :; fi; \
|
||||
done
|
||||
|
||||
uninstall-libLTLIBRARIES:
|
||||
@$(NORMAL_UNINSTALL)
|
||||
@set -x; list='$(lib_LTLIBRARIES)'; for p in $$list; do \
|
||||
p=$(am__strip_dir) \
|
||||
echo " $(LIBTOOL) --mode=uninstall rm -f '$(DESTDIR)$(libdir)/$$p'"; \
|
||||
$(LIBTOOL) --mode=uninstall rm -f "$(DESTDIR)$(libdir)/$$p"; \
|
||||
done
|
||||
|
||||
clean-libLTLIBRARIES:
|
||||
-test -z "$(lib_LTLIBRARIES)" || rm -f $(lib_LTLIBRARIES)
|
||||
@list='$(lib_LTLIBRARIES)'; for p in $$list; do \
|
||||
dir="`echo $$p | sed -e 's|/[^/]*$$||'`"; \
|
||||
test "$$dir" != "$$p" || dir=.; \
|
||||
echo "rm -f \"$${dir}/so_locations\""; \
|
||||
rm -f "$${dir}/so_locations"; \
|
||||
done
|
||||
|
||||
clean-noinstLTLIBRARIES:
|
||||
-test -z "$(noinst_LTLIBRARIES)" || rm -f $(noinst_LTLIBRARIES)
|
||||
@list='$(noinst_LTLIBRARIES)'; for p in $$list; do \
|
||||
dir="`echo $$p | sed -e 's|/[^/]*$$||'`"; \
|
||||
test "$$dir" != "$$p" || dir=.; \
|
||||
echo "rm -f \"$${dir}/so_locations\""; \
|
||||
rm -f "$${dir}/so_locations"; \
|
||||
done
|
||||
lib_highgui.la: $(lib_highgui_la_OBJECTS) $(lib_highgui_la_DEPENDENCIES)
|
||||
$(CXXLINK) $(lib_highgui_la_LDFLAGS) $(lib_highgui_la_OBJECTS) $(lib_highgui_la_LIBADD) $(LIBS)
|
||||
libhighgui.la: $(libhighgui_la_OBJECTS) $(libhighgui_la_DEPENDENCIES)
|
||||
$(CXXLINK) -rpath $(libdir) $(libhighgui_la_LDFLAGS) $(libhighgui_la_OBJECTS) $(libhighgui_la_LIBADD) $(LIBS)
|
||||
|
||||
mostlyclean-compile:
|
||||
-rm -f *.$(OBJEXT)
|
||||
|
||||
distclean-compile:
|
||||
-rm -f *.tab.c
|
||||
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/bitstrm.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cvcap.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cvcap_dc1394.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cvcap_ffmpeg.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cvcap_qt.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cvcap_v4l.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cvcap_xine.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/dummy.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/grfmt_base.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/grfmt_bmp.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/grfmt_exr.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/grfmt_jpeg.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/grfmt_jpeg2000.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/grfmt_png.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/grfmt_pxm.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/grfmt_sunras.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/grfmt_tiff.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/image.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/loadsave.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/precomp.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/utils.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/window_carbon.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/window_gtk.Plo@am__quote@
|
||||
|
||||
.c.o:
|
||||
@am__fastdepCC_TRUE@ if $(COMPILE) -MT $@ -MD -MP -MF "$(DEPDIR)/$*.Tpo" -c -o $@ $<; \
|
||||
@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/$*.Tpo" "$(DEPDIR)/$*.Po"; else rm -f "$(DEPDIR)/$*.Tpo"; exit 1; fi
|
||||
@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
|
||||
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
|
||||
@am__fastdepCC_FALSE@ $(COMPILE) -c $<
|
||||
|
||||
.c.obj:
|
||||
@am__fastdepCC_TRUE@ if $(COMPILE) -MT $@ -MD -MP -MF "$(DEPDIR)/$*.Tpo" -c -o $@ `$(CYGPATH_W) '$<'`; \
|
||||
@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/$*.Tpo" "$(DEPDIR)/$*.Po"; else rm -f "$(DEPDIR)/$*.Tpo"; exit 1; fi
|
||||
@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
|
||||
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
|
||||
@am__fastdepCC_FALSE@ $(COMPILE) -c `$(CYGPATH_W) '$<'`
|
||||
|
||||
.c.lo:
|
||||
@am__fastdepCC_TRUE@ if $(LTCOMPILE) -MT $@ -MD -MP -MF "$(DEPDIR)/$*.Tpo" -c -o $@ $<; \
|
||||
@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/$*.Tpo" "$(DEPDIR)/$*.Plo"; else rm -f "$(DEPDIR)/$*.Tpo"; exit 1; fi
|
||||
@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@
|
||||
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
|
||||
@am__fastdepCC_FALSE@ $(LTCOMPILE) -c -o $@ $<
|
||||
|
||||
.cpp.o:
|
||||
@am__fastdepCXX_TRUE@ if $(CXXCOMPILE) -MT $@ -MD -MP -MF "$(DEPDIR)/$*.Tpo" -c -o $@ $<; \
|
||||
@am__fastdepCXX_TRUE@ then mv -f "$(DEPDIR)/$*.Tpo" "$(DEPDIR)/$*.Po"; else rm -f "$(DEPDIR)/$*.Tpo"; exit 1; fi
|
||||
@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
|
||||
@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
|
||||
@am__fastdepCXX_FALSE@ $(CXXCOMPILE) -c -o $@ $<
|
||||
|
||||
.cpp.obj:
|
||||
@am__fastdepCXX_TRUE@ if $(CXXCOMPILE) -MT $@ -MD -MP -MF "$(DEPDIR)/$*.Tpo" -c -o $@ `$(CYGPATH_W) '$<'`; \
|
||||
@am__fastdepCXX_TRUE@ then mv -f "$(DEPDIR)/$*.Tpo" "$(DEPDIR)/$*.Po"; else rm -f "$(DEPDIR)/$*.Tpo"; exit 1; fi
|
||||
@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
|
||||
@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
|
||||
@am__fastdepCXX_FALSE@ $(CXXCOMPILE) -c -o $@ `$(CYGPATH_W) '$<'`
|
||||
|
||||
.cpp.lo:
|
||||
@am__fastdepCXX_TRUE@ if $(LTCXXCOMPILE) -MT $@ -MD -MP -MF "$(DEPDIR)/$*.Tpo" -c -o $@ $<; \
|
||||
@am__fastdepCXX_TRUE@ then mv -f "$(DEPDIR)/$*.Tpo" "$(DEPDIR)/$*.Plo"; else rm -f "$(DEPDIR)/$*.Tpo"; exit 1; fi
|
||||
@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@
|
||||
@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
|
||||
@am__fastdepCXX_FALSE@ $(LTCXXCOMPILE) -c -o $@ $<
|
||||
|
||||
mostlyclean-libtool:
|
||||
-rm -f *.lo
|
||||
|
||||
clean-libtool:
|
||||
-rm -rf .libs _libs
|
||||
|
||||
distclean-libtool:
|
||||
-rm -f libtool
|
||||
uninstall-info-am:
|
||||
install-libhighguiincludeHEADERS: $(libhighguiinclude_HEADERS)
|
||||
@$(NORMAL_INSTALL)
|
||||
test -z "$(libhighguiincludedir)" || $(mkdir_p) "$(DESTDIR)$(libhighguiincludedir)"
|
||||
@list='$(libhighguiinclude_HEADERS)'; for p in $$list; do \
|
||||
if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \
|
||||
f=$(am__strip_dir) \
|
||||
echo " $(libhighguiincludeHEADERS_INSTALL) '$$d$$p' '$(DESTDIR)$(libhighguiincludedir)/$$f'"; \
|
||||
$(libhighguiincludeHEADERS_INSTALL) "$$d$$p" "$(DESTDIR)$(libhighguiincludedir)/$$f"; \
|
||||
done
|
||||
|
||||
uninstall-libhighguiincludeHEADERS:
|
||||
@$(NORMAL_UNINSTALL)
|
||||
@list='$(libhighguiinclude_HEADERS)'; for p in $$list; do \
|
||||
f=$(am__strip_dir) \
|
||||
echo " rm -f '$(DESTDIR)$(libhighguiincludedir)/$$f'"; \
|
||||
rm -f "$(DESTDIR)$(libhighguiincludedir)/$$f"; \
|
||||
done
|
||||
|
||||
ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES)
|
||||
list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
|
||||
unique=`for i in $$list; do \
|
||||
if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
|
||||
done | \
|
||||
$(AWK) ' { files[$$0] = 1; } \
|
||||
END { for (i in files) print i; }'`; \
|
||||
mkid -fID $$unique
|
||||
tags: TAGS
|
||||
|
||||
TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \
|
||||
$(TAGS_FILES) $(LISP)
|
||||
tags=; \
|
||||
here=`pwd`; \
|
||||
list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
|
||||
unique=`for i in $$list; do \
|
||||
if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
|
||||
done | \
|
||||
$(AWK) ' { files[$$0] = 1; } \
|
||||
END { for (i in files) print i; }'`; \
|
||||
if test -z "$(ETAGS_ARGS)$$tags$$unique"; then :; else \
|
||||
test -n "$$unique" || unique=$$empty_fix; \
|
||||
$(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
|
||||
$$tags $$unique; \
|
||||
fi
|
||||
ctags: CTAGS
|
||||
CTAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \
|
||||
$(TAGS_FILES) $(LISP)
|
||||
tags=; \
|
||||
here=`pwd`; \
|
||||
list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
|
||||
unique=`for i in $$list; do \
|
||||
if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
|
||||
done | \
|
||||
$(AWK) ' { files[$$0] = 1; } \
|
||||
END { for (i in files) print i; }'`; \
|
||||
test -z "$(CTAGS_ARGS)$$tags$$unique" \
|
||||
|| $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \
|
||||
$$tags $$unique
|
||||
|
||||
GTAGS:
|
||||
here=`$(am__cd) $(top_builddir) && pwd` \
|
||||
&& cd $(top_srcdir) \
|
||||
&& gtags -i $(GTAGS_ARGS) $$here
|
||||
|
||||
distclean-tags:
|
||||
-rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags
|
||||
|
||||
distdir: $(DISTFILES)
|
||||
@srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; \
|
||||
topsrcdirstrip=`echo "$(top_srcdir)" | sed 's|.|.|g'`; \
|
||||
list='$(DISTFILES)'; for file in $$list; do \
|
||||
case $$file in \
|
||||
$(srcdir)/*) file=`echo "$$file" | sed "s|^$$srcdirstrip/||"`;; \
|
||||
$(top_srcdir)/*) file=`echo "$$file" | sed "s|^$$topsrcdirstrip/|$(top_builddir)/|"`;; \
|
||||
esac; \
|
||||
if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \
|
||||
dir=`echo "$$file" | sed -e 's,/[^/]*$$,,'`; \
|
||||
if test "$$dir" != "$$file" && test "$$dir" != "."; then \
|
||||
dir="/$$dir"; \
|
||||
$(mkdir_p) "$(distdir)$$dir"; \
|
||||
else \
|
||||
dir=''; \
|
||||
fi; \
|
||||
if test -d $$d/$$file; then \
|
||||
if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \
|
||||
cp -pR $(srcdir)/$$file $(distdir)$$dir || exit 1; \
|
||||
fi; \
|
||||
cp -pR $$d/$$file $(distdir)$$dir || exit 1; \
|
||||
else \
|
||||
test -f $(distdir)/$$file \
|
||||
|| cp -p $$d/$$file $(distdir)/$$file \
|
||||
|| exit 1; \
|
||||
fi; \
|
||||
done
|
||||
check-am: all-am
|
||||
check: check-am
|
||||
all-am: Makefile $(LTLIBRARIES) $(HEADERS)
|
||||
installdirs:
|
||||
for dir in "$(DESTDIR)$(libdir)" "$(DESTDIR)$(libhighguiincludedir)"; do \
|
||||
test -z "$$dir" || $(mkdir_p) "$$dir"; \
|
||||
done
|
||||
install: install-am
|
||||
install-exec: install-exec-am
|
||||
install-data: install-data-am
|
||||
uninstall: uninstall-am
|
||||
|
||||
install-am: all-am
|
||||
@$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am
|
||||
|
||||
installcheck: installcheck-am
|
||||
install-strip:
|
||||
$(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
|
||||
install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
|
||||
`test -z '$(STRIP)' || \
|
||||
echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install
|
||||
mostlyclean-generic:
|
||||
|
||||
clean-generic:
|
||||
|
||||
distclean-generic:
|
||||
-test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES)
|
||||
|
||||
maintainer-clean-generic:
|
||||
@echo "This command is intended for maintainers to use"
|
||||
@echo "it deletes files that may require special tools to rebuild."
|
||||
clean: clean-am
|
||||
|
||||
clean-am: clean-generic clean-libLTLIBRARIES clean-libtool \
|
||||
clean-noinstLTLIBRARIES mostlyclean-am
|
||||
|
||||
distclean: distclean-am
|
||||
-rm -rf ./$(DEPDIR)
|
||||
-rm -f Makefile
|
||||
distclean-am: clean-am distclean-compile distclean-generic \
|
||||
distclean-libtool distclean-tags
|
||||
|
||||
dvi: dvi-am
|
||||
|
||||
dvi-am:
|
||||
|
||||
html: html-am
|
||||
|
||||
info: info-am
|
||||
|
||||
info-am:
|
||||
|
||||
install-data-am: install-libhighguiincludeHEADERS
|
||||
|
||||
install-exec-am: install-libLTLIBRARIES
|
||||
|
||||
install-info: install-info-am
|
||||
|
||||
install-man:
|
||||
|
||||
installcheck-am:
|
||||
|
||||
maintainer-clean: maintainer-clean-am
|
||||
-rm -rf ./$(DEPDIR)
|
||||
-rm -f Makefile
|
||||
maintainer-clean-am: distclean-am maintainer-clean-generic
|
||||
|
||||
mostlyclean: mostlyclean-am
|
||||
|
||||
mostlyclean-am: mostlyclean-compile mostlyclean-generic \
|
||||
mostlyclean-libtool
|
||||
|
||||
pdf: pdf-am
|
||||
|
||||
pdf-am:
|
||||
|
||||
ps: ps-am
|
||||
|
||||
ps-am:
|
||||
|
||||
uninstall-am: uninstall-info-am uninstall-libLTLIBRARIES \
|
||||
uninstall-libhighguiincludeHEADERS
|
||||
|
||||
.PHONY: CTAGS GTAGS all all-am check check-am clean clean-generic \
|
||||
clean-libLTLIBRARIES clean-libtool clean-noinstLTLIBRARIES \
|
||||
ctags distclean distclean-compile distclean-generic \
|
||||
distclean-libtool distclean-tags distdir dvi dvi-am html \
|
||||
html-am info info-am install install-am install-data \
|
||||
install-data-am install-exec install-exec-am install-info \
|
||||
install-info-am install-libLTLIBRARIES \
|
||||
install-libhighguiincludeHEADERS install-man install-strip \
|
||||
installcheck installcheck-am installdirs maintainer-clean \
|
||||
maintainer-clean-generic mostlyclean mostlyclean-compile \
|
||||
mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \
|
||||
tags uninstall uninstall-am uninstall-info-am \
|
||||
uninstall-libLTLIBRARIES uninstall-libhighguiincludeHEADERS
|
||||
|
||||
# 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:
|
||||
@@ -0,0 +1,152 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// Intel License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000, Intel Corporation, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of Intel Corporation may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#ifndef __HIGHGUI_H_
|
||||
#define __HIGHGUI_H_
|
||||
|
||||
#include "highgui.h"
|
||||
#include "cxmisc.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <limits.h>
|
||||
#include <ctype.h>
|
||||
#include <assert.h>
|
||||
|
||||
#ifndef WIN32
|
||||
#include "cvconfig.h"
|
||||
#else
|
||||
void FillBitmapInfo( BITMAPINFO* bmi, int width, int height, int bpp, int origin );
|
||||
#endif
|
||||
|
||||
/* Errors */
|
||||
#define HG_OK 0 /* Don't bet on it! */
|
||||
#define HG_BADNAME -1 /* Bad window or file name */
|
||||
#define HG_INITFAILED -2 /* Can't initialize HigHGUI. Possibly, can't find vlgrfmts.dll */
|
||||
#define HG_WCFAILED -3 /* Can't create a window */
|
||||
#define HG_NULLPTR -4 /* The null pointer where it should not appear */
|
||||
#define HG_BADPARAM -5
|
||||
|
||||
#define CV_WINDOW_MAGIC_VAL 0x00420042
|
||||
#define CV_TRACKBAR_MAGIC_VAL 0x00420043
|
||||
|
||||
/***************************** CvCapture structure ******************************/
|
||||
|
||||
#define CV_CAPTURE_BASE_API_COUNT 6
|
||||
|
||||
typedef void (CV_CDECL* CvCaptureCloseFunc) ( CvCapture* capture );
|
||||
typedef int (CV_CDECL* CvCaptureGrabFrameFunc) ( CvCapture* capture );
|
||||
typedef IplImage * (CV_CDECL* CvCaptureRetrieveFrameFunc) ( CvCapture* capture );
|
||||
typedef double (CV_CDECL* CvCaptureGetPropertyFunc) ( CvCapture* capture, int id );
|
||||
typedef int (CV_CDECL* CvCaptureSetPropertyFunc) ( CvCapture* capture,
|
||||
int id, double value );
|
||||
typedef const char * (CV_CDECL* CvCaptureGetDescriptionFunc)( CvCapture* capture );
|
||||
|
||||
typedef struct CvCaptureVTable
|
||||
{
|
||||
int count;
|
||||
CvCaptureCloseFunc close;
|
||||
CvCaptureGrabFrameFunc grab_frame;
|
||||
CvCaptureRetrieveFrameFunc retrieve_frame;
|
||||
CvCaptureGetPropertyFunc get_property;
|
||||
CvCaptureSetPropertyFunc set_property;
|
||||
CvCaptureGetDescriptionFunc get_description;
|
||||
}
|
||||
CvCaptureVTable;
|
||||
|
||||
typedef struct CvCapture
|
||||
{
|
||||
CvCaptureVTable* vtable;
|
||||
}
|
||||
CvCapture;
|
||||
|
||||
|
||||
#ifdef WIN32
|
||||
#define HAVE_VFW 1
|
||||
|
||||
/* uncomment to enable OpenEXR codec (will not compile under MSVC6) */
|
||||
//#define HAVE_ILMIMF 1
|
||||
|
||||
/* uncomment to enable CMUCamera1394 fireware camera module */
|
||||
//#define HAVE_CMU1394 1
|
||||
#endif
|
||||
|
||||
|
||||
#if defined (HAVE_CAMV4L) || defined (HAVE_CAMV4L2)
|
||||
CvCapture * cvCaptureFromCAM_V4L( int index );
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_DC1394
|
||||
CvCapture * cvCaptureFromCAM_DC1394( int index );
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_MIL
|
||||
CvCapture* cvCaptureFromCAM_MIL( int index );
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_CMU1394
|
||||
CvCapture * cvCaptureFromCAM_CMU( int index );
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_TYZX
|
||||
CV_IMPL CvCapture * cvCaptureFromCAM_TYZX( int index );
|
||||
#endif
|
||||
|
||||
#ifdef WIN32
|
||||
CvCapture* cvCaptureFromCAM_VFW( int index );
|
||||
CvCapture* cvCaptureFromFile_VFW( const char* filename );
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_XINE
|
||||
CvCapture* cvCaptureFromFile_XINE (const char* filename);
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_FFMPEG
|
||||
CvCapture* cvCaptureFromFile_FFMPEG (const char* filename);
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_QUICKTIME
|
||||
CvCapture * cvCaptureFromFile_QT (const char * filename);
|
||||
CvCapture * cvCaptureFromCAM_QT (const int index);
|
||||
#endif
|
||||
|
||||
#endif /* __HIGHGUI_H_ */
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,272 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// Intel License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000, Intel Corporation, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of Intel Corporation may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#ifndef _BITSTRM_H_
|
||||
#define _BITSTRM_H_
|
||||
|
||||
#include <stdio.h>
|
||||
#include <setjmp.h>
|
||||
|
||||
#if _MSC_VER >= 1200
|
||||
#pragma warning( disable: 4711 4324 )
|
||||
#endif
|
||||
|
||||
#define RBS_THROW_EOS -123 /* <end of stream> exception code */
|
||||
#define RBS_THROW_FORB -124 /* <forrbidden huffman code> exception code */
|
||||
#define RBS_HUFF_FORB 2047 /* forrbidden huffman code "value" */
|
||||
|
||||
typedef unsigned char uchar;
|
||||
typedef unsigned long ulong;
|
||||
|
||||
// class RBaseStream - base class for other reading streams.
|
||||
class RBaseStream
|
||||
{
|
||||
public:
|
||||
//methods
|
||||
RBaseStream();
|
||||
virtual ~RBaseStream();
|
||||
|
||||
virtual bool Open( const char* filename );
|
||||
virtual void Close();
|
||||
void SetBlockSize( int block_size, int unGetsize = 4 );
|
||||
bool IsOpened();
|
||||
void SetPos( int pos );
|
||||
int GetPos();
|
||||
void Skip( int bytes );
|
||||
jmp_buf& JmpBuf();
|
||||
|
||||
protected:
|
||||
|
||||
jmp_buf m_jmp_buf;
|
||||
uchar* m_start;
|
||||
uchar* m_end;
|
||||
uchar* m_current;
|
||||
FILE* m_file;
|
||||
int m_unGetsize;
|
||||
int m_block_size;
|
||||
int m_block_pos;
|
||||
bool m_jmp_set;
|
||||
bool m_is_opened;
|
||||
|
||||
virtual void ReadBlock();
|
||||
virtual void Release();
|
||||
virtual void Allocate();
|
||||
};
|
||||
|
||||
|
||||
// class RLByteStream - uchar-oriented stream.
|
||||
// l in prefix means that the least significant uchar of a multi-uchar value goes first
|
||||
class RLByteStream : public RBaseStream
|
||||
{
|
||||
public:
|
||||
virtual ~RLByteStream();
|
||||
|
||||
int GetByte();
|
||||
void GetBytes( void* buffer, int count, int* readed = 0 );
|
||||
int GetWord();
|
||||
int GetDWord();
|
||||
};
|
||||
|
||||
// class RMBitStream - uchar-oriented stream.
|
||||
// m in prefix means that the most significant uchar of a multi-uchar value go first
|
||||
class RMByteStream : public RLByteStream
|
||||
{
|
||||
public:
|
||||
virtual ~RMByteStream();
|
||||
|
||||
int GetWord();
|
||||
int GetDWord();
|
||||
};
|
||||
|
||||
// class RLBitStream - bit-oriented stream.
|
||||
// l in prefix means that the least significant bit of a multi-bit value goes first
|
||||
class RLBitStream : public RBaseStream
|
||||
{
|
||||
public:
|
||||
virtual ~RLBitStream();
|
||||
|
||||
void SetPos( int pos );
|
||||
int GetPos();
|
||||
int Get( int bits );
|
||||
int Show( int bits );
|
||||
int GetHuff( const short* table );
|
||||
void Move( int shift );
|
||||
void Skip( int bytes );
|
||||
|
||||
protected:
|
||||
int m_bit_idx;
|
||||
virtual void ReadBlock();
|
||||
};
|
||||
|
||||
// class RMBitStream - bit-oriented stream.
|
||||
// m in prefix means that the most significant bit of a multi-bit value goes first
|
||||
class RMBitStream : public RLBitStream
|
||||
{
|
||||
public:
|
||||
virtual ~RMBitStream();
|
||||
|
||||
void SetPos( int pos );
|
||||
int GetPos();
|
||||
int Get( int bits );
|
||||
int Show( int bits );
|
||||
int GetHuff( const short* table );
|
||||
void Move( int shift );
|
||||
void Skip( int bytes );
|
||||
|
||||
protected:
|
||||
virtual void ReadBlock();
|
||||
};
|
||||
|
||||
|
||||
// WBaseStream - base class for output streams
|
||||
class WBaseStream
|
||||
{
|
||||
public:
|
||||
//methods
|
||||
WBaseStream();
|
||||
virtual ~WBaseStream();
|
||||
|
||||
virtual bool Open( const char* filename );
|
||||
virtual void Close();
|
||||
void SetBlockSize( int block_size );
|
||||
bool IsOpened();
|
||||
int GetPos();
|
||||
|
||||
protected:
|
||||
|
||||
uchar* m_start;
|
||||
uchar* m_end;
|
||||
uchar* m_current;
|
||||
int m_block_size;
|
||||
int m_block_pos;
|
||||
FILE* m_file;
|
||||
bool m_is_opened;
|
||||
|
||||
virtual void WriteBlock();
|
||||
virtual void Release();
|
||||
virtual void Allocate();
|
||||
};
|
||||
|
||||
|
||||
// class WLByteStream - uchar-oriented stream.
|
||||
// l in prefix means that the least significant uchar of a multi-byte value goes first
|
||||
class WLByteStream : public WBaseStream
|
||||
{
|
||||
public:
|
||||
virtual ~WLByteStream();
|
||||
|
||||
void PutByte( int val );
|
||||
void PutBytes( const void* buffer, int count );
|
||||
void PutWord( int val );
|
||||
void PutDWord( int val );
|
||||
};
|
||||
|
||||
|
||||
// class WLByteStream - uchar-oriented stream.
|
||||
// m in prefix means that the least significant uchar of a multi-byte value goes last
|
||||
class WMByteStream : public WLByteStream
|
||||
{
|
||||
public:
|
||||
virtual ~WMByteStream();
|
||||
|
||||
void PutWord( int val );
|
||||
void PutDWord( int val );
|
||||
};
|
||||
|
||||
|
||||
// class WLBitStream - bit-oriented stream.
|
||||
// l in prefix means that the least significant bit of a multi-bit value goes first
|
||||
class WLBitStream : public WBaseStream
|
||||
{
|
||||
public:
|
||||
virtual ~WLBitStream();
|
||||
|
||||
int GetPos();
|
||||
void Put( int val, int bits );
|
||||
void PutHuff( int val, const int* table );
|
||||
|
||||
protected:
|
||||
int m_bit_idx;
|
||||
int m_val;
|
||||
virtual void WriteBlock();
|
||||
};
|
||||
|
||||
|
||||
// class WMBitStream - bit-oriented stream.
|
||||
// l in prefix means that the least significant bit of a multi-bit value goes first
|
||||
class WMBitStream : public WBaseStream
|
||||
{
|
||||
public:
|
||||
WMBitStream();
|
||||
virtual ~WMBitStream();
|
||||
|
||||
bool Open( const char* filename );
|
||||
void Close();
|
||||
virtual void Flush();
|
||||
|
||||
int GetPos();
|
||||
void Put( int val, int bits );
|
||||
void PutHuff( int val, const ulong* table );
|
||||
|
||||
protected:
|
||||
int m_bit_idx;
|
||||
ulong m_pad_val;
|
||||
ulong m_val;
|
||||
virtual void WriteBlock();
|
||||
void ResetBuffer();
|
||||
};
|
||||
|
||||
|
||||
|
||||
#define BSWAP(v) (((v)<<24)|(((v)&0xff00)<<8)| \
|
||||
(((v)>>8)&0xff00)|((unsigned)(v)>>24))
|
||||
|
||||
int* bsCreateSourceHuffmanTable( const uchar* src, int* dst,
|
||||
int max_bits, int first_bits );
|
||||
bool bsCreateDecodeHuffmanTable( const int* src, short* dst, int max_size );
|
||||
bool bsCreateEncodeHuffmanTable( const int* src, ulong* dst, int max_size );
|
||||
|
||||
void bsBSwapBlock( uchar *start, uchar *end );
|
||||
bool bsIsBigEndian( void );
|
||||
|
||||
extern const ulong bs_bit_mask[];
|
||||
|
||||
#endif/*_BITSTRM_H_*/
|
||||
@@ -0,0 +1,257 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// Intel License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000, Intel Corporation, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of Intel Corporation may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "_highgui.h"
|
||||
|
||||
#if _MSC_VER >= 1200
|
||||
#pragma warning( disable: 4711 )
|
||||
#endif
|
||||
|
||||
#if defined WIN64 && defined EM64T && defined _MSC_VER && !defined __ICL
|
||||
#pragma optimize("",off)
|
||||
#endif
|
||||
|
||||
|
||||
/************************* Reading AVIs & Camera data **************************/
|
||||
|
||||
CV_IMPL void cvReleaseCapture( CvCapture** pcapture )
|
||||
{
|
||||
if( pcapture && *pcapture )
|
||||
{
|
||||
CvCapture* capture = *pcapture;
|
||||
if( capture && capture->vtable &&
|
||||
capture->vtable->count >= CV_CAPTURE_BASE_API_COUNT &&
|
||||
capture->vtable->close )
|
||||
capture->vtable->close( capture );
|
||||
cvFree( pcapture );
|
||||
}
|
||||
}
|
||||
|
||||
CV_IMPL IplImage* cvQueryFrame( CvCapture* capture )
|
||||
{
|
||||
if( capture && capture->vtable &&
|
||||
capture->vtable->count >= CV_CAPTURE_BASE_API_COUNT &&
|
||||
capture->vtable->grab_frame && capture->vtable->retrieve_frame &&
|
||||
capture->vtable->grab_frame( capture ))
|
||||
return capture->vtable->retrieve_frame( capture );
|
||||
return 0;
|
||||
}
|
||||
|
||||
CV_IMPL int cvGrabFrame( CvCapture* capture )
|
||||
{
|
||||
if( capture && capture->vtable &&
|
||||
capture->vtable->count >= CV_CAPTURE_BASE_API_COUNT &&
|
||||
capture->vtable->grab_frame )
|
||||
return capture->vtable->grab_frame( capture );
|
||||
return 0;
|
||||
}
|
||||
|
||||
CV_IMPL IplImage* cvRetrieveFrame( CvCapture* capture )
|
||||
{
|
||||
if( capture && capture->vtable &&
|
||||
capture->vtable->count >= CV_CAPTURE_BASE_API_COUNT &&
|
||||
capture->vtable->retrieve_frame )
|
||||
return capture->vtable->retrieve_frame( capture );
|
||||
return 0;
|
||||
}
|
||||
|
||||
CV_IMPL double cvGetCaptureProperty( CvCapture* capture, int id )
|
||||
{
|
||||
if( capture && capture->vtable &&
|
||||
capture->vtable->count >= CV_CAPTURE_BASE_API_COUNT &&
|
||||
capture->vtable->get_property )
|
||||
return capture->vtable->get_property( capture, id );
|
||||
return 0;
|
||||
}
|
||||
|
||||
CV_IMPL int cvSetCaptureProperty( CvCapture* capture, int id, double value )
|
||||
{
|
||||
if( capture && capture->vtable &&
|
||||
capture->vtable->count >= CV_CAPTURE_BASE_API_COUNT &&
|
||||
capture->vtable->set_property )
|
||||
return capture->vtable->set_property( capture, id, value );
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Camera dispatching method: index is the camera number.
|
||||
* If given an index from 0 to 99, it tries to find the first
|
||||
* API that can access a given camera index.
|
||||
* Add multiples of 100 to select an API.
|
||||
*/
|
||||
CV_IMPL CvCapture * cvCaptureFromCAM (int index)
|
||||
{
|
||||
int domains[] =
|
||||
{
|
||||
CV_CAP_IEEE1394, // identical to CV_CAP_DC1394
|
||||
CV_CAP_STEREO,
|
||||
CV_CAP_VFW, // identical to CV_CAP_V4L
|
||||
CV_CAP_MIL,
|
||||
CV_CAP_QT,
|
||||
-1
|
||||
};
|
||||
|
||||
|
||||
// interpret preferred interface (0 = autodetect)
|
||||
int pref = (index / 100) * 100;
|
||||
if (pref)
|
||||
{
|
||||
domains[0]=pref;
|
||||
index %= 100;
|
||||
domains[1]=-1;
|
||||
}
|
||||
|
||||
// try every possibly installed camera API
|
||||
for (int i = 0; domains[i] >= 0; i++)
|
||||
{
|
||||
|
||||
// local variable to memorize the captured device
|
||||
CvCapture *capture;
|
||||
|
||||
switch (domains[i])
|
||||
{
|
||||
#ifdef HAVE_TYZX
|
||||
case CV_CAP_STEREO:
|
||||
capture = cvCaptureFromCAM_TYZX (index);
|
||||
if (capture)
|
||||
return capture;
|
||||
#endif
|
||||
|
||||
#if defined (HAVE_VFW)
|
||||
case CV_CAP_VFW:
|
||||
capture = cvCaptureFromCAM_VFW (index);
|
||||
if (capture)
|
||||
return capture;
|
||||
#elif defined (HAVE_CAMV4L) || defined (HAVE_CAMV4L2)
|
||||
case CV_CAP_V4L:
|
||||
capture = cvCaptureFromCAM_V4L (index);
|
||||
if (capture)
|
||||
return capture;
|
||||
#endif
|
||||
|
||||
#if defined (HAVE_DC1394)
|
||||
case CV_CAP_DC1394:
|
||||
capture = cvCaptureFromCAM_DC1394 (index);
|
||||
if (capture)
|
||||
return capture;
|
||||
#elif defined (HAVE_CMU1394)
|
||||
case CV_CAP_IEEE1394:
|
||||
capture = cvCaptureFromCAM_CMU (index);
|
||||
if (capture)
|
||||
return capture;
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_MIL
|
||||
case CV_CAP_MIL:
|
||||
capture = cvCaptureFromCAM_MIL (index);
|
||||
if (capture)
|
||||
return capture;
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_QUICKTIME
|
||||
case CV_CAP_QT:
|
||||
capture = cvCaptureFromCAM_QT (index);
|
||||
if (capture)
|
||||
return capture;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
// failed open a camera
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Videoreader dispatching method: it tries to find the first
|
||||
* API that can access a given filename.
|
||||
*/
|
||||
CV_IMPL CvCapture * cvCaptureFromFile (const char * filename)
|
||||
{
|
||||
CvCapture * result = 0;
|
||||
|
||||
#ifdef HAVE_VFW
|
||||
if (! result)
|
||||
result = cvCaptureFromFile_VFW (filename);
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_XINE
|
||||
if (! result)
|
||||
result = cvCaptureFromFile_XINE (filename);
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_FFMPEG
|
||||
if (! result)
|
||||
result = cvCaptureFromFile_FFMPEG (filename);
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_QUICKTIME
|
||||
if (! result)
|
||||
result = cvCaptureFromFile_QT (filename);
|
||||
#endif
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
#ifndef HAVE_FFMPEG
|
||||
#ifndef HAVE_VFW
|
||||
#ifndef HAVE_QUICKTIME
|
||||
|
||||
// quick fix for rc1
|
||||
|
||||
CV_IMPL CvVideoWriter* cvCreateVideoWriter( const char* filename, int fourcc,
|
||||
double fps, CvSize frameSize, int is_color )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
CV_IMPL int cvWriteFrame( CvVideoWriter* _writer, const IplImage* image )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
CV_IMPL void cvReleaseVideoWriter( CvVideoWriter** writer )
|
||||
{
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
@@ -0,0 +1,522 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// Intel License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000, Intel Corporation, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of Intel Corporation may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "_highgui.h"
|
||||
|
||||
#ifdef WIN32
|
||||
|
||||
/****************** Capturing video from camera via CMU lib *******************/
|
||||
|
||||
#if defined(HAVE_CMU1394)
|
||||
|
||||
// This firewire capability added by Philip Gruebele (pgruebele@cox.net).
|
||||
// For this to work you need to install the CMU firewire DCAM drivers,
|
||||
// located at http://www-2.cs.cmu.edu/~iwan/1394/.
|
||||
#include "1394camera.h"
|
||||
|
||||
typedef struct CvCaptureCAM_CMU
|
||||
{
|
||||
CvCaptureVTable* vtable;
|
||||
int fps; // 0-5
|
||||
int mode; // 0-7
|
||||
int format; // 0-2, 7 ?
|
||||
int index;
|
||||
IplImage * image;
|
||||
IplImage* rgb_frame;
|
||||
}
|
||||
CvCaptureCAM_CMU;
|
||||
|
||||
int icvOpenCAM_CMU(CvCaptureCAM_CMU * capture, int wIndex );
|
||||
int icvSetPropertyCAM_CMU( CvCaptureCAM_CMU* capture, int property_id, double value );
|
||||
void icvCloseCAM_CMU( CvCaptureCAM_CMU* capture );
|
||||
int icvGrabFrameCAM_CMU( CvCaptureCAM_CMU* capture );
|
||||
IplImage* icvRetrieveFrameCAM_CMU( CvCaptureCAM_CMU* capture );
|
||||
double icvGetPropertyCAM_CMU( CvCaptureCAM_CMU* capture, int property_id );
|
||||
int icvSetPropertyCAM_CMU( CvCaptureCAM_CMU* capture, int property_id, double value );
|
||||
|
||||
static CvCaptureVTable captureCAM_CMU_vtable =
|
||||
{
|
||||
6,
|
||||
(CvCaptureCloseFunc)icvCloseCAM_CMU,
|
||||
(CvCaptureGrabFrameFunc)icvGrabFrameCAM_CMU,
|
||||
(CvCaptureRetrieveFrameFunc)icvRetrieveFrameCAM_CMU,
|
||||
(CvCaptureGetPropertyFunc)icvGetPropertyCAM_CMU,
|
||||
(CvCaptureSetPropertyFunc)icvSetPropertyCAM_CMU,
|
||||
(CvCaptureGetDescriptionFunc)0
|
||||
};
|
||||
|
||||
// CMU 1394 camera stuff.
|
||||
// This firewire capability added by Philip Gruebele (pgruebele@cox.net)
|
||||
// and modified by Roman Stanchak (rstanchak@yahoo.com).
|
||||
// For this to work you need to install the CMU firewire DCAM drivers,
|
||||
// located at http://www-2.cs.cmu.edu/~iwan/1394/.
|
||||
#define CMU_MAX_CAMERAS 20
|
||||
int CMU_numCameras = 0;
|
||||
int CMU_numActiveCameras = 0;
|
||||
bool CMU_useCameraFlags[CMU_MAX_CAMERAS];
|
||||
C1394Camera *CMU_theCamera = 0;
|
||||
|
||||
// stupid defines for mode, format, FPS
|
||||
#define CV_CAP_IEEE1394_FPS_1_875 0
|
||||
#define CV_CAP_IEEE1394_FPS_3_75 1
|
||||
#define CV_CAP_IEEE1394_FPS_7_5 2
|
||||
#define CV_CAP_IEEE1394_FPS_15 3
|
||||
#define CV_CAP_IEEE1394_FPS_30 4
|
||||
#define CV_CAP_IEEE1394_FPS_60 5
|
||||
|
||||
// index by size, color
|
||||
#define CV_CAP_IEEE1394_COLOR_MONO 0
|
||||
#define CV_CAP_IEEE1394_COLOR_MONO16 1
|
||||
#define CV_CAP_IEEE1394_COLOR_YUV444 2
|
||||
#define CV_CAP_IEEE1394_COLOR_YUV422 3
|
||||
#define CV_CAP_IEEE1394_COLOR_YUV411 4
|
||||
#define CV_CAP_IEEE1394_COLOR_RGB 5
|
||||
|
||||
#define CV_CAP_IEEE1394_SIZE_160X120 0
|
||||
#define CV_CAP_IEEE1394_SIZE_320X240 1
|
||||
#define CV_CAP_IEEE1394_SIZE_640X480 2
|
||||
#define CV_CAP_IEEE1394_SIZE_800X600 3
|
||||
#define CV_CAP_IEEE1394_SIZE_1024X768 4
|
||||
#define CV_CAP_IEEE1394_SIZE_1280X960 5
|
||||
#define CV_CAP_IEEE1394_SIZE_1600X1200 6
|
||||
|
||||
// given color, size, output format
|
||||
// 1 16 444 422 411 RGB
|
||||
char CV_CAP_IEEE1394_FORMAT[7][6] = { {-1, -1, 0, -1, -1, -1}, // 160x120
|
||||
{-1, -1, -1, 0, -1, -1}, // 320x240
|
||||
{ 0, 0, -1, 0, 0, 0}, // 640x480
|
||||
{ 1, 1, -1, 1, -1, 1}, // 800x600
|
||||
{ 1, 1, -1, 1, -1, 1}, // 1024x768
|
||||
{ 2, 2, -1, 2, -1, 2}, // 1280x960
|
||||
{ 2, 2, -1, 2, -1, 2}}; // 1600x1200
|
||||
// given color, size, output corresponding mode
|
||||
char CV_CAP_IEEE1394_MODE[7][6] = { {-1, -1, 0, -1, -1, -1}, // 160x120
|
||||
{-1, -1, -1, 1, -1, -1}, // 320x240
|
||||
{ 5, 6, -1, 3, 2, 4}, // 640x480
|
||||
{ 2, 6, -1, 0, -1, 1}, // 800x600
|
||||
{ 5, 7, -1, 3, -1, 4}, // 1024x768
|
||||
{ 2, 6, -1, 0, -1, 1}, // 1280x960
|
||||
{ 5, 7, -1, 3, -1, 4}}; // 1600x1200
|
||||
// given format, mode, return COLOR
|
||||
char CV_CAP_IEEE1394_COLOR[2][8] = { { CV_CAP_IEEE1394_COLOR_YUV444,
|
||||
CV_CAP_IEEE1394_COLOR_YUV422,
|
||||
CV_CAP_IEEE1394_COLOR_YUV411,
|
||||
CV_CAP_IEEE1394_COLOR_YUV422,
|
||||
CV_CAP_IEEE1394_COLOR_RGB,
|
||||
CV_CAP_IEEE1394_COLOR_MONO,
|
||||
CV_CAP_IEEE1394_COLOR_MONO16 },
|
||||
{ CV_CAP_IEEE1394_COLOR_YUV422,
|
||||
CV_CAP_IEEE1394_COLOR_RGB,
|
||||
CV_CAP_IEEE1394_COLOR_MONO,
|
||||
CV_CAP_IEEE1394_COLOR_YUV422,
|
||||
CV_CAP_IEEE1394_COLOR_RGB,
|
||||
CV_CAP_IEEE1394_COLOR_MONO,
|
||||
CV_CAP_IEEE1394_COLOR_MONO16,
|
||||
CV_CAP_IEEE1394_COLOR_MONO16 } };
|
||||
|
||||
// convert frame rate to suitable enum
|
||||
/*static int icvFrameRateToIndex_CMU(double framerate){
|
||||
if(framerate > 30) return CV_CAP_IEEE1394_FPS_60;
|
||||
else if(framerate > 15) return CV_CAP_IEEE1394_FPS_30;
|
||||
else if(framerate > 7.5) return CV_CAP_IEEE1394_FPS_15;
|
||||
else if(framerate > 3.75) return CV_CAP_IEEE1394_FPS_7_5;
|
||||
else if(framerate > 1.875) return CV_CAP_IEEE1394_FPS_3_75;
|
||||
return CV_CAP_IEEE1394_FPS_1_875;
|
||||
}*/
|
||||
|
||||
#if _MSC_VER >= 1200
|
||||
#pragma comment(lib,"1394camera.lib")
|
||||
#endif
|
||||
|
||||
// return the size of the image
|
||||
CvSize icvGetSize_CMU( C1394Camera * cmucam ){
|
||||
//int format = cmucam->GetVideoFormat();
|
||||
//int mode = cmucam->GetVideoMode();
|
||||
|
||||
// irrelvant to depth
|
||||
// if( format > 1 ) format=1;
|
||||
|
||||
// for YUV, should we return a weirdly sized image?
|
||||
//switch(CV_CAP_IEEE1394_COLOR[format][mode]){
|
||||
//case CV_CAP_IEEE1394_COLOR_MONO16:
|
||||
// return cvSize(cmucam->m_width*2, cmucam->m_height);
|
||||
//default:
|
||||
// return cvSize(cmucam->m_width, cmucam->m_height);
|
||||
//}
|
||||
unsigned long width = 0, height = 0;
|
||||
cmucam->GetVideoFrameDimensions( &width, &height );
|
||||
return cvSize((int)width, (int)height);
|
||||
}
|
||||
|
||||
// return the opencv depth flag corresponding to the camera format
|
||||
int icvGetDepth_CMU( C1394Camera * cmucam ){
|
||||
int format = cmucam->GetVideoFormat();
|
||||
int mode = cmucam->GetVideoMode();
|
||||
|
||||
// TODO
|
||||
if( format==7 ) {
|
||||
assert(0);
|
||||
}
|
||||
// irrelvant to depth
|
||||
if( format > 1 ) format=1;
|
||||
|
||||
if(CV_CAP_IEEE1394_COLOR[format][mode]==CV_CAP_IEEE1394_COLOR_MONO16){
|
||||
return IPL_DEPTH_16S;
|
||||
}
|
||||
return IPL_DEPTH_8U;
|
||||
}
|
||||
|
||||
// return the number of channels for camera
|
||||
int icvGetNChannels_CMU( C1394Camera * cmucam ){
|
||||
|
||||
int format = cmucam->GetVideoFormat();
|
||||
int mode = cmucam->GetVideoMode();
|
||||
|
||||
if( format==7 ){
|
||||
assert(0);
|
||||
}
|
||||
|
||||
// irrelvant to nchannels
|
||||
if( format > 1 ) format=1;
|
||||
|
||||
switch(CV_CAP_IEEE1394_COLOR[format][mode]){
|
||||
case CV_CAP_IEEE1394_COLOR_RGB:
|
||||
return 3;
|
||||
case CV_CAP_IEEE1394_COLOR_MONO:
|
||||
case CV_CAP_IEEE1394_COLOR_MONO16:
|
||||
return 1;
|
||||
case CV_CAP_IEEE1394_COLOR_YUV422:
|
||||
case CV_CAP_IEEE1394_COLOR_YUV444:
|
||||
case CV_CAP_IEEE1394_COLOR_YUV411:
|
||||
return 3;
|
||||
default:
|
||||
;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
int icvOpenCAM_CMU(CvCaptureCAM_CMU * capture, int index )
|
||||
{
|
||||
// if first time, then allocate all available cameras
|
||||
if( CMU_numCameras == 0 )
|
||||
{
|
||||
CMU_numActiveCameras = 0;
|
||||
CMU_theCamera = new C1394Camera[CMU_MAX_CAMERAS];
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// create all cameras
|
||||
try
|
||||
{
|
||||
// create camera0
|
||||
if( CMU_theCamera[0].CheckLink() != CAM_SUCCESS )
|
||||
throw 1;
|
||||
|
||||
// we have one pin per camera
|
||||
CMU_numCameras = CMU_theCamera[0].GetNumberCameras();
|
||||
|
||||
// allocate remaining cameras
|
||||
for(int i = 1; i < CMU_numCameras && i<CMU_MAX_CAMERAS; i++ )
|
||||
{
|
||||
CMU_useCameraFlags[i] = false;
|
||||
if (CMU_theCamera[i].CheckLink() != CAM_SUCCESS)
|
||||
throw 1;
|
||||
}
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
// free any allocated cameras
|
||||
// ...
|
||||
CMU_numCameras = 0;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
// pick first unused camera
|
||||
if(index==-1){
|
||||
for(int i = 0; i < CMU_numCameras; i++ )
|
||||
{
|
||||
if( !CMU_useCameraFlags[i] ){
|
||||
index = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// no empty camera found
|
||||
if (index==-1)
|
||||
throw 1;
|
||||
|
||||
if (CMU_theCamera[index].SelectCamera(index) != CAM_SUCCESS)
|
||||
throw 2;
|
||||
|
||||
if (CMU_theCamera[index].InitCamera() != CAM_SUCCESS)
|
||||
throw 3;
|
||||
|
||||
// set initial format -- try to pick best frame rate first, then color, then size
|
||||
bool found_format = false;
|
||||
for (int rate=5; rate>=0 && !found_format; rate--){
|
||||
for (int color=CV_CAP_IEEE1394_COLOR_RGB; color>=0 && !found_format; color--){
|
||||
for (int size=CV_CAP_IEEE1394_SIZE_1600X1200; size>=0 && !found_format; size--){
|
||||
int format = CV_CAP_IEEE1394_FORMAT[size][color];
|
||||
int mode = CV_CAP_IEEE1394_MODE[size][color];
|
||||
if (format!=-1 && mode!=-1 &&
|
||||
CMU_theCamera[index].HasVideoFrameRate(format,mode,rate)){
|
||||
CMU_theCamera[index].SetVideoFormat(format);
|
||||
CMU_theCamera[index].SetVideoMode(mode);
|
||||
CMU_theCamera[index].SetVideoFrameRate(rate);
|
||||
found_format = (CMU_theCamera[index].StartImageAcquisition() == CAM_SUCCESS);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// try format 7
|
||||
if(!found_format){
|
||||
CMU_theCamera[index].SetVideoFormat(7);
|
||||
CMU_theCamera[index].SetVideoMode(0);
|
||||
if(CMU_theCamera[index].StartImageAcquisition() != CAM_SUCCESS){
|
||||
// no format found
|
||||
throw 9;
|
||||
}
|
||||
}
|
||||
|
||||
// allocate image frame
|
||||
capture->image = cvCreateImage(icvGetSize_CMU(&(CMU_theCamera[index])),
|
||||
icvGetDepth_CMU(&(CMU_theCamera[index])),
|
||||
icvGetNChannels_CMU(&(CMU_theCamera[index])));
|
||||
if (capture->image)
|
||||
{
|
||||
// successfully activated camera
|
||||
capture->index = index; //CMU_numActiveCameras;
|
||||
CMU_numActiveCameras++;
|
||||
CMU_useCameraFlags[index] = true;
|
||||
}
|
||||
}
|
||||
catch ( int )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
void icvCloseCAM_CMU( CvCaptureCAM_CMU* capture )
|
||||
{
|
||||
if( capture && capture->image )
|
||||
{
|
||||
cvReleaseImage( &capture->image );
|
||||
CMU_theCamera[capture->index].StopImageAcquisition();
|
||||
CMU_useCameraFlags[capture->index] = false;
|
||||
CMU_numActiveCameras--;
|
||||
|
||||
if (!CMU_numActiveCameras)
|
||||
{
|
||||
delete[] CMU_theCamera;
|
||||
CMU_theCamera = 0;
|
||||
CMU_numCameras = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int icvGrabFrameCAM_CMU( CvCaptureCAM_CMU* capture )
|
||||
{
|
||||
return capture->image && CMU_theCamera &&
|
||||
CMU_theCamera[capture->index].AcquireImage() == CAM_SUCCESS;
|
||||
}
|
||||
|
||||
static void swapRedBlue(IplImage * im){
|
||||
uchar * ptr = (uchar *) im->imageData;
|
||||
uchar t;
|
||||
for(int i=0; i<im->height; i++){
|
||||
ptr = (uchar *) im->imageData+im->widthStep*i;
|
||||
for(int j=0; j<im->width; j++){
|
||||
t = ptr[0];
|
||||
ptr[0] = ptr[2];
|
||||
ptr[2] = t;
|
||||
ptr+=3;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
IplImage* icvRetrieveFrameCAM_CMU( CvCaptureCAM_CMU* capture )
|
||||
{
|
||||
if( capture->image && CMU_theCamera )
|
||||
{
|
||||
//capture->image->imageData = (char *) CMU_theCamera[capture->index].GetRawData(0);
|
||||
CMU_theCamera[capture->index].getRGB((unsigned char*)capture->image->imageData,
|
||||
capture->image->imageSize);
|
||||
swapRedBlue( capture->image );
|
||||
return capture->image;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
double icvGetPropertyCAM_CMU( CvCaptureCAM_CMU* capture, int property_id )
|
||||
{
|
||||
switch( property_id )
|
||||
{
|
||||
case CV_CAP_PROP_FRAME_WIDTH:
|
||||
return capture->image->width;
|
||||
case CV_CAP_PROP_FRAME_HEIGHT:
|
||||
return capture->image->height;
|
||||
case CV_CAP_PROP_FPS:
|
||||
return CMU_theCamera[capture->index].GetVideoFrameRate();
|
||||
case CV_CAP_PROP_MODE:
|
||||
return CMU_theCamera[capture->index].GetVideoMode();
|
||||
case CV_CAP_PROP_FORMAT:
|
||||
return CMU_theCamera[capture->index].GetVideoFormat();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int icvSetVideoSize( CvCaptureCAM_CMU* capture, int, int) {
|
||||
if (capture==0) return 0;
|
||||
// change to closest size
|
||||
return -1;
|
||||
}
|
||||
|
||||
static int icvSetMode(CvCaptureCAM_CMU * capture, int mode){
|
||||
int format = CMU_theCamera[capture->index].GetVideoFormat();
|
||||
if(mode < 0 || mode > 7){
|
||||
return -1;
|
||||
}
|
||||
if(CMU_theCamera[capture->index].HasVideoMode(format, mode)){
|
||||
CMU_theCamera[capture->index].StopImageAcquisition();
|
||||
CMU_theCamera[capture->index].SetVideoMode(mode);
|
||||
CMU_theCamera[capture->index].StartImageAcquisition();
|
||||
return 0;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
static int icvSetFrameRate(CvCaptureCAM_CMU * capture, int rate){
|
||||
int mode = CMU_theCamera[capture->index].GetVideoMode();
|
||||
int format = CMU_theCamera[capture->index].GetVideoFormat();
|
||||
if(rate < 0 || rate > 5){
|
||||
return -1;
|
||||
}
|
||||
if(CMU_theCamera[capture->index].HasVideoFrameRate(format, mode, rate)){
|
||||
CMU_theCamera[capture->index].StopImageAcquisition();
|
||||
CMU_theCamera[capture->index].SetVideoFrameRate(rate);
|
||||
CMU_theCamera[capture->index].StartImageAcquisition();
|
||||
return 0;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
static int icvSetFormat(CvCaptureCAM_CMU * capture, int format){
|
||||
if(format < 0 || format > 2){
|
||||
return -1;
|
||||
}
|
||||
if(CMU_theCamera[capture->index].HasVideoFormat(format)){
|
||||
CMU_theCamera[capture->index].StopImageAcquisition();
|
||||
CMU_theCamera[capture->index].SetVideoFormat(format);
|
||||
CMU_theCamera[capture->index].StartImageAcquisition();
|
||||
return 0;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
int icvSetPropertyCAM_CMU( CvCaptureCAM_CMU* capture, int property_id, double value ){
|
||||
int retval = -1;
|
||||
int ival= cvRound(value);
|
||||
switch (property_id) {
|
||||
case CV_CAP_PROP_FRAME_WIDTH:
|
||||
case CV_CAP_PROP_FRAME_HEIGHT:
|
||||
{
|
||||
int width, height;
|
||||
if (property_id == CV_CAP_PROP_FRAME_WIDTH) {
|
||||
width = ival;
|
||||
height = width*3/4;
|
||||
}
|
||||
else {
|
||||
height = ival;
|
||||
width = height*4/3;
|
||||
}
|
||||
retval = icvSetVideoSize(capture, width, height);
|
||||
}
|
||||
break;
|
||||
case CV_CAP_PROP_FPS:
|
||||
retval =icvSetFrameRate(capture, ival);
|
||||
break;
|
||||
case CV_CAP_PROP_MODE:
|
||||
retval =icvSetMode(capture, ival);
|
||||
break;
|
||||
case CV_CAP_PROP_FORMAT:
|
||||
retval =icvSetFormat(capture, ival);
|
||||
break;
|
||||
}
|
||||
|
||||
// resize image if its not the right size anymore
|
||||
CvSize size = icvGetSize_CMU( &(CMU_theCamera[capture->index]) );
|
||||
int depth = icvGetDepth_CMU( &(CMU_theCamera[capture->index]) );
|
||||
int nch = icvGetNChannels_CMU( &(CMU_theCamera[capture->index]) );
|
||||
if(size.width != capture->image->width ||
|
||||
size.height != capture->image->height ||
|
||||
depth != capture->image->depth ||
|
||||
nch != capture->image->nChannels )
|
||||
{
|
||||
cvReleaseImage(&capture->image);
|
||||
capture->image = cvCreateImage(size, depth, nch);
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
|
||||
CvCapture * cvCaptureFromCAM_CMU (int index)
|
||||
{
|
||||
CvCaptureCAM_CMU* capture = (CvCaptureCAM_CMU*)cvAlloc( sizeof(*capture));
|
||||
memset( capture, 0, sizeof(*capture));
|
||||
capture->vtable = &captureCAM_CMU_vtable;
|
||||
|
||||
if( icvOpenCAM_CMU( capture, index ))
|
||||
return (CvCapture*)capture;
|
||||
|
||||
cvReleaseCapture( (CvCapture**)&capture );
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif // CMU
|
||||
#endif // WIN32
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,795 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// Intel License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000, Intel Corporation, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of Intel Corporation may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "_highgui.h"
|
||||
|
||||
|
||||
extern "C" {
|
||||
#include <ffmpeg/avformat.h>
|
||||
}
|
||||
|
||||
#ifdef NDEBUG
|
||||
#define CV_WARN(message)
|
||||
#else
|
||||
#define CV_WARN(message) fprintf(stderr, "warning: %s (%s:%d)\n", message, __FILE__, __LINE__)
|
||||
#endif
|
||||
|
||||
typedef struct CvCaptureAVI_FFMPEG
|
||||
{
|
||||
CvCaptureVTable * vtable;
|
||||
|
||||
AVFormatContext * ic;
|
||||
int video_stream;
|
||||
AVStream * video_st;
|
||||
AVFrame * picture;
|
||||
int64_t picture_pts;
|
||||
AVFrame rgb_picture;
|
||||
|
||||
IplImage frame;
|
||||
} CvCaptureAVI_FFMPEG;
|
||||
|
||||
static void icvCloseAVI_FFMPEG( CvCaptureAVI_FFMPEG* capture )
|
||||
{
|
||||
//cvFree( (void**)&(capture->entries) );
|
||||
|
||||
if( capture->picture )
|
||||
av_free(capture->picture);
|
||||
|
||||
if( capture->video_st )
|
||||
{
|
||||
#if LIBAVFORMAT_BUILD > 4628
|
||||
avcodec_close( capture->video_st->codec );
|
||||
#else
|
||||
avcodec_close( &capture->video_st->codec );
|
||||
#endif
|
||||
capture->video_st = NULL;
|
||||
}
|
||||
|
||||
if( capture->ic )
|
||||
{
|
||||
av_close_input_file(capture->ic);
|
||||
capture->ic = NULL;
|
||||
}
|
||||
|
||||
if( capture->rgb_picture.data[0] )
|
||||
cvFree( &capture->rgb_picture.data[0] );
|
||||
|
||||
memset( &capture->frame, 0, sizeof(capture->frame));
|
||||
}
|
||||
|
||||
|
||||
static int icvOpenAVI_FFMPEG( CvCaptureAVI_FFMPEG* capture, const char* filename )
|
||||
{
|
||||
int err, valid = 0, video_index = -1, i;
|
||||
AVFormatContext *ic;
|
||||
|
||||
capture->ic = NULL;
|
||||
capture->video_stream = -1;
|
||||
capture->video_st = NULL;
|
||||
/* register all codecs, demux and protocols */
|
||||
av_register_all();
|
||||
|
||||
err = av_open_input_file(&ic, filename, NULL, 0, NULL);
|
||||
if (err < 0) {
|
||||
CV_WARN("Error opening file");
|
||||
goto exit_func;
|
||||
}
|
||||
capture->ic = ic;
|
||||
err = av_find_stream_info(ic);
|
||||
if (err < 0) {
|
||||
CV_WARN("Could not find codec parameters");
|
||||
goto exit_func;
|
||||
}
|
||||
for(i = 0; i < ic->nb_streams; i++) {
|
||||
#if LIBAVFORMAT_BUILD > 4628
|
||||
AVCodecContext *enc = ic->streams[i]->codec;
|
||||
#else
|
||||
AVCodecContext *enc = &ic->streams[i]->codec;
|
||||
#endif
|
||||
AVCodec *codec;
|
||||
if( CODEC_TYPE_VIDEO == enc->codec_type && video_index < 0) {
|
||||
video_index = i;
|
||||
codec = avcodec_find_decoder(enc->codec_id);
|
||||
if (!codec ||
|
||||
avcodec_open(enc, codec) < 0)
|
||||
goto exit_func;
|
||||
capture->video_stream = i;
|
||||
capture->video_st = ic->streams[i];
|
||||
capture->picture = avcodec_alloc_frame();
|
||||
|
||||
capture->rgb_picture.data[0] = (uchar*)cvAlloc(
|
||||
avpicture_get_size( PIX_FMT_BGR24,
|
||||
enc->width, enc->height ));
|
||||
avpicture_fill( (AVPicture*)&capture->rgb_picture, capture->rgb_picture.data[0],
|
||||
PIX_FMT_BGR24, enc->width, enc->height );
|
||||
|
||||
cvInitImageHeader( &capture->frame, cvSize( enc->width,
|
||||
enc->height ), 8, 3, 0, 4 );
|
||||
cvSetData( &capture->frame, capture->rgb_picture.data[0],
|
||||
capture->rgb_picture.linesize[0] );
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(video_index >= 0)
|
||||
valid = 1;
|
||||
|
||||
exit_func:
|
||||
|
||||
if( !valid )
|
||||
icvCloseAVI_FFMPEG( capture );
|
||||
|
||||
return valid;
|
||||
}
|
||||
|
||||
|
||||
static int icvGrabFrameAVI_FFMPEG( CvCaptureAVI_FFMPEG* capture )
|
||||
{
|
||||
int valid=0;
|
||||
static bool bFirstTime = true;
|
||||
static AVPacket pkt;
|
||||
int got_picture;
|
||||
|
||||
// First time we're called, set packet.data to NULL to indicate it
|
||||
// doesn't have to be freed
|
||||
if (bFirstTime) {
|
||||
bFirstTime = false;
|
||||
pkt.data = NULL;
|
||||
}
|
||||
|
||||
if( !capture || !capture->ic || !capture->video_st )
|
||||
return 0;
|
||||
|
||||
// free last packet if exist
|
||||
if (pkt.data != NULL) {
|
||||
av_free_packet (&pkt);
|
||||
}
|
||||
|
||||
// get the next frame
|
||||
while ((0 == valid) && (av_read_frame(capture->ic, &pkt) >= 0)) {
|
||||
if( pkt.stream_index != capture->video_stream ) continue;
|
||||
|
||||
#if LIBAVFORMAT_BUILD > 4628
|
||||
avcodec_decode_video(capture->video_st->codec,
|
||||
capture->picture, &got_picture,
|
||||
pkt.data, pkt.size);
|
||||
#else
|
||||
avcodec_decode_video(&capture->video_st->codec,
|
||||
capture->picture, &got_picture,
|
||||
pkt.data, pkt.size);
|
||||
#endif
|
||||
|
||||
if (got_picture) {
|
||||
// we have a new picture, so memorize it
|
||||
capture->picture_pts = pkt.pts;
|
||||
valid = 1;
|
||||
}
|
||||
}
|
||||
|
||||
// return if we have a new picture or not
|
||||
return valid;
|
||||
}
|
||||
|
||||
|
||||
static const IplImage* icvRetrieveFrameAVI_FFMPEG( CvCaptureAVI_FFMPEG* capture )
|
||||
{
|
||||
if( !capture || !capture->video_st || !capture->picture->data[0] )
|
||||
return 0;
|
||||
#if LIBAVFORMAT_BUILD > 4628
|
||||
img_convert( (AVPicture*)&capture->rgb_picture, PIX_FMT_BGR24,
|
||||
(AVPicture*)capture->picture,
|
||||
capture->video_st->codec->pix_fmt,
|
||||
capture->video_st->codec->width,
|
||||
capture->video_st->codec->height );
|
||||
#else
|
||||
img_convert( (AVPicture*)&capture->rgb_picture, PIX_FMT_BGR24,
|
||||
(AVPicture*)capture->picture,
|
||||
capture->video_st->codec.pix_fmt,
|
||||
capture->video_st->codec.width,
|
||||
capture->video_st->codec.height );
|
||||
#endif
|
||||
return &capture->frame;
|
||||
}
|
||||
|
||||
|
||||
static int icvSetPropertyAVI_FFMPEG( CvCaptureAVI_FFMPEG* capture,
|
||||
int property_id, double value );
|
||||
|
||||
static double icvGetPropertyAVI_FFMPEG( CvCaptureAVI_FFMPEG* capture, int property_id )
|
||||
{
|
||||
if( !capture || !capture->video_st || !capture->picture->data[0] )
|
||||
return 0;
|
||||
|
||||
int64_t timestamp;
|
||||
timestamp = capture->picture_pts;
|
||||
|
||||
switch( property_id )
|
||||
{
|
||||
case CV_CAP_PROP_POS_MSEC:
|
||||
if(capture->ic->start_time != static_cast<double>(AV_NOPTS_VALUE))
|
||||
return (double)(timestamp - capture->ic->start_time)*1000/(double)AV_TIME_BASE;
|
||||
break;
|
||||
case CV_CAP_PROP_POS_FRAMES:
|
||||
if(capture->video_st->cur_dts != static_cast<double>(AV_NOPTS_VALUE))
|
||||
return (double)capture->video_st->cur_dts-1;
|
||||
break;
|
||||
case CV_CAP_PROP_POS_AVI_RATIO:
|
||||
if(capture->ic->start_time != static_cast<double>(AV_NOPTS_VALUE) && capture->ic->duration != static_cast<double>(AV_NOPTS_VALUE))
|
||||
return (double)(timestamp-capture->ic->start_time)/(double)capture->ic->duration;
|
||||
break;
|
||||
case CV_CAP_PROP_FRAME_WIDTH:
|
||||
return capture->frame.width;
|
||||
break;
|
||||
case CV_CAP_PROP_FRAME_HEIGHT:
|
||||
return capture->frame.height;
|
||||
break;
|
||||
case CV_CAP_PROP_FPS:
|
||||
#if LIBAVCODEC_BUILD > 4753
|
||||
return av_q2d (capture->video_st->r_frame_rate);
|
||||
#else
|
||||
return (double)capture->video_st->codec.frame_rate
|
||||
/ (double)capture->video_st->codec.frame_rate_base;
|
||||
#endif
|
||||
break;
|
||||
case CV_CAP_PROP_FOURCC:
|
||||
#if LIBAVFORMAT_BUILD > 4628
|
||||
return (double)capture->video_st->codec->codec_tag;
|
||||
#else
|
||||
return (double)capture->video_st->codec.codec_tag;
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static int icvSetPropertyAVI_FFMPEG( CvCaptureAVI_FFMPEG* capture,
|
||||
int property_id, double value )
|
||||
{
|
||||
if( !capture || !capture->video_st || !capture->picture->data[0] )
|
||||
return 0;
|
||||
switch( property_id )
|
||||
{
|
||||
#if 0
|
||||
case CV_CAP_PROP_POS_MSEC:
|
||||
case CV_CAP_PROP_POS_FRAMES:
|
||||
case CV_CAP_PROP_POS_AVI_RATIO:
|
||||
{
|
||||
int64_t timestamp = AV_NOPTS_VALUE;
|
||||
switch( property_id )
|
||||
{
|
||||
case CV_CAP_PROP_POS_FRAMES:
|
||||
if(capture->ic->start_time != AV_NOPTS_VALUE) {
|
||||
value *= (double)capture->video_st->codec.frame_rate_base
|
||||
/ (double)capture->video_st->codec.frame_rate;
|
||||
timestamp = capture->ic->start_time+(int64_t)(value*AV_TIME_BASE);
|
||||
}
|
||||
break;
|
||||
case CV_CAP_PROP_POS_MSEC:
|
||||
if(capture->ic->start_time != AV_NOPTS_VALUE)
|
||||
timestamp = capture->ic->start_time+(int64_t)(value*AV_TIME_BASE/1000);
|
||||
break;
|
||||
case CV_CAP_PROP_POS_AVI_RATIO:
|
||||
if(capture->ic->start_time != AV_NOPTS_VALUE && capture->ic->duration != AV_NOPTS_VALUE)
|
||||
timestamp = capture->ic->start_time+(int64_t)(value*capture->ic->duration);
|
||||
break;
|
||||
}
|
||||
if(timestamp != AV_NOPTS_VALUE) {
|
||||
//printf("timestamp=%g\n",(double)timestamp);
|
||||
int ret = av_seek_frame(capture->ic, -1, timestamp, 0);
|
||||
if (ret < 0) {
|
||||
fprintf(stderr, "HIGHGUI ERROR: AVI: could not seek to position %0.3f\n",
|
||||
(double)timestamp / AV_TIME_BASE);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static CvCaptureVTable captureAVI_FFMPEG_vtable =
|
||||
{
|
||||
6,
|
||||
(CvCaptureCloseFunc)icvCloseAVI_FFMPEG,
|
||||
(CvCaptureGrabFrameFunc)icvGrabFrameAVI_FFMPEG,
|
||||
(CvCaptureRetrieveFrameFunc)icvRetrieveFrameAVI_FFMPEG,
|
||||
(CvCaptureGetPropertyFunc)icvGetPropertyAVI_FFMPEG,
|
||||
(CvCaptureSetPropertyFunc)icvSetPropertyAVI_FFMPEG,
|
||||
(CvCaptureGetDescriptionFunc)0
|
||||
};
|
||||
|
||||
|
||||
CvCapture* cvCaptureFromFile_FFMPEG( const char* filename )
|
||||
{
|
||||
CvCaptureAVI_FFMPEG* capture = 0;
|
||||
|
||||
if( filename )
|
||||
{
|
||||
capture = (CvCaptureAVI_FFMPEG*)cvAlloc( sizeof(*capture));
|
||||
memset( capture, 0, sizeof(*capture));
|
||||
|
||||
capture->vtable = &captureAVI_FFMPEG_vtable;
|
||||
|
||||
if( !icvOpenAVI_FFMPEG( capture, filename ))
|
||||
cvReleaseCapture( (CvCapture**)&capture );
|
||||
}
|
||||
|
||||
return (CvCapture*)capture;
|
||||
}
|
||||
|
||||
///////////////// FFMPEG CvVideoWriter implementation //////////////////////////
|
||||
typedef struct CvAVI_FFMPEG_Writer
|
||||
{
|
||||
AVOutputFormat *fmt;
|
||||
AVFormatContext *oc;
|
||||
uint8_t * outbuf;
|
||||
uint32_t outbuf_size;
|
||||
FILE * outfile;
|
||||
AVFrame * picture;
|
||||
AVFrame * rgb_picture;
|
||||
uint8_t * picbuf;
|
||||
AVStream * video_st;
|
||||
} CvAVI_FFMPEG_Writer;
|
||||
|
||||
/**
|
||||
* the following function is a modified version of code
|
||||
* found in ffmpeg-0.4.9-pre1/output_example.c
|
||||
*/
|
||||
static AVFrame * icv_alloc_picture_FFMPEG(int pix_fmt, int width, int height, bool alloc)
|
||||
{
|
||||
AVFrame * picture;
|
||||
uint8_t * picture_buf;
|
||||
int size;
|
||||
|
||||
picture = avcodec_alloc_frame();
|
||||
if (!picture)
|
||||
return NULL;
|
||||
size = avpicture_get_size(pix_fmt, width, height);
|
||||
if(alloc){
|
||||
picture_buf = (uint8_t *) cvAlloc(size);
|
||||
if (!picture_buf)
|
||||
{
|
||||
av_free(picture);
|
||||
return NULL;
|
||||
}
|
||||
avpicture_fill((AVPicture *)picture, picture_buf,
|
||||
pix_fmt, width, height);
|
||||
}
|
||||
else {
|
||||
}
|
||||
return picture;
|
||||
}
|
||||
|
||||
/* add a video output stream */
|
||||
static AVStream *icv_add_video_stream_FFMPEG(AVFormatContext *oc, int codec_tag, int w, int h, int bitrate, double fps, int pixel_format)
|
||||
{
|
||||
AVCodecContext *c;
|
||||
AVStream *st;
|
||||
int codec_id;
|
||||
int frame_rate, frame_rate_base;
|
||||
AVCodec *codec;
|
||||
|
||||
|
||||
st = av_new_stream(oc, 0);
|
||||
if (!st) {
|
||||
CV_WARN("Could not allocate stream");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#if LIBAVFORMAT_BUILD > 4628
|
||||
c = st->codec;
|
||||
#else
|
||||
c = &(st->codec);
|
||||
#endif
|
||||
#if LIBAVFORMAT_BUILD > 4621
|
||||
codec_id = av_guess_codec(oc->oformat, NULL, oc->filename, NULL, CODEC_TYPE_VIDEO);
|
||||
#else
|
||||
codec_id = oc->oformat->video_codec;
|
||||
#endif
|
||||
|
||||
if(codec_tag) c->codec_tag=codec_tag;
|
||||
|
||||
c->codec_id = (CodecID) codec_id;
|
||||
codec = avcodec_find_encoder(c->codec_id);
|
||||
|
||||
c->codec_type = CODEC_TYPE_VIDEO;
|
||||
|
||||
/* put sample parameters */
|
||||
c->bit_rate = bitrate;
|
||||
|
||||
/* resolution must be a multiple of two */
|
||||
c->width = w;
|
||||
c->height = h;
|
||||
|
||||
/* time base: this is the fundamental unit of time (in seconds) in terms
|
||||
of which frame timestamps are represented. for fixed-fps content,
|
||||
timebase should be 1/framerate and timestamp increments should be
|
||||
identically 1. */
|
||||
frame_rate=cvRound(fps);
|
||||
frame_rate_base=1;
|
||||
while (fabs((double)frame_rate/frame_rate_base) - fps > 0.001){
|
||||
frame_rate_base*=10;
|
||||
frame_rate=cvRound(fps*frame_rate_base);
|
||||
}
|
||||
#if LIBAVFORMAT_BUILD > 4752
|
||||
c->time_base.den = frame_rate;
|
||||
c->time_base.num = frame_rate_base;
|
||||
/* adjust time base for supported framerates */
|
||||
if(codec && codec->supported_framerates){
|
||||
const AVRational *p= codec->supported_framerates;
|
||||
AVRational req= (AVRational){frame_rate, frame_rate_base};
|
||||
const AVRational *best=NULL;
|
||||
AVRational best_error= (AVRational){INT_MAX, 1};
|
||||
for(; p->den!=0; p++){
|
||||
AVRational error= av_sub_q(req, *p);
|
||||
if(error.num <0) error.num *= -1;
|
||||
if(av_cmp_q(error, best_error) < 0){
|
||||
best_error= error;
|
||||
best= p;
|
||||
}
|
||||
}
|
||||
c->time_base.den= best->num;
|
||||
c->time_base.num= best->den;
|
||||
}
|
||||
#else
|
||||
c->frame_rate = frame_rate;
|
||||
c->frame_rate_base = frame_rate_base;
|
||||
#endif
|
||||
|
||||
c->gop_size = 12; /* emit one intra frame every twelve frames at most */
|
||||
c->pix_fmt = (PixelFormat) pixel_format;
|
||||
if (c->codec_id == CODEC_ID_MPEG2VIDEO) {
|
||||
/* just for testing, we also add B frames */
|
||||
c->max_b_frames = 2;
|
||||
}
|
||||
if (c->codec_id == CODEC_ID_MPEG1VIDEO){
|
||||
/* needed to avoid using macroblocks in which some coeffs overflow
|
||||
this doesnt happen with normal video, it just happens here as the
|
||||
motion of the chroma plane doesnt match the luma plane */
|
||||
c->mb_decision=2;
|
||||
}
|
||||
// some formats want stream headers to be seperate
|
||||
if(!strcmp(oc->oformat->name, "mp4") || !strcmp(oc->oformat->name, "mov") || !strcmp(oc->oformat->name, "3gp"))
|
||||
c->flags |= CODEC_FLAG_GLOBAL_HEADER;
|
||||
|
||||
return st;
|
||||
}
|
||||
|
||||
/// Create a video writer object that uses FFMPEG
|
||||
CV_IMPL CvVideoWriter* cvCreateVideoWriter( const char * filename, int fourcc,
|
||||
double fps, CvSize frameSize, int /*is_color*/ )
|
||||
{
|
||||
CV_FUNCNAME("cvCreateVideoWriter");
|
||||
|
||||
CvAVI_FFMPEG_Writer * writer = NULL;
|
||||
|
||||
__BEGIN__;
|
||||
|
||||
// check arguments
|
||||
assert (filename);
|
||||
assert (fps > 0);
|
||||
assert (frameSize.width > 0 && frameSize.height > 0);
|
||||
|
||||
// allocate memory for structure...
|
||||
writer = (CvAVI_FFMPEG_Writer *) cvAlloc( sizeof(CvAVI_FFMPEG_Writer));
|
||||
memset (writer, 0, sizeof (*writer));
|
||||
|
||||
// tell FFMPEG to register codecs
|
||||
av_register_all ();
|
||||
|
||||
/* auto detect the output format from the name. default is mpeg. */
|
||||
writer->fmt = guess_format(NULL, filename, NULL);
|
||||
if (!writer->fmt) {
|
||||
CV_ERROR( CV_StsUnsupportedFormat, "Could not deduce output format from file extension");
|
||||
//writer->fmt = guess_format("mpeg", NULL, NULL);
|
||||
}
|
||||
|
||||
// alloc memory for context
|
||||
writer->oc = av_alloc_format_context();
|
||||
assert (writer->oc);
|
||||
|
||||
/* set file name */
|
||||
writer->oc->oformat = writer->fmt;
|
||||
snprintf(writer->oc->filename, sizeof(writer->oc->filename), "%s", filename);
|
||||
|
||||
// TODO -- safe to ignore output audio stream?
|
||||
writer->video_st = icv_add_video_stream_FFMPEG(writer->oc, fourcc, frameSize.width, frameSize.height, 800000, fps, PIX_FMT_YUV420P);
|
||||
|
||||
|
||||
/* set the output parameters (must be done even if no
|
||||
parameters). */
|
||||
if (av_set_parameters(writer->oc, NULL) < 0) {
|
||||
CV_ERROR(CV_StsBadArg, "Invalid output format parameters");
|
||||
}
|
||||
|
||||
dump_format(writer->oc, 0, filename, 1);
|
||||
|
||||
/* now that all the parameters are set, we can open the audio and
|
||||
video codecs and allocate the necessary encode buffers */
|
||||
if (!writer->video_st){
|
||||
CV_ERROR(CV_StsBadArg, "Couldn't open video stream");
|
||||
}
|
||||
|
||||
AVCodec *codec;
|
||||
AVCodecContext *c;
|
||||
|
||||
#if LIBAVFORMAT_BUILD > 4628
|
||||
c = (writer->video_st->codec);
|
||||
#else
|
||||
c = &(writer->video_st->codec);
|
||||
#endif
|
||||
|
||||
/* find the video encoder */
|
||||
codec = avcodec_find_encoder(c->codec_id);
|
||||
if (!codec) {
|
||||
CV_ERROR(CV_StsBadArg, "codec not found");
|
||||
}
|
||||
|
||||
/* open the codec */
|
||||
if (avcodec_open(c, codec) < 0) {
|
||||
char errtext[256];
|
||||
sprintf(errtext, "Could not open codec '%s'", codec->name);
|
||||
CV_ERROR(CV_StsBadArg, errtext);
|
||||
}
|
||||
|
||||
// printf("Using codec %s\n", codec->name);
|
||||
writer->outbuf = NULL;
|
||||
|
||||
if (!(writer->oc->oformat->flags & AVFMT_RAWPICTURE)) {
|
||||
/* allocate output buffer */
|
||||
/* XXX: API change will be done */
|
||||
writer->outbuf_size = 200000;
|
||||
writer->outbuf = (uint8_t *) malloc(writer->outbuf_size);
|
||||
}
|
||||
|
||||
bool need_color_convert;
|
||||
need_color_convert = c->pix_fmt != PIX_FMT_BGR24;
|
||||
|
||||
/* allocate the encoded raw picture */
|
||||
writer->picture = icv_alloc_picture_FFMPEG(c->pix_fmt, c->width, c->height, need_color_convert);
|
||||
if (!writer->picture) {
|
||||
CV_ERROR(CV_StsNoMem, "Could not allocate picture");
|
||||
}
|
||||
|
||||
/* if the output format is not YUV420P, then a temporary YUV420P
|
||||
picture is needed too. It is then converted to the required
|
||||
output format */
|
||||
writer->rgb_picture = NULL;
|
||||
if ( need_color_convert ) {
|
||||
writer->rgb_picture = icv_alloc_picture_FFMPEG(PIX_FMT_BGR24, c->width, c->height, false);
|
||||
if (!writer->rgb_picture) {
|
||||
CV_ERROR(CV_StsNoMem, "Could not allocate picture");
|
||||
}
|
||||
}
|
||||
|
||||
/* open the output file, if needed */
|
||||
if (!(writer->fmt->flags & AVFMT_NOFILE)) {
|
||||
if (url_fopen(&writer->oc->pb, filename, URL_WRONLY) < 0) {
|
||||
CV_ERROR(CV_StsBadArg, "Couldn't open output file for writing");
|
||||
}
|
||||
}
|
||||
|
||||
/* write the stream header, if any */
|
||||
av_write_header( writer->oc );
|
||||
|
||||
|
||||
__END__;
|
||||
|
||||
// return what we got
|
||||
return (CvVideoWriter *) writer;
|
||||
}
|
||||
|
||||
int icv_av_write_frame_FFMPEG( AVFormatContext * oc, AVStream * video_st, uint8_t * outbuf, uint32_t outbuf_size, AVFrame * picture ){
|
||||
CV_FUNCNAME("icv_av_write_frame_FFMPEG");
|
||||
|
||||
#if LIBAVFORMAT_BUILD > 4628
|
||||
AVCodecContext * c = video_st->codec;
|
||||
#else
|
||||
AVCodecContext * c = &(video_st->codec);
|
||||
#endif
|
||||
int out_size;
|
||||
int ret;
|
||||
|
||||
__BEGIN__;
|
||||
|
||||
if (oc->oformat->flags & AVFMT_RAWPICTURE) {
|
||||
/* raw video case. The API will change slightly in the near
|
||||
futur for that */
|
||||
AVPacket pkt;
|
||||
av_init_packet(&pkt);
|
||||
|
||||
pkt.flags |= PKT_FLAG_KEY;
|
||||
pkt.stream_index= video_st->index;
|
||||
pkt.data= (uint8_t *)picture;
|
||||
pkt.size= sizeof(AVPicture);
|
||||
|
||||
ret = av_write_frame(oc, &pkt);
|
||||
} else {
|
||||
/* encode the image */
|
||||
out_size = avcodec_encode_video(c, outbuf, outbuf_size, picture);
|
||||
/* if zero size, it means the image was buffered */
|
||||
if (out_size > 0) {
|
||||
AVPacket pkt;
|
||||
av_init_packet(&pkt);
|
||||
#if LIBAVFORMAT_BUILD > 4752
|
||||
pkt.pts = av_rescale_q(c->coded_frame->pts, c->time_base, video_st->time_base);
|
||||
#else
|
||||
pkt.pts = c->coded_frame->pts;
|
||||
#endif
|
||||
if(c->coded_frame->key_frame)
|
||||
pkt.flags |= PKT_FLAG_KEY;
|
||||
pkt.stream_index= video_st->index;
|
||||
pkt.data= outbuf;
|
||||
pkt.size= out_size;
|
||||
|
||||
/* write the compressed frame in the media file */
|
||||
ret = av_write_frame(oc, &pkt);
|
||||
} else {
|
||||
ret = 0;
|
||||
}
|
||||
}
|
||||
if (ret != 0) {
|
||||
CV_ERROR(CV_StsError, "Error while writing video frame");
|
||||
}
|
||||
|
||||
__END__;
|
||||
return CV_StsOk;
|
||||
}
|
||||
|
||||
/// write a frame with FFMPEG
|
||||
CV_IMPL int cvWriteFrame( CvVideoWriter * writer, const IplImage * image )
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
CV_FUNCNAME("cvWriteFrame");
|
||||
|
||||
__BEGIN__;
|
||||
|
||||
// typecast from opaque data type to implemented struct
|
||||
CvAVI_FFMPEG_Writer * mywriter = (CvAVI_FFMPEG_Writer*) writer;
|
||||
#if LIBAVFORMAT_BUILD > 4628
|
||||
AVCodecContext *c = mywriter->video_st->codec;
|
||||
#else
|
||||
AVCodecContext *c = &(mywriter->video_st->codec);
|
||||
#endif
|
||||
// check parameters
|
||||
assert ( image );
|
||||
assert ( image->nChannels == 3 );
|
||||
assert ( image->depth == IPL_DEPTH_8U );
|
||||
|
||||
|
||||
// check if buffer sizes match, i.e. image has expected format (size, channels, bitdepth, alignment)
|
||||
assert (image->imageSize == avpicture_get_size (PIX_FMT_BGR24, image->width, image->height));
|
||||
|
||||
if (c->pix_fmt != PIX_FMT_BGR24 ) {
|
||||
assert( mywriter->rgb_picture );
|
||||
// let rgb_picture point to the raw data buffer of 'image'
|
||||
avpicture_fill((AVPicture *)mywriter->rgb_picture, (uint8_t *) image->imageData,
|
||||
PIX_FMT_BGR24, image->width, image->height);
|
||||
|
||||
// convert to the color format needed by the codec
|
||||
if( img_convert((AVPicture *)mywriter->picture, c->pix_fmt,
|
||||
(AVPicture *)mywriter->rgb_picture, PIX_FMT_BGR24,
|
||||
image->width, image->height) < 0){
|
||||
CV_ERROR(CV_StsUnsupportedFormat, "FFMPEG::img_convert pixel format conversion from BGR24 not handled");
|
||||
}
|
||||
}
|
||||
else{
|
||||
avpicture_fill((AVPicture *)mywriter->picture, (uint8_t *) image->imageData,
|
||||
PIX_FMT_BGR24, image->width, image->height);
|
||||
}
|
||||
|
||||
ret = icv_av_write_frame_FFMPEG( mywriter->oc, mywriter->video_st, mywriter->outbuf, mywriter->outbuf_size, mywriter->picture);
|
||||
|
||||
__END__;
|
||||
return ret;
|
||||
}
|
||||
|
||||
/// close video output stream and free associated memory
|
||||
CV_IMPL void cvReleaseVideoWriter( CvVideoWriter ** writer )
|
||||
{
|
||||
int i;
|
||||
|
||||
// nothing to do if already released
|
||||
if ( !(*writer) )
|
||||
return;
|
||||
|
||||
// release data structures in reverse order
|
||||
CvAVI_FFMPEG_Writer * mywriter = (CvAVI_FFMPEG_Writer*)(*writer);
|
||||
|
||||
/* no more frame to compress. The codec has a latency of a few
|
||||
frames if using B frames, so we get the last frames by
|
||||
passing the same picture again */
|
||||
// TODO -- do we need to account for latency here?
|
||||
|
||||
/* write the trailer, if any */
|
||||
av_write_trailer(mywriter->oc);
|
||||
|
||||
// free pictures
|
||||
#if LIBAVFORMAT_BUILD > 4628
|
||||
if( mywriter->video_st->codec->pix_fmt != PIX_FMT_BGR24){
|
||||
#else
|
||||
if( mywriter->video_st->codec.pix_fmt != PIX_FMT_BGR24){
|
||||
#endif
|
||||
cvFree(&(mywriter->picture->data[0]));
|
||||
}
|
||||
av_free(mywriter->picture);
|
||||
|
||||
if (mywriter->rgb_picture) {
|
||||
av_free(mywriter->rgb_picture);
|
||||
}
|
||||
|
||||
/* close codec */
|
||||
#if LIBAVFORMAT_BUILD > 4628
|
||||
avcodec_close(mywriter->video_st->codec);
|
||||
#else
|
||||
avcodec_close(&(mywriter->video_st->codec));
|
||||
#endif
|
||||
|
||||
av_free(mywriter->outbuf);
|
||||
|
||||
/* free the streams */
|
||||
for(i = 0; i < mywriter->oc->nb_streams; i++) {
|
||||
av_freep(&mywriter->oc->streams[i]->codec);
|
||||
av_freep(&mywriter->oc->streams[i]);
|
||||
}
|
||||
|
||||
if (!(mywriter->fmt->flags & AVFMT_NOFILE)) {
|
||||
/* close the output file */
|
||||
url_fclose(&mywriter->oc->pb);
|
||||
}
|
||||
|
||||
/* free the stream */
|
||||
av_free(mywriter->oc);
|
||||
|
||||
/* free cvVideoWriter */
|
||||
cvFree ( writer );
|
||||
|
||||
// mark as released
|
||||
(*writer) = 0;
|
||||
}
|
||||
@@ -0,0 +1,217 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// Intel License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000, Intel Corporation, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of Intel Corporation may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "_highgui.h"
|
||||
#include "mil.h"
|
||||
|
||||
#if _MSC_VER >= 1200
|
||||
#pragma warning( disable: 4711 )
|
||||
#pragma comment(lib,"mil.lib")
|
||||
#pragma comment(lib,"milmet2.lib")
|
||||
#endif
|
||||
|
||||
#if defined WIN64 && defined EM64T && defined _MSC_VER && !defined __ICL
|
||||
#pragma optimize("",off)
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
/********************* Capturing video from camera via MIL *********************/
|
||||
|
||||
struct
|
||||
{
|
||||
MIL_ID MilApplication;
|
||||
int MilUser;
|
||||
} g_Mil = {0,0}; //global structure for handling MIL application
|
||||
|
||||
typedef struct CvCaptureCAM_MIL
|
||||
{
|
||||
CvCaptureVTable* vtable;
|
||||
MIL_ID
|
||||
MilSystem, /* System identifier. */
|
||||
MilDisplay, /* Display identifier. */
|
||||
MilDigitizer, /* Digitizer identifier. */
|
||||
MilImage; /* Image buffer identifier. */
|
||||
IplImage* rgb_frame;
|
||||
}
|
||||
CvCaptureCAM_MIL;
|
||||
|
||||
// Initialize camera input
|
||||
static int icvOpenCAM_MIL( CvCaptureCAM_MIL* capture, int wIndex )
|
||||
{
|
||||
if( g_Mil.MilApplication == M_NULL )
|
||||
{
|
||||
assert(g_Mil.MilUser == 0);
|
||||
MappAlloc(M_DEFAULT, &(g_Mil.MilApplication) );
|
||||
g_Mil.MilUser = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
assert(g_Mil.MilUser>0);
|
||||
g_Mil.MilUser++;
|
||||
}
|
||||
|
||||
int dev_table[16] = { M_DEV0, M_DEV1, M_DEV2, M_DEV3,
|
||||
M_DEV4, M_DEV5, M_DEV6, M_DEV7,
|
||||
M_DEV8, M_DEV9, M_DEV10, M_DEV11,
|
||||
M_DEV12, M_DEV13, M_DEV14, M_DEV15 };
|
||||
|
||||
//set default window size
|
||||
int w = 320/*160*/;
|
||||
int h = 240/*120*/;
|
||||
|
||||
|
||||
for( ; wIndex < 16; wIndex++ )
|
||||
{
|
||||
MsysAlloc( M_SYSTEM_SETUP, //we use default system,
|
||||
//if this does not work
|
||||
//try to define exact board
|
||||
//e.g.M_SYSTEM_METEOR,M_SYSTEM_METEOR_II...
|
||||
dev_table[wIndex],
|
||||
M_DEFAULT,
|
||||
&(capture->MilSystem) );
|
||||
|
||||
if( capture->MilSystem != M_NULL )
|
||||
break;
|
||||
}
|
||||
if( capture->MilSystem != M_NULL )
|
||||
{
|
||||
MdigAlloc(capture->MilSystem,M_DEFAULT,
|
||||
M_CAMERA_SETUP, //default. May be M_NTSC or other
|
||||
M_DEFAULT,&(capture->MilDigitizer));
|
||||
|
||||
capture->rgb_frame = cvCreateImage(cvSize(w,h), IPL_DEPTH_8U, 3 );
|
||||
MdigControl(capture->MilDigitizer, M_GRAB_SCALE, 1.0 / 2);
|
||||
|
||||
/*below line enables getting image vertical orientation
|
||||
consistent with VFW but it introduces some image corruption
|
||||
on MeteorII, so we left the image as is*/
|
||||
//MdigControl(capture->MilDigitizer, M_GRAB_DIRECTION_Y, M_REVERSE );
|
||||
|
||||
capture->MilImage = MbufAllocColor(capture->MilSystem, 3, w, h,
|
||||
8+M_UNSIGNED,
|
||||
M_IMAGE + M_GRAB,
|
||||
M_NULL);
|
||||
}
|
||||
|
||||
return capture->MilSystem != M_NULL;
|
||||
}
|
||||
|
||||
static void icvCloseCAM_MIL( CvCaptureCAM_MIL* capture )
|
||||
{
|
||||
if( capture->MilSystem != M_NULL )
|
||||
{
|
||||
MdigFree( capture->MilDigitizer );
|
||||
MbufFree( capture->MilImage );
|
||||
MsysFree( capture->MilSystem );
|
||||
cvReleaseImage(&capture->rgb_frame );
|
||||
capture->rgb_frame = 0;
|
||||
|
||||
g_Mil.MilUser--;
|
||||
if(!g_Mil.MilUser)
|
||||
MappFree(g_Mil.MilApplication);
|
||||
|
||||
capture->MilSystem = M_NULL;
|
||||
capture->MilDigitizer = M_NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static int icvGrabFrameCAM_MIL( CvCaptureCAM_MIL* capture )
|
||||
{
|
||||
if( capture->MilSystem )
|
||||
{
|
||||
MdigGrab(capture->MilDigitizer, capture->MilImage);
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static IplImage* icvRetrieveFrameCAM_MIL( CvCaptureCAM_MIL* capture )
|
||||
{
|
||||
MbufGetColor(capture->MilImage, M_BGR24+M_PACKED, M_ALL_BAND, (void*)(capture->rgb_frame->imageData));
|
||||
//make image vertical orientation consistent with VFW
|
||||
//You can find some better way to do this
|
||||
capture->rgb_frame->origin = IPL_ORIGIN_BL;
|
||||
cvFlip(capture->rgb_frame,capture->rgb_frame,0);
|
||||
return capture->rgb_frame;
|
||||
}
|
||||
|
||||
static double icvGetPropertyCAM_MIL( CvCaptureCAM_MIL* capture, int property_id )
|
||||
{
|
||||
switch( property_id )
|
||||
{
|
||||
case CV_CAP_PROP_FRAME_WIDTH:
|
||||
if( capture->rgb_frame) return capture->rgb_frame->width;
|
||||
case CV_CAP_PROP_FRAME_HEIGHT:
|
||||
if( capture->rgb_frame) return capture->rgb_frame->height;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static CvCaptureVTable captureCAM_MIL_vtable =
|
||||
{
|
||||
6,
|
||||
(CvCaptureCloseFunc)icvCloseCAM_MIL,
|
||||
(CvCaptureGrabFrameFunc)icvGrabFrameCAM_MIL,
|
||||
(CvCaptureRetrieveFrameFunc)icvRetrieveFrameCAM_MIL,
|
||||
(CvCaptureGetPropertyFunc)icvGetPropertyCAM_MIL,
|
||||
(CvCaptureSetPropertyFunc)0,
|
||||
(CvCaptureGetDescriptionFunc)0
|
||||
};
|
||||
|
||||
CvCapture* cvCaptureFromCAM_MIL( int index )
|
||||
{
|
||||
CvCaptureCAM_MIL* capture = (CvCaptureCAM_MIL*)cvAlloc( sizeof(*capture));
|
||||
memset( capture, 0, sizeof(*capture));
|
||||
capture->vtable = &captureCAM_MIL_vtable;
|
||||
|
||||
if( icvOpenCAM_MIL( capture, index ))
|
||||
return (CvCapture*)capture;
|
||||
|
||||
cvReleaseCapture( (CvCapture**)&capture );
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,242 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// Intel License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000, Intel Corporation, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of Intel Corporation may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "_highgui.h"
|
||||
#include <DeepSeaIF.h>
|
||||
|
||||
#if _MSC_VER >= 1200
|
||||
#pragma comment(lib,"DeepSeaIF.lib")
|
||||
#endif
|
||||
|
||||
|
||||
/****************** Capturing video from TYZX stereo camera *******************/
|
||||
/** Initially developed by Roman Stanchak rstanchak@yahoo.com */
|
||||
|
||||
typedef struct CvCaptureCAM_TYZX
|
||||
{
|
||||
CvCaptureVTable* vtable;
|
||||
int index;
|
||||
IplImage* image;
|
||||
}
|
||||
CvCaptureCAM_TYZX;
|
||||
|
||||
static int icvOpenCAM_TYZX (CvCaptureCAM_TYZX * capture, int wIndex );
|
||||
static int icvSetPropertyCAM_TYZX (CvCaptureCAM_TYZX* capture, int property_id, double value );
|
||||
static void icvCloseCAM_TYZX (CvCaptureCAM_TYZX* capture );
|
||||
static int icvGrabFrameCAM_TYZX (CvCaptureCAM_TYZX* capture );
|
||||
static IplImage * icvRetrieveFrameCAM_TYZX (CvCaptureCAM_TYZX* capture );
|
||||
static double icvGetPropertyCAM_TYZX (CvCaptureCAM_TYZX* capture, int property_id );
|
||||
static int icvSetPropertyCAM_TYZX (CvCaptureCAM_TYZX* capture, int property_id, double value );
|
||||
|
||||
static CvCaptureVTable captureCAM_TYZX_vtable =
|
||||
{
|
||||
6,
|
||||
(CvCaptureCloseFunc)icvCloseCAM_TYZX,
|
||||
(CvCaptureGrabFrameFunc)icvGrabFrameCAM_TYZX,
|
||||
(CvCaptureRetrieveFrameFunc)icvRetrieveFrameCAM_TYZX,
|
||||
(CvCaptureGetPropertyFunc)icvGetPropertyCAM_TYZX,
|
||||
(CvCaptureSetPropertyFunc)icvSetPropertyCAM_TYZX,
|
||||
(CvCaptureGetDescriptionFunc)0
|
||||
};
|
||||
|
||||
|
||||
|
||||
DeepSeaIF * g_tyzx_camera = 0;
|
||||
int g_tyzx_refcount = 0;
|
||||
|
||||
static int icvOpenCAM_TYZX(CvCaptureCAM_TYZX * capture, int index )
|
||||
{
|
||||
if(!g_tyzx_camera){
|
||||
g_tyzx_camera = new DeepSeaIF;
|
||||
if(!g_tyzx_camera) return 0;
|
||||
|
||||
if(!g_tyzx_camera->initializeSettings(NULL)){
|
||||
delete g_tyzx_camera;
|
||||
return 0;
|
||||
}
|
||||
|
||||
// set initial sensor mode
|
||||
// TODO is g_tyzx_camera redundant?
|
||||
g_tyzx_camera->setSensorMode(g_tyzx_camera->getSensorMode());
|
||||
|
||||
// mm's
|
||||
g_tyzx_camera->setZUnits((int) 1000);
|
||||
|
||||
g_tyzx_camera->enableLeftColor(true);
|
||||
g_tyzx_camera->setColorMode(DeepSeaIF::BGRcolor);
|
||||
g_tyzx_camera->setDoIntensityCrop(true);
|
||||
g_tyzx_camera->enable8bitImages(true);
|
||||
if(!g_tyzx_camera->startCapture()){
|
||||
return 0;
|
||||
}
|
||||
g_tyzx_refcount++;
|
||||
}
|
||||
capture->index=index;
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void icvCloseCAM_TYZX( CvCaptureCAM_TYZX* capture )
|
||||
{
|
||||
if( capture && capture->image )
|
||||
{
|
||||
cvReleaseImage( &capture->image );
|
||||
capture->image = 0;
|
||||
g_tyzx_refcount--;
|
||||
if(g_tyzx_refcount==0){
|
||||
delete g_tyzx_camera;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static int icvGrabFrameCAM_TYZX (CvCaptureCAM_TYZX * )
|
||||
{
|
||||
return g_tyzx_camera && g_tyzx_camera->grab();
|
||||
}
|
||||
|
||||
static void icvAllocateImageCAM_TYZX (CvCaptureCAM_TYZX * capture)
|
||||
{
|
||||
int depth, nch;
|
||||
CvSize size;
|
||||
|
||||
// assume we want to resize
|
||||
if(capture->image)
|
||||
{
|
||||
cvReleaseImage(&(capture->image));
|
||||
}
|
||||
|
||||
// figure out size depending on index provided
|
||||
switch(capture->index){
|
||||
case CV_TYZX_RIGHT:
|
||||
size = cvSize(g_tyzx_camera->intensityWidth(), g_tyzx_camera->intensityHeight());
|
||||
depth = 8;
|
||||
nch = 1;
|
||||
break;
|
||||
case CV_TYZX_Z:
|
||||
size = cvSize(g_tyzx_camera->zWidth(), g_tyzx_camera->zHeight());
|
||||
depth = IPL_DEPTH_16S;
|
||||
nch = 1;
|
||||
break;
|
||||
case CV_TYZX_LEFT:
|
||||
default:
|
||||
size = cvSize(g_tyzx_camera->intensityWidth(), g_tyzx_camera->intensityHeight());
|
||||
depth = 8;
|
||||
nch = 1;
|
||||
break;
|
||||
}
|
||||
capture->image = cvCreateImage(size, depth, nch);
|
||||
}
|
||||
|
||||
/// Copy 'grabbed' image into capture buffer and return it.
|
||||
static IplImage * icvRetrieveFrameCAM_TYZX (CvCaptureCAM_TYZX * capture)
|
||||
{
|
||||
if(!capture || !g_tyzx_camera) return 0;
|
||||
|
||||
if(!capture->image){
|
||||
icvAllocateImageCAM_TYZX(capture);
|
||||
if(!capture->image) return 0;
|
||||
}
|
||||
|
||||
// copy camera image into buffer.
|
||||
// tempting to reference TYZX memory directly to avoid copying.
|
||||
switch (capture->index)
|
||||
{
|
||||
case CV_TYZX_RIGHT:
|
||||
memcpy(capture->image->imageData, g_tyzx_camera->getRImage(), capture->image->imageSize);
|
||||
break;
|
||||
case CV_TYZX_Z:
|
||||
memcpy(capture->image->imageData, g_tyzx_camera->getZImage(), capture->image->imageSize);
|
||||
break;
|
||||
case CV_TYZX_LEFT:
|
||||
default:
|
||||
memcpy(capture->image->imageData, g_tyzx_camera->getLImage(), capture->image->imageSize);
|
||||
break;
|
||||
}
|
||||
|
||||
return capture->image;
|
||||
}
|
||||
|
||||
static double icvGetPropertyCAM_TYZX (CvCaptureCAM_TYZX * capture, int property_id)
|
||||
{
|
||||
CvSize size;
|
||||
switch(capture->index)
|
||||
{
|
||||
case CV_TYZX_LEFT:
|
||||
size = cvSize(g_tyzx_camera->intensityWidth(), g_tyzx_camera->intensityHeight());
|
||||
break;
|
||||
case CV_TYZX_RIGHT:
|
||||
size = cvSize(g_tyzx_camera->intensityWidth(), g_tyzx_camera->intensityHeight());
|
||||
break;
|
||||
case CV_TYZX_Z:
|
||||
size = cvSize(g_tyzx_camera->zWidth(), g_tyzx_camera->zHeight());
|
||||
break;
|
||||
default:
|
||||
size = cvSize(0,0);
|
||||
}
|
||||
|
||||
switch( property_id )
|
||||
{
|
||||
case CV_CAP_PROP_FRAME_WIDTH:
|
||||
return size.width;
|
||||
case CV_CAP_PROP_FRAME_HEIGHT:
|
||||
return size.height;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int icvSetPropertyCAM_TYZX (CvCaptureCAM_TYZX *, int, double )
|
||||
{
|
||||
int retval = -1;
|
||||
return retval;
|
||||
}
|
||||
|
||||
CvCapture * cvCaptureFromCAM_TYZX (int index)
|
||||
{
|
||||
CvCaptureCAM_TYZX * capture = (CvCaptureCAM_TYZX*) cvAlloc( sizeof(*capture));
|
||||
memset( capture, 0, sizeof(*capture));
|
||||
capture->vtable = &captureCAM_TYZX_vtable;
|
||||
|
||||
if (icvOpenCAM_TYZX( capture, index ))
|
||||
return (CvCapture*)capture;
|
||||
|
||||
cvReleaseCapture( (CvCapture**)&capture );
|
||||
return 0;
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,683 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// Intel License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000, Intel Corporation, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of Intel Corporation may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "_highgui.h"
|
||||
|
||||
#include <vfw.h>
|
||||
#if _MSC_VER >= 1200
|
||||
#pragma warning( disable: 4711 )
|
||||
#endif
|
||||
|
||||
#if defined WIN64 && defined EM64T && defined _MSC_VER && !defined __ICL
|
||||
#pragma optimize("",off)
|
||||
#endif
|
||||
|
||||
|
||||
CvCapture* cvCaptureFromFile_VFW (const char* filename);
|
||||
CvCapture* cvCaptureFromCAM_VFW (int index);
|
||||
|
||||
/********************* Capturing video from AVI via VFW ************************/
|
||||
|
||||
static BITMAPINFOHEADER icvBitmapHeader( int width, int height, int bpp, int compression = BI_RGB )
|
||||
{
|
||||
BITMAPINFOHEADER bmih;
|
||||
memset( &bmih, 0, sizeof(bmih));
|
||||
bmih.biSize = sizeof(bmih);
|
||||
bmih.biWidth = width;
|
||||
bmih.biHeight = height;
|
||||
bmih.biBitCount = (WORD)bpp;
|
||||
bmih.biCompression = compression;
|
||||
bmih.biPlanes = 1;
|
||||
|
||||
return bmih;
|
||||
}
|
||||
|
||||
static void icvInitCapture_VFW()
|
||||
{
|
||||
static int isInitialized = 0;
|
||||
if( !isInitialized )
|
||||
{
|
||||
AVIFileInit();
|
||||
isInitialized = 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
typedef struct CvCaptureAVI_VFW
|
||||
{
|
||||
CvCaptureVTable * vtable;
|
||||
PAVIFILE avifile;
|
||||
PAVISTREAM avistream;
|
||||
PGETFRAME getframe;
|
||||
AVISTREAMINFO aviinfo;
|
||||
BITMAPINFOHEADER * bmih;
|
||||
CvSlice film_range;
|
||||
double fps;
|
||||
int pos;
|
||||
IplImage frame;
|
||||
CvSize size;
|
||||
}
|
||||
CvCaptureAVI_VFW;
|
||||
|
||||
|
||||
static void icvCloseAVI_VFW( CvCaptureAVI_VFW* capture )
|
||||
{
|
||||
if( capture->getframe )
|
||||
{
|
||||
AVIStreamGetFrameClose( capture->getframe );
|
||||
capture->getframe = 0;
|
||||
}
|
||||
if( capture->avistream )
|
||||
{
|
||||
AVIStreamRelease( capture->avistream );
|
||||
capture->avistream = 0;
|
||||
}
|
||||
if( capture->avifile )
|
||||
{
|
||||
AVIFileRelease( capture->avifile );
|
||||
capture->avifile = 0;
|
||||
}
|
||||
capture->bmih = 0;
|
||||
capture->pos = 0;
|
||||
capture->film_range.start_index = capture->film_range.end_index = 0;
|
||||
memset( &capture->frame, 0, sizeof(capture->frame));
|
||||
}
|
||||
|
||||
static int icvOpenAVI_VFW( CvCaptureAVI_VFW* capture, const char* filename )
|
||||
{
|
||||
HRESULT hr;
|
||||
|
||||
icvInitCapture_VFW();
|
||||
|
||||
if( !capture )
|
||||
return 0;
|
||||
|
||||
hr = AVIFileOpen( &capture->avifile, filename, OF_READ, NULL );
|
||||
if( SUCCEEDED(hr))
|
||||
{
|
||||
hr = AVIFileGetStream( capture->avifile, &capture->avistream, streamtypeVIDEO, 0 );
|
||||
if( SUCCEEDED(hr))
|
||||
{
|
||||
hr = AVIStreamInfo( capture->avistream, &capture->aviinfo,
|
||||
sizeof(capture->aviinfo));
|
||||
if( SUCCEEDED(hr))
|
||||
{
|
||||
capture->size.width = capture->aviinfo.rcFrame.right -
|
||||
capture->aviinfo.rcFrame.left;
|
||||
capture->size.height = capture->aviinfo.rcFrame.bottom -
|
||||
capture->aviinfo.rcFrame.top;
|
||||
BITMAPINFOHEADER bmih = icvBitmapHeader(
|
||||
capture->size.width, capture->size.height, 24 );
|
||||
|
||||
capture->film_range.start_index = (int)capture->aviinfo.dwStart;
|
||||
capture->film_range.end_index = capture->film_range.start_index +
|
||||
(int)capture->aviinfo.dwLength;
|
||||
capture->fps = ((double)capture->aviinfo.dwRate)/capture->aviinfo.dwScale;
|
||||
capture->pos = capture->film_range.start_index;
|
||||
capture->getframe = AVIStreamGetFrameOpen( capture->avistream, &bmih );
|
||||
if( capture->getframe != 0 )
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
icvCloseAVI_VFW( capture );
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int icvGrabFrameAVI_VFW( CvCaptureAVI_VFW* capture )
|
||||
{
|
||||
if( capture->avistream )
|
||||
{
|
||||
capture->bmih = (BITMAPINFOHEADER*)
|
||||
AVIStreamGetFrame( capture->getframe, capture->pos++ );
|
||||
}
|
||||
|
||||
return capture->bmih != 0;
|
||||
}
|
||||
|
||||
static const IplImage* icvRetrieveFrameAVI_VFW( CvCaptureAVI_VFW* capture )
|
||||
{
|
||||
if( capture->avistream && capture->bmih )
|
||||
{
|
||||
cvInitImageHeader( &capture->frame,
|
||||
cvSize( capture->bmih->biWidth,
|
||||
capture->bmih->biHeight ),
|
||||
IPL_DEPTH_8U, 3, IPL_ORIGIN_BL, 4 );
|
||||
capture->frame.imageData = capture->frame.imageDataOrigin =
|
||||
(char*)(capture->bmih + 1);
|
||||
return &capture->frame;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static double icvGetPropertyAVI_VFW( CvCaptureAVI_VFW* capture, int property_id )
|
||||
{
|
||||
switch( property_id )
|
||||
{
|
||||
case CV_CAP_PROP_POS_MSEC:
|
||||
return cvRound(capture->pos*1000./capture->fps);
|
||||
case CV_CAP_PROP_POS_FRAMES:
|
||||
return capture->pos;
|
||||
case CV_CAP_PROP_POS_AVI_RATIO:
|
||||
return (capture->pos - capture->film_range.start_index)/
|
||||
(capture->film_range.end_index - capture->film_range.start_index + 1e-10);
|
||||
case CV_CAP_PROP_FRAME_WIDTH:
|
||||
return capture->size.width;
|
||||
case CV_CAP_PROP_FRAME_HEIGHT:
|
||||
return capture->size.height;
|
||||
case CV_CAP_PROP_FPS:
|
||||
return capture->fps;
|
||||
case CV_CAP_PROP_FOURCC:
|
||||
return capture->aviinfo.fccHandler;
|
||||
case CV_CAP_PROP_FRAME_COUNT:
|
||||
return capture->film_range.end_index - capture->film_range.start_index;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static int icvSetPropertyAVI_VFW( CvCaptureAVI_VFW* capture,
|
||||
int property_id, double value )
|
||||
{
|
||||
switch( property_id )
|
||||
{
|
||||
case CV_CAP_PROP_POS_MSEC:
|
||||
case CV_CAP_PROP_POS_FRAMES:
|
||||
case CV_CAP_PROP_POS_AVI_RATIO:
|
||||
{
|
||||
int pos;
|
||||
switch( property_id )
|
||||
{
|
||||
case CV_CAP_PROP_POS_MSEC:
|
||||
pos = cvRound(value*capture->fps*0.001);
|
||||
break;
|
||||
case CV_CAP_PROP_POS_AVI_RATIO:
|
||||
pos = cvRound(value*(capture->film_range.end_index -
|
||||
capture->film_range.start_index) +
|
||||
capture->film_range.start_index);
|
||||
break;
|
||||
default:
|
||||
pos = cvRound(value);
|
||||
}
|
||||
if( pos < capture->film_range.start_index )
|
||||
pos = capture->film_range.start_index;
|
||||
if( pos > capture->film_range.end_index )
|
||||
pos = capture->film_range.end_index;
|
||||
capture->pos = pos;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static CvCaptureVTable captureAVI_VFW_vtable =
|
||||
{
|
||||
6,
|
||||
(CvCaptureCloseFunc) icvCloseAVI_VFW,
|
||||
(CvCaptureGrabFrameFunc) icvGrabFrameAVI_VFW,
|
||||
(CvCaptureRetrieveFrameFunc) icvRetrieveFrameAVI_VFW,
|
||||
(CvCaptureGetPropertyFunc) icvGetPropertyAVI_VFW,
|
||||
(CvCaptureSetPropertyFunc) icvSetPropertyAVI_VFW,
|
||||
(CvCaptureGetDescriptionFunc) 0
|
||||
};
|
||||
|
||||
|
||||
CvCapture* cvCaptureFromFile_VFW (const char* filename)
|
||||
{
|
||||
CvCaptureAVI_VFW* capture = 0;
|
||||
|
||||
if( filename )
|
||||
{
|
||||
capture = (CvCaptureAVI_VFW*)cvAlloc( sizeof(*capture));
|
||||
memset( capture, 0, sizeof(*capture));
|
||||
|
||||
capture->vtable = &captureAVI_VFW_vtable;
|
||||
|
||||
if( !icvOpenAVI_VFW( capture, filename ))
|
||||
cvReleaseCapture( (CvCapture**)&capture );
|
||||
}
|
||||
|
||||
return (CvCapture*)capture;
|
||||
}
|
||||
|
||||
/********************* Capturing video from camera via VFW *********************/
|
||||
|
||||
typedef struct CvCaptureCAM_VFW
|
||||
{
|
||||
CvCaptureVTable* vtable;
|
||||
CAPDRIVERCAPS caps;
|
||||
HWND capWnd;
|
||||
VIDEOHDR* hdr;
|
||||
DWORD fourcc;
|
||||
HIC hic;
|
||||
IplImage* rgb_frame;
|
||||
IplImage frame;
|
||||
}
|
||||
CvCaptureCAM_VFW;
|
||||
|
||||
|
||||
static LRESULT PASCAL FrameCallbackProc( HWND hWnd, VIDEOHDR* hdr )
|
||||
{
|
||||
CvCaptureCAM_VFW* capture = 0;
|
||||
|
||||
if (!hWnd) return FALSE;
|
||||
|
||||
capture = (CvCaptureCAM_VFW*)capGetUserData(hWnd);
|
||||
capture->hdr = hdr;
|
||||
|
||||
return (LRESULT)TRUE;
|
||||
}
|
||||
|
||||
|
||||
// Initialize camera input
|
||||
static int icvOpenCAM_VFW( CvCaptureCAM_VFW* capture, int wIndex )
|
||||
{
|
||||
char szDeviceName[80];
|
||||
char szDeviceVersion[80];
|
||||
HWND hWndC = 0;
|
||||
|
||||
if( (unsigned)wIndex >= 10 )
|
||||
wIndex = 0;
|
||||
|
||||
for( ; wIndex < 10; wIndex++ )
|
||||
{
|
||||
if( capGetDriverDescription( wIndex, szDeviceName,
|
||||
sizeof (szDeviceName), szDeviceVersion,
|
||||
sizeof (szDeviceVersion)))
|
||||
{
|
||||
hWndC = capCreateCaptureWindow ( "My Own Capture Window",
|
||||
WS_POPUP | WS_CHILD, 0, 0, 320, 240, 0, 0);
|
||||
if( capDriverConnect (hWndC, wIndex))
|
||||
break;
|
||||
DestroyWindow( hWndC );
|
||||
hWndC = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if( hWndC )
|
||||
{
|
||||
capture->capWnd = hWndC;
|
||||
capture->hdr = 0;
|
||||
capture->hic = 0;
|
||||
capture->fourcc = (DWORD)-1;
|
||||
capture->rgb_frame = 0;
|
||||
|
||||
memset( &capture->caps, 0, sizeof(capture->caps));
|
||||
capDriverGetCaps( hWndC, &capture->caps, sizeof(&capture->caps));
|
||||
::MoveWindow( hWndC, 0, 0, 320, 240, TRUE );
|
||||
capSetUserData( hWndC, (size_t)capture );
|
||||
capSetCallbackOnFrame( hWndC, FrameCallbackProc );
|
||||
CAPTUREPARMS p;
|
||||
capCaptureGetSetup(hWndC,&p,sizeof(CAPTUREPARMS));
|
||||
p.dwRequestMicroSecPerFrame = 66667/2;
|
||||
capCaptureSetSetup(hWndC,&p,sizeof(CAPTUREPARMS));
|
||||
//capPreview( hWndC, 1 );
|
||||
capPreviewScale(hWndC,FALSE);
|
||||
capPreviewRate(hWndC,1);
|
||||
}
|
||||
return capture->capWnd != 0;
|
||||
}
|
||||
|
||||
static void icvCloseCAM_VFW( CvCaptureCAM_VFW* capture )
|
||||
{
|
||||
if( capture && capture->capWnd )
|
||||
{
|
||||
capSetCallbackOnFrame( capture->capWnd, NULL );
|
||||
capDriverDisconnect( capture->capWnd );
|
||||
DestroyWindow( capture->capWnd );
|
||||
cvReleaseImage( &capture->rgb_frame );
|
||||
if( capture->hic )
|
||||
{
|
||||
ICDecompressEnd( capture->hic );
|
||||
ICClose( capture->hic );
|
||||
}
|
||||
|
||||
capture->capWnd = 0;
|
||||
capture->hic = 0;
|
||||
capture->hdr = 0;
|
||||
capture->fourcc = 0;
|
||||
capture->rgb_frame = 0;
|
||||
memset( &capture->frame, 0, sizeof(capture->frame));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static int icvGrabFrameCAM_VFW( CvCaptureCAM_VFW* capture )
|
||||
{
|
||||
if( capture->capWnd )
|
||||
{
|
||||
SendMessage( capture->capWnd, WM_CAP_GRAB_FRAME_NOSTOP, 0, 0 );
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static IplImage* icvRetrieveFrameCAM_VFW( CvCaptureCAM_VFW* capture )
|
||||
{
|
||||
if( capture->capWnd )
|
||||
{
|
||||
BITMAPINFO vfmt;
|
||||
memset( &vfmt, 0, sizeof(vfmt));
|
||||
int sz = capGetVideoFormat( capture->capWnd, &vfmt, sizeof(vfmt));
|
||||
|
||||
if( capture->hdr && capture->hdr->lpData && sz != 0 )
|
||||
{
|
||||
long code = ICERR_OK;
|
||||
char* frame_data = (char*)capture->hdr->lpData;
|
||||
|
||||
if( vfmt.bmiHeader.biCompression != BI_RGB ||
|
||||
vfmt.bmiHeader.biBitCount != 24 )
|
||||
{
|
||||
BITMAPINFOHEADER& vfmt0 = vfmt.bmiHeader;
|
||||
BITMAPINFOHEADER vfmt1 = icvBitmapHeader( vfmt0.biWidth, vfmt0.biHeight, 24 );
|
||||
code = ICERR_ERROR;
|
||||
|
||||
if( capture->hic == 0 ||
|
||||
capture->fourcc != vfmt0.biCompression ||
|
||||
capture->rgb_frame == 0 ||
|
||||
vfmt0.biWidth != capture->rgb_frame->width ||
|
||||
vfmt0.biHeight != capture->rgb_frame->height )
|
||||
{
|
||||
if( capture->hic )
|
||||
{
|
||||
ICDecompressEnd( capture->hic );
|
||||
ICClose( capture->hic );
|
||||
}
|
||||
capture->hic = ICOpen( MAKEFOURCC('V','I','D','C'),
|
||||
vfmt0.biCompression, ICMODE_DECOMPRESS );
|
||||
if( capture->hic &&
|
||||
ICDecompressBegin( capture->hic, &vfmt0, &vfmt1 ) == ICERR_OK )
|
||||
{
|
||||
cvReleaseImage( &capture->rgb_frame );
|
||||
capture->rgb_frame = cvCreateImage(
|
||||
cvSize( vfmt0.biWidth, vfmt0.biHeight ), IPL_DEPTH_8U, 3 );
|
||||
capture->rgb_frame->origin = IPL_ORIGIN_BL;
|
||||
|
||||
code = ICDecompress( capture->hic, 0,
|
||||
&vfmt0, capture->hdr->lpData,
|
||||
&vfmt1, capture->rgb_frame->imageData );
|
||||
frame_data = capture->rgb_frame->imageData;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if( code == ICERR_OK )
|
||||
{
|
||||
cvInitImageHeader( &capture->frame,
|
||||
cvSize(vfmt.bmiHeader.biWidth,
|
||||
vfmt.bmiHeader.biHeight),
|
||||
IPL_DEPTH_8U, 3, IPL_ORIGIN_BL, 4 );
|
||||
capture->frame.imageData = capture->frame.imageDataOrigin = frame_data;
|
||||
return &capture->frame;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static double icvGetPropertyCAM_VFW( CvCaptureCAM_VFW* capture, int property_id )
|
||||
{
|
||||
switch( property_id )
|
||||
{
|
||||
case CV_CAP_PROP_FRAME_WIDTH:
|
||||
return capture->frame.width;
|
||||
case CV_CAP_PROP_FRAME_HEIGHT:
|
||||
return capture->frame.height;
|
||||
case CV_CAP_PROP_FOURCC:
|
||||
return capture->fourcc;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
static CvCaptureVTable captureCAM_VFW_vtable =
|
||||
{
|
||||
6,
|
||||
(CvCaptureCloseFunc)icvCloseCAM_VFW,
|
||||
(CvCaptureGrabFrameFunc)icvGrabFrameCAM_VFW,
|
||||
(CvCaptureRetrieveFrameFunc)icvRetrieveFrameCAM_VFW,
|
||||
(CvCaptureGetPropertyFunc)icvGetPropertyCAM_VFW,
|
||||
(CvCaptureSetPropertyFunc)0,
|
||||
(CvCaptureGetDescriptionFunc)0
|
||||
};
|
||||
|
||||
|
||||
CvCapture* cvCaptureFromCAM_VFW( int index )
|
||||
{
|
||||
CvCaptureCAM_VFW * capture = (CvCaptureCAM_VFW*)cvAlloc( sizeof(*capture));
|
||||
memset( capture, 0, sizeof(*capture));
|
||||
capture->vtable = &captureCAM_VFW_vtable;
|
||||
|
||||
if( icvOpenCAM_VFW( capture, index ))
|
||||
return (CvCapture*)capture;
|
||||
|
||||
cvReleaseCapture( (CvCapture**)&capture );
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/*************************** writing AVIs ******************************/
|
||||
|
||||
typedef struct CvAVI_VFW_Writer
|
||||
{
|
||||
PAVIFILE avifile;
|
||||
PAVISTREAM compressed;
|
||||
PAVISTREAM uncompressed;
|
||||
double fps;
|
||||
CvSize frameSize;
|
||||
IplImage * tempFrame;
|
||||
long pos;
|
||||
int fourcc;
|
||||
} CvAVI_VFW_Writer;
|
||||
|
||||
|
||||
static void icvCloseAVIWriter( CvAVI_VFW_Writer* writer )
|
||||
{
|
||||
if( writer )
|
||||
{
|
||||
if( writer->uncompressed )
|
||||
AVIStreamRelease( writer->uncompressed );
|
||||
if( writer->compressed )
|
||||
AVIStreamRelease( writer->compressed );
|
||||
if( writer->avifile )
|
||||
AVIFileRelease( writer->avifile );
|
||||
cvReleaseImage( &writer->tempFrame );
|
||||
memset( writer, 0, sizeof(*writer));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// philipg. Made this code capable of writing 8bpp gray scale bitmaps
|
||||
typedef struct tagBITMAPINFO_8Bit
|
||||
{
|
||||
BITMAPINFOHEADER bmiHeader;
|
||||
RGBQUAD bmiColors[256];
|
||||
} BITMAPINFOHEADER_8BIT;
|
||||
|
||||
static int icvInitAVIWriter( CvAVI_VFW_Writer* writer, int fourcc,
|
||||
double fps, CvSize frameSize, int is_color )
|
||||
{
|
||||
if( writer && writer->avifile )
|
||||
{
|
||||
AVICOMPRESSOPTIONS copts, *pcopts = &copts;
|
||||
AVISTREAMINFO aviinfo;
|
||||
|
||||
assert( frameSize.width > 0 && frameSize.height > 0 );
|
||||
|
||||
BITMAPINFOHEADER_8BIT bmih;
|
||||
int i;
|
||||
|
||||
bmih.bmiHeader = icvBitmapHeader( frameSize.width, frameSize.height, is_color ? 24 : 8 );
|
||||
for( i = 0; i < 256; i++ )
|
||||
{
|
||||
bmih.bmiColors[i].rgbBlue = (BYTE)i;
|
||||
bmih.bmiColors[i].rgbGreen = (BYTE)i;
|
||||
bmih.bmiColors[i].rgbRed = (BYTE)i;
|
||||
bmih.bmiColors[i].rgbReserved = 0;
|
||||
}
|
||||
|
||||
memset( &aviinfo, 0, sizeof(aviinfo));
|
||||
aviinfo.fccType = streamtypeVIDEO;
|
||||
aviinfo.fccHandler = 0;
|
||||
// use highest possible accuracy for dwRate/dwScale
|
||||
aviinfo.dwScale = (DWORD)((double)0x7FFFFFFF / fps);
|
||||
aviinfo.dwRate = cvRound(fps * aviinfo.dwScale);
|
||||
aviinfo.rcFrame.top = aviinfo.rcFrame.left = 0;
|
||||
aviinfo.rcFrame.right = frameSize.width;
|
||||
aviinfo.rcFrame.bottom = frameSize.height;
|
||||
|
||||
if( AVIFileCreateStream( writer->avifile,
|
||||
&writer->uncompressed, &aviinfo ) == AVIERR_OK )
|
||||
{
|
||||
copts.fccType = streamtypeVIDEO;
|
||||
copts.fccHandler = fourcc != -1 ? fourcc : 0;
|
||||
copts.dwKeyFrameEvery = 1;
|
||||
copts.dwQuality = (DWORD)-1;
|
||||
copts.dwBytesPerSecond = 0;
|
||||
copts.dwFlags = AVICOMPRESSF_VALID;
|
||||
copts.lpFormat = &bmih;
|
||||
copts.cbFormat = (is_color ? sizeof(BITMAPINFOHEADER) : sizeof(bmih));
|
||||
copts.lpParms = 0;
|
||||
copts.cbParms = 0;
|
||||
copts.dwInterleaveEvery = 0;
|
||||
|
||||
if( fourcc != -1 ||
|
||||
AVISaveOptions( 0, 0, 1, &writer->uncompressed, &pcopts ) == TRUE )
|
||||
{
|
||||
if( AVIMakeCompressedStream( &writer->compressed,
|
||||
writer->uncompressed, pcopts, 0 ) == AVIERR_OK &&
|
||||
// check that the resolution was not changed
|
||||
bmih.bmiHeader.biWidth == frameSize.width &&
|
||||
bmih.bmiHeader.biHeight == frameSize.height &&
|
||||
AVIStreamSetFormat( writer->compressed, 0, &bmih, sizeof(bmih)) == AVIERR_OK )
|
||||
{
|
||||
writer->fps = fps;
|
||||
writer->fourcc = (int)copts.fccHandler;
|
||||
writer->frameSize = frameSize;
|
||||
writer->tempFrame = cvCreateImage( frameSize, 8, (is_color ? 3 : 1) );
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
icvCloseAVIWriter( writer );
|
||||
return 0;
|
||||
}
|
||||
|
||||
CV_IMPL CvVideoWriter* cvCreateVideoWriter( const char* filename, int fourcc,
|
||||
double fps, CvSize frameSize, int is_color )
|
||||
{
|
||||
CvAVI_VFW_Writer* writer = (CvAVI_VFW_Writer*)cvAlloc( sizeof(CvAVI_VFW_Writer));
|
||||
memset( writer, 0, sizeof(*writer));
|
||||
|
||||
icvInitCapture_VFW();
|
||||
|
||||
if( AVIFileOpen( &writer->avifile, filename, OF_CREATE | OF_WRITE, 0 ) == AVIERR_OK )
|
||||
{
|
||||
if( frameSize.width > 0 && frameSize.height > 0 )
|
||||
{
|
||||
if( !icvInitAVIWriter( writer, fourcc, fps, frameSize, is_color ))
|
||||
cvReleaseVideoWriter( (CvVideoWriter**)&writer );
|
||||
}
|
||||
else if( fourcc == -1 )
|
||||
{
|
||||
icvCloseAVIWriter( writer );
|
||||
}
|
||||
else
|
||||
{
|
||||
/* postpone initialization until the first frame is written */
|
||||
writer->fourcc = fourcc;
|
||||
writer->fps = fps;
|
||||
writer->frameSize = frameSize;
|
||||
}
|
||||
}
|
||||
|
||||
return (CvVideoWriter*)writer;
|
||||
}
|
||||
|
||||
CV_IMPL int cvWriteFrame( CvVideoWriter* _writer, const IplImage* image )
|
||||
{
|
||||
CvAVI_VFW_Writer* writer = (CvAVI_VFW_Writer*)_writer;
|
||||
|
||||
if( writer && (writer->compressed ||
|
||||
icvInitAVIWriter( writer, writer->fourcc, writer->fps,
|
||||
writer->frameSize, image->nChannels > 1 )))
|
||||
{
|
||||
if (image->nChannels != writer->tempFrame->nChannels)
|
||||
{
|
||||
cvConvertImage( image, writer->tempFrame,
|
||||
image->origin == 0 ? CV_CVTIMG_FLIP : 0 );
|
||||
image = (const IplImage*)writer->tempFrame;
|
||||
}
|
||||
// If only flipping is needed, do not call cvConvertImage because when source and destination are single channel, cvConvertImage fails.
|
||||
else if (image->origin == 0)
|
||||
{
|
||||
cvFlip( image, writer->tempFrame, 0 );
|
||||
image = (const IplImage*)writer->tempFrame;
|
||||
}
|
||||
if( AVIStreamWrite( writer->compressed, writer->pos++, 1, image->imageData,
|
||||
image->imageSize, AVIIF_KEYFRAME, 0, 0 ) == AVIERR_OK )
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
CV_IMPL void cvReleaseVideoWriter( CvVideoWriter** writer )
|
||||
{
|
||||
if( writer && *writer )
|
||||
{
|
||||
icvCloseAVIWriter( (CvAVI_VFW_Writer*)*writer );
|
||||
cvFree( writer );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,794 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// Intel License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000, Intel Corporation, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of Intel Corporation may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
// Authors: Konstantin Dols <dols@ient.rwth-aachen.de>
|
||||
// Mark Asbach <asbach@ient.rwth-aachen.de>
|
||||
//
|
||||
// Institute of Communications Engineering
|
||||
// RWTH Aachen University
|
||||
|
||||
|
||||
#include "_highgui.h"
|
||||
|
||||
// required to enable some functions used here...
|
||||
#define XINE_ENABLE_EXPERIMENTAL_FEATURES
|
||||
|
||||
#include <cv.h>
|
||||
#include <cassert>
|
||||
|
||||
extern "C"
|
||||
{
|
||||
#include <xine.h>
|
||||
//#include <xine/xineutils.h>
|
||||
|
||||
// forward declaration from <xine/xineutils.h>
|
||||
const char *xine_get_homedir( void );
|
||||
}
|
||||
|
||||
typedef struct CvCaptureAVI_XINE
|
||||
{
|
||||
/// method call table
|
||||
CvCaptureVTable * vtable;
|
||||
|
||||
xine_t * xine;
|
||||
xine_stream_t * stream;
|
||||
xine_video_port_t * vo_port;
|
||||
|
||||
/// frame returned by xine_get_next_video_frame()
|
||||
xine_video_frame_t xine_frame;
|
||||
|
||||
IplImage * yuv_frame;
|
||||
IplImage * bgr_frame;
|
||||
|
||||
/// image dimansions of the input stream.
|
||||
CvSize size;
|
||||
|
||||
/// framenumber of the last frame received from xine_get_next_video_frame().
|
||||
/// note: always keep this value updated !!!!
|
||||
int frame_number;
|
||||
|
||||
/// framerate of the opened stream
|
||||
double frame_rate;
|
||||
|
||||
/// duration of a frame in stream
|
||||
double frame_duration;
|
||||
|
||||
/// indicated if input is seekable
|
||||
bool seekable;
|
||||
|
||||
}
|
||||
CvCaptureAVI_XINE;
|
||||
|
||||
|
||||
// 4:2:2 interleaved -> BGR
|
||||
static void icvYUY2toBGR( CvCaptureAVI_XINE * capture )
|
||||
{
|
||||
uint8_t * v = capture->xine_frame.data;
|
||||
int offset;
|
||||
for ( int y = 0; y < capture->yuv_frame->height; y++ )
|
||||
{
|
||||
offset = y * capture->yuv_frame->widthStep;
|
||||
|
||||
for ( int x = 0; x < capture->yuv_frame->width; x++, offset += 3 )
|
||||
{
|
||||
capture->yuv_frame->imageData[ offset + 1 ] = v[ 3 ];
|
||||
capture->yuv_frame->imageData[ offset + 2 ] = v[ 1 ];
|
||||
if ( x & 1 )
|
||||
{
|
||||
capture->yuv_frame->imageData[ offset ] = v[ 2 ];
|
||||
v += 4;
|
||||
}
|
||||
else
|
||||
{
|
||||
capture->yuv_frame->imageData[ offset ] = v[ 0 ];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// convert to BGR
|
||||
cvCvtColor( capture->yuv_frame, capture->bgr_frame, CV_YCrCb2BGR );
|
||||
}
|
||||
|
||||
|
||||
// 4:2:0 planary -> BGR
|
||||
static void icvYV12toBGR( CvCaptureAVI_XINE * capture )
|
||||
{
|
||||
IplImage * yuv = capture->yuv_frame;
|
||||
int w_Y = capture->size.width;
|
||||
int h_Y = capture->size.height;
|
||||
|
||||
int w_UV = w_Y >> 1;
|
||||
|
||||
int size_Y = w_Y * h_Y;
|
||||
int size_UV = size_Y / 4;
|
||||
|
||||
int line = yuv->widthStep;
|
||||
|
||||
uint8_t * addr_Y = capture->xine_frame.data;
|
||||
uint8_t * addr_U = addr_Y + size_Y;
|
||||
uint8_t * addr_V = addr_U + size_UV;
|
||||
|
||||
// YYYY..UU.VV. -> BGRBGRBGR...
|
||||
for ( int y = 0; y < h_Y; y++ )
|
||||
{
|
||||
int offset = y * line;
|
||||
for ( int x = 0; x < w_Y; x++, offset += 3 )
|
||||
{
|
||||
/*
|
||||
if ( x&1 )
|
||||
{
|
||||
addr_U++; addr_V++;
|
||||
}
|
||||
*/
|
||||
int one_zero = x & 1;
|
||||
addr_U += one_zero;
|
||||
addr_V += one_zero;
|
||||
|
||||
yuv->imageData[ offset ] = *( addr_Y++ );
|
||||
yuv->imageData[ offset + 1 ] = *addr_U;
|
||||
yuv->imageData[ offset + 2 ] = *addr_V;
|
||||
}
|
||||
|
||||
if ( y & 1 )
|
||||
{
|
||||
addr_U -= w_UV;
|
||||
addr_V -= w_UV;
|
||||
}
|
||||
}
|
||||
|
||||
/* convert to BGR */
|
||||
cvCvtColor( capture->yuv_frame, capture->bgr_frame, CV_YCrCb2BGR );
|
||||
}
|
||||
|
||||
static void icvCloseAVI_XINE( CvCaptureAVI_XINE* capture )
|
||||
{
|
||||
xine_free_video_frame( capture->vo_port, &capture->xine_frame );
|
||||
|
||||
if ( capture->yuv_frame ) cvReleaseImage( &capture->yuv_frame );
|
||||
if ( capture->bgr_frame ) cvReleaseImage( &capture->bgr_frame );
|
||||
|
||||
xine_close( capture->stream );
|
||||
// xine_dispose( capture->stream );
|
||||
|
||||
if ( capture->vo_port ) xine_close_video_driver( capture->xine, capture->vo_port );
|
||||
|
||||
xine_exit( capture->xine );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* CHECKS IF THE STREAM IN * capture IS SEEKABLE.
|
||||
**/
|
||||
static void icvCheckSeekAVI_XINE( CvCaptureAVI_XINE * capture )
|
||||
{
|
||||
OPENCV_ASSERT ( capture, "icvCheckSeekAVI_XINE( CvCaptureAVI_XINE* )", "illegal capture");
|
||||
OPENCV_ASSERT ( capture->stream,
|
||||
"icvCheckSeekAVI_XINE( CvCaptureAVI_XINE* )", "illegal capture->stream");
|
||||
OPENCV_ASSERT ( capture->vo_port,
|
||||
"icvCheckSeekAVI_XINE( CvCaptureAVI_XINE* )", "illegal capture->vo_port");
|
||||
|
||||
#ifndef NDEBUG
|
||||
fprintf( stderr, "(DEBUG) icvCheckSeekAVI_XINE ... start\n" );
|
||||
#endif
|
||||
|
||||
// temp. frame for testing.
|
||||
xine_video_frame_t tmp;
|
||||
// try to seek to a future frame...
|
||||
xine_play( capture->stream, 0, 300 ); /* 300msec */
|
||||
// try to receive the frame...
|
||||
xine_get_next_video_frame( capture->vo_port, &tmp );
|
||||
// if the framenumber is still 0, we can't use the xine seek functionality
|
||||
capture->seekable = ( tmp.frame_number != 0 );
|
||||
// reset stream
|
||||
xine_play( capture->stream, 0, 0 );
|
||||
// release xine_frame
|
||||
xine_free_video_frame( capture->vo_port, &tmp );
|
||||
|
||||
#ifndef NDEBUG
|
||||
if ( capture->seekable )
|
||||
fprintf( stderr, "(DEBUG) icvCheckSeekAVI_XINE: Input is seekable, using XINE seek implementation.\n" );
|
||||
else
|
||||
fprintf( stderr, "(DEBUG) icvCheckSeekAVI_XINE: Input is NOT seekable, using fallback function.\n" );
|
||||
|
||||
fprintf( stderr, "(DEBUG) icvCheckSeekAVI_XINE ... end\n" );
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
static int icvOpenAVI_XINE( CvCaptureAVI_XINE* capture, const char* filename )
|
||||
{
|
||||
#ifndef NDEBUG
|
||||
fprintf( stderr, "(DEBUG) icvOpenAVI_XINE ... start\n" );
|
||||
#endif
|
||||
|
||||
char configfile[ 2048 ];
|
||||
|
||||
capture->xine = xine_new();
|
||||
sprintf( configfile, "%s%s", xine_get_homedir(), "/.xine/config" );
|
||||
|
||||
xine_config_load( capture->xine, configfile );
|
||||
xine_init( capture->xine );
|
||||
|
||||
xine_engine_set_param( capture->xine, 0, 0 );
|
||||
capture->vo_port = xine_new_framegrab_video_port( capture->xine );
|
||||
if ( capture->vo_port == NULL )
|
||||
{
|
||||
printf( "(ERROR)icvOpenAVI_XINE(): Unable to initialize video driver.\n" );
|
||||
return 0;
|
||||
}
|
||||
|
||||
capture->stream = xine_stream_new( capture->xine, NULL, capture->vo_port );
|
||||
|
||||
if ( !xine_open( capture->stream, filename ) )
|
||||
{
|
||||
printf( "(ERROR)icvOpenAVI_XINE(): Unable to open source '%s'\n", filename );
|
||||
return 0;
|
||||
}
|
||||
// reset stream...
|
||||
xine_play( capture->stream, 0, 0 );
|
||||
|
||||
|
||||
// initialize some internals...
|
||||
capture->frame_number = 0;
|
||||
|
||||
if ( !xine_get_next_video_frame( capture->vo_port, &capture->xine_frame ) )
|
||||
{
|
||||
#ifndef NDEBUG
|
||||
fprintf( stderr, "(DEBUG) icvOpenAVI_XINE ... failed!\n" );
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
capture->size = cvSize( capture->xine_frame.width, capture->xine_frame.height );
|
||||
capture->yuv_frame = cvCreateImage( capture->size, IPL_DEPTH_8U, 3 );
|
||||
capture->bgr_frame = cvCreateImage( capture->size, IPL_DEPTH_8U, 3 );
|
||||
|
||||
xine_free_video_frame( capture->vo_port, &capture->xine_frame );
|
||||
capture->xine_frame.data[ 0 ] = 0;
|
||||
|
||||
icvCheckSeekAVI_XINE( capture );
|
||||
|
||||
capture->frame_duration = xine_get_stream_info( capture->stream, XINE_STREAM_INFO_FRAME_DURATION ) / 90.;
|
||||
capture->frame_rate = 1000 / capture->frame_duration;
|
||||
|
||||
#ifndef NDEBUG
|
||||
fprintf( stderr, "(DEBUG) frame_duration = %f, framerate = %f\n", capture->frame_duration, capture->frame_rate );
|
||||
#endif
|
||||
|
||||
OPENCV_ASSERT ( capture->yuv_frame,
|
||||
"icvOpenAVI_XINE( CvCaptureAVI_XINE *, const char *)", "couldn't create yuv frame");
|
||||
|
||||
OPENCV_ASSERT ( capture->bgr_frame,
|
||||
"icvOpenAVI_XINE( CvCaptureAVI_XINE *, const char *)", "couldn't create bgr frame");
|
||||
|
||||
#ifndef NDEBUG
|
||||
fprintf( stderr, "(DEBUG) icvOpenAVI_XINE ... end\n" );
|
||||
#endif
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
static int icvGrabFrameAVI_XINE( CvCaptureAVI_XINE* capture )
|
||||
{
|
||||
#ifndef NDEBUG
|
||||
fprintf( stderr, "(DEBUG) icvGrabFrameAVI_XINE ... start\n" );
|
||||
#endif
|
||||
|
||||
OPENCV_ASSERT ( capture,
|
||||
"icvGrabFrameAVI_XINE( CvCaptureAVI_XINE * )", "illegal capture");
|
||||
OPENCV_ASSERT ( capture->vo_port,
|
||||
"icvGrabFrameAVI_XINE( CvCaptureAVI_XINE * )", "illegal capture->vo_port");
|
||||
|
||||
int res = xine_get_next_video_frame( capture->vo_port, &capture->xine_frame );
|
||||
|
||||
/* always keep internal framenumber updated !!! */
|
||||
if ( res ) capture->frame_number++;
|
||||
|
||||
#ifndef NDEBUG
|
||||
fprintf( stderr, "(DEBUG) icvGrabFrameAVI_XINE ... end\n" );
|
||||
#endif
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
static const IplImage* icvRetrieveFrameAVI_XINE( CvCaptureAVI_XINE* capture )
|
||||
{
|
||||
#ifndef NDEBUG
|
||||
fprintf( stderr, "(DEBUG) icvRetrieveFrameAVI_XINE ... start\n" );
|
||||
#endif
|
||||
|
||||
OPENCV_ASSERT ( capture,
|
||||
"icvRetrieveFrameAVI_XINE( CvCaptureAVI_XINE * )", "illegal capture");
|
||||
OPENCV_ASSERT ( capture->stream,
|
||||
"icvRetrieveFrameAVI_XINE( CvCaptureAVI_XINE * )", "illegal capture->stream");
|
||||
OPENCV_ASSERT ( capture->vo_port,
|
||||
"icvRetrieveFrameAVI_XINE( CvCaptureAVI_XINE * )", "illegal capture->vo_port");
|
||||
|
||||
/* no frame grabbed yet? so let's do it now! */
|
||||
int res = 0;
|
||||
if ( capture->xine_frame.data == 0 )
|
||||
{
|
||||
res = icvGrabFrameAVI_XINE( capture );
|
||||
}
|
||||
else
|
||||
{
|
||||
res = 1;
|
||||
}
|
||||
|
||||
if ( res )
|
||||
{
|
||||
switch ( capture->xine_frame.colorspace )
|
||||
{
|
||||
case XINE_IMGFMT_YV12: icvYV12toBGR( capture );
|
||||
#ifndef NDEBUG
|
||||
printf( "(DEBUG)icvRetrieveFrameAVI_XINE: converted YV12 to BGR.\n" );
|
||||
#endif
|
||||
break;
|
||||
|
||||
case XINE_IMGFMT_YUY2: icvYUY2toBGR( capture );
|
||||
#ifndef NDEBUG
|
||||
printf( "(DEBUG)icvRetrieveFrameAVI_XINE: converted YUY2 to BGR.\n" );
|
||||
#endif
|
||||
break;
|
||||
case XINE_IMGFMT_XVMC: printf( "(ERROR)icvRetrieveFrameAVI_XINE: XVMC format not supported!\n" );
|
||||
break;
|
||||
|
||||
case XINE_IMGFMT_XXMC: printf( "(ERROR)icvRetrieveFrameAVI_XINE: XXMC format not supported!\n" );
|
||||
break;
|
||||
|
||||
default: printf( "(ERROR)icvRetrieveFrameAVI_XINE: unknown color/pixel format!\n" );
|
||||
}
|
||||
|
||||
/* always release last xine_frame, not needed anymore, but store its frame_number in *capture ! */
|
||||
xine_free_video_frame( capture->vo_port, &capture->xine_frame );
|
||||
capture->xine_frame.data = 0;
|
||||
|
||||
#ifndef NDEBUG
|
||||
fprintf( stderr, "(DEBUG) icvRetrieveFrameAVI_XINE ... end\n" );
|
||||
#endif
|
||||
return capture->bgr_frame;
|
||||
}
|
||||
|
||||
#ifndef NDEBUG
|
||||
fprintf( stderr, "(DEBUG) icvRetrieveFrameAVI_XINE ... failed!\n" );
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* THIS FUNCTION IS A FALLBACK FUNCTION FOR THE CASE THAT THE XINE SEEK IMPLEMENTATION
|
||||
* DOESN'T WORK WITH THE ACTUAL INPUT. THIS FUNCTION IS ONLY USED IN THE CASE OF AN EMERGENCY,
|
||||
* BECAUSE IT IS VERY SLOW !
|
||||
**/
|
||||
static int icvOldSeekFrameAVI_XINE( CvCaptureAVI_XINE* capture, int f )
|
||||
{
|
||||
#ifndef NDEBUG
|
||||
fprintf( stderr, "(DEBUG) icvOldSeekFrameAVI_XINE ... start\n" );
|
||||
#endif
|
||||
|
||||
OPENCV_ASSERT ( capture,
|
||||
"icvRetricvOldSeekFrameAVI_XINE( CvCaptureAVI_XINE *, int )", "illegal capture");
|
||||
OPENCV_ASSERT ( capture->stream,
|
||||
"icvOldSeekFrameAVI_XINE( CvCaptureAVI_XINE *, int )", "illegal capture->stream");
|
||||
OPENCV_ASSERT ( capture->vo_port,
|
||||
"icvOldSeekFrameAVI_XINE( CvCaptureAVI_XINE *, int )", "illegal capture->vo_port");
|
||||
|
||||
// not needed tnx to asserts...
|
||||
// we need a valid capture context and it's stream to seek through
|
||||
// if ( !capture || !capture->stream ) return 0;
|
||||
|
||||
// no need to seek if we are already there...
|
||||
if ( f == capture->frame_number )
|
||||
{
|
||||
#ifndef NDEBUG
|
||||
fprintf( stderr, "(DEBUG) icvOldSeekFrameAVI_XINE ... end\n" );
|
||||
#endif
|
||||
return 1;
|
||||
}
|
||||
// if the requested position is behind out actual position,
|
||||
// we just need to read the remaining amount of frames until we are there.
|
||||
else if ( f > capture->frame_number )
|
||||
{
|
||||
for ( ;capture->frame_number < f;capture->frame_number++ )
|
||||
/// un-increment framenumber grabbing failed
|
||||
if ( !xine_get_next_video_frame( capture->vo_port, &capture->xine_frame ) )
|
||||
{
|
||||
capture->frame_number--;
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
xine_free_video_frame( capture->vo_port, &capture->xine_frame );
|
||||
}
|
||||
}
|
||||
// otherwise we need to reset the stream and
|
||||
// start reading frames from the beginning.
|
||||
else // f < capture->frame_number
|
||||
{
|
||||
/// reset stream, should also work with non-seekable input
|
||||
xine_play( capture->stream, 0, 0 );
|
||||
/// read frames until we are at the requested frame
|
||||
for ( capture->frame_number = 0; capture->frame_number < f; capture->frame_number++ )
|
||||
/// un-increment last framenumber if grabbing failed
|
||||
if ( !xine_get_next_video_frame( capture->vo_port, &capture->xine_frame ) )
|
||||
{
|
||||
capture->frame_number--;
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
xine_free_video_frame( capture->vo_port, &capture->xine_frame );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#ifndef NDEBUG
|
||||
fprintf( stderr, "(DEBUG) icvOldSeekFrameAVI_XINE ... end\n" );
|
||||
#endif
|
||||
return ( f == capture->frame_number ) ? 1 : 0;
|
||||
}
|
||||
|
||||
|
||||
static int icvSeekFrameAVI_XINE( CvCaptureAVI_XINE* capture, int f )
|
||||
{
|
||||
#ifndef NDEBUG
|
||||
fprintf( stderr, "(DEBUG) icvSeekFrameAVI_XINE ... start\n" );
|
||||
#endif
|
||||
|
||||
OPENCV_ASSERT ( capture,
|
||||
"icvSeekFrameAVI_XINE( CvCaptureAVI_XINE *, int )", "illegal capture");
|
||||
OPENCV_ASSERT ( capture->stream,
|
||||
"icvSeekFrameAVI_XINE( CvCaptureAVI_XINE *, int )", "illegal capture->stream");
|
||||
OPENCV_ASSERT ( capture->vo_port,
|
||||
"icvSeekFrameAVI_XINE( CvCaptureAVI_XINE *, int )", "illegal capture->vo_port");
|
||||
|
||||
// not needed tnx to asserts...
|
||||
// we need a valid capture context and it's stream to seek through
|
||||
// if ( !capture || !capture->stream ) return 0;
|
||||
|
||||
if ( capture->seekable )
|
||||
{
|
||||
|
||||
/// use xinelib's seek functionality
|
||||
int new_time = ( int ) ( ( f + 1 ) * ( float ) capture->frame_duration );
|
||||
|
||||
#ifndef NDEBUG
|
||||
fprintf( stderr, "(DEBUG) calling xine_play()" );
|
||||
#endif
|
||||
if ( xine_play( capture->stream, 0, new_time ) )
|
||||
{
|
||||
#ifndef NDEBUG
|
||||
fprintf( stderr, "ok\n" );
|
||||
fprintf( stderr, "(DEBUG) icvSeekFrameAVI_XINE ... end\n" );
|
||||
#endif
|
||||
capture->frame_number = f;
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
#ifndef NDEBUG
|
||||
fprintf( stderr, "failed\n" );
|
||||
fprintf( stderr, "(DEBUG) icvSeekFrameAVI_XINE ... failed\n" );
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
#ifndef NDEBUG
|
||||
fprintf( stderr, "(DEBUG) icvSeekFrameAVI_XINE ... end\n" );
|
||||
#endif
|
||||
return icvOldSeekFrameAVI_XINE( capture, f );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static int icvSeekTimeAVI_XINE( CvCaptureAVI_XINE* capture, int t )
|
||||
{
|
||||
#ifndef NDEBUG
|
||||
fprintf( stderr, "(DEBUG) icvSeekTimeAVI_XINE ... start\n" );
|
||||
#endif
|
||||
|
||||
OPENCV_ASSERT ( capture,
|
||||
"icvSeekTimeAVI_XINE( CvCaptureAVI_XINE *, int )", "illegal capture");
|
||||
OPENCV_ASSERT ( capture->stream,
|
||||
"icvSeekTimeAVI_XINE( CvCaptureAVI_XINE *, int )", "illegal capture->stream");
|
||||
OPENCV_ASSERT ( capture->vo_port,
|
||||
"icvSeekTimeAVI_XINE( CvCaptureAVI_XINE *, int )", "illegal capture->vo_port");
|
||||
|
||||
#ifndef NDEBUG
|
||||
fprintf( stderr, "(DEBUG) icvSeekTimeAVI_XINE ... start\n" );
|
||||
#endif
|
||||
|
||||
// not needed tnx to asserts...
|
||||
// we need a valid capture context and it's stream to seek through
|
||||
// if ( !capture || !capture->stream ) return 0;
|
||||
|
||||
if ( capture->seekable )
|
||||
{
|
||||
/// use xinelib's seek functionality
|
||||
if ( xine_play( capture->stream, 0, t ) )
|
||||
{
|
||||
capture->frame_number = ( int ) ( ( float ) t * capture->frame_rate / 1000 );
|
||||
#ifndef NDEBUG
|
||||
fprintf( stderr, "(DEBUG) icvSeekFrameAVI_XINE ... end\n" );
|
||||
#endif
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
#ifndef NDEBUG
|
||||
fprintf( stderr, "(DEBUG) icvSeekFrameAVI_XINE ... failed!\n" );
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
int new_frame = ( int ) ( ( float ) t * capture->frame_rate / 1000 );
|
||||
#ifndef NDEBUG
|
||||
fprintf( stderr, "(DEBUG) icvSeekFrameAVI_XINE ....end\n" );
|
||||
#endif
|
||||
return icvOldSeekFrameAVI_XINE( capture, new_frame );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static int icvSeekRatioAVI_XINE( CvCaptureAVI_XINE* capture, double ratio )
|
||||
{
|
||||
#ifndef NDEBUG
|
||||
fprintf( stderr, "(DEBUG) icvSeekRatioAVI_XINE ... start\n" );
|
||||
#endif
|
||||
|
||||
OPENCV_ASSERT ( capture,
|
||||
"icvSeekRatioAVI_XINE( CvCaptureAVI_XINE *, double )", "illegal capture");
|
||||
OPENCV_ASSERT ( capture->stream,
|
||||
"icvSeekRatioAVI_XINE( CvCaptureAVI_XINE *, double )", "illegal capture->stream");
|
||||
OPENCV_ASSERT ( capture->vo_port,
|
||||
"icvSeekRatioAVI_XINE( CvCaptureAVI_XINE *, double )", "illegal capture->vo_port");
|
||||
|
||||
// not needed tnx to asserts...
|
||||
// we need a valid capture context and it's stream to seek through
|
||||
// if ( !capture || !capture->stream ) return 0;
|
||||
|
||||
/// ratio must be [0..1]
|
||||
if ( ratio > 1 || ratio < 0 ) return 0;
|
||||
|
||||
if ( capture->seekable )
|
||||
{
|
||||
// TODO: FIX IT, DOESN'T WORK PROPERLY, YET...!
|
||||
int pos_t, pos_l, length;
|
||||
xine_get_pos_length( capture->stream, &pos_l, &pos_t, &length );
|
||||
fprintf( stderr, "ratio on GetProperty(): %n\n", pos_l );
|
||||
|
||||
/// use xinelib's seek functionality
|
||||
if ( xine_play( capture->stream, (int)(ratio*(float)length), 0 ) )
|
||||
{
|
||||
capture->frame_number = ( int ) ( ratio*length / capture->frame_duration );
|
||||
}
|
||||
else
|
||||
{
|
||||
#ifndef NDEBUG
|
||||
fprintf( stderr, "(DEBUG) icvSeekRatioAVI_XINE ... failed!\n" );
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/// TODO: fill it !
|
||||
fprintf( stderr, "icvSeekRatioAVI_XINE(): Seek not supported by stream !\n" );
|
||||
fprintf( stderr, "icvSeekRatioAVI_XINE(): (seek in stream with NO seek support NOT implemented...yet!)\n" );
|
||||
#ifndef NDEBUG
|
||||
fprintf( stderr, "(DEBUG) icvSeekRatioAVI_XINE ... failed!\n" );
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifndef NDEBUG
|
||||
fprintf( stderr, "(DEBUG) icvSeekRatioAVI_XINE ... end!\n" );
|
||||
#endif
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
static double icvGetPropertyAVI_XINE( CvCaptureAVI_XINE* capture, int property_id )
|
||||
{
|
||||
#ifndef NDEBUG
|
||||
fprintf( stderr, "(DEBUG) icvGetPropertyAVI_XINE ... start\n" );
|
||||
#endif
|
||||
|
||||
OPENCV_ASSERT ( capture,
|
||||
"icvGetPropertyAVI_XINE( CvCaptureAVI_XINE *, int )", "illegal capture");
|
||||
OPENCV_ASSERT ( capture->stream,
|
||||
"icvGetPropertyAVI_XINE( CvCaptureAVI_XINE *, int )", "illegal capture->stream");
|
||||
OPENCV_ASSERT ( capture->vo_port,
|
||||
"icvGetPropertyAVI_XINE( CvCaptureAVI_XINE *, int )", "illegal capture->vo_port");
|
||||
OPENCV_ASSERT ( capture->xine,
|
||||
"icvGetPropertyAVI_XINE( CvCaptureAVI_XINE *, int )", "illegal capture->xine");
|
||||
OPENCV_ASSERT ( capture->bgr_frame,
|
||||
"icvGetPropertyAVI_XINE( CvCaptureAVI_XINE *, int )", "illegal capture->bgr_frame");
|
||||
|
||||
// not needed tnx to asserts...
|
||||
// we need a valid capture context and it's stream to seek through
|
||||
// if ( !capture || !capture->stream || !capture->bgr_frame || !capture->xine || !capture->vo_port ) return 0
|
||||
|
||||
int pos_t, pos_l, length;
|
||||
xine_get_pos_length( capture->stream, &pos_l, &pos_t, &length );
|
||||
fprintf( stderr, "ratio on GetProperty(): %i\n", pos_l );
|
||||
|
||||
switch ( property_id )
|
||||
{
|
||||
/// return actual position in msec
|
||||
case CV_CAP_PROP_POS_MSEC:
|
||||
if ( !capture->seekable )
|
||||
{
|
||||
fprintf( stderr, "(ERROR) GetPropertyAVI_XINE(CV_CAP_PROP_POS_MSEC:\n" );
|
||||
fprintf( stderr, " Stream is NOT seekable, so position info may NOT be valid !!\n" );
|
||||
}
|
||||
return pos_t;
|
||||
|
||||
/// return actual frame number
|
||||
case CV_CAP_PROP_POS_FRAMES:
|
||||
/// we insist the capture->frame_number to be remain updated !!!!
|
||||
return capture->frame_number;
|
||||
|
||||
/// return actual position ratio in the range [0..1] depending on
|
||||
/// the total length of the stream and the actual position
|
||||
case CV_CAP_PROP_POS_AVI_RATIO:
|
||||
if ( !capture->seekable )
|
||||
{
|
||||
fprintf( stderr, "(ERROR) GetPropertyAVI_XINE(CV_CAP_PROP_POS_AVI_RATIO:\n" );
|
||||
fprintf( stderr, " Stream is NOT seekable, so ratio info may NOT be valid !!\n" );
|
||||
}
|
||||
if ( length == 0 ) break;
|
||||
else return pos_l / 65535;
|
||||
|
||||
|
||||
/// return width of image source
|
||||
case CV_CAP_PROP_FRAME_WIDTH:
|
||||
return capture->size.width;
|
||||
|
||||
/// return height of image source
|
||||
case CV_CAP_PROP_FRAME_HEIGHT:
|
||||
return capture->size.height;
|
||||
|
||||
/// return framerate of stream
|
||||
case CV_CAP_PROP_FPS:
|
||||
if ( !capture->seekable )
|
||||
{
|
||||
fprintf( stderr, "(ERROR) GetPropertyAVI_XINE(CV_CAP_PROP_FPS:\n" );
|
||||
fprintf( stderr, " Stream is NOT seekable, so FPS info may NOT be valid !!\n" );
|
||||
}
|
||||
return capture->frame_rate;
|
||||
|
||||
/// return four-character-code (FOURCC) of source's codec
|
||||
case CV_CAP_PROP_FOURCC:
|
||||
return ( double ) xine_get_stream_info( capture->stream, XINE_STREAM_INFO_VIDEO_FOURCC );
|
||||
}
|
||||
|
||||
#ifndef NDEBUG
|
||||
fprintf( stderr, "(DEBUG) icvGetPropertyAVI_XINE ... failed!\n" );
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static int icvSetPropertyAVI_XINE( CvCaptureAVI_XINE* capture,
|
||||
int property_id, double value )
|
||||
{
|
||||
#ifndef NDEBUG
|
||||
fprintf( stderr, "(DEBUG) icvSetPropertyAVI_XINE ... start\n" );
|
||||
#endif
|
||||
|
||||
OPENCV_ASSERT ( capture,
|
||||
"icvSetPropertyAVI_XINE( CvCaptureAVI_XINE *, int, double )", "illegal capture");
|
||||
OPENCV_ASSERT ( capture->stream,
|
||||
"icvGetPropericvSetPropertyAVI_XINE( CvCaptureAVI_XINE *, int )", "illegal capture->stream");
|
||||
OPENCV_ASSERT ( capture->vo_port,
|
||||
"icvSetPropertyAVI_XINE( CvCaptureAVI_XINE *, int, double )", "illegal capture->vo_port");
|
||||
|
||||
// not needed tnx to asserts...
|
||||
// we need a valid capture context and it's stream to seek through
|
||||
// if ( !capture || !capture->stream || !capture->bgr_frame || !capture->xine || !capture->vo_port ) return 0
|
||||
|
||||
#ifndef NDEBUG
|
||||
fprintf( stderr, "(DEBUG) icvSetPropertyAVI_XINE: seeking to value %f ... ", value );
|
||||
#endif
|
||||
|
||||
switch ( property_id )
|
||||
{
|
||||
/// set (seek to) position in msec
|
||||
case CV_CAP_PROP_POS_MSEC:
|
||||
return icvSeekTimeAVI_XINE( capture, ( int ) value );
|
||||
|
||||
/// set (seek to) frame number
|
||||
case CV_CAP_PROP_POS_FRAMES:
|
||||
return icvSeekFrameAVI_XINE( capture, ( int ) value );
|
||||
|
||||
/// set (seek to) position ratio in the range [0..1] depending on
|
||||
/// the total length of the stream and the actual position
|
||||
case CV_CAP_PROP_POS_AVI_RATIO:
|
||||
return icvSeekRatioAVI_XINE( capture, value );
|
||||
|
||||
default:
|
||||
#ifndef NDEBUG
|
||||
fprintf( stderr, "(DEBUG) icvSetPropertyAVI_XINE ... failed!\n" );
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static CvCaptureVTable captureAVI_XINE_vtable =
|
||||
{
|
||||
6,
|
||||
( CvCaptureCloseFunc ) icvCloseAVI_XINE,
|
||||
( CvCaptureGrabFrameFunc ) icvGrabFrameAVI_XINE,
|
||||
( CvCaptureRetrieveFrameFunc ) icvRetrieveFrameAVI_XINE,
|
||||
( CvCaptureGetPropertyFunc ) icvGetPropertyAVI_XINE,
|
||||
( CvCaptureSetPropertyFunc ) icvSetPropertyAVI_XINE,
|
||||
( CvCaptureGetDescriptionFunc ) 0
|
||||
};
|
||||
|
||||
|
||||
CvCapture* cvCaptureFromFile_XINE( const char* filename )
|
||||
{
|
||||
// construct capture struct
|
||||
CvCaptureAVI_XINE * capture = ( CvCaptureAVI_XINE* ) cvAlloc ( sizeof ( CvCaptureAVI_XINE ) );
|
||||
memset( capture, 0, sizeof ( CvCaptureAVI_XINE ) );
|
||||
capture->vtable = &captureAVI_XINE_vtable;
|
||||
|
||||
// initialize XINE
|
||||
if ( !icvOpenAVI_XINE( capture, filename ) )
|
||||
return 0;
|
||||
|
||||
OPENCV_ASSERT ( capture,
|
||||
"cvCaptureFromFile_XINE( const char * )", "couldn't create capture");
|
||||
|
||||
return ( CvCapture* ) capture;
|
||||
|
||||
}
|
||||
|
||||
#undef NDEBUG
|
||||
@@ -0,0 +1 @@
|
||||
// this file is empty but needed for libtool
|
||||
@@ -0,0 +1,301 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// Intel License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000, Intel Corporation, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of Intel Corporation may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "_highgui.h"
|
||||
|
||||
#include "grfmt_base.h"
|
||||
#include "bitstrm.h"
|
||||
|
||||
|
||||
GrFmtReader::GrFmtReader( const char* filename )
|
||||
{
|
||||
strncpy( m_filename, filename, sizeof(m_filename) - 1 );
|
||||
m_filename[sizeof(m_filename)-1] = '\0';
|
||||
m_width = m_height = 0;
|
||||
m_iscolor = false;
|
||||
m_bit_depth = 8;
|
||||
m_native_depth = false;
|
||||
m_isfloat = false;
|
||||
}
|
||||
|
||||
|
||||
GrFmtReader::~GrFmtReader()
|
||||
{
|
||||
Close();
|
||||
}
|
||||
|
||||
|
||||
void GrFmtReader::Close()
|
||||
{
|
||||
m_width = m_height = 0;
|
||||
m_iscolor = false;
|
||||
}
|
||||
|
||||
|
||||
GrFmtWriter::GrFmtWriter( const char* filename )
|
||||
{
|
||||
strncpy( m_filename, filename, sizeof(m_filename) - 1 );
|
||||
m_filename[sizeof(m_filename)-1] = '\0';
|
||||
}
|
||||
|
||||
|
||||
bool GrFmtWriter::IsFormatSupported( int depth )
|
||||
{
|
||||
return depth == IPL_DEPTH_8U;
|
||||
}
|
||||
|
||||
|
||||
GrFmtFilterFactory::GrFmtFilterFactory()
|
||||
{
|
||||
m_description = m_signature = 0;
|
||||
m_sign_len = 0;
|
||||
}
|
||||
|
||||
|
||||
bool GrFmtFilterFactory::CheckSignature( const char* signature )
|
||||
{
|
||||
return m_sign_len > 0 && signature != 0 &&
|
||||
memcmp( signature, m_signature, m_sign_len ) == 0;
|
||||
}
|
||||
|
||||
|
||||
static int GetExtensionLength( const char* buffer )
|
||||
{
|
||||
int len = 0;
|
||||
|
||||
if( buffer )
|
||||
{
|
||||
const char* ext = strchr( buffer, '.');
|
||||
if( ext++ )
|
||||
while( isalnum(ext[len]) && len < _MAX_PATH )
|
||||
len++;
|
||||
}
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
|
||||
bool GrFmtFilterFactory::CheckExtension( const char* format )
|
||||
{
|
||||
const char* descr = 0;
|
||||
int len = 0;
|
||||
|
||||
if( !format || !m_description )
|
||||
return false;
|
||||
|
||||
// find the right-most extension of the passed format string
|
||||
for(;;)
|
||||
{
|
||||
const char* ext = strchr( format + 1, '.' );
|
||||
if( !ext ) break;
|
||||
format = ext;
|
||||
}
|
||||
|
||||
len = GetExtensionLength( format );
|
||||
|
||||
if( format[0] != '.' || len == 0 )
|
||||
return false;
|
||||
|
||||
descr = strchr( m_description, '(' );
|
||||
|
||||
while( descr )
|
||||
{
|
||||
descr = strchr( descr + 1, '.' );
|
||||
int i, len2 = GetExtensionLength( descr );
|
||||
|
||||
if( len2 == 0 )
|
||||
break;
|
||||
|
||||
if( len2 == len )
|
||||
{
|
||||
for( i = 0; i < len; i++ )
|
||||
{
|
||||
int c1 = tolower(format[i+1]);
|
||||
int c2 = tolower(descr[i+1]);
|
||||
|
||||
if( c1 != c2 )
|
||||
break;
|
||||
}
|
||||
if( i == len )
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
///////////////////// GrFmtFilterList //////////////////////////
|
||||
|
||||
GrFmtFactoriesList::GrFmtFactoriesList()
|
||||
{
|
||||
m_factories = 0;
|
||||
RemoveAll();
|
||||
}
|
||||
|
||||
|
||||
GrFmtFactoriesList::~GrFmtFactoriesList()
|
||||
{
|
||||
RemoveAll();
|
||||
}
|
||||
|
||||
|
||||
void GrFmtFactoriesList::RemoveAll()
|
||||
{
|
||||
if( m_factories )
|
||||
{
|
||||
for( int i = 0; i < m_curFactories; i++ ) delete m_factories[i];
|
||||
delete[] m_factories;
|
||||
}
|
||||
m_factories = 0;
|
||||
m_maxFactories = m_curFactories = 0;
|
||||
}
|
||||
|
||||
|
||||
bool GrFmtFactoriesList::AddFactory( GrFmtFilterFactory* factory )
|
||||
{
|
||||
assert( factory != 0 );
|
||||
if( m_curFactories == m_maxFactories )
|
||||
{
|
||||
// reallocate the factorys pointers storage
|
||||
int newMaxFactories = 2*m_maxFactories;
|
||||
if( newMaxFactories < 16 ) newMaxFactories = 16;
|
||||
|
||||
GrFmtFilterFactory** newFactories = new GrFmtFilterFactory*[newMaxFactories];
|
||||
|
||||
for( int i = 0; i < m_curFactories; i++ ) newFactories[i] = m_factories[i];
|
||||
|
||||
delete[] m_factories;
|
||||
m_factories = newFactories;
|
||||
m_maxFactories = newMaxFactories;
|
||||
}
|
||||
|
||||
m_factories[m_curFactories++] = factory;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
ListPosition GrFmtFactoriesList::GetFirstFactoryPos()
|
||||
{
|
||||
return (ListPosition)m_factories;
|
||||
}
|
||||
|
||||
|
||||
GrFmtFilterFactory* GrFmtFactoriesList::GetNextFactory( ListPosition& pos )
|
||||
{
|
||||
GrFmtFilterFactory* factory = 0;
|
||||
GrFmtFilterFactory** temp = (GrFmtFilterFactory**)pos;
|
||||
|
||||
assert( temp == 0 || (m_factories <= temp && temp < m_factories + m_curFactories));
|
||||
if( temp )
|
||||
{
|
||||
factory = *temp++;
|
||||
pos = (ListPosition)(temp < m_factories + m_curFactories ? temp : 0);
|
||||
}
|
||||
return factory;
|
||||
}
|
||||
|
||||
|
||||
GrFmtReader* GrFmtFactoriesList::FindReader( const char* filename )
|
||||
{
|
||||
FILE* f = 0;
|
||||
char signature[4096];
|
||||
int sign_len = 0;
|
||||
GrFmtReader* reader = 0;
|
||||
ListPosition pos = GetFirstFactoryPos();
|
||||
|
||||
if( !filename ) return 0;
|
||||
|
||||
while( pos )
|
||||
{
|
||||
GrFmtFilterFactory* tempFactory = GetNextFactory(pos);
|
||||
int cur_sign_len = tempFactory->GetSignatureLength();
|
||||
if( sign_len < cur_sign_len ) sign_len = cur_sign_len;
|
||||
}
|
||||
|
||||
assert( sign_len <= (int)sizeof(signature) );
|
||||
f = fopen( filename, "rb" );
|
||||
|
||||
if( f )
|
||||
{
|
||||
sign_len = (int)fread( signature, 1, sign_len, f );
|
||||
fclose(f);
|
||||
|
||||
pos = GetFirstFactoryPos();
|
||||
while( pos )
|
||||
{
|
||||
GrFmtFilterFactory* tempFactory = GetNextFactory(pos);
|
||||
int cur_sign_len = tempFactory->GetSignatureLength();
|
||||
if( cur_sign_len <= sign_len && tempFactory->CheckSignature(signature))
|
||||
{
|
||||
reader = tempFactory->NewReader( filename );
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return reader;
|
||||
}
|
||||
|
||||
|
||||
GrFmtWriter* GrFmtFactoriesList::FindWriter( const char* filename )
|
||||
{
|
||||
GrFmtWriter* writer = 0;
|
||||
ListPosition pos = GetFirstFactoryPos();
|
||||
|
||||
if( !filename ) return 0;
|
||||
|
||||
while( pos )
|
||||
{
|
||||
GrFmtFilterFactory* tempFactory = GetNextFactory(pos);
|
||||
if( tempFactory->CheckExtension( filename ))
|
||||
{
|
||||
writer = tempFactory->NewWriter( filename );
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return writer;
|
||||
}
|
||||
|
||||
/* End of file. */
|
||||
|
||||
@@ -0,0 +1,162 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// Intel License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000, Intel Corporation, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of Intel Corporation may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#ifndef _GRFMT_BASE_H_
|
||||
#define _GRFMT_BASE_H_
|
||||
|
||||
#if _MSC_VER >= 1200
|
||||
#pragma warning( disable: 4514 )
|
||||
#pragma warning( disable: 4711 )
|
||||
#pragma warning( disable: 4611 )
|
||||
#endif
|
||||
|
||||
#include "utils.h"
|
||||
#include "bitstrm.h"
|
||||
|
||||
#define RBS_BAD_HEADER -125 /* invalid image header */
|
||||
#define BAD_HEADER_ERR() goto bad_header_exit
|
||||
|
||||
#ifndef _MAX_PATH
|
||||
#define _MAX_PATH 1024
|
||||
#endif
|
||||
|
||||
|
||||
///////////////////////////////// base class for readers ////////////////////////
|
||||
class GrFmtReader
|
||||
{
|
||||
public:
|
||||
|
||||
GrFmtReader( const char* filename );
|
||||
virtual ~GrFmtReader();
|
||||
|
||||
int GetWidth() { return m_width; };
|
||||
int GetHeight() { return m_height; };
|
||||
bool IsColor() { return m_iscolor; };
|
||||
int GetDepth() { return m_bit_depth; };
|
||||
void UseNativeDepth( bool yes ) { m_native_depth = yes; };
|
||||
bool IsFloat() { return m_isfloat; };
|
||||
|
||||
virtual bool ReadHeader() = 0;
|
||||
virtual bool ReadData( uchar* data, int step, int color ) = 0;
|
||||
virtual void Close();
|
||||
|
||||
protected:
|
||||
|
||||
bool m_iscolor;
|
||||
int m_width; // width of the image ( filled by ReadHeader )
|
||||
int m_height; // height of the image ( filled by ReadHeader )
|
||||
int m_bit_depth;// bit depth per channel (normally 8)
|
||||
char m_filename[_MAX_PATH]; // filename
|
||||
bool m_native_depth;// use the native bit depth of the image
|
||||
bool m_isfloat; // is image saved as float or double?
|
||||
};
|
||||
|
||||
|
||||
///////////////////////////// base class for writers ////////////////////////////
|
||||
class GrFmtWriter
|
||||
{
|
||||
public:
|
||||
|
||||
GrFmtWriter( const char* filename );
|
||||
virtual ~GrFmtWriter() {};
|
||||
virtual bool IsFormatSupported( int depth );
|
||||
virtual bool WriteImage( const uchar* data, int step,
|
||||
int width, int height, int depth, int channels ) = 0;
|
||||
protected:
|
||||
char m_filename[_MAX_PATH]; // filename
|
||||
};
|
||||
|
||||
|
||||
////////////////////////////// base class for filter factories //////////////////
|
||||
class GrFmtFilterFactory
|
||||
{
|
||||
public:
|
||||
|
||||
GrFmtFilterFactory();
|
||||
virtual ~GrFmtFilterFactory() {};
|
||||
|
||||
const char* GetDescription() { return m_description; };
|
||||
int GetSignatureLength() { return m_sign_len; };
|
||||
virtual bool CheckSignature( const char* signature );
|
||||
virtual bool CheckExtension( const char* filename );
|
||||
virtual GrFmtReader* NewReader( const char* filename ) = 0;
|
||||
virtual GrFmtWriter* NewWriter( const char* filename ) = 0;
|
||||
|
||||
protected:
|
||||
const char* m_description;
|
||||
// graphic format description in form:
|
||||
// <Some textual description>( *.<extension1> [; *.<extension2> ...]).
|
||||
// the textual description can not contain symbols '(', ')'
|
||||
// and may be, some others. It is safe to use letters, digits and spaces only.
|
||||
// e.g. "Targa (*.tga)",
|
||||
// or "Portable Graphic Format (*.pbm;*.pgm;*.ppm)"
|
||||
|
||||
int m_sign_len; // length of the signature of the format
|
||||
const char* m_signature; // signature of the format
|
||||
};
|
||||
|
||||
|
||||
/////////////////////////// list of graphic format filters ///////////////////////////////
|
||||
|
||||
typedef void* ListPosition;
|
||||
|
||||
class GrFmtFactoriesList
|
||||
{
|
||||
public:
|
||||
|
||||
GrFmtFactoriesList();
|
||||
virtual ~GrFmtFactoriesList();
|
||||
void RemoveAll();
|
||||
bool AddFactory( GrFmtFilterFactory* factory );
|
||||
int FactoriesCount() { return m_curFactories; };
|
||||
ListPosition GetFirstFactoryPos();
|
||||
GrFmtFilterFactory* GetNextFactory( ListPosition& pos );
|
||||
virtual GrFmtReader* FindReader( const char* filename );
|
||||
virtual GrFmtWriter* FindWriter( const char* filename );
|
||||
|
||||
protected:
|
||||
|
||||
GrFmtFilterFactory** m_factories;
|
||||
int m_maxFactories;
|
||||
int m_curFactories;
|
||||
};
|
||||
|
||||
#endif/*_GRFMT_BASE_H_*/
|
||||
@@ -0,0 +1,551 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// Intel License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000, Intel Corporation, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of Intel Corporation may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "_highgui.h"
|
||||
#include "grfmt_bmp.h"
|
||||
|
||||
static const char* fmtSignBmp = "BM";
|
||||
|
||||
GrFmtBmp::GrFmtBmp()
|
||||
{
|
||||
m_sign_len = 2;
|
||||
m_signature = fmtSignBmp;
|
||||
m_description = "Windows bitmap (*.bmp;*.dib)";
|
||||
}
|
||||
|
||||
|
||||
GrFmtBmp::~GrFmtBmp()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
GrFmtReader* GrFmtBmp::NewReader( const char* filename )
|
||||
{
|
||||
return new GrFmtBmpReader( filename );
|
||||
}
|
||||
|
||||
|
||||
GrFmtWriter* GrFmtBmp::NewWriter( const char* filename )
|
||||
{
|
||||
return new GrFmtBmpWriter( filename );
|
||||
}
|
||||
|
||||
|
||||
/************************ BMP reader *****************************/
|
||||
|
||||
GrFmtBmpReader::GrFmtBmpReader( const char* filename ) : GrFmtReader( filename )
|
||||
{
|
||||
m_offset = -1;
|
||||
}
|
||||
|
||||
|
||||
GrFmtBmpReader::~GrFmtBmpReader()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void GrFmtBmpReader::Close()
|
||||
{
|
||||
m_strm.Close();
|
||||
GrFmtReader::Close();
|
||||
}
|
||||
|
||||
|
||||
bool GrFmtBmpReader::ReadHeader()
|
||||
{
|
||||
bool result = false;
|
||||
|
||||
assert( strlen(m_filename) != 0 );
|
||||
if( !m_strm.Open( m_filename )) return false;
|
||||
|
||||
if( setjmp( m_strm.JmpBuf()) == 0 )
|
||||
{
|
||||
m_strm.Skip( 10 );
|
||||
m_offset = m_strm.GetDWord();
|
||||
|
||||
int size = m_strm.GetDWord();
|
||||
|
||||
if( size >= 36 )
|
||||
{
|
||||
m_width = m_strm.GetDWord();
|
||||
m_height = m_strm.GetDWord();
|
||||
m_bpp = m_strm.GetDWord() >> 16;
|
||||
m_rle_code = (BmpCompression)m_strm.GetDWord();
|
||||
m_strm.Skip(12);
|
||||
int clrused = m_strm.GetDWord();
|
||||
m_strm.Skip( size - 36 );
|
||||
|
||||
if( m_width > 0 && m_height > 0 &&
|
||||
(((m_bpp == 1 || m_bpp == 4 || m_bpp == 8 ||
|
||||
m_bpp == 24 || m_bpp == 32 ) && m_rle_code == BMP_RGB) ||
|
||||
(m_bpp == 16 && (m_rle_code == BMP_RGB || m_rle_code == BMP_BITFIELDS)) ||
|
||||
(m_bpp == 4 && m_rle_code == BMP_RLE4) ||
|
||||
(m_bpp == 8 && m_rle_code == BMP_RLE8)))
|
||||
{
|
||||
m_iscolor = true;
|
||||
result = true;
|
||||
|
||||
if( m_bpp <= 8 )
|
||||
{
|
||||
memset( m_palette, 0, sizeof(m_palette));
|
||||
m_strm.GetBytes( m_palette, (clrused == 0? 1<<m_bpp : clrused)*4 );
|
||||
m_iscolor = IsColorPalette( m_palette, m_bpp );
|
||||
}
|
||||
else if( m_bpp == 16 && m_rle_code == BMP_BITFIELDS )
|
||||
{
|
||||
int redmask = m_strm.GetDWord();
|
||||
int greenmask = m_strm.GetDWord();
|
||||
int bluemask = m_strm.GetDWord();
|
||||
|
||||
if( bluemask == 0x1f && greenmask == 0x3e0 && redmask == 0x7c00 )
|
||||
m_bpp = 15;
|
||||
else if( bluemask == 0x1f && greenmask == 0x7e0 && redmask == 0xf800 )
|
||||
;
|
||||
else
|
||||
result = false;
|
||||
}
|
||||
else if( m_bpp == 16 && m_rle_code == BMP_RGB )
|
||||
m_bpp = 15;
|
||||
}
|
||||
}
|
||||
else if( size == 12 )
|
||||
{
|
||||
m_width = m_strm.GetWord();
|
||||
m_height = m_strm.GetWord();
|
||||
m_bpp = m_strm.GetDWord() >> 16;
|
||||
m_rle_code = BMP_RGB;
|
||||
|
||||
if( m_width > 0 && m_height > 0 &&
|
||||
(m_bpp == 1 || m_bpp == 4 || m_bpp == 8 ||
|
||||
m_bpp == 24 || m_bpp == 32 ))
|
||||
{
|
||||
if( m_bpp <= 8 )
|
||||
{
|
||||
uchar buffer[256*3];
|
||||
int j, clrused = 1 << m_bpp;
|
||||
m_strm.GetBytes( buffer, clrused*3 );
|
||||
for( j = 0; j < clrused; j++ )
|
||||
{
|
||||
m_palette[j].b = buffer[3*j+0];
|
||||
m_palette[j].g = buffer[3*j+1];
|
||||
m_palette[j].r = buffer[3*j+2];
|
||||
}
|
||||
}
|
||||
result = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if( !result )
|
||||
{
|
||||
m_offset = -1;
|
||||
m_width = m_height = -1;
|
||||
m_strm.Close();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
bool GrFmtBmpReader::ReadData( uchar* data, int step, int color )
|
||||
{
|
||||
const int buffer_size = 1 << 12;
|
||||
uchar buffer[buffer_size];
|
||||
uchar bgr_buffer[buffer_size];
|
||||
uchar gray_palette[256];
|
||||
bool result = false;
|
||||
uchar* src = buffer;
|
||||
uchar* bgr = bgr_buffer;
|
||||
int src_pitch = ((m_width*(m_bpp != 15 ? m_bpp : 16) + 7)/8 + 3) & -4;
|
||||
int nch = color ? 3 : 1;
|
||||
int width3 = m_width*nch;
|
||||
int y;
|
||||
|
||||
if( m_offset < 0 || !m_strm.IsOpened())
|
||||
return false;
|
||||
|
||||
data += (m_height - 1)*step;
|
||||
step = -step;
|
||||
|
||||
if( (m_bpp != 24 || !color) && src_pitch+32 > buffer_size )
|
||||
src = new uchar[src_pitch+32];
|
||||
|
||||
if( !color )
|
||||
{
|
||||
if( m_bpp <= 8 )
|
||||
{
|
||||
CvtPaletteToGray( m_palette, gray_palette, 1 << m_bpp );
|
||||
}
|
||||
if( m_width*3 + 32 > buffer_size ) bgr = new uchar[m_width*3 + 32];
|
||||
}
|
||||
|
||||
if( setjmp( m_strm.JmpBuf()) == 0 )
|
||||
{
|
||||
m_strm.SetPos( m_offset );
|
||||
|
||||
switch( m_bpp )
|
||||
{
|
||||
/************************* 1 BPP ************************/
|
||||
case 1:
|
||||
for( y = 0; y < m_height; y++, data += step )
|
||||
{
|
||||
m_strm.GetBytes( src, src_pitch );
|
||||
FillColorRow1( color ? data : bgr, src, m_width, m_palette );
|
||||
if( !color )
|
||||
icvCvt_BGR2Gray_8u_C3C1R( bgr, 0, data, 0, cvSize(m_width,1) );
|
||||
}
|
||||
result = true;
|
||||
break;
|
||||
|
||||
/************************* 4 BPP ************************/
|
||||
case 4:
|
||||
if( m_rle_code == BMP_RGB )
|
||||
{
|
||||
for( y = 0; y < m_height; y++, data += step )
|
||||
{
|
||||
m_strm.GetBytes( src, src_pitch );
|
||||
if( color )
|
||||
FillColorRow4( data, src, m_width, m_palette );
|
||||
else
|
||||
FillGrayRow4( data, src, m_width, gray_palette );
|
||||
}
|
||||
result = true;
|
||||
}
|
||||
else if( m_rle_code == BMP_RLE4 ) // rle4 compression
|
||||
{
|
||||
uchar* line_end = data + width3;
|
||||
y = 0;
|
||||
|
||||
for(;;)
|
||||
{
|
||||
int code = m_strm.GetWord();
|
||||
int len = code & 255;
|
||||
code >>= 8;
|
||||
if( len != 0 ) // encoded mode
|
||||
{
|
||||
PaletteEntry clr[2];
|
||||
uchar gray_clr[2];
|
||||
int t = 0;
|
||||
|
||||
clr[0] = m_palette[code >> 4];
|
||||
clr[1] = m_palette[code & 15];
|
||||
gray_clr[0] = gray_palette[code >> 4];
|
||||
gray_clr[1] = gray_palette[code & 15];
|
||||
|
||||
uchar* end = data + len*nch;
|
||||
if( end > line_end ) goto decode_rle4_bad;
|
||||
do
|
||||
{
|
||||
if( color )
|
||||
WRITE_PIX( data, clr[t] );
|
||||
else
|
||||
*data = gray_clr[t];
|
||||
t ^= 1;
|
||||
}
|
||||
while( (data += nch) < end );
|
||||
}
|
||||
else if( code > 2 ) // absolute mode
|
||||
{
|
||||
if( data + code*nch > line_end ) goto decode_rle4_bad;
|
||||
m_strm.GetBytes( src, (((code + 1)>>1) + 1) & -2 );
|
||||
if( color )
|
||||
data = FillColorRow4( data, src, code, m_palette );
|
||||
else
|
||||
data = FillGrayRow4( data, src, code, gray_palette );
|
||||
}
|
||||
else
|
||||
{
|
||||
int x_shift3 = (int)(line_end - data);
|
||||
int y_shift = m_height - y;
|
||||
|
||||
if( code == 2 )
|
||||
{
|
||||
x_shift3 = m_strm.GetByte()*nch;
|
||||
y_shift = m_strm.GetByte();
|
||||
}
|
||||
|
||||
len = x_shift3 + (y_shift * width3) & ((code == 0) - 1);
|
||||
|
||||
if( color )
|
||||
data = FillUniColor( data, line_end, step, width3,
|
||||
y, m_height, x_shift3,
|
||||
m_palette[0] );
|
||||
else
|
||||
data = FillUniGray( data, line_end, step, width3,
|
||||
y, m_height, x_shift3,
|
||||
gray_palette[0] );
|
||||
|
||||
if( y >= m_height )
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
result = true;
|
||||
decode_rle4_bad: ;
|
||||
}
|
||||
break;
|
||||
|
||||
/************************* 8 BPP ************************/
|
||||
case 8:
|
||||
if( m_rle_code == BMP_RGB )
|
||||
{
|
||||
for( y = 0; y < m_height; y++, data += step )
|
||||
{
|
||||
m_strm.GetBytes( src, src_pitch );
|
||||
if( color )
|
||||
FillColorRow8( data, src, m_width, m_palette );
|
||||
else
|
||||
FillGrayRow8( data, src, m_width, gray_palette );
|
||||
}
|
||||
result = true;
|
||||
}
|
||||
else if( m_rle_code == BMP_RLE8 ) // rle8 compression
|
||||
{
|
||||
uchar* line_end = data + width3;
|
||||
int line_end_flag = 0;
|
||||
y = 0;
|
||||
|
||||
for(;;)
|
||||
{
|
||||
int code = m_strm.GetWord();
|
||||
int len = code & 255;
|
||||
code >>= 8;
|
||||
if( len != 0 ) // encoded mode
|
||||
{
|
||||
int prev_y = y;
|
||||
len *= nch;
|
||||
|
||||
if( data + len > line_end )
|
||||
goto decode_rle8_bad;
|
||||
|
||||
if( color )
|
||||
data = FillUniColor( data, line_end, step, width3,
|
||||
y, m_height, len,
|
||||
m_palette[code] );
|
||||
else
|
||||
data = FillUniGray( data, line_end, step, width3,
|
||||
y, m_height, len,
|
||||
gray_palette[code] );
|
||||
|
||||
line_end_flag = y - prev_y;
|
||||
}
|
||||
else if( code > 2 ) // absolute mode
|
||||
{
|
||||
int prev_y = y;
|
||||
int code3 = code*nch;
|
||||
|
||||
if( data + code3 > line_end )
|
||||
goto decode_rle8_bad;
|
||||
m_strm.GetBytes( src, (code + 1) & -2 );
|
||||
if( color )
|
||||
data = FillColorRow8( data, src, code, m_palette );
|
||||
else
|
||||
data = FillGrayRow8( data, src, code, gray_palette );
|
||||
|
||||
line_end_flag = y - prev_y;
|
||||
}
|
||||
else
|
||||
{
|
||||
int x_shift3 = (int)(line_end - data);
|
||||
int y_shift = m_height - y;
|
||||
|
||||
if( code || !line_end_flag || x_shift3 < width3 )
|
||||
{
|
||||
if( code == 2 )
|
||||
{
|
||||
x_shift3 = m_strm.GetByte()*nch;
|
||||
y_shift = m_strm.GetByte();
|
||||
}
|
||||
|
||||
x_shift3 += (y_shift * width3) & ((code == 0) - 1);
|
||||
|
||||
if( y >= m_height )
|
||||
break;
|
||||
|
||||
if( color )
|
||||
data = FillUniColor( data, line_end, step, width3,
|
||||
y, m_height, x_shift3,
|
||||
m_palette[0] );
|
||||
else
|
||||
data = FillUniGray( data, line_end, step, width3,
|
||||
y, m_height, x_shift3,
|
||||
gray_palette[0] );
|
||||
|
||||
if( y >= m_height )
|
||||
break;
|
||||
}
|
||||
|
||||
line_end_flag = 0;
|
||||
}
|
||||
}
|
||||
|
||||
result = true;
|
||||
decode_rle8_bad: ;
|
||||
}
|
||||
break;
|
||||
/************************* 15 BPP ************************/
|
||||
case 15:
|
||||
for( y = 0; y < m_height; y++, data += step )
|
||||
{
|
||||
m_strm.GetBytes( src, src_pitch );
|
||||
if( !color )
|
||||
icvCvt_BGR5552Gray_8u_C2C1R( src, 0, data, 0, cvSize(m_width,1) );
|
||||
else
|
||||
icvCvt_BGR5552BGR_8u_C2C3R( src, 0, data, 0, cvSize(m_width,1) );
|
||||
}
|
||||
result = true;
|
||||
break;
|
||||
/************************* 16 BPP ************************/
|
||||
case 16:
|
||||
for( y = 0; y < m_height; y++, data += step )
|
||||
{
|
||||
m_strm.GetBytes( src, src_pitch );
|
||||
if( !color )
|
||||
icvCvt_BGR5652Gray_8u_C2C1R( src, 0, data, 0, cvSize(m_width,1) );
|
||||
else
|
||||
icvCvt_BGR5652BGR_8u_C2C3R( src, 0, data, 0, cvSize(m_width,1) );
|
||||
}
|
||||
result = true;
|
||||
break;
|
||||
/************************* 24 BPP ************************/
|
||||
case 24:
|
||||
for( y = 0; y < m_height; y++, data += step )
|
||||
{
|
||||
m_strm.GetBytes( color ? data : src, src_pitch );
|
||||
if( !color )
|
||||
icvCvt_BGR2Gray_8u_C3C1R( src, 0, data, 0, cvSize(m_width,1) );
|
||||
}
|
||||
result = true;
|
||||
break;
|
||||
/************************* 32 BPP ************************/
|
||||
case 32:
|
||||
for( y = 0; y < m_height; y++, data += step )
|
||||
{
|
||||
m_strm.GetBytes( src, src_pitch );
|
||||
|
||||
if( !color )
|
||||
icvCvt_BGRA2Gray_8u_C4C1R( src, 0, data, 0, cvSize(m_width,1) );
|
||||
else
|
||||
icvCvt_BGRA2BGR_8u_C4C3R( src, 0, data, 0, cvSize(m_width,1) );
|
||||
}
|
||||
result = true;
|
||||
break;
|
||||
default:
|
||||
assert(0);
|
||||
}
|
||||
}
|
||||
|
||||
if( src != buffer ) delete[] src;
|
||||
if( bgr != bgr_buffer ) delete[] bgr;
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
GrFmtBmpWriter::GrFmtBmpWriter( const char* filename ) : GrFmtWriter( filename )
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
GrFmtBmpWriter::~GrFmtBmpWriter()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
bool GrFmtBmpWriter::WriteImage( const uchar* data, int step,
|
||||
int width, int height, int /*depth*/, int channels )
|
||||
{
|
||||
bool result = false;
|
||||
int fileStep = (width*channels + 3) & -4;
|
||||
uchar zeropad[] = "\0\0\0\0";
|
||||
|
||||
assert( data && width > 0 && height > 0 && step >= fileStep );
|
||||
|
||||
if( m_strm.Open( m_filename ) )
|
||||
{
|
||||
int bitmapHeaderSize = 40;
|
||||
int paletteSize = channels > 1 ? 0 : 1024;
|
||||
int headerSize = 14 /* fileheader */ + bitmapHeaderSize + paletteSize;
|
||||
PaletteEntry palette[256];
|
||||
|
||||
// write signature 'BM'
|
||||
m_strm.PutBytes( fmtSignBmp, (int)strlen(fmtSignBmp) );
|
||||
|
||||
// write file header
|
||||
m_strm.PutDWord( fileStep*height + headerSize ); // file size
|
||||
m_strm.PutDWord( 0 );
|
||||
m_strm.PutDWord( headerSize );
|
||||
|
||||
// write bitmap header
|
||||
m_strm.PutDWord( bitmapHeaderSize );
|
||||
m_strm.PutDWord( width );
|
||||
m_strm.PutDWord( height );
|
||||
m_strm.PutWord( 1 );
|
||||
m_strm.PutWord( channels << 3 );
|
||||
m_strm.PutDWord( BMP_RGB );
|
||||
m_strm.PutDWord( 0 );
|
||||
m_strm.PutDWord( 0 );
|
||||
m_strm.PutDWord( 0 );
|
||||
m_strm.PutDWord( 0 );
|
||||
m_strm.PutDWord( 0 );
|
||||
|
||||
if( channels == 1 )
|
||||
{
|
||||
FillGrayPalette( palette, 8 );
|
||||
m_strm.PutBytes( palette, sizeof(palette));
|
||||
}
|
||||
|
||||
width *= channels;
|
||||
data += step*(height - 1);
|
||||
for( ; height--; data -= step )
|
||||
{
|
||||
m_strm.PutBytes( data, width );
|
||||
if( fileStep > width )
|
||||
m_strm.PutBytes( zeropad, fileStep - width );
|
||||
}
|
||||
|
||||
m_strm.Close();
|
||||
result = true;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,107 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// Intel License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000, Intel Corporation, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of Intel Corporation may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#ifndef _GRFMT_BMP_H_
|
||||
#define _GRFMT_BMP_H_
|
||||
|
||||
#include "grfmt_base.h"
|
||||
|
||||
enum BmpCompression
|
||||
{
|
||||
BMP_RGB = 0,
|
||||
BMP_RLE8 = 1,
|
||||
BMP_RLE4 = 2,
|
||||
BMP_BITFIELDS = 3
|
||||
};
|
||||
|
||||
|
||||
// Windows Bitmap reader
|
||||
class GrFmtBmpReader : public GrFmtReader
|
||||
{
|
||||
public:
|
||||
|
||||
GrFmtBmpReader( const char* filename );
|
||||
~GrFmtBmpReader();
|
||||
|
||||
bool ReadData( uchar* data, int step, int color );
|
||||
bool ReadHeader();
|
||||
void Close();
|
||||
|
||||
protected:
|
||||
|
||||
RLByteStream m_strm;
|
||||
PaletteEntry m_palette[256];
|
||||
int m_bpp;
|
||||
int m_offset;
|
||||
BmpCompression m_rle_code;
|
||||
};
|
||||
|
||||
|
||||
// ... writer
|
||||
class GrFmtBmpWriter : public GrFmtWriter
|
||||
{
|
||||
public:
|
||||
|
||||
GrFmtBmpWriter( const char* filename );
|
||||
~GrFmtBmpWriter();
|
||||
|
||||
bool WriteImage( const uchar* data, int step,
|
||||
int width, int height, int depth, int channels );
|
||||
protected:
|
||||
|
||||
WLByteStream m_strm;
|
||||
};
|
||||
|
||||
|
||||
// ... and filter factory
|
||||
class GrFmtBmp : public GrFmtFilterFactory
|
||||
{
|
||||
public:
|
||||
|
||||
GrFmtBmp();
|
||||
~GrFmtBmp();
|
||||
|
||||
GrFmtReader* NewReader( const char* filename );
|
||||
GrFmtWriter* NewWriter( const char* filename );
|
||||
|
||||
};
|
||||
|
||||
#endif/*_GRFMT_BMP_H_*/
|
||||
@@ -0,0 +1,737 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// Intel License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000, Intel Corporation, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of Intel Corporation may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "_highgui.h"
|
||||
|
||||
#ifdef HAVE_ILMIMF
|
||||
|
||||
#include <OpenEXR/ImfHeader.h>
|
||||
#include <OpenEXR/ImfInputFile.h>
|
||||
#include <OpenEXR/ImfOutputFile.h>
|
||||
#include <OpenEXR/ImfChannelList.h>
|
||||
#include <OpenEXR/ImfStandardAttributes.h>
|
||||
#include <OpenEXR/half.h>
|
||||
#include "grfmt_exr.h"
|
||||
|
||||
#if defined _MSC_VER && _MSC_VER >= 1200
|
||||
#pragma comment(lib, "Half.lib")
|
||||
#pragma comment(lib, "Iex.lib")
|
||||
#pragma comment(lib, "IlmImf.lib")
|
||||
#pragma comment(lib, "IlmThread.lib")
|
||||
#pragma comment(lib, "Imath.lib")
|
||||
|
||||
#undef UINT
|
||||
#define UINT ((Imf::PixelType)0)
|
||||
#undef HALF
|
||||
#define HALF ((Imf::PixelType)1)
|
||||
#undef FLOAT
|
||||
#define FLOAT ((Imf::PixelType)2)
|
||||
#undef uint
|
||||
#define uint unsigned
|
||||
|
||||
#endif
|
||||
|
||||
// Exr Filter Factory
|
||||
GrFmtExr::GrFmtExr()
|
||||
{
|
||||
m_sign_len = 4;
|
||||
m_signature = "\x76\x2f\x31\x01";
|
||||
m_description = "OpenEXR Image files (*.exr)";
|
||||
}
|
||||
|
||||
|
||||
GrFmtExr::~GrFmtExr()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
GrFmtReader* GrFmtExr::NewReader( const char* filename )
|
||||
{
|
||||
return new GrFmtExrReader( filename );
|
||||
}
|
||||
|
||||
|
||||
GrFmtWriter* GrFmtExr::NewWriter( const char* filename )
|
||||
{
|
||||
return new GrFmtExrWriter( filename );
|
||||
}
|
||||
|
||||
|
||||
/////////////////////// GrFmtExrReader ///////////////////
|
||||
|
||||
GrFmtExrReader::GrFmtExrReader( const char* filename ) : GrFmtReader( filename )
|
||||
{
|
||||
m_file = new InputFile( filename );
|
||||
m_red = m_green = m_blue = 0;
|
||||
}
|
||||
|
||||
|
||||
GrFmtExrReader::~GrFmtExrReader()
|
||||
{
|
||||
Close();
|
||||
}
|
||||
|
||||
|
||||
void GrFmtExrReader::Close()
|
||||
{
|
||||
if( m_file )
|
||||
{
|
||||
delete m_file;
|
||||
m_file = 0;
|
||||
}
|
||||
|
||||
GrFmtReader::Close();
|
||||
}
|
||||
|
||||
bool GrFmtExrReader::ReadHeader()
|
||||
{
|
||||
bool result = false;
|
||||
|
||||
if( !m_file ) // probably paranoid
|
||||
return false;
|
||||
|
||||
m_datawindow = m_file->header().dataWindow();
|
||||
m_width = m_datawindow.max.x - m_datawindow.min.x + 1;
|
||||
m_height = m_datawindow.max.y - m_datawindow.min.y + 1;
|
||||
|
||||
// the type HALF is converted to 32 bit float
|
||||
// and the other types supported by OpenEXR are 32 bit anyway
|
||||
m_bit_depth = 32;
|
||||
|
||||
if( hasChromaticities( m_file->header() ))
|
||||
m_chroma = chromaticities( m_file->header() );
|
||||
|
||||
const ChannelList &channels = m_file->header().channels();
|
||||
m_red = channels.findChannel( "R" );
|
||||
m_green = channels.findChannel( "G" );
|
||||
m_blue = channels.findChannel( "B" );
|
||||
if( m_red || m_green || m_blue )
|
||||
{
|
||||
m_iscolor = true;
|
||||
m_ischroma = false;
|
||||
result = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_green = channels.findChannel( "Y" );
|
||||
if( m_green )
|
||||
{
|
||||
m_ischroma = true;
|
||||
m_red = channels.findChannel( "RY" );
|
||||
m_blue = channels.findChannel( "BY" );
|
||||
m_iscolor = (m_blue || m_red);
|
||||
result = true;
|
||||
}
|
||||
else
|
||||
result = false;
|
||||
}
|
||||
|
||||
if( result )
|
||||
{
|
||||
int uintcnt = 0;
|
||||
int chcnt = 0;
|
||||
if( m_red )
|
||||
{
|
||||
chcnt++;
|
||||
uintcnt += ( m_red->type == UINT );
|
||||
}
|
||||
if( m_green )
|
||||
{
|
||||
chcnt++;
|
||||
uintcnt += ( m_green->type == UINT );
|
||||
}
|
||||
if( m_blue )
|
||||
{
|
||||
chcnt++;
|
||||
uintcnt += ( m_blue->type == UINT );
|
||||
}
|
||||
m_type = (chcnt == uintcnt) ? UINT : FLOAT;
|
||||
|
||||
m_isfloat = (m_type == FLOAT);
|
||||
}
|
||||
|
||||
if( !result )
|
||||
Close();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
bool GrFmtExrReader::ReadData( uchar* data, int step, int color )
|
||||
{
|
||||
bool justcopy = m_native_depth;
|
||||
bool chromatorgb = false;
|
||||
bool rgbtogray = false;
|
||||
bool result = true;
|
||||
FrameBuffer frame;
|
||||
int xsample[3] = {1, 1, 1};
|
||||
char *buffer;
|
||||
int xstep;
|
||||
int ystep;
|
||||
|
||||
xstep = m_native_depth ? 4 : 1;
|
||||
|
||||
if( !m_native_depth || (!color && m_iscolor ))
|
||||
{
|
||||
buffer = (char *)new float[ m_width * 3 ];
|
||||
ystep = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
buffer = (char *)data;
|
||||
ystep = step;
|
||||
}
|
||||
|
||||
if( m_ischroma )
|
||||
{
|
||||
if( color )
|
||||
{
|
||||
if( m_iscolor )
|
||||
{
|
||||
if( m_blue )
|
||||
{
|
||||
frame.insert( "BY", Slice( m_type,
|
||||
buffer - m_datawindow.min.x * 12 - m_datawindow.min.y * ystep,
|
||||
12, ystep, m_blue->xSampling, m_blue->ySampling, 0.0 ));
|
||||
xsample[0] = m_blue->ySampling;
|
||||
}
|
||||
if( m_green )
|
||||
{
|
||||
frame.insert( "Y", Slice( m_type,
|
||||
buffer - m_datawindow.min.x * 12 - m_datawindow.min.y * ystep + 4,
|
||||
12, ystep, m_green->xSampling, m_green->ySampling, 0.0 ));
|
||||
xsample[1] = m_green->ySampling;
|
||||
}
|
||||
if( m_red )
|
||||
{
|
||||
frame.insert( "RY", Slice( m_type,
|
||||
buffer - m_datawindow.min.x * 12 - m_datawindow.min.y * ystep + 8,
|
||||
12, ystep, m_red->xSampling, m_red->ySampling, 0.0 ));
|
||||
xsample[2] = m_red->ySampling;
|
||||
}
|
||||
chromatorgb = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
frame.insert( "Y", Slice( m_type,
|
||||
buffer - m_datawindow.min.x * 12 - m_datawindow.min.y * ystep,
|
||||
12, ystep, m_green->xSampling, m_green->ySampling, 0.0 ));
|
||||
frame.insert( "Y", Slice( m_type,
|
||||
buffer - m_datawindow.min.x * 12 - m_datawindow.min.y * ystep + 4,
|
||||
12, ystep, m_green->xSampling, m_green->ySampling, 0.0 ));
|
||||
frame.insert( "Y", Slice( m_type,
|
||||
buffer - m_datawindow.min.x * 12 - m_datawindow.min.y * ystep + 8,
|
||||
12, ystep, m_green->xSampling, m_green->ySampling, 0.0 ));
|
||||
xsample[0] = m_green->ySampling;
|
||||
xsample[1] = m_green->ySampling;
|
||||
xsample[2] = m_green->ySampling;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
frame.insert( "Y", Slice( m_type,
|
||||
buffer - m_datawindow.min.x * 4 - m_datawindow.min.y * ystep,
|
||||
4, ystep, m_green->xSampling, m_green->ySampling, 0.0 ));
|
||||
xsample[0] = m_green->ySampling;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if( m_blue )
|
||||
{
|
||||
frame.insert( "B", Slice( m_type,
|
||||
buffer - m_datawindow.min.x * 12 - m_datawindow.min.y * ystep,
|
||||
12, ystep, m_blue->xSampling, m_blue->ySampling, 0.0 ));
|
||||
xsample[0] = m_blue->ySampling;
|
||||
}
|
||||
if( m_green )
|
||||
{
|
||||
frame.insert( "G", Slice( m_type,
|
||||
buffer - m_datawindow.min.x * 12 - m_datawindow.min.y * ystep + 4,
|
||||
12, ystep, m_green->xSampling, m_green->ySampling, 0.0 ));
|
||||
xsample[1] = m_green->ySampling;
|
||||
}
|
||||
if( m_red )
|
||||
{
|
||||
frame.insert( "R", Slice( m_type,
|
||||
buffer - m_datawindow.min.x * 12 - m_datawindow.min.y * ystep + 8,
|
||||
12, ystep, m_red->xSampling, m_red->ySampling, 0.0 ));
|
||||
xsample[2] = m_red->ySampling;
|
||||
}
|
||||
if(color == 0)
|
||||
{
|
||||
rgbtogray = true;
|
||||
justcopy = false;
|
||||
}
|
||||
}
|
||||
|
||||
m_file->setFrameBuffer( frame );
|
||||
if( justcopy )
|
||||
{
|
||||
m_file->readPixels( m_datawindow.min.y, m_datawindow.max.y );
|
||||
|
||||
if( color )
|
||||
{
|
||||
if( m_blue && (m_blue->xSampling != 1 || m_blue->ySampling != 1) )
|
||||
UpSample( data, 3, step / xstep, xsample[0], m_blue->ySampling );
|
||||
if( m_green && (m_green->xSampling != 1 || m_green->ySampling != 1) )
|
||||
UpSample( data + xstep, 3, step / xstep, xsample[1], m_green->ySampling );
|
||||
if( m_red && (m_red->xSampling != 1 || m_red->ySampling != 1) )
|
||||
UpSample( data + 2 * xstep, 3, step / xstep, xsample[2], m_red->ySampling );
|
||||
}
|
||||
else if( m_green && (m_green->xSampling != 1 || m_green->ySampling != 1) )
|
||||
UpSample( data, 1, step / xstep, xsample[0], m_green->ySampling );
|
||||
}
|
||||
else
|
||||
{
|
||||
uchar *out = data;
|
||||
int x, y;
|
||||
for( y = m_datawindow.min.y; y <= m_datawindow.max.y; y++ )
|
||||
{
|
||||
m_file->readPixels( y, y );
|
||||
|
||||
if( rgbtogray )
|
||||
{
|
||||
if( xsample[0] != 1 )
|
||||
UpSampleX( (float *)buffer, 3, xsample[0] );
|
||||
if( xsample[1] != 1 )
|
||||
UpSampleX( (float *)buffer + 4, 3, xsample[1] );
|
||||
if( xsample[2] != 1 )
|
||||
UpSampleX( (float *)buffer + 8, 3, xsample[2] );
|
||||
|
||||
RGBToGray( (float *)buffer, (float *)out );
|
||||
}
|
||||
else
|
||||
{
|
||||
if( xsample[0] != 1 )
|
||||
UpSampleX( (float *)buffer, 3, xsample[0] );
|
||||
if( xsample[1] != 1 )
|
||||
UpSampleX( (float *)(buffer + 4), 3, xsample[1] );
|
||||
if( xsample[2] != 1 )
|
||||
UpSampleX( (float *)(buffer + 8), 3, xsample[2] );
|
||||
|
||||
if( chromatorgb )
|
||||
ChromaToBGR( (float *)buffer, 1, step );
|
||||
|
||||
if( m_type == FLOAT )
|
||||
{
|
||||
float *fi = (float *)buffer;
|
||||
for( x = 0; x < m_width * 3; x++)
|
||||
{
|
||||
int t = cvRound(fi[x]*5);
|
||||
out[x] = CV_CAST_8U(t);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
uint *ui = (uint *)buffer;
|
||||
for( x = 0; x < m_width * 3; x++)
|
||||
{
|
||||
uint t = ui[x];
|
||||
out[x] = CV_CAST_8U(t);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
out += step;
|
||||
}
|
||||
if( color )
|
||||
{
|
||||
if( m_blue && (m_blue->xSampling != 1 || m_blue->ySampling != 1) )
|
||||
UpSampleY( data, 3, step / xstep, m_blue->ySampling );
|
||||
if( m_green && (m_green->xSampling != 1 || m_green->ySampling != 1) )
|
||||
UpSampleY( data + xstep, 3, step / xstep, m_green->ySampling );
|
||||
if( m_red && (m_red->xSampling != 1 || m_red->ySampling != 1) )
|
||||
UpSampleY( data + 2 * xstep, 3, step / xstep, m_red->ySampling );
|
||||
}
|
||||
else if( m_green && (m_green->xSampling != 1 || m_green->ySampling != 1) )
|
||||
UpSampleY( data, 1, step / xstep, m_green->ySampling );
|
||||
}
|
||||
|
||||
if( chromatorgb )
|
||||
ChromaToBGR( (float *)data, m_height, step / xstep );
|
||||
|
||||
Close();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
// on entry pixel values are stored packed in the upper left corner of the image
|
||||
// this functions expands them by duplication to cover the whole image
|
||||
*/
|
||||
void GrFmtExrReader::UpSample( uchar *data, int xstep, int ystep, int xsample, int ysample )
|
||||
{
|
||||
for( int y = (m_height - 1) / ysample, yre = m_height - ysample; y >= 0; y--, yre -= ysample )
|
||||
{
|
||||
for( int x = (m_width - 1) / xsample, xre = m_width - xsample; x >= 0; x--, xre -= xsample )
|
||||
{
|
||||
for( int i = 0; i < ysample; i++ )
|
||||
{
|
||||
for( int n = 0; n < xsample; n++ )
|
||||
{
|
||||
if( !m_native_depth )
|
||||
data[(yre + i) * ystep + (xre + n) * xstep] = data[y * ystep + x * xstep];
|
||||
else if( m_type == FLOAT )
|
||||
((float *)data)[(yre + i) * ystep + (xre + n) * xstep] = ((float *)data)[y * ystep + x * xstep];
|
||||
else
|
||||
((uint *)data)[(yre + i) * ystep + (xre + n) * xstep] = ((uint *)data)[y * ystep + x * xstep];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
// on entry pixel values are stored packed in the upper left corner of the image
|
||||
// this functions expands them by duplication to cover the whole image
|
||||
*/
|
||||
void GrFmtExrReader::UpSampleX( float *data, int xstep, int xsample )
|
||||
{
|
||||
for( int x = (m_width - 1) / xsample, xre = m_width - xsample; x >= 0; x--, xre -= xsample )
|
||||
{
|
||||
for( int n = 0; n < xsample; n++ )
|
||||
{
|
||||
if( m_type == FLOAT )
|
||||
((float *)data)[(xre + n) * xstep] = ((float *)data)[x * xstep];
|
||||
else
|
||||
((uint *)data)[(xre + n) * xstep] = ((uint *)data)[x * xstep];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
// on entry pixel values are stored packed in the upper left corner of the image
|
||||
// this functions expands them by duplication to cover the whole image
|
||||
*/
|
||||
void GrFmtExrReader::UpSampleY( uchar *data, int xstep, int ystep, int ysample )
|
||||
{
|
||||
for( int y = m_height - ysample, yre = m_height - ysample; y >= 0; y -= ysample, yre -= ysample )
|
||||
{
|
||||
for( int x = 0; x < m_width; x++ )
|
||||
{
|
||||
for( int i = 1; i < ysample; i++ )
|
||||
{
|
||||
if( !m_native_depth )
|
||||
data[(yre + i) * ystep + x * xstep] = data[y * ystep + x * xstep];
|
||||
else if( m_type == FLOAT )
|
||||
((float *)data)[(yre + i) * ystep + x * xstep] = ((float *)data)[y * ystep + x * xstep];
|
||||
else
|
||||
((uint *)data)[(yre + i) * ystep + x * xstep] = ((uint *)data)[y * ystep + x * xstep];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
// algorithm from ImfRgbaYca.cpp
|
||||
*/
|
||||
void GrFmtExrReader::ChromaToBGR( float *data, int numlines, int step )
|
||||
{
|
||||
int x, y, t;
|
||||
|
||||
for( y = 0; y < numlines; y++ )
|
||||
{
|
||||
for( x = 0; x < m_width; x++ )
|
||||
{
|
||||
double b, Y, r;
|
||||
if( !m_native_depth )
|
||||
{
|
||||
b = ((uchar *)data)[y * step + x * 3];
|
||||
Y = ((uchar *)data)[y * step + x * 3 + 1];
|
||||
r = ((uchar *)data)[y * step + x * 3 + 2];
|
||||
}
|
||||
else if( m_type == FLOAT )
|
||||
{
|
||||
b = data[y * step + x * 3];
|
||||
Y = data[y * step + x * 3 + 1];
|
||||
r = data[y * step + x * 3 + 2];
|
||||
}
|
||||
else
|
||||
{
|
||||
b = ((uint *)data)[y * step + x * 3];
|
||||
Y = ((uint *)data)[y * step + x * 3 + 1];
|
||||
r = ((uint *)data)[y * step + x * 3 + 2];
|
||||
}
|
||||
r = (r + 1) * Y;
|
||||
b = (b + 1) * Y;
|
||||
Y = (Y - b * m_chroma.blue[1] - r * m_chroma.red[1]) / m_chroma.green[1];
|
||||
|
||||
if( !m_native_depth )
|
||||
{
|
||||
int t = cvRound(b);
|
||||
((uchar *)data)[y * step + x * 3] = CV_CAST_8U(t);
|
||||
t = cvRound(Y);
|
||||
((uchar *)data)[y * step + x * 3 + 1] = CV_CAST_8U(t);
|
||||
t = cvRound(r);
|
||||
((uchar *)data)[y * step + x * 3 + 2] = CV_CAST_8U(t);
|
||||
}
|
||||
else if( m_type == FLOAT )
|
||||
{
|
||||
data[y * step + x * 3] = (float)b;
|
||||
data[y * step + x * 3 + 1] = (float)Y;
|
||||
data[y * step + x * 3 + 2] = (float)r;
|
||||
}
|
||||
else
|
||||
{
|
||||
int t = cvRound(b);
|
||||
((uint *)data)[y * step + x * 3] = (uint)MAX(t,0);
|
||||
t = cvRound(Y);
|
||||
((uint *)data)[y * step + x * 3 + 1] = (uint)MAX(t,0);
|
||||
t = cvRound(r);
|
||||
((uint *)data)[y * step + x * 3 + 2] = (uint)MAX(t,0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
// convert one row to gray
|
||||
*/
|
||||
void GrFmtExrReader::RGBToGray( float *in, float *out )
|
||||
{
|
||||
if( m_type == FLOAT )
|
||||
{
|
||||
if( m_native_depth )
|
||||
{
|
||||
for( int i = 0, n = 0; i < m_width; i++, n += 3 )
|
||||
out[i] = in[n] * m_chroma.blue[0] + in[n + 1] * m_chroma.green[0] + in[n + 2] * m_chroma.red[0];
|
||||
}
|
||||
else
|
||||
{
|
||||
uchar *o = (uchar *)out;
|
||||
for( int i = 0, n = 0; i < m_width; i++, n += 3 )
|
||||
o[i] = (uchar) (in[n] * m_chroma.blue[0] + in[n + 1] * m_chroma.green[0] + in[n + 2] * m_chroma.red[0]);
|
||||
}
|
||||
}
|
||||
else // UINT
|
||||
{
|
||||
if( m_native_depth )
|
||||
{
|
||||
uint *ui = (uint *)in;
|
||||
for( int i = 0; i < m_width * 3; i++ )
|
||||
ui[i] -= 0x80000000;
|
||||
int *si = (int *)in;
|
||||
for( int i = 0, n = 0; i < m_width; i++, n += 3 )
|
||||
((int *)out)[i] = int(si[n] * m_chroma.blue[0] + si[n + 1] * m_chroma.green[0] + si[n + 2] * m_chroma.red[0]);
|
||||
}
|
||||
else // how to best convert float to uchar?
|
||||
{
|
||||
uint *ui = (uint *)in;
|
||||
for( int i = 0, n = 0; i < m_width; i++, n += 3 )
|
||||
((uchar *)out)[i] = uchar((ui[n] * m_chroma.blue[0] + ui[n + 1] * m_chroma.green[0] + ui[n + 2] * m_chroma.red[0]) * (256.0 / 4294967296.0));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/////////////////////// GrFmtExrWriter ///////////////////
|
||||
|
||||
|
||||
GrFmtExrWriter::GrFmtExrWriter( const char* filename ) : GrFmtWriter( filename )
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
GrFmtExrWriter::~GrFmtExrWriter()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
bool GrFmtExrWriter::IsFormatSupported( int depth )
|
||||
{
|
||||
return depth == IPL_DEPTH_8U || depth == IPL_DEPTH_8S ||
|
||||
depth == IPL_DEPTH_16U || depth == IPL_DEPTH_16S ||
|
||||
depth == IPL_DEPTH_32S || depth == IPL_DEPTH_32F;
|
||||
// TODO: do (or should) we support 64f?
|
||||
}
|
||||
|
||||
|
||||
// TODO scale appropriately
|
||||
bool GrFmtExrWriter::WriteImage( const uchar* data, int step,
|
||||
int width, int height, int depth, int channels )
|
||||
{
|
||||
bool result = false;
|
||||
|
||||
Header header( width, height );
|
||||
PixelType type;
|
||||
bool issigned = depth < 0;
|
||||
bool isfloat = depth == IPL_DEPTH_32F || depth == IPL_DEPTH_64F;
|
||||
|
||||
if(depth == IPL_DEPTH_8U || depth == IPL_DEPTH_8S)
|
||||
type = HALF;
|
||||
else if(isfloat)
|
||||
type = FLOAT;
|
||||
else
|
||||
type = UINT;
|
||||
|
||||
depth &= 255;
|
||||
|
||||
if( channels == 3 )
|
||||
{
|
||||
header.channels().insert( "R", Channel( type ));
|
||||
header.channels().insert( "G", Channel( type ));
|
||||
header.channels().insert( "B", Channel( type ));
|
||||
//printf("bunt\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
header.channels().insert( "Y", Channel( type ));
|
||||
//printf("gray\n");
|
||||
}
|
||||
|
||||
OutputFile file( m_filename, header );
|
||||
|
||||
FrameBuffer frame;
|
||||
|
||||
char *buffer;
|
||||
int bufferstep;
|
||||
int size;
|
||||
if( type == FLOAT && depth == 32 )
|
||||
{
|
||||
buffer = (char *)const_cast<uchar *>(data);
|
||||
bufferstep = step;
|
||||
size = 4;
|
||||
}
|
||||
else if( depth > 16 || type == UINT )
|
||||
{
|
||||
buffer = (char *)new uint[width * channels];
|
||||
bufferstep = 0;
|
||||
size = 4;
|
||||
}
|
||||
else
|
||||
{
|
||||
buffer = (char *)new half[width * channels];
|
||||
bufferstep = 0;
|
||||
size = 2;
|
||||
}
|
||||
|
||||
//printf("depth %d %s\n", depth, types[type]);
|
||||
|
||||
if( channels == 3 )
|
||||
{
|
||||
frame.insert( "B", Slice( type, buffer, size * 3, bufferstep ));
|
||||
frame.insert( "G", Slice( type, buffer + size, size * 3, bufferstep ));
|
||||
frame.insert( "R", Slice( type, buffer + size * 2, size * 3, bufferstep ));
|
||||
}
|
||||
else
|
||||
frame.insert( "Y", Slice( type, buffer, size, bufferstep ));
|
||||
|
||||
file.setFrameBuffer( frame );
|
||||
|
||||
int offset = issigned ? 1 << (depth - 1) : 0;
|
||||
|
||||
result = true;
|
||||
if( type == FLOAT && depth == 32 )
|
||||
{
|
||||
try
|
||||
{
|
||||
file.writePixels( height );
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
result = false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// int scale = 1 << (32 - depth);
|
||||
// printf("scale %d\n", scale);
|
||||
for(int line = 0; line < height; line++)
|
||||
{
|
||||
if(type == UINT)
|
||||
{
|
||||
uint *buf = (uint *)buffer; // FIXME 64-bit problems
|
||||
|
||||
if( depth <= 8 )
|
||||
{
|
||||
for(int i = 0; i < width * channels; i++)
|
||||
buf[i] = data[i] + offset;
|
||||
}
|
||||
else if( depth <= 16 )
|
||||
{
|
||||
unsigned short *sd = (unsigned short *)data;
|
||||
for(int i = 0; i < width * channels; i++)
|
||||
buf[i] = sd[i] + offset;
|
||||
}
|
||||
else
|
||||
{
|
||||
int *sd = (int *)data; // FIXME 64-bit problems
|
||||
for(int i = 0; i < width * channels; i++)
|
||||
buf[i] = (uint) sd[i] + offset;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
half *buf = (half *)buffer;
|
||||
|
||||
if( depth <= 8 )
|
||||
{
|
||||
for(int i = 0; i < width * channels; i++)
|
||||
buf[i] = data[i];
|
||||
}
|
||||
else if( depth <= 16 )
|
||||
{
|
||||
unsigned short *sd = (unsigned short *)data;
|
||||
for(int i = 0; i < width * channels; i++)
|
||||
buf[i] = sd[i];
|
||||
}
|
||||
}
|
||||
try
|
||||
{
|
||||
file.writePixels( 1 );
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
result = false;
|
||||
break;
|
||||
}
|
||||
data += step;
|
||||
}
|
||||
delete buffer;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/* End of file. */
|
||||
@@ -0,0 +1,116 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// Intel License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000, Intel Corporation, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of Intel Corporation may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#ifndef _GRFMT_EXR_H_
|
||||
#define _GRFMT_EXR_H_
|
||||
|
||||
#ifdef HAVE_ILMIMF
|
||||
|
||||
#include <ImfChromaticities.h>
|
||||
#include <ImfInputFile.h>
|
||||
#include <ImfChannelList.h>
|
||||
#include <ImathBox.h>
|
||||
#include "grfmt_base.h"
|
||||
|
||||
using namespace Imf;
|
||||
using namespace Imath;
|
||||
|
||||
/* libpng version only */
|
||||
|
||||
class GrFmtExrReader : public GrFmtReader
|
||||
{
|
||||
public:
|
||||
|
||||
GrFmtExrReader( const char* filename );
|
||||
~GrFmtExrReader();
|
||||
|
||||
bool ReadData( uchar* data, int step, int color );
|
||||
bool ReadHeader();
|
||||
void Close();
|
||||
|
||||
protected:
|
||||
void UpSample( uchar *data, int xstep, int ystep, int xsample, int ysample );
|
||||
void UpSampleX( float *data, int xstep, int xsample );
|
||||
void UpSampleY( uchar *data, int xstep, int ystep, int ysample );
|
||||
void ChromaToBGR( float *data, int numlines, int step );
|
||||
void RGBToGray( float *in, float *out );
|
||||
|
||||
InputFile *m_file;
|
||||
PixelType m_type;
|
||||
Box2i m_datawindow;
|
||||
bool m_ischroma;
|
||||
const Channel *m_red;
|
||||
const Channel *m_green;
|
||||
const Channel *m_blue;
|
||||
Chromaticities m_chroma;
|
||||
};
|
||||
|
||||
|
||||
class GrFmtExrWriter : public GrFmtWriter
|
||||
{
|
||||
public:
|
||||
|
||||
GrFmtExrWriter( const char* filename );
|
||||
~GrFmtExrWriter();
|
||||
|
||||
bool IsFormatSupported( int depth );
|
||||
bool WriteImage( const uchar* data, int step,
|
||||
int width, int height, int depth, int channels );
|
||||
protected:
|
||||
};
|
||||
|
||||
|
||||
// Exr filter factory
|
||||
class GrFmtExr : public GrFmtFilterFactory
|
||||
{
|
||||
public:
|
||||
|
||||
GrFmtExr();
|
||||
~GrFmtExr();
|
||||
|
||||
GrFmtReader* NewReader( const char* filename );
|
||||
GrFmtWriter* NewWriter( const char* filename );
|
||||
// bool CheckSignature( const char* signature );
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
#endif/*_GRFMT_EXR_H_*/
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,214 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// Intel License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000, Intel Corporation, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of Intel Corporation may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#ifndef _GRFMT_JPEG_H_
|
||||
#define _GRFMT_JPEG_H_
|
||||
|
||||
#include "grfmt_base.h"
|
||||
#include "bitstrm.h"
|
||||
|
||||
#ifdef HAVE_JPEG
|
||||
|
||||
/* IJG-based version */
|
||||
|
||||
class GrFmtJpegReader : public GrFmtReader
|
||||
{
|
||||
public:
|
||||
|
||||
GrFmtJpegReader( const char* filename );
|
||||
~GrFmtJpegReader();
|
||||
|
||||
bool ReadData( uchar* data, int step, int color );
|
||||
bool ReadHeader();
|
||||
void Close();
|
||||
|
||||
protected:
|
||||
|
||||
void* m_cinfo; // pointer to IJG JPEG codec structure
|
||||
void* m_jerr; // pointer to error processing manager state
|
||||
FILE* m_f;
|
||||
};
|
||||
|
||||
|
||||
class GrFmtJpegWriter : public GrFmtWriter
|
||||
{
|
||||
public:
|
||||
|
||||
GrFmtJpegWriter( const char* filename );
|
||||
~GrFmtJpegWriter();
|
||||
|
||||
bool WriteImage( const uchar* data, int step,
|
||||
int width, int height, int depth, int channels );
|
||||
};
|
||||
|
||||
#else
|
||||
|
||||
/* hand-crafted implementation */
|
||||
|
||||
class RJpegBitStream : public RMBitStream
|
||||
{
|
||||
public:
|
||||
RMByteStream m_low_strm;
|
||||
|
||||
RJpegBitStream();
|
||||
~RJpegBitStream();
|
||||
|
||||
virtual bool Open( const char* filename );
|
||||
virtual void Close();
|
||||
|
||||
void Flush(); // flushes high-level bit stream
|
||||
void AlignOnByte();
|
||||
int FindMarker();
|
||||
|
||||
protected:
|
||||
virtual void ReadBlock();
|
||||
};
|
||||
|
||||
|
||||
//////////////////// JPEG reader /////////////////////
|
||||
|
||||
class GrFmtJpegReader : public GrFmtReader
|
||||
{
|
||||
public:
|
||||
|
||||
GrFmtJpegReader( const char* filename );
|
||||
~GrFmtJpegReader();
|
||||
|
||||
bool ReadData( uchar* data, int step, int color );
|
||||
bool ReadHeader();
|
||||
void Close();
|
||||
|
||||
protected:
|
||||
|
||||
int m_offset; // offset of first scan
|
||||
int m_version; // JFIF version
|
||||
int m_planes; // 3 (YCrCb) or 1 (Gray)
|
||||
int m_precision; // 8 or 12-bit per sample
|
||||
int m_type; // SOF type
|
||||
int m_MCUs; // MCUs in restart interval
|
||||
int m_ss, m_se, m_ah, m_al; // progressive JPEG parameters
|
||||
|
||||
// information about each component
|
||||
struct cmp_info
|
||||
{
|
||||
char h; // horizontal sampling factor
|
||||
char v; // vertical sampling factor
|
||||
char tq; // quantization table index
|
||||
char td, ta; // DC & AC huffman tables
|
||||
int dc_pred; // DC predictor
|
||||
};
|
||||
|
||||
cmp_info m_ci[3];
|
||||
|
||||
int m_tq[4][64];
|
||||
bool m_is_tq[4];
|
||||
|
||||
short* m_td[4];
|
||||
bool m_is_td[4];
|
||||
|
||||
short* m_ta[4];
|
||||
bool m_is_ta[4];
|
||||
|
||||
RJpegBitStream m_strm;
|
||||
|
||||
protected:
|
||||
|
||||
bool LoadQuantTables( int length );
|
||||
bool LoadHuffmanTables( int length );
|
||||
void ProcessScan( int* idx, int ns, uchar* data, int step, int color );
|
||||
void ResetDecoder();
|
||||
void GetBlock( int* block, int c );
|
||||
};
|
||||
|
||||
|
||||
//////////////////// JPEG-specific output bitstream ///////////////////////
|
||||
|
||||
class WJpegBitStream : public WMBitStream
|
||||
{
|
||||
public:
|
||||
WMByteStream m_low_strm;
|
||||
|
||||
WJpegBitStream();
|
||||
~WJpegBitStream();
|
||||
|
||||
virtual void Flush();
|
||||
virtual bool Open( const char* filename );
|
||||
virtual void Close();
|
||||
|
||||
protected:
|
||||
virtual void WriteBlock();
|
||||
};
|
||||
|
||||
|
||||
//////////////////// JPEG reader /////////////////////
|
||||
|
||||
class GrFmtJpegWriter : public GrFmtWriter
|
||||
{
|
||||
public:
|
||||
|
||||
GrFmtJpegWriter( const char* filename );
|
||||
~GrFmtJpegWriter();
|
||||
|
||||
bool WriteImage( const uchar* data, int step,
|
||||
int width, int height, int depth, int channels );
|
||||
|
||||
protected:
|
||||
|
||||
WJpegBitStream m_strm;
|
||||
};
|
||||
|
||||
#endif /* HAVE_JPEG */
|
||||
|
||||
|
||||
// JPEG filter factory
|
||||
class GrFmtJpeg : public GrFmtFilterFactory
|
||||
{
|
||||
public:
|
||||
|
||||
GrFmtJpeg();
|
||||
~GrFmtJpeg();
|
||||
|
||||
GrFmtReader* NewReader( const char* filename );
|
||||
GrFmtWriter* NewWriter( const char* filename );
|
||||
};
|
||||
|
||||
|
||||
#endif/*_GRFMT_JPEG_H_*/
|
||||
@@ -0,0 +1,502 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// Intel License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000, Intel Corporation, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of Intel Corporation may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "_highgui.h"
|
||||
|
||||
#ifdef HAVE_JASPER
|
||||
|
||||
#include "grfmt_jpeg2000.h"
|
||||
|
||||
// JPEG-2000 Filter Factory
|
||||
GrFmtJpeg2000::GrFmtJpeg2000()
|
||||
{
|
||||
m_sign_len = 12;
|
||||
m_signature = "\x00\x00\x00\x0cjP \r\n\x87\n";
|
||||
m_description = "JPEG-2000 files (*.jp2)";
|
||||
jas_init();
|
||||
}
|
||||
|
||||
|
||||
GrFmtJpeg2000::~GrFmtJpeg2000()
|
||||
{
|
||||
jas_cleanup();
|
||||
}
|
||||
|
||||
|
||||
GrFmtReader* GrFmtJpeg2000::NewReader( const char* filename )
|
||||
{
|
||||
return new GrFmtJpeg2000Reader( filename );
|
||||
}
|
||||
|
||||
|
||||
GrFmtWriter* GrFmtJpeg2000::NewWriter( const char* filename )
|
||||
{
|
||||
return new GrFmtJpeg2000Writer( filename );
|
||||
}
|
||||
|
||||
|
||||
/////////////////////// GrFmtJpeg2000Reader ///////////////////
|
||||
|
||||
GrFmtJpeg2000Reader::GrFmtJpeg2000Reader( const char* filename ) : GrFmtReader( filename )
|
||||
{
|
||||
m_stream = 0;
|
||||
m_image = 0;
|
||||
}
|
||||
|
||||
|
||||
GrFmtJpeg2000Reader::~GrFmtJpeg2000Reader()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void GrFmtJpeg2000Reader::Close()
|
||||
{
|
||||
if( m_stream )
|
||||
{
|
||||
jas_stream_close( m_stream );
|
||||
m_stream = 0;
|
||||
}
|
||||
|
||||
if( m_image )
|
||||
{
|
||||
jas_image_destroy( m_image );
|
||||
m_image = 0;
|
||||
}
|
||||
GrFmtReader::Close();
|
||||
}
|
||||
|
||||
|
||||
bool GrFmtJpeg2000Reader::ReadHeader()
|
||||
{
|
||||
bool result = false;
|
||||
|
||||
Close();
|
||||
|
||||
m_stream = jas_stream_fopen( m_filename, "rb" );
|
||||
if( m_stream )
|
||||
{
|
||||
m_image = jas_image_decode( m_stream, -1, 0 );
|
||||
if( m_image ) {
|
||||
m_width = jas_image_width( m_image );
|
||||
m_height = jas_image_height( m_image );
|
||||
|
||||
int cntcmpts = 0; // count the known components
|
||||
int numcmpts = jas_image_numcmpts( m_image );
|
||||
for( int i = 0; i < numcmpts; i++ )
|
||||
{
|
||||
int depth = jas_image_cmptprec( m_image, i );
|
||||
if( depth > m_bit_depth )
|
||||
m_bit_depth = depth;
|
||||
if( m_bit_depth > 8 )
|
||||
m_bit_depth = 16;
|
||||
|
||||
if( jas_image_cmpttype( m_image, i ) > 2 )
|
||||
continue;
|
||||
cntcmpts++;
|
||||
}
|
||||
|
||||
if( cntcmpts )
|
||||
{
|
||||
m_iscolor = (cntcmpts > 1);
|
||||
|
||||
result = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if( !result )
|
||||
Close();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
bool GrFmtJpeg2000Reader::ReadData( uchar* data, int step, int color )
|
||||
{
|
||||
bool result = false;
|
||||
|
||||
color = color > 0 || ( m_iscolor && color < 0 );
|
||||
|
||||
if( m_stream && m_image )
|
||||
{
|
||||
bool convert;
|
||||
int colorspace;
|
||||
if( color )
|
||||
{
|
||||
convert = (jas_image_clrspc( m_image ) != JAS_CLRSPC_SRGB);
|
||||
colorspace = JAS_CLRSPC_SRGB;
|
||||
}
|
||||
else
|
||||
{
|
||||
convert = (jas_clrspc_fam( jas_image_clrspc( m_image ) ) != JAS_CLRSPC_FAM_GRAY);
|
||||
colorspace = JAS_CLRSPC_SGRAY; // TODO GENGRAY or SGRAY?
|
||||
}
|
||||
|
||||
// convert to the desired colorspace
|
||||
if( convert )
|
||||
{
|
||||
jas_cmprof_t *clrprof = jas_cmprof_createfromclrspc( colorspace );
|
||||
if( clrprof )
|
||||
{
|
||||
jas_image_t *img = jas_image_chclrspc( m_image, clrprof, JAS_CMXFORM_INTENT_RELCLR );
|
||||
if( img )
|
||||
{
|
||||
jas_image_destroy( m_image );
|
||||
m_image = img;
|
||||
result = true;
|
||||
}
|
||||
else
|
||||
fprintf(stderr, "JPEG 2000 LOADER ERROR: cannot convert colorspace\n");
|
||||
jas_cmprof_destroy( clrprof );
|
||||
}
|
||||
else
|
||||
fprintf(stderr, "JPEG 2000 LOADER ERROR: unable to create colorspace\n");
|
||||
}
|
||||
else
|
||||
result = true;
|
||||
|
||||
if( result )
|
||||
{
|
||||
int ncmpts;
|
||||
int cmptlut[3];
|
||||
if( color )
|
||||
{
|
||||
cmptlut[0] = jas_image_getcmptbytype( m_image, JAS_IMAGE_CT_RGB_B );
|
||||
cmptlut[1] = jas_image_getcmptbytype( m_image, JAS_IMAGE_CT_RGB_G );
|
||||
cmptlut[2] = jas_image_getcmptbytype( m_image, JAS_IMAGE_CT_RGB_R );
|
||||
if( cmptlut[0] < 0 || cmptlut[1] < 0 || cmptlut[0] < 0 )
|
||||
result = false;
|
||||
ncmpts = 3;
|
||||
}
|
||||
else
|
||||
{
|
||||
cmptlut[0] = jas_image_getcmptbytype( m_image, JAS_IMAGE_CT_GRAY_Y );
|
||||
if( cmptlut[0] < 0 )
|
||||
result = false;
|
||||
ncmpts = 1;
|
||||
}
|
||||
|
||||
if( result )
|
||||
{
|
||||
for( int i = 0; i < ncmpts; i++ )
|
||||
{
|
||||
int maxval = 1 << jas_image_cmptprec( m_image, cmptlut[i] );
|
||||
int offset = jas_image_cmptsgnd( m_image, cmptlut[i] ) ? maxval / 2 : 0;
|
||||
|
||||
int yend = jas_image_cmptbry( m_image, cmptlut[i] );
|
||||
int ystep = jas_image_cmptvstep( m_image, cmptlut[i] );
|
||||
int xend = jas_image_cmptbrx( m_image, cmptlut[i] );
|
||||
int xstep = jas_image_cmpthstep( m_image, cmptlut[i] );
|
||||
|
||||
jas_matrix_t *buffer = jas_matrix_create( yend / ystep, xend / xstep );
|
||||
if( buffer )
|
||||
{
|
||||
if( !jas_image_readcmpt( m_image, cmptlut[i], 0, 0, xend / xstep, yend / ystep, buffer ))
|
||||
{
|
||||
if( m_bit_depth == 8 || !m_native_depth )
|
||||
result = ReadComponent8u( data + i, buffer, step, cmptlut[i], maxval, offset, ncmpts );
|
||||
else
|
||||
result = ReadComponent16u( ((unsigned short *)data) + i, buffer, step / 2, cmptlut[i], maxval, offset, ncmpts );
|
||||
if( !result )
|
||||
{
|
||||
i = ncmpts;
|
||||
result = false;
|
||||
}
|
||||
}
|
||||
jas_matrix_destroy( buffer );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
fprintf(stderr, "JPEG2000 LOADER ERROR: colorspace conversion failed\n" );
|
||||
}
|
||||
|
||||
Close();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
bool GrFmtJpeg2000Reader::ReadComponent8u( uchar *data, jas_matrix_t *buffer,
|
||||
int step, int cmpt,
|
||||
int maxval, int offset, int ncmpts )
|
||||
{
|
||||
int xstart = jas_image_cmpttlx( m_image, cmpt );
|
||||
int xend = jas_image_cmptbrx( m_image, cmpt );
|
||||
int xstep = jas_image_cmpthstep( m_image, cmpt );
|
||||
int xoffset = jas_image_tlx( m_image );
|
||||
int ystart = jas_image_cmpttly( m_image, cmpt );
|
||||
int yend = jas_image_cmptbry( m_image, cmpt );
|
||||
int ystep = jas_image_cmptvstep( m_image, cmpt );
|
||||
int yoffset = jas_image_tly( m_image );
|
||||
int x, y, x1, y1, j;
|
||||
int rshift = cvRound(log(maxval/256.)/log(2.));
|
||||
int lshift = MAX(0, -rshift);
|
||||
rshift = MAX(0, rshift);
|
||||
int delta = (rshift > 0 ? 1 << (rshift - 1) : 0) + offset;
|
||||
|
||||
for( y = 0; y < yend - ystart; )
|
||||
{
|
||||
jas_seqent_t* pix_row = &jas_matrix_get( buffer, y / ystep, 0 );
|
||||
uchar* dst = data + (y - yoffset) * step - xoffset;
|
||||
|
||||
if( xstep == 1 )
|
||||
{
|
||||
if( maxval == 256 && offset == 0 )
|
||||
for( x = 0; x < xend - xstart; x++ )
|
||||
{
|
||||
int pix = pix_row[x];
|
||||
dst[x*ncmpts] = CV_CAST_8U(pix);
|
||||
}
|
||||
else
|
||||
for( x = 0; x < xend - xstart; x++ )
|
||||
{
|
||||
int pix = ((pix_row[x] + delta) >> rshift) << lshift;
|
||||
dst[x*ncmpts] = CV_CAST_8U(pix);
|
||||
}
|
||||
}
|
||||
else if( xstep == 2 && offset == 0 )
|
||||
for( x = 0, j = 0; x < xend - xstart; x += 2, j++ )
|
||||
{
|
||||
int pix = ((pix_row[j] + delta) >> rshift) << lshift;
|
||||
dst[x*ncmpts] = dst[(x+1)*ncmpts] = CV_CAST_8U(pix);
|
||||
}
|
||||
else
|
||||
for( x = 0, j = 0; x < xend - xstart; j++ )
|
||||
{
|
||||
int pix = ((pix_row[j] + delta) >> rshift) << lshift;
|
||||
pix = CV_CAST_8U(pix);
|
||||
for( x1 = x + xstep; x < x1; x++ )
|
||||
dst[x*ncmpts] = (uchar)pix;
|
||||
}
|
||||
y1 = y + ystep;
|
||||
for( ++y; y < y1; y++, dst += step )
|
||||
for( x = 0; x < xend - xstart; x++ )
|
||||
dst[x*ncmpts + step] = dst[x*ncmpts];
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool GrFmtJpeg2000Reader::ReadComponent16u( unsigned short *data, jas_matrix_t *buffer,
|
||||
int step, int cmpt,
|
||||
int maxval, int offset, int ncmpts )
|
||||
{
|
||||
int xstart = jas_image_cmpttlx( m_image, cmpt );
|
||||
int xend = jas_image_cmptbrx( m_image, cmpt );
|
||||
int xstep = jas_image_cmpthstep( m_image, cmpt );
|
||||
int xoffset = jas_image_tlx( m_image );
|
||||
int ystart = jas_image_cmpttly( m_image, cmpt );
|
||||
int yend = jas_image_cmptbry( m_image, cmpt );
|
||||
int ystep = jas_image_cmptvstep( m_image, cmpt );
|
||||
int yoffset = jas_image_tly( m_image );
|
||||
int x, y, x1, y1, j;
|
||||
int rshift = cvRound(log(maxval/65536.)/log(2.));
|
||||
int lshift = MAX(0, -rshift);
|
||||
rshift = MAX(0, rshift);
|
||||
int delta = (rshift > 0 ? 1 << (rshift - 1) : 0) + offset;
|
||||
|
||||
for( y = 0; y < yend - ystart; )
|
||||
{
|
||||
jas_seqent_t* pix_row = &jas_matrix_get( buffer, y / ystep, 0 );
|
||||
ushort* dst = data + (y - yoffset) * step - xoffset;
|
||||
|
||||
if( xstep == 1 )
|
||||
{
|
||||
if( maxval == 65536 && offset == 0 )
|
||||
for( x = 0; x < xend - xstart; x++ )
|
||||
{
|
||||
int pix = pix_row[x];
|
||||
dst[x*ncmpts] = CV_CAST_16U(pix);
|
||||
}
|
||||
else
|
||||
for( x = 0; x < xend - xstart; x++ )
|
||||
{
|
||||
int pix = ((pix_row[x] + delta) >> rshift) << lshift;
|
||||
dst[x*ncmpts] = CV_CAST_16U(pix);
|
||||
}
|
||||
}
|
||||
else if( xstep == 2 && offset == 0 )
|
||||
for( x = 0, j = 0; x < xend - xstart; x += 2, j++ )
|
||||
{
|
||||
int pix = ((pix_row[j] + delta) >> rshift) << lshift;
|
||||
dst[x*ncmpts] = dst[(x+1)*ncmpts] = CV_CAST_16U(pix);
|
||||
}
|
||||
else
|
||||
for( x = 0, j = 0; x < xend - xstart; j++ )
|
||||
{
|
||||
int pix = ((pix_row[j] + delta) >> rshift) << lshift;
|
||||
pix = CV_CAST_16U(pix);
|
||||
for( x1 = x + xstep; x < x1; x++ )
|
||||
dst[x*ncmpts] = (ushort)pix;
|
||||
}
|
||||
y1 = y + ystep;
|
||||
for( ++y; y < y1; y++, dst += step )
|
||||
for( x = 0; x < xend - xstart; x++ )
|
||||
dst[x*ncmpts + step] = dst[x*ncmpts];
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/////////////////////// GrFmtJpeg2000Writer ///////////////////
|
||||
|
||||
|
||||
GrFmtJpeg2000Writer::GrFmtJpeg2000Writer( const char* filename ) : GrFmtWriter( filename )
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
GrFmtJpeg2000Writer::~GrFmtJpeg2000Writer()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
bool GrFmtJpeg2000Writer::IsFormatSupported( int depth )
|
||||
{
|
||||
return depth == IPL_DEPTH_8U || depth == IPL_DEPTH_16U;
|
||||
}
|
||||
|
||||
|
||||
bool GrFmtJpeg2000Writer::WriteImage( const uchar* data, int step,
|
||||
int width, int height, int depth, int channels )
|
||||
{
|
||||
if( channels > 3 || channels < 1 )
|
||||
return false;
|
||||
|
||||
jas_image_cmptparm_t component_info[3];
|
||||
for( int i = 0; i < channels; i++ )
|
||||
{
|
||||
component_info[i].tlx = 0;
|
||||
component_info[i].tly = 0;
|
||||
component_info[i].hstep = 1;
|
||||
component_info[i].vstep = 1;
|
||||
component_info[i].width = width;
|
||||
component_info[i].height = height;
|
||||
component_info[i].prec = depth;
|
||||
component_info[i].sgnd = 0;
|
||||
}
|
||||
jas_image_t *img = jas_image_create( channels, component_info, (channels == 1) ? JAS_CLRSPC_SGRAY : JAS_CLRSPC_SRGB );
|
||||
if( !img )
|
||||
return false;
|
||||
|
||||
if(channels == 1)
|
||||
jas_image_setcmpttype( img, 0, JAS_IMAGE_CT_GRAY_Y );
|
||||
else
|
||||
{
|
||||
jas_image_setcmpttype( img, 0, JAS_IMAGE_CT_RGB_B );
|
||||
jas_image_setcmpttype( img, 1, JAS_IMAGE_CT_RGB_G );
|
||||
jas_image_setcmpttype( img, 2, JAS_IMAGE_CT_RGB_R );
|
||||
}
|
||||
|
||||
bool result;
|
||||
if( depth == 8 )
|
||||
result = WriteComponent8u( img, data, step, channels, width, height );
|
||||
else
|
||||
result = WriteComponent16u( img, (const unsigned short *)data, step / 2, channels, width, height );
|
||||
if( result )
|
||||
{
|
||||
jas_stream_t *stream = jas_stream_fopen( m_filename, "wb" );
|
||||
if( stream )
|
||||
{
|
||||
result = !jas_image_encode( img, stream, jas_image_strtofmt( "jp2" ), "" );
|
||||
|
||||
jas_stream_close( stream );
|
||||
}
|
||||
|
||||
}
|
||||
jas_image_destroy( img );
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
bool GrFmtJpeg2000Writer::WriteComponent8u( jas_image_t *img, const uchar *data,
|
||||
int step, int ncmpts, int w, int h )
|
||||
{
|
||||
jas_matrix_t *row = jas_matrix_create( 1, w );
|
||||
if(!row)
|
||||
return false;
|
||||
|
||||
for( int y = 0; y < h; y++, data += step )
|
||||
{
|
||||
for( int i = 0; i < ncmpts; i++ )
|
||||
{
|
||||
for( int x = 0; x < w; x++)
|
||||
jas_matrix_setv( row, x, data[x * ncmpts + i] );
|
||||
jas_image_writecmpt( img, i, 0, y, w, 1, row );
|
||||
}
|
||||
}
|
||||
|
||||
jas_matrix_destroy( row );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool GrFmtJpeg2000Writer::WriteComponent16u( jas_image_t *img, const unsigned short *data,
|
||||
int step, int ncmpts, int w, int h )
|
||||
{
|
||||
jas_matrix_t *row = jas_matrix_create( 1, w );
|
||||
if(!row)
|
||||
return false;
|
||||
|
||||
for( int y = 0; y < h; y++, data += step )
|
||||
{
|
||||
for( int i = 0; i < ncmpts; i++ )
|
||||
{
|
||||
for( int x = 0; x < w; x++)
|
||||
jas_matrix_setv( row, x, data[x * ncmpts + i] );
|
||||
jas_image_writecmpt( img, i, 0, y, w, 1, row );
|
||||
}
|
||||
}
|
||||
|
||||
jas_matrix_destroy( row );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/* End of file. */
|
||||
@@ -0,0 +1,115 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// Intel License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000, Intel Corporation, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of Intel Corporation may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#ifndef _GRFMT_JASPER_H_
|
||||
#define _GRFMT_JASPER_H_
|
||||
|
||||
#ifdef HAVE_JASPER
|
||||
|
||||
#ifdef WIN32
|
||||
#define JAS_WIN_MSVC_BUILD 1
|
||||
#endif
|
||||
|
||||
#include <jasper/jasper.h>
|
||||
// FIXME bad hack
|
||||
#undef uchar
|
||||
#undef ulong
|
||||
#include "grfmt_base.h"
|
||||
|
||||
|
||||
/* libpng version only */
|
||||
|
||||
class GrFmtJpeg2000Reader : public GrFmtReader
|
||||
{
|
||||
public:
|
||||
|
||||
GrFmtJpeg2000Reader( const char* filename );
|
||||
~GrFmtJpeg2000Reader();
|
||||
|
||||
bool CheckFormat( const char* signature );
|
||||
bool ReadData( uchar* data, int step, int color );
|
||||
bool ReadHeader();
|
||||
void Close();
|
||||
|
||||
protected:
|
||||
bool ReadComponent8u( uchar *data, jas_matrix_t *buffer, int step, int cmpt,
|
||||
int maxval, int offset, int ncmpts );
|
||||
bool ReadComponent16u( unsigned short *data, jas_matrix_t *buffer, int step, int cmpt,
|
||||
int maxval, int offset, int ncmpts );
|
||||
|
||||
jas_stream_t *m_stream;
|
||||
jas_image_t *m_image;
|
||||
};
|
||||
|
||||
|
||||
class GrFmtJpeg2000Writer : public GrFmtWriter
|
||||
{
|
||||
public:
|
||||
|
||||
GrFmtJpeg2000Writer( const char* filename );
|
||||
~GrFmtJpeg2000Writer();
|
||||
|
||||
bool IsFormatSupported( int depth );
|
||||
bool WriteImage( const uchar* data, int step,
|
||||
int width, int height, int depth, int channels );
|
||||
protected:
|
||||
bool WriteComponent8u( jas_image_t *img, const uchar *data,
|
||||
int step, int ncmpts, int w, int h );
|
||||
bool WriteComponent16u( jas_image_t *img, const unsigned short *data,
|
||||
int step, int ncmpts, int w, int h );
|
||||
};
|
||||
|
||||
|
||||
// PNG filter factory
|
||||
class GrFmtJpeg2000 : public GrFmtFilterFactory
|
||||
{
|
||||
public:
|
||||
|
||||
GrFmtJpeg2000();
|
||||
~GrFmtJpeg2000();
|
||||
|
||||
GrFmtReader* NewReader( const char* filename );
|
||||
GrFmtWriter* NewWriter( const char* filename );
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
#endif/*_GRFMT_JASPER_H_*/
|
||||
@@ -0,0 +1,333 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// Intel License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000, Intel Corporation, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of Intel Corporation may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "_highgui.h"
|
||||
|
||||
#ifdef HAVE_PNG
|
||||
|
||||
/****************************************************************************************\
|
||||
This part of the file implements PNG codec on base of libpng library,
|
||||
in particular, this code is based on example.c from libpng
|
||||
(see otherlibs/_graphics/readme.txt for copyright notice)
|
||||
and png2bmp sample from libpng distribution (Copyright (C) 1999-2001 MIYASAKA Masaru)
|
||||
\****************************************************************************************/
|
||||
|
||||
#if defined WIN32 || defined HAVE_PNG_H
|
||||
#include <png.h>
|
||||
#else
|
||||
#include <libpng/png.h>
|
||||
#endif
|
||||
#include "grfmt_png.h"
|
||||
|
||||
// PNG Filter Factory
|
||||
GrFmtPng::GrFmtPng()
|
||||
{
|
||||
m_sign_len = 8;
|
||||
m_signature = "\x89\x50\x4e\x47\xd\xa\x1a\xa";
|
||||
m_description = "Portable Network Graphics files (*.png)";
|
||||
}
|
||||
|
||||
|
||||
GrFmtPng::~GrFmtPng()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
GrFmtReader* GrFmtPng::NewReader( const char* filename )
|
||||
{
|
||||
return new GrFmtPngReader( filename );
|
||||
}
|
||||
|
||||
|
||||
GrFmtWriter* GrFmtPng::NewWriter( const char* filename )
|
||||
{
|
||||
return new GrFmtPngWriter( filename );
|
||||
}
|
||||
|
||||
|
||||
bool GrFmtPng::CheckSignature( const char* signature )
|
||||
{
|
||||
return png_check_sig( (uchar*)signature, m_sign_len ) != 0;
|
||||
}
|
||||
|
||||
/////////////////////// GrFmtPngReader ///////////////////
|
||||
|
||||
GrFmtPngReader::GrFmtPngReader( const char* filename ) : GrFmtReader( filename )
|
||||
{
|
||||
m_color_type = m_bit_depth = 0;
|
||||
m_png_ptr = 0;
|
||||
m_info_ptr = m_end_info = 0;
|
||||
m_f = 0;
|
||||
}
|
||||
|
||||
|
||||
GrFmtPngReader::~GrFmtPngReader()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void GrFmtPngReader::Close()
|
||||
{
|
||||
if( m_f )
|
||||
{
|
||||
fclose( m_f );
|
||||
m_f = 0;
|
||||
}
|
||||
|
||||
if( m_png_ptr )
|
||||
{
|
||||
png_structp png_ptr = (png_structp)m_png_ptr;
|
||||
png_infop info_ptr = (png_infop)m_info_ptr;
|
||||
png_infop end_info = (png_infop)m_end_info;
|
||||
png_destroy_read_struct( &png_ptr, &info_ptr, &end_info );
|
||||
m_png_ptr = m_info_ptr = m_end_info = 0;
|
||||
}
|
||||
GrFmtReader::Close();
|
||||
}
|
||||
|
||||
|
||||
bool GrFmtPngReader::ReadHeader()
|
||||
{
|
||||
bool result = false;
|
||||
|
||||
Close();
|
||||
|
||||
png_structp png_ptr = png_create_read_struct( PNG_LIBPNG_VER_STRING, 0, 0, 0 );
|
||||
|
||||
if( png_ptr )
|
||||
{
|
||||
png_infop info_ptr = png_create_info_struct( png_ptr );
|
||||
png_infop end_info = png_create_info_struct( png_ptr );
|
||||
|
||||
m_png_ptr = png_ptr;
|
||||
m_info_ptr = info_ptr;
|
||||
m_end_info = end_info;
|
||||
|
||||
if( info_ptr && end_info )
|
||||
{
|
||||
if( setjmp( png_ptr->jmpbuf ) == 0 )
|
||||
{
|
||||
m_f = fopen( m_filename, "rb" );
|
||||
if( m_f )
|
||||
{
|
||||
png_uint_32 width, height;
|
||||
int bit_depth, color_type;
|
||||
|
||||
png_init_io( png_ptr, m_f );
|
||||
png_read_info( png_ptr, info_ptr );
|
||||
|
||||
png_get_IHDR( png_ptr, info_ptr, &width, &height,
|
||||
&bit_depth, &color_type, 0, 0, 0 );
|
||||
|
||||
m_iscolor = color_type == PNG_COLOR_TYPE_RGB ||
|
||||
color_type == PNG_COLOR_TYPE_RGB_ALPHA ||
|
||||
color_type == PNG_COLOR_TYPE_PALETTE;
|
||||
|
||||
m_width = (int)width;
|
||||
m_height = (int)height;
|
||||
m_color_type = color_type;
|
||||
m_bit_depth = bit_depth;
|
||||
|
||||
result = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if( !result )
|
||||
Close();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
bool GrFmtPngReader::ReadData( uchar* data, int step, int color )
|
||||
{
|
||||
bool result = false;
|
||||
uchar** buffer = 0;
|
||||
|
||||
color = color > 0 || ( m_iscolor && color < 0 );
|
||||
|
||||
if( m_png_ptr && m_info_ptr && m_end_info && m_width && m_height )
|
||||
{
|
||||
png_structp png_ptr = (png_structp)m_png_ptr;
|
||||
png_infop info_ptr = (png_infop)m_info_ptr;
|
||||
png_infop end_info = (png_infop)m_end_info;
|
||||
|
||||
if( setjmp(png_ptr->jmpbuf) == 0 )
|
||||
{
|
||||
int y;
|
||||
|
||||
if( m_bit_depth > 8 && !m_native_depth )
|
||||
png_set_strip_16( png_ptr );
|
||||
else if( !isBigEndian() )
|
||||
png_set_swap( png_ptr );
|
||||
|
||||
/* observation: png_read_image() writes 400 bytes beyond
|
||||
* end of data when reading a 400x118 color png
|
||||
* "mpplus_sand.png". OpenCV crashes even with demo
|
||||
* programs. Looking at the loaded image I'd say we get 4
|
||||
* bytes per pixel instead of 3 bytes per pixel. Test
|
||||
* indicate that it is a good idea to always ask for
|
||||
* stripping alpha.. 18.11.2004 Axel Walthelm
|
||||
*/
|
||||
png_set_strip_alpha( png_ptr );
|
||||
|
||||
if( m_color_type == PNG_COLOR_TYPE_PALETTE )
|
||||
png_set_palette_to_rgb( png_ptr );
|
||||
|
||||
if( m_color_type == PNG_COLOR_TYPE_GRAY && m_bit_depth < 8 )
|
||||
png_set_gray_1_2_4_to_8( png_ptr );
|
||||
|
||||
if( m_iscolor && color )
|
||||
png_set_bgr( png_ptr ); // convert RGB to BGR
|
||||
else if( color )
|
||||
png_set_gray_to_rgb( png_ptr ); // Gray->RGB
|
||||
else
|
||||
png_set_rgb_to_gray( png_ptr, 1, -1, -1 ); // RGB->Gray
|
||||
|
||||
png_read_update_info( png_ptr, info_ptr );
|
||||
|
||||
buffer = new uchar*[m_height];
|
||||
|
||||
for( y = 0; y < m_height; y++ )
|
||||
buffer[y] = data + y*step;
|
||||
|
||||
png_read_image( png_ptr, buffer );
|
||||
png_read_end( png_ptr, end_info );
|
||||
|
||||
result = true;
|
||||
}
|
||||
}
|
||||
|
||||
Close();
|
||||
delete[] buffer;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/////////////////////// GrFmtPngWriter ///////////////////
|
||||
|
||||
|
||||
GrFmtPngWriter::GrFmtPngWriter( const char* filename ) : GrFmtWriter( filename )
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
GrFmtPngWriter::~GrFmtPngWriter()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
bool GrFmtPngWriter::IsFormatSupported( int depth )
|
||||
{
|
||||
return depth == IPL_DEPTH_8U || depth == IPL_DEPTH_16U;
|
||||
}
|
||||
|
||||
bool GrFmtPngWriter::WriteImage( const uchar* data, int step,
|
||||
int width, int height, int depth, int channels )
|
||||
{
|
||||
png_structp png_ptr = png_create_write_struct( PNG_LIBPNG_VER_STRING, 0, 0, 0 );
|
||||
png_infop info_ptr = 0;
|
||||
FILE* f = 0;
|
||||
uchar** buffer = 0;
|
||||
int y;
|
||||
bool result = false;
|
||||
|
||||
if( depth != IPL_DEPTH_8U && depth != IPL_DEPTH_16U )
|
||||
return false;
|
||||
|
||||
if( png_ptr )
|
||||
{
|
||||
info_ptr = png_create_info_struct( png_ptr );
|
||||
|
||||
if( info_ptr )
|
||||
{
|
||||
if( setjmp( png_ptr->jmpbuf ) == 0 )
|
||||
{
|
||||
f = fopen( m_filename, "wb" );
|
||||
|
||||
if( f )
|
||||
{
|
||||
png_init_io( png_ptr, f );
|
||||
|
||||
png_set_compression_mem_level( png_ptr, MAX_MEM_LEVEL );
|
||||
|
||||
png_set_IHDR( png_ptr, info_ptr, width, height, depth,
|
||||
channels == 1 ? PNG_COLOR_TYPE_GRAY :
|
||||
channels == 3 ? PNG_COLOR_TYPE_RGB : PNG_COLOR_TYPE_RGBA,
|
||||
PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_DEFAULT,
|
||||
PNG_FILTER_TYPE_DEFAULT );
|
||||
|
||||
png_write_info( png_ptr, info_ptr );
|
||||
|
||||
png_set_bgr( png_ptr );
|
||||
if( !isBigEndian() )
|
||||
png_set_swap( png_ptr );
|
||||
|
||||
buffer = new uchar*[height];
|
||||
for( y = 0; y < height; y++ )
|
||||
buffer[y] = (uchar*)(data + y*step);
|
||||
|
||||
png_write_image( png_ptr, buffer );
|
||||
png_write_end( png_ptr, info_ptr );
|
||||
|
||||
delete[] buffer;
|
||||
|
||||
result = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
png_destroy_write_struct( &png_ptr, &info_ptr );
|
||||
|
||||
if(f) fclose( f );
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/* End of file. */
|
||||
|
||||
|
||||
@@ -0,0 +1,103 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// Intel License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000, Intel Corporation, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of Intel Corporation may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#ifndef _GRFMT_PNG_H_
|
||||
#define _GRFMT_PNG_H_
|
||||
|
||||
#ifdef HAVE_PNG
|
||||
|
||||
#include "grfmt_base.h"
|
||||
#include "bitstrm.h"
|
||||
|
||||
/* libpng version only */
|
||||
|
||||
class GrFmtPngReader : public GrFmtReader
|
||||
{
|
||||
public:
|
||||
|
||||
GrFmtPngReader( const char* filename );
|
||||
~GrFmtPngReader();
|
||||
|
||||
bool CheckFormat( const char* signature );
|
||||
bool ReadData( uchar* data, int step, int color );
|
||||
bool ReadHeader();
|
||||
void Close();
|
||||
|
||||
protected:
|
||||
|
||||
void* m_png_ptr; // pointer to decompression structure
|
||||
void* m_info_ptr; // pointer to image information structure
|
||||
void* m_end_info; // pointer to one more image information structure
|
||||
FILE* m_f;
|
||||
int m_color_type;
|
||||
};
|
||||
|
||||
|
||||
class GrFmtPngWriter : public GrFmtWriter
|
||||
{
|
||||
public:
|
||||
|
||||
GrFmtPngWriter( const char* filename );
|
||||
~GrFmtPngWriter();
|
||||
|
||||
bool IsFormatSupported( int depth );
|
||||
bool WriteImage( const uchar* data, int step,
|
||||
int width, int height, int depth, int channels );
|
||||
protected:
|
||||
};
|
||||
|
||||
|
||||
// PNG filter factory
|
||||
class GrFmtPng : public GrFmtFilterFactory
|
||||
{
|
||||
public:
|
||||
|
||||
GrFmtPng();
|
||||
~GrFmtPng();
|
||||
|
||||
GrFmtReader* NewReader( const char* filename );
|
||||
GrFmtWriter* NewWriter( const char* filename );
|
||||
bool CheckSignature( const char* signature );
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
#endif/*_GRFMT_PNG_H_*/
|
||||
@@ -0,0 +1,423 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// Intel License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000, Intel Corporation, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of Intel Corporation may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "_highgui.h"
|
||||
#include "grfmt_pxm.h"
|
||||
|
||||
// P?M filter factory
|
||||
|
||||
GrFmtPxM::GrFmtPxM()
|
||||
{
|
||||
m_sign_len = 3;
|
||||
m_signature = "";
|
||||
m_description = "Portable image format (*.pbm;*.pgm;*.ppm)";
|
||||
}
|
||||
|
||||
|
||||
GrFmtPxM::~GrFmtPxM()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
bool GrFmtPxM::CheckSignature( const char* signature )
|
||||
{
|
||||
return signature[0] == 'P' &&
|
||||
'1' <= signature[1] && signature[1] <= '6' &&
|
||||
isspace(signature[2]);
|
||||
}
|
||||
|
||||
|
||||
GrFmtReader* GrFmtPxM::NewReader( const char* filename )
|
||||
{
|
||||
return new GrFmtPxMReader( filename );
|
||||
}
|
||||
|
||||
|
||||
GrFmtWriter* GrFmtPxM::NewWriter( const char* filename )
|
||||
{
|
||||
return new GrFmtPxMWriter( filename );
|
||||
}
|
||||
|
||||
|
||||
///////////////////////// P?M reader //////////////////////////////
|
||||
|
||||
static int ReadNumber( RLByteStream& strm, int maxdigits )
|
||||
{
|
||||
int code;
|
||||
int val = 0;
|
||||
int digits = 0;
|
||||
|
||||
code = strm.GetByte();
|
||||
|
||||
if( !isdigit(code))
|
||||
{
|
||||
do
|
||||
{
|
||||
if( code == '#' )
|
||||
{
|
||||
do
|
||||
{
|
||||
code = strm.GetByte();
|
||||
}
|
||||
while( code != '\n' && code != '\r' );
|
||||
}
|
||||
|
||||
code = strm.GetByte();
|
||||
|
||||
while( isspace(code))
|
||||
code = strm.GetByte();
|
||||
}
|
||||
while( !isdigit( code ));
|
||||
}
|
||||
|
||||
do
|
||||
{
|
||||
val = val*10 + code - '0';
|
||||
if( ++digits >= maxdigits ) break;
|
||||
code = strm.GetByte();
|
||||
}
|
||||
while( isdigit(code));
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
|
||||
GrFmtPxMReader::GrFmtPxMReader( const char* filename ) : GrFmtReader( filename )
|
||||
{
|
||||
m_offset = -1;
|
||||
}
|
||||
|
||||
|
||||
GrFmtPxMReader::~GrFmtPxMReader()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void GrFmtPxMReader::Close()
|
||||
{
|
||||
m_strm.Close();
|
||||
}
|
||||
|
||||
|
||||
bool GrFmtPxMReader::ReadHeader()
|
||||
{
|
||||
bool result = false;
|
||||
|
||||
assert( strlen(m_filename) != 0 );
|
||||
if( !m_strm.Open( m_filename )) return false;
|
||||
|
||||
if( setjmp( m_strm.JmpBuf()) == 0 )
|
||||
{
|
||||
int code = m_strm.GetByte();
|
||||
if( code != 'P' )
|
||||
BAD_HEADER_ERR();
|
||||
|
||||
code = m_strm.GetByte();
|
||||
switch( code )
|
||||
{
|
||||
case '1': case '4': m_bpp = 1; break;
|
||||
case '2': case '5': m_bpp = 8; break;
|
||||
case '3': case '6': m_bpp = 24; break;
|
||||
default: BAD_HEADER_ERR();
|
||||
}
|
||||
|
||||
m_binary = code >= '4';
|
||||
m_iscolor = m_bpp > 8;
|
||||
|
||||
m_width = ReadNumber( m_strm, INT_MAX );
|
||||
m_height = ReadNumber( m_strm, INT_MAX );
|
||||
|
||||
m_maxval = m_bpp == 1 ? 1 : ReadNumber( m_strm, INT_MAX );
|
||||
|
||||
if( m_maxval > 255 ) m_binary = false;
|
||||
|
||||
if( m_width > 0 && m_height > 0 && m_maxval > 0 && m_maxval < (1 << 16))
|
||||
{
|
||||
m_offset = m_strm.GetPos();
|
||||
result = true;
|
||||
}
|
||||
bad_header_exit:
|
||||
;
|
||||
}
|
||||
|
||||
if( !result )
|
||||
{
|
||||
m_offset = -1;
|
||||
m_width = m_height = -1;
|
||||
m_strm.Close();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
bool GrFmtPxMReader::ReadData( uchar* data, int step, int color )
|
||||
{
|
||||
const int buffer_size = 1 << 12;
|
||||
uchar buffer[buffer_size];
|
||||
uchar pal_buffer[buffer_size];
|
||||
uchar bgr_buffer[buffer_size];
|
||||
PaletteEntry palette[256];
|
||||
bool result = false;
|
||||
uchar* src = buffer;
|
||||
uchar* gray_palette = pal_buffer;
|
||||
uchar* bgr = bgr_buffer;
|
||||
int src_pitch = (m_width*m_bpp + 7)/8;
|
||||
int nch = m_iscolor ? 3 : 1;
|
||||
int width3 = m_width*nch;
|
||||
int i, x, y;
|
||||
|
||||
if( m_offset < 0 || !m_strm.IsOpened())
|
||||
return false;
|
||||
|
||||
if( src_pitch+32 > buffer_size )
|
||||
src = new uchar[width3 + 32];
|
||||
|
||||
if( m_maxval + 1 > buffer_size )
|
||||
gray_palette = new uchar[m_maxval + 1];
|
||||
|
||||
if( m_width*3 + 32 > buffer_size )
|
||||
bgr = new uchar[m_width*3 + 32];
|
||||
|
||||
// create LUT for converting colors
|
||||
for( i = 0; i <= m_maxval; i++ )
|
||||
{
|
||||
gray_palette[i] = (uchar)((i*255/m_maxval)^(m_bpp == 1 ? 255 : 0));
|
||||
}
|
||||
|
||||
FillGrayPalette( palette, m_bpp==1 ? 1 : 8 , m_bpp == 1 );
|
||||
|
||||
if( setjmp( m_strm.JmpBuf()) == 0 )
|
||||
{
|
||||
m_strm.SetPos( m_offset );
|
||||
|
||||
switch( m_bpp )
|
||||
{
|
||||
////////////////////////// 1 BPP /////////////////////////
|
||||
case 1:
|
||||
if( !m_binary )
|
||||
{
|
||||
for( y = 0; y < m_height; y++, data += step )
|
||||
{
|
||||
for( x = 0; x < m_width; x++ )
|
||||
src[x] = ReadNumber( m_strm, 1 ) != 0;
|
||||
|
||||
if( color )
|
||||
FillColorRow8( data, src, m_width, palette );
|
||||
else
|
||||
FillGrayRow8( data, src, m_width, gray_palette );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for( y = 0; y < m_height; y++, data += step )
|
||||
{
|
||||
m_strm.GetBytes( src, src_pitch );
|
||||
|
||||
if( color )
|
||||
FillColorRow1( data, src, m_width, palette );
|
||||
else
|
||||
FillGrayRow1( data, src, m_width, gray_palette );
|
||||
}
|
||||
}
|
||||
result = true;
|
||||
break;
|
||||
|
||||
////////////////////////// 8 BPP /////////////////////////
|
||||
case 8:
|
||||
case 24:
|
||||
for( y = 0; y < m_height; y++, data += step )
|
||||
{
|
||||
if( !m_binary )
|
||||
{
|
||||
for( x = 0; x < width3; x++ )
|
||||
{
|
||||
int code = ReadNumber( m_strm, INT_MAX );
|
||||
if( (unsigned)code > (unsigned)m_maxval ) code = m_maxval;
|
||||
src[x] = gray_palette[code];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
m_strm.GetBytes( src, src_pitch );
|
||||
}
|
||||
|
||||
if( m_bpp == 8 )
|
||||
{
|
||||
if( color )
|
||||
FillColorRow8( data, src, m_width, palette );
|
||||
else
|
||||
memcpy( data, src, m_width );
|
||||
}
|
||||
else
|
||||
{
|
||||
if( color )
|
||||
icvCvt_RGB2BGR_8u_C3R( src, 0, data, 0, cvSize(m_width,1) );
|
||||
else
|
||||
icvCvt_BGR2Gray_8u_C3C1R( src, 0, data, 0, cvSize(m_width,1), 2 );
|
||||
}
|
||||
}
|
||||
result = true;
|
||||
break;
|
||||
default:
|
||||
assert(0);
|
||||
}
|
||||
}
|
||||
|
||||
if( src != buffer )
|
||||
delete[] src;
|
||||
|
||||
if( bgr != bgr_buffer )
|
||||
delete[] bgr;
|
||||
|
||||
if( gray_palette != pal_buffer )
|
||||
delete[] gray_palette;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
GrFmtPxMWriter::GrFmtPxMWriter( const char* filename ) : GrFmtWriter( filename )
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
GrFmtPxMWriter::~GrFmtPxMWriter()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
static char PxMLUT[256][5];
|
||||
static bool isPxMLUTInitialized = false;
|
||||
|
||||
bool GrFmtPxMWriter::WriteImage( const uchar* data, int step,
|
||||
int width, int height, int /*depth*/, int _channels )
|
||||
{
|
||||
bool isBinary = false;
|
||||
bool result = false;
|
||||
|
||||
int channels = _channels > 1 ? 3 : 1;
|
||||
int fileStep = width*channels;
|
||||
int x, y;
|
||||
|
||||
assert( data && width > 0 && height > 0 && step >= fileStep );
|
||||
|
||||
if( m_strm.Open( m_filename ) )
|
||||
{
|
||||
int lineLength = ((isBinary ? 1 : 4)*channels +
|
||||
(channels > 1 ? 2 : 0))*width + 32;
|
||||
int bufferSize = 128; // buffer that should fit a header
|
||||
char* buffer = 0;
|
||||
|
||||
if( bufferSize < lineLength )
|
||||
bufferSize = lineLength;
|
||||
|
||||
buffer = new char[bufferSize];
|
||||
if( !buffer )
|
||||
{
|
||||
m_strm.Close();
|
||||
return false;
|
||||
}
|
||||
|
||||
if( !isPxMLUTInitialized )
|
||||
{
|
||||
for( int i = 0; i < 256; i++ )
|
||||
sprintf( PxMLUT[i], "%4d", i );
|
||||
|
||||
isPxMLUTInitialized = 1;
|
||||
}
|
||||
|
||||
// write header;
|
||||
sprintf( buffer, "P%c\n%d %d\n255\n",
|
||||
'2' + (channels > 1 ? 1 : 0) + (isBinary ? 3 : 0),
|
||||
width, height );
|
||||
|
||||
m_strm.PutBytes( buffer, (int)strlen(buffer) );
|
||||
|
||||
for( y = 0; y < height; y++, data += step )
|
||||
{
|
||||
if( isBinary )
|
||||
{
|
||||
if( _channels == 3 )
|
||||
icvCvt_BGR2RGB_8u_C3R( (uchar*)data, 0,
|
||||
(uchar*)buffer, 0, cvSize(width,1) );
|
||||
else if( _channels == 4 )
|
||||
icvCvt_BGRA2BGR_8u_C4C3R( (uchar*)data, 0,
|
||||
(uchar*)buffer, 0, cvSize(width,1), 1 );
|
||||
m_strm.PutBytes( channels > 1 ? buffer : (char*)data, fileStep );
|
||||
}
|
||||
else
|
||||
{
|
||||
char* ptr = buffer;
|
||||
|
||||
if( channels > 1 )
|
||||
for( x = 0; x < width*channels; x += channels )
|
||||
{
|
||||
strcpy( ptr, PxMLUT[data[x+2]] );
|
||||
ptr += 4;
|
||||
strcpy( ptr, PxMLUT[data[x+1]] );
|
||||
ptr += 4;
|
||||
strcpy( ptr, PxMLUT[data[x]] );
|
||||
ptr += 4;
|
||||
*ptr++ = ' ';
|
||||
*ptr++ = ' ';
|
||||
}
|
||||
else
|
||||
for( x = 0; x < width; x++ )
|
||||
{
|
||||
strcpy( ptr, PxMLUT[data[x]] );
|
||||
ptr += 4;
|
||||
}
|
||||
|
||||
*ptr++ = '\n';
|
||||
|
||||
m_strm.PutBytes( buffer, (int)(ptr - buffer) );
|
||||
}
|
||||
}
|
||||
delete[] buffer;
|
||||
m_strm.Close();
|
||||
result = true;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,101 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// Intel License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000, Intel Corporation, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of Intel Corporation may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#ifndef _GRFMT_PxM_H_
|
||||
#define _GRFMT_PxM_H_
|
||||
|
||||
#include "grfmt_base.h"
|
||||
#include "bitstrm.h"
|
||||
|
||||
|
||||
class GrFmtPxMReader : public GrFmtReader
|
||||
{
|
||||
public:
|
||||
|
||||
GrFmtPxMReader( const char* filename );
|
||||
~GrFmtPxMReader();
|
||||
|
||||
bool CheckFormat( const char* signature );
|
||||
bool ReadData( uchar* data, int step, int color );
|
||||
bool ReadHeader();
|
||||
void Close();
|
||||
|
||||
protected:
|
||||
|
||||
RLByteStream m_strm;
|
||||
PaletteEntry m_palette[256];
|
||||
int m_bpp;
|
||||
int m_offset;
|
||||
bool m_binary;
|
||||
int m_maxval;
|
||||
};
|
||||
|
||||
|
||||
class GrFmtPxMWriter : public GrFmtWriter
|
||||
{
|
||||
public:
|
||||
|
||||
GrFmtPxMWriter( const char* filename );
|
||||
~GrFmtPxMWriter();
|
||||
|
||||
bool WriteImage( const uchar* data, int step,
|
||||
int width, int height, int depth, int channels );
|
||||
protected:
|
||||
|
||||
WLByteStream m_strm;
|
||||
};
|
||||
|
||||
|
||||
// PxM filter factory
|
||||
class GrFmtPxM : public GrFmtFilterFactory
|
||||
{
|
||||
public:
|
||||
|
||||
GrFmtPxM();
|
||||
~GrFmtPxM();
|
||||
|
||||
GrFmtReader* NewReader( const char* filename );
|
||||
GrFmtWriter* NewWriter( const char* filename );
|
||||
bool CheckSignature( const char* signature );
|
||||
};
|
||||
|
||||
|
||||
#endif/*_GRFMT_PxM_H_*/
|
||||
@@ -0,0 +1,442 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// Intel License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000, Intel Corporation, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of Intel Corporation may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "_highgui.h"
|
||||
#include "grfmt_sunras.h"
|
||||
|
||||
static const char* fmtSignSunRas = "\x59\xA6\x6A\x95";
|
||||
|
||||
// Sun Raster filter factory
|
||||
|
||||
GrFmtSunRaster::GrFmtSunRaster()
|
||||
{
|
||||
m_sign_len = 4;
|
||||
m_signature = fmtSignSunRas;
|
||||
m_description = "Sun raster files (*.sr;*.ras)";
|
||||
}
|
||||
|
||||
|
||||
GrFmtSunRaster::~GrFmtSunRaster()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
GrFmtReader* GrFmtSunRaster::NewReader( const char* filename )
|
||||
{
|
||||
return new GrFmtSunRasterReader( filename );
|
||||
}
|
||||
|
||||
|
||||
GrFmtWriter* GrFmtSunRaster::NewWriter( const char* filename )
|
||||
{
|
||||
return new GrFmtSunRasterWriter( filename );
|
||||
}
|
||||
|
||||
|
||||
/************************ Sun Raster reader *****************************/
|
||||
|
||||
GrFmtSunRasterReader::GrFmtSunRasterReader( const char* filename ) : GrFmtReader( filename )
|
||||
{
|
||||
m_offset = -1;
|
||||
}
|
||||
|
||||
|
||||
GrFmtSunRasterReader::~GrFmtSunRasterReader()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void GrFmtSunRasterReader::Close()
|
||||
{
|
||||
m_strm.Close();
|
||||
}
|
||||
|
||||
|
||||
bool GrFmtSunRasterReader::ReadHeader()
|
||||
{
|
||||
bool result = false;
|
||||
|
||||
assert( strlen(m_filename) != 0 );
|
||||
if( !m_strm.Open( m_filename )) return false;
|
||||
|
||||
if( setjmp( m_strm.JmpBuf()) == 0 )
|
||||
{
|
||||
m_strm.Skip( 4 );
|
||||
m_width = m_strm.GetDWord();
|
||||
m_height = m_strm.GetDWord();
|
||||
m_bpp = m_strm.GetDWord();
|
||||
int palSize = 3*(1 << m_bpp);
|
||||
|
||||
m_strm.Skip( 4 );
|
||||
m_type = (SunRasType)m_strm.GetDWord();
|
||||
m_maptype = (SunRasMapType)m_strm.GetDWord();
|
||||
m_maplength = m_strm.GetDWord();
|
||||
|
||||
if( m_width > 0 && m_height > 0 &&
|
||||
(m_bpp == 1 || m_bpp == 8 || m_bpp == 24 || m_bpp == 32) &&
|
||||
(m_type == RAS_OLD || m_type == RAS_STANDARD ||
|
||||
(m_type == RAS_BYTE_ENCODED && m_bpp == 8) || m_type == RAS_FORMAT_RGB) &&
|
||||
(m_maptype == RMT_NONE && m_maplength == 0 ||
|
||||
m_maptype == RMT_EQUAL_RGB && m_maplength <= palSize && m_bpp <= 8))
|
||||
{
|
||||
memset( m_palette, 0, sizeof(m_palette));
|
||||
|
||||
if( m_maplength != 0 )
|
||||
{
|
||||
int readed;
|
||||
uchar buffer[256*3];
|
||||
|
||||
m_strm.GetBytes( buffer, m_maplength, &readed );
|
||||
if( readed == m_maplength )
|
||||
{
|
||||
int i;
|
||||
palSize = m_maplength/3;
|
||||
|
||||
for( i = 0; i < palSize; i++ )
|
||||
{
|
||||
m_palette[i].b = buffer[i + 2*palSize];
|
||||
m_palette[i].g = buffer[i + palSize];
|
||||
m_palette[i].r = buffer[i];
|
||||
m_palette[i].a = 0;
|
||||
}
|
||||
|
||||
m_iscolor = IsColorPalette( m_palette, m_bpp );
|
||||
m_offset = m_strm.GetPos();
|
||||
|
||||
assert( m_offset == 32 + m_maplength );
|
||||
result = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
m_iscolor = m_bpp > 8;
|
||||
|
||||
if( !m_iscolor )
|
||||
FillGrayPalette( m_palette, m_bpp );
|
||||
|
||||
m_offset = m_strm.GetPos();
|
||||
|
||||
assert( m_offset == 32 + m_maplength );
|
||||
result = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if( !result )
|
||||
{
|
||||
m_offset = -1;
|
||||
m_width = m_height = -1;
|
||||
m_strm.Close();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
bool GrFmtSunRasterReader::ReadData( uchar* data, int step, int color )
|
||||
{
|
||||
const int buffer_size = 1 << 12;
|
||||
uchar buffer[buffer_size];
|
||||
uchar bgr_buffer[buffer_size];
|
||||
uchar gray_palette[256];
|
||||
bool result = false;
|
||||
uchar* src = buffer;
|
||||
uchar* bgr = bgr_buffer;
|
||||
int src_pitch = ((m_width*m_bpp + 7)/8 + 1) & -2;
|
||||
int nch = color ? 3 : 1;
|
||||
int width3 = m_width*nch;
|
||||
int y;
|
||||
|
||||
if( m_offset < 0 || !m_strm.IsOpened())
|
||||
return false;
|
||||
|
||||
if( src_pitch+32 > buffer_size )
|
||||
src = new uchar[src_pitch+32];
|
||||
|
||||
if( m_width*3 + 32 > buffer_size )
|
||||
bgr = new uchar[m_width*3 + 32];
|
||||
|
||||
if( !color && m_maptype == RMT_EQUAL_RGB )
|
||||
CvtPaletteToGray( m_palette, gray_palette, 1 << m_bpp );
|
||||
|
||||
if( setjmp( m_strm.JmpBuf()) == 0 )
|
||||
{
|
||||
m_strm.SetPos( m_offset );
|
||||
|
||||
switch( m_bpp )
|
||||
{
|
||||
/************************* 1 BPP ************************/
|
||||
case 1:
|
||||
if( m_type != RAS_BYTE_ENCODED )
|
||||
{
|
||||
for( y = 0; y < m_height; y++, data += step )
|
||||
{
|
||||
m_strm.GetBytes( src, src_pitch );
|
||||
if( color )
|
||||
FillColorRow1( data, src, m_width, m_palette );
|
||||
else
|
||||
FillGrayRow1( data, src, m_width, gray_palette );
|
||||
}
|
||||
result = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
uchar* line_end = src + (m_width*m_bpp + 7)/8;
|
||||
uchar* tsrc = src;
|
||||
y = 0;
|
||||
|
||||
for(;;)
|
||||
{
|
||||
int max_count = (int)(line_end - tsrc);
|
||||
int code = 0, len = 0, len1 = 0;
|
||||
|
||||
do
|
||||
{
|
||||
code = m_strm.GetByte();
|
||||
if( code == 0x80 )
|
||||
{
|
||||
len = m_strm.GetByte();
|
||||
if( len != 0 ) break;
|
||||
}
|
||||
tsrc[len1] = (uchar)code;
|
||||
}
|
||||
while( ++len1 < max_count );
|
||||
|
||||
tsrc += len1;
|
||||
|
||||
if( len > 0 ) // encoded mode
|
||||
{
|
||||
++len;
|
||||
code = m_strm.GetByte();
|
||||
if( len > line_end - tsrc )
|
||||
{
|
||||
assert(0);
|
||||
goto bad_decoding_1bpp;
|
||||
}
|
||||
|
||||
memset( tsrc, code, len );
|
||||
tsrc += len;
|
||||
}
|
||||
|
||||
if( tsrc >= line_end )
|
||||
{
|
||||
tsrc = src;
|
||||
if( color )
|
||||
FillColorRow1( data, src, m_width, m_palette );
|
||||
else
|
||||
FillGrayRow1( data, src, m_width, gray_palette );
|
||||
data += step;
|
||||
if( ++y >= m_height ) break;
|
||||
}
|
||||
}
|
||||
result = true;
|
||||
bad_decoding_1bpp:
|
||||
;
|
||||
}
|
||||
break;
|
||||
/************************* 8 BPP ************************/
|
||||
case 8:
|
||||
if( m_type != RAS_BYTE_ENCODED )
|
||||
{
|
||||
for( y = 0; y < m_height; y++, data += step )
|
||||
{
|
||||
m_strm.GetBytes( src, src_pitch );
|
||||
if( color )
|
||||
FillColorRow8( data, src, m_width, m_palette );
|
||||
else
|
||||
FillGrayRow8( data, src, m_width, gray_palette );
|
||||
}
|
||||
result = true;
|
||||
}
|
||||
else // RLE-encoded
|
||||
{
|
||||
uchar* line_end = data + width3;
|
||||
y = 0;
|
||||
|
||||
for(;;)
|
||||
{
|
||||
int max_count = (int)(line_end - data);
|
||||
int code = 0, len = 0, len1;
|
||||
uchar* tsrc = src;
|
||||
|
||||
do
|
||||
{
|
||||
code = m_strm.GetByte();
|
||||
if( code == 0x80 )
|
||||
{
|
||||
len = m_strm.GetByte();
|
||||
if( len != 0 ) break;
|
||||
}
|
||||
*tsrc++ = (uchar)code;
|
||||
}
|
||||
while( (max_count -= nch) > 0 );
|
||||
|
||||
len1 = (int)(tsrc - src);
|
||||
|
||||
if( len1 > 0 )
|
||||
{
|
||||
if( color )
|
||||
FillColorRow8( data, src, len1, m_palette );
|
||||
else
|
||||
FillGrayRow8( data, src, len1, gray_palette );
|
||||
data += len1*nch;
|
||||
}
|
||||
|
||||
if( len > 0 ) // encoded mode
|
||||
{
|
||||
len = (len + 1)*nch;
|
||||
code = m_strm.GetByte();
|
||||
|
||||
if( color )
|
||||
data = FillUniColor( data, line_end, step, width3,
|
||||
y, m_height, len,
|
||||
m_palette[code] );
|
||||
else
|
||||
data = FillUniGray( data, line_end, step, width3,
|
||||
y, m_height, len,
|
||||
gray_palette[code] );
|
||||
if( y >= m_height )
|
||||
break;
|
||||
}
|
||||
|
||||
if( data == line_end )
|
||||
{
|
||||
if( m_strm.GetByte() != 0 )
|
||||
goto bad_decoding_end;
|
||||
line_end += step;
|
||||
data = line_end - width3;
|
||||
if( ++y >= m_height ) break;
|
||||
}
|
||||
}
|
||||
|
||||
result = true;
|
||||
bad_decoding_end:
|
||||
;
|
||||
}
|
||||
break;
|
||||
/************************* 24 BPP ************************/
|
||||
case 24:
|
||||
for( y = 0; y < m_height; y++, data += step )
|
||||
{
|
||||
m_strm.GetBytes( color ? data : bgr, src_pitch );
|
||||
|
||||
if( color )
|
||||
{
|
||||
if( m_type == RAS_FORMAT_RGB )
|
||||
icvCvt_RGB2BGR_8u_C3R( data, 0, data, 0, cvSize(m_width,1) );
|
||||
}
|
||||
else
|
||||
{
|
||||
icvCvt_BGR2Gray_8u_C3C1R( bgr, 0, data, 0, cvSize(m_width,1),
|
||||
m_type == RAS_FORMAT_RGB ? 2 : 0 );
|
||||
}
|
||||
}
|
||||
result = true;
|
||||
break;
|
||||
/************************* 32 BPP ************************/
|
||||
case 32:
|
||||
for( y = 0; y < m_height; y++, data += step )
|
||||
{
|
||||
/* hack: a0 b0 g0 r0 a1 b1 g1 r1 ... are written to src + 3,
|
||||
so when we look at src + 4, we see b0 g0 r0 x b1 g1 g1 x ... */
|
||||
m_strm.GetBytes( src + 3, src_pitch );
|
||||
|
||||
if( color )
|
||||
icvCvt_BGRA2BGR_8u_C4C3R( src + 4, 0, data, 0, cvSize(m_width,1),
|
||||
m_type == RAS_FORMAT_RGB ? 2 : 0 );
|
||||
else
|
||||
icvCvt_BGRA2Gray_8u_C4C1R( src + 4, 0, data, 0, cvSize(m_width,1),
|
||||
m_type == RAS_FORMAT_RGB ? 2 : 0 );
|
||||
}
|
||||
result = true;
|
||||
break;
|
||||
default:
|
||||
assert(0);
|
||||
}
|
||||
}
|
||||
|
||||
if( src != buffer ) delete[] src;
|
||||
if( bgr != bgr_buffer ) delete[] bgr;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
GrFmtSunRasterWriter::GrFmtSunRasterWriter( const char* filename ) : GrFmtWriter( filename )
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
GrFmtSunRasterWriter::~GrFmtSunRasterWriter()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
bool GrFmtSunRasterWriter::WriteImage( const uchar* data, int step,
|
||||
int width, int height, int /*depth*/, int channels )
|
||||
{
|
||||
bool result = false;
|
||||
int fileStep = (width*channels + 1) & -2;
|
||||
int y;
|
||||
|
||||
assert( data && width > 0 && height > 0 && step >= fileStep);
|
||||
|
||||
if( m_strm.Open( m_filename ) )
|
||||
{
|
||||
m_strm.PutBytes( fmtSignSunRas, (int)strlen(fmtSignSunRas) );
|
||||
m_strm.PutDWord( width );
|
||||
m_strm.PutDWord( height );
|
||||
m_strm.PutDWord( channels*8 );
|
||||
m_strm.PutDWord( fileStep*height );
|
||||
m_strm.PutDWord( RAS_STANDARD );
|
||||
m_strm.PutDWord( RMT_NONE );
|
||||
m_strm.PutDWord( 0 );
|
||||
|
||||
for( y = 0; y < height; y++, data += step )
|
||||
m_strm.PutBytes( data, fileStep );
|
||||
|
||||
m_strm.Close();
|
||||
result = true;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,113 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// Intel License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000, Intel Corporation, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of Intel Corporation may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#ifndef _GRFMT_SUNRAS_H_
|
||||
#define _GRFMT_SUNRAS_H_
|
||||
|
||||
#include "grfmt_base.h"
|
||||
|
||||
enum SunRasType
|
||||
{
|
||||
RAS_OLD = 0,
|
||||
RAS_STANDARD = 1,
|
||||
RAS_BYTE_ENCODED = 2, /* RLE encoded */
|
||||
RAS_FORMAT_RGB = 3 /* RGB instead of BGR */
|
||||
};
|
||||
|
||||
enum SunRasMapType
|
||||
{
|
||||
RMT_NONE = 0, /* direct color encoding */
|
||||
RMT_EQUAL_RGB = 1 /* paletted image */
|
||||
};
|
||||
|
||||
|
||||
// Sun Raster Reader
|
||||
class GrFmtSunRasterReader : public GrFmtReader
|
||||
{
|
||||
public:
|
||||
|
||||
GrFmtSunRasterReader( const char* filename );
|
||||
~GrFmtSunRasterReader();
|
||||
|
||||
bool ReadData( uchar* data, int step, int color );
|
||||
bool ReadHeader();
|
||||
void Close();
|
||||
|
||||
protected:
|
||||
|
||||
RMByteStream m_strm;
|
||||
PaletteEntry m_palette[256];
|
||||
int m_bpp;
|
||||
int m_offset;
|
||||
SunRasType m_type;
|
||||
SunRasMapType m_maptype;
|
||||
int m_maplength;
|
||||
};
|
||||
|
||||
|
||||
class GrFmtSunRasterWriter : public GrFmtWriter
|
||||
{
|
||||
public:
|
||||
|
||||
GrFmtSunRasterWriter( const char* filename );
|
||||
~GrFmtSunRasterWriter();
|
||||
|
||||
bool WriteImage( const uchar* data, int step,
|
||||
int width, int height, int depth, int channels );
|
||||
protected:
|
||||
|
||||
WMByteStream m_strm;
|
||||
};
|
||||
|
||||
|
||||
// ... and filter factory
|
||||
class GrFmtSunRaster : public GrFmtFilterFactory
|
||||
{
|
||||
public:
|
||||
|
||||
GrFmtSunRaster();
|
||||
~GrFmtSunRaster();
|
||||
|
||||
GrFmtReader* NewReader( const char* filename );
|
||||
GrFmtWriter* NewWriter( const char* filename );
|
||||
};
|
||||
|
||||
#endif/*_GRFMT_SUNRAS_H_*/
|
||||
@@ -0,0 +1,826 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// Intel License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000, Intel Corporation, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of Intel Corporation may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
/****************************************************************************************\
|
||||
A part of the file implements TIFF reader on base of libtiff library
|
||||
(see otherlibs/_graphics/readme.txt for copyright notice)
|
||||
\****************************************************************************************/
|
||||
|
||||
#include "_highgui.h"
|
||||
#include "grfmt_tiff.h"
|
||||
|
||||
static const char fmtSignTiffII[] = "II\x2a\x00";
|
||||
static const char fmtSignTiffMM[] = "MM\x00\x2a";
|
||||
|
||||
GrFmtTiff::GrFmtTiff()
|
||||
{
|
||||
m_sign_len = 4;
|
||||
m_signature = "";
|
||||
m_description = "TIFF Files (*.tiff;*.tif)";
|
||||
}
|
||||
|
||||
GrFmtTiff::~GrFmtTiff()
|
||||
{
|
||||
}
|
||||
|
||||
bool GrFmtTiff::CheckSignature( const char* signature )
|
||||
{
|
||||
return memcmp( signature, fmtSignTiffII, 4 ) == 0 ||
|
||||
memcmp( signature, fmtSignTiffMM, 4 ) == 0;
|
||||
}
|
||||
|
||||
|
||||
GrFmtReader* GrFmtTiff::NewReader( const char* filename )
|
||||
{
|
||||
return new GrFmtTiffReader( filename );
|
||||
}
|
||||
|
||||
|
||||
GrFmtWriter* GrFmtTiff::NewWriter( const char* filename )
|
||||
{
|
||||
return new GrFmtTiffWriter( filename );
|
||||
}
|
||||
|
||||
|
||||
#ifdef HAVE_TIFF
|
||||
|
||||
#include "tiff.h"
|
||||
#include "tiffio.h"
|
||||
|
||||
static int grfmt_tiff_err_handler_init = 0;
|
||||
|
||||
static void GrFmtSilentTIFFErrorHandler( const char*, const char*, va_list ) {}
|
||||
|
||||
GrFmtTiffReader::GrFmtTiffReader( const char* filename ) : GrFmtReader( filename )
|
||||
{
|
||||
m_tif = 0;
|
||||
|
||||
if( !grfmt_tiff_err_handler_init )
|
||||
{
|
||||
grfmt_tiff_err_handler_init = 1;
|
||||
|
||||
TIFFSetErrorHandler( GrFmtSilentTIFFErrorHandler );
|
||||
TIFFSetWarningHandler( GrFmtSilentTIFFErrorHandler );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
GrFmtTiffReader::~GrFmtTiffReader()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void GrFmtTiffReader::Close()
|
||||
{
|
||||
if( m_tif )
|
||||
{
|
||||
TIFF* tif = (TIFF*)m_tif;
|
||||
TIFFClose( tif );
|
||||
m_tif = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool GrFmtTiffReader::CheckFormat( const char* signature )
|
||||
{
|
||||
return memcmp( signature, fmtSignTiffII, 4 ) == 0 ||
|
||||
memcmp( signature, fmtSignTiffMM, 4 ) == 0;
|
||||
}
|
||||
|
||||
|
||||
bool GrFmtTiffReader::ReadHeader()
|
||||
{
|
||||
char errmsg[1024];
|
||||
bool result = false;
|
||||
|
||||
Close();
|
||||
TIFF* tif = TIFFOpen( m_filename, "r" );
|
||||
|
||||
if( tif )
|
||||
{
|
||||
int width = 0, height = 0, photometric = 0, compression = 0;
|
||||
m_tif = tif;
|
||||
|
||||
if( TIFFRGBAImageOK( tif, errmsg ) &&
|
||||
TIFFGetField( tif, TIFFTAG_IMAGEWIDTH, &width ) &&
|
||||
TIFFGetField( tif, TIFFTAG_IMAGELENGTH, &height ) &&
|
||||
TIFFGetField( tif, TIFFTAG_PHOTOMETRIC, &photometric ) &&
|
||||
(!TIFFGetField( tif, TIFFTAG_COMPRESSION, &compression ) ||
|
||||
(compression != COMPRESSION_LZW &&
|
||||
compression != COMPRESSION_OJPEG)))
|
||||
{
|
||||
m_width = width;
|
||||
m_height = height;
|
||||
m_iscolor = photometric > 1;
|
||||
|
||||
result = true;
|
||||
}
|
||||
}
|
||||
|
||||
if( !result )
|
||||
Close();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
bool GrFmtTiffReader::ReadData( uchar* data, int step, int color )
|
||||
{
|
||||
bool result = false;
|
||||
uchar* buffer = 0;
|
||||
|
||||
color = color > 0 || (color < 0 && m_iscolor);
|
||||
|
||||
if( m_tif && m_width && m_height )
|
||||
{
|
||||
TIFF* tif = (TIFF*)m_tif;
|
||||
int tile_width0 = m_width, tile_height0 = 0;
|
||||
int x, y, i;
|
||||
int is_tiled = TIFFIsTiled(tif);
|
||||
|
||||
if( !is_tiled &&
|
||||
TIFFGetField( tif, TIFFTAG_ROWSPERSTRIP, &tile_height0 ) ||
|
||||
is_tiled &&
|
||||
TIFFGetField( tif, TIFFTAG_TILEWIDTH, &tile_width0 ) &&
|
||||
TIFFGetField( tif, TIFFTAG_TILELENGTH, &tile_height0 ))
|
||||
{
|
||||
if( tile_width0 <= 0 )
|
||||
tile_width0 = m_width;
|
||||
|
||||
if( tile_height0 <= 0 )
|
||||
tile_height0 = m_height;
|
||||
|
||||
buffer = new uchar[tile_height0*tile_width0*4];
|
||||
|
||||
for( y = 0; y < m_height; y += tile_height0, data += step*tile_height0 )
|
||||
{
|
||||
int tile_height = tile_height0;
|
||||
|
||||
if( y + tile_height > m_height )
|
||||
tile_height = m_height - y;
|
||||
|
||||
for( x = 0; x < m_width; x += tile_width0 )
|
||||
{
|
||||
int tile_width = tile_width0, ok;
|
||||
|
||||
if( x + tile_width > m_width )
|
||||
tile_width = m_width - x;
|
||||
|
||||
if( !is_tiled )
|
||||
ok = TIFFReadRGBAStrip( tif, y, (uint32*)buffer );
|
||||
else
|
||||
ok = TIFFReadRGBATile( tif, x, y, (uint32*)buffer );
|
||||
|
||||
if( !ok )
|
||||
goto exit_func;
|
||||
|
||||
for( i = 0; i < tile_height; i++ )
|
||||
if( color )
|
||||
icvCvt_BGRA2BGR_8u_C4C3R( buffer + i*tile_width*4, 0,
|
||||
data + x*3 + step*(tile_height - i - 1), 0,
|
||||
cvSize(tile_width,1), 2 );
|
||||
else
|
||||
icvCvt_BGRA2Gray_8u_C4C1R( buffer + i*tile_width*4, 0,
|
||||
data + x + step*(tile_height - i - 1), 0,
|
||||
cvSize(tile_width,1), 2 );
|
||||
}
|
||||
}
|
||||
|
||||
result = true;
|
||||
}
|
||||
}
|
||||
|
||||
exit_func:
|
||||
|
||||
Close();
|
||||
delete[] buffer;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
static const int tiffMask[] = { 0xff, 0xff, 0xffffffff, 0xffff, 0xffffffff };
|
||||
|
||||
/************************ TIFF reader *****************************/
|
||||
|
||||
GrFmtTiffReader::GrFmtTiffReader( const char* filename ) : GrFmtReader( filename )
|
||||
{
|
||||
m_offsets = 0;
|
||||
m_maxoffsets = 0;
|
||||
m_strips = -1;
|
||||
m_max_pal_length = 0;
|
||||
m_temp_palette = 0;
|
||||
}
|
||||
|
||||
|
||||
GrFmtTiffReader::~GrFmtTiffReader()
|
||||
{
|
||||
Close();
|
||||
|
||||
delete[] m_offsets;
|
||||
delete[] m_temp_palette;
|
||||
}
|
||||
|
||||
void GrFmtTiffReader::Close()
|
||||
{
|
||||
m_strm.Close();
|
||||
}
|
||||
|
||||
|
||||
bool GrFmtTiffReader::CheckFormat( const char* signature )
|
||||
{
|
||||
return memcmp( signature, fmtSignTiffII, 4 ) == 0 ||
|
||||
memcmp( signature, fmtSignTiffMM, 4 ) == 0;
|
||||
}
|
||||
|
||||
|
||||
int GrFmtTiffReader::GetWordEx()
|
||||
{
|
||||
int val = m_strm.GetWord();
|
||||
if( m_byteorder == TIFF_ORDER_MM )
|
||||
val = ((val)>>8)|(((val)&0xff)<<8);
|
||||
return val;
|
||||
}
|
||||
|
||||
|
||||
int GrFmtTiffReader::GetDWordEx()
|
||||
{
|
||||
int val = m_strm.GetDWord();
|
||||
if( m_byteorder == TIFF_ORDER_MM )
|
||||
val = BSWAP( val );
|
||||
return val;
|
||||
}
|
||||
|
||||
|
||||
int GrFmtTiffReader::ReadTable( int offset, int count,
|
||||
TiffFieldType fieldType,
|
||||
int*& array, int& arraysize )
|
||||
{
|
||||
int i;
|
||||
|
||||
if( count < 0 )
|
||||
return RBS_BAD_HEADER;
|
||||
|
||||
if( fieldType != TIFF_TYPE_SHORT &&
|
||||
fieldType != TIFF_TYPE_LONG &&
|
||||
fieldType != TIFF_TYPE_BYTE )
|
||||
return RBS_BAD_HEADER;
|
||||
|
||||
if( count > arraysize )
|
||||
{
|
||||
delete[] array;
|
||||
arraysize = arraysize*3/2;
|
||||
if( arraysize < count )
|
||||
arraysize = count;
|
||||
array = new int[arraysize];
|
||||
}
|
||||
|
||||
if( count > 1 )
|
||||
{
|
||||
int pos = m_strm.GetPos();
|
||||
m_strm.SetPos( offset );
|
||||
|
||||
if( fieldType == TIFF_TYPE_LONG )
|
||||
{
|
||||
if( m_byteorder == TIFF_ORDER_MM )
|
||||
for( i = 0; i < count; i++ )
|
||||
array[i] = ((RMByteStream&)m_strm).GetDWord();
|
||||
else
|
||||
for( i = 0; i < count; i++ )
|
||||
array[i] = ((RLByteStream&)m_strm).GetDWord();
|
||||
}
|
||||
else if( fieldType == TIFF_TYPE_SHORT )
|
||||
{
|
||||
if( m_byteorder == TIFF_ORDER_MM )
|
||||
for( i = 0; i < count; i++ )
|
||||
array[i] = ((RMByteStream&)m_strm).GetWord();
|
||||
else
|
||||
for( i = 0; i < count; i++ )
|
||||
array[i] = ((RLByteStream&)m_strm).GetWord();
|
||||
}
|
||||
else // fieldType == TIFF_TYPE_BYTE
|
||||
for( i = 0; i < count; i++ )
|
||||
array[i] = m_strm.GetByte();
|
||||
|
||||
m_strm.SetPos(pos);
|
||||
}
|
||||
else
|
||||
{
|
||||
assert( (offset & ~tiffMask[fieldType]) == 0 );
|
||||
array[0] = offset;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
bool GrFmtTiffReader::ReadHeader()
|
||||
{
|
||||
bool result = false;
|
||||
int photometric = -1;
|
||||
int channels = 1;
|
||||
int pal_length = -1;
|
||||
|
||||
const int MAX_CHANNELS = 4;
|
||||
int bpp_arr[MAX_CHANNELS];
|
||||
|
||||
assert( strlen(m_filename) != 0 );
|
||||
if( !m_strm.Open( m_filename )) return false;
|
||||
|
||||
m_width = -1;
|
||||
m_height = -1;
|
||||
m_strips = -1;
|
||||
m_bpp = 1;
|
||||
m_compression = TIFF_UNCOMP;
|
||||
m_rows_per_strip = -1;
|
||||
m_iscolor = false;
|
||||
|
||||
if( setjmp( m_strm.JmpBuf()) == 0 )
|
||||
{
|
||||
m_byteorder = (TiffByteOrder)m_strm.GetWord();
|
||||
m_strm.Skip( 2 );
|
||||
int header_offset = GetDWordEx();
|
||||
|
||||
m_strm.SetPos( header_offset );
|
||||
|
||||
// read the first tag directory
|
||||
int i, j, count = GetWordEx();
|
||||
|
||||
for( i = 0; i < count; i++ )
|
||||
{
|
||||
// read tag
|
||||
TiffTag tag = (TiffTag)GetWordEx();
|
||||
TiffFieldType fieldType = (TiffFieldType)GetWordEx();
|
||||
int count = GetDWordEx();
|
||||
int value = GetDWordEx();
|
||||
if( count == 1 )
|
||||
{
|
||||
if( m_byteorder == TIFF_ORDER_MM )
|
||||
{
|
||||
if( fieldType == TIFF_TYPE_SHORT )
|
||||
value = (unsigned)value >> 16;
|
||||
else if( fieldType == TIFF_TYPE_BYTE )
|
||||
value = (unsigned)value >> 24;
|
||||
}
|
||||
|
||||
value &= tiffMask[fieldType];
|
||||
}
|
||||
|
||||
switch( tag )
|
||||
{
|
||||
case TIFF_TAG_WIDTH:
|
||||
m_width = value;
|
||||
break;
|
||||
|
||||
case TIFF_TAG_HEIGHT:
|
||||
m_height = value;
|
||||
break;
|
||||
|
||||
case TIFF_TAG_BITS_PER_SAMPLE:
|
||||
{
|
||||
int* bpp_arr_ref = bpp_arr;
|
||||
|
||||
if( count > MAX_CHANNELS )
|
||||
BAD_HEADER_ERR();
|
||||
|
||||
if( ReadTable( value, count, fieldType, bpp_arr_ref, count ) < 0 )
|
||||
BAD_HEADER_ERR();
|
||||
|
||||
for( j = 1; j < count; j++ )
|
||||
{
|
||||
if( bpp_arr[j] != bpp_arr[0] )
|
||||
BAD_HEADER_ERR();
|
||||
}
|
||||
|
||||
m_bpp = bpp_arr[0];
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case TIFF_TAG_COMPRESSION:
|
||||
m_compression = (TiffCompression)value;
|
||||
if( m_compression != TIFF_UNCOMP &&
|
||||
m_compression != TIFF_HUFFMAN &&
|
||||
m_compression != TIFF_PACKBITS )
|
||||
BAD_HEADER_ERR();
|
||||
break;
|
||||
|
||||
case TIFF_TAG_PHOTOMETRIC:
|
||||
photometric = value;
|
||||
if( (unsigned)photometric > 3 )
|
||||
BAD_HEADER_ERR();
|
||||
break;
|
||||
|
||||
case TIFF_TAG_STRIP_OFFSETS:
|
||||
m_strips = count;
|
||||
if( ReadTable( value, count, fieldType, m_offsets, m_maxoffsets ) < 0 )
|
||||
BAD_HEADER_ERR();
|
||||
break;
|
||||
|
||||
case TIFF_TAG_SAMPLES_PER_PIXEL:
|
||||
channels = value;
|
||||
if( channels != 1 && channels != 3 && channels != 4 )
|
||||
BAD_HEADER_ERR();
|
||||
break;
|
||||
|
||||
case TIFF_TAG_ROWS_PER_STRIP:
|
||||
m_rows_per_strip = value;
|
||||
break;
|
||||
|
||||
case TIFF_TAG_PLANAR_CONFIG:
|
||||
{
|
||||
int planar_config = value;
|
||||
if( planar_config != 1 )
|
||||
BAD_HEADER_ERR();
|
||||
}
|
||||
break;
|
||||
|
||||
case TIFF_TAG_COLOR_MAP:
|
||||
if( fieldType != TIFF_TYPE_SHORT || count < 2 )
|
||||
BAD_HEADER_ERR();
|
||||
if( ReadTable( value, count, fieldType,
|
||||
m_temp_palette, m_max_pal_length ) < 0 )
|
||||
BAD_HEADER_ERR();
|
||||
pal_length = count / 3;
|
||||
if( pal_length > 256 )
|
||||
BAD_HEADER_ERR();
|
||||
for( i = 0; i < pal_length; i++ )
|
||||
{
|
||||
m_palette[i].r = (uchar)(m_temp_palette[i] >> 8);
|
||||
m_palette[i].g = (uchar)(m_temp_palette[i + pal_length] >> 8);
|
||||
m_palette[i].b = (uchar)(m_temp_palette[i + pal_length*2] >> 8);
|
||||
}
|
||||
break;
|
||||
case TIFF_TAG_STRIP_COUNTS:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if( m_strips == 1 && m_rows_per_strip == -1 )
|
||||
m_rows_per_strip = m_height;
|
||||
|
||||
if( m_width > 0 && m_height > 0 && m_strips > 0 &&
|
||||
(m_height + m_rows_per_strip - 1)/m_rows_per_strip == m_strips )
|
||||
{
|
||||
switch( m_bpp )
|
||||
{
|
||||
case 1:
|
||||
if( photometric == 0 || photometric == 1 && channels == 1 )
|
||||
{
|
||||
FillGrayPalette( m_palette, m_bpp, photometric == 0 );
|
||||
result = true;
|
||||
m_iscolor = false;
|
||||
}
|
||||
break;
|
||||
case 4:
|
||||
case 8:
|
||||
if( (photometric == 0 || photometric == 1 ||
|
||||
photometric == 3 && pal_length == (1 << m_bpp)) &&
|
||||
m_compression != TIFF_HUFFMAN && channels == 1 )
|
||||
{
|
||||
if( pal_length < 0 )
|
||||
{
|
||||
FillGrayPalette( m_palette, m_bpp, photometric == 0 );
|
||||
m_iscolor = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_iscolor = IsColorPalette( m_palette, m_bpp );
|
||||
}
|
||||
result = true;
|
||||
}
|
||||
else if( photometric == 2 && pal_length < 0 &&
|
||||
(channels == 3 || channels == 4) &&
|
||||
m_compression == TIFF_UNCOMP )
|
||||
{
|
||||
m_bpp = 8*channels;
|
||||
m_iscolor = true;
|
||||
result = true;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
BAD_HEADER_ERR();
|
||||
}
|
||||
}
|
||||
bad_header_exit:
|
||||
;
|
||||
}
|
||||
|
||||
if( !result )
|
||||
{
|
||||
m_strips = -1;
|
||||
m_width = m_height = -1;
|
||||
m_strm.Close();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
bool GrFmtTiffReader::ReadData( uchar* data, int step, int color )
|
||||
{
|
||||
const int buffer_size = 1 << 12;
|
||||
uchar buffer[buffer_size];
|
||||
uchar gray_palette[256];
|
||||
bool result = false;
|
||||
uchar* src = buffer;
|
||||
int src_pitch = (m_width*m_bpp + 7)/8;
|
||||
int y = 0;
|
||||
|
||||
if( m_strips < 0 || !m_strm.IsOpened())
|
||||
return false;
|
||||
|
||||
if( src_pitch+32 > buffer_size )
|
||||
src = new uchar[src_pitch+32];
|
||||
|
||||
if( !color )
|
||||
if( m_bpp <= 8 )
|
||||
{
|
||||
CvtPaletteToGray( m_palette, gray_palette, 1 << m_bpp );
|
||||
}
|
||||
|
||||
if( setjmp( m_strm.JmpBuf()) == 0 )
|
||||
{
|
||||
for( int s = 0; s < m_strips; s++ )
|
||||
{
|
||||
int y_limit = m_rows_per_strip;
|
||||
|
||||
y_limit += y;
|
||||
if( y_limit > m_height ) y_limit = m_height;
|
||||
|
||||
m_strm.SetPos( m_offsets[s] );
|
||||
|
||||
if( m_compression == TIFF_UNCOMP )
|
||||
{
|
||||
for( ; y < y_limit; y++, data += step )
|
||||
{
|
||||
m_strm.GetBytes( src, src_pitch );
|
||||
if( color )
|
||||
switch( m_bpp )
|
||||
{
|
||||
case 1:
|
||||
FillColorRow1( data, src, m_width, m_palette );
|
||||
break;
|
||||
case 4:
|
||||
FillColorRow4( data, src, m_width, m_palette );
|
||||
break;
|
||||
case 8:
|
||||
FillColorRow8( data, src, m_width, m_palette );
|
||||
break;
|
||||
case 24:
|
||||
icvCvt_RGB2BGR_8u_C3R( src, 0, data, 0, cvSize(m_width,1) );
|
||||
break;
|
||||
case 32:
|
||||
icvCvt_BGRA2BGR_8u_C4C3R( src, 0, data, 0, cvSize(m_width,1), 2 );
|
||||
break;
|
||||
default:
|
||||
assert(0);
|
||||
goto bad_decoding_end;
|
||||
}
|
||||
else
|
||||
switch( m_bpp )
|
||||
{
|
||||
case 1:
|
||||
FillGrayRow1( data, src, m_width, gray_palette );
|
||||
break;
|
||||
case 4:
|
||||
FillGrayRow4( data, src, m_width, gray_palette );
|
||||
break;
|
||||
case 8:
|
||||
FillGrayRow8( data, src, m_width, gray_palette );
|
||||
break;
|
||||
case 24:
|
||||
icvCvt_BGR2Gray_8u_C3C1R( src, 0, data, 0, cvSize(m_width,1), 2 );
|
||||
break;
|
||||
case 32:
|
||||
icvCvt_BGRA2Gray_8u_C4C1R( src, 0, data, 0, cvSize(m_width,1), 2 );
|
||||
break;
|
||||
default:
|
||||
assert(0);
|
||||
goto bad_decoding_end;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
}
|
||||
|
||||
result = true;
|
||||
|
||||
bad_decoding_end:
|
||||
|
||||
;
|
||||
}
|
||||
}
|
||||
|
||||
if( src != buffer ) delete[] src;
|
||||
return result;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
GrFmtTiffWriter::GrFmtTiffWriter( const char* filename ) : GrFmtWriter( filename )
|
||||
{
|
||||
}
|
||||
|
||||
GrFmtTiffWriter::~GrFmtTiffWriter()
|
||||
{
|
||||
}
|
||||
|
||||
void GrFmtTiffWriter::WriteTag( TiffTag tag, TiffFieldType fieldType,
|
||||
int count, int value )
|
||||
{
|
||||
m_strm.PutWord( tag );
|
||||
m_strm.PutWord( fieldType );
|
||||
m_strm.PutDWord( count );
|
||||
m_strm.PutDWord( value );
|
||||
}
|
||||
|
||||
|
||||
bool GrFmtTiffWriter::WriteImage( const uchar* data, int step,
|
||||
int width, int height, int /*depth*/, int channels )
|
||||
{
|
||||
bool result = false;
|
||||
int fileStep = width*channels;
|
||||
|
||||
assert( data && width > 0 && height > 0 && step >= fileStep);
|
||||
|
||||
if( m_strm.Open( m_filename ) )
|
||||
{
|
||||
int rowsPerStrip = (1 << 13)/fileStep;
|
||||
|
||||
if( rowsPerStrip < 1 )
|
||||
rowsPerStrip = 1;
|
||||
|
||||
if( rowsPerStrip > height )
|
||||
rowsPerStrip = height;
|
||||
|
||||
int i, stripCount = (height + rowsPerStrip - 1) / rowsPerStrip;
|
||||
/*#if defined _DEBUG || !defined WIN32
|
||||
int uncompressedRowSize = rowsPerStrip * fileStep;
|
||||
#endif*/
|
||||
int directoryOffset = 0;
|
||||
|
||||
int* stripOffsets = new int[stripCount];
|
||||
short* stripCounts = new short[stripCount];
|
||||
uchar* buffer = new uchar[fileStep + 32];
|
||||
int stripOffsetsOffset = 0;
|
||||
int stripCountsOffset = 0;
|
||||
int bitsPerSample = 8; // TODO support 16 bit
|
||||
int y = 0;
|
||||
|
||||
m_strm.PutBytes( fmtSignTiffII, 4 );
|
||||
m_strm.PutDWord( directoryOffset );
|
||||
|
||||
// write an image data first (the most reasonable way
|
||||
// for compressed images)
|
||||
for( i = 0; i < stripCount; i++ )
|
||||
{
|
||||
int limit = y + rowsPerStrip;
|
||||
|
||||
if( limit > height )
|
||||
limit = height;
|
||||
|
||||
stripOffsets[i] = m_strm.GetPos();
|
||||
|
||||
for( ; y < limit; y++, data += step )
|
||||
{
|
||||
if( channels == 3 )
|
||||
icvCvt_BGR2RGB_8u_C3R( data, 0, buffer, 0, cvSize(width,1) );
|
||||
else if( channels == 4 )
|
||||
icvCvt_BGRA2RGBA_8u_C4R( data, 0, buffer, 0, cvSize(width,1) );
|
||||
|
||||
m_strm.PutBytes( channels > 1 ? buffer : data, fileStep );
|
||||
}
|
||||
|
||||
stripCounts[i] = (short)(m_strm.GetPos() - stripOffsets[i]);
|
||||
/*assert( stripCounts[i] == uncompressedRowSize ||
|
||||
stripCounts[i] < uncompressedRowSize &&
|
||||
i == stripCount - 1);*/
|
||||
}
|
||||
|
||||
if( stripCount > 2 )
|
||||
{
|
||||
stripOffsetsOffset = m_strm.GetPos();
|
||||
for( i = 0; i < stripCount; i++ )
|
||||
m_strm.PutDWord( stripOffsets[i] );
|
||||
|
||||
stripCountsOffset = m_strm.GetPos();
|
||||
for( i = 0; i < stripCount; i++ )
|
||||
m_strm.PutWord( stripCounts[i] );
|
||||
}
|
||||
else if(stripCount == 2)
|
||||
{
|
||||
stripOffsetsOffset = m_strm.GetPos();
|
||||
for (i = 0; i < stripCount; i++)
|
||||
{
|
||||
m_strm.PutDWord (stripOffsets [i]);
|
||||
}
|
||||
stripCountsOffset = stripCounts [0] + (stripCounts [1] << 16);
|
||||
}
|
||||
else
|
||||
{
|
||||
stripOffsetsOffset = stripOffsets[0];
|
||||
stripCountsOffset = stripCounts[0];
|
||||
}
|
||||
|
||||
if( channels > 1 )
|
||||
{
|
||||
bitsPerSample = m_strm.GetPos();
|
||||
m_strm.PutWord(8);
|
||||
m_strm.PutWord(8);
|
||||
m_strm.PutWord(8);
|
||||
if( channels == 4 )
|
||||
m_strm.PutWord(8);
|
||||
}
|
||||
|
||||
directoryOffset = m_strm.GetPos();
|
||||
|
||||
// write header
|
||||
m_strm.PutWord( 9 );
|
||||
|
||||
/* warning: specification 5.0 of Tiff want to have tags in
|
||||
ascending order. This is a non-fatal error, but this cause
|
||||
warning with some tools. So, keep this in ascending order */
|
||||
|
||||
WriteTag( TIFF_TAG_WIDTH, TIFF_TYPE_LONG, 1, width );
|
||||
WriteTag( TIFF_TAG_HEIGHT, TIFF_TYPE_LONG, 1, height );
|
||||
WriteTag( TIFF_TAG_BITS_PER_SAMPLE,
|
||||
TIFF_TYPE_SHORT, channels, bitsPerSample );
|
||||
WriteTag( TIFF_TAG_COMPRESSION, TIFF_TYPE_LONG, 1, TIFF_UNCOMP );
|
||||
WriteTag( TIFF_TAG_PHOTOMETRIC, TIFF_TYPE_SHORT, 1, channels > 1 ? 2 : 1 );
|
||||
|
||||
WriteTag( TIFF_TAG_STRIP_OFFSETS, TIFF_TYPE_LONG,
|
||||
stripCount, stripOffsetsOffset );
|
||||
|
||||
WriteTag( TIFF_TAG_SAMPLES_PER_PIXEL, TIFF_TYPE_SHORT, 1, channels );
|
||||
WriteTag( TIFF_TAG_ROWS_PER_STRIP, TIFF_TYPE_LONG, 1, rowsPerStrip );
|
||||
|
||||
WriteTag( TIFF_TAG_STRIP_COUNTS,
|
||||
stripCount > 1 ? TIFF_TYPE_SHORT : TIFF_TYPE_LONG,
|
||||
stripCount, stripCountsOffset );
|
||||
|
||||
m_strm.PutDWord(0);
|
||||
m_strm.Close();
|
||||
|
||||
// write directory offset
|
||||
FILE* f = fopen( m_filename, "r+b" );
|
||||
buffer[0] = (uchar)directoryOffset;
|
||||
buffer[1] = (uchar)(directoryOffset >> 8);
|
||||
buffer[2] = (uchar)(directoryOffset >> 16);
|
||||
buffer[3] = (uchar)(directoryOffset >> 24);
|
||||
|
||||
fseek( f, 4, SEEK_SET );
|
||||
fwrite( buffer, 1, 4, f );
|
||||
fclose(f);
|
||||
|
||||
delete[] stripOffsets;
|
||||
delete[] stripCounts;
|
||||
delete[] buffer;
|
||||
|
||||
result = true;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,178 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// Intel License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000, Intel Corporation, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of Intel Corporation may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#ifndef _GRFMT_TIFF_H_
|
||||
#define _GRFMT_TIFF_H_
|
||||
|
||||
#include "grfmt_base.h"
|
||||
|
||||
|
||||
// native simple TIFF codec
|
||||
enum TiffCompression
|
||||
{
|
||||
TIFF_UNCOMP = 1,
|
||||
TIFF_HUFFMAN = 2,
|
||||
TIFF_PACKBITS = 32773
|
||||
};
|
||||
|
||||
enum TiffByteOrder
|
||||
{
|
||||
TIFF_ORDER_II = 0x4949,
|
||||
TIFF_ORDER_MM = 0x4d4d
|
||||
};
|
||||
|
||||
|
||||
enum TiffTag
|
||||
{
|
||||
TIFF_TAG_WIDTH = 256,
|
||||
TIFF_TAG_HEIGHT = 257,
|
||||
TIFF_TAG_BITS_PER_SAMPLE = 258,
|
||||
TIFF_TAG_COMPRESSION = 259,
|
||||
TIFF_TAG_PHOTOMETRIC = 262,
|
||||
TIFF_TAG_STRIP_OFFSETS = 273,
|
||||
TIFF_TAG_STRIP_COUNTS = 279,
|
||||
TIFF_TAG_SAMPLES_PER_PIXEL = 277,
|
||||
TIFF_TAG_ROWS_PER_STRIP = 278,
|
||||
TIFF_TAG_PLANAR_CONFIG = 284,
|
||||
TIFF_TAG_COLOR_MAP = 320
|
||||
};
|
||||
|
||||
|
||||
enum TiffFieldType
|
||||
{
|
||||
TIFF_TYPE_BYTE = 1,
|
||||
TIFF_TYPE_SHORT = 3,
|
||||
TIFF_TYPE_LONG = 4
|
||||
};
|
||||
|
||||
|
||||
|
||||
#ifdef HAVE_TIFF
|
||||
|
||||
// libtiff based TIFF codec
|
||||
|
||||
class GrFmtTiffReader : public GrFmtReader
|
||||
{
|
||||
public:
|
||||
|
||||
GrFmtTiffReader( const char* filename );
|
||||
~GrFmtTiffReader();
|
||||
|
||||
bool CheckFormat( const char* signature );
|
||||
bool ReadData( uchar* data, int step, int color );
|
||||
bool ReadHeader();
|
||||
void Close();
|
||||
|
||||
protected:
|
||||
|
||||
void* m_tif;
|
||||
};
|
||||
|
||||
|
||||
#else
|
||||
|
||||
class GrFmtTiffReader : public GrFmtReader
|
||||
{
|
||||
public:
|
||||
|
||||
GrFmtTiffReader( const char* filename );
|
||||
~GrFmtTiffReader();
|
||||
|
||||
bool CheckFormat( const char* signature );
|
||||
bool ReadData( uchar* data, int step, int color );
|
||||
bool ReadHeader();
|
||||
void Close();
|
||||
|
||||
protected:
|
||||
|
||||
RLByteStream m_strm;
|
||||
PaletteEntry m_palette[256];
|
||||
int m_bpp;
|
||||
int* m_temp_palette;
|
||||
int m_max_pal_length;
|
||||
int* m_offsets;
|
||||
int m_maxoffsets;
|
||||
int m_strips;
|
||||
int m_rows_per_strip;
|
||||
TiffCompression m_compression;
|
||||
TiffByteOrder m_byteorder;
|
||||
|
||||
int GetWordEx();
|
||||
int GetDWordEx();
|
||||
int ReadTable( int offset, int count, TiffFieldType fieldtype,
|
||||
int*& array, int& arraysize );
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
// ... and writer
|
||||
class GrFmtTiffWriter : public GrFmtWriter
|
||||
{
|
||||
public:
|
||||
|
||||
GrFmtTiffWriter( const char* filename );
|
||||
~GrFmtTiffWriter();
|
||||
|
||||
bool WriteImage( const uchar* data, int step,
|
||||
int width, int height, int depth, int channels );
|
||||
protected:
|
||||
|
||||
WLByteStream m_strm;
|
||||
|
||||
void WriteTag( TiffTag tag, TiffFieldType fieldType,
|
||||
int count, int value );
|
||||
};
|
||||
|
||||
|
||||
// TIFF filter factory
|
||||
class GrFmtTiff : public GrFmtFilterFactory
|
||||
{
|
||||
public:
|
||||
|
||||
GrFmtTiff();
|
||||
~GrFmtTiff();
|
||||
|
||||
GrFmtReader* NewReader( const char* filename );
|
||||
GrFmtWriter* NewWriter( const char* filename );
|
||||
bool CheckSignature( const char* signature );
|
||||
};
|
||||
|
||||
#endif/*_GRFMT_TIFF_H_*/
|
||||
@@ -0,0 +1,55 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// Intel License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000, Intel Corporation, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of Intel Corporation may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#ifndef _GRFMTS_H_
|
||||
#define _GRFMTS_H_
|
||||
|
||||
#include "grfmt_base.h"
|
||||
#include "grfmt_bmp.h"
|
||||
#include "grfmt_sunras.h"
|
||||
#include "grfmt_jpeg.h"
|
||||
#include "grfmt_pxm.h"
|
||||
#include "grfmt_tiff.h"
|
||||
#include "grfmt_png.h"
|
||||
#include "grfmt_jpeg2000.h"
|
||||
#include "grfmt_exr.h"
|
||||
|
||||
#endif/*_GRFMTS_H_*/
|
||||
@@ -0,0 +1,412 @@
|
||||
# Microsoft Developer Studio Project File - Name="highgui" - Package Owner=<4>
|
||||
# Microsoft Developer Studio Generated Build File, Format Version 6.00
|
||||
# ** DO NOT EDIT **
|
||||
|
||||
# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102
|
||||
|
||||
CFG=highgui - Win32 Debug64 Itanium
|
||||
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
|
||||
!MESSAGE use the Export Makefile command and run
|
||||
!MESSAGE
|
||||
!MESSAGE NMAKE /f "highgui.mak".
|
||||
!MESSAGE
|
||||
!MESSAGE You can specify a configuration when running NMAKE
|
||||
!MESSAGE by defining the macro CFG on the command line. For example:
|
||||
!MESSAGE
|
||||
!MESSAGE NMAKE /f "highgui.mak" CFG="highgui - Win32 Debug64 Itanium"
|
||||
!MESSAGE
|
||||
!MESSAGE Possible choices for configuration are:
|
||||
!MESSAGE
|
||||
!MESSAGE "highgui - Win32 Release" (based on "Win32 (x86) Dynamic-Link Library")
|
||||
!MESSAGE "highgui - Win32 Debug" (based on "Win32 (x86) Dynamic-Link Library")
|
||||
!MESSAGE "highgui - Win32 Release64" (based on "Win32 (x86) Dynamic-Link Library")
|
||||
!MESSAGE "highgui - Win32 Debug64" (based on "Win32 (x86) Dynamic-Link Library")
|
||||
!MESSAGE "highgui - Win32 Release64 Itanium" (based on "Win32 (x86) Dynamic-Link Library")
|
||||
!MESSAGE "highgui - Win32 Debug64 Itanium" (based on "Win32 (x86) Dynamic-Link Library")
|
||||
!MESSAGE
|
||||
|
||||
# Begin Project
|
||||
# PROP AllowPerConfigDependencies 0
|
||||
# PROP Scc_ProjName ""
|
||||
# PROP Scc_LocalPath ""
|
||||
CPP=xicl6.exe
|
||||
MTL=midl.exe
|
||||
RSC=rc.exe
|
||||
|
||||
!IF "$(CFG)" == "highgui - Win32 Release"
|
||||
|
||||
# PROP BASE Use_MFC 0
|
||||
# PROP BASE Use_Debug_Libraries 0
|
||||
# PROP BASE Output_Dir "Release"
|
||||
# PROP BASE Intermediate_Dir "Release"
|
||||
# PROP BASE Target_Dir ""
|
||||
# PROP Use_MFC 0
|
||||
# PROP Use_Debug_Libraries 0
|
||||
# PROP Output_Dir "..\..\_temp\HighGUI_Rls"
|
||||
# PROP Intermediate_Dir "..\..\_temp\HighGUI_Rls"
|
||||
# PROP Ignore_Export_Lib 0
|
||||
# PROP Target_Dir ""
|
||||
LIB32=link.exe -lib
|
||||
# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "HIGHGUI_EXPORTS" /YX /FD /c
|
||||
# ADD CPP /nologo /MD /W4 /Zi /O2 /I "..\..\cxcore\include" /I "..\..\cv\include" /I ".\\" /I "..\_graphics\include" /D "NDEBUG" /D "HAVE_JPEG" /D "WIN32" /D "_WINDOWS" /D "_MBCS" /D "CVAPI_EXPORTS" /D "HAVE_PNG" /D "HAVE_TIFF" /D "HAVE_JASPER" /FR /Yu"_highgui.h" /FD /c
|
||||
# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
|
||||
# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
|
||||
# ADD BASE RSC /l 0x419 /d "NDEBUG"
|
||||
# ADD RSC /l 0x419 /d "NDEBUG"
|
||||
BSC32=bscmake.exe
|
||||
# ADD BASE BSC32 /nologo
|
||||
# ADD BSC32 /nologo
|
||||
LINK32=xilink6.exe
|
||||
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386
|
||||
# ADD LINK32 cxcore.lib kernel32.lib user32.lib gdi32.lib comdlg32.lib advapi32.lib shell32.lib comctl32.lib libjpeg.lib libjasper.lib libpng.lib libtiff.lib zlib.lib vfw32.lib /nologo /dll /pdb:"..\..\bin/highgui100.pdb" /debug /machine:I386 /nodefaultlib:"libmmd.lib" /out:"..\..\bin/highgui100.dll" /implib:"..\..\lib/highgui.lib" /libpath:"..\..\lib" /libpath:"..\_graphics\lib"
|
||||
# SUBTRACT LINK32 /pdb:none
|
||||
|
||||
!ELSEIF "$(CFG)" == "highgui - Win32 Debug"
|
||||
|
||||
# PROP BASE Use_MFC 0
|
||||
# PROP BASE Use_Debug_Libraries 1
|
||||
# PROP BASE Output_Dir "Debug"
|
||||
# PROP BASE Intermediate_Dir "Debug"
|
||||
# PROP BASE Target_Dir ""
|
||||
# PROP Use_MFC 0
|
||||
# PROP Use_Debug_Libraries 1
|
||||
# PROP Output_Dir "..\..\_temp\HighGUI_Dbg"
|
||||
# PROP Intermediate_Dir "..\..\_temp\HighGUI_Dbg"
|
||||
# PROP Ignore_Export_Lib 0
|
||||
# PROP Target_Dir ""
|
||||
LIB32=link.exe -lib
|
||||
# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "HIGHGUI_EXPORTS" /YX /FD /GZ /c
|
||||
# ADD CPP /nologo /MDd /W4 /Gm /Zi /Od /I "..\..\cxcore\include" /I "..\..\cv\include" /I ".\\" /I "..\_graphics\include" /D "_DEBUG" /D "WIN32" /D "_WINDOWS" /D "_MBCS" /D "CVAPI_EXPORTS" /D "HAVE_PNG" /D "HAVE_TIFF" /D "HAVE_JASPER" /FR /Yu"_highgui.h" /FD /GZ /c
|
||||
# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32
|
||||
# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32
|
||||
# ADD BASE RSC /l 0x419 /d "_DEBUG"
|
||||
# ADD RSC /l 0x419 /d "_DEBUG"
|
||||
BSC32=bscmake.exe
|
||||
# ADD BASE BSC32 /nologo
|
||||
# ADD BSC32 /nologo
|
||||
LINK32=xilink6.exe
|
||||
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /pdbtype:sept
|
||||
# ADD LINK32 cxcored.lib kernel32.lib user32.lib gdi32.lib comdlg32.lib advapi32.lib shell32.lib comctl32.lib libjpeg.lib libjasper.lib libpng.lib libtiff.lib zlib.lib vfw32.lib /nologo /dll /pdb:"..\..\bin/highgui100d.pdb" /debug /machine:I386 /nodefaultlib:"libmmdd.lib" /out:"..\..\bin/highgui100d.dll" /implib:"..\..\lib/highguid.lib" /pdbtype:sept /libpath:"..\..\lib" /libpath:"..\_graphics\lib"
|
||||
# SUBTRACT LINK32 /pdb:none /nodefaultlib
|
||||
|
||||
!ELSEIF "$(CFG)" == "highgui - Win32 Release64"
|
||||
|
||||
# PROP BASE Use_MFC 0
|
||||
# PROP BASE Use_Debug_Libraries 0
|
||||
# PROP BASE Output_Dir "highgui___Win32_Release64"
|
||||
# PROP BASE Intermediate_Dir "highgui___Win32_Release64"
|
||||
# PROP BASE Ignore_Export_Lib 0
|
||||
# PROP BASE Target_Dir ""
|
||||
# PROP Use_MFC 0
|
||||
# PROP Use_Debug_Libraries 0
|
||||
# PROP Output_Dir "..\..\_temp\highgui_Rls64"
|
||||
# PROP Intermediate_Dir "..\..\_temp\highgui_Rls64"
|
||||
# PROP Ignore_Export_Lib 0
|
||||
# PROP Target_Dir ""
|
||||
LIB32=link.exe -lib
|
||||
# ADD BASE CPP /nologo /MD /W4 /Zi /O2 /I "..\..\cxcore\include" /I "..\..\cv\include" /I ".\\" /I "..\_graphics\include" /D "NDEBUG" /D "WIN32" /D "_WINDOWS" /D "_MBCS" /D "CVAPI_EXPORTS" /D "HAVE_JPEG" /D "HAVE_PNG" /D "HAVE_TIFF" /FR /Yu"_highgui.h" /FD /c
|
||||
# ADD CPP /nologo /MD /W4 /Zi /O2 /I "..\..\cxcore\include" /I "..\..\cv\include" /I ".\\" /I "..\_graphics\include" /D "_WINDOWS" /D "_MBCS" /D "CVAPI_EXPORTS" /D "NDEBUG" /D "WIN32" /D "WIN64" /D "EM64T" /D "HAVE_JPEG" /D "HAVE_PNG" /D "HAVE_TIFF" /FR /Yu"_highgui.h" /FD /c
|
||||
# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
|
||||
# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
|
||||
# ADD BASE RSC /l 0x419 /d "NDEBUG"
|
||||
# ADD RSC /l 0x419 /d "NDEBUG"
|
||||
BSC32=bscmake.exe
|
||||
# ADD BASE BSC32 /nologo
|
||||
# ADD BSC32 /nologo
|
||||
LINK32=xilink6.exe
|
||||
# ADD BASE LINK32 cxcore.lib kernel32.lib user32.lib gdi32.lib comdlg32.lib advapi32.lib shell32.lib comctl32.lib vfw32.lib /nologo /dll /debug /machine:IX86 /nodefaultlib:"libmmd.lib" /out:"..\..\bin/highgui100.dll" /implib:"..\..\lib/highgui.lib" /libpath:"..\..\lib" /libpath:"..\_graphics\lib" /machine:AMD64
|
||||
# SUBTRACT BASE LINK32 /pdb:none
|
||||
# ADD LINK32 cxcore_64.lib zlib_64.lib libpng_64.lib libjpeg_64.lib libtiff_64.lib kernel32.lib user32.lib gdi32.lib comdlg32.lib advapi32.lib shell32.lib comctl32.lib vfw32.lib /nologo /dll /debug /machine:IX86 /nodefaultlib:"libmmd.lib" /out:"..\..\bin/highgui100_64.dll" /implib:"..\..\lib/highgui_64.lib" /libpath:"..\..\lib" /libpath:"..\_graphics\lib" /machine:AMD64
|
||||
# SUBTRACT LINK32 /pdb:none
|
||||
|
||||
!ELSEIF "$(CFG)" == "highgui - Win32 Debug64"
|
||||
|
||||
# PROP BASE Use_MFC 0
|
||||
# PROP BASE Use_Debug_Libraries 1
|
||||
# PROP BASE Output_Dir "highgui___Win32_Debug64"
|
||||
# PROP BASE Intermediate_Dir "highgui___Win32_Debug64"
|
||||
# PROP BASE Ignore_Export_Lib 0
|
||||
# PROP BASE Target_Dir ""
|
||||
# PROP Use_MFC 0
|
||||
# PROP Use_Debug_Libraries 1
|
||||
# PROP Output_Dir "..\..\_temp\highgui_Dbg64"
|
||||
# PROP Intermediate_Dir "..\..\_temp\highgui_Dbg64"
|
||||
# PROP Ignore_Export_Lib 0
|
||||
# PROP Target_Dir ""
|
||||
LIB32=link.exe -lib
|
||||
# ADD BASE CPP /nologo /MDd /W4 /Gm /Zi /Od /I "..\..\cxcore\include" /I "..\..\cv\include" /I ".\\" /I "..\_graphics\include" /D "_DEBUG" /D "WIN32" /D "_WINDOWS" /D "_MBCS" /D "CVAPI_EXPORTS" /D "HAVE_JPEG" /D "HAVE_PNG" /D "HAVE_TIFF" /FR /Yu"_highgui.h" /FD /GZ /c
|
||||
# ADD CPP /nologo /MDd /W4 /Gm /Zi /Od /I "..\..\cxcore\include" /I "..\..\cv\include" /I ".\\" /I "..\_graphics\include" /D "_WINDOWS" /D "_MBCS" /D "CVAPI_EXPORTS" /D "_DEBUG" /D "WIN32" /D "WIN64" /D "EM64T" /D "HAVE_JPEG" /D "HAVE_PNG" /D "HAVE_TIFF" /FR /Yu"_highgui.h" /FD /Wp64 /c
|
||||
# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32
|
||||
# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32
|
||||
# ADD BASE RSC /l 0x419 /d "_DEBUG"
|
||||
# ADD RSC /l 0x419 /d "_DEBUG"
|
||||
BSC32=bscmake.exe
|
||||
# ADD BASE BSC32 /nologo
|
||||
# ADD BSC32 /nologo
|
||||
LINK32=xilink6.exe
|
||||
# ADD BASE LINK32 cxcored.lib kernel32.lib user32.lib gdi32.lib comdlg32.lib advapi32.lib shell32.lib comctl32.lib vfw32.lib /nologo /dll /debug /machine:IX86 /nodefaultlib:"libmmdd.lib" /out:"..\..\bin/highgui100d.dll" /implib:"..\..\lib/highguid.lib" /pdbtype:sept /libpath:"..\..\lib" /libpath:"..\_graphics\lib" /machine:AMD64
|
||||
# SUBTRACT BASE LINK32 /pdb:none /nodefaultlib
|
||||
# ADD LINK32 cxcored_64.lib zlibd_64.lib libpngd_64.lib libjpegd_64.lib libtiffd_64.lib kernel32.lib user32.lib gdi32.lib comdlg32.lib advapi32.lib shell32.lib comctl32.lib vfw32.lib /nologo /dll /pdb:"..\..\bin/highgui100d_64.pdb" /debug /machine:IX86 /nodefaultlib:"libmmdd.lib" /out:"..\..\bin/highgui100d_64.dll" /implib:"..\..\lib/highguid_64.lib" /libpath:"..\..\lib" /libpath:"..\_graphics\lib" /machine:AMD64
|
||||
# SUBTRACT LINK32 /pdb:none
|
||||
|
||||
!ELSEIF "$(CFG)" == "highgui - Win32 Release64 Itanium"
|
||||
|
||||
# PROP BASE Use_MFC 0
|
||||
# PROP BASE Use_Debug_Libraries 0
|
||||
# PROP BASE Output_Dir "highgui___Win32_Release64_Itanium"
|
||||
# PROP BASE Intermediate_Dir "highgui___Win32_Release64_Itanium"
|
||||
# PROP BASE Ignore_Export_Lib 0
|
||||
# PROP BASE Target_Dir ""
|
||||
# PROP Use_MFC 0
|
||||
# PROP Use_Debug_Libraries 0
|
||||
# PROP Output_Dir "..\..\_temp\highgui_RlsI7"
|
||||
# PROP Intermediate_Dir "..\..\_temp\highgui_RlsI7"
|
||||
# PROP Ignore_Export_Lib 0
|
||||
# PROP Target_Dir ""
|
||||
LIB32=link.exe -lib
|
||||
# ADD BASE CPP /nologo /MD /W4 /Zi /O2 /I "..\..\cxcore\include" /I "..\..\cv\include" /I ".\\" /I "..\_graphics\include" /D "_WINDOWS" /D "_MBCS" /D "CVAPI_EXPORTS" /D "NDEBUG" /D "WIN32" /D "WIN64" /D "EM64T" /FR /Yu"_highgui.h" /FD /c
|
||||
# ADD CPP /nologo /MD /w /W0 /Zi /O2 /I "..\..\cxcore\include" /I "..\..\cv\include" /I ".\\" /I "..\_graphics\include" /D "_WINDOWS" /D "_MBCS" /D "CVAPI_EXPORTS" /D "NDEBUG" /D "WIN32" /D "WIN64" /D "HAVE_JPEG" /D "HAVE_PNG" /D "HAVE_TIFF" /FR /Yu"_highgui.h" /FD /c
|
||||
# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
|
||||
# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
|
||||
# ADD BASE RSC /l 0x419 /d "NDEBUG"
|
||||
# ADD RSC /l 0x419 /d "NDEBUG"
|
||||
BSC32=bscmake.exe
|
||||
# ADD BASE BSC32 /nologo
|
||||
# ADD BSC32 /nologo
|
||||
LINK32=xilink6.exe
|
||||
# ADD BASE LINK32 cxcore_i7.lib kernel32.lib user32.lib gdi32.lib comdlg32.lib advapi32.lib shell32.lib comctl32.lib vfw32.lib /nologo /dll /debug /machine:IX86 /nodefaultlib:"libmmd.lib" /out:"..\..\bin/highgui100_i7.dll" /implib:"..\..\lib/highgui_i7.lib" /libpath:"..\..\lib" /libpath:"..\_graphics\lib" /machine:IA64
|
||||
# SUBTRACT BASE LINK32 /pdb:none
|
||||
# ADD LINK32 cxcore_i7.lib zlib_i7.lib libpng_i7.lib libjpeg_i7.lib libtiff_i7.lib kernel32.lib user32.lib gdi32.lib comdlg32.lib advapi32.lib shell32.lib comctl32.lib vfw32.lib /nologo /dll /debug /machine:IX86 /out:"..\..\bin/highgui100_i7.dll" /implib:"..\..\lib/highgui_i7.lib" /libpath:"..\..\lib" /libpath:"..\_graphics\lib" /machine:IA64
|
||||
# SUBTRACT LINK32 /pdb:none
|
||||
|
||||
!ELSEIF "$(CFG)" == "highgui - Win32 Debug64 Itanium"
|
||||
|
||||
# PROP BASE Use_MFC 0
|
||||
# PROP BASE Use_Debug_Libraries 1
|
||||
# PROP BASE Output_Dir "highgui___Win32_Debug64_Itanium"
|
||||
# PROP BASE Intermediate_Dir "highgui___Win32_Debug64_Itanium"
|
||||
# PROP BASE Ignore_Export_Lib 0
|
||||
# PROP BASE Target_Dir ""
|
||||
# PROP Use_MFC 0
|
||||
# PROP Use_Debug_Libraries 1
|
||||
# PROP Output_Dir "..\..\_temp\highgui_DbgI7"
|
||||
# PROP Intermediate_Dir "..\..\_temp\highgui_DbgI7"
|
||||
# PROP Ignore_Export_Lib 0
|
||||
# PROP Target_Dir ""
|
||||
LIB32=link.exe -lib
|
||||
# ADD BASE CPP /nologo /MDd /W4 /Gm /Zi /Od /I "..\..\cxcore\include" /I "..\..\cv\include" /I ".\\" /I "..\_graphics\include" /D "_WINDOWS" /D "_MBCS" /D "CVAPI_EXPORTS" /D "_DEBUG" /D "WIN32" /D "WIN64" /D "EM64T" /FR /Yu"_highgui.h" /FD /Wp64 /c
|
||||
# ADD CPP /nologo /MDd /W3 /Gm /Zi /Od /I "..\..\cxcore\include" /I "..\..\cv\include" /I ".\\" /I "..\_graphics\include" /D "_WINDOWS" /D "_MBCS" /D "CVAPI_EXPORTS" /D "_DEBUG" /D "WIN32" /D "WIN64" /D "HAVE_JPEG" /D "HAVE_PNG" /D "HAVE_TIFF" /FR /Yu"_highgui.h" /FD /Qwd167 /c
|
||||
# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32
|
||||
# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32
|
||||
# ADD BASE RSC /l 0x419 /d "_DEBUG"
|
||||
# ADD RSC /l 0x419 /d "_DEBUG"
|
||||
BSC32=bscmake.exe
|
||||
# ADD BASE BSC32 /nologo
|
||||
# ADD BSC32 /nologo
|
||||
LINK32=xilink6.exe
|
||||
# ADD BASE LINK32 cxcored_i7.lib kernel32.lib user32.lib gdi32.lib comdlg32.lib advapi32.lib shell32.lib comctl32.lib vfw32.lib /nologo /dll /pdb:"..\..\bin/highgui100d_i7.pdb" /debug /machine:IX86 /nodefaultlib:"libmmdd.lib" /out:"..\..\bin/highgui100d_i7.dll" /implib:"..\..\lib/highguid_i7.lib" /libpath:"..\..\lib" /libpath:"..\_graphics\lib" /machine:IA64
|
||||
# SUBTRACT BASE LINK32 /pdb:none
|
||||
# ADD LINK32 cxcored_i7.lib zlibd_i7.lib libpngd_i7.lib libjpegd_i7.lib libtiffd_i7.lib kernel32.lib user32.lib gdi32.lib comdlg32.lib advapi32.lib shell32.lib comctl32.lib vfw32.lib /nologo /dll /pdb:"..\..\bin/highgui100d_i7.pdb" /debug /machine:IX86 /out:"..\..\bin/highgui100d_i7.dll" /implib:"..\..\lib/highguid_i7.lib" /libpath:"..\..\lib" /libpath:"..\_graphics\lib" /machine:IA64
|
||||
# SUBTRACT LINK32 /pdb:none
|
||||
|
||||
!ENDIF
|
||||
|
||||
# Begin Target
|
||||
|
||||
# Name "highgui - Win32 Release"
|
||||
# Name "highgui - Win32 Debug"
|
||||
# Name "highgui - Win32 Release64"
|
||||
# Name "highgui - Win32 Debug64"
|
||||
# Name "highgui - Win32 Release64 Itanium"
|
||||
# Name "highgui - Win32 Debug64 Itanium"
|
||||
# Begin Group "Source Files"
|
||||
|
||||
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
|
||||
# Begin Group "grfmts"
|
||||
|
||||
# PROP Default_Filter ""
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\bitstrm.cpp
|
||||
# ADD CPP /Yu"_highgui.h"
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\bitstrm.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\grfmt_base.cpp
|
||||
# ADD CPP /Yu"_highgui.h"
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\grfmt_base.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\grfmt_bmp.cpp
|
||||
# ADD CPP /Yu"_highgui.h"
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\grfmt_bmp.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\grfmt_exr.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\grfmt_exr.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\grfmt_jpeg.cpp
|
||||
# ADD CPP /Yu"_highgui.h"
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\grfmt_jpeg.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\grfmt_jpeg2000.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\grfmt_jpeg2000.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\grfmt_png.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\grfmt_png.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\grfmt_pxm.cpp
|
||||
# ADD CPP /Yu"_highgui.h"
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\grfmt_pxm.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\grfmt_sunras.cpp
|
||||
# ADD CPP /Yu"_highgui.h"
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\grfmt_sunras.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\grfmt_tiff.cpp
|
||||
# ADD CPP /Yu"_highgui.h"
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\grfmt_tiff.h
|
||||
# End Source File
|
||||
# End Group
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\cvcap.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\cvcap_cmu.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\cvcap_vfw.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\highgui.rc
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\image.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\loadsave.cpp
|
||||
# ADD CPP /Yu"_highgui.h"
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\precomp.cpp
|
||||
# ADD CPP /Yc"_highgui.h"
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\utils.cpp
|
||||
# ADD CPP /Yu"_highgui.h"
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\window_w32.cpp
|
||||
|
||||
!IF "$(CFG)" == "highgui - Win32 Release"
|
||||
|
||||
!ELSEIF "$(CFG)" == "highgui - Win32 Debug"
|
||||
|
||||
# ADD CPP /Yu
|
||||
|
||||
!ELSEIF "$(CFG)" == "highgui - Win32 Release64"
|
||||
|
||||
!ELSEIF "$(CFG)" == "highgui - Win32 Debug64"
|
||||
|
||||
# ADD BASE CPP /Yu
|
||||
# ADD CPP /Yu
|
||||
|
||||
!ELSEIF "$(CFG)" == "highgui - Win32 Release64 Itanium"
|
||||
|
||||
!ELSEIF "$(CFG)" == "highgui - Win32 Debug64 Itanium"
|
||||
|
||||
# ADD BASE CPP /Yu
|
||||
# ADD CPP /Yu
|
||||
|
||||
!ENDIF
|
||||
|
||||
# End Source File
|
||||
# End Group
|
||||
# Begin Group "Header Files"
|
||||
|
||||
# PROP Default_Filter "h;hpp;hxx;hm;inl"
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\_highgui.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\cvcap_cmu.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\cvcap_tyzx.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\grfmts.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\highgui.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\utils.h
|
||||
# End Source File
|
||||
# End Group
|
||||
# Begin Group "Resource Files"
|
||||
|
||||
# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
|
||||
# End Group
|
||||
# End Target
|
||||
# End Project
|
||||
@@ -0,0 +1,486 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// Intel License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000, Intel Corporation, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of Intel Corporation may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#ifndef _HIGH_GUI_
|
||||
#define _HIGH_GUI_
|
||||
|
||||
#ifndef SKIP_INCLUDES
|
||||
|
||||
#include "cxcore.h"
|
||||
#if defined WIN32 || defined WIN64
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
#else // SKIP_INCLUDES
|
||||
|
||||
#if defined WIN32 || defined WIN64
|
||||
#define CV_CDECL __cdecl
|
||||
#define CV_STDCALL __stdcall
|
||||
#else
|
||||
#define CV_CDECL
|
||||
#define CV_STDCALL
|
||||
#endif
|
||||
|
||||
#ifndef CV_EXTERN_C
|
||||
#ifdef __cplusplus
|
||||
#define CV_EXTERN_C extern "C"
|
||||
#define CV_DEFAULT(val) = val
|
||||
#else
|
||||
#define CV_EXTERN_C
|
||||
#define CV_DEFAULT(val)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef CV_EXTERN_C_FUNCPTR
|
||||
#ifdef __cplusplus
|
||||
#define CV_EXTERN_C_FUNCPTR(x) extern "C" { typedef x; }
|
||||
#else
|
||||
#define CV_EXTERN_C_FUNCPTR(x) typedef x
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef CV_INLINE
|
||||
#if defined __cplusplus
|
||||
#define CV_INLINE inline
|
||||
#elif (defined WIN32 || defined WIN64) && !defined __GNUC__
|
||||
#define CV_INLINE __inline
|
||||
#else
|
||||
#define CV_INLINE static
|
||||
#endif
|
||||
#endif /* CV_INLINE */
|
||||
|
||||
#if (defined WIN32 || defined WIN64) && defined CVAPI_EXPORTS
|
||||
#define CV_EXPORTS __declspec(dllexport)
|
||||
#else
|
||||
#define CV_EXPORTS
|
||||
#endif
|
||||
|
||||
#ifndef CVAPI
|
||||
#define CVAPI(rettype) CV_EXTERN_C CV_EXPORTS rettype CV_CDECL
|
||||
#endif
|
||||
|
||||
#endif // SKIP_INCLUDES
|
||||
|
||||
#if defined(_CH_)
|
||||
#pragma package <chopencv>
|
||||
#include <chdl.h>
|
||||
LOAD_CHDL(highgui)
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/****************************************************************************************\
|
||||
* Basic GUI functions *
|
||||
\****************************************************************************************/
|
||||
|
||||
/* this function is used to set some external parameters in case of X Window */
|
||||
CVAPI(int) cvInitSystem( int argc, char** argv );
|
||||
|
||||
CVAPI(int) cvStartWindowThread();
|
||||
|
||||
#define CV_WINDOW_AUTOSIZE 1
|
||||
/* create window */
|
||||
CVAPI(int) cvNamedWindow( const char* name, int flags CV_DEFAULT(CV_WINDOW_AUTOSIZE) );
|
||||
|
||||
/* display image within window (highgui windows remember their content) */
|
||||
CVAPI(void) cvShowImage( const char* name, const CvArr* image );
|
||||
|
||||
/* resize/move window */
|
||||
CVAPI(void) cvResizeWindow( const char* name, int width, int height );
|
||||
CVAPI(void) cvMoveWindow( const char* name, int x, int y );
|
||||
|
||||
|
||||
/* destroy window and all the trackers associated with it */
|
||||
CVAPI(void) cvDestroyWindow( const char* name );
|
||||
|
||||
CVAPI(void) cvDestroyAllWindows(void);
|
||||
|
||||
/* get native window handle (HWND in case of Win32 and Widget in case of X Window) */
|
||||
CVAPI(void*) cvGetWindowHandle( const char* name );
|
||||
|
||||
/* get name of highgui window given its native handle */
|
||||
CVAPI(const char*) cvGetWindowName( void* window_handle );
|
||||
|
||||
|
||||
typedef void (CV_CDECL *CvTrackbarCallback)(int pos);
|
||||
|
||||
/* create trackbar and display it on top of given window, set callback */
|
||||
CVAPI(int) cvCreateTrackbar( const char* trackbar_name, const char* window_name,
|
||||
int* value, int count, CvTrackbarCallback on_change );
|
||||
|
||||
/* retrieve or set trackbar position */
|
||||
CVAPI(int) cvGetTrackbarPos( const char* trackbar_name, const char* window_name );
|
||||
CVAPI(void) cvSetTrackbarPos( const char* trackbar_name, const char* window_name, int pos );
|
||||
|
||||
#define CV_EVENT_MOUSEMOVE 0
|
||||
#define CV_EVENT_LBUTTONDOWN 1
|
||||
#define CV_EVENT_RBUTTONDOWN 2
|
||||
#define CV_EVENT_MBUTTONDOWN 3
|
||||
#define CV_EVENT_LBUTTONUP 4
|
||||
#define CV_EVENT_RBUTTONUP 5
|
||||
#define CV_EVENT_MBUTTONUP 6
|
||||
#define CV_EVENT_LBUTTONDBLCLK 7
|
||||
#define CV_EVENT_RBUTTONDBLCLK 8
|
||||
#define CV_EVENT_MBUTTONDBLCLK 9
|
||||
|
||||
#define CV_EVENT_FLAG_LBUTTON 1
|
||||
#define CV_EVENT_FLAG_RBUTTON 2
|
||||
#define CV_EVENT_FLAG_MBUTTON 4
|
||||
#define CV_EVENT_FLAG_CTRLKEY 8
|
||||
#define CV_EVENT_FLAG_SHIFTKEY 16
|
||||
#define CV_EVENT_FLAG_ALTKEY 32
|
||||
|
||||
typedef void (CV_CDECL *CvMouseCallback )(int event, int x, int y, int flags, void* param);
|
||||
|
||||
/* assign callback for mouse events */
|
||||
CVAPI(void) cvSetMouseCallback( const char* window_name, CvMouseCallback on_mouse,
|
||||
void* param CV_DEFAULT(NULL));
|
||||
|
||||
/* 8bit, color or not */
|
||||
#define CV_LOAD_IMAGE_UNCHANGED -1
|
||||
/* 8bit, gray */
|
||||
#define CV_LOAD_IMAGE_GRAYSCALE 0
|
||||
/* ?, color */
|
||||
#define CV_LOAD_IMAGE_COLOR 1
|
||||
/* any depth, ? */
|
||||
#define CV_LOAD_IMAGE_ANYDEPTH 2
|
||||
/* ?, any color */
|
||||
#define CV_LOAD_IMAGE_ANYCOLOR 4
|
||||
|
||||
/* load image from file
|
||||
iscolor can be a combination of above flags where CV_LOAD_IMAGE_UNCHANGED
|
||||
overrides the other flags
|
||||
using CV_LOAD_IMAGE_ANYCOLOR alone is equivalent to CV_LOAD_IMAGE_UNCHANGED
|
||||
unless CV_LOAD_IMAGE_ANYDEPTH is specified images are converted to 8bit
|
||||
*/
|
||||
CVAPI(IplImage*) cvLoadImage( const char* filename, int iscolor CV_DEFAULT(CV_LOAD_IMAGE_COLOR));
|
||||
CVAPI(CvMat*) cvLoadImageM( const char* filename, int iscolor CV_DEFAULT(CV_LOAD_IMAGE_COLOR));
|
||||
|
||||
/* save image to file */
|
||||
CVAPI(int) cvSaveImage( const char* filename, const CvArr* image );
|
||||
|
||||
#define CV_CVTIMG_FLIP 1
|
||||
#define CV_CVTIMG_SWAP_RB 2
|
||||
/* utility function: convert one image to another with optional vertical flip */
|
||||
CVAPI(void) cvConvertImage( const CvArr* src, CvArr* dst, int flags CV_DEFAULT(0));
|
||||
|
||||
/* wait for key event infinitely (delay<=0) or for "delay" milliseconds */
|
||||
CVAPI(int) cvWaitKey(int delay CV_DEFAULT(0));
|
||||
|
||||
|
||||
/****************************************************************************************\
|
||||
* Working with Video Files and Cameras *
|
||||
\****************************************************************************************/
|
||||
|
||||
/* "black box" capture structure */
|
||||
typedef struct CvCapture CvCapture;
|
||||
|
||||
/* start capturing frames from video file */
|
||||
CVAPI(CvCapture*) cvCreateFileCapture( const char* filename );
|
||||
|
||||
#define CV_CAP_ANY 0 // autodetect
|
||||
|
||||
#define CV_CAP_MIL 100 // MIL proprietary drivers
|
||||
|
||||
#define CV_CAP_VFW 200 // platform native
|
||||
#define CV_CAP_V4L 200
|
||||
#define CV_CAP_V4L2 200
|
||||
|
||||
#define CV_CAP_FIREWARE 300 // IEEE 1394 drivers
|
||||
#define CV_CAP_IEEE1394 300
|
||||
#define CV_CAP_DC1394 300
|
||||
#define CV_CAP_CMU1394 300
|
||||
|
||||
#define CV_CAP_STEREO 400 // TYZX proprietary drivers
|
||||
#define CV_CAP_TYZX 400
|
||||
#define CV_TYZX_LEFT 400
|
||||
#define CV_TYZX_RIGHT 401
|
||||
#define CV_TYZX_COLOR 402
|
||||
#define CV_TYZX_Z 403
|
||||
|
||||
#define CV_CAP_QT 500 // QuickTime
|
||||
|
||||
/* start capturing frames from camera: index = camera_index + domain_offset (CV_CAP_*) */
|
||||
CVAPI(CvCapture*) cvCreateCameraCapture( int index );
|
||||
|
||||
/* grab a frame, return 1 on success, 0 on fail.
|
||||
this function is thought to be fast */
|
||||
CVAPI(int) cvGrabFrame( CvCapture* capture );
|
||||
|
||||
/* get the frame grabbed with cvGrabFrame(..)
|
||||
This function may apply some frame processing like
|
||||
frame decompression, flipping etc.
|
||||
!!!DO NOT RELEASE or MODIFY the retrieved frame!!! */
|
||||
CVAPI(IplImage*) cvRetrieveFrame( CvCapture* capture );
|
||||
|
||||
/* Just a combination of cvGrabFrame and cvRetrieveFrame
|
||||
!!!DO NOT RELEASE or MODIFY the retrieved frame!!! */
|
||||
CVAPI(IplImage*) cvQueryFrame( CvCapture* capture );
|
||||
|
||||
/* stop capturing/reading and free resources */
|
||||
CVAPI(void) cvReleaseCapture( CvCapture** capture );
|
||||
|
||||
#define CV_CAP_PROP_POS_MSEC 0
|
||||
#define CV_CAP_PROP_POS_FRAMES 1
|
||||
#define CV_CAP_PROP_POS_AVI_RATIO 2
|
||||
#define CV_CAP_PROP_FRAME_WIDTH 3
|
||||
#define CV_CAP_PROP_FRAME_HEIGHT 4
|
||||
#define CV_CAP_PROP_FPS 5
|
||||
#define CV_CAP_PROP_FOURCC 6
|
||||
#define CV_CAP_PROP_FRAME_COUNT 7
|
||||
#define CV_CAP_PROP_FORMAT 8
|
||||
#define CV_CAP_PROP_MODE 9
|
||||
#define CV_CAP_PROP_BRIGHTNESS 10
|
||||
#define CV_CAP_PROP_CONTRAST 11
|
||||
#define CV_CAP_PROP_SATURATION 12
|
||||
#define CV_CAP_PROP_HUE 13
|
||||
#define CV_CAP_PROP_GAIN 14
|
||||
#define CV_CAP_PROP_CONVERT_RGB 15
|
||||
|
||||
|
||||
/* retrieve or set capture properties */
|
||||
CVAPI(double) cvGetCaptureProperty( CvCapture* capture, int property_id );
|
||||
CVAPI(int) cvSetCaptureProperty( CvCapture* capture, int property_id, double value );
|
||||
|
||||
/* "black box" video file writer structure */
|
||||
typedef struct CvVideoWriter CvVideoWriter;
|
||||
|
||||
#define CV_FOURCC(c1,c2,c3,c4) \
|
||||
(((c1)&255) + (((c2)&255)<<8) + (((c3)&255)<<16) + (((c4)&255)<<24))
|
||||
|
||||
/* initialize video file writer */
|
||||
CVAPI(CvVideoWriter*) cvCreateVideoWriter( const char* filename, int fourcc,
|
||||
double fps, CvSize frame_size,
|
||||
int is_color CV_DEFAULT(1));
|
||||
|
||||
/* write frame to video file */
|
||||
CVAPI(int) cvWriteFrame( CvVideoWriter* writer, const IplImage* image );
|
||||
|
||||
/* close video file writer */
|
||||
CVAPI(void) cvReleaseVideoWriter( CvVideoWriter** writer );
|
||||
|
||||
/****************************************************************************************\
|
||||
* Obsolete functions/synonyms *
|
||||
\****************************************************************************************/
|
||||
|
||||
#ifndef HIGHGUI_NO_BACKWARD_COMPATIBILITY
|
||||
#define HIGHGUI_BACKWARD_COMPATIBILITY
|
||||
#endif
|
||||
|
||||
#ifdef HIGHGUI_BACKWARD_COMPATIBILITY
|
||||
|
||||
#define cvCaptureFromFile cvCreateFileCapture
|
||||
#define cvCaptureFromCAM cvCreateCameraCapture
|
||||
#define cvCaptureFromAVI cvCaptureFromFile
|
||||
#define cvCreateAVIWriter cvCreateVideoWriter
|
||||
#define cvWriteToAVI cvWriteFrame
|
||||
#define cvAddSearchPath(path)
|
||||
#define cvvInitSystem cvInitSystem
|
||||
#define cvvNamedWindow cvNamedWindow
|
||||
#define cvvShowImage cvShowImage
|
||||
#define cvvResizeWindow cvResizeWindow
|
||||
#define cvvDestroyWindow cvDestroyWindow
|
||||
#define cvvCreateTrackbar cvCreateTrackbar
|
||||
#define cvvLoadImage(name) cvLoadImage((name),1)
|
||||
#define cvvSaveImage cvSaveImage
|
||||
#define cvvAddSearchPath cvAddSearchPath
|
||||
#define cvvWaitKey(name) cvWaitKey(0)
|
||||
#define cvvWaitKeyEx(name,delay) cvWaitKey(delay)
|
||||
#define cvvConvertImage cvConvertImage
|
||||
#define HG_AUTOSIZE CV_WINDOW_AUTOSIZE
|
||||
#define set_preprocess_func cvSetPreprocessFuncWin32
|
||||
#define set_postprocess_func cvSetPostprocessFuncWin32
|
||||
|
||||
#ifdef WIN32
|
||||
|
||||
typedef int (CV_CDECL * CvWin32WindowCallback)(HWND, UINT, WPARAM, LPARAM, int*);
|
||||
CVAPI(void) cvSetPreprocessFuncWin32( CvWin32WindowCallback on_preprocess );
|
||||
CVAPI(void) cvSetPostprocessFuncWin32( CvWin32WindowCallback on_postprocess );
|
||||
|
||||
CV_INLINE int iplWidth( const IplImage* img );
|
||||
CV_INLINE int iplWidth( const IplImage* img )
|
||||
{
|
||||
return !img ? 0 : !img->roi ? img->width : img->roi->width;
|
||||
}
|
||||
|
||||
CV_INLINE int iplHeight( const IplImage* img );
|
||||
CV_INLINE int iplHeight( const IplImage* img )
|
||||
{
|
||||
return !img ? 0 : !img->roi ? img->height : img->roi->height;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#endif /* obsolete functions */
|
||||
|
||||
/* For use with Win32 */
|
||||
#ifdef WIN32
|
||||
|
||||
CV_INLINE RECT NormalizeRect( RECT r );
|
||||
CV_INLINE RECT NormalizeRect( RECT r )
|
||||
{
|
||||
int t;
|
||||
|
||||
if( r.left > r.right )
|
||||
{
|
||||
t = r.left;
|
||||
r.left = r.right;
|
||||
r.right = t;
|
||||
}
|
||||
|
||||
if( r.top > r.bottom )
|
||||
{
|
||||
t = r.top;
|
||||
r.top = r.bottom;
|
||||
r.bottom = t;
|
||||
}
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
CV_INLINE CvRect RectToCvRect( RECT sr );
|
||||
CV_INLINE CvRect RectToCvRect( RECT sr )
|
||||
{
|
||||
sr = NormalizeRect( sr );
|
||||
return cvRect( sr.left, sr.top, sr.right - sr.left, sr.bottom - sr.top );
|
||||
}
|
||||
|
||||
CV_INLINE RECT CvRectToRect( CvRect sr );
|
||||
CV_INLINE RECT CvRectToRect( CvRect sr )
|
||||
{
|
||||
RECT dr;
|
||||
dr.left = sr.x;
|
||||
dr.top = sr.y;
|
||||
dr.right = sr.x + sr.width;
|
||||
dr.bottom = sr.y + sr.height;
|
||||
|
||||
return dr;
|
||||
}
|
||||
|
||||
CV_INLINE IplROI RectToROI( RECT r );
|
||||
CV_INLINE IplROI RectToROI( RECT r )
|
||||
{
|
||||
IplROI roi;
|
||||
r = NormalizeRect( r );
|
||||
roi.xOffset = r.left;
|
||||
roi.yOffset = r.top;
|
||||
roi.width = r.right - r.left;
|
||||
roi.height = r.bottom - r.top;
|
||||
roi.coi = 0;
|
||||
|
||||
return roi;
|
||||
}
|
||||
|
||||
#endif /* WIN32 */
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* end of extern "C" */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
|
||||
#if defined __cplusplus && (!defined WIN32 || !defined (__GNUC__))
|
||||
|
||||
#define CImage CvvImage
|
||||
|
||||
/* CvvImage class definition */
|
||||
class CV_EXPORTS CvvImage
|
||||
{
|
||||
public:
|
||||
CvvImage();
|
||||
virtual ~CvvImage();
|
||||
|
||||
/* Create image (BGR or grayscale) */
|
||||
virtual bool Create( int width, int height, int bits_per_pixel, int image_origin = 0 );
|
||||
|
||||
/* Load image from specified file */
|
||||
virtual bool Load( const char* filename, int desired_color = 1 );
|
||||
|
||||
/* Load rectangle from the file */
|
||||
virtual bool LoadRect( const char* filename,
|
||||
int desired_color, CvRect r );
|
||||
|
||||
#ifdef WIN32
|
||||
virtual bool LoadRect( const char* filename,
|
||||
int desired_color, RECT r )
|
||||
{
|
||||
return LoadRect( filename, desired_color,
|
||||
cvRect( r.left, r.top, r.right - r.left, r.bottom - r.top ));
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Save entire image to specified file. */
|
||||
virtual bool Save( const char* filename );
|
||||
|
||||
/* Get copy of input image ROI */
|
||||
virtual void CopyOf( CvvImage& image, int desired_color = -1 );
|
||||
virtual void CopyOf( IplImage* img, int desired_color = -1 );
|
||||
|
||||
IplImage* GetImage() { return m_img; };
|
||||
virtual void Destroy(void);
|
||||
|
||||
/* width and height of ROI */
|
||||
int Width() { return !m_img ? 0 : !m_img->roi ? m_img->width : m_img->roi->width; };
|
||||
int Height() { return !m_img ? 0 : !m_img->roi ? m_img->height : m_img->roi->height;};
|
||||
int Bpp() { return m_img ? (m_img->depth & 255)*m_img->nChannels : 0; };
|
||||
|
||||
virtual void Fill( int color );
|
||||
|
||||
/* draw to highgui window */
|
||||
virtual void Show( const char* window );
|
||||
|
||||
#ifdef WIN32
|
||||
/* draw part of image to the specified DC */
|
||||
virtual void Show( HDC dc, int x, int y, int width, int height,
|
||||
int from_x = 0, int from_y = 0 );
|
||||
/* draw the current image ROI to the specified rectangle of the destination DC */
|
||||
virtual void DrawToHDC( HDC hDCDst, RECT* pDstRect );
|
||||
#endif
|
||||
|
||||
protected:
|
||||
|
||||
IplImage* m_img;
|
||||
};
|
||||
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* _HIGH_GUI_ */
|
||||
@@ -0,0 +1,121 @@
|
||||
//Microsoft Developer Studio generated resource script.
|
||||
//
|
||||
#include "resource.h"
|
||||
|
||||
#define APSTUDIO_READONLY_SYMBOLS
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Generated from the TEXTINCLUDE 2 resource.
|
||||
//
|
||||
#include "afxres.h"
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
#undef APSTUDIO_READONLY_SYMBOLS
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Russian resources
|
||||
|
||||
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_RUS)
|
||||
#ifdef _WIN32
|
||||
LANGUAGE LANG_RUSSIAN, SUBLANG_DEFAULT
|
||||
#pragma code_page(1251)
|
||||
#endif //_WIN32
|
||||
|
||||
#ifdef APSTUDIO_INVOKED
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// TEXTINCLUDE
|
||||
//
|
||||
|
||||
1 TEXTINCLUDE DISCARDABLE
|
||||
BEGIN
|
||||
"resource.h\0"
|
||||
END
|
||||
|
||||
2 TEXTINCLUDE DISCARDABLE
|
||||
BEGIN
|
||||
"#include ""afxres.h""\r\n"
|
||||
"\0"
|
||||
END
|
||||
|
||||
3 TEXTINCLUDE DISCARDABLE
|
||||
BEGIN
|
||||
"\r\n"
|
||||
"\0"
|
||||
END
|
||||
|
||||
#endif // APSTUDIO_INVOKED
|
||||
|
||||
#endif // Russian resources
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// English (U.S.) resources
|
||||
|
||||
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
|
||||
#ifdef _WIN32
|
||||
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
|
||||
#pragma code_page(1252)
|
||||
#endif //_WIN32
|
||||
|
||||
#ifndef _MAC
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Version
|
||||
//
|
||||
|
||||
VS_VERSION_INFO VERSIONINFO
|
||||
FILEVERSION 1,0,0,1
|
||||
PRODUCTVERSION 1,0,0,1
|
||||
FILEFLAGSMASK 0x3fL
|
||||
#ifdef _DEBUG
|
||||
FILEFLAGS 0x1L
|
||||
#else
|
||||
FILEFLAGS 0x0L
|
||||
#endif
|
||||
FILEOS 0x40004L
|
||||
FILETYPE 0x2L
|
||||
FILESUBTYPE 0x0L
|
||||
BEGIN
|
||||
BLOCK "StringFileInfo"
|
||||
BEGIN
|
||||
BLOCK "040904b0"
|
||||
BEGIN
|
||||
VALUE "Comments", "Intel® Open Source Computer Vision Library: The GUI & Video part\0"
|
||||
VALUE "CompanyName", "Intel Corporation\0"
|
||||
VALUE "FileDescription", "Small GUI & Video library for OpenCV samples\0"
|
||||
VALUE "FileVersion", "1, 0, 0, 1\0"
|
||||
VALUE "InternalName", "highgui100.dll\0"
|
||||
VALUE "LegalCopyright", "Copyright © 2002-2006\0"
|
||||
VALUE "LegalTrademarks", "\0"
|
||||
VALUE "OriginalFilename", "highgui100.dll\0"
|
||||
VALUE "PrivateBuild", "\0"
|
||||
VALUE "ProductName", "Intel® Open Source Computer Vision Library.\0"
|
||||
VALUE "ProductVersion", "1, 0, 0, 1\0"
|
||||
VALUE "SpecialBuild", "\0"
|
||||
END
|
||||
END
|
||||
BLOCK "VarFileInfo"
|
||||
BEGIN
|
||||
VALUE "Translation", 0x409, 1200
|
||||
END
|
||||
END
|
||||
|
||||
#endif // !_MAC
|
||||
|
||||
#endif // English (U.S.) resources
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
|
||||
#ifndef APSTUDIO_INVOKED
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Generated from the TEXTINCLUDE 3 resource.
|
||||
//
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
#endif // not APSTUDIO_INVOKED
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,285 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// Intel License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000, Intel Corporation, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of Intel Corporation may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
//
|
||||
// Image.cpp: implementation of the CvvImage class.
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "_highgui.h"
|
||||
|
||||
#if defined __cplusplus && (!defined WIN32 || !defined __GNUC__)
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// Construction/Destruction
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
CvvImage::CvvImage()
|
||||
{
|
||||
m_img = 0;
|
||||
}
|
||||
|
||||
void CvvImage::Destroy()
|
||||
{
|
||||
cvReleaseImage( &m_img );
|
||||
}
|
||||
|
||||
CvvImage::~CvvImage()
|
||||
{
|
||||
Destroy();
|
||||
}
|
||||
|
||||
bool CvvImage::Create( int w, int h, int bpp, int origin )
|
||||
{
|
||||
const unsigned max_img_size = 10000;
|
||||
|
||||
if( (bpp != 8 && bpp != 24 && bpp != 32) ||
|
||||
(unsigned)w >= max_img_size || (unsigned)h >= max_img_size ||
|
||||
(origin != IPL_ORIGIN_TL && origin != IPL_ORIGIN_BL))
|
||||
{
|
||||
assert(0); // most probably, it is a programming error
|
||||
return false;
|
||||
}
|
||||
|
||||
if( !m_img || Bpp() != bpp || m_img->width != w || m_img->height != h )
|
||||
{
|
||||
if( m_img && m_img->nSize == sizeof(IplImage))
|
||||
Destroy();
|
||||
|
||||
/* prepare IPL header */
|
||||
m_img = cvCreateImage( cvSize( w, h ), IPL_DEPTH_8U, bpp/8 );
|
||||
}
|
||||
|
||||
if( m_img )
|
||||
m_img->origin = origin == 0 ? IPL_ORIGIN_TL : IPL_ORIGIN_BL;
|
||||
|
||||
return m_img != 0;
|
||||
}
|
||||
|
||||
void CvvImage::CopyOf( CvvImage& image, int desired_color )
|
||||
{
|
||||
IplImage* img = image.GetImage();
|
||||
if( img )
|
||||
{
|
||||
CopyOf( img, desired_color );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#define HG_IS_IMAGE(img) \
|
||||
((img) != 0 && ((const IplImage*)(img))->nSize == sizeof(IplImage) && \
|
||||
((IplImage*)img)->imageData != 0)
|
||||
|
||||
|
||||
void CvvImage::CopyOf( IplImage* img, int desired_color )
|
||||
{
|
||||
if( HG_IS_IMAGE(img) )
|
||||
{
|
||||
int color = desired_color;
|
||||
CvSize size = cvGetSize( img );
|
||||
|
||||
if( color < 0 )
|
||||
color = img->nChannels > 1;
|
||||
|
||||
if( Create( size.width, size.height,
|
||||
(!color ? 1 : img->nChannels > 1 ? img->nChannels : 3)*8,
|
||||
img->origin ))
|
||||
{
|
||||
cvConvertImage( img, m_img, 0 );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool CvvImage::Load( const char* filename, int desired_color )
|
||||
{
|
||||
IplImage* img = cvLoadImage( filename, desired_color );
|
||||
if( !img )
|
||||
return false;
|
||||
|
||||
CopyOf( img, desired_color );
|
||||
cvReleaseImage( &img );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool CvvImage::LoadRect( const char* filename,
|
||||
int desired_color, CvRect r )
|
||||
{
|
||||
if( r.width < 0 || r.height < 0 ) return false;
|
||||
|
||||
IplImage* img = cvLoadImage( filename, desired_color );
|
||||
if( !img )
|
||||
return false;
|
||||
|
||||
if( r.width == 0 || r.height == 0 )
|
||||
{
|
||||
r.width = img->width;
|
||||
r.height = img->height;
|
||||
r.x = r.y = 0;
|
||||
}
|
||||
|
||||
if( r.x > img->width || r.y > img->height ||
|
||||
r.x + r.width < 0 || r.y + r.height < 0 )
|
||||
{
|
||||
cvReleaseImage( &img );
|
||||
return false;
|
||||
}
|
||||
|
||||
/* truncate r to source image */
|
||||
if( r.x < 0 )
|
||||
{
|
||||
r.width += r.x;
|
||||
r.x = 0;
|
||||
}
|
||||
if( r.y < 0 )
|
||||
{
|
||||
r.height += r.y;
|
||||
r.y = 0;
|
||||
}
|
||||
|
||||
if( r.x + r.width > img->width )
|
||||
r.width = img->width - r.x;
|
||||
|
||||
if( r.y + r.height > img->height )
|
||||
r.height = img->height - r.y;
|
||||
|
||||
cvSetImageROI( img, r );
|
||||
CopyOf( img, desired_color );
|
||||
|
||||
cvReleaseImage( &img );
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool CvvImage::Save( const char* filename )
|
||||
{
|
||||
if( !m_img )
|
||||
return false;
|
||||
cvSaveImage( filename, m_img );
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void CvvImage::Show( const char* window )
|
||||
{
|
||||
if( m_img )
|
||||
cvShowImage( window, m_img );
|
||||
}
|
||||
|
||||
|
||||
#ifdef WIN32
|
||||
|
||||
void CvvImage::Show( HDC dc, int x, int y, int w, int h, int from_x, int from_y )
|
||||
{
|
||||
if( m_img && m_img->depth == IPL_DEPTH_8U )
|
||||
{
|
||||
uchar buffer[sizeof(BITMAPINFOHEADER) + 1024];
|
||||
BITMAPINFO* bmi = (BITMAPINFO*)buffer;
|
||||
int bmp_w = m_img->width, bmp_h = m_img->height;
|
||||
|
||||
FillBitmapInfo( bmi, bmp_w, bmp_h, Bpp(), m_img->origin );
|
||||
|
||||
from_x = MIN( MAX( from_x, 0 ), bmp_w - 1 );
|
||||
from_y = MIN( MAX( from_y, 0 ), bmp_h - 1 );
|
||||
|
||||
int sw = MAX( MIN( bmp_w - from_x, w ), 0 );
|
||||
int sh = MAX( MIN( bmp_h - from_y, h ), 0 );
|
||||
|
||||
SetDIBitsToDevice(
|
||||
dc, x, y, sw, sh, from_x, from_y, from_y, sh,
|
||||
m_img->imageData + from_y*m_img->widthStep,
|
||||
bmi, DIB_RGB_COLORS );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void CImage::DrawToHDC( HDC hDCDst, RECT* pDstRect )
|
||||
{
|
||||
if( pDstRect && m_img && m_img->depth == IPL_DEPTH_8U && m_img->imageData )
|
||||
{
|
||||
uchar buffer[sizeof(BITMAPINFOHEADER) + 1024];
|
||||
BITMAPINFO* bmi = (BITMAPINFO*)buffer;
|
||||
int bmp_w = m_img->width, bmp_h = m_img->height;
|
||||
|
||||
CvRect roi = cvGetImageROI( m_img );
|
||||
CvRect dst = RectToCvRect( *pDstRect );
|
||||
|
||||
if( roi.width == dst.width && roi.height == dst.height )
|
||||
{
|
||||
Show( hDCDst, dst.x, dst.y, dst.width, dst.height, roi.x, roi.y );
|
||||
return;
|
||||
}
|
||||
|
||||
if( roi.width > dst.width )
|
||||
{
|
||||
SetStretchBltMode(
|
||||
hDCDst, // handle to device context
|
||||
HALFTONE );
|
||||
}
|
||||
else
|
||||
{
|
||||
SetStretchBltMode(
|
||||
hDCDst, // handle to device context
|
||||
COLORONCOLOR );
|
||||
}
|
||||
|
||||
FillBitmapInfo( bmi, bmp_w, bmp_h, Bpp(), m_img->origin );
|
||||
|
||||
::StretchDIBits(
|
||||
hDCDst,
|
||||
dst.x, dst.y, dst.width, dst.height,
|
||||
roi.x, roi.y, roi.width, roi.height,
|
||||
m_img->imageData, bmi, DIB_RGB_COLORS, SRCCOPY );
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
void CvvImage::Fill( int color )
|
||||
{
|
||||
cvSet( m_img, cvScalar(color&255,(color>>8)&255,(color>>16)&255,(color>>24)&255) );
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/* End of file. */
|
||||
@@ -0,0 +1,531 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// Intel License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000, Intel Corporation, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of Intel Corporation may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
//
|
||||
// Loading and saving IPL images.
|
||||
//
|
||||
|
||||
#include "_highgui.h"
|
||||
#include "grfmts.h"
|
||||
|
||||
#if 0
|
||||
/****************************************************************************************\
|
||||
* Path class (list of search folders) *
|
||||
\****************************************************************************************/
|
||||
|
||||
class CvFilePath
|
||||
{
|
||||
public:
|
||||
CvFilePath();
|
||||
~CvFilePath();
|
||||
|
||||
// preprocess folder or file name - calculate its length,
|
||||
// check for invalid symbols in the name and substitute
|
||||
// all backslashes with simple slashes.
|
||||
// the result is put into the specified buffer
|
||||
static int Preprocess( const char* filename, char* buffer );
|
||||
|
||||
// add folder to the path
|
||||
bool Add( const char* path );
|
||||
|
||||
// clear the path
|
||||
void Clear();
|
||||
|
||||
// return the path - string, where folders are separated by ';'
|
||||
const char* Get() const { return m_path; };
|
||||
|
||||
// find the file in the path
|
||||
const char* Find( const char* filename, char* buffer ) const;
|
||||
|
||||
// return the first folder from the path
|
||||
// the returned string is not terminated by '\0'!!!
|
||||
// its length is returned via len parameter
|
||||
const char* First( int& len ) const;
|
||||
|
||||
// return the folder, next in the path after the specified folder.
|
||||
// see also note to First() method
|
||||
const char* Next( const char* folder, int& len ) const;
|
||||
|
||||
protected:
|
||||
|
||||
char* m_path;
|
||||
int m_maxsize;
|
||||
int m_len;
|
||||
};
|
||||
|
||||
|
||||
void CvFilePath::Clear()
|
||||
{
|
||||
delete[] m_path;
|
||||
m_maxsize = m_len = 0;
|
||||
}
|
||||
|
||||
|
||||
CvFilePath::CvFilePath()
|
||||
{
|
||||
m_path = 0;
|
||||
m_maxsize = m_len = 0;
|
||||
}
|
||||
|
||||
|
||||
CvFilePath::~CvFilePath()
|
||||
{
|
||||
Clear();
|
||||
}
|
||||
|
||||
|
||||
bool CvFilePath::Add( const char* path )
|
||||
{
|
||||
char buffer[_MAX_PATH + 1];
|
||||
int len = Preprocess( path, buffer );
|
||||
|
||||
if( len < 0 )
|
||||
return false;
|
||||
|
||||
if( m_len + len + 3 // +1 for one more ';',
|
||||
// another +1 for possible additional '/',
|
||||
// and the last +1 is for '\0'
|
||||
> m_maxsize )
|
||||
{
|
||||
int new_size = (m_len + len + 3 + 1023) & -1024;
|
||||
char* new_path = new char[new_size];
|
||||
|
||||
if( m_path )
|
||||
{
|
||||
memcpy( new_path, m_path, m_len );
|
||||
delete[] m_path;
|
||||
}
|
||||
|
||||
m_path = new_path;
|
||||
m_maxsize = new_size;
|
||||
}
|
||||
|
||||
m_path[m_len++] = ';';
|
||||
memcpy( m_path + m_len, buffer, len );
|
||||
m_len += len;
|
||||
|
||||
if( m_path[m_len] != '/' )
|
||||
m_path[m_len++] = '/';
|
||||
|
||||
m_path[m_len] = '\0'; // '\0' is not counted in m_len.
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
const char* CvFilePath::First( int& len ) const
|
||||
{
|
||||
const char* path = (const char*)(m_path ? m_path : "");
|
||||
const char* path_end = path;
|
||||
|
||||
while( *path_end && *path_end != ';' )
|
||||
path_end++;
|
||||
|
||||
len = path_end - path;
|
||||
return path;
|
||||
}
|
||||
|
||||
|
||||
const char* CvFilePath::Next( const char* folder, int& len ) const
|
||||
{
|
||||
if( !folder || folder < m_path || folder >= m_path + m_len )
|
||||
return 0;
|
||||
|
||||
folder = strchr( folder, ';' );
|
||||
if( folder )
|
||||
{
|
||||
const char* folder_end = ++folder;
|
||||
while( *folder_end && *folder_end != ';' )
|
||||
folder_end++;
|
||||
|
||||
len = folder_end - folder;
|
||||
}
|
||||
|
||||
return folder;
|
||||
}
|
||||
|
||||
|
||||
const char* CvFilePath::Find( const char* filename, char* buffer ) const
|
||||
{
|
||||
char path0[_MAX_PATH + 1];
|
||||
int len = Preprocess( filename, path0 );
|
||||
int folder_len = 0;
|
||||
const char* folder = First( folder_len );
|
||||
char* name_only = 0;
|
||||
char* name = path0;
|
||||
FILE* f = 0;
|
||||
|
||||
if( len < 0 )
|
||||
return 0;
|
||||
|
||||
do
|
||||
{
|
||||
if( folder_len + len <= _MAX_PATH )
|
||||
{
|
||||
memcpy( buffer, folder, folder_len );
|
||||
strcpy( buffer + folder_len, name );
|
||||
|
||||
f = fopen( buffer, "rb" );
|
||||
if( f )
|
||||
break;
|
||||
}
|
||||
|
||||
if( name != name_only )
|
||||
{
|
||||
name_only = strrchr( path0, '/' );
|
||||
if( !name_only )
|
||||
name_only = path0;
|
||||
else
|
||||
name_only++;
|
||||
len = strlen( name_only );
|
||||
name = name_only;
|
||||
}
|
||||
}
|
||||
while( (folder = Next( folder, folder_len )) != 0 );
|
||||
|
||||
filename = 0;
|
||||
|
||||
if( f )
|
||||
{
|
||||
filename = (const char*)buffer;
|
||||
fclose(f);
|
||||
}
|
||||
|
||||
return filename;
|
||||
}
|
||||
|
||||
|
||||
int CvFilePath::Preprocess( const char* str, char* buffer )
|
||||
{
|
||||
int i;
|
||||
|
||||
if( !str || !buffer )
|
||||
return -1;
|
||||
|
||||
for( i = 0; i <= _MAX_PATH; i++ )
|
||||
{
|
||||
buffer[i] = str[i];
|
||||
|
||||
if( isalnum(str[i])) // fast check to skip most of characters
|
||||
continue;
|
||||
|
||||
if( str[i] == '\0' )
|
||||
break;
|
||||
|
||||
if( str[i] == '\\' ) // convert back slashes to simple slashes
|
||||
// (for Win32-*NIX compatibility)
|
||||
buffer[i] = '/';
|
||||
|
||||
if (str[i] == '*' || str[i] == '?' || str[i] == '\"' ||
|
||||
str[i] == '>' || str[i] == '<' ||
|
||||
str[i] == ';' || /* used as a separator in the path */
|
||||
#ifndef WIN32
|
||||
str[i] == ',' || str[i] == '%' ||
|
||||
#endif
|
||||
str[i] == '|')
|
||||
return -1;
|
||||
}
|
||||
|
||||
return i <= _MAX_PATH ? i : -1;
|
||||
}
|
||||
#endif
|
||||
|
||||
/****************************************************************************************\
|
||||
* Image Readers & Writers Class *
|
||||
\****************************************************************************************/
|
||||
|
||||
class CvImageFilters
|
||||
{
|
||||
public:
|
||||
|
||||
CvImageFilters();
|
||||
~CvImageFilters();
|
||||
|
||||
GrFmtReader* FindReader( const char* filename ) const;
|
||||
GrFmtWriter* FindWriter( const char* filename ) const;
|
||||
|
||||
//const CvFilePath& Path() const { return (const CvFilePath&)m_path; };
|
||||
//CvFilePath& Path() { return m_path; };
|
||||
|
||||
protected:
|
||||
|
||||
GrFmtFactoriesList* m_factories;
|
||||
};
|
||||
|
||||
|
||||
CvImageFilters::CvImageFilters()
|
||||
{
|
||||
m_factories = new GrFmtFactoriesList;
|
||||
|
||||
m_factories->AddFactory( new GrFmtBmp() );
|
||||
m_factories->AddFactory( new GrFmtJpeg() );
|
||||
m_factories->AddFactory( new GrFmtSunRaster() );
|
||||
m_factories->AddFactory( new GrFmtPxM() );
|
||||
m_factories->AddFactory( new GrFmtTiff() );
|
||||
#ifdef HAVE_PNG
|
||||
m_factories->AddFactory( new GrFmtPng() );
|
||||
#endif
|
||||
#ifdef HAVE_JASPER
|
||||
m_factories->AddFactory( new GrFmtJpeg2000() );
|
||||
#endif
|
||||
#ifdef HAVE_ILMIMF
|
||||
m_factories->AddFactory( new GrFmtExr() );
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
CvImageFilters::~CvImageFilters()
|
||||
{
|
||||
delete m_factories;
|
||||
}
|
||||
|
||||
|
||||
GrFmtReader* CvImageFilters::FindReader( const char* filename ) const
|
||||
{
|
||||
return m_factories->FindReader( filename );
|
||||
}
|
||||
|
||||
|
||||
GrFmtWriter* CvImageFilters::FindWriter( const char* filename ) const
|
||||
{
|
||||
return m_factories->FindWriter( filename );
|
||||
}
|
||||
|
||||
/****************************************************************************************\
|
||||
* HighGUI loading & saving function implementation *
|
||||
\****************************************************************************************/
|
||||
|
||||
static int icvSetCXCOREBindings(void)
|
||||
{
|
||||
return CV_SET_IMAGE_IO_FUNCTIONS();
|
||||
}
|
||||
|
||||
int cxcore_bindings_initialized = icvSetCXCOREBindings();
|
||||
|
||||
// global image I/O filters
|
||||
static CvImageFilters g_Filters;
|
||||
|
||||
#if 0
|
||||
CV_IMPL void
|
||||
cvAddSearchPath( const char* path )
|
||||
{
|
||||
CV_FUNCNAME( "cvAddSearchPath" );
|
||||
|
||||
__BEGIN__;
|
||||
|
||||
if( !path || strlen(path) == 0 )
|
||||
CV_ERROR( CV_StsNullPtr, "Null path" );
|
||||
|
||||
g_Filters.AddPath( path );
|
||||
|
||||
__END__;
|
||||
}
|
||||
#endif
|
||||
|
||||
static void*
|
||||
icvLoadImage( const char* filename, int flags, bool load_as_matrix )
|
||||
{
|
||||
GrFmtReader* reader = 0;
|
||||
IplImage* image = 0;
|
||||
CvMat hdr, *matrix = 0;
|
||||
int depth = 8;
|
||||
|
||||
CV_FUNCNAME( "cvLoadImage" );
|
||||
|
||||
__BEGIN__;
|
||||
|
||||
CvSize size;
|
||||
int iscolor;
|
||||
int cn;
|
||||
|
||||
if( !filename || strlen(filename) == 0 )
|
||||
CV_ERROR( CV_StsNullPtr, "null filename" );
|
||||
|
||||
reader = g_Filters.FindReader( filename );
|
||||
if( !reader )
|
||||
EXIT;
|
||||
|
||||
if( !reader->ReadHeader() )
|
||||
EXIT;
|
||||
|
||||
size.width = reader->GetWidth();
|
||||
size.height = reader->GetHeight();
|
||||
|
||||
if( flags == -1 )
|
||||
iscolor = reader->IsColor();
|
||||
else
|
||||
{
|
||||
if( (flags & CV_LOAD_IMAGE_COLOR) != 0 ||
|
||||
((flags & CV_LOAD_IMAGE_ANYCOLOR) != 0 && reader->IsColor()) )
|
||||
iscolor = 1;
|
||||
else
|
||||
iscolor = 0;
|
||||
|
||||
if( (flags & CV_LOAD_IMAGE_ANYDEPTH) != 0 )
|
||||
{
|
||||
reader->UseNativeDepth(true);
|
||||
depth = reader->GetDepth();
|
||||
}
|
||||
}
|
||||
|
||||
cn = iscolor ? 3 : 1;
|
||||
|
||||
if( load_as_matrix )
|
||||
{
|
||||
int type;
|
||||
if(reader->IsFloat() && depth != 8)
|
||||
type = CV_32F;
|
||||
else
|
||||
type = ( depth <= 8 ) ? CV_8U : ( depth <= 16 ) ? CV_16U : CV_32S;
|
||||
CV_CALL( matrix = cvCreateMat( size.height, size.width, CV_MAKETYPE(type, cn) ));
|
||||
}
|
||||
else
|
||||
{
|
||||
int type;
|
||||
if(reader->IsFloat() && depth != 8)
|
||||
type = IPL_DEPTH_32F;
|
||||
else
|
||||
type = ( depth <= 8 ) ? IPL_DEPTH_8U : ( depth <= 16 ) ? IPL_DEPTH_16U : IPL_DEPTH_32S;
|
||||
CV_CALL( image = cvCreateImage( size, type, cn ));
|
||||
matrix = cvGetMat( image, &hdr );
|
||||
}
|
||||
|
||||
if( !reader->ReadData( matrix->data.ptr, matrix->step, iscolor ))
|
||||
{
|
||||
if( load_as_matrix )
|
||||
cvReleaseMat( &matrix );
|
||||
else
|
||||
cvReleaseImage( &image );
|
||||
EXIT;
|
||||
}
|
||||
|
||||
__END__;
|
||||
|
||||
delete reader;
|
||||
|
||||
if( cvGetErrStatus() < 0 )
|
||||
{
|
||||
if( load_as_matrix )
|
||||
cvReleaseMat( &matrix );
|
||||
else
|
||||
cvReleaseImage( &image );
|
||||
}
|
||||
|
||||
return load_as_matrix ? (void*)matrix : (void*)image;
|
||||
}
|
||||
|
||||
|
||||
CV_IMPL IplImage*
|
||||
cvLoadImage( const char* filename, int iscolor )
|
||||
{
|
||||
return (IplImage*)icvLoadImage( filename, iscolor, false );
|
||||
}
|
||||
|
||||
CV_IMPL CvMat*
|
||||
cvLoadImageM( const char* filename, int iscolor )
|
||||
{
|
||||
return (CvMat*)icvLoadImage( filename, iscolor, true );
|
||||
}
|
||||
|
||||
|
||||
CV_IMPL int
|
||||
cvSaveImage( const char* filename, const CvArr* arr )
|
||||
{
|
||||
int origin = 0;
|
||||
GrFmtWriter* writer = 0;
|
||||
CvMat *temp = 0, *temp2 = 0;
|
||||
|
||||
CV_FUNCNAME( "cvSaveImage" );
|
||||
|
||||
__BEGIN__;
|
||||
|
||||
CvMat stub, *image;
|
||||
int channels, ipl_depth;
|
||||
|
||||
if( !filename || strlen(filename) == 0 )
|
||||
CV_ERROR( CV_StsNullPtr, "null filename" );
|
||||
|
||||
CV_CALL( image = cvGetMat( arr, &stub ));
|
||||
|
||||
if( CV_IS_IMAGE( arr ))
|
||||
origin = ((IplImage*)arr)->origin;
|
||||
|
||||
channels = CV_MAT_CN( image->type );
|
||||
if( channels != 1 && channels != 3 && channels != 4 )
|
||||
CV_ERROR( CV_BadNumChannels, "" );
|
||||
|
||||
writer = g_Filters.FindWriter( filename );
|
||||
if( !writer )
|
||||
CV_ERROR( CV_StsError, "could not find a filter for the specified extension" );
|
||||
|
||||
if( origin )
|
||||
{
|
||||
CV_CALL( temp = cvCreateMat(image->rows, image->cols, image->type) );
|
||||
CV_CALL( cvFlip( image, temp, 0 ));
|
||||
image = temp;
|
||||
}
|
||||
|
||||
ipl_depth = cvCvToIplDepth(image->type);
|
||||
|
||||
if( !writer->IsFormatSupported(ipl_depth) )
|
||||
{
|
||||
assert( writer->IsFormatSupported(IPL_DEPTH_8U) );
|
||||
CV_CALL( temp2 = cvCreateMat(image->rows,
|
||||
image->cols, CV_MAKETYPE(CV_8U,channels)) );
|
||||
CV_CALL( cvConvertImage( image, temp2 ));
|
||||
image = temp2;
|
||||
ipl_depth = IPL_DEPTH_8U;
|
||||
}
|
||||
|
||||
if( !writer->WriteImage( image->data.ptr, image->step, image->width,
|
||||
image->height, ipl_depth, channels ))
|
||||
CV_ERROR( CV_StsError, "could not save the image" );
|
||||
|
||||
__END__;
|
||||
|
||||
delete writer;
|
||||
cvReleaseMat( &temp );
|
||||
cvReleaseMat( &temp2 );
|
||||
|
||||
return cvGetErrStatus() >= 0;
|
||||
}
|
||||
|
||||
/* End of file. */
|
||||
@@ -0,0 +1,24 @@
|
||||
TARGET := highgui
|
||||
BINTYPE := DLL
|
||||
SRC_ROOT := ../../otherlibs/highgui
|
||||
INC_ROOT := ../../otherlibs/highgui
|
||||
CXCORE_INC := ../../cxcore/include
|
||||
SRC_DIRS := . ../../cxcore/include
|
||||
|
||||
|
||||
OBJS := bitstrm.o cvcap.o cvcap_cmu.o cvcap_vfw.o grfmt_base.o grfmt_bmp.o \
|
||||
grfmt_jpeg.o grfmt_png.o grfmt_pxm.o grfmt_sunras.o grfmt_tiff.o image.o \
|
||||
loadsave.o utils.o window.o window_w32.o
|
||||
|
||||
CXXFLAGS := -D"HAVE_JPEG" -D"HAVE_PNG" -D"HAVE_ZLIB" -D"HAVE_TIFF" -D"CVAPI_EXPORTS" \
|
||||
-I"$(INC_ROOT)" -I"$(CXCORE_INC)" -I"../../otherlibs/_graphics/include"
|
||||
|
||||
INCS := bitstrm.h grfmts.h grfmt_base.h grfmt_bmp.h grfmt_jpeg.h \
|
||||
grfmt_png.h grfmt_pxm.h grfmt_sunras.h grfmt_tiff.h \
|
||||
_highgui.h utils.h highgui.h \
|
||||
cxcore.h cxcore.hpp cxerror.h cxmisc.h cxtypes.h cvver.h
|
||||
|
||||
LIBS := -lcxcore$(DBG) -Wl,-L../../otherlibs/_graphics/lib \
|
||||
-ltiff -ljpeg -lpng -lz -lvfw_avi32 -lvfw_cap32 -lvfw_ms32 -lcomctl32
|
||||
|
||||
include ../../_make/make_module_gnu.mak
|
||||
@@ -0,0 +1,46 @@
|
||||
TARGET = highgui
|
||||
BINTYPE = DLL
|
||||
ROOT = ..\..
|
||||
PCH = _highgui.h
|
||||
PCH_STARTER = precomp
|
||||
|
||||
OBJS = $(OBJPATH)/bitstrm.obj $(OBJPATH)/cvcap.obj $(OBJPATH)/cvcap_cmu.obj\
|
||||
$(OBJPATH)/cvcap_vfw.obj $(OBJPATH)/grfmt_base.obj $(OBJPATH)/grfmt_bmp.obj \
|
||||
$(OBJPATH)/grfmt_jpeg.obj $(OBJPATH)/grfmt_png.obj $(OBJPATH)/grfmt_pxm.obj \
|
||||
$(OBJPATH)/grfmt_sunras.obj $(OBJPATH)/grfmt_tiff.obj $(OBJPATH)/image.obj \
|
||||
$(OBJPATH)/loadsave.obj $(OBJPATH)/utils.obj \
|
||||
$(OBJPATH)/window.obj $(OBJPATH)/window_w32.obj
|
||||
|
||||
INCS = ./bitstrm.h ./grfmts.h ./grfmt_base.h ./grfmt_bmp.h ./grfmt_jpeg.h \
|
||||
./grfmt_png.h ./grfmt_pxm.h ./grfmt_sunras.h ./grfmt_tiff.h \
|
||||
./_highgui.h ./utils.h ./highgui.h \
|
||||
$(ROOT)/cxcore/include/cxcore.h $(ROOT)/cxcore/include/cxcore.hpp \
|
||||
$(ROOT)/cxcore/include/cxerror.h $(ROOT)/cxcore/include/cxmisc.h \
|
||||
$(ROOT)/cxcore/include/cxtypes.h $(ROOT)/cxcore/include/cvver.h
|
||||
|
||||
!if "$(MS)" == "bc"
|
||||
GRLIB_SUFFIX = _bcc
|
||||
LIBJASPER =
|
||||
!else
|
||||
GRLIB_SUFFIX =
|
||||
!if "$(PLATFORM)" == "I386"
|
||||
LIBJASPER = libjasper$(OUT_P_SUFFIX)$(GRLIB_SUFFIX).lib
|
||||
!endif
|
||||
!endif
|
||||
|
||||
!if "$(PLATFORM)" != "IA64"
|
||||
CXXFLAGS_GRFMT = /DHAVE_JPEG /DHAVE_PNG /DHAVE_PNG /I"../_graphics/include"
|
||||
LIBS_GRFMT = libjpeg$(OUT_P_SUFFIX)$(GRLIB_SUFFIX).lib \
|
||||
libpng$(OUT_P_SUFFIX)$(GRLIB_SUFFIX).lib \
|
||||
libtiff$(OUT_P_SUFFIX)$(GRLIB_SUFFIX).lib \
|
||||
zlib$(OUT_P_SUFFIX)$(GRLIB_SUFFIX).lib $(LIBJASPER)
|
||||
!else
|
||||
CXXFLAGS_GRFMT =
|
||||
LIBS_GRFMT =
|
||||
!endif
|
||||
|
||||
CXXFLAGS_PROJ = /I"." /I"$(ROOT)/cxcore/include" $(CXXFLAGS_GRFMT)
|
||||
LIBS_PROJ = $(LIBPATH)"..\_graphics\lib" $(LIBPATH)"$(ROOT)/lib" vfw32.lib comctl32.lib \
|
||||
cxcore$(DBG)$(OUT_P_SUFFIX).lib $(LIBS_GRFMT)
|
||||
|
||||
!include $(ROOT)/_make/make_module_$(MS).mak
|
||||
@@ -0,0 +1,2 @@
|
||||
swig -DSKIP_INCLUDES -python -small highgui.i
|
||||
gcc -I/usr/include/python2.3/ -I../../cxcore/include -D CV_NO_BACKWARD_COMPATIBILITY -c highgui_wrap.c
|
||||
@@ -0,0 +1,43 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// Intel License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000, Intel Corporation, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of Intel Corporation may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "_highgui.h"
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
//{{NO_DEPENDENCIES}}
|
||||
// Microsoft Developer Studio generated include file.
|
||||
// Used by highgui.rc
|
||||
//
|
||||
|
||||
// Next default values for new objects
|
||||
//
|
||||
#ifdef APSTUDIO_INVOKED
|
||||
#ifndef APSTUDIO_READONLY_SYMBOLS
|
||||
#define _APS_NEXT_RESOURCE_VALUE 101
|
||||
#define _APS_NEXT_COMMAND_VALUE 40001
|
||||
#define _APS_NEXT_CONTROL_VALUE 1000
|
||||
#define _APS_NEXT_SYMED_VALUE 101
|
||||
#endif
|
||||
#endif
|
||||
@@ -0,0 +1,592 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// Intel License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000, Intel Corporation, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of Intel Corporation may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "_highgui.h"
|
||||
#include "utils.h"
|
||||
|
||||
#define SCALE 14
|
||||
#define cR (int)(0.299*(1 << SCALE) + 0.5)
|
||||
#define cG (int)(0.587*(1 << SCALE) + 0.5)
|
||||
#define cB ((1 << SCALE) - cR - cG)
|
||||
|
||||
|
||||
void icvCvt_BGR2Gray_8u_C3C1R( const uchar* rgb, int rgb_step,
|
||||
uchar* gray, int gray_step,
|
||||
CvSize size, int _swap_rb )
|
||||
{
|
||||
int i;
|
||||
int swap_rb = _swap_rb ? 2 : 0;
|
||||
for( ; size.height--; gray += gray_step )
|
||||
{
|
||||
for( i = 0; i < size.width; i++, rgb += 3 )
|
||||
{
|
||||
int t = descale( rgb[swap_rb]*cB + rgb[1]*cG + rgb[swap_rb^2]*cR, SCALE );
|
||||
gray[i] = (uchar)t;
|
||||
}
|
||||
|
||||
rgb += rgb_step - size.width*3;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void icvCvt_BGRA2Gray_8u_C4C1R( const uchar* rgba, int rgba_step,
|
||||
uchar* gray, int gray_step,
|
||||
CvSize size, int _swap_rb )
|
||||
{
|
||||
int i;
|
||||
int swap_rb = _swap_rb ? 2 : 0;
|
||||
for( ; size.height--; gray += gray_step )
|
||||
{
|
||||
for( i = 0; i < size.width; i++, rgba += 4 )
|
||||
{
|
||||
int t = descale( rgba[swap_rb]*cB + rgba[1]*cG + rgba[swap_rb^2]*cR, SCALE );
|
||||
gray[i] = (uchar)t;
|
||||
}
|
||||
|
||||
rgba += rgba_step - size.width*4;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void icvCvt_Gray2BGR_8u_C1C3R( const uchar* gray, int gray_step,
|
||||
uchar* bgr, int bgr_step, CvSize size )
|
||||
{
|
||||
int i;
|
||||
for( ; size.height--; gray += gray_step )
|
||||
{
|
||||
for( i = 0; i < size.width; i++, bgr += 3 )
|
||||
{
|
||||
bgr[0] = bgr[1] = bgr[2] = gray[i];
|
||||
}
|
||||
bgr += bgr_step - size.width*3;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void icvCvt_BGRA2BGR_8u_C4C3R( const uchar* bgra, int bgra_step,
|
||||
uchar* bgr, int bgr_step,
|
||||
CvSize size, int _swap_rb )
|
||||
{
|
||||
int i;
|
||||
int swap_rb = _swap_rb ? 2 : 0;
|
||||
for( ; size.height--; )
|
||||
{
|
||||
for( i = 0; i < size.width; i++, bgr += 3, bgra += 4 )
|
||||
{
|
||||
uchar t0 = bgra[swap_rb], t1 = bgra[1];
|
||||
bgr[0] = t0; bgr[1] = t1;
|
||||
t0 = bgra[swap_rb^2]; bgr[2] = t0;
|
||||
}
|
||||
bgr += bgr_step - size.width*3;
|
||||
bgra += bgra_step - size.width*4;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void icvCvt_BGRA2RGBA_8u_C4R( const uchar* bgra, int bgra_step,
|
||||
uchar* rgba, int rgba_step, CvSize size )
|
||||
{
|
||||
int i;
|
||||
for( ; size.height--; )
|
||||
{
|
||||
for( i = 0; i < size.width; i++, bgra += 4, rgba += 4 )
|
||||
{
|
||||
uchar t0 = bgra[0], t1 = bgra[1];
|
||||
uchar t2 = bgra[2], t3 = bgra[3];
|
||||
rgba[0] = t2; rgba[1] = t1;
|
||||
rgba[2] = t0; rgba[3] = t3;
|
||||
}
|
||||
bgra += bgra_step - size.width*4;
|
||||
rgba += rgba_step - size.width*4;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void icvCvt_BGR2RGB_8u_C3R( const uchar* bgr, int bgr_step,
|
||||
uchar* rgb, int rgb_step, CvSize size )
|
||||
{
|
||||
int i;
|
||||
for( ; size.height--; )
|
||||
{
|
||||
for( i = 0; i < size.width; i++, bgr += 3, rgb += 3 )
|
||||
{
|
||||
uchar t0 = bgr[0], t1 = bgr[1], t2 = bgr[2];
|
||||
rgb[2] = t0; rgb[1] = t1; rgb[0] = t2;
|
||||
}
|
||||
bgr += bgr_step - size.width*3;
|
||||
rgb += rgb_step - size.width*3;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
typedef unsigned short ushort;
|
||||
|
||||
void icvCvt_BGR5552Gray_8u_C2C1R( const uchar* bgr555, int bgr555_step,
|
||||
uchar* gray, int gray_step, CvSize size )
|
||||
{
|
||||
int i;
|
||||
for( ; size.height--; gray += gray_step, bgr555 += bgr555_step )
|
||||
{
|
||||
for( i = 0; i < size.width; i++ )
|
||||
{
|
||||
int t = descale( ((((ushort*)bgr555)[i] << 3) & 0xf8)*cB +
|
||||
((((ushort*)bgr555)[i] >> 2) & 0xf8)*cG +
|
||||
((((ushort*)bgr555)[i] >> 7) & 0xf8)*cR, SCALE );
|
||||
gray[i] = (uchar)t;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void icvCvt_BGR5652Gray_8u_C2C1R( const uchar* bgr565, int bgr565_step,
|
||||
uchar* gray, int gray_step, CvSize size )
|
||||
{
|
||||
int i;
|
||||
for( ; size.height--; gray += gray_step, bgr565 += bgr565_step )
|
||||
{
|
||||
for( i = 0; i < size.width; i++ )
|
||||
{
|
||||
int t = descale( ((((ushort*)bgr565)[i] << 3) & 0xf8)*cB +
|
||||
((((ushort*)bgr565)[i] >> 3) & 0xfc)*cG +
|
||||
((((ushort*)bgr565)[i] >> 8) & 0xf8)*cR, SCALE );
|
||||
gray[i] = (uchar)t;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void icvCvt_BGR5552BGR_8u_C2C3R( const uchar* bgr555, int bgr555_step,
|
||||
uchar* bgr, int bgr_step, CvSize size )
|
||||
{
|
||||
int i;
|
||||
for( ; size.height--; bgr555 += bgr555_step )
|
||||
{
|
||||
for( i = 0; i < size.width; i++, bgr += 3 )
|
||||
{
|
||||
int t0 = (((ushort*)bgr555)[i] << 3) & 0xf8;
|
||||
int t1 = (((ushort*)bgr555)[i] >> 2) & 0xf8;
|
||||
int t2 = (((ushort*)bgr555)[i] >> 7) & 0xf8;
|
||||
bgr[0] = (uchar)t0; bgr[1] = (uchar)t1; bgr[2] = (uchar)t2;
|
||||
}
|
||||
bgr += bgr_step - size.width*3;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void icvCvt_BGR5652BGR_8u_C2C3R( const uchar* bgr565, int bgr565_step,
|
||||
uchar* bgr, int bgr_step, CvSize size )
|
||||
{
|
||||
int i;
|
||||
for( ; size.height--; bgr565 += bgr565_step )
|
||||
{
|
||||
for( i = 0; i < size.width; i++, bgr += 3 )
|
||||
{
|
||||
int t0 = (((ushort*)bgr565)[i] << 3) & 0xf8;
|
||||
int t1 = (((ushort*)bgr565)[i] >> 3) & 0xfc;
|
||||
int t2 = (((ushort*)bgr565)[i] >> 8) & 0xf8;
|
||||
bgr[0] = (uchar)t0; bgr[1] = (uchar)t1; bgr[2] = (uchar)t2;
|
||||
}
|
||||
bgr += bgr_step - size.width*3;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void icvCvt_CMYK2BGR_8u_C4C3R( const uchar* cmyk, int cmyk_step,
|
||||
uchar* bgr, int bgr_step, CvSize size )
|
||||
{
|
||||
int i;
|
||||
for( ; size.height--; )
|
||||
{
|
||||
for( i = 0; i < size.width; i++, bgr += 3, cmyk += 4 )
|
||||
{
|
||||
int c = cmyk[0], m = cmyk[1], y = cmyk[2], k = cmyk[3];
|
||||
c = k - ((255 - c)*k>>8);
|
||||
m = k - ((255 - m)*k>>8);
|
||||
y = k - ((255 - y)*k>>8);
|
||||
bgr[2] = (uchar)c; bgr[1] = (uchar)m; bgr[0] = (uchar)y;
|
||||
}
|
||||
bgr += bgr_step - size.width*3;
|
||||
cmyk += cmyk_step - size.width*4;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void icvCvt_CMYK2Gray_8u_C4C1R( const uchar* cmyk, int cmyk_step,
|
||||
uchar* gray, int gray_step, CvSize size )
|
||||
{
|
||||
int i;
|
||||
for( ; size.height--; )
|
||||
{
|
||||
for( i = 0; i < size.width; i++, cmyk += 4 )
|
||||
{
|
||||
int c = cmyk[0], m = cmyk[1], y = cmyk[2], k = cmyk[3];
|
||||
c = k - ((255 - c)*k>>8);
|
||||
m = k - ((255 - m)*k>>8);
|
||||
y = k - ((255 - y)*k>>8);
|
||||
int t = descale( y*cB + m*cG + c*cR, SCALE );
|
||||
gray[i] = (uchar)t;
|
||||
}
|
||||
gray += gray_step;
|
||||
cmyk += cmyk_step - size.width*4;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void CvtPaletteToGray( const PaletteEntry* palette, uchar* grayPalette, int entries )
|
||||
{
|
||||
int i;
|
||||
for( i = 0; i < entries; i++ )
|
||||
{
|
||||
icvCvt_BGR2Gray_8u_C3C1R( (uchar*)(palette + i), 0, grayPalette + i, 0, cvSize(1,1) );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void FillGrayPalette( PaletteEntry* palette, int bpp, bool negative )
|
||||
{
|
||||
int i, length = 1 << bpp;
|
||||
int xor_mask = negative ? 255 : 0;
|
||||
|
||||
for( i = 0; i < length; i++ )
|
||||
{
|
||||
int val = (i * 255/(length - 1)) ^ xor_mask;
|
||||
palette[i].b = palette[i].g = palette[i].r = (uchar)val;
|
||||
palette[i].a = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool IsColorPalette( PaletteEntry* palette, int bpp )
|
||||
{
|
||||
int i, length = 1 << bpp;
|
||||
|
||||
for( i = 0; i < length; i++ )
|
||||
{
|
||||
if( palette[i].b != palette[i].g ||
|
||||
palette[i].b != palette[i].r )
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
uchar* FillUniColor( uchar* data, uchar*& line_end,
|
||||
int step, int width3,
|
||||
int& y, int height,
|
||||
int count3, PaletteEntry clr )
|
||||
{
|
||||
do
|
||||
{
|
||||
uchar* end = data + count3;
|
||||
|
||||
if( end > line_end )
|
||||
end = line_end;
|
||||
|
||||
count3 -= (int)(end - data);
|
||||
|
||||
for( ; data < end; data += 3 )
|
||||
{
|
||||
WRITE_PIX( data, clr );
|
||||
}
|
||||
|
||||
if( data >= line_end )
|
||||
{
|
||||
line_end += step;
|
||||
data = line_end - width3;
|
||||
if( ++y >= height ) break;
|
||||
}
|
||||
}
|
||||
while( count3 > 0 );
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
|
||||
uchar* FillUniGray( uchar* data, uchar*& line_end,
|
||||
int step, int width,
|
||||
int& y, int height,
|
||||
int count, uchar clr )
|
||||
{
|
||||
do
|
||||
{
|
||||
uchar* end = data + count;
|
||||
|
||||
if( end > line_end )
|
||||
end = line_end;
|
||||
|
||||
count -= (int)(end - data);
|
||||
|
||||
for( ; data < end; data++ )
|
||||
{
|
||||
*data = clr;
|
||||
}
|
||||
|
||||
if( data >= line_end )
|
||||
{
|
||||
line_end += step;
|
||||
data = line_end - width;
|
||||
if( ++y >= height ) break;
|
||||
}
|
||||
}
|
||||
while( count > 0 );
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
|
||||
uchar* FillColorRow8( uchar* data, uchar* indices, int len, PaletteEntry* palette )
|
||||
{
|
||||
uchar* end = data + len*3;
|
||||
while( (data += 3) < end )
|
||||
{
|
||||
*((PaletteEntry*)(data-3)) = palette[*indices++];
|
||||
}
|
||||
PaletteEntry clr = palette[indices[0]];
|
||||
WRITE_PIX( data - 3, clr );
|
||||
return data;
|
||||
}
|
||||
|
||||
|
||||
uchar* FillGrayRow8( uchar* data, uchar* indices, int len, uchar* palette )
|
||||
{
|
||||
int i;
|
||||
for( i = 0; i < len; i++ )
|
||||
{
|
||||
data[i] = palette[indices[i]];
|
||||
}
|
||||
return data + len;
|
||||
}
|
||||
|
||||
|
||||
uchar* FillColorRow4( uchar* data, uchar* indices, int len, PaletteEntry* palette )
|
||||
{
|
||||
uchar* end = data + len*3;
|
||||
|
||||
while( (data += 6) < end )
|
||||
{
|
||||
int idx = *indices++;
|
||||
*((PaletteEntry*)(data-6)) = palette[idx >> 4];
|
||||
*((PaletteEntry*)(data-3)) = palette[idx & 15];
|
||||
}
|
||||
|
||||
int idx = indices[0];
|
||||
PaletteEntry clr = palette[idx >> 4];
|
||||
WRITE_PIX( data - 6, clr );
|
||||
|
||||
if( data == end )
|
||||
{
|
||||
clr = palette[idx & 15];
|
||||
WRITE_PIX( data - 3, clr );
|
||||
}
|
||||
return end;
|
||||
}
|
||||
|
||||
|
||||
uchar* FillGrayRow4( uchar* data, uchar* indices, int len, uchar* palette )
|
||||
{
|
||||
uchar* end = data + len;
|
||||
while( (data += 2) < end )
|
||||
{
|
||||
int idx = *indices++;
|
||||
data[-2] = palette[idx >> 4];
|
||||
data[-1] = palette[idx & 15];
|
||||
}
|
||||
|
||||
int idx = indices[0];
|
||||
uchar clr = palette[idx >> 4];
|
||||
data[-2] = clr;
|
||||
|
||||
if( data == end )
|
||||
{
|
||||
clr = palette[idx & 15];
|
||||
data[-1] = clr;
|
||||
}
|
||||
return end;
|
||||
}
|
||||
|
||||
|
||||
uchar* FillColorRow1( uchar* data, uchar* indices, int len, PaletteEntry* palette )
|
||||
{
|
||||
uchar* end = data + len*3;
|
||||
|
||||
while( (data += 24) < end )
|
||||
{
|
||||
int idx = *indices++;
|
||||
*((PaletteEntry*)(data - 24)) = palette[(idx & 128) != 0];
|
||||
*((PaletteEntry*)(data - 21)) = palette[(idx & 64) != 0];
|
||||
*((PaletteEntry*)(data - 18)) = palette[(idx & 32) != 0];
|
||||
*((PaletteEntry*)(data - 15)) = palette[(idx & 16) != 0];
|
||||
*((PaletteEntry*)(data - 12)) = palette[(idx & 8) != 0];
|
||||
*((PaletteEntry*)(data - 9)) = palette[(idx & 4) != 0];
|
||||
*((PaletteEntry*)(data - 6)) = palette[(idx & 2) != 0];
|
||||
*((PaletteEntry*)(data - 3)) = palette[(idx & 1) != 0];
|
||||
}
|
||||
|
||||
int idx = indices[0] << 24;
|
||||
for( data -= 24; data < end; data += 3, idx += idx )
|
||||
{
|
||||
PaletteEntry clr = palette[idx < 0];
|
||||
WRITE_PIX( data, clr );
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
|
||||
uchar* FillGrayRow1( uchar* data, uchar* indices, int len, uchar* palette )
|
||||
{
|
||||
uchar* end = data + len;
|
||||
|
||||
while( (data += 8) < end )
|
||||
{
|
||||
int idx = *indices++;
|
||||
*((uchar*)(data - 8)) = palette[(idx & 128) != 0];
|
||||
*((uchar*)(data - 7)) = palette[(idx & 64) != 0];
|
||||
*((uchar*)(data - 6)) = palette[(idx & 32) != 0];
|
||||
*((uchar*)(data - 5)) = palette[(idx & 16) != 0];
|
||||
*((uchar*)(data - 4)) = palette[(idx & 8) != 0];
|
||||
*((uchar*)(data - 3)) = palette[(idx & 4) != 0];
|
||||
*((uchar*)(data - 2)) = palette[(idx & 2) != 0];
|
||||
*((uchar*)(data - 1)) = palette[(idx & 1) != 0];
|
||||
}
|
||||
|
||||
int idx = indices[0] << 24;
|
||||
for( data -= 8; data < end; data++, idx += idx )
|
||||
{
|
||||
data[0] = palette[idx < 0];
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
|
||||
CV_IMPL void
|
||||
cvConvertImage( const CvArr* srcarr, CvArr* dstarr, int flags )
|
||||
{
|
||||
CvMat* temp = 0;
|
||||
|
||||
CV_FUNCNAME( "cvConvertImage" );
|
||||
|
||||
__BEGIN__;
|
||||
|
||||
CvMat srcstub, *src;
|
||||
CvMat dststub, *dst;
|
||||
int src_cn, swap_rb = flags & CV_CVTIMG_SWAP_RB;
|
||||
|
||||
CV_CALL( src = cvGetMat( srcarr, &srcstub ));
|
||||
CV_CALL( dst = cvGetMat( dstarr, &dststub ));
|
||||
|
||||
src_cn = CV_MAT_CN( src->type );
|
||||
|
||||
if( src_cn != 1 && src_cn != 3 && src_cn != 4 )
|
||||
CV_ERROR( CV_BadNumChannels, "Source image must have 1, 3 or 4 channels" );
|
||||
|
||||
if( CV_MAT_DEPTH( dst->type ) != CV_8U )
|
||||
CV_ERROR( CV_BadDepth, "Destination image must be 8u" );
|
||||
|
||||
if( CV_MAT_CN(dst->type) != 1 && CV_MAT_CN(dst->type) != 3 )
|
||||
CV_ERROR( CV_BadNumChannels, "Destination image must have 1 or 3 channels" );
|
||||
|
||||
if( !CV_ARE_DEPTHS_EQ( src, dst ))
|
||||
{
|
||||
double scale = 0, shift = 0;
|
||||
int src_depth = CV_MAT_DEPTH(src->type);
|
||||
temp = cvCreateMat( src->height, src->width,
|
||||
(src->type & CV_MAT_CN_MASK)|(dst->type & CV_MAT_DEPTH_MASK));
|
||||
scale = src_depth <= CV_8S ? 1 : src_depth <= CV_32S ? 1./256 : 255;
|
||||
shift = src_depth == CV_8S || src_depth == CV_16S ? 128 : 0;
|
||||
cvConvertScale( src, temp, scale, shift );
|
||||
src = temp;
|
||||
}
|
||||
|
||||
{
|
||||
uchar *s = src->data.ptr, *d = dst->data.ptr;
|
||||
int s_step = src->step, d_step = dst->step;
|
||||
int code = src_cn*10 + CV_MAT_CN(dst->type);
|
||||
CvSize size = { src->cols, src->rows };
|
||||
|
||||
if( CV_IS_MAT_CONT(src->type & dst->type) )
|
||||
{
|
||||
size.width *= size.height;
|
||||
size.height = 1;
|
||||
s_step = d_step = CV_STUB_STEP;
|
||||
}
|
||||
|
||||
switch( code )
|
||||
{
|
||||
case 13:
|
||||
icvCvt_Gray2BGR_8u_C1C3R( s, s_step, d, d_step, size );
|
||||
break;
|
||||
case 31:
|
||||
icvCvt_BGR2Gray_8u_C3C1R( s, s_step, d, d_step, size, swap_rb );
|
||||
break;
|
||||
case 33:
|
||||
if( swap_rb )
|
||||
icvCvt_RGB2BGR_8u_C3R( s, s_step, d, d_step, size );
|
||||
break;
|
||||
case 41:
|
||||
icvCvt_BGRA2Gray_8u_C4C1R( s, s_step, d, d_step, size, swap_rb );
|
||||
break;
|
||||
case 43:
|
||||
icvCvt_BGRA2BGR_8u_C4C3R( s, s_step, d, d_step, size, swap_rb );
|
||||
break;
|
||||
default:
|
||||
CV_ERROR( CV_StsUnsupportedFormat, "Unsupported combination of input/output formats" );
|
||||
}
|
||||
|
||||
if( code != 33 || swap_rb )
|
||||
src = dst;
|
||||
}
|
||||
|
||||
if( flags & CV_CVTIMG_FLIP )
|
||||
{
|
||||
CV_CALL( cvFlip( src, dst, 0 ));
|
||||
}
|
||||
else if( src != dst )
|
||||
{
|
||||
CV_CALL( cvCopy( src, dst ));
|
||||
}
|
||||
|
||||
__END__;
|
||||
|
||||
cvReleaseMat( &temp );
|
||||
}
|
||||
@@ -0,0 +1,110 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// Intel License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000, Intel Corporation, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of Intel Corporation may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#ifndef _UTILS_H_
|
||||
#define _UTILS_H_
|
||||
|
||||
struct PaletteEntry
|
||||
{
|
||||
unsigned char b, g, r, a;
|
||||
};
|
||||
|
||||
#define WRITE_PIX( ptr, clr ) \
|
||||
(((uchar*)(ptr))[0] = (clr).b, \
|
||||
((uchar*)(ptr))[1] = (clr).g, \
|
||||
((uchar*)(ptr))[2] = (clr).r)
|
||||
|
||||
#define descale(x,n) (((x) + (1 << ((n)-1))) >> (n))
|
||||
#define saturate(x) (uchar)(((x) & ~255) == 0 ? (x) : ~((x)>>31))
|
||||
|
||||
void icvCvt_BGR2Gray_8u_C3C1R( const uchar* bgr, int bgr_step,
|
||||
uchar* gray, int gray_step,
|
||||
CvSize size, int swap_rb=0 );
|
||||
void icvCvt_BGRA2Gray_8u_C4C1R( const uchar* bgra, int bgra_step,
|
||||
uchar* gray, int gray_step,
|
||||
CvSize size, int swap_rb=0 );
|
||||
void icvCvt_Gray2BGR_8u_C1C3R( const uchar* gray, int gray_step,
|
||||
uchar* bgr, int bgr_step, CvSize size );
|
||||
void icvCvt_BGRA2BGR_8u_C4C3R( const uchar* bgra, int bgra_step,
|
||||
uchar* bgr, int bgr_step,
|
||||
CvSize size, int swap_rb=0 );
|
||||
void icvCvt_BGR2RGB_8u_C3R( const uchar* bgr, int bgr_step,
|
||||
uchar* rgb, int rgb_step, CvSize size );
|
||||
#define icvCvt_RGB2BGR_8u_C3R icvCvt_BGR2RGB_8u_C3R
|
||||
|
||||
void icvCvt_BGRA2RGBA_8u_C4R( const uchar* bgra, int bgra_step,
|
||||
uchar* rgba, int rgba_step, CvSize size );
|
||||
#define icvCvt_RGBA2BGRA_8u_C4R icvCvt_BGRA2RGBA_8u_C4R
|
||||
|
||||
void icvCvt_BGR5552Gray_8u_C2C1R( const uchar* bgr555, int bgr555_step,
|
||||
uchar* gray, int gray_step, CvSize size );
|
||||
void icvCvt_BGR5652Gray_8u_C2C1R( const uchar* bgr565, int bgr565_step,
|
||||
uchar* gray, int gray_step, CvSize size );
|
||||
void icvCvt_BGR5552BGR_8u_C2C3R( const uchar* bgr555, int bgr555_step,
|
||||
uchar* bgr, int bgr_step, CvSize size );
|
||||
void icvCvt_BGR5652BGR_8u_C2C3R( const uchar* bgr565, int bgr565_step,
|
||||
uchar* bgr, int bgr_step, CvSize size );
|
||||
void icvCvt_CMYK2BGR_8u_C4C3R( const uchar* cmyk, int cmyk_step,
|
||||
uchar* bgr, int bgr_step, CvSize size );
|
||||
void icvCvt_CMYK2Gray_8u_C4C1R( const uchar* ycck, int ycck_step,
|
||||
uchar* gray, int gray_step, CvSize size );
|
||||
|
||||
void FillGrayPalette( PaletteEntry* palette, int bpp, bool negative = false );
|
||||
bool IsColorPalette( PaletteEntry* palette, int bpp );
|
||||
void CvtPaletteToGray( const PaletteEntry* palette, uchar* grayPalette, int entries );
|
||||
uchar* FillUniColor( uchar* data, uchar*& line_end, int step, int width3,
|
||||
int& y, int height, int count3, PaletteEntry clr );
|
||||
uchar* FillUniGray( uchar* data, uchar*& line_end, int step, int width3,
|
||||
int& y, int height, int count3, uchar clr );
|
||||
|
||||
uchar* FillColorRow8( uchar* data, uchar* indices, int len, PaletteEntry* palette );
|
||||
uchar* FillGrayRow8( uchar* data, uchar* indices, int len, uchar* palette );
|
||||
uchar* FillColorRow4( uchar* data, uchar* indices, int len, PaletteEntry* palette );
|
||||
uchar* FillGrayRow4( uchar* data, uchar* indices, int len, uchar* palette );
|
||||
uchar* FillColorRow1( uchar* data, uchar* indices, int len, PaletteEntry* palette );
|
||||
uchar* FillGrayRow1( uchar* data, uchar* indices, int len, uchar* palette );
|
||||
|
||||
CV_INLINE bool isBigEndian( void )
|
||||
{
|
||||
return (((const int*)"\0\x1\x2\x3\x4\x5\x6\x7")[0] & 255) != 0;
|
||||
}
|
||||
|
||||
#endif/*_UTILS_H_*/
|
||||
@@ -0,0 +1,161 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// Intel License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000, Intel Corporation, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of Intel Corporation may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "_highgui.h"
|
||||
|
||||
// in later times, use this file as a dispatcher to implementations like cvcap.cpp
|
||||
|
||||
|
||||
#if defined (WIN32) // see window_w32.cpp
|
||||
#elif defined (HAVE_GTK) // see window_gtk.cpp
|
||||
#elif defined (HAVE_CARBON) // see window_carbon.cpp
|
||||
|
||||
|
||||
#else
|
||||
|
||||
// No windowing system present at compile time ;-(
|
||||
//
|
||||
// We will build place holders that don't break the API but give an error
|
||||
// at runtime. This way people can choose to replace an installed HighGUI
|
||||
// version with a more capable one without a need to recompile dependent
|
||||
// applications or libraries.
|
||||
|
||||
|
||||
#define CV_NO_GUI_ERROR(funcname) \
|
||||
cvError( CV_StsError, funcname, \
|
||||
"The function is not implemented. " \
|
||||
"Rebuild the library with Windows, GTK+ 2.x or Carbon support", \
|
||||
__FILE__, __LINE__ )
|
||||
|
||||
|
||||
CV_IMPL int cvNamedWindow( const char*, int )
|
||||
{
|
||||
CV_NO_GUI_ERROR("cvNamedWindow");
|
||||
return -1;
|
||||
}
|
||||
|
||||
CV_IMPL void cvDestroyWindow( const char* )
|
||||
{
|
||||
CV_NO_GUI_ERROR( "cvDestroyWindow" );
|
||||
}
|
||||
|
||||
CV_IMPL void
|
||||
cvDestroyAllWindows( void )
|
||||
{
|
||||
CV_NO_GUI_ERROR( "cvDestroyAllWindows" );
|
||||
}
|
||||
|
||||
CV_IMPL void
|
||||
cvShowImage( const char*, const CvArr* )
|
||||
{
|
||||
CV_NO_GUI_ERROR( "cvShowImage" );
|
||||
}
|
||||
|
||||
CV_IMPL void cvResizeWindow( const char*, int, int )
|
||||
{
|
||||
CV_NO_GUI_ERROR( "cvResizeWindow" );
|
||||
}
|
||||
|
||||
CV_IMPL void cvMoveWindow( const char*, int, int )
|
||||
{
|
||||
CV_NO_GUI_ERROR( "cvMoveWindow" );
|
||||
}
|
||||
|
||||
CV_IMPL int
|
||||
cvCreateTrackbar( const char*, const char*,
|
||||
int*, int, CvTrackbarCallback )
|
||||
{
|
||||
CV_NO_GUI_ERROR( "cvCreateTrackbar" );
|
||||
return -1;
|
||||
}
|
||||
|
||||
CV_IMPL void
|
||||
cvSetMouseCallback( const char*, CvMouseCallback, void* )
|
||||
{
|
||||
CV_NO_GUI_ERROR( "cvSetMouseCallback" );
|
||||
}
|
||||
|
||||
CV_IMPL int cvGetTrackbarPos( const char*, const char* )
|
||||
{
|
||||
CV_NO_GUI_ERROR( "cvGetTrackbarPos" );
|
||||
return -1;
|
||||
}
|
||||
|
||||
CV_IMPL void cvSetTrackbarPos( const char*, const char*, int )
|
||||
{
|
||||
CV_NO_GUI_ERROR( "cvSetTrackbarPos" );
|
||||
}
|
||||
|
||||
CV_IMPL void* cvGetWindowHandle( const char* )
|
||||
{
|
||||
CV_NO_GUI_ERROR( "cvGetWindowHandle" );
|
||||
return 0;
|
||||
}
|
||||
|
||||
CV_IMPL const char* cvGetWindowName( void* )
|
||||
{
|
||||
CV_NO_GUI_ERROR( "cvGetWindowName" );
|
||||
return 0;
|
||||
}
|
||||
|
||||
CV_IMPL int cvWaitKey( int )
|
||||
{
|
||||
CV_NO_GUI_ERROR( "cvWaitKey" );
|
||||
return -1;
|
||||
}
|
||||
|
||||
CV_IMPL int cvInitSystem( int argc, char** argv )
|
||||
{
|
||||
|
||||
CV_NO_GUI_ERROR( "cvInitSystem" );
|
||||
return -1;
|
||||
}
|
||||
|
||||
CV_IMPL int cvStartWindowThread()
|
||||
{
|
||||
|
||||
CV_NO_GUI_ERROR( "cvStartWindowThread" );
|
||||
return -1;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/* End of file. */
|
||||
@@ -0,0 +1,863 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// Intel License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000, Intel Corporation, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of Intel Corporation may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "_highgui.h"
|
||||
|
||||
#include <Carbon/Carbon.h>
|
||||
|
||||
#include <unistd.h>
|
||||
#include <cstdio>
|
||||
#include <cmath>
|
||||
|
||||
//#define MS_TO_TICKS(a) a*3/50
|
||||
|
||||
#define LABELWIDTH 64
|
||||
#define INTERWIDGETSPACE 16
|
||||
#define WIDGETHEIGHT 32
|
||||
#define NO_KEY -1
|
||||
|
||||
struct CvWindow;
|
||||
|
||||
typedef struct CvTrackbar
|
||||
{
|
||||
int signature;
|
||||
|
||||
ControlRef trackbar;
|
||||
ControlRef label;
|
||||
|
||||
char* name;
|
||||
CvTrackbar* next;
|
||||
CvWindow* parent;
|
||||
int* data;
|
||||
int pos;
|
||||
int maxval;
|
||||
CvTrackbarCallback notify;
|
||||
}
|
||||
CvTrackbar;
|
||||
|
||||
|
||||
typedef struct CvWindow
|
||||
{
|
||||
int signature;
|
||||
|
||||
char* name;
|
||||
CvWindow* prev;
|
||||
CvWindow* next;
|
||||
|
||||
WindowRef window;
|
||||
CGImageRef imageRef;
|
||||
int imageWidth;//FD
|
||||
int imageHeight;//FD
|
||||
|
||||
CvMat* image;
|
||||
CvMat* dst_image;
|
||||
int converted;
|
||||
int last_key;
|
||||
int flags;
|
||||
|
||||
CvMouseCallback on_mouse;
|
||||
void* on_mouse_param;
|
||||
|
||||
struct {
|
||||
int pos;
|
||||
int rows;
|
||||
CvTrackbar* first;
|
||||
}
|
||||
toolbar;
|
||||
int trackbarheight;
|
||||
}
|
||||
CvWindow;
|
||||
|
||||
static CvWindow* hg_windows = 0;
|
||||
|
||||
#define Assert(exp) \
|
||||
if( !(exp) ) \
|
||||
{ \
|
||||
printf("Assertion: %s %s: %d\n", #exp, __FILE__, __LINE__);\
|
||||
assert(exp); \
|
||||
}
|
||||
|
||||
static int wasInitialized = 0;
|
||||
static char lastKey = NO_KEY;
|
||||
OSStatus keyHandler(EventHandlerCallRef hcr, EventRef theEvent, void* inUserData);
|
||||
static pascal OSStatus windowEventHandler(EventHandlerCallRef nextHandler, EventRef theEvent, void *inUserData);
|
||||
|
||||
static const EventTypeSpec applicationKeyboardEvents[] =
|
||||
{
|
||||
{ kEventClassKeyboard, kEventRawKeyDown },
|
||||
};
|
||||
|
||||
CV_IMPL int cvInitSystem( int argc, char** argv )
|
||||
{
|
||||
OSErr err = noErr;
|
||||
if( !wasInitialized )
|
||||
{
|
||||
|
||||
hg_windows = 0;
|
||||
err = InstallApplicationEventHandler(NewEventHandlerUPP( keyHandler),GetEventTypeCount(applicationKeyboardEvents),applicationKeyboardEvents,NULL,NULL);
|
||||
if (err != noErr)
|
||||
{
|
||||
fprintf(stderr,"InstallApplicationEventHandler was not ok\n");
|
||||
}
|
||||
wasInitialized = 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// TODO: implement missing functionality
|
||||
CV_IMPL int cvStartWindowThread()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int icvCountTrackbarInWindow( const CvWindow* window)
|
||||
{
|
||||
CvTrackbar* trackbar = window->toolbar.first;
|
||||
int count = 0;
|
||||
while (trackbar != 0) {
|
||||
count++;
|
||||
trackbar = trackbar->next;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
static CvTrackbar* icvTrackbarByHandle( void * handle )
|
||||
{
|
||||
CvWindow* window = hg_windows;
|
||||
CvTrackbar* trackbar = NULL;
|
||||
while( window != 0 && window->window != handle) {
|
||||
trackbar = window->toolbar.first;
|
||||
while (trackbar != 0 && trackbar->trackbar != handle)
|
||||
trackbar = trackbar->next;
|
||||
if (trackbar != 0 && trackbar->trackbar == handle)
|
||||
break;
|
||||
window = window->next;
|
||||
}
|
||||
return trackbar;
|
||||
}
|
||||
|
||||
static CvWindow* icvWindowByHandle( void * handle )
|
||||
{
|
||||
CvWindow* window = hg_windows;
|
||||
|
||||
while( window != 0 && window->window != handle)
|
||||
window = window->next;
|
||||
|
||||
return window;
|
||||
}
|
||||
|
||||
CV_IMPL CvWindow * icvFindWindowByName( const char* name)
|
||||
{
|
||||
CvWindow* window = hg_windows;
|
||||
while( window != 0 && strcmp(name, window->name) != 0 )
|
||||
window = window->next;
|
||||
|
||||
return window;
|
||||
}
|
||||
|
||||
static CvTrackbar* icvFindTrackbarByName( const CvWindow* window, const char* name )
|
||||
{
|
||||
CvTrackbar* trackbar = window->toolbar.first;
|
||||
|
||||
while (trackbar != 0 && strcmp( trackbar->name, name ) != 0)
|
||||
trackbar = trackbar->next;
|
||||
|
||||
return trackbar;
|
||||
}
|
||||
|
||||
//FD
|
||||
/* draw image to frame */
|
||||
static void icvDrawImage( CvWindow* window )
|
||||
{
|
||||
Assert( window != 0 );
|
||||
if( window->imageRef == 0 ) return;
|
||||
|
||||
CGContextRef myContext;
|
||||
CvTrackbar* t;
|
||||
CGRect rect;
|
||||
Rect portrect;
|
||||
int width = window->imageWidth;
|
||||
int height = window->imageHeight;
|
||||
|
||||
GetWindowPortBounds(window->window, &portrect);
|
||||
|
||||
if( window->flags & CV_WINDOW_AUTOSIZE )
|
||||
{
|
||||
CGPoint origin = {0,0};
|
||||
CGSize size = {portrect.right-portrect.left, portrect.bottom-portrect.top-window->trackbarheight};
|
||||
rect.origin = origin; rect.size = size;
|
||||
}
|
||||
else
|
||||
{
|
||||
CGPoint origin = {0, portrect.bottom - height - window->trackbarheight};
|
||||
CGSize size = {width, height};
|
||||
rect.origin = origin; rect.size = size;
|
||||
}
|
||||
|
||||
/* To be sybnchronous we are using this, better would be to susbcribe to the draw event and process whenever requested, we might save SOME CPU cycles*/
|
||||
SetPortWindowPort (window->window);
|
||||
QDBeginCGContext (GetWindowPort (window->window), &myContext);
|
||||
CGContextSetInterpolationQuality (myContext, kCGInterpolationLow);
|
||||
CGContextDrawImage(myContext,rect,window->imageRef);
|
||||
CGContextFlush(myContext);// 4
|
||||
QDEndCGContext (GetWindowPort(window->window), &myContext);// 5
|
||||
}
|
||||
|
||||
//FD
|
||||
/* update imageRef */
|
||||
static void icvPutImage( CvWindow* window )
|
||||
{
|
||||
Assert( window != 0 );
|
||||
if( window->image == 0 ) return;
|
||||
|
||||
CGColorSpaceRef colorspace = NULL;
|
||||
CGDataProviderRef provider = NULL;
|
||||
int width = window->imageWidth = window->image->cols;
|
||||
int height = window->imageHeight = window->image->rows;
|
||||
|
||||
colorspace = CGColorSpaceCreateDeviceRGB();
|
||||
|
||||
int size = 8;
|
||||
int nbChannels = 3;
|
||||
|
||||
provider = CGDataProviderCreateWithData(NULL, window->image->data.ptr, width * height , NULL );
|
||||
|
||||
if (window->imageRef != NULL){
|
||||
CGImageRelease(window->imageRef);
|
||||
window->image == NULL;
|
||||
}
|
||||
|
||||
window->imageRef = CGImageCreate( width, height, size , size*nbChannels , window->image->step, colorspace, kCGImageAlphaNone , provider, NULL, true, kCGRenderingIntentDefault );
|
||||
icvDrawImage( window );
|
||||
}
|
||||
|
||||
static void icvUpdateWindowSize( const CvWindow* window )
|
||||
{
|
||||
int width = 0, height = 240; /* init ˆ al taille de base de l'image*/
|
||||
CvTrackbar* t;
|
||||
Rect globalBounds;
|
||||
|
||||
GetWindowBounds(window->window, kWindowContentRgn, &globalBounds);
|
||||
|
||||
int minWidth = 320;
|
||||
|
||||
if( window->image ) {
|
||||
width = MAX(MAX(window->image->width, width), minWidth);
|
||||
height = window->image->height;
|
||||
} else
|
||||
width = minWidth;
|
||||
|
||||
height += window->trackbarheight;
|
||||
|
||||
//height +=WIDGETHEIGHT; /* 32 pixels are spearating tracbars from the video display */
|
||||
|
||||
globalBounds.right = globalBounds.left + width;
|
||||
globalBounds.bottom = globalBounds.top + height;
|
||||
SetWindowBounds(window->window, kWindowContentRgn, &globalBounds);
|
||||
}
|
||||
|
||||
static void icvDeleteWindow( CvWindow* window )
|
||||
{
|
||||
CvTrackbar* trackbar;
|
||||
|
||||
if( window->prev )
|
||||
window->prev->next = window->next;
|
||||
else
|
||||
hg_windows = window->next;
|
||||
|
||||
if( window->next )
|
||||
window->next->prev = window->prev;
|
||||
|
||||
window->prev = window->next = 0;
|
||||
|
||||
cvReleaseMat( &window->image );
|
||||
cvReleaseMat( &window->dst_image );
|
||||
|
||||
for( trackbar = window->toolbar.first; trackbar != 0; )
|
||||
{
|
||||
CvTrackbar* next = trackbar->next;
|
||||
cvFree( (void**)&trackbar );
|
||||
trackbar = next;
|
||||
}
|
||||
|
||||
if (window->imageRef != NULL)
|
||||
CGImageRelease(window->imageRef);
|
||||
|
||||
cvFree( (void**)&window );
|
||||
}
|
||||
|
||||
|
||||
CV_IMPL void cvDestroyWindow( const char* name)
|
||||
{
|
||||
CV_FUNCNAME( "cvDestroyWindow" );
|
||||
|
||||
__BEGIN__;
|
||||
|
||||
CvWindow* window;
|
||||
|
||||
if(!name)
|
||||
CV_ERROR( CV_StsNullPtr, "NULL name string" );
|
||||
|
||||
window = icvFindWindowByName( name );
|
||||
if( !window )
|
||||
EXIT;
|
||||
|
||||
icvDeleteWindow( window );
|
||||
|
||||
__END__;
|
||||
}
|
||||
|
||||
|
||||
CV_IMPL void cvDestroyAllWindows( void )
|
||||
{
|
||||
while( hg_windows )
|
||||
{
|
||||
CvWindow* window = hg_windows;
|
||||
icvDeleteWindow( window );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
CV_IMPL void cvShowImage( const char* name, const CvArr* arr)
|
||||
{
|
||||
CV_FUNCNAME( "cvShowImage" );
|
||||
|
||||
__BEGIN__;
|
||||
|
||||
CvWindow* window;
|
||||
int origin = 0;
|
||||
int resize = 0;
|
||||
CvMat stub, *image;
|
||||
|
||||
if( !name )
|
||||
CV_ERROR( CV_StsNullPtr, "NULL name" );
|
||||
|
||||
window = icvFindWindowByName(name);
|
||||
if( !window || !arr )
|
||||
EXIT; // keep silence here.
|
||||
|
||||
if( CV_IS_IMAGE_HDR( arr ))
|
||||
origin = ((IplImage*)arr)->origin;
|
||||
|
||||
CV_CALL( image = cvGetMat( arr, &stub ));
|
||||
|
||||
/*
|
||||
if( !window->image )
|
||||
cvResizeWindow( name, image->cols, image->rows );
|
||||
*/
|
||||
|
||||
if( window->image &&
|
||||
!CV_ARE_SIZES_EQ(window->image, image) ) {
|
||||
if ( ! (window->flags & CV_WINDOW_AUTOSIZE) )//FD
|
||||
resize = 1;
|
||||
cvReleaseMat( &window->image );
|
||||
}
|
||||
|
||||
if( !window->image ) {
|
||||
resize = 1;//FD
|
||||
window->image = cvCreateMat( image->rows, image->cols, CV_8UC3 );
|
||||
}
|
||||
|
||||
cvConvertImage( image, window->image, (origin != 0 ? CV_CVTIMG_FLIP : 0) + CV_CVTIMG_SWAP_RB );
|
||||
icvPutImage( window );
|
||||
if ( resize )//FD
|
||||
icvUpdateWindowSize( window );
|
||||
|
||||
__END__;
|
||||
}
|
||||
|
||||
CV_IMPL void cvResizeWindow( const char* name, int width, int height)
|
||||
{
|
||||
CV_FUNCNAME( "cvResizeWindow" );
|
||||
|
||||
__BEGIN__;
|
||||
|
||||
CvWindow* window;
|
||||
//CvTrackbar* trackbar;
|
||||
|
||||
if( !name )
|
||||
CV_ERROR( CV_StsNullPtr, "NULL name" );
|
||||
|
||||
window = icvFindWindowByName(name);
|
||||
if(!window)
|
||||
EXIT;
|
||||
|
||||
SizeWindow(window->window, width, height, true);
|
||||
|
||||
__END__;
|
||||
}
|
||||
|
||||
CV_IMPL void cvMoveWindow( const char* name, int x, int y)
|
||||
{
|
||||
CV_FUNCNAME( "cvMoveWindow" );
|
||||
|
||||
__BEGIN__;
|
||||
|
||||
CvWindow* window;
|
||||
//CvTrackbar* trackbar;
|
||||
|
||||
if( !name )
|
||||
CV_ERROR( CV_StsNullPtr, "NULL name" );
|
||||
|
||||
window = icvFindWindowByName(name);
|
||||
if(!window)
|
||||
EXIT;
|
||||
|
||||
MoveWindow(window->window, x, y, true);
|
||||
|
||||
__END__;
|
||||
}
|
||||
|
||||
void TrackbarActionProcPtr (ControlRef theControl, ControlPartCode partCode)
|
||||
{
|
||||
CvTrackbar * trackbar = icvTrackbarByHandle (theControl);
|
||||
|
||||
if (trackbar == NULL)
|
||||
{
|
||||
fprintf(stderr,"Erreur recuperation trackbar\n");
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( trackbar->data )
|
||||
*trackbar->data = GetControl32BitValue (theControl);
|
||||
if ( trackbar->notify )
|
||||
trackbar->notify(GetControl32BitValue (theControl));
|
||||
}
|
||||
}
|
||||
|
||||
CV_IMPL int cvCreateTrackbar (const char* trackbar_name, const char* window_name,int* val, int count, CvTrackbarCallback on_notify)
|
||||
{
|
||||
int result = 0;
|
||||
|
||||
CV_FUNCNAME( "cvCreateTrackbar" );
|
||||
__BEGIN__;
|
||||
|
||||
/*char slider_name[32];*/
|
||||
CvWindow* window = 0;
|
||||
CvTrackbar* trackbar = 0;
|
||||
Rect stboundsRect;
|
||||
ControlRef outControl;
|
||||
ControlRef stoutControl;
|
||||
Rect bounds;
|
||||
|
||||
if( !window_name || !trackbar_name )
|
||||
CV_ERROR( CV_StsNullPtr, "NULL window or trackbar name" );
|
||||
|
||||
if( count <= 0 )
|
||||
CV_ERROR( CV_StsOutOfRange, "Bad trackbar maximal value" );
|
||||
|
||||
window = icvFindWindowByName(window_name);
|
||||
if( !window )
|
||||
EXIT;
|
||||
|
||||
trackbar = icvFindTrackbarByName(window,trackbar_name);
|
||||
if( !trackbar )
|
||||
{
|
||||
int len = strlen(trackbar_name);
|
||||
trackbar = (CvTrackbar*)cvAlloc(sizeof(CvTrackbar) + len + 1);
|
||||
memset( trackbar, 0, sizeof(*trackbar));
|
||||
trackbar->signature = CV_TRACKBAR_MAGIC_VAL;
|
||||
trackbar->name = (char*)(trackbar+1);
|
||||
memcpy( trackbar->name, trackbar_name, len + 1 );
|
||||
trackbar->parent = window;
|
||||
trackbar->next = window->toolbar.first;
|
||||
window->toolbar.first = trackbar;
|
||||
|
||||
if( val )
|
||||
{
|
||||
int value = *val;
|
||||
if( value < 0 )
|
||||
value = 0;
|
||||
if( value > count )
|
||||
value = count;
|
||||
trackbar->pos = value;
|
||||
trackbar->data = val;
|
||||
}
|
||||
|
||||
trackbar->maxval = count;
|
||||
trackbar->notify = on_notify;
|
||||
|
||||
int c = icvCountTrackbarInWindow(window);
|
||||
|
||||
GetWindowBounds(window->window,kWindowContentRgn,&bounds);
|
||||
|
||||
stboundsRect.top = (INTERWIDGETSPACE +WIDGETHEIGHT)* (c-1)+INTERWIDGETSPACE;
|
||||
stboundsRect.left = INTERWIDGETSPACE;
|
||||
stboundsRect.bottom = stboundsRect.top + WIDGETHEIGHT;
|
||||
stboundsRect.right = stboundsRect.left+LABELWIDTH;
|
||||
|
||||
fprintf(stdout,"create trackabar bounds (%d %d %d %d)\n",stboundsRect.top,stboundsRect.left,stboundsRect.bottom,stboundsRect.right);
|
||||
CreateStaticTextControl (window->window,&stboundsRect,CFStringCreateWithCString(NULL,trackbar_name,kCFStringEncodingASCII),NULL,&stoutControl);
|
||||
|
||||
stboundsRect.top = (INTERWIDGETSPACE +WIDGETHEIGHT)* (c-1)+INTERWIDGETSPACE;
|
||||
stboundsRect.left = INTERWIDGETSPACE*2+LABELWIDTH;
|
||||
stboundsRect.bottom = stboundsRect.top + WIDGETHEIGHT;
|
||||
stboundsRect.right = bounds.right-INTERWIDGETSPACE;
|
||||
|
||||
CreateSliderControl (window->window,&stboundsRect, trackbar->pos,0,trackbar->maxval,kControlSliderLiveFeedback,0,true,NewControlActionUPP(TrackbarActionProcPtr),&outControl);
|
||||
|
||||
bounds.bottom += INTERWIDGETSPACE + WIDGETHEIGHT;
|
||||
SetControlVisibility (outControl,true,true);
|
||||
SetControlVisibility (stoutControl,true,true);
|
||||
|
||||
trackbar->trackbar = outControl;
|
||||
trackbar->label = stoutControl;
|
||||
if (c == 1)
|
||||
window->trackbarheight = INTERWIDGETSPACE*2 + WIDGETHEIGHT;
|
||||
else
|
||||
window->trackbarheight += INTERWIDGETSPACE + WIDGETHEIGHT;
|
||||
icvUpdateWindowSize( window );
|
||||
}
|
||||
__END__;
|
||||
return result;
|
||||
}
|
||||
|
||||
CV_IMPL void
|
||||
cvSetMouseCallback( const char* name, CvMouseCallback function, void* info)
|
||||
{
|
||||
CvWindow* window = icvFindWindowByName( name );
|
||||
if (window != NULL)
|
||||
{
|
||||
window->on_mouse = function;
|
||||
window->on_mouse_param = info;
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf(stdout,"Une erreur lors de cvSetMouseCallback, window nom trouvee : %s",name);
|
||||
}
|
||||
}
|
||||
|
||||
CV_IMPL int cvGetTrackbarPos( const char*, const char* )
|
||||
{
|
||||
//CV_NO_GTK_ERROR( "cvGetTrackbarPos" );
|
||||
return -1;
|
||||
}
|
||||
|
||||
CV_IMPL void cvSetTrackbarPos( const char*, const char*, int )
|
||||
{
|
||||
// CV_NO_GTK_ERROR( "cvSetTrackbarPos" );
|
||||
return ;
|
||||
}
|
||||
|
||||
CV_IMPL void* cvGetWindowHandle( const char* name )
|
||||
{
|
||||
WindowRef result = 0;
|
||||
|
||||
CV_FUNCNAME( "cvGetWindowHandle" );
|
||||
|
||||
__BEGIN__;
|
||||
|
||||
CvWindow* window;
|
||||
window = icvFindWindowByName( name );
|
||||
if (window != NULL)
|
||||
result = window->window;
|
||||
else
|
||||
result = NULL;
|
||||
|
||||
__END__;
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
CV_IMPL const char* cvGetWindowName( void* window_handle )
|
||||
{
|
||||
const char* window_name = "";
|
||||
|
||||
CV_FUNCNAME( "cvGetWindowName" );
|
||||
|
||||
__BEGIN__;
|
||||
|
||||
CvWindow* window;
|
||||
|
||||
if( window_handle == 0 )
|
||||
CV_ERROR( CV_StsNullPtr, "NULL window" );
|
||||
window = icvWindowByHandle(window_handle );
|
||||
if( window )
|
||||
window_name = window->name;
|
||||
|
||||
__END__;
|
||||
|
||||
return window_name;
|
||||
}
|
||||
|
||||
|
||||
CV_IMPL int cvNamedWindow( const char* name, int flags )
|
||||
{
|
||||
int result = 0;
|
||||
CV_FUNCNAME( "cvNamedWindow" );
|
||||
if (!wasInitialized)
|
||||
cvInitSystem(0, NULL);
|
||||
|
||||
// to be able to display a window, we need to be a 'faceful' application
|
||||
// http://lists.apple.com/archives/carbon-dev/2005/Jun/msg01414.html
|
||||
static bool switched_to_faceful = false;
|
||||
if (! switched_to_faceful)
|
||||
{
|
||||
ProcessSerialNumber psn = { 0, kCurrentProcess };
|
||||
OSStatus ret = TransformProcessType (&psn, kProcessTransformToForegroundApplication );
|
||||
|
||||
if (ret == noErr)
|
||||
{
|
||||
SetFrontProcess( &psn );
|
||||
switched_to_faceful = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf(stderr, "Failed to tranform process type: %d\n", (int) ret);
|
||||
fflush (stderr);
|
||||
}
|
||||
}
|
||||
|
||||
__BEGIN__;
|
||||
|
||||
WindowRef outWindow = NULL;
|
||||
OSStatus err = noErr;
|
||||
Rect contentBounds = {100,100,320,440};
|
||||
|
||||
CvWindow* window;
|
||||
UInt wAttributes = 0;
|
||||
|
||||
int len;
|
||||
|
||||
const EventTypeSpec genericWindowEventHandler[] = {
|
||||
{ kEventClassMouse, kEventMouseMoved},
|
||||
{ kEventClassMouse, kEventMouseUp},
|
||||
{ kEventClassMouse, kEventMouseDown},
|
||||
{ kEventClassWindow, kEventWindowClose },
|
||||
{ kEventClassWindow, kEventWindowBoundsChanged }//FD
|
||||
};
|
||||
|
||||
if( !name )
|
||||
CV_ERROR( CV_StsNullPtr, "NULL name string" );
|
||||
|
||||
if( icvFindWindowByName( name ) != 0 ){
|
||||
result = 1;
|
||||
EXIT;
|
||||
}
|
||||
len = strlen(name);
|
||||
CV_CALL( window = (CvWindow*)cvAlloc(sizeof(CvWindow) + len + 1));
|
||||
memset( window, 0, sizeof(*window));
|
||||
window->name = (char*)(window + 1);
|
||||
memcpy( window->name, name, len + 1 );
|
||||
window->flags = flags;
|
||||
window->signature = CV_WINDOW_MAGIC_VAL;
|
||||
window->image = 0;
|
||||
window->last_key = 0;
|
||||
window->on_mouse = 0;
|
||||
window->on_mouse_param = 0;
|
||||
|
||||
window->next = hg_windows;
|
||||
window->prev = 0;
|
||||
if( hg_windows )
|
||||
hg_windows->prev = window;
|
||||
hg_windows = window;
|
||||
wAttributes = kWindowStandardDocumentAttributes | kWindowStandardHandlerAttribute | kWindowLiveResizeAttribute;
|
||||
|
||||
err = CreateNewWindow ( kDocumentWindowClass,wAttributes,&contentBounds,&outWindow);
|
||||
if (err != noErr)
|
||||
fprintf(stderr,"Erreur while creating the window\n");
|
||||
|
||||
SetWindowTitleWithCFString(outWindow,CFStringCreateWithCString(NULL,name,kCFStringEncodingASCII));
|
||||
if (err != noErr)
|
||||
fprintf(stdout,"Erreur SetWindowTitleWithCFString\n");
|
||||
|
||||
window->window = outWindow;
|
||||
|
||||
err = InstallWindowEventHandler(outWindow, NewEventHandlerUPP(windowEventHandler), GetEventTypeCount(genericWindowEventHandler), genericWindowEventHandler, outWindow, NULL);
|
||||
|
||||
ShowWindow( outWindow );
|
||||
result = 1;
|
||||
|
||||
__END__;
|
||||
return result;
|
||||
}
|
||||
|
||||
static pascal OSStatus windowEventHandler(EventHandlerCallRef nextHandler, EventRef theEvent, void *inUserData)
|
||||
{
|
||||
CvWindow* window = NULL;
|
||||
UInt32 eventKind, eventClass;
|
||||
OSErr err = noErr;
|
||||
int event = 0;
|
||||
UInt32 count = 0;
|
||||
HIPoint point = {0,0};
|
||||
EventMouseButton eventMouseButton = 0;//FD
|
||||
UInt32 modifiers;//FD
|
||||
|
||||
WindowRef theWindow = (WindowRef)inUserData;
|
||||
if (theWindow == NULL)
|
||||
return eventNotHandledErr;
|
||||
window = icvWindowByHandle(theWindow);
|
||||
if ( window == NULL)
|
||||
return eventNotHandledErr;
|
||||
|
||||
eventKind = GetEventKind(theEvent);
|
||||
eventClass = GetEventClass(theEvent);
|
||||
|
||||
switch (eventClass) {
|
||||
case kEventClassMouse : {
|
||||
switch (eventKind){
|
||||
case kEventMouseUp :
|
||||
case kEventMouseDown :
|
||||
case kEventMouseMoved : {
|
||||
err = CallNextEventHandler(nextHandler, theEvent);
|
||||
if (err != eventNotHandledErr)
|
||||
return err;
|
||||
err = GetEventParameter(theEvent, kEventParamMouseButton, typeMouseButton, NULL, sizeof(eventMouseButton), NULL, &eventMouseButton);
|
||||
err = GetEventParameter(theEvent, kEventParamKeyModifiers, typeUInt32, NULL, sizeof(modifiers), NULL, &modifiers);
|
||||
err = GetEventParameter(theEvent,kEventParamClickCount,typeUInt32,NULL,sizeof(UInt32),NULL,&count);
|
||||
if (err == noErr){
|
||||
if (count >1) event += 6;
|
||||
} else {
|
||||
event = CV_EVENT_MOUSEMOVE;
|
||||
}
|
||||
|
||||
if (eventKind == kEventMouseUp)
|
||||
event +=4;
|
||||
if (eventKind == kEventMouseDown)
|
||||
event +=1;
|
||||
|
||||
err = GetEventParameter(theEvent, kEventParamWindowMouseLocation, typeHIPoint, NULL, sizeof(point), NULL, &point);
|
||||
if (eventKind != kEventMouseMoved){
|
||||
switch(eventMouseButton){
|
||||
case kEventMouseButtonPrimary:
|
||||
if (modifiers & controlKey) /* ctrl-click for right button */
|
||||
event += 1;
|
||||
break;
|
||||
case kEventMouseButtonSecondary:
|
||||
event += 1;
|
||||
break;
|
||||
case kEventMouseButtonTertiary:
|
||||
event += 2;
|
||||
break;
|
||||
}
|
||||
}
|
||||
int c = icvCountTrackbarInWindow(window);
|
||||
|
||||
if (window->on_mouse != NULL){
|
||||
int lx,ly;
|
||||
Rect structure, content;
|
||||
GetWindowBounds(theWindow, kWindowStructureRgn, &structure);
|
||||
GetWindowBounds(theWindow, kWindowContentRgn, &content);
|
||||
lx = point.x - content.left + structure.left;
|
||||
ly = point.y - window->trackbarheight - content.top + structure.top; /* minus la taille des trackbars */
|
||||
if (window->flags & CV_WINDOW_AUTOSIZE) {//FD
|
||||
//printf("was %d,%d\n", lx, ly);
|
||||
/* scale the mouse coordinates */
|
||||
lx = lx * window->imageWidth / (content.right - content.left);
|
||||
ly = ly * window->imageHeight / (content.bottom - content.top - window->trackbarheight);
|
||||
//printf("now %d,%d\n", lx, ly);
|
||||
}
|
||||
//fprintf(stdout,"final OpenCV event is %d\n",event);
|
||||
//fprintf(stdout,"event @ %d %d which is localy %d %d offset of %d\n",point.h, point.v ,lx,ly,yOffset);
|
||||
if (lx>0 && ly >0){ /* a remettre dans les coordonnŽes locale */
|
||||
window->on_mouse(event,lx,ly,0,NULL);
|
||||
}
|
||||
}
|
||||
}
|
||||
default : return eventNotHandledErr;
|
||||
}
|
||||
}
|
||||
case kEventClassWindow : {//FD
|
||||
switch (eventKind){
|
||||
case kEventWindowBoundsChanged :
|
||||
{
|
||||
/* resize the trackbars */
|
||||
CvTrackbar *t;
|
||||
Rect bounds;
|
||||
GetWindowBounds(window->window,kWindowContentRgn,&bounds);
|
||||
for ( t = window->toolbar.first; t != 0; t = t->next )
|
||||
SizeControl(t->trackbar,bounds.right - bounds.left - INTERWIDGETSPACE*3 - LABELWIDTH , WIDGETHEIGHT);
|
||||
}
|
||||
/* redraw the image */
|
||||
icvDrawImage(window);
|
||||
break;
|
||||
default :
|
||||
return eventNotHandledErr;
|
||||
}
|
||||
}
|
||||
default:
|
||||
return eventNotHandledErr;
|
||||
}
|
||||
|
||||
return eventNotHandledErr;
|
||||
}
|
||||
|
||||
OSStatus keyHandler(EventHandlerCallRef hcr, EventRef theEvent, void* inUserData)
|
||||
{
|
||||
UInt32 eventKind;
|
||||
UInt32 eventClass;
|
||||
OSErr err = noErr;
|
||||
|
||||
eventKind = GetEventKind (theEvent);
|
||||
eventClass = GetEventClass (theEvent);
|
||||
err = GetEventParameter(theEvent, kEventParamKeyMacCharCodes, typeChar, NULL, sizeof(lastKey), NULL, &lastKey);
|
||||
if (err != noErr)
|
||||
lastKey = NO_KEY;
|
||||
|
||||
return noErr;
|
||||
}
|
||||
|
||||
CV_IMPL int cvWaitKey (int maxWait)
|
||||
{
|
||||
EventRecord theEvent;
|
||||
|
||||
// wait at least for one event (to allow mouse, etc. processing), exit if maxWait milliseconds passed (nullEvent)
|
||||
UInt32 start = TickCount();
|
||||
do
|
||||
{
|
||||
// remaining time until maxWait is over
|
||||
UInt32 wait = EventTimeToTicks (maxWait / 1000.0) - (TickCount() - start);
|
||||
if (wait < 0)
|
||||
wait = 0;
|
||||
|
||||
WaitNextEvent (everyEvent, &theEvent, maxWait > 0 ? wait : kDurationForever, NULL);
|
||||
}
|
||||
while (lastKey == NO_KEY && theEvent.what != nullEvent);
|
||||
|
||||
int key = lastKey;
|
||||
lastKey = NO_KEY;
|
||||
return key;
|
||||
}
|
||||
|
||||
/* End of file. */
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user