From 9e9a246736b2fa0497f5cb6157c9c1d90ac8af34 Mon Sep 17 00:00:00 2001 From: bolero-MURAKAMI Date: Fri, 20 Sep 2013 01:04:30 +0900 Subject: [PATCH] add tools darkcult, add testspr/test.sh --- testspr/sprout.cpp | 4 ++ testspr/test.sh | 92 +++++++++++++++++++++++++ tools/compost/wavconv.cpp | 134 ++++++++++++++++++++++++++++++++++++ tools/darkroom/darkcult.cpp | 90 ++++++++++++++++++++++++ tools/darkroom/darkcult.sh | 99 ++++++++++++++++++++++++++ tools/darkroom/texconv.cpp | 72 +++++++++++++++++++ 6 files changed, 491 insertions(+) create mode 100755 testspr/test.sh create mode 100644 tools/compost/wavconv.cpp create mode 100644 tools/darkroom/darkcult.cpp create mode 100755 tools/darkroom/darkcult.sh create mode 100644 tools/darkroom/texconv.cpp diff --git a/testspr/sprout.cpp b/testspr/sprout.cpp index 0a5d9725..8fcb97d8 100644 --- a/testspr/sprout.cpp +++ b/testspr/sprout.cpp @@ -13,6 +13,10 @@ # define TESTSPR_CPP_INCLUDE #endif +#ifdef TESTSPR_CONFIG_INCLUDE_HEADER_ALL +# include "./header_all.hpp" +#endif + #include "../libs/array/test/array.cpp" #include "../libs/string/test/string.cpp" #include "../libs/bitset/test/bitset.cpp" diff --git a/testspr/test.sh b/testspr/test.sh new file mode 100755 index 00000000..8597f94f --- /dev/null +++ b/testspr/test.sh @@ -0,0 +1,92 @@ +#!/bin/bash +# ============================================================================= +# Copyright (c) 2011-2013 Bolero MURAKAMI +# https://github.com/bolero-MURAKAMI/Sprout +# +# Distributed under the Boost Software License, Version 1.0. (See accompanying +# file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +# ============================================================================= +stagedir="testspr" +gcc_version="4.7.0 4.7.1 4.7.2 4.7.3 4.8.0 4.8.1" +clang_version="3.2 3.3" +declare -a user_macros +user_macros=() +force=0 +declare -A version_specific_options +version_specific_options=( + [clang-3.3]="-ftemplate-depth=512" +) + +compile() { + echo ": $1-$2 compile..." + /usr/local/$1-$2/bin/${1/%cc}++ -Wall -pedantic -std=c++11 -o ${stagedir}/test_$1${2//.} $4 $3 + let "succ_$1${2//.} = $?" +} + +execute() { + if eval [ \$succ_$1${2//.} -eq 0 ]; then + echo ": $1-$2 compile succeeded." + if ${stagedir}/test_$1${2//.}; then + echo ": $1-$2 execute succeeded." + else + echo >&2 -e ": \e[31m$1-$2 execute failed.\e[m" + fi + else + echo >&2 -e ": \e[31m$1-$2 compile failed.\e[m" + fi +} + +args=`getopt -o d:D:f -l stagedir:,gcc-version:,clang-version:,define:,force -- "$@"` +if [ "$?" -ne 0 ]; then + echo >&2 -e ": \e[31musage: $0 [-d|--stagedir=path] [--gcc-version=versions] [--clang-version=versions] [-D|--define=identifier]* [-f|-force]\e[m" + exit 1 +fi +eval set -- ${args} +while [ -n "$1" ]; do + case $1 in + -d|--stagedir) stagedir=$2; shift 2;; + --gcc-version) gcc_version="$2"; shift 2;; + --clang-version) clang_version="$2"; shift 2;; + -D|--define) user_macros=(${user_macros[@]} "$2"); shift 2;; + -f|--force) force=1; shift 2;; + --) shift; break;; + *) echo >&2 -e ": \e[31munknown option($1) used.\e[m"; exit 1;; + esac +done +echo ": settings" +echo ": stagedir = ${stagedir}" +echo ": gcc-version = (${gcc_version})" +echo ": clang-version = (${clang_version})" +echo ": user-macros = (${user_macros[*]})" +echo ": force = ${force}" + +if [ -d "${stagedir}" ]; then + if [ ${force} -eq 0 ]; then + echo >&2 -e ": \e[31mstagedir(${stagedir}) is already exist.\e[m" + exit 1 + else + rm -f -r ${stagedir}/* + fi +else + mkdir -p ${stagedir} +fi + +for user_macro in ${user_macros}; do + define_options="${define_options} -D${user_macro}" +done + +for version in ${gcc_version}; do + compile gcc ${version} $(cd $(dirname $0); pwd)/sprout.cpp "${define_options} ${version_specific_options[gcc-${version}]}" +done + +for version in ${clang_version}; do + compile clang ${version} $(cd $(dirname $0); pwd)/sprout.cpp "${define_options} ${version_specific_options[clang-${version}]}" +done + +for version in ${gcc_version}; do + execute gcc ${version} +done + +for version in ${clang_version}; do + execute clang ${version} +done diff --git a/tools/compost/wavconv.cpp b/tools/compost/wavconv.cpp new file mode 100644 index 00000000..d54ca12c --- /dev/null +++ b/tools/compost/wavconv.cpp @@ -0,0 +1,134 @@ +/*============================================================================= + Copyright (c) 2011-2013 Bolero MURAKAMI + https://github.com/bolero-MURAKAMI/Sprout + + Distributed under the Boost Software License, Version 1.0. (See accompanying + file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +=============================================================================*/ +#include +#include +#include +#include +#include +#include +#include +#include +#include + +template +std::string read_chunk(InputIterator& it) { + std::string s; + for (std::size_t i = 0; i != N; ++i, ++it) { + s.push_back(*it); + } + return s; +} + +template +IntType read_int(InputIterator& it) { + IntType n = 0; + for (std::size_t i = 0; i != sizeof(IntType); ++i, ++it) { + n |= static_cast(static_cast(*it)) << (i * CHAR_BIT); + } + return n; +} + +int main(int argc, char* argv[]) { + if (argc < 2) { + std::cerr + << "#error missing parameter.\n" + << std::flush + ; + return 0; + } + + std::ifstream ifs(argv[1], std::ios_base::in | std::ios_base::binary); + std::istreambuf_iterator it(ifs); + std::istreambuf_iterator last; + std::cout + << "#if defined(COMPOST_LOADING_SOURCE_VERSION)\n" + "\n" + "COMPOST_SRC_VERSION(0)\n" + "\n" + "#elif defined(COMPOST_LOADING_SOURCE_INFO)\n" + "\n" + ; + + if (read_chunk(it) != "RIFF") { + std::cerr + << "#error not RIFF file.\n" + << std::flush + ; + return EXIT_FAILURE; + } + /*auto file_size = */read_int(it); + if (read_chunk(it) != "WAVE") { + std::cerr + << "#error not WAVE format.\n" + << std::flush + ; + return EXIT_FAILURE; + } + + while (read_chunk(it) != "fmt ") { + auto chunk_size = read_int(it); + std::advance(it, chunk_size); + } + auto fmt_size = read_int(it); + auto format_tag = read_int(it); + auto channels = read_int(it); + auto samples_per_sec = read_int(it); + auto bytes_per_sec = read_int(it); + auto block_size = read_int(it); + auto bits_per_sample = read_int(it); + std::cout + << format_tag << ",\n" + << channels << ",\n" + << samples_per_sec << ",\n" + << bytes_per_sec << ",\n" + << block_size << ",\n" + << bits_per_sample << ",\n" + ; + std::advance(it, fmt_size - 16); + + while (read_chunk(it) != "data") { + auto chunk_size = read_int(it); + std::advance(it, chunk_size); + } + auto data_size = read_int(it); + std::size_t size = data_size / (bits_per_sample / CHAR_BIT); + std::cout + << size << "\n" + << "\n" + "#elif defined(COMPOST_LOADING_SOURCE_DATA)\n" + "\n" + ; + if (size > 0) { + if (bits_per_sample == 16) { + for (std::size_t i = 1; i != size; ++i) { + std::cout + << read_int(it) << ",\n" + ; + } + std::cout + << read_int(it) << "\n" + ; + } else if (bits_per_sample == 8) { + for (std::size_t i = 1; i != size; ++i) { + std::cout + << read_int(it) << ",\n" + ; + } + std::cout + << read_int(it) << "\n" + ; + } + } + + std::cout + << "\n" + "#endif\n" + << std::flush + ; +} + diff --git a/tools/darkroom/darkcult.cpp b/tools/darkroom/darkcult.cpp new file mode 100644 index 00000000..a46c70b2 --- /dev/null +++ b/tools/darkroom/darkcult.cpp @@ -0,0 +1,90 @@ +/*============================================================================= + Copyright (c) 2011-2013 Bolero MURAKAMI + https://github.com/bolero-MURAKAMI/Sprout + + Distributed under the Boost Software License, Version 1.0. (See accompanying + file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +=============================================================================*/ +// +// DARKROOM_SOURCE +// +#ifndef DARKROOM_SOURCE +# error DARKROOM_SOURCE not defined. for example: "scene.hpp" +#else +# include DARKROOM_SOURCE +#endif + +// +// DARKROOM_TOTAL_WIDTH +// DARKROOM_TOTAL_HEIGHT +// +#ifndef DARKROOM_TOTAL_WIDTH +# define DARKROOM_TOTAL_WIDTH 16 +#endif +#ifndef DARKROOM_TOTAL_HEIGHT +# define DARKROOM_TOTAL_HEIGHT DARKROOM_TOTAL_WIDTH +#endif + +// +// DARKROOM_TILE_WIDTH +// DARKROOM_TILE_HEIGHT +// +#ifndef DARKROOM_TILE_WIDTH +# define DARKROOM_TILE_WIDTH DARKROOM_TOTAL_WIDTH +#endif +#ifndef DARKROOM_TILE_HEIGHT +# define DARKROOM_TILE_HEIGHT DARKROOM_TOTAL_HEIGHT +#endif + +// +// DARKROOM_OFFSET_X +// DARKROOM_OFFSET_Y +// +#ifndef DARKROOM_OFFSET_X +# define DARKROOM_OFFSET_X 0 +#endif +#ifndef DARKROOM_OFFSET_Y +# define DARKROOM_OFFSET_Y 0 +#endif + +#include +#include +#include + +namespace darkcult { + SPROUT_STATIC_CONSTEXPR std::size_t total_width = DARKROOM_TOTAL_WIDTH; + SPROUT_STATIC_CONSTEXPR std::size_t total_height = DARKROOM_TOTAL_HEIGHT; + SPROUT_STATIC_CONSTEXPR std::size_t tile_width = DARKROOM_TILE_WIDTH; + SPROUT_STATIC_CONSTEXPR std::size_t tile_height = DARKROOM_TILE_HEIGHT; + SPROUT_STATIC_CONSTEXPR std::size_t offset_x = DARKROOM_OFFSET_X; + SPROUT_STATIC_CONSTEXPR std::size_t offset_y = DARKROOM_OFFSET_Y; +} // namespace darkcult + +int main() { + using namespace sprout::darkroom; + + typedef pixels::color_pixels::type image_type; + SPROUT_STATIC_CONSTEXPR auto image = pixels::generate( + darkcult::raytracer, darkcult::renderer, darkcult::camera, + darkcult::object, darkcult::light, + darkcult::offset_x, darkcult::offset_y, + darkcult::total_width, darkcult::total_height + ); + + std::cout + << "P3" << std::endl + << image[0].size() << ' ' << image.size() << std::endl + << 255 << std::endl + ; + for (auto i = image.begin(), last = image.end(); i != last; ++i) { + auto const& line = *i; + for (auto j = line.begin(), last = line.end(); j != last; ++j) { + auto const& pixel = *j; + std::cout + << unsigned(colors::r(pixel)) << ' ' + << unsigned(colors::g(pixel)) << ' ' + << unsigned(colors::b(pixel)) << std::endl + ; + } + } +} diff --git a/tools/darkroom/darkcult.sh b/tools/darkroom/darkcult.sh new file mode 100755 index 00000000..0aa4ed84 --- /dev/null +++ b/tools/darkroom/darkcult.sh @@ -0,0 +1,99 @@ +#!/bin/bash +# ============================================================================= +# Copyright (c) 2011-2013 Bolero MURAKAMI +# https://github.com/bolero-MURAKAMI/Sprout +# +# Distributed under the Boost Software License, Version 1.0. (See accompanying +# file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +# ============================================================================= +# +# requires: ImageMagick (http://www.imagemagick.org/script/index.php) +# +src="" +stagedir="darkroom" +width=16 +height=16 +tile_width=16 +tile_height=16 +force=0 + +args=`getopt -o s:d:w:h:W:H:f -l source:,stagedir:,width:,height:,tile-width:,tile-height:,force -- "$@"` +if [ "$?" -ne 0 ]; then + echo >&2 -e ": \e[31musage: $0 -s|--source=file [-d|--stagedir=path] [-w|--width=value] [-h|--height=value] [-W|--tile-width=value] [-H|--tile-height=value] [-f|-force]\e[m" + exit 1 +fi +eval set -- ${args} +while [ -n "$1" ]; do + case $1 in + -s|--source) src=$2; shift 2;; + -d|--stagedir) stagedir=$2; shift 2;; + -w|--width) width=$2; shift 2;; + -h|--height) height=$2; shift 2;; + -W|--tile-width) tile_width=$2; shift 2;; + -H|--tile-height) tile_height=$2; shift 2;; + -f|--force) force=1; shift 2;; + --) shift; break;; + *) echo >&2 -e ": \e[31munknown option($1) used.\e[m"; exit 1;; + esac +done + +echo ": settings" +echo ": source = ${src}" +echo ": stagedir = ${stagedir}" +echo ": width = ${width}" +echo ": height = ${height}" +echo ": tile-width = ${tile_width}" +echo ": tile-height = ${tile_height}" +echo ": force = ${force}" + +if [ ! -f "${src}" ]; then + echo >&2 ": \e[31msource(${src}) is not exist.\e[m" + exit 1 +fi + +if [ -d "${stagedir}" ]; then + if [ ${force} -eq 0 ]; then + echo >&2 -e ": \e[31mstagedir(${stagedir}) is already exist.\e[m" + exit 1 + else + rm -f -r ${stagedir}/* + fi +else + mkdir -p ${stagedir} +fi + +echo ": rendering..." +start=$SECONDS + +for ((y=0; y ${stagedir}/${y}/${x}.ppm +# rm ${binname} + done; + pushd ${stagedir}/${y}/ + convert +append $(ls *.ppm | sort -n) ../${y}.ppm + popd + + let y_elapsed=$SECONDS-$y_start + echo ": elapsed(${y}) = ${y_elapsed}s" +done; +pushd ${stagedir} +convert -append $(ls *.ppm | sort -n) out.ppm +popd + +let elapsed=$SECONDS-$start +echo ": elapsed = ${elapsed}s" + +echo ": finished" diff --git a/tools/darkroom/texconv.cpp b/tools/darkroom/texconv.cpp new file mode 100644 index 00000000..ce2e7f17 --- /dev/null +++ b/tools/darkroom/texconv.cpp @@ -0,0 +1,72 @@ +/*============================================================================= + Copyright (c) 2011-2013 Bolero MURAKAMI + https://github.com/bolero-MURAKAMI/Sprout + + Distributed under the Boost Software License, Version 1.0. (See accompanying + file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +=============================================================================*/ +/* + requires: OpenCV (http://opencv.jp/) +*/ +#include +#include +#include +#include +#include +#include +#include + +int main(int argc, char* argv[]) { + if (argc < 2) { + std::cerr + << "#error missing parameter.\n" + << std::flush + ; + return 0; + } + + cv::Mat image(cv::imread(argv[1])); + std::cout + << "#if defined(DARKROOM_LOADING_TEXTURE_VERSION)\n" + "\n" + "DARKROOM_TEX_VERSION(0)\n" + "\n" + "#elif defined(DARKROOM_LOADING_TEXTURE_INFO)\n" + "\n" + "DARKROOM_TEX_IMAGE_DEFAULT,\n" + "DARKROOM_TEX_PIXEL_INT_R8G8B8,\n" + << image.cols << ",\n" + << image.rows << "\n" + << "\n" + "#elif defined(DARKROOM_LOADING_TEXTURE_PIXEL)\n" + "\n" + ; + + std::cout << std::hex; + for (std::size_t y = 0, h = image.rows; y != h; ++y) { + for (std::size_t x = 0, w = image.cols; x != w; ++x) { + auto pixel = image.ptr(y) + x * 3; + std::cout + << "0x" + << std::setfill('0') << std::setw(2) << unsigned(pixel[2]) + << std::setfill('0') << std::setw(2) << unsigned(pixel[1]) + << std::setfill('0') << std::setw(2) << unsigned(pixel[0]) + ; + if (!(y == h - 1 && x == w - 1)) { + std::cout << ','; + if (x != w - 1) { + std::cout << ' '; + } + } + } + std::cout << '\n'; + } + std::cout << std::dec; + + std::cout + << "\n" + "#endif\n" + << std::flush + ; +} +