MCPcopy Create free account
hub / github.com/BespokeSynth/BespokeSynth / RenderScreenshot

Method RenderScreenshot

Source/HelpDisplay.cpp:586–631  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

584}
585
586void HelpDisplay::RenderScreenshot(int x, int y, int width, int height, std::string filename)
587{
588 float scale = gDrawScale * TheSynth->GetPixelRatio();
589 x = (x + TheSynth->GetDrawOffset().x) * scale;
590 y = (y + TheSynth->GetDrawOffset().y) * scale;
591 width = width * scale;
592 height = height * scale;
593
594 unsigned char* pixels = new unsigned char[3 * (width) * (height)];
595
596 juce::gl::glReadBuffer(juce::gl::GL_BACK);
597 int oldAlignment;
598 juce::gl::glGetIntegerv(juce::gl::GL_PACK_ALIGNMENT, &oldAlignment);
599 juce::gl::glPixelStorei(juce::gl::GL_PACK_ALIGNMENT, 1); //tight packing
600 juce::gl::glReadPixels(x, ofGetHeight() * scale - y - height, width, height, juce::gl::GL_RGB, juce::gl::GL_UNSIGNED_BYTE, pixels);
601 juce::gl::glPixelStorei(juce::gl::GL_PACK_ALIGNMENT, oldAlignment);
602
603 juce::Image image(juce::Image::RGB, width, height, true);
604 for (int ix = 0; ix < width; ++ix)
605 {
606 for (int iy = 0; iy < height; ++iy)
607 {
608 int pos = (ix + (height - 1 - iy) * width) * 3;
609 image.setPixelAt(ix, iy, juce::Colour(pixels[pos], pixels[pos + 1], pixels[pos + 2]));
610 }
611 }
612
613 {
614 juce::File(ofToDataPath("screenshots")).createDirectory();
615 juce::File pngFile(ofToDataPath("screenshots/" + filename));
616 if (pngFile.existsAsFile())
617 pngFile.deleteFile();
618 juce::FileOutputStream stream(pngFile);
619 juce::PNGImageFormat pngWriter;
620 pngWriter.writeImageToStream(image, stream);
621 }
622
623 /*{
624 juce::File rawFile(ofToDataPath("screenshot.txt"));
625 if (rawFile.existsAsFile())
626 rawFile.deleteFile();
627 FileOutputStream stream(rawFile);
628 for (int i = 0; i < width*height * 3; ++i)
629 stream << pixels[i] << ' ';
630 }*/
631}

Callers

nothing calls this directly

Calls 4

ofGetHeightFunction · 0.85
ofToDataPathFunction · 0.85
GetPixelRatioMethod · 0.80
GetDrawOffsetMethod · 0.80

Tested by

no test coverage detected