Skip to content

Commit f2aacfb

Browse files
committed
add --disable-cache
Signed-off-by: Anton Dukhovnikov <[email protected]>
1 parent 7665b22 commit f2aacfb

File tree

4 files changed

+133
-103
lines changed

4 files changed

+133
-103
lines changed

include/rawtoaces/cache_base.h

Lines changed: 34 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -40,37 +40,49 @@ template <class Descriptor, class CacheEntryData, size_t size> class CacheBase
4040
std::list<std::pair<Descriptor, CacheEntryData>> &map =
4141
_maps[map_index];
4242

43-
if ( verbosity > 0 )
43+
if ( disabled )
4444
{
45-
std::cerr << name << ": searching for a " << descriptor;
45+
if ( verbosity > 0 )
46+
{
47+
std::cerr << name << ": disabled " << std::endl;
48+
}
49+
map.clear();
4650
}
47-
48-
for ( auto iter = map.begin(); iter != map.end(); ++iter )
51+
else
4952
{
50-
if ( iter->first == descriptor )
53+
54+
if ( verbosity > 0 )
5155
{
52-
if ( iter != map.begin() )
53-
{
54-
map.splice( map.begin(), map, iter, std::next( iter ) );
55-
}
56+
std::cerr << name << ": searching for a " << descriptor;
57+
}
5658

57-
if ( verbosity > 0 )
59+
for ( auto iter = map.begin(); iter != map.end(); ++iter )
60+
{
61+
if ( iter->first == descriptor )
5862
{
59-
std::cerr << name << ": found in cache!" << std::endl;
63+
if ( iter != map.begin() )
64+
{
65+
map.splice( map.begin(), map, iter, std::next( iter ) );
66+
}
67+
68+
if ( verbosity > 0 )
69+
{
70+
std::cerr << name << ": found in cache!" << std::endl;
71+
}
72+
return map.front().second;
6073
}
61-
return map.front().second;
6274
}
63-
}
6475

65-
if ( map.size() == capacity )
66-
{
67-
map.pop_back();
68-
}
76+
if ( map.size() == capacity )
77+
{
78+
map.pop_back();
79+
}
6980

70-
if ( verbosity > 0 )
71-
{
72-
std::cerr << name << ": not found. Calculating a new entry."
73-
<< std::endl;
81+
if ( verbosity > 0 )
82+
{
83+
std::cerr << name << ": not found. Calculating a new entry."
84+
<< std::endl;
85+
}
7486
}
7587

7688
map.emplace_front(
@@ -83,6 +95,7 @@ template <class Descriptor, class CacheEntryData, size_t size> class CacheBase
8395
return data;
8496
};
8597

98+
bool disabled = false;
8699
int capacity = 10;
87100
int verbosity = 0;
88101
std::string name = "Cache";

include/rawtoaces/rawtoaces_util.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,9 @@ class ImageConverter
8383
int cropbox[4] = { 0, 0, 0, 0 };
8484
int verbosity = 0;
8585

86-
bool overwrite = false;
87-
bool create_dirs = false;
86+
bool disable_cache = false;
87+
bool overwrite = false;
88+
bool create_dirs = false;
8889
std::string output_dir;
8990

9091
/// Initialise the parser object with all the command line parameters

src/rawtoaces2/main.cpp

Lines changed: 87 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,31 @@
88

99
using namespace rta;
1010

11+
bool check_and_add(
12+
const std::filesystem::path &path, std::vector<std::string> &batch )
13+
{
14+
if ( std::filesystem::is_regular_file( path ) ||
15+
std::filesystem::is_symlink( path ) )
16+
{
17+
auto e = path.extension();
18+
19+
if ( e == ".exr" || e == ".EXR" )
20+
return false;
21+
if ( e == ".jpg" || e == ".JPG" )
22+
return false;
23+
if ( e == ".jpeg" || e == ".JPEG" )
24+
return false;
25+
26+
std::string str = path.string();
27+
batch.push_back( str );
28+
}
29+
else
30+
{
31+
std::cerr << "Not a regular file: " << path << std::endl;
32+
}
33+
return true;
34+
}
35+
1136
int main( int argc, const char *argv[] )
1237
{
1338
OIIO::ArgParse argParse;
@@ -26,9 +51,11 @@ int main( int argc, const char *argv[] )
2651
return 1;
2752
}
2853

