diff options
author | Emmanuele Bassi <ebassi@gmail.com> | 2019-10-07 23:52:29 +0000 |
---|---|---|
committer | Emmanuele Bassi <ebassi@gmail.com> | 2019-10-07 23:52:29 +0000 |
commit | 09788c786f832deec2ae5d9e7b468e7ee0df112d (patch) | |
tree | 5ac7e5dacae7e0eba6b629839680dd4d4381cb76 | |
parent | e1efdc92f71e1c233dfb680cc73549392079a3b6 (diff) | |
parent | 6134c915fd66fdb4c6b89b0547e68ac8edc62a08 (diff) | |
download | clutter-09788c786f832deec2ae5d9e7b468e7ee0df112d.tar.gz |
Merge branch '10bpc' into 'master'
Handle 8 and 10 bits colour depth in picking code (#11)
See merge request GNOME/clutter!10
-rw-r--r-- | clutter/clutter-main.c | 54 |
1 files changed, 33 insertions, 21 deletions
diff --git a/clutter/clutter-main.c b/clutter/clutter-main.c index 3e4335ec4..89b2f9e6b 100644 --- a/clutter/clutter-main.c +++ b/clutter/clutter-main.c @@ -587,6 +587,9 @@ _clutter_id_to_color (guint id_, { ClutterMainContext *ctx; gint red, green, blue; + /* keep track of the bit depth of the RGB channels of the framebuffers (i.e. + * either 8 or 10) */ + gint bpc; ctx = _clutter_context_get_default (); @@ -610,13 +613,16 @@ _clutter_id_to_color (guint id_, } } + bpc = ctx->fb_r_mask; + g_assert (bpc == 8 || bpc == 10); + /* compute the numbers we'll store in the components */ - red = (id_ >> (ctx->fb_g_mask_used+ctx->fb_b_mask_used)) - & (0xff >> (8-ctx->fb_r_mask_used)); + red = (id_ >> (ctx->fb_g_mask_used + ctx->fb_b_mask_used)) + & (0xff >> (bpc - ctx->fb_r_mask_used)); green = (id_ >> ctx->fb_b_mask_used) - & (0xff >> (8-ctx->fb_g_mask_used)); + & (0xff >> (bpc - ctx->fb_g_mask_used)); blue = (id_) - & (0xff >> (8-ctx->fb_b_mask_used)); + & (0xff >> (bpc - ctx->fb_b_mask_used)); /* shift left bits a bit and add one, this circumvents * at least some potential rounding errors in GL/GLES @@ -629,10 +635,10 @@ _clutter_id_to_color (guint id_, if (ctx->fb_b_mask_used != ctx->fb_b_mask) blue = blue * 2; - /* shift up to be full 8bit values */ - red = (red << (8 - ctx->fb_r_mask)) | (0x7f >> (ctx->fb_r_mask_used)); - green = (green << (8 - ctx->fb_g_mask)) | (0x7f >> (ctx->fb_g_mask_used)); - blue = (blue << (8 - ctx->fb_b_mask)) | (0x7f >> (ctx->fb_b_mask_used)); + /* shift up to occupy the full bit depth of the channel */ + red = (red << (bpc - ctx->fb_r_mask)) | (0x7f >> (ctx->fb_r_mask_used)); + green = (green << (bpc - ctx->fb_g_mask)) | (0x7f >> (ctx->fb_g_mask_used)); + blue = (blue << (bpc - ctx->fb_b_mask)) | (0x7f >> (ctx->fb_b_mask_used)); col->red = red; col->green = green; @@ -646,9 +652,9 @@ _clutter_id_to_color (guint id_, */ if (G_UNLIKELY (clutter_pick_debug_flags & CLUTTER_DEBUG_DUMP_PICK_BUFFERS)) { - col->red = (col->red << 4) | (col->red >> 4); - col->green = (col->green << 4) | (col->green >> 4); - col->blue = (col->blue << 4) | (col->blue >> 4); + col->red = (col->red << bpc / 2) | (col->red >> bpc / 2); + col->green = (col->green << bpc / 2) | (col->green >> bpc / 2); + col->blue = (col->blue << bpc / 2) | (col->blue >> bpc / 2); } } @@ -658,11 +664,17 @@ _clutter_pixel_to_id (guchar pixel[4]) ClutterMainContext *ctx; gint red, green, blue; guint retval; + /* keep track of the bit depth of the RGB channels of the framebuffers (i.e. + * either 8 or 10) */ + gint bpc; ctx = _clutter_context_get_default (); + bpc = ctx->fb_r_mask; + g_assert (bpc == 8 || bpc == 10); + /* reduce the pixel components to the number of bits actually used of the - * 8bits. + * bit depth of the channel (i.e. 8 or 10 bits) */ if (G_UNLIKELY (clutter_pick_debug_flags & CLUTTER_DEBUG_DUMP_PICK_BUFFERS)) { @@ -673,18 +685,18 @@ _clutter_pixel_to_id (guchar pixel[4]) * identifiers (otherwise pick buffers dumped to an image will pretty * much just look black.) Here we reverse that rotation. */ - tmp = ((pixel[0] << 4) | (pixel[0] >> 4)); - red = tmp >> (8 - ctx->fb_r_mask); - tmp = ((pixel[1] << 4) | (pixel[1] >> 4)); - green = tmp >> (8 - ctx->fb_g_mask); - tmp = ((pixel[2] << 4) | (pixel[2] >> 4)); - blue = tmp >> (8 - ctx->fb_b_mask); + tmp = ((pixel[0] << bpc / 2) | (pixel[0] >> bpc / 2)); + red = tmp >> (bpc - ctx->fb_r_mask); + tmp = ((pixel[1] << bpc / 2) | (pixel[1] >> bpc / 2)); + green = tmp >> (bpc - ctx->fb_g_mask); + tmp = ((pixel[2] << bpc / 2) | (pixel[2] >> bpc / 2)); + blue = tmp >> (bpc - ctx->fb_b_mask); } else { - red = pixel[0] >> (8 - ctx->fb_r_mask); - green = pixel[1] >> (8 - ctx->fb_g_mask); - blue = pixel[2] >> (8 - ctx->fb_b_mask); + red = pixel[0] >> (bpc - ctx->fb_r_mask); + green = pixel[1] >> (bpc - ctx->fb_g_mask); + blue = pixel[2] >> (bpc - ctx->fb_b_mask); } /* divide potentially by two if 'fuzzy' */ |