| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/gfx/gtk_util.h" | 5 #include "base/gfx/gtk_util.h" |
| 6 | 6 |
| 7 #include <gdk/gdk.h> | 7 #include <gdk/gdk.h> |
| 8 #include <gtk/gtk.h> | 8 #include <gtk/gtk.h> |
| 9 #include <stdlib.h> | 9 #include <stdlib.h> |
| 10 | 10 |
| 11 #include "base/gfx/rect.h" | 11 #include "base/gfx/rect.h" |
| 12 | 12 |
| 13 namespace gfx { | 13 namespace gfx { |
| 14 | 14 |
| 15 const GdkColor kGdkWhite = GDK_COLOR_RGB(0xff, 0xff, 0xff); | 15 const GdkColor kGdkWhite = GDK_COLOR_RGB(0xff, 0xff, 0xff); |
| 16 const GdkColor kGdkBlack = GDK_COLOR_RGB(0x00, 0x00, 0x00); | 16 const GdkColor kGdkBlack = GDK_COLOR_RGB(0x00, 0x00, 0x00); |
| 17 const GdkColor kGdkGreen = GDK_COLOR_RGB(0x00, 0xff, 0x00); | 17 const GdkColor kGdkGreen = GDK_COLOR_RGB(0x00, 0xff, 0x00); |
| 18 | 18 |
| 19 void SubtractRectanglesFromRegion(GdkRegion* region, | 19 void SubtractRectanglesFromRegion(GdkRegion* region, |
| 20 const std::vector<Rect>& cutouts) { | 20 const std::vector<Rect>& cutouts) { |
| 21 for (size_t i = 0; i < cutouts.size(); ++i) { | 21 for (size_t i = 0; i < cutouts.size(); ++i) { |
| 22 GdkRectangle rect = cutouts[i].ToGdkRectangle(); | 22 GdkRectangle rect = cutouts[i].ToGdkRectangle(); |
| 23 GdkRegion* rect_region = gdk_region_rectangle(&rect); | 23 GdkRegion* rect_region = gdk_region_rectangle(&rect); |
| 24 gdk_region_subtract(region, rect_region); | 24 gdk_region_subtract(region, rect_region); |
| 25 // TODO(deanm): It would be nice to be able to reuse the GdkRegion here. | 25 // TODO(deanm): It would be nice to be able to reuse the GdkRegion here. |
| 26 gdk_region_destroy(rect_region); | 26 gdk_region_destroy(rect_region); |
| 27 } | 27 } |
| 28 } | 28 } |
| 29 | 29 |
| 30 uint8_t* BGRAToRGBA(const uint8_t* pixels, int width, int height, int stride) { | |
| 31 if (stride == 0) | |
| 32 stride = width * 4; | |
| 33 | |
| 34 guchar* new_pixels = static_cast<guchar*>(malloc(height * stride)); | |
| 35 | |
| 36 // We have to copy the pixels and swap from BGRA to RGBA. | |
| 37 for (int i = 0; i < height; ++i) { | |
| 38 for (int j = 0; j < width; ++j) { | |
| 39 int idx = i * stride + j * 4; | |
| 40 new_pixels[idx] = pixels[idx + 2]; | |
| 41 new_pixels[idx + 1] = pixels[idx + 1]; | |
| 42 new_pixels[idx + 2] = pixels[idx]; | |
| 43 new_pixels[idx + 3] = pixels[idx + 3]; | |
| 44 } | |
| 45 } | |
| 46 | |
| 47 return new_pixels; | |
| 48 } | |
| 49 | |
| 50 } // namespace gfx | 30 } // namespace gfx |
| OLD | NEW |