Skip to content
Closed

OIIO #143

Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
95 changes: 95 additions & 0 deletions include/rawtoaces/cache_base.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
// Copyright Contributors to the rawtoaces project.
// SPDX-License-Identifier: Apache-2.0
// https://github.com/AcademySoftwareFoundation/rawtoaces

#include <iostream>
#include <filesystem>

#include <string>
#include <list>
#include <variant>

#include <rawtoaces/metadata.h>

namespace rta
{
namespace cache
{

template <class CacheEntryData> class CacheEntryDescriptor
{
public:
virtual size_t map_index() const = 0;
virtual bool fetch( CacheEntryData &data, int verbosity = 0 ) const = 0;
virtual bool operator==( const CacheEntryDescriptor &other ) const = 0;

// Each subclass must also implement the folowing 2 methods.
// Not sure how to declare them here.

// friend std::ostream& operator<< (std::ostream& stream, const DescriptorBase& descriptor);
// std::tuple<Types && ...> construct_entry() const
};

template <class Descriptor, class CacheEntryData, size_t size> class CacheBase
{
public:
const CacheEntryData &fetch( const Descriptor &descriptor )
{
size_t map_index = descriptor.map_index();

std::list<std::pair<Descriptor, CacheEntryData>> &map =
_maps[map_index];

if ( verbosity > 0 )
{
std::cerr << name << ": searching for a " << descriptor;
}

for ( auto iter = map.begin(); iter != map.end(); ++iter )
{
if ( iter->first == descriptor )
{
if ( iter != map.begin() )
{
map.splice( map.begin(), map, iter, std::next( iter ) );
}

if ( verbosity > 0 )
{
std::cerr << name << ": found in cache!" << std::endl;
}
return map.front().second;
}
}

if ( map.size() == capacity )
{
map.pop_back();
}

if ( verbosity > 0 )
{
std::cerr << name << ": not found. Calculating a new entry."
<< std::endl;
}

map.emplace_front(
std::piecewise_construct,
std::forward_as_tuple( descriptor ),
descriptor.construct_entry() );

CacheEntryData &data = map.front().second;
descriptor.fetch( data, verbosity );
return data;
};

int capacity = 10;
int verbosity = 0;
std::string name = "Cache";

private:
std::list<std::pair<Descriptor, CacheEntryData>> _maps[size];
};

} // namespace cache
} // namespace rta
29 changes: 29 additions & 0 deletions include/rawtoaces/metadata.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,35 @@ struct Metadata
std::vector<double> neutralRGB;

double baselineExposure;

friend bool operator==( const Metadata &m1, const Metadata &m2 )
{
if ( m1.calibrationIlluminant1 != m2.calibrationIlluminant1 )
return false;
if ( m1.calibrationIlluminant2 != m2.calibrationIlluminant2 )
return false;
if ( m1.baselineExposure != m2.baselineExposure )
return false;
if ( m1.analogBalance != m2.analogBalance )
return false;
if ( m1.neutralRGB != m2.neutralRGB )
return false;
if ( m1.cameraCalibration1 != m2.cameraCalibration1 )
return false;
if ( m1.cameraCalibration2 != m2.cameraCalibration2 )
return false;
if ( m1.xyz2rgbMatrix1 != m2.xyz2rgbMatrix1 )
return false;
if ( m1.xyz2rgbMatrix2 != m2.xyz2rgbMatrix2 )
return false;

return true;
}

friend bool operator!=( const Metadata &m1, const Metadata &m2 )
{
return !( m1 == m2 );
}
};

} // namespace rta
Expand Down
3 changes: 3 additions & 0 deletions src/rawtoaces2/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,7 @@ target_link_libraries ( rawtoaces2
rawtoaces_util2
)


set_target_properties(rawtoaces2 PROPERTIES XCODE_SCHEME_ARGUMENTS "${CMAKE_XCODE_SCHEME_ARGUMENTS}" )

install( TARGETS rawtoaces2 DESTINATION bin )
4 changes: 2 additions & 2 deletions src/rawtoaces_idt/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ install(FILES
${PROJECT_SOURCE_DIR}/include/rawtoaces/define.h
${PROJECT_SOURCE_DIR}/include/rawtoaces/mathOps.h
${PROJECT_SOURCE_DIR}/include/rawtoaces/rta.h

DESTINATION include/rawtoaces
${PROJECT_SOURCE_DIR}/include/rawtoaces/metadata.h
DESTINATION include/rawtoaces
)

install( TARGETS ${RAWTOACESIDTLIB} DESTINATION lib )
6 changes: 5 additions & 1 deletion src/rawtoaces_util2/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@ cmake_minimum_required(VERSION 3.10)
include_directories( "${CMAKE_CURRENT_SOURCE_DIR}" )

add_library ( rawtoaces_util2 ${DO_SHARED}
transform_cache.cpp
transform_cache.h
rawtoaces_util.cpp
${PROJECT_SOURCE_DIR}/include/rawtoaces/rawtoaces_util.h
${PROJECT_SOURCE_DIR}/include/rawtoaces/cache_base.h
)

set_property(TARGET rawtoaces_util2 PROPERTY CXX_STANDARD 17)
Expand Down Expand Up @@ -31,7 +34,8 @@ set_target_properties( rawtoaces_util2 PROPERTIES

install(
FILES
${PROJECT_SOURCE_DIR}/include/rawtoaces/rawtoaces_util.h
${PROJECT_SOURCE_DIR}/include/rawtoaces/rawtoaces_util.h
${PROJECT_SOURCE_DIR}/include/rawtoaces/cache_base.h
DESTINATION include/rawtoaces
)

Expand Down
Loading
Loading