@@ -258,9 +258,15 @@ class alignas(64) Oscilloscope : public juce::Thread
258258 }
259259
260260 for (auto & image : images) {
261- image = Image (PixelFormat::ARGB , _width + 10 , _height, true );
261+ image = Image (PixelFormat::ARGB ,
262+ _width + 10 ,
263+ _height,
264+ true ,
265+ juce::SoftwareImageType ());
262266 }
263267
268+ renderImage = Image (PixelFormat::ARGB , _width + 10 , _height, true );
269+
264270 frontBufferIndex.store (0 , std::memory_order_release);
265271 subPixelOffset = 0 .0f ;
266272
@@ -326,26 +332,36 @@ class alignas(64) Oscilloscope : public juce::Thread
326332 const int backIndex = currentFront == 0 ? 1 : 0 ;
327333
328334 auto & backImage = images[(size_t )backIndex];
335+ const auto & frontImage = images[(size_t )currentFront];
329336
330- backImage = images[( size_t )currentFront] .createCopy ();
337+ backImage = frontImage .createCopy ();
331338
332339 // Left scrolling 2.0: Hopefully without crashing host DAWs
333340 const int shift = jmin (pixelToDraw, width);
334341 if (shift > 0 ) {
335342 // Move content LEFT safely inside bounds
336- // backImage.moveImageSection(0,
337- // 0, // destX, destY
338- // shift,
339- // 0, // sourceX, sourceY
340- // width - shift,
341- // height);
343+ backImage.moveImageSection (0 ,
344+ 0 , // destX, destY
345+ shift,
346+ 0 , // sourceX, sourceY
347+ width - shift,
348+ height);
342349
343350 backImage.clear (juce::Rectangle<int >(width - shift, 0 , shift, height),
344351 juce::Colours::transparentBlack);
345352 }
346353
354+ if (renderImage.getWidth () != backImage.getWidth () ||
355+ renderImage.getHeight () != backImage.getHeight ()) {
356+ renderImage = Image (
357+ PixelFormat::ARGB , backImage.getWidth (), backImage.getHeight (), true );
358+ } else {
359+ renderImage.clear (renderImage.getBounds (),
360+ juce::Colours::transparentBlack);
361+ }
362+
347363 // Render new audio data
348- juce::Graphics g (backImage );
364+ juce::Graphics renderGraphics (renderImage );
349365
350366 const typename Renderer::RenderContext context{
351367 firstSamplesToDraw,
@@ -362,7 +378,12 @@ class alignas(64) Oscilloscope : public juce::Thread
362378
363379 if (auto currentRenderer =
364380 std::atomic_load_explicit (&renderer, std::memory_order_acquire)) {
365- currentRenderer->draw (g, ringBuffer, channel, context);
381+ currentRenderer->draw (renderGraphics, ringBuffer, channel, context);
382+ }
383+
384+ {
385+ juce::Graphics backGraphics (backImage);
386+ backGraphics.drawImageAt (renderImage, 0 , 0 );
366387 }
367388
368389 frontBufferIndex.store (backIndex, std::memory_order_release);
@@ -378,8 +399,11 @@ class alignas(64) Oscilloscope : public juce::Thread
378399 // ==============================================================================
379400 // Other members
380401 juce::Rectangle<int > bounds = juce::Rectangle<int >(0 , 0 , 1 , 1 );
381- std::array<Image, 2 > images = { Image (PixelFormat::ARGB , 1 , 1 , true ),
382- Image (PixelFormat::ARGB , 1 , 1 , true ) };
402+ std::array<Image, 2 > images = {
403+ Image (PixelFormat::ARGB , 1 , 1 , true , juce::SoftwareImageType ()),
404+ Image (PixelFormat::ARGB , 1 , 1 , true , juce::SoftwareImageType ())
405+ };
406+ Image renderImage = Image (PixelFormat::ARGB , 1 , 1 , true );
383407 std::atomic<int > frontBufferIndex{ 0 };
384408 std::atomic<int > renderWidth{ 1 };
385409 std::atomic<int > renderHeight{ 1 };
0 commit comments