aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorMarkus Ongyerth <ongy@ongy.net>2018-01-31 12:54:57 +0100
committerMarkus Ongyerth <ongy@ongy.net>2018-01-31 12:54:57 +0100
commit4afc933ea4946e00977c18dbed5dea47ddf8b204 (patch)
tree28d2625330b696cfee934042dc477fefd6ee7d87 /examples
parent429f06d3f16c0401bb8a4acfbfc239b2745c9496 (diff)
fixes 90 degree rotation screenshots
This fixes the screenshot example application when an output is rotated by 90 degrees. Other tranformations are not taken into account yet.
Diffstat (limited to 'examples')
-rw-r--r--examples/screenshot.c33
1 files changed, 27 insertions, 6 deletions
diff --git a/examples/screenshot.c b/examples/screenshot.c
index ba225023..12892476 100644
--- a/examples/screenshot.c
+++ b/examples/screenshot.c
@@ -48,6 +48,7 @@ struct screenshooter_output {
struct wl_output *output;
struct wl_buffer *buffer;
int width, height, offset_x, offset_y;
+ int transform;
void *data;
struct wl_list link;
};
@@ -60,6 +61,7 @@ static void output_handle_geometry(void *data, struct wl_output *wl_output,
if (wl_output == output->output) {
output->offset_x = x;
output->offset_y = y;
+ output->transform = transform;
}
}
@@ -163,10 +165,21 @@ static void write_image(const char *filename, int width, int height) {
void *d = data + (output->offset_y - min_y) * buffer_stride +
(output->offset_x - min_x) * 4;
- for (int i = 0; i < output->height; i++) {
- memcpy(d, s, output_stride);
- d += buffer_stride;
- s += output_stride;
+ if (output->transform == WL_OUTPUT_TRANSFORM_90) {
+ uint32_t *ss = s;
+ uint32_t *sd = d;
+ for (int i = 0; i < output->width; ++i) {
+ for (int j = 0; j < output->height; ++j) {
+ sd[i * width + j]
+ = ss[j * output->width + (output->width - i)];
+ }
+ }
+ } else {
+ for (int i = 0; i < output->height; i++) {
+ memcpy(d, s, output_stride);
+ d += buffer_stride;
+ s += output_stride;
+ }
}
free(output);
@@ -211,15 +224,23 @@ static void write_image(const char *filename, int width, int height) {
}
static int set_buffer_size(int *width, int *height) {
+ int owidth, oheight;
min_x = min_y = INT_MAX;
max_x = max_y = INT_MIN;
struct screenshooter_output *output;
wl_list_for_each(output, &output_list, link) {
+ if (output->transform & 0x1) {
+ owidth = output->height;
+ oheight = output->width;
+ } else {
+ owidth = output->width;
+ oheight = output->height;
+ }
min_x = MIN(min_x, output->offset_x);
min_y = MIN(min_y, output->offset_y);
- max_x = MAX(max_x, output->offset_x + output->width);
- max_y = MAX(max_y, output->offset_y + output->height);
+ max_x = MAX(max_x, output->offset_x + owidth);
+ max_y = MAX(max_y, output->offset_y + oheight);
}
if (max_x <= min_x || max_y <= min_y) {