From 2e087265468db6369a65f3da28f0c2777788bcb6 Mon Sep 17 00:00:00 2001 From: "estade@chromium.org" Date: Wed, 15 Jul 2009 01:07:53 +0000 Subject: Don't try to set transparency on pixbufs that don't have any transparency channel. Also add DCHECK to make sure the assumption rowstride >= width * 4 is true. The reason this didn't cause any crashes or graphical corruption is because the non-transparent images don't have any white in them (luckily we are not making a browser for an ipod). BUG=16749 TEST=valgrind the browser, open find bar Review URL: http://codereview.chromium.org/155547 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@20701 0039d316-1c4b-4281-b951-d872f2087c98 --- chrome/browser/gtk/nine_box.cc | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'chrome') diff --git a/chrome/browser/gtk/nine_box.cc b/chrome/browser/gtk/nine_box.cc index af2de61..66e7793 100644 --- a/chrome/browser/gtk/nine_box.cc +++ b/chrome/browser/gtk/nine_box.cc @@ -138,11 +138,21 @@ void NineBox::ChangeWhiteToTransparent() { if (!pixbuf) continue; + if (!gdk_pixbuf_get_has_alpha(pixbuf)) + continue; + guchar* pixels = gdk_pixbuf_get_pixels(pixbuf); int rowstride = gdk_pixbuf_get_rowstride(pixbuf); + int width = gdk_pixbuf_get_width(pixbuf); + int height = gdk_pixbuf_get_height(pixbuf); + + if (width * 4 > rowstride) { + NOTREACHED(); + continue; + } - for (int i = 0; i < gdk_pixbuf_get_height(pixbuf); ++i) { - for (int j = 0; j < gdk_pixbuf_get_width(pixbuf); ++j) { + for (int i = 0; i < height; ++i) { + for (int j = 0; j < width; ++j) { guchar* pixel = &pixels[i * rowstride + j * 4]; if (pixel[0] == 0xff && pixel[1] == 0xff && pixel[2] == 0xff) { pixel[3] = 0; -- cgit v1.1