Merge lp:~vikoadi/pantheon-files/fix-1087641 into lp:~elementary-apps/pantheon-files/trunk

Proposed by Viko Adi Rahmawan
Status: Merged
Approved by: David Gomes
Approved revision: 1465
Merged at revision: 1476
Proposed branch: lp:~vikoadi/pantheon-files/fix-1087641
Merge into: lp:~elementary-apps/pantheon-files/trunk
Diff against target: 84 lines (+49/-10)
1 file modified
src/marlin-icon-renderer.c (+49/-10)
To merge this branch: bzr merge lp:~vikoadi/pantheon-files/fix-1087641
Reviewer Review Type Date Requested Status
David Gomes (community) Approve
Danielle Foré Approve
Cassidy James Blaede Pending
Review via email: mp+214148@code.launchpad.net

Commit message

don't set shadows for small and transparent images

Description of the change

the current problem is the mask that is intended to be an opaque layer of transparent is happen to be transparent too so the shadow behind rectangle is visible.
my branch will just fill the rectangle with full opaque white. its the same implementation as windows 8 did. i think its better than having to use gtk style background color (we cant see picture that intended for white background if our gtk style background is black). Or do we still need to use gtk style background?

To post a comment you must log in.
1464. By Viko Adi Rahmawan

fill transparent image with an opaque white instead of detecting background color which can turn out to be transparent

Revision history for this message
Danielle Foré (danrabbit) wrote :

Hrm. I'm not entirely sure it's really that much better looking as white than it was as just transparent. I played around with adding some padding around the image or changing the background color and I just wasn't happy with it any of those ways. I'm wondering if it'd be better to just remove both the background and the shadow.

Requesting Cassidy James for a second opinion.

1465. By Viko Adi Rahmawan

dont use shadow for small icon and icon with alpha channel on the side (based on thunar algorithm)

Revision history for this message
Viko Adi Rahmawan (vikoadi) wrote :

have update the branch not to use background or shadow on :
-icon smaller than 48px
-icon with transparency

Revision history for this message
Danielle Foré (danrabbit) wrote :

Ah yeah this is great. Design approval :)

review: Approve
Revision history for this message
David Gomes (davidgomes) wrote :

That looks like some hacky code but it still gets my approval.

review: Approve
Revision history for this message
Viko Adi Rahmawan (vikoadi) wrote :

hello,
about the code, i took the shadowing decision right from thunar source
code. and I'd love to know what's hacky about my code and probably clean it
up (not until next week) .
Thanks

On Thursday, April 17, 2014, David Gomes <email address hidden> wrote:

> The proposal to merge lp:~vikoadi/pantheon-files/fix-1087641 into
> lp:pantheon-files has been updated.
>
> Status: Needs review => Approved
>
> For more details, see:
>
> https://code.launchpad.net/~vikoadi/pantheon-files/fix-1087641/+merge/214148
> --
>
> https://code.launchpad.net/~vikoadi/pantheon-files/fix-1087641/+merge/214148
> You are the owner of lp:~vikoadi/pantheon-files/fix-1087641.
>

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/marlin-icon-renderer.c'
2--- src/marlin-icon-renderer.c 2014-03-12 23:46:52 +0000
3+++ src/marlin-icon-renderer.c 2014-04-07 03:45:18 +0000
4@@ -59,6 +59,9 @@
5 const GdkRectangle *background_area,
6 const GdkRectangle *cell_area,
7 GtkCellRendererState flags);
8+static inline gboolean thumbnail_needs_frame (const GdkPixbuf *thumbnail,
9+ gint width,
10+ gint height);
11
12
13 enum {
14@@ -534,18 +537,12 @@
15
16 if (priv->file->flags == GOF_FILE_THUMB_STATE_READY
17 && gof_file_get_thumbnail_path (priv->file)
18- && gof_file_thumb_can_frame (priv->file))
19+ && gof_file_thumb_can_frame (priv->file)
20+ && thumbnail_needs_frame (pixbuf, pix_rect.width, pix_rect.height))
21 {
22 cairo_make_shadow_for_rect (cr, pix_rect.x+4, pix_rect.y+4,
23 pix_rect.width-4, pix_rect.height-6,
24 4, 0, 0, 0, 8);
25- /* we need to mask the underlying shadows in case of transparent thumbs */
26- GdkRGBA bg_color;
27- gtk_style_context_get_background_color (context, GTK_STATE_FLAG_NORMAL, &bg_color);
28- gdk_cairo_set_source_rgba (cr, &bg_color);
29- cairo_rectangle (cr, pix_rect.x, pix_rect.y,
30- pix_rect.width, pix_rect.height);
31- cairo_fill (cr);
32 }
33
34 gtk_render_icon (context, cr, pixbuf,
35@@ -794,5 +791,47 @@
36 _cairo_pattern_destroy0 (pat);
37 }
38
39-
40-
41+static inline gboolean
42+thumbnail_needs_frame (const GdkPixbuf *thumbnail,
43+ gint width,
44+ gint height)
45+{
46+ const guchar *pixels;
47+ gint rowstride;
48+ gint n;
49+
50+ /* don't add frames to small thumbnails */
51+ if (width < 48 && height < 48)
52+ return FALSE;
53+
54+ /* always add a frame to thumbnails w/o alpha channel */
55+ if (G_LIKELY (!gdk_pixbuf_get_has_alpha (thumbnail)))
56+ return TRUE;
57+
58+ /* get a pointer to the thumbnail data */
59+ pixels = gdk_pixbuf_get_pixels (thumbnail);
60+
61+ /* check if we have a transparent pixel on the first row */
62+ for (n = width * 4; n > 0; n -= 4)
63+ if (pixels[n - 1] < 255u)
64+ return FALSE;
65+ g_debug("transparent pixel");
66+
67+ /* determine the rowstride */
68+ rowstride = gdk_pixbuf_get_rowstride (thumbnail);
69+
70+ /* skip the first row */
71+ pixels += rowstride;
72+
73+ /* check if we have a transparent pixel in the first or last column */
74+ for (n = height - 2; n > 0; --n, pixels += rowstride)
75+ if (pixels[3] < 255u || pixels[width * 4 - 1] < 255u)
76+ return FALSE;
77+
78+ /* check if we have a transparent pixel on the last row */
79+ for (n = width * 4; n > 0; n -= 4)
80+ if (pixels[n - 1] < 255u)
81+ return FALSE;
82+
83+ return TRUE;
84+}

Subscribers

People subscribed via source and target branches

to all changes: