add tools darkcult, add testspr/test.sh

This commit is contained in:
bolero-MURAKAMI 2013-09-20 01:04:30 +09:00
parent d7bf483c4a
commit 9e9a246736
6 changed files with 491 additions and 0 deletions

View file

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

92
testspr/test.sh Executable file
View file

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

134
tools/compost/wavconv.cpp Normal file
View file

@ -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 <climits>
#include <cstddef>
#include <cstdint>
#include <cstdlib>
#include <string>
#include <iterator>
#include <type_traits>
#include <iostream>
#include <fstream>
template<std::size_t N = 4, typename InputIterator>
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<typename IntType, typename InputIterator>
IntType read_int(InputIterator& it) {
IntType n = 0;
for (std::size_t i = 0; i != sizeof(IntType); ++i, ++it) {
n |= static_cast<IntType>(static_cast<unsigned char>(*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<char> it(ifs);
std::istreambuf_iterator<char> 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<std::uint32_t>(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<std::uint32_t>(it);
std::advance(it, chunk_size);
}
auto fmt_size = read_int<std::uint32_t>(it);
auto format_tag = read_int<std::uint16_t>(it);
auto channels = read_int<std::uint16_t>(it);
auto samples_per_sec = read_int<std::uint32_t>(it);
auto bytes_per_sec = read_int<std::uint32_t>(it);
auto block_size = read_int<std::uint16_t>(it);
auto bits_per_sample = read_int<std::uint16_t>(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<std::uint32_t>(it);
std::advance(it, chunk_size);
}
auto data_size = read_int<std::uint32_t>(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<std::int16_t>(it) << ",\n"
;
}
std::cout
<< read_int<std::int16_t>(it) << "\n"
;
} else if (bits_per_sample == 8) {
for (std::size_t i = 1; i != size; ++i) {
std::cout
<< read_int<std::uint8_t>(it) << ",\n"
;
}
std::cout
<< read_int<std::uint8_t>(it) << "\n"
;
}
}
std::cout
<< "\n"
"#endif\n"
<< std::flush
;
}

View file

@ -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 <cstddef>
#include <iostream>
#include <sprout/darkroom.hpp>
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<darkcult::tile_width, darkcult::tile_height>::type image_type;
SPROUT_STATIC_CONSTEXPR auto image = pixels::generate<image_type>(
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
;
}
}
}

99
tools/darkroom/darkcult.sh Executable file
View file

@ -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<height; y+=tile_height)); do
y_start=$SECONDS
for ((x=0; x<width; x+=tile_width)); do
mkdir -p ${stagedir}/${y}/
binname=${stagedir}/${x}.${y}.out
g++ -o ${binname} -std=c++11 \
-DDARKROOM_SOURCE="\"${src}\"" \
-DDARKROOM_TOTAL_WIDTH=${width} \
-DDARKROOM_TOTAL_HEIGHT=${height} \
-DDARKROOM_TILE_WIDTH=${tile_width} \
-DDARKROOM_TILE_HEIGHT=${tile_height} \
-DDARKROOM_OFFSET_X=${x} \
-DDARKROOM_OFFSET_Y=${y} \
$(cd $(dirname $0); pwd)/darkcult.cpp && ${binname} > ${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"

View file

@ -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 <cstddef>
#include <iostream>
#include <iomanip>
#include <opencv/cv.h>
#include <opencv/highgui.h>
#include <opencv/cv.hpp>
#include <opencv/highgui.hpp>
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
;
}