blob: 4a294608ae01b9e612629df2cfd89be6f78f4999 [file] [log] [blame]
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001#include "precompiled.h"
2//
Geoff Lang86846e22014-06-03 15:48:54 -04003// Copyright (c) 2013-2014 The ANGLE Project Authors. All rights reserved.
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00004// Use of this source code is governed by a BSD-style license that can be
5// found in the LICENSE file.
6//
7
8// loadimage.cpp: Defines image loading functions.
9
10#include "libGLESv2/renderer/loadimage.h"
11
12namespace rx
13{
14
Geoff Lang86846e22014-06-03 15:48:54 -040015void LoadA8ToRGBA8(size_t width, size_t height, size_t depth,
16 const uint8_t *input, size_t inputRowPitch, size_t inputDepthPitch,
17 uint8_t *output, size_t outputRowPitch, size_t outputDepthPitch)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000018{
Geoff Lang86846e22014-06-03 15:48:54 -040019 for (size_t z = 0; z < depth; z++)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000020 {
Geoff Lang86846e22014-06-03 15:48:54 -040021 for (size_t y = 0; y < height; y++)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000022 {
Geoff Lang86846e22014-06-03 15:48:54 -040023 const uint8_t *source = OffsetDataPointer<uint8_t>(input, y, z, inputRowPitch, inputDepthPitch);
24 uint32_t *dest = OffsetDataPointer<uint32_t>(output, y, z, outputRowPitch, outputDepthPitch);
25 for (size_t x = 0; x < width; x++)
26 {
27 dest[x] = static_cast<uint32_t>(source[x]) << 24;
28 }
29 }
30 }
31}
32
33void LoadA8ToBGRA8(size_t width, size_t height, size_t depth,
34 const uint8_t *input, size_t inputRowPitch, size_t inputDepthPitch,
35 uint8_t *output, size_t outputRowPitch, size_t outputDepthPitch)
36{
37 // Same as loading to RGBA
38 LoadA8ToRGBA8(width, height, depth, input, inputRowPitch, inputDepthPitch, output, outputRowPitch, outputDepthPitch);
39}
40
41void LoadA32FToRGBA32F(size_t width, size_t height, size_t depth,
42 const uint8_t *input, size_t inputRowPitch, size_t inputDepthPitch,
43 uint8_t *output, size_t outputRowPitch, size_t outputDepthPitch)
44{
45 for (size_t z = 0; z < depth; z++)
46 {
47 for (size_t y = 0; y < height; y++)
48 {
49 const float *source = OffsetDataPointer<float>(input, y, z, inputRowPitch, inputDepthPitch);
50 float *dest = OffsetDataPointer<float>(output, y, z, outputRowPitch, outputDepthPitch);
51 for (size_t x = 0; x < width; x++)
52 {
53 dest[4 * x + 0] = 0.0f;
54 dest[4 * x + 1] = 0.0f;
55 dest[4 * x + 2] = 0.0f;
56 dest[4 * x + 3] = source[x];
57 }
58 }
59 }
60}
61
62void LoadA16FToRGBA16F(size_t width, size_t height, size_t depth,
63 const uint8_t *input, size_t inputRowPitch, size_t inputDepthPitch,
64 uint8_t *output, size_t outputRowPitch, size_t outputDepthPitch)
65{
66 for (size_t z = 0; z < depth; z++)
67 {
68 for (size_t y = 0; y < height; y++)
69 {
70 const uint16_t *source = OffsetDataPointer<uint16_t>(input, y, z, inputRowPitch, inputDepthPitch);
71 uint16_t *dest = OffsetDataPointer<uint16_t>(output, y, z, outputRowPitch, outputDepthPitch);
72 for (size_t x = 0; x < width; x++)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000073 {
74 dest[4 * x + 0] = 0;
75 dest[4 * x + 1] = 0;
76 dest[4 * x + 2] = 0;
77 dest[4 * x + 3] = source[x];
78 }
79 }
80 }
81}
82
Geoff Lang86846e22014-06-03 15:48:54 -040083void LoadL8ToRGBA8(size_t width, size_t height, size_t depth,
84 const uint8_t *input, size_t inputRowPitch, size_t inputDepthPitch,
85 uint8_t *output, size_t outputRowPitch, size_t outputDepthPitch)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000086{
Geoff Lang86846e22014-06-03 15:48:54 -040087 for (size_t z = 0; z < depth; z++)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000088 {
Geoff Lang86846e22014-06-03 15:48:54 -040089 for (size_t y = 0; y < height; y++)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000090 {
Geoff Lang86846e22014-06-03 15:48:54 -040091 const uint8_t *source = OffsetDataPointer<uint8_t>(input, y, z, inputRowPitch, inputDepthPitch);
92 uint8_t *dest = OffsetDataPointer<uint8_t>(output, y, z, outputRowPitch, outputDepthPitch);
93 for (size_t x = 0; x < width; x++)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000094 {
95 dest[4 * x + 0] = source[x];
96 dest[4 * x + 1] = source[x];
97 dest[4 * x + 2] = source[x];
98 dest[4 * x + 3] = 0xFF;
99 }
100 }
101 }
102}
103
Geoff Lang86846e22014-06-03 15:48:54 -0400104void LoadL8ToBGRA8(size_t width, size_t height, size_t depth,
105 const uint8_t *input, size_t inputRowPitch, size_t inputDepthPitch,
106 uint8_t *output, size_t outputRowPitch, size_t outputDepthPitch)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000107{
Geoff Lang86846e22014-06-03 15:48:54 -0400108 // Same as loading to RGBA
109 LoadL8ToRGBA8(width, height, depth, input, inputRowPitch, inputDepthPitch, output, outputRowPitch, outputDepthPitch);
110}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000111
Geoff Lang86846e22014-06-03 15:48:54 -0400112void LoadL32FToRGBA32F(size_t width, size_t height, size_t depth,
113 const uint8_t *input, size_t inputRowPitch, size_t inputDepthPitch,
114 uint8_t *output, size_t outputRowPitch, size_t outputDepthPitch)
115{
116 for (size_t z = 0; z < depth; z++)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000117 {
Geoff Lang86846e22014-06-03 15:48:54 -0400118 for (size_t y = 0; y < height; y++)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000119 {
Geoff Lang86846e22014-06-03 15:48:54 -0400120 const float *source = OffsetDataPointer<float>(input, y, z, inputRowPitch, inputDepthPitch);
121 float *dest = OffsetDataPointer<float>(output, y, z, outputRowPitch, outputDepthPitch);
122 for (size_t x = 0; x < width; x++)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000123 {
124 dest[4 * x + 0] = source[x];
125 dest[4 * x + 1] = source[x];
126 dest[4 * x + 2] = source[x];
127 dest[4 * x + 3] = 1.0f;
128 }
129 }
130 }
131}
132
Geoff Lang86846e22014-06-03 15:48:54 -0400133void LoadL16FToRGBA16F(size_t width, size_t height, size_t depth,
134 const uint8_t *input, size_t inputRowPitch, size_t inputDepthPitch,
135 uint8_t *output, size_t outputRowPitch, size_t outputDepthPitch)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000136{
Geoff Lang86846e22014-06-03 15:48:54 -0400137 for (size_t z = 0; z < depth; z++)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000138 {
Geoff Lang86846e22014-06-03 15:48:54 -0400139 for (size_t y = 0; y < height; y++)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000140 {
Geoff Lang86846e22014-06-03 15:48:54 -0400141 const uint16_t *source = OffsetDataPointer<uint16_t>(input, y, z, inputRowPitch, inputDepthPitch);
142 uint16_t *dest = OffsetDataPointer<uint16_t>(output, y, z, outputRowPitch, outputDepthPitch);
143 for (size_t x = 0; x < width; x++)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000144 {
145 dest[4 * x + 0] = source[x];
146 dest[4 * x + 1] = source[x];
147 dest[4 * x + 2] = source[x];
Geoff Langb69d39b2014-05-06 11:49:22 -0400148 dest[4 * x + 3] = gl::Float16One;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000149 }
150 }
151 }
152}
153
Geoff Lang86846e22014-06-03 15:48:54 -0400154void LoadLA8ToRGBA8(size_t width, size_t height, size_t depth,
155 const uint8_t *input, size_t inputRowPitch, size_t inputDepthPitch,
156 uint8_t *output, size_t outputRowPitch, size_t outputDepthPitch)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000157{
Geoff Lang86846e22014-06-03 15:48:54 -0400158 for (size_t z = 0; z < depth; z++)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000159 {
Geoff Lang86846e22014-06-03 15:48:54 -0400160 for (size_t y = 0; y < height; y++)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000161 {
Geoff Lang86846e22014-06-03 15:48:54 -0400162 const uint8_t *source = OffsetDataPointer<uint8_t>(input, y, z, inputRowPitch, inputDepthPitch);
163 uint8_t *dest = OffsetDataPointer<uint8_t>(output, y, z, outputRowPitch, outputDepthPitch);
164 for (size_t x = 0; x < width; x++)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000165 {
Geoff Lang86846e22014-06-03 15:48:54 -0400166 dest[4 * x + 0] = source[2 * x + 0];
167 dest[4 * x + 1] = source[2 * x + 0];
168 dest[4 * x + 2] = source[2 * x + 0];
169 dest[4 * x + 3] = source[2 * x + 1];
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000170 }
171 }
172 }
173}
174
Geoff Lang86846e22014-06-03 15:48:54 -0400175void LoadLA8ToBGRA8(size_t width, size_t height, size_t depth,
176 const uint8_t *input, size_t inputRowPitch, size_t inputDepthPitch,
177 uint8_t *output, size_t outputRowPitch, size_t outputDepthPitch)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000178{
Geoff Lang86846e22014-06-03 15:48:54 -0400179 // Same as loading to RGBA
180 LoadLA8ToRGBA8(width, height, depth, input, inputRowPitch, inputDepthPitch, output, outputRowPitch, outputDepthPitch);
181}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000182
Geoff Lang86846e22014-06-03 15:48:54 -0400183void LoadLA32FToRGBA32F(size_t width, size_t height, size_t depth,
184 const uint8_t *input, size_t inputRowPitch, size_t inputDepthPitch,
185 uint8_t *output, size_t outputRowPitch, size_t outputDepthPitch)
186{
187 for (size_t z = 0; z < depth; z++)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000188 {
Geoff Lang86846e22014-06-03 15:48:54 -0400189 for (size_t y = 0; y < height; y++)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000190 {
Geoff Lang86846e22014-06-03 15:48:54 -0400191 const float *source = OffsetDataPointer<float>(input, y, z, inputRowPitch, inputDepthPitch);
192 float *dest = OffsetDataPointer<float>(output, y, z, outputRowPitch, outputDepthPitch);
193 for (size_t x = 0; x < width; x++)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000194 {
Geoff Lang86846e22014-06-03 15:48:54 -0400195 dest[4 * x + 0] = source[2 * x + 0];
196 dest[4 * x + 1] = source[2 * x + 0];
197 dest[4 * x + 2] = source[2 * x + 0];
198 dest[4 * x + 3] = source[2 * x + 1];
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000199 }
200 }
201 }
202}
203
Geoff Lang86846e22014-06-03 15:48:54 -0400204void LoadLA16FToRGBA16F(size_t width, size_t height, size_t depth,
205 const uint8_t *input, size_t inputRowPitch, size_t inputDepthPitch,
206 uint8_t *output, size_t outputRowPitch, size_t outputDepthPitch)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000207{
Geoff Lang86846e22014-06-03 15:48:54 -0400208 for (size_t z = 0; z < depth; z++)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000209 {
Geoff Lang86846e22014-06-03 15:48:54 -0400210 for (size_t y = 0; y < height; y++)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000211 {
Geoff Lang86846e22014-06-03 15:48:54 -0400212 const uint16_t *source = OffsetDataPointer<uint16_t>(input, y, z, inputRowPitch, inputDepthPitch);
213 uint16_t *dest = OffsetDataPointer<uint16_t>(output, y, z, outputRowPitch, outputDepthPitch);
214 for (size_t x = 0; x < width; x++)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000215 {
Geoff Lang86846e22014-06-03 15:48:54 -0400216 dest[4 * x + 0] = source[2 * x + 0];
217 dest[4 * x + 1] = source[2 * x + 0];
218 dest[4 * x + 2] = source[2 * x + 0];
219 dest[4 * x + 3] = source[2 * x + 1];
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000220 }
221 }
222 }
223}
224
Geoff Lang86846e22014-06-03 15:48:54 -0400225void LoadRGB8ToBGRX8(size_t width, size_t height, size_t depth,
226 const uint8_t *input, size_t inputRowPitch, size_t inputDepthPitch,
227 uint8_t *output, size_t outputRowPitch, size_t outputDepthPitch)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000228{
Geoff Lang86846e22014-06-03 15:48:54 -0400229 for (size_t z = 0; z < depth; z++)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000230 {
Geoff Lang86846e22014-06-03 15:48:54 -0400231 for (size_t y = 0; y < height; y++)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000232 {
Geoff Lang86846e22014-06-03 15:48:54 -0400233 const uint8_t *source = OffsetDataPointer<uint8_t>(input, y, z, inputRowPitch, inputDepthPitch);
234 uint8_t *dest = OffsetDataPointer<uint8_t>(output, y, z, outputRowPitch, outputDepthPitch);
235 for (size_t x = 0; x < width; x++)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000236 {
237 dest[4 * x + 0] = source[x * 3 + 2];
238 dest[4 * x + 1] = source[x * 3 + 1];
239 dest[4 * x + 2] = source[x * 3 + 0];
240 dest[4 * x + 3] = 0xFF;
241 }
242 }
243 }
244}
245
Geoff Lang86846e22014-06-03 15:48:54 -0400246void LoadRG8ToBGRX8(size_t width, size_t height, size_t depth,
247 const uint8_t *input, size_t inputRowPitch, size_t inputDepthPitch,
248 uint8_t *output, size_t outputRowPitch, size_t outputDepthPitch)
Geoff Lang632192d2013-10-04 13:40:46 -0400249{
Geoff Lang86846e22014-06-03 15:48:54 -0400250 for (size_t z = 0; z < depth; z++)
Geoff Lang632192d2013-10-04 13:40:46 -0400251 {
Geoff Lang86846e22014-06-03 15:48:54 -0400252 for (size_t y = 0; y < height; y++)
Geoff Lang632192d2013-10-04 13:40:46 -0400253 {
Geoff Lang86846e22014-06-03 15:48:54 -0400254 const uint8_t *source = OffsetDataPointer<uint8_t>(input, y, z, inputRowPitch, inputDepthPitch);
255 uint8_t *dest = OffsetDataPointer<uint8_t>(output, y, z, outputRowPitch, outputDepthPitch);
256 for (size_t x = 0; x < width; x++)
Geoff Lang632192d2013-10-04 13:40:46 -0400257 {
258 dest[4 * x + 0] = 0x00;
259 dest[4 * x + 1] = source[x * 2 + 1];
260 dest[4 * x + 2] = source[x * 2 + 0];
261 dest[4 * x + 3] = 0xFF;
262 }
263 }
264 }
265}
266
Geoff Lang86846e22014-06-03 15:48:54 -0400267void LoadR8ToBGRX8(size_t width, size_t height, size_t depth,
268 const uint8_t *input, size_t inputRowPitch, size_t inputDepthPitch,
269 uint8_t *output, size_t outputRowPitch, size_t outputDepthPitch)
Geoff Lang632192d2013-10-04 13:40:46 -0400270{
Geoff Lang86846e22014-06-03 15:48:54 -0400271 for (size_t z = 0; z < depth; z++)
Geoff Lang632192d2013-10-04 13:40:46 -0400272 {
Geoff Lang86846e22014-06-03 15:48:54 -0400273 for (size_t y = 0; y < height; y++)
Geoff Lang632192d2013-10-04 13:40:46 -0400274 {
Geoff Lang86846e22014-06-03 15:48:54 -0400275 const uint8_t *source = OffsetDataPointer<uint8_t>(input, y, z, inputRowPitch, inputDepthPitch);
276 uint8_t *dest = OffsetDataPointer<uint8_t>(output, y, z, outputRowPitch, outputDepthPitch);
277 for (size_t x = 0; x < width; x++)
Geoff Lang632192d2013-10-04 13:40:46 -0400278 {
279 dest[4 * x + 0] = 0x00;
280 dest[4 * x + 1] = 0x00;
281 dest[4 * x + 2] = source[x];
282 dest[4 * x + 3] = 0xFF;
283 }
284 }
285 }
286}
287
Geoff Lang86846e22014-06-03 15:48:54 -0400288void LoadR5G6B5ToBGRA8(size_t width, size_t height, size_t depth,
289 const uint8_t *input, size_t inputRowPitch, size_t inputDepthPitch,
290 uint8_t *output, size_t outputRowPitch, size_t outputDepthPitch)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000291{
Geoff Lang86846e22014-06-03 15:48:54 -0400292 for (size_t z = 0; z < depth; z++)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000293 {
Geoff Lang86846e22014-06-03 15:48:54 -0400294 for (size_t y = 0; y < height; y++)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000295 {
Geoff Lang86846e22014-06-03 15:48:54 -0400296 const uint16_t *source = OffsetDataPointer<uint16_t>(input, y, z, inputRowPitch, inputDepthPitch);
297 uint8_t *dest = OffsetDataPointer<uint8_t>(output, y, z, outputRowPitch, outputDepthPitch);
298 for (size_t x = 0; x < width; x++)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000299 {
Geoff Lang86846e22014-06-03 15:48:54 -0400300 uint16_t rgb = source[x];
301 dest[4 * x + 0] = ((rgb & 0x001F) << 3) | ((rgb & 0x001F) >> 2);
302 dest[4 * x + 1] = ((rgb & 0x07E0) >> 3) | ((rgb & 0x07E0) >> 9);
303 dest[4 * x + 2] = ((rgb & 0xF800) >> 8) | ((rgb & 0xF800) >> 13);
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000304 dest[4 * x + 3] = 0xFF;
305 }
306 }
307 }
308}
309
Geoff Lang86846e22014-06-03 15:48:54 -0400310void LoadR5G6B5ToRGBA8(size_t width, size_t height, size_t depth,
311 const uint8_t *input, size_t inputRowPitch, size_t inputDepthPitch,
312 uint8_t *output, size_t outputRowPitch, size_t outputDepthPitch)
shannonwoods@chromium.org36d0be92013-05-30 00:15:59 +0000313{
Geoff Lang86846e22014-06-03 15:48:54 -0400314 for (size_t z = 0; z < depth; z++)
shannonwoods@chromium.org36d0be92013-05-30 00:15:59 +0000315 {
Geoff Lang86846e22014-06-03 15:48:54 -0400316 for (size_t y = 0; y < height; y++)
shannonwoods@chromium.org36d0be92013-05-30 00:15:59 +0000317 {
Geoff Lang86846e22014-06-03 15:48:54 -0400318 const uint16_t *source = OffsetDataPointer<uint16_t>(input, y, z, inputRowPitch, inputDepthPitch);
319 uint8_t *dest = OffsetDataPointer<uint8_t>(output, y, z, outputRowPitch, outputDepthPitch);
320 for (size_t x = 0; x < width; x++)
shannonwoods@chromium.org36d0be92013-05-30 00:15:59 +0000321 {
Geoff Lang86846e22014-06-03 15:48:54 -0400322 uint16_t rgb = source[x];
323 dest[4 * x + 0] = ((rgb & 0xF800) >> 8) | ((rgb & 0xF800) >> 13);
324 dest[4 * x + 1] = ((rgb & 0x07E0) >> 3) | ((rgb & 0x07E0) >> 9);
325 dest[4 * x + 2] = ((rgb & 0x001F) << 3) | ((rgb & 0x001F) >> 2);
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000326 dest[4 * x + 3] = 0xFF;
327 }
328 }
329 }
330}
331
Geoff Lang86846e22014-06-03 15:48:54 -0400332void LoadRGBA8ToBGRA8(size_t width, size_t height, size_t depth,
333 const uint8_t *input, size_t inputRowPitch, size_t inputDepthPitch,
334 uint8_t *output, size_t outputRowPitch, size_t outputDepthPitch)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000335{
Geoff Lang86846e22014-06-03 15:48:54 -0400336 for (size_t z = 0; z < depth; z++)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000337 {
Geoff Lang86846e22014-06-03 15:48:54 -0400338 for (size_t y = 0; y < height; y++)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000339 {
Geoff Lang86846e22014-06-03 15:48:54 -0400340 const uint32_t *source = OffsetDataPointer<uint32_t>(input, y, z, inputRowPitch, inputDepthPitch);
341 uint32_t *dest = OffsetDataPointer<uint32_t>(output, y, z, outputRowPitch, outputDepthPitch);
342 for (size_t x = 0; x < width; x++)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000343 {
Geoff Lang86846e22014-06-03 15:48:54 -0400344 uint32_t rgba = source[x];
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000345 dest[x] = (_rotl(rgba, 16) & 0x00ff00ff) | (rgba & 0xff00ff00);
346 }
347 }
348 }
349}
350
Geoff Lang86846e22014-06-03 15:48:54 -0400351void LoadRGBA4ToBGRA8(size_t width, size_t height, size_t depth,
352 const uint8_t *input, size_t inputRowPitch, size_t inputDepthPitch,
353 uint8_t *output, size_t outputRowPitch, size_t outputDepthPitch)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000354{
Geoff Lang86846e22014-06-03 15:48:54 -0400355 for (size_t z = 0; z < depth; z++)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000356 {
Geoff Lang86846e22014-06-03 15:48:54 -0400357 for (size_t y = 0; y < height; y++)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000358 {
Geoff Lang86846e22014-06-03 15:48:54 -0400359 const uint16_t *source = OffsetDataPointer<uint16_t>(input, y, z, inputRowPitch, inputDepthPitch);
360 uint8_t *dest = OffsetDataPointer<uint8_t>(output, y, z, outputRowPitch, outputDepthPitch);
361 for (size_t x = 0; x < width; x++)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000362 {
Geoff Lang86846e22014-06-03 15:48:54 -0400363 uint16_t rgba = source[x];
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000364 dest[4 * x + 0] = ((rgba & 0x00F0) << 0) | ((rgba & 0x00F0) >> 4);
365 dest[4 * x + 1] = ((rgba & 0x0F00) >> 4) | ((rgba & 0x0F00) >> 8);
366 dest[4 * x + 2] = ((rgba & 0xF000) >> 8) | ((rgba & 0xF000) >> 12);
367 dest[4 * x + 3] = ((rgba & 0x000F) << 4) | ((rgba & 0x000F) >> 0);
368 }
369 }
370 }
371}
372
Geoff Lang86846e22014-06-03 15:48:54 -0400373void LoadRGBA4ToRGBA8(size_t width, size_t height, size_t depth,
374 const uint8_t *input, size_t inputRowPitch, size_t inputDepthPitch,
375 uint8_t *output, size_t outputRowPitch, size_t outputDepthPitch)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000376{
Geoff Lang86846e22014-06-03 15:48:54 -0400377 for (size_t z = 0; z < depth; z++)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000378 {
Geoff Lang86846e22014-06-03 15:48:54 -0400379 for (size_t y = 0; y < height; y++)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000380 {
Geoff Lang86846e22014-06-03 15:48:54 -0400381 const uint16_t *source = OffsetDataPointer<uint16_t>(input, y, z, inputRowPitch, inputDepthPitch);
382 uint8_t *dest = OffsetDataPointer<uint8_t>(output, y, z, outputRowPitch, outputDepthPitch);
383 for (size_t x = 0; x < width; x++)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000384 {
Geoff Lang86846e22014-06-03 15:48:54 -0400385 uint16_t rgba = source[x];
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000386 dest[4 * x + 0] = ((rgba & 0xF000) >> 8) | ((rgba & 0xF000) >> 12);
387 dest[4 * x + 1] = ((rgba & 0x0F00) >> 4) | ((rgba & 0x0F00) >> 8);
388 dest[4 * x + 2] = ((rgba & 0x00F0) << 0) | ((rgba & 0x00F0) >> 4);
389 dest[4 * x + 3] = ((rgba & 0x000F) << 4) | ((rgba & 0x000F) >> 0);
390 }
391 }
392 }
393}
394
Geoff Lang86846e22014-06-03 15:48:54 -0400395void LoadBGRA4ToBGRA8(size_t width, size_t height, size_t depth,
396 const uint8_t *input, size_t inputRowPitch, size_t inputDepthPitch,
397 uint8_t *output, size_t outputRowPitch, size_t outputDepthPitch)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000398{
Geoff Lang86846e22014-06-03 15:48:54 -0400399 for (size_t z = 0; z < depth; z++)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000400 {
Geoff Lang86846e22014-06-03 15:48:54 -0400401 for (size_t y = 0; y < height; y++)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000402 {
Geoff Lang86846e22014-06-03 15:48:54 -0400403 const uint16_t *source = OffsetDataPointer<uint16_t>(input, y, z, inputRowPitch, inputDepthPitch);
404 uint8_t *dest = OffsetDataPointer<uint8_t>(output, y, z, outputRowPitch, outputDepthPitch);
405 for (size_t x = 0; x < width; x++)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000406 {
Geoff Lang86846e22014-06-03 15:48:54 -0400407 uint16_t bgra = source[x];
408 dest[4 * x + 0] = ((bgra & 0xF000) >> 8) | ((bgra & 0xF000) >> 12);
409 dest[4 * x + 1] = ((bgra & 0x0F00) >> 4) | ((bgra & 0x0F00) >> 8);
410 dest[4 * x + 2] = ((bgra & 0x00F0) << 0) | ((bgra & 0x00F0) >> 4);
411 dest[4 * x + 3] = ((bgra & 0x000F) << 4) | ((bgra & 0x000F) >> 0);
412 }
413 }
414 }
415}
416
417void LoadRGB5A1ToBGRA8(size_t width, size_t height, size_t depth,
418 const uint8_t *input, size_t inputRowPitch, size_t inputDepthPitch,
419 uint8_t *output, size_t outputRowPitch, size_t outputDepthPitch)
420{
421 for (size_t z = 0; z < depth; z++)
422 {
423 for (size_t y = 0; y < height; y++)
424 {
425 const uint16_t *source = OffsetDataPointer<uint16_t>(input, y, z, inputRowPitch, inputDepthPitch);
426 uint8_t *dest = OffsetDataPointer<uint8_t>(output, y, z, outputRowPitch, outputDepthPitch);
427 for (size_t x = 0; x < width; x++)
428 {
429 uint16_t rgba = source[x];
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000430 dest[4 * x + 0] = ((rgba & 0x003E) << 2) | ((rgba & 0x003E) >> 3);
431 dest[4 * x + 1] = ((rgba & 0x07C0) >> 3) | ((rgba & 0x07C0) >> 8);
432 dest[4 * x + 2] = ((rgba & 0xF800) >> 8) | ((rgba & 0xF800) >> 13);
433 dest[4 * x + 3] = (rgba & 0x0001) ? 0xFF : 0;
434 }
435 }
436 }
437}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000438
Geoff Lang86846e22014-06-03 15:48:54 -0400439void LoadRGB5A1ToRGBA8(size_t width, size_t height, size_t depth,
440 const uint8_t *input, size_t inputRowPitch, size_t inputDepthPitch,
441 uint8_t *output, size_t outputRowPitch, size_t outputDepthPitch)
442{
443 for (size_t z = 0; z < depth; z++)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000444 {
Geoff Lang86846e22014-06-03 15:48:54 -0400445 for (size_t y = 0; y < height; y++)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000446 {
Geoff Lang86846e22014-06-03 15:48:54 -0400447 const uint16_t *source = OffsetDataPointer<uint16_t>(input, y, z, inputRowPitch, inputDepthPitch);
448 uint8_t *dest = OffsetDataPointer<uint8_t>(output, y, z, outputRowPitch, outputDepthPitch);
449 for (size_t x = 0; x < width; x++)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000450 {
Geoff Lang86846e22014-06-03 15:48:54 -0400451 uint16_t rgba = source[x];
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000452 dest[4 * x + 0] = ((rgba & 0xF800) >> 8) | ((rgba & 0xF800) >> 13);
453 dest[4 * x + 1] = ((rgba & 0x07C0) >> 3) | ((rgba & 0x07C0) >> 8);
454 dest[4 * x + 2] = ((rgba & 0x003E) << 2) | ((rgba & 0x003E) >> 3);
455 dest[4 * x + 3] = (rgba & 0x0001) ? 0xFF : 0;
456 }
457 }
458 }
459}
460
Geoff Lang86846e22014-06-03 15:48:54 -0400461
462void LoadBGR5A1ToBGRA8(size_t width, size_t height, size_t depth,
463 const uint8_t *input, size_t inputRowPitch, size_t inputDepthPitch,
464 uint8_t *output, size_t outputRowPitch, size_t outputDepthPitch)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000465{
Geoff Lang86846e22014-06-03 15:48:54 -0400466 for (size_t z = 0; z < depth; z++)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000467 {
Geoff Lang86846e22014-06-03 15:48:54 -0400468 for (size_t y = 0; y < height; y++)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000469 {
Geoff Lang86846e22014-06-03 15:48:54 -0400470 const uint16_t *source = OffsetDataPointer<uint16_t>(input, y, z, inputRowPitch, inputDepthPitch);
471 uint8_t *dest = OffsetDataPointer<uint8_t>(output, y, z, outputRowPitch, outputDepthPitch);
472 for (size_t x = 0; x < width; x++)
shannonwoods@chromium.org5d4468e2013-05-30 00:13:56 +0000473 {
Geoff Lang86846e22014-06-03 15:48:54 -0400474 uint16_t bgra = source[x];
475 dest[4 * x + 0] = ((bgra & 0xF800) >> 8) | ((bgra & 0xF800) >> 13);
476 dest[4 * x + 1] = ((bgra & 0x07C0) >> 3) | ((bgra & 0x07C0) >> 8);
477 dest[4 * x + 2] = ((bgra & 0x003E) << 2) | ((bgra & 0x003E) >> 3);
478 dest[4 * x + 3] = (bgra & 0x0001) ? 0xFF : 0;
479 }
480 }
481 }
482}
483
484void LoadRGB10A2ToRGBA8(size_t width, size_t height, size_t depth,
485 const uint8_t *input, size_t inputRowPitch, size_t inputDepthPitch,
486 uint8_t *output, size_t outputRowPitch, size_t outputDepthPitch)
487{
488 for (size_t z = 0; z < depth; z++)
489 {
490 for (size_t y = 0; y < height; y++)
491 {
492 const uint32_t *source = OffsetDataPointer<uint32_t>(input, y, z, inputRowPitch, inputDepthPitch);
493 uint8_t *dest = OffsetDataPointer<uint8_t>(output, y, z, outputRowPitch, outputDepthPitch);
494 for (size_t x = 0; x < width; x++)
495 {
496 uint32_t rgba = source[x];
shannonwoods@chromium.org5d4468e2013-05-30 00:13:56 +0000497 dest[4 * x + 0] = (rgba & 0x000003FF) >> 2;
498 dest[4 * x + 1] = (rgba & 0x000FFC00) >> 12;
499 dest[4 * x + 2] = (rgba & 0x3FF00000) >> 22;
500 dest[4 * x + 3] = ((rgba & 0xC0000000) >> 30) * 0x55;
501 }
502 }
503 }
504}
505
Geoff Lang86846e22014-06-03 15:48:54 -0400506void LoadRGB16FToRGB9E5(size_t width, size_t height, size_t depth,
507 const uint8_t *input, size_t inputRowPitch, size_t inputDepthPitch,
508 uint8_t *output, size_t outputRowPitch, size_t outputDepthPitch)
shannonwoods@chromium.org92b9cd52013-05-30 00:14:48 +0000509{
Geoff Lang86846e22014-06-03 15:48:54 -0400510 for (size_t z = 0; z < depth; z++)
shannonwoods@chromium.org92b9cd52013-05-30 00:14:48 +0000511 {
Geoff Lang86846e22014-06-03 15:48:54 -0400512 for (size_t y = 0; y < height; y++)
shannonwoods@chromium.org92b9cd52013-05-30 00:14:48 +0000513 {
Geoff Lang86846e22014-06-03 15:48:54 -0400514 const uint16_t *source = OffsetDataPointer<uint16_t>(input, y, z, inputRowPitch, inputDepthPitch);
515 uint32_t *dest = OffsetDataPointer<uint32_t>(output, y, z, outputRowPitch, outputDepthPitch);
516 for (size_t x = 0; x < width; x++)
shannonwoods@chromium.org92b9cd52013-05-30 00:14:48 +0000517 {
518 dest[x] = gl::convertRGBFloatsTo999E5(gl::float16ToFloat32(source[x * 3 + 0]),
519 gl::float16ToFloat32(source[x * 3 + 1]),
520 gl::float16ToFloat32(source[x * 3 + 2]));
521 }
522 }
523 }
524}
525
Geoff Lang86846e22014-06-03 15:48:54 -0400526void LoadRGB32FToRGB9E5(size_t width, size_t height, size_t depth,
527 const uint8_t *input, size_t inputRowPitch, size_t inputDepthPitch,
528 uint8_t *output, size_t outputRowPitch, size_t outputDepthPitch)
shannonwoods@chromium.org92b9cd52013-05-30 00:14:48 +0000529{
Geoff Lang86846e22014-06-03 15:48:54 -0400530 for (size_t z = 0; z < depth; z++)
shannonwoods@chromium.org92b9cd52013-05-30 00:14:48 +0000531 {
Geoff Lang86846e22014-06-03 15:48:54 -0400532 for (size_t y = 0; y < height; y++)
shannonwoods@chromium.org92b9cd52013-05-30 00:14:48 +0000533 {
Geoff Lang86846e22014-06-03 15:48:54 -0400534 const float *source = OffsetDataPointer<float>(input, y, z, inputRowPitch, inputDepthPitch);
535 uint32_t *dest = OffsetDataPointer<uint32_t>(output, y, z, outputRowPitch, outputDepthPitch);
536 for (size_t x = 0; x < width; x++)
shannonwoods@chromium.org92b9cd52013-05-30 00:14:48 +0000537 {
538 dest[x] = gl::convertRGBFloatsTo999E5(source[x * 3 + 0], source[x * 3 + 1], source[x * 3 + 2]);
539 }
540 }
541 }
542}
543
Geoff Lang86846e22014-06-03 15:48:54 -0400544void LoadRGB16FToRG11B10F(size_t width, size_t height, size_t depth,
545 const uint8_t *input, size_t inputRowPitch, size_t inputDepthPitch,
546 uint8_t *output, size_t outputRowPitch, size_t outputDepthPitch)
shannonwoods@chromium.orga43d8292013-05-30 00:15:50 +0000547{
Geoff Lang86846e22014-06-03 15:48:54 -0400548 for (size_t z = 0; z < depth; z++)
shannonwoods@chromium.orga43d8292013-05-30 00:15:50 +0000549 {
Geoff Lang86846e22014-06-03 15:48:54 -0400550 for (size_t y = 0; y < height; y++)
shannonwoods@chromium.orga43d8292013-05-30 00:15:50 +0000551 {
Geoff Lang86846e22014-06-03 15:48:54 -0400552 const uint16_t *source = OffsetDataPointer<uint16_t>(input, y, z, inputRowPitch, inputDepthPitch);
553 uint32_t *dest = OffsetDataPointer<uint32_t>(output, y, z, outputRowPitch, outputDepthPitch);
554 for (size_t x = 0; x < width; x++)
shannonwoods@chromium.orga43d8292013-05-30 00:15:50 +0000555 {
556 dest[x] = (gl::float32ToFloat11(gl::float16ToFloat32(source[x * 3 + 0])) << 0) |
557 (gl::float32ToFloat11(gl::float16ToFloat32(source[x * 3 + 1])) << 11) |
558 (gl::float32ToFloat10(gl::float16ToFloat32(source[x * 3 + 2])) << 22);
559 }
560 }
561 }
562}
563
Geoff Lang86846e22014-06-03 15:48:54 -0400564void LoadRGB32FToRG11B10F(size_t width, size_t height, size_t depth,
565 const uint8_t *input, size_t inputRowPitch, size_t inputDepthPitch,
566 uint8_t *output, size_t outputRowPitch, size_t outputDepthPitch)
shannonwoods@chromium.orga43d8292013-05-30 00:15:50 +0000567{
Geoff Lang86846e22014-06-03 15:48:54 -0400568 for (size_t z = 0; z < depth; z++)
shannonwoods@chromium.orga43d8292013-05-30 00:15:50 +0000569 {
Geoff Lang86846e22014-06-03 15:48:54 -0400570 for (size_t y = 0; y < height; y++)
shannonwoods@chromium.orga43d8292013-05-30 00:15:50 +0000571 {
Geoff Lang86846e22014-06-03 15:48:54 -0400572 const float *source = OffsetDataPointer<float>(input, y, z, inputRowPitch, inputDepthPitch);
573 uint32_t *dest = OffsetDataPointer<uint32_t>(output, y, z, outputRowPitch, outputDepthPitch);
574 for (size_t x = 0; x < width; x++)
shannonwoods@chromium.orga43d8292013-05-30 00:15:50 +0000575 {
576 dest[x] = (gl::float32ToFloat11(source[x * 3 + 0]) << 0) |
577 (gl::float32ToFloat11(source[x * 3 + 1]) << 11) |
578 (gl::float32ToFloat10(source[x * 3 + 2]) << 22);
579 }
580 }
581 }
582}
583
Geoff Lang86846e22014-06-03 15:48:54 -0400584void LoadG8R24ToR24G8(size_t width, size_t height, size_t depth,
585 const uint8_t *input, size_t inputRowPitch, size_t inputDepthPitch,
586 uint8_t *output, size_t outputRowPitch, size_t outputDepthPitch)
Geoff Lang4133f5c2013-10-10 13:51:18 -0400587{
Geoff Lang86846e22014-06-03 15:48:54 -0400588 for (size_t z = 0; z < depth; z++)
Geoff Lang4133f5c2013-10-10 13:51:18 -0400589 {
Geoff Lang86846e22014-06-03 15:48:54 -0400590 for (size_t y = 0; y < height; y++)
Geoff Lang4133f5c2013-10-10 13:51:18 -0400591 {
Geoff Lang86846e22014-06-03 15:48:54 -0400592 const uint32_t *source = OffsetDataPointer<uint32_t>(input, y, z, inputRowPitch, inputDepthPitch);
593 uint32_t *dest = OffsetDataPointer<uint32_t>(output, y, z, outputRowPitch, outputDepthPitch);
594 for (size_t x = 0; x < width; x++)
Geoff Lang4133f5c2013-10-10 13:51:18 -0400595 {
Geoff Lang86846e22014-06-03 15:48:54 -0400596 uint32_t d = source[x] >> 8;
597 uint8_t s = source[x] & 0xFF;
Geoff Lang5c9a29a2014-02-11 10:26:24 -0500598 dest[x] = d | (s << 24);
Geoff Lang4133f5c2013-10-10 13:51:18 -0400599 }
600 }
601 }
602}
603
Geoff Lang86846e22014-06-03 15:48:54 -0400604void LoadRGB32FToRGBA16F(size_t width, size_t height, size_t depth,
605 const uint8_t *input, size_t inputRowPitch, size_t inputDepthPitch,
606 uint8_t *output, size_t outputRowPitch, size_t outputDepthPitch)
shannonwoods@chromium.orgde7e6a22013-05-30 00:16:46 +0000607{
Geoff Lang86846e22014-06-03 15:48:54 -0400608 for (size_t z = 0; z < depth; z++)
shannonwoods@chromium.orgde7e6a22013-05-30 00:16:46 +0000609 {
Geoff Lang86846e22014-06-03 15:48:54 -0400610 for (size_t y = 0; y < height; y++)
shannonwoods@chromium.orgde7e6a22013-05-30 00:16:46 +0000611 {
Geoff Lang86846e22014-06-03 15:48:54 -0400612 const float *source = OffsetDataPointer<float>(input, y, z, inputRowPitch, inputDepthPitch);
613 uint16_t *dest = OffsetDataPointer<uint16_t>(output, y, z, outputRowPitch, outputDepthPitch);
614 for (size_t x = 0; x < width; x++)
shannonwoods@chromium.orgde7e6a22013-05-30 00:16:46 +0000615 {
616 dest[x * 4 + 0] = gl::float32ToFloat16(source[x * 3 + 0]);
617 dest[x * 4 + 1] = gl::float32ToFloat16(source[x * 3 + 1]);
618 dest[x * 4 + 2] = gl::float32ToFloat16(source[x * 3 + 2]);
619 dest[x * 4 + 3] = gl::Float16One;
620 }
621 }
622 }
623}
624
Geoff Lang86846e22014-06-03 15:48:54 -0400625void LoadR32ToR16(size_t width, size_t height, size_t depth,
626 const uint8_t *input, size_t inputRowPitch, size_t inputDepthPitch,
627 uint8_t *output, size_t outputRowPitch, size_t outputDepthPitch)
Geoff Lang87465462013-06-17 16:28:54 -0400628{
Geoff Lang86846e22014-06-03 15:48:54 -0400629 for (size_t z = 0; z < depth; z++)
Geoff Lang87465462013-06-17 16:28:54 -0400630 {
Geoff Lang86846e22014-06-03 15:48:54 -0400631 for (size_t y = 0; y < height; y++)
Geoff Lang87465462013-06-17 16:28:54 -0400632 {
Geoff Lang86846e22014-06-03 15:48:54 -0400633 const uint32_t *source = OffsetDataPointer<uint32_t>(input, y, z, inputRowPitch, inputDepthPitch);
634 uint16_t *dest = OffsetDataPointer<uint16_t>(output, y, z, outputRowPitch, outputDepthPitch);
635 for (size_t x = 0; x < width; x++)
Geoff Lang87465462013-06-17 16:28:54 -0400636 {
637 dest[x] = source[x] >> 16;
638 }
639 }
640 }
641}
642
Geoff Lang86846e22014-06-03 15:48:54 -0400643void LoadR32ToR24G8(size_t width, size_t height, size_t depth,
644 const uint8_t *input, size_t inputRowPitch, size_t inputDepthPitch,
645 uint8_t *output, size_t outputRowPitch, size_t outputDepthPitch)
Geoff Lange4a492b2014-06-19 14:14:41 -0400646{
Geoff Lang86846e22014-06-03 15:48:54 -0400647 for (size_t z = 0; z < depth; z++)
Geoff Lange4a492b2014-06-19 14:14:41 -0400648 {
Geoff Lang86846e22014-06-03 15:48:54 -0400649 for (size_t y = 0; y < height; y++)
Geoff Lange4a492b2014-06-19 14:14:41 -0400650 {
Geoff Lang86846e22014-06-03 15:48:54 -0400651 const uint32_t *source = OffsetDataPointer<uint32_t>(input, y, z, inputRowPitch, inputDepthPitch);
652 uint32_t *dest = OffsetDataPointer<uint32_t>(output, y, z, outputRowPitch, outputDepthPitch);
Geoff Lange4a492b2014-06-19 14:14:41 -0400653
Geoff Lang86846e22014-06-03 15:48:54 -0400654 for (size_t x = 0; x < width; x++)
Geoff Lange4a492b2014-06-19 14:14:41 -0400655 {
656 dest[x] = source[x] >> 8;
657 }
658 }
659 }
660}
661
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000662}