• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

ossia / score / 43892858954

16 Nov 2026 03:06PM UTC coverage: 61.472% (+0.3%) from 61.219%
43892858954

push

github

jcelerier
score: the open right-click box is exported in every build, so add-ons using score's knobs, sliders and spinboxes link on Windows

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KdPgufUMRpkKzaYvUs9iHW

261684 of 791694 branches covered (33.05%)

267913 of 435828 relevant lines covered (61.47%)

724440.84 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

68.72
/src/plugins/score-plugin-ui/Ui/TextureView.cpp
1
#include "TextureView.hpp"
2

3
#include <Gfx/Graph/RenderList.hpp>
4
#include <Gfx/Graph/Utils.hpp>
5

6
#include <QPainter>
7
#include <QtGui/private/qrhi_p.h>
8

9
#include <Ui/Monitor/Paint.hpp>
10

11
#include <cmath>
12

13
namespace Ui::TextureView
14
{
15
namespace
16
{
17
struct Params
18
{
19
  float luma[4];
20
  //! mode, show NaN, background, reference present
21
  int32_t config[4];
22
  //! exposure gain, zebra high, zebra low, peaking threshold
23
  float view[4];
24
  //! blend, wipe, frame counter
25
  float view2[4];
26
  //! width, height
27
  int32_t sizes[4];
28
  //! layout, slice, layer or face, rows reversed: see shownTextureGlsl
29
  int32_t shown[4];
30
};
31
static_assert(sizeof(Params) == 96);
32

33
constexpr int max_size = 8192;
34

35
const char* const shader_header = R"_(#version 450
36
layout(local_size_x = 16, local_size_y = 16) in;
37
layout(std140, binding = 0) uniform Params
38
{
39
  vec4 luma;
40
  ivec4 config;
41
  vec4 view;
42
  vec4 view2;
43
  ivec4 sizes;
44
  ivec4 shown;
45
};
46
)_";
47

48
// The input, of any kind, is read through shownTexel: binding 1
49
const char* const shader_main = R"_(
50
layout(binding = 2) uniform sampler2D refTex;
51
layout(binding = 3, rgba8) uniform writeonly image2D outImage;
52

53
// False-colour palette after the ARRI conventions, as in the Video Monitor
54
// shader of the library
55
vec3 false_color(float L)
56
{
57
  if(L < 0.005) return vec3(0.0, 0.0, 0.4);
58
  if(L < 0.02)  return vec3(0.0, 0.0, 0.8);
59
  if(L < 0.06)  return vec3(0.0, 0.4, 0.8);
60
  if(L < 0.12)  return vec3(0.0, 0.6, 0.3);
61
  if(L < 0.18)  return vec3(0.2, 0.2, 0.2);
62
  if(L < 0.25)  return vec3(0.4, 0.4, 0.4);
63
  if(L < 0.40)  return vec3(0.3, 0.6, 0.1);
64
  if(L < 0.55)  return vec3(0.5, 0.8, 0.2);
65
  if(L < 0.70)  return vec3(0.8, 0.8, 0.0);
66
  if(L < 0.85)  return vec3(1.0, 0.5, 0.0);
67
  if(L < 0.95)  return vec3(1.0, 0.2, 0.2);
68
  if(L < 1.005) return vec3(1.0, 0.0, 0.5);
69
  return vec3(1.0, 0.0, 1.0);
70
}
71

72
vec4 inputAt(ivec2 p, out bool inside)
73
{
74
  return shownTexel(p, sizes.xy, shown.x, shown.y, shown.z != 0, inside);
75
}
76

77
float lumaAt(ivec2 p)
78
{
79
  p = clamp(p, ivec2(0), sizes.xy - 1);
80
  bool inside;
81
  return dot(inputAt(p, inside).rgb * view.x, luma.rgb);
82
}
83

84
void main()
85
{
86
  ivec2 p = ivec2(gl_GlobalInvocationID.xy);
87
  if(p.x >= sizes.x || p.y >= sizes.y)
88
    return;
89
  bool inside;
90
  vec4 src = inputAt(p, inside);
91
  // Between the tiles of an overview
92
  if(!inside)
93
  {
94
    imageStore(outImage, p, vec4(0.12, 0.12, 0.12, 1.0));
95
    return;
96
  }
97
  vec3 c = src.rgb * view.x;
98
  float a = src.a;
99
  float L = dot(c, luma.rgb);
100
  int mode = config.x;
101
  float blend = view2.x;
102
  vec3 outc = c;
103

104
  if(mode == 0)
105
  {
106
    // Under the image: checkerboard, black, grey, white, magenta, or none
107
    // to show the colour whatever its alpha
108
    vec3 under;
109
    switch(config.z)
110
    {
111
      case 0: under = ((p.x / 8 + p.y / 8) % 2 == 0) ? vec3(0.42) : vec3(0.58); break;
112
      case 1: under = vec3(0.0); break;
113
      case 2: under = vec3(0.18); break;
114
      case 3: under = vec3(1.0); break;
115
      default: under = vec3(1.0, 0.0, 1.0); break;
116
    }
117
    if(config.z != 5)
118
      outc = mix(under, clamp(c, 0.0, 1.0), clamp(a, 0.0, 1.0));
119
  }
120
  else if(mode == 1) outc = vec3(c.r);
121
  else if(mode == 2) outc = vec3(c.g);
122
  else if(mode == 3) outc = vec3(c.b);
123
  else if(mode == 4) outc = vec3(a);
124
  else if(mode == 5) outc = vec3(L);
125
  else if(mode == 6)
126
  {
127
    outc = mix(clamp(c, 0.0, 1.0), false_color(L), blend);
128
  }
129
  else if(mode == 7)
130
  {
131
    float maxC = max(c.r, max(c.g, c.b));
132
    float stripe = step(0.5, fract(float(p.x + p.y) / 8.0));
133
    outc = clamp(c, 0.0, 1.0);
134
    if(maxC > view.y)
135
      outc = mix(outc, vec3(1.0, 0.0, 0.0), stripe * blend);
136
    if(maxC < view.z)
137
      outc = mix(outc, vec3(0.0, 0.0, 1.0), stripe * blend);
138
  }
139
  else if(mode == 8)
140
  {
141
    // Sobel on luma: sharp edges are in focus
142
    float tl = lumaAt(p + ivec2(-1, -1)), t = lumaAt(p + ivec2(0, -1)), tr = lumaAt(p + ivec2(1, -1));
143
    float l = lumaAt(p + ivec2(-1, 0)), r = lumaAt(p + ivec2(1, 0));
144
    float bl = lumaAt(p + ivec2(-1, 1)), b = lumaAt(p + ivec2(0, 1)), br = lumaAt(p + ivec2(1, 1));
145
    float gx = (tr + 2.0 * r + br) - (tl + 2.0 * l + bl);
146
    float gy = (bl + 2.0 * b + br) - (tl + 2.0 * t + tr);
147
    float edge = length(vec2(gx, gy));
148
    outc = clamp(c, 0.0, 1.0) * 0.6;
149
    if(edge > view.w)
150
      outc = mix(outc, vec3(1.0, 0.15, 0.15), blend + (1.0 - blend) * 0.5);
151
  }
152
  else if(mode == 9)
153
  {
154
    float stripe = step(0.5, fract(float(p.x + p.y) / 6.0));
155
    outc = clamp(c, 0.0, 1.0);
156
    if(any(lessThan(c, vec3(0.0))))
157
      outc = mix(outc, vec3(0.0, 1.0, 1.0), stripe * blend);
158
    else if(any(greaterThan(c, vec3(1.0))))
159
      outc = mix(outc, vec3(1.0, 0.0, 1.0), stripe * blend);
160
  }
161
  else if(mode == 10 || mode == 11)
162
  {
163
    vec2 uv = (vec2(p) + 0.5) / vec2(sizes.xy);
164
    vec3 ref = config.w != 0 ? textureLod(refTex, uv, 0.0).rgb * view.x : vec3(0.0);
165
    if(mode == 10)
166
    {
167
      int split = int(view2.y * float(sizes.x));
168
      outc = p.x < split ? c : ref;
169
      if(abs(p.x - split) < 1)
170
        outc = vec3(1.0);
171
    }
172
    else
173
    {
174
      outc = abs(c - ref);
175
    }
176
  }
177

178
  if(config.y != 0 && (any(isnan(src)) || any(isinf(src))))
179
  {
180
    // Blinks, so that it cannot be mistaken for content
181
    outc = (int(view2.z) / 15) % 2 == 0 ? vec3(1.0, 0.0, 1.0) : vec3(0.0, 1.0, 0.0);
182
  }
183
  imageStore(outImage, p, vec4(clamp(outc, 0.0, 1.0), 1.0));
184
}
185
)_";
186
}
187

188
Node::Node() = default;
18 ✔
189
Node::~Node() = default;
9 ✔
190

191
void Node::init(score::gfx::RenderList& r, QRhiResourceUpdateBatch& res)
10 ✔
192
{
193
  m_rhi = r.state.rhi;
10 ✔
194
  if(!m_rhi || !m_rhi->isFeatureSupported(QRhi::Compute))
10 !
195
    return;
8 ✔
196
  auto& rhi = *m_rhi;
2 ✔
197
  m_params = rhi.newBuffer(QRhiBuffer::Dynamic, QRhiBuffer::UniformBuffer, sizeof(Params));
2 ✔
198
  m_params->create();
2 ✔
199
  m_sampler = rhi.newSampler(
2 ✔
200
      QRhiSampler::Linear, QRhiSampler::Linear, QRhiSampler::None,
201
      QRhiSampler::ClampToEdge, QRhiSampler::ClampToEdge);
202
  m_sampler->create();
2 ✔
203
  resizeOutput(QSize{16, 16});
2 ✔
204

205
  // The pipeline is built once, against bindings of the same layout as the
206
  // ones each frame then points at its textures
207
  auto* empty = &r.emptyTexture();
2 ✔
208
  m_srb = rhi.newShaderResourceBindings();
2 ✔
209
  setBindings(empty, empty);
2 ✔
210
  m_boundInput = m_boundReference = empty;
2 ✔
211
  if(!m_srb->create())
2 !
212
  {
213
    delete m_srb;
×
214
    m_srb = nullptr;
×
215
    return;
×
216
  }
217
  pipeline(r, score::gfx::TextureKind::Texture2D);
2 ✔
218
}
10 ✔
219

220
QRhiComputePipeline* Node::pipeline(score::gfx::RenderList& r, score::gfx::TextureKind kind)
4 ✔
221
{
222
  // The variants differ only in the type of binding 1: all of them work with
223
  // the bindings, whatever texture these point at
224
  const int k = int(kind);
4 ✔
225
  if(m_pipelines[k] || m_failed[k] || !m_srb)
4 !
226
    return m_pipelines[k];
2 ✔
227
  QRhiComputePipeline* pl{};
2 ✔
228
  try
229
  {
230
    QString src = shader_header;
2 !
231
    src += score::gfx::shownTextureGlsl(kind, 1, "inTex");
2 !
232
    src += shader_main;
2 !
233
    pl = m_rhi->newComputePipeline();
2 !
234
    pl->setShaderStage({QRhiShaderStage::Compute, score::gfx::makeCompute(r.state, src)});
2 !
235
    pl->setShaderResourceBindings(m_srb);
2 !
236
    if(!pl->create())
2 !
237
    {
238
      delete pl;
×
239
      pl = nullptr;
×
240
    }
×
241
  }
2 ✔
242
  catch(...)
243
  {
244
    delete pl;
×
245
    pl = nullptr;
×
246
  }
×
247
  m_pipelines[k] = pl;
2 ✔
248
  m_failed[k] = !pl;
2 ✔
249
  return pl;
2 ✔
250
}
4 ✔
251

252
bool Node::resizeOutput(QSize sz)
4 ✔
253
{
254
  if(m_out && m_out->pixelSize() == sz)
4 !
255
    return false;
×
256
  if(m_out)
4 ✔
257
    m_out->deleteLater();
2 ✔
258
  m_out = m_rhi->newTexture(QRhiTexture::RGBA8, sz, 1, QRhiTexture::UsedWithLoadStore);
4 ✔
259
  m_out->create();
4 ✔
260
  outputs.texture.texture.handle = m_out;
4 ✔
261
  outputs.texture.texture.width = sz.width();
4 ✔
262
  outputs.texture.texture.height = sz.height();
4 ✔
263
  outputs.texture.texture.format = halp::gpu_texture::RGBA8;
4 ✔
264
  return true;
4 ✔
265
}
4 ✔
266

267
void Node::setBindings(QRhiTexture* input, QRhiTexture* reference)
4 ✔
268
{
269
  using B = QRhiShaderResourceBinding;
270
  constexpr auto stage = B::ComputeStage;
4 ✔
271
  m_srb->setBindings(
8 ✔
272
      {B::uniformBuffer(0, stage, m_params), B::sampledTexture(1, stage, input, m_sampler),
12 ✔
273
       B::sampledTexture(2, stage, reference, m_sampler), B::imageStore(3, stage, m_out, 0)});
8 ✔
274
}
4 ✔
275

276
void Node::runInitialPasses(
5,034 ✔
277
    score::gfx::RenderList& r, QRhiCommandBuffer& cb, QRhiResourceUpdateBatch*& res,
278
    score::gfx::Edge& e)
279
{
280
  using namespace score::gfx;
281
  auto* input = static_cast<QRhiTexture*>(inputs.image.texture.handle);
5,034 ✔
282
  const TextureShape shape = input ? TextureShape::of(*input) : TextureShape{};
5,034 !
283
  if(monitor)
5,034 !
284
    Ui::Monitor::publish(*monitor, shape);
5,034 ✔
285

286
  if(!m_rhi || !m_srb || !m_out)
5,034 !
287
    return;
5,032 ✔
288
  auto& rhi = *m_rhi;
2 ✔
289

290
  auto* reference = static_cast<QRhiTexture*>(inputs.reference.texture.handle);
2 ✔
291
  // The reference is compared as a 2D image
292
  if(reference && TextureShape::of(*reference).kind != TextureKind::Texture2D)
2 !
293
    reference = nullptr;
×
294
  auto* const pl = pipeline(r, shape.kind);
2 ✔
295
  if(!pl)
2 !
296
    return;
×
297

298
  const QSize in_size = input ? input->pixelSize() : QSize{16, 16};
2 !
299
  const ShownTexture shown = Ui::Monitor::shownTexture(
2 ✔
300
      shape, inputs.layout.value, inputs.slice.value, inputs.layer.value);
2 ✔
301
  const QSize out_size = shown.layered() ? shown.size(max_size)
2 !
302
                                         : QSize{
2 ✔
303
                                             std::clamp(in_size.width(), 1, max_size),
2 ✔
304
                                             std::clamp(in_size.height(), 1, max_size)};
2 ✔
305

306
  const bool resized = resizeOutput(out_size);
2 ✔
307
  QRhiTexture* const empty = &r.emptyTexture();
2 ✔
308
  QRhiTexture* in = input ? input : empty;
2 !
309
  QRhiTexture* ref = reference ? reference : empty;
2 !
310
  if(resized || in != m_boundInput || ref != m_boundReference)
2 !
311
  {
312
    // Same layout: the pipeline keeps working with them
313
    setBindings(in, ref);
2 ✔
314
    m_srb->updateResources();
2 ✔
315
    m_boundInput = in;
2 ✔
316
    m_boundReference = ref;
2 ✔
317
  }
2 ✔
318

319
  const bool rec2020 = inputs.luma.value == LumaStandard::Rec2020;
2 ✔
320
  Params params{
12 ✔
321
      .luma = {rec2020 ? 0.2627f : 0.2126f, rec2020 ? 0.6780f : 0.7152f, rec2020 ? 0.0593f : 0.0722f, 0.f},
2 ✔
322
      .config = {int(inputs.mode.value), inputs.nan.value ? 1 : 0, int(inputs.background.value), reference ? 1 : 0},
2 ✔
323
      .view = {std::exp2(inputs.exposure.value), inputs.zebra_high.value, inputs.zebra_low.value, inputs.peaking.value},
2 ✔
324
      .view2 = {inputs.blend.value, inputs.wipe.value, float(m_frame++), 0.f},
2 ✔
325
      .sizes = {out_size.width(), out_size.height(), 0, 0},
2 ✔
326
      .shown = {shown.overview() ? 1 : 0, shown.index, rhi.isYUpInNDC() ? 1 : 0, 0}};
2 ✔
327
  res->updateDynamicBuffer(m_params, 0, sizeof(Params), &params);
2 ✔
328

329
  cb.beginComputePass(res);
2 ✔
330
  res = rhi.nextResourceUpdateBatch();
2 ✔
331
  cb.setComputePipeline(pl);
2 ✔
332
  cb.setShaderResources(m_srb);
2 ✔
333
  cb.dispatch((out_size.width() + 15) / 16, (out_size.height() + 15) / 16, 1);
2 ✔
334
  cb.endComputePass();
2 ✔
335

336
  outputs.resolution.value = {float(in_size.width()), float(in_size.height())};
2 ✔
337
  if(!input)
2 !
338
    outputs.resolution.value = {0.f, 0.f};
×
339
}
5,034 ✔
340

341
void Node::release(score::gfx::RenderList& r)
10 ✔
342
{
343
  for(auto*& pl : m_pipelines)
50 ✔
344
  {
345
    if(pl)
40 ✔
346
      pl->deleteLater();
2 ✔
347
    pl = nullptr;
40 ✔
348
  }
349
  m_failed = {};
10 ✔
350
  for(QRhiResource* res : std::initializer_list<QRhiResource*>{
80 ✔
351
          m_srb, m_params, m_out, m_sampler})
40 ✔
352
    if(res)
40 ✔
353
      res->deleteLater();
8 ✔
354
  m_srb = nullptr;
10 ✔
355
  m_params = nullptr;
10 ✔
356
  m_out = nullptr;
10 ✔
357
  m_sampler = nullptr;
10 ✔
358
  m_boundInput = m_boundReference = nullptr;
10 ✔
359
  outputs.texture.texture.handle = nullptr;
10 ✔
360
  outputs.texture.texture.width = 0;
10 ✔
361
  outputs.texture.texture.height = 0;
10 ✔
362
}
10 ✔
363

