blob: a58ee99ad0fc1083a1f3b3474e8b525ee29e851c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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
|