fix darkcult: use imagemagick -> netpbm

This commit is contained in:
bolero-MURAKAMI 2013-09-21 13:56:23 +09:00
parent 3e33de25eb
commit a5a7ae1d7a
5 changed files with 239 additions and 45 deletions

View file

@ -11,6 +11,8 @@ 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=()
declare -a include_paths
include_paths=()
force=0
declare -A version_specific_options
version_specific_options=(
@ -36,9 +38,9 @@ execute() {
fi
}
args=`getopt -o S:D:f -l stagedir:,gcc-version:,clang-version:,define:,force -- "$@"`
args=`getopt -o S:D:I:f -l stagedir:,gcc-version:,clang-version:,define:,include:,force -- "$@"`
if [ "$?" -ne 0 ]; then
echo >&2 -e ": \e[31musage: $0 [-S|--stagedir=path] [--gcc-version=versions] [--clang-version=versions] [-D|--define=identifier]* [-f|-force]\e[m"
echo >&2 -e ": \e[31musage: $0 [-S|--stagedir=path] [--gcc-version=versions] [--clang-version=versions] [-D|--define=identifier]* [-I|--include=path]* [-f|-force]\e[m"
exit 1
fi
eval set -- ${args}
@ -48,6 +50,7 @@ while [ -n "$1" ]; do
--gcc-version) gcc_version="$2"; shift 2;;
--clang-version) clang_version="$2"; shift 2;;
-D|--define) user_macros=(${user_macros[@]} "$2"); shift 2;;
-I|--include) include_paths=(${include_paths[@]} "$2"); shift 2;;
-f|--force) force=1; shift;;
--) shift; break;;
*) echo >&2 -e ": \e[31munknown option($1) used.\e[m"; exit 1;;
@ -58,6 +61,7 @@ echo ": stagedir = \"${stagedir}\""
echo ": gcc-version = (${gcc_version})"
echo ": clang-version = (${clang_version})"
echo ": user-macros = (${user_macros[*]})"
echo ": include-paths = (${include_paths[*]})"
echo ": force = ${force}"
if [ -d "${stagedir}" ]; then
@ -75,12 +79,16 @@ for user_macro in ${user_macros}; do
define_options="${define_options} -D${user_macro}"
done
for include_path in ${include_paths}; do
include_options="${include_options} -I${include_path}"
done
for version in ${gcc_version}; do
compile gcc ${version} $(cd $(dirname $0); pwd)/sprout.cpp "${define_options} ${version_specific_options[gcc-${version}]}"
compile gcc ${version} $(cd $(dirname $0); pwd)/sprout.cpp "${define_options} ${include_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}]}"
compile clang ${version} $(cd $(dirname $0); pwd)/sprout.cpp "${define_options} ${include_options} ${version_specific_options[clang-${version}]}"
done
for version in ${gcc_version}; do

View file