364
Layer::Layer(
50 ✔
365
    const Process::ProcessModel& process, const Process::Context& doc,
366
    QGraphicsItem* parent)
367
    : Gfx::OutletPreviewLayer{process, doc, parent}
25 ✔
368
    , m_process{process}
25 ✔
369
{
25 ✔
370
  setAcceptedMouseButtons({});
25 !
371
  setAcceptHoverEvents(true);
25 !
372
  Ui::Monitor::showInlet(process, 0, doc, this, this);
25 !
373
  Ui::Monitor::showInlet(
25 !
374
      process, 1, doc, this, this, Ui::Monitor::firstInletY + Ui::Monitor::inletSpacing);
25 ✔
375
  Ui::Monitor::ModeSwitch::make(process, doc, this, this);
25 !
376
  if(process.outlets().size() > 1)
25 !
377
    m_resolution = qobject_cast<const Process::ControlOutlet*>(process.outlets()[1]);
25 !
378
  placeholder = QStringLiteral("Texture view\nno image");
25 !
379
}
25 ✔
380

381
std::array<float, 2> Layer::resolution() const
×
382
{
383
  if(!m_resolution)
×
384
    return {};
×
385
  const auto v = ossia::convert<ossia::vec2f>(m_resolution->value());
×
386
  return {v[0], v[1]};
×
387
}
×
388

389
score::gfx::TextureShape Layer::textureShape() const
×
390
{
391
  if(auto* m = dynamic_cast<const Ui::Monitor::TextureShapeMonitor*>(m_process.monitor().get()))
×
392
    return Ui::Monitor::latestShape(*m);
×
393
  return {};
×
394
}
×
395

396
void Layer::hoverMoveEvent(QGraphicsSceneHoverEvent* ev)
×
397
{
398
  m_hover = ev->pos();
×
399
}
×
400

401
void Layer::hoverLeaveEvent(QGraphicsSceneHoverEvent*)
×
402
{
403
  m_hover.reset();
×
404
  update();
×
405
}
×
406

407
void Layer::paintOverlay(QPainter* p, const QRectF& r) const
×
408
{
409
  using namespace Ui::Monitor;
410
  const auto res = resolution();
×
411
  const auto shown = Ui::Monitor::shownTexture(m_process, textureShape());
×
412
  const bool hovered = m_hover && r.contains(*m_hover) && res[0] > 0;
×
413
  const double u = hovered ? (m_hover->x() - r.left()) / r.width() : 0.;
×
414
  const double v = hovered ? (m_hover->y() - r.top()) / r.height() : 0.;
×
415
  QString value;
×
416
  if(hovered)
×
417
  {
418
    const QImage img = preview().image();
×
419
    if(!img.isNull())
×
420
    {
421
      const QColor c = img.pixelColor(
×
422
          std::clamp(int(u * img.width()), 0, img.width() - 1),
×
423
          std::clamp(int(v * img.height()), 0, img.height() - 1));
×
424
      value = QStringLiteral("  shown %1 %2 %3").arg(c.red()).arg(c.green()).arg(c.blue());
×
425
    }
×
426
  }
×
427

428
  QStringList info;
×
429
  if(shown.layered() && res[0] > 0)
×
430
  {
431
    // A texture of its producer: its own size, and where the pointer is in it
432
    info = Ui::Monitor::describeShown(
×
433
        shown, hovered ? std::optional<QPointF>{QPointF{u, v}} : std::nullopt);
×
434
    if(hovered && info.size() > 1)
×
435
      info.back() += value;
×
436
  }
×
437
  else
438
  {
439
    if(res[0] > 0)
×
440
      info << QStringLiteral("rendered at %1 x %2").arg(res[0]).arg(res[1]);
×
441
    if(hovered)
×
442
      info << QStringLiteral("%1, %2").arg(int(u * res[0])).arg(int(v * res[1])) + value;
×
443
  }
444
  if(!info.isEmpty() && isUnderMouse())
×
445
    // Under the mode switch, right of the inlets
446
    drawReadout(*p, QPointF{std::max(r.left() + 2, 14.), std::max(r.top() + 2, 16.)}, info);
×
447
}
×
448
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc