├── .gitignore ├── .gitmodules ├── LICENSE ├── Makefile.am ├── README ├── autogen.sh ├── configure.ac ├── doxygen.am ├── m4 ├── ac_append_supported_cflags.m4 ├── ac_append_supported_ldflags.m4 ├── as-nano.m4 ├── ax_boost_base.m4 ├── ax_boost_program_options.m4 ├── ax_boost_system.m4 ├── ax_boost_thread.m4 ├── ax_create_stdint_h.m4 ├── ax_cxx_have_sstream.m4 ├── ax_cxx_namespaces.m4 ├── ax_prog_doxygen.m4 └── ax_pthread.m4 ├── src ├── DecodeFrame │ ├── DecodeFrame.cpp │ ├── DecodeParams.cpp │ ├── DecodeParams.h │ └── Makefile.am ├── DecodeStream │ ├── DecodeParams.cpp │ ├── DecodeParams.h │ ├── DecodeStream.cpp │ └── Makefile.am ├── EncodeStream │ ├── EncodeParams.cpp │ ├── EncodeParams.h │ ├── EncodeStream.cpp │ └── Makefile.am ├── Library │ ├── Arrays.h │ ├── DataUnit.h │ ├── Frame.h │ ├── FrameResolutions.h │ ├── Makefile.am │ ├── Picture.h │ ├── Quantisation.h │ ├── Slices.h │ ├── Utils.h │ ├── VLC.h │ ├── WaveletTransform.h │ └── src │ │ ├── Arrays.cpp │ │ ├── DataUnit.cpp │ │ ├── Frame.cpp │ │ ├── Picture.cpp │ │ ├── Quantisation.cpp │ │ ├── Slices.cpp │ │ ├── Utils.cpp │ │ ├── VLC.cpp │ │ └── WaveletTransform.cpp ├── Makefile.am ├── boost │ ├── COPYING │ ├── Makefile.am │ ├── multi_array.hpp │ ├── multi_array.original │ └── multi_array │ │ ├── algorithm.hpp │ │ ├── base.hpp │ │ ├── collection_concept.hpp │ │ ├── concept_checks.hpp │ │ ├── copy_array.hpp │ │ ├── extent_gen.hpp │ │ ├── extent_range.hpp │ │ ├── index_gen.hpp │ │ ├── index_range.hpp │ │ ├── iterator.hpp │ │ ├── multi_array_ref.hpp │ │ ├── multi_array_ref.original │ │ ├── range_list.hpp │ │ ├── storage_order.hpp │ │ ├── subarray.hpp │ │ ├── subarray.original │ │ ├── types.hpp │ │ ├── view.hpp │ │ └── view.original └── tclap │ ├── Arg.h │ ├── ArgException.h │ ├── ArgTraits.h │ ├── COPYING │ ├── CmdLine.h │ ├── CmdLineInterface.h │ ├── CmdLineOutput.h │ ├── Constraint.h │ ├── DocBookOutput.h │ ├── HelpVisitor.h │ ├── IgnoreRestVisitor.h │ ├── Makefile.am │ ├── MultiArg.h │ ├── MultiSwitchArg.h │ ├── OptionalUnlabeledTracker.h │ ├── StandardTraits.h │ ├── StdOutput.h │ ├── SwitchArg.h │ ├── UnlabeledMultiArg.h │ ├── UnlabeledValueArg.h │ ├── ValueArg.h │ ├── ValuesConstraint.h │ ├── VersionVisitor.h │ ├── Visitor.h │ ├── XorHandler.h │ └── ZshCompletionOutput.h ├── tests ├── .gitignore ├── Arrays.cpp ├── DataUnit.cpp ├── Makefile.am ├── Quantisation.cpp └── Utils.cpp └── tools ├── Makefile.am ├── convert_from_16p2 ├── convert_to_16p2 └── vc2streamdebugger /.gitignore: -------------------------------------------------------------------------------- 1 | *.in 2 | aclocal.m4 3 | autom4te.cache/ 4 | compile 5 | config.guess 6 | config.sub 7 | configure 8 | depcomp 9 | missing 10 | src/vc2reference-stdint.h 11 | .#* 12 | *~ 13 | install-sh 14 | ltmain.sh 15 | m4/libtool.m4 16 | m4/ltoptions.m4 17 | m4/ltsugar.m4 18 | m4/ltversion.m4 19 | m4/lt~obsolete.m4 20 | 21 | src/DecodeStream 22 | src/EncodeStream 23 | src/DecodeFrame 24 | 25 | test-driver 26 | ar-lib 27 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "googletest"] 2 | path = googletest 3 | url = git@github.com:google/googletest.git 4 | ignore = untracked 5 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright [2015] [British Broadcasting Corporation] 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | -------------------------------------------------------------------------------- /Makefile.am: -------------------------------------------------------------------------------- 1 | 2 | AUTOMAKE_OPTIONS = foreign 3 | 4 | SUBDIRS = src tools tests 5 | 6 | EXTRA_DIST = autogen.sh 7 | 8 | ACLOCAL_AMFLAGS = -I m4 9 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | VC-2 Reference Encoder and Decoder 2 | ---------------------------------- 3 | 4 | Copyright (C) Tim Borer, James Weaver and Galen Reich 2010-2020, 5 | British Broadcasting Corporation. 6 | < galen.reich@bbc.co.uk > 7 | 8 | 9 | This repository contains a SMPTE 2042-1 VC-2 reference encoder and 10 | decoder. It can be compiled using autotools on Linux or Windows and 11 | includes the following executables once compiled: 12 | 13 | o EncodeStream -- an encoder which will encode a VC-2 compliant stream 14 | using one of the supported LD or HQ profiles. 15 | o DecodeStream -- a decoder which will decode a VC-2 compliant stream 16 | which complies with the LD or HQ profiles. 17 | 18 | The EncodeStream tool supports the following profiles: 19 | o HQ_CBR -- an encoder for the High Quality (HQ) profile of 20 | VC-2 which encodes at a constant bit rate. 21 | o HQ_ConstQ -- an encoder for the High Quality (HQ) profile of 22 | VC-2 which encodes with a constant quantiser value. 23 | o LD -- an OBSOLETE encoder for the Low Delay (LD) profile of VC-2. 24 | (included for backwards compatibility). 25 | 26 | In addition, an optional utility (DecodeFrame) is includeded which 27 | takes in the compressed bytes of a VC-2 frame without any surrounding 28 | headers. This is not compiled by default but can be enabled with the 29 | --enable-frame-decoder flag (./configure --enable-frame-decoder). 30 | 31 | The googletest testing framework can be used to run tests on the 32 | repository. This requires the googletest submodule to be added by 33 | git submodule init 34 | git submodule update 35 | (or using --recurse-submodules when cloning) 36 | Then using `make check' to build and run the tests. 37 | 38 | Additional help on each executable will be printed if it is run with 39 | the --help parameter. 40 | -------------------------------------------------------------------------------- /autogen.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | autoreconf -f -i 3 | -------------------------------------------------------------------------------- /configure.ac: -------------------------------------------------------------------------------- 1 | AC_PREREQ([2.68]) 2 | AC_INIT([VC2REFERENCE],[0.1.0.2]) 3 | 4 | AC_CANONICAL_TARGET 5 | case $target in 6 | x86_64-*) 7 | TARGET="x86_64" 8 | ;; 9 | *) 10 | TARGET="unknown" 11 | ;; 12 | esac 13 | if test "$TARGET" != "x86_64" ; then 14 | AC_MSG_ERROR([Only x86_64 architecture is supported]) 15 | fi; 16 | 17 | AS_NANO(VC2REFERENCE_CVS=no,VC2REFERENCE_CVS=yes) 18 | 19 | AM_INIT_AUTOMAKE([1.11 silent-rules subdir-objects]) 20 | AM_SILENT_RULES([yes]) 21 | 22 | # Version number that will be appended to the library filename 23 | VC2REFERENCE_MAJORMINOR=0.1 24 | AC_SUBST(VC2REFERENCE_MAJORMINOR) 25 | 26 | AC_CONFIG_HEADERS([config.h]) 27 | 28 | AM_PROG_AR 29 | LT_PREREQ([2.2.6]) 30 | LT_INIT(disable-static win32-dll) 31 | 32 | AC_PROG_CXX 33 | AM_PROG_CC_C_O 34 | 35 | AC_CONFIG_SRCDIR([src/Library/Utils.h]) 36 | 37 | AC_CONFIG_MACRO_DIR([m4]) 38 | ACLOCAL_AMFLAGS="-I m4 $ACLOCAL_AMFLAGS" 39 | AC_SUBST(ACLOCAL_AMFLAGS) 40 | 41 | AC_MSG_CHECKING(whether to enable frame decoder) 42 | AC_ARG_ENABLE([frame-decoder], 43 | [ --enable-frame-decoder Turn on frame decoder], 44 | [case "${enableval}" in 45 | yes) framedecoder=true ;; 46 | no) framedecoder=false ;; 47 | *) AC_MSG_ERROR([bad value ${enableval} for --enable-frame-decoder]) ;; 48 | esac],[framedecoder=false]) 49 | AM_CONDITIONAL([ENABLE_FRAME_DECODER], [test "x$framedecoder" = "xtrue"]) 50 | 51 | VC2REFERENCE_CFLAGS="$VC2REFERENCE_CFLAGS -g -Og -DDEBUG" 52 | CXXFLAGS="-Og" 53 | VC2REFERENCE_LDFLAGS="$VC2REFERENCE_LDFLAGS" 54 | 55 | LIBBOOST_VER="1.49.0" 56 | AX_BOOST_BASE($LIBBOOST_VER, HAVE_BOOST=yes, HAVE_BOOST=no) 57 | if test "x${HAVE_BOOST}" != xyes ; then 58 | AC_MSG_ERROR([Boost library is required]) 59 | fi 60 | AX_BOOST_PROGRAM_OPTIONS 61 | AX_BOOST_THREAD 62 | AX_BOOST_SYSTEM 63 | AX_CXX_HAVE_SSTREAM 64 | 65 | # Check for pkg-config 66 | PKG_PROG_PKG_CONFIG([0.26]) 67 | 68 | IS_LINUX=no 69 | AC_CANONICAL_HOST 70 | case $host_os in 71 | linux*) 72 | IS_LINUX=yes 73 | ;; 74 | esac 75 | AM_CONDITIONAL(IS_LINUX, test x${IS_LINUX} = xyes) 76 | AC_SUBST(IS_LINUX) 77 | 78 | # Checks for typedefs, structures, and compiler characteristics. 79 | AC_TYPE_SIZE_T 80 | AX_CREATE_STDINT_H([src/vc2reference-stdint.h]) 81 | 82 | AC_APPEND_SUPPORTED_CFLAGS(VC2REFERENCE_CFLAGS, [-Wall]) 83 | 84 | VC2REFERENCE_CFLAGS="$VC2REFERENCE_CFLAGS -I\$(top_srcdir)" 85 | AC_SUBST(VC2REFERENCE_CFLAGS) 86 | 87 | VC2REFERENCE_LDFLAGS="$VC2REFERENCE_LDFLAGS" 88 | AC_APPEND_SUPPORTED_LDFLAGS(VC2REFERENCE_LDFLAGS, [-Wl,--no-undefined]) 89 | if test "x$IS_LINUX" = "xno" 90 | then 91 | AC_APPEND_SUPPORTED_LDFLAGS(VC2REFERENCE_LDFLAGS, [-Qunused-arguments]) 92 | fi 93 | AC_SUBST(VC2REFERENCE_LDFLAGS) 94 | 95 | VC2REFERENCE_LIBS="\$(top_builddir)/src/Libaray/libVC2-$VC2REFERENCE_MAJORMINOR.la" 96 | AC_SUBST(VC2REFERENCE_LIBS) 97 | 98 | AC_SUBST(VC2REFERENCE_PKG_DEPS) 99 | 100 | pkgconfigdir="\$(libdir)/pkgconfig" 101 | AC_SUBST(pkgconfigdir) 102 | 103 | vc2referencebindir="\$(libdir)/vc2reference/" 104 | AC_SUBST(vc2referencebindir) 105 | 106 | configfiledir="\$(sysconfdir)/vc2reference" 107 | AC_SUBST(configfiledir) 108 | 109 | AC_CONFIG_FILES([ 110 | Makefile 111 | tests/Makefile 112 | tools/Makefile 113 | src/Makefile 114 | src/boost/Makefile 115 | src/tclap/Makefile 116 | src/Library/Makefile 117 | src/DecodeStream/Makefile 118 | src/EncodeStream/Makefile 119 | src/DecodeFrame/Makefile 120 | ]) 121 | AC_OUTPUT 122 | -------------------------------------------------------------------------------- /doxygen.am: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2004 Oren Ben-Kiki 2 | # This file is distributed under the same terms as the Automake macro files. 3 | 4 | # Generate automatic documentation using Doxygen. Goals and variables values 5 | # are controlled by the various DX_COND_??? conditionals set by autoconf. 6 | # 7 | # The provided goals are: 8 | # doxygen-doc: Generate all doxygen documentation. 9 | # doxygen-run: Run doxygen, which will generate some of the documentation 10 | # (HTML, CHM, CHI, MAN, RTF, XML) but will not do the post 11 | # processing required for the rest of it (PS, PDF, and some MAN). 12 | # doxygen-man: Rename some doxygen generated man pages. 13 | # doxygen-ps: Generate doxygen PostScript documentation. 14 | # doxygen-pdf: Generate doxygen PDF documentation. 15 | # 16 | # Note that by default these are not integrated into the automake goals. If 17 | # doxygen is used to generate man pages, you can achieve this integration by 18 | # setting man3_MANS to the list of man pages generated and then adding the 19 | # dependency: 20 | # 21 | # $(man3_MANS): doxygen-doc 22 | # 23 | # This will cause make to run doxygen and generate all the documentation. 24 | # 25 | # The following variable is intended for use in Makefile.am: 26 | # 27 | # DX_CLEANFILES = everything to clean. 28 | # 29 | # This is usually added to MOSTLYCLEANFILES. 30 | 31 | ## --------------------------------- ## 32 | ## Format-independent Doxygen rules. ## 33 | ## --------------------------------- ## 34 | 35 | if DX_COND_doc 36 | 37 | ## ------------------------------- ## 38 | ## Rules specific for HTML output. ## 39 | ## ------------------------------- ## 40 | 41 | if DX_COND_html 42 | 43 | DX_CLEAN_HTML = @DX_DOCDIR@/html 44 | 45 | endif DX_COND_html 46 | 47 | ## ------------------------------ ## 48 | ## Rules specific for CHM output. ## 49 | ## ------------------------------ ## 50 | 51 | if DX_COND_chm 52 | 53 | DX_CLEAN_CHM = @DX_DOCDIR@/chm 54 | 55 | if DX_COND_chi 56 | 57 | DX_CLEAN_CHI = @DX_DOCDIR@/@PACKAGE@.chi 58 | 59 | endif DX_COND_chi 60 | 61 | endif DX_COND_chm 62 | 63 | ## ------------------------------ ## 64 | ## Rules specific for MAN output. ## 65 | ## ------------------------------ ## 66 | 67 | if DX_COND_man 68 | 69 | DX_CLEAN_MAN = @DX_DOCDIR@/man 70 | 71 | endif DX_COND_man 72 | 73 | ## ------------------------------ ## 74 | ## Rules specific for RTF output. ## 75 | ## ------------------------------ ## 76 | 77 | if DX_COND_rtf 78 | 79 | DX_CLEAN_RTF = @DX_DOCDIR@/rtf 80 | 81 | endif DX_COND_rtf 82 | 83 | ## ------------------------------ ## 84 | ## Rules specific for XML output. ## 85 | ## ------------------------------ ## 86 | 87 | if DX_COND_xml 88 | 89 | DX_CLEAN_XML = @DX_DOCDIR@/xml 90 | 91 | endif DX_COND_xml 92 | 93 | ## ----------------------------- ## 94 | ## Rules specific for PS output. ## 95 | ## ----------------------------- ## 96 | 97 | if DX_COND_ps 98 | 99 | DX_CLEAN_PS = @DX_DOCDIR@/@PACKAGE@.ps 100 | 101 | DX_PS_GOAL = doxygen-ps 102 | 103 | doxygen-ps: @DX_DOCDIR@/@PACKAGE@.ps 104 | 105 | @DX_DOCDIR@/@PACKAGE@.ps: @DX_DOCDIR@/@PACKAGE@.tag 106 | cd @DX_DOCDIR@/latex; \ 107 | rm -f *.aux *.toc *.idx *.ind *.ilg *.log *.out; \ 108 | $(DX_LATEX) refman.tex; \ 109 | $(MAKEINDEX_PATH) refman.idx; \ 110 | $(DX_LATEX) refman.tex; \ 111 | countdown=5; \ 112 | while $(DX_EGREP) 'Rerun (LaTeX|to get cross-references right)' \ 113 | refman.log > /dev/null 2>&1 \ 114 | && test $$countdown -gt 0; do \ 115 | $(DX_LATEX) refman.tex; \ 116 | countdown=`expr $$countdown - 1`; \ 117 | done; \ 118 | $(DX_DVIPS) -o ../@PACKAGE@.ps refman.dvi 119 | 120 | endif DX_COND_ps 121 | 122 | ## ------------------------------ ## 123 | ## Rules specific for PDF output. ## 124 | ## ------------------------------ ## 125 | 126 | if DX_COND_pdf 127 | 128 | DX_CLEAN_PDF = @DX_DOCDIR@/@PACKAGE@.pdf 129 | 130 | DX_PDF_GOAL = doxygen-pdf 131 | 132 | doxygen-pdf: @DX_DOCDIR@/@PACKAGE@.pdf 133 | 134 | @DX_DOCDIR@/@PACKAGE@.pdf: @DX_DOCDIR@/@PACKAGE@.tag 135 | cd @DX_DOCDIR@/latex; \ 136 | rm -f *.aux *.toc *.idx *.ind *.ilg *.log *.out; \ 137 | $(DX_PDFLATEX) refman.tex; \ 138 | $(DX_MAKEINDEX) refman.idx; \ 139 | $(DX_PDFLATEX) refman.tex; \ 140 | countdown=5; \ 141 | while $(DX_EGREP) 'Rerun (LaTeX|to get cross-references right)' \ 142 | refman.log > /dev/null 2>&1 \ 143 | && test $$countdown -gt 0; do \ 144 | $(DX_PDFLATEX) refman.tex; \ 145 | countdown=`expr $$countdown - 1`; \ 146 | done; \ 147 | mv refman.pdf ../@PACKAGE@.pdf 148 | 149 | endif DX_COND_pdf 150 | 151 | ## ------------------------------------------------- ## 152 | ## Rules specific for LaTeX (shared for PS and PDF). ## 153 | ## ------------------------------------------------- ## 154 | 155 | if DX_COND_latex 156 | 157 | DX_CLEAN_LATEX = @DX_DOCDIR@/latex 158 | 159 | endif DX_COND_latex 160 | 161 | .PHONY: doxygen-run doxygen-doc $(DX_PS_GOAL) $(DX_PDF_GOAL) 162 | 163 | .INTERMEDIATE: doxygen-run $(DX_PS_GOAL) $(DX_PDF_GOAL) 164 | 165 | doxygen-run: @DX_DOCDIR@/@PACKAGE@.tag 166 | 167 | doxygen-doc: doxygen-run $(DX_PS_GOAL) $(DX_PDF_GOAL) 168 | 169 | @DX_DOCDIR@/@PACKAGE@.tag: $(DX_CONFIG) $(pkginclude_HEADERS) 170 | rm -rf @DX_DOCDIR@ 171 | $(DX_ENV) $(DX_DOXYGEN) $(srcdir)/$(DX_CONFIG) 172 | 173 | DX_CLEANFILES = \ 174 | @DX_DOCDIR@/@PACKAGE@.tag \ 175 | -r \ 176 | $(DX_CLEAN_HTML) \ 177 | $(DX_CLEAN_CHM) \ 178 | $(DX_CLEAN_CHI) \ 179 | $(DX_CLEAN_MAN) \ 180 | $(DX_CLEAN_RTF) \ 181 | $(DX_CLEAN_XML) \ 182 | $(DX_CLEAN_PS) \ 183 | $(DX_CLEAN_PDF) \ 184 | $(DX_CLEAN_LATEX) 185 | 186 | endif DX_COND_doc 187 | -------------------------------------------------------------------------------- /m4/ac_append_supported_cflags.m4: -------------------------------------------------------------------------------- 1 | dnl AC_APPEND_SUPPORTED_CFLAGS(CFLAGS_VARIABLE, [flags to check]) 2 | dnl Example: AC_APPEND_SUPPORTED_CFLAGS(JSONSPIRIT_CFLAGS, [-Wall -Wextra]) 3 | dnl If flags are supported, they are appended to the variable passed as the first argument 4 | 5 | AC_DEFUN([AC_APPEND_SUPPORTED_CFLAGS], [ 6 | AC_MSG_CHECKING([whether $CC supports $2]) 7 | orig_cflags="$CFLAGS" 8 | CFLAGS="-Werror $2" 9 | AC_LINK_IFELSE([AC_LANG_PROGRAM()], 10 | [support_c_flag=yes], 11 | [support_c_flag=no]) 12 | if test "x$support_c_flag" = "xyes"; then 13 | AC_MSG_RESULT(yes) 14 | $1="$$1 $2" 15 | else 16 | AC_MSG_RESULT(no) 17 | fi 18 | CFLAGS="$orig_cflags" 19 | ]) 20 | -------------------------------------------------------------------------------- /m4/ac_append_supported_ldflags.m4: -------------------------------------------------------------------------------- 1 | dnl AC_APPEND_SUPPORTED_LDFLAGS(LDFLAGS_VARIABLE, [flags to check]) 2 | dnl Example: AC_APPEND_SUPPORTED_LDFLAGS(JSONSPIRIT_LDFLAGS, [-Wl,--no-undefined]) 3 | dnl If flags are supported, they are appended to the variable passed as the first argument 4 | 5 | AC_DEFUN([AC_APPEND_SUPPORTED_LDFLAGS], [ 6 | AC_MSG_CHECKING([whether $CC supports $2]) 7 | orig_ldflags="$LDFLAGS" 8 | LDFLAGS="$2" 9 | AC_LINK_IFELSE([AC_LANG_PROGRAM()], 10 | [support_ld_flag=yes], 11 | [support_ld_flag=no]) 12 | if test "x$support_ld_flag" = "xyes"; then 13 | AC_MSG_RESULT(yes) 14 | $1="$$1 $2" 15 | else 16 | AC_MSG_RESULT(no) 17 | fi 18 | LDFLAGS="$orig_ldflags" 19 | ]) 20 | -------------------------------------------------------------------------------- /m4/as-nano.m4: -------------------------------------------------------------------------------- 1 | dnl as-version.m4 0.1.0 2 | 3 | dnl autostars m4 macro for versioning (modified) 4 | 5 | dnl Thomas Vander Stichele 6 | dnl David Schleef 7 | 8 | dnl $Id: as-nano.m4,v 1.2 2007-03-16 23:30:02 ds Exp $ 9 | 10 | dnl AS_VERSION(ACTION-IF-NO-NANO, [ACTION-IF-NANO]) 11 | 12 | AC_DEFUN([AS_NANO], 13 | [ 14 | AC_MSG_CHECKING(nano version) 15 | 16 | NANO=$(echo AC_PACKAGE_VERSION | sed ['s/[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\.*//']) 17 | AC_SUBST(NANO) 18 | 19 | if test x"$NANO" = x || test "x$NANO" = "x0" ; then 20 | AC_MSG_RESULT([0 (release)]) 21 | NANO=0 22 | ifelse([$1], , :, [$1]) 23 | else 24 | AC_MSG_RESULT($NANO) 25 | ifelse([$2], , :, [$2]) 26 | fi 27 | ]) 28 | -------------------------------------------------------------------------------- /m4/ax_boost_program_options.m4: -------------------------------------------------------------------------------- 1 | # ============================================================================ 2 | # http://www.gnu.org/software/autoconf-archive/ax_boost_program_options.html 3 | # ============================================================================ 4 | # 5 | # SYNOPSIS 6 | # 7 | # AX_BOOST_PROGRAM_OPTIONS 8 | # 9 | # DESCRIPTION 10 | # 11 | # Test for program options library from the Boost C++ libraries. The macro 12 | # requires a preceding call to AX_BOOST_BASE. Further documentation is 13 | # available at . 14 | # 15 | # This macro calls: 16 | # 17 | # AC_SUBST(BOOST_PROGRAM_OPTIONS_LIB) 18 | # 19 | # And sets: 20 | # 21 | # HAVE_BOOST_PROGRAM_OPTIONS 22 | # 23 | # LICENSE 24 | # 25 | # Copyright (c) 2009 Thomas Porschberg 26 | # 27 | # Copying and distribution of this file, with or without modification, are 28 | # permitted in any medium without royalty provided the copyright notice 29 | # and this notice are preserved. This file is offered as-is, without any 30 | # warranty. 31 | 32 | #serial 22 33 | 34 | AC_DEFUN([AX_BOOST_PROGRAM_OPTIONS], 35 | [ 36 | AC_ARG_WITH([boost-program-options], 37 | AS_HELP_STRING([--with-boost-program-options@<:@=special-lib@:>@], 38 | [use the program options library from boost - it is possible to specify a certain library for the linker 39 | e.g. --with-boost-program-options=boost_program_options-gcc-mt-1_33_1 ]), 40 | [ 41 | if test "$withval" = "no"; then 42 | want_boost="no" 43 | elif test "$withval" = "yes"; then 44 | want_boost="yes" 45 | ax_boost_user_program_options_lib="" 46 | else 47 | want_boost="yes" 48 | ax_boost_user_program_options_lib="$withval" 49 | fi 50 | ], 51 | [want_boost="yes"] 52 | ) 53 | 54 | if test "x$want_boost" = "xyes"; then 55 | AC_REQUIRE([AC_PROG_CC]) 56 | export want_boost 57 | CPPFLAGS_SAVED="$CPPFLAGS" 58 | CPPFLAGS="$CPPFLAGS $BOOST_CPPFLAGS" 59 | export CPPFLAGS 60 | LDFLAGS_SAVED="$LDFLAGS" 61 | LDFLAGS="$LDFLAGS $BOOST_LDFLAGS" 62 | export LDFLAGS 63 | AC_CACHE_CHECK([whether the Boost::Program_Options library is available], 64 | ax_cv_boost_program_options, 65 | [AC_LANG_PUSH(C++) 66 | AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[@%:@include 67 | ]], 68 | [[boost::program_options::options_description generic("Generic options"); 69 | return 0;]])], 70 | ax_cv_boost_program_options=yes, ax_cv_boost_program_options=no) 71 | AC_LANG_POP([C++]) 72 | ]) 73 | if test "$ax_cv_boost_program_options" = yes; then 74 | AC_DEFINE(HAVE_BOOST_PROGRAM_OPTIONS,,[define if the Boost::PROGRAM_OPTIONS library is available]) 75 | BOOSTLIBDIR=`echo $BOOST_LDFLAGS | sed -e 's/@<:@^\/@:>@*//'` 76 | if test "x$ax_boost_user_program_options_lib" = "x"; then 77 | for libextension in `ls $BOOSTLIBDIR/libboost_program_options*.so* 2>/dev/null | sed 's,.*/,,' | sed -e 's;^lib\(boost_program_options.*\)\.so.*$;\1;'` `ls $BOOSTLIBDIR/libboost_program_options*.dylib* 2>/dev/null | sed 's,.*/,,' | sed -e 's;^lib\(boost_program_options.*\)\.dylib.*$;\1;'` `ls $BOOSTLIBDIR/libboost_program_options*.a* 2>/dev/null | sed 's,.*/,,' | sed -e 's;^lib\(boost_program_options.*\)\.a.*$;\1;'` ; do 78 | ax_lib=${libextension} 79 | AC_CHECK_LIB($ax_lib, exit, 80 | [BOOST_PROGRAM_OPTIONS_LIB="-l$ax_lib"; AC_SUBST(BOOST_PROGRAM_OPTIONS_LIB) link_program_options="yes"; break], 81 | [link_program_options="no"]) 82 | done 83 | if test "x$link_program_options" != "xyes"; then 84 | for libextension in `ls $BOOSTLIBDIR/boost_program_options*.dll* 2>/dev/null | sed 's,.*/,,' | sed -e 's;^\(boost_program_options.*\)\.dll.*$;\1;'` `ls $BOOSTLIBDIR/boost_program_options*.a* 2>/dev/null | sed 's,.*/,,' | sed -e 's;^\(boost_program_options.*\)\.a.*$;\1;'` ; do 85 | ax_lib=${libextension} 86 | AC_CHECK_LIB($ax_lib, exit, 87 | [BOOST_PROGRAM_OPTIONS_LIB="-l$ax_lib"; AC_SUBST(BOOST_PROGRAM_OPTIONS_LIB) link_program_options="yes"; break], 88 | [link_program_options="no"]) 89 | done 90 | fi 91 | else 92 | for ax_lib in $ax_boost_user_program_options_lib boost_program_options-$ax_boost_user_program_options_lib; do 93 | AC_CHECK_LIB($ax_lib, main, 94 | [BOOST_PROGRAM_OPTIONS_LIB="-l$ax_lib"; AC_SUBST(BOOST_PROGRAM_OPTIONS_LIB) link_program_options="yes"; break], 95 | [link_program_options="no"]) 96 | done 97 | fi 98 | if test "x$ax_lib" = "x"; then 99 | AC_MSG_ERROR(Could not find a version of the library!) 100 | fi 101 | if test "x$link_program_options" != "xyes"; then 102 | AC_MSG_ERROR([Could not link against [$ax_lib] !]) 103 | fi 104 | fi 105 | CPPFLAGS="$CPPFLAGS_SAVED" 106 | LDFLAGS="$LDFLAGS_SAVED" 107 | fi 108 | ]) 109 | -------------------------------------------------------------------------------- /m4/ax_boost_system.m4: -------------------------------------------------------------------------------- 1 | # =========================================================================== 2 | # http://www.gnu.org/software/autoconf-archive/ax_boost_system.html 3 | # =========================================================================== 4 | # 5 | # SYNOPSIS 6 | # 7 | # AX_BOOST_SYSTEM 8 | # 9 | # DESCRIPTION 10 | # 11 | # Test for System library from the Boost C++ libraries. The macro requires 12 | # a preceding call to AX_BOOST_BASE. Further documentation is available at 13 | # . 14 | # 15 | # This macro calls: 16 | # 17 | # AC_SUBST(BOOST_SYSTEM_LIB) 18 | # 19 | # And sets: 20 | # 21 | # HAVE_BOOST_SYSTEM 22 | # 23 | # LICENSE 24 | # 25 | # Copyright (c) 2008 Thomas Porschberg 26 | # Copyright (c) 2008 Michael Tindal 27 | # Copyright (c) 2008 Daniel Casimiro 28 | # 29 | # Copying and distribution of this file, with or without modification, are 30 | # permitted in any medium without royalty provided the copyright notice 31 | # and this notice are preserved. This file is offered as-is, without any 32 | # warranty. 33 | 34 | #serial 17 35 | 36 | AC_DEFUN([AX_BOOST_SYSTEM], 37 | [ 38 | AC_ARG_WITH([boost-system], 39 | AS_HELP_STRING([--with-boost-system@<:@=special-lib@:>@], 40 | [use the System library from boost - it is possible to specify a certain library for the linker 41 | e.g. --with-boost-system=boost_system-gcc-mt ]), 42 | [ 43 | if test "$withval" = "no"; then 44 | want_boost="no" 45 | elif test "$withval" = "yes"; then 46 | want_boost="yes" 47 | ax_boost_user_system_lib="" 48 | else 49 | want_boost="yes" 50 | ax_boost_user_system_lib="$withval" 51 | fi 52 | ], 53 | [want_boost="yes"] 54 | ) 55 | 56 | if test "x$want_boost" = "xyes"; then 57 | AC_REQUIRE([AC_PROG_CC]) 58 | AC_REQUIRE([AC_CANONICAL_BUILD]) 59 | CPPFLAGS_SAVED="$CPPFLAGS" 60 | CPPFLAGS="$CPPFLAGS $BOOST_CPPFLAGS" 61 | export CPPFLAGS 62 | 63 | LDFLAGS_SAVED="$LDFLAGS" 64 | LDFLAGS="$LDFLAGS $BOOST_LDFLAGS" 65 | export LDFLAGS 66 | 67 | AC_CACHE_CHECK(whether the Boost::System library is available, 68 | ax_cv_boost_system, 69 | [AC_LANG_PUSH([C++]) 70 | CXXFLAGS_SAVE=$CXXFLAGS 71 | 72 | AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[@%:@include ]], 73 | [[boost::system::system_category]])], 74 | ax_cv_boost_system=yes, ax_cv_boost_system=no) 75 | CXXFLAGS=$CXXFLAGS_SAVE 76 | AC_LANG_POP([C++]) 77 | ]) 78 | if test "x$ax_cv_boost_system" = "xyes"; then 79 | AC_SUBST(BOOST_CPPFLAGS) 80 | 81 | AC_DEFINE(HAVE_BOOST_SYSTEM,,[define if the Boost::System library is available]) 82 | BOOSTLIBDIR=`echo $BOOST_LDFLAGS | sed -e 's/@<:@^\/@:>@*//'` 83 | 84 | LDFLAGS_SAVE=$LDFLAGS 85 | if test "x$ax_boost_user_system_lib" = "x"; then 86 | for libextension in `ls -r $BOOSTLIBDIR/libboost_system* 2>/dev/null | sed 's,.*/lib,,' | sed 's,\..*,,'` ; do 87 | ax_lib=${libextension} 88 | AC_CHECK_LIB($ax_lib, exit, 89 | [BOOST_SYSTEM_LIB="-l$ax_lib"; AC_SUBST(BOOST_SYSTEM_LIB) link_system="yes"; break], 90 | [link_system="no"]) 91 | done 92 | if test "x$link_system" != "xyes"; then 93 | for libextension in `ls -r $BOOSTLIBDIR/boost_system* 2>/dev/null | sed 's,.*/,,' | sed -e 's,\..*,,'` ; do 94 | ax_lib=${libextension} 95 | AC_CHECK_LIB($ax_lib, exit, 96 | [BOOST_SYSTEM_LIB="-l$ax_lib"; AC_SUBST(BOOST_SYSTEM_LIB) link_system="yes"; break], 97 | [link_system="no"]) 98 | done 99 | fi 100 | 101 | else 102 | for ax_lib in $ax_boost_user_system_lib boost_system-$ax_boost_user_system_lib; do 103 | AC_CHECK_LIB($ax_lib, exit, 104 | [BOOST_SYSTEM_LIB="-l$ax_lib"; AC_SUBST(BOOST_SYSTEM_LIB) link_system="yes"; break], 105 | [link_system="no"]) 106 | done 107 | 108 | fi 109 | if test "x$ax_lib" = "x"; then 110 | AC_MSG_ERROR(Could not find a version of the library!) 111 | fi 112 | if test "x$link_system" = "xno"; then 113 | AC_MSG_ERROR(Could not link against $ax_lib !) 114 | fi 115 | fi 116 | 117 | CPPFLAGS="$CPPFLAGS_SAVED" 118 | LDFLAGS="$LDFLAGS_SAVED" 119 | fi 120 | ]) 121 | -------------------------------------------------------------------------------- /m4/ax_boost_thread.m4: -------------------------------------------------------------------------------- 1 | # =========================================================================== 2 | # http://www.gnu.org/software/autoconf-archive/ax_boost_thread.html 3 | # =========================================================================== 4 | # 5 | # SYNOPSIS 6 | # 7 | # AX_BOOST_THREAD 8 | # 9 | # DESCRIPTION 10 | # 11 | # Test for Thread library from the Boost C++ libraries. The macro requires 12 | # a preceding call to AX_BOOST_BASE. Further documentation is available at 13 | # . 14 | # 15 | # This macro calls: 16 | # 17 | # AC_SUBST(BOOST_THREAD_LIB) 18 | # 19 | # And sets: 20 | # 21 | # HAVE_BOOST_THREAD 22 | # 23 | # LICENSE 24 | # 25 | # Copyright (c) 2009 Thomas Porschberg 26 | # Copyright (c) 2009 Michael Tindal 27 | # 28 | # Copying and distribution of this file, with or without modification, are 29 | # permitted in any medium without royalty provided the copyright notice 30 | # and this notice are preserved. This file is offered as-is, without any 31 | # warranty. 32 | 33 | #serial 27 34 | 35 | AC_DEFUN([AX_BOOST_THREAD], 36 | [ 37 | AC_ARG_WITH([boost-thread], 38 | AS_HELP_STRING([--with-boost-thread@<:@=special-lib@:>@], 39 | [use the Thread library from boost - it is possible to specify a certain library for the linker 40 | e.g. --with-boost-thread=boost_thread-gcc-mt ]), 41 | [ 42 | if test "$withval" = "no"; then 43 | want_boost="no" 44 | elif test "$withval" = "yes"; then 45 | want_boost="yes" 46 | ax_boost_user_thread_lib="" 47 | else 48 | want_boost="yes" 49 | ax_boost_user_thread_lib="$withval" 50 | fi 51 | ], 52 | [want_boost="yes"] 53 | ) 54 | 55 | if test "x$want_boost" = "xyes"; then 56 | AC_REQUIRE([AC_PROG_CC]) 57 | AC_REQUIRE([AC_CANONICAL_BUILD]) 58 | CPPFLAGS_SAVED="$CPPFLAGS" 59 | CPPFLAGS="$CPPFLAGS $BOOST_CPPFLAGS" 60 | export CPPFLAGS 61 | 62 | LDFLAGS_SAVED="$LDFLAGS" 63 | LDFLAGS="$LDFLAGS $BOOST_LDFLAGS" 64 | export LDFLAGS 65 | 66 | AC_CACHE_CHECK(whether the Boost::Thread library is available, 67 | ax_cv_boost_thread, 68 | [AC_LANG_PUSH([C++]) 69 | CXXFLAGS_SAVE=$CXXFLAGS 70 | 71 | if test "x$host_os" = "xsolaris" ; then 72 | CXXFLAGS="-pthreads $CXXFLAGS" 73 | elif test "x$host_os" = "xmingw32" ; then 74 | CXXFLAGS="-mthreads $CXXFLAGS" 75 | else 76 | CXXFLAGS="-pthread $CXXFLAGS" 77 | fi 78 | AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[@%:@include ]], 79 | [[boost::thread_group thrds; 80 | return 0;]])], 81 | ax_cv_boost_thread=yes, ax_cv_boost_thread=no) 82 | CXXFLAGS=$CXXFLAGS_SAVE 83 | AC_LANG_POP([C++]) 84 | ]) 85 | if test "x$ax_cv_boost_thread" = "xyes"; then 86 | if test "x$host_os" = "xsolaris" ; then 87 | BOOST_CPPFLAGS="-pthreads $BOOST_CPPFLAGS" 88 | elif test "x$host_os" = "xmingw32" ; then 89 | BOOST_CPPFLAGS="-mthreads $BOOST_CPPFLAGS" 90 | else 91 | BOOST_CPPFLAGS="-pthread $BOOST_CPPFLAGS" 92 | fi 93 | 94 | AC_SUBST(BOOST_CPPFLAGS) 95 | 96 | AC_DEFINE(HAVE_BOOST_THREAD,,[define if the Boost::Thread library is available]) 97 | BOOSTLIBDIR=`echo $BOOST_LDFLAGS | sed -e 's/@<:@^\/@:>@*//'` 98 | 99 | LDFLAGS_SAVE=$LDFLAGS 100 | case "x$host_os" in 101 | *bsd* ) 102 | LDFLAGS="-pthread $LDFLAGS" 103 | break; 104 | ;; 105 | esac 106 | if test "x$ax_boost_user_thread_lib" = "x"; then 107 | for libextension in `ls -r $BOOSTLIBDIR/libboost_thread* 2>/dev/null | sed 's,.*/lib,,' | sed 's,\..*,,'`; do 108 | ax_lib=${libextension} 109 | AC_CHECK_LIB($ax_lib, exit, 110 | [BOOST_THREAD_LIB="-l$ax_lib"; AC_SUBST(BOOST_THREAD_LIB) link_thread="yes"; break], 111 | [link_thread="no"]) 112 | done 113 | if test "x$link_thread" != "xyes"; then 114 | for libextension in `ls -r $BOOSTLIBDIR/boost_thread* 2>/dev/null | sed 's,.*/,,' | sed 's,\..*,,'`; do 115 | ax_lib=${libextension} 116 | AC_CHECK_LIB($ax_lib, exit, 117 | [BOOST_THREAD_LIB="-l$ax_lib"; AC_SUBST(BOOST_THREAD_LIB) link_thread="yes"; break], 118 | [link_thread="no"]) 119 | done 120 | fi 121 | 122 | else 123 | for ax_lib in $ax_boost_user_thread_lib boost_thread-$ax_boost_user_thread_lib; do 124 | AC_CHECK_LIB($ax_lib, exit, 125 | [BOOST_THREAD_LIB="-l$ax_lib"; AC_SUBST(BOOST_THREAD_LIB) link_thread="yes"; break], 126 | [link_thread="no"]) 127 | done 128 | 129 | fi 130 | if test "x$ax_lib" = "x"; then 131 | AC_MSG_ERROR(Could not find a version of the library!) 132 | fi 133 | if test "x$link_thread" = "xno"; then 134 | AC_MSG_ERROR(Could not link against $ax_lib !) 135 | else 136 | case "x$host_os" in 137 | *bsd* ) 138 | BOOST_LDFLAGS="-pthread $BOOST_LDFLAGS" 139 | break; 140 | ;; 141 | esac 142 | 143 | fi 144 | fi 145 | 146 | CPPFLAGS="$CPPFLAGS_SAVED" 147 | LDFLAGS="$LDFLAGS_SAVED" 148 | fi 149 | ]) 150 | -------------------------------------------------------------------------------- /m4/ax_cxx_have_sstream.m4: -------------------------------------------------------------------------------- 1 | # =========================================================================== 2 | # http://www.gnu.org/software/autoconf-archive/ax_cxx_have_sstream.html 3 | # =========================================================================== 4 | # 5 | # SYNOPSIS 6 | # 7 | # AX_CXX_HAVE_SSTREAM 8 | # 9 | # DESCRIPTION 10 | # 11 | # If the C++ library has a working stringstream, define HAVE_SSTREAM. 12 | # 13 | # LICENSE 14 | # 15 | # Copyright (c) 2008 Ben Stanley 16 | # 17 | # Copying and distribution of this file, with or without modification, are 18 | # permitted in any medium without royalty provided the copyright notice 19 | # and this notice are preserved. This file is offered as-is, without any 20 | # warranty. 21 | 22 | #serial 6 23 | 24 | AU_ALIAS([AC_CXX_HAVE_SSTREAM], [AX_CXX_HAVE_SSTREAM]) 25 | AC_DEFUN([AX_CXX_HAVE_SSTREAM], 26 | [AC_CACHE_CHECK(whether the compiler has stringstream, 27 | ax_cv_cxx_have_sstream, 28 | [AC_REQUIRE([AX_CXX_NAMESPACES]) 29 | AC_LANG_SAVE 30 | AC_LANG_CPLUSPLUS 31 | AC_TRY_COMPILE([#include 32 | #ifdef HAVE_NAMESPACES 33 | using namespace std; 34 | #endif],[stringstream message; message << "Hello"; return 0;], 35 | ax_cv_cxx_have_sstream=yes, ax_cv_cxx_have_sstream=no) 36 | AC_LANG_RESTORE 37 | ]) 38 | if test "$ax_cv_cxx_have_sstream" = yes; then 39 | AC_DEFINE(HAVE_SSTREAM,,[define if the compiler has stringstream]) 40 | fi 41 | ]) 42 | -------------------------------------------------------------------------------- /m4/ax_cxx_namespaces.m4: -------------------------------------------------------------------------------- 1 | # =========================================================================== 2 | # http://www.gnu.org/software/autoconf-archive/ax_cxx_namespaces.html 3 | # =========================================================================== 4 | # 5 | # SYNOPSIS 6 | # 7 | # AX_CXX_NAMESPACES 8 | # 9 | # DESCRIPTION 10 | # 11 | # If the compiler can prevent names clashes using namespaces, define 12 | # HAVE_NAMESPACES. 13 | # 14 | # LICENSE 15 | # 16 | # Copyright (c) 2008 Todd Veldhuizen 17 | # Copyright (c) 2008 Luc Maisonobe 18 | # Copyright (c) 2013 Bastien Roucaries 19 | # 20 | # Copying and distribution of this file, with or without modification, are 21 | # permitted in any medium without royalty provided the copyright notice 22 | # and this notice are preserved. This file is offered as-is, without any 23 | # warranty. 24 | 25 | #serial 8 26 | 27 | AU_ALIAS([AC_CXX_NAMESPACES], [AX_CXX_NAMESPACES]) 28 | AC_DEFUN([AX_CXX_NAMESPACES], 29 | [AC_CACHE_CHECK(whether the compiler implements namespaces, 30 | ax_cv_cxx_namespaces, 31 | [AC_LANG_PUSH([C++]) 32 | AC_COMPILE_IFELSE([AC_LANG_SOURCE([namespace Outer { namespace Inner { int i = 0; }} 33 | using namespace Outer::Inner; int foo(void) { return i;} ])], 34 | ax_cv_cxx_namespaces=yes, ax_cv_cxx_namespaces=no) 35 | AC_LANG_POP 36 | ]) 37 | if test "$ax_cv_cxx_namespaces" = yes; then 38 | AC_DEFINE(HAVE_NAMESPACES,,[define if the compiler implements namespaces]) 39 | fi 40 | ]) 41 | -------------------------------------------------------------------------------- /src/DecodeFrame/DecodeParams.h: -------------------------------------------------------------------------------- 1 | /*********************************************************************/ 2 | /* DecodeParams.h */ 3 | /* Author: Tim Borer and Galen Reich */ 4 | /* This version September 2020 */ 5 | /* */ 6 | /* Declares getting program parameters from command line. */ 7 | /* Copyright (c) BBC 2011-2020 -- For license see the LICENSE file */ 8 | /*********************************************************************/ 9 | 10 | #ifndef DECODEPARAMS_SEPT20 11 | #define DECODEPARAMS_SEPT20 12 | 13 | #include 14 | #include "Picture.h" 15 | #include "WaveletTransform.h" 16 | 17 | enum Output {TRANSFORM, QUANTISED, INDICES, DECODED}; 18 | enum Mode {HQ, LD}; 19 | 20 | std::ostream& operator<<(std::ostream&, Output value); 21 | 22 | std::istream& operator>>(std::istream&, Output& value); 23 | 24 | struct ProgramParams { 25 | std::string inFileName; 26 | std::string outFileName; 27 | bool verbose; 28 | int height; 29 | int width; 30 | enum ColourFormat chromaFormat; 31 | int bytes; 32 | int lumaDepth; 33 | int chromaDepth; 34 | bool interlaced; 35 | bool topFieldFirst; 36 | enum WaveletKernel kernel; 37 | int waveletDepth; 38 | int ySize; 39 | int xSize; 40 | enum Output output; 41 | enum Mode mode; 42 | std::string error; 43 | 44 | int slice_scalar; 45 | int slice_prefix; 46 | int compressedBytes; 47 | }; 48 | 49 | ProgramParams getCommandLineParams(int argc, char * argv[], const char* details[]); 50 | 51 | #endif // DECODEPARAMS_SEPT20 52 | -------------------------------------------------------------------------------- /src/DecodeFrame/Makefile.am: -------------------------------------------------------------------------------- 1 | AM_CXXFLAGS = \ 2 | -I$(top_srcdir)/src/ \ 3 | -I$(top_srcdir)/src/Library/ \ 4 | $(VC2REFERENCE_CFLAGS) \ 5 | $(BOOST_CFLAGS) 6 | 7 | AM_LDFLAGS = $(VC2REFERENCE_LDFLAGS) 8 | 9 | LDADD = ../Library/libVC2.la \ 10 | $(BOOST_LDFLAGS) \ 11 | $(BOOST_SYSTEM_LIB)\ 12 | $(BOOST_THREAD_LIB) 13 | 14 | bin_PROGRAMS = DecodeFrame 15 | 16 | DecodeFrame_SOURCES = \ 17 | DecodeFrame.cpp \ 18 | DecodeParams.cpp 19 | 20 | noinst_HEADERS = \ 21 | DecodeParams.h 22 | -------------------------------------------------------------------------------- /src/DecodeStream/DecodeParams.cpp: -------------------------------------------------------------------------------- 1 | /*********************************************************************/ 2 | /* DecodeParams.cpp */ 3 | /* Author: Tim Borer */ 4 | /* This version 20th September 2013 */ 5 | /* */ 6 | /* Defines getting program parameters from command line. */ 7 | /* Copyright (c) BBC 2011-2015 -- For license see the LICENSE file */ 8 | /*********************************************************************/ 9 | 10 | #include "DecodeParams.h" 11 | #include "Picture.h" 12 | #include "WaveletTransform.h" 13 | 14 | #include //For cin, cout, cerr, clog 15 | #include // For invalid_argument 16 | #include 17 | 18 | using std::clog; 19 | using std::endl; 20 | using std::string; 21 | using std::string; 22 | using std::invalid_argument; 23 | 24 | #include 25 | 26 | using TCLAP::CmdLine; 27 | using TCLAP::SwitchArg; 28 | using TCLAP::ValueArg; 29 | using TCLAP::UnlabeledValueArg; 30 | 31 | // Tell tclap that various enums are to be treated as tclap values 32 | namespace TCLAP { 33 | template <> 34 | struct ArgTraits { // Let TCLAP parse Output objects 35 | typedef ValueLike ValueCategory; 36 | }; 37 | } 38 | 39 | ProgramParams getCommandLineParams(int argc, char * argv[], const char* details[]) { 40 | 41 | const char * const version = details[0]; 42 | const char * const description = details[2]; 43 | 44 | if (argc<2) { 45 | clog << "Version: " << version << endl; 46 | clog << description << endl; 47 | clog << "\nFor more details and useage use -h or --help" << endl; 48 | exit(EXIT_SUCCESS); 49 | } 50 | 51 | ProgramParams params; 52 | 53 | try { 54 | 55 | // Define tclap command line object 56 | CmdLine cmd(description, ' ', version); 57 | 58 | // Define tclap command line parameters (and add them to tclap command line) 59 | UnlabeledValueArg inFile("inFile", "Input file name", true, "-", "string", cmd); 60 | UnlabeledValueArg outFile("outFile", "Output file name", true, "-", "string", cmd); 61 | SwitchArg verbosity("v", "verbose", "Output extra information to standard log", cmd); 62 | // "cla" prefix == command line argument 63 | ValueArg cla_output("o", "output", "Program output (Transform, Quantised, Indices, Decoded)", false, DECODED, "string", cmd); 64 | 65 | // Parse the argv array 66 | cmd.parse(argc, argv); 67 | 68 | // Initialise program parameters 69 | const string inFileName = inFile.getValue(); 70 | const string outFileName = outFile.getValue(); 71 | const bool verbose = verbosity.getValue(); 72 | const Output output = cla_output.getValue(); 73 | 74 | params.inFileName = inFileName; 75 | params.outFileName = outFileName; 76 | params.verbose = verbose; 77 | params.output = output; 78 | 79 | } 80 | 81 | // catch any TCLAP exceptions 82 | catch (TCLAP::ArgException &e) { 83 | params.error = string("Command line error: ") + e.error() + " for arg " + e.argId(); 84 | } 85 | 86 | // catch other exceptions 87 | catch(const std::exception& ex) { 88 | params.error = string(ex.what()); 89 | } 90 | 91 | return params; 92 | } 93 | 94 | std::ostream& operator<<(std::ostream& os, Output output) { 95 | const char* s; 96 | switch (output) { 97 | case TRANSFORM: 98 | s = "Transform"; 99 | break; 100 | case QUANTISED: 101 | s = "Quantised"; 102 | break; 103 | case INDICES: 104 | s = "Indices"; 105 | break; 106 | case DECODED: 107 | s = "Decoded"; 108 | break; 109 | default: 110 | s = "Unknown output!"; 111 | break; 112 | } 113 | return os<>(std::istream& is, Output& output) { 117 | std::string text; 118 | is >> text; 119 | if (text == "Transform") output = TRANSFORM; 120 | else if (text == "Quantised") output = QUANTISED; 121 | else if (text == "Indices") output = INDICES; 122 | else if (text == "Decoded") output = DECODED; 123 | else is.setstate(std::ios_base::badbit|std::ios_base::failbit); 124 | // Alternatively 125 | // else throw std::invalid_argument("invalid input"); 126 | return is; 127 | } 128 | -------------------------------------------------------------------------------- /src/DecodeStream/DecodeParams.h: -------------------------------------------------------------------------------- 1 | /*********************************************************************/ 2 | /* DecodeParams.h */ 3 | /* Author: Tim Borer */ 4 | /* This version 20th September 2013 */ 5 | /* */ 6 | /* Declares getting program parameters from command line. */ 7 | /* Copyright (c) BBC 2011-2015 -- For license see the LICENSE file */ 8 | /*********************************************************************/ 9 | 10 | #ifndef DECODEPARAMS_20SEPT13 11 | #define DECODEPARAMS_20SEPT13 12 | 13 | #include 14 | #include "Picture.h" 15 | #include "WaveletTransform.h" 16 | 17 | enum Output {TRANSFORM, QUANTISED, INDICES, DECODED}; 18 | 19 | std::ostream& operator<<(std::ostream&, Output value); 20 | 21 | std::istream& operator>>(std::istream&, Output& value); 22 | 23 | struct ProgramParams { 24 | std::string inFileName; 25 | std::string outFileName; 26 | bool verbose; 27 | enum Output output; 28 | std::string error; 29 | }; 30 | 31 | ProgramParams getCommandLineParams(int argc, char * argv[], const char* details[]); 32 | 33 | #endif // DECODEPARAMS_20SEPT13 34 | -------------------------------------------------------------------------------- /src/DecodeStream/Makefile.am: -------------------------------------------------------------------------------- 1 | AM_CXXFLAGS = \ 2 | -I$(top_srcdir)/src/ \ 3 | -I$(top_srcdir)/src/Library/ \ 4 | $(VC2REFERENCE_CFLAGS) \ 5 | $(BOOST_CFLAGS) 6 | 7 | AM_LDFLAGS = $(VC2REFERENCE_LDFLAGS) 8 | 9 | LDADD = ../Library/libVC2.la \ 10 | $(BOOST_LDFLAGS) \ 11 | $(BOOST_SYSTEM_LIB)\ 12 | $(BOOST_THREAD_LIB) 13 | 14 | bin_PROGRAMS = DecodeStream 15 | 16 | DecodeStream_SOURCES = \ 17 | DecodeStream.cpp \ 18 | DecodeParams.cpp 19 | 20 | noinst_HEADERS = \ 21 | DecodeParams.h 22 | -------------------------------------------------------------------------------- /src/EncodeStream/EncodeParams.h: -------------------------------------------------------------------------------- 1 | /*********************************************************************/ 2 | /* EncodeParams.h */ 3 | /* Author: Tim Borer and Galen Reich, BBC Research & Development */ 4 | /* This version 15th September 2020 */ 5 | /* */ 6 | /* Declares getting program parameters from command line. */ 7 | /* Copyright (c) BBC 2011-2020 -- For license see the LICENSE file */ 8 | /*********************************************************************/ 9 | 10 | #ifndef ENCODERPARAMS_SEPT20 11 | #define ENCODERPARAMS_SEPT20 12 | 13 | #include 14 | 15 | #include "Picture.h" 16 | #include "WaveletTransform.h" 17 | #include "DataUnit.h" 18 | 19 | enum Output {TRANSFORM, QUANTISED, INDICES, PACKAGED, STREAM, DECODED, PSNR}; 20 | enum Mode {HQ_ConstQ, HQ_CBR, LD}; 21 | 22 | std::ostream& operator<<(std::ostream&, Output value); 23 | 24 | std::istream& operator>>(std::istream&, Output& value); 25 | 26 | struct ProgramParams { 27 | std::string inFileName; 28 | std::string outFileName; 29 | bool verbose; 30 | int height; 31 | int width; 32 | enum ColourFormat chromaFormat; 33 | int bytes; 34 | int lumaDepth; 35 | int chromaDepth; 36 | bool interlaced; 37 | bool topFieldFirst; 38 | enum WaveletKernel kernel; 39 | int waveletDepth; 40 | int ySize; 41 | int xSize; 42 | enum Mode mode; 43 | enum Output output; 44 | FrameRate frame_rate; 45 | std::string error; 46 | 47 | // Mode dependent 48 | int slice_scalar; 49 | int slice_prefix; 50 | int fragment_length; 51 | int compressedBytes; 52 | int qIndex; 53 | }; 54 | 55 | ProgramParams getCommandLineParams(int argc, char * argv[], const char* details[]); 56 | 57 | #endif // ENCODERPARAMS_SEPT20 58 | -------------------------------------------------------------------------------- /src/EncodeStream/Makefile.am: -------------------------------------------------------------------------------- 1 | AM_CXXFLAGS = \ 2 | -I$(top_srcdir)/src/ \ 3 | -I$(top_srcdir)/src/Library/ \ 4 | $(VC2REFERENCE_CFLAGS) \ 5 | $(BOOST_CFLAGS) 6 | 7 | AM_LDFLAGS = $(VC2REFERENCE_LDFLAGS) 8 | 9 | LDADD = ../Library/libVC2.la \ 10 | $(BOOST_LDFLAGS) \ 11 | $(BOOST_SYSTEM_LIB)\ 12 | $(BOOST_THREAD_LIB) 13 | 14 | bin_PROGRAMS = EncodeStream 15 | 16 | EncodeStream_SOURCES = \ 17 | EncodeStream.cpp \ 18 | EncodeParams.cpp 19 | 20 | noinst_HEADERS = \ 21 | EncodeParams.h 22 | -------------------------------------------------------------------------------- /src/Library/Arrays.h: -------------------------------------------------------------------------------- 1 | /*********************************************************************/ 2 | /* Arrays.h */ 3 | /* Author: Tim Borer */ 4 | /* This version 11th July 2011 */ 5 | /* */ 6 | /* Declares stuff related to mulitdimensional arrays. */ 7 | /* Copyright (c) BBC 2011-2015 -- For license see the LICENSE file */ 8 | /*********************************************************************/ 9 | 10 | #ifndef ARRAYS_25FEB10 11 | #define ARRAYS_25FEB10 12 | 13 | #include 14 | #include "boost/multi_array.hpp" 15 | #include "boost/array.hpp" 16 | 17 | using boost::extents; // An extents generator object used to define array sizes 18 | using boost::indices; // An index generator object used to define array views 19 | 20 | typedef boost::multi_array_types::index_range Range; // Range(bottom, top+1, stride) 21 | 22 | typedef boost::multi_array_types::index Index; 23 | 24 | // Shape2D is a 1D Array used to store the size of a picture 25 | typedef boost::array Shape2D; 26 | 27 | // Array1D is (surprise) a one dimensional array or vector 28 | typedef boost::multi_array Array1D; 29 | 30 | // Array2D is a 2D array for holding picture or coefficient samples 31 | typedef boost::multi_array Array2D; 32 | 33 | // View2D is a view of a Array2D, 34 | // that is a synonym for a subset of array values 35 | typedef Array2D::array_view<2>::type View2D; 36 | 37 | // ConstView2D is a constant view of a Array2D, 38 | typedef Array2D::const_array_view<2>::type ConstView2D; 39 | 40 | // BlockVector is a 1D Array (i.e. vector) of 2D arrays (each element is, itself, a little 2D array) 41 | // A BlockVector may be used for storing an array of wavelet transform subbands (each subband is, 42 | // itself, a 2D array of coefficients). 43 | typedef boost::multi_array BlockVector; 44 | 45 | // BlockArray is a 2D array of 2D arrays (each block is a little 2D array) 46 | typedef boost::multi_array BlockArray; 47 | 48 | // ArrayIndices2D specifies the subset of array elements which define a view, 49 | // that is it specifies the subsampling factor and subsampling phase. 50 | typedef boost::detail::multi_array::index_gen<2, 2> ArrayIndices2D; 51 | 52 | // Get the shape of a 2D array 53 | const Shape2D shape(const Array2D&); 54 | const Shape2D shape(const View2D&); 55 | const Shape2D shape(const ConstView2D&); 56 | const Shape2D shape(const BlockArray&); 57 | 58 | // Splits a large 2D array into an array of smaller 2D arrays (blocks) 59 | // Note that if the number of blocks is not a sub-multiple of the input array dimensions then 60 | // the blocks will have different sizes! 61 | // yBlocks and xBlocks are the number of blocks in the vertical and horizontal dimension respectively. 62 | // Splits a picture into slices or a subband into codeblocks. 63 | const BlockArray split_into_blocks(const Array2D& picture, int yBlocks, int xBlocks); 64 | 65 | // Converts an array of blocks back to a single 2D array 66 | // This is the inverse of "split_into_blocks()" 67 | // The array of blocks might represent slices or codeblocks 68 | const Array2D merge_blocks(const BlockArray& blocks); 69 | 70 | // Clip an array to specified limits 71 | const Array2D clip(const Array2D& values, const int min_value, const int max_value); 72 | 73 | //**************** Array IO declarations ****************// 74 | 75 | namespace arrayio { 76 | 77 | enum ioFormat {UNSIGNED, SIGNED, OFFSET}; 78 | 79 | // Format manipulator - sets io format 80 | class format { 81 | public: 82 | format(ioFormat f): iof(f) {}; 83 | void operator () (std::ios_base& stream) const; 84 | private: 85 | const ioFormat iof; 86 | }; 87 | 88 | // Format manipulator - sets number of bytes per element 89 | class wordWidth { 90 | public: 91 | wordWidth(int b): no_of_bytes(b) {}; 92 | void operator () (std::ios_base& stream) const; 93 | private: 94 | const int no_of_bytes; 95 | }; 96 | 97 | // Format manipulator - sets number of bits used for data 98 | class bitDepth { 99 | public: 100 | bitDepth(int b): no_of_bits(b) {}; 101 | void operator () (std::ios_base& stream) const; 102 | private: 103 | const int no_of_bits; 104 | }; 105 | 106 | // Format manipulator - sets the offset for offset binary 107 | // (Default offset, if not explicitly set, is half range) 108 | class offset { 109 | public: 110 | offset(int z): zeroValue(z) {}; 111 | void operator () (std::ios_base& stream) const; 112 | private: 113 | const int zeroValue; 114 | }; 115 | 116 | // Set data to be left justified within the data word 117 | std::ostream& left_justified(std::ostream& stream); 118 | 119 | // Set data to be left justified within the data word 120 | std::istream& left_justified(std::istream& stream); 121 | 122 | // Set data to be right justified within the data word 123 | std::ostream& right_justified(std::ostream& stream); 124 | 125 | // Set data to be right justified within the data word 126 | std::istream& right_justified(std::istream& stream); 127 | 128 | // Set data format to offset binary 129 | std::ostream& offset_binary(std::ostream& stream); 130 | 131 | // Set data format to offset binary 132 | std::istream& offset_binary(std::istream& stream); 133 | 134 | // Set data format to signed binary (two's complement) 135 | std::ostream& signed_binary(std::ostream& stream); 136 | 137 | // Set data format to signed binary (two's complement) 138 | std::istream& signed_binary(std::istream& stream); 139 | 140 | // Set data format to unsigned binary 141 | std::ostream& unsigned_binary(std::ostream& stream); 142 | 143 | // Set data format to unsigned binary 144 | std::istream& unsigned_binary(std::istream& stream); 145 | 146 | // Set data format to text 147 | std::ostream& text(std::ostream& stream); 148 | 149 | // Set data format to text 150 | std::istream& text(std::istream& stream); 151 | 152 | } // end namespace arrayio 153 | 154 | // ostream io format manipulator 155 | std::ostream& operator << (std::ostream& stream, arrayio::format f); 156 | 157 | // istream io format manipulator 158 | std::istream& operator >> (std::istream& stream, arrayio::format f); 159 | 160 | // ostream wordWidth format manipulator 161 | std::ostream& operator << (std::ostream& stream, arrayio::wordWidth w); 162 | 163 | // istream wordWidth format manipulator 164 | std::istream& operator >> (std::istream& stream, arrayio::wordWidth w); 165 | 166 | // ostream bit depth format manipulator 167 | std::ostream& operator << (std::ostream& stream, arrayio::bitDepth d); 168 | 169 | // istream bit depth format manipulator 170 | std::istream& operator >> (std::istream& stream, arrayio::bitDepth d); 171 | 172 | // ostream offset format manipulator 173 | std::ostream& operator << (std::ostream& stream, arrayio::offset z); 174 | 175 | // istream offset format manipulator 176 | std::istream& operator >> (std::istream& stream, arrayio::offset z); 177 | 178 | std::istream& operator >> (std::istream& stream, Array2D& array); 179 | 180 | std::ostream& operator << (std::ostream& stream, const Array2D& array); 181 | 182 | #endif //ARRAYS_25FEB10 183 | -------------------------------------------------------------------------------- /src/Library/DataUnit.h: -------------------------------------------------------------------------------- 1 | /*********************************************************************/ 2 | /* DataUnit.h */ 3 | /* Author: James Weaver and Galen Reich */ 4 | /* This version July 2020 */ 5 | /* */ 6 | /* Declares stuff related to VC2 Data Units. */ 7 | /* Copyright (c) BBC 2011-2020 -- For license see the LICENSE file */ 8 | /*********************************************************************/ 9 | 10 | #ifndef DATAUNIT_17JUN15 11 | #define DATAUNIT_17JUN15 12 | 13 | #include 14 | 15 | #include "Utils.h" 16 | #include "Picture.h" 17 | #include "Slices.h" 18 | #include "WaveletTransform.h" 19 | #include "VLC.h" 20 | 21 | enum DataUnitType { 22 | UNKNOWN_DATA_UNIT, 23 | SEQUENCE_HEADER, 24 | END_OF_SEQUENCE, 25 | AUXILIARY_DATA, 26 | PADDING_DATA, 27 | HQ_PICTURE, 28 | LD_PICTURE, 29 | HQ_FRAGMENT, 30 | LD_FRAGMENT 31 | }; 32 | 33 | class DataUnit { 34 | public: 35 | DataUnit(); 36 | 37 | int length(); 38 | DataUnitType type; 39 | Bytes next_parse_offset; 40 | Bytes prev_parse_offset; 41 | 42 | friend std::istream& operator >> (std::istream& stream, DataUnit &d); 43 | 44 | }; 45 | 46 | class PicturePreamble; 47 | class FragmentSlices; 48 | 49 | class Fragment { 50 | public: 51 | Fragment() 52 | : mNSlices(0) 53 | , mSliceOffsetX(0) 54 | , mSliceOffsetY(0) {} 55 | 56 | int n_slices() { return mNSlices; } 57 | int slice_offset_x() { return mSliceOffsetX; } 58 | int slice_offset_y() { return mSliceOffsetY; } 59 | 60 | friend std::istream& operator >> (std::istream& stream, Fragment &f); 61 | 62 | protected: 63 | int mNSlices; 64 | int mSliceOffsetX; 65 | int mSliceOffsetY; 66 | }; 67 | 68 | class WrappedPicture { 69 | public: 70 | WrappedPicture(const unsigned long picture_number, 71 | const WaveletKernel wavelet_kernel, 72 | const int depth, 73 | const int slices_x, 74 | const int slices_y, 75 | const int slice_prefix, 76 | const int slice_size_scalar, 77 | const Slices &slices); 78 | 79 | WrappedPicture(const unsigned long picture_number, 80 | const WaveletKernel wavelet_kernel, 81 | const int depth, 82 | const int slices_x, 83 | const int slices_y, 84 | const utils::Rational slice_bytes, 85 | const Slices &slices); 86 | unsigned long picture_number; 87 | WaveletKernel wavelet_kernel; 88 | int depth; 89 | int slices_x; 90 | int slices_y; 91 | int slice_prefix; 92 | int slice_size_scalar; 93 | utils::Rational slice_bytes; 94 | Slices slices; 95 | }; 96 | 97 | enum FrameRate { FR_UNSET = -1, FR0, FR24000_1001, FR24, FR25, FR30000_1001, FR30, FR50, FR60000_1001, FR60, FR15000_1001, FR25_2, FR48, FR48_1001, FR96, FR100, FR120_1001, FR120 }; 98 | //enum ColourFormat {CF_UNSET=-1, CF444, CF422, CF420}; 99 | enum PixelAspectRatio { AR_UNSET = -1, AR0, AR1_1, AR10_11, AR12_11, AR40_33, AR16_11, AR4_3 }; 100 | enum SignalRange { SR_UNSET = -1, SR0, SR8_FULL, SR8, SR10, SR12, SR10_FULL, SR12_FULL, SR16, SR16_FULL}; 101 | enum ColorSpec { CS_UNSET = -1, CS_CUSTOM, CS_SDTV_525, CS_SDTV_625, CS_HDTV, CS_D_CINEMA, CS_UHDTV, CS_HDRTV_PQ, CS_HDRTV_HLG}; 102 | const FrameRate MAX_V2_FRAMERATE = FR48; 103 | enum Profile { PROFILE_UNKNOWN, PROFILE_LD, PROFILE_HQ }; 104 | 105 | class SequenceHeader { 106 | public: 107 | SequenceHeader(); 108 | SequenceHeader( Profile profile, 109 | int height, 110 | int width, 111 | ColourFormat chromaFormat, 112 | bool interlace, 113 | FrameRate frameRate, 114 | bool topFieldFirst, 115 | int bitdepth, 116 | 117 | // Optional Args 118 | PixelAspectRatio pixelAspectRatio = AR_UNSET, 119 | int cleanWidth = -1, 120 | int cleanHeight = -1, 121 | int leftOffset = -1, 122 | int topOffset = -1, 123 | 124 | ColorSpec colorSpec = CS_UNSET, 125 | int colorPrimaries = 0, // HDTV 126 | int colorMatrix = 0, // HDTV 127 | int transferFunction = 0, //TV Gamma 128 | 129 | bool use_v3 = false 130 | ); 131 | 132 | int major_version; 133 | int minor_version; 134 | Profile profile; 135 | int width; 136 | int height; 137 | ColourFormat chromaFormat; 138 | bool interlace; 139 | FrameRate frameRate; 140 | bool topFieldFirst; 141 | unsigned int frameRateNumer; 142 | unsigned int frameRateDenom; 143 | int bitdepth; 144 | unsigned int lumaExcursion; 145 | unsigned int lumaOffset; 146 | unsigned int colorDiffExcursion; 147 | unsigned int colorDiffOffset; 148 | 149 | PixelAspectRatio pixelAspectRatio; 150 | unsigned int pixelAspectRatioNumer; 151 | unsigned int pixelAspectRatioDenom; 152 | int cleanWidth; 153 | int cleanHeight; 154 | int leftOffset; 155 | int topOffset; 156 | 157 | ColorSpec colorSpec; 158 | int colorPrimaries; 159 | int colorMatrix; 160 | int transferFunction; 161 | }; 162 | 163 | SequenceHeader getDefaultSourceParameters(const int base_video_format_index); 164 | 165 | struct video_format { 166 | 167 | video_format(); 168 | video_format(const SequenceHeader &fmt); 169 | 170 | int major_version; 171 | int minor_version; 172 | int profile; 173 | int level; 174 | int base_video_format; 175 | 176 | bool custom_dimensions_flag; 177 | int frame_width; 178 | int frame_height; 179 | bool custom_color_diff_format_flag; 180 | int color_diff_format; 181 | bool custom_scan_format_flag; 182 | int source_sampling; 183 | bool custom_frame_rate_flag; 184 | FrameRate frame_rate; 185 | unsigned int frame_rate_numer; 186 | unsigned int frame_rate_denom; 187 | bool custom_pixel_aspect_ratio_flag; 188 | int pixel_aspect_ratio; 189 | unsigned int pixel_aspect_ratio_numer; 190 | unsigned int pixel_aspect_ratio_denom; 191 | bool custom_clean_area_flag; 192 | int clean_width; 193 | int clean_height; 194 | int left_offset; 195 | int top_offset; 196 | bool custom_signal_range_flag; 197 | int bitdepth; 198 | unsigned int luma_excursion; 199 | unsigned int luma_offset; 200 | unsigned int color_diff_excursion; 201 | unsigned int color_diff_offset; 202 | bool custom_color_spec_flag; 203 | int color_spec; 204 | bool custom_color_primaries_flag; 205 | int color_primaries; 206 | bool custom_color_matrix_flag; 207 | int color_matrix; 208 | bool custom_transfer_function_flag; 209 | int transfer_function; 210 | 211 | bool top_field_first; 212 | }; 213 | 214 | class PictureHeader { 215 | public: 216 | unsigned long picture_number; 217 | }; 218 | 219 | std::istream &operator >> (std::istream &stream, PictureHeader &h); 220 | 221 | class PicturePreamble { 222 | public: 223 | PicturePreamble(); 224 | 225 | WaveletKernel wavelet_kernel; 226 | WaveletKernel wavelet_kernel_ho; 227 | int depth; 228 | int depth_ho; 229 | int slices_x; 230 | int slices_y; 231 | int slice_prefix; 232 | int slice_size_scalar; 233 | utils::Rational slice_bytes; 234 | }; 235 | 236 | namespace dataunitio { 237 | using sliceio::highQualityCBR; 238 | using sliceio::highQualityVBR; 239 | 240 | int &majorVersionNum(std::ios_base& stream); 241 | 242 | std::istream& lowDelay(std::istream& stream); 243 | 244 | std::istream& synchronise(std::istream& stream); 245 | 246 | std::ostream& start_sequence(std::ostream& stream); 247 | std::ostream& end_sequence(std::ostream& stream); 248 | 249 | class fragmentedPictures { 250 | public: 251 | fragmentedPictures(const int f) : mFL(f) {}; 252 | void operator() (std::ios_base &stream) const; 253 | private: 254 | const int mFL; 255 | }; 256 | }; 257 | 258 | std::ostream& operator << (std::ostream& stream, dataunitio::fragmentedPictures arg); 259 | 260 | std::ostream& operator << (std::ostream& stream, const WrappedPicture& d); 261 | 262 | std::ostream& operator << (std::ostream& stream, const SequenceHeader& s); 263 | 264 | std::ostream& operator << (std::ostream& stream, const DataUnitType& t); 265 | 266 | std::ostream& operator << (std::ostream& stream, const FrameRate& t); 267 | 268 | std::istream& operator >> (std::istream& stream, DataUnit &d); 269 | 270 | std::istream& operator >> (std::istream& stream, Fragment &d); 271 | 272 | std::istream& operator >> (std::istream& stream, SequenceHeader &hdr); 273 | 274 | std::istream& operator >> (std::istream& stream, PicturePreamble &hdr); 275 | 276 | #endif /* DATAUNIT_17JUN15 */ 277 | -------------------------------------------------------------------------------- /src/Library/Frame.h: -------------------------------------------------------------------------------- 1 | /************************************************************************/ 2 | /* Frame.h */ 3 | /* Author: Tim Borer */ 4 | /* This version 26th September 2011 */ 5 | /* */ 6 | /* Declares stuff related to colour frames. */ 7 | /* 6th May 2011: Initial version */ 8 | /* 2nd June 2011: Added "frame" method */ 9 | /* 26th Sept 2011: Added constructor from height, width & colour format */ 10 | /* Copyright (c) BBC 2011-2015 -- For license see the LICENSE file */ 11 | /************************************************************************/ 12 | 13 | #ifndef FRAME_6MAY11 14 | #define FRAME_6MAY11 15 | 16 | #include "Picture.h" 17 | 18 | class Frame: public Picture { 19 | public: 20 | Frame(int height, int width, ColourFormat, bool interlaced=false, bool topFieldFirst=true); 21 | Frame(const PictureFormat&, bool interlaced=false, bool topFieldFirst=true); 22 | bool interlaced() const; 23 | void interlaced(bool); 24 | bool topFieldFirst() const; 25 | void topFieldFirst(bool); 26 | const Picture topField() const; 27 | void topField(const Picture&); 28 | const Picture bottomField() const; 29 | void bottomField(const Picture&); 30 | const Picture firstField() const; 31 | void firstField(const Picture&); 32 | const Picture secondField() const; 33 | void secondField(const Picture&); 34 | const Picture& frame() const; 35 | void frame(const Picture&); 36 | private: 37 | bool intl; 38 | bool tff; 39 | }; 40 | 41 | #endif //FRAME_6MAY11 42 | -------------------------------------------------------------------------------- /src/Library/FrameResolutions.h: -------------------------------------------------------------------------------- 1 | /*********************************************************************/ 2 | /* FrameResolutions.h */ 3 | /* Author: Tim Borer */ 4 | /* This version 8th August 2010 */ 5 | /* */ 6 | /* Defines a table of frame resolutions */ 7 | /* */ 8 | /* Copyright (c) BBC 2011-2015 -- For license see the LICENSE file */ 9 | /*********************************************************************/ 10 | 11 | #ifndef FRAMERESOLUTIONS_25FEB10 12 | #define FRAMERESOLUTIONS_25FEB10 13 | 14 | const int frameResolutions[][2] = { 15 | // height, width 16 | { 1080, 1920 }, 17 | { 1080, 1440 }, 18 | { 1080, 960 }, 19 | { 720, 1280 }, 20 | { 720, 960 }, 21 | { 720, 640 }, 22 | { 576, 720 }, 23 | { 576, 704 }, 24 | { 576, 540 }, 25 | { 576, 360 }, 26 | { 486, 720 }, 27 | { 486, 704 }, 28 | { 486, 540 }, 29 | { 486, 360 }, 30 | { 480, 720 }, 31 | { 480, 704 }, 32 | { 480, 540 }, 33 | { 480, 360 } 34 | }; 35 | 36 | #endif //FRAMERESOLUTIONS_25FEB10 37 | -------------------------------------------------------------------------------- /src/Library/Makefile.am: -------------------------------------------------------------------------------- 1 | noinst_LTLIBRARIES = libVC2.la 2 | 3 | libVC2_la_LIBADD = \ 4 | $(BOOST_LDFLAGS) \ 5 | $(BOOST_SYSTEM_LIB)\ 6 | $(BOOST_THREAD_LIB) 7 | 8 | libVC2_la_LDFLAGS = \ 9 | -no-undefined \ 10 | $(VC2REFERENCE_LDFLAGS) \ 11 | -lpthread 12 | 13 | libVC2_la_CPPFLAGS = \ 14 | -I$(top_srcdir)/src/ \ 15 | $(VC2REFERENCE_CFLAGS) \ 16 | $(BOOST_CFLAGS) 17 | 18 | libVC2_la_SOURCES = src/DataUnit.cpp src/Arrays.cpp src/Frame.cpp src/Picture.cpp src/Quantisation.cpp src/Slices.cpp src/Utils.cpp src/VLC.cpp src/WaveletTransform.cpp 19 | 20 | pkginclude_HEADERS = 21 | 22 | noinst_HEADERS = DataUnit.h Arrays.h Frame.h FrameResolutions.h Picture.h Quantisation.h Slices.h Utils.h VLC.h WaveletTransform.h 23 | 24 | EXTRA_DIST = 25 | -------------------------------------------------------------------------------- /src/Library/Picture.h: -------------------------------------------------------------------------------- 1 | /*********************************************************************/ 2 | /* Picture.h */ 3 | /* Author: Tim Borer and Galen Reich */ 4 | /* This version July 2020 */ 5 | /* */ 6 | /* Declares stuff related to colour pictures. */ 7 | /* Copyright (c) BBC 2011-2020 -- For license see the LICENSE file */ 8 | /*********************************************************************/ 9 | 10 | #ifndef PICTURE_3MAY11 11 | #define PICTURE_3MAY11 12 | 13 | #include 14 | 15 | #include "Arrays.h" 16 | 17 | enum ColourFormat {CF_UNSET=-1, CF444, CF422, CF420}; //CF_UNSET needed for PictureFormat default constructor 18 | 19 | std::ostream& operator<<(std::ostream& os, ColourFormat format); 20 | 21 | std::istream& operator>>(std::istream& strm, ColourFormat& format); 22 | 23 | class PictureFormat { 24 | public: 25 | PictureFormat(); //Needed for Picture default constructor 26 | PictureFormat(int height, int width, ColourFormat); 27 | // Use this constructor for non-standard picture (e.g. wavelet transforms) 28 | PictureFormat(int lumaHeight, int lumaWidth, int chromaHeight, int chromaWidth, ColourFormat); 29 | // Constructor checks format has right number of samples (or 30 | // returns default if height or width = 0 (i.e. unknown) 31 | PictureFormat(int height, int width, ColourFormat, int imageSamples); 32 | operator const bool() const; //Test if valid PictureFormat 33 | const ColourFormat chromaFormat() const; 34 | const Shape2D lumaShape() const; 35 | const Shape2D chromaShape()const; 36 | const int lumaHeight() const; 37 | const int lumaWidth() const; 38 | const int chromaHeight() const; 39 | const int chromaWidth() const; 40 | const int samples() const; 41 | private: 42 | void construct(int height, int width, ColourFormat); 43 | // Guess frame format from number of samples in the frame and the colour format. 44 | // The list of supported frame formats is in "FrameResolutions.h" 45 | void guessFormat(int imageSamples, ColourFormat); 46 | int yHeight; 47 | int yWidth; 48 | int uvHeight; 49 | int uvWidth; 50 | ColourFormat uvFormat; 51 | }; 52 | 53 | class Picture { 54 | public: 55 | Picture(); //Needed for arrays of pictures. Picture can be set by assignment (only) 56 | Picture(const PictureFormat&); 57 | Picture(const int height, const int width, const ColourFormat); 58 | Picture(const PictureFormat&, const Array2D& y, const Array2D& c1, const Array2D& c2); 59 | PictureFormat format() const; 60 | const Array2D& y() const; 61 | const Array2D& c1() const; 62 | const Array2D& c2() const; 63 | void y(const Array2D&); 64 | void c1(const Array2D&); 65 | void c2(const Array2D&); 66 | protected: 67 | PictureFormat picFormat; 68 | Array2D luma, chroma1, chroma2; 69 | friend std::istream& operator >> (std::istream&, Picture&); 70 | }; 71 | 72 | typedef boost::multi_array PictureArray; 73 | 74 | // Get the shape of a PictureArray 75 | const Shape2D shape(const PictureArray&); 76 | 77 | const PictureArray split_into_blocks(const Picture& picture, int ySlices, int xSlices); 78 | 79 | const Picture merge_blocks(const PictureArray& blocks); 80 | 81 | // Clip a Picture to specified limits 82 | // First function clips all components to the same values (good for RGB) 83 | const Picture clip(const Picture& picture, const int min_value, const int max_value); 84 | // Second function clips luma and chroma values separately (good for YUV) 85 | const Picture clip(const Picture& picture, 86 | const int luma_min, const int luma_max, 87 | const int chroma_min, const int chroma_max); 88 | 89 | //**** Picture IO declarations ****// 90 | 91 | namespace pictureio { 92 | 93 | // Use same io manipulators as in ArrayIO.h 94 | using arrayio::left_justified; 95 | using arrayio::right_justified; 96 | using arrayio::offset_binary; 97 | using arrayio::signed_binary; 98 | using arrayio::unsigned_binary; 99 | using arrayio::text; 100 | 101 | //Use same wordWidth class as in ArrayIO.h 102 | using arrayio::wordWidth; 103 | 104 | using arrayio::ioFormat; 105 | 106 | // Use to set data format as an alternative to manipulators above or 107 | // use for different data formats for luma and chroma 108 | class format { 109 | public: 110 | format(ioFormat f): lumaFormat(f), chromaFormat(f) {}; 111 | format(ioFormat lf, ioFormat cf): lumaFormat(lf), chromaFormat(cf) {}; 112 | void operator () (std::ios_base& stream) const; 113 | private: 114 | const ioFormat lumaFormat; 115 | const ioFormat chromaFormat; 116 | }; 117 | 118 | class bitDepth { 119 | public: 120 | bitDepth(int d): lumaBitDepth(d), chromaBitDepth(d) {}; 121 | bitDepth(int ld, int cd): lumaBitDepth(ld), chromaBitDepth(cd) {}; 122 | void operator () (std::ios_base& stream) const; 123 | private: 124 | const int lumaBitDepth; 125 | const int chromaBitDepth; 126 | }; 127 | 128 | class offset { 129 | public: 130 | offset(int o): lumaOffset(o), chromaOffset(o) {}; 131 | offset(int lo, int co): lumaOffset(lo), chromaOffset(co) {}; 132 | void operator () (std::ios_base& stream) const; 133 | private: 134 | const int lumaOffset; 135 | const int chromaOffset; 136 | }; 137 | 138 | } // end namespace pictureio 139 | 140 | // ostream io format, format manipulator 141 | std::ostream& operator << (std::ostream& stream, pictureio::format); 142 | 143 | // istream io format, format manipulator 144 | std::istream& operator >> (std::istream& stream, pictureio::format); 145 | 146 | // ostream bit Depth format manipulator 147 | std::ostream& operator << (std::ostream& stream, pictureio::bitDepth); 148 | 149 | // istream bit Depth format manipulator 150 | std::istream& operator >> (std::istream& stream, pictureio::bitDepth); 151 | 152 | // ostream offset format manipulator 153 | std::ostream& operator << (std::ostream& stream, pictureio::offset); 154 | 155 | // istream offset format manipulator 156 | std::istream& operator >> (std::istream& stream, pictureio::offset); 157 | 158 | std::istream& operator >> (std::istream& stream, Picture& array); 159 | 160 | std::ostream& operator << (std::ostream& stream, const Picture& array); 161 | 162 | #endif //PICTURE_3MAY11 163 | -------------------------------------------------------------------------------- /src/Library/Quantisation.h: -------------------------------------------------------------------------------- 1 | /*********************************************************************/ 2 | /* Quantisation.h */ 3 | /* Author: Tim Borer, BBC Research */ 4 | /* This version 7th July 2011 */ 5 | /* */ 6 | /* Declares stuff related to quantisation */ 7 | /* Copyright (c) BBC 2011-2015 -- For license see the LICENSE file */ 8 | /*********************************************************************/ 9 | 10 | #ifndef QUANTISATION_14MAY10 11 | #define QUANTISATION_14MAY10 12 | 13 | #include "Arrays.h" 14 | #include "Picture.h" 15 | 16 | const int adjust_quant_index(const int qIndex, const int qMatrix); 17 | 18 | const Array1D adjust_quant_indices(const Array1D& qIndices, const int qMatrix); 19 | 20 | const Array2D adjust_quant_indices(const Array2D& qIndices, const int qMatrix); 21 | 22 | // Quantise according to parameter q 23 | const int quant(int value, int q); 24 | 25 | // Inverse quantise a value according to quantisation index q 26 | const int scale(int value, int q); 27 | 28 | // Quantise all the coefficients in a block using 29 | // the same quantiser index 30 | const Array2D quantise_block(const ConstView2D& block, int q); 31 | 32 | // Quantise a block of coefficients using an array of quantisers 33 | // The block to be quantised may either be the transform of the whole picture 34 | // or a subband. In the former case this function will quantise slices, in the 35 | // latter case this function will quantise codeblocks 36 | const Array2D quantise_block(const ConstView2D& block, const Array2D& qIndices); 37 | 38 | // Inverse quantise all the coefficients in a block using 39 | // the same quantiser index 40 | const Array2D inverse_quantise_block(const ConstView2D& block, int q); 41 | 42 | // Inverse quantise a block of quantised coefficients using an array of quantisers. 43 | // The block to be inverse quantised may correspond either to the transform of the whole picture 44 | // or to a subband. In the former case this function will inverse quantise slices, in the 45 | // latter case this function will inverse quantise codeblocks 46 | const Array2D inverse_quantise_block(const ConstView2D& block, const Array2D& qIndices); 47 | 48 | /***** Predictive Quantisation for Simple, Main and Low Delay Profiles *****/ 49 | 50 | // Predict LL subband coefficient, at position [y][x], 51 | // from its neighbours above and to the left. 52 | const int predictDC(const Array2D& llSubband, int y, int x); 53 | 54 | // Quantise in-place transformed coefficients (using LL subband prediction) 55 | const Array2D quantise_transform(const Array2D& coefficients, 56 | const Array2D& qIndices, 57 | const Array1D& qMatrix); 58 | 59 | // Inverse quantise in-place transformed coefficients (using LL subband prediction) 60 | const Array2D inverse_quantise_transform(const Array2D& qCoeffs, 61 | const Array2D& qIndices, 62 | const Array1D& qMatrix); 63 | 64 | /***** Non-predictive Quantisation for High Quality Profile *****/ 65 | 66 | // Quantise in-place transformed coefficients (without LL subband prediction) 67 | const Array2D quantise_transform_np(const Array2D& coefficients, 68 | const int qIndex, 69 | const Array1D& qMatrix); 70 | 71 | const Array2D quantise_transform_np(const Array2D& coefficients, 72 | const Array2D& qIndices, 73 | const Array1D& qMatrix); 74 | 75 | // Inverse quantise in-place transformed coefficients (without LL subband prediction) 76 | const Array2D inverse_quantise_transform_np(const Array2D& qCoeffs, 77 | const Array2D& qIndices, 78 | const Array1D& qMatrix); 79 | 80 | // Quantise in-place transformed coefficients (using LL subband prediction) 81 | const Picture quantise_transform(const Picture& coefficients, 82 | const int qIndex, 83 | const Array1D& qMatrix); 84 | 85 | const Picture quantise_transform(const Picture& coefficients, 86 | const Array2D& qIndices, 87 | const Array1D& qMatrix); 88 | 89 | // Inverse quantise in-place transformed coefficients (using LL subband prediction) 90 | const Picture inverse_quantise_transform(const Picture& qCoeffs, 91 | const int qIndex, 92 | const Array1D& qMatrix); 93 | 94 | const Picture inverse_quantise_transform(const Picture& qCoeffs, 95 | const Array2D& qIndices, 96 | const Array1D& qMatrix); 97 | 98 | // Quantise in-place transformed coefficients (without LL subband prediction) 99 | const Picture quantise_transform_np(const Picture& coefficients, 100 | const int qIndex, 101 | const Array1D& qMatrix); 102 | 103 | const Picture quantise_transform_np(const Picture& coefficients, 104 | const Array2D& qIndices, 105 | const Array1D& qMatrix); 106 | 107 | // Inverse quantise in-place transformed coefficients (without LL subband prediction) 108 | const Picture inverse_quantise_transform_np(const Picture& qCoeffs, 109 | const int qIndex, 110 | const Array1D& qMatrix); 111 | 112 | const Picture inverse_quantise_transform_np(const Picture& qCoeffs, 113 | const Array2D& qIndices, 114 | const Array1D& qMatrix); 115 | 116 | const long long yss_for_slice(const Picture &inPicture, 117 | const int qIndex, 118 | const Array1D& qMatrix); 119 | 120 | #endif //QUANTISATION_14MAY10 121 | -------------------------------------------------------------------------------- /src/Library/Slices.h: -------------------------------------------------------------------------------- 1 | /*********************************************************************/ 2 | /* Slices.h */ 3 | /* Author: Tim Borer */ 4 | /* This version 8th August 2011 */ 5 | /* */ 6 | /* Defines stuff releating to slices in both low delay and */ 7 | /* high quality profile */ 8 | /* Copyright (c) BBC 2011-2015 -- For license see the LICENSE file */ 9 | /*********************************************************************/ 10 | 11 | #ifndef SLICES_24JUNE11 12 | #define SLICES_24JUNE11 13 | 14 | #include "Arrays.h" 15 | #include "Picture.h" 16 | 17 | // This slice_bytes returns the actual number of bytes for a slice at specific co-ordinates 18 | const int slice_bytes(int v, int h, // Slice co-ordinates 19 | const int ySlices, const int xSlices, // Number of slices 20 | const int sliceBytesNumerator, const int sliceBytesDenominator); 21 | 22 | // And this one fills an arrays with the number of bytes for corresponding slices (Scalar should be 1 for LD) 23 | const Array2D slice_bytes(const int ySlices, const int xSlices, const int totalBytes, const int scalar); 24 | 25 | // luma_slice_bits returns the number of bits in an LD luma slice after VLC coding 26 | const int luma_slice_bits(const Array2D& lumaSlice, const char waveletDepth); 27 | 28 | // chroma_slice_bits returns the number of bits in an LD luma slice after VLC coding 29 | const int chroma_slice_bits(const Array2D& uSlice, const Array2D& vSlice, const char waveletDepth); 30 | 31 | // Returns the number of bytes in a component HQ slice after VLC coding (no DC prediction) 32 | const int component_slice_bytes(const Array2D& componentSlice, const char waveletDepth, const int scalar); 33 | 34 | // Define a state machine for quantising slices 35 | class SliceQuantiser { 36 | public: 37 | SliceQuantiser(const Array2D& coefficients, 38 | int vSlices, int hSlices, 39 | const Array1D& quantMatrix); 40 | const int row() const {return v;} //Get row number for slice 41 | const int column() const {return h;} //Get column number for slice 42 | const bool next_slice(); //Go to next slice in raster order (returns false if no more slices) 43 | virtual const Array2D& quantise_slice(int qIndex) = 0; 44 | virtual ~SliceQuantiser() {} 45 | protected: 46 | const int ySlices; //Number of rows 47 | const int xSlices; //Number of columns 48 | const int coeffsHeight; 49 | const int coeffsWidth; 50 | const int sliceHeight; 51 | const int sliceWidth; 52 | const int numberOfSubbands; 53 | const int waveletDepth; 54 | const int transformSize; // 2**waveletDepth 55 | int v; //Current row 56 | int h; //Current column 57 | Array2D qSlice; // Slice array of quantised coeffs to be returned by "quantise_slice" 58 | private: 59 | SliceQuantiser(const SliceQuantiser&); //No copying 60 | SliceQuantiser& operator=(const SliceQuantiser&); //No assignment 61 | }; 62 | 63 | //**** Slice IO declarations ****// 64 | 65 | struct Slices { 66 | Slices(const PictureArray& yuvSlices, const int waveletDepth, const Array2D& qIndices); 67 | Slices(const PictureFormat& pictureFormat, int waveletDepth, 68 | int ySlices, int xSlices); 69 | PictureArray yuvSlices; 70 | const int waveletDepth; 71 | Array2D qIndices; 72 | 73 | int nSlices() { return yuvSlices.shape()[0]*yuvSlices.shape()[1]; } 74 | }; 75 | 76 | std::ostream& operator << (std::ostream& stream, const Slices& s); 77 | 78 | std::istream& operator >> (std::istream& stream, Slices& s); 79 | 80 | struct Slice { 81 | Slice(const Picture& p, int d, int i): 82 | yuvSlice(p), waveletDepth(d), qIndex(i) {}; 83 | Slice(const PictureFormat& f, int d): 84 | yuvSlice(f), waveletDepth(d) {}; 85 | Picture yuvSlice; 86 | const int waveletDepth; 87 | int qIndex; 88 | }; 89 | 90 | std::ostream& operator << (std::ostream& stream, const Slice& s); 91 | 92 | std::istream& operator >> (std::istream& stream, Slice& s); 93 | 94 | class Fragment; 95 | 96 | namespace sliceio { 97 | 98 | enum SliceIOMode {UNKNOWN, LD, HQVBR, HQCBR}; 99 | 100 | SliceIOMode &sliceIOMode(std::ios_base& stream); 101 | 102 | class lowDelay { 103 | public: 104 | lowDelay(const Array2D& b): bytes(b) {}; 105 | void operator () (std::ios_base& stream) const; 106 | private: 107 | const Array2D& bytes; 108 | }; 109 | 110 | class highQualityCBR { 111 | public: 112 | highQualityCBR(const Array2D& b, const int p, const int s): bytes(b), prefix(p), scalar(s) {}; 113 | void operator () (std::ios_base& stream) const; 114 | private: 115 | const Array2D& bytes; 116 | const int prefix; 117 | const int scalar; 118 | }; 119 | 120 | class highQualityVBR { 121 | public: 122 | highQualityVBR(const int p, const int s): prefix(p), scalar(s) {}; 123 | void operator () (std::ios_base& stream) const; 124 | private: 125 | const int prefix; 126 | const int scalar; 127 | }; 128 | 129 | // ostream format manipulator to set the size of a single slice 130 | class setBytes { 131 | public: 132 | setBytes(const int b): bytes(b) {}; 133 | void operator () (std::ios_base& stream) const; 134 | private: 135 | const int bytes; 136 | }; 137 | 138 | const Array2D *SliceSizes(std::ios_base& stream); 139 | 140 | class ExpectedSlicesForFragment { 141 | public: 142 | ExpectedSlicesForFragment(Fragment &frag); 143 | void operator () (std::ios_base& stream) const; 144 | private: 145 | const int n_slices; 146 | const int slice_offset_x; 147 | const int slice_offset_y; 148 | }; 149 | } // end namespace sliceio 150 | 151 | // istream format manipulator to set slice offsets when reading fragments 152 | std::istream& operator >> (std::istream& stream, sliceio::ExpectedSlicesForFragment esf); 153 | 154 | // ostream format manipulator to set the size of a single slice 155 | std::ostream& operator << (std::ostream& stream, sliceio::setBytes arg); 156 | 157 | // istream format manipulator to set the size of a single slice 158 | std::istream& operator >> (std::istream& stream, sliceio::setBytes arg); 159 | 160 | // ostream low delay format manipulator 161 | std::ostream& operator << (std::ostream& stream, sliceio::lowDelay arg); 162 | 163 | // istream low delay format manipulator 164 | std::istream& operator >> (std::istream& stream, sliceio::lowDelay arg); 165 | 166 | // ostream low delay format manipulator 167 | std::ostream& operator << (std::ostream& stream, sliceio::highQualityCBR arg); 168 | 169 | // istream low delay format manipulator 170 | std::istream& operator >> (std::istream& stream, sliceio::highQualityCBR arg); 171 | 172 | // ostream low delay format manipulator 173 | std::ostream& operator << (std::ostream& stream, sliceio::highQualityVBR arg); 174 | 175 | // istream low delay format manipulator 176 | std::istream& operator >> (std::istream& stream, sliceio::highQualityVBR arg); 177 | 178 | #endif //SLICES_24JUNE11 179 | -------------------------------------------------------------------------------- /src/Library/Utils.h: -------------------------------------------------------------------------------- 1 | /*********************************************************************/ 2 | /* Utils.h */ 3 | /* Author: Tim Borer and Galen Reich */ 4 | /* This version July 2020 */ 5 | /* */ 6 | /* Declares utility functions listed below (in namespace utils) */ 7 | /* fileSize: returns the size of a file in bytes */ 8 | /* pow: raises an integer to an integer power */ 9 | /* intlog2: the number of bits needed to express a number */ 10 | /* rationalise: the simplest form of a rational number */ 11 | /* Copyright (c) BBC 2011-2020 -- For license see the LICENSE file */ 12 | /*********************************************************************/ 13 | 14 | #ifndef UTILS_25FEB10 15 | #define UTILS_25FEB10 16 | 17 | #include 18 | 19 | namespace utils { 20 | 21 | // Does what it says on the tin. Returns file size in bytes. 22 | // Leaves the read pointer in the same position 23 | // TO DO: change return type to size_t? 24 | const int fileSize(const std::ifstream& infile); 25 | 26 | // A little utility function, raises base to power exp 27 | const int pow(int base, int exp); 28 | 29 | // Another utility function which counts the bits needed to express a number 30 | const int intlog2(int value); 31 | 32 | // Calculate the picture number given a frame number, picture number, and number 33 | // of pictures per frame - 1 or 2 (interlaced) 34 | unsigned long getPictureNumber(int fieldNumber, unsigned long long frameNumber, const int fieldsPerFrame); 35 | 36 | struct Rational { 37 | int numerator; 38 | int denominator; 39 | }; 40 | 41 | // Returns a rational number in which both numerator & denominator have been 42 | // divided by their greatest common divisor. 43 | const Rational rationalise(const int numerator, 44 | const int denominator); 45 | 46 | // Two functions to set the mode of stdio 47 | // Utility for setting the mode of stdin/stdout and cin/cout to either 48 | // binary or text mode. 49 | // The function actually changes the mode of stdin/out but since these 50 | // use the same file id as cin/cout it changes the mode of those as well. 51 | // This function is only really relevant to Windows OS. *nixes use binary 52 | // IO mode all the time (there is no distinction beween binary and text mode). 53 | // The function does nothing under *nixes. 54 | // An argument is needed to control the mode. This is should be a 55 | // platform independent type. I have used std::ios_base::openmode for this 56 | // purpose. When a value of std::ios_base::binary is passed as a parameter 57 | // then the stdio and cin/out streams are set to binary mode (on Windows OS). 58 | // Return value: as _setmode function for Windows (-1 indicates error) 59 | // 0 for *nix (always succeeds) 60 | 61 | int setstdinmode(std::ios_base::openmode); 62 | int setstdoutmode(std::ios_base::openmode); 63 | 64 | } // End namespace utils 65 | 66 | // Output formating for rational on streams 67 | std::ostream &operator << (std::ostream &stream, utils::Rational &r); 68 | 69 | #endif //UTILS_25FEB10 70 | -------------------------------------------------------------------------------- /src/Library/VLC.h: -------------------------------------------------------------------------------- 1 | /*********************************************************************/ 2 | /* VLC.h */ 3 | /* Author: Tim Borer */ 4 | /* This version 26th June 2011 */ 5 | /* */ 6 | /* Declares stuff related to variable length coding (exp-Golomb) */ 7 | /* 21st June 2011: Copied version from 30th May 2010 */ 8 | /* 26th June 2011: Made number of bytes in "Bytes" constant */ 9 | /* Copyright (c) BBC 2011-2015 -- For license see the LICENSE file */ 10 | /*********************************************************************/ 11 | 12 | #ifndef VLC_14MAY10 13 | #define VLC_14MAY10 14 | 15 | #include 16 | 17 | class UnsignedVLC { 18 | public: 19 | UnsignedVLC() {} 20 | UnsignedVLC(unsigned int value); 21 | UnsignedVLC(unsigned int numOfBits, unsigned int code): 22 | nBits(numOfBits), bits(code) {}; 23 | const unsigned int numOfBits() const {return nBits;} 24 | const unsigned int code() const {return bits;} 25 | operator const unsigned int() const; 26 | public: 27 | unsigned int nBits; 28 | unsigned int bits; 29 | }; 30 | 31 | class SignedVLC { 32 | public: 33 | SignedVLC() {} 34 | SignedVLC(int value); 35 | SignedVLC(unsigned int numOfBits, unsigned int code): 36 | nBits(numOfBits), bits(code) {}; 37 | const unsigned int numOfBits() const {return nBits;} 38 | const unsigned int code() const {return bits;} 39 | operator const int() const; 40 | public: 41 | unsigned int nBits; 42 | unsigned int bits; 43 | }; 44 | 45 | // ostream inserter for unsigned interleaved expGolomb 46 | std::ostream& operator << (std::ostream& stream, UnsignedVLC); 47 | 48 | // istream extractor for unsigned interleaved expGolomb 49 | std::istream& operator >> (std::istream& stream, UnsignedVLC&); 50 | 51 | // ostream inserter for signed interleaved expGolomb 52 | std::ostream& operator << (std::ostream& stream, SignedVLC); 53 | 54 | // istream extractor for signed interleaved expGolomb 55 | std::istream& operator >> (std::istream& stream, SignedVLC&); 56 | 57 | class Boolean { 58 | public: 59 | Boolean() {} 60 | Boolean(bool arg): bit(arg) {} 61 | operator bool() const {return bit;} 62 | private: 63 | bool bit; 64 | }; 65 | 66 | std::ostream& operator << (std::ostream& stream, Boolean); 67 | 68 | std::istream& operator >> (std::istream& stream, Boolean&); 69 | 70 | class Bits { 71 | public: 72 | explicit Bits(unsigned int no_of_bits): nBits(no_of_bits) {} 73 | Bits(unsigned int no_of_bits, unsigned int value); 74 | Bits& operator=(unsigned int arg) { 75 | bits=arg; 76 | return *this; } 77 | operator unsigned int() const {return bits;} 78 | const unsigned int bitCount() const {return nBits;} 79 | private: 80 | const unsigned int nBits; 81 | unsigned int bits; 82 | }; 83 | 84 | std::ostream& operator << (std::ostream& stream, Bits b); 85 | 86 | std::istream& operator >> (std::istream& stream, Bits& b); 87 | 88 | class Bytes { 89 | public: 90 | explicit Bytes(unsigned int no_of_bytes): nBytes(no_of_bytes) {} 91 | Bytes(unsigned int no_of_bytes, unsigned long value); 92 | Bytes& operator=(unsigned long arg) { 93 | bytes=arg; 94 | return *this; } 95 | operator unsigned long() const {return bytes;} 96 | const unsigned int byteCount() const {return nBytes;} 97 | private: 98 | const unsigned int nBytes; 99 | unsigned long bytes; 100 | }; 101 | 102 | std::ostream& operator << (std::ostream& stream, Bytes b); 103 | 104 | std::istream& operator >> (std::istream& stream, Bytes& b); 105 | 106 | namespace vlc { 107 | 108 | class bounded { 109 | public: 110 | bounded(int maxBits): bits(maxBits) {}; 111 | // Set maximum bits more to be written to stream 112 | void operator () (std::ios_base& stream) const; 113 | private: 114 | int bits; 115 | }; 116 | 117 | // ostream unbounded format manipulator 118 | std::ostream& unbounded(std::ostream& stream); 119 | 120 | // ostream unbounded format manipulator 121 | std::istream& unbounded(std::istream& stream); 122 | 123 | // ostream flush writes zero bits to end of bounded stream 124 | // Note: end of bounded stream may not be byte aligned 125 | std::ostream& flush(std::ostream& stream); 126 | 127 | // istream flush moves read pointer to end of bounded stream 128 | // Note: end of bounded stream may not be byte aligned 129 | std::istream& flush(std::istream& stream); 130 | 131 | // ostream align moves read pinter to start of next byte 132 | std::ostream& align(std::ostream& stream); 133 | 134 | // istream align moves write pinter to start of next byte 135 | std::istream& align(std::istream& stream); 136 | 137 | } // end namespace vlc 138 | 139 | // ostream bounded format manipulator 140 | std::ostream& operator << (std::ostream& stream, vlc::bounded b); 141 | 142 | // istream bounded format manipulator 143 | std::istream& operator >> (std::istream& stream, vlc::bounded b); 144 | 145 | #endif //VLC_14MAY10 146 | -------------------------------------------------------------------------------- /src/Library/WaveletTransform.h: -------------------------------------------------------------------------------- 1 | /*********************************************************************/ 2 | /* WaveletTransform.h */ 3 | /* Author: Tim Borer */ 4 | /* This version 7th July 2011 */ 5 | /* */ 6 | /* Declares wavelet transform stuff */ 7 | /* Copyright (c) BBC 2011-2015 -- For license see the LICENSE file */ 8 | /*********************************************************************/ 9 | 10 | #ifndef WAVELETTRANSFORM_1MARCH10 11 | #define WAVELETTRANSFORM_1MARCH10 12 | 13 | #include 14 | #include "Arrays.h" 15 | #include "Picture.h" 16 | 17 | // Define enumeration for different ypes of wavelet kernel 18 | // Kernels are: Deslauriers-Dubuc (9,7) 19 | // LeGall (5,3) 20 | // Deslauriers-Dubuc (13,7) 21 | // Haar with no shift 22 | // Haar with single shift per level 23 | // Fidelity filter 24 | // Daubechies (9,7) integer approximation 25 | // NullKernel (does nothing, for test purposes) 26 | enum WaveletKernel {DD97, LeGall, DD137, Haar0, Haar1, Fidelity, Daub97, NullKernel}; 27 | 28 | std::ostream& operator<<(std::ostream& os, WaveletKernel kernel); 29 | 30 | std::istream& operator>>(std::istream& strm, WaveletKernel& kernel); 31 | 32 | // Return the size of a padded array given image size and wavelet depth. 33 | const int paddedSize(int size, int depth); 34 | 35 | // Check if a wavelet transform is possible with the given wavelet depth 36 | const bool waveletTransformIsPossible(const int waveletDepth, const int lengthLuma, const int lengthChroma); 37 | 38 | // Checks if a wavelet transform is possible with the given slice size for the given wavelet depth 39 | const int sliceSizeIsValid(const int waveletDepth, const int lengthLuma, const int lengthChroma, const int nSize); 40 | 41 | // Suggest a wavelet depth that can encode the image 42 | const int suggestWaveletDepth(const int lumaWidth, const int lumaHeight, const int chromaWidth, const int chromaHeight); 43 | const int suggestWaveletDepth(const int lumaWidth, const int lumaHeight, const int chromaWidth, const int chromaHeight, int startingDepth); 44 | 45 | // Calculate suggested slice size parameters for the user 46 | const int suggestSliceSize(const int waveletDepth, const int lengthLuma, const int lengthChroma); 47 | const int suggestSliceSize(const int waveletDepth, const int lengthLuma, const int lengthChroma, int startingSliceSize); 48 | 49 | //Forward wavelet transform, including padding if necessary 50 | const Array2D waveletTransform(const Array2D& picture, WaveletKernel kernel, int depth); 51 | 52 | //Inverse wavelet transform, removes padding if necessary. 53 | // "shape" give size of unpadded image 54 | const Array2D inverseWaveletTransform(const Array2D& transform, 55 | WaveletKernel kernel, 56 | int depth, 57 | Shape2D shape); 58 | 59 | // Return the default quantisation matrix for a given wavelet kernel and depth 60 | const Array1D quantMatrix(WaveletKernel kernel, int depth); 61 | 62 | // Convert a Array2D containing an in place wavelet transform into a 1D array of subbands 63 | const BlockVector split_into_subbands(const Array2D& picture, const char waveletDepth); 64 | 65 | // Converts a 1D array of subbands back to a single single Array2D corresponding 66 | // to an in-place wavelet transform 67 | const Array2D merge_subbands(const BlockVector& subbands); 68 | 69 | //Forward wavelet transform, including padding if necessary 70 | const Picture waveletTransform(const Picture& picture, enum WaveletKernel kernel, int depth); 71 | 72 | //Inverse wavelet transform, removes padding if necessary. 73 | // "format" specifies format of unpadded image 74 | const Picture inverseWaveletTransform(const Picture& transform, 75 | enum WaveletKernel kernel, 76 | int depth, 77 | PictureFormat format); 78 | 79 | #endif //WAVELETTRANSFORM_1MARCH10 80 | -------------------------------------------------------------------------------- /src/Library/src/Frame.cpp: -------------------------------------------------------------------------------- 1 | /*********************************************************************/ 2 | /* Frame.cpp */ 3 | /* Author: Tim Borer */ 4 | /* This version 26th August 2011 */ 5 | /* */ 6 | /* Defines stuff related to colour frames. */ 7 | /* 6th May 2011: Initial version */ 8 | /* 2nd June 2011: Added "frame" methods and some other implementaions*/ 9 | /* 5th August 2011: Corrected header declaration */ 10 | /* 26th Sept 2011: Added alternate constructor (see header) */ 11 | /* Copyright (c) BBC 2011-2015 -- For license see the LICENSE file */ 12 | /*********************************************************************/ 13 | 14 | #include "Frame.h" 15 | 16 | Frame::Frame(int height, int width, ColourFormat format, bool interlaced, bool topFieldFirst): 17 | Picture(PictureFormat(height, width, format)), intl(interlaced), tff(topFieldFirst) { 18 | } 19 | 20 | Frame::Frame(const PictureFormat& format, bool interlaced, bool topFieldFirst): 21 | Picture(format), intl(interlaced), tff(topFieldFirst) { 22 | } 23 | 24 | bool Frame::interlaced() const { 25 | return intl; 26 | } 27 | 28 | void Frame::interlaced(bool i) { 29 | intl = i; 30 | } 31 | 32 | bool Frame::topFieldFirst() const { 33 | return tff; 34 | } 35 | 36 | void Frame::topFieldFirst(bool t) { 37 | tff = t; 38 | } 39 | 40 | const Picture Frame::topField() const { 41 | // Get parameters of field 42 | const int height = format().lumaHeight()/2; 43 | const int width = format().lumaWidth(); 44 | const ColourFormat chromaFormat = format().chromaFormat(); 45 | // Construct interlaced field 46 | Picture picture(PictureFormat(height, width, chromaFormat)); 47 | // Set components of interlaced field 48 | const int top = 0; 49 | const int yBottom = format().lumaHeight(); 50 | const int uvBottom = format().chromaHeight(); 51 | using boost::indices; 52 | picture.y(y()[indices[Range(top,yBottom,2)][Range()]]); 53 | picture.c1(c1()[indices[Range(top,uvBottom,2)][Range()]]); 54 | picture.c2(c2()[indices[Range(top,uvBottom,2)][Range()]]); 55 | return picture; 56 | } 57 | 58 | void Frame::topField(const Picture& f) { 59 | const int top = 0; 60 | const int yBottom = format().lumaHeight(); 61 | const int uvBottom = format().chromaHeight(); 62 | using boost::indices; 63 | luma[indices[Range(top,yBottom,2)][Range()]] = f.y(); 64 | chroma1[indices[Range(top,uvBottom,2)][Range()]] = f.c1(); 65 | chroma2[indices[Range(top,uvBottom,2)][Range()]] = f.c2(); 66 | } 67 | 68 | const Picture Frame::bottomField() const { 69 | // Get parameters of field 70 | const int height = format().lumaHeight()/2; 71 | const int width = format().lumaWidth(); 72 | const ColourFormat chromaFormat = format().chromaFormat(); 73 | // Construct interlaced field 74 | Picture picture(PictureFormat(height, width, chromaFormat)); 75 | // Set components of interlaced field 76 | const int top = 1; 77 | const int yBottom = format().lumaHeight(); 78 | const int uvBottom = format().chromaHeight(); 79 | using boost::indices; 80 | picture.y(y()[indices[Range(top,yBottom,2)][Range()]]); 81 | picture.c1(c1()[indices[Range(top,uvBottom,2)][Range()]]); 82 | picture.c2(c2()[indices[Range(top,uvBottom,2)][Range()]]); 83 | return picture; 84 | } 85 | 86 | void Frame::bottomField(const Picture& f) { 87 | const int top = 1; 88 | const int yBottom = format().lumaHeight(); 89 | const int uvBottom = format().chromaHeight(); 90 | using boost::indices; 91 | luma[indices[Range(top,yBottom,2)][Range()]] = f.y(); 92 | chroma1[indices[Range(top,uvBottom,2)][Range()]] = f.c1(); 93 | chroma2[indices[Range(top,uvBottom,2)][Range()]] = f.c2(); 94 | } 95 | 96 | const Picture Frame::firstField() const { 97 | return (tff? topField() : bottomField()); 98 | } 99 | 100 | void Frame::firstField(const Picture& f) { 101 | tff ? topField(f) : bottomField(f); 102 | } 103 | 104 | const Picture Frame::secondField() const { 105 | return (tff? bottomField() : topField()); 106 | } 107 | 108 | void Frame::secondField(const Picture& f) { 109 | tff ? bottomField(f) : topField(f); 110 | } 111 | 112 | const Picture& Frame::frame() const { 113 | return *this; 114 | } 115 | 116 | void Frame::frame(const Picture& f) { 117 | Picture::operator=(f); 118 | } 119 | -------------------------------------------------------------------------------- /src/Library/src/Utils.cpp: -------------------------------------------------------------------------------- 1 | /*********************************************************************/ 2 | /* Utils.cpp */ 3 | /* Author: Tim Borer and Galen Reich */ 4 | /* This version July 2020 */ 5 | /* */ 6 | /* Defines utility functions listed below (in namespace utils) */ 7 | /* fileSize: returns the size of a file in bytes */ 8 | /* pow: raises an integer to an integer power */ 9 | /* intlog2: the number of bits needed to express a number */ 10 | /* rationalise: the simplest form of a rational number */ 11 | /* Copyright (c) BBC 2011-2020 -- For license see the LICENSE file */ 12 | /*********************************************************************/ 13 | 14 | #include "Utils.h" 15 | 16 | #include "boost/integer/common_factor_rt.hpp" // For gcd function 17 | 18 | // Does what it says on the tin. Returns file size in bytes. 19 | // Leaves the read pointer in the same position 20 | // TO DO: change return type to size_t? 21 | const int utils::fileSize(const std::ifstream& infile) { 22 | // const cast is becuase the function is logically const but 23 | // needs to modify the fstream then restore it. 24 | std::ifstream& file = const_cast(infile); 25 | std::ifstream::pos_type filePosn = file.tellg(); 26 | file.seekg(0, std::ios::end); 27 | int size = static_cast(std::streamoff(file.tellg())); 28 | file.seekg(filePosn); 29 | return size; 30 | } 31 | 32 | // A little utility function, raises base to power exp 33 | const int utils::pow(int base, int exp) { 34 | int value = 1; 35 | if (exp>0) while (exp--) value *= base; 36 | return value; 37 | } 38 | 39 | // Another utility function which counts the bits needed to express a number 40 | const int utils::intlog2(int value) { 41 | int log = 0; 42 | --value; 43 | while (value>0) { 44 | value >>= 1; 45 | ++log; 46 | } 47 | return log; 48 | } 49 | 50 | // Calculate the picture number given a frame number, picture number, and number 51 | // of pictures per frame - 1 or 2 (interlaced) 52 | unsigned long utils::getPictureNumber(int fieldNumber, unsigned long long frameNumber, const int fieldsPerFrame){ 53 | 54 | // Input checking 55 | if (fieldNumber < 0) throw std::logic_error("field number should be positive"); 56 | if (fieldNumber > fieldsPerFrame) throw std::logic_error("field number exceeds number of fields per frame"); 57 | if (fieldsPerFrame!=1 && fieldsPerFrame!=2) throw std::logic_error("number of fields per frame should be 1 (progressive) or 2 (interlaced)"); 58 | 59 | const unsigned long long bigPictureNumber = fieldNumber + frameNumber*fieldsPerFrame; 60 | const unsigned long long bitLimit32 = (1ULL) << 32; 61 | // Wrap round to 0 after 2^32 -1 bits 62 | return bigPictureNumber % bitLimit32; 63 | } 64 | 65 | const utils::Rational utils::rationalise(const int numerator, 66 | const int denominator) { 67 | const int gcd = boost::integer::gcd(numerator, denominator); 68 | utils::Rational result; 69 | result.numerator = numerator/gcd; 70 | result.denominator = denominator/gcd; 71 | return result; 72 | } 73 | 74 | // Utilities to set iomode for stdio 75 | #ifdef _WIN32 76 | 77 | #include //Defines _fileno (needed to set standard i/o to binary mode) 78 | #include //Defines _setmode (needed to set standard input to binary mode) 79 | #include //Contains definition of _O_BINARY 80 | 81 | int utils::setstdinmode(std::ios_base::openmode mode) { 82 | int winMode; 83 | if ((mode&std::ios_base::binary)==std::ios_base::binary) winMode=_O_BINARY; 84 | else winMode=_O_TEXT; 85 | //Set standard input and standard output to binary mode. 86 | return _setmode(_fileno( stdin ), winMode ); 87 | } 88 | 89 | int utils::setstdoutmode(std::ios_base::openmode mode) { 90 | int winMode; 91 | if ((mode&std::ios_base::binary)==std::ios_base::binary) winMode=_O_BINARY; 92 | else winMode=_O_TEXT; 93 | //Set standard input and standard output to binary mode. 94 | return _setmode(_fileno( stdout ), winMode ); 95 | } 96 | 97 | #else 98 | 99 | int utils::setstdinmode(std::ios_base::openmode) { 100 | return 0; 101 | } 102 | 103 | int utils::setstdoutmode(std::ios_base::openmode) { 104 | return 0; 105 | } 106 | 107 | std::ostream &operator << (std::ostream &stream, utils::Rational &r) { 108 | stream << r.numerator << "/" << r.denominator; 109 | return stream; 110 | } 111 | 112 | #endif 113 | 114 | -------------------------------------------------------------------------------- /src/Makefile.am: -------------------------------------------------------------------------------- 1 | AUTOMAKE_OPTIONS = foreign 2 | 3 | if ENABLE_FRAME_DECODER 4 | OPT_SUBDIRS = DecodeFrame 5 | else 6 | OPT_SUBDIRS = 7 | endif 8 | 9 | SUBDIRS = boost tclap Library DecodeStream EncodeStream $(OPT_SUBDIRS) 10 | 11 | DISTCLEANFILES = vc2reference-stdint.h 12 | -------------------------------------------------------------------------------- /src/boost/COPYING: -------------------------------------------------------------------------------- 1 | Boost Software License - Version 1.0 - August 17th, 2003 2 | 3 | Permission is hereby granted, free of charge, to any person or organization 4 | obtaining a copy of the software and accompanying documentation covered by 5 | this license (the "Software") to use, reproduce, display, distribute, 6 | execute, and transmit the Software, and to prepare derivative works of the 7 | Software, and to permit third-parties to whom the Software is furnished to 8 | do so, all subject to the following: 9 | 10 | The copyright notices in the Software and this entire statement, including 11 | the above license grant, this restriction and the following disclaimer, 12 | must be included in all copies of the Software, in whole or in part, and 13 | all derivative works of the Software, unless such copies or derivative 14 | works are solely in the form of machine-executable object code generated by 15 | a source language processor. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT 20 | SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE 21 | FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, 22 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 23 | DEALINGS IN THE SOFTWARE. 24 | -------------------------------------------------------------------------------- /src/boost/Makefile.am: -------------------------------------------------------------------------------- 1 | EXTRA_DIST = \ 2 | COPYING \ 3 | multi_array.original \ 4 | multi_array/view.original \ 5 | multi_array/multi_array_ref.original \ 6 | multi_array/subarray.original 7 | 8 | noinst_HEADERS = \ 9 | multi_array.hpp \ 10 | multi_array/algorithm.hpp \ 11 | multi_array/collection_concept.hpp \ 12 | multi_array/copy_array.hpp \ 13 | multi_array/extent_range.hpp \ 14 | multi_array/index_range.hpp \ 15 | multi_array/multi_array_ref.hpp \ 16 | multi_array/range_list.hpp \ 17 | multi_array/subarray.hpp \ 18 | multi_array/types.hpp \ 19 | multi_array/base.hpp \ 20 | multi_array/concept_checks.hpp \ 21 | multi_array/extent_gen.hpp \ 22 | multi_array/index_gen.hpp \ 23 | multi_array/iterator.hpp \ 24 | multi_array/storage_order.hpp \ 25 | multi_array/view.hpp 26 | 27 | -------------------------------------------------------------------------------- /src/boost/multi_array/algorithm.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BOOST_ALGORITHM_RG071801_HPP 2 | #define BOOST_ALGORITHM_RG071801_HPP 3 | 4 | // 5 | // 6 | // Copyright (c) 1994 7 | // Hewlett-Packard Company 8 | // 9 | // Permission to use, copy, modify, distribute and sell this software 10 | // and its documentation for any purpose is hereby granted without fee, 11 | // provided that the above copyright notice appear in all copies and 12 | // that both that copyright notice and this permission notice appear 13 | // in supporting documentation. Hewlett-Packard Company makes no 14 | // representations about the suitability of this software for any 15 | // purpose. It is provided "as is" without express or implied warranty. 16 | // 17 | // 18 | // Copyright (c) 1996-1998 19 | // Silicon Graphics Computer Systems, Inc. 20 | // 21 | // Permission to use, copy, modify, distribute and sell this software 22 | // and its documentation for any purpose is hereby granted without fee, 23 | // provided that the above copyright notice appear in all copies and 24 | // that both that copyright notice and this permission notice appear 25 | // in supporting documentation. Silicon Graphics makes no 26 | // representations about the suitability of this software for any 27 | // purpose. It is provided "as is" without express or implied warranty. 28 | // 29 | 30 | // Copyright 2002 The Trustees of Indiana University. 31 | 32 | // Use, modification and distribution is subject to the Boost Software 33 | // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 34 | // http://www.boost.org/LICENSE_1_0.txt) 35 | 36 | // Boost.MultiArray Library 37 | // Authors: Ronald Garcia 38 | // Jeremy Siek 39 | // Andrew Lumsdaine 40 | // See http://www.boost.org/libs/multi_array for documentation. 41 | 42 | 43 | #include "boost/iterator.hpp" 44 | 45 | namespace boost { 46 | namespace detail { 47 | namespace multi_array { 48 | //-------------------------------------------------- 49 | // copy_n (not part of the C++ standard) 50 | #if 1 51 | 52 | template 53 | OutputIter copy_n(InputIter first, Size count, 54 | OutputIter result) { 55 | for ( ; count > 0; --count) { 56 | *result = *first; 57 | ++first; 58 | ++result; 59 | } 60 | return result; 61 | } 62 | #else // !1 63 | 64 | template 65 | OutputIter copy_n__(InputIter first, Size count, 66 | OutputIter result, 67 | std::input_iterator_tag) { 68 | for ( ; count > 0; --count) { 69 | *result = *first; 70 | ++first; 71 | ++result; 72 | } 73 | return result; 74 | } 75 | 76 | template 77 | inline OutputIter 78 | copy_n__(RAIter first, Size count, 79 | OutputIter result, 80 | std::random_access_iterator_tag) { 81 | RAIter last = first + count; 82 | return std::copy(first, last, result); 83 | } 84 | 85 | template 86 | inline OutputIter 87 | copy_n__(InputIter first, Size count, OutputIter result) { 88 | typedef typename std::iterator_traits::iterator_category cat; 89 | return copy_n__(first, count, result, cat()); 90 | } 91 | 92 | template 93 | inline OutputIter 94 | copy_n(InputIter first, Size count, OutputIter result) { 95 | return copy_n__(first, count, result); 96 | } 97 | 98 | #endif // 1 99 | } // namespace multi_array 100 | } // namespace detail 101 | } // namespace boost 102 | 103 | #endif // BOOST_ALGORITHM_RG071801_HPP 104 | -------------------------------------------------------------------------------- /src/boost/multi_array/collection_concept.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2002 The Trustees of Indiana University. 2 | 3 | // Use, modification and distribution is subject to the Boost Software 4 | // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 5 | // http://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // Boost.MultiArray Library 8 | // Authors: Ronald Garcia 9 | // Jeremy Siek 10 | // Andrew Lumsdaine 11 | // See http://www.boost.org/libs/multi_array for documentation. 12 | 13 | #ifndef COLLECTION_CONCEPT_RG103101_HPP 14 | #define COLLECTION_CONCEPT_RG103101_HPP 15 | 16 | #include "boost/concept_check.hpp" 17 | 18 | namespace boost { 19 | namespace detail { 20 | namespace multi_array { // Old location for this 21 | using boost::CollectionConcept; 22 | } 23 | } 24 | 25 | } 26 | #endif // COLLECTION_CONCEPT_RG103101_HPP 27 | -------------------------------------------------------------------------------- /src/boost/multi_array/concept_checks.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2002 The Trustees of Indiana University. 2 | 3 | // Use, modification and distribution is subject to the Boost Software 4 | // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 5 | // http://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // Boost.MultiArray Library 8 | // Authors: Ronald Garcia 9 | // Jeremy Siek 10 | // Andrew Lumsdaine 11 | // See http://www.boost.org/libs/multi_array for documentation. 12 | 13 | #ifndef BOOST_MULTI_ARRAY_CONCEPT_CHECKS_RG110101_HPP 14 | #define BOOST_MULTI_ARRAY_CONCEPT_CHECKS_RG110101_HPP 15 | 16 | // 17 | // concept-checks.hpp - Checks out Const MultiArray and MultiArray 18 | // concepts 19 | // 20 | 21 | #include "boost/concept_check.hpp" 22 | #include "boost/iterator/iterator_concepts.hpp" 23 | 24 | namespace boost { 25 | namespace multi_array_concepts { 26 | 27 | namespace detail { 28 | // 29 | // idgen_helper - 30 | // This is a helper for generating index_gen instantiations with 31 | // the right type in order to test the call to 32 | // operator[](index_gen). Since one would normally write: 33 | // A[ indices[range1][range2] ]; // or 34 | // B[ indices[index1][index2][range1] ]; 35 | // idgen helper allows us to generate the "indices" type by 36 | // creating it through recursive calls. 37 | template 38 | struct idgen_helper { 39 | 40 | template 41 | static void call(Array& a, const IdxGen& idgen, Call_Type c) { 42 | idgen_helper::call(a,idgen[c],c); 43 | } 44 | }; 45 | 46 | template <> 47 | struct idgen_helper<0> { 48 | 49 | template 50 | static void call(Array& a, const IdxGen& idgen, Call_Type) { 51 | a[ idgen ]; 52 | } 53 | }; 54 | 55 | } // namespace detail 56 | 57 | 58 | template 59 | struct ConstMultiArrayConcept 60 | { 61 | void constraints() { 62 | // function_requires< CopyConstructibleConcept >(); 63 | function_requires< boost_concepts::ForwardTraversalConcept >(); 64 | function_requires< boost_concepts::ReadableIteratorConcept >(); 65 | function_requires< boost_concepts::ForwardTraversalConcept >(); 66 | function_requires< boost_concepts::ReadableIteratorConcept >(); 67 | 68 | // RG - a( CollectionArchetype) when available... 69 | a[ id ]; 70 | // Test slicing, keeping only the first dimension, losing the rest 71 | detail::idgen_helper::call(a,idgen[range],id); 72 | 73 | // Test slicing, keeping all dimensions. 74 | detail::idgen_helper::call(a,idgen[range],range); 75 | 76 | st = a.size(); 77 | st = a.num_dimensions(); 78 | st = Array::dimensionality; 79 | st = a.num_elements(); 80 | stp = a.shape(); 81 | idp = a.strides(); 82 | idp = a.index_bases(); 83 | cit = a.begin(); 84 | cit = a.end(); 85 | crit = a.rbegin(); 86 | crit = a.rend(); 87 | eltp = a.origin(); 88 | } 89 | 90 | typedef typename Array::value_type value_type; 91 | typedef typename Array::reference reference; 92 | typedef typename Array::const_reference const_reference; 93 | typedef typename Array::size_type size_type; 94 | typedef typename Array::difference_type difference_type; 95 | typedef typename Array::iterator iterator; 96 | typedef typename Array::const_iterator const_iterator; 97 | typedef typename Array::reverse_iterator reverse_iterator; 98 | typedef typename Array::const_reverse_iterator const_reverse_iterator; 99 | typedef typename Array::element element; 100 | typedef typename Array::index index; 101 | typedef typename Array::index_gen index_gen; 102 | typedef typename Array::index_range index_range; 103 | typedef typename Array::extent_gen extent_gen; 104 | typedef typename Array::extent_range extent_range; 105 | 106 | Array a; 107 | size_type st; 108 | const size_type* stp; 109 | index id; 110 | const index* idp; 111 | const_iterator cit; 112 | const_reverse_iterator crit; 113 | const element* eltp; 114 | index_gen idgen; 115 | index_range range; 116 | }; 117 | 118 | 119 | template 120 | struct MutableMultiArrayConcept 121 | { 122 | void constraints() { 123 | // function_requires< CopyConstructibleConcept >(); 124 | 125 | function_requires< boost_concepts::ForwardTraversalConcept >(); 126 | function_requires< boost_concepts::ReadableIteratorConcept >(); 127 | function_requires< boost_concepts::WritableIteratorConcept >(); 128 | function_requires< boost_concepts::ForwardTraversalConcept >(); 129 | function_requires< boost_concepts::ReadableIteratorConcept >(); 130 | function_requires< boost::OutputIterator >(); 131 | 132 | // RG - a( CollectionArchetype) when available... 133 | value_type vt = a[ id ]; 134 | 135 | // Test slicing, keeping only the first dimension, losing the rest 136 | detail::idgen_helper::call(a,idgen[range],id); 137 | 138 | // Test slicing, keeping all dimensions. 139 | detail::idgen_helper::call(a,idgen[range],range); 140 | 141 | st = a.size(); 142 | st = a.num_dimensions(); 143 | st = a.num_elements(); 144 | stp = a.shape(); 145 | idp = a.strides(); 146 | idp = a.index_bases(); 147 | it = a.begin(); 148 | it = a.end(); 149 | rit = a.rbegin(); 150 | rit = a.rend(); 151 | eltp = a.origin(); 152 | const_constraints(a); 153 | } 154 | 155 | void const_constraints(const Array& a) { 156 | 157 | // value_type vt = a[ id ]; 158 | 159 | // Test slicing, keeping only the first dimension, losing the rest 160 | detail::idgen_helper::call(a,idgen[range],id); 161 | 162 | // Test slicing, keeping all dimensions. 163 | detail::idgen_helper::call(a,idgen[range],range); 164 | 165 | st = a.size(); 166 | st = a.num_dimensions(); 167 | st = a.num_elements(); 168 | stp = a.shape(); 169 | idp = a.strides(); 170 | idp = a.index_bases(); 171 | cit = a.begin(); 172 | cit = a.end(); 173 | crit = a.rbegin(); 174 | crit = a.rend(); 175 | eltp = a.origin(); 176 | } 177 | 178 | typedef typename Array::value_type value_type; 179 | typedef typename Array::reference reference; 180 | typedef typename Array::const_reference const_reference; 181 | typedef typename Array::size_type size_type; 182 | typedef typename Array::difference_type difference_type; 183 | typedef typename Array::iterator iterator; 184 | typedef typename Array::const_iterator const_iterator; 185 | typedef typename Array::reverse_iterator reverse_iterator; 186 | typedef typename Array::const_reverse_iterator const_reverse_iterator; 187 | typedef typename Array::element element; 188 | typedef typename Array::index index; 189 | typedef typename Array::index_gen index_gen; 190 | typedef typename Array::index_range index_range; 191 | typedef typename Array::extent_gen extent_gen; 192 | typedef typename Array::extent_range extent_range; 193 | 194 | Array a; 195 | size_type st; 196 | const size_type* stp; 197 | index id; 198 | const index* idp; 199 | iterator it; 200 | const_iterator cit; 201 | reverse_iterator rit; 202 | const_reverse_iterator crit; 203 | const element* eltp; 204 | index_gen idgen; 205 | index_range range; 206 | }; 207 | 208 | 209 | } // namespace multi_array 210 | 211 | namespace detail { 212 | namespace multi_array { // Old locations for these 213 | using boost::multi_array_concepts::ConstMultiArrayConcept; 214 | using boost::multi_array_concepts::MutableMultiArrayConcept; 215 | } 216 | } 217 | 218 | } // namespace boost 219 | 220 | 221 | #endif // BOOST_MULTI_ARRAY_CONCEPT_CHECKS_RG110101_HPP 222 | -------------------------------------------------------------------------------- /src/boost/multi_array/copy_array.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2002 The Trustees of Indiana University. 2 | 3 | // Use, modification and distribution is subject to the Boost Software 4 | // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 5 | // http://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // Boost.MultiArray Library 8 | // Authors: Ronald Garcia 9 | // Jeremy Siek 10 | // Andrew Lumsdaine 11 | // See http://www.boost.org/libs/multi_array for documentation. 12 | 13 | #ifndef COPY_ARRAY_RG092101_HPP 14 | #define COPY_ARRAY_RG092101_HPP 15 | 16 | // 17 | // copy_array.hpp - generic code for copying the contents of one 18 | // Basic_MultiArray to another. We assume that they are of the same 19 | // shape 20 | // 21 | #include "boost/type.hpp" 22 | #include "boost/assert.hpp" 23 | 24 | namespace boost { 25 | namespace detail { 26 | namespace multi_array { 27 | 28 | template 29 | class copy_dispatch { 30 | public: 31 | template 32 | static void copy_array (SourceIterator first, SourceIterator last, 33 | DestIterator result) { 34 | while (first != last) { 35 | copy_array(*first++,*result++); 36 | } 37 | } 38 | private: 39 | // Array2 has to be passed by VALUE here because subarray 40 | // pseudo-references are temporaries created by iterator::operator*() 41 | template 42 | static void copy_array (const Array1& source, Array2 dest) { 43 | copy_array(source.begin(),source.end(),dest.begin()); 44 | } 45 | 46 | static void copy_array (const Element& source, Element& dest) { 47 | dest = source; 48 | } 49 | 50 | }; 51 | 52 | 53 | template 54 | void copy_array (Array1& source, Array2& dest) { 55 | BOOST_ASSERT(std::equal(source.shape(),source.shape()+source.num_dimensions(), 56 | dest.shape())); 57 | // Dispatch to the proper function 58 | typedef typename Array1::element element_type; 59 | copy_dispatch:: 60 | copy_array(source.begin(),source.end(),dest.begin()); 61 | } 62 | 63 | 64 | } // namespace multi_array 65 | } // namespace detail 66 | } // namespace boost 67 | 68 | #endif // COPY_ARRAY_RG092101_HPP 69 | -------------------------------------------------------------------------------- /src/boost/multi_array/extent_gen.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2002 The Trustees of Indiana University. 2 | 3 | // Use, modification and distribution is subject to the Boost Software 4 | // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 5 | // http://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // Boost.MultiArray Library 8 | // Authors: Ronald Garcia 9 | // Jeremy Siek 10 | // Andrew Lumsdaine 11 | // See http://www.boost.org/libs/multi_array for documentation. 12 | 13 | #ifndef BOOST_EXTENT_GEN_RG071801_HPP 14 | #define BOOST_EXTENT_GEN_RG071801_HPP 15 | 16 | #include "boost/multi_array/extent_range.hpp" 17 | #include "boost/multi_array/range_list.hpp" 18 | #include "boost/multi_array/types.hpp" 19 | #include "boost/array.hpp" 20 | #include 21 | 22 | namespace boost { 23 | namespace detail { 24 | namespace multi_array { 25 | 26 | 27 | template 28 | class extent_gen { 29 | public: 30 | typedef boost::detail::multi_array::index index; 31 | typedef boost::detail::multi_array::size_type size_type; 32 | typedef extent_range range; 33 | private: 34 | typedef typename range_list_generator::type range_list; 35 | public: 36 | template 37 | struct gen_type { 38 | typedef extent_gen type; 39 | }; 40 | 41 | range_list ranges_; 42 | 43 | extent_gen() { } 44 | 45 | // Used by operator[] to expand extent_gens 46 | extent_gen(const extent_gen& rhs, 47 | const range& a_range) 48 | { 49 | std::copy(rhs.ranges_.begin(),rhs.ranges_.end(),ranges_.begin()); 50 | *ranges_.rbegin() = a_range; 51 | } 52 | 53 | extent_gen 54 | operator[](const range& a_range) 55 | { 56 | return extent_gen(*this,a_range); 57 | } 58 | 59 | extent_gen 60 | operator[](index idx) 61 | { 62 | return extent_gen(*this,range(0,idx)); 63 | } 64 | 65 | static extent_gen<0> extents() { 66 | return extent_gen<0>(); 67 | } 68 | }; 69 | 70 | } // namespace multi_array 71 | } // namespace detail 72 | } // namespace boost 73 | 74 | 75 | #endif // BOOST_EXTENT_GEN_RG071801_HPP 76 | -------------------------------------------------------------------------------- /src/boost/multi_array/extent_range.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2002 The Trustees of Indiana University. 2 | 3 | // Use, modification and distribution is subject to the Boost Software 4 | // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 5 | // http://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // Boost.MultiArray Library 8 | // Authors: Ronald Garcia 9 | // Jeremy Siek 10 | // Andrew Lumsdaine 11 | // See http://www.boost.org/libs/multi_array for documentation. 12 | 13 | #ifndef BOOST_EXTENT_RANGE_RG071801_HPP 14 | #define BOOST_EXTENT_RANGE_RG071801_HPP 15 | 16 | #include 17 | 18 | namespace boost { 19 | namespace detail { 20 | namespace multi_array { 21 | 22 | template 23 | class extent_range : private std::pair { 24 | typedef std::pair super_type; 25 | public: 26 | typedef Extent index; 27 | typedef SizeType size_type; 28 | 29 | extent_range(index start, index finish) : 30 | super_type(start,finish) { } 31 | 32 | extent_range(index finish) : 33 | super_type(0,finish) { } 34 | 35 | extent_range() : super_type(0,0) { } 36 | 37 | index start() const { return super_type::first; } 38 | 39 | index finish() const { return super_type::second; } 40 | 41 | size_type size() const { return super_type::second - super_type::first; } 42 | }; 43 | 44 | } // namespace multi_array 45 | } // namespace detail 46 | } // namespace boost 47 | 48 | 49 | #endif // BOOST_EXTENT_RANGE_RG071801_HPP 50 | -------------------------------------------------------------------------------- /src/boost/multi_array/index_gen.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2002 The Trustees of Indiana University. 2 | 3 | // Use, modification and distribution is subject to the Boost Software 4 | // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 5 | // http://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // Boost.MultiArray Library 8 | // Authors: Ronald Garcia 9 | // Jeremy Siek 10 | // Andrew Lumsdaine 11 | // See http://www.boost.org/libs/multi_array for documentation. 12 | 13 | #ifndef BOOST_INDEX_GEN_RG071801_HPP 14 | #define BOOST_INDEX_GEN_RG071801_HPP 15 | 16 | #include "boost/array.hpp" 17 | #include "boost/multi_array/index_range.hpp" 18 | #include "boost/multi_array/range_list.hpp" 19 | #include "boost/multi_array/types.hpp" 20 | #include 21 | #include 22 | 23 | namespace boost { 24 | namespace detail { 25 | namespace multi_array { 26 | 27 | 28 | template 29 | struct index_gen { 30 | private: 31 | typedef ::boost::detail::multi_array::index index; 32 | typedef ::boost::detail::multi_array::size_type size_type; 33 | typedef index_range range; 34 | public: 35 | template 36 | struct gen_type { 37 | typedef index_gen type; 38 | }; 39 | 40 | typedef typename range_list_generator::type range_list; 41 | range_list ranges_; 42 | 43 | index_gen() { } 44 | 45 | template 46 | explicit index_gen(const index_gen& rhs, 47 | const range& r) 48 | { 49 | std::copy(rhs.ranges_.begin(),rhs.ranges_.end(),ranges_.begin()); 50 | *ranges_.rbegin() = r; 51 | } 52 | 53 | index_gen 54 | operator[](const range& r) const 55 | { 56 | index_gen tmp; 57 | std::copy(ranges_.begin(),ranges_.end(),tmp.ranges_.begin()); 58 | *tmp.ranges_.rbegin() = r; 59 | return tmp; 60 | } 61 | 62 | index_gen 63 | operator[](index idx) const 64 | { 65 | index_gen tmp; 66 | std::copy(ranges_.begin(),ranges_.end(),tmp.ranges_.begin()); 67 | *tmp.ranges_.rbegin() = range(idx); 68 | return tmp; 69 | } 70 | 71 | static index_gen<0,0> indices() { 72 | return index_gen<0,0>(); 73 | } 74 | }; 75 | 76 | } // namespace multi_array 77 | } // namespace detail 78 | } // namespace boost 79 | 80 | 81 | #endif // BOOST_INDEX_GEN_RG071801_HPP 82 | -------------------------------------------------------------------------------- /src/boost/multi_array/index_range.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2002 The Trustees of Indiana University. 2 | 3 | // Use, modification and distribution is subject to the Boost Software 4 | // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 5 | // http://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // Boost.MultiArray Library 8 | // Authors: Ronald Garcia 9 | // Jeremy Siek 10 | // Andrew Lumsdaine 11 | // See http://www.boost.org/libs/multi_array for documentation. 12 | 13 | #ifndef BOOST_INDEX_RANGE_RG071801_HPP 14 | #define BOOST_INDEX_RANGE_RG071801_HPP 15 | 16 | #include 17 | #include 18 | #include 19 | 20 | // For representing intervals, also with stride. 21 | // A degenerate range is a range with one element. 22 | 23 | // Thanks to Doug Gregor for the really cool idea of using the 24 | // comparison operators to express various interval types! 25 | 26 | // Internally, we represent the interval as half-open. 27 | 28 | namespace boost { 29 | namespace detail { 30 | namespace multi_array { 31 | 32 | template 33 | class index_range { 34 | public: 35 | typedef Index index; 36 | typedef SizeType size_type; 37 | 38 | private: 39 | static index from_start() 40 | { return (std::numeric_limits::min)(); } 41 | 42 | static index to_end() 43 | { return (std::numeric_limits::max)(); } 44 | 45 | public: 46 | 47 | index_range() 48 | { 49 | start_ = from_start(); 50 | finish_ = to_end(); 51 | stride_ = 1; 52 | degenerate_ = false; 53 | } 54 | 55 | explicit index_range(index pos) 56 | { 57 | start_ = pos; 58 | finish_ = pos+1; 59 | stride_ = 1; 60 | degenerate_ = true; 61 | } 62 | 63 | explicit index_range(index start, index finish, index stride=1) 64 | : start_(start), finish_(finish), stride_(stride), 65 | degenerate_(false) 66 | { } 67 | 68 | 69 | // These are for chaining assignments to an index_range 70 | index_range& start(index s) { 71 | start_ = s; 72 | degenerate_ = false; 73 | return *this; 74 | } 75 | 76 | index_range& finish(index f) { 77 | finish_ = f; 78 | degenerate_ = false; 79 | return *this; 80 | } 81 | 82 | index_range& stride(index s) { stride_ = s; return *this; } 83 | 84 | index start() const 85 | { 86 | return start_; 87 | } 88 | 89 | index get_start(index low_index_range = index_range::from_start()) const 90 | { 91 | if (start_ == from_start()) 92 | return low_index_range; 93 | return start_; 94 | } 95 | 96 | index finish() const 97 | { 98 | return finish_; 99 | } 100 | 101 | index get_finish(index high_index_range = index_range::to_end()) const 102 | { 103 | if (finish_ == to_end()) 104 | return high_index_range; 105 | return finish_; 106 | } 107 | 108 | index stride() const { return stride_; } 109 | 110 | void set_index_range(index start, index finish, index stride=1) 111 | { 112 | start_ = start; 113 | finish_ = finish; 114 | stride_ = stride; 115 | } 116 | 117 | static index_range all() 118 | { return index_range(from_start(), to_end(), 1); } 119 | 120 | bool is_degenerate() const { return degenerate_; } 121 | 122 | index_range operator-(index shift) const 123 | { 124 | return index_range(start_ - shift, finish_ - shift, stride_); 125 | } 126 | 127 | index_range operator+(index shift) const 128 | { 129 | return index_range(start_ + shift, finish_ + shift, stride_); 130 | } 131 | 132 | index operator[](unsigned i) const 133 | { 134 | return start_ + i * stride_; 135 | } 136 | 137 | index operator()(unsigned i) const 138 | { 139 | return start_ + i * stride_; 140 | } 141 | 142 | // add conversion to std::slice? 143 | 144 | public: 145 | index start_, finish_, stride_; 146 | bool degenerate_; 147 | }; 148 | 149 | // Express open and closed interval end-points using the comparison 150 | // operators. 151 | 152 | // left closed 153 | template 154 | inline index_range 155 | operator<=(Index s, const index_range& r) 156 | { 157 | return index_range(s, r.finish(), r.stride()); 158 | } 159 | 160 | // left open 161 | template 162 | inline index_range 163 | operator<(Index s, const index_range& r) 164 | { 165 | return index_range(s + 1, r.finish(), r.stride()); 166 | } 167 | 168 | // right open 169 | template 170 | inline index_range 171 | operator<(const index_range& r, Index f) 172 | { 173 | return index_range(r.start(), f, r.stride()); 174 | } 175 | 176 | // right closed 177 | template 178 | inline index_range 179 | operator<=(const index_range& r, Index f) 180 | { 181 | return index_range(r.start(), f + 1, r.stride()); 182 | } 183 | 184 | } // namespace multi_array 185 | } // namespace detail 186 | } // namespace boost 187 | 188 | #endif // BOOST_INDEX_RANGE_RG071801_HPP 189 | -------------------------------------------------------------------------------- /src/boost/multi_array/iterator.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2002 The Trustees of Indiana University. 2 | 3 | // Use, modification and distribution is subject to the Boost Software 4 | // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 5 | // http://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // Boost.MultiArray Library 8 | // Authors: Ronald Garcia 9 | // Jeremy Siek 10 | // Andrew Lumsdaine 11 | // See http://www.boost.org/libs/multi_array for documentation. 12 | 13 | #ifndef ITERATOR_RG071801_HPP 14 | #define ITERATOR_RG071801_HPP 15 | 16 | // 17 | // iterator.hpp - implementation of iterators for the 18 | // multi-dimensional array class 19 | // 20 | 21 | #include "boost/multi_array/base.hpp" 22 | #include "boost/iterator/iterator_facade.hpp" 23 | #include 24 | #include 25 | #include 26 | 27 | namespace boost { 28 | namespace detail { 29 | namespace multi_array { 30 | 31 | ///////////////////////////////////////////////////////////////////////// 32 | // iterator components 33 | ///////////////////////////////////////////////////////////////////////// 34 | 35 | template 36 | struct operator_arrow_proxy 37 | { 38 | operator_arrow_proxy(T const& px) : value_(px) {} 39 | T* operator->() const { return &value_; } 40 | // This function is needed for MWCW and BCC, which won't call operator-> 41 | // again automatically per 13.3.1.2 para 8 42 | operator T*() const { return &value_; } 43 | mutable T value_; 44 | }; 45 | 46 | template 48 | class array_iterator; 49 | 50 | template 52 | class array_iterator 53 | : public 54 | iterator_facade< 55 | array_iterator 56 | , typename associated_types::value_type 57 | , IteratorCategory 58 | , Reference 59 | > 60 | , private 61 | value_accessor_generator::type 62 | { 63 | friend class iterator_core_access; 64 | typedef detail::multi_array::associated_types access_t; 65 | 66 | typedef iterator_facade< 67 | array_iterator 68 | , typename detail::multi_array::associated_types::value_type 69 | , boost::random_access_traversal_tag 70 | , Reference 71 | > facade_type; 72 | 73 | typedef typename access_t::index index; 74 | typedef typename access_t::size_type size_type; 75 | 76 | #ifndef BOOST_NO_MEMBER_TEMPLATE_FRIENDS 77 | template 78 | friend class array_iterator; 79 | #else 80 | public: 81 | #endif 82 | 83 | index idx_; 84 | TPtr base_; 85 | const size_type* extents_; 86 | const index* strides_; 87 | const index* index_base_; 88 | 89 | public: 90 | // Typedefs to circumvent ambiguities between parent classes 91 | typedef typename facade_type::reference reference; 92 | typedef typename facade_type::value_type value_type; 93 | typedef typename facade_type::difference_type difference_type; 94 | 95 | array_iterator() {} 96 | 97 | array_iterator(index idx, TPtr base, const size_type* extents, 98 | const index* strides, 99 | const index* index_base) : 100 | idx_(idx), base_(base), extents_(extents), 101 | strides_(strides), index_base_(index_base) { } 102 | 103 | template 104 | array_iterator( 105 | const array_iterator& rhs 106 | , typename boost::enable_if_convertible::type* = 0 107 | ) 108 | : idx_(rhs.idx_), base_(rhs.base_), extents_(rhs.extents_), 109 | strides_(rhs.strides_), index_base_(rhs.index_base_) { } 110 | 111 | 112 | // RG - we make our own operator-> 113 | operator_arrow_proxy 114 | operator->() const 115 | { 116 | return operator_arrow_proxy(this->dereference()); 117 | } 118 | 119 | 120 | reference dereference() const 121 | { 122 | typedef typename value_accessor_generator::type accessor; 123 | return accessor::access(boost::type(), 124 | idx_, 125 | base_, 126 | extents_, 127 | strides_, 128 | index_base_); 129 | } 130 | 131 | void increment() { ++idx_; } 132 | void decrement() { --idx_; } 133 | 134 | template 135 | bool equal(IteratorAdaptor& rhs) const { 136 | const std::size_t N = NumDims::value; 137 | return (idx_ == rhs.idx_) && 138 | (base_ == rhs.base_) && 139 | ( (extents_ == rhs.extents_) || 140 | std::equal(extents_,extents_+N,rhs.extents_) ) && 141 | ( (strides_ == rhs.strides_) || 142 | std::equal(strides_,strides_+N,rhs.strides_) ) && 143 | ( (index_base_ == rhs.index_base_) || 144 | std::equal(index_base_,index_base_+N,rhs.index_base_) ); 145 | } 146 | 147 | template 148 | void advance(DifferenceType n) { 149 | idx_ += n; 150 | } 151 | 152 | template 153 | typename facade_type::difference_type 154 | distance_to(IteratorAdaptor& rhs) const { 155 | return rhs.idx_ - idx_; 156 | } 157 | 158 | 159 | }; 160 | 161 | } // namespace multi_array 162 | } // namespace detail 163 | } // namespace boost 164 | 165 | #endif // ITERATOR_RG071801_HPP 166 | -------------------------------------------------------------------------------- /src/boost/multi_array/range_list.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2002 The Trustees of Indiana University. 2 | 3 | // Use, modification and distribution is subject to the Boost Software 4 | // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 5 | // http://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // Boost.MultiArray Library 8 | // Authors: Ronald Garcia 9 | // Jeremy Siek 10 | // Andrew Lumsdaine 11 | // See http://www.boost.org/libs/multi_array for documentation. 12 | 13 | #ifndef RANGE_LIST_RG072501_HPP 14 | #define RANGE_LIST_RG072501_HPP 15 | // 16 | // range_list.hpp - helper to build boost::arrays for *_set types 17 | // 18 | 19 | #include "boost/array.hpp" 20 | 21 | namespace boost { 22 | namespace detail { 23 | namespace multi_array { 24 | 25 | ///////////////////////////////////////////////////////////////////////// 26 | // choose range list begins 27 | // 28 | 29 | struct choose_range_list_n { 30 | template 31 | struct bind { 32 | typedef boost::array type; 33 | }; 34 | }; 35 | 36 | struct choose_range_list_zero { 37 | template 38 | struct bind { 39 | typedef boost::array type; 40 | }; 41 | }; 42 | 43 | 44 | template 45 | struct range_list_gen_helper { 46 | typedef choose_range_list_n choice; 47 | }; 48 | 49 | template <> 50 | struct range_list_gen_helper<0> { 51 | typedef choose_range_list_zero choice; 52 | }; 53 | 54 | template 55 | struct range_list_generator { 56 | private: 57 | typedef typename range_list_gen_helper::choice Choice; 58 | public: 59 | typedef typename Choice::template bind::type type; 60 | }; 61 | 62 | // 63 | // choose range list ends 64 | ///////////////////////////////////////////////////////////////////////// 65 | 66 | } // namespace multi_array 67 | } // namespace detail 68 | } // namespace boost 69 | 70 | #endif // RANGE_LIST_RG072501_HPP 71 | -------------------------------------------------------------------------------- /src/boost/multi_array/storage_order.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2002 The Trustees of Indiana University. 2 | 3 | // Use, modification and distribution is subject to the Boost Software 4 | // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 5 | // http://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // Boost.MultiArray Library 8 | // Authors: Ronald Garcia 9 | // Jeremy Siek 10 | // Andrew Lumsdaine 11 | // See http://www.boost.org/libs/multi_array for documentation. 12 | 13 | #ifndef BOOST_STORAGE_ORDER_RG071801_HPP 14 | #define BOOST_STORAGE_ORDER_RG071801_HPP 15 | 16 | #include "boost/multi_array/types.hpp" 17 | #include "boost/array.hpp" 18 | #include "boost/multi_array/algorithm.hpp" 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | namespace boost { 26 | 27 | // RG - This is to make things work with VC++. So sad, so sad. 28 | class c_storage_order; 29 | class fortran_storage_order; 30 | 31 | template 32 | class general_storage_order 33 | { 34 | public: 35 | typedef detail::multi_array::size_type size_type; 36 | template 37 | general_storage_order(OrderingIter ordering, 38 | AscendingIter ascending) { 39 | boost::detail::multi_array::copy_n(ordering,NumDims,ordering_.begin()); 40 | boost::detail::multi_array::copy_n(ascending,NumDims,ascending_.begin()); 41 | } 42 | 43 | // RG - ideally these would not be necessary, but some compilers 44 | // don't like template conversion operators. I suspect that not 45 | // too many folk will feel the need to use customized 46 | // storage_order objects, I sacrifice that feature for compiler support. 47 | general_storage_order(const c_storage_order&) { 48 | for (size_type i=0; i != NumDims; ++i) { 49 | ordering_[i] = NumDims - 1 - i; 50 | } 51 | ascending_.assign(true); 52 | } 53 | 54 | general_storage_order(const fortran_storage_order&) { 55 | for (size_type i=0; i != NumDims; ++i) { 56 | ordering_[i] = i; 57 | } 58 | ascending_.assign(true); 59 | } 60 | 61 | size_type ordering(size_type dim) const { return ordering_[dim]; } 62 | bool ascending(size_type dim) const { return ascending_[dim]; } 63 | 64 | bool all_dims_ascending() const { 65 | return std::accumulate(ascending_.begin(),ascending_.end(),true, 66 | std::logical_and()); 67 | } 68 | 69 | bool operator==(general_storage_order const& rhs) const { 70 | return (ordering_ == rhs.ordering_) && 71 | (ascending_ == rhs.ascending_); 72 | } 73 | 74 | protected: 75 | boost::array ordering_; 76 | boost::array ascending_; 77 | }; 78 | 79 | class c_storage_order 80 | { 81 | typedef detail::multi_array::size_type size_type; 82 | public: 83 | // This is the idiom for creating your own custom storage orders. 84 | // Not supported by all compilers though! 85 | #ifndef __MWERKS__ // Metrowerks screams "ambiguity!" 86 | template 87 | operator general_storage_order() const { 88 | boost::array ordering; 89 | boost::array ascending; 90 | 91 | for (size_type i=0; i != NumDims; ++i) { 92 | ordering[i] = NumDims - 1 - i; 93 | ascending[i] = true; 94 | } 95 | return general_storage_order(ordering.begin(), 96 | ascending.begin()); 97 | } 98 | #endif 99 | }; 100 | 101 | class fortran_storage_order 102 | { 103 | typedef detail::multi_array::size_type size_type; 104 | public: 105 | // This is the idiom for creating your own custom storage orders. 106 | // Not supported by all compilers though! 107 | #ifndef __MWERKS__ // Metrowerks screams "ambiguity!" 108 | template 109 | operator general_storage_order() const { 110 | boost::array ordering; 111 | boost::array ascending; 112 | 113 | for (size_type i=0; i != NumDims; ++i) { 114 | ordering[i] = i; 115 | ascending[i] = true; 116 | } 117 | return general_storage_order(ordering.begin(), 118 | ascending.begin()); 119 | } 120 | #endif 121 | }; 122 | 123 | } // namespace boost 124 | 125 | #endif // BOOST_ARRAY_STORAGE_RG071801_HPP 126 | -------------------------------------------------------------------------------- /src/boost/multi_array/types.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2002 The Trustees of Indiana University. 2 | 3 | // Use, modification and distribution is subject to the Boost Software 4 | // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 5 | // http://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // Boost.MultiArray Library 8 | // Authors: Ronald Garcia 9 | // Jeremy Siek 10 | // Andrew Lumsdaine 11 | // See http://www.boost.org/libs/multi_array for documentation. 12 | 13 | 14 | #ifndef BOOST_MULTI_ARRAY_TYPES_RG071801_HPP 15 | #define BOOST_MULTI_ARRAY_TYPES_RG071801_HPP 16 | 17 | // 18 | // types.hpp - supply types that are needed by several headers 19 | // 20 | #include "boost/config.hpp" 21 | #include 22 | 23 | namespace boost { 24 | namespace detail { 25 | namespace multi_array{ 26 | 27 | // needed typedefs 28 | typedef std::size_t size_type; 29 | typedef std::ptrdiff_t index; 30 | 31 | } // namespace multi_array 32 | } // namespace detail 33 | } // namespace boost 34 | 35 | 36 | 37 | 38 | #endif // BOOST_MULTI_ARRAY_TYPES_RG071801_HPP 39 | -------------------------------------------------------------------------------- /src/tclap/ArgException.h: -------------------------------------------------------------------------------- 1 | // -*- Mode: c++; c-basic-offset: 4; tab-width: 4; -*- 2 | 3 | /****************************************************************************** 4 | * 5 | * file: ArgException.h 6 | * 7 | * Copyright (c) 2003, Michael E. Smoot . 8 | * All rights reverved. 9 | * 10 | * See the file COPYING in the top directory of this distribution for 11 | * more information. 12 | * 13 | * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS 14 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 16 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 19 | * DEALINGS IN THE SOFTWARE. 20 | * 21 | *****************************************************************************/ 22 | 23 | 24 | #ifndef TCLAP_ARG_EXCEPTION_H 25 | #define TCLAP_ARG_EXCEPTION_H 26 | 27 | #include 28 | #include 29 | 30 | namespace TCLAP { 31 | 32 | /** 33 | * A simple class that defines and argument exception. Should be caught 34 | * whenever a CmdLine is created and parsed. 35 | */ 36 | class ArgException : public std::exception 37 | { 38 | public: 39 | 40 | /** 41 | * Constructor. 42 | * \param text - The text of the exception. 43 | * \param id - The text identifying the argument source. 44 | * \param td - Text describing the type of ArgException it is. 45 | * of the exception. 46 | */ 47 | ArgException( const std::string& text = "undefined exception", 48 | const std::string& id = "undefined", 49 | const std::string& td = "Generic ArgException") 50 | : std::exception(), 51 | _errorText(text), 52 | _argId( id ), 53 | _typeDescription(td) 54 | { } 55 | 56 | /** 57 | * Destructor. 58 | */ 59 | virtual ~ArgException() throw() { } 60 | 61 | /** 62 | * Returns the error text. 63 | */ 64 | std::string error() const { return ( _errorText ); } 65 | 66 | /** 67 | * Returns the argument id. 68 | */ 69 | std::string argId() const 70 | { 71 | if ( _argId == "undefined" ) 72 | return " "; 73 | else 74 | return ( "Argument: " + _argId ); 75 | } 76 | 77 | /** 78 | * Returns the arg id and error text. 79 | */ 80 | const char* what() const throw() 81 | { 82 | static std::string ex; 83 | ex = _argId + " -- " + _errorText; 84 | return ex.c_str(); 85 | } 86 | 87 | /** 88 | * Returns the type of the exception. Used to explain and distinguish 89 | * between different child exceptions. 90 | */ 91 | std::string typeDescription() const 92 | { 93 | return _typeDescription; 94 | } 95 | 96 | 97 | private: 98 | 99 | /** 100 | * The text of the exception message. 101 | */ 102 | std::string _errorText; 103 | 104 | /** 105 | * The argument related to this exception. 106 | */ 107 | std::string _argId; 108 | 109 | /** 110 | * Describes the type of the exception. Used to distinguish 111 | * between different child exceptions. 112 | */ 113 | std::string _typeDescription; 114 | 115 | }; 116 | 117 | /** 118 | * Thrown from within the child Arg classes when it fails to properly 119 | * parse the argument it has been passed. 120 | */ 121 | class ArgParseException : public ArgException 122 | { 123 | public: 124 | /** 125 | * Constructor. 126 | * \param text - The text of the exception. 127 | * \param id - The text identifying the argument source 128 | * of the exception. 129 | */ 130 | ArgParseException( const std::string& text = "undefined exception", 131 | const std::string& id = "undefined" ) 132 | : ArgException( text, 133 | id, 134 | std::string( "Exception found while parsing " ) + 135 | std::string( "the value the Arg has been passed." )) 136 | { } 137 | }; 138 | 139 | /** 140 | * Thrown from CmdLine when the arguments on the command line are not 141 | * properly specified, e.g. too many arguments, required argument missing, etc. 142 | */ 143 | class CmdLineParseException : public ArgException 144 | { 145 | public: 146 | /** 147 | * Constructor. 148 | * \param text - The text of the exception. 149 | * \param id - The text identifying the argument source 150 | * of the exception. 151 | */ 152 | CmdLineParseException( const std::string& text = "undefined exception", 153 | const std::string& id = "undefined" ) 154 | : ArgException( text, 155 | id, 156 | std::string( "Exception found when the values ") + 157 | std::string( "on the command line do not meet ") + 158 | std::string( "the requirements of the defined ") + 159 | std::string( "Args." )) 160 | { } 161 | }; 162 | 163 | /** 164 | * Thrown from Arg and CmdLine when an Arg is improperly specified, e.g. 165 | * same flag as another Arg, same name, etc. 166 | */ 167 | class SpecificationException : public ArgException 168 | { 169 | public: 170 | /** 171 | * Constructor. 172 | * \param text - The text of the exception. 173 | * \param id - The text identifying the argument source 174 | * of the exception. 175 | */ 176 | SpecificationException( const std::string& text = "undefined exception", 177 | const std::string& id = "undefined" ) 178 | : ArgException( text, 179 | id, 180 | std::string("Exception found when an Arg object ")+ 181 | std::string("is improperly defined by the ") + 182 | std::string("developer." )) 183 | { } 184 | 185 | }; 186 | 187 | class ExitException { 188 | public: 189 | ExitException(int estat) : _estat(estat) {} 190 | 191 | int getExitStatus() const { return _estat; } 192 | 193 | private: 194 | int _estat; 195 | }; 196 | 197 | } // namespace TCLAP 198 | 199 | #endif 200 | 201 | -------------------------------------------------------------------------------- /src/tclap/ArgTraits.h: -------------------------------------------------------------------------------- 1 | // -*- Mode: c++; c-basic-offset: 4; tab-width: 4; -*- 2 | 3 | /****************************************************************************** 4 | * 5 | * file: ArgTraits.h 6 | * 7 | * Copyright (c) 2007, Daniel Aarno, Michael E. Smoot . 8 | * All rights reverved. 9 | * 10 | * See the file COPYING in the top directory of this distribution for 11 | * more information. 12 | * 13 | * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS 14 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 16 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 19 | * DEALINGS IN THE SOFTWARE. 20 | * 21 | *****************************************************************************/ 22 | 23 | // This is an internal tclap file, you should probably not have to 24 | // include this directly 25 | 26 | #ifndef TCLAP_ARGTRAITS_H 27 | #define TCLAP_ARGTRAITS_H 28 | 29 | namespace TCLAP { 30 | 31 | // We use two empty structs to get compile type specialization 32 | // function to work 33 | 34 | /** 35 | * A value like argument value type is a value that can be set using 36 | * operator>>. This is the default value type. 37 | */ 38 | struct ValueLike { 39 | typedef ValueLike ValueCategory; 40 | virtual ~ValueLike() {} 41 | }; 42 | 43 | /** 44 | * A string like argument value type is a value that can be set using 45 | * operator=(string). Usefull if the value type contains spaces which 46 | * will be broken up into individual tokens by operator>>. 47 | */ 48 | struct StringLike { 49 | virtual ~StringLike() {} 50 | }; 51 | 52 | /** 53 | * A class can inherit from this object to make it have string like 54 | * traits. This is a compile time thing and does not add any overhead 55 | * to the inherenting class. 56 | */ 57 | struct StringLikeTrait { 58 | typedef StringLike ValueCategory; 59 | virtual ~StringLikeTrait() {} 60 | }; 61 | 62 | /** 63 | * A class can inherit from this object to make it have value like 64 | * traits. This is a compile time thing and does not add any overhead 65 | * to the inherenting class. 66 | */ 67 | struct ValueLikeTrait { 68 | typedef ValueLike ValueCategory; 69 | virtual ~ValueLikeTrait() {} 70 | }; 71 | 72 | /** 73 | * Arg traits are used to get compile type specialization when parsing 74 | * argument values. Using an ArgTraits you can specify the way that 75 | * values gets assigned to any particular type during parsing. The two 76 | * supported types are StringLike and ValueLike. 77 | */ 78 | template 79 | struct ArgTraits { 80 | typedef typename T::ValueCategory ValueCategory; 81 | virtual ~ArgTraits() {} 82 | //typedef ValueLike ValueCategory; 83 | }; 84 | 85 | #endif 86 | 87 | } // namespace 88 | -------------------------------------------------------------------------------- /src/tclap/COPYING: -------------------------------------------------------------------------------- 1 | Copyright (c) 2003 Michael E. Smoot 2 | 3 | Permission is hereby granted, free of charge, to any person 4 | obtaining a copy of this software and associated documentation 5 | files (the "Software"), to deal in the Software without restriction, 6 | including without limitation the rights to use, copy, modify, merge, 7 | publish, distribute, sublicense, and/or sell copies of the Software, 8 | and to permit persons to whom the Software is furnished to do so, 9 | subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be 12 | included in all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 16 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 18 | BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 19 | AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR 20 | IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | 23 | 24 | -------------------------------------------------------------------------------- /src/tclap/CmdLineInterface.h: -------------------------------------------------------------------------------- 1 | 2 | /****************************************************************************** 3 | * 4 | * file: CmdLineInterface.h 5 | * 6 | * Copyright (c) 2003, Michael E. Smoot . 7 | * Copyright (c) 2004, Michael E. Smoot, Daniel Aarno. 8 | * All rights reverved. 9 | * 10 | * See the file COPYING in the top directory of this distribution for 11 | * more information. 12 | * 13 | * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS 14 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 16 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 19 | * DEALINGS IN THE SOFTWARE. 20 | * 21 | *****************************************************************************/ 22 | 23 | #ifndef TCLAP_COMMANDLINE_INTERFACE_H 24 | #define TCLAP_COMMANDLINE_INTERFACE_H 25 | 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | 32 | 33 | namespace TCLAP { 34 | 35 | class Arg; 36 | class CmdLineOutput; 37 | class XorHandler; 38 | 39 | /** 40 | * The base class that manages the command line definition and passes 41 | * along the parsing to the appropriate Arg classes. 42 | */ 43 | class CmdLineInterface 44 | { 45 | public: 46 | 47 | /** 48 | * Destructor 49 | */ 50 | virtual ~CmdLineInterface() {} 51 | 52 | /** 53 | * Adds an argument to the list of arguments to be parsed. 54 | * \param a - Argument to be added. 55 | */ 56 | virtual void add( Arg& a )=0; 57 | 58 | /** 59 | * An alternative add. Functionally identical. 60 | * \param a - Argument to be added. 61 | */ 62 | virtual void add( Arg* a )=0; 63 | 64 | /** 65 | * Add two Args that will be xor'd. 66 | * If this method is used, add does 67 | * not need to be called. 68 | * \param a - Argument to be added and xor'd. 69 | * \param b - Argument to be added and xor'd. 70 | */ 71 | virtual void xorAdd( Arg& a, Arg& b )=0; 72 | 73 | /** 74 | * Add a list of Args that will be xor'd. If this method is used, 75 | * add does not need to be called. 76 | * \param xors - List of Args to be added and xor'd. 77 | */ 78 | virtual void xorAdd( std::vector& xors )=0; 79 | 80 | /** 81 | * Parses the command line. 82 | * \param argc - Number of arguments. 83 | * \param argv - Array of arguments. 84 | */ 85 | virtual void parse(int argc, const char * const * argv)=0; 86 | 87 | /** 88 | * Parses the command line. 89 | * \param args - A vector of strings representing the args. 90 | * args[0] is still the program name. 91 | */ 92 | void parse(std::vector& args); 93 | 94 | /** 95 | * Returns the CmdLineOutput object. 96 | */ 97 | virtual CmdLineOutput* getOutput()=0; 98 | 99 | /** 100 | * \param co - CmdLineOutput object that we want to use instead. 101 | */ 102 | virtual void setOutput(CmdLineOutput* co)=0; 103 | 104 | /** 105 | * Returns the version string. 106 | */ 107 | virtual std::string& getVersion()=0; 108 | 109 | /** 110 | * Returns the program name string. 111 | */ 112 | virtual std::string& getProgramName()=0; 113 | 114 | /** 115 | * Returns the argList. 116 | */ 117 | virtual std::list& getArgList()=0; 118 | 119 | /** 120 | * Returns the XorHandler. 121 | */ 122 | virtual XorHandler& getXorHandler()=0; 123 | 124 | /** 125 | * Returns the delimiter string. 126 | */ 127 | virtual char getDelimiter()=0; 128 | 129 | /** 130 | * Returns the message string. 131 | */ 132 | virtual std::string& getMessage()=0; 133 | 134 | /** 135 | * Indicates whether or not the help and version switches were created 136 | * automatically. 137 | */ 138 | virtual bool hasHelpAndVersion()=0; 139 | 140 | /** 141 | * Resets the instance as if it had just been constructed so that the 142 | * instance can be reused. 143 | */ 144 | virtual void reset()=0; 145 | }; 146 | 147 | } //namespace 148 | 149 | 150 | #endif 151 | -------------------------------------------------------------------------------- /src/tclap/CmdLineOutput.h: -------------------------------------------------------------------------------- 1 | 2 | 3 | /****************************************************************************** 4 | * 5 | * file: CmdLineOutput.h 6 | * 7 | * Copyright (c) 2004, Michael E. Smoot 8 | * All rights reverved. 9 | * 10 | * See the file COPYING in the top directory of this distribution for 11 | * more information. 12 | * 13 | * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS 14 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 16 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 19 | * DEALINGS IN THE SOFTWARE. 20 | * 21 | *****************************************************************************/ 22 | 23 | #ifndef TCLAP_CMDLINEOUTPUT_H 24 | #define TCLAP_CMDLINEOUTPUT_H 25 | 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | 33 | namespace TCLAP { 34 | 35 | class CmdLineInterface; 36 | class ArgException; 37 | 38 | /** 39 | * The interface that any output object must implement. 40 | */ 41 | class CmdLineOutput 42 | { 43 | 44 | public: 45 | 46 | /** 47 | * Virtual destructor. 48 | */ 49 | virtual ~CmdLineOutput() {} 50 | 51 | /** 52 | * Generates some sort of output for the USAGE. 53 | * \param c - The CmdLine object the output is generated for. 54 | */ 55 | virtual void usage(CmdLineInterface& c)=0; 56 | 57 | /** 58 | * Generates some sort of output for the version. 59 | * \param c - The CmdLine object the output is generated for. 60 | */ 61 | virtual void version(CmdLineInterface& c)=0; 62 | 63 | /** 64 | * Generates some sort of output for a failure. 65 | * \param c - The CmdLine object the output is generated for. 66 | * \param e - The ArgException that caused the failure. 67 | */ 68 | virtual void failure( CmdLineInterface& c, 69 | ArgException& e )=0; 70 | 71 | }; 72 | 73 | } //namespace TCLAP 74 | #endif 75 | -------------------------------------------------------------------------------- /src/tclap/Constraint.h: -------------------------------------------------------------------------------- 1 | 2 | /****************************************************************************** 3 | * 4 | * file: Constraint.h 5 | * 6 | * Copyright (c) 2005, Michael E. Smoot 7 | * All rights reverved. 8 | * 9 | * See the file COPYING in the top directory of this distribution for 10 | * more information. 11 | * 12 | * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS 13 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 14 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 15 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 16 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 17 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 18 | * DEALINGS IN THE SOFTWARE. 19 | * 20 | *****************************************************************************/ 21 | 22 | #ifndef TCLAP_CONSTRAINT_H 23 | #define TCLAP_CONSTRAINT_H 24 | 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | 32 | namespace TCLAP { 33 | 34 | /** 35 | * The interface that defines the interaction between the Arg and Constraint. 36 | */ 37 | template 38 | class Constraint 39 | { 40 | 41 | public: 42 | /** 43 | * Returns a description of the Constraint. 44 | */ 45 | virtual std::string description() const =0; 46 | 47 | /** 48 | * Returns the short ID for the Constraint. 49 | */ 50 | virtual std::string shortID() const =0; 51 | 52 | /** 53 | * The method used to verify that the value parsed from the command 54 | * line meets the constraint. 55 | * \param value - The value that will be checked. 56 | */ 57 | virtual bool check(const T& value) const =0; 58 | 59 | /** 60 | * Destructor. 61 | * Silences warnings about Constraint being a base class with virtual 62 | * functions but without a virtual destructor. 63 | */ 64 | virtual ~Constraint() { ; } 65 | }; 66 | 67 | } //namespace TCLAP 68 | #endif 69 | -------------------------------------------------------------------------------- /src/tclap/HelpVisitor.h: -------------------------------------------------------------------------------- 1 | 2 | /****************************************************************************** 3 | * 4 | * file: HelpVisitor.h 5 | * 6 | * Copyright (c) 2003, Michael E. Smoot . 7 | * All rights reverved. 8 | * 9 | * See the file COPYING in the top directory of this distribution for 10 | * more information. 11 | * 12 | * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS 13 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 14 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 15 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 16 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 17 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 18 | * DEALINGS IN THE SOFTWARE. 19 | * 20 | *****************************************************************************/ 21 | 22 | #ifndef TCLAP_HELP_VISITOR_H 23 | #define TCLAP_HELP_VISITOR_H 24 | 25 | #include 26 | #include 27 | #include 28 | 29 | namespace TCLAP { 30 | 31 | /** 32 | * A Visitor object that calls the usage method of the given CmdLineOutput 33 | * object for the specified CmdLine object. 34 | */ 35 | class HelpVisitor: public Visitor 36 | { 37 | private: 38 | /** 39 | * Prevent accidental copying. 40 | */ 41 | HelpVisitor(const HelpVisitor& rhs); 42 | HelpVisitor& operator=(const HelpVisitor& rhs); 43 | 44 | protected: 45 | 46 | /** 47 | * The CmdLine the output will be generated for. 48 | */ 49 | CmdLineInterface* _cmd; 50 | 51 | /** 52 | * The output object. 53 | */ 54 | CmdLineOutput** _out; 55 | 56 | public: 57 | 58 | /** 59 | * Constructor. 60 | * \param cmd - The CmdLine the output will be generated for. 61 | * \param out - The type of output. 62 | */ 63 | HelpVisitor(CmdLineInterface* cmd, CmdLineOutput** out) 64 | : Visitor(), _cmd( cmd ), _out( out ) { } 65 | 66 | /** 67 | * Calls the usage method of the CmdLineOutput for the 68 | * specified CmdLine. 69 | */ 70 | void visit() { (*_out)->usage(*_cmd); throw ExitException(0); } 71 | 72 | }; 73 | 74 | } 75 | 76 | #endif 77 | -------------------------------------------------------------------------------- /src/tclap/IgnoreRestVisitor.h: -------------------------------------------------------------------------------- 1 | 2 | /****************************************************************************** 3 | * 4 | * file: IgnoreRestVisitor.h 5 | * 6 | * Copyright (c) 2003, Michael E. Smoot . 7 | * All rights reverved. 8 | * 9 | * See the file COPYING in the top directory of this distribution for 10 | * more information. 11 | * 12 | * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS 13 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 14 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 15 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 16 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 17 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 18 | * DEALINGS IN THE SOFTWARE. 19 | * 20 | *****************************************************************************/ 21 | 22 | 23 | #ifndef TCLAP_IGNORE_REST_VISITOR_H 24 | #define TCLAP_IGNORE_REST_VISITOR_H 25 | 26 | #include 27 | #include 28 | 29 | namespace TCLAP { 30 | 31 | /** 32 | * A Vistor that tells the CmdLine to begin ignoring arguments after 33 | * this one is parsed. 34 | */ 35 | class IgnoreRestVisitor: public Visitor 36 | { 37 | public: 38 | 39 | /** 40 | * Constructor. 41 | */ 42 | IgnoreRestVisitor() : Visitor() {} 43 | 44 | /** 45 | * Sets Arg::_ignoreRest. 46 | */ 47 | void visit() { Arg::beginIgnoring(); } 48 | }; 49 | 50 | } 51 | 52 | #endif 53 | -------------------------------------------------------------------------------- /src/tclap/Makefile.am: -------------------------------------------------------------------------------- 1 | EXTRA_DIST = \ 2 | COPYING 3 | 4 | noinst_HEADERS = \ 5 | ArgException.h \ 6 | ArgTraits.h \ 7 | CmdLineInterface.h \ 8 | Constraint.h \ 9 | DocBookOutput.h \ 10 | IgnoreRestVisitor.h \ 11 | MultiSwitchArg.h \ 12 | StandardTraits.h \ 13 | SwitchArg.h \ 14 | UnlabeledValueArg.h \ 15 | ValuesConstraint.h \ 16 | Visitor.h \ 17 | ZshCompletionOutput.h \ 18 | Arg.h \ 19 | CmdLine.h \ 20 | CmdLineOutput.h \ 21 | HelpVisitor.h \ 22 | MultiArg.h \ 23 | OptionalUnlabeledTracker.h \ 24 | StdOutput.h \ 25 | UnlabeledMultiArg.h \ 26 | ValueArg.h \ 27 | VersionVisitor.h \ 28 | XorHandler.h 29 | -------------------------------------------------------------------------------- /src/tclap/MultiSwitchArg.h: -------------------------------------------------------------------------------- 1 | 2 | /****************************************************************************** 3 | * 4 | * file: MultiSwitchArg.h 5 | * 6 | * Copyright (c) 2003, Michael E. Smoot . 7 | * Copyright (c) 2004, Michael E. Smoot, Daniel Aarno. 8 | * Copyright (c) 2005, Michael E. Smoot, Daniel Aarno, Erik Zeek. 9 | * All rights reverved. 10 | * 11 | * See the file COPYING in the top directory of this distribution for 12 | * more information. 13 | * 14 | * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS 15 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | * 22 | *****************************************************************************/ 23 | 24 | 25 | #ifndef TCLAP_MULTI_SWITCH_ARG_H 26 | #define TCLAP_MULTI_SWITCH_ARG_H 27 | 28 | #include 29 | #include 30 | 31 | #include 32 | 33 | namespace TCLAP { 34 | 35 | /** 36 | * A multiple switch argument. If the switch is set on the command line, then 37 | * the getValue method will return the number of times the switch appears. 38 | */ 39 | class MultiSwitchArg : public SwitchArg 40 | { 41 | protected: 42 | 43 | /** 44 | * The value of the switch. 45 | */ 46 | int _value; 47 | 48 | /** 49 | * Used to support the reset() method so that ValueArg can be 50 | * reset to their constructed value. 51 | */ 52 | int _default; 53 | 54 | public: 55 | 56 | /** 57 | * MultiSwitchArg constructor. 58 | * \param flag - The one character flag that identifies this 59 | * argument on the command line. 60 | * \param name - A one word name for the argument. Can be 61 | * used as a long flag on the command line. 62 | * \param desc - A description of what the argument is for or 63 | * does. 64 | * \param init - Optional. The initial/default value of this Arg. 65 | * Defaults to 0. 66 | * \param v - An optional visitor. You probably should not 67 | * use this unless you have a very good reason. 68 | */ 69 | MultiSwitchArg(const std::string& flag, 70 | const std::string& name, 71 | const std::string& desc, 72 | int init = 0, 73 | Visitor* v = NULL); 74 | 75 | 76 | /** 77 | * MultiSwitchArg constructor. 78 | * \param flag - The one character flag that identifies this 79 | * argument on the command line. 80 | * \param name - A one word name for the argument. Can be 81 | * used as a long flag on the command line. 82 | * \param desc - A description of what the argument is for or 83 | * does. 84 | * \param parser - A CmdLine parser object to add this Arg to 85 | * \param init - Optional. The initial/default value of this Arg. 86 | * Defaults to 0. 87 | * \param v - An optional visitor. You probably should not 88 | * use this unless you have a very good reason. 89 | */ 90 | MultiSwitchArg(const std::string& flag, 91 | const std::string& name, 92 | const std::string& desc, 93 | CmdLineInterface& parser, 94 | int init = 0, 95 | Visitor* v = NULL); 96 | 97 | 98 | /** 99 | * Handles the processing of the argument. 100 | * This re-implements the SwitchArg version of this method to set the 101 | * _value of the argument appropriately. 102 | * \param i - Pointer the the current argument in the list. 103 | * \param args - Mutable list of strings. Passed 104 | * in from main(). 105 | */ 106 | virtual bool processArg(int* i, std::vector& args); 107 | 108 | /** 109 | * Returns int, the number of times the switch has been set. 110 | */ 111 | int getValue(); 112 | 113 | /** 114 | * Returns the shortID for this Arg. 115 | */ 116 | std::string shortID(const std::string& val) const; 117 | 118 | /** 119 | * Returns the longID for this Arg. 120 | */ 121 | std::string longID(const std::string& val) const; 122 | 123 | void reset(); 124 | 125 | }; 126 | 127 | ////////////////////////////////////////////////////////////////////// 128 | //BEGIN MultiSwitchArg.cpp 129 | ////////////////////////////////////////////////////////////////////// 130 | inline MultiSwitchArg::MultiSwitchArg(const std::string& flag, 131 | const std::string& name, 132 | const std::string& desc, 133 | int init, 134 | Visitor* v ) 135 | : SwitchArg(flag, name, desc, false, v), 136 | _value( init ), 137 | _default( init ) 138 | { } 139 | 140 | inline MultiSwitchArg::MultiSwitchArg(const std::string& flag, 141 | const std::string& name, 142 | const std::string& desc, 143 | CmdLineInterface& parser, 144 | int init, 145 | Visitor* v ) 146 | : SwitchArg(flag, name, desc, false, v), 147 | _value( init ), 148 | _default( init ) 149 | { 150 | parser.add( this ); 151 | } 152 | 153 | inline int MultiSwitchArg::getValue() { return _value; } 154 | 155 | inline bool MultiSwitchArg::processArg(int *i, std::vector& args) 156 | { 157 | if ( _ignoreable && Arg::ignoreRest() ) 158 | return false; 159 | 160 | if ( argMatches( args[*i] )) 161 | { 162 | // so the isSet() method will work 163 | _alreadySet = true; 164 | 165 | // Matched argument: increment value. 166 | ++_value; 167 | 168 | _checkWithVisitor(); 169 | 170 | return true; 171 | } 172 | else if ( combinedSwitchesMatch( args[*i] ) ) 173 | { 174 | // so the isSet() method will work 175 | _alreadySet = true; 176 | 177 | // Matched argument: increment value. 178 | ++_value; 179 | 180 | // Check for more in argument and increment value. 181 | while ( combinedSwitchesMatch( args[*i] ) ) 182 | ++_value; 183 | 184 | _checkWithVisitor(); 185 | 186 | return false; 187 | } 188 | else 189 | return false; 190 | } 191 | 192 | inline std::string 193 | MultiSwitchArg::shortID(const std::string& val) const 194 | { 195 | return Arg::shortID(val) + " ... "; 196 | } 197 | 198 | inline std::string 199 | MultiSwitchArg::longID(const std::string& val) const 200 | { 201 | return Arg::longID(val) + " (accepted multiple times)"; 202 | } 203 | 204 | inline void 205 | MultiSwitchArg::reset() 206 | { 207 | MultiSwitchArg::_value = MultiSwitchArg::_default; 208 | } 209 | 210 | ////////////////////////////////////////////////////////////////////// 211 | //END MultiSwitchArg.cpp 212 | ////////////////////////////////////////////////////////////////////// 213 | 214 | } //namespace TCLAP 215 | 216 | #endif 217 | -------------------------------------------------------------------------------- /src/tclap/OptionalUnlabeledTracker.h: -------------------------------------------------------------------------------- 1 | 2 | 3 | /****************************************************************************** 4 | * 5 | * file: OptionalUnlabeledTracker.h 6 | * 7 | * Copyright (c) 2005, Michael E. Smoot . 8 | * All rights reverved. 9 | * 10 | * See the file COPYING in the top directory of this distribution for 11 | * more information. 12 | * 13 | * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS 14 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 16 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 19 | * DEALINGS IN THE SOFTWARE. 20 | * 21 | *****************************************************************************/ 22 | 23 | 24 | #ifndef TCLAP_OPTIONAL_UNLABELED_TRACKER_H 25 | #define TCLAP_OPTIONAL_UNLABELED_TRACKER_H 26 | 27 | #include 28 | 29 | namespace TCLAP { 30 | 31 | class OptionalUnlabeledTracker 32 | { 33 | 34 | public: 35 | 36 | static void check( bool req, const std::string& argName ); 37 | 38 | static void gotOptional() { alreadyOptionalRef() = true; } 39 | 40 | static bool& alreadyOptional() { return alreadyOptionalRef(); } 41 | 42 | private: 43 | 44 | static bool& alreadyOptionalRef() { static bool ct = false; return ct; } 45 | }; 46 | 47 | 48 | inline void OptionalUnlabeledTracker::check( bool req, const std::string& argName ) 49 | { 50 | if ( OptionalUnlabeledTracker::alreadyOptional() ) 51 | throw( SpecificationException( 52 | "You can't specify ANY Unlabeled Arg following an optional Unlabeled Arg", 53 | argName ) ); 54 | 55 | if ( !req ) 56 | OptionalUnlabeledTracker::gotOptional(); 57 | } 58 | 59 | 60 | } // namespace TCLAP 61 | 62 | #endif 63 | -------------------------------------------------------------------------------- /src/tclap/StandardTraits.h: -------------------------------------------------------------------------------- 1 | // -*- Mode: c++; c-basic-offset: 4; tab-width: 4; -*- 2 | 3 | /****************************************************************************** 4 | * 5 | * file: StandardTraits.h 6 | * 7 | * Copyright (c) 2007, Daniel Aarno, Michael E. Smoot . 8 | * All rights reverved. 9 | * 10 | * See the file COPYING in the top directory of this distribution for 11 | * more information. 12 | * 13 | * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS 14 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 16 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 19 | * DEALINGS IN THE SOFTWARE. 20 | * 21 | *****************************************************************************/ 22 | 23 | // This is an internal tclap file, you should probably not have to 24 | // include this directly 25 | 26 | #ifndef TCLAP_STANDARD_TRAITS_H 27 | #define TCLAP_STANDARD_TRAITS_H 28 | 29 | #ifdef HAVE_CONFIG_H 30 | #include // To check for long long 31 | #endif 32 | 33 | // If Microsoft has already typedef'd wchar_t as an unsigned 34 | // short, then compiles will break because it's as if we're 35 | // creating ArgTraits twice for unsigned short. Thus... 36 | #ifdef _MSC_VER 37 | #ifndef _NATIVE_WCHAR_T_DEFINED 38 | #define TCLAP_DONT_DECLARE_WCHAR_T_ARGTRAITS 39 | #endif 40 | #endif 41 | 42 | namespace TCLAP { 43 | 44 | // ====================================================================== 45 | // Integer types 46 | // ====================================================================== 47 | 48 | /** 49 | * longs have value-like semantics. 50 | */ 51 | template<> 52 | struct ArgTraits { 53 | typedef ValueLike ValueCategory; 54 | }; 55 | 56 | /** 57 | * ints have value-like semantics. 58 | */ 59 | template<> 60 | struct ArgTraits { 61 | typedef ValueLike ValueCategory; 62 | }; 63 | 64 | /** 65 | * shorts have value-like semantics. 66 | */ 67 | template<> 68 | struct ArgTraits { 69 | typedef ValueLike ValueCategory; 70 | }; 71 | 72 | /** 73 | * chars have value-like semantics. 74 | */ 75 | template<> 76 | struct ArgTraits { 77 | typedef ValueLike ValueCategory; 78 | }; 79 | 80 | #ifdef HAVE_LONG_LONG 81 | /** 82 | * long longs have value-like semantics. 83 | */ 84 | template<> 85 | struct ArgTraits { 86 | typedef ValueLike ValueCategory; 87 | }; 88 | #endif 89 | 90 | // ====================================================================== 91 | // Unsigned integer types 92 | // ====================================================================== 93 | 94 | /** 95 | * unsigned longs have value-like semantics. 96 | */ 97 | template<> 98 | struct ArgTraits { 99 | typedef ValueLike ValueCategory; 100 | }; 101 | 102 | /** 103 | * unsigned ints have value-like semantics. 104 | */ 105 | template<> 106 | struct ArgTraits { 107 | typedef ValueLike ValueCategory; 108 | }; 109 | 110 | /** 111 | * unsigned shorts have value-like semantics. 112 | */ 113 | template<> 114 | struct ArgTraits { 115 | typedef ValueLike ValueCategory; 116 | }; 117 | 118 | /** 119 | * unsigned chars have value-like semantics. 120 | */ 121 | template<> 122 | struct ArgTraits { 123 | typedef ValueLike ValueCategory; 124 | }; 125 | 126 | // Microsoft implements size_t awkwardly. 127 | #if defined(_MSC_VER) && defined(_M_X64) 128 | /** 129 | * size_ts have value-like semantics. 130 | */ 131 | template<> 132 | struct ArgTraits { 133 | typedef ValueLike ValueCategory; 134 | }; 135 | #endif 136 | 137 | 138 | #ifdef HAVE_LONG_LONG 139 | /** 140 | * unsigned long longs have value-like semantics. 141 | */ 142 | template<> 143 | struct ArgTraits { 144 | typedef ValueLike ValueCategory; 145 | }; 146 | #endif 147 | 148 | // ====================================================================== 149 | // Float types 150 | // ====================================================================== 151 | 152 | /** 153 | * floats have value-like semantics. 154 | */ 155 | template<> 156 | struct ArgTraits { 157 | typedef ValueLike ValueCategory; 158 | }; 159 | 160 | /** 161 | * doubles have value-like semantics. 162 | */ 163 | template<> 164 | struct ArgTraits { 165 | typedef ValueLike ValueCategory; 166 | }; 167 | 168 | // ====================================================================== 169 | // Other types 170 | // ====================================================================== 171 | 172 | /** 173 | * bools have value-like semantics. 174 | */ 175 | template<> 176 | struct ArgTraits { 177 | typedef ValueLike ValueCategory; 178 | }; 179 | 180 | 181 | /** 182 | * wchar_ts have value-like semantics. 183 | */ 184 | #ifndef TCLAP_DONT_DECLARE_WCHAR_T_ARGTRAITS 185 | template<> 186 | struct ArgTraits { 187 | typedef ValueLike ValueCategory; 188 | }; 189 | #endif 190 | 191 | /** 192 | * Strings have string like argument traits. 193 | */ 194 | template<> 195 | struct ArgTraits { 196 | typedef StringLike ValueCategory; 197 | }; 198 | 199 | template 200 | void SetString(T &dst, const std::string &src) 201 | { 202 | dst = src; 203 | } 204 | 205 | } // namespace 206 | 207 | #endif 208 | 209 | -------------------------------------------------------------------------------- /src/tclap/SwitchArg.h: -------------------------------------------------------------------------------- 1 | 2 | /****************************************************************************** 3 | * 4 | * file: SwitchArg.h 5 | * 6 | * Copyright (c) 2003, Michael E. Smoot . 7 | * Copyright (c) 2004, Michael E. Smoot, Daniel Aarno. 8 | * All rights reverved. 9 | * 10 | * See the file COPYING in the top directory of this distribution for 11 | * more information. 12 | * 13 | * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS 14 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 16 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 19 | * DEALINGS IN THE SOFTWARE. 20 | * 21 | *****************************************************************************/ 22 | 23 | 24 | #ifndef TCLAP_SWITCH_ARG_H 25 | #define TCLAP_SWITCH_ARG_H 26 | 27 | #include 28 | #include 29 | 30 | #include 31 | 32 | namespace TCLAP { 33 | 34 | /** 35 | * A simple switch argument. If the switch is set on the command line, then 36 | * the getValue method will return the opposite of the default value for the 37 | * switch. 38 | */ 39 | class SwitchArg : public Arg 40 | { 41 | protected: 42 | 43 | /** 44 | * The value of the switch. 45 | */ 46 | bool _value; 47 | 48 | /** 49 | * Used to support the reset() method so that ValueArg can be 50 | * reset to their constructed value. 51 | */ 52 | bool _default; 53 | 54 | public: 55 | 56 | /** 57 | * SwitchArg constructor. 58 | * \param flag - The one character flag that identifies this 59 | * argument on the command line. 60 | * \param name - A one word name for the argument. Can be 61 | * used as a long flag on the command line. 62 | * \param desc - A description of what the argument is for or 63 | * does. 64 | * \param def - The default value for this Switch. 65 | * \param v - An optional visitor. You probably should not 66 | * use this unless you have a very good reason. 67 | */ 68 | SwitchArg(const std::string& flag, 69 | const std::string& name, 70 | const std::string& desc, 71 | bool def = false, 72 | Visitor* v = NULL); 73 | 74 | 75 | /** 76 | * SwitchArg constructor. 77 | * \param flag - The one character flag that identifies this 78 | * argument on the command line. 79 | * \param name - A one word name for the argument. Can be 80 | * used as a long flag on the command line. 81 | * \param desc - A description of what the argument is for or 82 | * does. 83 | * \param parser - A CmdLine parser object to add this Arg to 84 | * \param def - The default value for this Switch. 85 | * \param v - An optional visitor. You probably should not 86 | * use this unless you have a very good reason. 87 | */ 88 | SwitchArg(const std::string& flag, 89 | const std::string& name, 90 | const std::string& desc, 91 | CmdLineInterface& parser, 92 | bool def = false, 93 | Visitor* v = NULL); 94 | 95 | 96 | /** 97 | * Handles the processing of the argument. 98 | * This re-implements the Arg version of this method to set the 99 | * _value of the argument appropriately. 100 | * \param i - Pointer the the current argument in the list. 101 | * \param args - Mutable list of strings. Passed 102 | * in from main(). 103 | */ 104 | virtual bool processArg(int* i, std::vector& args); 105 | 106 | /** 107 | * Checks a string to see if any of the chars in the string 108 | * match the flag for this Switch. 109 | */ 110 | bool combinedSwitchesMatch(std::string& combined); 111 | 112 | /** 113 | * Returns bool, whether or not the switch has been set. 114 | */ 115 | bool getValue(); 116 | 117 | virtual void reset(); 118 | 119 | private: 120 | /** 121 | * Checks to see if we've found the last match in 122 | * a combined string. 123 | */ 124 | bool lastCombined(std::string& combined); 125 | 126 | /** 127 | * Does the common processing of processArg. 128 | */ 129 | void commonProcessing(); 130 | }; 131 | 132 | ////////////////////////////////////////////////////////////////////// 133 | //BEGIN SwitchArg.cpp 134 | ////////////////////////////////////////////////////////////////////// 135 | inline SwitchArg::SwitchArg(const std::string& flag, 136 | const std::string& name, 137 | const std::string& desc, 138 | bool default_val, 139 | Visitor* v ) 140 | : Arg(flag, name, desc, false, false, v), 141 | _value( default_val ), 142 | _default( default_val ) 143 | { } 144 | 145 | inline SwitchArg::SwitchArg(const std::string& flag, 146 | const std::string& name, 147 | const std::string& desc, 148 | CmdLineInterface& parser, 149 | bool default_val, 150 | Visitor* v ) 151 | : Arg(flag, name, desc, false, false, v), 152 | _value( default_val ), 153 | _default(default_val) 154 | { 155 | parser.add( this ); 156 | } 157 | 158 | inline bool SwitchArg::getValue() { return _value; } 159 | 160 | inline bool SwitchArg::lastCombined(std::string& combinedSwitches ) 161 | { 162 | for ( unsigned int i = 1; i < combinedSwitches.length(); i++ ) 163 | if ( combinedSwitches[i] != Arg::blankChar() ) 164 | return false; 165 | 166 | return true; 167 | } 168 | 169 | inline bool SwitchArg::combinedSwitchesMatch(std::string& combinedSwitches ) 170 | { 171 | // make sure this is actually a combined switch 172 | if ( combinedSwitches.length() > 0 && 173 | combinedSwitches[0] != Arg::flagStartString()[0] ) 174 | return false; 175 | 176 | // make sure it isn't a long name 177 | if ( combinedSwitches.substr( 0, Arg::nameStartString().length() ) == 178 | Arg::nameStartString() ) 179 | return false; 180 | 181 | // make sure the delimiter isn't in the string 182 | if ( combinedSwitches.find_first_of( Arg::delimiter() ) != std::string::npos ) 183 | return false; 184 | 185 | // ok, we're not specifying a ValueArg, so we know that we have 186 | // a combined switch list. 187 | for ( unsigned int i = 1; i < combinedSwitches.length(); i++ ) 188 | if ( _flag.length() > 0 && 189 | combinedSwitches[i] == _flag[0] && 190 | _flag[0] != Arg::flagStartString()[0] ) 191 | { 192 | // update the combined switches so this one is no longer present 193 | // this is necessary so that no unlabeled args are matched 194 | // later in the processing. 195 | //combinedSwitches.erase(i,1); 196 | combinedSwitches[i] = Arg::blankChar(); 197 | return true; 198 | } 199 | 200 | // none of the switches passed in the list match. 201 | return false; 202 | } 203 | 204 | inline void SwitchArg::commonProcessing() 205 | { 206 | if ( _xorSet ) 207 | throw(CmdLineParseException( 208 | "Mutually exclusive argument already set!", toString())); 209 | 210 | if ( _alreadySet ) 211 | throw(CmdLineParseException("Argument already set!", toString())); 212 | 213 | _alreadySet = true; 214 | 215 | if ( _value == true ) 216 | _value = false; 217 | else 218 | _value = true; 219 | 220 | _checkWithVisitor(); 221 | } 222 | 223 | inline bool SwitchArg::processArg(int *i, std::vector& args) 224 | { 225 | if ( _ignoreable && Arg::ignoreRest() ) 226 | return false; 227 | 228 | // if the whole string matches the flag or name string 229 | if ( argMatches( args[*i] ) ) 230 | { 231 | commonProcessing(); 232 | 233 | return true; 234 | } 235 | // if a substring matches the flag as part of a combination 236 | else if ( combinedSwitchesMatch( args[*i] ) ) 237 | { 238 | // check again to ensure we don't misinterpret 239 | // this as a MultiSwitchArg 240 | if ( combinedSwitchesMatch( args[*i] ) ) 241 | throw(CmdLineParseException("Argument already set!", 242 | toString())); 243 | 244 | commonProcessing(); 245 | 246 | // We only want to return true if we've found the last combined 247 | // match in the string, otherwise we return true so that other 248 | // switches in the combination will have a chance to match. 249 | return lastCombined( args[*i] ); 250 | } 251 | else 252 | return false; 253 | } 254 | 255 | inline void SwitchArg::reset() 256 | { 257 | Arg::reset(); 258 | _value = _default; 259 | } 260 | ////////////////////////////////////////////////////////////////////// 261 | //End SwitchArg.cpp 262 | ////////////////////////////////////////////////////////////////////// 263 | 264 | } //namespace TCLAP 265 | 266 | #endif 267 | -------------------------------------------------------------------------------- /src/tclap/ValuesConstraint.h: -------------------------------------------------------------------------------- 1 | 2 | 3 | /****************************************************************************** 4 | * 5 | * file: ValuesConstraint.h 6 | * 7 | * Copyright (c) 2005, Michael E. Smoot 8 | * All rights reverved. 9 | * 10 | * See the file COPYING in the top directory of this distribution for 11 | * more information. 12 | * 13 | * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS 14 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 16 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 19 | * DEALINGS IN THE SOFTWARE. 20 | * 21 | *****************************************************************************/ 22 | 23 | #ifndef TCLAP_VALUESCONSTRAINT_H 24 | #define TCLAP_VALUESCONSTRAINT_H 25 | 26 | #include 27 | #include 28 | #include 29 | 30 | #ifdef HAVE_CONFIG_H 31 | #include 32 | #else 33 | #define HAVE_SSTREAM 34 | #endif 35 | 36 | #if defined(HAVE_SSTREAM) 37 | #include 38 | #elif defined(HAVE_STRSTREAM) 39 | #include 40 | #else 41 | #error "Need a stringstream (sstream or strstream) to compile!" 42 | #endif 43 | 44 | namespace TCLAP { 45 | 46 | /** 47 | * A Constraint that constrains the Arg to only those values specified 48 | * in the constraint. 49 | */ 50 | template 51 | class ValuesConstraint : public Constraint 52 | { 53 | 54 | public: 55 | 56 | /** 57 | * Constructor. 58 | * \param allowed - vector of allowed values. 59 | */ 60 | ValuesConstraint(std::vector& allowed); 61 | 62 | /** 63 | * Virtual destructor. 64 | */ 65 | virtual ~ValuesConstraint() {} 66 | 67 | /** 68 | * Returns a description of the Constraint. 69 | */ 70 | virtual std::string description() const; 71 | 72 | /** 73 | * Returns the short ID for the Constraint. 74 | */ 75 | virtual std::string shortID() const; 76 | 77 | /** 78 | * The method used to verify that the value parsed from the command 79 | * line meets the constraint. 80 | * \param value - The value that will be checked. 81 | */ 82 | virtual bool check(const T& value) const; 83 | 84 | protected: 85 | 86 | /** 87 | * The list of valid values. 88 | */ 89 | std::vector _allowed; 90 | 91 | /** 92 | * The string used to describe the allowed values of this constraint. 93 | */ 94 | std::string _typeDesc; 95 | 96 | }; 97 | 98 | template 99 | ValuesConstraint::ValuesConstraint(std::vector& allowed) 100 | : _allowed(allowed), 101 | _typeDesc("") 102 | { 103 | for ( unsigned int i = 0; i < _allowed.size(); i++ ) 104 | { 105 | 106 | #if defined(HAVE_SSTREAM) 107 | std::ostringstream os; 108 | #elif defined(HAVE_STRSTREAM) 109 | std::ostrstream os; 110 | #else 111 | #error "Need a stringstream (sstream or strstream) to compile!" 112 | #endif 113 | 114 | os << _allowed[i]; 115 | 116 | std::string temp( os.str() ); 117 | 118 | if ( i > 0 ) 119 | _typeDesc += "|"; 120 | _typeDesc += temp; 121 | } 122 | } 123 | 124 | template 125 | bool ValuesConstraint::check( const T& val ) const 126 | { 127 | if ( std::find(_allowed.begin(),_allowed.end(),val) == _allowed.end() ) 128 | return false; 129 | else 130 | return true; 131 | } 132 | 133 | template 134 | std::string ValuesConstraint::shortID() const 135 | { 136 | return _typeDesc; 137 | } 138 | 139 | template 140 | std::string ValuesConstraint::description() const 141 | { 142 | return _typeDesc; 143 | } 144 | 145 | 146 | } //namespace TCLAP 147 | #endif 148 | 149 | -------------------------------------------------------------------------------- /src/tclap/VersionVisitor.h: -------------------------------------------------------------------------------- 1 | // -*- Mode: c++; c-basic-offset: 4; tab-width: 4; -*- 2 | 3 | /****************************************************************************** 4 | * 5 | * file: VersionVisitor.h 6 | * 7 | * Copyright (c) 2003, Michael E. Smoot . 8 | * All rights reverved. 9 | * 10 | * See the file COPYING in the top directory of this distribution for 11 | * more information. 12 | * 13 | * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS 14 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 16 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 19 | * DEALINGS IN THE SOFTWARE. 20 | * 21 | *****************************************************************************/ 22 | 23 | 24 | #ifndef TCLAP_VERSION_VISITOR_H 25 | #define TCLAP_VERSION_VISITOR_H 26 | 27 | #include 28 | #include 29 | #include 30 | 31 | namespace TCLAP { 32 | 33 | /** 34 | * A Vistor that will call the version method of the given CmdLineOutput 35 | * for the specified CmdLine object and then exit. 36 | */ 37 | class VersionVisitor: public Visitor 38 | { 39 | private: 40 | /** 41 | * Prevent accidental copying 42 | */ 43 | VersionVisitor(const VersionVisitor& rhs); 44 | VersionVisitor& operator=(const VersionVisitor& rhs); 45 | 46 | protected: 47 | 48 | /** 49 | * The CmdLine of interest. 50 | */ 51 | CmdLineInterface* _cmd; 52 | 53 | /** 54 | * The output object. 55 | */ 56 | CmdLineOutput** _out; 57 | 58 | public: 59 | 60 | /** 61 | * Constructor. 62 | * \param cmd - The CmdLine the output is generated for. 63 | * \param out - The type of output. 64 | */ 65 | VersionVisitor( CmdLineInterface* cmd, CmdLineOutput** out ) 66 | : Visitor(), _cmd( cmd ), _out( out ) { } 67 | 68 | /** 69 | * Calls the version method of the output object using the 70 | * specified CmdLine. 71 | */ 72 | void visit() { 73 | (*_out)->version(*_cmd); 74 | throw ExitException(0); 75 | } 76 | 77 | }; 78 | 79 | } 80 | 81 | #endif 82 | -------------------------------------------------------------------------------- /src/tclap/Visitor.h: -------------------------------------------------------------------------------- 1 | 2 | /****************************************************************************** 3 | * 4 | * file: Visitor.h 5 | * 6 | * Copyright (c) 2003, Michael E. Smoot . 7 | * All rights reverved. 8 | * 9 | * See the file COPYING in the top directory of this distribution for 10 | * more information. 11 | * 12 | * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS 13 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 14 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 15 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 16 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 17 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 18 | * DEALINGS IN THE SOFTWARE. 19 | * 20 | *****************************************************************************/ 21 | 22 | 23 | #ifndef TCLAP_VISITOR_H 24 | #define TCLAP_VISITOR_H 25 | 26 | namespace TCLAP { 27 | 28 | /** 29 | * A base class that defines the interface for visitors. 30 | */ 31 | class Visitor 32 | { 33 | public: 34 | 35 | /** 36 | * Constructor. Does nothing. 37 | */ 38 | Visitor() { } 39 | 40 | /** 41 | * Destructor. Does nothing. 42 | */ 43 | virtual ~Visitor() { } 44 | 45 | /** 46 | * Does nothing. Should be overridden by child. 47 | */ 48 | virtual void visit() { } 49 | }; 50 | 51 | } 52 | 53 | #endif 54 | -------------------------------------------------------------------------------- /src/tclap/XorHandler.h: -------------------------------------------------------------------------------- 1 | 2 | /****************************************************************************** 3 | * 4 | * file: XorHandler.h 5 | * 6 | * Copyright (c) 2003, Michael E. Smoot . 7 | * Copyright (c) 2004, Michael E. Smoot, Daniel Aarno. 8 | * All rights reverved. 9 | * 10 | * See the file COPYING in the top directory of this distribution for 11 | * more information. 12 | * 13 | * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS 14 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 16 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 19 | * DEALINGS IN THE SOFTWARE. 20 | * 21 | *****************************************************************************/ 22 | 23 | #ifndef TCLAP_XORHANDLER_H 24 | #define TCLAP_XORHANDLER_H 25 | 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | 32 | namespace TCLAP { 33 | 34 | /** 35 | * This class handles lists of Arg's that are to be XOR'd on the command 36 | * line. This is used by CmdLine and you shouldn't ever use it. 37 | */ 38 | class XorHandler 39 | { 40 | protected: 41 | 42 | /** 43 | * The list of of lists of Arg's to be or'd together. 44 | */ 45 | std::vector< std::vector > _orList; 46 | 47 | public: 48 | 49 | /** 50 | * Constructor. Does nothing. 51 | */ 52 | XorHandler( ) : _orList(std::vector< std::vector >()) {} 53 | 54 | /** 55 | * Add a list of Arg*'s that will be orred together. 56 | * \param ors - list of Arg* that will be xor'd. 57 | */ 58 | void add( std::vector& ors ); 59 | 60 | /** 61 | * Checks whether the specified Arg is in one of the xor lists and 62 | * if it does match one, returns the size of the xor list that the 63 | * Arg matched. If the Arg matches, then it also sets the rest of 64 | * the Arg's in the list. You shouldn't use this. 65 | * \param a - The Arg to be checked. 66 | */ 67 | int check( const Arg* a ); 68 | 69 | /** 70 | * Returns the XOR specific short usage. 71 | */ 72 | std::string shortUsage(); 73 | 74 | /** 75 | * Prints the XOR specific long usage. 76 | * \param os - Stream to print to. 77 | */ 78 | void printLongUsage(std::ostream& os); 79 | 80 | /** 81 | * Simply checks whether the Arg is contained in one of the arg 82 | * lists. 83 | * \param a - The Arg to be checked. 84 | */ 85 | bool contains( const Arg* a ); 86 | 87 | std::vector< std::vector >& getXorList(); 88 | 89 | }; 90 | 91 | 92 | ////////////////////////////////////////////////////////////////////// 93 | //BEGIN XOR.cpp 94 | ////////////////////////////////////////////////////////////////////// 95 | inline void XorHandler::add( std::vector& ors ) 96 | { 97 | _orList.push_back( ors ); 98 | } 99 | 100 | inline int XorHandler::check( const Arg* a ) 101 | { 102 | // iterate over each XOR list 103 | for ( int i = 0; static_cast(i) < _orList.size(); i++ ) 104 | { 105 | // if the XOR list contains the arg.. 106 | ArgVectorIterator ait = std::find( _orList[i].begin(), 107 | _orList[i].end(), a ); 108 | if ( ait != _orList[i].end() ) 109 | { 110 | // first check to see if a mutually exclusive switch 111 | // has not already been set 112 | for ( ArgVectorIterator it = _orList[i].begin(); 113 | it != _orList[i].end(); 114 | it++ ) 115 | if ( a != (*it) && (*it)->isSet() ) 116 | throw(CmdLineParseException( 117 | "Mutually exclusive argument already set!", 118 | (*it)->toString())); 119 | 120 | // go through and set each arg that is not a 121 | for ( ArgVectorIterator it = _orList[i].begin(); 122 | it != _orList[i].end(); 123 | it++ ) 124 | if ( a != (*it) ) 125 | (*it)->xorSet(); 126 | 127 | // return the number of required args that have now been set 128 | if ( (*ait)->allowMore() ) 129 | return 0; 130 | else 131 | return static_cast(_orList[i].size()); 132 | } 133 | } 134 | 135 | if ( a->isRequired() ) 136 | return 1; 137 | else 138 | return 0; 139 | } 140 | 141 | inline bool XorHandler::contains( const Arg* a ) 142 | { 143 | for ( int i = 0; static_cast(i) < _orList.size(); i++ ) 144 | for ( ArgVectorIterator it = _orList[i].begin(); 145 | it != _orList[i].end(); 146 | it++ ) 147 | if ( a == (*it) ) 148 | return true; 149 | 150 | return false; 151 | } 152 | 153 | inline std::vector< std::vector >& XorHandler::getXorList() 154 | { 155 | return _orList; 156 | } 157 | 158 | 159 | 160 | ////////////////////////////////////////////////////////////////////// 161 | //END XOR.cpp 162 | ////////////////////////////////////////////////////////////////////// 163 | 164 | } //namespace TCLAP 165 | 166 | #endif 167 | -------------------------------------------------------------------------------- /tests/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !*.cpp 3 | !Makefile.am -------------------------------------------------------------------------------- /tests/Arrays.cpp: -------------------------------------------------------------------------------- 1 | #include "gtest/gtest.h" 2 | #include "Arrays.h" 3 | 4 | 5 | // Check array shape is set correctly 6 | TEST(ArrayTest2D, GetShape){ 7 | 8 | unsigned int height = 3; 9 | unsigned int width = 7; 10 | 11 | Array2D test_array(extents[height][width]); 12 | 13 | ASSERT_EQ(height,test_array.shape()[0]); 14 | ASSERT_EQ(width,test_array.shape()[1]); 15 | 16 | } 17 | 18 | // Run all tests 19 | int main(int argc, char **argv){ 20 | ::testing::InitGoogleTest(&argc, argv); 21 | return RUN_ALL_TESTS(); 22 | } -------------------------------------------------------------------------------- /tests/DataUnit.cpp: -------------------------------------------------------------------------------- 1 | #include "gtest/gtest.h" 2 | #include "DataUnit.h" 3 | 4 | 5 | // Parameterised test to check valid header parsing 6 | // for operator >> (std::istream& stream, DataUnit &d) 7 | struct header_contents{ 8 | unsigned int type; 9 | unsigned int next_parse_offset; 10 | unsigned int prev_parse_offset; 11 | unsigned int type_result; 12 | }; 13 | 14 | struct HeaderParseTest : testing::Test, testing::WithParamInterface{ 15 | DataUnit du; 16 | }; 17 | 18 | TEST_P(HeaderParseTest, CheckValidHeaders){ 19 | 20 | auto as = GetParam(); 21 | 22 | Bytes next(4,as.next_parse_offset); 23 | Bytes prev(4,as.prev_parse_offset); 24 | 25 | std::stringstream ss; 26 | ss << 'B' //0x41 27 | << 'B' //0x41 28 | << 'C' //0x42 29 | << 'D' //0x43 30 | << (unsigned char)as.type 31 | << next 32 | << prev; 33 | 34 | ss >> du; 35 | 36 | EXPECT_EQ(du.type, as.type_result); 37 | EXPECT_EQ((unsigned int)du.next_parse_offset, as.next_parse_offset); 38 | EXPECT_EQ((unsigned int)du.prev_parse_offset, as.prev_parse_offset); 39 | EXPECT_EQ(du.length(), (int)as.next_parse_offset - 13); 40 | 41 | }; 42 | 43 | INSTANTIATE_TEST_SUITE_P(Default, HeaderParseTest, 44 | testing::Values( 45 | header_contents{0x00,0,0,SEQUENCE_HEADER}, 46 | header_contents{0x10,20,20,END_OF_SEQUENCE}, 47 | header_contents{0x20,128,0,AUXILIARY_DATA}, 48 | header_contents{0x30,0,3245,PADDING_DATA}, 49 | header_contents{0xC8,23,0,LD_PICTURE}, 50 | header_contents{0xE8,13,13,HQ_PICTURE}, 51 | header_contents{0xCC,13,13,LD_FRAGMENT}, 52 | header_contents{0xEC,13,0,HQ_FRAGMENT} 53 | )); 54 | 55 | // Check correct exception is thrown when the prefix is incorrect 56 | TEST(HeaderParseTest, ThrowErrorIfPrefixIncorrect){ 57 | DataUnit du; 58 | std::stringstream ss; 59 | ss << 'A' 60 | << 'B' 61 | << 'C' 62 | << 'D'; 63 | 64 | try{ 65 | ss >> du; 66 | } catch (std::logic_error& exception){ 67 | EXPECT_EQ(std::string(exception.what()), 68 | "Read bytes do not match expected parse_info_header."); 69 | } 70 | } 71 | 72 | // Check correct exception is thrown when the type is incorrect 73 | TEST(HeaderParseTest, ThrowErrorIfTypeIncorrect){ 74 | DataUnit du; 75 | std::stringstream ss; 76 | ss << 'B' 77 | << 'B' 78 | << 'C' 79 | << 'D' 80 | << (unsigned char) 0xFF; 81 | 82 | try{ 83 | 84 | 85 | ss >> du; 86 | 87 | } catch (std::logic_error& exception){ 88 | EXPECT_EQ(std::string(exception.what()), 89 | "Stream Error: Unknown data unit type."); 90 | } 91 | } 92 | 93 | TEST(BaseVideoTest, CheckAccess){ 94 | SequenceHeader test = getDefaultSourceParameters(4); 95 | 96 | EXPECT_EQ(test.width, 352); 97 | EXPECT_EQ(test.height,288); 98 | EXPECT_EQ(test.chromaFormat, CF420); 99 | EXPECT_EQ(test.frameRate, FR25_2); 100 | EXPECT_EQ(test.bitdepth, 8); 101 | 102 | } 103 | 104 | 105 | // Run all tests 106 | int main(int argc, char **argv){ 107 | ::testing::InitGoogleTest(&argc, argv); 108 | return RUN_ALL_TESTS(); 109 | } 110 | -------------------------------------------------------------------------------- /tests/Makefile.am: -------------------------------------------------------------------------------- 1 | check_LTLIBRARIES = libgtest.la 2 | libgtest_la_SOURCES = ../googletest/googletest/src/gtest-all.cc 3 | libgtest_la_CPPFLAGS = -I$(top_srcdir)/googletest/googletest/include \ 4 | -I$(top_srcdir)/googletest/googletest -pthread 5 | libgtest_la_LDFLAGS = -pthread 6 | 7 | MAIN_LDADD = libgtest.la \ 8 | $(top_srcdir)/src/Library/libVC2.la \ 9 | $(BOOST_LDFLAGS) \ 10 | $(BOOST_SYSTEM_LIB)\ 11 | $(BOOST_THREAD_LIB) 12 | 13 | MAIN_CPPFLAGS = -I$(top_srcdir)/src/ \ 14 | -I$(top_srcdir)/src/Library \ 15 | -I$(top_srcdir)/googletest/googletest/include \ 16 | -I$(top_srcdir)/googletest/googletest -pthread \ 17 | $(VC2REFERENCE_CFLAGS) \ 18 | $(BOOST_CFLAGS) 19 | 20 | MAIN_LD_FLAGS = -pthread 21 | 22 | check_PROGRAMS = arrays quantisation dataunit utils 23 | 24 | arrays_SOURCES = Arrays.cpp 25 | arrays_LDADD = $(MAIN_LDADD) 26 | arrays_LDFLAGS = $(MAIN_LD_FLAGS) 27 | arrays_CPPFLAGS = $(MAIN_CPPFLAGS) 28 | 29 | dataunit_SOURCES = DataUnit.cpp 30 | dataunit_LDADD = $(MAIN_LDADD) 31 | dataunit_LDFLAGS = $(MAIN_LD_FLAGS) 32 | dataunit_CPPFLAGS = $(MAIN_CPPFLAGS) 33 | 34 | quantisation_SOURCES = Quantisation.cpp 35 | quantisation_LDADD = $(MAIN_LDADD) 36 | quantisation_LDFLAGS = $(MAIN_LD_FLAGS) 37 | quantisation_CPPFLAGS = $(MAIN_CPPFLAGS) 38 | 39 | utils_SOURCES = Utils.cpp 40 | utils_LDADD = $(MAIN_LDADD) 41 | utils_LDFLAGS = $(MAIN_LD_FLAGS) 42 | utils_CPPFLAGS = $(MAIN_CPPFLAGS) 43 | 44 | TESTS = arrays quantisation dataunit utils 45 | -------------------------------------------------------------------------------- /tests/Quantisation.cpp: -------------------------------------------------------------------------------- 1 | #include "gtest/gtest.h" 2 | #include "Quantisation.h" 3 | 4 | 5 | // Check correct exception is thrown when a quantisation factor is too large 6 | TEST(QuantisationFactorTest, ThrowErrorIfTooLarge){ 7 | try{ 8 | quant(12,130); 9 | } catch (std::logic_error& exception){ 10 | EXPECT_EQ(std::string(exception.what()), "quantization index exceeds maximum implemented value."); 11 | } 12 | } 13 | 14 | 15 | // Parameterised test to check quantising a few values 16 | struct quantised_values{ 17 | int value; 18 | int q; 19 | int result; 20 | }; 21 | 22 | struct QuantisationFactorTest : testing::Test, testing::WithParamInterface{}; 23 | 24 | TEST_P(QuantisationFactorTest, CheckNormalOperation){ 25 | auto as = GetParam(); 26 | EXPECT_EQ(quant(as.value, as.q), as.result); 27 | 28 | }; 29 | 30 | INSTANTIATE_TEST_SUITE_P(Default, QuantisationFactorTest, 31 | testing::Values( 32 | quantised_values{12,0,12}, 33 | quantised_values{12,2,8}, 34 | quantised_values{-12,2,-8}, 35 | quantised_values{-12,-2,-12} 36 | )); 37 | 38 | 39 | // Run all tests 40 | int main(int argc, char **argv){ 41 | ::testing::InitGoogleTest(&argc, argv); 42 | return RUN_ALL_TESTS(); 43 | } -------------------------------------------------------------------------------- /tests/Utils.cpp: -------------------------------------------------------------------------------- 1 | #include "gtest/gtest.h" 2 | #include "Utils.h" 3 | 4 | // Parameterised test to check getting the picture number 5 | struct picture_values{ 6 | int fieldNumber; 7 | unsigned long long frameNumber; 8 | const int fieldsPerFrame; 9 | unsigned long result; 10 | }; 11 | 12 | struct GetPictureNumberTest : testing::Test, testing::WithParamInterface{}; 13 | 14 | TEST_P(GetPictureNumberTest, CheckNormalOperation){ 15 | auto as = GetParam(); 16 | EXPECT_EQ(utils::getPictureNumber(as.fieldNumber, as.frameNumber, as.fieldsPerFrame), as.result); 17 | }; 18 | 19 | INSTANTIATE_TEST_SUITE_P(Default, GetPictureNumberTest, 20 | testing::Values( 21 | picture_values{0,0,1,0}, 22 | picture_values{1,0,1,1}, 23 | picture_values{2,0,2,2}, 24 | picture_values{1,1,1,2}, 25 | picture_values{2,1,2,4}, 26 | picture_values{1,2,2,5}, 27 | picture_values{0,((1ULL)<<32)-1 ,1,((1ULL)<<32)-1}, // 2^32-1 28 | picture_values{0,(1ULL)<<32,1,0} 29 | )); 30 | 31 | // Parameterised test to check getting the picture number exceptions 32 | struct picture_exceptions{ 33 | int fieldNumber; 34 | unsigned long long frameNumber; 35 | const int fieldsPerFrame; 36 | std::string exceptionString; 37 | }; 38 | 39 | struct GetPictureNumberExceptionTest : testing::Test, testing::WithParamInterface{}; 40 | 41 | TEST_P(GetPictureNumberExceptionTest, CheckExeptionsCorrectlyThrown){ 42 | auto as = GetParam(); 43 | try{ 44 | utils::getPictureNumber(as.fieldNumber, as.frameNumber, as.fieldsPerFrame); 45 | FAIL(); // Fail if an exception is not thrown 46 | } catch (std::logic_error& exception){ 47 | EXPECT_EQ(std::string(exception.what()), as.exceptionString); 48 | } 49 | }; 50 | 51 | INSTANTIATE_TEST_SUITE_P(Default, GetPictureNumberExceptionTest, 52 | testing::Values( 53 | picture_exceptions{-5,0,1,"field number should be positive"}, 54 | picture_exceptions{2,0,1,"field number exceeds number of fields per frame"}, 55 | picture_exceptions{0,0,3,"number of fields per frame should be 1 (progressive) or 2 (interlaced)"} 56 | )); 57 | 58 | 59 | // Run all tests 60 | int main(int argc, char **argv){ 61 | ::testing::InitGoogleTest(&argc, argv); 62 | return RUN_ALL_TESTS(); 63 | } 64 | -------------------------------------------------------------------------------- /tools/Makefile.am: -------------------------------------------------------------------------------- 1 | noinst_SCRIPTS = vc2streamdebugger convert_from_16p2 convert_to_16p2 2 | -------------------------------------------------------------------------------- /tools/convert_from_16p2: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | #***************************************************************************** 4 | #* convert_from_16p2: A simple utility that converts from the raw format 5 | #* preferred by these reference programmes 6 | #***************************************************************************** 7 | #* Copyright (C) 2020 BBC 8 | #* 9 | #* Authors: James P. Weaver and Galen Reich 10 | #* 11 | #* This program is free software; you can redistribute it and/or modify 12 | #* it under the terms of the GNU General Public License as published by 13 | #* the Free Software Foundation; either version 2 of the License, or 14 | #* (at your option) any later version. 15 | #* 16 | #* This program is distributed in the hope that it will be useful, 17 | #* but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | #* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | #* GNU General Public License for more details. 20 | #* 21 | #* You should have received a copy of the GNU General Public License 22 | #* along with this program; if not, write to the Free Software 23 | #* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA. 24 | #* 25 | #* This program is also available under a commercial proprietary license. 26 | #* For more information, contact us at ipstudio@bbc.co.uk. 27 | #***************************************************************************** 28 | 29 | if __name__ == "__main__": 30 | import argparse 31 | 32 | parser = argparse.ArgumentParser(formatter_class=argparse.RawDescriptionHelpFormatter, description="""\ 33 | 16p2 to yuv converter 34 | --------------------- 35 | 36 | Input file should be in 16p2 format (as output by DecodeStream). 37 | ie. 16-bit yuv planar data samples with the active bits in the high order bits 38 | 39 | Output file will be in one of several formats depending on settings, the 40 | following table shows the ffmpeg pixel_format name for each of these formats: 41 | 42 | +-------------+--------------------+--------------------+ 43 | | Active Bits | Colour Subsampling | ffmpeg format name | 44 | +-------------+--------------------+--------------------+ 45 | | 8 | 4:2:0 | yuv420p | 46 | | 8 | 4:2:2 | yuv422p | 47 | | 8 | 4:4:4 | yuv444p | 48 | | 10 | 4:2:0 | yuv420p10le | 49 | | 10 | 4:2:2 | yuv422p10le | 50 | | 10 | 4:4:4 | yuv444p10le | 51 | | 12 | 4:2:0 | yuv420p12le | 52 | | 12 | 4:2:2 | yuv422p12le | 53 | | 12 | 4:4:4 | yuv444p12le | 54 | | 16 | 4:2:0 | yuv420p16le | 55 | | 16 | 4:2:2 | yuv422p16le | 56 | | 16 | 4:4:4 | yuv444p16le | 57 | +-------------+--------------------+--------------------+ 58 | 59 | """) 60 | parser.add_argument('infilename', metavar='file', type=str, 61 | help='input 16p2 file') 62 | parser.add_argument('--bits', metavar='bits', type=int, default=10, 63 | help='active bits (default 10)') 64 | 65 | args = parser.parse_args() 66 | 67 | word = bytearray(2) 68 | with open(args.infilename, "rb") as fi: 69 | with open(args.infilename+'.yuv', "wb") as fo: 70 | while True: 71 | if fi.readinto(word) == 0: 72 | break 73 | if args.bits == 8: 74 | fo.write(word[:1]) 75 | else: 76 | n = ((word[0] << 8) + word[1]) >> (16 - args.bits) 77 | word[1] = n >> 8 78 | word[0] = n & 0xFF 79 | fo.write(word) 80 | -------------------------------------------------------------------------------- /tools/convert_to_16p2: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | #***************************************************************************** 4 | #* convert_to_16p2: A simple utility that converts to the raw format 5 | #* preferred by these reference programmes 6 | #***************************************************************************** 7 | #* Copyright (C) 2020 BBC 8 | #* 9 | #* Authors: James P. Weaver and Galen Reich 10 | #* 11 | #* This program is free software; you can redistribute it and/or modify 12 | #* it under the terms of the GNU General Public License as published by 13 | #* the Free Software Foundation; either version 2 of the License, or 14 | #* (at your option) any later version. 15 | #* 16 | #* This program is distributed in the hope that it will be useful, 17 | #* but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | #* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | #* GNU General Public License for more details. 20 | #* 21 | #* You should have received a copy of the GNU General Public License 22 | #* along with this program; if not, write to the Free Software 23 | #* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA. 24 | #* 25 | #* This program is also available under a commercial proprietary license. 26 | #* For more information, contact us at ipstudio@bbc.co.uk. 27 | #***************************************************************************** 28 | 29 | if __name__ == "__main__": 30 | import argparse 31 | parser = argparse.ArgumentParser(formatter_class=argparse.RawDescriptionHelpFormatter, description="""\ 32 | yuv to 16p2 converter 33 | --------------------- 34 | 35 | Input file should be in one of several formats depending on settings, the following 36 | table shows the ffmpeg pixel_format name for each of these formats: 37 | 38 | +-------------+--------------------+--------------------+ 39 | | Active Bits | Colour Subsampling | ffmpeg format name | 40 | +-------------+--------------------+--------------------+ 41 | | 8 | 4:2:0 | yuv420p | 42 | | 8 | 4:2:2 | yuv422p | 43 | | 8 | 4:4:4 | yuv444p | 44 | | 10 | 4:2:0 | yuv420p10le | 45 | | 10 | 4:2:2 | yuv422p10le | 46 | | 10 | 4:4:4 | yuv444p10le | 47 | | 12 | 4:2:0 | yuv420p12le | 48 | | 12 | 4:2:2 | yuv422p12le | 49 | | 12 | 4:4:4 | yuv444p12le | 50 | | 16 | 4:2:0 | yuv420p16le | 51 | | 16 | 4:2:2 | yuv422p16le | 52 | | 16 | 4:4:4 | yuv444p16le | 53 | +-------------+--------------------+--------------------+ 54 | 55 | Output file will be in 16p2 format (suitable to use as input to by EncodeHQ-CBR, etc ...). 56 | ie. 16-bit yuv planar data samples with the active bits in the high order bits 57 | 58 | """) 59 | parser.add_argument('infilename', metavar='file', type=str, 60 | help='input yuv file') 61 | parser.add_argument('--bits', metavar='bits', type=int, default=10, 62 | help='active bits (default 10)') 63 | 64 | args = parser.parse_args() 65 | 66 | outfilename = args.infilename + ".16p2" 67 | of = open(outfilename, "wb") 68 | 69 | word = bytearray(2) 70 | with open(args.infilename, "rb") as fi: 71 | with open(args.infilename+'.16p2', "wb") as fo: 72 | while True: 73 | if fi.readinto(word) == 0: 74 | break 75 | if args.bits == 8: 76 | fo.write(word[0:1]) 77 | fo.write(b"\x00") 78 | fo.write(word[1:2]) 79 | fo.write(b"\x00") 80 | else: 81 | n = ((word[1] << 8) + word[0]) << (16 - args.bits) 82 | 83 | word[0] = n >> 8 84 | word[1] = n & 0xFF 85 | fo.write(word) 86 | --------------------------------------------------------------------------------