summaryrefslogtreecommitdiffstats
path: root/base/gfx/gtk_util.cc
diff options
context:
space:
mode:
Diffstat (limited to 'base/gfx/gtk_util.cc')
-rwxr-xr-xbase/gfx/gtk_util.cc31
1 files changed, 20 insertions, 11 deletions
diff --git a/base/gfx/gtk_util.cc b/base/gfx/gtk_util.cc
index ba93c34..0d2eee0 100755
--- a/base/gfx/gtk_util.cc
+++ b/base/gfx/gtk_util.cc
@@ -40,25 +40,34 @@ static void FreePixels(guchar* pixels, gpointer data) {
free(data);
}
-GdkPixbuf* GdkPixbufFromSkBitmap(const SkBitmap* bitmap) {
- bitmap->lockPixels();
- int width = bitmap->width();
- int height = bitmap->height();
- int stride = bitmap->rowBytes();
- const guchar* orig_data = static_cast<guchar*>(bitmap->getPixels());
- guchar* data = static_cast<guchar*>(malloc(height * stride));
+uint8_t* BGRAToRGBA(const uint8_t* pixels, int width, int height, int stride) {
+ if (stride == 0)
+ stride = width * 4;
+
+ guchar* new_pixels = static_cast<guchar*>(malloc(height * stride));
// We have to copy the pixels and swap from BGRA to RGBA.
for (int i = 0; i < height; ++i) {
for (int j = 0; j < width; ++j) {
int idx = i * stride + j * 4;
- data[idx] = orig_data[idx + 2];
- data[idx + 1] = orig_data[idx + 1];
- data[idx + 2] = orig_data[idx];
- data[idx + 3] = orig_data[idx + 3];
+ new_pixels[idx] = pixels[idx + 2];
+ new_pixels[idx + 1] = pixels[idx + 1];
+ new_pixels[idx + 2] = pixels[idx];
+ new_pixels[idx + 3] = pixels[idx + 3];
}
}
+ return new_pixels;
+}
+
+GdkPixbuf* GdkPixbufFromSkBitmap(const SkBitmap* bitmap) {
+ bitmap->lockPixels();
+ int width = bitmap->width();
+ int height = bitmap->height();
+ int stride = bitmap->rowBytes();
+ const guchar* orig_data = static_cast<guchar*>(bitmap->getPixels());
+ guchar* data = BGRAToRGBA(orig_data, width, height, stride);
+
// This pixbuf takes ownership of our malloc()ed data and will
// free it for us when it is destroyed.
GdkPixbuf* pixbuf = gdk_pixbuf_new_from_data(