Commit 03be5f8d authored by abmyii's avatar abmyii
Browse files

Implement rotation algorithm

parent c4dee098
......@@ -85,22 +85,24 @@ void shutdown(int)
running = 0;
}
void read_pixels(GLenum format, mir::geometry::Size const& size, std::vector<char> *fb)
void read_pixels(int bpp, GLenum format, mir::geometry::Size const& size, std::vector<char> &fb)
{
auto width = size.width.as_uint32_t();
auto height = size.height.as_uint32_t();
// https://stackoverflow.com/a/60696921
std::vector<char> pixels(4 * width * height);
std::vector<char> pixels(bpp * width * height);
std::vector<char> rotated(bpp * height * width);
glReadPixels(0, 0, width, height, format, GL_UNSIGNED_BYTE, pixels.data());
for(int line = 0; line != height/2; ++line) {
std::swap_ranges(
pixels.begin() + 4 * width * line,
pixels.begin() + 4 * width * (line+1),
pixels.begin() + 4 * width * (height-line-1));
for (int x = width*bpp; x > 0; x -= bpp) {
for (int y = 0; y < height; y++) {
int offset = (width * bpp * y) + x;
std::vector<char> pixel(pixels.begin()+offset-bpp, pixels.begin()+offset);
rotated.insert(rotated.end(), pixel.begin(), pixel.end());
}
}
fb->assign(pixels.begin(), pixels.end());
fb = pixels;
#ifdef DEBUG
unsigned int sum = 0;
unsigned int *pui = (unsigned int *) buffer;
......@@ -559,7 +561,7 @@ void do_screencast(EGLSetup const& egl_setup,
{
auto time_point = std::chrono::steady_clock::now() + capture_period;
read_pixels(format, size, &frame_data);
read_pixels(bpp, format, size, frame_data);
auto write_out_future = std::async(
std::launch::async,
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment