@@ -412,29 +412,23 @@ void NVGSurface::renderFrameToImage(Image& image, Rectangle<int> area)
412412 auto bufferSize = fbHeight * fbWidth;
413413 if (bufferSize != backupPixelData.size ())
414414 backupPixelData.resize (bufferSize);
415- nvgReadPixels (nvg, invalidFBO->image , 0 , 0 , fbWidth, fbHeight, backupPixelData.data ()); // TODO: would be nice to read only a part of the image, but that gets tricky with openGL
415+
416+ auto region = area.getIntersection (getLocalBounds ()) * getRenderScale ();
417+ nvgReadPixels (nvg, invalidFBO, region.getX (), region.getY (), region.getWidth (), region.getHeight (), fbHeight, backupPixelData.data ());
416418
417419 if (!image.isValid () || image.getWidth () != fbWidth || image.getHeight () != fbHeight) {
418420 image = Image (Image::PixelFormat::ARGB, fbWidth, fbHeight, true );
419421 }
420422 Image::BitmapData imageData (image, Image::BitmapData::readOnly);
421423
422- int width = imageData.width ;
423- int height = imageData.height ;
424-
425- auto region = area.getIntersection (getLocalBounds ()) * getRenderScale ();
426- for (int y = 0 ; y < height; ++y) {
427- if (y < region.getY () || y > region.getBottom ())
428- continue ;
429- auto * scanLine = (uint32*)imageData.getLinePointer (y);
430- for (int x = 0 ; x < width; ++x) {
431- if (x < region.getX () || x > region.getRight ())
432- continue ;
424+ for (int y = 0 ; y < region.getHeight (); y++) {
425+ auto * scanLine = (uint32*)imageData.getLinePointer (y + region.getY ());
426+ for (int x = 0 ; x < region.getWidth (); x++) {
433427#if NANOVG_GL_IMPLEMENTATION
434428 // OpenGL images are upside down
435- uint32 argb = backupPixelData[(height - (y + 1 )) * width + x];
429+ uint32 argb = backupPixelData[(region. getHeight () - (y + 1 )) * region. getWidth () + x];
436430#else
437- uint32 argb = backupPixelData[y * width + x];
431+ uint32 argb = backupPixelData[y * region. getWidth () + x];
438432#endif
439433 uint8 a = argb >> 24 ;
440434 uint8 r = argb >> 16 ;
@@ -443,13 +437,13 @@ void NVGSurface::renderFrameToImage(Image& image, Rectangle<int> area)
443437
444438 // order bytes as abgr
445439#if NANOVG_GL_IMPLEMENTATION
446- scanLine[x] = (a << 24 ) | (b << 16 ) | (g << 8 ) | r;
440+ scanLine[x + region. getX () ] = (a << 24 ) | (b << 16 ) | (g << 8 ) | r;
447441#else
448- scanLine[x] = (a << 24 ) | (r << 16 ) | (g << 8 ) | b;
442+ scanLine[x + region. getX () ] = (a << 24 ) | (r << 16 ) | (g << 8 ) | b;
449443#endif
450444 }
451445 }
452-
446+
453447 backupImageComponent.setVisible (true );
454448 backupImageComponent.setImage (image);
455449 backupImageComponent.repaint ();
@@ -459,12 +453,6 @@ void NVGSurface::setRenderThroughImage(bool shouldRenderThroughImage)
459453{
460454 renderThroughImage = shouldRenderThroughImage;
461455 invalidateAll ();
462-
463- #if JUCE_LINUX
464- detachContext ();
465- initialise ();
466- #endif
467-
468456 updateWindowContextVisibility ();
469457}
470458
0 commit comments