diff options
author | jhawkins@chromium.org <jhawkins@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-10-28 19:37:29 +0000 |
---|---|---|
committer | jhawkins@chromium.org <jhawkins@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-10-28 19:37:29 +0000 |
commit | 7110c24868971986f9e5cbd22a8dd1e87bda021f (patch) | |
tree | 0d650181d24330c4f72be140224af4a17fed4b51 /base | |
parent | cf34891f6a2391419f416356350a542aa4c1cc0f (diff) | |
download | chromium_src-7110c24868971986f9e5cbd22a8dd1e87bda021f.zip chromium_src-7110c24868971986f9e5cbd22a8dd1e87bda021f.tar.gz chromium_src-7110c24868971986f9e5cbd22a8dd1e87bda021f.tar.bz2 |
Cleanup: Get rid of app/gtk_util.h.
* Most functions moved to chrome/browser/gtk/gtk_util.h because they're only
used within chrome/browser.
* BGRAToRGBA() is used within chrome/ and app/ so moved it to base/gtk_util.h.
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/4170002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@64295 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base')
-rw-r--r-- | base/gtk_util.cc | 22 | ||||
-rw-r--r-- | base/gtk_util.h | 6 |
2 files changed, 28 insertions, 0 deletions
diff --git a/base/gtk_util.cc b/base/gtk_util.cc index 79fc485..b526aca 100644 --- a/base/gtk_util.cc +++ b/base/gtk_util.cc @@ -4,6 +4,8 @@ #include "base/gtk_util.h" +#include <stdlib.h> + namespace gtk_util { namespace { @@ -46,4 +48,24 @@ std::string RemoveWindowsStyleAccelerators(const std::string& label) { return ConvertAmperstandsTo(label, ""); } +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 gtk_util diff --git a/base/gtk_util.h b/base/gtk_util.h index 435780d..912bfbd 100644 --- a/base/gtk_util.h +++ b/base/gtk_util.h @@ -7,6 +7,7 @@ #pragma once #include <string> +#include <stdint.h> namespace gtk_util { @@ -17,6 +18,11 @@ std::string ConvertAcceleratorsFromWindowsStyle(const std::string& label); // Removes the "&" accelerators from a Windows label. std::string RemoveWindowsStyleAccelerators(const std::string& label); +// 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 gtk_util #endif // BASE_GTK_UTIL_H_ |