Skip to content

Added option to save video on death#270

Open
Punikekk wants to merge 2 commits intodarkbot-reloaded:masterfrom
Punikekk:death-recorder
Open

Added option to save video on death#270
Punikekk wants to merge 2 commits intodarkbot-reloaded:masterfrom
Punikekk:death-recorder

Conversation

@Punikekk
Copy link
Copy Markdown
Member

@Punikekk Punikekk commented May 6, 2023

No description provided.

Comment on lines +84 to +85
double frameWidth = mainGui.getWidth() - 16;
double frameHeight = mainGui.getHeight() - 8;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you're manually trying to get rid of the border, does that mean you just want the map being rendered? can't you dump the graphics being written for that component instead of the whole frame?

I think it'd probably be useful, especially given we fully render that ourselves to a graphics 2d, and that we probably can straight up copy it to a buffer with some method in there

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I want to record whole bot GUI
Rendering image this way, shows a weird white border around gui, probably it is casused by flatlaf's native border on Windows*
So 16 pixels less are there only to remove white border

Comment on lines +92 to +99
for (int offset = 0, h = 0; h < HEIGHT; h++) {
for (int w = 0; w < WIDTH; w++) {
int v = imageCache.getRGB(w, h);
bitmapBuffer[offset++] = (byte) (((v >>> 16) & 0xff) - 128);
bitmapBuffer[offset++] = (byte) (((v >>> 8) & 0xff) - 128);
bitmapBuffer[offset++] = (byte) (((v) & 0xff) - 128);
}
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are we totally certain there's no other way to extract a graphics2d's rendered output to a byte array if you don't do it yourself?

From what i could find, you can create a BufferedImage, then call component.paint(image.getGraphics()). It will paint that component to the image and you'll have your desired data in image -> raster -> data buffer. Additionally you could be doing this directly at render time and then just render the buffered image to the component for very little recording overhead, ie, in MapDrawer have something like:

@Override
public void paint(Graphics g) {
    BufferedImage img = new BufferedImage(width(), height(), BufferedImage.TYPE_INT_RGB);
    Graphics2D imgGraphics = img.getGraphics();
    
    // All the logic to draw, do it based on img. 
    // Optionally only do this whole render-to-image if you want the frame saved, 
    // otherwise rendering to g directly.
    doPaintStuff(imgGraphics);
    
    // Normally use the image as if it was the proper render
    g.drawImage(img, 0, 0, width, height);

    img.getRaster().getDataBuffer(); // here's your pixel data to save
}

If course you'll have to benchmark this, but i'm pretty sure this is going to be faster than manually iterating and calling a method to get rgb manually for each pixel in the image, especially if using any higher resolution.


CompressedFrame compressedImage;
if (compressedFrames.size() <= currentFrame) {
compressedFrames.add(compressedImage = new CompressedFrame());
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of add & remove, consider simply using a circular buffer (or ring buffer), much more convenient.

Essentially you'll be writing to a different index each time and once you get to the end it starts re-writing the beginning, once you want to finally save it as video you can just iterate from head + 1 up till you loop arround to head (head being the current "index" you're writing to.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is actually kinda a circular buffer, no remove method is called

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants