diff options
author | sgk@google.com <sgk@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-04-21 17:20:10 +0000 |
---|---|---|
committer | sgk@google.com <sgk@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-04-21 17:20:10 +0000 |
commit | 75ae542de5a321e53449c8d5da34ffd519680db5 (patch) | |
tree | 9bea9a95fdbf0c8c746e31d90c291c564985c0a2 /base | |
parent | 08f75ed78a7f1823b850aa8cc0c90d4f760fc6ca (diff) | |
download | chromium_src-75ae542de5a321e53449c8d5da34ffd519680db5.zip chromium_src-75ae542de5a321e53449c8d5da34ffd519680db5.tar.gz chromium_src-75ae542de5a321e53449c8d5da34ffd519680db5.tar.bz2 |
Eliminate a circular dependency by making BGRAToRGBA() generic (no pulling in guchar from gtk.h) and moving it from base/gfx to base.
Review URL: http://codereview.chromium.org/87016
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@14117 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base')
-rw-r--r-- | base/base.gyp | 3 | ||||
-rw-r--r-- | base/clipboard_linux.cc | 6 | ||||
-rwxr-xr-x | base/gfx/gtk_util.cc | 20 | ||||
-rwxr-xr-x | base/gfx/gtk_util.h | 5 | ||||
-rw-r--r-- | base/linux_util.cc | 31 | ||||
-rw-r--r-- | base/linux_util.h | 19 |
6 files changed, 56 insertions, 28 deletions
diff --git a/base/base.gyp b/base/base.gyp index 3180c70..977b9d8 100644 --- a/base/base.gyp +++ b/base/base.gyp @@ -136,6 +136,8 @@ 'lazy_instance.cc', 'lazy_instance.h', 'linked_ptr.h', + 'linux_util.cc', + 'linux_util.h', 'lock.cc', 'lock.h', 'lock_impl.h', @@ -397,6 +399,7 @@ 'directory_watcher_inotify.cc', 'hmac_nss.cc', 'idle_timer_none.cc', + 'linux_util.cc', 'message_pump_glib.cc', 'nss_init.cc', 'nss_init.h', diff --git a/base/clipboard_linux.cc b/base/clipboard_linux.cc index 7d568e1..ce53902 100644 --- a/base/clipboard_linux.cc +++ b/base/clipboard_linux.cc @@ -10,7 +10,7 @@ #include <string> #include <utility> -#include "base/gfx/gtk_util.h" +#include "base/linux_util.h" #include "base/string_util.h" namespace { @@ -178,8 +178,8 @@ void Clipboard::WriteWebSmartPaste() { void Clipboard::WriteBitmap(const char* pixel_data, const char* size_data) { const gfx::Size* size = reinterpret_cast<const gfx::Size*>(size_data); - guchar* data = gfx::BGRAToRGBA(reinterpret_cast<const uint8_t*>(pixel_data), - size->width(), size->height(), 0); + guchar* data = base::BGRAToRGBA(reinterpret_cast<const uint8_t*>(pixel_data), + size->width(), size->height(), 0); GdkPixbuf* pixbuf = gdk_pixbuf_new_from_data(data, GDK_COLORSPACE_RGB, TRUE, diff --git a/base/gfx/gtk_util.cc b/base/gfx/gtk_util.cc index 77ec95a..03acfbf 100755 --- a/base/gfx/gtk_util.cc +++ b/base/gfx/gtk_util.cc @@ -27,24 +27,4 @@ void SubtractRectanglesFromRegion(GdkRegion* region, } } -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; - 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; -} - } // namespace gfx diff --git a/base/gfx/gtk_util.h b/base/gfx/gtk_util.h index 3a1a1d4..110caf5 100755 --- a/base/gfx/gtk_util.h +++ b/base/gfx/gtk_util.h @@ -28,11 +28,6 @@ extern const GdkColor kGdkGreen; void SubtractRectanglesFromRegion(GdkRegion* region, const std::vector<Rect>& cutouts); -// 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); - } // namespace gfx #endif // BASE_GFX_GTK_UTIL_H_ diff --git a/base/linux_util.cc b/base/linux_util.cc new file mode 100644 index 0000000..a58ee99 --- /dev/null +++ b/base/linux_util.cc @@ -0,0 +1,31 @@ +// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "linux_util.h" + +#include <stdlib.h> + +namespace base { + +uint8_t* BGRAToRGBA(const uint8_t* pixels, int width, int height, int stride) { + if (stride == 0) + stride = width * 4; + + uint8_t* new_pixels = static_cast<uint8_t*>(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; + 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; +} + +} // namespace base diff --git a/base/linux_util.h b/base/linux_util.h new file mode 100644 index 0000000..aa418cc --- /dev/null +++ b/base/linux_util.h @@ -0,0 +1,19 @@ +// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef BASE_LINUX_UTIL_H__ +#define BASE_LINUX_UTIL_H__ + +#include <stdint.h> + +namespace base { + +// 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); + +} // namespace base + +#endif // BASE_LINUX_UTIL_H__ |