29-
auto files = argParse["filename"].as_vec<std::string>();
30-
std::vector<std::string> files_to_convert;
54+
// Create a separate batch for each input directory.
55+
// Reserve the first batch for the individual input files.
56+
std::vector<std::vector<std::string>> batches( 1 );
3157

58+
auto files = argParse["filename"].as_vec<std::string>();
3259
for ( auto filename: files )
3360
{
3461
if ( !std::filesystem::exists( filename ) )
@@ -42,102 +69,85 @@ int main( int argc, const char *argv[] )
4269

4370
if ( std::filesystem::is_directory( filename ) )
4471
{
72+
std::vector<std::string> &curr_batch = batches.emplace_back();
4573
auto it = std::filesystem::directory_iterator( filename );
4674

4775
for ( auto filename2: it )
4876
{
49-
if ( std::filesystem::is_regular_file( filename2 ) ||
50-
std::filesystem::is_symlink( filename2 ) )
51-
{
52-
auto e = filename2.path().extension();
53-
54-
if ( e == ".exr" || e == ".EXR" )
55-
continue;
56-
if ( e == ".jpg" || e == ".JPG" )
57-
continue;
58-
if ( e == ".jpeg" || e == ".JPEG" )
59-
continue;
60-
61-
files_to_convert.push_back( filename2.path().string() );
62-
}
77+
if ( !check_and_add( filename2, curr_batch ) )
78+
continue;
6379
}
6480
}
65-
else if (
66-
std::filesystem::is_regular_file( filename ) ||
67-
std::filesystem::is_symlink( filename ) )
68-
{
69-
auto e = std::filesystem::path( filename ).extension();
70-
71-
if ( e == ".exr" || e == ".EXR" )
72-
continue;
73-
if ( e == ".jpg" || e == ".JPG" )
74-
continue;
75-
if ( e == ".jpeg" || e == ".JPEG" )
76-
continue;
77-
78-
files_to_convert.push_back( filename );
79-
}
8081
else
8182
{
82-
std::cerr << "Not a file or directory: " << filename << std::endl;
83-
return 1;
83+
if ( !check_and_add( filename, batches[0] ) )
84+
continue;
8485
}
8586
}
8687

8788
bool result = true;
88-
for ( auto const &input_filename: files_to_convert )
89+
for ( auto const &batch: batches )
8990
{
90-
std::string output_filename = input_filename;
91-
if ( !converter.make_output_path( output_filename ) )
92-
continue;
91+
for ( auto const &input_filename: batch )
92+
{
93+
std::string output_filename = input_filename;
94+
if ( !converter.make_output_path( output_filename ) )
95+
continue;
9396

94-
OIIO::ParamValueList options;
97+
OIIO::ParamValueList options;
9598

96-
if ( !converter.configure( input_filename, options ) )
97-
{
98-
std::cerr << "Failed to configure the reader for the file: "
99-
<< input_filename << std::endl;
100-
result = false;
101-
continue;
102-
}
99+
if ( !converter.configure( input_filename, options ) )
100+
{
101+
std::cerr << "Failed to configure the reader for the file: "
102+
<< input_filename << std::endl;
103+
result = false;
104+
continue;
105+
}
103106

104-
OIIO::ImageSpec imageSpec;
105-
imageSpec.extra_attribs = options;
107+
OIIO::ImageSpec imageSpec;
108+
imageSpec.extra_attribs = options;
106109

107-
OIIO::ImageBuf buffer = OIIO::ImageBuf(
108-
input_filename, 0, 0, nullptr, &imageSpec, nullptr );
110+
OIIO::ImageBuf buffer = OIIO::ImageBuf(
111+
input_filename, 0, 0, nullptr, &imageSpec, nullptr );
109112

110-
if ( !buffer.read(
111-
0, 0, 0, buffer.nchannels(), true, OIIO::TypeDesc::FLOAT ) )
112-
{
113-
std::cerr << "Failed to read for the file: " << input_filename
114-
<< std::endl;
115-
result = false;
116-
continue;
117-
}
113+
if ( !buffer.read(
114+
0,
115+
0,
116+
0,
117+
buffer.nchannels(),
118+
true,
119+
OIIO::TypeDesc::FLOAT ) )
120+
{
121+
std::cerr << "Failed to read for the file: " << input_filename
122+
<< std::endl;
123+
result = false;
124+
continue;
125+
}
118126

119-
if ( !converter.apply_matrix( buffer, buffer ) )
120-
{
121-
std::cerr << "Failed to apply colour space conversion to the file: "
122-
<< input_filename << std::endl;
123-
result = false;
124-
continue;
125-
}
127+
if ( !converter.apply_matrix( buffer, buffer ) )
128+
{
129+
std::cerr
130+
<< "Failed to apply colour space conversion to the file: "
131+
<< input_filename << std::endl;
132+
result = false;
133+
continue;
134+
}
126135

127-
if ( !converter.apply_scale( buffer, buffer ) )
128-
{
129-
std::cerr << "Failed to apply scale to the file: " << input_filename
130-
<< std::endl;
131-
result = false;
132-
continue;
133-
}
136+
if ( !converter.apply_scale( buffer, buffer ) )
137+
{
138+
std::cerr << "Failed to apply scale to the file: "
139+
<< input_filename << std::endl;
140+
result = false;
141+
continue;
142+
}
134143

135-
if ( !converter.save( output_filename, buffer ) )
136-
{
137-
std::cerr << "Failed to save the file: " << output_filename
138-
<< std::endl;
139-
result = false;
140-
continue;
144+
if ( !converter.save( output_filename, buffer ) )
145+
{
146+
std::cerr << "Failed to save the file: " << output_filename
147+
<< std::endl;
148+
result = false;
149+
continue;
150+
}
141151
}
142152
}
143153

src/rawtoaces_util2/rawtoaces_util.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,10 @@ void ImageConverter::init_parser( OIIO::ArgParse &argParse )
212212
.help( "Create output directories if they don't exist." )
213213
.action( OIIO::ArgParse::store_true() );
214214

215+
argParse.arg( "--disable-cache" )
216+
.help( "Disable the colour space transform cache." )
217+
.action( OIIO::ArgParse::store_true() );
218+
215219
argParse.separator( "Raw conversion options:" );
216220

217221
argParse.arg( "--no-auto-bright" )
@@ -509,9 +513,10 @@ bool ImageConverter::parse_params( const OIIO::ArgParse &argParse )
509513
highlight_mode = argParse["highlight-mode"].get<int>();
510514
flip = argParse["flip"].get<int>();
511515

512-
overwrite = argParse["overwrite"].get<int>();
513-
create_dirs = argParse["create-dirs"].get<int>();
514-
output_dir = argParse["output-dir"].get();
516+
disable_cache = argParse["disable-cache"].get<int>();
517+
overwrite = argParse["overwrite"].get<int>();
518+
create_dirs = argParse["create-dirs"].get<int>();
519+
output_dir = argParse["output-dir"].get();
515520

516521
return true;
517522
}
@@ -919,6 +924,7 @@ void ImageConverter::prepareIDT_spectral(
919924
descriptor.value = lower_illuminant;
920925
}
921926

927+
transform_cache.disabled = disable_cache;
922928
transform_cache.verbosity = verbosity;
923929
const cache::TransformCacheEntryData &wb_data =
924930
transform_cache.fetch( descriptor );

0 commit comments

Comments
 (0)