MCPcopy Create free account
hub / github.com/heygen-com/hyperframes / parseCubeLut

Function parseCubeLut

packages/core/src/colorLuts.ts:95–182  ·  view source on GitHub ↗
(input: string, options: ParseCubeLutOptions = {})

Source from the content-addressed store, hash-verified

93
94// fallow-ignore-next-line complexity
95export function parseCubeLut(input: string, options: ParseCubeLutOptions = {}): CubeLut3D {
96 const maxSize = options.maxSize ?? DEFAULT_MAX_SIZE;
97 let title: string | null = null;
98 let domainMin: CubeLutVec3 = DEFAULT_DOMAIN_MIN;
99 let domainMax: CubeLutVec3 = DEFAULT_DOMAIN_MAX;
100 let lut1dSize: number | null = null;
101 let lut3dSize: number | null = null;
102 const rows: number[] = [];
103
104 const lines = input.replace(/^\uFEFF/, "").split(/\r?\n/);
105 for (let i = 0; i < lines.length; i++) {
106 const lineNumber = i + 1;
107 const line = stripComment(lines[i] ?? "").trim();
108 if (!line) continue;
109 const parts = line.split(/\s+/);
110 const keyword = (parts[0] ?? "").toUpperCase();
111 const rest = parts.slice(1);
112
113 if (keyword === "TITLE") {
114 title = parseTitle(line);
115 continue;
116 }
117 if (keyword === "DOMAIN_MIN") {
118 domainMin = parseVec3(rest, keyword, lineNumber);
119 continue;
120 }
121 if (keyword === "DOMAIN_MAX") {
122 domainMax = parseVec3(rest, keyword, lineNumber);
123 continue;
124 }
125 if (keyword === "LUT_1D_SIZE") {
126 lut1dSize = parseSize(rest[0], keyword, lineNumber);
127 continue;
128 }
129 if (keyword === "LUT_3D_SIZE") {
130 lut3dSize = parseSize(rest[0], keyword, lineNumber);
131 if (lut3dSize > maxSize) {
132 throw new CubeLutParseError(`LUT_3D_SIZE ${lut3dSize} exceeds max ${maxSize}`, lineNumber);
133 }
134 continue;
135 }
136
137 if (!isNumericDataLine(keyword)) {
138 if (keyword.startsWith("LUT_")) {
139 throw new CubeLutParseError(`Unsupported cube keyword ${keyword}`, lineNumber);
140 }
141 continue;
142 }
143 if (!lut3dSize) {
144 if (lut1dSize) {
145 throw new CubeLutParseError("1D cube LUTs are not supported yet", lineNumber);
146 }
147 throw new CubeLutParseError("LUT data appears before LUT_3D_SIZE", lineNumber);
148 }
149 if (parts.length !== 3) {
150 throw new CubeLutParseError("LUT data rows must contain three numbers", lineNumber);
151 }
152 rows.push(

Callers 2

colorLuts.test.tsFile · 0.90
getCubeLutFunction · 0.90

Calls 7

stripCommentFunction · 0.85
parseTitleFunction · 0.85
parseVec3Function · 0.85
parseSizeFunction · 0.85
isNumericDataLineFunction · 0.85
parseFiniteNumberFunction · 0.85
validateDomainFunction · 0.85

Tested by

no test coverage detected