summaryrefslogtreecommitdiffstats
path: root/app/gtk_util.cc
diff options
context:
space:
mode:
Diffstat (limited to 'app/gtk_util.cc')
-rw-r--r--app/gtk_util.cc20
1 files changed, 20 insertions, 0 deletions
diff --git a/app/gtk_util.cc b/app/gtk_util.cc
index 0411fbb..00b1b5b 100644
--- a/app/gtk_util.cc
+++ b/app/gtk_util.cc
@@ -31,6 +31,26 @@ void GetWidgetSizeFromResources(
GetWidgetSizeFromCharacters(widget, chars, lines, width, height);
}
+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;
+}
+
void GetWidgetSizeFromCharacters(
GtkWidget* widget, double width_chars, double height_lines,
int* width, int* height) {