mirror of
https://github.com/bolero-MURAKAMI/Sprout
synced 2025-08-03 12:49:50 +00:00
fix darkcult: use imagemagick -> netpbm
This commit is contained in:
parent
3e33de25eb
commit
a5a7ae1d7a
5 changed files with 239 additions and 45 deletions
|
@ -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
|
||||
;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue