-
Notifications
You must be signed in to change notification settings - Fork 56
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added option to save video on death #270
base: master
Are you sure you want to change the base?
Conversation
double frameWidth = mainGui.getWidth() - 16; | ||
double frameHeight = mainGui.getHeight() - 8; |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
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); | ||
} | ||
} |
There was a problem hiding this comment.
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()); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
No description provided.