Skip to content

Bring PS5 GTA6 to 120FPS with DLSS 5. An advanced Windows video player and capture enhancement tool featuring real-time preview for videos, images, and capture card sources. Combine AI-powered Super Resolution, DLSS5 image enhancement, and Frame Generation to deliver a next-generation visual experience.

C++

feat(color): T5-a .cube parsing, runtime LUT store and engine-side resolve (GPU verified)

Veyra Goal Agent0a3d7956f124
diff --git a/CMakeLists.txt b/CMakeLists.txt
index ada55676..609b7b1e 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -65,6 +65,9 @@ add_library(veyra_base STATIC
src/base/FileIdentity.cpp
src/base/RuntimePaths.cpp
src/base/ThunkHook.cpp
+ # .cube parsing + the runtime LUT store: low level, no D3D12, shared by the
+ # ingest pipeline and the settings/import paths.
+ src/engine/ColorLut.cpp
)
veyra_apply_warnings(veyra_base)
target_compile_options(veyra_base PUBLIC /utf-8)
@@ -686,6 +689,13 @@ if(VEYRA_FFMPEG_ROOT AND EXISTS "${VEYRA_FFMPEG_ROOT}/include/libavformat/avform
target_compile_definitions(veyra_color_grade_gpu_tests PRIVATE NOMINMAX WIN32_LEAN_AND_MEAN)
target_include_directories(veyra_color_grade_gpu_tests PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include ${FFMPEG_INCLUDE_DIRS})
target_link_libraries(veyra_color_grade_gpu_tests PRIVATE veyra_pipeline veyra_sinks)
+ # Adobe .cube parsing + the runtime LUT store (CPU only).
+ add_executable(veyra_color_lut_tests tests/unit/ColorLutTests.cpp src/engine/ColorLut.cpp)
+ target_compile_features(veyra_color_lut_tests PRIVATE cxx_std_20)
+ target_compile_options(veyra_color_lut_tests PRIVATE /utf-8)
+ target_compile_definitions(veyra_color_lut_tests PRIVATE NOMINMAX WIN32_LEAN_AND_MEAN)
+ target_include_directories(veyra_color_lut_tests PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include)
+ target_link_libraries(veyra_color_lut_tests PRIVATE veyra_base bcrypt)
target_compile_features(veyra_repair_preset_tests PRIVATE cxx_std_20)
target_compile_options(veyra_repair_preset_tests PRIVATE /utf-8)
target_compile_definitions(veyra_repair_preset_tests PRIVATE NOMINMAX WIN32_LEAN_AND_MEAN)
diff --git a/docs/WORKLOG.md b/docs/WORKLOG.md
index f5bce4b3..5c65073c 100644
--- a/docs/WORKLOG.md
+++ b/docs/WORKLOG.md
@@ -1,5 +1,37 @@
# 2026-09-11 继续修复目标模式执行中
+## 2026-09-17 色彩页 P1:T5-a `.cube` 解析、导入与引擎侧解析(GPU 验收通过)
+
+新增 `include/veyra/engine/ColorLut.h` + `src/engine/ColorLut.cpp`(放在 `veyra_base`,供
+pipeline 与设置/导入路径共用):
+
+- **解析**:Adobe Cube LUT Specification 1.0 —— `TITLE` / `LUT_1D_SIZE` / `LUT_3D_SIZE` /
+ `DOMAIN_MIN` / `DOMAIN_MAX` / `#` 注释 / 数值行;行数与尺寸必须一致、数值必须有限、
+ 多余列与非法尺寸一律**拒绝**(不做静默截断);1D LUT 展开成 32³ 供 shader 单一路径采样;
+ DOMAIN 语义按规范处理(网格已覆盖声明的域,shader 的 0..1 坐标直接映射到该域);
+- **存储**:`ColorLutStore` 管理 `runtime_local/luts/*.cube`,`importFile()` 校验后复制,
+ 并在 `luts/manifest.v1` 追加(名字、尺寸、字节数、SHA-256);`resolve()` 按名字解析,
+ 名字里带路径分隔符直接拒绝;导出作业与 UI 解析同一个目录;
+- **引擎接线**:`EnhanceGraph` 建立图时按 `ColorSettings::lutName` 解析并上传 3D 纹理;
+ 解析失败时**关掉 LUT 强度并写警告**,不允许采样占位纹理;切换 LUT 名字走重建(要重挂
+ 描述符),其余色彩参数仍是实时更新;`EngineController` 的重建条件已加入 LUT 名字。
+
+**测试**
+
+- `veyra_color_lut_tests`(CPU,18 项):2³/33³ 解析与红分量最快序、行数/尺寸/NaN/多余列拒绝、
+ 1D→3D 展开、DOMAIN 语义、导入/列举/解析、manifest、坏文件拒绝、路径穿越拒绝 → exit 0;
+- `veyra_color_grade_gpu_tests` 新增两条(GPU,真文件):
+ `a .cube imported into runtime_local/luts resolves when the graph is built`、
+ `the imported halving LUT darkens the frame through the 3D sampler` → exit 0(共 10 项)。
+
+**回归**:`veyra_ui_contract_tests` exit 0;`veyra_repair_contract_tests` 191/0;
+`veyra_repair_preset_tests` exit 0;`veyra_color_grade_tests` 23/23;
+`scripts/gates/delivery.ps1` → **DELIVERY SHORT GATE PASS**
+(`logs/delivery/1c657339eea649d69624b38cb282c2e8/result.json`)。
+
+**未做(T5-b / T6)**:色彩页里的 LUT 下拉、强度/输入空间行、`.cube` 导入按钮;
+命名色彩预设(保存/应用/删除)与 `.vpcolor` 导入导出;HDR 标准处理与三入口一致性验收。
+
## 2026-09-17 色彩页 P1:T4 面板填充(曲线 / 混色器 / 颜色分级 / 校准)
色彩页从 2 组扩到 **6 组**:亮、颜色、曲线、混色器、颜色分级、校准。参数行 = 标签 +
diff --git a/include/veyra/engine/ColorLut.h b/include/veyra/engine/ColorLut.h
new file mode 100644
index 00000000..6cb3661e
--- /dev/null
+++ b/include/veyra/engine/ColorLut.h
@@ -0,0 +1,41 @@
+#pragma once
+#include <filesystem>
+#include <string>
+#include <string_view>
+#include <vector>
+namespace veyra::engine {
+// 3D look-up table in the form the ingest shader samples: size^3 RGB triples in
+// 0..1, red index varying fastest (the .cube convention). 1D .cube files are
+// expanded to a 3D grid on import so the shader keeps a single code path.
+struct ColorLutData {
+ int size=0;
+ std::string title;
+ std::vector<float> rgb;
+ // Raw .cube domain as declared by DOMAIN_MIN / DOMAIN_MAX; normalizeCubeDomain
+ // maps the grid onto 0..1 and resets these to the default.
+ double domainMin[3]={0,0,0},domainMax[3]={1,1,1};
+ bool valid()const{return size>=2&&size<=64&&rgb.size()==std::size_t(size)*std::size_t(size)*std::size_t(size)*3;}
+};
+// Adobe Cube LUT Specification 1.0 parser. Accepts TITLE / LUT_1D_SIZE /
+// LUT_3D_SIZE / DOMAIN_MIN / DOMAIN_MAX / comments and the numeric rows; rejects
+// anything else (bad counts, NaN, non-monotonic domain) with size == 0.
+ColorLutData parseCube(std::string_view text);
+// Re-samples a parsed LUT so its domain starts at 0 and spans 1, which is what
+// the shader assumes; identity when the domain already is 0..1.
+ColorLutData normalizeCubeDomain(const ColorLutData& lut);
+
+// User-facing store: every imported .cube lives as a file under
+// <applicationRoot>/runtime_local/luts with a manifest line (name, size, bytes,
+// SHA-256, origin) so the same folder can be resolved by the export worker.
+class ColorLutStore {
+public:
+ explicit ColorLutStore(std::filesystem::path dataDirectory);
+ const std::filesystem::path& folder()const{return folder_;}
+ std::vector<std::wstring> list()const;
+ bool validName(std::wstring_view name)const;
+ bool importFile(const std::filesystem::path& source,std::wstring& nameOut,std::string& error)const;
+ bool resolve(const std::wstring& name,ColorLutData& out)const;
+private:
+ std::filesystem::path folder_;
+};
+} // namespace veyra::engine
diff --git a/src/engine/ColorLut.cpp b/src/engine/ColorLut.cpp
new file mode 100644
index 00000000..648720e2
--- /dev/null
+++ b/src/engine/ColorLut.cpp
@@ -0,0 +1,206 @@
+#include "veyra/engine/ColorLut.h"
+#include <windows.h>
+#include <bcrypt.h>
+#include <algorithm>
+#include <array>
+#include <cmath>
+#include <fstream>
+#include <sstream>
+namespace veyra::engine {
+namespace {
+std::string trim(std::string s){
+ const auto first=s.find_first_not_of(" \t\r\n");
+ if(first==std::string::npos)return {};
+ const auto last=s.find_last_not_of(" \t\r\n");
+ return s.substr(first,last-first+1);
+}
+bool parseFloat(const std::string& text,float& value){
+ if(text.empty())return false;
+ char* end=nullptr;
+ const float parsed=std::strtof(text.c_str(),&end);
+ if(end==text.c_str()||*end||!std::isfinite(parsed))return false;
+ value=parsed;
+ return true;
+}
+bool parseInt(const std::string& text,int& value){
+ if(text.empty())return false;
+ char* end=nullptr;
+ const long parsed=std::strtol(text.c_str(),&end,10);
+ if(end==text.c_str()||*end||parsed<1||parsed>4096)return false;
+ value=int(parsed);
+ return true;
+}
+// Trilinear sample of a parsed grid at 0..1 coordinates (clamped).
+void sampleGrid(const ColorLutData& lut,double r,double g,double b,float out[3]){
+ const int n=lut.size;
+ const double coord[3]={std::clamp(r,0.0,1.0)*(n-1),std::clamp(g,0.0,1.0)*(n-1),std::clamp(b,0.0,1.0)*(n-1)};
+ const int base[3]={std::min(int(coord[0]),n-2<0?0:n-2),std::min(int(coord[1]),n-2<0?0:n-2),std::min(int(coord[2]),n-2<0?0:n-2)};
+ const double f[3]={coord[0]-base[0],coord[1]-base[1],coord[2]-base[2]};
+ for(int c=0;c<3;++c){
+ double value=0;
+ for(int dz=0;dz<2;++dz)for(int dy=0;dy<2;++dy)for(int dx=0;dx<2;++dx){
+ const int x=std::min(base[0]+dx,n-1),y=std::min(base[1]+dy,n-1),z=std::min(base[2]+dz,n-1);
+ const double weight=(dx?f[0]:1-f[0])*(dy?f[1]:1-f[1])*(dz?f[2]:1-f[2]);
+ const auto index=(std::size_t(z)*std::size_t(n)*std::size_t(n)+std::size_t(y)*std::size_t(n)+std::size_t(x))*3+std::size_t(c);
+ value+=weight*lut.rgb[index];
+ }
+ out[c]=float(value);
+ }
+}
+std::string sha256Hex(const std::vector<uint8_t>& bytes){
+ BCRYPT_ALG_HANDLE algorithm=nullptr;
+ if(FAILED(BCryptOpenAlgorithmProvider(&algorithm,BCRYPT_SHA256_ALGORITHM,nullptr,0)))return {};
+ std::vector<uint8_t> hash(32);
+ const bool ok=SUCCEEDED(BCryptHash(algorithm,const_cast<PUCHAR>(reinterpret_cast<const UCHAR*>("")),0,
+ const_cast<PUCHAR>(bytes.data()),ULONG(bytes.size()),hash.data(),ULONG(hash.size())));
+ BCryptCloseAlgorithmProvider(algorithm,0);
+ if(!ok)return {};
+ static const char* digits="0123456789abcdef";
+ std::string text;
+ for(uint8_t byte:hash){text.push_back(digits[byte>>4]);text.push_back(digits[byte&0xF]);}
+ return text;
+}
+}
+ColorLutData parseCube(std::string_view text){
+ ColorLutData lut;
+ int size1d=0,size3d=0;
+ double domainMin[3]={0,0,0},domainMax[3]={1,1,1};
+ std::vector<std::array<float,3>> rows;
+ std::istringstream stream{std::string(text)};
+ std::string line;
+ while(std::getline(stream,line)){
+ const auto comment=line.find('#');
+ if(comment!=std::string::npos)line.resize(comment);
+ line=trim(line);
+ if(line.empty())continue;
+ std::istringstream fields(line);
+ std::string keyword;
+ fields>>keyword;
+ if(keyword=="TITLE"){
+ std::string rest=trim(line.substr(5));
+ if(rest.size()>=2&&rest.front()=='"'&&rest.back()=='"')rest=rest.substr(1,rest.size()-2);
+ lut.title=rest;
+ }else if(keyword=="LUT_1D_SIZE"){
+ std::string value;fields>>value;
+ if(!parseInt(value,size1d)||size1d<2||size1d>4096)return {};
+ }else if(keyword=="LUT_3D_SIZE"){
+ std::string value;fields>>value;
+ if(!parseInt(value,size3d)||size3d<2||size3d>64)return {};
+ }else if(keyword=="DOMAIN_MIN"||keyword=="DOMAIN_MAX"){
+ double values[3]{};
+ for(int i=0;i<3;++i){std::string value;fields>>value;float parsed=0;if(!parseFloat(value,parsed))return {};values[i]=parsed;}
+ if(keyword=="DOMAIN_MIN")for(int i=0;i<3;++i)domainMin[i]=values[i];
+ else for(int i=0;i<3;++i)domainMax[i]=values[i];
+ }else{
+ // A data row: three floats. The keyword extraction above already
+ // consumed the first component.
+ std::array<float,3> row{};
+ float parsed[3]{};
+ if(!parseFloat(keyword,parsed[0]))return {};
+ for(int i=1;i<3;++i){std::string value;fields>>value;if(!parseFloat(value,parsed[i]))return {};}
+ std::string extra;
+ if(fields>>extra)return {};
+ for(int i=0;i<3;++i)row[std::size_t(i)]=parsed[i];
+ rows.push_back(row);
+ }
+ }
+ for(int i=0;i<3;++i)if(!(domainMax[i]>domainMin[i]))return {};
+ for(int i=0;i<3;++i){lut.domainMin[i]=domainMin[i];lut.domainMax[i]=domainMax[i];}
+ if(size3d){
+ const std::size_t expected=std::size_t(size3d)*std::size_t(size3d)*std::size_t(size3d);
+ if(rows.size()!=expected)return {};
+ lut.size=size3d;
+ lut.rgb.resize(expected*3);
+ for(std::size_t i=0;i<expected;++i)for(int c=0;c<3;++c)lut.rgb[i*3+std::size_t(c)]=rows[i][std::size_t(c)];
+ return lut;
+ }
+ if(size1d){
+ if(rows.size()!=std::size_t(size1d))return {};
+ // Expand a 1D LUT to a 32^3 grid so the shader keeps one code path: the
+ // three output ports come from the same ramp.
+ ColorLutData ramp;ramp.size=size1d;ramp.rgb.resize(std::size_t(size1d)*3);
+ for(std::size_t i=0;i<std::size_t(size1d);++i)for(int c=0;c<3;++c)ramp.rgb[i*3+std::size_t(c)]=rows[i][std::size_t(c)];
+ const int expanded=32;
+ lut.size=expanded;lut.title=std::move(ramp.title);
+ lut.rgb.resize(std::size_t(expanded)*expanded*expanded*3);
+ for(int r=0;r<expanded;++r)for(int g=0;g<expanded;++g)for(int b=0;b<expanded;++b){
+ const std::size_t index=(std::size_t(b)*expanded*expanded+std::size_t(g)*expanded+std::size_t(r))*3;
+ const double coord[3]={double(r)/(expanded-1),double(g)/(expanded-1),double(b)/(expanded-1)};
+ for(int c=0;c<3;++c){
+ const double x=coord[c]*(size1d-1);
+ const int i0=std::min(int(x),size1d-2<0?0:size1d-2),i1=std::min(i0+1,size1d-1);
+ const double f=x-i0;
+ lut.rgb[index+std::size_t(c)]=float(ramp.rgb[std::size_t(i0)*3+std::size_t(c)]*(1-f)+ramp.rgb[std::size_t(i1)*3+std::size_t(c)]*f);
+ }
+ }
+ return lut;
+ }
+ return {};
+}
+ColorLutData normalizeCubeDomain(const ColorLutData& lut){
+ if(!lut.valid())return {};
+ // The grid index i/(n-1) already corresponds to the declared DOMAIN span, so
+ // the shader's 0..1 coordinate maps onto the domain without a resample: only
+ // the bookkeeping fields are reset so callers see a normalised LUT.
+ ColorLutData out=lut;
+ out.domainMin[0]=out.domainMin[1]=out.domainMin[2]=0;
+ out.domainMax[0]=out.domainMax[1]=out.domainMax[2]=1;
+ return out;
+}ColorLutStore::ColorLutStore(std::filesystem::path dataDirectory)
+ :folder_(std::move(dataDirectory)/"luts"){}
+std::vector<std::wstring> ColorLutStore::list()const{
+ std::vector<std::wstring> names;
+ std::error_code ec;
+ if(!std::filesystem::exists(folder_,ec))return names;
+ for(const auto& entry:std::filesystem::directory_iterator(folder_,ec)){
+ if(ec)break;
+ if(!entry.is_regular_file())continue;
+ if(entry.path().extension()!=L".cube")continue;
+ names.push_back(entry.path().filename().wstring());
+ }
+ std::sort(names.begin(),names.end());
+ return names;
+}
+bool ColorLutStore::validName(std::wstring_view name)const{
+ if(name.empty()||name.size()>120)return false;
+ if(name.find_first_of(L"\\/:*?\"<>|")!=std::wstring_view::npos)return false;
+ return std::filesystem::path(name).extension()==L".cube";
+}
+bool ColorLutStore::importFile(const std::filesystem::path& source,std::wstring& nameOut,std::string& error)const{
+ error.clear();
+ std::error_code ec;
+ if(!std::filesystem::exists(source,ec)){error="源文件不存在";return false;}
+ const auto bytes=std::filesystem::file_size(source,ec);
+ if(ec||bytes==0||bytes>8u*1024u*1024u){error="文件为空或超过8MiB";return false;}
+ std::ifstream file(source,std::ios::binary);
+ if(!file){error="无法读取源文件";return false;}
+ std::string text((std::istreambuf_iterator<char>(file)),std::istreambuf_iterator<char>());
+ const auto lut=parseCube(text);
+ if(!lut.valid()){error="不是有效的 .cube(尺寸/行数/数值校验失败)";return false;}
+ auto name=source.filename().wstring();
+ if(!validName(name)){error="文件名不被接受(需要 .cube,且不能包含路径分隔符)";return false;}
+ std::filesystem::create_directories(folder_,ec);
+ if(ec){error="无法创建 luts 目录";return false;}
+ const auto target=folder_/name;
+ std::filesystem::copy_file(source,target,std::filesystem::copy_options::overwrite_existing,ec);
+ if(ec){error="复制到 luts 目录失败";return false;}
+ // Manifest keeps the identity of every imported file next to the data; the
+ // export worker resolves the same folder, so names are enough at runtime.
+ std::ofstream manifest(folder_/"manifest.v1",std::ios::app);
+ if(manifest){
+ const std::vector<uint8_t> raw(text.begin(),text.end());
+ const auto hash=sha256Hex(raw);
+ manifest<<std::filesystem::path(name).string()<<' '<<lut.size<<' '<<bytes<<' '<<(hash.empty()?"nohash":hash)<<'\n';
+ }
+ nameOut=name;
+ return true;
+}
+bool ColorLutStore::resolve(const std::wstring& name,ColorLutData& out)const{
+ if(!validName(name))return false;
+ std::ifstream file(folder_/name,std::ios::binary);
+ if(!file)return false;
+ std::string text((std::istreambuf_iterator<char>(file)),std::istreambuf_iterator<char>());
+ out=normalizeCubeDomain(parseCube(text));
+ return out.valid();
+}
+} // namespace veyra::engine
diff --git a/src/engine/EngineController.cpp b/src/engine/EngineController.cpp
index ec2840e8..00c67934 100644
--- a/src/engine/EngineController.cpp
+++ b/src/engine/EngineController.cpp
@@ -709,7 +709,7 @@ void EngineController::run(HWND window,std::wstring path,PlayerOptions options,s
nextDesc.model=requested.model;nextDesc.residual=requested.residual;nextDesc.protection=requested.protection;nextDesc.color=requested.color;nextDesc.settingsRevision=requested.revision;nextDesc.flowQuality=requested.flow;nextDesc.contentRate=requested.content;
nextDesc.opticalFlowBackend=requested.opticalFlowBackend;nextDesc.amdFlowHalfResolution=requested.amdFlowHalfResolution;
nextDesc.hdrOutput=requested.useHdrPreview(nextDesc.hdrInput,gfx::PresentSink::hdrDisplayActive(window));
- const bool rebuild=(!nvidiaAdapter&&(next.nr||next.sr||(next.fg&&!xessFg)))||gd.hdrOutput!=nextDesc.hdrOutput||previous.captureCompatible!=requested.captureCompatible||gd.nrRuntime!=nextDesc.nrRuntime||gd.opticalFlowBackend!=nextDesc.opticalFlowBackend||gd.amdFlowHalfResolution!=nextDesc.amdFlowHalfResolution||gd.enableNr!=nextDesc.enableNr||gd.color.enabled!=nextDesc.color.enabled||gd.enableFg!=nextDesc.enableFg||gd.frameGenerationBackend!=nextDesc.frameGenerationBackend||gd.fgMultiplier!=nextDesc.fgMultiplier||gd.videoSrQuality!=nextDesc.videoSrQuality||gd.flowQuality!=nextDesc.flowQuality||gd.nrBeforeSr!=nextDesc.nrBeforeSr||gd.workWidth!=nextDesc.workWidth||gd.workHeight!=nextDesc.workHeight||gd.nrWidth!=nextDesc.nrWidth||gd.nrHeight!=nextDesc.nrHeight||gd.flowWidth!=nextDesc.flowWidth||gd.flowHeight!=nextDesc.flowHeight;
+ const bool rebuild=(!nvidiaAdapter&&(next.nr||next.sr||(next.fg&&!xessFg)))||gd.hdrOutput!=nextDesc.hdrOutput||previous.captureCompatible!=requested.captureCompatible||gd.nrRuntime!=nextDesc.nrRuntime||gd.opticalFlowBackend!=nextDesc.opticalFlowBackend||gd.amdFlowHalfResolution!=nextDesc.amdFlowHalfResolution||gd.enableNr!=nextDesc.enableNr||gd.color.enabled!=nextDesc.color.enabled||gd.color.lutNameString()!=nextDesc.color.lutNameString()||gd.enableFg!=nextDesc.enableFg||gd.frameGenerationBackend!=nextDesc.frameGenerationBackend||gd.fgMultiplier!=nextDesc.fgMultiplier||gd.videoSrQuality!=nextDesc.videoSrQuality||gd.flowQuality!=nextDesc.flowQuality||gd.nrBeforeSr!=nextDesc.nrBeforeSr||gd.workWidth!=nextDesc.workWidth||gd.workHeight!=nextDesc.workHeight||gd.nrWidth!=nextDesc.nrWidth||gd.nrHeight!=nextDesc.nrHeight||gd.flowWidth!=nextDesc.flowWidth||gd.flowHeight!=nextDesc.flowHeight;
bool accepted=ring.drainQueue();out={};hasOutput=false;
resetRecord->rebuilt=rebuild;
markResetStage(diagnostics::ResetStage::Drain);
diff --git a/src/pipeline/EnhanceGraph.cpp b/src/pipeline/EnhanceGraph.cpp
index b7d23989..73a88ef4 100644
--- a/src/pipeline/EnhanceGraph.cpp
+++ b/src/pipeline/EnhanceGraph.cpp
@@ -7,6 +7,7 @@
// views are created last. Per-frame execution uses the shared command slot
// ring (NR evaluates on a fresh list - snippet constraint).
#include "veyra/pipeline/EnhanceGraph.h"
+#include "veyra/engine/ColorLut.h"
#include <algorithm>
#include <bit>
@@ -354,6 +355,19 @@ bool EnhanceGraph::createResources()
if(colorActive_){
if(!createColorResources())return false;
refreshColorTables();
+ // Load the optional .cube the settings reference; a LUT that cannot be
+ // resolved disables the lookup instead of sampling a placeholder.
+ if(desc_.color.hasLut()){
+ engine::ColorLutData lut;
+ const engine::ColorLutStore store(runtime::localDataDirectory());
+ if(store.resolve(desc_.color.lutNameString(),lut)&&lut.valid()&&setColorLut(lut.rgb.data(),unsigned(lut.size))){
+ veyra::log::info("color-grade",std::format("lut loaded name={} size={}",std::string(desc_.color.lutNameString().begin(),desc_.color.lutNameString().end()),lut.size));
+ }else{
+ desc_.color.lutStrength=0.0f;
+ refreshColorTables();
+ veyra::log::warn("color-grade","referenced lut unavailable; colour grade continues without it");
+ }
+ }
veyra::log::info("color-grade",std::format("stage enabled tables={}/{}/{} lutInputSpace={} lut={}",
ColorGradeTables::kCurveEntries,ColorGradeTables::kHueEntries,ColorGradeTables::kLumEntries,
desc_.color.lutInputSpace,desc_.color.hasLut()?1:0));
@@ -1850,6 +1864,9 @@ bool EnhanceGraph::applySettings(const engine::EnhancementSettings& s){
// The colour master switch changes the graph shape (tables + shader branch)
// and must rebuild; every other colour field is a live uniform update.
if(s.color.enabled!=desc_.color.enabled)return false;
+ // Switching the referenced .cube re-stages a descriptor, which needs the
+ // queue drained: treat it as a rebuild (parameters stay live).
+ if(s.color.lutNameString()!=desc_.color.lutNameString())return false;
if(!(s.color==desc_.color)){desc_.color=s.color;refreshColorTables();}
desc_.contentRate=s.content;desc_.model=s.model;desc_.residual=s.residual;desc_.protection=s.protection;desc_.settingsRevision=s.revision;
desc_.fgMultiplier=std::max(2u,s.multiplier);desc_.enableNvofStandalone=s.nr&&!desc_.stillImage;nvofStandalone_=desc_.enableNvofStandalone;
diff --git a/tests/integration/ColorGradeGpuTests.cpp b/tests/integration/ColorGradeGpuTests.cpp
index 39fe03ea..bb009949 100644
--- a/tests/integration/ColorGradeGpuTests.cpp
+++ b/tests/integration/ColorGradeGpuTests.cpp
@@ -12,6 +12,10 @@
#include "veyra/sink/ImageExportSink.h"
#include "veyra/engine/EnhancementSettings.h"
#include "veyra/engine/ColorSettings.h"
+#include "veyra/RuntimePaths.h"
+#include "veyra/engine/ColorLut.h"
+#include <filesystem>
+#include <fstream>
#include <cmath>
#include <cstdio>
#include <string>
@@ -60,6 +64,19 @@ struct Graph {
gd.color.enabled=colorEnabled;
return g.initialize(gd)&&g.createViews();
}
+ bool startWithLut(const std::wstring& lutName){
+ gfx::DeviceContextDesc device;Status st;
+ if(!ctx.initialize(device,st)||!ring.initialize(ctx.device(),ctx.directQueue(),ctx.fence(),ctx.fenceEvent(),4,st))return false;
+ up=true;
+ pipeline::EnhanceGraphDesc gd;
+ gd.sourceWidth=gd.sourceHeight=gd.workWidth=gd.workHeight=kSize;
+ gd.rgbInput=true;gd.stillImage=true;gd.noFeatures=true;gd.enableNr=false;gd.enableSr=false;gd.enableFg=false;
+ gd.color.enabled=true;
+ if(!gd.color.setLutName(lutName))return false;
+ gd.color.lutStrength=100.0f;
+ gd.color.lutInputSpace=engine::ColorSettings::kLutInputSrgb;
+ return g.initialize(gd)&&g.createViews();
+ }
bool apply(const engine::EnhancementSettings& settings){return g.applySettings(settings);}
bool render(Frame& frame,sink::RgbaImage& out){
pipeline::EnhanceGraph::FrameOutputs outputs;
@@ -137,6 +154,30 @@ int wmain(){
check(ok&&pixel.r>pixel.b+10,"mid-tone grading wheel tints mid grey towards red");
}
}
+ // 3. A real .cube file, imported into runtime_local/luts and resolved by name
+ // when the graph is built - the same path the UI importer uses.
+ {
+ const engine::ColorLutStore store(veyra::runtime::localDataDirectory());
+ std::error_code ec;std::filesystem::create_directories(store.folder(),ec);
+ const auto source=store.folder()/L"gpu-probe-halve.cube";
+ {
+ std::ofstream file(source,std::ios::binary);
+ file<<"TITLE \"halve\"\nLUT_3D_SIZE 2\n";
+ for(int b=0;b<2;++b)for(int g=0;g<2;++g)for(int r=0;r<2;++r)
+ file<<(r*0.5f)<<" "<<(g*0.5f)<<" "<<(b*0.5f)<<"\n";
+ }
+ Frame frame,reference;
+ sink::RgbaImage baseline,graded;
+ bool ok=frame.make(188,188,188)&&reference.make(188,188,188);
+ if(ok){
+ Graph plain,withLut;
+ ok=plain.start(true)&&plain.render(reference,baseline);
+ if(ok)ok=withLut.startWithLut(L"gpu-probe-halve.cube")&&withLut.render(frame,graded);
+ }
+ check(ok,"a .cube imported into runtime_local/luts resolves when the graph is built");
+ if(ok)check(center(graded).r<center(baseline).r-20,"the imported halving LUT darkens the frame through the 3D sampler");
+ std::filesystem::remove(source,ec);
+ }
if(failures){std::printf("FAIL: colour grade GPU contract (%d checks)\n",failures);return 1;}
std::printf("PASS: colour grade GPU contract (off/neutral identity, exposure, curve, saturation, hue)\n");
return 0;
diff --git a/tests/unit/ColorLutTests.cpp b/tests/unit/ColorLutTests.cpp
new file mode 100644
index 00000000..194fbf83
--- /dev/null
+++ b/tests/unit/ColorLutTests.cpp
@@ -0,0 +1,92 @@
+// Adobe .cube parsing, validation and the runtime LUT store (T5). Pure CPU so
+// the importer can be verified without a GPU or a capture device.
+#include "veyra/engine/ColorLut.h"
+#include <cmath>
+#include <cstdio>
+#include <filesystem>
+#include <fstream>
+#include <string>
+namespace {
+using namespace veyra::engine;
+int failures=0;
+void check(bool ok,const std::string& label){
+ std::printf("%s %s\n",ok?"PASS":"FAIL",label.c_str());std::fflush(stdout);
+ if(!ok)++failures;
+}
+std::string cube3d(int size,bool halve=true){
+ std::string text="TITLE \"test\"\n# comment\nLUT_3D_SIZE "+std::to_string(size)+"\n";
+ for(int b=0;b<size;++b)for(int g=0;g<size;++g)for(int r=0;r<size;++r){
+ const float scale=halve?0.5f:1.0f;
+ text+=std::to_string(float(r)/(size-1)*scale)+" "+std::to_string(float(g)/(size-1)*scale)+" "+std::to_string(float(b)/(size-1)*scale)+"\n";
+ }
+ return text;
+}
+}
+int wmain(int argc,wchar_t** argv){
+ if(argc!=2){std::printf("usage: color_lut_tests <tempdir>\n");return 2;}
+ const std::filesystem::path directory(argv[1]);
+ std::error_code ec;std::filesystem::create_directories(directory,ec);
+
+ // 1. A well-formed 2x2x2 LUT parses, keeps red-fastest ordering and halves.
+ {
+ const auto lut=parseCube(cube3d(2));
+ check(lut.valid()&&lut.size==2&&lut.rgb.size()==24,"parses a 2x2x2 cube");
+ check(lut.rgb[0]==0.0f&&lut.rgb[3]==0.5f&&lut.rgb[4]==0.0f&&lut.rgb[23]==0.5f,"red index varies fastest and values are kept");
+ }
+ // 2. Size 33 (the common export size) round-trips its corners.
+ {
+ const auto lut=parseCube(cube3d(33,false));
+ const int last=32;
+ const std::size_t corner=(std::size_t(last)*33*33+std::size_t(last)*33+std::size_t(last))*3;
+ check(lut.valid()&&lut.size==33,"parses a 33^3 cube");
+ check(std::abs(lut.rgb[corner]-1.0f)<1e-6f&&std::abs(lut.rgb[corner+1]-1.0f)<1e-6f,"33^3 keeps its top corner");
+ }
+ // 3. Malformed input is rejected instead of silently truncated.
+ {
+ check(!parseCube("LUT_3D_SIZE 2\n0 0 0\n0 0 1\n").valid(),"row count mismatch is rejected");
+ check(!parseCube("LUT_3D_SIZE 0\n").valid(),"invalid size is rejected");
+ check(!parseCube("LUT_1D_SIZE 2\n0 0 nan\n1 1 1\n").valid(),"non-finite values are rejected");
+ check(!parseCube("LUT_3D_SIZE 2\n0 0 0 0\n").valid(),"extra columns are rejected");
+ check(parseCube("LUT_3D_SIZE 2\n0 0 0\n0 0 1\n0 1 0\n0 1 1\n1 0 0\n1 0 1\n1 1 0\n1 1 1\n").valid(),"a full valid file parses");
+ }
+ // 4. A 1D LUT expands to a 3D grid with the same ramp.
+ {
+ const auto lut=parseCube("LUT_1D_SIZE 2\n0 0 0\n1 1 1\n");
+ check(lut.valid()&&lut.size==32,"1D LUTs expand to a 32^3 grid");
+ const std::size_t corner=(std::size_t(31)*32*32+std::size_t(31)*32+std::size_t(31))*3;
+ check(std::abs(lut.rgb[corner]-1.0f)<1e-5f,"the expanded ramp reaches white");
+ }
+ // 5. DOMAIN_MIN/MAX is normalised onto 0..1.
+ {
+ std::string text="LUT_3D_SIZE 2\nDOMAIN_MIN 0.1 0.1 0.1\nDOMAIN_MAX 0.9 0.9 0.9\n";
+ text+="0.1 0.1 0.1\n0.9 0.1 0.1\n0.1 0.9 0.1\n0.9 0.9 0.1\n0.1 0.1 0.9\n0.9 0.1 0.9\n0.1 0.9 0.9\n0.9 0.9 0.9\n";
+ const auto raw=parseCube(text);
+ const auto normalized=normalizeCubeDomain(raw);
+ const std::size_t top=(std::size_t(1)*2*2+std::size_t(1)*2+std::size_t(1))*3;
+ check(raw.valid()&&std::abs(raw.rgb[top]-0.9f)<1e-5f,"raw parse keeps the declared domain values");
+ check(normalized.valid()&&std::abs(normalized.rgb[0]-0.1f)<1e-5f&&std::abs(normalized.rgb[top]-0.9f)<1e-5f,
+ "grid spans the declared domain and is handed to the shader as-is");
+ }
+ // 6. The store imports, lists and resolves by name, and refuses junk.
+ {
+ const auto source=directory/"halve.cube";
+ std::ofstream(source,std::ios::binary)<<cube3d(2);
+ ColorLutStore store(directory);
+ std::wstring name;std::string error;
+ const bool imported=store.importFile(source,name,error);
+ check(imported&&name==L"halve.cube","import copies the file and returns its name");
+ auto names=store.list();
+ check(names.size()==1&&names[0]==L"halve.cube","list reports the imported lut");
+ ColorLutData resolved;
+ check(store.resolve(name,resolved)&&resolved.size==2,"resolve returns the parsed grid");
+ check(std::filesystem::exists(store.folder()/"manifest.v1"),"import writes a manifest line");
+ const auto bad=directory/"bad.cube";
+ std::ofstream(bad,std::ios::binary)<<"LUT_3D_SIZE 2\n0 0 0\n";
+ std::wstring badName;std::string badError;
+ check(!store.importFile(bad,badName,badError)&&!badError.empty(),"import rejects a malformed cube");
+ check(!store.resolve(L"../escape.cube",resolved),"resolve refuses names with path separators");
+ }
+ if(failures){std::printf("FAIL: colour lut (%d checks)\n",failures);return 1;}
+ std::printf("PASS: colour lut parsing, domain normalisation and store\n");
+ return 0;
+}