@ -15,23 +15,25 @@
#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);
namespace toolspr {
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;
}
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);
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;
}
return n;
}
} // namespace toolspr
int main(int argc, char* argv[]) {
if (argc < 2) {
@ -54,15 +56,15 @@ int main(int argc, char* argv[]) {
"\n"
;
if (read_chunk(it) != "RIFF") {
if (toolspr::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") {
/*auto file_size = */toolspr::read_int<std::uint32_t>(it);
if (toolspr::read_chunk(it) != "WAVE") {
std::cerr
<< "#error not WAVE format.\n"
<< std::flush
@ -70,17 +72,17 @@ int main(int argc, char* argv[]) {
return EXIT_FAILURE;
}
while (read_chunk(it) != "fmt ") {
auto chunk_size = read_int<std::uint32_t>(it);
while (toolspr::read_chunk(it) != "fmt ") {
auto chunk_size = toolspr::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);
auto fmt_size = toolspr::read_int<std::uint32_t>(it);
auto format_tag = toolspr::read_int<std::uint16_t>(it);
auto channels = toolspr::read_int<std::uint16_t>(it);
auto samples_per_sec = toolspr::read_int<std::uint32_t>(it);
auto bytes_per_sec = toolspr::read_int<std::uint32_t>(it);
auto block_size = toolspr::read_int<std::uint16_t>(it);
auto bits_per_sample = toolspr::read_int<std::uint16_t>(it);
std::cout
<< format_tag << ",\n"
<< channels << ",\n"
@ -91,11 +93,11 @@ int main(int argc, char* argv[]) {
;
std::advance(it, fmt_size - 16);
while (read_chunk(it) != "data") {
auto chunk_size = read_int<std::uint32_t>(it);
while (toolspr::read_chunk(it) != "data") {
auto chunk_size = toolspr::read_int<std::uint32_t>(it);
std::advance(it, chunk_size);
}
auto data_size = read_int<std::uint32_t>(it);
auto data_size = toolspr::read_int<std::uint32_t>(it);
std::size_t size = data_size / (bits_per_sample / CHAR_BIT);
std::cout
<< size << "\n"
@ -107,20 +109,20 @@ int main(int argc, char* argv[]) {
if (bits_per_sample == 16) {
for (std::size_t i = 1; i != size; ++i) {
std::cout
<< read_int<std::int16_t>(it) << ",\n"
<< toolspr::read_int<std::int16_t>(it) << ",\n"
;
}
std::cout
<< read_int<std::int16_t>(it) << "\n"
<< toolspr::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"
<< toolspr::read_int<std::uint8_t>(it) << ",\n"
;
}
std::cout
<< read_int<std::uint8_t>(it) << "\n"
<< toolspr::read_int<std::uint8_t>(it) << "\n"
;
}
}
@ -131,4 +133,3 @@ int main(int argc, char* argv[]) {
<< std::flush
;
}

176
tools/compost/wave_io.hpp Normal file
View file

@ -0,0 +1,176 @@
/*=============================================================================
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)
=============================================================================*/
#ifndef TOOLS_COMPOST_WAVE_IO_HPP
#define TOOLS_COMPOST_WAVE_IO_HPP
#include <climits>
#include <cstddef>
#include <cstdint>
#include <string>
#include <algorithm>
#include <ios>
#include <iostream>
#include <fstream>
#include <type_traits>
#include <unistd.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/ioctl.h>
#include <linux/soundcard.h>
namespace toolspr {
//
// output_plot
//
// output for gnuplot
//
template<typename Elem, typename Traits, typename InputRange>
std::basic_ostream<Elem, Traits>& output_plot(std::basic_ostream<Elem, Traits>& os, InputRange const& range) {
os << std::fixed;
unsigned x = 0;
for (auto const& e : range) {
os << x++ << ',' << e << '\n';
}
return os;
}
template<typename InputRange>
std::basic_ostream<Elem, Traits>& output_plot(std::string const& filename, InputRange const& range) {
std::ofstream os(filename);
output_plot(os, range);
}
//
// output_plot_real
//
// output for gnuplot (only real part)
//
template<typename Elem, typename Traits, typename InputRange>
std::basic_ostream<Elem, Traits>& output_plot_real(std::basic_ostream<Elem, Traits>& os, InputRange const& range) {
os << std::fixed;
unsigned x = 0;
for (auto const& e : range) {
os << x++ << ',' << real(e) << '\n';
}
return os;
}
template<typename InputRange>
std::basic_ostream<Elem, Traits>& output_plot_real(std::string const& filename, InputRange const& range) {
std::ofstream os(filename);
output_plot_real(os, range);
}
//
// write_chunk
// write_int
// write_wav
//
// write data for wav format
//
template<typename OutputIterator>
void write_chunk(OutputIterator& it, std::string const& s) {
it = std::copy(s.begin(), s.end(), it);
}
template<typename IntType, typename OutputIterator>
void write_int(OutputIterator& it, IntType const& n) {
for (std::size_t i = 0; i != sizeof(IntType); ++i, ++it) {
*it = static_cast<char>((static_cast<typename std::make_unsigned<IntType>::type>(n) >> (i * CHAR_BIT)) & 0xFF);
}
}
template<typename OutputIterator, typename InputRange>
void write_wav(OutputIterator& it, sprout::compost::sources::info_type const& info, InputRange const& data) {
std::size_t data_size = info.size * info.bits_per_sample / CHAR_BIT;
write_chunk(it, "RIFF");
write_int(it, 36 + data_size);
write_chunk(it, "WAVE");
write_chunk(it, "fmt ");
write_int(it, 16);
write_int(it, info.format_tag);
write_int(it, info.channels);
write_int(it, info.samples_per_sec);
write_int(it, info.bytes_per_sec);
write_int(it, info.block_size);
write_int(it, info.bits_per_sample);
write_chunk(it, "data");
write_int(it, data_size);
if (info.bits_per_sample == 16) {
for (auto e : data) {
write_int<std::int16_t>(it, e);
}
} else if (info.bits_per_sample == 8) {
for (auto e : data) {
write_int<std::uint8_t>(it, e);
}
}
}
//
// output_wav
//
// output for wav format
//
template<typename Elem, typename Traits, typename InputRange>
void output_wav(std::basic_ostream<Elem, Traits>& os, sprout::compost::sources::info_type const& info, InputRange const& data) {
std::ostreambuf_iterator<Elem> it(os);
write_wav(it, info, data);
}
template<typename InputRange>
void output_wav(std::string const& filename, sprout::compost::sources::info_type const& info, InputRange const& data) {
std::ofstream os(filename, std::ios_base::out | std::ios_base::binary);
output_wav(os, info, data);
}
//
// setup_dev_dsp
//
// Setting up dsp device
//
int setup_dev_dsp(sprout::compost::sources::info_type const& info) {
/* open of dsp device */
int fd = open("/dev/dsp", O_RDWR);
if (fd < 0) {
std::cerr << "open of /dev/dsp failed" << std::endl;
return -1;
}
/* initializations of dsp device */
int arg = 0;
int status = 0;
/* sampling bit rate */
arg = info.bits_per_sample;
status = ioctl(fd, SOUND_PCM_WRITE_BITS, &arg);
if (status == -1 || arg != info.bits_per_sample) {
return -1;
}
/* stereo or monoral */
arg = info.channels;
status = ioctl(fd, SOUND_PCM_WRITE_CHANNELS, &arg);
if (status == -1 || arg != info.channels) {
return -1;
}
/* sampling frequency */
arg = info.samples_per_sec;
status = ioctl(fd, SOUND_PCM_WRITE_RATE, &arg);
if (status == -1 || arg != static_cast<int>(info.samples_per_sec)) {
return -1;
}
return fd;
}
//
// write_dev_dsp
//
// write to dsp device
//
ssize_t write_dev_dsp(int fd, void const* buf, std::size_t n) {
return write(fd, buf, n);
}
} // namespace toolspr
#endif // #ifndef TOOLS_COMPOST_WAVE_IO_HPP

View file

@ -7,7 +7,7 @@
# 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)
# requires: Netpbm (http://netpbm.sourceforge.net/)
#
src="../../example/darkroom/two_spheres.hpp"
stagedir="darkroom"
@ -15,11 +15,13 @@ width=16
height=16
tile_width=16
tile_height=16
declare -a include_paths
include_paths=()
force=0
args=`getopt -o s:S:w:h:W:H:f -l source:,stagedir:,width:,height:,tile-width:,tile-height:,force -- "$@"`
args=`getopt -o s:S:w:h:W:H:I:f -l source:,stagedir:,width:,height:,tile-width:,tile-height:,include:,force -- "$@"`
if [ "$?" -ne 0 ]; then
echo >&2 -e ": \e[31musage: $0 [-s|--source=file] [-S|--stagedir=path] [-w|--width=value] [-h|--height=value] [-W|--tile-width=value] [-H|--tile-height=value] [-f|-force]\e[m"
echo >&2 -e ": \e[31musage: $0 [-s|--source=file] [-S|--stagedir=path] [-w|--width=value] [-h|--height=value] [-W|--tile-width=value] [-H|--tile-height=value] [-I|--include=path]* [-f|-force]\e[m"
exit 1
fi
eval set -- ${args}
@ -31,6 +33,7 @@ while [ -n "$1" ]; do
-h|--height) height=$2; shift 2;;
-W|--tile-width) tile_width=$2; shift 2;;
-H|--tile-height) tile_height=$2; shift 2;;
-I|--include) include_paths=(${include_paths[@]} "$2"); shift 2;;
-f|--force) force=1; shift;;
--) shift; break;;
*) echo >&2 -e ": \e[31munknown option($1) used.\e[m"; exit 1;;
@ -44,6 +47,7 @@ echo ": width = ${width}"
echo ": height = ${height}"
echo ": tile-width = ${tile_width}"
echo ": tile-height = ${tile_height}"
echo ": include-paths = (${include_paths[*]})"
echo ": force = ${force}"
if [ ! -f "${src}" -a ! -f "$(cd $(dirname $0); pwd)/${src}" ]; then
@ -62,6 +66,10 @@ else
mkdir -p ${stagedir}
fi
for include_path in ${include_paths}; do
include_options="${include_options} -I${include_path}"
done
echo ": start."
start=${SECONDS}
@ -73,6 +81,7 @@ for ((y=0; y<height; y+=tile_height)); do
mkdir -p ${stagedir}/${y}/
binname=${stagedir}/${y}/${x}.out
g++ -o ${binname} -std=c++11 \
${include_options} \
-DDARKROOM_SOURCE="\"${src}\"" \
-DDARKROOM_TOTAL_WIDTH=${width} \
-DDARKROOM_TOTAL_HEIGHT=${height} \
@ -81,17 +90,18 @@ for ((y=0; y<height; y+=tile_height)); do
-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}/ > /dev/null
convert +append $(ls *.ppm | sort -n) ../${y}.ppm
# convert +append $(ls *.ppm | sort -n) ../${y}.ppm
pnmcat -lr $(ls *.ppm | sort -n) > ../${y}.ppm
popd > /dev/null
let "y_elapsed=${SECONDS}-${y_start}"
echo ": elapsed = ${y_elapsed}s"
done
pushd ${stagedir} > /dev/null
convert -append $(ls *.ppm | sort -n) out.ppm
#convert -append $(ls *.ppm | sort -n) out.ppm
pnmcat -tb $(ls *.ppm | sort -n) > out.ppm
popd > /dev/null
let "elapsed=${SECONDS}-${start}"

View file

@ -69,4 +69,3 @@ int main(int argc, char* argv[]) {
<< std::flush
;
}