|
21 | 21 | #include "strformat.h"
|
22 | 22 | #include "vbiparse.h"
|
23 | 23 |
|
| 24 | +#include <array> |
24 | 25 | #include <cassert>
|
25 | 26 | #include <cctype>
|
26 | 27 | #include <cstdio>
|
@@ -616,11 +617,11 @@ static clock_t lastprogress = 0;
|
616 | 617 |
|
617 | 618 |
|
618 | 619 | // default compressors
|
619 |
| -static const chd_codec_type s_no_compression[4] = { CHD_CODEC_NONE, CHD_CODEC_NONE, CHD_CODEC_NONE, CHD_CODEC_NONE }; |
620 |
| -static const chd_codec_type s_default_raw_compression[4] = { CHD_CODEC_LZMA, CHD_CODEC_ZLIB, CHD_CODEC_HUFFMAN, CHD_CODEC_FLAC }; |
621 |
| -static const chd_codec_type s_default_hd_compression[4] = { CHD_CODEC_LZMA, CHD_CODEC_ZLIB, CHD_CODEC_HUFFMAN, CHD_CODEC_FLAC }; |
622 |
| -static const chd_codec_type s_default_cd_compression[4] = { CHD_CODEC_CD_LZMA, CHD_CODEC_CD_ZLIB, CHD_CODEC_CD_FLAC }; |
623 |
| -static const chd_codec_type s_default_ld_compression[4] = { CHD_CODEC_AVHUFF }; |
| 620 | +static const std::array<chd_codec_type, 4> s_no_compression = { CHD_CODEC_NONE, CHD_CODEC_NONE, CHD_CODEC_NONE, CHD_CODEC_NONE }; |
| 621 | +static const std::array<chd_codec_type, 4> s_default_raw_compression = { CHD_CODEC_LZMA, CHD_CODEC_ZLIB, CHD_CODEC_HUFFMAN, CHD_CODEC_FLAC }; |
| 622 | +static const std::array<chd_codec_type, 4> s_default_hd_compression = { CHD_CODEC_LZMA, CHD_CODEC_ZLIB, CHD_CODEC_HUFFMAN, CHD_CODEC_FLAC }; |
| 623 | +static const std::array<chd_codec_type, 4> s_default_cd_compression = { CHD_CODEC_CD_LZMA, CHD_CODEC_CD_ZLIB, CHD_CODEC_CD_FLAC }; |
| 624 | +static const std::array<chd_codec_type, 4> s_default_ld_compression = { CHD_CODEC_AVHUFF }; |
624 | 625 |
|
625 | 626 |
|
626 | 627 | // descriptions for each option
|
@@ -1302,7 +1303,7 @@ static uint32_t parse_hunk_size(
|
1302 | 1303 | // compression parameter string
|
1303 | 1304 | //-------------------------------------------------
|
1304 | 1305 |
|
1305 |
| -static void parse_compression(const parameters_map ¶ms, const chd_codec_type (&defaults)[4], const chd_file &output_parent, chd_codec_type compression[4]) |
| 1306 | +static void parse_compression(const parameters_map ¶ms, const std::array<chd_codec_type, 4> &defaults, const chd_file &output_parent, chd_codec_type compression[4]) |
1306 | 1307 | {
|
1307 | 1308 | // TODO: should we default to the same compression as the output parent?
|
1308 | 1309 | std::copy(std::begin(defaults), std::end(defaults), compression);
|
@@ -2345,6 +2346,39 @@ static void do_create_ld(parameters_map ¶ms)
|
2345 | 2346 | }
|
2346 | 2347 |
|
2347 | 2348 |
|
| 2349 | +//------------------------------------------------- |
| 2350 | +// get_compression_defaults - use CHD metadata to |
| 2351 | +// pick the preferred type |
| 2352 | +//------------------------------------------------- |
| 2353 | + |
| 2354 | +static const std::array<chd_codec_type, 4> &get_compression_defaults(chd_file &input_chd) |
| 2355 | +{ |
| 2356 | + std::error_condition err = input_chd.check_is_hd(); |
| 2357 | + if (err == chd_file::error::METADATA_NOT_FOUND) |
| 2358 | + err = input_chd.check_is_dvd(); |
| 2359 | + if (!err) |
| 2360 | + return s_default_hd_compression; |
| 2361 | + if (err != chd_file::error::METADATA_NOT_FOUND) |
| 2362 | + throw err; |
| 2363 | + |
| 2364 | + err = input_chd.check_is_av(); |
| 2365 | + if (!err) |
| 2366 | + return s_default_ld_compression; |
| 2367 | + if (err != chd_file::error::METADATA_NOT_FOUND) |
| 2368 | + throw err; |
| 2369 | + |
| 2370 | + err = input_chd.check_is_cd(); |
| 2371 | + if (err == chd_file::error::METADATA_NOT_FOUND) |
| 2372 | + err = input_chd.check_is_gd(); |
| 2373 | + if (!err) |
| 2374 | + return s_default_cd_compression; |
| 2375 | + if (err != chd_file::error::METADATA_NOT_FOUND) |
| 2376 | + throw err; |
| 2377 | + |
| 2378 | + return s_default_raw_compression; |
| 2379 | +} |
| 2380 | + |
| 2381 | + |
2348 | 2382 | //-------------------------------------------------
|
2349 | 2383 | // do_copy - create a new CHD with data from
|
2350 | 2384 | // another CHD
|
@@ -2372,14 +2406,7 @@ static void do_copy(parameters_map ¶ms)
|
2372 | 2406 |
|
2373 | 2407 | // process compression; we default to our current preferences using metadata to pick the type
|
2374 | 2408 | chd_codec_type compression[4];
|
2375 |
| - if (!input_chd.check_is_hd() || !input_chd.check_is_dvd()) |
2376 |
| - parse_compression(params, s_default_hd_compression, output_parent, compression); |
2377 |
| - else if (!input_chd.check_is_av()) |
2378 |
| - parse_compression(params, s_default_ld_compression, output_parent, compression); |
2379 |
| - else if (!input_chd.check_is_cd() || !input_chd.check_is_gd()) |
2380 |
| - parse_compression(params, s_default_cd_compression, output_parent, compression); |
2381 |
| - else |
2382 |
| - parse_compression(params, s_default_raw_compression, output_parent, compression); |
| 2409 | + parse_compression(params, get_compression_defaults(input_chd), output_parent, compression); |
2383 | 2410 |
|
2384 | 2411 | // process numprocessors
|
2385 | 2412 | parse_numprocessors(params);
|
|
0 commit comments