summaryrefslogtreecommitdiffstats
path: root/base/gfx
diff options
context:
space:
mode:
authorestade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-04-07 01:22:22 +0000
committerestade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-04-07 01:22:22 +0000
commite4a41d8af760e10cd8d85ae877c9169f86ca6084 (patch)
treeaa384a871cca99389706994830a5aa5d86f7bf81 /base/gfx
parent7a69c1461163ab03dac93b8459ac6f71c6df4a44 (diff)
downloadchromium_src-e4a41d8af760e10cd8d85ae877c9169f86ca6084.zip
chromium_src-e4a41d8af760e10cd8d85ae877c9169f86ca6084.tar.gz
chromium_src-e4a41d8af760e10cd8d85ae877c9169f86ca6084.tar.bz2
Linux: store clipboard image as bmp rather than converting to PNG.
Review URL: http://codereview.chromium.org/63040 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@13218 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/gfx')
-rwxr-xr-xbase/gfx/gtk_util.cc31
-rwxr-xr-xbase/gfx/gtk_util.h9
2 files changed, 27 insertions, 13 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(
diff --git a/base/gfx/gtk_util.h b/base/gfx/gtk_util.h
index 6a6cdd6..1b70ae0 100755
--- a/base/gfx/gtk_util.h
+++ b/base/gfx/gtk_util.h
@@ -30,8 +30,13 @@ extern const GdkColor kGdkGreen;
void SubtractRectanglesFromRegion(GdkRegion* region,
const std::vector<Rect>& cutouts);
-// Convert and copy a SkBitmap to a GdkPixbuf. NOTE: This is an expensive
-// operation, all of the pixels must be copied and their order swapped.
+// Makes a copy of |pixels| with the ordering changed from BGRA to RGBA.
+// The caller is responsible for free()ing the data. If |stride| is 0,
+// it's assumed to be 4 * |width|.
+uint8_t* BGRAToRGBA(const uint8_t* pixels, int width, int height, int stride);
+
+// Convert and copy a SkBitmap to a GdkPixbuf. NOTE: this uses BGRAToRGBA, so
+// it is an expensive operation.
GdkPixbuf* GdkPixbufFromSkBitmap(const SkBitmap* bitmap);
// Create a GtkBin with |child| as its child widget. This bin will paint a