So run your algorithm over the current content of the framebuffer to work out the amount of "grey" on the screen right now. Then use that as the border.
Right, that would be ideal. But like I said, depending on the application, it's not always practical to do that. Perhaps it's something you're implementing in software and you don't have enough free memory or CPU cycles or whatever to really do it properly. Or maybe there's just not enough time to work out the code to do it properly before the ship date. Or maybe it's something being implemented in hardware and there's no way to get an average luminance number from the frame buffer. Bruno didn't say why he wanted the gray value or what his restrictions were, so I started with Genixia's comment that it should ideally be an average of the image content, and talked about alternatives if that wasn't feasible.